https://github.com/kodlan updated https://github.com/llvm/llvm-project/pull/220344
>From ffe8e142a5397c6b98a1798bdef71639e0b76c1e Mon Sep 17 00:00:00 2001 From: Stanislav Bardyuk <[email protected]> Date: Tue, 1 Sep 2026 19:10:40 +0000 Subject: [PATCH] [Clang] Honor pragma suppression at the instantiation point for availability warnings in system headers Check the diagnostic state at the outermost point of instantiation before forcing an availability warning past the system header suppression, so a pragma that ignores the warning where the instantiation was requested silences it again (regressed in 23 by 86bd00348e5a). Fixes #219685 --- clang/docs/ReleaseNotes.md | 5 +++ clang/lib/Sema/SemaAvailability.cpp | 17 +++++++ ...stem-header-pragma-instantiation-point.cpp | 45 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 clang/test/SemaCXX/warn-deprecated-system-header-pragma-instantiation-point.cpp diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index a1f24a8caedae5..2d4411ba84b74d 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -303,6 +303,11 @@ features cannot lower the translation-unit ABI level; `-pedantic` or when that group is enabled explicitly, matching how the `_BitInt` type itself is already handled. +- Fixed a Clang 23 regression where `#pragma clang diagnostic ignored + "-Wdeprecated-declarations"` at the point of instantiation no longer + silenced deprecation warnings emitted from a template defined in a system + header. (#GH219685) + - Fixed bug in `-Wdocumentation` so that it correctly handles explicit function template instantiations (#64087). diff --git a/clang/lib/Sema/SemaAvailability.cpp b/clang/lib/Sema/SemaAvailability.cpp index 6ae08b0783f406..48bc67367c52c7 100644 --- a/clang/lib/Sema/SemaAvailability.cpp +++ b/clang/lib/Sema/SemaAvailability.cpp @@ -669,6 +669,23 @@ static void DoEmitAvailabilityWarning(Sema &S, AvailabilityResult K, bool ShouldAllowWarningInSystemHeader = InstantiationLoc != Loc && !S.getSourceManager().isInSystemHeader(InstantiationLoc); + // A warning shown in a system header only because the instantiation was + // requested from user code must still honor the diagnostic state (e.g. a + // pragma) at that point of instantiation (GH219685). + if (ShouldAllowWarningInSystemHeader && + S.getSourceManager().isInSystemHeader(Loc)) { + unsigned UsedDiag = !Message.empty() ? diag_message + : !UnknownObjCClass ? diag + : diag_fwdclass_message; + for (const Sema::CodeSynthesisContext &CSC : S.CodeSynthesisContexts) { + if (!CSC.isInstantiationRecord() || CSC.PointOfInstantiation.isInvalid()) + continue; + if (!S.getSourceManager().isInSystemHeader(CSC.PointOfInstantiation) && + S.getDiagnostics().isIgnored(UsedDiag, CSC.PointOfInstantiation)) + ShouldAllowWarningInSystemHeader = false; + break; + } + } struct AllowWarningInSystemHeaders { AllowWarningInSystemHeaders(DiagnosticsEngine &E, bool AllowWarningInSystemHeaders) diff --git a/clang/test/SemaCXX/warn-deprecated-system-header-pragma-instantiation-point.cpp b/clang/test/SemaCXX/warn-deprecated-system-header-pragma-instantiation-point.cpp new file mode 100644 index 00000000000000..71875eae2ddf5b --- /dev/null +++ b/clang/test/SemaCXX/warn-deprecated-system-header-pragma-instantiation-point.cpp @@ -0,0 +1,45 @@ +// RUN: %clang_cc1 -fsyntax-only -Wdeprecated-declarations -verify %s +// RUN: %clang_cc1 -fsyntax-only -Wdeprecated-declarations -DUNRELATED_PRAGMA -verify=escape %s +// RUN: %clang_cc1 -fsyntax-only -Wdeprecated-declarations -DNO_PRAGMA -verify=escape %s + +// A deprecation warning emitted inside a system header is shown when the +// instantiation is requested from user code, but a pragma suppressing it at +// the point of instantiation must silence it (GH219685). Pragmas for other +// groups, or no pragma at all, must not. + +#ifdef BE_THE_HEADER +#pragma clang system_header + +template <class T> +struct TUnderlying { + using Type = __underlying_type(T); // escape-warning {{'EDoomed' is deprecated}} \ + // escape-warning {{'EGone' is deprecated: use EFine}} +}; + +#else +#define BE_THE_HEADER +#include __FILE__ + +enum class [[deprecated]] EDoomed { A }; // escape-note 2 {{'EDoomed' has been explicitly marked deprecated here}} +enum class [[deprecated("use EFine")]] EGone { A }; // escape-note 2 {{'EGone' has been explicitly marked deprecated here}} + +#if defined(UNRELATED_PRAGMA) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-variable" +#endif +#if !defined(UNRELATED_PRAGMA) && !defined(NO_PRAGMA) +// expected-no-diagnostics +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#endif + +using FUnder = TUnderlying<EDoomed>::Type; // escape-warning {{'EDoomed' is deprecated}} \ + // escape-note {{in instantiation of template class 'TUnderlying<EDoomed>' requested here}} +using FUnder2 = TUnderlying<EGone>::Type; // escape-warning {{'EGone' is deprecated: use EFine}} \ + // escape-note {{in instantiation of template class 'TUnderlying<EGone>' requested here}} + +#if !defined(NO_PRAGMA) +#pragma clang diagnostic pop +#endif + +#endif _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
