Skip to content

Commit 23b0541

Browse files
committed
De-nest tentative parsing to disambiguate lambdas from designators; no
functionality change. llvm-svn: 150817
1 parent fd7d1b4 commit 23b0541

File tree

1 file changed

+45
-42
lines changed

1 file changed

+45
-42
lines changed

clang/lib/Parse/ParseInit.cpp

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -58,52 +58,55 @@ bool Parser::MayBeDesignationStart() {
5858
return true;
5959
}
6060

61-
// Parse up to (at most) the token after the closing ']' to determine
62-
// whether this is a C99 designator or a lambda.
63-
TentativeParsingAction Tentative(*this);
64-
ConsumeBracket();
65-
while (true) {
66-
switch (Tok.getKind()) {
67-
case tok::equal:
68-
case tok::amp:
69-
case tok::identifier:
70-
case tok::kw_this:
71-
// These tokens can occur in a capture list or a constant-expression.
72-
// Keep looking.
73-
ConsumeToken();
74-
continue;
75-
76-
case tok::comma:
77-
// Since a comma cannot occur in a constant-expression, this must
78-
// be a lambda.
79-
Tentative.Revert();
80-
return false;
81-
82-
case tok::r_square: {
83-
// Once we hit the closing square bracket, we look at the next
84-
// token. If it's an '=', this is a designator. Otherwise, it's a
85-
// lambda expression. This decision favors lambdas over the older
86-
// GNU designator syntax, which allows one to omit the '=', but is
87-
// consistent with GCC.
88-
ConsumeBracket();
89-
tok::TokenKind Kind = Tok.getKind();
90-
Tentative.Revert();
91-
return Kind == tok::equal;
92-
}
93-
94-
default:
95-
// Anything else cannot occur in a lambda capture list, so it
96-
// must be a designator.
97-
Tentative.Revert();
98-
return true;
99-
}
100-
}
101-
102-
return true;
61+
// Handle the complicated case below.
62+
break;
10363
}
10464
case tok::identifier: // designation: identifier ':'
10565
return PP.LookAhead(0).is(tok::colon);
10666
}
67+
68+
// Parse up to (at most) the token after the closing ']' to determine
69+
// whether this is a C99 designator or a lambda.
70+
TentativeParsingAction Tentative(*this);
71+
ConsumeBracket();
72+
while (true) {
73+
switch (Tok.getKind()) {
74+
case tok::equal:
75+
case tok::amp:
76+
case tok::identifier:
77+
case tok::kw_this:
78+
// These tokens can occur in a capture list or a constant-expression.
79+
// Keep looking.
80+
ConsumeToken();
81+
continue;
82+
83+
case tok::comma:
84+
// Since a comma cannot occur in a constant-expression, this must
85+
// be a lambda.
86+
Tentative.Revert();
87+
return false;
88+
89+
case tok::r_square: {
90+
// Once we hit the closing square bracket, we look at the next
91+
// token. If it's an '=', this is a designator. Otherwise, it's a
92+
// lambda expression. This decision favors lambdas over the older
93+
// GNU designator syntax, which allows one to omit the '=', but is
94+
// consistent with GCC.
95+
ConsumeBracket();
96+
tok::TokenKind Kind = Tok.getKind();
97+
Tentative.Revert();
98+
return Kind == tok::equal;
99+
}
100+
101+
default:
102+
// Anything else cannot occur in a lambda capture list, so it
103+
// must be a designator.
104+
Tentative.Revert();
105+
return true;
106+
}
107+
}
108+
109+
return true;
107110
}
108111

109112
static void CheckArrayDesignatorSyntax(Parser &P, SourceLocation Loc,

0 commit comments

Comments
 (0)