r373059 - Revert r373056: [clang-format] Reference qualifiers in member templates causing extra indentation

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 27 02:49:20 PDT 2019


Author: ibiryukov
Date: Fri Sep 27 02:49:20 2019
New Revision: 373059

URL: http://llvm.org/viewvc/llvm-project?rev=373059&view=rev
Log:
Revert r373056: [clang-format] Reference qualifiers in member templates causing extra indentation

Reason: this breaks unit tests.

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373059&r1=373058&r2=373059&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Sep 27 02:49:20 2019
@@ -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

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373059&r1=373058&r2=373059&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Sep 27 02:49:20 2019
@@ -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




More information about the cfe-commits mailing list