[PATCH] D59546: [clang-format] structured binding in range for detected as Objective C
This revision was automatically updated to reflect the committed changes. Closed by commit rC356575: [clang-format] structured binding in range for detected as Objective C (authored by paulhoad, committed by ). Herald added a project: clang. Changed prior to commit: https://reviews.llvm.org/D59546?vs=191288&id=191524#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59546/new/ https://reviews.llvm.org/D59546 Files: lib/Format/TokenAnnotator.cpp unittests/Format/FormatTest.cpp Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -410,7 +410,10 @@ 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: unittests/Format/FormatTest.cpp === --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -12926,6 +12926,9 @@ 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, ...]]")); Index: lib/Format/TokenAnnotator.cpp === --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -410,7 +410,10 @@ 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: unittests/Format/FormatTest.cpp === --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -12926,6 +12926,9 @@ 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, ...]]")); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59546: [clang-format] structured binding in range for detected as Objective C
klimek accepted this revision. klimek added a comment. This revision is now accepted and ready to land. lg CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59546/new/ https://reviews.llvm.org/D59546 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D59546: [clang-format] structured binding in range for detected as Objective C
MyDeveloperDay created this revision. MyDeveloperDay added reviewers: djasper, klimek, JonasToth, reuk. MyDeveloperDay added a project: clang-tools-extra. 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 -- #include #include std::vector> C; void foo() { for (auto && [A,B] : C) { std::string D = A + B; } } The following code fixes this issue of incorrect detection https://reviews.llvm.org/D59546 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12924,6 +12924,9 @@ 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", Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -410,7 +410,10 @@ 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: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12924,6 +12924,9 @@ 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", Index: clang/lib/Format/TokenAnnotator.cpp === --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -410,7 +410,10 @@ 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; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits