https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62244
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Marek Polacek <[email protected]>: https://gcc.gnu.org/g:5fd9f0f77f2bdb9a2843bb9b9b55ab6bd2cbd5c8 commit r17-472-g5fd9f0f77f2bdb9a2843bb9b9b55ab6bd2cbd5c8 Author: Marek Polacek <[email protected]> Date: Mon May 11 17:19:42 2026 -0400 c++: deferred parsing of default arguments [PR50479] In void fn (int i = sizeof (i)) {} the i in sizeof should refer to the parameter ([basic.scope.pdecl]) and since the second i is not evaluated, the code is valid per [dcl.fct.default]/9: A parameter shall not appear as a potentially evaluated expression in a default argument. This patch fixes this by moving the grokdeclarator call from _parameter_declaration_list to _parameter_declaration and maybe calling pushdecl before parsing the default argument. PR c++/50479 PR c++/62244 gcc/cp/ChangeLog: * parser.cc (cp_parser_parameter_declaration_list): Move the grokdeclarator call and setting DECL_SOURCE_LOCATION to... (cp_parser_parameter_declaration): ...here. New tree parameter. Set it. Call pushdecl for a named decl with a default argument. gcc/testsuite/ChangeLog: * g++.dg/reflect/parm1.C: Uncomment code. * g++.dg/parse/defarg22.C: New test. * g++.dg/parse/defarg23.C: New test. * g++.dg/parse/defarg24.C: New test. * g++.dg/parse/defarg25.C: New test. * g++.dg/parse/defarg26.C: New test. Reviewed-by: Jason Merrill <[email protected]>
