Skip to content

Commit 01174ff

Browse files
authored
Remove unneeded checks for null; NFC (#145686)
At the start of the case for `tok::colon`, we do an early return if `Prev` is null. Nothing else within that case modifies the value of `Prev`, so the checks for null are unnecessary and were confusing static analysis tools.
1 parent d16f42d commit 01174ff

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ class AnnotatingParser {
13711371
Tok->setType(TT_InlineASMColon);
13721372
} else if (Contexts.back().ColonIsDictLiteral || Style.isProto()) {
13731373
Tok->setType(TT_DictLiteral);
1374-
if (Prev && Style.isTextProto())
1374+
if (Style.isTextProto())
13751375
Prev->setType(TT_SelectorName);
13761376
} else if (Contexts.back().ColonIsObjCMethodExpr ||
13771377
Line.startsWith(TT_ObjCMethodSpecifier)) {
@@ -1408,7 +1408,6 @@ class AnnotatingParser {
14081408
}
14091409
} else if (Contexts.back().ContextType == Context::C11GenericSelection) {
14101410
Tok->setType(TT_GenericSelectionColon);
1411-
assert(Prev);
14121411
if (Prev->isPointerOrReference())
14131412
Prev->setFinalizedType(TT_PointerOrReference);
14141413
} else if ((CurrentToken && CurrentToken->is(tok::numeric_constant)) ||
@@ -1419,8 +1418,6 @@ class AnnotatingParser {
14191418
!Line.getFirstNonComment()->isOneOf(tok::kw_enum, tok::kw_case,
14201419
tok::kw_default) &&
14211420
!Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
1422-
if (!Prev)
1423-
break;
14241421
if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
14251422
Prev->ClosesRequiresClause) {
14261423
Tok->setType(TT_CtorInitializerColon);

0 commit comments

Comments
 (0)