diff options
author | Paul Hoad <mydeveloperday@gmail.com> | 2019-03-20 17:10:23 +0000 |
---|---|---|
committer | Paul Hoad <mydeveloperday@gmail.com> | 2019-03-20 17:10:23 +0000 |
commit | db1974197072634580cb043145a0a709634f23e8 (patch) | |
tree | f688cd942c2bf803bc892e5d4283c7bee24d9b24 | |
parent | 77bca6d29682f75c7103443166c76621120a6035 (diff) | |
download | bcm5719-llvm-db1974197072634580cb043145a0a709634f23e8.tar.gz bcm5719-llvm-db1974197072634580cb043145a0a709634f23e8.zip |
[clang-format] structured binding in range for detected as Objective C
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
llvm-svn: 356575
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 5 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 3 |
2 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index ef449e44c95..bd4591189f4 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 09c49b4408e..23ea8a8d8ed 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -12926,6 +12926,9 @@ TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) { 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", "[[clang::callable_when(\"unconsumed\", \"unknown\")]]")); EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]")); |