diff options
Diffstat (limited to 'test/SemaCXX')
23 files changed, 241 insertions, 39 deletions
diff --git a/test/SemaCXX/address-of-temporary.cpp b/test/SemaCXX/address-of-temporary.cpp new file mode 100644 index 0000000..decdc95 --- /dev/null +++ b/test/SemaCXX/address-of-temporary.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -Wno-error=address-of-temporary -verify %s +struct X { + X(); + X(int); + X(int, int); +}; + +void *f0() { return &X(); } // expected-warning{{taking the address of a temporary object}} +void *f1() { return &X(1); } // expected-warning{{taking the address of a temporary object}} +void *f2() { return &X(1, 2); } // expected-warning{{taking the address of a temporary object}} +void *f3() { return &(X)1; } // expected-warning{{taking the address of a temporary object}} + diff --git a/test/SemaCXX/attr-weakref.cpp b/test/SemaCXX/attr-weakref.cpp new file mode 100644 index 0000000..5773acc --- /dev/null +++ b/test/SemaCXX/attr-weakref.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// GCC will accept anything as the argument of weakref. Should we +// check for an existing decl? +static int a1() __attribute__((weakref ("foo"))); +static int a2() __attribute__((weakref, alias ("foo"))); + +static int a3 __attribute__((weakref ("foo"))); +static int a4 __attribute__((weakref, alias ("foo"))); + +// gcc rejects, clang accepts +static int a5 __attribute__((alias ("foo"), weakref)); + +// this is pointless, but accepted by gcc. We reject it. +static int a6 __attribute__((weakref)); //expected-error {{weakref declaration of 'a6' must also have an alias attribute}} + +// gcc warns, clang rejects +void f(void) { + static int a __attribute__((weakref ("v2"))); // expected-error {{declaration of 'a' must be in a global context}} +} + +// both gcc and clang reject +class c { + static int a __attribute__((weakref ("v2"))); // expected-error {{declaration of 'a' must be in a global context}} + static int b() __attribute__((weakref ("f3"))); // expected-error {{declaration of 'b' must be in a global context}} +}; +int a7() __attribute__((weakref ("f1"))); // expected-error {{declaration of 'a7' must be static}} +int a8 __attribute__((weakref ("v1"))); // expected-error {{declaration of 'a8' must be static}} + +// gcc accepts this +int a9 __attribute__((weakref)); // expected-error {{declaration of 'a9' must be static}} diff --git a/test/SemaCXX/blocks-1.cpp b/test/SemaCXX/blocks-1.cpp new file mode 100644 index 0000000..d93997a --- /dev/null +++ b/test/SemaCXX/blocks-1.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s -fblocks + +extern "C" int exit(int); + +typedef struct { + unsigned long ps[30]; + int qs[30]; +} BobTheStruct; + +int main (int argc, const char * argv[]) { + BobTheStruct inny; + BobTheStruct outty; + BobTheStruct (^copyStruct)(BobTheStruct); + int i; + + for(i=0; i<30; i++) { + inny.ps[i] = i * i * i; + inny.qs[i] = -i * i * i; + } + + copyStruct = ^(BobTheStruct aBigStruct){ return aBigStruct; }; // pass-by-value intrinsically copies the argument + + outty = copyStruct(inny); + + if ( &inny == &outty ) { + exit(1); + } + for(i=0; i<30; i++) { + if ( (inny.ps[i] != outty.ps[i]) || (inny.qs[i] != outty.qs[i]) ) { + exit(1); + } + } + + return 0; +} diff --git a/test/SemaCXX/complex-overload.cpp b/test/SemaCXX/complex-overload.cpp index 3378755..2c057ac 100644 --- a/test/SemaCXX/complex-overload.cpp +++ b/test/SemaCXX/complex-overload.cpp @@ -1,5 +1,5 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -char *foo(float); // expected-note 3 {{candidate function}} +char *foo(float); void test_foo_1(float fv, double dv, float _Complex fc, double _Complex dc) { char *cp1 = foo(fv); @@ -9,20 +9,20 @@ void test_foo_1(float fv, double dv, float _Complex fc, double _Complex dc) { char *cp4 = foo(dc); } -int *foo(float _Complex); // expected-note 3 {{candidate function}} +int *foo(float _Complex); void test_foo_2(float fv, double dv, float _Complex fc, double _Complex dc) { char *cp1 = foo(fv); - char *cp2 = foo(dv); // expected-error{{call to 'foo' is ambiguous; candidates are:}} + char *cp2 = foo(dv); int *ip = foo(fc); - int *lp = foo(dc); // expected-error{{call to 'foo' is ambiguous; candidates are:}} + int *lp = foo(dc); } -long *foo(double _Complex); // expected-note {{candidate function}} +long *foo(double _Complex); void test_foo_3(float fv, double dv, float _Complex fc, double _Complex dc) { char *cp1 = foo(fv); - char *cp2 = foo(dv); // expected-error{{call to 'foo' is ambiguous; candidates are:}} + char *cp2 = foo(dv); int *ip = foo(fc); long *lp = foo(dc); } diff --git a/test/SemaCXX/composite-pointer-type.cpp b/test/SemaCXX/composite-pointer-type.cpp index fdf838f..e8b0920 100644 --- a/test/SemaCXX/composite-pointer-type.cpp +++ b/test/SemaCXX/composite-pointer-type.cpp @@ -50,3 +50,11 @@ typedef double Matrix4[4][4]; bool f(Matrix4 m1, const Matrix4 m2) { return m1 != m2; } + +// PR6346 +bool f1(bool b, void **p, const void **q) { + if (p == q) // expected-warning{{comparison of distinct pointer types ('void **' and 'void const **') uses non-standard composite pointer type 'void const *const *'}} + return false; + + return b? p : q; // expected-warning{{incompatible operand types ('void **' and 'void const **') use non-standard composite pointer type 'void const *const *'}} +} diff --git a/test/SemaCXX/condition.cpp b/test/SemaCXX/condition.cpp index fe802d0..b3e862d 100644 --- a/test/SemaCXX/condition.cpp +++ b/test/SemaCXX/condition.cpp @@ -18,7 +18,8 @@ void test() { while (struct S {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}} while (struct {} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{no viable conversion}} expected-error {{value of type 'struct <anonymous>' is not contextually convertible to 'bool'}} expected-note{{candidate constructor (the implicit copy constructor)}} - switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} + switch (enum {E} x=0) ; // expected-error {{types may not be defined in conditions}} expected-error {{cannot initialize}} \ + // expected-warning{{enumeration value 'E' not handled in switch}} if (int x=0) { // expected-note 2 {{previous definition is here}} int x; // expected-error {{redefinition of 'x'}} diff --git a/test/SemaCXX/copy-constructor-error.cpp b/test/SemaCXX/copy-constructor-error.cpp index 9cae775..9809bfc 100644 --- a/test/SemaCXX/copy-constructor-error.cpp +++ b/test/SemaCXX/copy-constructor-error.cpp @@ -10,3 +10,16 @@ void g() { S a( f() ); } +namespace PR6064 { + struct A { + A() { } + inline A(A&, int); + }; + + A::A(A&, int = 0) { } + + void f() { + A const a; + A b(a); + } +} diff --git a/test/SemaCXX/dcl_init_aggr.cpp b/test/SemaCXX/dcl_init_aggr.cpp index 861eb3d..461c60b 100644 --- a/test/SemaCXX/dcl_init_aggr.cpp +++ b/test/SemaCXX/dcl_init_aggr.cpp @@ -38,7 +38,7 @@ char cv[4] = { 'a', 's', 'd', 'f', 0 }; // expected-error{{excess elements in ar // C++ [dcl.init.aggr]p7 struct TooFew { int a; char* b; int c; }; -TooFew too_few = { 1, "asdf" }; // okay +TooFew too_few = { 1, "asdf" }; // expected-warning{{conversion from string literal to 'char *' is deprecated}} struct NoDefaultConstructor { // expected-note 3 {{candidate constructor (the implicit copy constructor)}} \ // expected-note{{declared here}} diff --git a/test/SemaCXX/default2.cpp b/test/SemaCXX/default2.cpp index d2c44bd..e674260 100644 --- a/test/SemaCXX/default2.cpp +++ b/test/SemaCXX/default2.cpp @@ -16,7 +16,8 @@ void i() } -int f1(int i, int i, int j) { // expected-error {{redefinition of parameter 'i'}} +int f1(int i, // expected-note {{previous declaration is here}} + int i, int j) { // expected-error {{redefinition of parameter 'i'}} i = 17; return j; } diff --git a/test/SemaCXX/destructor.cpp b/test/SemaCXX/destructor.cpp index 6837cd4..ab3c809 100644 --- a/test/SemaCXX/destructor.cpp +++ b/test/SemaCXX/destructor.cpp @@ -40,9 +40,9 @@ struct F { ~F(); // expected-error {{destructor cannot be redeclared}} }; -~; // expected-error {{expected the class name after '~' to name a destructor}} +~; // expected-error {{expected a class name after '~' to name a destructor}} ~undef(); // expected-error {{expected the class name after '~' to name a destructor}} -~operator+(int, int); // expected-error {{expected the class name after '~' to name a destructor}} +~operator+(int, int); // expected-error {{expected a class name after '~' to name a destructor}} ~F(){} // expected-error {{destructor must be a non-static member function}} struct G { @@ -61,3 +61,20 @@ struct X {}; struct Y { ~X(); // expected-error {{expected the class name after '~' to name the enclosing class}} }; + +namespace PR6421 { + class T; // expected-note{{forward declaration}} + + class QGenericArgument + { + template<typename U> + void foo(T t) // expected-error{{variable has incomplete type}} + { } + + void disconnect() + { + T* t; + bob<QGenericArgument>(t); // expected-error{{undeclared identifier 'bob'}} + } + }; +} diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp index 4f2f197..e8275d4 100644 --- a/test/SemaCXX/i-c-e-cxx.cpp +++ b/test/SemaCXX/i-c-e-cxx.cpp @@ -37,3 +37,8 @@ namespace pr6206 { return str[0]; } } + +// PR6373: default arguments don't count. +void pr6373(const unsigned x = 0) { + unsigned max = 80 / x; +} diff --git a/test/SemaCXX/implicit-virtual-member-functions.cpp b/test/SemaCXX/implicit-virtual-member-functions.cpp index 4ae9eae..1bb5adb 100644 --- a/test/SemaCXX/implicit-virtual-member-functions.cpp +++ b/test/SemaCXX/implicit-virtual-member-functions.cpp @@ -15,9 +15,9 @@ void B::f() { // expected-note {{implicit default destructor for 'struct B' firs struct C : A { // expected-error {{no suitable member 'operator delete' in 'C'}} C(); void operator delete(void *, int); // expected-note {{'operator delete' declared here}} -}; // expected-note {{implicit default destructor for 'struct C' first required here}} +}; -C::C() { } +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}} diff --git a/test/SemaCXX/invalid-member-expr.cpp b/test/SemaCXX/invalid-member-expr.cpp index 666595c..7b17afb 100644 --- a/test/SemaCXX/invalid-member-expr.cpp +++ b/test/SemaCXX/invalid-member-expr.cpp @@ -6,7 +6,7 @@ void test() { X x; x.int; // expected-error{{expected unqualified-id}} - x.~int(); // expected-error{{expected the class name}} + x.~int(); // expected-error{{expected a class name}} x.operator; // expected-error{{missing type specifier after 'operator'}} x.operator typedef; // expected-error{{missing type specifier after 'operator'}} } @@ -15,7 +15,7 @@ void test2() { X *x; x->int; // expected-error{{expected unqualified-id}} - x->~int(); // expected-error{{expected the class name}} + x->~int(); // expected-error{{expected a class name}} x->operator; // expected-error{{missing type specifier after 'operator'}} x->operator typedef; // expected-error{{missing type specifier after 'operator'}} } diff --git a/test/SemaCXX/local-classes.cpp b/test/SemaCXX/local-classes.cpp new file mode 100644 index 0000000..6799e58 --- /dev/null +++ b/test/SemaCXX/local-classes.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace PR6382 { + int foo() + { + goto error; + { + struct BitPacker { + BitPacker() {} + }; + BitPacker packer; + } + + error: + return -1; + } +} + +namespace PR6383 { + void test (bool gross) + { + struct compare_and_set + { + void operator() (const bool inner, const bool gross = false) + { + // the code + } + } compare_and_set2; + + compare_and_set2 (false, gross); + } +} diff --git a/test/SemaCXX/member-name-lookup.cpp b/test/SemaCXX/member-name-lookup.cpp index ff14416..94296e1 100644 --- a/test/SemaCXX/member-name-lookup.cpp +++ b/test/SemaCXX/member-name-lookup.cpp @@ -2,7 +2,7 @@ struct A { int a; // expected-note 4{{member found by ambiguous name lookup}} static int b; - static int c; // expected-note 4{{member found by ambiguous name lookup}} + static int c; // expected-note 2{{member found by ambiguous name lookup}} enum E { enumerator }; @@ -75,7 +75,7 @@ struct B2 : virtual A { }; struct C2 : virtual A { - int c; // expected-note 2{{member found by ambiguous name lookup}} + int c; int d; // expected-note 2{{member found by ambiguous name lookup}} enum E3 { enumerator3_2 }; // expected-note 2{{member found by ambiguous name lookup}} @@ -93,7 +93,7 @@ struct G : F, D2 { void test_virtual_lookup(D2 d2, G g) { (void)d2.a; (void)d2.b; - d2.c; // expected-error{{member 'c' found in multiple base classes of different types}} + (void)d2.c; // okay d2.d; // expected-error{{member 'd' found in multiple base classes of different types}} d2.f(0); // okay d2.static_f(0); // okay @@ -112,7 +112,7 @@ void test_virtual_lookup(D2 d2, G g) { void D2::test_virtual_lookup() { (void)a; (void)b; - c; // expected-error{{member 'c' found in multiple base classes of different types}} + (void)c; // okay d; // expected-error{{member 'd' found in multiple base classes of different types}} f(0); // okay static_f(0); // okay diff --git a/test/SemaCXX/member-pointer.cpp b/test/SemaCXX/member-pointer.cpp index 3d9d5b5e..d6050cd 100644 --- a/test/SemaCXX/member-pointer.cpp +++ b/test/SemaCXX/member-pointer.cpp @@ -12,8 +12,7 @@ int A::*pdi1; int (::A::*pdi2); int (A::*pfi)(int); -int B::*pbi; // expected-error {{expected a class or namespace}} \ - // expected-error{{does not point into a class}} +int B::*pbi; // expected-error {{expected a class or namespace}} int C::*pci; // expected-error {{'pci' does not point into a class}} void A::*pdv; // expected-error {{'pdv' declared as a member pointer to void}} int& A::*pdr; // expected-error {{'pdr' declared as a member pointer to a reference}} diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 8a217b3..247e91b 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -13,8 +13,9 @@ namespace A { } A:: ; // expected-error {{expected unqualified-id}} -::A::ax::undef ex3; // expected-error {{no member named}} -A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} +// FIXME: redundant errors +::A::ax::undef ex3; // expected-error {{no member named}} expected-error {{unknown type name}} +A::undef1::undef2 ex4; // expected-error {{no member named 'undef1'}} expected-error {{unknown type name}} int A::C::Ag1() { return 0; } diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index acd4a23..68323d8 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -159,12 +159,10 @@ void loadEngineFor() { } template <class T> struct TBase { - 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}} + void* operator new(T size, int); // expected-error {{'operator new' cannot take a dependent type as first parameter; use 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}} +TBase<int> t1; class X6 { public: diff --git a/test/SemaCXX/overload-call.cpp b/test/SemaCXX/overload-call.cpp index e2a4fd8..77e0908 100644 --- a/test/SemaCXX/overload-call.cpp +++ b/test/SemaCXX/overload-call.cpp @@ -53,7 +53,7 @@ int* k(char*); double* k(bool); void test_k() { - int* ip1 = k("foo"); + int* ip1 = k("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}} double* dp1 = k(L"foo"); } @@ -61,7 +61,7 @@ int* l(wchar_t*); double* l(bool); void test_l() { - int* ip1 = l(L"foo"); + int* ip1 = l(L"foo"); // expected-warning{{conversion from string literal to 'wchar_t *' is deprecated}} double* dp1 = l("foo"); } @@ -79,7 +79,7 @@ class E; void test_n(E* e) { char ca[7]; int* ip1 = n(ca); - int* ip2 = n("foo"); + int* ip2 = n("foo"); // expected-warning{{conversion from string literal to 'char *' is deprecated}} float fa[7]; double* dp1 = n(fa); @@ -359,3 +359,30 @@ namespace DerivedToBaseVsVoid { int &ir = f(b); } } + +// PR 6398 + PR 6421 +namespace test4 { + class A; + class B { + static void foo(); // expected-note {{not viable}} + static void foo(int*); // expected-note {{not viable}} + static void foo(long*); // expected-note {{not viable}} + + void bar(A *a) { + foo(a); // expected-error {{no matching function for call}} + } + }; +} + +namespace DerivedToBase { + struct A { }; + struct B : A { }; + struct C : B { }; + + int &f0(const A&); + float &f0(B); + + void g() { + float &fr = f0(C()); + } +} diff --git a/test/SemaCXX/pseudo-destructors.cpp b/test/SemaCXX/pseudo-destructors.cpp index 15e37c5..472e5b4 100644 --- a/test/SemaCXX/pseudo-destructors.cpp +++ b/test/SemaCXX/pseudo-destructors.cpp @@ -5,21 +5,23 @@ enum Foo { F }; typedef Foo Bar; typedef int Integer; +typedef double Double; void g(); namespace N { typedef Foo Wibble; + typedef int OtherInteger; } -void f(A* a, Foo *f, int *i) { +void f(A* a, Foo *f, int *i, double *d) { a->~A(); a->A::~A(); a->~foo(); // expected-error{{identifier 'foo' in pseudo-destructor expression does not name a type}} - // FIXME: the type printed below isn't wonderful - a->~Bar(); // expected-error{{no member named}} + // FIXME: the diagnostic below isn't wonderful + a->~Bar(); // expected-error{{does not name a type}} f->~Bar(); f->~Foo(); @@ -28,9 +30,17 @@ void f(A* a, Foo *f, int *i) { g().~Bar(); // expected-error{{non-scalar}} f->::~Bar(); - f->N::~Wibble(); + f->N::~Wibble(); // FIXME: technically, Wibble isn't a class-name f->::~Bar(17, 42); // expected-error{{cannot have any arguments}} + + i->~Integer(); + i->Integer::~Integer(); + i->N::~OtherInteger(); + i->N::OtherInteger::~OtherInteger(); + i->N::OtherInteger::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}} + i->N::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}} + i->Integer::~Double(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('Double' (aka 'double')) in pseudo-destructor expression}} } typedef int Integer; diff --git a/test/SemaCXX/statements.cpp b/test/SemaCXX/statements.cpp index 3698258..852086e 100644 --- a/test/SemaCXX/statements.cpp +++ b/test/SemaCXX/statements.cpp @@ -1,5 +1,17 @@ -// RUN: %clang_cc1 %s -fsyntax-only -pedantic +// RUN: %clang_cc1 %s -fsyntax-only -pedantic -verify void foo() { return foo(); } + +// PR6451 - C++ Jump checking +struct X { + X(); +}; + +void test2() { + goto later; // expected-error {{illegal goto into protected scope}} + X x; // expected-note {{jump bypasses variable initialization}} +later: + ; +} diff --git a/test/SemaCXX/type-convert-construct.cpp b/test/SemaCXX/type-convert-construct.cpp index d786a9a..8f92a03 100644 --- a/test/SemaCXX/type-convert-construct.cpp +++ b/test/SemaCXX/type-convert-construct.cpp @@ -11,7 +11,7 @@ void f() { int *p; bool v6 = T(0) == p; char *str; - str = "a string"; + str = "a string"; // expected-warning{{conversion from string literal to 'char *' is deprecated}} wchar_t *wstr; - wstr = L"a wide string"; + wstr = L"a wide string"; // expected-warning{{conversion from string literal to 'wchar_t *' is deprecated}} } diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp index a7ed91d..01b36de 100644 --- a/test/SemaCXX/warn-unreachable.cpp +++ b/test/SemaCXX/warn-unreachable.cpp @@ -52,8 +52,8 @@ void test4() { int mem; } s; S &foor(); - halt(), foor() - .mem; // expected-warning {{will never be executed}} + halt(), foor()// expected-warning {{will never be executed}} + .mem; } void test5() { |