4 ms·
Here's a program that uses only std::unique_ptr: #include<iostream> #include<memory> int main() { std::unique_ptr<int> null_ptr; std
by steveklabnik 2y ago
Here's a program that uses only std::unique_ptr:
#include<iostream>
#include<memory>
int main() {
std::unique_ptr<int> null_ptr;
std::cout << *null_ptr << std::endl; // Undefined behavior
}
Clang 20 compiles this code with `-std=c++23 -Wall -Werror`. If you add -fsanitize=undefined, it will print
==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x55589736d8ea bp 0x7ffe04a94920 sp 0x7ffe04a948d0 T1)
or similar.