llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: Aaron Ballman (AaronBallman)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/145686.diff


1 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+1-4) 


``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d2f8b2703a9a3..6ad9a79998426 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1371,7 +1371,7 @@ class AnnotatingParser {
         Tok->setType(TT_InlineASMColon);
       } else if (Contexts.back().ColonIsDictLiteral || Style.isProto()) {
         Tok->setType(TT_DictLiteral);
-        if (Prev && Style.isTextProto())
+        if (Style.isTextProto())
           Prev->setType(TT_SelectorName);
       } else if (Contexts.back().ColonIsObjCMethodExpr ||
                  Line.startsWith(TT_ObjCMethodSpecifier)) {
@@ -1408,7 +1408,6 @@ class AnnotatingParser {
         }
       } else if (Contexts.back().ContextType == Context::C11GenericSelection) {
         Tok->setType(TT_GenericSelectionColon);
-        assert(Prev);
         if (Prev->isPointerOrReference())
           Prev->setFinalizedType(TT_PointerOrReference);
       } else if ((CurrentToken && CurrentToken->is(tok::numeric_constant)) ||
@@ -1419,8 +1418,6 @@ class AnnotatingParser {
                  !Line.getFirstNonComment()->isOneOf(tok::kw_enum, 
tok::kw_case,
                                                      tok::kw_default) &&
                  !Line.startsWith(tok::kw_typedef, tok::kw_enum)) {
-        if (!Prev)
-          break;
         if (Prev->isOneOf(tok::r_paren, tok::kw_noexcept) ||
             Prev->ClosesRequiresClause) {
           Tok->setType(TT_CtorInitializerColon);

``````````

</details>


https://github.com/llvm/llvm-project/pull/145686
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to