diff --git a/include/__config b/include/__config index b9d47ac39..6f5fc3c6c 100644 --- a/include/__config +++ b/include/__config @@ -25,8 +25,12 @@ #ifdef __GNUC__ #define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__) +// The _GNUC_VER_NEW macro better represents the new GCC versioning scheme +// introduced in GCC 5.0. +#define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__) #else #define _GNUC_VER 0 +#define _GNUC_VER_NEW 0 #endif #define _LIBCPP_VERSION 5000 @@ -1061,7 +1065,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( #endif #if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700 -#define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF +# define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF #endif #if !defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) @@ -1097,6 +1101,10 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( # define _LIBCPP_HAS_NO_DEDUCTION_GUIDES #endif +#if !__has_keyword(__is_aggregate) && (_GNUC_VER_NEW < 7001) +# define _LIBCPP_HAS_NO_IS_AGGREGATE +#endif + #endif // __cplusplus #endif // _LIBCPP_CONFIG diff --git a/include/type_traits b/include/type_traits index c0922392a..9db4d6614 100644 --- a/include/type_traits +++ b/include/type_traits @@ -97,6 +97,7 @@ namespace std template struct is_polymorphic; template struct is_abstract; template struct is_final; // C++14 + template struct is_aggregate; // C++17 template struct is_constructible; template struct is_default_constructible; @@ -286,6 +287,8 @@ namespace std = is_abstract::value; // C++17 template constexpr bool is_final_v = is_final::value; // C++17 + template constexpr bool is_aggregate_v + = is_aggregate::value; // C++17 template constexpr bool is_signed_v = is_signed::value; // C++17 template constexpr bool is_unsigned_v @@ -1336,6 +1339,19 @@ template _LIBCPP_CONSTEXPR bool is_final_v = is_final<_Tp>::value; #endif +// is_aggregate +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + +template struct _LIBCPP_TEMPLATE_VIS +is_aggregate : public integral_constant {}; + +#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template +constexpr bool is_aggregate_v = is_aggregate<_Tp>::value; +#endif + +#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + // is_base_of #ifdef _LIBCPP_HAS_IS_BASE_OF diff --git a/test/libcxx/utilities/meta/meta.unary/meta.unary.prop/missing_is_aggregate_trait.fail.cpp b/test/libcxx/utilities/meta/meta.unary/meta.unary.prop/missing_is_aggregate_trait.fail.cpp new file mode 100644 index 000000000..e3e083bfb --- /dev/null +++ b/test/libcxx/utilities/meta/meta.unary/meta.unary.prop/missing_is_aggregate_trait.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template struct is_aggregate; +// template constexpr bool is_aggregate_v = is_aggregate::value; + +#include + +int main () +{ +#ifdef _LIBCPP_HAS_NO_IS_AGGREGATE + // This should not compile when _LIBCPP_HAS_NO_IS_AGGREGATE is defined. + bool b = __is_aggregate(void); + ((void)b); +#else +#error Forcing failure... +#endif +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_aggregate.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_aggregate.pass.cpp new file mode 100644 index 000000000..9c72d4d44 --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_aggregate.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// + +// template struct is_aggregate; +// template constexpr bool is_aggregate_v = is_aggregate::value; + +#include +#include "test_macros.h" + +template +void test_true() +{ +#if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + static_assert( std::is_aggregate::value, ""); + static_assert( std::is_aggregate::value, ""); + static_assert( std::is_aggregate::value, ""); + static_assert( std::is_aggregate::value, ""); + static_assert( std::is_aggregate_v, ""); + static_assert( std::is_aggregate_v, ""); + static_assert( std::is_aggregate_v, ""); + static_assert( std::is_aggregate_v, ""); +#endif +} + +template +void test_false() +{ +#if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + static_assert(!std::is_aggregate::value, ""); + static_assert(!std::is_aggregate::value, ""); + static_assert(!std::is_aggregate::value, ""); + static_assert(!std::is_aggregate::value, ""); + static_assert(!std::is_aggregate_v, ""); + static_assert(!std::is_aggregate_v, ""); + static_assert(!std::is_aggregate_v, ""); + static_assert(!std::is_aggregate_v, ""); +#endif +} + +struct Aggregate {}; +struct HasCons { HasCons(int); }; +struct HasPriv { + void PreventUnusedPrivateMemberWarning(); +private: + int x; +}; +struct Union { int x; void* y; }; + + +int main () +{ + { + test_false(); + test_false(); + test_false(); + test_false(); + test_false(); + test_false(); + test_false(); + test_false(); + test_false(); + } + { + test_true(); + test_true(); + test_true(); + test_true(); + } +} diff --git a/www/cxx1z_status.html b/www/cxx1z_status.html index 1dc51743b..36c225085 100644 --- a/www/cxx1z_status.html +++ b/www/cxx1z_status.html @@ -480,7 +480,7 @@ 2904Make variant move-assignment more exception safeKona 2905is_constructible_v<unique_ptr<P, D>, P, D const &> should be false when D is not copy constructibleKona 2908The less-than operator for shared pointers could do moreKona - 2911An is_aggregate type trait is neededKona + 2911An is_aggregate type trait is neededKonaComplete 2921packaged_task and type-erased allocatorsKona 2934optional<const T> doesn't compare with TKonaComplete