← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH/QUESTION] Fix -Wshadow warnings in sch_sheet_path.cpp

 

John,

I went ahead and merged your patch even though there seems to be not
logical reason for the shadow variable warning.  There is not much risk
in renaming a few variables to keep the compiler from complaining.
Thank you for your contribution to KiCad.

Cheers,

Wayne

On 6/28/2018 9:44 AM, John Beard wrote:
> Hi,
> 
> Simple patch to fix a trio of -Wshadow warnings in SCH_SHEET_PATH.
> 
> Apparently, these shadow declarations from the STL vector header:
> 
>     /home/john/src/kicad/eeschema/sch_sheet_path.cpp: In member
> function ‘void SCH_SHEET_PATH::GetComponents(SCH_REFERENCE_LIST&,
> bool, bool)’:
>     /home/john/src/kicad/eeschema/sch_sheet_path.cpp:202:42: warning:
> declaration of ‘reference’ shadows a previous local [-Wshadow]
>                      SCH_REFERENCE reference( component, part, *this );
>                                               ^~~~~~~~~
>     In file included from /usr/include/c++/8.1.1/vector:64,
>                      from /home/john/src/kicad/include/macros.h:34,
>                      from /home/john/src/kicad/eeschema/./sch_screen.h:33,
>                      from /home/john/src/kicad/eeschema/sch_sheet_path.cpp:34:
>     /usr/include/c++/8.1.1/bits/stl_vector.h:367:50: note: shadowed
> declaration is here
>            typedef typename _Alloc_traits::reference  reference;
> 
> I'm unclear on how that has come about, as I can't see anything
> obviously allowing std::vector::reference to be shadowed here.
> 
> The only use of a using or typedef called "reference" seems to be in
> iterator.h, but it's private and looks unrelated anyway:
> 
>     using reference = typename DLIST_ITERATOR<T>::reference;
> 
> With this code, I get no errors:
> 
>     #include <vector>
> 
>     int main() {
>         int reference = 0;
>         return reference;
>     }
> 
> Even with this code, I don't get the same error:
> 
>     #include <vector>
>     using reference = std::vector<char>::reference;
> 
>     int main() {
>         int reference = 0;
>         return reference;
>     }
> 
>     $ g++ -Wall -Wextra -Wshadow wshadow.cpp -o wshadow.o
>     wshadow.cpp: In function ‘int main()’:
>     wshadow.cpp:9:9: warning: declaration of ‘reference’ shadows a
> global declaration [-Wshadow]
>          int reference = 0;
> 
> The patch fixes the error by renaming the offending variables to
> "schReference", but I think it would be nicer to see if we can avoid
> the vector typedef leaking out so it can even be shadowed in the first
> place?
> 
> Compiler is GCC 8.1.1, which might have a bearing on reproducibility.
> 
> Cheers,
> 
> John
> 
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 


References