-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add test coverage for P2445R1 (std::forward_like
)
#3072
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 0 additions & 72 deletions
72
tests/std/tests/P2445R1_forward_like/test.compile.pass.cpp
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <cassert> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
using namespace std; | ||
|
||
struct U {}; // class type so const-qualification is not stripped from a prvalue | ||
using CU = const U; | ||
using T = int; | ||
using CT = const T; | ||
|
||
U u{}; | ||
const U& cu = u; | ||
|
||
static_assert(is_same_v<decltype(forward_like<T>(U{})), U&&>); | ||
static_assert(is_same_v<decltype(forward_like<T>(CU{})), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<T>(u)), U&&>); | ||
static_assert(is_same_v<decltype(forward_like<T>(cu)), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<T>(std::move(u))), U&&>); | ||
static_assert(is_same_v<decltype(forward_like<T>(std::move(cu))), CU&&>); | ||
|
||
static_assert(is_same_v<decltype(forward_like<CT>(U{})), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT>(CU{})), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT>(u)), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT>(cu)), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT>(std::move(u))), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT>(std::move(cu))), CU&&>); | ||
|
||
static_assert(is_same_v<decltype(forward_like<T&>(U{})), U&>); | ||
static_assert(is_same_v<decltype(forward_like<T&>(CU{})), CU&>); | ||
static_assert(is_same_v<decltype(forward_like<T&>(u)), U&>); | ||
static_assert(is_same_v<decltype(forward_like<T&>(cu)), CU&>); | ||
static_assert(is_same_v<decltype(forward_like<T&>(std::move(u))), U&>); | ||
static_assert(is_same_v<decltype(forward_like<T&>(std::move(cu))), CU&>); | ||
|
||
static_assert(is_same_v<decltype(forward_like<CT&>(U{})), CU&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&>(CU{})), CU&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&>(u)), CU&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&>(cu)), CU&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&>(std::move(u))), CU&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&>(std::move(cu))), CU&>); | ||
|
||
static_assert(is_same_v<decltype(forward_like<T&&>(U{})), U&&>); | ||
static_assert(is_same_v<decltype(forward_like<T&&>(CU{})), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<T&&>(u)), U&&>); | ||
static_assert(is_same_v<decltype(forward_like<T&&>(cu)), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<T&&>(std::move(u))), U&&>); | ||
static_assert(is_same_v<decltype(forward_like<T&&>(std::move(cu))), CU&&>); | ||
|
||
static_assert(is_same_v<decltype(forward_like<CT&&>(U{})), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&&>(CU{})), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&&>(u)), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&&>(cu)), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&&>(std::move(u))), CU&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&&>(std::move(cu))), CU&&>); | ||
|
||
static_assert(noexcept(forward_like<T>(u))); | ||
|
||
static_assert(is_same_v<decltype(forward_like<U&>(u)), U&>); | ||
static_assert(is_same_v<decltype(forward_like<CU&>(cu)), CU&>); | ||
static_assert(is_same_v<decltype(forward_like<U&&>(std::move(u))), U&&>); | ||
static_assert(is_same_v<decltype(forward_like<CU&&>(std::move(cu))), CU&&>); | ||
|
||
struct NoCtorCopyMove { | ||
NoCtorCopyMove() = delete; | ||
NoCtorCopyMove(const NoCtorCopyMove&) = delete; | ||
NoCtorCopyMove(NoCtorCopyMove&&) = delete; | ||
}; | ||
|
||
static_assert(is_same_v<decltype(forward_like<CT&&>(declval<NoCtorCopyMove>())), const NoCtorCopyMove&&>); | ||
static_assert(is_same_v<decltype(forward_like<CT&>(declval<NoCtorCopyMove>())), const NoCtorCopyMove&>); | ||
static_assert(is_same_v<decltype(forward_like<T&&>(declval<NoCtorCopyMove>())), NoCtorCopyMove&&>); | ||
static_assert(is_same_v<decltype(forward_like<T&>(declval<NoCtorCopyMove>())), NoCtorCopyMove&>); | ||
|
||
static_assert(noexcept(forward_like<T>(declval<NoCtorCopyMove>()))); | ||
|
||
constexpr bool test() { | ||
{ | ||
int val = 1729; | ||
auto&& result = forward_like<const double&>(val); | ||
static_assert(is_same_v<decltype(result), const int&>); | ||
assert(&result == &val); | ||
} | ||
{ | ||
int val = 1729; | ||
auto&& result = forward_like<double&>(val); | ||
static_assert(is_same_v<decltype(result), int&>); | ||
assert(&result == &val); | ||
} | ||
{ | ||
int val = 1729; | ||
auto&& result = forward_like<const double&&>(val); | ||
static_assert(is_same_v<decltype(result), const int&&>); | ||
assert(&result == &val); | ||
} | ||
{ | ||
int val = 1729; | ||
auto&& result = forward_like<double&&>(val); | ||
static_assert(is_same_v<decltype(result), int&&>); | ||
assert(&result == &val); | ||
} | ||
return true; | ||
} | ||
|
||
int main() { | ||
assert(test()); | ||
static_assert(test()); | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to other reviewers: I'm not requesting a comment clarifying why we qualify
std::move
throughout despiteusing namespace std
. Yes, it's unconventional, but I assume this usage will become widespread when we adopt Clang 15 with the new warning about usingmove
unqualified. (No change requested.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning might be obnoxious/widespread enough that we'll need to silence it in the matrices. (I'm not too worried about omitting
_STD
in product code, we're pretty good about that.) Still, no objections to doing this for now.