[clang] ed4a2a1 - [Clang] handle invalid close location in static assert declaration (#108701)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 16 05:58:53 PDT 2024


Author: Oleksandr T.
Date: 2024-09-16T08:58:50-04:00
New Revision: ed4a2a108ec867188c65f4c3743008db8dd1c0bb

URL: https://github.com/llvm/llvm-project/commit/ed4a2a108ec867188c65f4c3743008db8dd1c0bb
DIFF: https://github.com/llvm/llvm-project/commit/ed4a2a108ec867188c65f4c3743008db8dd1c0bb.diff

LOG: [Clang] handle invalid close location in static assert declaration (#108701)

Fixes #108687

Added: 
    clang/test/Parser/static_assert.cpp

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Parse/ParseDeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 485b75049927fe..17ec1fe0b946de 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..6f0f5a0311bc18 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -1109,7 +1109,8 @@ Decl *Parser::ParseStaticAssertDeclaration(SourceLocation &DeclEnd) {
     }
   }
 
-  T.consumeClose();
+  if (T.consumeClose())
+    return nullptr;
 
   DeclEnd = Tok.getLocation();
   ExpectAndConsumeSemi(diag::err_expected_semi_after_static_assert, TokName);

diff  --git a/clang/test/Parser/static_assert.cpp b/clang/test/Parser/static_assert.cpp
new file mode 100644
index 00000000000000..4fe7d3cda7b214
--- /dev/null
+++ b/clang/test/Parser/static_assert.cpp
@@ -0,0 +1,6 @@
+// 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
+
+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 ')'}}


        


More information about the cfe-commits mailing list