Skip to content

Commit 78e84e5

Browse files
authored
[Clang] A lone [ does not an attribute make (#147306)
In some tentative parses, we would always consider `[` as the start of an attribute - only `[[` should be. Fixes #63880
1 parent 39ea9b7 commit 78e84e5

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ Bug Fixes to C++ Support
932932
through its address (``(&Foo::bar<baz>)()``).
933933
- Correctly handle allocations in the condition of a ``if constexpr``.(#GH120197) (#GH134820)
934934
- Fixed a crash when handling invalid member using-declaration in C++20+ mode. (#GH63254)
935+
- Fixed parsing of lambda expressions that appear after ``*`` or ``&`` in contexts where a declaration can appear. (#GH63880)
935936
- Fix name lookup in lambda appearing in the body of a requires expression. (#GH147650)
936937
- Fix a crash when trying to instantiate an ambiguous specialization. (#GH51866)
937938
- Improved handling of variables with ``consteval`` constructors, to

clang/lib/Parse/ParseTentative.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,12 @@ bool Parser::TrySkipAttributes() {
735735
tok::kw_alignas) ||
736736
Tok.isRegularKeywordAttribute()) {
737737
if (Tok.is(tok::l_square)) {
738+
if (!NextToken().is(tok::l_square))
739+
return true;
740+
738741
ConsumeBracket();
739-
if (Tok.isNot(tok::l_square))
740-
return false;
741742
ConsumeBracket();
743+
742744
if (!SkipUntil(tok::r_square) || Tok.isNot(tok::r_square))
743745
return false;
744746
// Note that explicitly checking for `[[` and `]]` allows to fail as

clang/test/Parser/cxx0x-lambda-expressions.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,15 @@ struct U {
159159
template <typename T>
160160
void m_fn1(T x = 0[0); // expected-error{{expected ']'}} expected-note{{to match this '['}}
161161
} *U;
162+
163+
164+
165+
namespace GH63880{
166+
void f() {
167+
char* i(*[] { return new int; }());
168+
// expected-error@-1{{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}}
169+
170+
char* j(&[]() -> int& { return *new int; }());
171+
//expected-error@-1{{cannot initialize a variable of type 'char *' with an rvalue of type 'int *'}}
172+
}
173+
}

0 commit comments

Comments
 (0)