@@ -149,6 +149,11 @@ struct policy_queries {
149149 !Policy::eoft_constructor_takes_control_block;
150150 }
151151
152+ // / Is @ref basic_enable_observer_from_this guaranteed to always have a valid block pointer?
153+ static constexpr bool eoft_always_has_block () noexcept {
154+ return eoft_constructor_allocates () || eoft_base_constructor_needs_block ();
155+ }
156+
152157 // / Does @ref basic_observable_ptr allow releasing and acquiring raw pointers?
153158 static constexpr bool owner_allow_release () noexcept {
154159 return !Policy::is_sealed;
@@ -1521,19 +1526,15 @@ class basic_enable_observer_from_this :
15211526 * the object was allocated on the stack, or if it is owned by another
15221527 * type of smart pointer, then this function will return nullptr.
15231528 */
1524- observer_type observer_from_this () noexcept (
1525- queries::eoft_constructor_allocates () || queries::eoft_base_constructor_needs_block()) {
1526-
1529+ observer_type observer_from_this () noexcept (queries::eoft_always_has_block()) {
15271530 static_assert (
15281531 std::is_base_of_v<basic_enable_observer_from_this, std::decay_t <T>>,
15291532 " T must inherit from basic_enable_observer_from_this<T>" );
15301533
1531- if constexpr (
1532- !queries::eoft_constructor_allocates () &&
1533- !queries::eoft_base_constructor_needs_block ()) {
1534+ if constexpr (!queries::eoft_always_has_block ()) {
15341535 // This check is not needed if the constructor allocates or if we ask for the
15351536 // control block in the constructor; then we always have a valid control block and
1536- // this cannot fail.
1537+ // this function cannot fail.
15371538 if (!this ->this_control_block ) {
15381539 throw bad_observer_from_this{};
15391540 }
@@ -1549,19 +1550,15 @@ class basic_enable_observer_from_this :
15491550 * the object was allocated on the stack, or if it is owned by another
15501551 * type of smart pointer, then this function will return nullptr.
15511552 */
1552- const_observer_type observer_from_this () const noexcept (
1553- queries::eoft_constructor_allocates () || queries::eoft_base_constructor_needs_block()) {
1554-
1553+ const_observer_type observer_from_this () const noexcept (queries::eoft_always_has_block()) {
15551554 static_assert (
15561555 std::is_base_of_v<basic_enable_observer_from_this, std::decay_t <T>>,
15571556 " T must inherit from basic_enable_observer_from_this<T>" );
15581557
1559- if constexpr (
1560- !queries::eoft_constructor_allocates () &&
1561- !queries::eoft_base_constructor_needs_block ()) {
1558+ if constexpr (!queries::eoft_always_has_block ()) {
15621559 // This check is not needed if the constructor allocates or if we ask for the
15631560 // control block in the constructor; then we always have a valid control block and
1564- // this cannot fail.
1561+ // this function cannot fail.
15651562 if (!this ->this_control_block ) {
15661563 throw bad_observer_from_this{};
15671564 }
0 commit comments