1 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -pedantic-errors -verify=expected,cxx98 %s
2 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -pedantic-errors -verify=expected %s
3 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++14 -pedantic-errors -verify=expected %s
4 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++17 -pedantic-errors -verify=expected %s
5 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++20 -pedantic-errors -verify=expected,since-cxx20 %s
6 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -pedantic-errors -verify=expected,since-cxx20,since-cxx23 %s
7 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++2c -pedantic-errors -verify=expected,since-cxx20,since-cxx23,since-cxx26 %s
9 #if __cplusplus == 199711L
10 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
11 // cxx98-error@-1 {{variadic macros are a C99 feature}}
14 #if __cplusplus == 199711L
15 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
17 #define __enable_constant_folding
21 #if __cplusplus >= 202002L
22 struct strong_ordering
{
24 constexpr operator int() const { return n
; }
25 static const strong_ordering less
, equal
, greater
;
27 constexpr strong_ordering
strong_ordering::less
{-1},
28 strong_ordering::equal
{0}, strong_ordering::greater
{1};
32 namespace cwg2707
{ // cwg2707: 20
34 #if __cplusplus >= 202002L
36 template <class T
, unsigned N
> struct A
{ // #cwg2707-A
40 template <typename
... T
>
41 A(T
...) -> A
<int, sizeof...(T
)> requires (sizeof...(T
) == 2); // #cwg2707-guide-A
43 // Brace elision is not allowed for synthesized CTAD guides if the array size
44 // is value-dependent.
45 // So this should pick up our explicit deduction guide.
49 // since-cxx20-error@-1 {{no viable constructor or deduction guide}}
50 // since-cxx20-note@#cwg2707-A {{candidate function template not viable}}
51 // since-cxx20-note@#cwg2707-A {{implicit deduction guide}}
52 // since-cxx20-note@#cwg2707-guide-A {{constraints not satisfied}}
53 // since-cxx20-note@#cwg2707-guide-A {{because 'sizeof...(T) == 2' (3 == 2) evaluated to false}}
54 // since-cxx20-note@#cwg2707-A {{candidate function template not viable}}
55 // since-cxx20-note@#cwg2707-A {{implicit deduction guide}}
59 } // namespace cwg2707
61 namespace cwg2718
{ // cwg2718: 2.7
67 // expected-error@-1 {{non-const lvalue reference to type 'D' cannot bind to a value of unrelated type 'B'}}
71 } // namespace cwg2718
73 namespace cwg2749
{ // cwg2749: 20
82 static_assert(__enable_constant_folding(static_cast<void*>(&x
[0]) < static_cast<void*>(&x
[1])), "");
83 static_assert(__enable_constant_folding(static_cast<void*>(&y
[0].i
) < static_cast<void*>(&y
[0].j
)), "");
84 static_assert(__enable_constant_folding(static_cast<void*>(&y
[0].j
) < static_cast<void*>(&y
[1].i
)), "");
86 #if __cplusplus >= 202002L
87 static_assert((static_cast<void*>(&x
[0]) <=> static_cast<void*>(&x
[1])) == std::strong_ordering::less
);
88 static_assert((static_cast<void*>(&y
[0].i
) <=> static_cast<void*>(&y
[0].j
)) == std::strong_ordering::less
);
89 static_assert((static_cast<void*>(&y
[0].j
) <=> static_cast<void*>(&y
[1].i
)) == std::strong_ordering::less
);
92 } // namespace cwg2749
94 namespace cwg2759
{ // cwg2759: 19
95 #if __cplusplus >= 201103L
102 struct CEmptyStruct
{};
103 struct CEmptyStruct2
{};
105 struct CStructNoUniqueAddress
{
107 [[no_unique_address
]] int two
;
110 struct CStructNoUniqueAddress2
{
112 [[no_unique_address
]] int two
;
119 [[no_unique_address
]] CEmptyStruct d
;
120 [[no_unique_address
]] CEmptyStruct2 e
;
128 [[no_unique_address
]] CEmptyStruct d
;
135 [[no_unique_address
]] CEmptyStruct d
;
138 struct StructWithAnonUnion
{
143 [[no_unique_address
]] CEmptyStruct d
;
144 [[no_unique_address
]] CEmptyStruct2 e
;
148 struct StructWithAnonUnion2
{
154 [[no_unique_address
]] CEmptyStruct d
;
158 struct StructWithAnonUnion3
{
164 [[no_unique_address
]] CEmptyStruct d
;
168 static_assert(__is_layout_compatible(CStruct
, CStructNoUniqueAddress
) != bool(__has_cpp_attribute(no_unique_address
)), "");
169 static_assert(__is_layout_compatible(CStructNoUniqueAddress
, CStructNoUniqueAddress2
) != bool(__has_cpp_attribute(no_unique_address
)), "");
170 static_assert(!__is_layout_compatible(UnionLayout
, UnionLayout2
), "");
171 static_assert(!__is_layout_compatible(UnionLayout
, UnionLayout3
), "");
172 static_assert(!__is_layout_compatible(StructWithAnonUnion
, StructWithAnonUnion2
), "");
173 static_assert(!__is_layout_compatible(StructWithAnonUnion
, StructWithAnonUnion3
), "");
175 } // namespace cwg2759
177 namespace cwg2789
{ // cwg2789: 18
178 #if __cplusplus >= 202302L
179 template <typename T
= int>
181 constexpr void g(); // #cwg2789-g1
184 template <typename T
= int>
186 constexpr void g() requires
true; // #cwg2789-g2
189 template <typename T
= int>
190 struct S
: Base
<T
>, Base2
<T
> {
192 constexpr void f(this S
&) requires
true{};
202 // since-cxx23-error@-1 {{call to member function 'g' is ambiguous}}
203 // since-cxx23-note@#cwg2789-g1 {{candidate function}}
204 // since-cxx23-note@#cwg2789-g2 {{candidate function}}
209 namespace cwg2798
{ // cwg2798: 17
210 #if __cplusplus > 202302L
213 data_
= new char[6]();
214 __builtin_memcpy(data_
, "Hello", 5);
217 constexpr ~string() { delete[] data_
; }
218 constexpr unsigned long size() const { return 5; };
219 constexpr const char *data() const { return data_
; }
226 consteval X
f() { return {}; }
228 static_assert(false, f().s
);
229 // since-cxx26-error@-1 {{static assertion failed: Hello}}
231 } // namespace cwg2798