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
3f778b20
Commit
3f778b20
authored
Jul 12, 2016
by
Victor Zverovich
Committed by
Jonathan Müller
Oct 23, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check -> const_check to avoid a conflict with AssertMacros.h (#350)
(cherry picked from commit
86316940
)
parent
27f604a1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
15 deletions
+16
-15
fmt/format.h
fmt/format.h
+9
-9
test/format-test.cc
test/format-test.cc
+2
-2
test/printf-test.cc
test/printf-test.cc
+5
-4
No files found.
fmt/format.h
View file @
3f778b20
...
@@ -309,7 +309,7 @@ inline DummyInt _isnan(...) { return DummyInt(); }
...
@@ -309,7 +309,7 @@ inline DummyInt _isnan(...) { return DummyInt(); }
// A helper function to suppress bogus "conditional expression is constant"
// A helper function to suppress bogus "conditional expression is constant"
// warnings.
// warnings.
template
<
typename
T
>
template
<
typename
T
>
inline
T
check
(
T
value
)
{
return
value
;
}
inline
T
c
onst_c
heck
(
T
value
)
{
return
value
;
}
}
}
}
// namespace fmt
}
// namespace fmt
...
@@ -328,7 +328,7 @@ class numeric_limits<fmt::internal::DummyInt> :
...
@@ -328,7 +328,7 @@ class numeric_limits<fmt::internal::DummyInt> :
using
namespace
fmt
::
internal
;
using
namespace
fmt
::
internal
;
// The resolution "priority" is:
// The resolution "priority" is:
// isinf macro > std::isinf > ::isinf > fmt::internal::isinf
// isinf macro > std::isinf > ::isinf > fmt::internal::isinf
if
(
check
(
sizeof
(
isinf
(
x
))
==
sizeof
(
bool
)
||
if
(
c
onst_c
heck
(
sizeof
(
isinf
(
x
))
==
sizeof
(
bool
)
||
sizeof
(
isinf
(
x
))
==
sizeof
(
int
)))
{
sizeof
(
isinf
(
x
))
==
sizeof
(
int
)))
{
return
isinf
(
x
)
!=
0
;
return
isinf
(
x
)
!=
0
;
}
}
...
@@ -339,7 +339,7 @@ class numeric_limits<fmt::internal::DummyInt> :
...
@@ -339,7 +339,7 @@ class numeric_limits<fmt::internal::DummyInt> :
template
<
typename
T
>
template
<
typename
T
>
static
bool
isnotanumber
(
T
x
)
{
static
bool
isnotanumber
(
T
x
)
{
using
namespace
fmt
::
internal
;
using
namespace
fmt
::
internal
;
if
(
check
(
sizeof
(
isnan
(
x
))
==
sizeof
(
bool
)
||
if
(
c
onst_c
heck
(
sizeof
(
isnan
(
x
))
==
sizeof
(
bool
)
||
sizeof
(
isnan
(
x
))
==
sizeof
(
int
)))
{
sizeof
(
isnan
(
x
))
==
sizeof
(
int
)))
{
return
isnan
(
x
)
!=
0
;
return
isnan
(
x
)
!=
0
;
}
}
...
@@ -349,7 +349,7 @@ class numeric_limits<fmt::internal::DummyInt> :
...
@@ -349,7 +349,7 @@ class numeric_limits<fmt::internal::DummyInt> :
// Portable version of signbit.
// Portable version of signbit.
static
bool
isnegative
(
double
x
)
{
static
bool
isnegative
(
double
x
)
{
using
namespace
fmt
::
internal
;
using
namespace
fmt
::
internal
;
if
(
check
(
sizeof
(
signbit
(
x
))
==
sizeof
(
int
)))
if
(
c
onst_c
heck
(
sizeof
(
signbit
(
x
))
==
sizeof
(
int
)))
return
signbit
(
x
)
!=
0
;
return
signbit
(
x
)
!=
0
;
if
(
x
<
0
)
return
true
;
if
(
x
<
0
)
return
true
;
if
(
!
isnotanumber
(
x
))
return
false
;
if
(
!
isnotanumber
(
x
))
return
false
;
...
@@ -1203,7 +1203,7 @@ class MakeValue : public Arg {
...
@@ -1203,7 +1203,7 @@ class MakeValue : public Arg {
MakeValue
(
long
value
)
{
MakeValue
(
long
value
)
{
// To minimize the number of types we need to deal with, long is
// To minimize the number of types we need to deal with, long is
// translated either to int or to long long depending on its size.
// translated either to int or to long long depending on its size.
if
(
check
(
sizeof
(
long
)
==
sizeof
(
int
)))
if
(
c
onst_c
heck
(
sizeof
(
long
)
==
sizeof
(
int
)))
int_value
=
static_cast
<
int
>
(
value
);
int_value
=
static_cast
<
int
>
(
value
);
else
else
long_long_value
=
value
;
long_long_value
=
value
;
...
@@ -1213,7 +1213,7 @@ class MakeValue : public Arg {
...
@@ -1213,7 +1213,7 @@ class MakeValue : public Arg {
}
}
MakeValue
(
unsigned
long
value
)
{
MakeValue
(
unsigned
long
value
)
{
if
(
check
(
sizeof
(
unsigned
long
)
==
sizeof
(
unsigned
)))
if
(
c
onst_c
heck
(
sizeof
(
unsigned
long
)
==
sizeof
(
unsigned
)))
uint_value
=
static_cast
<
unsigned
>
(
value
);
uint_value
=
static_cast
<
unsigned
>
(
value
);
else
else
ulong_long_value
=
value
;
ulong_long_value
=
value
;
...
@@ -1864,7 +1864,7 @@ class ArgFormatterBase : public ArgVisitor<Impl, void> {
...
@@ -1864,7 +1864,7 @@ class ArgFormatterBase : public ArgVisitor<Impl, void> {
out
+=
spec_
.
width_
-
CHAR_WIDTH
;
out
+=
spec_
.
width_
-
CHAR_WIDTH
;
}
else
if
(
spec_
.
align_
==
ALIGN_CENTER
)
{
}
else
if
(
spec_
.
align_
==
ALIGN_CENTER
)
{
out
=
writer_
.
fill_padding
(
out
,
spec_
.
width_
,
out
=
writer_
.
fill_padding
(
out
,
spec_
.
width_
,
internal
::
check
(
CHAR_WIDTH
),
fill
);
internal
::
c
onst_c
heck
(
CHAR_WIDTH
),
fill
);
}
else
{
}
else
{
std
::
uninitialized_fill_n
(
out
+
CHAR_WIDTH
,
std
::
uninitialized_fill_n
(
out
+
CHAR_WIDTH
,
spec_
.
width_
-
CHAR_WIDTH
,
fill
);
spec_
.
width_
-
CHAR_WIDTH
,
fill
);
...
...
test/format-test.cc
View file @
3f778b20
...
@@ -933,7 +933,7 @@ TEST(FormatterTest, RuntimeWidth) {
...
@@ -933,7 +933,7 @@ TEST(FormatterTest, RuntimeWidth) {
FormatError
,
"number is too big"
);
FormatError
,
"number is too big"
);
EXPECT_THROW_MSG
(
format
(
"{0:{1}}"
,
0
,
-
1l
),
EXPECT_THROW_MSG
(
format
(
"{0:{1}}"
,
0
,
-
1l
),
FormatError
,
"negative width"
);
FormatError
,
"negative width"
);
if
(
fmt
::
internal
::
check
(
sizeof
(
long
)
>
sizeof
(
int
)))
{
if
(
fmt
::
internal
::
c
onst_c
heck
(
sizeof
(
long
)
>
sizeof
(
int
)))
{
long
value
=
INT_MAX
;
long
value
=
INT_MAX
;
EXPECT_THROW_MSG
(
format
(
"{0:{1}}"
,
0
,
(
value
+
1
)),
EXPECT_THROW_MSG
(
format
(
"{0:{1}}"
,
0
,
(
value
+
1
)),
FormatError
,
"number is too big"
);
FormatError
,
"number is too big"
);
...
@@ -1052,7 +1052,7 @@ TEST(FormatterTest, RuntimePrecision) {
...
@@ -1052,7 +1052,7 @@ TEST(FormatterTest, RuntimePrecision) {
FormatError
,
"number is too big"
);
FormatError
,
"number is too big"
);
EXPECT_THROW_MSG
(
format
(
"{0:.{1}}"
,
0
,
-
1l
),
EXPECT_THROW_MSG
(
format
(
"{0:.{1}}"
,
0
,
-
1l
),
FormatError
,
"negative precision"
);
FormatError
,
"negative precision"
);
if
(
fmt
::
internal
::
check
(
sizeof
(
long
)
>
sizeof
(
int
)))
{
if
(
fmt
::
internal
::
c
onst_c
heck
(
sizeof
(
long
)
>
sizeof
(
int
)))
{
long
value
=
INT_MAX
;
long
value
=
INT_MAX
;
EXPECT_THROW_MSG
(
format
(
"{0:.{1}}"
,
0
,
(
value
+
1
)),
EXPECT_THROW_MSG
(
format
(
"{0:.{1}}"
,
0
,
(
value
+
1
)),
FormatError
,
"number is too big"
);
FormatError
,
"number is too big"
);
...
...
test/printf-test.cc
View file @
3f778b20
...
@@ -295,12 +295,13 @@ void TestLength(const char *length_spec, U value) {
...
@@ -295,12 +295,13 @@ void TestLength(const char *length_spec, U value) {
fmt
::
LongLong
signed_value
=
0
;
fmt
::
LongLong
signed_value
=
0
;
fmt
::
ULongLong
unsigned_value
=
0
;
fmt
::
ULongLong
unsigned_value
=
0
;
// Apply integer promotion to the argument.
// Apply integer promotion to the argument.
fmt
::
ULongLong
max
=
std
::
numeric_limits
<
U
>::
max
();
using
std
::
numeric_limits
;
using
fmt
::
internal
::
check
;
fmt
::
ULongLong
max
=
numeric_limits
<
U
>::
max
();
if
(
check
(
max
<=
static_cast
<
unsigned
>
(
std
::
numeric_limits
<
int
>::
max
())))
{
using
fmt
::
internal
::
const_check
;
if
(
const_check
(
max
<=
static_cast
<
unsigned
>
(
numeric_limits
<
int
>::
max
())))
{
signed_value
=
static_cast
<
int
>
(
value
);
signed_value
=
static_cast
<
int
>
(
value
);
unsigned_value
=
static_cast
<
unsigned
>
(
value
);
unsigned_value
=
static_cast
<
unsigned
>
(
value
);
}
else
if
(
c
heck
(
max
<=
std
::
numeric_limits
<
unsigned
>::
max
()))
{
}
else
if
(
c
onst_check
(
max
<=
numeric_limits
<
unsigned
>::
max
()))
{
signed_value
=
static_cast
<
unsigned
>
(
value
);
signed_value
=
static_cast
<
unsigned
>
(
value
);
unsigned_value
=
static_cast
<
unsigned
>
(
value
);
unsigned_value
=
static_cast
<
unsigned
>
(
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