https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/187859
Fixes #187690 --- This PR fixes parser recovery for invalid `static_assert` declarations with string literal messages. The parser now stops the message lookahead on `;` and `eof`, so invalid inputs are diagnosed as parse errors. >From 6c06d75558f7044646a4d3a86ba1b7247f39eabd Mon Sep 17 00:00:00 2001 From: Oleksandr Tarasiuk <[email protected]> Date: Sat, 21 Mar 2026 14:24:49 +0200 Subject: [PATCH] [Clang] fix parser recovery for invalid static_assert string messages --- clang/docs/ReleaseNotes.rst | 1 + clang/lib/Parse/ParseDeclCXX.cpp | 2 +- clang/test/Parser/static_assert.cpp | 12 +++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 45234c316eba8..fb674faa42006 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -339,6 +339,7 @@ Bug Fixes in This Version - Fixed a crash when normalizing constraints involving concept template parameters whose index coincided with non-concept template parameters in the same parameter mapping. - Fixed a crash caused by accessing dependent diagnostics of a non-dependent context. - Fixed a crash when substituting into a non-type template parameter that has a type containing an undeduced placeholder type. +- Fixed a crash when parsing invalid ``static_assert`` declarations with string-literal messages (#GH187690). Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 274c354d59808..e3bb52647176f 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -980,7 +980,7 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd) { if (getLangOpts().CPlusPlus11) { for (unsigned I = 0;; ++I) { const Token &T = GetLookAheadToken(I); - if (T.is(tok::r_paren)) + if (T.isOneOf(tok::r_paren, tok::semi, tok::eof)) break; if (!tokenIsLikeStringLiteral(T, getLangOpts()) || T.hasUDSuffix()) { ParseAsExpression = true; diff --git a/clang/test/Parser/static_assert.cpp b/clang/test/Parser/static_assert.cpp index 4fe7d3cda7b21..52ef8a93cea34 100644 --- a/clang/test/Parser/static_assert.cpp +++ b/clang/test/Parser/static_assert.cpp @@ -1,6 +1,8 @@ -// RUN: %clang_cc1 -fsyntax-only -triple=x86_64-linux -std=c++2a -verify=cxx2a %s -// RUN: %clang_cc1 -fsyntax-only -triple=x86_64-linux -std=c++2c -verify=cxx2c %s +// RUN: %clang_cc1 -fsyntax-only -triple=x86_64-linux -verify %s -static_assert(true, "" // cxx2a-warning {{'static_assert' with a user-generated message is a C++26 extension}} \ - // cxx2a-note {{to match this '('}} cxx2c-note {{to match this '('}} - // cxx2a-error {{expected ')'}} cxx2c-error {{expected ')'}} +// expected-error@+1 {{unexpected ';' before ')'}} +static_assert(true, "";); + +// expected-error@+2 {{expected ')'}} +// expected-note@+1 {{to match this '('}} +static_assert(true, "" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
