diff options
author | Paul Hoad <mydeveloperday@gmail.com> | 2019-09-29 13:45:38 +0000 |
---|---|---|
committer | Paul Hoad <mydeveloperday@gmail.com> | 2019-09-29 13:45:38 +0000 |
commit | 83476b813e27f719139c5776d7eca35913363eb2 (patch) | |
tree | 01819a8629a16eae688fbd1c1736d3b5807003f5 /clang/lib/Format/TokenAnnotator.cpp | |
parent | 72b544e656b643135246c15cb334d09dca9851ac (diff) | |
download | bcm5719-llvm-83476b813e27f719139c5776d7eca35913363eb2.tar.gz bcm5719-llvm-83476b813e27f719139c5776d7eca35913363eb2.zip |
[clang-format] Reference qualifiers in member templates causing extra indentation.
Summary:
The following code
```
struct f {
template <class T>
void bar() && noexcept {}
};
```
will be formatted to the following with LLVM style, and
`AlwaysBreakTemplateDeclarations: Yes`
```
struct f {
template <class T>
void bar() && noexcept {}
};
```
The indentation of the `void bar()` line is wrong.
Reviewers: klimek, owenpan, krasimir, timwoj, MyDeveloperDay
Reviewed By: klimek, MyDeveloperDay
Subscribers: MyDeveloperDay, ilya-biryukov, llvm-commits, cfe-commits
Patch By: AndWass
Tags: #clang-format, #clang, #llvm
Differential Revision: https://reviews.llvm.org/D68072
llvm-svn: 373165
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index e584eec368d..91ac9822c8a 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), - Keywords(Keywords) { + TrailingReturnFound(false), Keywords(Keywords) { Contexts.push_back(Context(tok::unknown, 1, /*IsExpression=*/false)); resetTokenMetadata(CurrentToken); } @@ -1389,7 +1389,11 @@ private: } else if (Current.is(tok::arrow) && AutoFound && Line.MustBeDeclaration && Current.NestingLevel == 0) { Current.Type = TT_TrailingReturnArrow; - } else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) { + TrailingReturnFound = true; + } else if (Current.is(tok::star) || + (Current.isOneOf(tok::amp, tok::ampamp) && + (Current.NestingLevel != 0 || !Line.MightBeFunctionDecl || + TrailingReturnFound))) { Current.Type = determineStarAmpUsage(Current, Contexts.back().CanBeExpression && Contexts.back().IsExpression, @@ -1412,6 +1416,8 @@ private: Current.Type = TT_ConditionalExpr; } } else if (Current.isBinaryOperator() && + !(Line.MightBeFunctionDecl && Current.NestingLevel == 0 && + Current.isOneOf(tok::amp, tok::ampamp)) && (!Current.Previous || Current.Previous->isNot(tok::l_square)) && (!Current.is(tok::greater) && Style.Language != FormatStyle::LK_TextProto)) { @@ -1486,10 +1492,12 @@ 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) && + } else if (Current.isOneOf(tok::identifier, tok::kw_const, tok::amp, + tok::ampamp) && Current.Previous && !Current.Previous->isOneOf(tok::equal, tok::at) && - Line.MightBeFunctionDecl && Contexts.size() == 1) { + Line.MightBeFunctionDecl && !TrailingReturnFound && + Contexts.size() == 1) { // Line.MightBeFunctionDecl can only be true after the parentheses of a // function declaration have been found. Current.Type = TT_TrailingAnnotation; @@ -1767,6 +1775,7 @@ 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 @@ -2680,6 +2689,14 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, Right.MatchingParen->endsSequence(TT_DictLiteral, tok::at)) // Objective-C dictionary literal -> no space before closing brace. return false; + if (Right.Type == TT_TrailingAnnotation && + Right.isOneOf(tok::amp, tok::ampamp) && + Left.isOneOf(tok::kw_const, tok::kw_volatile) && + (!Right.Next || Right.Next->is(tok::semi))) + // Match const and volatile ref-qualifiers without any additional + // qualifiers such as + // void Fn() const &; + return Style.PointerAlignment != FormatStyle::PAS_Left; return true; } |