Commit 09d59250 authored by Yuzhu Shen's avatar Yuzhu Shen Committed by Commit Bot

Mojo C++ bindings: more readable error message for missing *Traits specialization.

BUG=None

Change-Id: I3cae8cee3d77006c659bb9784a7089478276016e
Reviewed-on: https://chromium-review.googlesource.com/574682Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Yuzhu Shen <yzshen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487638}
parent 46eb9acc
...@@ -9,8 +9,19 @@ ...@@ -9,8 +9,19 @@
// a data type is read, written and logged in the IPC system. // a data type is read, written and logged in the IPC system.
namespace IPC { namespace IPC {
namespace internal {
template <typename T>
struct AlwaysFalse {
static const bool value = false;
};
} // namespace internal
template <class P> struct ParamTraits { 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> template <class P>
......
...@@ -22,7 +22,6 @@ component("bindings") { ...@@ -22,7 +22,6 @@ component("bindings") {
"$interfaces_bindings_gen_dir/pipe_control_messages.mojom.cc", "$interfaces_bindings_gen_dir/pipe_control_messages.mojom.cc",
"$interfaces_bindings_gen_dir/pipe_control_messages.mojom.h", "$interfaces_bindings_gen_dir/pipe_control_messages.mojom.h",
"array_data_view.h", "array_data_view.h",
"array_traits.h",
"array_traits_carray.h", "array_traits_carray.h",
"array_traits_stl.h", "array_traits_stl.h",
"associated_binding.h", "associated_binding.h",
...@@ -110,7 +109,6 @@ component("bindings") { ...@@ -110,7 +109,6 @@ component("bindings") {
"lib/sync_handle_watcher.cc", "lib/sync_handle_watcher.cc",
"lib/task_runner_helper.cc", "lib/task_runner_helper.cc",
"lib/task_runner_helper.h", "lib/task_runner_helper.h",
"lib/template_util.h",
"lib/unserialized_message_context.cc", "lib/unserialized_message_context.cc",
"lib/unserialized_message_context.h", "lib/unserialized_message_context.h",
"lib/validate_params.h", "lib/validate_params.h",
...@@ -122,7 +120,6 @@ component("bindings") { ...@@ -122,7 +120,6 @@ component("bindings") {
"lib/validation_util.h", "lib/validation_util.h",
"map.h", "map.h",
"map_data_view.h", "map_data_view.h",
"map_traits.h",
"map_traits_stl.h", "map_traits_stl.h",
"message.h", "message.h",
"message_header_validator.h", "message_header_validator.h",
...@@ -135,7 +132,6 @@ component("bindings") { ...@@ -135,7 +132,6 @@ component("bindings") {
"raw_ptr_impl_ref_traits.h", "raw_ptr_impl_ref_traits.h",
"scoped_interface_endpoint_handle.h", "scoped_interface_endpoint_handle.h",
"string_data_view.h", "string_data_view.h",
"string_traits.h",
"string_traits_stl.h", "string_traits_stl.h",
"string_traits_string16.h", "string_traits_string16.h",
"string_traits_string_piece.h", "string_traits_string_piece.h",
...@@ -149,7 +145,6 @@ component("bindings") { ...@@ -149,7 +145,6 @@ component("bindings") {
"sync_handle_watcher.h", "sync_handle_watcher.h",
"thread_safe_interface_ptr.h", "thread_safe_interface_ptr.h",
"type_converter.h", "type_converter.h",
"union_traits.h",
"unique_ptr_impl_ref_traits.h", "unique_ptr_impl_ref_traits.h",
] ]
...@@ -171,8 +166,13 @@ component("bindings") { ...@@ -171,8 +166,13 @@ component("bindings") {
source_set("struct_traits") { source_set("struct_traits") {
sources = [ sources = [
"array_traits.h",
"enum_traits.h", "enum_traits.h",
"lib/template_util.h",
"map_traits.h",
"string_traits.h",
"struct_traits.h", "struct_traits.h",
"union_traits.h",
] ]
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_ #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_TRAITS_H_
#define 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 { namespace mojo {
// This must be specialized for any type |T| to be serialized/deserialized as // This must be specialized for any type |T| to be serialized/deserialized as
...@@ -64,7 +66,11 @@ namespace mojo { ...@@ -64,7 +66,11 @@ namespace mojo {
// }; // };
// //
template <typename T> 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 } // namespace mojo
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_ENUM_TRAITS_H_ #ifndef MOJO_PUBLIC_CPP_BINDINGS_ENUM_TRAITS_H_
#define 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 { namespace mojo {
// This must be specialized for any type |T| to be serialized/deserialized as a // This must be specialized for any type |T| to be serialized/deserialized as a
...@@ -20,7 +22,11 @@ namespace mojo { ...@@ -20,7 +22,11 @@ namespace mojo {
// }; // };
// //
template <typename MojomType, typename T> 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 } // namespace mojo
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "mojo/public/cpp/bindings/lib/array_internal.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" #include "third_party/WebKit/Source/platform/wtf/text/StringUTF8Adaptor.h"
namespace mojo { namespace mojo {
......
...@@ -114,6 +114,11 @@ struct Conditional<false, T, F> { ...@@ -114,6 +114,11 @@ struct Conditional<false, T, F> {
typedef F type; typedef F type;
}; };
template <typename T>
struct AlwaysFalse {
static const bool value = false;
};
} // namespace internal } // namespace internal
} // namespace mojo } // namespace mojo
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_H_ #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_H_
#define 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 { namespace mojo {
// This must be specialized for any type |T| to be serialized/deserialized as // This must be specialized for any type |T| to be serialized/deserialized as
...@@ -49,7 +51,11 @@ namespace mojo { ...@@ -49,7 +51,11 @@ namespace mojo {
// }; // };
// //
template <typename T> 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 } // namespace mojo
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_ #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_H_
#define 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 { namespace mojo {
...@@ -47,7 +47,11 @@ namespace mojo { ...@@ -47,7 +47,11 @@ namespace mojo {
// so that you can do any necessary cleanup. // so that you can do any necessary cleanup.
// //
template <typename T> 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 } // namespace mojo
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "mojo/public/cpp/bindings/bindings_export.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" #include "mojo/public/cpp/bindings/string_traits.h"
namespace mojo { namespace mojo {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_TRAITS_H_ #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRUCT_TRAITS_H_
#define 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 { namespace mojo {
// This must be specialized for any type |T| to be serialized/deserialized as // This must be specialized for any type |T| to be serialized/deserialized as
...@@ -158,7 +160,11 @@ namespace mojo { ...@@ -158,7 +160,11 @@ namespace mojo {
// }; // };
// //
template <typename DataViewType, typename T> 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 } // namespace mojo
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_ #ifndef MOJO_PUBLIC_CPP_BINDINGS_UNION_TRAITS_H_
#define 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 { namespace mojo {
// This must be specialized for any type |T| to be serialized/deserialized as // This must be specialized for any type |T| to be serialized/deserialized as
...@@ -32,7 +34,11 @@ namespace mojo { ...@@ -32,7 +34,11 @@ namespace mojo {
// will be called. // will be called.
// //
template <typename DataViewType, typename T> 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 } // namespace mojo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment