From 1d29a69139b86eea21fc99c6fc3ecbf9dc000027 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Lacaze Date: Wed, 1 Sep 2021 22:16:45 +0200 Subject: [PATCH 1/3] Add a testcase demonstrating ODR violation in ranges.h --- test/CMakeLists.txt | 2 +- test/ranges-odr-test.cc | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/ranges-odr-test.cc diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bf3785a65d72..6bf68fb3c469 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -85,7 +85,7 @@ endif () add_fmt_test(ostream-test) add_fmt_test(compile-test) add_fmt_test(printf-test) -add_fmt_test(ranges-test) +add_fmt_test(ranges-test ranges-odr-test.cc) add_fmt_test(scan-test) add_fmt_test(unicode-test HEADER_ONLY) if (MSVC) diff --git a/test/ranges-odr-test.cc b/test/ranges-odr-test.cc new file mode 100644 index 000000000000..3ecba1b926c9 --- /dev/null +++ b/test/ranges-odr-test.cc @@ -0,0 +1,22 @@ +// Formatting library for C++ - the core API +// +// Copyright (c) 2012 - present, Victor Zverovich +// All rights reserved. +// +// For the license information refer to format.h. +// +// Copyright (c) 2018 - present, Remotion (Igor Schulz) +// All Rights Reserved +// {fmt} support for ranges, containers and types tuple interface. + +#include "fmt/ranges.h" + +#include + +#include "gtest/gtest.h" + +TEST(ranges_odr_test, format_vector) { + auto v = std::vector{1, 2, 3, 5, 7, 11}; + EXPECT_EQ(fmt::format("{}", v), "[1, 2, 3, 5, 7, 11]"); +} + From dc683b527196ff23c8995813ba6fe3ef6bd4d8a6 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Lacaze Date: Wed, 1 Sep 2021 22:20:58 +0200 Subject: [PATCH 2/3] Fix ODR violation in ranges.h --- include/fmt/ranges.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index eac81a798e81..acff1574a877 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -437,7 +437,7 @@ auto find_escape(const Char* begin, const Char* end) return {begin, nullptr, 0}; } -auto find_escape(const char* begin, const char* end) +inline auto find_escape(const char* begin, const char* end) -> find_escape_result { if (!is_utf8()) return find_escape(begin, end); auto result = find_escape_result{end, nullptr, 0}; From bcc0c19d29fa543ae5689ebe966bea0fa8240a8b Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Lacaze Date: Thu, 2 Sep 2021 17:02:45 +0200 Subject: [PATCH 3/3] Fix comments --- test/ranges-odr-test.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/ranges-odr-test.cc b/test/ranges-odr-test.cc index 3ecba1b926c9..9d6cd1ffce45 100644 --- a/test/ranges-odr-test.cc +++ b/test/ranges-odr-test.cc @@ -4,10 +4,6 @@ // All rights reserved. // // For the license information refer to format.h. -// -// Copyright (c) 2018 - present, Remotion (Igor Schulz) -// All Rights Reserved -// {fmt} support for ranges, containers and types tuple interface. #include "fmt/ranges.h" @@ -15,6 +11,7 @@ #include "gtest/gtest.h" +// call fmt::format from another translation unit to test ODR TEST(ranges_odr_test, format_vector) { auto v = std::vector{1, 2, 3, 5, 7, 11}; EXPECT_EQ(fmt::format("{}", v), "[1, 2, 3, 5, 7, 11]");