diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-24 07:38:34 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-24 07:38:34 +0000 |
commit | 4ca8ac2e61c37ddadf37024af86f3e1019af8532 (patch) | |
tree | eaded653632e9c6319917df7f2fa190fb5cf1751 /test/SemaCXX/type-traits.cpp | |
parent | 59950d3aa54ca5066b1fb08a8c79ebfe10e0919b (diff) |
Implement a new type trait __is_trivially_constructible(T, Args...)
that provides the behavior of the C++11 library trait
std::is_trivially_constructible<T, Args...>, which can't be
implemented purely as a library.
Since __is_trivially_constructible can have zero or more arguments, I
needed to add Yet Another Type Trait Expression Class, this one
handling arbitrary arguments. The next step will be to migrate
UnaryTypeTrait and BinaryTypeTrait over to this new, more general
TypeTrait class.
Fixes the Clang side of <rdar://problem/10895483> / PR12038.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@151352 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/type-traits.cpp')
-rw-r--r-- | test/SemaCXX/type-traits.cpp | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp index 50c135d0b7..fd41c17ab2 100644 --- a/test/SemaCXX/type-traits.cpp +++ b/test/SemaCXX/type-traits.cpp @@ -47,6 +47,10 @@ struct TrivialMoveButNotCopy { TrivialMoveButNotCopy &operator=(TrivialMoveButNotCopy&&) = default; TrivialMoveButNotCopy &operator=(const TrivialMoveButNotCopy&); }; +struct NonTrivialDefault { + NonTrivialDefault(); +}; + struct HasDest { ~HasDest(); }; class HasPriv { int priv; }; class HasProt { protected: int prot; }; @@ -104,6 +108,10 @@ class AllPrivate { ~AllPrivate() throw(); }; +struct ThreeArgCtor { + ThreeArgCtor(int*, char*, int); +}; + void is_pod() { { int arr[T(__is_pod(int))]; } @@ -1602,7 +1610,7 @@ void is_trivial() { int arr[F(__is_trivial(cvoid))]; } } -void is_trivially_copyable() +void trivial_checks() { { int arr[T(__is_trivially_copyable(int))]; } { int arr[T(__is_trivially_copyable(Enum))]; } @@ -1646,6 +1654,25 @@ void is_trivially_copyable() { int arr[F(__is_trivially_copyable(void))]; } { int arr[F(__is_trivially_copyable(cvoid))]; } + { int arr[T((__is_trivially_constructible(int)))]; } + { int arr[T((__is_trivially_constructible(int, int)))]; } + { int arr[T((__is_trivially_constructible(int, float)))]; } + { int arr[T((__is_trivially_constructible(int, int&)))]; } + { int arr[T((__is_trivially_constructible(int, const int&)))]; } + { int arr[T((__is_trivially_constructible(int, int)))]; } + { int arr[T((__is_trivially_constructible(HasCopyAssign, HasCopyAssign)))]; } + { int arr[T((__is_trivially_constructible(HasCopyAssign, const HasCopyAssign&)))]; } + { int arr[T((__is_trivially_constructible(HasCopyAssign, HasCopyAssign&&)))]; } + { int arr[T((__is_trivially_constructible(HasCopyAssign)))]; } + { int arr[T((__is_trivially_constructible(NonTrivialDefault, + const NonTrivialDefault&)))]; } + { int arr[T((__is_trivially_constructible(NonTrivialDefault, + NonTrivialDefault&&)))]; } + + { int arr[F((__is_trivially_constructible(int, int*)))]; } + { int arr[F((__is_trivially_constructible(NonTrivialDefault)))]; } + { int arr[F((__is_trivially_constructible(ThreeArgCtor, int*, char*, int&)))]; } + { int arr[T((__is_trivially_assignable(int&, int)))]; } { int arr[T((__is_trivially_assignable(int&, int&)))]; } { int arr[T((__is_trivially_assignable(int&, int&&)))]; } @@ -1680,6 +1707,33 @@ void is_trivially_copyable() TrivialMoveButNotCopy&&)))]; } } +// Instantiation of __is_trivially_constructible +template<typename T, typename ...Args> +struct is_trivially_constructible { + static const bool value = __is_trivially_constructible(T, Args...); +}; + +void is_trivially_constructible_test() { + { int arr[T((is_trivially_constructible<int>::value))]; } + { int arr[T((is_trivially_constructible<int, int>::value))]; } + { int arr[T((is_trivially_constructible<int, float>::value))]; } + { int arr[T((is_trivially_constructible<int, int&>::value))]; } + { int arr[T((is_trivially_constructible<int, const int&>::value))]; } + { int arr[T((is_trivially_constructible<int, int>::value))]; } + { int arr[T((is_trivially_constructible<HasCopyAssign, HasCopyAssign>::value))]; } + { int arr[T((is_trivially_constructible<HasCopyAssign, const HasCopyAssign&>::value))]; } + { int arr[T((is_trivially_constructible<HasCopyAssign, HasCopyAssign&&>::value))]; } + { int arr[T((is_trivially_constructible<HasCopyAssign>::value))]; } + { int arr[T((is_trivially_constructible<NonTrivialDefault, + const NonTrivialDefault&>::value))]; } + { int arr[T((is_trivially_constructible<NonTrivialDefault, + NonTrivialDefault&&>::value))]; } + + { int arr[F((is_trivially_constructible<int, int*>::value))]; } + { int arr[F((is_trivially_constructible<NonTrivialDefault>::value))]; } + { int arr[F((is_trivially_constructible<ThreeArgCtor, int*, char*, int&>::value))]; } +} + void array_rank() { int t01[T(__array_rank(IntAr) == 1)]; int t02[T(__array_rank(ConstIntArAr) == 2)]; |