------- Additional Comments From austern at apple dot com  2004-11-29 20:56 
-------
Yep, I see what the problem is now.  When we create a builtin in C++, we create 
the declaration in both 
the global namespace and namespace std. Later, when we see the declaration of 
snprintf in the global 
namespace, we correctly set the assembler name of ::snprintf.  We don't set the 
assembler name of ::
snprintf, since it's a separate declaration. Then we see the using-declaration, 
which is handled by 
do_nonmember_using_decl. It sees that we have an snprintf in namespace std 
already, verifies that ::
snprintf and std::snprintf are compatible so this is not an error, and then 
just continues to use the 
original declaration of std::snprintf that was created by builtin_function.  
Nothing ever sets the 
assembler name of std::snprintf to match the one that got set for ::snprintf.

So what to do about this? In principle, I think the answer is that 
builtin_function is doing something 
wrong by calling builtin_function_1 twice, once for the global namespace and 
once for namespace std.  
If we really must define all builtins in namespace std (what's the rationale?), 
then at least we should do 
it with a using-declaration instead of creating two entirely separate decls.  
This would help compile 
time performance a little bit: builtin_function_1 is just expensive enough to 
show up on profiles.

If that's too radical a change given the current state of the compiler, then we 
could special-case builtins 
in do_nonmember_using_decl to make sure that the assembler name gets copied 
correctly. This 
wouldn't be hard.  There's already some special-casing for builtins there. 

-- 


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

Reply via email to