Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/unsafe.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
// src/unsafe.c
#include <stdio.h>
// violations.cpp
#include <stdexcept>

int global;
class Unsafe {
int *p;
public:
Unsafe() { // Constructor throws without handling
p = new int(42);
if (*p == 42)
throw std::runtime_error("ERR51: unhandled exception"); // triggers ERR51-CPP
}

int main(void) {
global = 42;
printf("%d\n", global);
~Unsafe() noexcept { // Destructor references deleted memory
delete p;
int x = *p; // ERR53-CPP: value referenced after destruction
(void)x;
}
};

int main() {
try {
Unsafe u; // construction will throw
} catch (...) {
// Intentionally empty to keep program running
}
return 0;
}