public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19809] New: Multiple definitions of friend functions in template classes
@ 2005-02-07 23:36 sstrasser at systemhaus-gruppe dot de
  2005-02-08  3:37 ` [Bug c++/19809] [3.4/4.0 Regression] " giovannibajo at libero dot it
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: sstrasser at systemhaus-gruppe dot de @ 2005-02-07 23:36 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/19809] [3.4/4.0 Regression] Multiple definitions of friend functions in template classes
  2005-02-07 23:36 [Bug c++/19809] New: Multiple definitions of friend functions in template classes sstrasser at systemhaus-gruppe dot de
@ 2005-02-08  3:37 ` giovannibajo at libero dot it
  2005-02-16 19:12 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: giovannibajo at libero dot it @ 2005-02-08  3:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2005-02-07 19:46 -------
My understanding is that this should create one definition *per* instantiation 
so there is an ODR conflict if the signatures match. Notice that it is still 
useful to do something as:

template <class T>
struct A {
   friend void foo(A<T> t) { .... }
};

template class A<int>;
template class A<float>;

thus different overloads are injected into the global namespace.

Now, the standard says that we are not forced to detect ODR violations. On the 
other hand, we used to do so for this case, so I qualify this as a QoI 
regression.

CC'ing Kriang as he surely knows if this is fixable in the 4.0 timeframe.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lerdsuwa at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |accepts-invalid
      Known to fail|                            |3.4.4 4.0.0
      Known to work|                            |3.3.4
   Last reconfirmed|0000-00-00 00:00:00         |2005-02-07 19:46:48
               date|                            |
            Summary|Multiple definitions of     |[3.4/4.0 Regression]
                   |friend functions in template|Multiple definitions of
                   |classes                     |friend functions in template
                   |                            |classes
   Target Milestone|---                         |3.4.4


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/19809] [3.4/4.0 Regression] Multiple definitions of friend functions in template classes
  2005-02-07 23:36 [Bug c++/19809] New: Multiple definitions of friend functions in template classes sstrasser at systemhaus-gruppe dot de
  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
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-16 19:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-16 15:02 -------
: Search converges between 2004-02-01-trunk (#445) and 2004-03-01-trunk (#446).
: Search converges between 2004-03-01-3.4 (#2) and 2004-03-15-3.4 (#3).

-- 


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/19809] [3.4/4.0/4.1 Regression] Multiple definitions of friend functions in template classes
  2005-02-07 23:36 [Bug c++/19809] New: Multiple definitions of friend functions in template classes sstrasser at systemhaus-gruppe dot de
  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 ` 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
  4 siblings, 0 replies; 6+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-05-19 17:53 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.4.4                       |3.4.5


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/19809] [3.4/4.0/4.1 Regression] Multiple definitions of friend functions in template classes
  2005-02-07 23:36 [Bug c++/19809] New: Multiple definitions of friend functions in template classes sstrasser at systemhaus-gruppe dot de
                   ` (2 preceding siblings ...)
  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
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-22 21:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-22 21:13 -------
Moving to 4.0.2 pre Mark.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|3.4.5                       |4.0.2


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/19809] [3.4/4.0/4.1 Regression] Multiple definitions of friend functions in template classes
  2005-02-07 23:36 [Bug c++/19809] New: Multiple definitions of friend functions in template classes sstrasser at systemhaus-gruppe dot de
                   ` (3 preceding siblings ...)
  2005-07-22 21:18 ` pinskia at gcc dot gnu dot org
@ 2005-09-27 16:25 ` mmitchel at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-09-27 16:25 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.2                       |4.0.3


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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-09-27 16:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-07 23:36 [Bug c++/19809] New: Multiple definitions of friend functions in template classes sstrasser at systemhaus-gruppe dot de
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

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).