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
2039dce7
Commit
2039dce7
authored
Jun 06, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect consteval
parent
d551b88a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
45 deletions
+12
-45
include/fmt/core.h
include/fmt/core.h
+12
-8
test/format-test.cc
test/format-test.cc
+0
-9
test/printf-test.cc
test/printf-test.cc
+0
-28
No files found.
include/fmt/core.h
View file @
2039dce7
...
...
@@ -284,8 +284,16 @@
# define FMT_UNICODE !FMT_MSC_VER
#endif
#ifndef FMT_COMPILE_TIME_CHECKS
# define FMT_COMPILE_TIME_CHECKS 0
#ifndef FMT_CONSTEVAL
# if ((FMT_GCC_VERSION >= 1000 || FMT_CLANG_VERSION >= 1101) && \
__cplusplus > 201703L) || \
(defined(__cpp_consteval) && \
!FMT_MSC_VER) // consteval is broken in MSVC.
# define FMT_CONSTEVAL consteval
# define FMT_HAS_CONSTEVAL
# else
# define FMT_CONSTEVAL
# endif
#endif
#ifndef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
...
...
@@ -2813,17 +2821,13 @@ template <typename Char, typename... Args> class basic_format_string {
template
<
typename
S
,
FMT_ENABLE_IF
(
std
::
is_convertible
<
const
S
&
,
basic_string_view
<
Char
>
>::
value
)
>
#if FMT_COMPILE_TIME_CHECKS
consteval
#endif
basic_format_string
(
const
S
&
s
)
:
str_
(
s
)
{
FMT_CONSTEVAL
basic_format_string
(
const
S
&
s
)
:
str_
(
s
)
{
static_assert
(
detail
::
count
<
(
std
::
is_base_of
<
detail
::
view
,
remove_reference_t
<
Args
>>::
value
&&
std
::
is_reference
<
Args
>::
value
)...
>
()
==
0
,
"passing views as lvalues is disallowed"
);
#if
FMT_COMPILE_TIME_CHECKS
#if
def FMT_HAS_CONSTEVAL
if
constexpr
(
detail
::
count_named_args
<
Args
...
>
()
==
0
)
{
using
checker
=
detail
::
format_string_checker
<
Char
,
detail
::
error_handler
,
remove_cvref_t
<
Args
>
...
>
;
...
...
test/format-test.cc
View file @
2039dce7
...
...
@@ -2059,15 +2059,6 @@ TEST(format_test, vformat_to) {
EXPECT_EQ
(
"42"
,
s
);
}
template
<
typename
T
>
static
std
::
string
fmt_to_string
(
const
T
&
t
)
{
return
fmt
::
format
(
FMT_STRING
(
"{}"
),
t
);
}
TEST
(
format_test
,
fmt_string_in_template
)
{
EXPECT_EQ
(
fmt_to_string
(
1
),
"1"
);
EXPECT_EQ
(
fmt_to_string
(
0
),
"0"
);
}
#endif // FMT_USE_CONSTEXPR
TEST
(
format_test
,
char_traits_is_not_ambiguous
)
{
...
...
test/printf-test.cc
View file @
2039dce7
...
...
@@ -52,34 +52,6 @@ std::wstring test_sprintf(fmt::basic_string_view<wchar_t> format,
<< "format: " << format; \
EXPECT_EQ(expected_output, fmt::sprintf(make_positional(format), arg))
template
<
typename
T
>
struct
value_extractor
{
T
operator
()(
T
value
)
{
return
value
;
}
template
<
typename
U
>
FMT_NORETURN
T
operator
()(
U
)
{
throw
std
::
runtime_error
(
fmt
::
format
(
"invalid type {}"
,
typeid
(
U
).
name
()));
}
#if FMT_USE_INT128
// Apple Clang does not define typeid for __int128_t and __uint128_t.
FMT_NORETURN
T
operator
()(
fmt
::
detail
::
int128_t
)
{
throw
std
::
runtime_error
(
"invalid type __int128_t"
);
}
FMT_NORETURN
T
operator
()(
fmt
::
detail
::
uint128_t
)
{
throw
std
::
runtime_error
(
"invalid type __uint128_t"
);
}
#endif
};
TEST
(
printf_test
,
arg_converter
)
{
long
long
value
=
max_value
<
long
long
>
();
auto
arg
=
fmt
::
detail
::
make_arg
<
fmt
::
format_context
>
(
value
);
fmt
::
visit_format_arg
(
fmt
::
detail
::
arg_converter
<
long
long
,
fmt
::
format_context
>
(
arg
,
'd'
),
arg
);
EXPECT_EQ
(
value
,
fmt
::
visit_format_arg
(
value_extractor
<
long
long
>
(),
arg
));
}
TEST
(
printf_test
,
no_args
)
{
EXPECT_EQ
(
"test"
,
test_sprintf
(
"test"
));
EXPECT_EQ
(
L"test"
,
fmt
::
sprintf
(
L"test"
));
...
...
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