]> granicus.if.org Git - clang/commitdiff
clang-format: Don't insert space in __has_include
authorDaniel Jasper <djasper@google.com>
Wed, 28 Aug 2013 08:24:04 +0000 (08:24 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 28 Aug 2013 08:24:04 +0000 (08:24 +0000)
Before:
  #if __has_include( <strstream>)
  #include <strstream>
  #endif

After:
  #if __has_include(<strstream>)
  #include <strstream>
  #endif

This fixes llvm.org/PR16516.

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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index bec589d572ff2267b71e3e2ac3c574acd28e16ab..b634bbdbf62cf4c5ee320ac24f73d4fabcd26318 100644 (file)
@@ -1292,7 +1292,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
     return true;
   if (Tok.Previous->Type == TT_TemplateCloser && Tok.is(tok::l_paren))
     return false;
-  if (Tok.is(tok::less) && Line.First->is(tok::hash))
+  if (Tok.is(tok::less) && Tok.Previous->isNot(tok::l_paren) &&
+      Line.First->is(tok::hash))
     return true;
   if (Tok.Type == TT_TrailingUnaryOperator)
     return false;
index 24ba93f1b984955f86f3a9193fa22e7f00e67801..f5afbd3d7c4978a3700f2a6bdd9e98a2c334b525 100644 (file)
@@ -3990,6 +3990,9 @@ TEST_F(FormatTest, HandlesIncludeDirectives) {
   verifyFormat("#import \"a/b/string\"");
   verifyFormat("#import \"string.h\"");
   verifyFormat("#import \"string.h\"");
+  verifyFormat("#if __has_include(<strstream>)\n"
+               "#include <strstream>\n"
+               "#endif");
 }
 
 //===----------------------------------------------------------------------===//