Skip to content

Commit 76ee344

Browse files
authored
[clang][NFC] Refactor expected directives in C++ DRs 700-1999 (#74767)
This patch continues the work started with ea5b1ef. See that commit and its corresponding PR for details.
1 parent 58bdef2 commit 76ee344

14 files changed

+1530
-859
lines changed

clang/test/CXX/drs/dr10xx.cpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2-
// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3-
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4-
// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5-
// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6-
// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
1+
// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
2+
// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
3+
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
4+
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
5+
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
6+
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
77

88
namespace std {
99
__extension__ typedef __SIZE_TYPE__ size_t;
@@ -18,30 +18,40 @@ namespace dr1004 { // dr1004: 5
1818
template<typename> struct A {};
1919
template<typename> struct B1 {};
2020
template<template<typename> class> struct B2 {};
21-
template<typename X> void f(); // expected-note {{[with X = dr1004::A<int>]}}
22-
template<template<typename> class X> void f(); // expected-note {{[with X = dr1004::A]}}
23-
template<template<typename> class X> void g(); // expected-note {{[with X = dr1004::A]}}
24-
template<typename X> void g(); // expected-note {{[with X = dr1004::A<int>]}}
21+
template<typename X> void f(); // #dr1004-f-1
22+
template<template<typename> class X> void f(); // #dr1004-f-2
23+
template<template<typename> class X> void g(); // #dr1004-g-1
24+
template<typename X> void g(); // #dr1004-g-2
2525
struct C : A<int> {
2626
B1<A> b1a;
2727
B2<A> b2a;
2828
void h() {
29-
f<A>(); // expected-error {{ambiguous}}
30-
g<A>(); // expected-error {{ambiguous}}
29+
f<A>();
30+
// expected-error@-1 {{call to 'f' is ambiguous}}
31+
// expected-note@#dr1004-f-1 {{candidate function [with X = dr1004::A<int>]}}
32+
// expected-note@#dr1004-f-2 {{candidate function [with X = dr1004::A]}}
33+
g<A>();
34+
// expected-error@-1 {{call to 'g' is ambiguous}}
35+
// expected-note@#dr1004-g-1 {{candidate function [with X = dr1004::A]}}
36+
// expected-note@#dr1004-g-2 {{candidate function [with X = dr1004::A<int>]}}
3137
}
3238
};
3339

3440
// This example (from the standard) is actually ill-formed, because
3541
// name lookup of "T::template A" names the constructor.
36-
template<class T, template<class> class U = T::template A> struct Third { }; // expected-error {{is a constructor name}}
37-
Third<A<int> > t; // expected-note {{in instantiation of default argument}}
42+
template<class T, template<class> class U = T::template A> struct Third { };
43+
// expected-error@-1 {{is a constructor name}}
44+
// expected-note@#dr1004-t {{in instantiation of default argument}}
45+
Third<A<int> > t; // #dr1004-t
3846
}
3947

4048
namespace dr1042 { // dr1042: 3.5
4149
#if __cplusplus >= 201402L
4250
// C++14 added an attribute that we can test the semantics of.
43-
using foo [[deprecated]] = int; // expected-note {{'foo' has been explicitly marked deprecated here}}
44-
foo f = 12; // expected-warning {{'foo' is deprecated}}
51+
using foo [[deprecated]] = int; // #dr1042-using
52+
foo f = 12;
53+
// since-cxx14-warning@-1 {{'foo' is deprecated}}
54+
// since-cxx14-note@#dr1042-using {{'foo' has been explicitly marked deprecated here}}
4555
#elif __cplusplus >= 201103L
4656
// C++11 did not have any attributes that could be applied to an alias
4757
// declaration, so the best we can test is that we accept an empty attribute
@@ -76,7 +86,8 @@ namespace dr1054 { // dr1054: no
7686
// which copy-initializes a temporary from 'a'. Therefore this is
7787
// ill-formed because A does not have a volatile copy constructor.
7888
// (We might want to track this aspect under dr1383 instead?)
79-
a; // expected-warning {{assign into a variable to force a volatile load}}
89+
a;
90+
// expected-warning@-1 {{expression result unused; assign into a variable to force a volatile load}}
8091
}
8192
}
8293

clang/test/CXX/drs/dr11xx.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2-
// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3-
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4-
// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5-
// RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
1+
// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2+
// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
3+
// RUN: %clang_cc1 -std=c++14 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
4+
// RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
5+
// RUN: %clang_cc1 -std=c++2a %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
66

77
namespace dr1111 { // dr1111: 3.2
88
namespace example1 {
9-
template <typename> struct set;
9+
template <typename> struct set; // #dr1111-struct-set
1010

1111
struct X {
12-
template <typename T> void set(const T &value);
12+
template <typename T> void set(const T &value); // #dr1111-func-set
1313
};
1414
void foo() {
1515
X x;
16-
#pragma clang diagnostic push
17-
#if __cplusplus < 201103L
18-
#pragma clang diagnostic ignored "-Wambiguous-member-template"
19-
#endif
16+
// FIXME: should we backport C++11 behavior?
2017
x.set<double>(3.2);
21-
#pragma clang diagnostic pop
18+
// cxx98-error@-1 {{lookup of 'set' in member access expression is ambiguous; using member of 'X'}}
19+
// cxx98-note@#dr1111-func-set {{lookup in the object type 'X' refers here}}
20+
// cxx98-note@#dr1111-struct-set {{lookup from the current scope refers here}}
2221
}
2322

2423
struct Y {};
2524
void bar() {
2625
Y y;
27-
y.set<double>(3.2); // expected-error {{no member named 'set' in 'dr1111::example1::Y'}}
26+
y.set<double>(3.2);
27+
// expected-error@-1 {{no member named 'set' in 'dr1111::example1::Y'}}
2828
}
2929
} // namespace example1
3030

@@ -46,8 +46,10 @@ void baz() {
4646

4747
namespace dr1113 { // dr1113: partial
4848
namespace named {
49-
extern int a; // expected-note {{previous}}
50-
static int a; // expected-error {{static declaration of 'a' follows non-static}}
49+
extern int a; // #dr1113-a
50+
static int a;
51+
// expected-error@-1 {{static declaration of 'a' follows non-static}}
52+
// expected-note@#dr1113-a {{previous declaration is here}}
5153
}
5254
namespace {
5355
extern int a;

clang/test/CXX/drs/dr12xx.cpp

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2-
// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3-
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4-
// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5-
// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6-
// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
1+
// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2+
// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3+
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx98-14,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4+
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5+
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6+
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors
77

88
// dr1200: na
99

@@ -40,28 +40,33 @@ struct S {
4040
S* operator()();
4141
int N;
4242
int M;
43-
#if __cplusplus > 202002L
43+
#if __cplusplus >= 202302L
4444
template <typename T>
4545
static constexpr auto V = 0;
4646
void f(char);
4747
void f(int);
4848
void mem(S s) {
49-
auto(s)()->M; //expected-warning {{expression result unused}}
50-
auto(s)()->V<int>; //expected-warning {{expression result unused}}
49+
auto(s)()->M;
50+
// since-cxx23-warning@-1 {{expression result unused}}
51+
auto(s)()->V<int>;
52+
// since-cxx23-warning@-1 {{expression result unused}}
5153
auto(s)()->f(0);
5254
}
5355
#endif
5456
};
5557
void f(S s) {
5658
{
57-
#if __cplusplus > 202002L
58-
auto(s)()->N; //expected-warning {{expression result unused}}
59+
#if __cplusplus >= 202302L
60+
auto(s)()->N;
61+
//since-cxx23-warning@-1 {{expression result unused}}
5962
#endif
6063
auto(s)()->M;
6164
}
6265
{
63-
S(s)()->N; //expected-warning {{expression result unused}}
64-
S(s)()->M; //expected-warning {{expression result unused}}
66+
S(s)()->N;
67+
// since-cxx11-warning@-1 {{expression result unused}}
68+
S(s)()->M;
69+
// since-cxx11-warning@-1 {{expression result unused}}
6570
}
6671
}
6772

@@ -74,23 +79,27 @@ void g() {
7479
A a(B ()->C);
7580
A b(auto ()->C);
7681
static_assert(sizeof(B ()->C[1] == sizeof(int)), "");
77-
sizeof(auto () -> C[1]); // expected-error{{function cannot return array type 'C[1]'}}
82+
sizeof(auto () -> C[1]);
83+
// since-cxx11-error@-1 {{function cannot return array type 'C[1]' (aka 'dr1223::BB[1]')}}
7884
}
7985

8086
}
8187
#endif
8288

8389
#if __cplusplus >= 201103L
8490
namespace dr1227 { // dr1227: 3.0
85-
template <class T> struct A { using X = typename T::X; }; // expected-error {{type 'int' cannot be used prior to '::' because it has no members}}
91+
template <class T> struct A { using X = typename T::X; };
92+
// since-cxx11-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
93+
// since-cxx11-note@#dr1227-g {{in instantiation of template class 'dr1227::A<int>' requested here}}
94+
// since-cxx11-note@#dr1227-g-int {{while substituting explicitly-specified template arguments into function template 'g'}}
8695
template <class T> typename T::X f(typename A<T>::X);
8796
template <class T> void f(...) { }
88-
template <class T> auto g(typename A<T>::X) -> typename T::X; // expected-note {{in instantiation of template class 'dr1227::A<int>' requested here}}
97+
template <class T> auto g(typename A<T>::X) -> typename T::X; // #dr1227-g
8998
template <class T> void g(...) { }
9099

91100
void h() {
92101
f<int>(0); // OK, substituting return type causes deduction to fail
93-
g<int>(0); // expected-note {{while substituting explicitly-specified template arguments into function template 'g'}}
102+
g<int>(0); // #dr1227-g-int
94103
}
95104
}
96105
#endif
@@ -109,15 +118,21 @@ struct Derived : Base {
109118

110119
namespace dr1265 { // dr1265: 5
111120
#if __cplusplus >= 201103L
112-
auto a = 0, b() -> int; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
113-
auto b() -> int, d = 0; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
114-
auto e() -> int, f() -> int; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
121+
auto a = 0, b() -> int;
122+
// since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
123+
auto b() -> int, d = 0;
124+
// since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
125+
auto e() -> int, f() -> int;
126+
// since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
115127
#endif
116128

117129
#if __cplusplus >= 201402L
118-
auto g(), h = 0; // expected-error {{function with deduced return type must be the only declaration in its group}}
119-
auto i = 0, j(); // expected-error {{function with deduced return type must be the only declaration in its group}}
120-
auto k(), l(); // expected-error {{function with deduced return type must be the only declaration in its group}}
130+
auto g(), h = 0;
131+
// since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
132+
auto i = 0, j();
133+
// since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
134+
auto k(), l();
135+
// since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
121136
#endif
122137
}
123138

@@ -130,16 +145,16 @@ namespace dr1295 { // dr1295: 4
130145

131146
X x = {1};
132147

133-
unsigned const &r1 = static_cast<X &&>(x).bitfield; // expected-error 0-1{{C++11}}
134-
unsigned const &r2 = static_cast<unsigned &&>(x.bitfield); // expected-error 0-1{{C++11}}
148+
unsigned const &r1 = static_cast<X &&>(x).bitfield;
149+
// cxx98-error@-1 {{rvalue references are a C++11 extension}}
150+
unsigned const &r2 = static_cast<unsigned &&>(x.bitfield);
151+
// cxx98-error@-1 {{rvalue references are a C++11 extension}}
135152

136-
template<unsigned &r> struct Y {};
137-
Y<x.bitfield> y;
138-
#if __cplusplus <= 201402L
139-
// expected-error@-2 {{does not refer to any declaration}} expected-note@-3 {{here}}
140-
#else
141-
// expected-error@-4 {{refers to subobject}}
142-
#endif
153+
template<unsigned &r> struct Y {}; // #dr1295-Y
154+
Y<x.bitfield> y; // #dr1295-y
155+
// cxx98-14-error@-1 {{non-type template argument does not refer to any declaration}}
156+
// cxx98-14-note@#dr1295-Y {{template parameter is declared here}}
157+
// since-cxx17-error@#dr1295-y {{non-type template argument refers to subobject 'x.bitfield'}}
143158

144159
#if __cplusplus >= 201103L
145160
const unsigned other = 0;

0 commit comments

Comments
 (0)