c++/9769: compiles wrong code but executable SEGV with -freg-struct-return
jbakker@rssd.esa.int
jbakker@rssd.esa.int
Thu Feb 20 10:06:00 GMT 2003
>Number: 9769
>Category: c++
>Synopsis: compiles wrong code but executable SEGV with -freg-struct-return
>Confidential: no
>Severity: critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Feb 20 10:06:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Jorgo Bakker
>Release: gcc version 3.2.2
>Organization:
>Environment:
Reading specs from /usr/local/devel/gcc-3.2.2/lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/specs
Configured with: ../gcc-3.2.2/configure --prefix=/usr/local/devel/gcc-3.2.2 --with-gnu-as --with-as=/usr/local/bin/as --with-gnu-ld --with-ld=/usr/local/bin/ld --enable-languages=c,c++,f77
Thread model: posix
gcc version 3.2.2
>Description:
Compiling (wrong? operator+(const char*, std::string) ) code, make sthe resulting executable seg.fault, if
the "-freg-struct-return" is given without optimization.
With optimization (-O2), things work.
>How-To-Repeat:
$ cat > bug.cc
// -*-C++-*-
// File: bug.cc
// Author: Jorgo Bakker (jbakker@rssd.esa.int)
// Generated: Thu Feb 20 09:53:50 MET 2003
#include<string>
#include<iostream>
int main() {
std::string s("This is my life");
std::cout << "*** " << s << std::endl; // ok
std::cout << "*** " + s << std::endl; // seg fault
return 0;
}
^D
$c++ -freg-struct-return bug.cc -o bug
$./bug
*** This is my life
Abort (core dumped)
>Fix:
- Compiler should bail out on: "*** " + s
or
- Behavior should be the same with/without -freg-struct-return
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list