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
dd97f492
Commit
dd97f492
authored
Mar 21, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve exception safety in dynamic_format_arg_store
parent
29511694
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
8 deletions
+33
-8
include/fmt/core.h
include/fmt/core.h
+6
-6
test/core-test.cc
test/core-test.cc
+27
-2
No files found.
include/fmt/core.h
View file @
dd97f492
...
@@ -284,7 +284,7 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
...
@@ -284,7 +284,7 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line,
#ifndef FMT_ASSERT
#ifndef FMT_ASSERT
# ifdef NDEBUG
# ifdef NDEBUG
// FMT_ASSERT is not empty to avoid -Werror=empty-body.
// FMT_ASSERT is not empty to avoid -Werror=empty-body.
# define FMT_ASSERT(condition, message) ((void)0)
# define FMT_ASSERT(condition, message) ((void)0)
# else
# else
# define FMT_ASSERT(condition, message) \
# define FMT_ASSERT(condition, message) \
...
@@ -1236,11 +1236,11 @@ class dynamic_arg_list {
...
@@ -1236,11 +1236,11 @@ class dynamic_arg_list {
public:
public:
template
<
typename
T
,
typename
Arg
>
const
T
&
push
(
const
Arg
&
arg
)
{
template
<
typename
T
,
typename
Arg
>
const
T
&
push
(
const
Arg
&
arg
)
{
auto
n
ext
=
std
::
move
(
head_
);
auto
n
ode
=
std
::
unique_ptr
<
typed_node
<
T
>>
(
new
typed_node
<
T
>
(
arg
)
);
auto
node
=
new
typed_node
<
T
>
(
arg
)
;
auto
&
value
=
node
->
value
;
head_
.
reset
(
node
);
node
->
next
=
std
::
move
(
head_
);
head_
->
next
=
std
::
move
(
next
);
head_
=
std
::
move
(
node
);
return
node
->
value
;
return
value
;
}
}
};
};
}
// namespace internal
}
// namespace internal
...
...
test/core-test.cc
View file @
dd97f492
...
@@ -435,8 +435,7 @@ template <> struct formatter<custom_type> {
...
@@ -435,8 +435,7 @@ template <> struct formatter<custom_type> {
}
}
template
<
typename
FormatContext
>
template
<
typename
FormatContext
>
auto
format
(
const
custom_type
&
p
,
FormatContext
&
ctx
)
->
decltype
(
format_to
(
auto
format
(
const
custom_type
&
p
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
ctx
.
out
(),
std
::
declval
<
typename
FormatContext
::
char_type
const
*>
()))
{
return
format_to
(
ctx
.
out
(),
"cust={}"
,
p
.
i
);
return
format_to
(
ctx
.
out
(),
"cust={}"
,
p
.
i
);
}
}
};
};
...
@@ -478,6 +477,32 @@ TEST(FormatDynArgsTest, NamedArgByRef) {
...
@@ -478,6 +477,32 @@ TEST(FormatDynArgsTest, NamedArgByRef) {
EXPECT_EQ
(
"42"
,
result
);
EXPECT_EQ
(
"42"
,
result
);
}
}
struct
copy_throwable
{
copy_throwable
()
{}
copy_throwable
(
const
copy_throwable
&
)
{
throw
"deal with it"
;
}
};
FMT_BEGIN_NAMESPACE
template
<
>
struct
formatter
<
copy_throwable
>
{
auto
parse
(
format_parse_context
&
ctx
)
const
->
decltype
(
ctx
.
begin
())
{
return
ctx
.
begin
();
}
auto
format
(
copy_throwable
,
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
ctx
.
out
();
}
};
FMT_END_NAMESPACE
TEST
(
FormatDynArgsTest
,
ThrowOnCopy
)
{
fmt
::
dynamic_format_arg_store
<
fmt
::
format_context
>
store
;
store
.
push_back
(
std
::
string
(
"foo"
));
try
{
store
.
push_back
(
copy_throwable
());
}
catch
(...)
{
}
EXPECT_EQ
(
fmt
::
vformat
(
"{}"
,
store
),
"foo"
);
}
TEST
(
StringViewTest
,
ValueType
)
{
TEST
(
StringViewTest
,
ValueType
)
{
static_assert
(
std
::
is_same
<
string_view
::
value_type
,
char
>::
value
,
""
);
static_assert
(
std
::
is_same
<
string_view
::
value_type
,
char
>::
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