[clang] [C23] Implement N3018: The constexpr specifier for object definitions (PR #73099)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 28 09:00:02 PST 2023


================
@@ -5152,13 +5152,17 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
     // and definitions of functions and variables.
     // C++2a [dcl.constexpr]p1: The consteval specifier shall be applied only to
     // the declaration of a function or function template
-    if (Tag)
+    if (Tag) {
       Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_tag)
           << GetDiagnosticTypeSpecifierID(DS)
           << static_cast<int>(DS.getConstexprSpecifier());
-    else
-      Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_wrong_decl_kind)
-          << static_cast<int>(DS.getConstexprSpecifier());
+    } else {
+      if (getLangOpts().C23)
+        Diag(DS.getConstexprSpecLoc(), diag::err_c23_constexpr_not_variable);
+      else
+        Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_wrong_decl_kind)
+            << static_cast<int>(DS.getConstexprSpecifier());
+    }
----------------
AaronBallman wrote:

```suggestion
    else if (getLangOpts().C23)
        Diag(DS.getConstexprSpecLoc(), diag::err_c23_constexpr_not_variable);
    else
      Diag(DS.getConstexprSpecLoc(), diag::err_constexpr_wrong_decl_kind)
          << static_cast<int>(DS.getConstexprSpecifier());
```
(and can remove the inserted brace above, which GitHub helpfully won't let me add to the suggested edits..)

https://github.com/llvm/llvm-project/pull/73099


More information about the cfe-commits mailing list