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