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

--- Comment #13 from Louis Dionne <ldionne.2 at gmail dot com> ---
Actually, the problem is much worse than I thought. It turns out that with -O1,
the following code does not pass the assertion:

    #include <cassert>

    template <typename Xn>
    struct tuple {
        Xn storage_;

        constexpr tuple(Xn const& xn)
            : storage_(xn)
        { }

        template <typename ...dummy>
        constexpr tuple(tuple const& other)
            : storage_(other.storage_)
        { }

        template <typename ...dummy>
        constexpr tuple(tuple& other)
            : tuple(const_cast<tuple const&>(other))
        { }
    };

    template <typename T>
    struct wrapper { T value; };

    template <typename T>
    constexpr wrapper<T> wrap(T t) { return {t}; }

    int main() {
        wrapper<tuple<int>> t = wrap(tuple<int>{2});
        assert(t.value.storage_ == 2);
    }


Live example: http://melpon.org/wandbox/permlink/nRGrPcbvqYWhzCDt

This is the same code as above, except the `t` variable is not constexpr
anymore.
This seems like a case of invalid codegen. If I make the `wrap` function
non-constexpr,
the problem goes away. Should I create a separate bug report for this?

Reply via email to