cid c90840cf617c9bf940faa5838b3a286e8a657d5dcd5c72c23bcaef4f85b66e16 · original · open access · via openalex
Title: A Clang-Tidy Checker for Replacing Pointers with References Authors: Ábel Szauter; Norbert Pataki Venue: Advances in transdisciplinary engineering Year: 2026 Canonical: doi:10.3233/atde260478 URL: https://doi.org/10.3233/atde260478 Collector: openalex OA: true ABSTRACT C++ inherited raw pointers from the C language but also introduced references as a safer and more expressive alternative. Although references have been part of the language since the first C++ standard (C++98), many modern codebases still rely heavily on pointers. This often leads to situations where a pointer is used even though reassignment, nullability, or pointer arithmetic are not required, resulting in unnecessary defensive checks and APIs that do not clearly express intent. While this mismatch is well known, detecting reference-replaceable pointers manually in large projects is impractical. In this paper, we investigate the conditions under which a raw pointer can be safely replaced with a reference by examining the absence of nullability-related checks, verifying that objects are always initialized, analyzing declaration and comparison contexts, assessing how pointers are used as function parameters, and confirming that no pointer reassignment occurs. We also present a custom clang-tidy checker that warns the user when such a replacement is possible, and optionally provides an automatic fix-it to perform the transformation.