[Bug c++/12370] New: [3.4 regression] wrong code involving friends

reichelt at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Mon Sep 22 21:28:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: [3.4 regression] wrong code involving friends
           Product: gcc
           Version: 3.4
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: critical
          Priority: P1
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,rth at redhat dot com
  GCC host triplet: i686-pc-linux-gnu

The following code snippet miscompiles with mainline on i686-pc-linux-gnu:

=====================================================================
template <typename T> struct A
{
    T x;
    A(T t) : x(t) {}
    friend A<int> foo (const A<unsigned>&);
};

A<int> foo (const A<unsigned>& a) { A<int> res(a.x); return res; }

int main()
{
    return foo(A<unsigned>(0)).x;
}
=====================================================================

It should return "0" but returns "16" instead.
If I delete the friend declaration, the code compiles fine.

This regression was introduced between 2003-08-29 22:00 and 23:30.

Richard, there were 5 commits from you in this timeframe

  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00940.html
  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00942.html
  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00943.html
  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00945.html
  http://gcc.gnu.org/ml/gcc-cvs/2003-08/msg00947.html

and one from Mark (which is about labels and shouldn't be the problem here).
Could you please have a look?

Thanks,
Volker



More information about the Gcc-bugs mailing list