[clang] [Clang] handle invalid close location in static assert declaration (PR #108701)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 14 14:51:38 PDT 2024
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/108701
>From cbe06cf33277f904fe002db90d428a55b777ff5d Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Sat, 14 Sep 2024 17:02:01 +0300
Subject: [PATCH 1/2] [Clang] handle invalid close location in static assert
declaration
---
clang/docs/ReleaseNotes.rst | 2 +-
clang/lib/Parse/ParseDeclCXX.cpp | 3 ++-
clang/test/SemaCXX/static-assert-cxx26.cpp | 3 +++
3 files changed, 6 insertions(+), 2 deletions(-)
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..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/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 at -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 ')'}}
>From 77063cc64c5047144c2fa0291c38248401d33164 Mon Sep 17 00:00:00 2001
From: Oleksandr T <oleksandr.tarasiuk at outlook.com>
Date: Sun, 15 Sep 2024 00:51:21 +0300
Subject: [PATCH 2/2] add test to cover c++2a compliance
---
clang/test/SemaCXX/static-assert-cxx20.cpp | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 clang/test/SemaCXX/static-assert-cxx20.cpp
diff --git a/clang/test/SemaCXX/static-assert-cxx20.cpp b/clang/test/SemaCXX/static-assert-cxx20.cpp
new file mode 100644
index 00000000000000..479fd14dc5bfad
--- /dev/null
+++ b/clang/test/SemaCXX/static-assert-cxx20.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -std=c++2a -triple=x86_64-linux -fsyntax-only %s -verify
+
+static_assert(true, "" // expected-warning {{'static_assert' with a user-generated message is a C++26 extension}} \
+ // expected-note {{to match this '('}}
+ // expected-error {{expected ')'}}
More information about the cfe-commits
mailing list