https://github.com/alejandro-colomar updated https://github.com/llvm/llvm-project/pull/244642
>From 422c01e791f548e4accdc61a388213ea77c3e24c 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/DiagnosticParseKinds.td | 6 ++---- clang/lib/Parse/ParseDecl.cpp | 6 ++---- clang/test/Parser/declarators.c | 4 +++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 2be6ff8344cd6d..aeb11a63b98abf 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -465,10 +465,8 @@ 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'">; 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
