1 // RUN: %clang_cc1 -std=c++20 -pedantic -verify %s
5 static constexpr int value
= 1;
11 // it is a qualified name in a type-id-only context (see below), or
12 // [its smallest enclosing [/new/defining/]-type-id is]:
14 auto *Ptr
= new T::type();
15 // - a defining-type-id
16 class T::tclass Empty1
;
17 T::tclass Empty2
; // expected-error{{missing 'typename'}}
18 // - a trailing-return-type
20 // - default argument of a type-parameter of a template [see below]
24 auto StaticCast
= static_cast<T::type
>(1.2);
26 const auto *ConstCast
= const_cast<const T::type
*>(Ptr
);
28 int ReinterpretCast
= reinterpret_cast<T::type
>(4);
31 virtual ~B() = default;
33 struct D
: T::tclass
{};
34 auto *Base
= dynamic_cast<T::tclass
*>(new B
);
36 T::type Invalid
; // expected-error{{missing 'typename'}}
41 // As default argument.
42 template <typename T
, typename
= T::type
>
45 template struct DefaultArg
<X
>;
47 // it is a decl-specifier of the decl-specifier-seq of a
48 // - simple-declaration or a function-definition in namespace scope
52 template int VarTemp
<X
>;
55 T::type
FuncDef() { return 1; }
57 template int FuncDef
<X
>();
63 void FuncParam(T::type
); // ok, but variable template
64 // expected-error@-1{{variable has incomplete type 'void'}}
67 void FuncParam2(const T::type
, int); // expected-error{{missing 'typename'}}
71 // member-declaration,
74 // parameter-declaration in a member-declaration, unless that
75 // parameter-declaration appears in a default argument
76 void NoDefault(T::type
);
77 void Default(int A
= T::value
);
80 template struct MemberDecl
<X
>;
82 // parameter-declaration in a declarator of a function or function template
83 // declaration where the declarator-id is qualified, unless that
84 // parameter-declaration appears in a default argument,
85 struct QualifiedFunc
{
87 void foo(typename
T::type
);
93 void QualifiedFunc::foo(T::type
) {}
95 void QualifiedFunc::bar(typename
T::type
) {}
99 // parameter-declaration in a lambda-declarator, unless that
100 // parameter-declaration appears in a default argument, or
101 auto Lambda1
= [](T::type
) {};
102 auto Lambda2
= [](int A
= T::value
) {};
105 template void g
<X
>();
107 // parameter-declaration of a (non-type) template-parameter.
108 template <typename T
, T::type
>
111 template void NonTypeArg
<X
, 0>();
113 template <typename T
>
114 void f(T::type
) {} // expected-error {{missing 'typename'}}
117 template <typename T
>
118 int f(typename
T::type
);
119 template <typename T
>
123 template <typename T
>
124 int N::f(T::type
); // ok, function
125 template <typename T
>
126 int N::Var(T::value
); // ok, variable
129 return N::f
<X
>(10) + N::Var
<X
>;
133 inline namespace A
{ template <typename T
> int f(typename
T::type
); } // expected-note{{previous definition is here}}
134 inline namespace B
{ template <typename T
> int f(T::type
); }
137 template <typename T
>
138 int NN::f(T::type
); // expected-error{{redefinition of 'f' as different kind of symbol}}
142 static constexpr auto value
= V
;
145 template <typename T
,
147 bool = bool(T::value
),
148 bool = videntity
<bool(T::value
)>::value
>
149 void f(int = T::value
) {}
151 template <typename
> int test() = delete;
152 template <auto> int test();
154 template <typename T
>
155 int Test
= test
<int(T::value
)>();
156 template int Test
<X
>;
158 template<typename T
> struct A
{
159 enum E
: T::type
{}; // expected-error{{missing 'typename'}}
160 operator T::type() {} // expected-error{{missing 'typename'}}
161 void f() { this->operator T::type(); } // expected-error{{missing 'typename'}}
166 C(T::type
); // implicit typename context
167 friend C (T::fn
)(); // not implicit typename context, declarator-id of friend declaration
168 C(T::type::*x
)[3]; // not implicit typename context, pointer-to-member type
171 template <typename T
>
180 template<typename T
> struct S
{
181 friend X::X(T::type
);
182 friend X::X(T::type
= (int)(void(*)(typename
T::type
))(nullptr)); // expected-error {{friend declaration specifying a default argument must be a definition}}
183 friend X::X(T::type
= (int)(void(*)(T::type
))(nullptr)); // expected-error {{friend declaration specifying a default argument must be a definition}} \
184 // expected-error {{expected expression}}
185 friend void X::f(T::type
);