Fix an odr violation in ranges.h (#2483)

* Add a testcase demonstrating ODR violation in ranges.h

* Fix ODR violation in ranges.h

* Fix comments

Co-authored-by: Pierre-Antoine Lacaze <pa.lacaze@gmail.com>
This commit is contained in:
Pierre-Antoine Lacaze
2021-09-02 08:47:44 -07:00
committed by GitHub
co-authored by Pierre-Antoine Lacaze
parent ee0659f8b6
commit d58d19ba32
3 changed files with 21 additions and 2 deletions
+1 -1
View File
@@ -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)
+19
View File
@@ -0,0 +1,19 @@
// Formatting library for C++ - the core API
//
// Copyright (c) 2012 - present, Victor Zverovich
// All rights reserved.
//
// For the license information refer to format.h.
#include "fmt/ranges.h"
#include <vector>
#include "gtest/gtest.h"
// call fmt::format from another translation unit to test ODR
TEST(ranges_odr_test, format_vector) {
auto v = std::vector<int>{1, 2, 3, 5, 7, 11};
EXPECT_EQ(fmt::format("{}", v), "[1, 2, 3, 5, 7, 11]");
}