diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2019-09-27 09:49:20 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2019-09-27 09:49:20 +0000 |
commit | 4627bdedd90de9b5fb9115ac2ffae83f5ce9096e (patch) | |
tree | 6663e2962676b5ce851075bbc6ae59f11aa4b86b | |
parent | b8cf059faccb794c47be6775f99457992ac6b2da (diff) | |
download | bcm5719-llvm-4627bdedd90de9b5fb9115ac2ffae83f5ce9096e.tar.gz bcm5719-llvm-4627bdedd90de9b5fb9115ac2ffae83f5ce9096e.zip |
Revert r373056: [clang-format] Reference qualifiers in member templates causing extra indentation
Reason: this breaks unit tests.
llvm-svn: 373059
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 16 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 35 |
2 files changed, 4 insertions, 47 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 918d5d3588b..e584eec368d 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -65,7 +65,7 @@ public: AnnotatingParser(const FormatStyle &Style, AnnotatedLine &Line, const AdditionalKeywords &Keywords) : Style(Style), Line(Line), CurrentToken(Line.First), AutoFound(false), - TrailingReturnFound(false), Keywords(Keywords) { + Keywords(Keywords) { Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false)); resetTokenMetadata(CurrentToken); } @@ -1389,10 +1389,7 @@ private: } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration && Current.NestingLevel == 0) { Current.Type = TT_TrailingReturnArrow; - TrailingReturnFound = true; - } else if (Current.is(tok::star) || - (Current.isOneOf(tok::amp, tok::ampamp) && - (!Line.MightBeFunctionDecl || TrailingReturnFound))) { + } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) { Current.Type = determineStarAmpUsage(Current, Contexts.back().CanBeExpression && Contexts.back().IsExpression, @@ -1415,8 +1412,6 @@ private: Current.Type = TT_ConditionalExpr; } } else if (Current.isBinaryOperator() && - !(Line.MightBeFunctionDecl && - Current.isOneOf(tok::amp, tok::ampamp)) && (!Current.Previous || Current.Previous->isNot(tok::l_square)) && (!Current.is(tok::greater) && Style.Language != FormatStyle::LK_TextProto)) { @@ -1491,12 +1486,10 @@ private: // colon after this, this is the only place which annotates the identifier // as a selector.) Current.Type = TT_SelectorName; - } else if (Current.isOneOf(tok::identifier, tok::kw_const, tok::amp, - tok::ampamp) && + } else if (Current.isOneOf(tok::identifier, tok::kw_const) && Current.Previous && !Current.Previous->isOneOf(tok::equal, tok::at) && - Line.MightBeFunctionDecl && !TrailingReturnFound && - Contexts.size() == 1) { + Line.MightBeFunctionDecl && Contexts.size() == 1) { // Line.MightBeFunctionDecl can only be true after the parentheses of a // function declaration have been found. Current.Type = TT_TrailingAnnotation; @@ -1774,7 +1767,6 @@ private: AnnotatedLine &Line; FormatToken *CurrentToken; bool AutoFound; - bool TrailingReturnFound; const AdditionalKeywords &Keywords; // Set of "<" tokens that do not open a template parameter list. If parseAngle diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index ecb3dddfdf8..581d15672ba 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -14373,41 +14373,6 @@ TEST_F(FormatTest, AmbersandInLamda) { verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle); } -TEST_F(FormatTest, RefQualifiedTemplateMember) { - FormatStyle AlignStyle = getLLVMStyle(); - AlignStyle.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_Yes; - - verifyFormat("struct f {\n" - " template <class T>\n" - " int &foo() & noexcept {}\n" - "};", - AlignStyle); - - verifyFormat("struct f {\n" - " template <class T>\n" - " int &foo() && noexcept {}\n" - "};", - AlignStyle); - - verifyFormat("struct f {\n" - " template <class T>\n" - " int &foo() const & noexcept {}\n" - "};", - AlignStyle); - - verifyFormat("struct f {\n" - " template <class T>\n" - " int &foo() const & noexcept {}\n" - "};", - AlignStyle); - - verifyFormat("struct f {\n" - " template <class T>\n" - " auto foo() && noexcept -> int & {}\n" - "};", - AlignStyle); -} - } // end namespace } // end namespace format } // end namespace clang |