Skip to content

Commit 3951d18

Browse files
committed
Fix bindings of trailing returns
Signed-off-by: Roberto Raggi <[email protected]>
1 parent ca1bbd6 commit 3951d18

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

src/parser/cxx/ast_rewriter.cc

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,17 +2516,27 @@ auto ASTRewriter::ExpressionVisitor::operator()(LambdaExpressionAST* ast)
25162516
lambdaSpecifierList = &(*lambdaSpecifierList)->next;
25172517
}
25182518

2519-
copy->exceptionSpecifier = rewrite(ast->exceptionSpecifier);
2519+
{
2520+
auto _ = Binder::ScopeGuard(binder());
25202521

2521-
for (auto attributeList = &copy->attributeList;
2522-
auto node : ListView{ast->attributeList}) {
2523-
auto value = rewrite(node);
2524-
*attributeList = make_list_node(arena(), value);
2525-
attributeList = &(*attributeList)->next;
2522+
if (copy->parameterDeclarationClause) {
2523+
binder()->setScope(
2524+
copy->parameterDeclarationClause->functionParametersSymbol);
2525+
}
2526+
2527+
copy->exceptionSpecifier = rewrite(ast->exceptionSpecifier);
2528+
2529+
for (auto attributeList = &copy->attributeList;
2530+
auto node : ListView{ast->attributeList}) {
2531+
auto value = rewrite(node);
2532+
*attributeList = make_list_node(arena(), value);
2533+
attributeList = &(*attributeList)->next;
2534+
}
2535+
2536+
copy->trailingReturnType = rewrite(ast->trailingReturnType);
2537+
copy->requiresClause = rewrite(ast->requiresClause);
25262538
}
25272539

2528-
copy->trailingReturnType = rewrite(ast->trailingReturnType);
2529-
copy->requiresClause = rewrite(ast->requiresClause);
25302540
copy->statement = ast_cast<CompoundStatementAST>(rewrite(ast->statement));
25312541
copy->captureDefault = ast->captureDefault;
25322542
copy->symbol = ast->symbol;
@@ -3974,6 +3984,13 @@ auto ASTRewriter::DeclaratorChunkVisitor::operator()(
39743984
copy->parameterDeclarationClause = rewrite(ast->parameterDeclarationClause);
39753985
copy->rparenLoc = ast->rparenLoc;
39763986

3987+
auto _ = Binder::ScopeGuard{binder()};
3988+
3989+
if (copy->parameterDeclarationClause) {
3990+
binder()->setScope(
3991+
copy->parameterDeclarationClause->functionParametersSymbol);
3992+
}
3993+
39773994
auto cvQualifierListCtx = DeclSpecs{rewriter()};
39783995
for (auto cvQualifierList = &copy->cvQualifierList;
39793996
auto node : ListView{ast->cvQualifierList}) {

src/parser/cxx/parser.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,8 @@ auto Parser::parse_lambda_expression(ExpressionAST*& yyast) -> bool {
11381138
}
11391139

11401140
expect(TokenKind::T_RPAREN, ast->rparenLoc);
1141+
1142+
setScope(ast->parameterDeclarationClause->functionParametersSymbol);
11411143
}
11421144

11431145
parse_optional_attribute_specifier_seq(ast->gnuAtributeList,
@@ -5452,6 +5454,8 @@ auto Parser::parse_function_declarator(FunctionDeclaratorChunkAST*& yyast,
54525454
}
54535455

54545456
if (!match(TokenKind::T_RPAREN, rparenLoc)) return false;
5457+
5458+
setScope(parameterDeclarationClause->functionParametersSymbol);
54555459
}
54565460

54575461
lookahead.commit();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %cxx -verify -fcheck -dump-symbols %s | %filecheck %s
2+
3+
auto f(int x) -> decltype(x);
4+
auto g(int x, decltype(x)* y) -> decltype(y);
5+
auto k(int x) -> decltype((x));
6+
7+
// clang-format off
8+
// CHECK:namespace
9+
// CHECK-NEXT: function int f(int)
10+
// CHECK-NEXT: function int* g(int, int*)
11+
// CHECK-NEXT: function int& k(int)

0 commit comments

Comments
 (0)