[PATCH] Header guard warning is too agressive

Richard Trieu rtrieu at google.com
Wed Sep 11 14:10:24 PDT 2013


  If I understand the issue correctly, and from reading PR17053, the problem is that the main file in the translation unit would have a structure similar to a header guard but it should not be considered a header guard.  This patch does not fix that issue.  Instead, it looks at the edit distance between #define and #ifndef macro names.  This only coincidentally fixes the examples given.  The test case also does not follow the examples as it is still inside a header, not the main file.

  It would be better to detect if the lexer is at the top most file and skip the diagnostic then.


================
Comment at: lib/Lex/PPLexerChange.cpp:280
@@ +279,3 @@
+              << ControllingMacro
+              << FixItHint::CreateReplacement(
+                                              CurPPLexer->MIOpt.GetDefinedLocation(),
----------------
Ismail Pazarbasi wrote:
> I haven't tried thoroughly, but I guess it'd be better to print the fix-it on the warning instead of the note, because clang-check will ignore the note (and I need clang-check to apply the fixit).
This seems like a valid point.  There is only one suggestion, so it should be placed in the warning instead of the note, but that change should go in a separate patch.


http://llvm-reviews.chandlerc.com/D1506



More information about the cfe-commits mailing list