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

            Bug ID: 108364
           Summary: Construction from prvalue erroneously uses
                    move-constructor
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fchelnokov at gmail dot com
  Target Milestone: ---

In the following code Bar default-constructor initializes its unmovable parent
Foo using a conversion operator creating a prvalue:

struct Foo {
    Foo() = default;
    Foo(Foo const&) = delete;
    Foo(Foo&&) = delete;
};

Foo foo() { return {}; }

template<typename F>
struct call_wrapper {
    F&& f;

    constexpr operator decltype(auto)() && {
        return static_cast<F&&>(f)();
    }
};
template<typename F>
call_wrapper(F&&) -> call_wrapper<F>;

struct Bar : Foo {
    Bar() : Foo(call_wrapper{foo}) {}
};

It works in Clang and MSVC, but unfortunately not in GCC, which prints
error: use of deleted function 'Foo::Foo(Foo&&)

Online demo: https://gcc.godbolt.org/z/3Wfdfb36a

This type of object construction was recommended in
https://stackoverflow.com/a/75068264/7325599

Reply via email to