| 1 |
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 3 |
|
| 4 |
namespace test0 { |
| 5 |
struct A { // expected-note {{candidate function (the implicit copy assignment operator) not viable: 'this' argument has type 'const A', but method is not marked const}} |
| 6 |
#if __cplusplus >= 201103L |
| 7 |
// expected-note@-2 {{candidate function (the implicit move assignment operator) not viable: 'this' argument has type 'const A', but method is not marked const}} |
| 8 |
#endif |
| 9 |
A &operator=(void*); // expected-note {{candidate function not viable: 'this' argument has type 'const A', but method is not marked const}} |
| 10 |
}; |
| 11 |
|
| 12 |
void test(const A &a) { |
| 13 |
a = "help"; // expected-error {{no viable overloaded '='}} |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
namespace PR16314 { |
| 18 |
void f(char*); |
| 19 |
int &f(...); |
| 20 |
void x() |
| 21 |
{ |
| 22 |
int &n = f("foo"); |
| 23 |
#if __cplusplus < 201103L |
| 24 |
// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}} |
| 25 |
// expected-error@-3 {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'void'}} |
| 26 |
#endif |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
namespace warn_if_best { |
| 31 |
int f(char *); |
| 32 |
void f(double); |
| 33 |
void x() |
| 34 |
{ |
| 35 |
int n = f("foo"); |
| 36 |
#if __cplusplus < 201103L |
| 37 |
// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}} |
| 38 |
#else |
| 39 |
// expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}} |
| 40 |
#endif |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
namespace userdefined_vs_illformed { |
| 45 |
struct X { X(const char *); }; |
| 46 |
|
| 47 |
void *f(char *p); // best for C++03 |
| 48 |
double f(X x); // best for C++11 |
| 49 |
void g() |
| 50 |
{ |
| 51 |
double d = f("foo"); |
| 52 |
#if __cplusplus < 201103L |
| 53 |
// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}} |
| 54 |
// expected-error@-3 {{cannot initialize a variable of type 'double' with an rvalue of type 'void *'}} |
| 55 |
#endif |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
namespace sfinae_test { |
| 60 |
int f(int, char*); |
| 61 |
|
| 62 |
template<int T> |
| 63 |
struct S { typedef int type; }; |
| 64 |
|
| 65 |
template<> |
| 66 |
struct S<sizeof(int)> { typedef void type; }; |
| 67 |
|
| 68 |
// C++11: SFINAE failure |
| 69 |
// C++03: ok |
| 70 |
template<typename T> int cxx11_ignored(T, typename S<sizeof(f(T(), "foo"))>::type *); |
| 71 |
#if __cplusplus < 201103L |
| 72 |
// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}} |
| 73 |
#else |
| 74 |
// expected-note@-4 {{candidate template ignored: substitution failure}} |
| 75 |
#endif |
| 76 |
|
| 77 |
// C++11: better than latter |
| 78 |
// C++03: worse than latter |
| 79 |
template<typename T> void g(T, ...); |
| 80 |
template<typename T> int g(T, typename S<sizeof(f(T(), "foo"))>::type *); |
| 81 |
#if __cplusplus < 201103L |
| 82 |
// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}} |
| 83 |
#endif |
| 84 |
|
| 85 |
int a = cxx11_ignored(0, 0); |
| 86 |
int b = g(0, 0); |
| 87 |
#if __cplusplus >= 201103L |
| 88 |
// expected-error@-3 {{no matching function for call to 'cxx11_ignored'}} |
| 89 |
// expected-error@-3 {{cannot initialize a variable of type 'int' with an rvalue of type 'void'}} |
| 90 |
#endif |
| 91 |
} |