mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 15:21:54 +00:00
Work around UDL macro stringification bug on some versions of GCC
See bug report: https://gcc.gnu.org/ml/gcc-bugs/2015-04/msg02027.html
This commit is contained in:
parent
bc6010cc21
commit
c0813c59f3
@ -1604,23 +1604,31 @@ TEST(FormatTest, MaxArgs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if FMT_USE_USER_DEFINED_LITERALS
|
#if FMT_USE_USER_DEFINED_LITERALS
|
||||||
|
// Passing user-defined literals directly to EXPECT_EQ causes problems
|
||||||
|
// with macro argument stringification (#) on some versions of GCC.
|
||||||
|
// Workaround: Assing the UDL result to a variable before the macro.
|
||||||
|
|
||||||
using namespace fmt::literals;
|
using namespace fmt::literals;
|
||||||
|
|
||||||
TEST(LiteralsTest, Format) {
|
TEST(LiteralsTest, Format) {
|
||||||
EXPECT_EQ(format("{}c{}", "ab", 1), "{}c{}"_format("ab", 1));
|
auto udl_format = "{}c{}"_format("ab", 1);
|
||||||
EXPECT_EQ(format(L"{}c{}", L"ab", 1), L"{}c{}"_format(L"ab", 1));
|
EXPECT_EQ(format("{}c{}", "ab", 1), udl_format);
|
||||||
|
auto udl_format_w = L"{}c{}"_format(L"ab", 1);
|
||||||
|
EXPECT_EQ(format(L"{}c{}", L"ab", 1), udl_format_w);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LiteralsTest, NamedArg) {
|
TEST(LiteralsTest, NamedArg) {
|
||||||
|
auto udl_a = format("{first}{second}{first}{third}",
|
||||||
|
"first"_a="abra", "second"_a="cad", "third"_a=99);
|
||||||
EXPECT_EQ(format("{first}{second}{first}{third}",
|
EXPECT_EQ(format("{first}{second}{first}{third}",
|
||||||
fmt::arg("first", "abra"), fmt::arg("second", "cad"),
|
fmt::arg("first", "abra"), fmt::arg("second", "cad"),
|
||||||
fmt::arg("third", 99)),
|
fmt::arg("third", 99)),
|
||||||
format("{first}{second}{first}{third}",
|
udl_a);
|
||||||
"first"_a="abra", "second"_a="cad", "third"_a=99));
|
auto udl_a_w = format(L"{first}{second}{first}{third}",
|
||||||
|
L"first"_a=L"abra", L"second"_a=L"cad", L"third"_a=99);
|
||||||
EXPECT_EQ(format(L"{first}{second}{first}{third}",
|
EXPECT_EQ(format(L"{first}{second}{first}{third}",
|
||||||
fmt::arg(L"first", L"abra"), fmt::arg(L"second", L"cad"),
|
fmt::arg(L"first", L"abra"), fmt::arg(L"second", L"cad"),
|
||||||
fmt::arg(L"third", 99)),
|
fmt::arg(L"third", 99)),
|
||||||
format(L"{first}{second}{first}{third}",
|
udl_a_w);
|
||||||
L"first"_a=L"abra", L"second"_a=L"cad", L"third"_a=99));
|
|
||||||
}
|
}
|
||||||
#endif // FMT_USE_USER_DEFINED_LITERALS
|
#endif // FMT_USE_USER_DEFINED_LITERALS
|
||||||
|
Loading…
Reference in New Issue
Block a user