[docs] Add LICENSE.txt to the root of the mono-repo
[llvm-project.git] / clang / test / SemaCXX / overload-0x.cpp
blob94864b79234aff42af4968af39efdcb700101ec3
1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify %s
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}}
12 void test(const A &a) {
13 a = "help"; // expected-error {{no viable overloaded '='}}
17 namespace PR16314 {
18 void f(char*);
19 int &f(...);
20 void x()
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
30 namespace warn_if_best {
31 int f(char *);
32 void f(double);
33 void x()
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
44 namespace userdefined_vs_illformed {
45 struct X { X(const char *); };
47 void *f(char *p); // best for C++03
48 double f(X x); // best for C++11
49 void g()
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
59 namespace sfinae_test {
60 int f(int, char*);
62 template<int T>
63 struct S { typedef int type; };
65 template<>
66 struct S<sizeof(int)> { typedef void type; };
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
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
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