fix potential undefined behaviour

fix #19
This commit is contained in:
Evgeniy A. Dushistov
2017-07-04 22:30:26 +03:00
parent b4fc882f25
commit b2ced870ab
3 changed files with 9 additions and 17 deletions

View File

@@ -27,6 +27,14 @@ public:
}
}
friend inline bool operator==(const ResourceWrapper& lhs, nullptr_t) noexcept {
return !lhs.p_;
}
friend inline bool operator!=(const ResourceWrapper& lhs, nullptr_t) noexcept {
return !!lhs.p_;
}
friend inline T *get_impl(const ResourceWrapper& rw) {
return rw.p_;
}
@@ -39,21 +47,6 @@ private:
T *p_;
void free_resource() { if (p_) unref_res(p_); }
// Helper for enabling 'if (sp)'
struct Tester {
Tester() {}
private:
void operator delete(void*);
};
public:
// enable 'if (sp)'
operator Tester*() const {
if (!*this)
return 0;
static Tester t;
return &t;
}
};
namespace glib {