Bug 86157

Summary: Wmisleading-indentation disabled after a #line directive
Product: gcc Reporter: Xavier <chantry.xavier>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal CC: dmalcolm, egallager
Priority: P3 Keywords: diagnostic
Version: 6.3.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78352
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Attachments: test case with a block macro

Description Xavier 2018-06-14 20:33:06 UTC
Created attachment 44279 [details]
test case with a block macro

Today at work an instance of the "goto fail" bug was discovered and fixed (4 years after being introduced).

We have a coding rule to enforce brackets even for single instructions, exactly to avoid that kind of bug. It's quite well respected, but we have no tool to check it.

I learned about the Wmisleading-indentation feature, that is awesome ! But we already have gcc 6 and -Wall, and the bug was not found. That's because of that exception : "The warning is not issued after a #line directive, since this typically indicates autogenerated code, and no assumptions can be made about the layout of the file that the directive references.".

That's a shame. We have a few #line directives in most of our files (compiled by gcc) because we use an apple extension called blocks (a kind of closure).

More details at https://techtalk.intersec.com/2014/11/blocks-rewriting-with-clang/

So it would be great to have the Wmisleading-indentation feature even for files with #line directives, perhaps with another flag ?
Any idea or suggestion or workaround is welcome.

Well an easy workaround is to disable the #line directives just for running that check from time to time. So I just did that but still no warning, there is another problem, I just realized this case is more complex than it looked. See attachment for a simplified test case. Since the first line hides a block macro, the problem is not detected anyway.
Comment 1 Eric Gallager 2018-06-15 03:32:14 UTC
(In reply to Xavier from comment #0)
> 
> That's a shame. We have a few #line directives in most of our files
> (compiled by gcc) because we use an apple extension called blocks (a kind of
> closure).

Tangent, but the bug for adding blocks support to gcc is bug 78352 

> 
> More details at
> https://techtalk.intersec.com/2014/11/blocks-rewriting-with-clang/
>
Comment 2 Eric Gallager 2019-06-15 04:05:45 UTC
cc-ing author of -Wmisleading-indentation