diff options
Diffstat (limited to 'test/SemaCXX')
36 files changed, 448 insertions, 53 deletions
diff --git a/test/SemaCXX/array-bound-merge.cpp b/test/SemaCXX/array-bound-merge.cpp new file mode 100644 index 0000000..579c793 --- /dev/null +++ b/test/SemaCXX/array-bound-merge.cpp @@ -0,0 +1,9 @@ +// RUN: clang-cc -fsyntax-only -verify %s +// PR5515 + +extern int a[]; +int a[10]; +extern int b[10]; +int b[]; +extern int c[1]; +int c[] = {1,2}; // expected-error {{excess elements in array initializer}} diff --git a/test/SemaCXX/attr-cxx0x.cpp b/test/SemaCXX/attr-cxx0x.cpp index da52d33..d68779c 100644 --- a/test/SemaCXX/attr-cxx0x.cpp +++ b/test/SemaCXX/attr-cxx0x.cpp @@ -2,7 +2,7 @@ int final_fail [[final]]; //expected-error {{'final' attribute only applies to virtual method or class types}} -struct [[final]] final_base { }; // expected-note {{struct final_base declared here}} +struct [[final]] final_base { }; // expected-note {{'struct final_base' declared here}} struct final_child : final_base { }; // expected-error {{derivation from 'final' struct final_base}} struct final_member { virtual void quux [[final]] (); }; // expected-note {{overridden virtual function is here}} @@ -33,4 +33,4 @@ struct base { }; struct [[base_check, base_check]] bc : base { // expected-error {{'base_check' attribute cannot be repeated}} -};
\ No newline at end of file +}; diff --git a/test/SemaCXX/attr-noreturn.cpp b/test/SemaCXX/attr-noreturn.cpp new file mode 100644 index 0000000..e4fdc08 --- /dev/null +++ b/test/SemaCXX/attr-noreturn.cpp @@ -0,0 +1,30 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +// PR5620 +void f0() __attribute__((__noreturn__)); +void f1(void (*)()); +void f2() { f1(f0); } + +// Taking the address of a noreturn function +void test_f0a() { + void (*fp)() = f0; + void (*fp1)() __attribute__((noreturn)) = f0; +} + +// Taking the address of an overloaded noreturn function +void f0(int) __attribute__((__noreturn__)); + +void test_f0b() { + void (*fp)() = f0; + void (*fp1)() __attribute__((noreturn)) = f0; +} + +// No-returned function pointers +typedef void (* noreturn_fp)() __attribute__((noreturn)); + +void f3(noreturn_fp); // expected-note{{candidate function}} + +void test_f3() { + f3(f0); // okay + f3(f2); // expected-error{{no matching function for call}} +} diff --git a/test/SemaCXX/compare.cpp b/test/SemaCXX/compare.cpp index e38b6b3..7188678 100644 --- a/test/SemaCXX/compare.cpp +++ b/test/SemaCXX/compare.cpp @@ -49,8 +49,8 @@ int test0(long a, unsigned long b) { ((signed char) A == (unsigned char) b) + (A < (unsigned long) b) + (A < (unsigned int) b) + - (A < (unsigned short) b) + // expected-warning {{comparison of integers of different signs}} - (A < (unsigned char) b) + // expected-warning {{comparison of integers of different signs}} + (A < (unsigned short) b) + + (A < (unsigned char) b) + ((long) A < b) + ((int) A < b) + ((short) A < b) + @@ -78,9 +78,9 @@ int test0(long a, unsigned long b) { (a < (unsigned short) B) + (a < (unsigned char) B) + ((long) a < B) + - ((int) a < B) + // expected-warning {{comparison of integers of different signs}} - ((short) a < B) + // expected-warning {{comparison of integers of different signs}} - ((signed char) a < B) + // expected-warning {{comparison of integers of different signs}} + ((int) a < B) + + ((short) a < B) + + ((signed char) a < B) + ((long) a < (unsigned long) B) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) B) + // expected-warning {{comparison of integers of different signs}} ((short) a < (unsigned short) B) + // expected-warning {{comparison of integers of different signs}} @@ -101,8 +101,8 @@ int test0(long a, unsigned long b) { ((signed char) C == (unsigned char) b) + (C < (unsigned long) b) + (C < (unsigned int) b) + - (C < (unsigned short) b) + // expected-warning {{comparison of integers of different signs}} - (C < (unsigned char) b) + // expected-warning {{comparison of integers of different signs}} + (C < (unsigned short) b) + + (C < (unsigned char) b) + ((long) C < b) + ((int) C < b) + ((short) C < b) + @@ -130,9 +130,9 @@ int test0(long a, unsigned long b) { (a < (unsigned short) C) + (a < (unsigned char) C) + ((long) a < C) + - ((int) a < C) + // expected-warning {{comparison of integers of different signs}} - ((short) a < C) + // expected-warning {{comparison of integers of different signs}} - ((signed char) a < C) + // expected-warning {{comparison of integers of different signs}} + ((int) a < C) + + ((short) a < C) + + ((signed char) a < C) + ((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}} ((short) a < (unsigned short) C) + // expected-warning {{comparison of integers of different signs}} @@ -193,3 +193,8 @@ int test0(long a, unsigned long b) { 10 ; } + +int test1(int i) { + enum en { zero }; + return i > zero; +} diff --git a/test/SemaCXX/convert-to-bool.cpp b/test/SemaCXX/convert-to-bool.cpp index 937b272..277bfc6 100644 --- a/test/SemaCXX/convert-to-bool.cpp +++ b/test/SemaCXX/convert-to-bool.cpp @@ -49,7 +49,7 @@ void test_explicit_bool(ExplicitConvToBool ecb) { } void test_explicit_conv_to_ref(ExplicitConvToRef ecr) { - int& i1 = ecr; // expected-error{{non-const lvalue reference to type 'int' cannot be initialized with a value of type 'struct ExplicitConvToRef'}} + int& i1 = ecr; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a value of unrelated type 'struct ExplicitConvToRef'}} int& i2(ecr); // okay } @@ -57,11 +57,11 @@ struct A { }; struct B { }; struct C { explicit operator A&(); // expected-warning{{explicit conversion functions are a C++0x extension}} - operator B&(); + operator B&(); // expected-note{{candidate}} }; void test_copy_init_conversions(C c) { - A &a = c; // expected-error{{non-const lvalue reference to type 'struct A' cannot be initialized with a value of type 'struct C'}} + A &a = c; // expected-error{{no viable conversion from 'struct C' to 'struct A'}} B &b = b; // okay } diff --git a/test/SemaCXX/decl-init-ref.cpp b/test/SemaCXX/decl-init-ref.cpp index d7db647..20eb91a 100644 --- a/test/SemaCXX/decl-init-ref.cpp +++ b/test/SemaCXX/decl-init-ref.cpp @@ -1,6 +1,6 @@ // RUN: clang-cc -fsyntax-only -verify -std=c++0x %s -struct A {}; +struct A {}; // expected-note {{candidate function}} struct BASE { operator A(); // expected-note {{candidate function}} @@ -21,6 +21,6 @@ extern B f(); const int& ri = (void)0; // expected-error {{invalid initialization of reference of type 'int const &' from expression of type 'void'}} int main() { - const A& rca = f(); // expected-error {{rvalue reference cannot bind to lvalue due to multiple conversion functions}} - A& ra = f(); // expected-error {{non-const lvalue reference to type 'struct A' cannot be initialized with a temporary of type 'class B'}} + const A& rca = f(); // expected-error {{conversion from 'class B' to 'struct A const' is ambiguous}} + A& ra = f(); // expected-error {{non-const lvalue reference to type 'struct A' cannot bind to a temporary of type 'class B'}} } diff --git a/test/SemaCXX/default-assignment-operator.cpp b/test/SemaCXX/default-assignment-operator.cpp index e627fef..0377657 100644 --- a/test/SemaCXX/default-assignment-operator.cpp +++ b/test/SemaCXX/default-assignment-operator.cpp @@ -1,7 +1,6 @@ // RUN: clang-cc -fsyntax-only -verify %s -class Base { // expected-error {{cannot define the implicit default assignment operator for 'class Base'}} \ - // expected-note {{synthesized method is first required here}} +class Base { // expected-error {{cannot define the implicit default assignment operator for 'class Base'}} int &ref; // expected-note {{declared at}} }; @@ -26,7 +25,7 @@ Z z2; // Test1 void f(X x, const X cx) { - x = cx; // expected-note {{synthesized method is first required here}} + x = cx; // expected-note 2 {{synthesized method is first required here}} x = cx; z1 = z2; } diff --git a/test/SemaCXX/enum.cpp b/test/SemaCXX/enum.cpp index db25681..3315de0 100644 --- a/test/SemaCXX/enum.cpp +++ b/test/SemaCXX/enum.cpp @@ -1,4 +1,5 @@ // RUN: clang-cc -fsyntax-only -verify %s + enum E { Val1, Val2 @@ -25,13 +26,42 @@ void bar() { /// PR3688 struct s1 { - enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}} expected-note{{forward declaration of 'enum s1::e1'}} + enum e1 (*bar)(void); // expected-error{{ISO C++ forbids forward references to 'enum' types}} }; enum e1 { YES, NO }; static enum e1 badfunc(struct s1 *q) { - return q->bar(); // expected-error{{calling function with incomplete return type 'enum s1::e1'}} + return q->bar(); } enum e2; // expected-error{{ISO C++ forbids forward references to 'enum' types}} + +namespace test1 { + template <class A, class B> struct is_same { static const int value = -1; }; + template <class A> struct is_same<A,A> { static const int value = 1; }; + + enum enum0 { v0 }; + int test0[is_same<typeof(+v0), int>::value]; + + enum enum1 { v1 = __INT_MAX__ }; + int test1[is_same<typeof(+v1), int>::value]; + + enum enum2 { v2 = __INT_MAX__ * 2U }; + int test2[is_same<typeof(+v2), unsigned int>::value]; + + // This kindof assumes that 'int' is smaller than 'long long'. +#if defined(__LP64__) + enum enum3 { v3 = __LONG_LONG_MAX__ }; + int test3[is_same<typeof(+v3), long>::value]; + + enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL }; + int test4[is_same<typeof(+v4), unsigned long>::value]; +#else + enum enum3 { v3 = __LONG_LONG_MAX__ }; + int test3[is_same<typeof(+v3), long long>::value]; + + enum enum4 { v4 = __LONG_LONG_MAX__ * 2ULL }; + int test4[is_same<typeof(+v4), unsigned long long>::value]; +#endif +} diff --git a/test/SemaCXX/exception-spec.cpp b/test/SemaCXX/exception-spec.cpp index 56cc435..efc9833 100644 --- a/test/SemaCXX/exception-spec.cpp +++ b/test/SemaCXX/exception-spec.cpp @@ -186,5 +186,18 @@ template <typename T> struct TEx; // expected-note {{template is declared here}} void tf() throw(TEx<int>); // expected-error {{implicit instantiation of undefined template}} -// DR 437, class throws itself. FIXME: See Sema::CheckSpecifiedExceptionType. -//struct DR437 { void f() throw(DR437); }; +// DR 437, class throws itself. +struct DR437 { + void f() throw(DR437); + void g() throw(DR437*); + void h() throw(DR437&); +}; + +// DR 437 within a nested class +struct DR437_out { + struct DR437_in { + void f() throw(DR437_out); + void g() throw(DR437_out*); + void h() throw(DR437_out&); + }; +}; diff --git a/test/SemaCXX/friend.cpp b/test/SemaCXX/friend.cpp index 76e84e5..d1c42eb 100644 --- a/test/SemaCXX/friend.cpp +++ b/test/SemaCXX/friend.cpp @@ -4,3 +4,14 @@ friend class A; // expected-error {{'friend' used outside of class}} void f() { friend class A; } // expected-error {{'friend' used outside of class}} class C { friend class A; }; class D { void f() { friend class A; } }; // expected-error {{'friend' used outside of class}} + +// PR5760 +namespace test0 { + namespace ns { + void f(int); + } + + struct A { + friend void ns::f(int a); + }; +} diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp index 785ea0e..b7db907 100644 --- a/test/SemaCXX/i-c-e-cxx.cpp +++ b/test/SemaCXX/i-c-e-cxx.cpp @@ -14,3 +14,10 @@ void f() { int array[value]; } } + +int a() { + const int t=t; // expected-note {{subexpression not valid}} + switch(1) { + case t:; // expected-error {{not an integer constant expression}} + } +} diff --git a/test/SemaCXX/implicit-member-functions.cpp b/test/SemaCXX/implicit-member-functions.cpp new file mode 100644 index 0000000..1867808 --- /dev/null +++ b/test/SemaCXX/implicit-member-functions.cpp @@ -0,0 +1,14 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +struct A { }; // expected-note {{previous implicit declaration is here}} +A::A() { } // expected-error {{definition of implicitly declared constructor}} + +struct B { }; // expected-note {{previous implicit declaration is here}} +B::B(const B&) { } // expected-error {{definition of implicitly declared copy constructor}} + +struct C { }; // expected-note {{previous implicit declaration is here}} +C& C::operator=(const C&) { return *this; } // expected-error {{definition of implicitly declared copy assignment operator}} + +struct D { }; // expected-note {{previous implicit declaration is here}} +D::~D() { } // expected-error {{definition of implicitly declared destructor}} + diff --git a/test/SemaCXX/implicit-virtual-member-functions.cpp b/test/SemaCXX/implicit-virtual-member-functions.cpp new file mode 100644 index 0000000..30fe278 --- /dev/null +++ b/test/SemaCXX/implicit-virtual-member-functions.cpp @@ -0,0 +1,29 @@ +// RUN: clang-cc -fsyntax-only -verify %s +struct A { + virtual ~A(); +}; + +struct B : A { // expected-error {{no suitable member 'operator delete' in 'B'}} + virtual void f(); + + void operator delete (void *, int); // expected-note {{'operator delete' declared here}} +}; + +void B::f() { // expected-note {{implicit default destructor for 'struct B' first required here}} +} + +struct C : A { // expected-error {{no suitable member 'operator delete' in 'C'}} + C(); + void operator delete(void *, int); // expected-note {{'operator delete' declared here}} +}; + +C::C() { } // expected-note {{implicit default destructor for 'struct C' first required here}} + +struct D : A { // expected-error {{no suitable member 'operator delete' in 'D'}} + void operator delete(void *, int); // expected-note {{'operator delete' declared here}} +}; + +void f() { + new D; // expected-note {{implicit default destructor for 'struct D' first required here}} +} + diff --git a/test/SemaCXX/linkage-spec.cpp b/test/SemaCXX/linkage-spec.cpp index fc9b3ab..d19727a 100644 --- a/test/SemaCXX/linkage-spec.cpp +++ b/test/SemaCXX/linkage-spec.cpp @@ -40,3 +40,17 @@ namespace pr5430 { } using namespace pr5430; extern "C" void pr5430::func(void) { } + +// PR5404 +int f2(char *) +{ + return 0; +} + +extern "C" +{ + int f2(int) + { + return f2((char *)0); + } +} diff --git a/test/SemaCXX/literal-type.cpp b/test/SemaCXX/literal-type.cpp new file mode 100644 index 0000000..0dca9c9 --- /dev/null +++ b/test/SemaCXX/literal-type.cpp @@ -0,0 +1,10 @@ +// RUN: clang-cc -fsyntax-only -verify -std=c++0x %s + +static_assert(__is_literal(int), "fail"); +static_assert(__is_literal(void*), "fail"); +enum E { E1 }; +static_assert(__is_literal(E), "fail"); +static_assert(__is_literal(decltype(E1)), "fail"); +typedef int IAR[10]; +static_assert(__is_literal(IAR), "fail"); +// FIXME: Records diff --git a/test/SemaCXX/member-expr-anonymous-union.cpp b/test/SemaCXX/member-expr-anonymous-union.cpp new file mode 100644 index 0000000..9566df4 --- /dev/null +++ b/test/SemaCXX/member-expr-anonymous-union.cpp @@ -0,0 +1,9 @@ +// RUN: clang-cc %s -fsyntax-only -verify +// PR5543 + +struct A { int x; union { int* y; float& z; }; }; struct B : A {int a;}; +int* a(B* x) { return x->y; } + +struct x { union { int y; }; }; x y; template <int X> int f() { return X+y.y; } +int g() { return f<2>(); } + diff --git a/test/SemaCXX/member-expr.cpp b/test/SemaCXX/member-expr.cpp index cd13bcc..9cd6855 100644 --- a/test/SemaCXX/member-expr.cpp +++ b/test/SemaCXX/member-expr.cpp @@ -41,3 +41,18 @@ void test2(X *xp) { xp->::i = 7; // expected-error{{qualified member access refers to a member in the global namespace}} xp->C::i = 7; // expected-error{{qualified member access refers to a member in namespace 'C'}} } + + +namespace test3 { + struct NamespaceDecl; + + struct NamedDecl { + void *getIdentifier() const; + }; + + struct NamespaceDecl : NamedDecl { + bool isAnonymousNamespace() const { + return !getIdentifier(); + } + }; +} diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 83c72417..6a51261 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -186,12 +186,10 @@ class foo { }; -// PR4452 -// FIXME: This error recovery sucks. -foo<somens:a> a2; // expected-error {{unexpected namespace name 'somens': expected expression}} \ -expected-error {{C++ requires a type specifier for all declarations}} +// PR4452 / PR4451 +foo<somens:a> a2; // expected-error {{unexpected ':' in nested name specifier}} -somens::a a3 = a2; +somens::a a3 = a2; // expected-error {{cannot initialize 'a3' with an lvalue of type 'foo<somens::a>'}} diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index f2fe0a7..8a3ec8b 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -140,10 +140,8 @@ public: class Base { public: - static int operator new(signed char) throw(); // expected-error {{'operator new' takes type size_t}} \ - // expected-error {{operator new' must return type 'void *'}} - static int operator new[] (signed char) throw(); // expected-error {{'operator new[]' takes type size_t}} \ - // expected-error {{operator new[]' must return type 'void *'}} + static void *operator new(signed char) throw(); // expected-error {{'operator new' takes type size_t}} + static int operator new[] (size_t) throw(); // expected-error {{operator new[]' must return type 'void *'}} }; class Tier {}; @@ -160,9 +158,11 @@ void loadEngineFor() { } template <class T> struct TBase { - void* operator new(T size, int); // expected-error {{'operator new' takes type size_t}} + void* operator new(T size, int); // expected-error {{'operator new' cannot take a dependent type as first parameter; use size_t}}\ + // expected-error {{'operator new' takes type size_t}} }; +// FIXME: We should not try to instantiate operator new, since it is invalid. TBase<int> t1; // expected-note {{in instantiation of template class 'struct TBase<int>' requested here}} class X6 { @@ -202,3 +202,17 @@ struct X11 : X10 { // expected-error {{no suitable member 'operator delete' in ' void f() { X11 x11; // expected-note {{implicit default destructor for 'struct X11' first required here}} } + +struct X12 { + void* operator new(size_t, void*); +}; + +struct X13 : X12 { + using X12::operator new; +}; + +static void* f(void* g) +{ + return new (g) X13(); +} + diff --git a/test/SemaCXX/offsetof.cpp b/test/SemaCXX/offsetof.cpp index f0290e8..bc7a707 100644 --- a/test/SemaCXX/offsetof.cpp +++ b/test/SemaCXX/offsetof.cpp @@ -13,3 +13,8 @@ void f() { int i = __builtin_offsetof(P, fieldThatPointsToANonPODType.m); // expected-warning{{offset of on non-POD type 'struct P'}} } +struct Base { int x; }; +struct Derived : Base { int y; }; +int o = __builtin_offsetof(Derived, x); // expected-warning{{offset of on non-POD type}} + +const int o2 = sizeof(__builtin_offsetof(Derived, x)); diff --git a/test/SemaCXX/overload-call-copycon.cpp b/test/SemaCXX/overload-call-copycon.cpp index 755e27a..6436236 100644 --- a/test/SemaCXX/overload-call-copycon.cpp +++ b/test/SemaCXX/overload-call-copycon.cpp @@ -1,4 +1,4 @@ -// RUN: clang-cc -fsyntax-only %s +// RUN: clang-cc -fsyntax-only %s -Wnon-pod-varargs class X { }; int& copycon(X x); @@ -23,10 +23,10 @@ float& copycon2(...); void test_copycon2(A a, const A ac, B b, B const bc, B volatile bv) { int& i1 = copycon2(b); - float& f1 = copycon2(bc); - float& f2 = copycon2(bv); + float& f1 = copycon2(bc); // expected-warning {{cannot pass object of non-POD type}} + float& f2 = copycon2(bv); // expected-warning {{cannot pass object of non-POD type}} short& s1 = copycon2(a); - float& f3 = copycon2(ac); + float& f3 = copycon2(ac); // expected-warning {{cannot pass object of non-POD type}} } int& copycon3(A a); @@ -34,7 +34,7 @@ float& copycon3(...); void test_copycon3(B b, const B bc) { int& i1 = copycon3(b); - float& f1 = copycon3(bc); + float& f1 = copycon3(bc); // expected-warning {{cannot pass object of non-POD type}} } diff --git a/test/SemaCXX/overload-call.cpp b/test/SemaCXX/overload-call.cpp index 3a0bf30..5d27182 100644 --- a/test/SemaCXX/overload-call.cpp +++ b/test/SemaCXX/overload-call.cpp @@ -92,7 +92,7 @@ enum PromotesToInt { }; enum PromotesToUnsignedInt { - PromotesToUnsignedIntValue = 1u + PromotesToUnsignedIntValue = __INT_MAX__ * 2U }; int* o(int); @@ -291,3 +291,13 @@ void f(SR) { } void g(opt o) { f(o); } + + +namespace PR5756 { + int &a(void*, int); + float &a(void*, float); + void b() { + int &ir = a(0,0); + (void)ir; + } +} diff --git a/test/SemaCXX/overloaded-operator.cpp b/test/SemaCXX/overloaded-operator.cpp index 16d3704..672b8b4 100644 --- a/test/SemaCXX/overloaded-operator.cpp +++ b/test/SemaCXX/overloaded-operator.cpp @@ -67,7 +67,7 @@ void enum_test(Enum1 enum1, Enum2 enum2, E1 e1, E2 e2) { float &f1 = (e1 == e2); float &f2 = (enum1 == e2); float &f3 = (e1 == enum2); - float &f4 = (enum1 == enum2); // expected-error{{non-const lvalue reference to type 'float' cannot be initialized with a temporary of type 'bool'}} + float &f4 = (enum1 == enum2); // expected-error{{non-const lvalue reference to type 'float' cannot bind to a temporary of type 'bool'}} } // PR5244 - Argument-dependent lookup would include the two operators below, diff --git a/test/SemaCXX/prefetch-enum.cpp b/test/SemaCXX/prefetch-enum.cpp new file mode 100644 index 0000000..829321f --- /dev/null +++ b/test/SemaCXX/prefetch-enum.cpp @@ -0,0 +1,9 @@ +// RUN: clang-cc -fsyntax-only %s -verify +// PR5679 + +enum X { A = 3 }; + +void Test() { + char ch; + __builtin_prefetch(&ch, 0, A); +} diff --git a/test/SemaCXX/qualified-id-lookup.cpp b/test/SemaCXX/qualified-id-lookup.cpp index 254a18d..5a11a0c 100644 --- a/test/SemaCXX/qualified-id-lookup.cpp +++ b/test/SemaCXX/qualified-id-lookup.cpp @@ -109,3 +109,18 @@ struct Undef { // expected-note{{definition of 'struct Undef' is not complete un int Undef::f() { return sizeof(Undef); } + +// PR clang/5667 +namespace test1 { + template <typename T> struct is_class { + enum { value = 0 }; + }; + + template <typename T> class ClassChecker { + bool isClass() { + return is_class<T>::value; + } + }; + + template class ClassChecker<int>; +} diff --git a/test/SemaCXX/ref-init-ambiguous.cpp b/test/SemaCXX/ref-init-ambiguous.cpp index dda1ead..6062099 100644 --- a/test/SemaCXX/ref-init-ambiguous.cpp +++ b/test/SemaCXX/ref-init-ambiguous.cpp @@ -3,18 +3,19 @@ enum E2 { }; struct A { - operator E2&(); // expected-note 3 {{candidate function}} + operator E2&(); // expected-note 2 {{candidate function}} }; struct B { - operator E2&(); // expected-note 3 {{candidate function}} + operator E2&(); // expected-note 2 {{candidate function}} }; struct C : B, A { }; void test(C c) { - const E2 &e2 = c; // expected-error {{reference initialization of type 'enum E2 const &' with initializer of type 'struct C' is ambiguous}} + // FIXME: state that there was an ambiguity in the conversion! + const E2 &e2 = c; // expected-error {{reference to type 'enum E2 const' could not bind to an lvalue of type 'struct C'}} } void foo(const E2 &); diff --git a/test/SemaCXX/references.cpp b/test/SemaCXX/references.cpp index e03abf4..45d3923 100644 --- a/test/SemaCXX/references.cpp +++ b/test/SemaCXX/references.cpp @@ -44,17 +44,17 @@ B fB(); // C++ [dcl.init.ref]p5b2 void test4() { - double& rd2 = 2.0; // expected-error{{non-const lvalue reference to type 'double' cannot be initialized with a temporary of type 'double'}} + double& rd2 = 2.0; // expected-error{{non-const lvalue reference to type 'double' cannot bind to a temporary of type 'double'}} int i = 2; - double& rd3 = i; // expected-error{{non-const lvalue reference to type 'double' cannot be initialized with a value of type 'int'}} + double& rd3 = i; // expected-error{{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}} const A& rca = fB(); } void test5() { - const double& rcd2 = 2; // rcd2 refers to temporary with value 2.0 + // const double& rcd2 = 2; // rcd2 refers to temporary with value 2.0 const volatile int cvi = 1; - const int& r = cvi; // expected-error{{initialization of reference to type 'int const' with a value of type 'int const volatile' drops qualifiers}} + const int& r = cvi; // expected-error{{binding of reference to type 'int const' to a value of type 'int const volatile' drops qualifiers}} } // C++ [dcl.init.ref]p3 diff --git a/test/SemaCXX/rval-references.cpp b/test/SemaCXX/rval-references.cpp index 5132c2a..7a71607 100644 --- a/test/SemaCXX/rval-references.cpp +++ b/test/SemaCXX/rval-references.cpp @@ -44,7 +44,7 @@ void f() { conv_to_not_int_rvalue cnir; not_int &&ni4 = cnir; // expected-error {{rvalue reference cannot bind to lvalue}} - not_int &ni5 = cnir; // expected-error{{non-const lvalue reference to type 'struct not_int' cannot be initialized with a value of type 'struct conv_to_not_int_rvalue'}} + not_int &ni5 = cnir; // expected-error{{non-const lvalue reference to type 'struct not_int' cannot bind to a value of unrelated type 'struct conv_to_not_int_rvalue'}} not_int &&ni6 = conv_to_not_int_rvalue(); diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp index 340c0ae..dfb4edc 100644 --- a/test/SemaCXX/type-traits.cpp +++ b/test/SemaCXX/type-traits.cpp @@ -250,3 +250,11 @@ void has_trivial_destructor() { int t17[T(__has_trivial_destructor(NonPODAr))]; int t18[T(__has_trivial_destructor(VirtAr))]; } + +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>))]; +}
\ No newline at end of file diff --git a/test/SemaCXX/using-decl-1.cpp b/test/SemaCXX/using-decl-1.cpp index 42deb27..0235624 100644 --- a/test/SemaCXX/using-decl-1.cpp +++ b/test/SemaCXX/using-decl-1.cpp @@ -38,3 +38,7 @@ struct X1 : X0 { (*this)(1); } }; + +struct A { void f(); }; +struct B : A { }; +class C : B { using B::f; }; diff --git a/test/SemaCXX/using-decl-templates.cpp b/test/SemaCXX/using-decl-templates.cpp index 684009b..a19223d 100644 --- a/test/SemaCXX/using-decl-templates.cpp +++ b/test/SemaCXX/using-decl-templates.cpp @@ -10,7 +10,7 @@ template<typename T> struct B : A<T> { using A<T>::N; // expected-error{{dependent using declaration resolved to type without 'typename'}} using A<T>::foo; // expected-error{{no member named 'foo'}} - using A<double>::f; // expected-error{{using declaration refers into 'A<double>::', which is not a base class of 'B'}} + using A<double>::f; // expected-error{{using declaration refers into 'A<double>::', which is not a base class of 'B<int>'}} }; B<int> a; // expected-note{{in instantiation of template class 'struct B<int>' requested here}} @@ -34,3 +34,14 @@ template<typename T> struct E : A<T> { void g() { f(); } }; + +namespace test0 { + struct Base { + int foo; + }; + template<typename T> struct E : Base { + using Base::foo; + }; + + template struct E<int>; +} diff --git a/test/SemaCXX/using-directive.cpp b/test/SemaCXX/using-directive.cpp index 51f347d..b7583f2 100644 --- a/test/SemaCXX/using-directive.cpp +++ b/test/SemaCXX/using-directive.cpp @@ -112,3 +112,12 @@ using namespace Alias; void testAlias() { inAliased(); } + +namespace N { void f2(int); } + +extern "C++" { + using namespace N; + void f3() { f2(1); } +} + +void f4() { f2(1); } diff --git a/test/SemaCXX/vararg-non-pod.cpp b/test/SemaCXX/vararg-non-pod.cpp index 977df14..f913531 100644 --- a/test/SemaCXX/vararg-non-pod.cpp +++ b/test/SemaCXX/vararg-non-pod.cpp @@ -1,4 +1,4 @@ -// RUN: clang-cc -fsyntax-only -verify -fblocks %s +// RUN: clang-cc -fsyntax-only -verify -fblocks %s -Wnon-pod-varargs extern char version[]; @@ -66,3 +66,25 @@ void t5() E e(10, c); // expected-warning{{cannot pass object of non-POD type 'class C' through variadic constructor; call will abort at runtime}} (void)E(10, c); // expected-warning{{cannot pass object of non-POD type 'class C' through variadic constructor; call will abort at runtime}} } + +// PR5761: unevaluated operands and the non-POD warning +class Foo { + public: + Foo() {} +}; + +int Helper(...); +const int size = sizeof(Helper(Foo())); + +namespace std { + class type_info { }; +} + +struct Base { virtual ~Base(); }; +Base &get_base(...); +int eat_base(...); + +void test_typeid(Base &base) { + (void)typeid(get_base(base)); // expected-warning{{cannot pass object of non-POD type 'struct Base' through variadic function; call will abort at runtime}} + (void)typeid(eat_base(base)); // okay +} diff --git a/test/SemaCXX/virtual-member-functions-key-function.cpp b/test/SemaCXX/virtual-member-functions-key-function.cpp new file mode 100644 index 0000000..4e7ff69 --- /dev/null +++ b/test/SemaCXX/virtual-member-functions-key-function.cpp @@ -0,0 +1,22 @@ +// RUN: clang-cc -fsyntax-only -verify %s +struct A { + virtual ~A(); +}; + +struct B : A { // expected-error {{no suitable member 'operator delete' in 'B'}} + B() { } // expected-note {{implicit default destructor for 'struct B' first required here}} + void operator delete(void *, int); // expected-note {{'operator delete' declared here}} +}; + +struct C : A { // expected-error {{no suitable member 'operator delete' in 'C'}} + void operator delete(void *, int); // expected-note {{'operator delete' declared here}} +}; + +void f() { + // new B should mark the constructor as used, which then marks + // all the virtual members as used, because B has no key function. + (void)new B; + + // Same here, except that C has an implicit constructor. + (void)new C; // expected-note {{implicit default destructor for 'struct C' first required here}} +} diff --git a/test/SemaCXX/virtual-override.cpp b/test/SemaCXX/virtual-override.cpp index 4a3b10f..c18a77f 100644 --- a/test/SemaCXX/virtual-override.cpp +++ b/test/SemaCXX/virtual-override.cpp @@ -1,5 +1,4 @@ // RUN: clang-cc -fsyntax-only -faccess-control -verify %s - namespace T1 { class A { @@ -104,3 +103,50 @@ namespace T7 { virtual b* f(); }; } + +// PR5656 +class X0 { + virtual void f0(); +}; +class X1 : public X0 { + void f0() = 0; +}; + +template <typename Base> +struct Foo : Base { + void f(int) = 0; // expected-error{{not virtual and cannot be declared pure}} +}; + +struct Base1 { virtual void f(int); }; +struct Base2 { }; + +void test() { + (void)sizeof(Foo<Base1>); + (void)sizeof(Foo<Base2>); // expected-note{{instantiation}} +} + +template<typename Base> +struct Foo2 : Base { + template<typename T> int f(T); +}; + +void test2() { + Foo2<Base1> f1; + Foo2<Base2> f2; + f1.f(17); + f2.f(17); +}; + +struct Foo3 { + virtual void f(int) = 0; // expected-note{{pure virtual function}} +}; + +template<typename T> +struct Bar3 : Foo3 { + void f(T); +}; + +void test3() { + Bar3<int> b3i; // okay + Bar3<float> b3f; // expected-error{{is an abstract class}} +} diff --git a/test/SemaCXX/warn-missing-prototypes.cpp b/test/SemaCXX/warn-missing-prototypes.cpp new file mode 100644 index 0000000..079a837 --- /dev/null +++ b/test/SemaCXX/warn-missing-prototypes.cpp @@ -0,0 +1,26 @@ +// RUN: clang-cc -fsyntax-only -verify -Wmissing-prototypes %s + +void f() { } // expected-warning {{no previous prototype for function 'f'}} + +namespace NS { + void f() { } // expected-warning {{no previous prototype for function 'f'}} +} + +namespace { + // Don't warn about functions in anonymous namespaces. + void f() { } +} + +struct A { + // Don't warn about member functions. + void f() { } +}; + +// Don't warn about inline functions. +inline void g() { } + +// Don't warn about function templates. +template<typename> void h() { } + +// Don't warn when instantiating function templates. +template void h<int>(); |