Bug 112908 (lwg3819) - __reference_{converts,constructs}_from_temporary checks for move constructor when binding prvalue to reference of the same type
Summary: __reference_{converts,constructs}_from_temporary checks for move constructor ...
Alias: lwg3819
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
Keywords: accepts-invalid, wrong-code
Depends on:
Reported: 2023-12-07 21:51 UTC by Mital Ashok
Modified: 2023-12-20 16:27 UTC (History)
4 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2023-12-20 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Mital Ashok 2023-12-07 21:51:58 UTC
The following compiles on trunk:

    struct NonMovable {
      NonMovable() = default;
      NonMovable(NonMovable&&) = delete;

    static_assert( __reference_converts_from_temporary(int&&, int));
    static_assert(!__reference_converts_from_temporary(NonMovable&&, NonMovable));
    static_assert( __reference_constructs_from_temporary(int&&, int));
    static_assert(!__reference_constructs_from_temporary(NonMovable&&, NonMovable));

When the NonMovable assertions should fail because there *is* a temporary being bound to a reference (in exactly the same way as the int case).

We can observe it instantiating constructors that shouldn't be too:

    template<typename T>
    struct S {
      template<typename U = T>
      S(const S&&) noexcept(U()) {}

    static_assert(__reference_converts_from_temporary(const S<bool>&&, const S<bool>));
    static_assert(__reference_converts_from_temporary(const S<void*>&&, const S<void*>));

Which complains about a conversion from void* to bool even though constructors shouldn't be looked at.
Comment 1 Patrick Palka 2023-12-20 16:13:36 UTC
This seems to be https://cplusplus.github.io/LWG/issue3819