summaryrefslogtreecommitdiffstats
path: root/test/SemaCXX/type-traits.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/type-traits.cpp')
-rw-r--r--test/SemaCXX/type-traits.cpp166
1 files changed, 163 insertions, 3 deletions
diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp
index b05dd07..ff9a6bf 100644
--- a/test/SemaCXX/type-traits.cpp
+++ b/test/SemaCXX/type-traits.cpp
@@ -11,6 +11,7 @@ struct Empty {};
typedef Empty EmptyAr[10];
typedef int Int;
typedef Int IntAr[10];
+typedef Int IntArNB[];
class Statics { static int priv; static NonPOD np; };
union EmptyUnion {};
union Union { int i; float f; };
@@ -19,7 +20,15 @@ struct HasOp { void operator *(); };
struct HasConv { operator int(); };
struct HasAssign { void operator =(int); };
+struct HasAnonymousUnion {
+ union {
+ int i;
+ float f;
+ };
+};
+
// Not PODs
+typedef const void cvoid;
struct Derives : POD {};
struct DerivesEmpty : Empty {};
struct HasCons { HasCons(int); };
@@ -32,6 +41,7 @@ struct HasNonPOD { NonPOD np; };
struct HasVirt { virtual void Virt() {}; };
typedef Derives NonPODAr[10];
typedef HasVirt VirtAr[10];
+typedef HasCons NonPODArNB[];
union NonPODUnion { int i; Derives n; };
struct HasNoThrowCopyAssign {
@@ -80,6 +90,8 @@ void is_pod()
int t11[T(__is_pod(HasOp))];
int t12[T(__is_pod(HasConv))];
int t13[T(__is_pod(HasAssign))];
+ int t14[T(__is_pod(IntArNB))];
+ int t15[T(__is_pod(HasAnonymousUnion))];
int t21[F(__is_pod(Derives))];
int t22[F(__is_pod(HasCons))];
@@ -92,6 +104,9 @@ void is_pod()
int t29[F(__is_pod(HasVirt))];
int t30[F(__is_pod(NonPODAr))];
int t31[F(__is_pod(DerivesEmpty))];
+ int t32[F(__is_pod(void))];
+ int t33[F(__is_pod(cvoid))];
+ int t34[F(__is_pod(NonPODArNB))];
// int t32[F(__is_pod(NonPODUnion))];
}
@@ -122,6 +137,9 @@ void is_empty()
int t25[F(__is_empty(HasRef))];
int t26[F(__is_empty(HasVirt))];
int t27[F(__is_empty(BitOnly))];
+ int t28[F(__is_empty(void))];
+ int t29[F(__is_empty(IntArNB))];
+ int t30[F(__is_empty(HasAnonymousUnion))];
// int t27[F(__is_empty(DerivesVirt))];
}
@@ -132,6 +150,7 @@ void is_class()
int t01[T(__is_class(Derives))];
int t02[T(__is_class(HasPriv))];
int t03[T(__is_class(ClassType))];
+ int t04[T(__is_class(HasAnonymousUnion))];
int t11[F(__is_class(int))];
int t12[F(__is_class(Enum))];
@@ -139,6 +158,8 @@ void is_class()
int t14[F(__is_class(IntAr))];
int t15[F(__is_class(NonPODAr))];
int t16[F(__is_class(Union))];
+ int t17[F(__is_class(cvoid))];
+ int t18[F(__is_class(IntArNB))];
}
typedef Union UnionAr[10];
@@ -154,6 +175,9 @@ void is_union()
int t13[F(__is_union(Int))];
int t14[F(__is_union(IntAr))];
int t15[F(__is_union(UnionAr))];
+ int t16[F(__is_union(cvoid))];
+ int t17[F(__is_union(IntArNB))];
+ int t18[F(__is_union(HasAnonymousUnion))];
}
typedef Enum EnumType;
@@ -170,6 +194,9 @@ void is_enum()
int t15[F(__is_enum(UnionAr))];
int t16[F(__is_enum(Derives))];
int t17[F(__is_enum(ClassType))];
+ int t18[F(__is_enum(cvoid))];
+ int t19[F(__is_enum(IntArNB))];
+ int t20[F(__is_enum(HasAnonymousUnion))];
}
typedef HasVirt Polymorph;
@@ -188,6 +215,8 @@ void is_polymorphic()
int t16[F(__is_polymorphic(Derives))];
int t17[F(__is_polymorphic(ClassType))];
int t18[F(__is_polymorphic(Enum))];
+ int t19[F(__is_polymorphic(cvoid))];
+ int t20[F(__is_polymorphic(IntArNB))];
}
typedef Int& IntRef;
@@ -198,6 +227,13 @@ struct HasCopy {
HasCopy(HasCopy& cp);
};
+struct HasTemplateCons {
+ HasVirt Annoying;
+
+ template <typename T>
+ HasTemplateCons(const T&);
+};
+
void has_trivial_default_constructor() {
int t01[T(__has_trivial_constructor(Int))];
int t02[T(__has_trivial_constructor(IntAr))];
@@ -217,6 +253,9 @@ void has_trivial_default_constructor() {
int t16[T(__has_trivial_constructor(const Int))];
int t17[T(__has_trivial_constructor(NonPODAr))];
int t18[F(__has_trivial_constructor(VirtAr))];
+ int t19[F(__has_trivial_constructor(void))];
+ int t20[F(__has_trivial_constructor(cvoid))];
+ int t21[F(__has_trivial_constructor(HasTemplateCons))];
}
void has_trivial_copy_constructor() {
@@ -238,6 +277,9 @@ void has_trivial_copy_constructor() {
int t16[T(__has_trivial_copy(const Int))];
int t17[F(__has_trivial_copy(NonPODAr))];
int t18[F(__has_trivial_copy(VirtAr))];
+ int t19[F(__has_trivial_copy(void))];
+ int t20[F(__has_trivial_copy(cvoid))];
+ int t21[F(__has_trivial_copy(HasTemplateCons))];
}
void has_trivial_copy_assignment() {
@@ -259,6 +301,8 @@ void has_trivial_copy_assignment() {
int t16[F(__has_trivial_assign(const Int))];
int t17[F(__has_trivial_assign(NonPODAr))];
int t18[F(__has_trivial_assign(VirtAr))];
+ int t19[F(__has_trivial_assign(void))];
+ int t20[F(__has_trivial_assign(cvoid))];
}
void has_trivial_destructor() {
@@ -280,14 +324,16 @@ void has_trivial_destructor() {
int t16[T(__has_trivial_destructor(const Int))];
int t17[T(__has_trivial_destructor(NonPODAr))];
int t18[T(__has_trivial_destructor(VirtAr))];
+ int t19[F(__has_trivial_destructor(void))];
+ int t20[F(__has_trivial_destructor(cvoid))];
}
struct A { ~A() {} };
template<typename> struct B : A { };
void f() {
- int t01[T(!__has_trivial_destructor(A))];
- int t02[T(!__has_trivial_destructor(B<int>))];
+ int t01[F(__has_trivial_destructor(A))];
+ int t02[F(__has_trivial_destructor(B<int>))];
}
void has_nothrow_assign() {
@@ -309,10 +355,12 @@ void has_nothrow_assign() {
int t16[F(__has_nothrow_assign(const Int))];
int t17[F(__has_nothrow_assign(NonPODAr))];
int t18[F(__has_nothrow_assign(VirtAr))];
-
int t19[T(__has_nothrow_assign(HasNoThrowCopyAssign))];
int t20[F(__has_nothrow_assign(HasMultipleCopyAssign))];
int t21[T(__has_nothrow_assign(HasMultipleNoThrowCopyAssign))];
+ int t22[F(__has_nothrow_assign(void))];
+ int t23[F(__has_nothrow_assign(cvoid))];
+ int t24[T(__has_nothrow_assign(HasVirtDest))];
}
void has_nothrow_copy() {
@@ -338,6 +386,10 @@ void has_nothrow_copy() {
int t19[T(__has_nothrow_copy(HasNoThrowCopy))];
int t20[F(__has_nothrow_copy(HasMultipleCopy))];
int t21[T(__has_nothrow_copy(HasMultipleNoThrowCopy))];
+ int t22[F(__has_nothrow_copy(void))];
+ int t23[F(__has_nothrow_copy(cvoid))];
+ int t24[T(__has_nothrow_copy(HasVirtDest))];
+ int t25[T(__has_nothrow_copy(HasTemplateCons))];
}
void has_nothrow_constructor() {
@@ -362,6 +414,10 @@ void has_nothrow_constructor() {
int t19[T(__has_nothrow_constructor(HasNoThrowConstructor))];
int t20[F(__has_nothrow_constructor(HasNoThrowConstructorWithArgs))];
+ int t21[F(__has_nothrow_constructor(void))];
+ int t22[F(__has_nothrow_constructor(cvoid))];
+ int t23[T(__has_nothrow_constructor(HasVirtDest))];
+ int t24[F(__has_nothrow_constructor(HasTemplateCons))];
}
void has_virtual_destructor() {
@@ -387,4 +443,108 @@ void has_virtual_destructor() {
int t19[T(__has_virtual_destructor(HasVirtDest))];
int t20[T(__has_virtual_destructor(DerivedVirtDest))];
int t21[F(__has_virtual_destructor(VirtDestAr))];
+ int t22[F(__has_virtual_destructor(void))];
+ int t23[F(__has_virtual_destructor(cvoid))];
+}
+
+
+class Base {};
+class Derived : Base {};
+class Derived2a : Derived {};
+class Derived2b : Derived {};
+class Derived3 : virtual Derived2a, virtual Derived2b {};
+template<typename T> struct BaseA { T a; };
+template<typename T> struct DerivedB : BaseA<T> { };
+template<typename T> struct CrazyDerived : T { };
+
+
+class class_forward; // expected-note {{forward declaration of 'class_forward'}}
+
+template <typename Base, typename Derived>
+void isBaseOfT() {
+ int t[T(__is_base_of(Base, Derived))];
+};
+template <typename Base, typename Derived>
+void isBaseOfF() {
+ int t[F(__is_base_of(Base, Derived))];
+};
+
+template <class T> class DerivedTemp : Base {};
+template <class T> class NonderivedTemp {};
+template <class T> class UndefinedTemp; // expected-note {{declared here}}
+
+void is_base_of() {
+ int t01[T(__is_base_of(Base, Derived))];
+ int t02[T(__is_base_of(const Base, Derived))];
+ int t03[F(__is_base_of(Derived, Base))];
+ int t04[F(__is_base_of(Derived, int))];
+ int t05[T(__is_base_of(Base, Base))];
+ int t06[T(__is_base_of(Base, Derived3))];
+ int t07[T(__is_base_of(Derived, Derived3))];
+ int t08[T(__is_base_of(Derived2b, Derived3))];
+ int t09[T(__is_base_of(Derived2a, Derived3))];
+ int t10[T(__is_base_of(BaseA<int>, DerivedB<int>))];
+ int t11[F(__is_base_of(DerivedB<int>, BaseA<int>))];
+ int t12[T(__is_base_of(Base, CrazyDerived<Base>))];
+ int t13[F(__is_base_of(Union, Union))];
+ int t14[T(__is_base_of(Empty, Empty))];
+ int t15[T(__is_base_of(class_forward, class_forward))];
+ int t16[F(__is_base_of(Empty, class_forward))]; // expected-error {{incomplete type 'class_forward' used in type trait expression}}
+ int t17[F(__is_base_of(Base&, Derived&))];
+ int t18[F(__is_base_of(Base[10], Derived[10]))];
+ int t19[F(__is_base_of(int, int))];
+ int t20[F(__is_base_of(long, int))];
+ int t21[T(__is_base_of(Base, DerivedTemp<int>))];
+ int t22[F(__is_base_of(Base, NonderivedTemp<int>))];
+ int t23[F(__is_base_of(Base, UndefinedTemp<int>))]; // expected-error {{implicit instantiation of undefined template 'UndefinedTemp<int>'}}
+
+ isBaseOfT<Base, Derived>();
+ isBaseOfF<Derived, Base>();
+
+ isBaseOfT<Base, CrazyDerived<Base> >();
+ isBaseOfF<CrazyDerived<Base>, Base>();
+
+ isBaseOfT<BaseA<int>, DerivedB<int> >();
+ isBaseOfF<DerivedB<int>, BaseA<int> >();
+}
+
+struct FromInt { FromInt(int); };
+struct ToInt { operator int(); };
+typedef void Function();
+
+void is_convertible_to();
+class PrivateCopy {
+ PrivateCopy(const PrivateCopy&);
+ friend void is_convertible_to();
+};
+
+template<typename T>
+struct X0 {
+ template<typename U> X0(const X0<U>&);
+};
+
+void is_convertible_to() {
+ int t01[T(__is_convertible_to(Int, Int))];
+ int t02[F(__is_convertible_to(Int, IntAr))];
+ int t03[F(__is_convertible_to(IntAr, IntAr))];
+ int t04[T(__is_convertible_to(void, void))];
+ int t05[T(__is_convertible_to(cvoid, void))];
+ int t06[T(__is_convertible_to(void, cvoid))];
+ int t07[T(__is_convertible_to(cvoid, cvoid))];
+ int t08[T(__is_convertible_to(int, FromInt))];
+ int t09[T(__is_convertible_to(long, FromInt))];
+ int t10[T(__is_convertible_to(double, FromInt))];
+ int t11[T(__is_convertible_to(const int, FromInt))];
+ int t12[T(__is_convertible_to(const int&, FromInt))];
+ int t13[T(__is_convertible_to(ToInt, int))];
+ int t14[T(__is_convertible_to(ToInt, const int&))];
+ int t15[T(__is_convertible_to(ToInt, long))];
+ int t16[F(__is_convertible_to(ToInt, int&))];
+ int t17[F(__is_convertible_to(ToInt, FromInt))];
+ int t18[T(__is_convertible_to(IntAr&, IntAr&))];
+ int t19[T(__is_convertible_to(IntAr&, const IntAr&))];
+ int t20[F(__is_convertible_to(const IntAr&, IntAr&))];
+ int t21[F(__is_convertible_to(Function, Function))];
+ int t22[F(__is_convertible_to(PrivateCopy, PrivateCopy))];
+ int t23[T(__is_convertible_to(X0<int>, X0<float>))];
}
OpenPOWER on IntegriCloud