This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/65352] array<T,0>::begin()/end() etc. forms a null reference and breaks on clang+ubsan
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 08 Mar 2015 18:13:38 +0000
- Subject: [Bug libstdc++/65352] array<T,0>::begin()/end() etc. forms a null reference and breaks on clang+ubsan
- Auto-submitted: auto-generated
- References: <bug-65352-4 at http dot gcc dot gnu dot org/bugzilla/>
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.