Commit 7fbbfed8 authored by Elias Kosunen's avatar Elias Kosunen Committed by Victor Zverovich

Fix warnings caused by usage of deprecated functionality

parent c3268f4e
...@@ -1076,7 +1076,11 @@ class context_base { ...@@ -1076,7 +1076,11 @@ class context_base {
public: public:
basic_parse_context<char_type>& parse_context() { return parse_context_; } basic_parse_context<char_type>& parse_context() { return parse_context_; }
FMT_DEPRECATED basic_format_args<Context> args() const { return args_; }
// basic_format_context::arg() depends on this
// Cannot be marked as deprecated without causing warnings
/*FMT_DEPRECATED*/ basic_format_args<Context> args() const { return args_; }
basic_format_arg<Context> arg(unsigned id) const { return args_.get(id); } basic_format_arg<Context> arg(unsigned id) const { return args_.get(id); }
internal::error_handler error_handler() { internal::error_handler error_handler() {
......
...@@ -116,9 +116,10 @@ template <typename T> struct ValueExtractor : fmt::internal::function<T> { ...@@ -116,9 +116,10 @@ template <typename T> struct ValueExtractor : fmt::internal::function<T> {
TEST(FormatTest, ArgConverter) { TEST(FormatTest, ArgConverter) {
long long value = std::numeric_limits<long long>::max(); long long value = std::numeric_limits<long long>::max();
auto arg = fmt::internal::make_arg<fmt::format_context>(value); auto arg = fmt::internal::make_arg<fmt::format_context>(value);
visit(fmt::internal::arg_converter<long long, fmt::format_context>(arg, 'd'), fmt::visit_format_arg(
arg); fmt::internal::arg_converter<long long, fmt::format_context>(arg, 'd'),
EXPECT_EQ(value, visit(ValueExtractor<long long>(), arg)); arg);
EXPECT_EQ(value, fmt::visit_format_arg(ValueExtractor<long long>(), arg));
} }
TEST(FormatTest, FormatNegativeNaN) { TEST(FormatTest, FormatNegativeNaN) {
......
...@@ -1720,13 +1720,32 @@ TEST(FormatIntTest, FormatInt) { ...@@ -1720,13 +1720,32 @@ TEST(FormatIntTest, FormatInt) {
fmt::format_int(std::numeric_limits<int64_t>::max()).str()); fmt::format_int(std::numeric_limits<int64_t>::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 <typename T> std::string format_decimal(T value) { template <typename T> std::string format_decimal(T value) {
char buffer[10]; char buffer[10];
char* ptr = buffer; 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); 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) { TEST(FormatIntTest, FormatDec) {
EXPECT_EQ("-42", format_decimal(static_cast<signed char>(-42))); EXPECT_EQ("-42", format_decimal(static_cast<signed char>(-42)));
EXPECT_EQ("-42", format_decimal(static_cast<short>(-42))); EXPECT_EQ("-42", format_decimal(static_cast<short>(-42)));
......
...@@ -59,7 +59,8 @@ TEST(OStreamTest, CustomArg) { ...@@ -59,7 +59,8 @@ TEST(OStreamTest, CustomArg) {
fmt::format_context ctx(std::back_inserter(base), "", fmt::format_args()); fmt::format_context ctx(std::back_inserter(base), "", fmt::format_args());
fmt::format_specs spec; fmt::format_specs spec;
test_arg_formatter af(ctx, spec); test_arg_formatter af(ctx, spec);
visit(af, fmt::internal::make_arg<fmt::format_context>(TestEnum())); fmt::visit_format_arg(
af, fmt::internal::make_arg<fmt::format_context>(TestEnum()));
EXPECT_EQ("TestEnum", std::string(buffer.data(), buffer.size())); EXPECT_EQ("TestEnum", std::string(buffer.data(), buffer.size()));
} }
...@@ -178,8 +179,7 @@ template <typename Output> Output& operator<<(Output& out, ABC) { ...@@ -178,8 +179,7 @@ template <typename Output> Output& operator<<(Output& out, ABC) {
} }
} // namespace fmt_test } // namespace fmt_test
template <typename T> template <typename T> struct TestTemplate {};
struct TestTemplate {};
template <typename T> template <typename T>
std::ostream& operator<<(std::ostream& os, TestTemplate<T>) { std::ostream& operator<<(std::ostream& os, TestTemplate<T>) {
...@@ -187,14 +187,13 @@ std::ostream& operator<<(std::ostream& os, TestTemplate<T>) { ...@@ -187,14 +187,13 @@ std::ostream& operator<<(std::ostream& os, TestTemplate<T>) {
} }
namespace fmt { namespace fmt {
template <typename T> template <typename T> struct formatter<TestTemplate<T>> : formatter<int> {
struct formatter<TestTemplate<T>> : formatter<int> {
template <typename FormatContext> template <typename FormatContext>
typename FormatContext::iterator format(TestTemplate<T>, FormatContext& ctx) { typename FormatContext::iterator format(TestTemplate<T>, FormatContext& ctx) {
return formatter<int>::format(2, ctx); return formatter<int>::format(2, ctx);
} }
}; };
} } // namespace fmt
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 407 #if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 407
TEST(OStreamTest, Template) { TEST(OStreamTest, Template) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment