From 7fbbfed8c63a26ec0fde5933106983cfde4a1b99 Mon Sep 17 00:00:00 2001 From: Elias Kosunen Date: Thu, 31 Jan 2019 23:47:57 -0500 Subject: [PATCH] Fix warnings caused by usage of deprecated functionality --- include/fmt/core.h | 6 +++++- test/format-impl-test.cc | 7 ++++--- test/format-test.cc | 21 ++++++++++++++++++++- test/ostream-test.cc | 11 +++++------ 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 0005cada..3a55f025 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1076,7 +1076,11 @@ class context_base { public: basic_parse_context& parse_context() { return parse_context_; } - FMT_DEPRECATED basic_format_args args() const { return args_; } + + // basic_format_context::arg() depends on this + // Cannot be marked as deprecated without causing warnings + /*FMT_DEPRECATED*/ basic_format_args args() const { return args_; } + basic_format_arg arg(unsigned id) const { return args_.get(id); } internal::error_handler error_handler() { diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index 8c52cb5e..38e571bf 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -116,9 +116,10 @@ template struct ValueExtractor : fmt::internal::function { TEST(FormatTest, ArgConverter) { long long value = std::numeric_limits::max(); auto arg = fmt::internal::make_arg(value); - visit(fmt::internal::arg_converter(arg, 'd'), - arg); - EXPECT_EQ(value, visit(ValueExtractor(), arg)); + fmt::visit_format_arg( + fmt::internal::arg_converter(arg, 'd'), + arg); + EXPECT_EQ(value, fmt::visit_format_arg(ValueExtractor(), arg)); } TEST(FormatTest, FormatNegativeNaN) { diff --git a/test/format-test.cc b/test/format-test.cc index 84142ffc..500f15ca 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1720,13 +1720,32 @@ TEST(FormatIntTest, FormatInt) { fmt::format_int(std::numeric_limits::max()).str()); } +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + +#if FMT_MSC_VER +#pragma warning(push) +#pragma warning(disable: 4996) // Using a deprecated function +#endif + template std::string format_decimal(T value) { char buffer[10]; char* ptr = buffer; - fmt::format_decimal(ptr, value); + // TODO: Replace with safer, non-deprecated overload + fmt::format_decimal(ptr, value); return std::string(buffer, ptr); } +#if FMT_MSC_VER +#pragma warning(pop) +#endif + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic pop +#endif + TEST(FormatIntTest, FormatDec) { EXPECT_EQ("-42", format_decimal(static_cast(-42))); EXPECT_EQ("-42", format_decimal(static_cast(-42))); diff --git a/test/ostream-test.cc b/test/ostream-test.cc index e27369ba..05fe290c 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -59,7 +59,8 @@ TEST(OStreamTest, CustomArg) { fmt::format_context ctx(std::back_inserter(base), "", fmt::format_args()); fmt::format_specs spec; test_arg_formatter af(ctx, spec); - visit(af, fmt::internal::make_arg(TestEnum())); + fmt::visit_format_arg( + af, fmt::internal::make_arg(TestEnum())); EXPECT_EQ("TestEnum", std::string(buffer.data(), buffer.size())); } @@ -178,8 +179,7 @@ template Output& operator<<(Output& out, ABC) { } } // namespace fmt_test -template -struct TestTemplate {}; +template struct TestTemplate {}; template std::ostream& operator<<(std::ostream& os, TestTemplate) { @@ -187,14 +187,13 @@ std::ostream& operator<<(std::ostream& os, TestTemplate) { } namespace fmt { -template -struct formatter> : formatter { +template struct formatter> : formatter { template typename FormatContext::iterator format(TestTemplate, FormatContext& ctx) { return formatter::format(2, ctx); } }; -} +} // namespace fmt #if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 407 TEST(OStreamTest, Template) {