serge1 / ELFIO

ELFIO - ELF (Executable and Linkable Format) reader and producer implemented as a header only C++ library

Home Page:http://serge1.github.io/ELFIO

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

parent shadows parent on Sections constructor

Rucadi opened this issue · comments

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 ) {}

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

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?

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