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

            Bug ID: 69327
           Summary: constexpr leaves reference member var uninitialized
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

With recent trunk GCC,

> $ cat test.cc
> struct S {
>     constexpr S(int & x): n(x) {}
>     int & n;
> };
> constexpr S f1(int & x) { return S(x); }
> constexpr S f2(int & x) { return f1(x); }
> S f3(int & x) { return f2(x); }
> int main() {
>     int n = 1;
>     return f3(n).n;
> }

> $ g++ test.cc && ./a.out
> Segmentation fault

typically causes a SEGV, as S::n remains uninitialized; x86-64 code generated
for f3 is

> 0000000000000000 <_Z2f3Ri>:
>    0:   55                      push   %rbp
>    1:   48 89 e5                mov    %rsp,%rbp
>    4:   48 89 7d e8             mov    %rdi,-0x18(%rbp)
>    8:   48 8b 45 f8             mov    -0x8(%rbp),%rax
>    c:   5d                      pop    %rbp
>    d:   c3                      retq

This is a stripped-down version of code in boost::fusion (calling
boost::fusion::begin on a boost::fusion::cons, as used by boost::spirit, in
turn used by libetonyek and LibreOffice), causing LibreOffice to fail.

Reply via email to