Boost logo

Boost :

Subject: Re: [boost] Warning policy? local variable hides (i.e. shadows) global variable
From: Beman Dawes (bdawes_at_[hidden])
Date: 2015-01-15 12:57:45


On Thu, Jan 15, 2015 at 10:19 AM, Rob Stewart <rob.stewart_at_[hidden]> wrote:

>> > * Prefix function argument names with "a_". Rationale: The "m_"
>> prefix
>> > for member names has been a success.
>
> Really? I think it's ugly.

Yes, that's why it is a success. It is ugly so users don't want to use
it themselves, so it avoids the shadow warning issue.

>
>> > * Suffix function argument names with "_". Rationale: Short and less
>> > distracting than "m_" prefix.
>
> I use a _ suffix for data members and a _ prefix for formal parameters.

Yes, those are non-starters because users do follow such conventions.

>
>> > Thoughts?
>>
>> Despite that the warnings should probably be fixed, I don't think
>> there is need for a naming policy.
>
> Normally, I'd dismiss such warnings as unwanted noise, but given Beman's anecdotal evidence of the benefit of addressing them, I'm inclined to agree that they should be addressed.

It isn't just me; a quick search finds comments like "The clang
-Wshadow warning is quite nice as code which trips it often has bugs
due to accidentally referencing the wrong identically named variable"
and a complaint Apple defaults to no shadow warnings.

--Beman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk