xref: /llvm-project/clang/test/SemaTemplate/class-template-id.cpp (revision 3b639d7d1d9b9f352c57460deaf70aaad238f8d9)
1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx23,precxx17 %std_cxx98-14 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx23,cxx17 %std_cxx17-20 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17,cxx23 %std_cxx23- %s
4 template<typename T, typename U = float> struct A { };
5 
6 typedef A<int> A_int;
7 
8 typedef float FLOAT;
9 
foo(A<int> * ptr,A<int> const * ptr2,A<int,double> * ptr3)10 A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) {
11   if (ptr)
12     return ptr; // okay
13   else if (ptr2)
14     return ptr2; // precxx23-error{{cannot initialize return object of type 'A<int, FLOAT> *' (aka 'A<int, float> *') with an lvalue of type 'const A<int> *'}} \
15                     cxx23-error{{cannot initialize return object of type 'A<int, FLOAT> *' (aka 'A<int, float> *') with an rvalue of type 'const A<int> *'}}
16   else {
17     return ptr3; // precxx23-error{{cannot initialize return object of type 'A<int, FLOAT> *' (aka 'A<int, float> *') with an lvalue of type 'A<int, double> *'}} \
18                     cxx23-error{{cannot initialize return object of type 'A<int, FLOAT> *' (aka 'A<int, float> *') with an rvalue of type 'A<int, double> *'}}
19   }
20 }
21 
22 template<int I> struct B;
23 
24 const int value = 12;
bar(B<(19)> * ptr1,B<(::value+7)> * ptr2,B<19-3> * ptr3)25 B<17 + 2> *bar(B<(19)> *ptr1, B< (::value + 7) > *ptr2, B<19 - 3> *ptr3) {
26   if (ptr1)
27     return ptr1;
28   else if (ptr2)
29     return ptr2;
30   else
31     return ptr3; // precxx23-error{{cannot initialize return object of type 'B<17 + 2> *' with an lvalue of type 'B<19 - 3>}} \
32                     cxx23-error{{cannot initialize return object of type 'B<17 + 2> *' with an rvalue of type 'B<19 - 3>}}
33 }
34 
35 typedef B<5> B5;
36 
37 
38 namespace N {
39   template<typename T> struct C {};
40 }
41 
42 N::C<int> c1;
43 typedef N::C<float> c2;
44 
45 // PR5655
46 template<typename T> struct Foo { }; // precxx17-note {{template is declared here}} \
47                                         cxx17-note {{candidate template ignored: couldn't infer template argument 'T'}} \
48                                         cxx17-note {{implicit deduction guide declared as 'template <typename T> Foo() -> Foo<T>'}} \
49                                         cxx17-note {{implicit deduction guide declared as 'template <typename T> Foo(Foo<T>) -> Foo<T>'}} \
50                                         cxx17-note {{candidate function template not viable: requires 1 argument, but 0 were provided}}
51 
52 void f(void) { Foo bar; } // precxx17-error {{use of class template 'Foo' requires template arguments}} \
53                              cxx17-error {{no viable constructor or deduction guide for deduction of template arguments of 'Foo'}}
54 
55 template <typename T> class Party;
56 template <> class Party<T> { friend struct Party<>; }; // expected-error {{use of undeclared identifier 'T'}}
57