Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
1e849319
Commit
1e849319
authored
Mar 01, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make compile-time checks in format_to handle references
parent
58e6c84f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
5 deletions
+6
-5
include/fmt/core.h
include/fmt/core.h
+1
-1
include/fmt/format.h
include/fmt/format.h
+3
-4
test/format-test.cc
test/format-test.cc
+2
-0
No files found.
include/fmt/core.h
View file @
1e849319
...
@@ -1460,7 +1460,7 @@ make_args_checked(const S& format_str,
...
@@ -1460,7 +1460,7 @@ make_args_checked(const S& format_str,
all_true
<
(
!
std
::
is_base_of
<
view
,
remove_reference_t
<
Args
>>::
value
||
all_true
<
(
!
std
::
is_base_of
<
view
,
remove_reference_t
<
Args
>>::
value
||
!
std
::
is_reference
<
Args
>::
value
)...
>::
value
,
!
std
::
is_reference
<
Args
>::
value
)...
>::
value
,
"passing views as lvalues is disallowed"
);
"passing views as lvalues is disallowed"
);
check_format_string
<
remove_const_t
<
remove_reference_t
<
Args
>>
...
>
(
format_str
);
check_format_string
<
Args
...
>
(
format_str
);
return
{
args
...};
return
{
args
...};
}
}
...
...
include/fmt/format.h
View file @
1e849319
...
@@ -2641,10 +2641,9 @@ FMT_CONSTEXPR bool do_check_format_string(basic_string_view<Char> s,
...
@@ -2641,10 +2641,9 @@ FMT_CONSTEXPR bool do_check_format_string(basic_string_view<Char> s,
template
<
typename
...
Args
,
typename
S
,
template
<
typename
...
Args
,
typename
S
,
enable_if_t
<
(
is_compile_string
<
S
>
::
value
),
int
>>
enable_if_t
<
(
is_compile_string
<
S
>
::
value
),
int
>>
void
check_format_string
(
S
format_str
)
{
void
check_format_string
(
S
format_str
)
{
FMT_CONSTEXPR_DECL
bool
invalid_format
=
FMT_CONSTEXPR_DECL
bool
invalid_format
=
internal
::
do_check_format_string
<
internal
::
do_check_format_string
<
typename
S
::
char_type
,
typename
S
::
char_type
,
internal
::
error_handler
,
internal
::
error_handler
,
Args
...
>
(
remove_const_t
<
remove_reference_t
<
Args
>>
...
>
(
to_string_view
(
format_str
));
to_string_view
(
format_str
));
(
void
)
invalid_format
;
(
void
)
invalid_format
;
}
}
...
...
test/format-test.cc
View file @
1e849319
...
@@ -1859,6 +1859,8 @@ TEST(FormatTest, CustomFormatCompileTimeString) {
...
@@ -1859,6 +1859,8 @@ TEST(FormatTest, CustomFormatCompileTimeString) {
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_STRING
(
"{}"
),
Answer
()));
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_STRING
(
"{}"
),
Answer
()));
Answer
answer
;
Answer
answer
;
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_STRING
(
"{}"
),
answer
));
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_STRING
(
"{}"
),
answer
));
char
buf
[
10
]
=
{};
fmt
::
format_to
(
buf
,
FMT_STRING
(
"{}"
),
answer
);
const
Answer
const_answer
=
Answer
();
const
Answer
const_answer
=
Answer
();
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_STRING
(
"{}"
),
const_answer
));
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_STRING
(
"{}"
),
const_answer
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment