GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

C++: Correctly parses default arguments referring to parameters.

Fixes a bug where default arguments could not refer to earlier parameters in the function declaration.

This commit fixes a bug where default arguments in C++ function declarations could not correctly refer to preceding parameters. The issue arose because the parser wasn’t properly associating the parameter’s scope before parsing the default argument. Now, code like void fn (int i = sizeof (i)) {} (where i in sizeof refers to the parameter) is correctly parsed.

In Details

This commit modifies cp_parser_parameter_declaration_list and cp_parser_parameter_declaration in gcc/cp/parser.cc. The grokdeclarator call and DECL_SOURCE_LOCATION setting are moved to cp_parser_parameter_declaration. Also, pushdecl is now called for named declarations with default arguments to manage scopes correctly, resolving PR50479 and PR62244.

For Context

In C++, you can provide default values for function parameters. This commit fixes a bug in the C++ compiler that prevented a default argument from referring to a parameter declared earlier in the same function's parameter list. This correction ensures that the compiler correctly understands and processes code where default arguments depend on other parameters.

Filed Under: c++parserdefault argumentbugfix