1 // RUN: %clang_cc1 -std=c++11 -verify %s -pedantic
2 // RUN: %clang_cc1 -std=c++20 -verify %s -pedantic
7 struct X
{ int n
= 0; } x
;
8 // Trigger construction of X() from a SFINAE context. This must not mark
9 // any part of X as invalid.
10 static_assert(!__is_constructible(X
), "");
11 // Check that X::n is not marked invalid.
12 double &r
= x
.n
; // expected-error {{non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'}}
14 // A::X can now be default-constructed.
15 static_assert(__is_constructible(A::X
), "");
28 #if __cplusplus >= 202002L
29 // This test ensures cleanup expressions are correctly produced
30 // in the presence of default member initializers.
33 constexpr string(const char*) {};
38 template <typename U
= S
>
39 constexpr optional(U
&&) {}
51 // Ensure that the this pointer is
52 // transformed without crashing
53 consteval
int immediate() { return 0;}
54 struct StructWithThisInInitializer
{
58 int m
= member() + immediate();
59 int m2
= this->member() + immediate();
63 struct StructWithThisInInitializerTPL
{
68 int m
= member
<int>() + immediate();
69 int m2
= this->member
<int>() + immediate();
73 (void)StructWithThisInInitializer
{};
74 (void)StructWithThisInInitializerTPL
<int>{};
77 struct ReferenceToNestedMembers
{
79 int a
= ((void)immediate(), m
); // ensure g is found in the correct scope
80 int b
= ((void)immediate(), this->m
); // ensure g is found in the correct scope
82 struct ReferenceToNestedMembersTest
{
84 ReferenceToNestedMembers j
{0};
85 } test_reference_to_nested_members
;
90 namespace odr_in_unevaluated_context
{
91 template <typename e
, bool = __is_constructible(e
)> struct f
{
95 template <class k
, f
<k
>::type
= false> int l
;
98 // This used to crash because m is first marked odr used
99 // during parsing, but subsequently used in an unevaluated context
100 // without being transformed.