-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++][functional] Implement not_fn<NTTP>
#86133
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
Merged
ldionne
merged 12 commits into
llvm:main
from
JMazurkiewicz:libcxx/functional/nttp_not_fn
Jan 10, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
009bdc4
[libc++] Implement `not_fn<NTTP>`
JMazurkiewicz 7ea0b51
Move assertions to file scope
JMazurkiewicz 01540ec
Test more `not_fn`s for emptiness
JMazurkiewicz bdfe173
Add missing `[[nodiscard]]` test
JMazurkiewicz d92507c
the
JMazurkiewicz e045e2e
Add extra `noexcept` test
JMazurkiewicz e2587ff
Finish sentence
JMazurkiewicz 8029264
Merge branch 'main' into libcxx/functional/nttp_not_fn
JMazurkiewicz b6f90c9
Fix ASAN/TSAN/UBSAN/MSAN CI
JMazurkiewicz 2815e3d
Merge branch 'main' into libcxx/functional/nttp_not_fn
JMazurkiewicz 9d8c65b
Merge branch 'main' into libcxx/functional/nttp_not_fn
JMazurkiewicz 17eb8e1
Merge branch 'main' into libcxx/functional/nttp_not_fn
JMazurkiewicz 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
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
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
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
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
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
43 changes: 43 additions & 0 deletions
43
libcxx/test/libcxx/utilities/function.objects/func.not.fn/not_fn.nttp.compile.pass.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 | ||
|
|
||
| // <functional> | ||
|
|
||
| // Type of `std::not_fn<NTTP>()` is always empty. | ||
|
|
||
| #include <functional> | ||
| #include <type_traits> | ||
|
|
||
| struct NonEmptyFunctionObject { | ||
| bool val = true; | ||
| bool operator()() const; | ||
| }; | ||
|
|
||
| bool func(); | ||
|
|
||
| struct SomeClass { | ||
| bool member_object; | ||
| bool member_function(); | ||
| }; | ||
|
|
||
| using ResultWithEmptyFuncObject = decltype(std::not_fn<std::false_type{}>()); | ||
| static_assert(std::is_empty_v<ResultWithEmptyFuncObject>); | ||
|
|
||
| using ResultWithNotEmptyFuncObject = decltype(std::not_fn<NonEmptyFunctionObject{}>()); | ||
| static_assert(std::is_empty_v<ResultWithNotEmptyFuncObject>); | ||
|
|
||
| using ResultWithFunctionPointer = decltype(std::not_fn<&func>()); | ||
| static_assert(std::is_empty_v<ResultWithFunctionPointer>); | ||
|
|
||
| using ResultWithMemberObjectPointer = decltype(std::not_fn<&SomeClass::member_object>()); | ||
| static_assert(std::is_empty_v<ResultWithMemberObjectPointer>); | ||
|
|
||
| using ResultWithMemberFunctionPointer = decltype(std::not_fn<&SomeClass::member_function>()); | ||
| static_assert(std::is_empty_v<ResultWithMemberFunctionPointer>); | ||
24 changes: 24 additions & 0 deletions
24
libcxx/test/libcxx/utilities/function.objects/func.not.fn/not_fn.nttp.nodiscard.verify.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 | ||
|
|
||
| // <functional> | ||
|
|
||
| // Test the libc++ extension that std::not_fn<NTTP> is marked as [[nodiscard]]. | ||
|
|
||
| #include <functional> | ||
| #include <type_traits> | ||
|
|
||
| void test() { | ||
| using F = std::true_type; | ||
| std::not_fn<F{}>(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
ldionne marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| auto negated = std::not_fn<F{}>(); | ||
| negated(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}} | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.