https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86491

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jason Vas Dias from comment #4)
> I see now I should have used 'extern C c_', and defined it in tM.C.

Or give the whole template internal linkage.

> 
> But actually, in the context in which it was used, since there was no
> other defining translation unit, and it was only instantiated in a main()
> program, I do not think the warning should have been issued. If I was
> actually trying to instantiate multiple 'class D' objects from multiple
> translation units, there would be a problem, but I was not.

Which is why it's a warning, not an error. Lots of warnings tell you about
things that might be a problem. 


> 
> And really, that '-Wsubobject-linkage' should be split into:
>   A) Detect genuine anonymous namespace use
>   B) Detect usage of static object references in headers that can be
>      included by multiple files, and issue a separate warning message like 
>       'static object reference may not be to same object\
>        if used in multiple translation units'
>      or something like that.

No, I think there is just one warning needed. It's the same problem whether
it's caused by anon namespaces or static linkage. But the warning text should
refer to internal linkage, and maybe mention either anon namespace or 'static'
in a note, depending on which was used.


> 
> It is highly confusing to claim that code uses anonymous namespaces 
> when it does not.

Agreed.

Reply via email to