fix universal: fix ForwardLike in C++23 to behave same as std::forwad_like#1246
Open
emikg777 wants to merge 1 commit into
Open
fix universal: fix ForwardLike in C++23 to behave same as std::forwad_like#1246emikg777 wants to merge 1 commit into
emikg777 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
utils::ForwardLikeusedreturn x;for the non-const lvalue-like case.This no longer matches
std::forward_likein C++23. Since P2266R3 ("Simpler implicit move"), the C++23 return statement rules treat a move-eligible returned expression as an xvalue. In standard wording this is the return statement wording in[stmt.return]: if the returned expression is move-eligible, it is treated as an xvalue.std::forward_like<T>still has to preserve the reference category requested byT&&, soForwardLike<int&>(...)must produce an lvalue reference.The existing
forward_like_test.cppfails with gcc 15.2.0:This change implements
ForwardLikevia explicit casts to the expected reference type instead of relying onreturn x,std::move, orstd::as_const.Here is minimal demonsration of difference between original ForwardLike and std::forward_like in C++23:
https://godbolt.org/z/s7WdxYaWe
The implementation now:
constfromTto the returned reference type;T&&to decide whether the result should be an lvalue reference or an rvalue reference;std::forward_likesemantics.Testing:
CMAKE_CXX_STANDARD=23.userver-universal-unittest.userver-universal-unittestrun: 1671/1672 tests passed. The only failure wasLogFilepath.UserverCroppedCorrectly, which appears to be path-layout-sensitive when userver is built as a CPM dependency under_deps/userver-src.