[clang] [Clang] A lone `[` does not an attribute make (PR #147306)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 7 06:59:56 PDT 2025
https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/147306
In some tentative parses, we would always consider `[` as the start of an attribute - only `[[` should be.
Fixes #63880
>From b47ae00ae1971d0d57d2a4b5da1cf8f02a0c1194 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Mon, 7 Jul 2025 15:57:56 +0200
Subject: [PATCH] [Clang] A lone `[` does not an attribute make
In some tentative parses, we would always consider `[` as the start
of an attribute - only `[[` should be.
Fixes #63880
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Parse/ParseTentative.cpp | 6 ++++--
clang/test/Parser/cxx0x-lambda-expressions.cpp | 12 ++++++++++++
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a6be59f1d6bd7..6153138c2f152 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -903,6 +903,7 @@ Bug Fixes to C++ Support
- Fix a bug where private access specifier of overloaded function not respected. (#GH107629)
- Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820)
- Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254)
+- Fixed parsing of lambda expressions that appear after ``*`` or ``&`` in contexts where a declaration can appear. (#GH63880)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Parse/ParseTentative.cpp b/clang/lib/Parse/ParseTentative.cpp
index 95cee824c40b7..b58100c635677 100644
--- a/clang/lib/Parse/ParseTentative.cpp
+++ b/clang/lib/Parse/ParseTentative.cpp
@@ -735,10 +735,12 @@ bool Parser::TrySkipAttributes() {
tok::kw_alignas) ||
Tok.isRegularKeywordAttribute()) {
if (Tok.is(tok::l_square)) {
+ if (!NextToken().is(tok::l_square))
+ return true;
+
ConsumeBracket();
- if (Tok.isNot(tok::l_square))
- return false;
ConsumeBracket();
+
if (!SkipUntil(tok::r_square) || Tok.isNot(tok::r_square))
return false;
// Note that explicitly checking for `[[` and `]]` allows to fail as
diff --git a/clang/test/Parser/cxx0x-lambda-expressions.cpp b/clang/test/Parser/cxx0x-lambda-expressions.cpp
index a786a964163e4..f90f8ce27c53e 100644
--- a/clang/test/Parser/cxx0x-lambda-expressions.cpp
+++ b/clang/test/Parser/cxx0x-lambda-expressions.cpp
@@ -159,3 +159,15 @@ struct U {
template <typename T>
void m_fn1(T x = 0[0); // expected-error{{expected ']'}} expected-note{{to match this '['}}
} *U;
+
+
+
+namespace GH63880{
+void f() {
+ char* i(*[] { return new int; }());
+ // expected-error at -1{{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}}
+
+ char* j(&[]() -> int& { return *new int; }());
+ //expected-error at -1{{cannot initialize a variable of type 'char *' with an rvalue of type 'int *'}}
+}
+}
More information about the cfe-commits
mailing list