Skip to content

Commit

Permalink
[clang][NFC] Refactor expected directives in C++ DRs 2000-2799 (#74921)
Browse files Browse the repository at this point in the history
This patch continues the work started with ea5b1ef. See that commit and its
corresponding PR for details.
  • Loading branch information
Endilll committed Dec 9, 2023
1 parent 312cb34 commit 6ed9a81
Show file tree
Hide file tree
Showing 10 changed files with 499 additions and 298 deletions.
219 changes: 139 additions & 80 deletions clang/test/CXX/drs/dr20xx.cpp

Large diffs are not rendered by default.

141 changes: 92 additions & 49 deletions clang/test/CXX/drs/dr21xx.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// 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

#if __cplusplus < 201103L
// expected-error@+1 {{variadic macro}}
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,cxx98 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors

#if __cplusplus == 199711L
#define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
// cxx98-error@-1 {{variadic macros are a C99 feature}}
#endif

namespace dr2100 { // dr2100: 12
Expand All @@ -18,15 +19,14 @@ namespace dr2100 { // dr2100: 12
return X<&n>::n; // ok, value-dependent
}
int g() {
static const int n = 2;
static const int n = 2; // #dr2100-n
return X<&n>::n; // ok, value-dependent
#if __cplusplus < 201702L
// expected-error@-2 {{does not have linkage}} expected-note@-3 {{here}}
#endif
// cxx98-14-error@-1 {{non-type template argument refers to object 'n' that does not have linkage}}
// cxx98-14-note@#dr2100-n {{non-type template argument refers to object here}}
}
};
template<const int *P> struct X<P> {
#if __cplusplus < 201103L
#if __cplusplus == 199711L
static const int n = 0;
#else
static const int n = *P;
Expand All @@ -40,11 +40,13 @@ namespace dr2100 { // dr2100: 12
template<typename T> struct B {
static const int n = 1;
int f() {
return Y<n>::declared_later; // expected-error {{no member named 'declared_later'}}
return Y<n>::declared_later;
// expected-error@-1 {{no member named 'declared_later' in 'dr2100::Y<1>'}}
}
int g() {
static const int n = 2;
return Y<n>::declared_later; // expected-error {{no member named 'declared_later'}}
return Y<n>::declared_later;
// expected-error@-1 {{no member named 'declared_later' in 'dr2100::Y<2>'}}
}
};
template<int N> struct Y<N> {
Expand All @@ -55,10 +57,12 @@ namespace dr2100 { // dr2100: 12
namespace dr2103 { // dr2103: yes
void f() {
int a;
int &r = a; // expected-note {{here}}
int &r = a; // #dr2103-r
struct Inner {
void f() {
int &s = r; // expected-error {{enclosing function}}
int &s = r;
// expected-error@-1 {{reference to local variable 'r' declared in enclosing function 'dr2103::f'}}
// expected-note@#dr2103-r {{'r' declared here}}
(void)s;
}
};
Expand All @@ -84,28 +88,46 @@ namespace dr2126 { // dr2126: 12
A &b = (A &)(const A &)A{1}; // const temporary
A &&c = (A &&)(const A &)A{1}; // const temporary

A &&d = {1}; // non-const temporary expected-note {{here}}
const A &e = (A &)(A &&) A{1}; // non-const temporary expected-note {{here}}
A &&f = (A &&)(A &&) A{1}; // non-const temporary expected-note {{here}}
A &&d = {1}; // non-const temporary #dr21260-d
const A &e = (A &)(A &&) A{1}; // non-const temporary #dr21260-e
A &&f = (A &&)(A &&) A{1}; // non-const temporary #dr21260-f

constexpr const A &g = {1}; // const temporary
constexpr A &&h = {1}; // non-const temporary expected-note {{here}}
constexpr A &&h = {1}; // non-const temporary #dr21260-h

struct B { const A &a; };
B i = {{1}}; // extending decl not usable in constant expr expected-note {{here}}
const B j = {{1}}; // extending decl not usable in constant expr expected-note {{here}}
B i = {{1}}; // extending decl not usable in constant expr #dr21260-i
const B j = {{1}}; // extending decl not usable in constant expr #dr21260-j
constexpr B k = {{1}}; // extending decl usable in constant expr

static_assert(a.n == 1, "");
static_assert(b.n == 1, "");
static_assert(c.n == 1, "");
static_assert(d.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
static_assert(e.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
static_assert(f.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
static_assert(d.n == 1, "");
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
// since-cxx11-note@#dr21260-d {{temporary created here}}
static_assert(e.n == 1, "");
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
// since-cxx11-note@#dr21260-e {{temporary created here}}
static_assert(f.n == 1, "");
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
// since-cxx11-note@#dr21260-f {{temporary created here}}
static_assert(g.n == 1, "");
static_assert(h.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
static_assert(i.a.n == 1, ""); // expected-error {{constant}} expected-note {{read of non-constexpr variable}}
static_assert(j.a.n == 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
static_assert(h.n == 1, "");
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
// since-cxx11-note@#dr21260-h {{temporary created here}}
static_assert(i.a.n == 1, "");
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of non-constexpr variable 'i' is not allowed in a constant expression}}
// since-cxx11-note@#dr21260-i {{declared here}}
static_assert(j.a.n == 1, "");
// since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
// since-cxx11-note@-2 {{read of temporary is not allowed in a constant expression outside the expression that created the temporary}}
// since-cxx11-note@#dr21260-j {{temporary created here}}
static_assert(k.a.n == 1, "");
#endif
}
Expand All @@ -128,19 +150,27 @@ struct B{};

void foo() {
struct A *b = (1 == 1) ? new struct A : new struct A;
struct S *a = (1 == 1) ? new struct S : new struct S; // expected-error 2{{allocation of incomplete type}} // expected-note 2{{forward}}
struct S *a = (1 == 1) ? new struct S : new struct S;
// expected-error@-1 {{allocation of incomplete type 'struct S'}}
// expected-note@-2 {{forward declaration of 'S'}}
// expected-error@-3 {{allocation of incomplete type 'struct S'}}
// expected-note@-4 {{forward declaration of 'S'}}

#if __cplusplus >= 201103L
A *aa = new struct A{};
B<int> *bb = new struct B<int>{};
(void)new struct C{}; // expected-error {{allocation of incomplete type }} // expected-note {{forward}}
(void)new struct C{};
// since-cxx11-error@-1 {{allocation of incomplete type 'struct C'}}
// since-cxx11-note@-2 {{forward declaration of 'C'}}

struct A *c = (1 == 1) ? new struct A {} : new struct A {};

alignof(struct D{}); // expected-error {{cannot be defined in a type specifier}}
alignof(struct D{});
// since-cxx11-error@-1 {{'D' cannot be defined in a type specifier}}
#endif

sizeof(struct E{}); // expected-error {{cannot be defined in a type specifier}}
sizeof(struct E{});
// expected-error@-1 {{'E' cannot be defined in a type specifier}}

}
}
Expand All @@ -149,7 +179,8 @@ namespace dr2157 { // dr2157: 11
#if __cplusplus >= 201103L
enum E : int;
struct X {
enum dr2157::E : int(); // expected-error {{only allows ':' in member enumeration declaration to introduce a fixed underlying type}}
enum dr2157::E : int();
// since-cxx11-error@-1 {{ISO C++ only allows ':' in member enumeration declaration to introduce a fixed underlying type, not an anonymous bit-field}}
};
#endif
}
Expand All @@ -159,11 +190,13 @@ namespace dr2157 { // dr2157: 11
namespace dr2170 { // dr2170: 9
#if __cplusplus >= 201103L
void f() {
constexpr int arr[3] = {1, 2, 3}; // expected-note {{here}}
constexpr int arr[3] = {1, 2, 3}; // #dr2170-arr
struct S {
int get(int n) { return arr[n]; }
const int &get_ref(int n) { return arr[n]; } // expected-error {{enclosing function}}
// FIXME: expected-warning@-1 {{reference to stack}}
const int &get_ref(int n) { return arr[n]; }
// since-cxx11-warning@-1 {{reference to stack memory associated with local variable 'arr' returned}} FIXME
// since-cxx11-error@-2 {{reference to local variable 'arr' declared in enclosing function 'dr2170::f'}}
// since-cxx11-note@#dr2170-arr {{'arr' declared here}}
};
}
#endif
Expand Down Expand Up @@ -198,22 +231,32 @@ static_assert(!__is_trivially_assignable(NonConstCopy &&, NonConstCopy &&), "");

namespace dr2180 { // dr2180: yes
class A {
A &operator=(const A &); // expected-note 0-2{{here}}
A &operator=(A &&); // expected-note 0-2{{here}} expected-error 0-1{{extension}}
A &operator=(const A &); // #dr2180-A-copy
A &operator=(A &&); // #dr2180-A-move
// cxx98-error@-1 {{rvalue references are a C++11 extension}}
};

struct B : virtual A {
struct B : virtual A { // #dr2180-B
B &operator=(const B &);
B &operator=(B &&); // expected-error 0-1{{extension}}
B &operator=(B &&);
// cxx98-error@-1 {{rvalue references are a C++11 extension}}
virtual void foo() = 0;
};
#if __cplusplus < 201103L
B &B::operator=(const B&) = default; // expected-error {{private member}} expected-error {{extension}} expected-note {{here}}
B &B::operator=(B&&) = default; // expected-error {{private member}} expected-error 2{{extension}} expected-note {{here}}
#else
B &B::operator=(const B&) = default; // expected-error {{would delete}} expected-note@-9{{inaccessible copy assignment}}
B &B::operator=(B&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
#endif
B &B::operator=(const B&) = default; // #dr2180-B-copy
// cxx98-error@-1 {{defaulted function definitions are a C++11 extension}}
// cxx98-error@-2 {{'operator=' is a private member of 'dr2180::A'}}
// cxx98-note@-3 {{in defaulted copy assignment operator for 'dr2180::B' first required here}}
// cxx98-note@#dr2180-A-copy {{implicitly declared private here}}
// since-cxx11-error@#dr2180-B-copy {{defaulting this copy assignment operator would delete it after its first declaration}}
// since-cxx11-note@#dr2180-B {{copy assignment operator of 'B' is implicitly deleted because base class 'A' has an inaccessible copy assignment operator}}
B &B::operator=(B&&) = default; // #dr2180-B-move
// cxx98-error@-1 {{rvalue references are a C++11 extension}}
// cxx98-error@-2 {{defaulted function definitions are a C++11 extension}}
// cxx98-error@-3 {{'operator=' is a private member of 'dr2180::A'}}
// cxx98-note@-4 {{in defaulted move assignment operator for 'dr2180::B' first required here}}
// cxx98-note@#dr2180-A-move {{implicitly declared private here}}
// since-cxx11-error@#dr2180-B-move {{defaulting this move assignment operator would delete it after its first declaration}}
// since-cxx11-note@#dr2180-B {{move assignment operator of 'B' is implicitly deleted because base class 'A' has an inaccessible move assignment operator}}
}

namespace dr2199 { // dr2199: 3.8
Expand Down
37 changes: 23 additions & 14 deletions clang/test/CXX/drs/dr22xx.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++1z -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors


#if __cplusplus >= 201103L
namespace dr2211 { // dr2211: 8
void f() {
int a;
auto f = [a](int a) { (void)a; }; // expected-error {{a lambda parameter cannot shadow an explicitly captured entity}}
// expected-note@-1{{variable 'a' is explicitly captured here}}
auto f = [a](int a) { (void)a; };
// since-cxx11-error@-1 {{a lambda parameter cannot shadow an explicitly captured entity}}
// since-cxx11-note@-2 {{variable 'a' is explicitly captured here}}
auto g = [=](int a) { (void)a; };
}
}
Expand All @@ -24,9 +29,12 @@ struct A<int, U>;

namespace dr2229 { // dr2229: 7
struct AnonBitfieldQualifiers {
const unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
const volatile unsigned : 1; // expected-error {{anonymous bit-field cannot have qualifiers}}
const unsigned : 1;
// expected-error@-1 {{anonymous bit-field cannot have qualifiers}}
volatile unsigned : 1;
// expected-error@-1 {{anonymous bit-field cannot have qualifiers}}
const volatile unsigned : 1;
// expected-error@-1 {{anonymous bit-field cannot have qualifiers}}

unsigned : 1;
const unsigned i1 : 1;
Expand Down Expand Up @@ -98,7 +106,8 @@ namespace MultilevelSpecialization {
template <T... V> void f(int i = 0, int (&... arr)[V]);
};
template<> template<int a, int b>
void B<int, int>::f(int i, int (&arr1)[a], int (&arr2)[b]) {} // expected-error {{does not match}}
void B<int, int>::f(int i, int (&arr1)[a], int (&arr2)[b]) {}
// since-cxx11-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'dr2233::MultilevelSpecialization::B<int, int>'}}
template<> template<>
void B<int, int>::f<1, 1>(int i, int (&arr1a)[1], int (&arr2a)[1]) {}
}
Expand Down Expand Up @@ -134,10 +143,10 @@ struct C { explicit operator D(); } c;
B b1(a);
const B &b2{a}; // FIXME ill-formed
const B &b3(a);
// expected-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
// expected-note@#dr2267-struct-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const B &' for 1st argument}}
// expected-note@#dr2267-struct-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st argument}}
// expected-note@#dr2267-struct-B {{explicit constructor is not a candidate}}
// since-cxx11-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
// since-cxx11-note@#dr2267-struct-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'struct A' to 'const B &' for 1st argument}}
// since-cxx11-note@#dr2267-struct-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st argument}}
// since-cxx11-note@#dr2267-struct-B {{explicit constructor is not a candidate}}

D d1(c);
const D &d2{c}; // FIXME ill-formed
Expand Down
10 changes: 0 additions & 10 deletions clang/test/CXX/drs/dr2354.cpp

This file was deleted.

0 comments on commit 6ed9a81

Please sign in to comment.