diff options
author | Roman Divacky <rdivacky@FreeBSD.org> | 2009-10-23 14:22:18 +0000 |
---|---|---|
committer | Roman Divacky <rdivacky@FreeBSD.org> | 2009-10-23 14:22:18 +0000 |
commit | 73490b890977362d28dd6326843a1ecae413921d (patch) | |
tree | 3fdd91eae574e32453a4baf462961c742df2691a /test/SemaCXX | |
parent | a5f348eb914e67b51914117fac117c18c1f8d650 (diff) |
Notes
Diffstat (limited to 'test/SemaCXX')
-rw-r--r-- | test/SemaCXX/abstract.cpp | 15 | ||||
-rw-r--r-- | test/SemaCXX/ambiguous-builtin-unary-operator.cpp | 18 | ||||
-rw-r--r-- | test/SemaCXX/bool.cpp | 12 | ||||
-rw-r--r-- | test/SemaCXX/builtin-ptrtomember-ambig.cpp | 5 | ||||
-rw-r--r-- | test/SemaCXX/builtin-ptrtomember-overload.cpp | 12 | ||||
-rw-r--r-- | test/SemaCXX/exception-spec.cpp | 3 | ||||
-rw-r--r-- | test/SemaCXX/incomplete-call.cpp | 7 | ||||
-rw-r--r-- | test/SemaCXX/member-expr.cpp | 11 | ||||
-rw-r--r-- | test/SemaCXX/overloaded-builtin-operators.cpp | 25 | ||||
-rw-r--r-- | test/SemaCXX/overloaded-operator.cpp | 2 | ||||
-rw-r--r-- | test/SemaCXX/ptrtomember-overload-resolution.cpp | 44 | ||||
-rw-r--r-- | test/SemaCXX/static-cast.cpp | 11 | ||||
-rw-r--r-- | test/SemaCXX/switch.cpp | 15 |
13 files changed, 177 insertions, 3 deletions
diff --git a/test/SemaCXX/abstract.cpp b/test/SemaCXX/abstract.cpp index e14304a26fe3d..42b8d7febe655 100644 --- a/test/SemaCXX/abstract.cpp +++ b/test/SemaCXX/abstract.cpp @@ -123,3 +123,18 @@ struct K { struct L : public K { void f(); }; + +// PR5222 +namespace PR5222 { + struct A { + virtual A *clone() = 0; + }; + struct B : public A { + virtual B *clone() = 0; + }; + struct C : public B { + virtual C *clone(); + }; + + C c; +} diff --git a/test/SemaCXX/ambiguous-builtin-unary-operator.cpp b/test/SemaCXX/ambiguous-builtin-unary-operator.cpp index 042546af69024..5affd19a2fdf0 100644 --- a/test/SemaCXX/ambiguous-builtin-unary-operator.cpp +++ b/test/SemaCXX/ambiguous-builtin-unary-operator.cpp @@ -2,17 +2,33 @@ struct A { operator int&(); + operator long*& (); }; struct B { operator long&(); + operator int*& (); }; struct C : B, A { }; void test(C c) { ++c; // expected-error {{use of overloaded operator '++' is ambiguous}}\ - // expected-note 4 {{built-in candidate operator ++ (}} + // expected-note {{built-in candidate operator++(int &)}} \ + // expected-note {{built-in candidate operator++(long &)}} \ + // expected-note {{built-in candidate operator++(long *&)}} \ + // expected-note {{built-in candidate operator++(int *&)}} } +struct A1 { operator volatile int&(); }; + +struct B1 { operator volatile long&(); }; + +struct C1 : B1, A1 { }; + +void test(C1 c) { + ++c; // expected-error {{use of overloaded operator '++' is ambiguous}} \ + // expected-note {{built-in candidate operator++(int volatile &)}} \ + // expected-note {{built-in candidate operator++(long volatile &)}} +} diff --git a/test/SemaCXX/bool.cpp b/test/SemaCXX/bool.cpp index bc44c73d8cace..259c09c6cb833 100644 --- a/test/SemaCXX/bool.cpp +++ b/test/SemaCXX/bool.cpp @@ -16,3 +16,15 @@ void test(bool b) bool *b1 = (int *)0; // expected-error{{expected 'bool *'}} } + +// static_assert_arg_is_bool(x) compiles only if x is a bool. +template <typename T> +void static_assert_arg_is_bool(T x) { + bool* p = &x; +} + +void test2() { + int n = 2; + static_assert_arg_is_bool(n && 4); + static_assert_arg_is_bool(n || 5); +} diff --git a/test/SemaCXX/builtin-ptrtomember-ambig.cpp b/test/SemaCXX/builtin-ptrtomember-ambig.cpp index 7e20af35394b8..1b52651910d95 100644 --- a/test/SemaCXX/builtin-ptrtomember-ambig.cpp +++ b/test/SemaCXX/builtin-ptrtomember-ambig.cpp @@ -19,6 +19,9 @@ struct C : B { void foo(C c, int A::* pmf) { // FIXME. Why so many built-in candidates? int i = c->*pmf; // expected-error {{use of overloaded operator '->*' is ambiguous}} \ - // expected-note 40 {{built-in candidate operator ->* ('struct A}} + // expected-note {{built-in candidate operator->*(struct A const *, int const struct A::*)}} \ + // expected-note {{built-in candidate operator->*(struct A const *, int struct A::*)}} \ + // expected-note {{built-in candidate operator->*(struct A *, int const struct A::*)}} \ + // expected-note {{built-in candidate operator->*(struct A *, int struct A::*)}} } diff --git a/test/SemaCXX/builtin-ptrtomember-overload.cpp b/test/SemaCXX/builtin-ptrtomember-overload.cpp index 718e981805aa6..ed52d47f2cda7 100644 --- a/test/SemaCXX/builtin-ptrtomember-overload.cpp +++ b/test/SemaCXX/builtin-ptrtomember-overload.cpp @@ -16,3 +16,15 @@ void foo(C c, B b, int A::* pmf) { int i = b->*pmf; } +struct D { + operator const D *(); +}; + +struct DPtr { + operator volatile int D::*(); +}; + +int test(D d, DPtr dptr) { + return d->*dptr; +} + diff --git a/test/SemaCXX/exception-spec.cpp b/test/SemaCXX/exception-spec.cpp index 9b2a07d796543..56cc435f7db3a 100644 --- a/test/SemaCXX/exception-spec.cpp +++ b/test/SemaCXX/exception-spec.cpp @@ -185,3 +185,6 @@ void mfnptr() 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); }; diff --git a/test/SemaCXX/incomplete-call.cpp b/test/SemaCXX/incomplete-call.cpp index 08bfdefd62478..3ce898a76f2cc 100644 --- a/test/SemaCXX/incomplete-call.cpp +++ b/test/SemaCXX/incomplete-call.cpp @@ -40,3 +40,10 @@ void g() { (b.*mfp)(); // expected-error {{calling function with incomplete return type 'struct A'}} } + + +struct C; // expected-note{{forward declaration}} + +void test_incomplete_object_call(C& c) { + c(); // expected-error{{incomplete type in call to object of type}} +} diff --git a/test/SemaCXX/member-expr.cpp b/test/SemaCXX/member-expr.cpp index 28b1224d8d8fb..069f52605b92e 100644 --- a/test/SemaCXX/member-expr.cpp +++ b/test/SemaCXX/member-expr.cpp @@ -31,3 +31,14 @@ int f0(B *b) { return b->f0->f0; // expected-error{{member reference base type 'struct A *()' is not a structure or union}} \ // expected-note{{perhaps you meant to call this function}} } + +int i; + +namespace C { + int i; +} + +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'}} +} diff --git a/test/SemaCXX/overloaded-builtin-operators.cpp b/test/SemaCXX/overloaded-builtin-operators.cpp index 0284b2929b3c0..13777daf2d20b 100644 --- a/test/SemaCXX/overloaded-builtin-operators.cpp +++ b/test/SemaCXX/overloaded-builtin-operators.cpp @@ -150,3 +150,28 @@ void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr, void test_assign_restrictions(ShortRef& sr) { sr = (short)0; // expected-error{{no viable overloaded '='}} } + +struct Base { }; +struct Derived1 : Base { }; +struct Derived2 : Base { }; + +template<typename T> +struct ConvertibleToPtrOf { + operator T*(); +}; + +bool test_with_base_ptrs(ConvertibleToPtrOf<Derived1> d1, + ConvertibleToPtrOf<Derived2> d2) { + return d1 == d2; // expected-error{{invalid operands}} +} + +// DR425 +struct A { + template< typename T > operator T() const; +}; + +void test_dr425(A a) { + // FIXME: lots of candidates here! + (void)(1.0f * a); // expected-error{{ambiguous}} \ + // expected-note 81{{candidate}} +} diff --git a/test/SemaCXX/overloaded-operator.cpp b/test/SemaCXX/overloaded-operator.cpp index 8f71ad5381382..10b0f5a76804f 100644 --- a/test/SemaCXX/overloaded-operator.cpp +++ b/test/SemaCXX/overloaded-operator.cpp @@ -155,7 +155,7 @@ typedef INTREF Func1(FLOAT, double); typedef float& Func2(int, double); struct ConvertToFunc { - operator Func1*(); // expected-note{{conversion candidate of type 'INTREF (*)(float, double)'}} + operator Func1*(); // expected-note{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}} operator Func2&(); // expected-note{{conversion candidate of type 'float &(&)(int, double)'}} void operator()(); }; diff --git a/test/SemaCXX/ptrtomember-overload-resolution.cpp b/test/SemaCXX/ptrtomember-overload-resolution.cpp new file mode 100644 index 0000000000000..b3b65ce840cbf --- /dev/null +++ b/test/SemaCXX/ptrtomember-overload-resolution.cpp @@ -0,0 +1,44 @@ +// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x + +// 13.3.3.2 Ranking implicit conversion sequences +// conversion of A::* to B::* is better than conversion of A::* to C::*, +struct A { +int Ai; +}; + +struct B : public A {}; +struct C : public B {}; + +const char * f(int C::*){ return ""; } +int f(int B::*) { return 1; } + +struct D : public C {}; + +const char * g(int B::*){ return ""; } +int g(int D::*) { return 1; } + +void test() +{ + int i = f(&A::Ai); + + const char * str = g(&A::Ai); +} + +// conversion of B::* to C::* is better than conversion of A::* to C::* +typedef void (A::*pmfa)(); +typedef void (B::*pmfb)(); +typedef void (C::*pmfc)(); + +struct X { + operator pmfa(); + operator pmfb(); +}; + + +void g(pmfc); + +void test2(X x) +{ + g(x); +} + diff --git a/test/SemaCXX/static-cast.cpp b/test/SemaCXX/static-cast.cpp index 8db8e33b93ce1..d816c05e3ee37 100644 --- a/test/SemaCXX/static-cast.cpp +++ b/test/SemaCXX/static-cast.cpp @@ -133,3 +133,14 @@ void t_529_9() (void)static_cast<int A::*>((int H::*)0); // expected-error {{ambiguous conversion from pointer to member of derived class 'struct H'}} (void)static_cast<int A::*>((int F::*)0); // expected-error {{conversion from pointer to member of class 'struct F'}} } + +// PR 5261 - static_cast should instantiate template if possible +namespace pr5261 { + struct base {}; + template<typename E> struct derived : public base {}; + template<typename E> struct outer { + base *pb; + ~outer() { (void)static_cast<derived<E>*>(pb); } + }; + outer<int> EntryList; +} diff --git a/test/SemaCXX/switch.cpp b/test/SemaCXX/switch.cpp new file mode 100644 index 0000000000000..b22adb749576a --- /dev/null +++ b/test/SemaCXX/switch.cpp @@ -0,0 +1,15 @@ +// RUN: clang-cc -fsyntax-only -verify %s + +void test() { + bool x = true; + switch (x) { // expected-warning {{bool}} + case 0: + break; + } + + int n = 3; + switch (n && 1) { // expected-warning {{bool}} + case 1: + break; + } +} |