clang 13 to trunk accepts implicit move of parameters in C++17 and no feature flag set
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.~~
but isn't valid
any arguments?
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
This is what p0527 and subsequently p1825 fixed in C++20 but the example 2 was explicitly in p0527 as IF in C++17
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.
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 :)
@llvm/issue-subscribers-clang-frontend
Author: beached (beached)
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.~~