[Bug c++/58738] forward declaration of function inside function cause link problem with optimization

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Oct 15 13:09:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58738

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The standard says:

The name of a function declared in block scope and the name of a variable
declared by a block scope extern declaration have linkage. If there is a
visible declaration of an entity with linkage having the same name and type,
ignoring entities declared outside the innermost enclosing namespace scope, the
block scope declaration declares that same entity and receives the linkage of
the previous declaration. If there is more than one such matching entity, the
program is ill-formed. Otherwise, if no matching entity is found, the block
scope entity
receives external linkage.

That means the first declaration of bar() has external linkage, but the later
definition has internal linkage because it's a member of an unnamed namespace,
so the declaration does not match the definition.

So I think your program is invalid.



More information about the Gcc-bugs mailing list