| 1 |
// RUN: %clang_cc1 -std=c++11 -verify %s -pedantic |
| 2 |
// RUN: %clang_cc1 -std=c++11 -verify %s -pedantic -fexperimental-new-constant-interpreter |
| 3 |
// RUN: %clang_cc1 -std=c++20 -verify %s -pedantic |
| 4 |
// RUN: %clang_cc1 -std=c++20 -verify %s -pedantic -fexperimental-new-constant-interpreter |
| 5 |
|
| 6 |
|
| 7 |
namespace PR31692 { |
| 8 |
struct A { |
| 9 |
struct X { int n = 0; } x; |
| 10 |
// Trigger construction of X() from a SFINAE context. This must not mark |
| 11 |
// any part of X as invalid. |
| 12 |
static_assert(!__is_constructible(X), ""); |
| 13 |
// Check that X::n is not marked invalid. |
| 14 |
double &r = x.n; // expected-error {{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}} |
| 15 |
}; |
| 16 |
// A::X can now be default-constructed. |
| 17 |
static_assert(__is_constructible(A::X), ""); |
| 18 |
} |
| 19 |
|
| 20 |
|
| 21 |
struct S { |
| 22 |
} constexpr s; |
| 23 |
struct C { |
| 24 |
C(S); |
| 25 |
}; |
| 26 |
class MemInit { |
| 27 |
C m = s; |
| 28 |
}; |
| 29 |
|
| 30 |
#if __cplusplus >= 202002L |
| 31 |
// This test ensures cleanup expressions are correctly produced |
| 32 |
// in the presence of default member initializers. |
| 33 |
namespace PR136554 { |
| 34 |
struct string { |
| 35 |
constexpr string(const char*) {}; |
| 36 |
constexpr ~string(); |
| 37 |
}; |
| 38 |
struct S; |
| 39 |
struct optional { |
| 40 |
template <typename U = S> |
| 41 |
constexpr optional(U &&) {} |
| 42 |
}; |
| 43 |
struct S { |
| 44 |
string a; |
| 45 |
optional b; |
| 46 |
int defaulted = 0; |
| 47 |
} test { |
| 48 |
"", { |
| 49 |
{ "", 0 } |
| 50 |
} |
| 51 |
}; |
| 52 |
|
| 53 |
// Ensure that the this pointer is |
| 54 |
// transformed without crashing |
| 55 |
consteval int immediate() { return 0;} |
| 56 |
struct StructWithThisInInitializer { |
| 57 |
int member() const { |
| 58 |
return 0; |
| 59 |
} |
| 60 |
int m = member() + immediate(); |
| 61 |
int m2 = this->member() + immediate(); |
| 62 |
}; |
| 63 |
|
| 64 |
template <typename T> |
| 65 |
struct StructWithThisInInitializerTPL { |
| 66 |
template <typename U> |
| 67 |
int member() const { |
| 68 |
return 0; |
| 69 |
} |
| 70 |
int m = member<int>() + immediate(); |
| 71 |
int m2 = this->member<int>() + immediate(); |
| 72 |
}; |
| 73 |
|
| 74 |
void test_this() { |
| 75 |
(void)StructWithThisInInitializer{}; |
| 76 |
(void)StructWithThisInInitializerTPL<int>{}; |
| 77 |
} |
| 78 |
|
| 79 |
struct ReferenceToNestedMembers { |
| 80 |
int m; |
| 81 |
int a = ((void)immediate(), m); // ensure g is found in the correct scope |
| 82 |
int b = ((void)immediate(), this->m); // ensure g is found in the correct scope |
| 83 |
}; |
| 84 |
struct ReferenceToNestedMembersTest { |
| 85 |
void* m = nullptr; |
| 86 |
ReferenceToNestedMembers j{0}; |
| 87 |
} test_reference_to_nested_members; |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
namespace odr_in_unevaluated_context { |
| 93 |
template <typename e, bool = __is_constructible(e)> struct f { |
| 94 |
using type = bool; |
| 95 |
}; |
| 96 |
|
| 97 |
template <class k, f<k>::type = false> int l; |
| 98 |
int m; |
| 99 |
struct p { |
| 100 |
// This used to crash because m is first marked odr used |
| 101 |
// during parsing, but subsequently used in an unevaluated context |
| 102 |
// without being transformed. |
| 103 |
int o = m; |
| 104 |
p() {} |
| 105 |
}; |
| 106 |
|
| 107 |
int i = l<p>; |
| 108 |
} |
| 109 |
|
| 110 |
#endif |