xref: /aosp_15_r20/external/clang/test/SemaCXX/dependent-auto.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
2*67e74705SXin Li 
3*67e74705SXin Li template<typename T>
4*67e74705SXin Li struct only {
5*67e74705SXin Li   only(T);
6*67e74705SXin Li   template<typename U> only(U) = delete; // expected-note {{here}}
7*67e74705SXin Li };
8*67e74705SXin Li 
9*67e74705SXin Li template<typename ...T>
f(T...t)10*67e74705SXin Li void f(T ...t) {
11*67e74705SXin Li   auto x(t...); // expected-error {{is empty}} expected-error {{contains multiple expressions}}
12*67e74705SXin Li   only<int> check = x;
13*67e74705SXin Li }
14*67e74705SXin Li 
g()15*67e74705SXin Li void g() {
16*67e74705SXin Li   f(); // expected-note {{here}}
17*67e74705SXin Li   f(0);
18*67e74705SXin Li   f(0, 1); // expected-note {{here}}
19*67e74705SXin Li }
20*67e74705SXin Li 
21*67e74705SXin Li 
22*67e74705SXin Li template<typename T>
h(T t)23*67e74705SXin Li bool h(T t) {
24*67e74705SXin Li   auto a = t;
25*67e74705SXin Li   decltype(a) b;
26*67e74705SXin Li   a = a + b;
27*67e74705SXin Li 
28*67e74705SXin Li   auto p = new auto(t);
29*67e74705SXin Li 
30*67e74705SXin Li   only<double*> test = p; // expected-error {{conversion function from 'char *' to 'only<double *>'}}
31*67e74705SXin Li   return p;
32*67e74705SXin Li }
33*67e74705SXin Li 
34*67e74705SXin Li bool b = h('x'); // expected-note {{here}}
35*67e74705SXin Li 
36*67e74705SXin Li // PR 9276 - Make sure we check auto types deduce the same
37*67e74705SXin Li // in the case of a dependent initializer
38*67e74705SXin Li namespace PR9276 {
39*67e74705SXin Li   template<typename T>
f()40*67e74705SXin Li   void f() {
41*67e74705SXin Li     auto i = T(), j = 0; // expected-error {{deduced as 'long' in declaration of 'i' and deduced as 'int' in declaration of 'j'}}
42*67e74705SXin Li   }
43*67e74705SXin Li 
g()44*67e74705SXin Li   void g() {
45*67e74705SXin Li     f<long>(); // expected-note {{here}}
46*67e74705SXin Li     f<int>();
47*67e74705SXin Li   }
48*67e74705SXin Li }
49*67e74705SXin Li 
50*67e74705SXin Li namespace NoRepeatedDiagnostic {
51*67e74705SXin Li   template<typename T>
f()52*67e74705SXin Li   void f() {
53*67e74705SXin Li     auto a = 0, b = 0.0, c = T(); // expected-error {{deduced as 'int' in declaration of 'a' and deduced as 'double' in declaration of 'b'}}
54*67e74705SXin Li   }
55*67e74705SXin Li   // We've already diagnosed an issue. No extra diagnostics is needed for these.
56*67e74705SXin Li   template void f<int>();
57*67e74705SXin Li   template void f<double>();
58*67e74705SXin Li   template void f<char>();
59*67e74705SXin Li }
60