diff --git a/src/parser/cxx/ast_rewriter.cc b/src/parser/cxx/ast_rewriter.cc index a7579b3d..969d89b7 100644 --- a/src/parser/cxx/ast_rewriter.cc +++ b/src/parser/cxx/ast_rewriter.cc @@ -2516,17 +2516,27 @@ auto ASTRewriter::ExpressionVisitor::operator()(LambdaExpressionAST* ast) lambdaSpecifierList = &(*lambdaSpecifierList)->next; } - copy->exceptionSpecifier = rewrite(ast->exceptionSpecifier); + { + auto _ = Binder::ScopeGuard(binder()); - for (auto attributeList = ©->attributeList; - auto node : ListView{ast->attributeList}) { - auto value = rewrite(node); - *attributeList = make_list_node(arena(), value); - attributeList = &(*attributeList)->next; + if (copy->parameterDeclarationClause) { + binder()->setScope( + copy->parameterDeclarationClause->functionParametersSymbol); + } + + copy->exceptionSpecifier = rewrite(ast->exceptionSpecifier); + + for (auto attributeList = ©->attributeList; + auto node : ListView{ast->attributeList}) { + auto value = rewrite(node); + *attributeList = make_list_node(arena(), value); + attributeList = &(*attributeList)->next; + } + + copy->trailingReturnType = rewrite(ast->trailingReturnType); + copy->requiresClause = rewrite(ast->requiresClause); } - copy->trailingReturnType = rewrite(ast->trailingReturnType); - copy->requiresClause = rewrite(ast->requiresClause); copy->statement = ast_cast(rewrite(ast->statement)); copy->captureDefault = ast->captureDefault; copy->symbol = ast->symbol; @@ -3974,6 +3984,13 @@ auto ASTRewriter::DeclaratorChunkVisitor::operator()( copy->parameterDeclarationClause = rewrite(ast->parameterDeclarationClause); copy->rparenLoc = ast->rparenLoc; + auto _ = Binder::ScopeGuard{binder()}; + + if (copy->parameterDeclarationClause) { + binder()->setScope( + copy->parameterDeclarationClause->functionParametersSymbol); + } + auto cvQualifierListCtx = DeclSpecs{rewriter()}; for (auto cvQualifierList = ©->cvQualifierList; auto node : ListView{ast->cvQualifierList}) { diff --git a/src/parser/cxx/parser.cc b/src/parser/cxx/parser.cc index 86e446c2..893b73bc 100644 --- a/src/parser/cxx/parser.cc +++ b/src/parser/cxx/parser.cc @@ -1138,6 +1138,8 @@ auto Parser::parse_lambda_expression(ExpressionAST*& yyast) -> bool { } expect(TokenKind::T_RPAREN, ast->rparenLoc); + + setScope(ast->parameterDeclarationClause->functionParametersSymbol); } parse_optional_attribute_specifier_seq(ast->gnuAtributeList, @@ -5452,6 +5454,8 @@ auto Parser::parse_function_declarator(FunctionDeclaratorChunkAST*& yyast, } if (!match(TokenKind::T_RPAREN, rparenLoc)) return false; + + setScope(parameterDeclarationClause->functionParametersSymbol); } lookahead.commit(); diff --git a/tests/unit_tests/sema/trailing_return_type_02.cc b/tests/unit_tests/sema/trailing_return_type_02.cc new file mode 100644 index 00000000..b8498f5e --- /dev/null +++ b/tests/unit_tests/sema/trailing_return_type_02.cc @@ -0,0 +1,11 @@ +// RUN: %cxx -verify -fcheck -dump-symbols %s | %filecheck %s + +auto f(int x) -> decltype(x); +auto g(int x, decltype(x)* y) -> decltype(y); +auto k(int x) -> decltype((x)); + +// clang-format off +// CHECK:namespace +// CHECK-NEXT: function int f(int) +// CHECK-NEXT: function int* g(int, int*) +// CHECK-NEXT: function int& k(int) \ No newline at end of file