1
votes
std::unique_ptr<Bar, void(*)(Bar*)> bar(new Bar(), [](Bar* b){ while(true); });

Declare it and immediately exit. Attempting to destruct it will cause the program to hang. Works for shared pointers too.

Yes, but you might as well just do while (true); without the smart pointer??HolyBlackCat
C++ won't prevent you from writing stupid programs. No language does.Mat
The person you can see in the mirror.Swift - Friday Pie
What's stopping me from sabotaging myself? Is that your question?sweenish
Also note that due to so-called Progress guarantee imposed by C++ language standard, such endless loops with no side effects cause the program to have undefined behavior, and thus may be completely optimized away, if compiler decides so, for example.heap underrun