#include <iostream>
struct L1 {
int value;
};
struct L2 {
L1 *value;
L2(L1 *value) : value(value) {}
~L2() { delete value; }
};
struct L3 {
L2 *value;
L3(L2 *value) : value(value) {}
~L3() { delete value; }
};
int main() {
auto l1 = new L1{ 5 };
auto l2 = new L2(l1);
auto l3 = new L3(l2);
delete l3;
std::cout << "got here!" << std::endl;
std::cout << l1->value << std::endl; // segfaults? -- no
std::cout << l2->value->value << std::endl; // segfaults?? -- no
return 0;
}
I would expect this code to segfault in the lines marked segfaults? ...
It actually just outputs 0... is this just because it's actually undefined behaviour?
I'm using programiz online C++ compiler
