-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Implement P2905R2 Runtime Format Strings #4196
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
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cb0d2da
Implement P2905R2 Runtime Format Strings
frederick-vs-ja 0e24b20
Handle `/permissive`
frederick-vs-ja 4776a72
Merge branch 'main' into p2905r2
frederick-vs-ja 7bb56b5
Merge branch 'main' into p2905r2
StephanTLavavej 03c2b35
Code review feedback.
StephanTLavavej 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,7 +248,8 @@ void test_visit_monostate() { | |
|
|
||
| template <class Context> | ||
| void test_lwg3810() { | ||
| [[maybe_unused]] auto args_store = make_format_args<Context>(1, 2, 3); | ||
| int args[]{1, 2, 3}; | ||
| [[maybe_unused]] auto args_store = make_format_args<Context>(args[0], args[1], args[2]); | ||
| static_assert(same_as<decltype(basic_format_args{args_store}), basic_format_args<Context>>); | ||
| } | ||
|
|
||
|
|
@@ -264,6 +265,53 @@ void test_lvalue_only_visitation() { | |
| visit_format_arg(lvalue_only_visitor{}, basic_format_arg<Context>{}); | ||
| } | ||
|
|
||
| namespace detail { | ||
| constexpr bool permissive() { | ||
| return false; | ||
| } | ||
|
|
||
| template <class> | ||
| struct DependentBase { | ||
| static constexpr bool permissive() { | ||
| return true; | ||
| } | ||
| }; | ||
|
|
||
| template <class T> | ||
| struct Derived : DependentBase<T> { | ||
| static constexpr bool test() { | ||
| return permissive(); | ||
| } | ||
| }; | ||
| } // namespace detail | ||
| constexpr bool is_permissive = detail::Derived<int>::test(); | ||
|
|
||
| template <class Context, class... Args> | ||
| concept CanMakeFormatArgs = requires(Args&&... args) { make_format_args<Context>(static_cast<Args&&>(args)...); }; | ||
|
|
||
| // P2905R2 Runtime format strings (make make_(w)format_args only take lvalue references) | ||
| template <class Context> | ||
| void test_lvalue_reference_parameters() { // COMPILE-ONLY | ||
StephanTLavavej marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using char_type = Context::char_type; | ||
|
|
||
| static_assert(CanMakeFormatArgs<Context, int&, long long&, double&, char_type&, char_type*&, const char_type*&, | ||
| basic_string<char_type>&, basic_string_view<char_type>&>); | ||
| static_assert( | ||
| CanMakeFormatArgs<Context, const int&, const long long&, const double&, const char_type&, char_type* const&, | ||
| const char_type* const&, const basic_string<char_type>&, const basic_string_view<char_type>&>); | ||
|
|
||
| static_assert(CanMakeFormatArgs<Context, const int, const long long, const double, const char_type, | ||
| char_type* const, const char_type* const, const basic_string<char_type>, const basic_string_view<char_type>>); | ||
|
Comment on lines
+303
to
+304
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No change requested: The fact that const rvalues are accepted indicates a design problem with the paper. |
||
|
|
||
| static_assert(!CanMakeFormatArgs<Context, int>); | ||
| static_assert(!CanMakeFormatArgs<Context, long long>); | ||
| static_assert(!CanMakeFormatArgs<Context, double>); | ||
| static_assert(!CanMakeFormatArgs<Context, char_type>); | ||
| static_assert(!CanMakeFormatArgs<Context, const char_type*>); | ||
StephanTLavavej marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| static_assert(CanMakeFormatArgs<Context, basic_string<char_type>> == is_permissive); | ||
| static_assert(CanMakeFormatArgs<Context, basic_string_view<char_type>> == is_permissive); | ||
| } | ||
|
|
||
| int main() { | ||
| test_basic_format_arg<format_context>(); | ||
| test_basic_format_arg<wformat_context>(); | ||
|
|
@@ -277,4 +325,7 @@ int main() { | |
|
|
||
| test_lvalue_only_visitation<format_context>(); | ||
| test_lvalue_only_visitation<wformat_context>(); | ||
|
|
||
| test_lvalue_reference_parameters<format_context>(); | ||
| test_lvalue_reference_parameters<wformat_context>(); | ||
| } | ||
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
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.