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