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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-08
     Ever confirmed|0                           |1

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Or just (untested):

--- 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&
+     static _Tp&
      _S_ref(const _Type&, std::size_t) noexcept
-     { return *static_cast<_Tp*>(nullptr); }
+     { return reinterpret_cast<_Tp&>(const_cast<_Type&>(t)); }
    };

   /**

It's undefined to refer to the element in the zero-size case, so casting to an
incompatible reference type shouldn't matter as noone will ever access anything
through that reference.


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