• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98
3 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
4 
5 #if __cplusplus >= 201103L
6 // expected-note@+3 2 {{candidate constructor}}
7 // expected-note@+2 {{passing argument to parameter here}}
8 #endif
9 struct A {
10 };
11 
12 struct ConvertibleToA {
13   operator A();
14 };
15 
16 struct ConvertibleToConstA {
17 #if __cplusplus >= 201103L
18 // expected-note@+2 {{candidate function}}
19 #endif
20   operator const A();
21 };
22 
23 struct B {
24   B& operator=(B&);  // expected-note 4 {{candidate function}}
25 };
26 
27 struct ConvertibleToB {
28   operator B();
29 };
30 
31 struct ConvertibleToBref {
32   operator B&();
33 };
34 
35 struct ConvertibleToConstB {
36   operator const B();
37 };
38 
39 struct ConvertibleToConstBref {
40   operator const B&();
41 };
42 
43 struct C {
44   int operator=(int); // expected-note{{candidate function}}
45   long operator=(long); // expected-note{{candidate function}}
46   int operator+=(int); // expected-note{{candidate function}}
47   int operator+=(long); // expected-note{{candidate function}}
48 };
49 
50 struct D {
51   D& operator+=(const D &);
52 };
53 
54 struct ConvertibleToInt {
55   operator int();
56 };
57 
test()58 void test() {
59   A a, na;
60   const A constA = A();
61   ConvertibleToA convertibleToA;
62   ConvertibleToConstA convertibleToConstA;
63 
64   B b, nb;
65   const B constB = B();
66   ConvertibleToB convertibleToB;
67   ConvertibleToBref convertibleToBref;
68   ConvertibleToConstB convertibleToConstB;
69   ConvertibleToConstBref convertibleToConstBref;
70 
71   C c, nc;
72   const C constC = C();
73 
74   D d, nd;
75   const D constD = D();
76 
77   ConvertibleToInt convertibleToInt;
78 
79   na = a;
80   na = constA;
81   na = convertibleToA;
82 #if __cplusplus >= 201103L
83 // expected-error@+2 {{no viable conversion}}
84 #endif
85   na = convertibleToConstA;
86   na += a; // expected-error{{no viable overloaded '+='}}
87 
88   nb = b;
89   nb = constB;  // expected-error{{no viable overloaded '='}}
90   nb = convertibleToB; // expected-error{{no viable overloaded '='}}
91   nb = convertibleToBref;
92   nb = convertibleToConstB; // expected-error{{no viable overloaded '='}}
93   nb = convertibleToConstBref; // expected-error{{no viable overloaded '='}}
94 
95   nc = c;
96   nc = constC;
97   nc = 1;
98   nc = 1L;
99   nc = 1.0; // expected-error{{use of overloaded operator '=' is ambiguous}}
100   nc += 1;
101   nc += 1L;
102   nc += 1.0; // expected-error{{use of overloaded operator '+=' is ambiguous}}
103 
104   nd = d;
105   nd += d;
106   nd += constD;
107 
108   int i;
109   i = convertibleToInt;
110   i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}}
111 }
112 
113 // <rdar://problem/8315440>: Don't crash
114 namespace test1 {
115   template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}}
A(UndeclaredType n)116     A(UndeclaredType n) : X(n) {} // expected-error {{unknown type name 'UndeclaredType'}}
117   };
118   template<typename T> class B : public A<T>     {
foo()119     virtual void foo() {}
120   };
121   extern template class A<char>;
122   extern template class B<char>;
123 }
124