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
8f8a1a02
Commit
8f8a1a02
authored
Jan 14, 2022
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of formattable types implicitly convertible to pointers
parent
b02e5af5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
include/fmt/core.h
include/fmt/core.h
+3
-2
test/core-test.cc
test/core-test.cc
+20
-1
No files found.
include/fmt/core.h
View file @
8f8a1a02
...
...
@@ -1398,10 +1398,11 @@ template <typename Context> struct arg_mapper {
template
<
typename
T
,
FMT_ENABLE_IF
(
std
::
is_member_pointer
<
T
>
::
value
||
std
::
is_
pointer
<
T
>
::
value
||
std
::
is_
member_pointer
<
T
>::
value
||
std
::
is_function
<
typename
std
::
remove_pointer
<
T
>::
type
>::
value
||
(
std
::
is_convertible
<
const
T
&
,
const
void
*>::
value
&&
!
std
::
is_convertible
<
const
T
&
,
const
char_type
*>::
value
))
>
!
std
::
is_convertible
<
const
T
&
,
const
char_type
*>::
value
&&
!
has_formatter
<
T
,
Context
>::
value
))
>
FMT_CONSTEXPR
auto
map
(
const
T
&
)
->
unformattable_pointer
{
return
{};
}
...
...
test/core-test.cc
View file @
8f8a1a02
...
...
@@ -737,6 +737,24 @@ struct convertible_to_pointer {
operator
const
int
*
()
const
{
return
nullptr
;
}
};
struct
convertible_to_pointer_formattable
{
operator
const
int
*
()
const
{
return
nullptr
;
}
};
FMT_BEGIN_NAMESPACE
template
<
>
struct
formatter
<
convertible_to_pointer_formattable
>
{
auto
parse
(
format_parse_context
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
return
ctx
.
begin
();
}
auto
format
(
convertible_to_pointer_formattable
,
format_context
&
ctx
)
const
->
decltype
(
ctx
.
out
())
{
auto
test
=
string_view
(
"test"
);
return
std
::
copy_n
(
test
.
data
(),
test
.
size
(),
ctx
.
out
());
}
};
FMT_END_NAMESPACE
enum
class
test_scoped_enum
{};
TEST
(
core_test
,
is_formattable
)
{
...
...
@@ -770,11 +788,12 @@ TEST(core_test, is_formattable) {
#endif
static_assert
(
!
fmt
::
is_formattable
<
convertible_to_pointer
>::
value
,
""
);
const
auto
f
=
convertible_to_pointer_formattable
();
EXPECT_EQ
(
fmt
::
format
(
"{}"
,
f
),
"test"
);
static_assert
(
!
fmt
::
is_formattable
<
void
(
*
)()
>::
value
,
""
);
struct
s
;
static_assert
(
!
fmt
::
is_formattable
<
int
(
s
::*
)
>::
value
,
""
);
static_assert
(
!
fmt
::
is_formattable
<
int
(
s
::*
)()
>::
value
,
""
);
static_assert
(
!
fmt
::
is_formattable
<
test_scoped_enum
>::
value
,
""
);
...
...
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