diff --git a/src/violations.cpp b/src/violations.cpp index ee4b5e7..7a6fa1e 100644 --- a/src/violations.cpp +++ b/src/violations.cpp @@ -1,27 +1,17 @@ -// violations.cpp -#include - -class Unsafe { - int *p; +// src/violations.cpp +class Test { public: - Unsafe() { // Constructor throws without handling - p = new int(42); - if (*p == 42) - throw std::runtime_error("ERR51: unhandled exception"); // triggers ERR51-CPP + int *ptr; + Test() { + ptr = new int(10); } - - ~Unsafe() noexcept { // Destructor references deleted memory - delete p; - int x = *p; // ERR53-CPP: value referenced after destruction - (void)x; + ~Test() { + delete ptr; + int x = *ptr; // ❗ Use-after-delete: triggers ERR53-CPP } }; int main() { - try { - Unsafe u; // construction will throw - } catch (...) { - // Intentionally empty to keep program running - } + Test t; return 0; }