Skip to content

Commit 92996d2

Browse files
dansarginsonJari Ronkainen
authored and
Jari Ronkainen
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 d83433c commit 92996d2

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

clang/lib/Parse/ParseExpr.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
18121812
PreferredType.get(Tok.getLocation()));
18131813
return ExprError();
18141814
}
1815+
18151816
#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
18161817
#include "clang/Basic/TransformTypeTraits.def"
18171818
// HACK: libstdc++ uses some of the transform-type-traits as alias
@@ -1823,6 +1824,10 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
18231824
goto ParseIdentifier;
18241825
}
18251826
goto ExpectedExpression;
1827+
1828+
case tok::kw_match: // C++ P2688 Pattern Matching: inspect-statement
1829+
Res = ParseInspectExpr();
1830+
break;
18261831
case tok::l_square:
18271832
if (getLangOpts().CPlusPlus) {
18281833
if (getLangOpts().ObjC) {
@@ -1848,10 +1853,14 @@ ExprResult Parser::ParseCastExpression(CastParseKind ParseKind,
18481853
Res = ParseObjCMessageExpression();
18491854
break;
18501855
}
1856+
<<<<<<< HEAD
18511857
[[fallthrough]];
18521858
case tok::kw_match: // C++ P2688 Pattern Matching: inspect-statement
18531859
Res = ParseInspectExpr();
18541860
break;
1861+
=======
1862+
LLVM_FALLTHROUGH;
1863+
>>>>>>> e01b7f381c56 (Fix incorrect fallthrough from parsing '[')
18551864
default:
18561865
ExpectedExpression:
18571866
NotCastExpr = true;

clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

+3-17
Original file line numberDiff line numberDiff line change
@@ -1519,24 +1519,10 @@ TEST_P(ASTMatchersTest, SwitchCase_MatchesSwitch) {
15191519
}
15201520

15211521
TEST(PatternMatching, MatchesInspect) {
1522-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __:; } }", inspectExpr(), true, "-fpattern-matching"));
1523-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42:; } }", inspectExpr(), true, "-fpattern-matching"));
1524-
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y:; } }", inspectExpr(), true, "-fpattern-matching"));
1522+
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __ => {} }; }", inspectExpr(), true, "-fpattern-matching"));
1523+
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42 => {} }; }", inspectExpr(), true, "-fpattern-matching"));
1524+
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y => {} }; }", inspectExpr(), true, "-fpattern-matching"));
15251525
EXPECT_TRUE(matchesConditionally("void x() { }", inspectExpr(), false, "-fpattern-matching"));
1526-
1527-
EXPECT_TRUE(matchesConditionally("void x() { struct A{int x;}; A a = {42}; inspect(a) { __:; } }", inspectExpr(), true, "-fpattern-matching"));
1528-
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"));
1529-
}
1530-
1531-
TEST(PatternMatching, MatchesPattern) {
1532-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { __:; } }", patternStmt(), true, "-fpattern-matching"));
1533-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42:; } }", patternStmt(), true, "-fpattern-matching"));
1534-
EXPECT_TRUE(matchesConditionally("void x() { int y=0; inspect(42) { y:; } }", patternStmt(), true, "-fpattern-matching"));
1535-
EXPECT_TRUE(matchesConditionally("void x() { }", patternStmt(), false, "-fpattern-matching"));
1536-
1537-
1538-
EXPECT_TRUE(matchesConditionally("void x() { int a=42; inspect(42) { a if(true):; } }", patternStmt(), true, "-fpattern-matching"));
1539-
EXPECT_TRUE(matchesConditionally("void x() { inspect(42) { 42 if(true):; } }", patternStmt(), true, "-fpattern-matching"));
15401526
}
15411527

15421528
TEST_P(ASTMatchersTest, CxxExceptionHandling_SimpleCases) {

0 commit comments

Comments
 (0)