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

--- Comment #8 from Barry Revzin <barry.revzin at gmail dot com> ---
This is the workaround I've been able to come up with so far
(https://compiler-explorer.com/z/Mn6xe8Tvx):

struct Empty {};

inline void not_constexpr() {}

struct S {
    Empty e;            // also [[no_unique_address]] Empty e; or struct S :
Empty
    union {
        int i;
        int big[32];
    };

    constexpr S() : i(5) {
#ifdef NO_FOLD
        if (!__builtin_is_constant_evaluated()) {
            not_constexpr();
        }
#endif
    }
};

S f() { return S(); }

constexpr S c;  // still a constant expression

Basically preventing gcc from constant-folding which leads to the extra
zeroing.

Reply via email to