// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-linux -Wno-c++11-narrowing -Wno-literal-conversion -std=c++20 -verify %s namespace test1 { template struct Foo { T t; }; template using Bar = Foo; Bar s = {1}; } // namespace test1 namespace test2 { template struct XYpair { X x; Y y; }; // A tricky explicit deduction guide that swapping X and Y. template XYpair(X, Y) -> XYpair; template using AliasXYpair = XYpair; AliasXYpair xy = {1.1, 2}; // XYpair static_assert(__is_same(decltype(xy.x), int)); static_assert(__is_same(decltype(xy.y), double)); } // namespace test2 namespace test3 { template struct container { // test with default arguments. container(T a, T b = T()); }; template using vector = container; vector v(0, 0); } // namespace test3 namespace test4 { // Explicit deduction guide. template struct X { T t; X(T); }; template X(T) -> X; template using AX = X; AX s = {1}; static_assert(__is_same(decltype(s.t), double)); // explicit one is picked. } // namespace test4 namespace test5 { template struct Foo {}; // Template parameter pack template using AF = Foo<1>; auto a = AF{}; } // namespace test5 namespace test6 { // non-type template argument. template struct Foo { Foo(T); }; template using AF = Foo; AF b{0}; } // namespace test6 namespace test7 { template struct Foo { Foo(T); }; // using alias chain. template using AF1 = Foo; template using AF2 = AF1; AF2 b = 1; } // namespace test7 namespace test8 { template struct Foo { Foo(T const (&)[N]); }; template using Bar = Foo; Bar s = {{1}}; } // namespace test8 namespace test9 { template struct Foo { Foo(T const (&)[N]); }; template using Bar = Foo; // expected-note {{candidate template ignored: couldn't infer template argument 'X'}} \ // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test9::Bar, test9::Foo) Bar(test9::Foo) -> test9::Foo'}} \ // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test9::Bar, test9::Foo) Bar(const X (&)[sizeof(X)]) -> test9::Foo'}} \ // expected-note {{candidate template ignored: constraints not satisfied [with X = int]}} \ // expected-note {{cannot deduce template arguments for 'test9::Bar' from 'test9::Foo'}} Bar s = {{1}}; // expected-error {{no viable constructor or deduction guide }} } // namespace test9 namespace test10 { template struct Foo { template Foo(U); }; template Foo(U) -> Foo; template using A = Foo; A a(2); // Foo } // namespace test10 namespace test11 { struct A {}; template struct Foo { T c; }; template using AFoo = Foo; // expected-note {{candidate template ignored: could not match 'test11::Foo' against 'int'}} \ // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test11::AFoo, test11::Foo) AFoo(test11::Foo) -> test11::Foo'}} \ // expected-note {{candidate template ignored: constraints not satisfied [with Y = int]}} \ // expected-note {{cannot deduce template arguments for 'test11::AFoo' from 'test11::Foo'}} \ // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test11::AFoo, test11::Foo) AFoo(Y) -> test11::Foo'}} \ // expected-note {{candidate function template not viable: requires 0 arguments, but 1 was provided}} \ // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test11::AFoo, test11::Foo) AFoo() -> test11::Foo'}} AFoo s = {1}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'AFoo'}} } // namespace test11 namespace test12 { // no crash on null access attribute template struct Foo { template struct Bar { Bar(K); }; template using ABar = Bar; void test() { ABar k = 2; } }; void func(Foo s) { s.test(); } } // namespace test12 namespace test13 { template struct Foo { Foo(Ts...); }; template using AFoo = Foo; auto b = AFoo{}; AFoo a(1, 2); template using BFoo = Foo; BFoo b2(1.0, 2.0); } // namespace test13 namespace test14 { template concept IsInt = __is_same(decltype(T()), int); template struct Foo { Foo(T const (&)[N]); }; template using Bar = Foo; // expected-note {{constraints not satisfied for class template 'Foo'}} // expected-note@-1 {{candidate template ignored: could not match}} expected-note@-1 {{candidate template ignored: constraints not satisfied}} // expected-note@-2 {{implicit deduction guide declared as 'template requires __is_deducible(test14::Bar, test14::Foo) Bar(test14::Foo) -> test14::Foo'}} // expected-note@-3 {{implicit deduction guide declared as 'template requires __is_deducible(test14::Bar, test14::Foo) Bar(const double (&)[K]) -> test14::Foo'}} double abc[3]; Bar s2 = {abc}; // expected-error {{no viable constructor or deduction guide for deduction }} } // namespace test14 namespace test15 { template struct Foo { Foo(T); }; template using AFoo = Foo; template concept False = false; // #test15_False template using BFoo = AFoo; // expected-note {{candidate template ignored: constraints not satisfied [with W = int]}} \ // expected-note@-1 {{because 'int' does not satisfy 'False'}} \ // expected-note@#test15_False {{because 'false' evaluated to false}} \ // expected-note {{implicit deduction guide declared as 'template W> requires __is_deducible(test15::AFoo, test15::Foo) && __is_deducible(test15::BFoo, test15::Foo) BFoo(W *) -> test15::Foo}} \ // expected-note {{candidate template ignored: could not match 'test15::Foo' against 'int *'}} \ // expected-note {{template W> requires __is_deducible(test15::AFoo, test15::Foo) && __is_deducible(test15::BFoo, test15::Foo) BFoo(test15::Foo) -> test15::Foo}} int i = 0; AFoo a1(&i); // OK, deduce Foo // the W is not deduced from the deduced type Foo. BFoo b2(&i); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'BFoo'}} } // namespace test15 namespace test16 { struct X { X(int); X(const X&); }; template struct Foo { T t; Foo(T t) : t(t) {} }; template using AFoo = Foo; int i = 0; AFoo s{i}; static_assert(__is_same(decltype(s.t), int)); template using BFoo = AFoo; // template explicit deduction guide. template Foo(T) -> Foo; static_assert(__is_same(decltype(AFoo(i).t), float)); static_assert(__is_same(decltype(BFoo(i).t), float)); // explicit deduction guide. Foo(int) -> Foo; static_assert(__is_same(decltype(AFoo(i).t), X)); static_assert(__is_same(decltype(BFoo(i).t), X)); Foo(double) -> Foo; static_assert(__is_same(decltype(AFoo(1.0).t), int)); static_assert(__is_same(decltype(BFoo(1.0).t), int)); } // namespace test16 namespace test17 { template struct Foo { T t; }; // CTAD for alias templates only works for the RHS of the alias of form of // [typename] [nested-name-specifier] [template] simple-template-id template using AFoo = Foo*; // expected-note {{template is declared here}} AFoo s = {1}; // expected-error {{alias template 'AFoo' requires template arguments; argument deduction only allowed for}} } // namespace test17 namespace test18 { template concept False = false; // expected-note {{because 'false' evaluated to false}} template struct Foo { T t; }; template requires False // expected-note {{because 'int' does not satisfy 'False'}} Foo(T) -> Foo; template using Bar = Foo; // expected-note {{could not match 'test18::Foo' against 'int'}} \ // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test18::Bar, test18::Foo) Bar(test18::Foo) -> test18::Foo'}} \ // expected-note {{candidate template ignored: constraints not satisfied}} \ // expected-note {{implicit deduction guide declared as 'template requires False && __is_deducible(test18::Bar, Foo) Bar(T) -> Foo'}} \ // expected-note {{candidate function template not viable}} \ // expected-note {{implicit deduction guide declared as 'template requires __is_deducible(test18::Bar, test18::Foo) Bar() -> test18::Foo'}} Bar s = {1}; // expected-error {{no viable constructor or deduction guide for deduction of template arguments}} } // namespace test18 // GH85406, verify no crash on invalid alias templates. namespace test19 { template class Foo {}; template template using Bar2 = Foo; // expected-error {{extraneous template parameter list in alias template declaration}} Bar2 b = 1; // expected-error {{no viable constructor or deduction guide for deduction of template arguments}} } // namespace test19 // GH85385 namespace test20 { template