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:09:00 +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
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.