1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
2 
3 // PR5908
4 template <typename Iterator>
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>
21   void A<r>::f()
22   {
23     unsigned k;
24     (void)(k % member);
25   }
26 }
27 
28 namespace PR7198 {
29   struct A
30   {
31     ~A() { }
32   };
33 
34   template<typename T>
35   struct B {
36     struct C : A {};
37     void f()
38     {
39       C c = C();
40     }
41   };
42 }
43 
44 namespace PR7724 {
45   template<typename OT> int myMethod()
46   { return 2 && sizeof(OT); }
47 }
48 
49 namespace test4 {
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;
59     void lookup() const {
60       int &v = (int &)k;
61     }
62   };
63 }
64 
65 namespace test6 {
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 {
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 {
84   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;
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 
111 template<typename T> void stmt_expr_1() {
112   static_assert( ({ false; }), "" );
113 }
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 {
122     void f() {
123       const int n = ({ if (x) {} 0; });
124     }
125   };
126 
127   template void B<int>::f();
128 
129   template<typename> void f() {
130     decltype(({})) x; // expected-error {{incomplete type}}
131   }
132   template void f<int>();
133 
134   template<typename T> void f2() {
135     decltype(({T();})) x; // expected-error {{incomplete type}}
136   }
137   template void f2<void>(); // expected-note {{instantiation of}}
138 
139   template<typename> auto g() {
140     auto c = [](auto, int) -> decltype(({})) {};
141     using T = decltype(c(0.0, 0));
142     using T = void;
143     return c(0, 0);
144   }
145   using U = decltype(g<int>()); // expected-note {{previous}}
146   using U = float; // expected-error {{different types ('float' vs 'decltype(g<int>())' (aka 'void'))}}
147 
148   void h(auto a, decltype(g<char>())*) {} // expected-note {{previous}}
149   void h(auto a, void*) {} // expected-error {{redefinition}}
150 
151   void i(auto a) {
152     [](auto a, int = ({decltype(a) i; i * 2;})){}(a); // expected-error {{invalid operands to binary expression ('decltype(a)' (aka 'void *') and 'int')}} expected-note {{in instantiation of}}
153   }
154   void use_i() {
155     i(0);
156     i((void*)0); // expected-note {{instantiation of}}
157   }
158 }
159 
160 namespace BindingInStmtExpr {
161   template<class ...Ts> struct overload : Ts... {
162     overload(Ts ...ts) : Ts(decltype(ts)(ts))... {}
163     using Ts::operator()...;
164   };
165 
166   template<int> struct N {};
167 
168   template<class T> auto num_bindings() {
169     auto f0 = [](auto t, unsigned) { return N<0>(); };
170     auto f1 = [](auto t, int) -> decltype(({ auto [_1] = t; N<1>(); })) { return {}; };
171     auto f2 = [](auto t, int) -> decltype(({ auto [_1, _2] = t; N<2>(); })) { return {}; };
172     auto f3 = [](auto t, int) -> decltype(({ auto [_1, _2, _3] = t; N<3>(); })) { return {}; };
173     return decltype(overload(f0, f1, f2, f3)(T(), 0))();
174   }
175 
176   struct T { int a; int b; };
177   // Make sure we get a correct, non-dependent type back.
178   using U = decltype(num_bindings<T>()); // expected-note {{previous}}
179   using U = N<3>; // expected-error-re {{type alias redefinition with different types ('N<3>' vs {{.*}}N<2>}}
180 }
181