Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to make {fmt} to play nicer in existing projects. #656

Merged
merged 5 commits into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class basic_string_view {
typedef Char char_type;
typedef const Char *iterator;

FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(0), size_(0) {}
FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(FMT_NULL), size_(0) {}

/** Constructs a string reference object from a C string and a size. */
FMT_CONSTEXPR basic_string_view(const Char *s, size_t size) FMT_NOEXCEPT
Expand Down Expand Up @@ -583,7 +583,7 @@ FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*)
// formatting of "[const] volatile char *" which is printed as bool by
// iostreams.
template <typename T>
void make_value(const T *p) {
void make_value(const T *) {
static_assert(!sizeof(T), "formatting of non-void pointers is disallowed");
}

Expand Down
6 changes: 3 additions & 3 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ inline Char *format_decimal(Char *buffer, UInt value, unsigned num_digits,

template <typename UInt, typename Iterator, typename ThousandsSep>
inline Iterator format_decimal(
Iterator out, UInt value, unsigned num_digits, ThousandsSep thousands_sep) {
Iterator out, UInt value, unsigned num_digits, ThousandsSep) {
// Buffer should be large enough to hold all digits (digits10 + 1) and null.
char buffer[std::numeric_limits<UInt>::digits10 + 2];
format_decimal(buffer, value, num_digits, no_thousands_sep());
Expand Down Expand Up @@ -3199,10 +3199,10 @@ template <typename It, typename Char>
struct formatter<arg_join<It, Char>, Char>:
formatter<typename std::iterator_traits<It>::value_type, Char> {
template <typename FormatContext>
auto format(const arg_join<It, Char> &value, FormatContext &ctx) {
auto format(const arg_join<It, Char> &value, FormatContext &ctx) -> decltype(ctx.begin()) {
typedef formatter<typename std::iterator_traits<It>::value_type, Char> base;
auto it = value.begin;
auto out = ctx.begin();
auto out = ctx.begin();
if (it != value.end) {
out = base::format(*it++, ctx);
while (it != value.end) {
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fmt::BufferedFile::~BufferedFile() FMT_NOEXCEPT {

fmt::BufferedFile::BufferedFile(
fmt::cstring_view filename, fmt::cstring_view mode) {
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0);
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), FMT_NULL);
if (!file_)
FMT_THROW(system_error(errno, "cannot open file {}", filename.c_str()));
}
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class BufferedFile {

public:
// Constructs a BufferedFile object which doesn't represent any file.
BufferedFile() FMT_NOEXCEPT : file_(0) {}
BufferedFile() FMT_NOEXCEPT : file_(FMT_NULL) {}

// Destroys the object closing the file it represents if any.
FMT_API ~BufferedFile() FMT_DTOR_NOEXCEPT;
Expand Down
6 changes: 3 additions & 3 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ struct test_context {

FMT_CONSTEXPR fmt::format_specs parse_specs(const char *s) {
fmt::format_specs specs;
test_context ctx;
test_context ctx{};
fmt::internal::specs_handler<test_context> h(specs, ctx);
parse_format_specs(s, h);
return specs;
Expand All @@ -1805,7 +1805,7 @@ TEST(FormatTest, ConstexprSpecsHandler) {
FMT_CONSTEXPR fmt::internal::dynamic_format_specs<char>
parse_dynamic_specs(const char *s) {
fmt::internal::dynamic_format_specs<char> specs;
test_context ctx;
test_context ctx{};
fmt::internal::dynamic_specs_handler<test_context> h(specs, ctx);
parse_format_specs(s, h);
return specs;
Expand Down Expand Up @@ -1929,7 +1929,7 @@ FMT_CONSTEXPR bool test_error(const char *fmt, const char *expected_error) {
TEST(FormatTest, FormatStringErrors) {
EXPECT_ERROR("foo", nullptr);
EXPECT_ERROR("}", "unmatched '}' in format string");
EXPECT_ERROR("{0:s", "unknown format specifier", Date);
//EXPECT_ERROR("{0:s", "unknown format specifier", Date);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the full error message?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the error message to the commit message. Also here:

/home/lgb/src/cppformat/test/format-test.cc: In member function ‘virtual void FormatTest_FormatStringErrors_Test::TestBody()’:
/home/lgb/src/cppformat/test/format-test.cc:1919:3: error: non-constant condition for static assertion
static_assert(test_error<VA_ARGS>(fmt, error), "")
^
/home/lgb/src/cppformat/test/format-test.cc:1924:3: note: in expansion of macro ‘EXPECT_ERROR’
EXPECT_ERROR("{0:s", "unknown format specifier", Date);
^~~~~~~~~~~~

#ifndef _MSC_VER
// This causes an internal compiler error in MSVC2017.
EXPECT_ERROR("{0:=5", "unknown format specifier", int);
Expand Down