Every looked at scope guard so far has a guard boolean variable. For example, see this discussion: The simplest and neatest c++11 ScopeGuard
But a simple guard works
You're observing the effects of Copy Elision (or Move Elision, in this case). Copy Elision is not guaranteed / mandatory, but usually performed by major compilers even when compiling w/o optimizations. Try gcc's -fno-elide-constructors to see it "break": http://melpon.org/wandbox/permlink/B73EuYYKGYFMnJtR