From: Daniel Jasper Date: Mon, 9 Jan 2017 11:04:07 +0000 (+0000) Subject: clang-format: Improve support for override/final as variable names. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5450c954e6f99bca336305e45a31edbc721d6271;p=clang clang-format: Improve support for override/final as variable names. Before: bool a = f() &&override.f(); bool a = f() &&final.f(); void f(const MyOverride & override); void f(const MyFinal & final); After: bool a = f() && override.f(); bool a = f() && final.f(); void f(const MyOverride &override); void f(const MyFinal &final); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291434 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index cf6373f456..b5f7de280a 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1282,9 +1282,7 @@ private: return TT_UnaryOperator; const FormatToken *NextToken = Tok.getNextNonComment(); - if (!NextToken || - NextToken->isOneOf(tok::arrow, Keywords.kw_final, tok::equal, - Keywords.kw_override) || + if (!NextToken || NextToken->isOneOf(tok::arrow, tok::equal) || (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) return TT_PointerOrReference; @@ -2088,9 +2086,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, !Line.IsMultiVariableDeclStmt))) return true; if (Left.is(TT_PointerOrReference)) - return Right.Tok.isLiteral() || - Right.isOneOf(TT_BlockComment, Keywords.kw_final, - Keywords.kw_override) || + return Right.Tok.isLiteral() || Right.is(TT_BlockComment) || + (Right.isOneOf(Keywords.kw_override, Keywords.kw_final) && + !Right.is(TT_StartOfName)) || (Right.is(tok::l_brace) && Right.BlockKind == BK_Block) || (!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare, tok::l_paren) && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 6f9df680ee..629e85803d 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5780,6 +5780,10 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyGoogleFormat("MACRO Constructor(const int& i) : a(a), b(b) {}"); verifyFormat("void f() { f(a, c * d); }"); verifyFormat("void f() { f(new a(), c * d); }"); + verifyFormat("void f(const MyOverride &override);"); + verifyFormat("void f(const MyFinal &final);"); + verifyIndependentOfContext("bool a = f() && override.f();"); + verifyIndependentOfContext("bool a = f() && final.f();"); verifyIndependentOfContext("InvalidRegions[*R] = 0;");