https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64112

            Bug ID: 64112
           Summary: Optimized away string literal leads to a core dump
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: regression
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fhansen at rocketmail dot com

The following program prints "str" when compiled without optimizations but core
dumps when compiled with GCC 4.8.0 and optimization level -O2.

The compilation command used: g++ -O2 test.cpp

#include <cstdio>

class X {
public:
  X(const char* str) : str_(str) {}
  const char* str_;
};

class Y {
public:
  Y(const X& x) : x_(x) {}
  void print() const { printf("%s\n", x_.str_); }

private:
  const X& x_;
};

int main() {
  Y y("str");
  y.print();
}

This appears to be a regression in 4.8.

Version and target:
g++ (GCC) 4.8.0
i686-pc-linux-gnu

Reply via email to