serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library
http://serge1.github.io/ELFIO
MIT License
729 stars 158 forks source link

parent shadows parent on Sections constructor #83

Closed Rucadi closed 2 years ago

Rucadi commented 2 years ago

Hi!

This is easy to fix and should silence compiler warnings:

In the explicit constructor of Sections:

explicit Sections( elfio* parent ) : parent( parent ) {}

Parent is shadowed, so the compiler shouts:

warning: declaration of 'parent' shadows a member of 'ELFIO::elfio::Segments' [-Wshadow] 988 | explicit Segments( elfio* parent ) : parent( parent ) {}

serge1 commented 2 years ago

I don't receive such warnings when compiled with GCC 10.3 and option "-Wall". Which compiler/version are you using?

serge1 commented 2 years ago

Hi, I am in doubts... The library compiles without warnings when '-Wall' and '-Wextra' options are provided. When option '-Wshadow' is explicitly provided, a lot of warnings are generated. By my opinion, making the local variables names differ from the class members will reduce code clearness.

Given, I didn't receive such requests in past, I would tend to leave the code as it is. At least at meantime. Do you think you can change compiler options in your project such that when ELFIO library is involved, '-Wshadow' option is not used?

serge1 commented 2 years ago

I found authorized opinion regarding this topic. Linus Torvalds also thinks that vars at declared at different scopes are OK to use: https://lkml.org/lkml/2006/11/28/253