Skip to content
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

[libc] Add invoke / invoke_result type traits #65750

Merged
merged 6 commits into from
Sep 15, 2023

Conversation

gchatelet
Copy link
Contributor

@gchatelet gchatelet commented Sep 8, 2023

@github-actions github-actions bot added the libc label Sep 8, 2023
@gchatelet gchatelet mentioned this pull request Sep 8, 2023
@gchatelet gchatelet changed the title [libc] add invoke_result type traits [libc] Add invoke_result type traits Sep 8, 2023
@gchatelet gchatelet requested review from legrosbuffle and removed request for legrosbuffle September 8, 2023 13:32
Copy link
Contributor

@legrosbuffle legrosbuffle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this comes mostly from existing implementations, but I can't easily wrap my head around this so I htink we should add a few tests for this...

gchatelet added a commit that referenced this pull request Sep 11, 2023
This is not exhaustive for now but it provides a placeholder for
`invoke_result` test mentioned in #65750.
@gchatelet gchatelet changed the title [libc] Add invoke_result type traits [libc] Add invoke / invoke_result type traits Sep 13, 2023
@gchatelet gchatelet marked this pull request as ready for review September 13, 2023 12:04
@gchatelet gchatelet requested a review from a team as a code owner September 13, 2023 12:04
libc/src/__support/CPP/type_traits/invoke.h Outdated Show resolved Hide resolved
libc/src/__support/CPP/type_traits/invoke.h Outdated Show resolved Hide resolved
libc/src/__support/CPP/type_traits/invoke.h Outdated Show resolved Hide resolved
libc/src/__support/CPP/type_traits/invoke.h Show resolved Hide resolved
libc/test/src/__support/CPP/type_traits_test.cpp Outdated Show resolved Hide resolved
libc/test/src/__support/CPP/type_traits_test.cpp Outdated Show resolved Hide resolved
auto lambda = [](int) -> double { return 0; };
EXPECT_TRUE((is_same_v<invoke_result_t<decltype(lambda), int>, double>));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're missing tests for a functor with overloaded types:

auto lambda = [](auto a) { return a; };
EXPECT_TRUE((is_same_v<invoke_result_t<decltype(lambda), int>, int>));
EXPECT_TRUE((is_same_v<invoke_result_t<decltype(lambda), double>, double>));

maybe also with auto& and auto&&.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx! This helped me catch a bug where the function return type should be decltype(auto) instead of auto for perfect forwarding.

@gchatelet
Copy link
Contributor Author

Thx for the thorough review @legrosbuffle, I really appreciate it.

@gchatelet gchatelet merged commit 2dbdc9f into llvm:main Sep 15, 2023
2 checks passed
@gchatelet gchatelet deleted the invoke_result branch September 15, 2023 12:52
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
This is not exhaustive for now but it provides a placeholder for
`invoke_result` test mentioned in llvm#65750.
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants