diff options
Diffstat (limited to 'test/SemaCXX')
44 files changed, 1116 insertions, 96 deletions
diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp new file mode 100644 index 0000000..fb3107f --- /dev/null +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -0,0 +1,44 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -fms-extensions -fexceptions + + +// ::type_info is predeclared with forward class declartion +void f(const type_info &a); + +// The following three are all equivalent when ms-extensions are on +void foo() throw(int); +void foo() throw(int, long); +void foo() throw(...); +void foo(); // expected-note {{previous declaration}} + +// Only nothrow specification is treated specially. +void foo() throw(); // expected-error {{exception specification in declaration does not match previous declaration}} + +// throw(...) +void r3(); +void r3() throw(...); + +void r6() throw(...); +void r6() throw(int); // okay + +struct Base { + virtual void f2(); + virtual void f3() throw(...); +}; + +struct Derived : Base { + virtual void f2() throw(...); + virtual void f3(); +}; + +// __stdcall handling +struct M { + int __stdcall addP(); + float __stdcall subtractP(); +}; + +template<typename T> void h1(T (__stdcall M::* const )()) { } + +void m1() { + h1<int>(&M::addP); + h1(&M::subtractP); +} diff --git a/test/SemaCXX/abstract.cpp b/test/SemaCXX/abstract.cpp index f64fda4..ad079c2 100644 --- a/test/SemaCXX/abstract.cpp +++ b/test/SemaCXX/abstract.cpp @@ -67,20 +67,23 @@ class F { virtual void f() = 0; // expected-note {{pure virtual function 'f'}} }; +// Diagnosing in these cases is prohibitively expensive. We still +// diagnose at the function definition, of course. + class Abstract; -void t7(Abstract a); // expected-error {{parameter type 'Abstract' is an abstract class}} +void t7(Abstract a); void t8() { - void h(Abstract a); // expected-error {{parameter type 'Abstract' is an abstract class}} + void h(Abstract a); } namespace N { -void h(Abstract a); // expected-error {{parameter type 'Abstract' is an abstract class}} +void h(Abstract a); } class Abstract { - virtual void f() = 0; // expected-note {{pure virtual function 'f'}} + virtual void f() = 0; }; // <rdar://problem/6854087> @@ -186,3 +189,63 @@ namespace test1 { C c; } } + +// rdar://problem/8302168 +namespace test2 { + struct X1 { + virtual void xfunc(void) = 0; // expected-note {{pure virtual function}} + void g(X1 parm7); // expected-error {{parameter type 'test2::X1' is an abstract class}} + void g(X1 parm8[2]); // expected-error {{array of abstract class type 'test2::X1'}} + }; + + template <int N> + struct X2 { + virtual void xfunc(void) = 0; // expected-note {{pure virtual function}} + void g(X2 parm10); // expected-error {{parameter type 'X2<N>' is an abstract class}} + void g(X2 parm11[2]); // expected-error {{array of abstract class type 'X2<N>'}} + }; +} + +namespace test3 { + struct A { // expected-note {{not complete until}} + A x; // expected-error {{field has incomplete type}} + virtual void abstract() = 0; + }; + + struct B { // expected-note {{not complete until}} + virtual void abstract() = 0; + B x; // expected-error {{field has incomplete type}} + }; + + struct C { + static C x; // expected-error {{abstract class}} + virtual void abstract() = 0; // expected-note {{pure virtual function}} + }; + + struct D { + virtual void abstract() = 0; // expected-note {{pure virtual function}} + static D x; // expected-error {{abstract class}} + }; +} + +namespace test4 { + template <class T> struct A { + A x; // expected-error {{abstract class}} + virtual void abstract() = 0; // expected-note {{pure virtual function}} + }; + + template <class T> struct B { + virtual void abstract() = 0; // expected-note {{pure virtual function}} + B x; // expected-error {{abstract class}} + }; + + template <class T> struct C { + static C x; // expected-error {{abstract class}} + virtual void abstract() = 0; // expected-note {{pure virtual function}} + }; + + template <class T> struct D { + virtual void abstract() = 0; // expected-note {{pure virtual function}} + static D x; // expected-error {{abstract class}} + }; +} diff --git a/test/SemaCXX/access-member-pointer.cpp b/test/SemaCXX/access-member-pointer.cpp new file mode 100644 index 0000000..676eb10 --- /dev/null +++ b/test/SemaCXX/access-member-pointer.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// PR7694 + +class A { }; +class B : private A { public: void foo(); }; // expected-note {{declared private here}} +void B::foo() { + (void)static_cast<void(A::*)()>(&B::foo); +} +void bar() { + (void)static_cast<void(A::*)()>(&B::foo); // expected-error {{cannot cast 'B' to its private base class 'A'}} +} diff --git a/test/SemaCXX/addr-of-overloaded-function.cpp b/test/SemaCXX/addr-of-overloaded-function.cpp index f8b00df..b581b8a 100644 --- a/test/SemaCXX/addr-of-overloaded-function.cpp +++ b/test/SemaCXX/addr-of-overloaded-function.cpp @@ -86,3 +86,13 @@ namespace test0 { myFunction(bar); } } + +namespace PR7971 { + struct S { + void g() { + f(&g); + } + void f(bool (*)(int, char)); + static bool g(int, char); + }; +} diff --git a/test/SemaCXX/altivec.cpp b/test/SemaCXX/altivec.cpp new file mode 100644 index 0000000..cdfc00a --- /dev/null +++ b/test/SemaCXX/altivec.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -faltivec -fno-lax-vector-conversions -triple powerpc-unknown-unknown -verify %s + +typedef int V4i __attribute__((vector_size(16))); + +void f(V4i a) +{ +} + +void test() +{ + V4i vGCC; + vector int vAltiVec; + + f(vAltiVec); + vGCC = vAltiVec; + vGCC = vGCC > vAltiVec; + vAltiVec = 0 ? vGCC : vGCC; +} diff --git a/test/SemaCXX/anonymous-struct.cpp b/test/SemaCXX/anonymous-struct.cpp new file mode 100644 index 0000000..dfa284a --- /dev/null +++ b/test/SemaCXX/anonymous-struct.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct S { + S(); // expected-note {{because type 'S' has a user-declared constructor}} +}; + +struct E { + struct { + S x; // expected-error {{anonymous struct member 'x' has a non-trivial constructor}} + }; +}; diff --git a/test/SemaCXX/attr-unavailable.cpp b/test/SemaCXX/attr-unavailable.cpp index 8b381df..6f5aa5e 100644 --- a/test/SemaCXX/attr-unavailable.cpp +++ b/test/SemaCXX/attr-unavailable.cpp @@ -12,9 +12,9 @@ void test_foo(short* sp) { double &dr = foo(1.0); foo(sp); // expected-error{{call to unavailable function 'foo'}} - void (*fp)(...) = &bar; // expected-warning{{'bar' is unavailable}} - void (*fp2)(...) = bar; // expected-warning{{'bar' is unavailable}} + void (*fp)(...) = &bar; // expected-error{{'bar' is unavailable}} + void (*fp2)(...) = bar; // expected-error{{'bar' is unavailable}} int &(*fp3)(int) = foo; - void (*fp4)(...) = foo; // expected-warning{{'foo' is unavailable}} + void (*fp4)(...) = foo; // expected-error{{'foo' is unavailable}} } diff --git a/test/SemaCXX/blocks.cpp b/test/SemaCXX/blocks.cpp index baa79e7..adbff55 100644 --- a/test/SemaCXX/blocks.cpp +++ b/test/SemaCXX/blocks.cpp @@ -41,3 +41,30 @@ namespace test2 { return Power(2).calculate(10); } } + +// rdar: // 8382559 +namespace radar8382559 { + void func(bool& outHasProperty); + + int test3() { + __attribute__((__blocks__(byref))) bool hasProperty = false; + bool has = true; + + bool (^b)() = ^ { + func(hasProperty); + if (hasProperty) + hasProperty = 0; + if (has) + hasProperty = 1; + return hasProperty; + }; + func(hasProperty); + func(has); + b(); + if (hasProperty) + hasProperty = 1; + if (has) + has = 2; + return hasProperty = 1; + } +} diff --git a/test/SemaCXX/borland-extensions.cpp b/test/SemaCXX/borland-extensions.cpp new file mode 100644 index 0000000..c33527c --- /dev/null +++ b/test/SemaCXX/borland-extensions.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -fborland-extensions + +// Borland extensions + +// 1. test -fborland-extensions +int dummy_function() { return 0; } + +// 2. test __pascal +int _pascal f2(); + +float __pascal gi2(int, int); +template<typename T> T g2(T (__pascal * const )(int, int)) { return 0; } + +struct M { + int __pascal addP(); + float __pascal subtractP(); +}; +template<typename T> int h2(T (__pascal M::* const )()) { return 0; } +void m2() { + int i; float f; + i = f2(); + f = gi2(2, i); + f = g2(gi2); + i = h2<int>(&M::addP); + f = h2(&M::subtractP); +} diff --git a/test/SemaCXX/constructor-initializer.cpp b/test/SemaCXX/constructor-initializer.cpp index cf309f5..31d5330 100644 --- a/test/SemaCXX/constructor-initializer.cpp +++ b/test/SemaCXX/constructor-initializer.cpp @@ -221,3 +221,17 @@ namespace PR7402 { S s(3); } } + +// <rdar://problem/8308215>: don't crash. +// Lots of questionable recovery here; errors can change. +namespace test3 { + class A : public std::exception {}; // expected-error {{undeclared identifier}} expected-error {{expected class name}} expected-note 3 {{candidate}} expected-note {{passing argument}} + class B : public A { + public: + B(const String& s, int e=0) // expected-error {{unknown type name}} + : A(e), m_String(s) , m_ErrorStr(__null) {} // expected-error {{no matching constructor}} expected-error {{does not name}} + B(const B& e) + : A(e), m_String(e.m_String), m_ErrorStr(__null) { // expected-error {{no viable conversion}} expected-error {{does not name}} + } + }; +} diff --git a/test/SemaCXX/conversion-function.cpp b/test/SemaCXX/conversion-function.cpp index 3e96d02..07281e1 100644 --- a/test/SemaCXX/conversion-function.cpp +++ b/test/SemaCXX/conversion-function.cpp @@ -97,9 +97,7 @@ void f(Yb& a) { class AutoPtrRef { }; class AutoPtr { - // FIXME: Using 'unavailable' since we do not have access control yet. - // FIXME: The error message isn't so good. - AutoPtr(AutoPtr &) __attribute__((unavailable)); // expected-note{{explicitly marked}} + AutoPtr(AutoPtr &); // expected-note{{declared private here}} public: AutoPtr(); @@ -115,7 +113,7 @@ AutoPtr test_auto_ptr(bool Cond) { AutoPtr p; if (Cond) - return p; // expected-error{{call to deleted constructor}} + return p; // expected-error{{calling a private constructor}} return AutoPtr(); } @@ -125,11 +123,12 @@ struct A1 { ~A1(); private: - A1(const A1&) __attribute__((unavailable)); // expected-note{{here}} + A1(const A1&); // expected-note 2 {{declared private here}} }; A1 f() { - return "Hello"; // expected-error{{invokes deleted constructor}} + // FIXME: redundant diagnostics! + return "Hello"; // expected-error {{calling a private constructor}} expected-warning {{an accessible copy constructor}} } namespace source_locations { @@ -215,3 +214,114 @@ struct Other { void test_any() { Any any = Other(); // expected-error{{cannot pass object of non-POD type 'Other' through variadic constructor; call will abort at runtime}} } + +namespace PR7055 { + // Make sure that we don't allow too many conversions in an + // auto_ptr-like template. In particular, we can't create multiple + // temporary objects when binding to a reference. + struct auto_ptr { + struct auto_ptr_ref { }; + + auto_ptr(auto_ptr&); + auto_ptr(auto_ptr_ref); + explicit auto_ptr(int *); + + operator auto_ptr_ref(); + }; + + struct X { + X(auto_ptr); + }; + + X f() { + X x(auto_ptr(new int)); + return X(auto_ptr(new int)); + } + + auto_ptr foo(); + + X e(foo()); + + struct Y { + Y(X); + }; + + Y f2(foo()); +} + +namespace PR7934 { + typedef unsigned char uint8; + + struct MutablePtr { + MutablePtr() : ptr(0) {} + void *ptr; + + operator void*() { return ptr; } + + private: + operator uint8*() { return reinterpret_cast<uint8*>(ptr); } + operator const char*() const { return reinterpret_cast<const char*>(ptr); } + }; + + void fake_memcpy(const void *); + + void use() { + MutablePtr ptr; + fake_memcpy(ptr); + } +} + +namespace rdar8018274 { + struct X { }; + struct Y { + operator const struct X *() const; + }; + + struct Z : Y { + operator struct X * (); + }; + + void test() { + Z x; + (void) (x != __null); + } + + + struct Base { + operator int(); + }; + + struct Derived1 : Base { }; + + struct Derived2 : Base { }; + + struct SuperDerived : Derived1, Derived2 { + using Derived1::operator int; + }; + + struct UeberDerived : SuperDerived { + operator long(); + }; + + void test2(UeberDerived ud) { + int i = ud; // expected-error{{ambiguous conversion from derived class 'rdar8018274::SuperDerived' to base class 'rdar8018274::Base'}} + } + + struct Base2 { + operator int(); + }; + + struct Base3 { + operator int(); + }; + + struct Derived23 : Base2, Base3 { + using Base2::operator int; + }; + + struct ExtraDerived23 : Derived23 { }; + + void test3(ExtraDerived23 ed) { + int i = ed; + } +} diff --git a/test/SemaCXX/copy-assignment.cpp b/test/SemaCXX/copy-assignment.cpp index bfe1501..5730b2a 100644 --- a/test/SemaCXX/copy-assignment.cpp +++ b/test/SemaCXX/copy-assignment.cpp @@ -97,3 +97,15 @@ void test() { i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}} } +// <rdar://problem/8315440>: Don't crash +// FIXME: the recovery here is really bad. +namespace test1 { + template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}} + A(UndeclaredType n) : X(n) {} // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{undeclared identifier 'n'}} expected-error {{expected ';' at end}} expected-error {{field has incomplete type}} + }; + template<typename T> class B : public A<T> { + virtual void foo() {} + }; + extern template class A<char>; // expected-note {{in instantiation}} expected-note {{not complete}} + extern template class B<char>; +} diff --git a/test/SemaCXX/crash-PR7625.cpp b/test/SemaCXX/crash-PR7625.cpp new file mode 100644 index 0000000..3ddf5e5 --- /dev/null +++ b/test/SemaCXX/crash-PR7625.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +template<typename T> struct a : T { + struct x : T { + int aa() { return p; } // expected-error{{use of undeclared identifier 'p'}} + }; +}; diff --git a/test/SemaCXX/decltype.cpp b/test/SemaCXX/decltype.cpp new file mode 100644 index 0000000..d4ef7e3 --- /dev/null +++ b/test/SemaCXX/decltype.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s + +// PR5290 +int const f0(); +void f0_test() { + decltype(0, f0()) i = 0; + i = 0; +} + +struct A { int a[1]; A() { } }; +typedef A const AC; +int &f1(int*); +float &f2(int const*); + +void test_f2() { + float &fr = f2(AC().a); +} + diff --git a/test/SemaCXX/default-constructor-initializers.cpp b/test/SemaCXX/default-constructor-initializers.cpp index 757332d..9da8556 100644 --- a/test/SemaCXX/default-constructor-initializers.cpp +++ b/test/SemaCXX/default-constructor-initializers.cpp @@ -43,7 +43,6 @@ Y4 y4; // More tests - struct Z1 { // expected-error {{must explicitly initialize the reference member 'z'}} \ // expected-error {{must explicitly initialize the const member 'c1'}} int& z; // expected-note {{declared here}} @@ -51,5 +50,12 @@ struct Z1 { // expected-error {{must explicitly initialize the reference member volatile int v1; }; +// Test default initialization which *requires* a constructor call for non-POD. Z1 z1; // expected-note {{first required here}} +// Ensure that value initialization doesn't use trivial implicit constructors. +namespace PR7948 { + // Note that this is also non-POD to ensure we don't just special case PODs. + struct S { const int x; ~S(); }; + const S arr[2] = { { 42 } }; +} diff --git a/test/SemaCXX/destructor.cpp b/test/SemaCXX/destructor.cpp index 4f6c76b..cdcae2e 100644 --- a/test/SemaCXX/destructor.cpp +++ b/test/SemaCXX/destructor.cpp @@ -103,5 +103,19 @@ namespace test6 { }; class B : A<int> { B(); }; - B::B() {} + B::B() {} // expected-note {{in instantiation of member function 'test6::A<int>::~A' requested here}} +} + +// Make sure classes are marked invalid when they have invalid +// members. This avoids a crash-on-invalid. +namespace test7 { + struct A { + ~A() const; // expected-error {{'const' qualifier is not allowed on a destructor}} + }; + struct B : A {}; + + void test() { + B *b; + b->~B(); + } } diff --git a/test/SemaCXX/enum.cpp b/test/SemaCXX/enum.cpp index 0690ead..1dc55e3 100644 --- a/test/SemaCXX/enum.cpp +++ b/test/SemaCXX/enum.cpp @@ -85,3 +85,8 @@ namespace PR7051 { // PR7466 enum { }; // expected-warning{{declaration does not declare anything}} typedef enum { }; // expected-warning{{typedef requires a name}} + +// PR7921 +enum PR7921E { + PR7921V = (PR7921E)(123) // expected-error {{expression is not an integer constant expression}} +}; diff --git a/test/SemaCXX/exception-spec.cpp b/test/SemaCXX/exception-spec.cpp index 498611e..b4bc78a 100644 --- a/test/SemaCXX/exception-spec.cpp +++ b/test/SemaCXX/exception-spec.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fms-extensions %s +// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions %s // Straight from the standard: // Plain function with spec @@ -43,18 +43,12 @@ void r2() throw(int); void r2() throw(INT); // throw-any spec and no spec at all are semantically equivalent -void r3(); -void r3() throw(...); - void r4() throw(int, float); void r4() throw(float, int); void r5() throw(int); // expected-note {{previous declaration}} void r5(); // expected-warning {{missing exception specification}} -void r6() throw(...); // expected-note {{previous declaration}} -void r6() throw(int); // expected-error {{exception specification in declaration does not match}} - void r7() throw(int); // expected-note {{previous declaration}} void r7() throw(float); // expected-error {{exception specification in declaration does not match}} @@ -89,8 +83,6 @@ struct P : private A struct Base { virtual void f1() throw(); - virtual void f2(); - virtual void f3() throw(...); virtual void f4() throw(int, float); virtual void f5() throw(int, float); @@ -107,8 +99,6 @@ struct Base struct Derived : Base { virtual void f1() throw(); - virtual void f2() throw(...); - virtual void f3(); virtual void f4() throw(float, int); virtual void f5() throw(float); diff --git a/test/SemaCXX/expressions.cpp b/test/SemaCXX/expressions.cpp index f3a05c1..b51194a 100644 --- a/test/SemaCXX/expressions.cpp +++ b/test/SemaCXX/expressions.cpp @@ -7,3 +7,10 @@ void test() { // Result of ! must be type bool. int i = choice(!1); } + +// rdar://8018252 +void f0() { + extern void f0_1(int*); + register int x; + f0_1(&x); +} diff --git a/test/SemaCXX/flexible-array-test.cpp b/test/SemaCXX/flexible-array-test.cpp index 02e3f83..95d8bb1 100644 --- a/test/SemaCXX/flexible-array-test.cpp +++ b/test/SemaCXX/flexible-array-test.cpp @@ -43,3 +43,13 @@ struct X { int blah; S strings[]; // expected-error {{flexible array member 'strings' of non-POD element type 'S []'}} }; + +class A { + int s; + char c[]; +}; + +union B { + int s; + char c[]; // expected-error {{field has incomplete type 'char []'}} +}; diff --git a/test/SemaCXX/i-c-e-cxx.cpp b/test/SemaCXX/i-c-e-cxx.cpp index 9672a42..2d08ea9 100644 --- a/test/SemaCXX/i-c-e-cxx.cpp +++ b/test/SemaCXX/i-c-e-cxx.cpp @@ -16,7 +16,7 @@ void f() { } int a() { - const int t=t; // expected-note {{subexpression not valid}} + const int t=t; switch(1) { // expected-warning {{no case matching constant switch condition '1'}} case t:; // expected-error {{not an integer constant expression}} } diff --git a/test/SemaCXX/inc-decrement-qualifiers.cpp b/test/SemaCXX/increment-decrement.cpp index ba837a9..11b7d1e 100644 --- a/test/SemaCXX/inc-decrement-qualifiers.cpp +++ b/test/SemaCXX/increment-decrement.cpp @@ -7,3 +7,8 @@ const int &dec = i--; const int &incfail = ++i; // expected-error {{drops qualifiers}} const int &decfail = --i; // expected-error {{drops qualifiers}} + +// PR7794 +void f0(int e) { + ++(int&)e; +} diff --git a/test/SemaCXX/linkage-spec.cpp b/test/SemaCXX/linkage-spec.cpp index 57730a6..86c3d3e 100644 --- a/test/SemaCXX/linkage-spec.cpp +++ b/test/SemaCXX/linkage-spec.cpp @@ -54,3 +54,35 @@ extern "C" return f2((char *)0); } } + +// PR6991 +extern "C" typedef int (*PutcFunc_t)(int); + + +// PR7859 +extern "C" void pr7859_a(int) {} // expected-note {{previous definition}} +extern "C" void pr7859_a(int) {} // expected-error {{redefinition}} + +extern "C" void pr7859_b() {} // expected-note {{previous definition}} +extern "C" void pr7859_b(int) {} // expected-error {{conflicting}} + +extern "C" void pr7859_c(short) {} // expected-note {{previous definition}} +extern "C" void pr7859_c(int) {} // expected-error {{conflicting}} + +// <rdar://problem/8318976> +extern "C" { + struct s0 { + private: + s0(); + s0(const s0 &); + }; +} + +//PR7754 +extern "C++" template <class T> int pr7754(T param); + +namespace N { + int value; +} + +extern "C++" using N::value; diff --git a/test/SemaCXX/member-expr.cpp b/test/SemaCXX/member-expr.cpp index 6830c5f..953ee48 100644 --- a/test/SemaCXX/member-expr.cpp +++ b/test/SemaCXX/member-expr.cpp @@ -101,3 +101,17 @@ namespace PR7508 { a.PopCleanupScope(); // expected-error{{no member named 'PopCleanupScope' in 'PR7508::A'}} } } + +namespace rdar8231724 { + namespace N { + template<typename T> struct X1; + int i; + } + + struct X { }; + struct Y : X { }; + + void f(Y *y) { + y->N::X1<int>; // expected-error{{'rdar8231724::N::X1' is not a member of class 'rdar8231724::Y'}} + } +} diff --git a/test/SemaCXX/member-pointer-ms.cpp b/test/SemaCXX/member-pointer-ms.cpp new file mode 100644 index 0000000..3b2d0fc --- /dev/null +++ b/test/SemaCXX/member-pointer-ms.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -cxx-abi microsoft -fsyntax-only -verify %s + +// Test that we reject pointers to members of incomplete classes (for now) +struct A; //expected-note{{forward declaration of 'A'}} +int A::*pai1; //expected-error{{incomplete type 'A'}} + +// Test that we don't allow reinterpret_casts from pointers of one size to +// pointers of a different size. +struct A {}; +struct B {}; +struct C: A, B {}; + +void (A::*paf)(); +void (C::*pcf)() = reinterpret_cast<void (C::*)()>(paf); //expected-error{{cannot reinterpret_cast from member pointer type}} diff --git a/test/SemaCXX/member-pointer.cpp b/test/SemaCXX/member-pointer.cpp index 9d5cd2f..795c0b9 100644 --- a/test/SemaCXX/member-pointer.cpp +++ b/test/SemaCXX/member-pointer.cpp @@ -79,7 +79,7 @@ void g() { void (HasMembers::*pmf)() = &HasMembers::f; void (*pnf)() = &Fake::f; - &hm.f; // expected-error {{must explicitly qualify}} expected-warning{{result unused}} + &hm.f; // expected-error {{cannot create a non-constant pointer to member function}} void (HasMembers::*pmgv)() = &HasMembers::g; void (HasMembers::*pmgi)(int) = &HasMembers::g; @@ -142,8 +142,8 @@ namespace pr5985 { void f() { void (c::*p)(); p = &h; // expected-error {{must explicitly qualify}} - p = &this->h; // expected-error {{must explicitly qualify}} - p = &(*this).h; // expected-error {{must explicitly qualify}} + p = &this->h; // expected-error {{cannot create a non-constant pointer to member function}} + p = &(*this).h; // expected-error {{cannot create a non-constant pointer to member function}} } }; } @@ -174,3 +174,99 @@ namespace PR7176 { void m() { (void)(Condition) &base::Continuous::cond; } } + +namespace rdar8358512 { + // We can't call this with an overload set because we're not allowed + // to look into overload sets unless the parameter has some kind of + // function type. + template <class F> void bind(F f); // expected-note 12 {{candidate template ignored}} + template <class F, class T> void bindmem(F (T::*f)()); // expected-note 4 {{candidate template ignored}} + template <class F> void bindfn(F (*f)()); // expected-note 4 {{candidate template ignored}} + + struct A { + void nonstat(); + void nonstat(int); + + void mixed(); + static void mixed(int); + + static void stat(); + static void stat(int); + + template <typename T> struct Test0 { + void test() { + bind(&nonstat); // expected-error {{no matching function for call}} + bind(&A::nonstat); // expected-error {{no matching function for call}} + + bind(&mixed); // expected-error {{no matching function for call}} + bind(&A::mixed); // expected-error {{no matching function for call}} + + bind(&stat); // expected-error {{no matching function for call}} + bind(&A::stat); // expected-error {{no matching function for call}} + } + }; + + template <typename T> struct Test1 { + void test() { + bindmem(&nonstat); // expected-error {{no matching function for call}} + bindmem(&A::nonstat); + + bindmem(&mixed); // expected-error {{no matching function for call}} + bindmem(&A::mixed); + + bindmem(&stat); // expected-error {{no matching function for call}} + bindmem(&A::stat); // expected-error {{no matching function for call}} + } + }; + + template <typename T> struct Test2 { + void test() { + bindfn(&nonstat); // expected-error {{no matching function for call}} + bindfn(&A::nonstat); // expected-error {{no matching function for call}} + + bindfn(&mixed); // expected-error {{no matching function for call}} + bindfn(&A::mixed); // expected-error {{no matching function for call}} + + bindfn(&stat); + bindfn(&A::stat); + } + }; + }; + + template <class T> class B { + void nonstat(); + void nonstat(int); + + void mixed(); + static void mixed(int); + + static void stat(); + static void stat(int); + + // None of these can be diagnosed yet, because the arguments are + // still dependent. + void test0a() { + bind(&nonstat); + bind(&B::nonstat); + + bind(&mixed); + bind(&B::mixed); + + bind(&stat); + bind(&B::stat); + } + + void test0b() { + bind(&nonstat); // expected-error {{no matching function for call}} + bind(&B::nonstat); // expected-error {{no matching function for call}} + + bind(&mixed); // expected-error {{no matching function for call}} + bind(&B::mixed); // expected-error {{no matching function for call}} + + bind(&stat); // expected-error {{no matching function for call}} + bind(&B::stat); // expected-error {{no matching function for call}} + } + }; + + template void B<int>::test0b(); // expected-note {{in instantiation}} +} diff --git a/test/SemaCXX/new-delete.cpp b/test/SemaCXX/new-delete.cpp index 25bf823..9a64e4c 100644 --- a/test/SemaCXX/new-delete.cpp +++ b/test/SemaCXX/new-delete.cpp @@ -310,3 +310,47 @@ namespace rdar8018245 { template int *f<X1>(); // expected-note{{in instantiation of}} } + +// <rdar://problem/8248780> +namespace Instantiate { + template<typename T> struct X { + operator T*(); + }; + + void f(X<int> &xi) { + delete xi; + } +} + +namespace PR7810 { + struct X { + // cv is ignored in arguments + static void operator delete(void *const); + }; + struct Y { + // cv is ignored in arguments + static void operator delete(void *volatile); + }; +} + +// Don't crash on template delete operators +namespace TemplateDestructors { + struct S { + virtual ~S() {} + + void* operator new(const size_t size); + template<class T> void* operator new(const size_t, const int, T*); + void operator delete(void*, const size_t); + template<class T> void operator delete(void*, const size_t, const int, T*); + }; +} + +namespace DeleteParam { + struct X { + void operator delete(X*); // expected-error{{first parameter of 'operator delete' must have type 'void *'}} + }; + + struct Y { + void operator delete(void* const); + }; +} diff --git a/test/SemaCXX/offsetof.cpp b/test/SemaCXX/offsetof.cpp index 639d7fa..17cee62 100644 --- a/test/SemaCXX/offsetof.cpp +++ b/test/SemaCXX/offsetof.cpp @@ -53,3 +53,16 @@ struct Derived2 : public Base1, public Base2 { int derived1[__builtin_offsetof(Derived2, x) == 0? 1 : -1]; int derived2[__builtin_offsetof(Derived2, y) == 4? 1 : -1]; int derived3[__builtin_offsetof(Derived2, z) == 8? 1 : -1]; + +// offsetof referring to anonymous struct in base. +// PR7769 +struct foo { + struct { + int x; + }; +}; + +struct bar : public foo { +}; + +int anonstruct[__builtin_offsetof(bar, x) == 0 ? 1 : -1]; diff --git a/test/SemaCXX/overload-call-copycon.cpp b/test/SemaCXX/overload-call-copycon.cpp index f57484e..6720cb6 100644 --- a/test/SemaCXX/overload-call-copycon.cpp +++ b/test/SemaCXX/overload-call-copycon.cpp @@ -1,40 +1,44 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -Wnon-pod-varargs -class X { }; +class X { }; // expected-note {{the implicit copy constructor}} \ + // expected-note{{the implicit default constructor}} -int& copycon(X x); +int& copycon(X x); // expected-note{{passing argument to parameter}} float& copycon(...); void test_copycon(X x, X const xc, X volatile xv) { int& i1 = copycon(x); int& i2 = copycon(xc); - float& f1 = copycon(xv); + copycon(xv); // expected-error{{no matching constructor}} } class A { public: - A(A&); + A(A&); // expected-note{{would lose const qualifier}} \ + // expected-note{{no known conversion}} }; -class B : public A { }; +class B : public A { }; // expected-note{{would lose const qualifier}} \ +// expected-note{{would lose volatile qualifier}} \ +// expected-note 2{{requires 0 arguments}} -short& copycon2(A a); -int& copycon2(B b); +short& copycon2(A a); // expected-note{{passing argument to parameter}} +int& copycon2(B b); // expected-note 2{{passing argument to parameter}} 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); // expected-warning {{cannot pass object of non-POD type}} - float& f2 = copycon2(bv); // expected-warning {{cannot pass object of non-POD type}} + copycon2(bc); // expected-error{{no matching constructor}} + copycon2(bv); // expected-error{{no matching constructor}} short& s1 = copycon2(a); - float& f3 = copycon2(ac); // expected-warning {{cannot pass object of non-POD type}} + copycon2(ac); // expected-error{{no matching constructor}} } -int& copycon3(A a); +int& copycon3(A a); // expected-note{{passing argument to parameter 'a' here}} float& copycon3(...); void test_copycon3(B b, const B bc) { int& i1 = copycon3(b); - float& f1 = copycon3(bc); // expected-warning {{cannot pass object of non-POD type}} + copycon3(bc); // expected-error{{no matching constructor}} } class C : public B { }; diff --git a/test/SemaCXX/qualified-member-enum.cpp b/test/SemaCXX/qualified-member-enum.cpp new file mode 100644 index 0000000..83b0a591 --- /dev/null +++ b/test/SemaCXX/qualified-member-enum.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// Check that this doesn't crash. +struct A { + enum {LABEL}; +}; +int f() { + return A().A::LABEL; +} + diff --git a/test/SemaCXX/return-noreturn.cpp b/test/SemaCXX/return-noreturn.cpp index 9242d12..dfd5487 100644 --- a/test/SemaCXX/return-noreturn.cpp +++ b/test/SemaCXX/return-noreturn.cpp @@ -7,9 +7,12 @@ namespace PR6884 { ~abort_struct() __attribute__((noreturn)); }; + // FIXME: Should either of these actually warn, since the destructor is + // marked noreturn? + int f() { abort_struct(); - } + } // expected-warning{{control reaches end of non-void function}} int f2() { abort_struct s; diff --git a/test/SemaCXX/return-stack-addr.cpp b/test/SemaCXX/return-stack-addr.cpp index ba64765..7d4cb96 100644 --- a/test/SemaCXX/return-stack-addr.cpp +++ b/test/SemaCXX/return-stack-addr.cpp @@ -108,5 +108,16 @@ int* ret_cpp_const_cast(const int x) { return const_cast<int*>(&x); // expected-warning {{address of stack memory}} } +// PR 7999 - handle the case where a field is itself a reference. +template <typename T> struct PR7999 { + PR7999(T& t) : value(t) {} + T& value; +}; + +struct PR7999_X {}; + +PR7999_X& PR7999_f(PR7999<PR7999_X> s) { return s.value; } // no-warning +void test_PR7999(PR7999_X& x) { (void)PR7999_f(x); } // no-warning + // TODO: test case for dynamic_cast. clang does not yet have // support for C++ classes to write such a test case. diff --git a/test/SemaCXX/scope-check.cpp b/test/SemaCXX/scope-check.cpp index cef64f6..cdc3868 100644 --- a/test/SemaCXX/scope-check.cpp +++ b/test/SemaCXX/scope-check.cpp @@ -121,3 +121,33 @@ namespace test6 { } } +// C++0x says it's okay to skip non-trivial initializers on static +// locals, and we implement that in '03 as well. +namespace test7 { + struct C { C(); }; + + void test() { + goto foo; + static C c; + foo: + return; + } +} + +// PR7789 +namespace test8 { + void test1(int c) { + switch (c) { + case 0: + int x = 56; // expected-note {{jump bypasses variable initialization}} + case 1: // expected-error {{switch case is in protected scope}} + x = 10; + } + } + + void test2() { + goto l2; // expected-error {{goto into protected scope}} + l1: int x = 5; // expected-note {{jump bypasses variable initialization}} + l2: x++; + } +} diff --git a/test/SemaCXX/switch.cpp b/test/SemaCXX/switch.cpp index 54240dc..fc13630 100644 --- a/test/SemaCXX/switch.cpp +++ b/test/SemaCXX/switch.cpp @@ -8,8 +8,7 @@ void test() { } int n = 3; - switch (n && 1) { // expected-warning {{bool}} \ - // expected-warning {{use of logical && with constant operand}} + switch (n && 1) { // expected-warning {{bool}} case 1: break; } diff --git a/test/SemaCXX/type-traits.cpp b/test/SemaCXX/type-traits.cpp index 85bd596..b05dd07 100644 --- a/test/SemaCXX/type-traits.cpp +++ b/test/SemaCXX/type-traits.cpp @@ -34,6 +34,37 @@ typedef Derives NonPODAr[10]; typedef HasVirt VirtAr[10]; union NonPODUnion { int i; Derives n; }; +struct HasNoThrowCopyAssign { + void operator =(const HasNoThrowCopyAssign&) throw(); +}; +struct HasMultipleCopyAssign { + void operator =(const HasMultipleCopyAssign&) throw(); + void operator =(volatile HasMultipleCopyAssign&); +}; +struct HasMultipleNoThrowCopyAssign { + void operator =(const HasMultipleNoThrowCopyAssign&) throw(); + void operator =(volatile HasMultipleNoThrowCopyAssign&) throw(); +}; + +struct HasNoThrowConstructor { HasNoThrowConstructor() throw(); }; +struct HasNoThrowConstructorWithArgs { + HasNoThrowConstructorWithArgs(HasCons i = HasCons(0)) throw(); +}; + +struct HasNoThrowCopy { HasNoThrowCopy(const HasNoThrowCopy&) throw(); }; +struct HasMultipleCopy { + HasMultipleCopy(const HasMultipleCopy&) throw(); + HasMultipleCopy(volatile HasMultipleCopy&); +}; +struct HasMultipleNoThrowCopy { + HasMultipleNoThrowCopy(const HasMultipleNoThrowCopy&) throw(); + HasMultipleNoThrowCopy(volatile HasMultipleNoThrowCopy&) throw(); +}; + +struct HasVirtDest { virtual ~HasVirtDest(); }; +struct DerivedVirtDest : HasVirtDest {}; +typedef HasVirtDest VirtDestAr[1]; + void is_pod() { int t01[T(__is_pod(int))]; @@ -258,3 +289,102 @@ void f() { int t01[T(!__has_trivial_destructor(A))]; int t02[T(!__has_trivial_destructor(B<int>))]; } + +void has_nothrow_assign() { + int t01[T(__has_nothrow_assign(Int))]; + int t02[T(__has_nothrow_assign(IntAr))]; + int t03[T(__has_nothrow_assign(Union))]; + int t04[T(__has_nothrow_assign(UnionAr))]; + int t05[T(__has_nothrow_assign(POD))]; + int t06[T(__has_nothrow_assign(Derives))]; + int t07[F(__has_nothrow_assign(ConstIntAr))]; + int t08[F(__has_nothrow_assign(ConstIntArAr))]; + int t09[T(__has_nothrow_assign(HasDest))]; + int t10[T(__has_nothrow_assign(HasPriv))]; + int t11[T(__has_nothrow_assign(HasCons))]; + int t12[T(__has_nothrow_assign(HasRef))]; + int t13[T(__has_nothrow_assign(HasCopy))]; + int t14[F(__has_nothrow_assign(IntRef))]; + int t15[F(__has_nothrow_assign(HasCopyAssign))]; + 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))]; +} + +void has_nothrow_copy() { + int t01[T(__has_nothrow_copy(Int))]; + int t02[T(__has_nothrow_copy(IntAr))]; + int t03[T(__has_nothrow_copy(Union))]; + int t04[T(__has_nothrow_copy(UnionAr))]; + int t05[T(__has_nothrow_copy(POD))]; + int t06[T(__has_nothrow_copy(Derives))]; + int t07[T(__has_nothrow_copy(ConstIntAr))]; + int t08[T(__has_nothrow_copy(ConstIntArAr))]; + int t09[T(__has_nothrow_copy(HasDest))]; + int t10[T(__has_nothrow_copy(HasPriv))]; + int t11[T(__has_nothrow_copy(HasCons))]; + int t12[T(__has_nothrow_copy(HasRef))]; + int t13[F(__has_nothrow_copy(HasCopy))]; + int t14[T(__has_nothrow_copy(IntRef))]; + int t15[T(__has_nothrow_copy(HasCopyAssign))]; + int t16[T(__has_nothrow_copy(const Int))]; + int t17[F(__has_nothrow_copy(NonPODAr))]; + int t18[F(__has_nothrow_copy(VirtAr))]; + + int t19[T(__has_nothrow_copy(HasNoThrowCopy))]; + int t20[F(__has_nothrow_copy(HasMultipleCopy))]; + int t21[T(__has_nothrow_copy(HasMultipleNoThrowCopy))]; +} + +void has_nothrow_constructor() { + int t01[T(__has_nothrow_constructor(Int))]; + int t02[T(__has_nothrow_constructor(IntAr))]; + int t03[T(__has_nothrow_constructor(Union))]; + int t04[T(__has_nothrow_constructor(UnionAr))]; + int t05[T(__has_nothrow_constructor(POD))]; + int t06[T(__has_nothrow_constructor(Derives))]; + int t07[T(__has_nothrow_constructor(ConstIntAr))]; + int t08[T(__has_nothrow_constructor(ConstIntArAr))]; + int t09[T(__has_nothrow_constructor(HasDest))]; + int t10[T(__has_nothrow_constructor(HasPriv))]; + int t11[F(__has_nothrow_constructor(HasCons))]; + int t12[F(__has_nothrow_constructor(HasRef))]; + int t13[F(__has_nothrow_constructor(HasCopy))]; + int t14[F(__has_nothrow_constructor(IntRef))]; + int t15[T(__has_nothrow_constructor(HasCopyAssign))]; + int t16[T(__has_nothrow_constructor(const Int))]; + int t17[T(__has_nothrow_constructor(NonPODAr))]; + // int t18[T(__has_nothrow_constructor(VirtAr))]; // not implemented + + int t19[T(__has_nothrow_constructor(HasNoThrowConstructor))]; + int t20[F(__has_nothrow_constructor(HasNoThrowConstructorWithArgs))]; +} + +void has_virtual_destructor() { + int t01[F(__has_virtual_destructor(Int))]; + int t02[F(__has_virtual_destructor(IntAr))]; + int t03[F(__has_virtual_destructor(Union))]; + int t04[F(__has_virtual_destructor(UnionAr))]; + int t05[F(__has_virtual_destructor(POD))]; + int t06[F(__has_virtual_destructor(Derives))]; + int t07[F(__has_virtual_destructor(ConstIntAr))]; + int t08[F(__has_virtual_destructor(ConstIntArAr))]; + int t09[F(__has_virtual_destructor(HasDest))]; + int t10[F(__has_virtual_destructor(HasPriv))]; + int t11[F(__has_virtual_destructor(HasCons))]; + int t12[F(__has_virtual_destructor(HasRef))]; + int t13[F(__has_virtual_destructor(HasCopy))]; + int t14[F(__has_virtual_destructor(IntRef))]; + int t15[F(__has_virtual_destructor(HasCopyAssign))]; + int t16[F(__has_virtual_destructor(const Int))]; + int t17[F(__has_virtual_destructor(NonPODAr))]; + int t18[F(__has_virtual_destructor(VirtAr))]; + + int t19[T(__has_virtual_destructor(HasVirtDest))]; + int t20[T(__has_virtual_destructor(DerivedVirtDest))]; + int t21[F(__has_virtual_destructor(VirtDestAr))]; +} diff --git a/test/SemaCXX/unary-real-imag.cpp b/test/SemaCXX/unary-real-imag.cpp new file mode 100644 index 0000000..91b63e3 --- /dev/null +++ b/test/SemaCXX/unary-real-imag.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +struct A {}; +int i = __real__ A(); // expected-error {{invalid type 'A' to __real operator}} +int j = __imag__ A(); // expected-error {{invalid type 'A' to __imag operator}} + diff --git a/test/SemaCXX/unreachable-code.cpp b/test/SemaCXX/unreachable-code.cpp index 528bba7..40d0c00 100644 --- a/test/SemaCXX/unreachable-code.cpp +++ b/test/SemaCXX/unreachable-code.cpp @@ -39,3 +39,20 @@ void test3() { bar(); // expected-warning {{will never be executed}} } } + +// PR 6130 - Don't warn about bogus unreachable code with throw's and +// temporary objects. +class PR6130 { +public: + PR6130(); + ~PR6130(); +}; + +int pr6130(unsigned i) { + switch(i) { + case 0: return 1; + case 1: return 2; + default: + throw PR6130(); // no-warning + } +} diff --git a/test/SemaCXX/vector-no-lax.cpp b/test/SemaCXX/vector-no-lax.cpp new file mode 100644 index 0000000..32dcacf --- /dev/null +++ b/test/SemaCXX/vector-no-lax.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -fno-lax-vector-conversions -verify %s +typedef unsigned int __attribute__((vector_size (16))) vUInt32; +typedef int __attribute__((vector_size (16))) vSInt32; + +vSInt32 foo (vUInt32 a) { + vSInt32 b = { 0, 0, 0, 0 }; + b += a; // expected-error{{can't convert between vector values}} + return b; +} diff --git a/test/SemaCXX/vector.cpp b/test/SemaCXX/vector.cpp index 66b2d68..9ae2c82 100644 --- a/test/SemaCXX/vector.cpp +++ b/test/SemaCXX/vector.cpp @@ -51,10 +51,10 @@ void conditional(bool Cond, char16 c16, longlong16 ll16, char16_e c16e, __typeof__(Cond? ll16 : ll16e) *ll16ep2 = &ll16e; __typeof__(Cond? ll16e : ll16) *ll16ep3 = &ll16e; - // Conditional operators with incompatible types. - (void)(Cond? c16 : ll16); // expected-error{{can't convert between vector values}} - (void)(Cond? ll16e : c16e); // expected-error{{can't convert between vector values}} - (void)(Cond? ll16e : c16); // expected-error{{can't convert between vector values}} + // Conditional operators with compatible types under -flax-vector-conversions (default) + (void)(Cond? c16 : ll16); + (void)(Cond? ll16e : c16e); + (void)(Cond? ll16e : c16); } // Test C++ cast'ing of vector types. @@ -183,8 +183,10 @@ void test_implicit_conversions(bool Cond, char16 c16, longlong16 ll16, (void)(Cond? to_c16 : to_c16e); (void)(Cond? to_ll16e : to_ll16); - (void)(Cond? to_c16 : to_ll16); // expected-error{{can't convert between vector values of different size}} - (void)(Cond? to_c16e : to_ll16e); // expected-error{{can't convert between vector values of different size}} + + // These 2 are convertable with -flax-vector-conversions (default) + (void)(Cond? to_c16 : to_ll16); + (void)(Cond? to_c16e : to_ll16e); } typedef float fltx2 __attribute__((__vector_size__(8))); diff --git a/test/SemaCXX/virtual-base-used.cpp b/test/SemaCXX/virtual-base-used.cpp new file mode 100644 index 0000000..d147b13 --- /dev/null +++ b/test/SemaCXX/virtual-base-used.cpp @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// PR7800 + +class NoDestroy { ~NoDestroy(); }; // expected-note 3 {{declared private here}} +struct A { + virtual ~A(); +}; + +struct B : public virtual A { + NoDestroy x; // expected-error {{field of type 'NoDestroy' has private destructor}} +}; +struct D : public virtual B { + virtual void foo(); + ~D(); +}; +void D::foo() { // expected-note {{implicit default destructor for 'B' first required here}} +} + +struct E : public virtual A { + NoDestroy x; // expected-error {{field of type 'NoDestroy' has private destructor}} +}; +struct F : public E { // expected-note {{implicit default destructor for 'E' first required here}} +}; +struct G : public virtual F { + virtual void foo(); + ~G(); +}; +void G::foo() { // expected-note {{implicit default destructor for 'F' first required here}} +} + +struct H : public virtual A { + NoDestroy x; // expected-error {{field of type 'NoDestroy' has private destructor}} +}; +struct I : public virtual H { + ~I(); +}; +struct J : public I { + virtual void foo(); + ~J(); +}; +void J::foo() { // expected-note {{implicit default destructor for 'H' first required here}} +} diff --git a/test/SemaCXX/warn-cast-align.cpp b/test/SemaCXX/warn-cast-align.cpp new file mode 100644 index 0000000..68acbdd --- /dev/null +++ b/test/SemaCXX/warn-cast-align.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -Wcast-align -verify %s + +// Simple casts. +void test0(char *P) { + char *a; short *b; int *c; + + a = (char*) P; + a = static_cast<char*>(P); + a = reinterpret_cast<char*>(P); + typedef char *CharPtr; + a = CharPtr(P); + + b = (short*) P; // expected-warning {{cast from 'char *' to 'short *' increases required alignment from 1 to 2}} + b = reinterpret_cast<short*>(P); + typedef short *ShortPtr; + b = ShortPtr(P); // expected-warning {{cast from 'char *' to 'ShortPtr' (aka 'short *') increases required alignment from 1 to 2}} + + c = (int*) P; // expected-warning {{cast from 'char *' to 'int *' increases required alignment from 1 to 4}} + c = reinterpret_cast<int*>(P); + typedef int *IntPtr; + c = IntPtr(P); // expected-warning {{cast from 'char *' to 'IntPtr' (aka 'int *') increases required alignment from 1 to 4}} +} + +// Casts from void* are a special case. +void test1(void *P) { + char *a; short *b; int *c; + + a = (char*) P; + a = static_cast<char*>(P); + a = reinterpret_cast<char*>(P); + typedef char *CharPtr; + a = CharPtr(P); + + b = (short*) P; + b = static_cast<short*>(P); + b = reinterpret_cast<short*>(P); + typedef short *ShortPtr; + b = ShortPtr(P); + + c = (int*) P; + c = static_cast<int*>(P); + c = reinterpret_cast<int*>(P); + typedef int *IntPtr; + c = IntPtr(P); +} diff --git a/test/SemaCXX/warn-for-var-in-else.cpp b/test/SemaCXX/warn-for-var-in-else.cpp deleted file mode 100644 index 1307c43..0000000 --- a/test/SemaCXX/warn-for-var-in-else.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -verify %s -// rdar://6425550 -int bar(); -void do_something(int); -int *get_ptr(); - -int foo() { - if (int X = bar()) { - return X; - } else { - do_something(X); // expected-warning{{'X' is always zero in this context}} - return 0; - } -} - -bool foo2() { - if (bool B = bar()) { - if (int Y = bar()) { - return B; - } else { - do_something(Y); // expected-warning{{'Y' is always zero in this context}} - return B; - } - } else { - if (bool B2 = B) { // expected-warning{{'B' is always false in this context}} - do_something(B); // expected-warning{{'B' is always false in this context}} - } else if (B2) { // expected-warning{{'B2' is always false in this context}} - do_something(B); // expected-warning{{'B' is always false in this context}} - do_something(B2); // expected-warning{{'B2' is always false in this context}} - } - return B; // expected-warning{{'B' is always false in this context}} - } -} - -void foo3() { - if (int *P1 = get_ptr()) - do_something(*P1); - else if (int *P2 = get_ptr()) { - do_something(*P1); // expected-warning{{'P1' is always NULL in this context}} - do_something(*P2); - } else { - do_something(*P1); // expected-warning{{'P1' is always NULL in this context}} - do_something(*P2); // expected-warning{{'P2' is always NULL in this context}} - } -} diff --git a/test/SemaCXX/warn-global-constructors.cpp b/test/SemaCXX/warn-global-constructors.cpp new file mode 100644 index 0000000..107bbe1 --- /dev/null +++ b/test/SemaCXX/warn-global-constructors.cpp @@ -0,0 +1,81 @@ +// RUN: %clang_cc1 -fsyntax-only -Wglobal-constructors %s -verify + +int opaque_int(); + +namespace test0 { + // These should never require global constructors. + int a; + int b = 20; + float c = 5.0f; + + // This global constructor is avoidable based on initialization order. + int d = b; // expected-warning {{global constructor}} + + // These global constructors are unavoidable. + int e = opaque_int(); // expected-warning {{global constructor}} + int f = b; // expected-warning {{global constructor}} +} + +namespace test1 { + struct A { int x; }; + A a; + A b = A(); + A c = { 10 }; + A d = { opaque_int() }; // expected-warning {{global constructor}} + A e = A(A()); + A f = A(a); // expected-warning {{global constructor}} + A g(a); // expected-warning {{global constructor}} + A h((A())); // expected-warning {{global constructor}} + A i((A(A()))); // expected-warning {{global constructor}} +} + +namespace test2 { + struct A { A(); }; + A a; // expected-warning {{global constructor}} + A b[10]; // expected-warning {{global constructor}} + A c[10][10]; // expected-warning {{global constructor}} + + A &d = a; + A &e = b[5]; + A &f = c[5][7]; +} + +namespace test3 { + struct A { ~A(); }; + A a; // expected-warning {{global destructor}} + A b[10]; // expected-warning {{global destructor}} + A c[10][10]; // expected-warning {{global destructor}} + + A &d = a; + A &e = b[5]; + A &f = c[5][7]; +} + +namespace test4 { + char a[] = "hello"; + char b[5] = "hello"; + char c[][5] = { "hello" }; +} + +namespace test5 { + struct A { A(); }; + + void f1() { + static A a; + } + void f2() { + static A& a = *new A; + } +} + +namespace test6 { + struct A { ~A(); }; + + void f1() { + static A a; // expected-warning {{global destructor}} + } + void f2() { + static A& a = *new A; + } + +}
\ No newline at end of file diff --git a/test/SemaCXX/warn-unused-filescoped.cpp b/test/SemaCXX/warn-unused-filescoped.cpp new file mode 100644 index 0000000..75fc6a4 --- /dev/null +++ b/test/SemaCXX/warn-unused-filescoped.cpp @@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-member-function %s + +static void f1(); // expected-warning{{unused}} + +namespace { + void f2(); // expected-warning{{unused}} + + void f3() { } // expected-warning{{unused}} + + struct S { + void m1() { } // expected-warning{{unused}} + void m2(); // expected-warning{{unused}} + void m3(); + S(const S&); + void operator=(const S&); + }; + + template <typename T> + struct TS { + void m(); + }; + template <> void TS<int>::m() { } // expected-warning{{unused}} + + template <typename T> + void tf() { } + template <> void tf<int>() { } // expected-warning{{unused}} + + struct VS { + virtual void vm() { } + }; + + struct SVS : public VS { + void vm() { } + }; +} + +void S::m3() { } // expected-warning{{unused}} + +static inline void f4() { } +const unsigned int cx = 0; + +static int x1; // expected-warning{{unused}} + +namespace { + int x2; // expected-warning{{unused}} + + struct S2 { + static int x; // expected-warning{{unused}} + }; + + template <typename T> + struct TS2 { + static int x; + }; + template <> int TS2<int>::x; // expected-warning{{unused}} +} |