diff options
author | mydeveloperday <mydeveloperday@gmail.com> | 2022-03-05 18:07:16 +0000 |
---|---|---|
committer | mydeveloperday <mydeveloperday@gmail.com> | 2022-03-05 18:08:25 +0000 |
commit | 28bb040ded83b7cffdd6e6102080ccbe7935dbfe (patch) | |
tree | 298cbca47dd3cff4430830ee92e016d3781e5f0a /clang/lib/Format/QualifierAlignmentFixer.cpp | |
parent | 9b03c08e8517ed2d95a91202744d07f7376848a9 (diff) | |
download | llvm-28bb040ded83b7cffdd6e6102080ccbe7935dbfe.zip llvm-28bb040ded83b7cffdd6e6102080ccbe7935dbfe.tar.gz llvm-28bb040ded83b7cffdd6e6102080ccbe7935dbfe.tar.bz2 |
[clang-format] QualifierOrder does not reorder template arguments
https://github.com/llvm/llvm-project/issues/53981
Reorder the qualifiers inside the template argument. This should handle the simple cases of
```
<const T>
<T const>
```
But only by relaxing that single letter capital variables are not possible macros
Fixes: #53981
Reviewed By: HazardyKnusperkeks, curdeius
Differential Revision: https://reviews.llvm.org/D120710
Diffstat (limited to 'clang/lib/Format/QualifierAlignmentFixer.cpp')
-rw-r--r-- | clang/lib/Format/QualifierAlignmentFixer.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index aff5562..7480202 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -224,6 +224,12 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false); Tok = LastQual; } else if (Tok->startsSequence(QualifierType, tok::identifier, + TT_TemplateCloser)) { + FormatToken *Closer = Tok->Next->Next; + rotateTokens(SourceMgr, Fixes, Tok, Tok->Next, /*Left=*/false); + Tok = Closer; + return Tok; + } else if (Tok->startsSequence(QualifierType, tok::identifier, TT_TemplateOpener)) { // Read from the TemplateOpener to // TemplateCloser as in const ArrayRef<int> a; const ArrayRef<int> &a; @@ -307,6 +313,11 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft( rotateTokens(SourceMgr, Fixes, Tok, Tok->Next, /*Left=*/true); Tok = Tok->Next; } + } else if (Tok->startsSequence(tok::identifier, QualifierType, + TT_TemplateCloser)) { + FormatToken *Closer = Tok->Next->Next; + rotateTokens(SourceMgr, Fixes, Tok, Tok->Next, /*Left=*/true); + Tok = Closer; } } if (Tok->is(TT_TemplateOpener) && Tok->Next && @@ -329,8 +340,12 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeLeft( Next = Next->getNextNonComment(); assert(Next->MatchingParen && "Missing template closer"); Next = Next->MatchingParen; + + // If the template closer is closing the requires clause, + // then stop and go back to the TemplateOpener and do whatever is + // inside the <>. if (Next->ClosesRequiresClause) - return Next; + return Next->MatchingParen; Next = Next->Next; // Move to the end of any template class members e.g. @@ -461,7 +476,8 @@ bool LeftRightQualifierAlignmentFixer::isPossibleMacro(const FormatToken *Tok) { if (!Tok->is(tok::identifier)) return false; if (Tok->TokenText.upper() == Tok->TokenText.str()) - return true; + // T,K,U,V likely could be template arguments + return (Tok->TokenText.size() != 1); return false; } |