[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaTemplate / dependent-expr.cpp
blobce210d9b74f6d988b378c9e9abd56dedd2d43091
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
3 // PR5908
4 template <typename Iterator>
5 void Test(Iterator it) {
6 *(it += 1);
9 namespace PR6045 {
10 template<unsigned int r>
11 class A
13 static const unsigned int member = r;
14 void f();
17 template<unsigned int r>
18 const unsigned int A<r>::member;
20 template<unsigned int r>
21 void A<r>::f()
23 unsigned k;
24 (void)(k % member);
28 namespace PR7198 {
29 struct A
31 ~A() { }
34 template<typename T>
35 struct B {
36 struct C : A {};
37 void f()
39 C c = C();
44 namespace PR7724 {
45 template<typename OT> int myMethod()
46 { return 2 && sizeof(OT); }
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)));
56 namespace test5 {
57 template <typename T> class chained_map {
58 int k;
59 void lookup() const {
60 int &v = (int &)k;
65 namespace test6 {
66 template<typename T> T f() {
67 const T &v(0);
68 return v;
70 int use = f<int>();
73 namespace PR8795 {
74 template <class _CharT> int test(_CharT t)
76 int data [] = {
77 sizeof(_CharT) > sizeof(char)
79 return data[0];
83 template<typename T> struct CastDependentIntToPointer {
84 static void* f() {
85 T *x;
86 return ((void*)(((unsigned long)(x)|0x1ul)));
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;
97 t *p;
98 template<typename T> void A<T>::f() {
99 p = g;
101 template struct A<int>;
104 namespace PR18152 {
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; }), "" );
114 void stmt_expr_2() {
115 static_assert( ({ false; }), "" ); // expected-error {{failed}}
118 namespace PR45083 {
119 struct A { bool x; };
121 template<typename> struct B : A {
122 void f() {
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));
137 using T = void;
138 return c(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>}}
169 namespace PR65153 {
170 struct A{};
172 template <const A& T>
173 const A JoinStringViews = T;
175 template <int V>
176 class Builder {
177 public:
178 static constexpr A Equal{};
179 // no crash here
180 static constexpr auto Val = JoinStringViews<Equal>;
182 } // namespace PR65153