]> granicus.if.org Git - clang/commitdiff
[clang-format] structured binding in range for detected as Objective C
authorPaul Hoad <mydeveloperday@gmail.com>
Wed, 20 Mar 2019 17:10:23 +0000 (17:10 +0000)
committerPaul Hoad <mydeveloperday@gmail.com>
Wed, 20 Mar 2019 17:10:23 +0000 (17:10 +0000)
Summary:
Sometime after 6.0.0 and the current trunk 9.0.0 the following code would be considered as objective C and not C++

Reported by: https://twitter.com/mattgodbolt/status/1096188576503644160

$ clang-format.exe test.h
Configuration file(s) do(es) not support Objective-C: C:\clang\build\.clang-format

--- test.h --
```

std::vector<std::pair<std::string,std::string>> C;

void foo()
{
   for (auto && [A,B] : C)
   {
       std::string D = A + B;
   }
}
```
The following code fixes this issue of incorrect detection

Reviewers: djasper, klimek, JonasToth, reuk

Reviewed By: klimek

Subscribers: cfe-commits

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D59546

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

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

index ef449e44c9526bdd51b8f15a027bc54f2a4fc48d..bd4591189f43f4c2a082f313dc98875f6a42d140 100644 (file)
@@ -410,7 +410,10 @@ private:
          Parent->isUnaryOperator() ||
          // FIXME(bug 36976): ObjC return types shouldn't use TT_CastRParen.
          Parent->isOneOf(TT_ObjCForIn, TT_CastRParen) ||
-         getBinOpPrecedence(Parent->Tok.getKind(), true, true) > prec::Unknown);
+         // for (auto && [A,B] : C)  && structure binding seen as ObjCMethodExpr
+         (Parent->isNot(tok::ampamp) &&
+          getBinOpPrecedence(Parent->Tok.getKind(), true, true) >
+              prec::Unknown));
     bool ColonFound = false;
 
     unsigned BindingIncrease = 1;
index 09c49b4408e495c633f4a8d2b997f302c84f4957..23ea8a8d8edf6baacdbc2619bab5b0d1118f6752 100644 (file)
@@ -12924,6 +12924,9 @@ TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {
             guessLanguage("foo.h", "[[abusing clang:fallthrough] bar];"));
   EXPECT_EQ(FormatStyle::LK_Cpp,
             guessLanguage("foo.h", "[[using gsl: suppress(\"type\")]];"));
+  EXPECT_EQ(
+      FormatStyle::LK_Cpp,
+      guessLanguage("foo.h", "for (auto &&[endpoint, stream] : streams_)"));
   EXPECT_EQ(
       FormatStyle::LK_Cpp,
       guessLanguage("foo.h",