The following program yields a segmentation fault in cc1plus when being
compiled with any optimization option -O.

If the argument in TestClass::f() is replaced either by a "const int" or an
"unsigned int", the program can indeed be compiled.
Moreover, if the ?-operator construct is replaced by, say, c[g(i)],
where g is another method, then the code is also compileable.
So the entire problem results from composing a ?-operator construct based on a
"const unsigned int" method parameter with a successive array access.


The program source code:

class TestClass {
public:
  TestClass() {
    c[0] = 1;
    c[1] = 2;
  }

  int f(const unsigned int i) {
    return c[(i==1) ? 1 : 0];
  }

  int c[2];
};

int main()
{
  TestClass c;
  int x = c.f(1);

  return 0;
}


output when compiling with "g++ -O2 bug.cpp -o bug.o":

bug.cpp: In function `int main()':
bug.cpp:18: warning: unused variable 'x'
g++: Internal error: Segmentation fault (program cc1plus)
Please submit a full bug report.
See <URL:http://bugzilla.redhat.com/bugzilla> for instructions.

Release: (output of "g++ -v")
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.3 20050227 (Red Hat 3.4.3-22.1)

Environment:
(Red Hat) Linux 2.6.9-11, i686 pc


-- 
           Summary: segmentation fault in cc1plus when compiling with -O
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: raasch at mathematik dot uni-marburg dot de
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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

Reply via email to