This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Possible bug in g++ - template specialization
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Maciej Cencora <m dot cencora at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 10 Jul 2009 14:44:06 +0200
- Subject: Re: Possible bug in g++ - template specialization
- References: <4d623d70907100448g529a565qc64371440c15a7c8@mail.gmail.com>
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.