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
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'}}
16 // A::X can now be default-constructed.
17 static_assert(__is_constructible(A::X
), "");
31 typedef decltype(sizeof(int)) size_t;
33 // libc++'s implementation
34 template <class _E
> class initializer_list
{
38 initializer_list(const _E
*__b
, size_t __s
) : __begin_(__b
), __size_(__s
) {}
41 typedef _E value_type
;
42 typedef const _E
&reference
;
43 typedef const _E
&const_reference
;
44 typedef size_t size_type
;
46 typedef const _E
*iterator
;
47 typedef const _E
*const_iterator
;
49 initializer_list() : __begin_(nullptr), __size_(0) {}
51 size_t size() const { return __size_
; }
52 const _E
*begin() const { return __begin_
; }
53 const _E
*end() const { return __begin_
+ __size_
; }
57 #if __cplusplus >= 201703L
59 // Test CXXDefaultInitExpr rebuild issue in
60 // https://github.com/llvm/llvm-project/pull/87933
61 namespace test_rebuild
{
62 template <typename T
, int> class C
{
64 C(std::initializer_list
<T
>);
67 template <typename T
> using Ptr
= __remove_pointer(T
) *;
68 template <typename T
> C(T
) -> C
<Ptr
<T
>, sizeof(T
)>;
72 template <typename T1
, typename T2
> T1
*some_func(T2
&&);
76 int *ar
= some_func
<int>(C
{some_func
<int>(0)});
81 template <int> class Vector
{
83 Vector(std::initializer_list
<int>);
85 template <typename
... Ts
> Vector(Ts
...) -> Vector
<sizeof...(Ts
)>;
86 class ProgramBuilder
{
88 template <typename T
, typename ARGS
> int *create(ARGS
);
91 struct TypeTest
: ProgramBuilder
{
92 int *str_f16
= create
<int>(Vector
{0});
95 class TypeTest_Element_Test
: TypeTest
{
98 void TypeTest_Element_Test::TestBody() {
99 int *expect
= str_f16
;
100 &TestBody_got
!= expect
; // expected-warning {{inequality comparison result unused}}
102 } // namespace test_rebuild
104 // Test CXXDefaultInitExpr rebuild issue in
105 // https://github.com/llvm/llvm-project/pull/92527
106 namespace test_rebuild2
{
124 } // namespace test_rebuild2
125 #endif // __cplusplus >= 201703L
127 #if __cplusplus >= 202002L
128 // This test ensures cleanup expressions are correctly produced
129 // in the presence of default member initializers.
132 constexpr string(const char*) {};
137 template <typename U
= S
>
138 constexpr optional(U
&&) {}
150 // Ensure that the this pointer is
151 // transformed without crashing
152 consteval
int immediate() { return 0;}
153 struct StructWithThisInInitializer
{
157 int m
= member() + immediate();
158 int m2
= this->member() + immediate();
161 template <typename T
>
162 struct StructWithThisInInitializerTPL
{
163 template <typename U
>
167 int m
= member
<int>() + immediate();
168 int m2
= this->member
<int>() + immediate();
172 (void)StructWithThisInInitializer
{};
173 (void)StructWithThisInInitializerTPL
<int>{};
176 struct ReferenceToNestedMembers
{
178 int a
= ((void)immediate(), m
); // ensure g is found in the correct scope
179 int b
= ((void)immediate(), this->m
); // ensure g is found in the correct scope
181 struct ReferenceToNestedMembersTest
{
183 ReferenceToNestedMembers j
{0};
184 } test_reference_to_nested_members
;
189 namespace odr_in_unevaluated_context
{
190 template <typename e
, bool = __is_constructible(e
)> struct f
{
194 template <class k
, f
<k
>::type
= false> int l
;
197 // This used to crash because m is first marked odr used
198 // during parsing, but subsequently used in an unevaluated context
199 // without being transformed.