https://github.com/shraavb created 
https://github.com/llvm/llvm-project/pull/246768

Adds a regression test for #39721.

A statement attribute such as `[[gsl::suppress]]` on a `return`, or on an `if` 
that never returns, used to produce a bogus `-Wunreachable-code` warning on the 
attribute itself. This was fixed in Clang 14 (bisected to 
c74ab84ea23f497ac83501473220cd9cfefe81e8 in the issue), but no test covers it.

The test checks that:
- no warning is emitted on the attribute in either case
- the warning for the genuinely unreachable `return 2;` is still emitted

Test run (`build/bin/llvm-lit clang/test/SemaCXX/unreachable-code.cpp`):

```
PASS: Clang :: SemaCXX/unreachable-code.cpp (1 of 1)
  Passed: 1 (100.00%)
```

To check the test can fail, I ran the file's RUN line with `-verify` on two 
modified copies (`a.cpp`, `b.cpp`; the checked-in test is unchanged).

`a.cpp`: `expected-warning` removed from `return 2;`:

```
error: 'expected-warning' diagnostics seen but not expected:
  File a.cpp Line 139: 'return' will never be executed
1 error generated.
```

`b.cpp`: `expected-warning` added on the attribute line:

```
error: 'expected-warning' diagnostics expected but not seen:
  File b.cpp Line 136: will never be executed
1 error generated.
```

AI use: Claude Code was used to explain the issue, and to help verify the test, 
fix whitespace and run git commands. I wrote the test.

Closes #39721


The server is unavailable at this time. Please wait a few minutes before you 
try again.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to