Some real-life feedback on -Wmisleading-indentation

Jeff Law law@redhat.com
Tue Jan 12 05:44:00 GMT 2016


On 01/11/2016 07:53 AM, David Malcolm wrote:

>
> In Chapter 31 of "Code Complete" (I'm looking at the 2nd edition),
> McConnell discusses the use of whitespace in code layout; he talks about
> both blank lines and indentation as being useful for providing hints to
> the human reader about the structure of the code.
>
> In several places he talks about the use of blank lines for separating
> groups of related statements into "paragraphs", that blank lines in code
> can and should be used to demarcate logical "blocks" of related
> statements (e.g. pp747-8 of 2nd edition).
>
> I think that in the Wine example above the blank lines do effectively
> create "paragraphs" of code to a human, and I agree that a human reader
> is unlikely to think of the
>
> if (0)
>
> as guarding the
>
>     params.cArgs = 1;
>
> since they're in different "paragraphs".
>
> I apologize if I'm belaboring the point here, but I think that
> -Wmisleading-indentation should make use of blank lines of code.
>
> I've posted patches to do so here, firstly here:
>
> https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03225.html
>
> which was rejected thusly by Jeff:
>> I would argue that each of these does represent misleading
>> indentation and that the warning is warranted for each.
>> Perhaps they aren't as bad as prior cases, but I'd still
>> consider them mis-leading.
> (https://gcc.gnu.org/ml/gcc-patches/2015-10/msg03242.html)
I still stand by that assessment.

ISTM for the wine case the backwards indentation (column-wise) of the IF 
may be the right filter, maybe that in conjunction with the blank line 
heuristic.  However, I stand by my belief that the blank line heuristic 
is wrong when used by itself.

Jeff



More information about the Gcc mailing list