Vlad Serebrennikov 604e4adef0
[clang] Non-trivial fixes in C++ DR tests (#179813)
This is a follow-up to #179674, which applies various fixes across C++
DR tests uncovered by `-verify-directives` (#179835
).

Changes here serve double duty. First, they fix actual problems found by
`-verify-directives`, because I've been manually enforcing those rules
manually for quite a while. Second, they show typical problems and
possible solutions when you opt-in a test to use `-verify-directives`.
This PR focuses on interesting cases, as partial diagnostic matches,
which are trivial to fix, are fixed in boring #179674

Changes include:
1. Getting rid of instantiations at the end of TU that emit diagnostics:
either trigger them earlier, or move them to a separate file
2. Reordering of `expected-error` and `expected-note` to match the order
in which corresponding diagnsotics are emitted.
3. Eliminating leftover partial matches of diagnostic text
4. Removing some extension warnings, because C++ DR tests are not
interested in features backported to older language modes.
5. Fix for a hilarious case of CWG413 test, which was checking for a
note from a typo correction that happened in another test.
2026-02-10 21:09:20 +00:00

27 lines
1.5 KiB
C++

// RUN: %clang_cc1 -std=c++98 %s -fexceptions -fcxx-exceptions -pedantic-errors -verify
// RUN: %clang_cc1 -std=c++11 %s -fexceptions -fcxx-exceptions -pedantic-errors -verify
// RUN: %clang_cc1 -std=c++14 %s -fexceptions -fcxx-exceptions -pedantic-errors -verify
// RUN: %clang_cc1 -std=c++17 %s -fexceptions -fcxx-exceptions -pedantic-errors -verify
// RUN: %clang_cc1 -std=c++20 %s -fexceptions -fcxx-exceptions -pedantic-errors -verify
// RUN: %clang_cc1 -std=c++23 %s -fexceptions -fcxx-exceptions -pedantic-errors -verify
// RUN: %clang_cc1 -std=c++2c %s -fexceptions -fcxx-exceptions -pedantic-errors -verify
namespace cwg390 { // cwg390: 3.3
template<typename T>
struct A {
A() { f(); }
// expected-warning@-1 {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'cwg390::A<int>'}}
// expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::A' requested here}}
// expected-note@#cwg390-f {{'f' declared here}}
virtual void f() = 0; // #cwg390-f
virtual ~A() = 0;
};
template<typename T> A<T>::~A() { T::error; }
// expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
// expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::~A' requested here}}
template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
struct B : A<int> { // #cwg390-A-int
void f() {}
} b;
} // namespace cwg390