EricWF updated this revision to Diff 93607. EricWF added a comment. - Fix typo in `// UNSUPPORTED` directive.
https://reviews.llvm.org/D31515 Files: include/__config include/type_traits test/libcxx/utilities/meta/meta.unary/meta.unary.prop/missing_is_aggregate_trait.fail.cpp test/std/utilities/meta/meta.unary/meta.unary.prop/is_aggregate.pass.cpp www/cxx1z_status.html
Index: www/cxx1z_status.html =================================================================== --- www/cxx1z_status.html +++ www/cxx1z_status.html @@ -480,7 +480,7 @@ <tr><td><a href="http://wg21.link/LWG2904">2904</a></td><td>Make variant move-assignment more exception safe</td><td>Kona</td><td></td></tr> <tr><td><a href="http://wg21.link/LWG2905">2905</a></td><td>is_constructible_v<unique_ptr<P, D>, P, D const &> should be false when D is not copy constructible</td><td>Kona</td><td></td></tr> <tr><td><a href="http://wg21.link/LWG2908">2908</a></td><td>The less-than operator for shared pointers could do more</td><td>Kona</td><td></td></tr> - <tr><td><a href="http://wg21.link/LWG2911">2911</a></td><td>An is_aggregate type trait is needed</td><td>Kona</td><td></td></tr> + <tr><td><a href="http://wg21.link/LWG2911">2911</a></td><td>An is_aggregate type trait is needed</td><td>Kona</td><td>Complete</td></tr> <tr><td><a href="http://wg21.link/LWG2921">2921</a></td><td>packaged_task and type-erased allocators</td><td>Kona</td><td></td></tr> <tr><td><a href="http://wg21.link/LWG2934">2934</a></td><td>optional<const T> doesn't compare with T</td><td>Kona</td><td>Complete</td></tr> <!-- Index: test/std/utilities/meta/meta.unary/meta.unary.prop/is_aggregate.pass.cpp =================================================================== --- /dev/null +++ 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 + +// <type_traits> + +// template <class T> struct is_aggregate; +// template <class T> constexpr bool is_aggregate_v = is_aggregate<T>::value; + +#include <type_traits> +#include "test_macros.h" + +template <class T> +void test_true() +{ +#if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + static_assert( std::is_aggregate<T>::value, ""); + static_assert( std::is_aggregate<const T>::value, ""); + static_assert( std::is_aggregate<volatile T>::value, ""); + static_assert( std::is_aggregate<const volatile T>::value, ""); + static_assert( std::is_aggregate_v<T>, ""); + static_assert( std::is_aggregate_v<const T>, ""); + static_assert( std::is_aggregate_v<volatile T>, ""); + static_assert( std::is_aggregate_v<const volatile T>, ""); +#endif +} + +template <class T> +void test_false() +{ +#if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + static_assert(!std::is_aggregate<T>::value, ""); + static_assert(!std::is_aggregate<const T>::value, ""); + static_assert(!std::is_aggregate<volatile T>::value, ""); + static_assert(!std::is_aggregate<const volatile T>::value, ""); + static_assert(!std::is_aggregate_v<T>, ""); + static_assert(!std::is_aggregate_v<const T>, ""); + static_assert(!std::is_aggregate_v<volatile T>, ""); + static_assert(!std::is_aggregate_v<const volatile T>, ""); +#endif +} + +struct Aggregate {}; +struct HasCons { HasCons(int); }; +struct HasPriv { + void PreventUnusedPrivateMemberWarning(); +private: + int x; +}; +struct Union { int x; void* y; }; + + +int main () +{ + { + test_false<void>(); + test_false<int>(); + test_false<void*>(); + test_false<void()>(); + test_false<void() const>(); + test_false<void(Aggregate::*)(int) const>(); + test_false<Aggregate&>(); + test_false<HasCons>(); + test_false<HasPriv>(); + } + { + test_true<Aggregate>(); + test_true<Aggregate[]>(); + test_true<Aggregate[42][101]>(); + test_true<Union>(); + } +} Index: test/libcxx/utilities/meta/meta.unary/meta.unary.prop/missing_is_aggregate_trait.fail.cpp =================================================================== --- /dev/null +++ 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 + +// <type_traits> + +// template <class T> struct is_aggregate; +// template <class T> constexpr bool is_aggregate_v = is_aggregate<T>::value; + +#include <type_traits> + +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 +} Index: include/type_traits =================================================================== --- include/type_traits +++ include/type_traits @@ -97,6 +97,7 @@ template <class T> struct is_polymorphic; template <class T> struct is_abstract; template <class T> struct is_final; // C++14 + template <class T> struct is_aggregate; // C++17 template <class T, class... Args> struct is_constructible; template <class T> struct is_default_constructible; @@ -286,6 +287,8 @@ = is_abstract<T>::value; // C++17 template <class T> constexpr bool is_final_v = is_final<T>::value; // C++17 + template <class T> constexpr bool is_aggregate_v + = is_aggregate<T>::value; // C++17 template <class T> constexpr bool is_signed_v = is_signed<T>::value; // C++17 template <class T> constexpr bool is_unsigned_v @@ -1325,6 +1328,19 @@ = is_final<_Tp>::value; #endif +// is_aggregate +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + +template <class _Tp> struct _LIBCPP_TEMPLATE_VIS +is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {}; + +#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Tp> +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 Index: include/__config =================================================================== --- include/__config +++ include/__config @@ -25,8 +25,10 @@ #ifdef __GNUC__ #define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__) +#define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__) #else #define _GNUC_VER 0 +#define _GNUC_VER_NEW 0 #endif #define _LIBCPP_VERSION 5000 @@ -1047,7 +1049,7 @@ #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) @@ -1083,6 +1085,10 @@ # 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits