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

36 lines
1.6 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 cwg98 { // cwg98: 2.7
void test(int n) {
switch (n) {
try { // #cwg98-try
case 0:
// expected-error@-1 {{cannot jump from switch statement to this case label}}
// expected-note@#cwg98-try {{jump bypasses initialization of try block}}
x:
throw n;
} catch (...) { // #cwg98-catch
case 1:
// expected-error@-1 {{cannot jump from switch statement to this case label}}
// expected-note@#cwg98-catch {{jump bypasses initialization of catch block}}
y:
throw n;
}
case 2:
goto x;
// expected-error@-1 {{cannot jump from this goto statement to its label}}
// expected-note@#cwg98-try {{jump bypasses initialization of try block}}
case 3:
goto y;
// expected-error@-1 {{cannot jump from this goto statement to its label}}
// expected-note@#cwg98-catch {{jump bypasses initialization of catch block}}
}
}
} // namespace cwg98