This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/19809] New: Multiple definitions of friend functions in template classes
- From: "sstrasser at systemhaus-gruppe dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Feb 2005 18:13:32 -0000
- Subject: [Bug c++/19809] New: Multiple definitions of friend functions in template classes
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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