From ce246aaf74cb7616777497da988804fa4c02bf2d Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 22 May 2022 06:49:31 -0700 Subject: [PATCH] Remove deprecated APIs --- include/fmt/format.h | 7 ------- include/fmt/os.h | 5 +---- src/os.cc | 11 ++--------- test/format-test.cc | 33 ++------------------------------- test/gtest-extra-test.cc | 2 +- test/os-test.cc | 22 +++++++++------------- test/posix-mock-test.cc | 2 +- 7 files changed, 16 insertions(+), 66 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 9f312624..500fd402 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3318,13 +3318,6 @@ constexpr auto operator"" _a(const char* s, size_t) -> detail::udl_arg { return {s}; } # endif - -// DEPRECATED! -// User-defined literal equivalent of fmt::format. -FMT_DEPRECATED constexpr auto operator"" _format(const char* s, size_t n) - -> detail::udl_formatter { - return {{s, n}}; -} } // namespace literals #endif // FMT_USE_USER_DEFINED_LITERALS diff --git a/include/fmt/os.h b/include/fmt/os.h index d7ba5f4c..d82be112 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -260,10 +260,7 @@ class buffered_file { // Returns the pointer to a FILE object representing this file. FILE* get() const noexcept { return file_; } - // We place parentheses around fileno to workaround a bug in some versions - // of MinGW that define fileno as a macro. - // DEPRECATED! Rename to descriptor to avoid issues with macros. - FMT_API int(fileno)() const; + FMT_API int descriptor() const; void vprint(string_view format_str, format_args args) { fmt::vprint(file_, format_str, args); diff --git a/src/os.cc b/src/os.cc index faa84c49..faa82512 100644 --- a/src/os.cc +++ b/src/os.cc @@ -51,10 +51,6 @@ # include #endif -#ifdef fileno -# undef fileno -#endif - namespace { #ifdef _WIN32 // Return type of read and write functions. @@ -206,11 +202,8 @@ void buffered_file::close() { if (result != 0) FMT_THROW(system_error(errno, "cannot close file")); } -// A macro used to prevent expansion of fileno on broken versions of MinGW. -#define FMT_ARGS - -int buffered_file::fileno() const { - int fd = FMT_POSIX_CALL(fileno FMT_ARGS(file_)); +int buffered_file::descriptor() const { + int fd = FMT_POSIX_CALL(fileno(file_)); if (fd == -1) FMT_THROW(system_error(errno, "cannot get file descriptor")); return fd; } diff --git a/test/format-test.cc b/test/format-test.cc index b4e1e194..c8779e32 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1875,38 +1875,8 @@ TEST(format_test, custom_format_compile_time_string) { } #if FMT_USE_USER_DEFINED_LITERALS -// Passing user-defined literals directly to EXPECT_EQ causes problems -// with macro argument stringification (#) on some versions of GCC. -// Workaround: Assing the UDL result to a variable before the macro. - -using namespace fmt::literals; - -# if FMT_GCC_VERSION -# define FMT_CHECK_DEPRECATED_UDL_FORMAT 1 -# elif FMT_CLANG_VERSION && defined(__has_warning) -# if __has_warning("-Wdeprecated-declarations") -# define FMT_CHECK_DEPRECATED_UDL_FORMAT 1 -# endif -# endif -# ifndef FMT_CHECK_DEPRECATED_UDL_FORMAT -# define FMT_CHECK_DEPRECATED_UDL_FORMAT 0 -# endif - -# if FMT_CHECK_DEPRECATED_UDL_FORMAT -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" - -TEST(format_test, format_udl) { - EXPECT_EQ("{}c{}"_format("ab", 1), fmt::format("{}c{}", "ab", 1)); - EXPECT_EQ("foo"_format(), "foo"); - EXPECT_EQ("{0:10}"_format(42), " 42"); - EXPECT_EQ("{}"_format(date(2015, 10, 21)), "2015-10-21"); -} - -# pragma GCC diagnostic pop -# endif - TEST(format_test, named_arg_udl) { + using namespace fmt::literals; auto udl_a = fmt::format("{first}{second}{first}{third}", "first"_a = "abra", "second"_a = "cad", "third"_a = 99); EXPECT_EQ( @@ -2209,6 +2179,7 @@ TEST(format_test, format_string_errors) { fmt::print("warning: constexpr is broken in this version of MSVC\n"); # endif # if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS + using namespace fmt::literals; EXPECT_ERROR("{foo}", "named argument is not found", decltype("bar"_a = 42)); EXPECT_ERROR("{foo}", "named argument is not found", decltype(fmt::arg("foo", 42))); diff --git a/test/gtest-extra-test.cc b/test/gtest-extra-test.cc index 0d86206c..69e42bc6 100644 --- a/test/gtest-extra-test.cc +++ b/test/gtest-extra-test.cc @@ -347,7 +347,7 @@ TEST(output_redirect_test, flush_error_in_ctor) { TEST(output_redirect_test, dup_error_in_ctor) { buffered_file f = open_buffered_file(); - int fd = (f.fileno)(); + int fd = (f.descriptor)(); file copy = file::dup(fd); FMT_POSIX(close(fd)); std::unique_ptr redir{nullptr}; diff --git a/test/os-test.cc b/test/os-test.cc index 5b5ef76e..a1745c8c 100644 --- a/test/os-test.cc +++ b/test/os-test.cc @@ -14,10 +14,6 @@ #include "gtest-extra.h" #include "util.h" -#ifdef fileno -# undef fileno -#endif - using fmt::buffered_file; using testing::HasSubstr; using wstring_view = fmt::basic_string_view; @@ -205,7 +201,7 @@ TEST(buffered_file_test, move_assignment) { TEST(buffered_file_test, move_assignment_closes_file) { buffered_file bf = open_buffered_file(); buffered_file bf2 = open_buffered_file(); - int old_fd = bf2.fileno(); + int old_fd = bf2.descriptor(); bf2 = std::move(bf); EXPECT_TRUE(isclosed(old_fd)); } @@ -225,7 +221,7 @@ TEST(buffered_file_test, move_from_temporary_in_assignment) { TEST(buffered_file_test, move_from_temporary_in_assignment_closes_file) { buffered_file f = open_buffered_file(); - int old_fd = f.fileno(); + int old_fd = f.descriptor(); f = open_buffered_file(); EXPECT_TRUE(isclosed(old_fd)); } @@ -234,7 +230,7 @@ TEST(buffered_file_test, close_file_in_dtor) { int fd = 0; { buffered_file f = open_buffered_file(); - fd = f.fileno(); + fd = f.descriptor(); } EXPECT_TRUE(isclosed(fd)); } @@ -249,7 +245,7 @@ TEST(buffered_file_test, close_error_in_dtor) { // otherwise the system may recycle closed file descriptor when // redirecting the output in EXPECT_STDERR and the second close // will break output redirection. - FMT_POSIX(close(f->fileno())); + FMT_POSIX(close(f->descriptor())); SUPPRESS_ASSERT(f.reset(nullptr)); }, system_error_message(EBADF, "cannot close file") + "\n"); @@ -257,7 +253,7 @@ TEST(buffered_file_test, close_error_in_dtor) { TEST(buffered_file_test, close) { buffered_file f = open_buffered_file(); - int fd = f.fileno(); + int fd = f.descriptor(); f.close(); EXPECT_TRUE(f.get() == nullptr); EXPECT_TRUE(isclosed(fd)); @@ -265,15 +261,15 @@ TEST(buffered_file_test, close) { TEST(buffered_file_test, close_error) { buffered_file f = open_buffered_file(); - FMT_POSIX(close(f.fileno())); + FMT_POSIX(close(f.descriptor())); EXPECT_SYSTEM_ERROR_NOASSERT(f.close(), EBADF, "cannot close file"); EXPECT_TRUE(f.get() == nullptr); } -TEST(buffered_file_test, fileno) { +TEST(buffered_file_test, descriptor) { auto f = open_buffered_file(); - EXPECT_TRUE(f.fileno() != -1); - file copy = file::dup(f.fileno()); + EXPECT_TRUE(f.descriptor() != -1); + file copy = file::dup(f.descriptor()); EXPECT_READ(copy, file_content); } diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index 32adbd50..819a94df 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -438,7 +438,7 @@ TEST(buffered_file_test, fileno_no_retry) { file::pipe(read_end, write_end); buffered_file f = read_end.fdopen("r"); fileno_count = 1; - EXPECT_SYSTEM_ERROR((f.fileno)(), EINTR, "cannot get file descriptor"); + EXPECT_SYSTEM_ERROR((f.descriptor)(), EINTR, "cannot get file descriptor"); EXPECT_EQ(2, fileno_count); fileno_count = 0; }