From: Daniel Jasper Date: Tue, 28 Oct 2014 18:11:52 +0000 (+0000) Subject: clang-format: Improve && detection as binary operators. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8365e2857ed8df2c7a9ad7400a5879c607b31788;p=clang clang-format: Improve && detection as binary operators. Before: template ::value &&(sizeof(T) > 1 || sizeof(T) < 8)>::type> void F(); After: template ::value && (sizeof(T) > 1 || sizeof(T) < 8)>::type> void F(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220805 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ff0af5a08c..14d164e2ae 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -992,6 +992,10 @@ private: (InTemplateArgument && NextToken->Tok.isAnyIdentifier())) return TT_BinaryOperator; + // "&&(" is quite unlikely to be two successive unary "&". + if (Tok.is(tok::ampamp) && NextToken && NextToken->is(tok::l_paren)) + return TT_BinaryOperator; + // This catches some cases where evaluation order is used as control flow: // aaa && aaa->f(); const FormatToken *NextNextToken = NextToken->getNextNonComment(); diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 37bd517867..163f0838c9 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5030,6 +5030,11 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyFormat("foo();"); verifyFormat("foo();"); verifyFormat("decltype(*::std::declval()) void F();"); + verifyFormat( + "template ::value &&\n" + " (sizeof(T) > 1 || sizeof(T) < 8)>::type>\n" + "void F();"); verifyIndependentOfContext("MACRO(int *i);"); verifyIndependentOfContext("MACRO(auto *a);");