xref: /llvm-project/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp (revision 3b639d7d1d9b9f352c57460deaf70aaad238f8d9)
1 // RUN: %clang_cc1 -std=c++20 -verify %s
2 
3 template<class T> struct S {
4     template<class U> struct N {
NS::N5         N(T) {}
NS::N6         N(T, U) {}
NS::N7         template<class V> N(V, U) {}
8     };
9 };
10 
11 S<int>::N x{"a", 1};
12 using T = decltype(x);
13 using T = S<int>::N<int>;
14 
15 template<class X> struct default_ftd_argument {
16     template<class Y> struct B {
17         template<class W = X, class Z = Y, class V = Z, int I = 0> B(Y);
18     };
19 };
20 
21 default_ftd_argument<int>::B default_arg("a");
22 using DefaultArg = decltype(default_arg);
23 using DefaultArg = default_ftd_argument<int>::B<const char *>;
24 
25 template<bool> struct test;
26 template<class X> struct non_type_param {
27     template<class Y> struct B {
28         B(Y);
29         template<class Z, test<Z::value> = 0> B(Z);
30     };
31 };
32 
33 non_type_param<int>::B ntp = 5;
34 using NonTypeParam = decltype(ntp);
35 using NonTypeParam = non_type_param<int>::B<int>;
36 
37 template<typename A, typename T>
38 concept True = true;
39 
40 template<typename T>
41 concept False = false;
42 
43 template<class X> struct concepts {
44     template<class Y> struct B {
45         template<class K = X, True<K> Z> B(Y, Z);
46     };
47 };
48 
49 concepts<int>::B cc(1, 3);
50 using Concepts = decltype(cc);
51 using Concepts = concepts<int>::B<int>;
52 
53 template<class X> struct requires_clause {
54     template<class Y> struct B {
55         template<class Z> requires true
56             B(Y, Z);
57     };
58 };
59 
60 requires_clause<int>::B req(1, 2);
61 using RC = decltype(req);
62 using RC = requires_clause<int>::B<int>;
63 
64 template<typename X> struct nested_init_list {
65     template<True<X> Y>
66     struct B {
67         X x;
68         Y y;
69     };
70 
71     template<False F>
72     struct concept_fail { // #INIT_LIST_INNER_INVALID
73         X x;
74         F f;
75     };
76 };
77 
78 nested_init_list<int>::B nil {1, 2};
79 using NIL = decltype(nil);
80 using NIL = nested_init_list<int>::B<int>;
81 
82 // expected-error@+1 {{no viable constructor or deduction guide for deduction of template arguments of 'nested_init_list<int>::concept_fail'}}
83 nested_init_list<int>::concept_fail nil_invalid{1, ""};
84 // expected-note@#INIT_LIST_INNER_INVALID {{candidate template ignored: substitution failure [with F = const char *]: constraints not satisfied for class template 'concept_fail' [with F = const char *]}}
85 // expected-note@#INIT_LIST_INNER_INVALID {{implicit deduction guide declared as 'template <False F> concept_fail(int, F) -> concept_fail<F>'}}
86 // expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 1 argument, but 2 were provided}}
87 // expected-note@#INIT_LIST_INNER_INVALID {{implicit deduction guide declared as 'template <False F> concept_fail(concept_fail<F>) -> concept_fail<F>'}}
88 // expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 0 arguments, but 2 were provided}}
89 // expected-note@#INIT_LIST_INNER_INVALID {{implicit deduction guide declared as 'template <False F> concept_fail() -> concept_fail<F>'}}
90 
91 namespace GH88142 {
92 
93 template <typename, typename...> struct X {
94   template <typename> struct Y {
YGH88142::X::Y95     template <typename T> Y(T) {}
96   };
97 
98   template <typename T> Y(T) -> Y<T>;
99 };
100 
101 X<int>::Y y(42);
102 
103 } // namespace PR88142
104