Debian Codegraph @

clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp

raw
1 // RUN: %clang_cc1 -std=c++20 -verify %s
2
3 template<class T> struct S {
4 template<class U> struct N {
5 N(T) {}
6 N(T, U) {}
7 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; // #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> // #INIT_LIST_INNER_INVALID_HEADER
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: constraints not satisfied [with F = const char *]}}
85 // expected-note@#INIT_LIST_INNER_INVALID_HEADER {{because 'const char *' does not satisfy 'False'}}
86 // expected-note@#False {{because 'false' evaluated to false}}
87 // expected-note@#INIT_LIST_INNER_INVALID {{implicit deduction guide declared as 'template <False F> concept_fail(int, F) -> nested_init_list<int>::concept_fail<F>'}}
88 // expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 1 argument, but 2 were provided}}
89 // expected-note@#INIT_LIST_INNER_INVALID {{implicit deduction guide declared as 'template <False F> concept_fail(nested_init_list<int>::concept_fail<F>) -> nested_init_list<int>::concept_fail<F>'}}
90 // expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 0 arguments, but 2 were provided}}
91 // expected-note@#INIT_LIST_INNER_INVALID {{implicit deduction guide declared as 'template <False F> concept_fail() -> nested_init_list<int>::concept_fail<F>'}}
92
93 namespace GH88142 {
94
95 template <typename, typename...> struct X {
96 template <typename> struct Y {
97 template <typename T> Y(T) {}
98 };
99
100 template <typename T> Y(T) -> Y<T>;
101 };
102
103 X<int>::Y y(42);
104
105 } // namespace PR88142