57 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx23,precxx17 %std_cxx98-14 %s2// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx23,cxx17 %std_cxx17-20 %s3// RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx17,cxx23 %std_cxx23- %s4template<typename T, typename U = float> struct A { };5 6typedef A<int> A_int;7 8typedef float FLOAT;9 10A<int, FLOAT> *foo(A<int> *ptr, A<int> const *ptr2, A<int, double> *ptr3) {11 if (ptr)12 return ptr; // okay13 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 22template<int I> struct B;23 24const int value = 12;25B<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 else31 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 35typedef B<5> B5;36 37 38namespace N {39 template<typename T> struct C {};40}41 42N::C<int> c1;43typedef N::C<float> c2;44 45// PR565546template<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 52void 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 55template <typename T> class Party;56template <> class Party<T> { friend struct Party<>; }; // expected-error {{use of undeclared identifier 'T'}}57