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
d940fa67
Commit
d940fa67
authored
May 19, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disable unsafe implicit conversion to std::string (#729)
parent
d2bf93fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
15 deletions
+13
-15
include/fmt/core.h
include/fmt/core.h
+3
-2
test/compile-test/CMakeLists.txt
test/compile-test/CMakeLists.txt
+9
-2
test/format-test.cc
test/format-test.cc
+0
-10
test/util-test.cc
test/util-test.cc
+1
-1
No files found.
include/fmt/core.h
View file @
d940fa67
...
...
@@ -629,8 +629,9 @@ inline typename std::enable_if<
template
<
typename
C
,
typename
T
,
typename
Char
=
typename
C
::
char_type
>
inline
typename
std
::
enable_if
<
!
convert_to_int
<
T
,
Char
>::
value
&&
!
std
::
is_convertible
<
T
,
basic_string_view
<
Char
>>::
value
&&
!
std
::
is_convertible
<
T
,
std
::
basic_string
<
Char
>>::
value
,
!
std
::
is_convertible
<
T
,
basic_string_view
<
Char
>>::
value
,
// Implicit conversion to std::string is not handled here because it's
// unsafe: https://github.com/fmtlib/fmt/issues/729
typed_value
<
C
,
custom_type
>>::
type
make_value
(
const
T
&
val
)
{
return
val
;
}
...
...
test/compile-test/CMakeLists.txt
View file @
d940fa67
...
...
@@ -9,8 +9,7 @@ set(CMAKE_REQUIRED_FLAGS ${CPP14_FLAG})
function
(
generate_source result fragment
)
set
(
${
result
}
"
#define FMT_HEADER_ONLY 1
#include
\"
fmt/posix.h
\"
#include
\"
fmt/ostream.h
\"
#include
\"
fmt/format.h
\"
int main() {
${
fragment
}
}
...
...
@@ -58,6 +57,14 @@ expect_compile_error("fmt::format(\"{}\", L\"foo\");")
# mixing UTF-8 with UTF-16/32 can result in an invalid output.
expect_compile_error
(
"fmt::format(L
\"
{}
\"
,
\"
foo
\"
);"
)
# Formatting a wide string with a narrow format string is forbidden.
expect_compile_error
(
"
struct S {
operator std::string() const { return std::string(); }
};
fmt::format(
\"
{}
\"
, S());
"
)
# Make sure that compiler features detected in the header
# match the features detected in CMake.
if
(
SUPPORTS_USER_DEFINED_LITERALS
)
...
...
test/format-test.cc
View file @
d940fa67
...
...
@@ -1072,16 +1072,6 @@ TEST(FormatterTest, FormatStdStringView) {
}
#endif
struct
ConvertibleToString
{
std
::
string
s
;
ConvertibleToString
()
:
s
(
"foo"
)
{}
operator
const
std
::
string
&
()
const
{
return
s
;
}
};
TEST
(
FormatterTest
,
FormatConvertibleToString
)
{
EXPECT_EQ
(
"foo"
,
format
(
"{}"
,
ConvertibleToString
()));
}
struct
ConvertibleToStringView
{
operator
fmt
::
string_view
()
const
{
return
"foo"
;
}
};
...
...
test/util-test.cc
View file @
d940fa67
...
...
@@ -402,7 +402,7 @@ TEST(UtilTest, BitCast) {
uint32_t
u
[
2
];
};
auto
s
=
fmt
::
internal
::
bit_cast
<
S
>
(
uint64_t
(
42
));
EXPECT_EQ
(
fmt
::
internal
::
bit_cast
<
uint64_t
>
(
s
),
42
);
EXPECT_EQ
(
fmt
::
internal
::
bit_cast
<
uint64_t
>
(
s
),
42
u
);
s
=
fmt
::
internal
::
bit_cast
<
S
>
(
uint64_t
(
~
0ull
));
EXPECT_EQ
(
fmt
::
internal
::
bit_cast
<
uint64_t
>
(
s
),
~
0ull
);
}
...
...
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