diff options
Diffstat (limited to 'test/SemaCXX')
29 files changed, 350 insertions, 127 deletions
diff --git a/test/SemaCXX/aggregate-initialization.cpp b/test/SemaCXX/aggregate-initialization.cpp index 255b3529823ee..ac482151fac1a 100644 --- a/test/SemaCXX/aggregate-initialization.cpp +++ b/test/SemaCXX/aggregate-initialization.cpp @@ -26,3 +26,7 @@ NonAggr1 na1 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr1' c NonAggr2 na2 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr2' cannot be initialized with an initializer list}} NonAggr3 na3 = { 17 }; // expected-error{{non-aggregate type 'class NonAggr3' cannot be initialized with an initializer list}} NonAggr4 na4 = { 17 }; // expected-error{{non-aggregate type 'struct NonAggr4' cannot be initialized with an initializer list}} + +// PR5817 +typedef int type[][2]; +const type foo = {0}; diff --git a/test/SemaCXX/ambig-user-defined-conversions.cpp b/test/SemaCXX/ambig-user-defined-conversions.cpp index 0820bc93c39f9..5e0a2e3766f88 100644 --- a/test/SemaCXX/ambig-user-defined-conversions.cpp +++ b/test/SemaCXX/ambig-user-defined-conversions.cpp @@ -1,52 +1,58 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -// Test1 -struct BASE { - operator int &(); // expected-note {{candidate function}} -}; -struct BASE1 { - operator int &(); // expected-note {{candidate function}} -}; - -struct B : public BASE, BASE1 { - -}; - -extern B f(); - -B b1; -void func(const int ci, const char cc); // expected-note {{candidate function}} -void func(const char ci, const B b); // expected-note {{candidate function}} -void func(const B b, const int ci); // expected-note {{candidate function}} - -const int Test1() { - func(b1, f()); // expected-error {{call to 'func' is ambiguous}} - return f(); // expected-error {{conversion from 'struct B' to 'int const' is ambiguous}} +namespace test0 { + struct BASE { + operator int &(); // expected-note {{candidate function}} + }; + struct BASE1 { + operator int &(); // expected-note {{candidate function}} + }; + + struct B : public BASE, BASE1 {}; + + extern B f(); + B b1; + + void func(const int ci, const char cc); // expected-note {{candidate function}} + void func(const char ci, const B b); // expected-note {{candidate function}} + void func(const B b, const int ci); // expected-note {{candidate function}} + + const int Test1() { + func(b1, f()); // expected-error {{call to 'func' is ambiguous}} + return f(); // expected-error {{conversion from 'struct test0::B' to 'int const' is ambiguous}} + } + + // This used to crash when comparing the two operands. + void func2(const char cc); // expected-note {{candidate function}} + void func2(const int ci); // expected-note {{candidate function}} + void Test2() { + func2(b1); // expected-error {{call to 'func2' is ambiguous}} + } } - -// Test2 -struct E; -struct A { - A (E&); -}; - -struct E { - operator A (); -}; - -struct C { - C (E&); -}; - -void f1(A); // expected-note {{candidate function}} -void f1(C); // expected-note {{candidate function}} - -void Test2() -{ - E b; - f1(b); // expected-error {{call to 'f1' is ambiguous}} - // ambiguous because b -> C via constructor and - // b → A via constructor or conversion function. +namespace test1 { + struct E; + struct A { + A (E&); + }; + + struct E { + operator A (); + }; + + struct C { + C (E&); + }; + + void f1(A); // expected-note {{candidate function}} + void f1(C); // expected-note {{candidate function}} + + void Test2() + { + E b; + f1(b); // expected-error {{call to 'f1' is ambiguous}} + // ambiguous because b -> C via constructor and + // b → A via constructor or conversion function. + } } diff --git a/test/SemaCXX/attr-unavailable.cpp b/test/SemaCXX/attr-unavailable.cpp index bebd4cb18e5da..8b381dfe4b25b 100644 --- a/test/SemaCXX/attr-unavailable.cpp +++ b/test/SemaCXX/attr-unavailable.cpp @@ -1,7 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -int &foo(int); -double &foo(double); +int &foo(int); // expected-note {{candidate}} +double &foo(double); // expected-note {{candidate}} void foo(...) __attribute__((__unavailable__)); // expected-note {{candidate function}} \ // expected-note{{function has been explicitly marked unavailable here}} diff --git a/test/SemaCXX/builtin-ptrtomember-overload-1.cpp b/test/SemaCXX/builtin-ptrtomember-overload-1.cpp index 137503b2a4e0c..b1b0b98b3c063 100644 --- a/test/SemaCXX/builtin-ptrtomember-overload-1.cpp +++ b/test/SemaCXX/builtin-ptrtomember-overload-1.cpp @@ -40,7 +40,7 @@ void foo1(C1 c1, int A::* pmf) { } void foo1(C1 c1, int E::* pmf) { - // FIXME. Error reporting needs much improvement here. - int i = c1->*pmf; // expected-error {{left hand operand to ->* must be a pointer to class compatible with the right hand operand, but is 'struct C1'}} \ - // expected-note {{because of ambiguity in conversion of 'struct C1' to 'struct E *'}} + int i = c1->*pmf; // expected-error {{use of overloaded operator '->*' is ambiguous}} \ + // expected-note {{because of ambiguity in conversion of 'struct C1' to 'struct E *'}} \ + // expected-note 4 {{built-in candidate operator}} } diff --git a/test/SemaCXX/composite-pointer-type.cpp b/test/SemaCXX/composite-pointer-type.cpp index 829e64f6c72ed..fdf838ffa09a0 100644 --- a/test/SemaCXX/composite-pointer-type.cpp +++ b/test/SemaCXX/composite-pointer-type.cpp @@ -43,3 +43,10 @@ int f2() { IntPtrPtr j = 0; return i != j; } + +// PR5763 +typedef double Matrix4[4][4]; + +bool f(Matrix4 m1, const Matrix4 m2) { + return m1 != m2; +} diff --git a/test/SemaCXX/condition.cpp b/test/SemaCXX/condition.cpp index a0b57e1baa53a..fe802d0555ed4 100644 --- a/test/SemaCXX/condition.cpp +++ b/test/SemaCXX/condition.cpp @@ -16,8 +16,8 @@ void test() { for (;s;) ; // expected-error {{value of type 'struct S' is not contextually convertible to 'bool'}} switch (s) {} // expected-error {{statement requires expression of integer type ('struct S' invalid)}} - 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 function}} - 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 function}} + 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}} if (int x=0) { // expected-note 2 {{previous definition is here}} diff --git a/test/SemaCXX/conditional-expr.cpp b/test/SemaCXX/conditional-expr.cpp index 0617cd5702c65..b71133bfeec86 100644 --- a/test/SemaCXX/conditional-expr.cpp +++ b/test/SemaCXX/conditional-expr.cpp @@ -7,8 +7,8 @@ struct ToBool { explicit operator bool(); }; struct B; -struct A { A(); A(const B&); }; -struct B { operator A() const; }; +struct A { A(); A(const B&); }; // expected-note 2 {{candidate constructor}} +struct B { operator A() const; }; // expected-note 2 {{candidate function}} struct I { operator int(); }; struct J { operator I(); }; struct K { operator double(); }; @@ -50,8 +50,8 @@ struct MixedFieldsDerived : MixedFields { enum Enum { EVal }; struct Ambig { - operator short(); - operator signed char(); + operator short(); // expected-note 2 {{candidate function}} + operator signed char(); // expected-note 2 {{candidate function}} }; void test() @@ -128,11 +128,10 @@ void test() // "the type [it] woud have if E2 were converted to an rvalue" vfn pfn = i1 ? F() : test; pfn = i1 ? test : F(); - // these are ambiguous - better messages would be nice - (void)(i1 ? A() : B()); // expected-error {{incompatible operand types}} - (void)(i1 ? B() : A()); // expected-error {{incompatible operand types}} - (void)(i1 ? 1 : Ambig()); // expected-error {{incompatible operand types}} - (void)(i1 ? Ambig() : 1); // expected-error {{incompatible operand types}} + (void)(i1 ? A() : B()); // expected-error {{conversion from 'struct B' to 'struct A' is ambiguous}} + (void)(i1 ? B() : A()); // expected-error {{conversion from 'struct B' to 'struct A' is ambiguous}} + (void)(i1 ? 1 : Ambig()); // expected-error {{conversion from 'struct Ambig' to 'int' is ambiguous}} + (void)(i1 ? Ambig() : 1); // expected-error {{conversion from 'struct Ambig' to 'int' is ambiguous}} // By the way, this isn't an lvalue: &(i1 ? i1 : i2); // expected-error {{address expression must be an lvalue or a function designator}} diff --git a/test/SemaCXX/constructor-initializer.cpp b/test/SemaCXX/constructor-initializer.cpp index 67d4074cbcdc9..53f057ed0f35f 100644 --- a/test/SemaCXX/constructor-initializer.cpp +++ b/test/SemaCXX/constructor-initializer.cpp @@ -97,13 +97,10 @@ struct Current : Derived { // expected-error {{member initializer 'NonExisting' does not name a non-static data member or}} }; - // FIXME. This is bad message! -struct M { // expected-note {{candidate function}} \ - // expected-note {{candidate function}} \ +struct M { // expected-note 2 {{candidate constructor (the implicit copy constructor)}} \ // expected-note {{declared here}} \ // expected-note {{declared here}} - M(int i, int j); // expected-note {{candidate function}} \ - // // expected-note {{candidate function}} + M(int i, int j); // expected-note 2 {{candidate constructor}} }; struct N : M { diff --git a/test/SemaCXX/conversion-function.cpp b/test/SemaCXX/conversion-function.cpp index db322f4a3d34e..4fef172bd5a1a 100644 --- a/test/SemaCXX/conversion-function.cpp +++ b/test/SemaCXX/conversion-function.cpp @@ -56,9 +56,9 @@ public: // This used to crash Clang. struct Flip; -struct Flop { // expected-note{{candidate function}} +struct Flop { // expected-note{{candidate is the implicit copy constructor}} Flop(); - Flop(const Flip&); // expected-note{{candidate function}} + Flop(const Flip&); // expected-note{{candidate constructor}} }; struct Flip { operator Flop() const; // expected-note{{candidate function}} diff --git a/test/SemaCXX/converting-constructor.cpp b/test/SemaCXX/converting-constructor.cpp index e78798b82cb76..1688e51e73fdf 100644 --- a/test/SemaCXX/converting-constructor.cpp +++ b/test/SemaCXX/converting-constructor.cpp @@ -27,7 +27,7 @@ public: FromShort(short s); }; -class FromShortExplicitly { // expected-note{{candidate function}} +class FromShortExplicitly { // expected-note{{candidate constructor (the implicit copy constructor)}} public: explicit FromShortExplicitly(short s); }; diff --git a/test/SemaCXX/copy-initialization.cpp b/test/SemaCXX/copy-initialization.cpp index ad149232a4e36..2cf878a84411b 100644 --- a/test/SemaCXX/copy-initialization.cpp +++ b/test/SemaCXX/copy-initialization.cpp @@ -2,7 +2,7 @@ class X { public: explicit X(const X&); - X(int*); // expected-note 2{{candidate function}} + X(int*); // expected-note 2{{candidate constructor}} explicit X(float*); }; diff --git a/test/SemaCXX/dcl_init_aggr.cpp b/test/SemaCXX/dcl_init_aggr.cpp index 87b51e32e5cf3..07ddb0add2cac 100644 --- a/test/SemaCXX/dcl_init_aggr.cpp +++ b/test/SemaCXX/dcl_init_aggr.cpp @@ -40,9 +40,9 @@ char cv[4] = { 'a', 's', 'd', 'f', 0 }; // expected-error{{excess elements in ar struct TooFew { int a; char* b; int c; }; TooFew too_few = { 1, "asdf" }; // okay -struct NoDefaultConstructor { // expected-note 3 {{candidate function}} \ +struct NoDefaultConstructor { // expected-note 3 {{candidate constructor (the implicit copy constructor)}} \ // expected-note{{declared here}} - NoDefaultConstructor(int); // expected-note 3 {{candidate function}} + NoDefaultConstructor(int); // expected-note 3 {{candidate constructor}} }; struct TooFewError { // expected-error{{implicit default constructor for}} int a; @@ -115,7 +115,7 @@ B2 b2_2 = { 4, d2, 0 }; B2 b2_3 = { c2, a2, a2 }; // C++ [dcl.init.aggr]p15: -union u { int a; char* b; }; // expected-note{{candidate function}} +union u { int a; char* b; }; // expected-note{{candidate constructor (the implicit copy constructor)}} u u1 = { 1 }; u u2 = u1; u u3 = 1; // expected-error{{no viable conversion}} diff --git a/test/SemaCXX/decl-init-ref.cpp b/test/SemaCXX/decl-init-ref.cpp index 294543f495dbd..656f3436a0c3b 100644 --- a/test/SemaCXX/decl-init-ref.cpp +++ b/test/SemaCXX/decl-init-ref.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s -struct A {}; // expected-note {{candidate function}} +struct A {}; // expected-note {{candidate is the implicit copy constructor}} struct BASE { operator A(); // expected-note {{candidate function}} diff --git a/test/SemaCXX/default2.cpp b/test/SemaCXX/default2.cpp index 880255e4531b1..d2c44bd998a0e 100644 --- a/test/SemaCXX/default2.cpp +++ b/test/SemaCXX/default2.cpp @@ -82,7 +82,7 @@ int Y::mem4(int i = a) // expected-error{{invalid use of nonstatic data member ' // constructors. class Z { public: - Z(Z&, int i = 17); // expected-note 3 {{candidate function}} + Z(Z&, int i = 17); // expected-note 3 {{candidate constructor}} void f(Z& z) { Z z2; // expected-error{{no matching constructor for initialization}} @@ -103,7 +103,7 @@ struct ZZ { void f(ZZ z = g()); // expected-error{{no matching constructor for initialization}} - ZZ(ZZ&, int = 17); // expected-note{{candidate function}} + ZZ(ZZ&, int = 17); // expected-note{{candidate constructor}} }; // http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#325 diff --git a/test/SemaCXX/direct-initializer.cpp b/test/SemaCXX/direct-initializer.cpp index 03a5da3a303b2..6601a3dd0d926 100644 --- a/test/SemaCXX/direct-initializer.cpp +++ b/test/SemaCXX/direct-initializer.cpp @@ -13,16 +13,16 @@ class Y { explicit Y(float); }; -class X { // expected-note{{candidate function}} +class X { // expected-note{{candidate constructor (the implicit copy constructor)}} public: - explicit X(int); // expected-note{{candidate function}} - X(float, float, float); // expected-note{{candidate function}} - X(float, Y); // expected-note{{candidate function}} + explicit X(int); // expected-note{{candidate constructor}} + X(float, float, float); // expected-note{{candidate constructor}} + X(float, Y); // expected-note{{candidate constructor}} }; -class Z { // expected-note{{candidate function}} +class Z { // expected-note{{candidate constructor (the implicit copy constructor)}} public: - Z(int); // expected-note{{candidate function}} + Z(int); // expected-note{{candidate constructor}} }; void g() { diff --git a/test/SemaCXX/functional-cast.cpp b/test/SemaCXX/functional-cast.cpp index 63be77008cb44..0bef0cd6be4c8 100644 --- a/test/SemaCXX/functional-cast.cpp +++ b/test/SemaCXX/functional-cast.cpp @@ -10,10 +10,8 @@ struct InitViaConstructor { InitViaConstructor(int i = 7); }; -// FIXME: error messages for implicitly-declared special member -// function candidates are very poor -struct NoValueInit { // expected-note 2 {{candidate function}} - NoValueInit(int i, int j); // expected-note 2 {{candidate function}} +struct NoValueInit { // expected-note 2 {{candidate constructor (the implicit copy constructor)}} + NoValueInit(int i, int j); // expected-note 2 {{candidate constructor}} }; void test_cxx_functional_value_init() { diff --git a/test/SemaCXX/implicit-virtual-member-functions.cpp b/test/SemaCXX/implicit-virtual-member-functions.cpp index a6b1f8c537d2b..4ae9eae3b316d 100644 --- a/test/SemaCXX/implicit-virtual-member-functions.cpp +++ b/test/SemaCXX/implicit-virtual-member-functions.cpp @@ -15,15 +15,15 @@ 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() { } // expected-note {{implicit default destructor for 'struct C' first required here}} +C::C() { } struct D : A { // expected-error {{no suitable member 'operator delete' in 'D'}} void operator delete(void *, int); // expected-note {{'operator delete' declared here}} -}; +}; // expected-note {{implicit default destructor for 'struct D' first required here}} void f() { - new D; // expected-note {{implicit default destructor for 'struct D' first required here}} + new D; } diff --git a/test/SemaCXX/literal-operators.cpp b/test/SemaCXX/literal-operators.cpp new file mode 100644 index 0000000000000..ec585a61da9fa --- /dev/null +++ b/test/SemaCXX/literal-operators.cpp @@ -0,0 +1,43 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s + +#include <stddef.h> + +struct tag { + void operator "" tag_bad (const char *); // expected-error {{literal operator 'operator "" tag_bad' must be in a namespace or global scope}} + friend void operator "" tag_good (const char *); +}; + +namespace ns { void operator "" ns_good (const char *); } + +// Check extern "C++" declarations +extern "C++" void operator "" extern_good (const char *); +extern "C++" { void operator "" extern_good (const char *); } + +void fn () { void operator "" fn_bad (const char *); } // expected-error {{literal operator 'operator "" fn_bad' must be in a namespace or global scope}} + +// One-param declarations (const char * was already checked) +void operator "" good (char); +void operator "" good (wchar_t); +void operator "" good (char16_t); +void operator "" good (char32_t); +void operator "" good (unsigned long long); +void operator "" good (long double); + +// Two-param declarations +void operator "" good (const char *, size_t); +void operator "" good (const wchar_t *, size_t); +void operator "" good (const char16_t *, size_t); +void operator "" good (const char32_t *, size_t); + +// Check typedef and array equivalences +void operator "" good (const char[]); +typedef const char c; +void operator "" good (c*); + +// Check extra cv-qualifiers +void operator "" cv_good (volatile const char *, const size_t); + +// Template delcaration (not implemented yet) +// template <char...> void operator "" good (); + +// FIXME: Test some invalid decls that might crop up. diff --git a/test/SemaCXX/member-pointer.cpp b/test/SemaCXX/member-pointer.cpp index 65d05eb5af749..3d9d5b5ebbbc5 100644 --- a/test/SemaCXX/member-pointer.cpp +++ b/test/SemaCXX/member-pointer.cpp @@ -80,7 +80,7 @@ void g() { void (HasMembers::*pmf)() = &HasMembers::f; void (*pnf)() = &Fake::f; - &hm.f; // FIXME: needs diagnostic expected-warning{{result unused}} + &hm.f; // expected-error {{must explicitly qualify}} expected-warning{{result unused}} void (HasMembers::*pmgv)() = &HasMembers::g; void (HasMembers::*pmgi)(int) = &HasMembers::g; @@ -136,3 +136,15 @@ void i() { OverloadsPtrMem m; int foo = m->*"Awesome!"; } + +namespace pr5985 { + struct c { + void h(); + 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}} + } + }; +} diff --git a/test/SemaCXX/namespace.cpp b/test/SemaCXX/namespace.cpp index ab690b7286ec8..2a9d31fa945a5 100644 --- a/test/SemaCXX/namespace.cpp +++ b/test/SemaCXX/namespace.cpp @@ -9,7 +9,7 @@ int A; // expected-error {{redefinition of 'A' as different kind of symbol}} class A; // expected-error {{redefinition of 'A' as different kind of symbol}} class B {}; // expected-note {{previous definition is here}} \ - // FIXME: ugly expected-note{{candidate function}} + // expected-note{{candidate function (the implicit copy assignment operator)}} void C(); // expected-note {{previous definition is here}} namespace C {} // expected-error {{redefinition of 'C' as different kind of symbol}} diff --git a/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 4e65b41e666c2..8618f0339bcaf 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/test/SemaCXX/nested-name-spec.cpp @@ -178,7 +178,7 @@ bool (foo_S::value); namespace somens { - struct a { }; // expected-note{{candidate function}} + struct a { }; // expected-note{{candidate constructor (the implicit copy constructor)}} } template <typename T> diff --git a/test/SemaCXX/overload-call.cpp b/test/SemaCXX/overload-call.cpp index 299c0a78f9267..d20bf23b8fd95 100644 --- a/test/SemaCXX/overload-call.cpp +++ b/test/SemaCXX/overload-call.cpp @@ -301,3 +301,35 @@ namespace PR5756 { (void)ir; } } + +// Tests the exact text used to note the candidates +namespace test1 { + template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'char const [6]' to 'unsigned int' for 2nd argument}} + void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'char const [6]' to 'char' for 2nd argument}} + void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}} + void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}} + void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}} + void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}} + void foo(int n, const char *s, int t, int u = 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}} + + void test() { + foo(4, "hello"); //expected-error {{no matching function for call to 'foo'}} + } +} + +// PR 6014 +namespace test2 { + struct QFixed { + QFixed(int i); + QFixed(long i); + }; + + bool operator==(const QFixed &f, int i); + + class qrgb666 { + inline operator unsigned int () const; + + inline bool operator==(const qrgb666 &v) const; + inline bool operator!=(const qrgb666 &v) const { return !(*this == v); } + }; +} diff --git a/test/SemaCXX/overload-member-call.cpp b/test/SemaCXX/overload-member-call.cpp index 4bb3ff3a54cd6..22416f3ea48ea 100644 --- a/test/SemaCXX/overload-member-call.cpp +++ b/test/SemaCXX/overload-member-call.cpp @@ -66,3 +66,33 @@ void test_X2(X2 *x2p, const X2 *cx2p) { int &ir = x2p->member(); float &fr = cx2p->member(); } + +// Tests the exact text used to note the candidates +namespace test1 { + class A { + template <class T> void foo(T t, unsigned N); // expected-note {{candidate function [with T = int] not viable: no known conversion from 'char const [6]' to 'unsigned int' for 2nd argument}} + void foo(int n, char N); // expected-note {{candidate function not viable: no known conversion from 'char const [6]' to 'char' for 2nd argument}} + void foo(int n); // expected-note {{candidate function not viable: requires 1 argument, but 2 were provided}} + void foo(unsigned n = 10); // expected-note {{candidate function not viable: requires at most 1 argument, but 2 were provided}} + void foo(int n, const char *s, int t); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}} + void foo(int n, const char *s, int t, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}} + void foo(int n, const char *s, int t, int u = 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}} + + void bar(double d); //expected-note {{candidate function not viable: 'this' argument has type 'class test1::A const', but method is not marked const}} + void bar(int i); //expected-note {{candidate function not viable: 'this' argument has type 'class test1::A const', but method is not marked const}} + + void baz(A &d); // expected-note {{candidate function not viable: 1st argument ('class test1::A const') would lose const qualifier}} + void baz(int i); // expected-note {{candidate function not viable: no known conversion from 'class test1::A const' to 'int' for 1st argument}} + }; + + void test() { + A a; + a.foo(4, "hello"); //expected-error {{no matching member function for call to 'foo'}} + + const A b; + b.bar(0); //expected-error {{no matching member function for call to 'bar'}} + + a.baz(b); //expected-error {{no matching member function for call to 'baz'}} + } +} + diff --git a/test/SemaCXX/overloaded-builtin-operators.cpp b/test/SemaCXX/overloaded-builtin-operators.cpp index 12903cc7facf4..61c2e2110a996 100644 --- a/test/SemaCXX/overloaded-builtin-operators.cpp +++ b/test/SemaCXX/overloaded-builtin-operators.cpp @@ -59,7 +59,7 @@ void f(Short s, Long l, Enum1 e1, Enum2 e2, Xpmf pmf) { // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2)); } -struct ShortRef { // expected-note{{candidate function}} +struct ShortRef { // expected-note{{candidate function (the implicit copy assignment operator)}} operator short&(); }; @@ -67,7 +67,7 @@ struct LongRef { operator volatile long&(); }; -struct XpmfRef { // expected-note{{candidate function}} +struct XpmfRef { // expected-note{{candidate function (the implicit copy assignment operator)}} operator pmf&(); }; diff --git a/test/SemaCXX/overloaded-operator.cpp b/test/SemaCXX/overloaded-operator.cpp index a20c69b8d5d1d..861d679c72611 100644 --- a/test/SemaCXX/overloaded-operator.cpp +++ b/test/SemaCXX/overloaded-operator.cpp @@ -190,16 +190,23 @@ typedef INTREF Func1(FLOAT, double); typedef float& Func2(int, double); struct ConvertToFunc { - operator Func1*(); // expected-note{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}} - operator Func2&(); // expected-note{{conversion candidate of type 'float &(&)(int, double)'}} + operator Func1*(); // expected-note 2{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}} + operator Func2&(); // expected-note 2{{conversion candidate of type 'float &(&)(int, double)'}} void operator()(); }; -void test_funcptr_call(ConvertToFunc ctf) { +struct ConvertToFuncDerived : ConvertToFunc { }; + +void test_funcptr_call(ConvertToFunc ctf, ConvertToFuncDerived ctfd) { int &i1 = ctf(1.0f, 2.0); - float &f2 = ctf((short int)1, 1.0f); + float &f1 = ctf((short int)1, 1.0f); ctf((long int)17, 2.0); // expected-error{{error: call to object of type 'struct ConvertToFunc' is ambiguous; candidates are:}} ctf(); + + int &i2 = ctfd(1.0f, 2.0); + float &f2 = ctfd((short int)1, 1.0f); + ctfd((long int)17, 2.0); // expected-error{{error: call to object of type 'struct ConvertToFuncDerived' is ambiguous; candidates are:}} + ctfd(); } struct HasMember { @@ -324,3 +331,27 @@ namespace pr5512 { a += x; } } + +// PR5900 +namespace pr5900 { + struct NotAnArray {}; + void test0() { + NotAnArray x; + x[0] = 0; // expected-error {{does not provide a subscript operator}} + } + + struct NonConstArray { + int operator[](unsigned); // expected-note {{candidate}} + }; + int test1() { + const NonConstArray x; + return x[0]; // expected-error {{no viable overloaded operator[] for type}} + } + + // Not really part of this PR, but implemented at the same time. + struct NotAFunction {}; + void test2() { + NotAFunction x; + x(); // expected-error {{does not provide a call operator}} + } +} diff --git a/test/SemaCXX/rval-references.cpp b/test/SemaCXX/rval-references.cpp index 7ff3d584c02e6..2a7fb25c62a9e 100644 --- a/test/SemaCXX/rval-references.cpp +++ b/test/SemaCXX/rval-references.cpp @@ -65,10 +65,10 @@ int&& should_not_warn(int&& i) { // But GCC 4.4 does // Test the return dance. This also tests IsReturnCopyElidable. struct MoveOnly { MoveOnly(); - MoveOnly(const MoveOnly&) = delete; // expected-note {{candidate function}} \ + MoveOnly(const MoveOnly&) = delete; // expected-note {{candidate constructor}} \ // expected-note 3{{explicitly marked deleted here}} - MoveOnly(MoveOnly&&); // expected-note {{candidate function}} - MoveOnly(int&&); // expected-note {{candidate function}} + MoveOnly(MoveOnly&&); // expected-note {{candidate constructor}} + MoveOnly(int&&); // expected-note {{candidate constructor}} }; MoveOnly gmo; diff --git a/test/SemaCXX/unreachable-code.cpp b/test/SemaCXX/unreachable-code.cpp new file mode 100644 index 0000000000000..528bba7d5e150 --- /dev/null +++ b/test/SemaCXX/unreachable-code.cpp @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fsyntax-only -Wunreachable-code -fblocks -verify %s + +int j; +void bar() { } +int test1() { + for (int i = 0; + i != 10; + ++i) { // expected-warning {{will never be executed}} + if (j == 23) // missing {}'s + bar(); + return 1; + } + return 0; + return 1; // expected-warning {{will never be executed}} +} + +void test2(int i) { + switch (i) { + case 0: + break; + bar(); // expected-warning {{will never be executed}} + case 2: + switch (i) { + default: + a: goto a; + } + bar(); // expected-warning {{will never be executed}} + } + b: goto b; + bar(); // expected-warning {{will never be executed}} +} + +void test3() { + ^{ return; + bar(); // expected-warning {{will never be executed}} + }(); + while (++j) { + continue; + bar(); // expected-warning {{will never be executed}} + } +} diff --git a/test/SemaCXX/virtual-member-functions-key-function.cpp b/test/SemaCXX/virtual-member-functions-key-function.cpp index 3d048595e94e0..2e21fb7365e9e 100644 --- a/test/SemaCXX/virtual-member-functions-key-function.cpp +++ b/test/SemaCXX/virtual-member-functions-key-function.cpp @@ -4,19 +4,26 @@ struct 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}} + B() { } void operator delete(void *, int); // expected-note {{'operator delete' declared here}} -}; +}; // expected-note {{implicit default destructor for 'struct B' first required here}} struct C : A { // expected-error {{no suitable member 'operator delete' in 'C'}} void operator delete(void *, int); // expected-note {{'operator delete' declared here}} -}; +}; // expected-note {{implicit default destructor for 'struct C' first required 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}} + (void)new C; } + +// Make sure that the key-function computation is consistent when the +// first virtual member function of a nested class has an inline body. +struct Outer { + struct Inner { + virtual void f() { } + void g(); + }; +}; + +void Outer::Inner::g() { } diff --git a/test/SemaCXX/warn-assignment-condition.cpp b/test/SemaCXX/warn-assignment-condition.cpp index 1df906dd7ec6c..ce16a68a77efc 100644 --- a/test/SemaCXX/warn-assignment-condition.cpp +++ b/test/SemaCXX/warn-assignment-condition.cpp @@ -11,26 +11,34 @@ void test() { A a, b; // With scalars. - if (x = 7) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + if (x = 7) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} if ((x = 7)) {} do { - } while (x = 7); // expected-warning {{using the result of an assignment as a condition without parentheses}} + } while (x = 7); // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} do { } while ((x = 7)); - while (x = 7) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + while (x = 7) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} while ((x = 7)) {} - for (; x = 7; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + for (; x = 7; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} for (; (x = 7); ) {} - if (p = p) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + if (p = p) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} if ((p = p)) {} do { - } while (p = p); // expected-warning {{using the result of an assignment as a condition without parentheses}} + } while (p = p); // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} do { } while ((p = p)); - while (p = p) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + while (p = p) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} while ((p = p)) {} - for (; p = p; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + for (; p = p; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} for (; (p = p); ) {} // Initializing variables (shouldn't warn). @@ -40,26 +48,34 @@ void test() { while (A y = a) {} // With temporaries. - if (x = (b+b).foo()) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + if (x = (b+b).foo()) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} if ((x = (b+b).foo())) {} do { - } while (x = (b+b).foo()); // expected-warning {{using the result of an assignment as a condition without parentheses}} + } while (x = (b+b).foo()); // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} do { } while ((x = (b+b).foo())); - while (x = (b+b).foo()) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + while (x = (b+b).foo()) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} while ((x = (b+b).foo())) {} - for (; x = (b+b).foo(); ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + for (; x = (b+b).foo(); ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} for (; (x = (b+b).foo()); ) {} // With a user-defined operator. - if (a = b + b) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + if (a = b + b) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} if ((a = b + b)) {} do { - } while (a = b + b); // expected-warning {{using the result of an assignment as a condition without parentheses}} + } while (a = b + b); // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} do { } while ((a = b + b)); - while (a = b + b) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + while (a = b + b) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} while ((a = b + b)) {} - for (; a = b + b; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} + for (; a = b + b; ) {} // expected-warning {{using the result of an assignment as a condition without parentheses}} \ + // expected-note{{use '==' to turn this assignment into an equality comparison}} for (; (a = b + b); ) {} } |