1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
4 template <typename Iterator
>
5 void Test(Iterator it
) {
10 template<unsigned int r
>
13 static const unsigned int member
= r
;
17 template<unsigned int r
>
18 const unsigned int A
<r
>::member
;
20 template<unsigned int r
>
45 template<typename OT
> int myMethod()
46 { return 2 && sizeof(OT
); }
50 template <typename T
> T
*addressof(T
&v
) {
51 return reinterpret_cast<T
*>(
52 &const_cast<char&>(reinterpret_cast<const volatile char &>(v
)));
57 template <typename T
> class chained_map
{
66 template<typename T
> T
f() {
74 template <class _CharT
> int test(_CharT t
)
77 sizeof(_CharT
) > sizeof(char)
83 template<typename T
> struct CastDependentIntToPointer
{
86 return ((void*)(((unsigned long)(x
)|0x1ul
)));
90 // Regression test for crasher in r194540.
93 template<typename
> struct A
{
98 template<typename T
> void A
<T
>::f() {
101 template struct A
<int>;
105 template<int N
> struct A
{
106 static const int n
= {N
};
108 template struct A
<0>;
111 template<typename T
> void stmt_expr_1() {
112 static_assert( ({ false; }), "" );
115 static_assert( ({ false; }), "" ); // expected-error {{failed}}
119 struct A
{ bool x
; };
121 template<typename
> struct B
: A
{
123 const int n
= ({ if (x
) {} 0; });
127 template void B
<int>::f();
129 template<typename
> void f() {
130 decltype(({})) x
; // expected-error {{incomplete type}}
132 template void f
<int>(); // expected-note {{instantiation of}}
134 template<typename
> auto g() {
135 auto c
= [](auto, int) -> decltype(({})) {};
136 using T
= decltype(c(0.0, 0));
140 using U
= decltype(g
<int>()); // expected-note {{previous}}
141 using U
= float; // expected-error {{different types ('float' vs 'decltype(g<int>())' (aka 'void'))}}
143 void h(auto a
, decltype(g
<char>())*) {} // expected-note {{previous}}
144 void h(auto a
, void *) {} // expected-error {{redefinition}}
147 namespace BindingInStmtExpr
{
148 template<class ...Ts
> struct overload
: Ts
... {
149 overload(Ts
...ts
) : Ts(decltype(ts
)(ts
))... {}
150 using Ts::operator()...;
153 template<int> struct N
{};
155 template<class T
> auto num_bindings() {
156 auto f0
= [](auto t
, unsigned) { return N
<0>(); };
157 auto f1
= [](auto t
, int) -> decltype(({ auto [_1
] = t
; N
<1>(); })) { return {}; };
158 auto f2
= [](auto t
, int) -> decltype(({ auto [_1
, _2
] = t
; N
<2>(); })) { return {}; };
159 auto f3
= [](auto t
, int) -> decltype(({ auto [_1
, _2
, _3
] = t
; N
<3>(); })) { return {}; };
160 return decltype(overload(f0
, f1
, f2
, f3
)(T(), 0))();
163 struct T
{ int a
; int b
; };
164 // Make sure we get a correct, non-dependent type back.
165 using U
= decltype(num_bindings
<T
>()); // expected-note {{previous}}
166 using U
= N
<3>; // expected-error-re {{type alias redefinition with different types ('N<3>' vs {{.*}}N<2>}}
172 template <const A
& T
>
173 const A JoinStringViews
= T
;
178 static constexpr A Equal
{};
180 static constexpr auto Val
= JoinStringViews
<Equal
>;
182 } // namespace PR65153