diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/ExtractAPI/DeclarationFragments.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Format/QualifierAlignmentFixer.cpp | 17 | ||||
| -rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 5 |
4 files changed, 25 insertions, 10 deletions
diff --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp b/clang/lib/ExtractAPI/DeclarationFragments.cpp index 791afc1a9757..00138c14ddcc 100644 --- a/clang/lib/ExtractAPI/DeclarationFragments.cpp +++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp @@ -636,7 +636,10 @@ DeclarationFragmentsBuilder::getFragmentsForParam(const ParmVarDecl *Param) { DeclarationFragments::FragmentKind::InternalParam); } else { Fragments.append(std::move(TypeFragments)); - if (!T->isAnyPointerType() && !T->isBlockPointerType()) + // If the type is a type alias, append the space + // even if the underlying type is a pointer type. + if (T->isTypedefNameType() || + (!T->isAnyPointerType() && !T->isBlockPointerType())) Fragments.appendSpace(); Fragments .append(Param->getName(), diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp b/clang/lib/Format/QualifierAlignmentFixer.cpp index 441a37a4902b..cc59dbd13621 100644 --- a/clang/lib/Format/QualifierAlignmentFixer.cpp +++ b/clang/lib/Format/QualifierAlignmentFixer.cpp @@ -182,8 +182,11 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( // We only need to think about streams that begin with a qualifier. if (Tok->isNot(QualifierType)) return Tok; + + const auto *Next = Tok->getNextNonComment(); + // Don't concern yourself if nothing follows the qualifier. - if (!Tok->Next) + if (!Next) return Tok; // Skip qualifiers to the left to find what preceeds the qualifiers. @@ -247,9 +250,15 @@ const FormatToken *LeftRightQualifierAlignmentFixer::analyzeRight( }(); // Find the last qualifier to the right. - const FormatToken *LastQual = Tok; - while (isQualifier(LastQual->getNextNonComment())) - LastQual = LastQual->getNextNonComment(); + const auto *LastQual = Tok; + for (; isQualifier(Next); Next = Next->getNextNonComment()) + LastQual = Next; + + if (!LastQual || !Next || + (LastQual->isOneOf(tok::kw_const, tok::kw_volatile) && + Next->isOneOf(Keywords.kw_override, Keywords.kw_final))) { + return Tok; + } // If this qualifier is to the right of a type or pointer do a partial sort // and return. diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 934605733542..3df071a197c6 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2385,17 +2385,17 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() { const FormatToken *LeftSquare = FormatTok; nextToken(); if (Previous) { + const auto *PrevPrev = Previous->getPreviousNonComment(); + if (Previous->is(tok::star) && PrevPrev && PrevPrev->isTypeName(LangOpts)) + return false; if (Previous->closesScope()) { // Not a potential C-style cast. if (Previous->isNot(tok::r_paren)) return false; - const auto *BeforeRParen = Previous->getPreviousNonComment(); // Lambdas can be cast to function types only, e.g. `std::function<int()>` // and `int (*)()`. - if (!BeforeRParen || !BeforeRParen->isOneOf(tok::greater, tok::r_paren)) + if (!PrevPrev || !PrevPrev->isOneOf(tok::greater, tok::r_paren)) return false; - } else if (Previous->is(tok::star)) { - Previous = Previous->getPreviousNonComment(); } if (Previous && Previous->Tok.getIdentifierInfo() && !Previous->isOneOf(tok::kw_return, tok::kw_co_await, tok::kw_co_yield, diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index cc3cc0f6906c..ecc696c53922 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -1295,7 +1295,10 @@ void WhitespaceManager::alignArrayInitializers() { bool FoundComplete = false; for (unsigned InsideIndex = ChangeIndex + 1; InsideIndex < ChangeEnd; ++InsideIndex) { - if (Changes[InsideIndex].Tok == C.Tok->MatchingParen) { + const auto *Tok = Changes[InsideIndex].Tok; + if (Tok->is(tok::pp_define)) + break; + if (Tok == C.Tok->MatchingParen) { alignArrayInitializers(ChangeIndex, InsideIndex + 1); ChangeIndex = InsideIndex + 1; FoundComplete = true; |
