Debian Codegraph @

clang/test/SemaTemplate/ctad.cpp

raw
1 // RUN: %clang_cc1 -std=c++17 -verify=expected,cxx17 %s
2 // RUN: %clang_cc1 -std=c++20 -verify=expected,cxx20 %s
3
4 namespace pr41427 {
5 template <typename T> class A {
6 public:
7 A(void (*)(T)) {}
8 };
9
10 void D(int) {}
11
12 void f() {
13 A a(&D);
14 using T = decltype(a);
15 using T = A<int>;
16 }
17 }
18
19 namespace Access {
20 struct B {
21 protected:
22 struct type {};
23 };
24 template<typename T> struct D : B { // expected-note {{not viable}} \
25 expected-note {{implicit deduction guide declared as 'template <typename T> D(Access::D<T>) -> Access::D<T>'}}
26 D(T, typename T::type); // expected-note {{private member}} \
27 // expected-note {{implicit deduction guide declared as 'template <typename T> D(T, typename T::type) -> Access::D<T>'}}
28 };
29 D b = {B(), {}};
30
31 class X {
32 using type = int;
33 };
34 D x = {X(), {}}; // expected-error {{no viable constructor or deduction guide}}
35
36 // Once we implement proper support for dependent nested name specifiers in
37 // friends, this should still work.
38 class Y {
39 template <typename T> friend D<T>::D(T, typename T::type); // expected-warning {{dependent nested name specifier}}
40 struct type {};
41 };
42 D y = {Y(), {}};
43
44 class Z {
45 template <typename T> friend class D;
46 struct type {};
47 };
48 D z = {Z(), {}};
49 }
50
51 namespace GH69987 {
52 template<class> struct X {};
53 template<class = void> struct X;
54 X x;
55
56 template<class T, class B> struct Y { Y(T); };
57 template<class T, class B=void> struct Y ;
58 Y y(1);
59 }
60
61 namespace NoCrashOnGettingDefaultArgLoc {
62 template <typename>
63 class A {
64 A(int = 1); // expected-note {{candidate template ignored: couldn't infer template argumen}} \
65 // expected-note {{implicit deduction guide declared as 'template <typename> D(int = <null expr>) -> NoCrashOnGettingDefaultArgLoc::D<type-parameter-0-0>'}}
66 };
67 class C : A<int> {
68 using A::A;
69 };
70 template <typename>
71 class D : C { // expected-note {{candidate function template not viable: requires 1 argument}} \
72 expected-note {{implicit deduction guide declared as 'template <typename> D(NoCrashOnGettingDefaultArgLoc::D<type-parameter-0-0>) -> NoCrashOnGettingDefaultArgLoc::D<type-parameter-0-0>'}}
73 using C::C;
74 };
75 D abc; // expected-error {{no viable constructor or deduction guide}}
76 }
77
78 namespace AsValueParameter {
79 namespace foo {
80 // cxx17-note@+2 {{template is declared here}}
81 // cxx20-note@+1 {{'A<int>' is not literal because it is not an aggregate and has no constexpr constructors other than copy or move constructors}}
82 template <class> struct A {
83 A();
84 };
85 }
86 template <foo::A> struct B {}; // expected-note {{template parameter is declared here}}
87 // cxx17-error@-1 {{use of class template 'foo::A' requires template arguments; argument deduction not allowed in template parameter}}
88
89 template struct B<foo::A<int>{}>;
90 // cxx17-error@-1 {{value of type 'foo::A<int>' is not implicitly convertible to 'int'}}
91 // cxx20-error@-2 {{non-type template parameter has non-literal type 'foo::A<int>' (aka 'AsValueParameter::foo::A<int>')}}
92 } // namespace AsValueParameter
93
94 namespace ConvertDeducedTemplateArgument {
95 namespace A {
96 template <class> struct B {};
97 }
98
99 template <template <class> class TT1> struct C {
100 C(TT1<int>);
101 };
102
103 template <template <class> class TT2> using D = TT2<int>;
104
105 auto x = C(D<A::B>());
106 }
107
108 namespace pr165560 {
109 template <class T, class> struct S {
110 using A = T;
111 template <class> struct I { // expected-note{{candidate function template not viable: requires 1 argument, but 0 were provided}} \
112 // expected-note{{implicit deduction guide declared as 'template <class> I(pr165560::S<int, int>::I<type-parameter-0-0>) -> pr165560::S<int, int>::I<type-parameter-0-0>'}}
113 I(typename A::F) {} // expected-error{{type 'A' (aka 'int') cannot be used prior to '::' because it has no members}}
114 };
115 };
116 S<int, int>::I i; // expected-error{{no viable constructor or deduction guide for deduction of template arguments of 'S<int, int>::I'}} \
117 // expected-note{{while building implicit deduction guide first needed here}}
118 }