| 1 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -pedantic-errors -verify=expected %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 %s |
| 6 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -pedantic-errors -verify=expected,since-cxx23 %s |
| 7 |
// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++2c -pedantic-errors -verify=expected,since-cxx23,since-cxx26 %s |
| 8 |
|
| 9 |
namespace cwg2718 { // cwg2718: 2.7 |
| 10 |
struct B {}; |
| 11 |
struct D; |
| 12 |
|
| 13 |
void f(B b) { |
| 14 |
static_cast<D&>(b); |
| 15 |
// expected-error@-1 {{non-const lvalue reference to type 'D' cannot bind to a value of unrelated type 'B'}} |
| 16 |
} |
| 17 |
|
| 18 |
struct D : B {}; |
| 19 |
} // namespace cwg2718 |
| 20 |
|
| 21 |
namespace cwg2759 { // cwg2759: 19 |
| 22 |
#if __cplusplus >= 201103L |
| 23 |
|
| 24 |
struct CStruct { |
| 25 |
int one; |
| 26 |
int two; |
| 27 |
}; |
| 28 |
|
| 29 |
struct CEmptyStruct {}; |
| 30 |
struct CEmptyStruct2 {}; |
| 31 |
|
| 32 |
struct CStructNoUniqueAddress { |
| 33 |
int one; |
| 34 |
[[no_unique_address]] int two; |
| 35 |
}; |
| 36 |
|
| 37 |
struct CStructNoUniqueAddress2 { |
| 38 |
int one; |
| 39 |
[[no_unique_address]] int two; |
| 40 |
}; |
| 41 |
|
| 42 |
union UnionLayout { |
| 43 |
int a; |
| 44 |
double b; |
| 45 |
CStruct c; |
| 46 |
[[no_unique_address]] CEmptyStruct d; |
| 47 |
[[no_unique_address]] CEmptyStruct2 e; |
| 48 |
}; |
| 49 |
|
| 50 |
union UnionLayout2 { |
| 51 |
CStruct c; |
| 52 |
int a; |
| 53 |
CEmptyStruct2 e; |
| 54 |
double b; |
| 55 |
[[no_unique_address]] CEmptyStruct d; |
| 56 |
}; |
| 57 |
|
| 58 |
union UnionLayout3 { |
| 59 |
CStruct c; |
| 60 |
int a; |
| 61 |
double b; |
| 62 |
[[no_unique_address]] CEmptyStruct d; |
| 63 |
}; |
| 64 |
|
| 65 |
struct StructWithAnonUnion { |
| 66 |
union { |
| 67 |
int a; |
| 68 |
double b; |
| 69 |
CStruct c; |
| 70 |
[[no_unique_address]] CEmptyStruct d; |
| 71 |
[[no_unique_address]] CEmptyStruct2 e; |
| 72 |
}; |
| 73 |
}; |
| 74 |
|
| 75 |
struct StructWithAnonUnion2 { |
| 76 |
union { |
| 77 |
CStruct c; |
| 78 |
int a; |
| 79 |
CEmptyStruct2 e; |
| 80 |
double b; |
| 81 |
[[no_unique_address]] CEmptyStruct d; |
| 82 |
}; |
| 83 |
}; |
| 84 |
|
| 85 |
struct StructWithAnonUnion3 { |
| 86 |
union { |
| 87 |
CStruct c; |
| 88 |
int a; |
| 89 |
CEmptyStruct2 e; |
| 90 |
double b; |
| 91 |
[[no_unique_address]] CEmptyStruct d; |
| 92 |
} u; |
| 93 |
}; |
| 94 |
|
| 95 |
static_assert(__is_layout_compatible(CStruct, CStructNoUniqueAddress) != bool(__has_cpp_attribute(no_unique_address)), ""); |
| 96 |
static_assert(__is_layout_compatible(CStructNoUniqueAddress, CStructNoUniqueAddress2) != bool(__has_cpp_attribute(no_unique_address)), ""); |
| 97 |
static_assert(!__is_layout_compatible(UnionLayout, UnionLayout2), ""); |
| 98 |
static_assert(!__is_layout_compatible(UnionLayout, UnionLayout3), ""); |
| 99 |
static_assert(!__is_layout_compatible(StructWithAnonUnion, StructWithAnonUnion2), ""); |
| 100 |
static_assert(!__is_layout_compatible(StructWithAnonUnion, StructWithAnonUnion3), ""); |
| 101 |
#endif |
| 102 |
} // namespace cwg2759 |
| 103 |
|
| 104 |
namespace cwg2789 { // cwg2789: 18 |
| 105 |
#if __cplusplus >= 202302L |
| 106 |
template <typename T = int> |
| 107 |
struct Base { |
| 108 |
constexpr void g(); // #cwg2789-g1 |
| 109 |
}; |
| 110 |
|
| 111 |
template <typename T = int> |
| 112 |
struct Base2 { |
| 113 |
constexpr void g() requires true; // #cwg2789-g2 |
| 114 |
}; |
| 115 |
|
| 116 |
template <typename T = int> |
| 117 |
struct S : Base<T>, Base2<T> { |
| 118 |
constexpr void f(); |
| 119 |
constexpr void f(this S&) requires true{}; |
| 120 |
|
| 121 |
using Base<T>::g; |
| 122 |
using Base2<T>::g; |
| 123 |
}; |
| 124 |
|
| 125 |
void test() { |
| 126 |
S<> s; |
| 127 |
s.f(); |
| 128 |
s.g(); |
| 129 |
// since-cxx23-error@-1 {{call to member function 'g' is ambiguous}} |
| 130 |
// since-cxx23-note@#cwg2789-g1 {{candidate function}} |
| 131 |
// since-cxx23-note@#cwg2789-g2 {{candidate function}} |
| 132 |
} |
| 133 |
#endif |
| 134 |
} |
| 135 |
|
| 136 |
namespace cwg2798 { // cwg2798: 17 |
| 137 |
#if __cpp_static_assert >= 202306 |
| 138 |
struct string { |
| 139 |
constexpr string() { |
| 140 |
data_ = new char[6](); |
| 141 |
__builtin_memcpy(data_, "Hello", 5); |
| 142 |
data_[5] = 0; |
| 143 |
} |
| 144 |
constexpr ~string() { delete[] data_; } |
| 145 |
constexpr unsigned long size() const { return 5; }; |
| 146 |
constexpr const char *data() const { return data_; } |
| 147 |
|
| 148 |
char *data_; |
| 149 |
}; |
| 150 |
struct X { |
| 151 |
string s; |
| 152 |
}; |
| 153 |
consteval X f() { return {}; } |
| 154 |
|
| 155 |
static_assert(false, f().s); |
| 156 |
// since-cxx26-error@-1 {{static assertion failed: Hello}} |
| 157 |
#endif |
| 158 |
} // namespace cwg2798 |
| 159 |
|