[PATCH] Refactor -Wmisleading-indentation API and extend coverage

Patrick Palka patrick@parcs.ath.cx
Mon Jun 8 19:44:00 GMT 2015


On Mon, Jun 8, 2015 at 2:45 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> Patrick Palka <patrick@parcs.ath.cx> writes:
>> At the same time this patch extends the coverage of the
>> -Wmisleading-indentation implementation to catch misleading indentation
>> involving the semicolon.  (These changes are all contained in
>> c-indentation.c.)  For example, now we warn on the following code
>> samples:
>>
>>   if (flag);
>>     foo ();
>>
>>   while (flag);
>>   {
>>     ...
>>   }
>>
>>   if (flag); {
>>     ...
>>   }
>>
>>   if (flag)
>>     ; /* blah */ {
>>       ...
>>     }
>>
>>   if (flag); foo ();
>>
>> while avoiding to warn on code that is poorly indented but not
>> misleadingly so;
>>
>>   while (flag);
>>   foo ();
>>
>>   while (flag)
>>     ;
>>     foo ();
>
> Maybe I've just been doing too much Python recently, but unlike the
> other two examples, this one does seem a little misleading.  What would
> happen for:
>
>   while (flag)
>     /* blah */;
>     foo ();
>
> where the semicolon is hidden after a comment?

Ah yeah, good point. The case when there is a comment in between the
guard and the semicolon is slightly tricky but doable.

>
> Thanks to David and you for the patches btw -- looks like a really
> useful feature.
>
> Richard
>
>>   if (flag1)
>>     ;
>>   if (flag)
>>     ;
>>   else
>>    ...



More information about the Gcc-patches mailing list