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 Jari Ronkainen committed Mar 26, 2024
1 parent d83433c commit 92996d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
9 changes: 9 additions & 0 deletions clang/lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
PreferredType.get(Tok.getLocation()));
return ExprError();
}

#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
#include "clang/Basic/TransformTypeTraits.def"
// HACK: libstdc++ uses some of the transform-type-traits as alias
Expand All @@ -1823,6 +1824,10 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
goto ParseIdentifier;
}
goto ExpectedExpression;

case tok::kw_match: // C++ P2688 Pattern Matching: inspect-statement
Res = ParseInspectExpr();
break;
case tok::l_square:
if (getLangOpts().CPlusPlus) {
if (getLangOpts().ObjC) {
Expand All @@ -1848,10 +1853,14 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
Res = ParseObjCMessageExpression();
break;
}
<<<<<<< HEAD
[[fallthrough]];
case tok::kw_match: // C++ P2688 Pattern Matching: inspect-statement
Res = ParseInspectExpr();
break;
=======
LLVM_FALLTHROUGH;
>>>>>>> e01b7f381c56 (Fix incorrect fallthrough from parsing '[')
default:
ExpectedExpression:
NotCastExpr = true;
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 @@ -1519,24 +1519,10 @@ TEST_P(ASTMatchersTest, 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_P(ASTMatchersTest, CxxExceptionHandling_SimpleCases) {
Expand Down

0 comments on commit 92996d2

Please sign in to comment.