https://github.com/alejandro-colomar updated 
https://github.com/llvm/llvm-project/pull/244642

>From 07a3015ffb153cd1f66293582d7932606bb174ae Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <[email protected]>
Date: Fri, 20 Nov 2026 15:23:35 +0100
Subject: [PATCH] [clang] Generalize static within array brackets

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n4018.htm>
Cc: Martin Uecker <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
---
 clang/include/clang/Basic/DiagnosticGroups.td     | 1 +
 clang/include/clang/Basic/DiagnosticParseKinds.td | 7 +++----
 clang/lib/Parse/ParseDecl.cpp                     | 6 ++----
 clang/test/Parser/declarators.c                   | 4 +++-
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 9f43b8570ea035..b8731b7e818a61 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -31,6 +31,7 @@ def GNUAutoType : DiagGroup<"gnu-auto-type">;
 def ArrayBounds : DiagGroup<"array-bounds">;
 def ArrayBoundsPointerArithmetic : 
DiagGroup<"array-bounds-pointer-arithmetic">;
 def ArrayParameter : DiagGroup<"array-parameter">;
+def UnspecifiedSizeWithStatic : DiagGroup<"unspecified-size-with-static">;
 def AutoDisableVptrSanitizer : DiagGroup<"auto-disable-vptr-sanitizer">;
 def Availability : DiagGroup<"availability">;
 def Section : DiagGroup<"section">;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 2be6ff8344cd6d..d759556c6a45b7 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -465,10 +465,9 @@ def err_unexpected_scope_on_base_decltype : Error<
 def err_expected_class_name : Error<"expected class name">;
 def err_expected_class_name_not_template :
   Error<"'typename' is redundant; base classes are implicitly types">;
-def err_unspecified_vla_size_with_static : Error<
-  "'static' may not be used with an unspecified variable length array size">;
-def err_unspecified_size_with_static : Error<
-  "'static' may not be used without an array size">;
+def ext_unspecified_size_with_static : Extension<
+  "ISO C requires a length expression with 'static'">,
+  InGroup<UnspecifiedSizeWithStatic>;
 def err_expected_parentheses_around_typename : Error<
   "expected parentheses around type name in %0 expression">;
 def err_expansion_stmt_requires_range : Error<
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index f20383f8374cc6..380f6d15f99f77 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -8049,8 +8049,7 @@ void Parser::ParseBracketDeclarator(Declarator &D) {
     ConsumeToken();  // Eat the '*'.
 
     if (StaticLoc.isValid()) {
-      Diag(StaticLoc, diag::err_unspecified_vla_size_with_static);
-      StaticLoc = SourceLocation();  // Drop the static.
+      Diag(StaticLoc, diag::ext_unspecified_size_with_static);
     }
     isStar = true;
   } else if (Tok.isNot(tok::r_square)) {
@@ -8070,8 +8069,7 @@ void Parser::ParseBracketDeclarator(Declarator &D) {
     }
   } else {
     if (StaticLoc.isValid()) {
-      Diag(StaticLoc, diag::err_unspecified_size_with_static);
-      StaticLoc = SourceLocation();  // Drop the static.
+      Diag(StaticLoc, diag::ext_unspecified_size_with_static);
     }
   }
 
diff --git a/clang/test/Parser/declarators.c b/clang/test/Parser/declarators.c
index 0a3580596646d5..571a7f21f3fd1c 100644
--- a/clang/test/Parser/declarators.c
+++ b/clang/test/Parser/declarators.c
@@ -7,7 +7,9 @@ void f1(int [*]);
 void f2(int [const *]);
 void f3(int [volatile const*]);
 int f4(*XX)(void); /* expected-error {{cannot return}} expected-error {{type 
specifier missing, defaults to 'int'; ISO C99 and later do not support implicit 
int}} */
-int f5(int [static]); /* expected-error {{'static' may not be used without an 
array size}} */
+int f5(int [static]); /* expected-warning {{ISO C requires a length expression 
with 'static'}} */
+int f5(int a[static]) {} /* expected-warning {{ISO C requires a length 
expression with 'static'}} */
+void f6(int [static *]); /* expected-warning {{ISO C requires a length 
expression with 'static'}} */
 
 char ((((*X))));
 

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

Reply via email to