This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Possible bug in g++ - template specialization


On Fri, Jul 10, 2009 at 1:48 PM, Maciej Cencora<m.cencora@gmail.com> wrote:
> Hi,
>
> I think I've found a bug in g++. Let's say we have following files:
>
> // a.hpp
>
> template<typename T>
> void func1()
> {
> ? ? ? ?// general code
> }
>
> // a.cpp
>
> #include "a.hpp"
>
> template<>
> void func1<int>()
> {
> ? ? ? ?// specialized code
> }
>
> // main.cpp
>
> #include "a.hpp"
>
> int main(void)
> {
> ? ? ? ?func1<int>();
>
> ? ? ? ?return 0;
> }
>
>
> Now when we run the program compiled with: g++ main.cpp a.cpp -o main
> specialized version of func1 will be called, but when compiled with
> -Os flag the general version will be called.
> I'm not an expert but I believe the -Os behaviour is the correct one.

By not making the specialized version available at the point of
instantiation you are violating the one-definition rule (ODR, no need
to diagnose it) and the behavior is undefined.

Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]