[Bug libstdc++/65352] array<T,0>::begin()/end() etc. forms a null reference and breaks on clang+ubsan
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Mar 8 18:13:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65352
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Oops, that should be:
--- a/libstdc++-v3/include/std/array
+++ b/libstdc++-v3/include/std/array
@@ -58,9 +58,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{
struct _Type { };
- static constexpr _Tp&
- _S_ref(const _Type&, std::size_t) noexcept
- { return *static_cast<_Tp*>(nullptr); }
+ static _Tp&
+ _S_ref(const _Type& __t, std::size_t) noexcept
+ { return reinterpret_cast<_Tp&>(const_cast<_Type&>(__t)); }
};
/**
I think it's OK to make it non-constexpr, because _S_ref only needs to be
constexpr for functions which access an element, which are also invalid for the
zero-size array.
More information about the Gcc-bugs
mailing list