From e5fc0341fcb0e1514daa2d347d832d1525142b33 Mon Sep 17 00:00:00 2001 From: Hidehiko Abe Date: Fri, 23 Feb 2018 09:50:41 +0000 Subject: [PATCH 03/10] Workaround for g++7 is_trivially_copy_constructible failure. cf) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80654 Please see also crbug.com/784732#27 for details. BUG=784732 TEST=Some with GCC. Change-Id: I0a6d28d9c26ac9ed026d137e17fddbe86586f1e1 Reviewed-on: https://chromium-review.googlesource.com/927942 Commit-Queue: Hidehiko Abe Reviewed-by: danakj Cr-Commit-Position: refs/heads/master@{#538740} --- base/optional.h | 3 ++- base/template_util.h | 18 ++++++++++++++++++ base/template_util_unittest.cc | 9 +++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/base/optional.h b/base/optional.h index f6619a575815..c763acf824ee 100644 --- a/base/optional.h +++ b/base/optional.h @@ -9,6 +9,7 @@ #include #include "base/logging.h" +#include "base/template_util.h" namespace base { @@ -106,7 +107,7 @@ struct OptionalStorageBase { // compiler generated constexpr {copy,move} constructors). Note that // placement-new is prohibited in constexpr. template ::value, + bool = is_trivially_copy_constructible::value, bool = std::is_trivially_move_constructible::value> struct OptionalStorage : OptionalStorageBase { // This is no trivially {copy,move} constructible case. Other cases are diff --git a/base/template_util.h b/base/template_util.h index f76003d8237b..8544aa294597 100644 --- a/base/template_util.h +++ b/base/template_util.h @@ -10,6 +10,7 @@ #include #include #include +#include #include "build/build_config.h" @@ -127,6 +128,23 @@ template using is_trivially_copyable = std::is_trivially_copyable; #endif +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 7 +// Workaround for g++7 and earlier family. +// Due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80654, without this +// Optional> where T is non-copyable causes a compile error. +// As we know it is not trivially copy constructible, explicitly declare so. +template +struct is_trivially_copy_constructible + : std::is_trivially_copy_constructible {}; + +template +struct is_trivially_copy_constructible> : std::false_type {}; +#else +// Otherwise use std::is_trivially_copy_constructible as is. +template +using is_trivially_copy_constructible = std::is_trivially_copy_constructible; +#endif + } // namespace base #undef CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX diff --git a/base/template_util_unittest.cc b/base/template_util_unittest.cc index 12e5d362dd25..2c42445f785d 100644 --- a/base/template_util_unittest.cc +++ b/base/template_util_unittest.cc @@ -92,6 +92,15 @@ static_assert(!base::is_trivially_copyable::value, "TrivialCopyButWithDestructor should not be detected as " "trivially copyable"); +class NoCopy { + public: + NoCopy(const NoCopy&) = delete; +}; + +static_assert( + !base::is_trivially_copy_constructible>::value, + "is_trivially_copy_constructible> must be compiled."); + } // namespace } // namespace base -- 2.16.2