1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
2 
3 // PR5908
4 template <typename Iterator>
Test(Iterator it)5 void Test(Iterator it) {
6   *(it += 1);
7 }
8 
9 namespace PR6045 {
10   template<unsigned int r>
11   class A
12   {
13     static const unsigned int member = r;
14     void f();
15   };
16 
17   template<unsigned int r>
18   const unsigned int A<r>::member;
19 
20   template<unsigned int r>
f()21   void A<r>::f()
22   {
23     unsigned k;
24     (void)(k % member);
25   }
26 }
27 
28 namespace PR7198 {
29   struct A
30   {
~APR7198::A31     ~A() { }
32   };
33 
34   template<typename T>
35   struct B {
36     struct C : A {};
fPR7198::B37     void f()
38     {
39       C c = C();
40     }
41   };
42 }
43 
44 namespace PR7724 {
myMethod()45   template<typename OT> int myMethod()
46   { return 2 && sizeof(OT); }
47 }
48 
49 namespace test4 {
addressof(T & v)50   template <typename T> T *addressof(T &v) {
51     return reinterpret_cast<T*>(
52              &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
53   }
54 }
55 
56 namespace test5 {
57   template <typename T> class chained_map {
58     int k;
lookup() const59     void lookup() const {
60       int &v = (int &)k;
61     }
62   };
63 }
64 
65 namespace test6 {
f()66   template<typename T> T f() {
67     const T &v(0);
68     return v;
69   }
70   int use = f<int>();
71 }
72 
73 namespace PR8795 {
test(_CharT t)74   template <class _CharT> int test(_CharT t)
75   {
76     int data [] = {
77       sizeof(_CharT) > sizeof(char)
78     };
79     return data[0];
80   }
81 }
82 
83 template<typename T> struct CastDependentIntToPointer {
fCastDependentIntToPointer84   static void* f() {
85     T *x;
86     return ((void*)(((unsigned long)(x)|0x1ul)));
87   }
88 };
89 
90 // Regression test for crasher in r194540.
91 namespace PR10837 {
92   typedef void t(int);
93   template<typename> struct A {
94     void f();
95     static t g;
96   };
97   t *p;
f()98   template<typename T> void A<T>::f() {
99     p = g;
100   }
101   template struct A<int>;
102 }
103 
104 namespace PR18152 {
105   template<int N> struct A {
106     static const int n = {N};
107   };
108   template struct A<0>;
109 }
110 
stmt_expr_1()111 template<typename T> void stmt_expr_1() {
112   static_assert( ({ false; }), "" );
113 }
stmt_expr_2()114 void stmt_expr_2() {
115   static_assert( ({ false; }), "" ); // expected-error {{failed}}
116 }
117 
118 namespace PR45083 {
119   struct A { bool x; };
120 
121   template<typename> struct B : A {
fPR45083::B122     void f() {
123       const int n = ({ if (x) {} 0; });
124     }
125   };
126 
127   template void B<int>::f();
128 
f()129   template<typename> void f() {
130     decltype(({})) x; // expected-error {{incomplete type}}
131   }
132   template void f<int>(); // expected-note {{instantiation of}}
133 
g()134   template<typename> auto g() {
135     auto c = [](auto, int) -> decltype(({})) {};
136     using T = decltype(c(0.0, 0));
137     using T = void;
138     return c(0, 0);
139   }
140   using U = decltype(g<int>()); // expected-note {{previous}}
141   using U = float; // expected-error {{different types ('float' vs 'decltype(g<int>())' (aka 'void'))}}
142 
h(auto a,decltype(g<char> ())*)143   void h(auto a, decltype(g<char>())*) {} // expected-note {{previous}}
h(auto a,void *)144   void h(auto a, void*) {} // expected-error {{redefinition}}
145 
i(auto a)146   void i(auto a) {
147     [](auto a, int = ({decltype(a) i; i * 2;})){}(a); // expected-error {{no matching function}} expected-note {{substitution failure}}
148   }
use_i()149   void use_i() {
150     i(0);
151     i((void*)0); // expected-note {{instantiation of}}
152   }
153 }
154 
155 namespace BindingInStmtExpr {
156   template<class ...Ts> struct overload : Ts... {
overloadBindingInStmtExpr::overload157     overload(Ts ...ts) : Ts(decltype(ts)(ts))... {}
158     using Ts::operator()...;
159   };
160 
161   template<int> struct N {};
162 
num_bindings()163   template<class T> auto num_bindings() {
164     auto f0 = [](auto t, unsigned) { return N<0>(); };
165     auto f1 = [](auto t, int) -> decltype(({ auto [_1] = t; N<1>(); })) { return {}; };
166     auto f2 = [](auto t, int) -> decltype(({ auto [_1, _2] = t; N<2>(); })) { return {}; };
167     auto f3 = [](auto t, int) -> decltype(({ auto [_1, _2, _3] = t; N<3>(); })) { return {}; };
168     return decltype(overload(f0, f1, f2, f3)(T(), 0))();
169   }
170 
171   struct T { int a; int b; };
172   // Make sure we get a correct, non-dependent type back.
173   using U = decltype(num_bindings<T>()); // expected-note {{previous}}
174   using U = N<3>; // expected-error-re {{type alias redefinition with different types ('N<3>' vs {{.*}}N<2>}}
175 }
176