[clang] 23 regression: pragma suppression at instantiation point no longer silences -Wdeprecated-declarations emitted from system-header templates
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Trying to bump up from 22 to 23, but this warning bug would be unpleasant to suppress universally.
This is the AI write-up. I verified the repro myself with 22.1.8 (pass) and 23.1.0 (fail).
Code files: [repro.zip](https://github.com/user-attachments/files/31598425/repro.zip)
Clang 23 does not honor #pragma clang diagnostic ignored "-Wdeprecated-declarations" at the point of template instantiation when the diagnostic's location is inside a system header. Clang 22 and earlier suppress these, as do GCC and MSVC for equivalent constructs.
Reproducer:
```c++
// sys/trait.h (included via -isystem)
template
struct TUnderlying
{
using Type = __underlying_type(T);
};
// repro.cpp
#include
enum class [[deprecated("gone")]] EDoomed : int
{
A
};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
using FUnder = TUnderlying::Type;
#pragma clang diagnostic pop
int main() { return 0; }
```
`clang -fsyntax-only -Wdeprecated-declarations -isystem sys dep_repro_sys.cpp`
┌──────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Compiler │ Result │
├──────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ clang 22.1.8 │ no warnings │
├──────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ clang 23.1.0 │ warning: 'EDoomed' is deprecated: gone [-Wdeprecated-declarations] at trait.h, note: in instantiation ... requested here at the pragma-guarded line │
└──────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Notes:
- The diagnostic's location is in the system header and its instantiation stack bottoms out at the pragma-guarded user code. Under the "emit system-header diagnostics when the instantiation stack reaches user code" rule, the user-code location's suppression mapping applied through Clang 22.
- If the template is defined in the same TU (not a system header), the warning escapes the instantiation-point pragma in both 22 and 23 — the longstanding behavior in #88715 / #106905 / #110321 (#76515 for the Clang 18 system-header cases). This report is only about the system-header case regressing between 22 and 23.
- Impact: suppression pragmas around standard type traits used with deprecated types no longer work. E.g. Unreal Engine's PRAGMA_DISABLE_DEPRECATION_WARNINGS around ENUM_RANGE_BY_COUNT(EDeprecatedEnum, ...) instantiates std::underlying_type_t in the MSVC STL and warns under Clang 23 with no use-site suppression available.
- The Clang 23 release notes do not document a change here.
```
Contributor guide
Research direction
Start with the sys/trait.h and repro.cpp examples in the report, then run the provided clang -fsyntax-only command with Clang 22 and 23 to confirm the diagnostic difference. Trace the system-header template instantiation and diagnostic pragma handling, using the linked historical issues for context; done means the pragma suppresses the warning again and the regression is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100