https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84373
Bug ID: 84373 Summary: g++ incorrectly resolves names for default parameters Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: smcallis at gmail dot com Target Milestone: --- Created attachment 43409 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43409&action=edit Reproduction of issue Code is attached, the gist is that when defining a default parameter, gcc allows you to refer to a global variable with the same name, whereas the spec would indicate that the function parameters should be included in the name lookup and cause an error. Stackoverflow reference: https://stackoverflow.com/questions/48771614/is-gcc-or-clang-correct-about-this-behavior For posterity, the part of the spec quoted regarding the behavior is: basic.scope.pdecl: The point of declaration for a name is immediately after its complete declarator (Clause [dcl.decl]) and before its initializer (if any), except as noted below. [ Example: int x = 12;{ int x = x; } Here the second x is initialized with its own (indeterminate) value. — end example ] and dcl.fct.default: Default arguments are evaluated each time the function is called. The order of evaluation of function arguments is unspecified. Consequently, parameters of a function shall not be used in a default argument, even if they are not evaluated. Parameters of a function declared before a default argument are in scope and can hide namespace and class member names