llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang 13 to trunk accepts implicit move of parameters in C++17 and no feature flag set

Open beached opened this issue 1 year ago • 6 comments

The following code is not an error in clang but isn't valid to my knowledge.

template <typename Pointer, typename F>
constexpr auto or_else(Pointer &&p, F &&f) -> remove_cvref_t<Pointer> {
    if (not p) {
        return FWD(f)( );
    }
    return std::move( p );  // not needed in clang 13+
}

std::unique_ptr<int> foo(std::unique_ptr<int> p) {
    return or_else(std::move(p), [] { return std::make_unique<int>(42); });
}

https://gcc.godbolt.org/z/TzWf6Eqov

The move on p isn't required as of clang-13 while compiled with -std=c++17 -pedantic -pedantic-errors. ~~The macro __cpp_implicit_move isn't defined either.~~

beached avatar Jan 12 '25 18:01 beached

but isn't valid

any arguments?

safocl avatar Jan 12 '25 18:01 safocl

std::unique_ptr<int> example(std::unique_ptr<int> && param) {
    return param; // should require move in 17, not 20
}

Better example. Just trying to find the language as this is pre-implicitly movable types

beached avatar Jan 12 '25 19:01 beached

This is what p0527 and subsequently p1825 fixed in C++20 but the example 2 was explicitly in p0527 as IF in C++17

beached avatar Jan 12 '25 19:01 beached

This is what p0527 and subsequently p1825 fixed in C++20 but the example 2 was explicitly in p0527 as IF in C++17

P1825 was applied as a DR in this commit.

MagentaTreehouse avatar Jan 12 '25 19:01 MagentaTreehouse

Thanks. I didn't realize that or see that in the 13 notes.

I get the desire to apply these to <C++20 but it does make it frustrating when all the compilers don't agree on applying it :)

beached avatar Jan 12 '25 19:01 beached

@llvm/issue-subscribers-clang-frontend

Author: beached (beached)

The following code is not an error in clang but isn't valid to my knowledge.
template &lt;typename Pointer, typename F&gt;
constexpr auto or_else(Pointer &amp;&amp;p, F &amp;&amp;f) -&gt; remove_cvref_t&lt;Pointer&gt; {
    if (not p) {
        return FWD(f)( );
    }
    return std::move( p );  // not needed in clang 13+
}

std::unique_ptr&lt;int&gt; foo(std::unique_ptr&lt;int&gt; p) {
    return or_else(std::move(p), [] { return std::make_unique&lt;int&gt;(42); });
}

https://gcc.godbolt.org/z/TzWf6Eqov

The move on p isn't required as of clang-13 while compiled with -std=c++17 -pedantic -pedantic-errors. ~~The macro __cpp_implicit_move isn't defined either.~~

llvmbot avatar Jan 13 '25 01:01 llvmbot