]> granicus.if.org Git - clang/commitdiff
Offer a fixit hint for our warning about tokens at the end of a directive:
authorChris Lattner <sabre@nondot.org>
Tue, 14 Apr 2009 05:15:20 +0000 (05:15 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 14 Apr 2009 05:15:20 +0000 (05:15 +0000)
t.c:3:8: warning: extra tokens at end of #endif directive
#endif foo
       ^
       //

Don't do this in strict-C89 mode because bcpl comments aren't
valid there, and it is too much trouble to analyze whether
C block comments are safe.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69024 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp

index affd9886f02edd784373aeb153a22eb4235deddd..742076956d2eb456d7c6529746dce7f303c3e982 100644 (file)
@@ -114,7 +114,13 @@ void Preprocessor::CheckEndOfDirective(const char *DirType) {
     LexUnexpandedToken(Tmp);
   
   if (Tmp.isNot(tok::eom)) {
-    Diag(Tmp, diag::ext_pp_extra_tokens_at_eol) << DirType;
+    // Add a fixit in GNU/C99/C++ mode.  Don't offer a fixit for strict-C89,
+    // because it is more trouble than it is worth to insert /**/ and check that
+    // there is no /**/ in the range also.
+    CodeModificationHint FixItHint;
+    if (Features.GNUMode || Features.C99 || Features.CPlusPlus)
+      FixItHint = CodeModificationHint::CreateInsertion(Tmp.getLocation(),"//");
+    Diag(Tmp, diag::ext_pp_extra_tokens_at_eol) << DirType << FixItHint;
     DiscardUntilEndOfDirective();
   }
 }