diff --git a/CMakeLists.txt b/CMakeLists.txt index 06e6e7b0..684f8149 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,7 @@ endif () add_library(format ${shared} ${FMT_SOURCES}) if (CMAKE_COMPILER_IS_GNUCXX) set_target_properties(format PROPERTIES COMPILE_FLAGS - "-Wall -Wextra -pedantic") + "-Wall -Wextra -Wshadow -pedantic") endif () if (CPP11_FLAG AND FMT_EXTRA_TESTS) set_target_properties(format PROPERTIES COMPILE_FLAGS ${CPP11_FLAG}) diff --git a/format.cc b/format.cc index 81a2ede0..07ce60b7 100644 --- a/format.cc +++ b/format.cc @@ -362,10 +362,10 @@ inline Arg::StringValue ignore_incompatible_str( } // namespace FMT_FUNC void fmt::SystemError::init( - int error_code, StringRef format_str, ArgList args) { - error_code_ = error_code; + int err_code, StringRef format_str, ArgList args) { + error_code_ = err_code; MemoryWriter w; - internal::format_system_error(w, error_code, format(format_str, args)); + internal::format_system_error(w, err_code, format(format_str, args)); std::runtime_error &base = *this; base = std::runtime_error(w.str()); } @@ -612,20 +612,20 @@ class fmt::internal::ArgFormatter : template template void fmt::BasicWriter::write_str( - const Arg::StringValue &str, const FormatSpec &spec) { + const Arg::StringValue &s, const FormatSpec &spec) { // Check if StrChar is convertible to Char. internal::CharTraits::convert(StrChar()); if (spec.type_ && spec.type_ != 's') internal::report_unknown_type(spec.type_, "string"); - const StrChar *s = str.value; - std::size_t size = str.size; - if (size == 0) { - if (!s) + const StrChar *str_value = s.value; + std::size_t str_size = s.size; + if (str_size == 0) { + if (!str_value) FMT_THROW(FormatError("string pointer is null")); - if (*s) - size = std::char_traits::length(s); + if (*str_value) + str_size = std::char_traits::length(str_value); } - write_str(s, size, spec); + write_str(str_value, str_size, spec); } template @@ -739,9 +739,9 @@ unsigned fmt::internal::PrintfFormatter::parse_header( template void fmt::internal::PrintfFormatter::format( - BasicWriter &writer, BasicStringRef format, + BasicWriter &writer, BasicStringRef format_str, const ArgList &args) { - const Char *start = format.c_str(); + const Char *start = format_str.c_str(); set_args(args); const Char *s = start; while (*s) { @@ -892,8 +892,8 @@ void fmt::internal::PrintfFormatter::format( case Arg::CUSTOM: { if (spec.type_) internal::report_unknown_type(spec.type_, "object"); - const void *s = "s"; - arg.custom.format(&writer, arg.custom.value, &s); + const void *str_format = "s"; + arg.custom.format(&writer, arg.custom.value, &str_format); break; } default: diff --git a/format.h b/format.h index c3c2d876..7c871acd 100644 --- a/format.h +++ b/format.h @@ -47,11 +47,14 @@ #ifdef __GNUC__ # define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) # define FMT_GCC_EXTENSION __extension__ -// Disable warning about "long long" which is sometimes reported even -// when using __extension__. # if FMT_GCC_VERSION >= 406 # pragma GCC diagnostic push +// Disable the warning about "long long" which is sometimes reported even +// when using __extension__. # pragma GCC diagnostic ignored "-Wlong-long" +// Disable the warning about declaration shadowing because it affects too +// many valid cases. +# pragma GCC diagnostic ignored "-Wshadow" # endif #else # define FMT_GCC_EXTENSION @@ -154,7 +157,7 @@ void format(BasicFormatter &f, const Char *&format_str, const T &value); different types of strings to a function, for example:: template - std::string format(StringRef format, const Args & ... args); + std::string format(StringRef format_str, const Args & ... args); format("{}", 42); format(std::string("{}"), 42); @@ -989,7 +992,7 @@ class PrintfFormatter : private FormatterBase { public: void format(BasicWriter &writer, - BasicStringRef format, const ArgList &args); + BasicStringRef format_str, const ArgList &args); }; } // namespace internal @@ -1388,7 +1391,7 @@ inline uint64_t make_type(FMT_GEN15(FMT_ARG_TYPE_DEFAULT)) { */ class SystemError : public internal::RuntimeError { private: - void init(int error_code, StringRef format_str, ArgList args); + void init(int err_code, StringRef format_str, ArgList args); protected: int error_code_;