diff options
| -rw-r--r-- | clang/lib/Format/FormatToken.h | 4 | ||||
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 2 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index f335eda086c..c5db18c8e0e 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -283,6 +283,10 @@ struct FormatToken { bool is(const IdentifierInfo *II) const { return II && II == Tok.getIdentifierInfo(); } + bool is(tok::PPKeywordKind Kind) const { + return Tok.getIdentifierInfo() && + Tok.getIdentifierInfo()->getPPKeywordID() == Kind; + } template <typename A, typename B> bool isOneOf(A K1, B K2) const { return is(K1) || is(K2); } diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 41d1811541a..26d358267b9 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1895,7 +1895,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, return true; return Line.Type == LT_ObjCDecl || Left.is(tok::semi) || (Style.SpaceBeforeParens != FormatStyle::SBPO_Never && - (Left.isOneOf(tok::kw_if, tok::kw_for, tok::kw_while, + (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while, tok::kw_switch, tok::kw_case, TT_ForEachMacro) || (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch, tok::kw_new, tok::kw_delete) && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 7eaebadcf7c..17243b70f78 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -6556,6 +6556,8 @@ TEST_F(FormatTest, DoNotInterfereWithErrorAndWarning) { TEST_F(FormatTest, FormatHashIfExpressions) { verifyFormat("#if AAAA && BBBB"); + verifyFormat("#if (AAAA && BBBB)"); + verifyFormat("#elif (AAAA && BBBB)"); // FIXME: Come up with a better indentation for #elif. verifyFormat( "#if !defined(AAAAAAA) && (defined CCCCCC || defined DDDDDD) && \\\n" |

