[cfe-dev] -Wheader-guard emits warning after #undef of guard macro

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Jan 14 10:24:31 PST 2014


On Jan 13, 2014, at 1:24 PM, Richard Trieu <rtrieu at google.com> wrote:

> On Mon, Jan 13, 2014 at 3:06 AM, Prathamesh Kulkarni <bilbotheelffriend at gmail.com> wrote:
> For the following test-case:
> #ifndef FOO
> #define FOO2
> 
> #undef FOO2
> #endif
> 
> -Wheader-guard emits warning:
> ./foo.h:4:9: warning: 'FOO' is used as a header guard here, followed
> by #define of a different macro [-Wheader-guard]
> #ifndef FOO
>         ^~~
> ./foo.h:5:9: note: 'FOO2' is defined here; did you mean 'FOO'?
> #define FOO2
>         ^~~~
> 
> Is this appropriate or should it suppress warning in this case
> since it's equivalent to the following: ?
> #ifndef FOO
> #endif
> 
> Thanks and Regards,
> Prathamesh
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> 
> Oops, forgot to include the mailing list.  Sorry for the double email, Prathamesh.
> 
> Prathamesh,
> 
> Can you tell me more about your use case?  Is this a common pattern you have encountered?
> 
> The header guard warning triggers on files with the following format:
> 
> // Start of file
> #ifndef Macro1
> #define Macro2
> ...
> #endif // matches the #ifndef on the first line.
> // End of file
> 
> and warns when Macro1 and Macro2 are close, but not exactly the same.  The warning already ignores cases where Macro1 and Macro2 are very different (edit distance is over half the length).  A similar exemption maybe be warranted in this case too.

Could we maybe not warn if the the #ifndef and #define are separated by at least one empty line ?

> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140114/b8e70f6e/attachment.html>


More information about the cfe-dev mailing list