Skip to content

Commit

Permalink
Remove deprecated APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed May 22, 2022
1 parent edeb3d8 commit ce246aa
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 66 deletions.
7 changes: 0 additions & 7 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3318,13 +3318,6 @@ constexpr auto operator"" _a(const char* s, size_t) -> detail::udl_arg<char> {
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<char> {
return {{s, n}};
}
} // namespace literals
#endif // FMT_USE_USER_DEFINED_LITERALS

Expand Down
5 changes: 1 addition & 4 deletions include/fmt/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 2 additions & 9 deletions src/os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@
# include <windows.h>
#endif

#ifdef fileno
# undef fileno
#endif

namespace {
#ifdef _WIN32
// Return type of read and write functions.
Expand Down Expand Up @@ -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;
}
Expand Down
33 changes: 2 additions & 31 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)));
Expand Down
2 changes: 1 addition & 1 deletion test/gtest-extra-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<output_redirect> redir{nullptr};
Expand Down
22 changes: 9 additions & 13 deletions test/os-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<wchar_t>;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -249,31 +245,31 @@ 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");
}

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));
}

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);
}

Expand Down
2 changes: 1 addition & 1 deletion test/posix-mock-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ce246aa

Please sign in to comment.