Skip to content

Commit d95d0fd

Browse files
committed
[Clang] enhance error recovery with RecoveryExpr for trailing commas in call arguments
1 parent f54cdc5 commit d95d0fd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

clang/lib/Parse/ParseExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3705,6 +3705,9 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
37053705
Token Comma = Tok;
37063706
ConsumeToken();
37073707
checkPotentialAngleBracketDelimiter(Comma);
3708+
3709+
if (Tok.is(tok::r_paren))
3710+
break;
37083711
}
37093712
if (SawError) {
37103713
// Ensure typos get diagnosed when errors were encountered while parsing the

clang/test/AST/ast-dump-recovery.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int some_func(int *);
99
// CHECK-NEXT: `-IntegerLiteral {{.*}} 123
1010
// DISABLED-NOT: -RecoveryExpr {{.*}} contains-errors
1111
int invalid_call = some_func(123);
12-
void test_invalid_call(int s) {
12+
void test_invalid_call_1(int s) {
1313
// CHECK: CallExpr {{.*}} '<dependent type>' contains-errors
1414
// CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} 'some_func'
1515
// CHECK-NEXT: |-RecoveryExpr {{.*}} <col:13>
@@ -32,6 +32,21 @@ void test_invalid_call(int s) {
3232
int var = some_func(undef1);
3333
}
3434

35+
int some_func2(int a, int b);
36+
void test_invalid_call_2() {
37+
// CHECK: `-RecoveryExpr {{.*}} 'int' contains-errors
38+
// CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'some_func2'
39+
// CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
40+
some_func2(1, );
41+
}
42+
43+
void test_invalid_call_3() {
44+
// CHECK: `-RecoveryExpr {{.*}} 'int' contains-errors
45+
// CHECK-NEXT: |-UnresolvedLookupExpr {{.*}} '<overloaded function type>' lvalue (ADL) = 'some_func2'
46+
// CHECK-NEXT: `-IntegerLiteral {{.*}} 'int' 1
47+
some_func2(1);
48+
}
49+
3550
int ambig_func(double);
3651
int ambig_func(float);
3752

0 commit comments

Comments
 (0)