From: Daniel Jasper Date: Tue, 21 Jan 2014 08:56:09 +0000 (+0000) Subject: clang-format: text following #if is likely an expression. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a63f66ffa92d9b5e199f9af7cc470e6b92fe0a31;p=clang clang-format: text following #if is likely an expression. Before: #if AAAA &&BBBB After: #if AAAA && BBBB git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199713 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 7b2c595403..418a7c5048 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -516,6 +516,7 @@ private: break; case tok::pp_if: case tok::pp_elif: + Contexts.back().IsExpression = true; parseLine(); break; default: @@ -531,7 +532,7 @@ public: parsePreprocessorDirective(); return LT_PreprocessorDirective; } - + // Directly allow to 'import ' to support protocol buffer // definitions (code.google.com/p/protobuf) or missing "#" (either way we // should not break the line). diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index e43d17fa05..a029176eef 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5112,6 +5112,7 @@ TEST_F(FormatTest, DoNotInterfereWithErrorAndWarning) { } TEST_F(FormatTest, FormatHashIfExpressions) { + verifyFormat("#if AAAA && BBBB"); // FIXME: Come up with a better indentation for #elif. verifyFormat( "#if !defined(AAAAAAA) && (defined CCCCCC || defined DDDDDD) && \\\n"