Skip to content

Commit

Permalink
Mojo C++ bindings: more readable error message for missing *Traits sp…
Browse files Browse the repository at this point in the history
…ecialization.

BUG=None

Change-Id: I3cae8cee3d77006c659bb9784a7089478276016e
Reviewed-on: https://chromium-review.googlesource.com/574682
Reviewed-by: Ken Rockot <rockot@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Yuzhu Shen <yzshen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487638}
  • Loading branch information
yzshen authored and Commit Bot committed Jul 18, 2017
1 parent 46eb9ac commit 09d5925
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 12 deletions.
11 changes: 11 additions & 0 deletions ipc/ipc_param_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@
// a data type is read, written and logged in the IPC system.

namespace IPC {
namespace internal {

template <typename T>
struct AlwaysFalse {
static const bool value = false;
};

} // namespace internal

template <class P> struct ParamTraits {
static_assert(internal::AlwaysFalse<P>::value,
"Cannot find the IPC::ParamTraits specialization. Did you "
"forget to include the corresponding header file?");
};

template <class P>
Expand Down
10 changes: 5 additions & 5 deletions mojo/public/cpp/bindings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ component("bindings") {
"$interfaces_bindings_gen_dir/pipe_control_messages.mojom.cc",
"$interfaces_bindings_gen_dir/pipe_control_messages.mojom.h",
"array_data_view.h",
"array_traits.h",
"array_traits_carray.h",
"array_traits_stl.h",
"associated_binding.h",
Expand Down Expand Up @@ -110,7 +109,6 @@ component("bindings") {
"lib/sync_handle_watcher.cc",
"lib/task_runner_helper.cc",
"lib/task_runner_helper.h",
"lib/template_util.h",
"lib/unserialized_message_context.cc",
"lib/unserialized_message_context.h",
"lib/validate_params.h",
Expand All @@ -122,7 +120,6 @@ component("bindings") {
"lib/validation_util.h",
"map.h",
"map_data_view.h",
"map_traits.h",
"map_traits_stl.h",
"message.h",
"message_header_validator.h",
Expand All @@ -135,7 +132,6 @@ component("bindings") {
"raw_ptr_impl_ref_traits.h",
"scoped_interface_endpoint_handle.h",
"string_data_view.h",
"string_traits.h",
"string_traits_stl.h",
"string_traits_string16.h",
"string_traits_string_piece.h",
Expand All @@ -149,7 +145,6 @@ component("bindings") {
"sync_handle_watcher.h",
"thread_safe_interface_ptr.h",
"type_converter.h",
"union_traits.h",
"unique_ptr_impl_ref_traits.h",
]

Expand All @@ -171,8 +166,13 @@ component("bindings") {

source_set("struct_traits") {
sources = [
"array_traits.h",
"enum_traits.h",
"lib/template_util.h",
"map_traits.h",
"string_traits.h",
"struct_traits.h",
"union_traits.h",
]
}

Expand Down
8 changes: 7 additions & 1 deletion mojo/public/cpp/bindings/array_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_

#include "mojo/public/cpp/bindings/lib/template_util.h"

namespace mojo {

// This must be specialized for any type |T| to be serialized/deserialized as
Expand Down Expand Up @@ -64,7 +66,11 @@ namespace mojo {
// };
//
template <typename T>
struct ArrayTraits;
struct ArrayTraits {
static_assert(internal::AlwaysFalse<T>::value,
"Cannot find the mojo::ArrayTraits specialization. Did you "
"forget to include the corresponding header file?");
};

} // namespace mojo

Expand Down
8 changes: 7 additions & 1 deletion mojo/public/cpp/bindings/enum_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_ENUM_TRAITS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_ENUM_TRAITS_H_

#include "mojo/public/cpp/bindings/lib/template_util.h"

namespace mojo {

// This must be specialized for any type |T| to be serialized/deserialized as a
Expand All @@ -20,7 +22,11 @@ namespace mojo {
// };
//
template <typename MojomType, typename T>
struct EnumTraits;
struct EnumTraits {
static_assert(internal::AlwaysFalse<T>::value,
"Cannot find the mojo::EnumTraits specialization. Did you "
"forget to include the corresponding header file?");
};

} // namespace mojo

Expand Down
1 change: 1 addition & 0 deletions mojo/public/cpp/bindings/lib/string_traits_wtf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "base/logging.h"
#include "mojo/public/cpp/bindings/lib/array_internal.h"
#include "mojo/public/cpp/bindings/string_data_view.h"
#include "third_party/WebKit/Source/platform/wtf/text/StringUTF8Adaptor.h"

namespace mojo {
Expand Down
5 changes: 5 additions & 0 deletions mojo/public/cpp/bindings/lib/template_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ struct Conditional<false, T, F> {
typedef F type;
};

template <typename T>
struct AlwaysFalse {
static const bool value = false;
};

} // namespace internal
} // namespace mojo

Expand Down
8 changes: 7 additions & 1 deletion mojo/public/cpp/bindings/map_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_H_

#include "mojo/public/cpp/bindings/lib/template_util.h"

namespace mojo {

// This must be specialized for any type |T| to be serialized/deserialized as
Expand Down Expand Up @@ -49,7 +51,11 @@ namespace mojo {
// };
//
template <typename T>
struct MapTraits;
struct MapTraits {
static_assert(internal::AlwaysFalse<T>::value,
"Cannot find the mojo::MapTraits specialization. Did you "
"forget to include the corresponding header file?");
};

} // namespace mojo

Expand Down
8 changes: 6 additions & 2 deletions mojo/public/cpp/bindings/string_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_

#include "mojo/public/cpp/bindings/string_data_view.h"
#include "mojo/public/cpp/bindings/lib/template_util.h"

namespace mojo {

Expand Down Expand Up @@ -47,7 +47,11 @@ namespace mojo {
// so that you can do any necessary cleanup.
//
template <typename T>
struct StringTraits;
struct StringTraits {
static_assert(internal::AlwaysFalse<T>::value,
"Cannot find the mojo::StringTraits specialization. Did you "
"forget to include the corresponding header file?");
};

} // namespace mojo

Expand Down
1 change: 1 addition & 0 deletions mojo/public/cpp/bindings/string_traits_string16.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "base/strings/string16.h"
#include "mojo/public/cpp/bindings/bindings_export.h"
#include "mojo/public/cpp/bindings/string_data_view.h"
#include "mojo/public/cpp/bindings/string_traits.h"

namespace mojo {
Expand Down
8 changes: 7 additions & 1 deletion mojo/public/cpp/bindings/struct_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_TRAITS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_TRAITS_H_

#include "mojo/public/cpp/bindings/lib/template_util.h"

namespace mojo {

// This must be specialized for any type |T| to be serialized/deserialized as
Expand Down Expand Up @@ -158,7 +160,11 @@ namespace mojo {
// };
//
template <typename DataViewType, typename T>
struct StructTraits;
struct StructTraits {
static_assert(internal::AlwaysFalse<T>::value,
"Cannot find the mojo::StructTraits specialization. Did you "
"forget to include the corresponding header file?");
};

} // namespace mojo

Expand Down
8 changes: 7 additions & 1 deletion mojo/public/cpp/bindings/union_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_
#define MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_

#include "mojo/public/cpp/bindings/lib/template_util.h"

namespace mojo {

// This must be specialized for any type |T| to be serialized/deserialized as
Expand Down Expand Up @@ -32,7 +34,11 @@ namespace mojo {
// will be called.
//
template <typename DataViewType, typename T>
struct UnionTraits;
struct UnionTraits {
static_assert(internal::AlwaysFalse<T>::value,
"Cannot find the mojo::UnionTraits specialization. Did you "
"forget to include the corresponding header file?");
};

} // namespace mojo

Expand Down

0 comments on commit 09d5925

Please sign in to comment.