Skip to content

Commit

Permalink
Fix incorrect fallthrough from parsing '['
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dansarginson authored and bcardosolopes committed Jan 29, 2021
1 parent dba1477 commit e01b7f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
6 changes: 3 additions & 3 deletions clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,9 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
cutOffParsing();
return ExprError();
}
case tok::kw_inspect: // C++2b Pattern Matching: inspect-statement
Res = ParseInspectExpr();
break;
case tok::l_square:
if (getLangOpts().CPlusPlus11) {
if (getLangOpts().ObjC) {
Expand All @@ -1688,9 +1691,6 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
break;
}
LLVM_FALLTHROUGH;
case tok::kw_inspect: // C++2b Pattern Matching: inspect-statement
Res = ParseInspectExpr();
break;
default:
NotCastExpr = true;
return ExprError();
Expand Down
20 changes: 3 additions & 17 deletions clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,24 +1176,10 @@ TEST(SwitchCase, MatchesSwitch) {
}

TEST(PatternMatching, MatchesInspect) {
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __:; } }", inspectExpr(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42:; } }", inspectExpr(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y:; } }", inspectExpr(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __ => {} }; }", inspectExpr(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42 => {} }; }", inspectExpr(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y => {} }; }", inspectExpr(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { }", inspectExpr(), false, "-fpattern-matching"));

EXPECT_TRUE(matchesConditionally("void x() { struct A{int x;}; A a = {42}; inspect(a) { __:; } }", inspectExpr(), true, "-fpattern-matching"));
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"));
}

TEST(PatternMatching, MatchesPattern) {
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __:; } }", patternStmt(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42:; } }", patternStmt(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y:; } }", patternStmt(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { }", patternStmt(), false, "-fpattern-matching"));


EXPECT_TRUE(matchesConditionally("void x() { int a=42; inspect(42) { a if(true):; } }", patternStmt(), true, "-fpattern-matching"));
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42 if(true):; } }", patternStmt(), true, "-fpattern-matching"));
}

TEST(ExceptionHandling, SimpleCases) {
Expand Down

0 comments on commit e01b7f3

Please sign in to comment.