[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaTemplate / class-template-id.cpp
blob96696f62b78a21549fe92e9795cfa06f1eb08957
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 { };
6 typedef A<int> A_int;
8 typedef float FLOAT;
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> *'}}
22 template<int I> struct B;
24 const int value = 12;
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>}}
35 typedef B<5> B5;
38 namespace N {
39 template<typename T> struct C {};
42 N::C<int> c1;
43 typedef N::C<float> c2;
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}}
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'}}
55 template <typename T> class Party;
56 template <> class Party<T> { friend struct Party<>; }; // expected-error {{use of undeclared identifier 'T'}}