@@ -3682,17 +3682,17 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
36823682 const FormatToken &Current,
36833683 const AnnotatedLine &Line,
36843684 FormatToken *&ClosingParen) {
3685- assert (Current.Previous );
3686-
36873685 if (Current.is (TT_FunctionDeclarationName))
36883686 return true ;
36893687
36903688 if (!Current.Tok .getIdentifierInfo ())
36913689 return false ;
36923690
3693- const auto &Previous = *Current.Previous ;
3691+ const auto *Prev = Current.getPreviousNonComment ();
3692+ assert (Prev);
3693+ const auto &Previous = *Prev;
36943694
3695- if (const auto *PrevPrev = Previous.Previous ;
3695+ if (const auto *PrevPrev = Previous.getPreviousNonComment () ;
36963696 PrevPrev && PrevPrev->is (TT_ObjCDecl)) {
36973697 return false ;
36983698 }
@@ -3859,20 +3859,20 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
38593859 First->TotalLength = First->IsMultiline
38603860 ? Style.ColumnLimit
38613861 : Line.FirstStartColumn + First->ColumnWidth ;
3862- FormatToken *Current = First->Next ;
3863- bool InFunctionDecl = Line.MightBeFunctionDecl ;
38643862 bool AlignArrayOfStructures =
38653863 (Style.AlignArrayOfStructures != FormatStyle::AIAS_None &&
38663864 Line.Type == LT_ArrayOfStructInitializer);
38673865 if (AlignArrayOfStructures)
38683866 calculateArrayInitializerColumnList (Line);
38693867
3868+ const auto *FirstNonComment = Line.getFirstNonComment ();
38703869 bool SeenName = false ;
38713870 bool LineIsFunctionDeclaration = false ;
3872- FormatToken *ClosingParen = nullptr ;
38733871 FormatToken *AfterLastAttribute = nullptr ;
3872+ FormatToken *ClosingParen = nullptr ;
38743873
3875- for (auto *Tok = Current; Tok; Tok = Tok->Next ) {
3874+ for (auto *Tok = FirstNonComment ? FirstNonComment->Next : nullptr ; Tok;
3875+ Tok = Tok->Next ) {
38763876 if (Tok->is (TT_StartOfName))
38773877 SeenName = true ;
38783878 if (Tok->Previous ->EndsCppAttributeGroup )
@@ -3894,7 +3894,9 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
38943894 }
38953895 }
38963896
3897- if (IsCpp && (LineIsFunctionDeclaration || First->is (TT_CtorDtorDeclName)) &&
3897+ if (IsCpp &&
3898+ (LineIsFunctionDeclaration ||
3899+ (FirstNonComment && FirstNonComment->is (TT_CtorDtorDeclName))) &&
38983900 Line.endsWith (tok::semi, tok::r_brace)) {
38993901 auto *Tok = Line.Last ->Previous ;
39003902 while (Tok->isNot (tok::r_brace))
@@ -3917,7 +3919,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
39173919 if (IsCpp) {
39183920 if (!LineIsFunctionDeclaration) {
39193921 // Annotate */&/&& in `operator` function calls as binary operators.
3920- for (const auto *Tok = First ; Tok; Tok = Tok->Next ) {
3922+ for (const auto *Tok = FirstNonComment ; Tok; Tok = Tok->Next ) {
39213923 if (Tok->isNot (tok::kw_operator))
39223924 continue ;
39233925 do {
@@ -3960,7 +3962,8 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
39603962 }
39613963 }
39623964
3963- while (Current) {
3965+ bool InFunctionDecl = Line.MightBeFunctionDecl ;
3966+ for (auto *Current = First->Next ; Current; Current = Current->Next ) {
39643967 const FormatToken *Prev = Current->Previous ;
39653968 if (Current->is (TT_LineComment)) {
39663969 if (Prev->is (BK_BracedInit) && Prev->opensScope ()) {
@@ -4050,13 +4053,11 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
40504053 } else {
40514054 Current->SplitPenalty += 20 * Current->BindingStrength ;
40524055 }
4053-
4054- Current = Current->Next ;
40554056 }
40564057
40574058 calculateUnbreakableTailLengths (Line);
40584059 unsigned IndentLevel = Line.Level ;
4059- for (Current = First; Current; Current = Current->Next ) {
4060+ for (auto * Current = First; Current; Current = Current->Next ) {
40604061 if (Current->Role )
40614062 Current->Role ->precomputeFormattingInfos (Current);
40624063 if (Current->MatchingParen &&
0 commit comments