This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

Re: PR 57779 New debug check


On 11 July 2013 21:49, Jonathan Wakely wrote:
> On 11 July 2013 21:16, François Dumont wrote:
>>     I am indeed dereferencing the end iterator but as long as it is just to
>> get the address of the resulting element it is fine.
>
> I don't think that's what the standard says.
>
> C99 and later say that &*p is OK if p is a null pointer, but C++ does
> not have the same rule, see e.g.
> http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#232 for an
> open issue on this topic.  Even if that proposed resolution were to be
> accepted (very unlikely, it's sat untouched for many years) what
> you're doing is not the same, because you dereference an iterator
> which returns a reference, and _then_ you take the address, so it's
> equivalent to:
>
> T& end() { T* p = 0; return *p; }
> T* p = &end();
>
> That forms an invalid reference before taking the address, so is not
> the same as &*(T*)0, it's more like &(T&)*(T*)0 and I'm uncomfortable
> with that.

... but willing to be convinced if I'm wrong :-)


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