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

GCC warnings if [-Wshadow] is enabled. #770

Closed
Remotion opened this issue Jun 8, 2018 · 13 comments
Closed

GCC warnings if [-Wshadow] is enabled. #770

Remotion opened this issue Jun 8, 2018 · 13 comments

Comments

@Remotion
Copy link
Contributor

Remotion commented Jun 8, 2018

In file included from \test\warnings_test.cpp:3:0:
fmt/format.h: In function 'Char* fmt::v5::internal::format_decimal(Char*, UInt, unsigned int, ThousandsSep)':
fmt/format.h:1081:55: warning: declaration of 'buffer' shadows a global declaration [-Wshadow]
                             ThousandsSep thousands_sep) {
                                                       ^
In file included from fmt/format.h:67:0,
                 from \test\warnings_test.cpp:3:
fmt/core.h:390:28: note: shadowed declaration is here
 typedef basic_buffer<char> buffer;
                            ^~~~~~
In file included from \test\warnings_test.cpp:3:0:
fmt/format.h: In function 'Iterator fmt::v5::internal::format_decimal(Iterator, UInt, unsigned int, ThousandsSep)':
fmt/format.h:1111:59: warning: declaration of 'buffer' shadows a global declaration [-Wshadow]
   char_type buffer[std::numeric_limits<UInt>::digits10 + 2];
                                                           ^
In file included from fmt/format.h:67:0,
                 from \test\warnings_test.cpp:3:
fmt/core.h:390:28: note: shadowed declaration is here
 typedef basic_buffer<char> buffer;
                            ^~~~~~
In file included from \test\warnings_test.cpp:3:0:
fmt/format.h: In function 'Char* fmt::v5::internal::format_uint(Char*, UInt, unsigned int, bool)':
fmt/format.h:1123:44: warning: declaration of 'buffer' shadows a global declaration [-Wshadow]
                          bool upper = false) {
                                            ^
In file included from fmt/format.h:67:0,
                 from \test\warnings_test.cpp:3:
fmt/core.h:390:28: note: shadowed declaration is here
 typedef basic_buffer<char> buffer;
                            ^~~~~~
In file included from \test\warnings_test.cpp:3:0:
fmt/format.h: In function 'It fmt::v5::internal::format_uint(It, UInt, unsigned int, bool)':
fmt/format.h:1139:64: warning: declaration of 'buffer' shadows a global declaration [-Wshadow]
   char buffer[std::numeric_limits<UInt>::digits / BASE_BITS + 2];
                                                                ^
In file included from fmt/format.h:67:0,
                 from \test\warnings_test.cpp:3:
fmt/core.h:390:28: note: shadowed declaration is here
 typedef basic_buffer<char> buffer;
                            ^~~~~~
In file included from \test\warnings_test.cpp:3:0:
fmt/format.h: In constructor 'constexpr fmt::v5::internal::arg_ref<Char>::arg_ref(unsigned int)':
fmt/format.h:1913:50: warning: declaration of 'index' shadows a member of 'fmt::v5::internal::arg_ref<Char>' [-Wshadow]
   FMT_CONSTEXPR explicit arg_ref(unsigned index) : kind(INDEX), index(index) {}
                                                  ^
fmt/format.h:1924:14: note: shadowed declaration is here
     unsigned index;
              ^~~~~
fmt/format.h: In constructor 'fmt::v5::internal::arg_ref<Char>::arg_ref(fmt::v5::basic_string_view<Char>)':
fmt/format.h:1914:50: warning: declaration of 'name' shadows a member of 'fmt::v5::internal::arg_ref<Char>' [-Wshadow]
   explicit arg_ref(basic_string_view<Char> name) : kind(NAME), name(name) {}
                                                  ^
fmt/format.h:1925:29: note: shadowed declaration is here
     basic_string_view<Char> name;
                             ^~~~
fmt/format.h: In member function 'constexpr typename ParseContext::iterator fmt::v5::formatter<T, Char, typename std::enable_if<fmt::v5::internal::format_type<typename fmt::v5::buffer_context<Char>::type, T>::value>::type>::parse(ParseContext&)':
fmt/format.h:3175:10: warning: declaration of 'type_spec' shadows a global declaration [-Wshadow]
     auto type_spec = specs_.type();
          ^~~~~~~~~
fmt/format.h:1275:37: note: shadowed declaration is here
 typedef format_spec<char, type_tag> type_spec;
                                     ^~~~~~~~~
fmt/format.h: In constructor 'fmt::v5::arg_join<It, Char>::arg_join(It, It, fmt::v5::basic_string_view<Char>)':
fmt/format.h:3405:5: warning: declaration of 'sep' shadows a member of 'fmt::v5::arg_join<It, Char>' [-Wshadow]
     : begin(begin), end(end), sep(sep) {}
     ^
fmt/format.h:3402:27: note: shadowed declaration is here
   basic_string_view<Char> sep;
                           ^~~
fmt/format.h:3405:5: warning: declaration of 'end' shadows a member of 'fmt::v5::arg_join<It, Char>' [-Wshadow]
     : begin(begin), end(end), sep(sep) {}
     ^
fmt/format.h:3401:6: note: shadowed declaration is here
   It end;
      ^~~
fmt/format.h:3405:5: warning: declaration of 'begin' shadows a member of 'fmt::v5::arg_join<It, Char>' [-Wshadow]
     : begin(begin), end(end), sep(sep) {}
     ^
fmt/format.h:3400:6: note: shadowed declaration is here
   It begin;
      ^~~~~
In file included from fmt/format.h:3736:0,
                 from \test\warnings_test.cpp:3:
fmt/format-inl.h: In static member function 'static int fmt::v5::internal::char_traits<char>::format_float(char*, std::size_t, const char*, int, T)':
fmt/format-inl.h:226:79: warning: declaration of 'buffer' shadows a global declaration [-Wshadow]
     char *buffer, std::size_t size, const char *format, int precision, T value) {
                                                                               ^
In file included from fmt/format.h:67:0,
                 from \test\warnings_test.cpp:3:
fmt/core.h:390:28: note: shadowed declaration is here
 typedef basic_buffer<char> buffer;
                            ^~~~~~
In file included from fmt/format.h:3736:0,
                 from \test\warnings_test.cpp:3:
fmt/format-inl.h: In static member function 'static int fmt::v5::internal::char_traits<wchar_t>::format_float(wchar_t*, std::size_t, const wchar_t*, int, T)':
fmt/format-inl.h:235:12: warning: declaration of 'buffer' shadows a global declaration [-Wshadow]
     T value) {
            ^
In file included from fmt/format.h:67:0,
                 from \test\warnings_test.cpp:3:
fmt/core.h:390:28: note: shadowed declaration is here
 typedef basic_buffer<char> buffer;
@eliaskosunen
Copy link
Contributor

I assume you're only including <core.h>, because -Wshadow is explicitly disabled here:

fmt/include/fmt/format.h

Lines 54 to 65 in 1b8a7f8

#if (defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 406) || \
FMT_CLANG_VERSION
# pragma GCC diagnostic push
// Disable the warning about declaration shadowing because it affects too
// many valid cases.
# pragma GCC diagnostic ignored "-Wshadow"
// Disable the warning about implicit conversions that may change the sign of
// an integer; silencing it otherwise would require many explicit casts.
# pragma GCC diagnostic ignored "-Wsign-conversion"
#endif

@Remotion
Copy link
Contributor Author

Remotion commented Jun 8, 2018

No.

#define FMT_HEADER_ONLY
#include "fmt/format.h"

int main() {
    std::string ss = "string";
    fmt::format("{} \n", ss);

    return 0;
}

@eliaskosunen
Copy link
Contributor

eliaskosunen commented Jun 8, 2018

Can't reproduce in CE: https://godbolt.org/g/gqstpW
What version of gcc are you using and are you sure that the version of fmt is post- 691a7a9 ?

@Remotion
Copy link
Contributor Author

Remotion commented Jun 8, 2018

GCC 7.3 from here https://nuwen.net/mingw.html

g++ -std=c++1z -pipe -Wall -Wextra -Wshadow -Wreturn-type -fconcepts -fstrong-eval-order -faligned-new -march=native

{fmt} is 1b8a7f8 commit.

@eliaskosunen
Copy link
Contributor

I think this might be an issue with MinGW rather than fmt, as I still can't reproduce with gcc 7.3 and with the same compiler flags: https://godbolt.org/g/tnNB8T

Does anyone have gcc 7.3 installed locally so they can verify?

What values are __GNUC__ and __clang__ defined to in your platform when compiling with those settings?

@Remotion
Copy link
Contributor Author

Remotion commented Jun 8, 2018

__GNUC__ is 7 and __clang__ is not defined.

So test __GNUC__ >= 406 will be false.

AS it described here https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.

If I change this test to __GNUC__ >= 4 then all the warnings disappear.

@eliaskosunen
Copy link
Contributor

You're correct, that comparison is incorrect. The proper expression would be (__GNUC__ * 100 + __GNUC_MINOR__) >= 406. You could probably submit a PR.

@vitaut
Copy link
Contributor

vitaut commented Jun 10, 2018

Fixed in 47268ec.

@vitaut vitaut closed this as completed Jun 10, 2018
@0x8000-0000
Copy link
Contributor

There are still shadow warnings in e37d6a9 with GCC 8.2

In file included from /home/florin/work/geometry/external/lib/fmt/src/format.cc:8:
/home/florin/work/geometry/external/lib/fmt/include/fmt/format-inl.h: In function ‘bool fmt::v5::internal::grisu2_gen_digits(char*, size_t&, uint32_t, uint64_t, int&, uint64_t, const fmt::v5::internal::fp&, const fmt::v5::internal::fp&, size_t)’:
/home/florin/work/geometry/external/lib/fmt/include/fmt/format-inl.h:484:69: error: declaration of ‘buffer’ shadows a global declaration [-Werror=shadow]
uint64_t delta, const fp &one, const fp &diff, size_t max_digits) {
^
In file included from /home/florin/work/geometry/external/lib/fmt/include/fmt/format.h:60,
from /home/florin/work/geometry/external/lib/fmt/include/fmt/format-inl.h:11,
from /home/florin/work/geometry/external/lib/fmt/src/format.cc:8:
/home/florin/work/geometry/external/lib/fmt/include/fmt/core.h:289:28: note: shadowed declaration is here
typedef basic_buffer buffer;
^~~~~~

@vitaut
Copy link
Contributor

vitaut commented Nov 28, 2018

AFAICS shadowing warnings are suppressed.

@0x8000-0000
Copy link
Contributor

/usr/bin/g++ -I/home/florin/work/geometry/external/lib/fmt/include -Wall -Wextra -Werror -pedantic -Wconversion -Wunused -Wshadow -g -std=c++17 -MD -MT external/lib/fmt/CMakeFiles/fmt.dir/src/format.cc.o -MF external/lib/fmt/CMakeFiles/fmt.dir/src/format.cc.o.d -o external/lib/fmt/CMakeFiles/fmt.dir/src/format.cc.o -c /home/florin/work/geometry/external/lib/fmt/src/format.cc

Will produce the warnings above, with GCC 8.2

@vitaut
Copy link
Contributor

vitaut commented Nov 29, 2018

I see, the suppression doesn't apply in that case. Should be fixed in fa1d4db.

@0x8000-0000
Copy link
Contributor

I see, the suppression doesn't apply in that case. Should be fixed in fa1d4db.

Confirmed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants