]> granicus.if.org Git - clang/commitdiff
clang-format: Improve && detection as binary operators.
authorDaniel Jasper <djasper@google.com>
Tue, 28 Oct 2014 18:11:52 +0000 (18:11 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 28 Oct 2014 18:11:52 +0000 (18:11 +0000)
Before:
  template <class T, class = typename std::enable_if<std::is_integral<
                         T>::value &&(sizeof(T) > 1 || sizeof(T) < 8)>::type>
  void F();

After:
  template <class T, class = typename std::enable_if<
                         std::is_integral<T>::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

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTest.cpp

index ff0af5a08c5bbcbd3e57fc27f74fa8b53188f0e5..14d164e2ae7152a8cb6585ec579eda963abff641 100644 (file)
@@ -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();
index 37bd5178674231dc39de8f1010402799b3e75c50..163f0838c9ef3c91b79e691f869bfd2f1d431c62 100644 (file)
@@ -5030,6 +5030,11 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("foo<b && false>();");
   verifyFormat("foo<b & 1>();");
   verifyFormat("decltype(*::std::declval<const T &>()) void F();");
+  verifyFormat(
+      "template <class T, class = typename std::enable_if<\n"
+      "                       std::is_integral<T>::value &&\n"
+      "                       (sizeof(T) > 1 || sizeof(T) < 8)>::type>\n"
+      "void F();");
 
   verifyIndependentOfContext("MACRO(int *i);");
   verifyIndependentOfContext("MACRO(auto *a);");