This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/104: Re: C++ optimization error
- To: gcc-gnats at sourceware dot cygnus dot com
- Subject: c++/104: Re: C++ optimization error
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Mon, 13 Mar 2000 09:56:07 +0100
- References: <199908112204.AAA01573@poekie.test>
- Resent-Cc: gcc-prs at gcc dot gnu dot org, m dot j dot s dot vandoesburg at student dot utwente dot nl
- Resent-Reply-To: gcc-gnats@gcc.gnu.org, "Martin v. Loewis" <martin@loewis.home.cs.tu-berlin.de>
>Number: 104
>Category: c++
>Synopsis: C++ optimization error
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: analyzed
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon Mar 13 01:05:59 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Mark van Doesburg <m.j.s.vandoesburg@student.utwente.nl>
>Release: 2.95.2
>Organization:
>Environment:
>Description:
Date: Thu, 12 Aug 1999 00:04:25 +0200
Original-Message-Id: <199908112204.AAA01573@poekie.test>
The attached program compiles correctly without optimization. With
optimizations the resulting a.out gives a segmentation fault.
System:
i586-pc-linux-gnulibc1, AMD k6-2, linux-2.2.11, libc-5.4.46
gcc:
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnulibc1/2.95.1/specs
gcc version 2.95.1 19990809 (prerelease)
(It also happens in gcc-2.95)
Correct options: gcc test.ii
Error options: gcc -O test.ii
greetings,
Mark.
---- original program ----------------------------------------------------
#include <matrix.h>
main()
{
matrix<fract,3> M; // when fract is changed to double
// a.out doesn't core dump with -O
M[0][0]=M[1][1]=M[2][2]=1;
M[0][1]=M[0][2]=M[1][0]=M[1][2]=M[2][0]=M[2][1]=0;
}
[MvL: The original report had a large preprocessor output attached, below
is a simplified version that still generates wrong code in 2.96 20000309]
>How-To-Repeat:
class fract {
int d;
public:
fract &operator=(fract f) { d=f.d; }
fract &operator=(int f) { d=f; }
};
template<class T,int S>
class coord {
T c[S];
public:
T &operator[](int i) { return c[i]; }
};
main()
{
coord<fract,2> M;
M[0]=M[1]=1;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: