[clang-tidy] Fix crash in readability-function-cognitive-complexity on weak refs