Skip to content

Commit

Permalink
[clang][NFC] Refactor expected directives in C++ DRs 700-1999 (llvm#…
Browse files Browse the repository at this point in the history
…74767)

This patch continues the work started with ea5b1ef. See that commit and its
corresponding PR for details.
  • Loading branch information
Endilll authored Dec 8, 2023
1 parent 58bdef2 commit 76ee344
Show file tree
Hide file tree
Showing 14 changed files with 1,530 additions and 859 deletions.
45 changes: 28 additions & 17 deletions clang/test/CXX/drs/dr10xx.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors

namespace std {
__extension__ typedef __SIZE_TYPE__ size_t;
Expand All @@ -18,30 +18,40 @@ namespace dr1004 { // dr1004: 5
template<typename> struct A {};
template<typename> struct B1 {};
template<template<typename> class> struct B2 {};
template<typename X> void f(); // expected-note {{[with X = dr1004::A<int>]}}
template<template<typename> class X> void f(); // expected-note {{[with X = dr1004::A]}}
template<template<typename> class X> void g(); // expected-note {{[with X = dr1004::A]}}
template<typename X> void g(); // expected-note {{[with X = dr1004::A<int>]}}
template<typename X> void f(); // #dr1004-f-1
template<template<typename> class X> void f(); // #dr1004-f-2
template<template<typename> class X> void g(); // #dr1004-g-1
template<typename X> void g(); // #dr1004-g-2
struct C : A<int> {
B1<A> b1a;
B2<A> b2a;
void h() {
f<A>(); // expected-error {{ambiguous}}
g<A>(); // expected-error {{ambiguous}}
f<A>();
// expected-error@-1 {{call to 'f' is ambiguous}}
// expected-note@#dr1004-f-1 {{candidate function [with X = dr1004::A<int>]}}
// expected-note@#dr1004-f-2 {{candidate function [with X = dr1004::A]}}
g<A>();
// expected-error@-1 {{call to 'g' is ambiguous}}
// expected-note@#dr1004-g-1 {{candidate function [with X = dr1004::A]}}
// expected-note@#dr1004-g-2 {{candidate function [with X = dr1004::A<int>]}}
}
};

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

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

Expand Down
32 changes: 17 additions & 15 deletions clang/test/CXX/drs/dr11xx.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++2a %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors

namespace dr1111 { // dr1111: 3.2
namespace example1 {
template <typename> struct set;
template <typename> struct set; // #dr1111-struct-set

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

struct Y {};
void bar() {
Y y;
y.set<double>(3.2); // expected-error {{no member named 'set' in 'dr1111::example1::Y'}}
y.set<double>(3.2);
// expected-error@-1 {{no member named 'set' in 'dr1111::example1::Y'}}
}
} // namespace example1

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

namespace dr1113 { // dr1113: partial
namespace named {
extern int a; // expected-note {{previous}}
static int a; // expected-error {{static declaration of 'a' follows non-static}}
extern int a; // #dr1113-a
static int a;
// expected-error@-1 {{static declaration of 'a' follows non-static}}
// expected-note@#dr1113-a {{previous declaration is here}}
}
namespace {
extern int a;
Expand Down
79 changes: 47 additions & 32 deletions clang/test/CXX/drs/dr12xx.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-14,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx98-14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++14 %s -verify=expected,cxx98-14,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx17,since-cxx14,since-cxx11,since-cxx23 -fexceptions -fcxx-exceptions -pedantic-errors

// dr1200: na

Expand Down Expand Up @@ -40,28 +40,33 @@ struct S {
S* operator()();
int N;
int M;
#if __cplusplus > 202002L
#if __cplusplus >= 202302L
template <typename T>
static constexpr auto V = 0;
void f(char);
void f(int);
void mem(S s) {
auto(s)()->M; //expected-warning {{expression result unused}}
auto(s)()->V<int>; //expected-warning {{expression result unused}}
auto(s)()->M;
// since-cxx23-warning@-1 {{expression result unused}}
auto(s)()->V<int>;
// since-cxx23-warning@-1 {{expression result unused}}
auto(s)()->f(0);
}
#endif
};
void f(S s) {
{
#if __cplusplus > 202002L
auto(s)()->N; //expected-warning {{expression result unused}}
#if __cplusplus >= 202302L
auto(s)()->N;
//since-cxx23-warning@-1 {{expression result unused}}
#endif
auto(s)()->M;
}
{
S(s)()->N; //expected-warning {{expression result unused}}
S(s)()->M; //expected-warning {{expression result unused}}
S(s)()->N;
// since-cxx11-warning@-1 {{expression result unused}}
S(s)()->M;
// since-cxx11-warning@-1 {{expression result unused}}
}
}

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

}
#endif

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

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

namespace dr1265 { // dr1265: 5
#if __cplusplus >= 201103L
auto a = 0, b() -> int; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
auto b() -> int, d = 0; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
auto e() -> int, f() -> int; // expected-error {{declaration with trailing return type must be the only declaration in its group}}
auto a = 0, b() -> int;
// since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
auto b() -> int, d = 0;
// since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
auto e() -> int, f() -> int;
// since-cxx11-error@-1 {{declaration with trailing return type must be the only declaration in its group}}
#endif

#if __cplusplus >= 201402L
auto g(), h = 0; // expected-error {{function with deduced return type must be the only declaration in its group}}
auto i = 0, j(); // expected-error {{function with deduced return type must be the only declaration in its group}}
auto k(), l(); // expected-error {{function with deduced return type must be the only declaration in its group}}
auto g(), h = 0;
// since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
auto i = 0, j();
// since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
auto k(), l();
// since-cxx14-error@-1 {{function with deduced return type must be the only declaration in its group}}
#endif
}

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

X x = {1};

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

template<unsigned &r> struct Y {};
Y<x.bitfield> y;
#if __cplusplus <= 201402L
// expected-error@-2 {{does not refer to any declaration}} expected-note@-3 {{here}}
#else
// expected-error@-4 {{refers to subobject}}
#endif
template<unsigned &r> struct Y {}; // #dr1295-Y
Y<x.bitfield> y; // #dr1295-y
// cxx98-14-error@-1 {{non-type template argument does not refer to any declaration}}
// cxx98-14-note@#dr1295-Y {{template parameter is declared here}}
// since-cxx17-error@#dr1295-y {{non-type template argument refers to subobject 'x.bitfield'}}

#if __cplusplus >= 201103L
const unsigned other = 0;
Expand Down
Loading

0 comments on commit 76ee344

Please sign in to comment.