Enforcing Memory Safety in Modern C++ Through a Safe Subset and Static Analysis
Author
Term
4. term
Education
Publication year
2025
Submitted on
2025-05-29
Pages
21
Abstract
This thesis investigates how memory safety can be enforced in C++ by defining a conservative, safe subset of the language and applying static analysis. While modern C++ offers features and guidelines that support safer programming practices, these are not enforced by compilers and remain optional. To address this, the project introduces a static analysis, that detects lifetime violations and enforces exclusive access to mutable resources, similar to Rust’s borrow checker and lifetime model. This analysis is accompanied by a proof-of-concept implementation, CPlusPlusty, as a Clang plugin. The approach restricts unsafe constructs by default and uses an over-approximating analysis to ensure soundness. CPlusPlusty demonstrates that memory safety guarantees can be retrofitted onto modern C++ code. The results suggest that such guarantees can be achieved without major language extensions or alternative frontends, merely by applying static analysis and enforcing safer usage patterns within standard C++.
Keywords
C++ ; static analysis ; safety ; memory safety ; Rust ; pointer analysis
Documents
