]> granicus.if.org Git - clang/commitdiff
clang-format: Fix false ObjC block detection.
authorDaniel Jasper <djasper@google.com>
Wed, 7 Oct 2015 03:43:10 +0000 (03:43 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 7 Oct 2015 03:43:10 +0000 (03:43 +0000)
Before:
  inline A operator^(const A &lhs, const A &rhs) {} int i;

After:
  inline A operator^(const A &lhs, const A &rhs) {}
  int i;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249517 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp

index 159e60bfe1559b2e6313b0689e141f75b644d4c1..634dbe970845e6283e5cdd9dc0591f71f9516639 100644 (file)
@@ -855,6 +855,11 @@ void UnwrappedLineParser::parseStructuralElement() {
     case tok::l_paren:
       parseParens();
       break;
+    case tok::kw_operator:
+      nextToken();
+      if (FormatTok->isBinaryOperator())
+        nextToken();
+      break;
     case tok::caret:
       nextToken();
       if (FormatTok->Tok.isAnyIdentifier() ||
index 6a265f3dd15dcf4c308249b6b5f4c13c2e3d7a64..ff9d2d473ffcb9dadc35c2c479f77882870da9c5 100644 (file)
@@ -5327,6 +5327,8 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
   verifyGoogleFormat("operator ::A();");
 
   verifyFormat("using A::operator+;");
+  verifyFormat("inline A operator^(const A &lhs, const A &rhs) {}\n"
+               "int i;");
 }
 
 TEST_F(FormatTest, UnderstandsFunctionRefQualification) {