This allows all the tests to run. It is possible to inspect the exception by
breaking on __cxa_throw.
ref->DoThing();
}
+#define TEST_FUNC(fn) { #fn , Test##fn }
+
int main() {
- TestPtr();
+ struct {
+ const char* name;
+ void (*test)();
+ } kTests[] = {
+ TEST_FUNC(Reset),
+ TEST_FUNC(Move),
+ TEST_FUNC(Ptr),
+ };
+
+ for (const auto& test : kTests) {
+ std::cout << "=== BEGIN " << test.name << " ===" << std::endl;
+ try {
+ test.test();
+ std::cout << "=== FAIL " << test.name
+ << ": Did not receive UseAfterFreeException ===" << std::endl;
+ } catch (zc::UseAfterFreeError) {
+ std::cout << "=== PASS " << test.name << " ===" << std::endl;
+ }
+ }
}
#include <stdexcept>
+#include "zcpointer.h"
+
namespace zc {
namespace internal {
void RaiseUseAfterFree(const char* error) {
- throw std::logic_error(error);
+ throw zc::UseAfterFreeError(error);
}
} // namespace internal
#include <limits>
#include <memory>
#include <forward_list>
+#include <stdexcept>
namespace zc {
+class UseAfterFreeError : public std::logic_error {
+ public:
+ using std::logic_error::logic_error;
+};
+
#if defined(ZCPOINTER_TRACK_REFS) && ZCPOINTER_TRACK_REFS
template <typename T> class ref;