[Bug c++/77615] Template specialization is resolved differently with and without optimizations turned on

2016-09-16 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77615

--- Comment #3 from Markus Trippelsdorf  ---
The compiler only sees single compilation units and it doesn't keep 
a database of previously seen units. 
When it compiles usage.cc it doesn't know anything about specialization.cc.

So there really is nothing that the compiler could do here.
And clang and other compilers also don't warn and behave exactly like
gcc once you use -O2.

[Bug c++/77615] Template specialization is resolved differently with and without optimizations turned on

2016-09-16 Thread jan.bujak at nokia dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77615

--- Comment #2 from Jan Bujak  ---
(In reply to Markus Trippelsdorf from comment #1)
> Please read: https://isocpp.org/wiki/faq/templates
> 
> * Why can’t I separate the definition of my templates class from its
> declaration and put it inside a .cpp file?

Yes, I was aware of that, and it does make sense from a *technical* standpoint,
but I reported the bug anyway because this is a potential landmine waiting to
go off. You'll probably disagree, but for me changing the optimization level
should *not* subtly change the behavior of the code without even a warning!

If doing this is incorrect then the compiler should at least generate a warning
instead of silently generating wrong code. The compiler knows that the template
was defined in a header file, and it knows that the specialization was defined
in a .cpp file, so it could tell the user that "hey, that probably won't work
as you think it should; if you know what you're doing then feel free to silence
this warning".

[Bug c++/77615] Template specialization is resolved differently with and without optimizations turned on

2016-09-16 Thread trippels at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77615

Markus Trippelsdorf  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 CC||trippels at gcc dot gnu.org
 Resolution|--- |INVALID

--- Comment #1 from Markus Trippelsdorf  ---
Please read: https://isocpp.org/wiki/faq/templates

* Why can’t I separate the definition of my templates class from its
declaration and put it inside a .cpp file?