https://github.com/bitcoin/bitcoin/blob/9ad6f14175c19b5d47267c3dd5840c14bad43c83/src/validation.cpp#L3711

If i'm following right the flow of the code, when we hit this lane `pindex` should be always equal to nullptr thus this check may be omitted
candidate_blocks_by_work.insert(std::make_pair(candidate->nChainWork, candidate));
            }
        }
    }
    
    while (true) {
        if (ShutdownRequested()) break;
        
        LimitValidationInterfaceQueue();
        LOCK(cs_main);
        LOCK(m_mempool.cs); 
        if (!m_chain.Contains(pindex)) break;
        pindex_was_in_chain = true;
        CBlockIndex *invalid_walk_tip = m_chain.Tip();
        
        
        DisconnectedBlockTransactions disconnectpool;
        bool ret = DisconnectTip(state, chainparams, &disconnectpool);
        
        
        
        
        
        UpdateMempoolForReorg(m_mempool, disconnectpool,  (++disconnected <= 10) && ret);
        if (!ret) return false;
        assert(invalid_walk_tip->pprev == m_chain.Tip());