public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Guenther <richard.guenther@gmail.com>
To: Maciej Cencora <m.cencora@gmail.com>
Cc: gcc@gcc.gnu.org
Subject: Re: Possible bug in g++ - template specialization
Date: Fri, 10 Jul 2009 12:44:00 -0000	[thread overview]
Message-ID: <84fc9c000907100544n6d0a3d6u3927eb9925d1110@mail.gmail.com> (raw)
In-Reply-To: <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.

      reply	other threads:[~2009-07-10 12:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10 11:48 Maciej Cencora
2009-07-10 12:44 ` Richard Guenther [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=84fc9c000907100544n6d0a3d6u3927eb9925d1110@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=m.cencora@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).