Debian Codegraph @

clang/test/CXX/temp/temp.decls/temp.mem/p1.cpp

raw
1 // RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s
2
3 template <class T> struct A {
4 static T cond;
5
6 template <class U> struct B {
7 static T twice(U value) {
8 return (cond ? value + value : value);
9 }
10 };
11 };
12 extern template bool A<bool>::cond;
13
14 int foo() {
15 A<bool>::cond = true;
16 return A<bool>::B<int>::twice(4);
17 }
18
19 namespace PR6376 {
20 template<typename T>
21 struct X {
22 template<typename Y>
23 struct Y1 { }; //
24 };
25
26 template<>
27 struct X<float> {
28 template<typename Y>
29 struct Y1 { };
30 };
31
32 template<typename T, typename U>
33 struct Z : public X<T>::template Y1<U> { };
34
35 Z<float, int> z0;
36 }
37
38 namespace OutOfLine {
39 template<typename T>
40 struct A {
41 struct B { };
42
43 template<typename U, B V>
44 void f();
45
46 template<typename U, B V>
47 void g() { } // expected-note {{previous definition is here}}
48
49 template<typename U, B V>
50 static int x;
51
52 template<typename U, B V>
53 static int x<U*, V>;
54
55 template<typename U, B V>
56 static inline int x<U&, V> = 0; // expected-note {{previous definition is here}}
57
58 template<typename U, B V>
59 struct C;
60
61 template<typename U, B V>
62 struct C<U*, V>;
63
64 template<typename U, B V>
65 struct C<U&, V> { }; // expected-note {{previous definition is here}}
66 };
67
68 template<typename T>
69 template<typename U, typename A<T>::B V>
70 void A<T>::f() { }
71
72 template<typename T>
73 template<typename U, typename A<T>::B V>
74 void A<T>::g() { } // expected-error {{redefinition of 'g'}}
75
76 template<typename T>
77 template<typename U, typename A<T>::B V>
78 int A<T>::x = 0;
79
80 template<typename T>
81 template<typename U, typename A<T>::B V>
82 int A<T>::x<U*, V> = 0;
83
84 template<typename T>
85 template<typename U, typename A<T>::B V>
86 int A<T>::x<U&, V> = 0; // expected-error {{redefinition of 'x<U &, V>'}}
87
88 template<typename T>
89 template<typename U, typename A<T>::B V>
90 struct A<T>::C { };
91
92 template<typename T>
93 template<typename U, typename A<T>::B V>
94 struct A<T>::C<U*, V> { };
95
96 template<typename T>
97 template<typename U, typename A<T>::B V>
98 struct A<T>::C<U&, V> { }; // expected-error {{redefinition of 'C<U &, V>'}}
99
100 // FIXME: Crashes when parsing the non-type template parameter prior to C++20
101 template<>
102 template<typename U, A<int>::B V>
103 void A<int>::f() { }
104
105 template<>
106 template<typename U, A<int>::B V>
107 void A<int>::g() { } // expected-note {{previous definition is here}}
108
109 template<>
110 template<typename U, A<int>::B V>
111 void A<int>::g() { } // expected-error {{redefinition of 'g'}}
112
113 template<>
114 template<typename U, A<int>::B V>
115 int A<int>::x = 0;
116
117 template<>
118 template<typename U, A<int>::B V>
119 int A<int>::x<U*, V> = 0;
120
121 template<>
122 template<typename U, A<int>::B V>
123 int A<int>::x<U&, V> = 0; // expected-note {{previous definition is here}}
124
125 template<>
126 template<typename U, A<int>::B V>
127 int A<int>::x<U&, V> = 0; // expected-error {{redefinition of 'x<U &, V>'}}
128
129 template<>
130 template<typename U, A<int>::B V>
131 struct A<int>::C { };
132
133 template<>
134 template<typename U, A<int>::B V>
135 struct A<int>::C<U*, V> { };
136
137 template<>
138 template<typename U, A<int>::B V>
139 struct A<int>::C<U&, V> { }; // expected-note {{previous definition is here}}
140
141 template<>
142 template<typename U, A<int>::B V>
143 struct A<int>::C<U&, V> { }; // expected-error {{redefinition of 'C<U &, V>'}}
144 }