From a4dd982805e89a37a080350bf8de9069135c5a60 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 28 Aug 2013 08:24:04 +0000 Subject: [PATCH] clang-format: Don't insert space in __has_include Before: #if __has_include( ) #include #endif After: #if __has_include() #include #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 | 3 ++- unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index bec589d572..b634bbdbf6 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 24ba93f1b9..f5afbd3d7c 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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()\n" + "#include \n" + "#endif"); } //===----------------------------------------------------------------------===// -- 2.40.0