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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
|
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
#if __cplusplus < 201103L
// expected-error@+1 {{variadic macro}}
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
#endif
namespace dr1812 { // dr1812: no
// NB: dup 1710
#if __cplusplus >= 201103L
template <typename T> struct A {
using B = typename T::C<int>;
// expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent template name}}
};
#endif
} // namespace dr1812
namespace dr1813 { // dr1813: 7
struct B { int i; };
struct C : B {};
struct D : C {};
struct E : D { char : 4; };
static_assert(__is_standard_layout(B), "");
static_assert(__is_standard_layout(C), "");
static_assert(__is_standard_layout(D), "");
static_assert(!__is_standard_layout(E), "");
struct Q {};
struct S : Q {};
struct T : Q {};
struct U : S, T {};
static_assert(__is_standard_layout(Q), "");
static_assert(__is_standard_layout(S), "");
static_assert(__is_standard_layout(T), "");
static_assert(!__is_standard_layout(U), "");
}
namespace dr1814 { // dr1814: yes
#if __cplusplus >= 201103L
void test() {
auto lam = [](int x = 42) { return x; };
}
#endif
}
namespace dr1815 { // dr1815: no
#if __cplusplus >= 201402L
// FIXME: needs codegen test
struct A { int &&r = 0; }; // expected-note {{default member init}}
A a = {}; // FIXME expected-warning {{not supported}}
struct B { int &&r = 0; }; // expected-error {{binds to a temporary}} expected-note {{default member init}}
B b; // expected-note {{here}}
#endif
}
namespace dr1821 { // dr1821: yes
struct A {
template <typename> struct B {
void f();
};
template <typename T> void B<T>::f(){};
// expected-error@-1 {{non-friend class member 'f' cannot have a qualified name}}
struct C {
void f();
};
void C::f() {}
// expected-error@-1 {{non-friend class member 'f' cannot have a qualified name}}
};
} // namespace dr1821
namespace dr1822 { // dr1822: yes
#if __cplusplus >= 201103L
int a;
auto x = [] (int a) {
#pragma clang __debug dump a // CHECK: ParmVarDecl
};
#endif
}
namespace dr1837 { // dr1837: 3.3
#if __cplusplus >= 201103L
template <typename T>
struct Fish { static const bool value = true; };
struct Other {
int p();
auto q() -> decltype(p()) *;
};
class Outer {
friend auto Other::q() -> decltype(this->p()) *; // expected-error {{invalid use of 'this'}}
int g();
int f() {
extern void f(decltype(this->g()) *);
struct Inner {
static_assert(Fish<decltype(this->g())>::value, ""); // expected-error {{invalid use of 'this'}}
enum { X = Fish<decltype(this->f())>::value }; // expected-error {{invalid use of 'this'}}
struct Inner2 : Fish<decltype(this->g())> { }; // expected-error {{invalid use of 'this'}}
friend void f(decltype(this->g()) *); // expected-error {{invalid use of 'this'}}
friend auto Other::q() -> decltype(this->p()) *; // expected-error {{invalid use of 'this'}}
};
return 0;
}
};
struct A {
int f();
bool b = [] {
struct Local {
static_assert(sizeof(this->f()) == sizeof(int), "");
};
};
};
#endif
}
namespace dr1872 { // dr1872: 9
#if __cplusplus >= 201103L
template<typename T> struct A : T {
constexpr int f() const { return 0; }
};
struct X {};
struct Y { virtual int f() const; };
struct Z : virtual X {};
constexpr int x = A<X>().f();
constexpr int y = A<Y>().f();
#if __cplusplus <= 201703L
// expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
#else
static_assert(y == 0);
#endif
// Note, this is invalid even though it would not use virtual dispatch.
constexpr int y2 = A<Y>().A<Y>::f();
#if __cplusplus <= 201703L
// expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
#else
static_assert(y == 0);
#endif
constexpr int z = A<Z>().f(); // expected-error {{constant expression}} expected-note {{non-literal type}}
#endif
}
namespace dr1881 { // dr1881: 7
struct A { int a : 4; };
struct B : A { int b : 3; };
static_assert(__is_standard_layout(A), "");
static_assert(!__is_standard_layout(B), "");
struct C { int : 0; };
struct D : C { int : 0; };
static_assert(__is_standard_layout(C), "");
static_assert(!__is_standard_layout(D), "");
}
void dr1891() { // dr1891: 4
#if __cplusplus >= 201103L
int n;
auto a = []{}; // expected-note 0-4{{}}
auto b = [=]{ return n; }; // expected-note 0-4{{}}
typedef decltype(a) A;
typedef decltype(b) B;
static_assert(!__has_trivial_constructor(A), "");
#if __cplusplus > 201703L
// expected-error@-2 {{failed}}
#endif
static_assert(!__has_trivial_constructor(B), "");
// C++20 allows default construction for non-capturing lambdas (P0624R2).
A x;
#if __cplusplus <= 201703L
// expected-error@-2 {{no matching constructor}}
#endif
B y; // expected-error {{no matching constructor}}
// C++20 allows assignment for non-capturing lambdas (P0624R2).
a = a;
a = static_cast<A&&>(a);
#if __cplusplus <= 201703L
// expected-error@-3 {{copy assignment operator is implicitly deleted}}
// expected-error@-3 {{copy assignment operator is implicitly deleted}}
#endif
b = b; // expected-error {{copy assignment operator is implicitly deleted}}
b = static_cast<B&&>(b); // expected-error {{copy assignment operator is implicitly deleted}}
#endif
}
namespace dr1894 { // dr1894: 3.8
// NB: reusing part of dr407 test
namespace A {
struct S {};
}
namespace B {
typedef int S;
}
namespace E {
typedef A::S S;
using A::S;
struct S s;
}
namespace F {
typedef A::S S;
}
namespace G {
using namespace A;
using namespace F;
struct S s;
}
namespace H {
using namespace F;
using namespace A;
struct S s;
}
}
|