92 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s2// RUN: %clang_cc1 -fsyntax-only -verify %s3 4namespace 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 >= 201103L7 // 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#endif9 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 17namespace PR16314 {18 void f(char*);19 int &f(...);20 void x()21 {22 int &n = f("foo");23#if __cplusplus < 201103L24 // 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#endif27 }28}29 30namespace warn_if_best {31 int f(char *);32 void f(double);33 void x()34 {35 int n = f("foo");36#if __cplusplus < 201103L37 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}38#else39 // expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}}40#endif41 }42}43 44namespace userdefined_vs_illformed {45 struct X { X(const char *); };46 47 void *f(char *p); // best for C++0348 double f(X x); // best for C++1149 void g()50 {51 double d = f("foo");52#if __cplusplus < 201103L53 // 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#endif56 }57}58 59namespace 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 failure69 // C++03: ok70 template<typename T> int cxx11_ignored(T, typename S<sizeof(f(T(), "foo"))>::type *);71#if __cplusplus < 201103L72 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}73#else74 // expected-note@-4 {{candidate template ignored: substitution failure}}75#endif76 77 // C++11: better than latter78 // C++03: worse than latter79 template<typename T> void g(T, ...);80 template<typename T> int g(T, typename S<sizeof(f(T(), "foo"))>::type *);81#if __cplusplus < 201103L82 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}83#endif84 85 int a = cxx11_ignored(0, 0);86 int b = g(0, 0);87#if __cplusplus >= 201103L88 // 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#endif91}92