public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sstrasser at systemhaus-gruppe dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/19809] New: Multiple definitions of friend functions in template classes
Date: Mon, 07 Feb 2005 23:36:00 -0000	[thread overview]
Message-ID: <20050207181328.19809.sstrasser@systemhaus-gruppe.de> (raw)

This report is based on <16899453.0502060835.6c893401@posting.google.com>

given this testcase:

#include <iostream>
template<int i>
struct n{
  friend void foo(){
    std::cerr << i << std::endl;;
  }
};

int main(){
  n<1> n1;
  n<2> n2;
  n<3> n3;
  foo();
}

there must be a bug here, though I'm not sure what exactly it is.

a) it could be a multiple definition of foo, which is reported by version 3.3.4,
but not by 4.0.0 and 3.4.3.

b) std note 14.5.3.3 could mean that it's not a multiple definition:

<<<3 When a function is defined in a friend function declaration in a class
template, the function is defined when the class template is first instantiated.
The function is defined even if it is never used.>>>

so if it's _only_ defined on the first instantiation this is not a multiple
definition - but then I don't think it is legal to use the template arguments of
struct n in the function definition

c) even if b) is wrong and usage of template arguments is allowed, there's still
a bug, because the result of the testcase above is "3", so the _last_
instantiation is used.


comeau C++ chooses a), so does 3.3.4.

-- 
           Summary: Multiple definitions of friend functions in template
                    classes
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sstrasser at systemhaus-gruppe dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19809


             reply	other threads:[~2005-02-07 18:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-07 23:36 sstrasser at systemhaus-gruppe dot de [this message]
2005-02-08  3:37 ` [Bug c++/19809] [3.4/4.0 Regression] " giovannibajo at libero dot it
2005-02-16 19:12 ` pinskia at gcc dot gnu dot org
2005-05-19 17:53 ` [Bug c++/19809] [3.4/4.0/4.1 " mmitchel at gcc dot gnu dot org
2005-07-22 21:18 ` pinskia at gcc dot gnu dot org
2005-09-27 16:25 ` mmitchel at gcc dot gnu dot org

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=20050207181328.19809.sstrasser@systemhaus-gruppe.de \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).