Skip to content

Commit 9383b8d

Browse files
committed
Added compile-time checks for incorrect inheritance
1 parent 84cf5db commit 9383b8d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

include/oup/observable_unique_ptr.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,9 @@ class enable_observer_from_this : public virtual details::enable_observer_from_t
13241324
* type of smart pointer, then this function will return nullptr.
13251325
*/
13261326
observer_ptr<T> observer_from_this() {
1327+
static_assert(std::is_base_of_v<enable_observer_from_this,std::decay_t<T>>,
1328+
"T must inherit from enable_observer_from_this<T>");
1329+
13271330
return observer_ptr<T>{this_control_block,
13281331
this_control_block ? static_cast<T*>(this) : nullptr};
13291332
}
@@ -1335,6 +1338,9 @@ class enable_observer_from_this : public virtual details::enable_observer_from_t
13351338
* type of smart pointer, then this function will return nullptr.
13361339
*/
13371340
observer_ptr<const T> observer_from_this() const {
1341+
static_assert(std::is_base_of_v<enable_observer_from_this,std::decay_t<T>>,
1342+
"T must inherit from enable_observer_from_this<T>");
1343+
13381344
return observer_ptr<const T>{this_control_block,
13391345
this_control_block ? static_cast<const T*>(this) : nullptr};
13401346
}

0 commit comments

Comments
 (0)