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

--- Comment #3 from Guillaume Racicot <dev at gracicot dot com> ---
I was able to reproduce this failure in x86-64 too.

Seems like with those change the frontend think there's a dangling reference
both in ARM64 and x86, and GCC generate bad code for both architectures:
    #include <print>

    struct val_ref {
        int val = 42;
        int& ref = val;
    };

    struct wrapper {
        constexpr wrapper(): impl{} {}
        // wrapper(wrapper&&) = delete; // uncomment to fix issue
        val_ref impl{};
    };

    constexpr auto make_s() {
        return wrapper{};
    }

    constexpr int test() {
        auto s = make_s();
        std::println("{}", s.impl.ref); // prints garbage
        return s.impl.ref;
    }

    //static_assert(test()); // uncomment for constexpr evaluator error

    int main() {
        return test() == 42 ? 0 : 1;
    }

Uncommenting the deleted move constructor fixes the code generation.

Compiler explorer link: https://godbolt.org/z/n57b1rbx1

Reply via email to