Skip to content

Commit

Permalink
Remove ABI-incompatible assertion code in any_view.hpp
Browse files Browse the repository at this point in the history
If a provider of an any_view is built without NDEBUG defined, but a
consumer is built with NDEBUG defined, the consumer will crash due to
ABI-incompatibility in any_ref.

Repros on clang with sanitizers, and that's an easily shareable demo:
  https://godbolt.org/z/Go9qxnjrM

Can't get it to repro with a small example in gcc, even with sanitizers

Repros in a small example on windows with msvc using same cpp/hpp files
as above link - usually assertion failure in the assertion that this
commit removes, sometimes Access Violation, but always crashes one way
or another. No sanitizers needed to get a crash with msvc. It's just
not easily shareable.
  • Loading branch information
Matt Beardsley committed Apr 22, 2024
1 parent 53c40dd commit fbfb4c3
Showing 1 changed file with 0 additions and 7 deletions.
7 changes: 0 additions & 7 deletions include/range/v3/view/any_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,15 @@ namespace ranges
template<typename T>
constexpr any_ref(T & obj) noexcept
: obj_(detail::addressof(obj))
#ifndef NDEBUG
, info_(&typeid(rtti_tag<T>))
#endif
{}
template<typename T>
T & get() const noexcept
{
RANGES_ASSERT(obj_ && info_ && *info_ == typeid(rtti_tag<T>));
return *const_cast<T *>(static_cast<T const volatile *>(obj_));
}

private:
void const volatile * obj_ = nullptr;
#ifndef NDEBUG
std::type_info const * info_ = nullptr;
#endif
};

template<typename Base>
Expand Down

0 comments on commit fbfb4c3

Please sign in to comment.