Fix warnings caused by usage of deprecated functionality

This commit is contained in:
Elias Kosunen 2019-01-31 23:47:57 -05:00 committed by Victor Zverovich
parent c3268f4e50
commit 7fbbfed8c6
4 changed files with 34 additions and 11 deletions

View File

@ -1076,7 +1076,11 @@ class context_base {
public:
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); }
internal::error_handler error_handler() {

View File

@ -116,9 +116,10 @@ template <typename T> struct ValueExtractor : fmt::internal::function<T> {
TEST(FormatTest, ArgConverter) {
long long value = std::numeric_limits<long long>::max();
auto arg = fmt::internal::make_arg<fmt::format_context>(value);
visit(fmt::internal::arg_converter<long long, fmt::format_context>(arg, 'd'),
arg);
EXPECT_EQ(value, visit(ValueExtractor<long long>(), arg));
fmt::visit_format_arg(
fmt::internal::arg_converter<long long, fmt::format_context>(arg, 'd'),
arg);
EXPECT_EQ(value, fmt::visit_format_arg(ValueExtractor<long long>(), arg));
}
TEST(FormatTest, FormatNegativeNaN) {

View File

@ -1720,13 +1720,32 @@ TEST(FormatIntTest, FormatInt) {
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) {
char buffer[10];
char* ptr = buffer;
// 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<signed char>(-42)));
EXPECT_EQ("-42", format_decimal(static_cast<short>(-42)));

View File

@ -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<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()));
}
@ -178,8 +179,7 @@ template <typename Output> Output& operator<<(Output& out, ABC) {
}
} // namespace fmt_test
template <typename T>
struct TestTemplate {};
template <typename T> struct TestTemplate {};
template <typename T>
std::ostream& operator<<(std::ostream& os, TestTemplate<T>) {
@ -187,14 +187,13 @@ std::ostream& operator<<(std::ostream& os, TestTemplate<T>) {
}
namespace fmt {
template <typename T>
struct formatter<TestTemplate<T>> : formatter<int> {
template <typename T> struct formatter<TestTemplate<T>> : formatter<int> {
template <typename FormatContext>
typename FormatContext::iterator format(TestTemplate<T>, FormatContext& ctx) {
return formatter<int>::format(2, ctx);
}
};
}
} // namespace fmt
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 407
TEST(OStreamTest, Template) {