https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/199537

>From 97d94f80ba404cfecc1da62f22ff952338f4a8f2 Mon Sep 17 00:00:00 2001
From: Mital Ashok <[email protected]>
Date: Mon, 25 May 2026 15:58:12 +0100
Subject: [PATCH] [C23] [Diagnostics] No longer warn with -Wc++98-compat when
 using constexpr in C23

Also changes the generic -Wpre-c23-compat warning about using the constexpr 
keyword to a more specific one about using the constexpr specifier on a 
declaration, to match the warning in C++ mode (and warn in Sema instead of 
reusing a Parse warning)
---
 clang/docs/ReleaseNotes.rst                      | 2 ++
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 +++
 clang/lib/Parse/ParseDecl.cpp                    | 2 --
 clang/lib/Sema/DeclSpec.cpp                      | 2 +-
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c1eacfc05dc8..b71bd180413ad 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -558,6 +558,8 @@ Improvements to Clang's diagnostics
 
 - Clang now emits error when attribute is missing closing ``]]`` followed by 
``;;``. (#GH187223)
 
+- No longer warn with about C++98 compatibility when using ``constexpr`` in 
C23.
+
 Improvements to Clang's time-trace
 ----------------------------------
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index dbe6cb2c3a41c..439641b81da2a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3135,6 +3135,9 @@ def note_private_extern : Note<
   "use __attribute__((visibility(\"hidden\"))) attribute instead">;
 
 // C23 constexpr
+def warn_c23_compat_constexpr : Warning<
+  "'constexpr' specifier is incompatible with C standards before C23">,
+  InGroup<CPre23Compat>, DefaultIgnore;
 def err_c23_constexpr_not_variable : Error<
   "'constexpr' can only be used in variable declarations">;
 def err_c23_constexpr_invalid_type : Error<
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 405dddf7991b4..04c3e9dd8b58e 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4275,8 +4275,6 @@ void Parser::ParseDeclarationSpecifiers(
 
     // constexpr, consteval, constinit specifiers
     case tok::kw_constexpr:
-      if (getLangOpts().C23)
-        Diag(Tok, diag::warn_c23_compat_keyword) << Tok.getName();
       isInvalid = DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, Loc,
                                       PrevSpec, DiagID);
       break;
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 660b1805c450e..f9be1402d5d6c 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -1436,7 +1436,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy 
&Policy) {
     S.Diag(TSTLoc, diag::warn_cxx98_compat_unicode_type)
       << (TypeSpecType == TST_char16 ? "char16_t" : "char32_t");
   if (getConstexprSpecifier() == ConstexprSpecKind::Constexpr)
-    S.Diag(ConstexprLoc, diag::warn_cxx98_compat_constexpr);
+    S.Diag(ConstexprLoc, S.getLangOpts().CPlusPlus ? 
diag::warn_cxx98_compat_constexpr : diag::warn_c23_compat_constexpr);
   else if (getConstexprSpecifier() == ConstexprSpecKind::Consteval)
     S.Diag(ConstexprLoc, diag::warn_cxx20_compat_consteval);
   else if (getConstexprSpecifier() == ConstexprSpecKind::Constinit)

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to