diff --git a/src/object.cpp b/src/object.cpp index dc4602c7..1d586f49 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -104,24 +104,68 @@ void object::releaseWeak(utility::weak_ref_base* w) const ref object::thisRef() { +#if VMIME_DEBUG + if (m_strongCount == 0) + { + std::ostringstream oss; + oss << "ERROR: thisRef() MUST NOT be called from the object constructor." + << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl; + + throw std::runtime_error(oss.str()); + } +#endif // VMIME_DEBUG + return ref ::fromPtr(this); } ref object::thisRef() const { +#if VMIME_DEBUG + if (m_strongCount == 0) + { + std::ostringstream oss; + oss << "ERROR: thisRef() MUST NOT be called from the object constructor." + << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl; + + throw std::runtime_error(oss.str()); + } +#endif // VMIME_DEBUG + return ref ::fromPtr(this); } weak_ref object::thisWeakRef() { +#if VMIME_DEBUG + if (m_strongCount == 0) + { + std::ostringstream oss; + oss << "ERROR: thisWeakRef() MUST NOT be called from the object constructor." + << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl; + + throw std::runtime_error(oss.str()); + } +#endif // VMIME_DEBUG + return weak_ref (thisRef()); } weak_ref object::thisWeakRef() const { +#if VMIME_DEBUG + if (m_strongCount == 0) + { + std::ostringstream oss; + oss << "ERROR: thisWeakRef() MUST NOT be called from the object constructor." + << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl; + + throw std::runtime_error(oss.str()); + } +#endif // VMIME_DEBUG + return weak_ref (thisRef()); }