[Bug c++/94184] New: Global variable inline constructor elision.

maxim.yegorushkin at gmail dot com gcc-bugzilla@gcc.gnu.org
Sun Mar 15 19:36:21 GMT 2020


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

            Bug ID: 94184
           Summary: Global variable inline constructor elision.
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maxim.yegorushkin at gmail dot com
  Target Milestone: ---

The following code:

    struct A { 
        int a_; 
        A(int a) : a_(a) {}
    };

    struct B { 
        int a_; 
        constexpr B(int a) : a_(a) {}
    };

    A a{1};
    B b{1};

When compiled with `gcc-9.2 -O3 -march=skylake -mtune=skylake -std=gnu++17`
generates a call to `A` constructor for variable `a`:

    _GLOBAL__sub_I_a:
        mov    DWORD PTR [rip+0x200bd6],0x1        # 601030 <__TMC_END__>
        ret    

And no call for `B` constructor for variable `b`, as expected of `constexpr`.

`clang-9.0 -O3 -march=skylake -mtune=skylake -std=gnu++17`, however, elides the
constructor calls for both `a` and `b` global variables, regardless of
`constexpr`.

Why can't `gcc` elide the call to `A` constructor for `a`, since `A` constuctor
is an inline function with a clear side-effect?

https://gcc.godbolt.org/z/5y3cD5


More information about the Gcc-bugs mailing list