mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-29 18:27:40 +02:00
Fix partial specialization problem for filesystem for Visual Studio (#2957)
* #2954: Provide std::conjunction and std::disjunction substitutes * #2954: Use conjunction and disjunction substitute to make formatter specializations for ranges and maps more robust (especially for Visual Studio compiler family) * #2954: As workaround for older MSVC compilers split formatter<std::filesystem::path> partial template specialization into two explicit specialization. * 2954: Add test case * Provide simplified implementations of conjunction and disjunction * Remove workaround explicit specializations if the partial specialization would cause an ambiguity error * Eliminate extra-test and merge it into existing std-test instead. Add conditionals for filesystem::path testing that does not run into the ambiguity problem.
This commit is contained in:
@ -6,13 +6,18 @@
|
||||
// For the license information refer to format.h.
|
||||
|
||||
#include "fmt/std.h"
|
||||
#include "fmt/ranges.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
TEST(std_test, path) {
|
||||
#ifdef __cpp_lib_filesystem
|
||||
// Test ambiguity problem described in #2954. We need to exclude compilers
|
||||
// where the ambiguity problem cannot be solved for now.
|
||||
#if defined(__cpp_lib_filesystem) && \
|
||||
(!FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920)
|
||||
EXPECT_EQ(fmt::format("{:8}", std::filesystem::path("foo")), "\"foo\" ");
|
||||
EXPECT_EQ(fmt::format("{}", std::filesystem::path("foo\"bar.txt")),
|
||||
"\"foo\\\"bar.txt\"");
|
||||
@ -31,6 +36,18 @@ TEST(std_test, path) {
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(ranges_std_test, format_vector_path) {
|
||||
// Test ambiguity problem described in #2954. We need to exclude compilers
|
||||
// where the ambiguity problem cannot be solved for now.
|
||||
#if defined(__cpp_lib_filesystem) && \
|
||||
(!FMT_MSC_VERSION || FMT_MSC_VERSION >= 1920)
|
||||
auto p = std::filesystem::path("foo/bar.txt");
|
||||
auto c = std::vector<std::string>{"abc", "def"};
|
||||
EXPECT_EQ(fmt::format("path={}, range={}", p, c),
|
||||
"path=\"foo/bar.txt\", range=[\"abc\", \"def\"]");
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(std_test, thread_id) {
|
||||
EXPECT_FALSE(fmt::format("{}", std::this_thread::get_id()).empty());
|
||||
}
|
||||
|
Reference in New Issue
Block a user