Index: clang/lib/Format/AffectedRangeManager.cpp =================================================================== --- clang/lib/Format/AffectedRangeManager.cpp +++ clang/lib/Format/AffectedRangeManager.cpp @@ -135,7 +135,7 @@ Line->First->NewlinesBefore == 0; bool IsContinuedComment = - Line->First->is(tok::comment) && Line->First->Next == nullptr && + Line->First->is(tok::comment) && !Line->First->Next && Line->First->NewlinesBefore < 2 && PreviousLine && PreviousLine->Affected && PreviousLine->Last->is(tok::comment); Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -614,7 +614,7 @@ State.NoContinuation = false; if ((Current.is(TT_ImplicitStringLiteral) && - (Previous.Tok.getIdentifierInfo() == nullptr || + (!Previous.Tok.getIdentifierInfo() || Previous.Tok.getIdentifierInfo()->getPPKeywordID() == tok::pp_not_keyword))) { unsigned EndColumn = @@ -1750,11 +1750,11 @@ NewState.BreakBeforeParameter = BreakBeforeParameter; NewState.HasMultipleNestedBlocks = (Current.BlockParameterCount > 1); - if (Style.BraceWrapping.BeforeLambdaBody && Current.Next != nullptr && + if (Style.BraceWrapping.BeforeLambdaBody && Current.Next && Current.is(tok::l_paren)) { // Search for any parameter that is a lambda. FormatToken const *next = Current.Next; - while (next != nullptr) { + while (next) { if (next->is(TT_LambdaLSquare)) { NewState.HasMultipleNestedBlocks = true; break; @@ -2169,7 +2169,7 @@ Current, StartColumn, Current.OriginalColumn, !Current.Previous, State.Line->InPPDirective, Encoding, Style, Whitespaces.useCRLF()); } else if (Current.is(TT_LineComment) && - (Current.Previous == nullptr || + (!Current.Previous || Current.Previous->isNot(TT_ImplicitStringLiteral))) { bool RegularComments = [&]() { for (const FormatToken *T = &Current; T && T->is(TT_LineComment); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -2454,7 +2454,7 @@ } bool containsOnlyComments(const AnnotatedLine &Line) { - for (FormatToken *Tok = Line.First; Tok != nullptr; Tok = Tok->Next) + for (FormatToken *Tok = Line.First; Tok; Tok = Tok->Next) if (Tok->isNot(tok::comment)) return false; return true; Index: clang/lib/Format/FormatToken.h =================================================================== --- clang/lib/Format/FormatToken.h +++ clang/lib/Format/FormatToken.h @@ -1552,7 +1552,7 @@ /// Returns \c true if \p Tok is a keyword or an identifier. bool isWordLike(const FormatToken &Tok) const { // getIdentifierinfo returns non-null for keywords as well as identifiers. - return Tok.Tok.getIdentifierInfo() != nullptr && + return Tok.Tok.getIdentifierInfo() && !Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe); } @@ -1715,7 +1715,7 @@ VerilogExtraKeywords.end(); default: // getIdentifierInfo returns non-null for both identifiers and keywords. - return Tok.Tok.getIdentifierInfo() != nullptr; + return Tok.Tok.getIdentifierInfo(); } } Index: clang/lib/Format/FormatToken.cpp =================================================================== --- clang/lib/Format/FormatToken.cpp +++ clang/lib/Format/FormatToken.cpp @@ -96,7 +96,7 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) { - if (State.NextToken == nullptr || !State.NextToken->Previous) + if (!State.NextToken || !State.NextToken->Previous) return 0; if (Formats.size() == 1) Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -45,7 +45,7 @@ /// invokes @selector(...)). So, we allow treat any identifier or /// keyword as a potential Objective-C selector component. static bool canBeObjCSelectorComponent(const FormatToken &Tok) { - return Tok.Tok.getIdentifierInfo() != nullptr; + return Tok.Tok.getIdentifierInfo(); } /// With `Left` being '(', check if we're at either `[...](` or @@ -1314,7 +1314,7 @@ Tok->Next->isNot(tok::l_paren)) { Tok->setType(TT_CSharpGenericTypeConstraint); parseCSharpGenericTypeConstraint(); - if (Tok->getPreviousNonComment() == nullptr) + if (!Tok->getPreviousNonComment()) Line.IsContinuation = true; } break; @@ -2824,7 +2824,7 @@ static unsigned maxNestingDepth(const AnnotatedLine &Line) { unsigned Result = 0; - for (const auto *Tok = Line.First; Tok != nullptr; Tok = Tok->Next) + for (const auto *Tok = Line.First; Tok; Tok = Tok->Next) Result = std::max(Result, Tok->NestingLevel); return Result; } @@ -3140,7 +3140,7 @@ calculateUnbreakableTailLengths(Line); unsigned IndentLevel = Line.Level; - for (Current = Line.First; Current != nullptr; Current = Current->Next) { + for (Current = Line.First; Current; Current = Current->Next) { if (Current->Role) Current->Role->precomputeFormattingInfos(Current); if (Current->MatchingParen && @@ -3180,10 +3180,10 @@ auto *CurrentToken = Line.First; CurrentToken->ArrayInitializerLineStart = true; unsigned Depth = 0; - while (CurrentToken != nullptr && CurrentToken != Line.Last) { + while (CurrentToken && CurrentToken != Line.Last) { if (CurrentToken->is(tok::l_brace)) { CurrentToken->IsArrayInitializer = true; - if (CurrentToken->Next != nullptr) + if (CurrentToken->Next) CurrentToken->Next->MustBreakBefore = true; CurrentToken = calculateInitializerColumnList(Line, CurrentToken->Next, Depth + 1); @@ -3195,14 +3195,14 @@ FormatToken *TokenAnnotator::calculateInitializerColumnList( AnnotatedLine &Line, FormatToken *CurrentToken, unsigned Depth) const { - while (CurrentToken != nullptr && CurrentToken != Line.Last) { + while (CurrentToken && CurrentToken != Line.Last) { if (CurrentToken->is(tok::l_brace)) ++Depth; else if (CurrentToken->is(tok::r_brace)) --Depth; if (Depth == 2 && CurrentToken->isOneOf(tok::l_brace, tok::comma)) { CurrentToken = CurrentToken->Next; - if (CurrentToken == nullptr) + if (!CurrentToken) break; CurrentToken->StartsColumn = true; CurrentToken = CurrentToken->Previous; Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1435,7 +1435,7 @@ Newlines = std::min(Newlines, 1u); } // Remove empty lines at the start of nested blocks (lambdas/arrow functions) - if (PreviousLine == nullptr && Line.Level > 0) + if (!PreviousLine && Line.Level > 0) Newlines = std::min(Newlines, 1u); if (Newlines == 0 && !RootToken.IsFirst) Newlines = 1; Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1166,7 +1166,7 @@ const FormatToken *FormatTok) { // FIXME: This returns true for C/C++ keywords like 'struct'. return FormatTok->is(tok::identifier) && - (FormatTok->Tok.getIdentifierInfo() == nullptr || + (!FormatTok->Tok.getIdentifierInfo() || !FormatTok->isOneOf( Keywords.kw_in, Keywords.kw_of, Keywords.kw_as, Keywords.kw_async, Keywords.kw_await, Keywords.kw_yield, Keywords.kw_finally, Index: clang/lib/Format/WhitespaceManager.h =================================================================== --- clang/lib/Format/WhitespaceManager.h +++ clang/lib/Format/WhitespaceManager.h @@ -294,7 +294,7 @@ calculateCellWidth(CellIter->Index, CellIter->EndIndex, true); if (Changes[CellIter->Index].NewlinesBefore == 0) CellWidth += NetWidth; - for (const auto *Next = CellIter->NextColumnElement; Next != nullptr; + for (const auto *Next = CellIter->NextColumnElement; Next; Next = Next->NextColumnElement) { auto ThisWidth = calculateCellWidth(Next->Index, Next->EndIndex, true); if (Changes[Next->Index].NewlinesBefore == 0) @@ -312,7 +312,7 @@ auto MaxNetWidth = getNetWidth(CellStart, CellStop, InitialSpaces); auto RowCount = 1U; auto Offset = std::distance(CellStart, CellStop); - for (const auto *Next = CellStop->NextColumnElement; Next != nullptr; + for (const auto *Next = CellStop->NextColumnElement; Next; Next = Next->NextColumnElement) { if (RowCount > MaxRowCount) break; Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -1172,7 +1172,7 @@ Changes[CellIter->Index].Spaces = (MaxNetWidth - ThisNetWidth); auto RowCount = 1U; auto Offset = std::distance(Cells.begin(), CellIter); - for (const auto *Next = CellIter->NextColumnElement; Next != nullptr; + for (const auto *Next = CellIter->NextColumnElement; Next; Next = Next->NextColumnElement) { auto *Start = (Cells.begin() + RowCount * CellDescs.CellCounts[0]); auto *End = Start + Offset; @@ -1191,7 +1191,7 @@ Changes[CellIter->Index].Spaces += (i > 0) ? 1 : 0; } alignToStartOfCell(CellIter->Index, CellIter->EndIndex); - for (const auto *Next = CellIter->NextColumnElement; Next != nullptr; + for (const auto *Next = CellIter->NextColumnElement; Next; Next = Next->NextColumnElement) { ThisWidth = calculateCellWidth(Next->Index, Next->EndIndex, true) + NetWidth; @@ -1233,7 +1233,7 @@ } auto RowCount = 1U; auto Offset = std::distance(Cells.begin(), CellIter); - for (const auto *Next = CellIter->NextColumnElement; Next != nullptr; + for (const auto *Next = CellIter->NextColumnElement; Next; Next = Next->NextColumnElement) { if (RowCount > CellDescs.CellCounts.size()) break; @@ -1253,7 +1253,7 @@ bool WhitespaceManager::isSplitCell(const CellDescription &Cell) { if (Cell.HasSplit) return true; - for (const auto *Next = Cell.NextColumnElement; Next != nullptr; + for (const auto *Next = Cell.NextColumnElement; Next; Next = Next->NextColumnElement) { if (Next->HasSplit) return true; @@ -1406,8 +1406,7 @@ WhitespaceManager::linkCells(CellDescriptions &&CellDesc) { auto &Cells = CellDesc.Cells; for (auto *CellIter = Cells.begin(); CellIter != Cells.end(); ++CellIter) { - if (CellIter->NextColumnElement == nullptr && - ((CellIter + 1) != Cells.end())) { + if (!CellIter->NextColumnElement && (CellIter + 1) != Cells.end()) { for (auto *NextIter = CellIter + 1; NextIter != Cells.end(); ++NextIter) { if (NextIter->Cell == CellIter->Cell) { CellIter->NextColumnElement = &(*NextIter);