chadaustin / sajson

Lightweight, extremely high-performance JSON parser for C++11
MIT License
562 stars 42 forks source link

warnings with -Wshadow #41

Closed wojdyr closed 6 years ago

wojdyr commented 6 years ago

The -Wshadow flag in GCC and Clang generates a number of warnings in sajson.h (copied below). This flag is not very popular, but on the other hand it'd not harm to avoid the warnings.

$ g++-7 -c -std=c++11 -Wshadow -Iinclude example/main.cpp
In file included from example/main.cpp:2:0:
include/sajson.h: In constructor ‘sajson::string::string(const char*, size_t)’:
include/sajson.h:221:13: warning: declaration of ‘text’ shadows a member of ‘sajson::string’ [-Wshadow]
             : text(text)
             ^
include/sajson.h:240:27: note: shadowed declaration is here
         const char* const text;
                           ^~~~
include/sajson.h: In constructor ‘sajson::literal::literal(const char*)’:
include/sajson.h:251:13: warning: declaration of ‘text’ shadows a member of ‘sajson::literal’ [-Wshadow]
             : string(text, strlen(text))
             ^
include/sajson.h:240:27: note: shadowed declaration is here
         const char* const text;
                           ^~~~
include/sajson.h: In constructor ‘sajson::mutable_string_view::mutable_string_view(size_t, char*)’:
include/sajson.h:271:13: warning: declaration of ‘data’ shadows a member of ‘sajson::mutable_string_view’ [-Wshadow]
             : length_(length)
             ^
include/sajson.h:345:15: note: shadowed declaration is here
         char* data;
               ^~~~
include/sajson.h: In constructor ‘sajson::value::value(sajson::type, const size_t*, const char*)’:
include/sajson.h:615:13: warning: declaration of ‘text’ shadows a member of ‘sajson::value’ [-Wshadow]
             : value_type(value_type)
             ^
include/sajson.h:634:27: note: shadowed declaration is here
         const char* const text;
                           ^~~~
include/sajson.h:615:13: warning: declaration of ‘payload’ shadows a member of ‘sajson::value’ [-Wshadow]
             : value_type(value_type)
             ^
include/sajson.h:633:29: note: shadowed declaration is here
         const size_t* const payload;
                             ^~~~~~~
include/sajson.h:615:13: warning: declaration of ‘value_type’ shadows a member of ‘sajson::value’ [-Wshadow]
             : value_type(value_type)
             ^
include/sajson.h:632:20: note: shadowed declaration is here
         const type value_type;
                    ^~~~~~~~~~
include/sajson.h: In constructor ‘sajson::internal::ownership::ownership(size_t*)’:
include/sajson.h:674:17: warning: declaration of ‘p’ shadows a member of ‘sajson::internal::ownership’ [-Wshadow]
                 : p(p)
                 ^
include/sajson.h:691:21: note: shadowed declaration is here
             size_t* p;
                     ^
include/sajson.h: In constructor ‘sajson::internal::ownership::ownership(sajson::internal::ownership&&)’:
include/sajson.h:678:13: warning: declaration of ‘p’ shadows a member of ‘sajson::internal::ownership’ [-Wshadow]
             : p(p.p) {
             ^
include/sajson.h:691:21: note: shadowed declaration is here
             size_t* p;
                     ^
In file included from example/main.cpp:2:0:
include/sajson.h: In constructor ‘sajson::document::document(const sajson::mutable_string_view&, sajson::internal::ownership&&, sajson::type, const size_t*)’:
include/sajson.h:828:13: warning: declaration of ‘root’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:865:29: note: shadowed declaration is here
         const size_t* const root;
                             ^~~~
include/sajson.h:828:13: warning: declaration of ‘root_type’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:864:20: note: shadowed declaration is here
         const type root_type;
                    ^~~~~~~~~
include/sajson.h:828:13: warning: declaration of ‘structure’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:863:29: note: shadowed declaration is here
         internal::ownership structure;
                             ^~~~~~~~~
include/sajson.h:828:13: warning: declaration of ‘input’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:862:29: note: shadowed declaration is here
         mutable_string_view input;
                             ^~~~~
include/sajson.h: In constructor ‘sajson::document::document(const sajson::mutable_string_view&, size_t, size_t, sajson::error, int)’:
include/sajson.h:841:13: warning: declaration of ‘error_arg’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:869:19: note: shadowed declaration is here
         const int error_arg;
                   ^~~~~~~~~
include/sajson.h:841:13: warning: declaration of ‘error_code’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:868:21: note: shadowed declaration is here
         const error error_code;
                     ^~~~~~~~~~
include/sajson.h:841:13: warning: declaration of ‘error_column’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:867:22: note: shadowed declaration is here
         const size_t error_column;
                      ^~~~~~~~~~~~
include/sajson.h:841:13: warning: declaration of ‘error_line’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:866:22: note: shadowed declaration is here
         const size_t error_line;
                      ^~~~~~~~~~
include/sajson.h:841:13: warning: declaration of ‘input’ shadows a member of ‘sajson::document’ [-Wshadow]
             : input(input)
             ^
include/sajson.h:862:29: note: shadowed declaration is here
         mutable_string_view input;
                             ^~~~~
include/sajson.h: In constructor ‘sajson::single_allocation::allocator::allocator(size_t*, size_t, bool)’:
include/sajson.h:952:17: warning: declaration of ‘should_deallocate’ shadows a member of ‘sajson::single_allocation::allocator’ [-Wshadow]
                 : structure(buffer)
                 ^
include/sajson.h:1022:18: note: shadowed declaration is here
             bool should_deallocate;
                  ^~~~~~~~~~~~~~~~~
include/sajson.h: In constructor ‘sajson::single_allocation::single_allocation(size_t*, size_t)’:
include/sajson.h:1040:13: warning: declaration of ‘existing_buffer’ shadows a member of ‘sajson::single_allocation’ [-Wshadow]
             : has_existing_buffer(true)
             ^
include/sajson.h:1077:17: note: shadowed declaration is here
         size_t* existing_buffer;
                 ^~~~~~~~~~~~~~~
include/sajson.h: In constructor ‘sajson::single_allocation::single_allocation(size_t (&)[N])’:
include/sajson.h:1049:13: warning: declaration of ‘existing_buffer’ shadows a member of ‘sajson::single_allocation’ [-Wshadow]
             : single_allocation(existing_buffer, N)
             ^
include/sajson.h:1077:17: note: shadowed declaration is here
         size_t* existing_buffer;
                 ^~~~~~~~~~~~~~~
include/sajson.h: In constructor ‘sajson::dynamic_allocation::allocator::allocator(size_t*, size_t, size_t)’:
include/sajson.h:1198:17: warning: declaration of ‘initial_stack_capacity’ shadows a member of ‘sajson::dynamic_allocation::allocator’ [-Wshadow]
                 : ast_buffer_bottom(buffer)
                 ^
include/sajson.h:1296:20: note: shadowed declaration is here
             size_t initial_stack_capacity;
                    ^~~~~~~~~~~~~~~~~~~~~~
include/sajson.h: In constructor ‘sajson::dynamic_allocation::dynamic_allocation(size_t, size_t)’:
include/sajson.h:1304:13: warning: declaration of ‘initial_stack_capacity’ shadows a member of ‘sajson::dynamic_allocation’ [-Wshadow]
             : initial_ast_capacity(initial_ast_capacity)
             ^
include/sajson.h:1336:16: note: shadowed declaration is here
         size_t initial_stack_capacity;
                ^~~~~~~~~~~~~~~~~~~~~~
include/sajson.h:1304:13: warning: declaration of ‘initial_ast_capacity’ shadows a member of ‘sajson::dynamic_allocation’ [-Wshadow]
             : initial_ast_capacity(initial_ast_capacity)
             ^
include/sajson.h:1335:16: note: shadowed declaration is here
         size_t initial_ast_capacity;
                ^~~~~~~~~~~~~~~~~~~~
include/sajson.h: In constructor ‘sajson::bounded_allocation::stack_head::stack_head(sajson::bounded_allocation::allocator*)’:
include/sajson.h:1399:17: warning: declaration of ‘source_allocator’ shadows a member of ‘sajson::bounded_allocation::stack_head’ [-Wshadow]
                 : source_allocator(source_allocator)
                 ^
include/sajson.h:1402:24: note: shadowed declaration is here
             allocator* source_allocator;
                        ^~~~~~~~~~~~~~~~
include/sajson.h: In constructor ‘sajson::bounded_allocation::bounded_allocation(size_t*, size_t)’:
include/sajson.h:1488:13: warning: declaration of ‘existing_buffer’ shadows a member of ‘sajson::bounded_allocation’ [-Wshadow]
             : existing_buffer(existing_buffer)
             ^
include/sajson.h:1509:17: note: shadowed declaration is here
         size_t* existing_buffer;
                 ^~~~~~~~~~~~~~~
include/sajson.h: In constructor ‘sajson::bounded_allocation::bounded_allocation(size_t (&)[N])’:
include/sajson.h:1496:13: warning: declaration of ‘existing_buffer’ shadows a member of ‘sajson::bounded_allocation’ [-Wshadow]
             : bounded_allocation(existing_buffer, N)
             ^
include/sajson.h:1509:17: note: shadowed declaration is here
         size_t* existing_buffer;
                 ^~~~~~~~~~~~~~~
include/sajson.h: In constructor ‘sajson::parser<Allocator>::parser(const sajson::mutable_string_view&, Allocator&&)’:
include/sajson.h:1520:13: warning: declaration of ‘allocator’ shadows a member of ‘sajson::parser<Allocator>’ [-Wshadow]
             : input(msv)
             ^
include/sajson.h:2433:19: note: shadowed declaration is here
         Allocator allocator;
                   ^~~~~~~~~
include/sajson.h: In member function ‘bool sajson::parser<Allocator>::parse()’:
include/sajson.h:1746:22: warning: declaration of ‘success’ shadows a previous local [-Wshadow]
                 bool success;
                      ^~~~~~~
include/sajson.h:1620:18: note: shadowed declaration is here
             bool success;
                  ^~~~~~~
include/sajson.h:1815:30: warning: declaration of ‘success’ shadows a previous local [-Wshadow]
                         bool success;
                              ^~~~~~~
include/sajson.h:1620:18: note: shadowed declaration is here
             bool success;
                  ^~~~~~~
include/sajson.h: In instantiation of ‘sajson::parser<Allocator>::parser(const sajson::mutable_string_view&, Allocator&&) [with Allocator = sajson::dynamic_allocation::allocator]’:
include/sajson.h:2464:16:   required from ‘sajson::document sajson::parse(const AllocationStrategy&, const StringType&) [with AllocationStrategy = sajson::dynamic_allocation; StringType = sajson::mutable_string_view]’
example/main.cpp:113:119:   required from here
include/sajson.h:1519:9: warning: declaration of ‘allocator’ shadows a member of ‘sajson::parser<sajson::dynamic_allocation::allocator>’ [-Wshadow]
         parser(const mutable_string_view& msv, Allocator&& allocator)
         ^~~~~~
include/sajson.h:2433:19: note: shadowed declaration is here
         Allocator allocator;
                   ^~~~~~~~~
include/sajson.h: In instantiation of ‘bool sajson::parser<Allocator>::parse() [with Allocator = sajson::dynamic_allocation::allocator]’:
include/sajson.h:1529:22:   required from ‘sajson::document sajson::parser<Allocator>::get_document() [with Allocator = sajson::dynamic_allocation::allocator]’
include/sajson.h:2467:24:   required from ‘sajson::document sajson::parse(const AllocationStrategy&, const StringType&) [with AllocationStrategy = sajson::dynamic_allocation; StringType = sajson::mutable_string_view]’
example/main.cpp:113:119:   required from here
include/sajson.h:1746:22: warning: declaration of ‘success’ shadows a previous local [-Wshadow]
                 bool success;
                      ^~~~~~~
include/sajson.h:1620:18: note: shadowed declaration is here
             bool success;
                  ^~~~~~~
include/sajson.h:1815:30: warning: declaration of ‘success’ shadows a previous local [-Wshadow]
                         bool success;
                              ^~~~~~~
include/sajson.h:1620:18: note: shadowed declaration is here
             bool success;
                  ^~~~~~~
chadaustin commented 6 years ago

Hi @wojdyr

Looks like most of these are in constructors - do you want to put together a pull request that renames the parameters to have a trailing underscore or something like that?

Otherwise, I will eventually get to this, but I've had a lot going on in my personal life. :)

Thanks, Chad

chadaustin commented 6 years ago

Fixed by #42