https://github.com/a-tarasyuk created https://github.com/llvm/llvm-project/pull/108701
Fixes #108687 >From 3e7e69e36e93f12c33ccdda9fea78e22cc9bdd84 Mon Sep 17 00:00:00 2001 From: Oleksandr T <oleksandr.taras...@outlook.com> Date: Sat, 14 Sep 2024 17:02:01 +0300 Subject: [PATCH] [Clang] handle invalid close location in static assert declaration --- clang/docs/ReleaseNotes.rst | 2 +- clang/lib/Parse/ParseDeclCXX.cpp | 2 ++ clang/test/SemaCXX/static-assert-cxx26.cpp | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 79b154ef1aef5e..27dde935ad19b9 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -388,7 +388,7 @@ Bug Fixes to C++ Support - Fixed a crash in the typo correction of an invalid CTAD guide. (#GH107887) - Fixed a crash when clang tries to subtitute parameter pack while retaining the parameter pack. #GH63819, #GH107560 - +- Fix a crash when a static assert declaration has an invalid close location. (#GH108687) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 6370da1fab0042..d02601172fe239 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -1110,6 +1110,8 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd) { } T.consumeClose(); + if (T.getCloseLocation().isInvalid()) + return nullptr; DeclEnd = Tok.getLocation(); ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert, TokName); diff --git a/clang/test/SemaCXX/static-assert-cxx26.cpp b/clang/test/SemaCXX/static-assert-cxx26.cpp index 7d896d8b365b74..95ffa8cd68cf7c 100644 --- a/clang/test/SemaCXX/static-assert-cxx26.cpp +++ b/clang/test/SemaCXX/static-assert-cxx26.cpp @@ -415,3 +415,6 @@ static_assert( // expected-note@-1 {{read of dereferenced one-past-the-end pointer is not allowed in a constant expression}} ); } + +static_assert(true, "" // expected-note {{to match this '('}} + // expected-error {{expected ')'}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits