A mechanized semantics for C++ object construction and destruction, with applications to resource management