diff options
Diffstat (limited to 'chromium/base/check_op.h')
-rw-r--r-- | chromium/base/check_op.h | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/chromium/base/check_op.h b/chromium/base/check_op.h index 4816df4e8b0..1acfa614e95 100644 --- a/chromium/base/check_op.h +++ b/chromium/base/check_op.h @@ -48,8 +48,10 @@ BASE_EXPORT char* StreamValToStr(const void* v, void (*stream_func)(std::ostream&, const void*)); -#ifndef __has_builtin -#define __has_builtin(x) 0 // Compatibility with non-clang compilers. +#ifdef __has_builtin +#define SUPPORTS_BUILTIN_ADDRESSOF (__has_builtin(__builtin_addressof)) +#else +#define SUPPORTS_BUILTIN_ADDRESSOF 0 #endif template <typename T> @@ -65,7 +67,7 @@ CheckOpValueStr(const T& v) { // operator& might be overloaded, so do the std::addressof dance. // __builtin_addressof is preferred since it also handles Obj-C ARC pointers. // Some casting is still needed, because T might be volatile. -#if __has_builtin(__builtin_addressof) +#if SUPPORTS_BUILTIN_ADDRESSOF const void* vp = const_cast<const void*>( reinterpret_cast<const volatile void*>(__builtin_addressof(v))); #else @@ -75,6 +77,8 @@ CheckOpValueStr(const T& v) { return StreamValToStr(vp, f); } +#undef SUPPORTS_BUILTIN_ADDRESSOF + // Overload for types that have no operator<< but do have .ToString() defined. template <typename T> inline typename std::enable_if< @@ -115,7 +119,7 @@ CheckOpValueStr(const T& v) { class CheckOpResult { public: // An empty result signals success. - constexpr CheckOpResult() = default; + constexpr CheckOpResult() {} // A non-success result. expr_str is something like "foo != bar". v1_str and // v2_str are the stringified run-time values of foo and bar. Takes ownership @@ -157,9 +161,13 @@ class CheckOpResult { #endif -// The int-int overload avoids address-taking static int members. +// The second overload avoids address-taking of static members for +// fundamental types. #define DEFINE_CHECK_OP_IMPL(name, op) \ - template <typename T, typename U> \ + template <typename T, typename U, \ + std::enable_if_t<!std::is_fundamental<T>::value || \ + !std::is_fundamental<U>::value, \ + int> = 0> \ constexpr ::logging::CheckOpResult Check##name##Impl( \ const T& v1, const U& v2, const char* expr_str) { \ if (ANALYZER_ASSUME_TRUE(v1 op v2)) \ @@ -167,7 +175,11 @@ class CheckOpResult { return ::logging::CheckOpResult(expr_str, CheckOpValueStr(v1), \ CheckOpValueStr(v2)); \ } \ - constexpr ::logging::CheckOpResult Check##name##Impl(int v1, int v2, \ + template <typename T, typename U, \ + std::enable_if_t<std::is_fundamental<T>::value && \ + std::is_fundamental<U>::value, \ + int> = 0> \ + constexpr ::logging::CheckOpResult Check##name##Impl(T v1, U v2, \ const char* expr_str) { \ if (ANALYZER_ASSUME_TRUE(v1 op v2)) \ return ::logging::CheckOpResult(); \ |