183 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s2 3// PR59084template <typename Iterator>5void Test(Iterator it) {6 *(it += 1);7}8 9namespace PR6045 {10 template<unsigned int r>11 class A12 {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 28namespace PR7198 {29 struct A30 {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 44namespace PR7724 {45 template<typename OT> int myMethod()46 { return 2 && sizeof(OT); }47}48 49namespace 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 56namespace test5 {57 template <typename T> class chained_map {58 int k;59 void lookup() const {60 int &v = (int &)k;61 }62 };63}64 65namespace test6 {66 template<typename T> T f() {67 const T &v(0);68 return v;69 }70 int use = f<int>();71}72 73namespace 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 83template<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.91namespace 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 104namespace PR18152 {105 template<int N> struct A {106 static const int n = {N};107 };108 template struct A<0>;109}110 111template<typename T> void stmt_expr_1() {112 static_assert( ({ false; }), "" );113}114void stmt_expr_2() {115 static_assert( ({ false; }), "" ); // expected-error {{failed}}116}117 118namespace 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>(); // expected-note {{instantiation of}}133 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 143 void h(auto a, decltype(g<char>())*) {} // expected-note {{previous}}144 void h(auto a, void *) {} // expected-error {{redefinition}}145}146 147namespace BindingInStmtExpr {148 template<class ...Ts> struct overload : Ts... {149 overload(Ts ...ts) : Ts(decltype(ts)(ts))... {}150 using Ts::operator()...;151 };152 153 template<int> struct N {};154 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))();161 }162 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>}}167}168 169namespace PR65153 {170struct A{};171 172template <const A& T>173const A JoinStringViews = T;174 175template <int V>176class Builder {177public:178 static constexpr A Equal{};179 // no crash here180 static constexpr auto Val = JoinStringViews<Equal>;181};182} // namespace PR65153183