Skip to content

Commit a13ce26

Browse files
committed
Fix incorrect fallthrough from parsing '['
inspect parsing was incorrectly inserted between parsing l_square and a deliberate fallthrough to default. Moved inspect up. Also fixed some ASTMatcher tests. Fixes llvm#8
1 parent dba1477 commit a13ce26

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

clang/lib/Parse/ParseExpr.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
16621662
cutOffParsing();
16631663
return ExprError();
16641664
}
1665+
case tok::kw_inspect: // C++2b Pattern Matching: inspect-statement
1666+
Res = ParseInspectExpr();
1667+
break;
16651668
case tok::l_square:
16661669
if (getLangOpts().CPlusPlus11) {
16671670
if (getLangOpts().ObjC) {
@@ -1688,9 +1691,6 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
16881691
break;
16891692
}
16901693
LLVM_FALLTHROUGH;
1691-
case tok::kw_inspect: // C++2b Pattern Matching: inspect-statement
1692-
Res = ParseInspectExpr();
1693-
break;
16941694
default:
16951695
NotCastExpr = true;
16961696
return ExprError();

clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

+3-17
Original file line numberDiff line numberDiff line change
@@ -1176,24 +1176,10 @@ TEST(SwitchCase, MatchesSwitch) {
11761176
}
11771177

11781178
TEST(PatternMatching, MatchesInspect) {
1179-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __:; } }", inspectExpr(), true, "-fpattern-matching"));
1180-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42:; } }", inspectExpr(), true, "-fpattern-matching"));
1181-
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y:; } }", inspectExpr(), true, "-fpattern-matching"));
1179+
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __ => {} }; }", inspectExpr(), true, "-fpattern-matching"));
1180+
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42 => {} }; }", inspectExpr(), true, "-fpattern-matching"));
1181+
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y => {} }; }", inspectExpr(), true, "-fpattern-matching"));
11821182
EXPECT_TRUE(matchesConditionally("void x() { }", inspectExpr(), false, "-fpattern-matching"));
1183-
1184-
EXPECT_TRUE(matchesConditionally("void x() { struct A{int x;}; A a = {42}; inspect(a) { __:; } }", inspectExpr(), true, "-fpattern-matching"));
1185-
EXPECT_TRUE(matchesConditionally("void x() { struct A{int x; bool operator==(const A& other) { return x == other.x; } }; A a = {42}; A b = a; inspect(a) { b:; } }", inspectExpr(), true, "-fpattern-matching"));
1186-
}
1187-
1188-
TEST(PatternMatching, MatchesPattern) {
1189-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __:; } }", patternStmt(), true, "-fpattern-matching"));
1190-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42:; } }", patternStmt(), true, "-fpattern-matching"));
1191-
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y:; } }", patternStmt(), true, "-fpattern-matching"));
1192-
EXPECT_TRUE(matchesConditionally("void x() { }", patternStmt(), false, "-fpattern-matching"));
1193-
1194-
1195-
EXPECT_TRUE(matchesConditionally("void x() { int a=42; inspect(42) { a if(true):; } }", patternStmt(), true, "-fpattern-matching"));
1196-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42 if(true):; } }", patternStmt(), true, "-fpattern-matching"));
11971183
}
11981184

11991185
TEST(ExceptionHandling, SimpleCases) {

0 commit comments

Comments
 (0)