This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/65352] array<T,0>::begin()/end() etc. forms a null reference and breaks on clang+ubsan


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]