PING: [PATCH] Improve message 'Undefined allocation of 0 bytes'

Jordan Rose jordan_rose at apple.com
Wed Apr 23 12:10:28 PDT 2014


On Apr 23, 2014, at 11:18 , Arthur O'Dwyer <arthur.j.odwyer at gmail.com> wrote:

> On Wed, Apr 23, 2014 at 9:54 AM, Daniel Marjamäki
> <Daniel.Marjamaki at evidente.se> wrote:
>> Jordan Rose wrote:
>>> 
>>> How about "allocation of 0 bytes has unspecified behavior"? It's a bit more wordy,
>>> but it also sounds more like something to pay attention to.
>> 
>> [...]
>> If you think "unspecified behaviour" is better I will happily change it.
> 
> Since the raison d'etre of this patch is that the current warning
> message is technically incorrect,
> IMHO it would be a mistake to change the message to something that is
> *equally* incorrect.
> 
> From N1570 (the publicly available C11 draft standard):
> ] If the size of the space requested is zero, the behavior is
> implementation-defined:
> ] either a null pointer is returned, or the behavior is as if the size
> were some nonzero value,
> ] except that the returned pointer shall not be used to access an object.
> 
> The difference between "unspecified" and "implementation-defined" is
> that conforming implementations MUST document their choices re
> "implementation-defined" behavior, whereas "unspecified" behavior
> might change capriciously even within a single run of the same
> program.
> 
> 
> Jordan Rose wrote:
>>> (I thought about "implementation-defined behavior" as well, but I'm not sure that's strong
>>> enough either...people might just assume they know how their own implementation works.
>>> Then again, it is documented for many platforms.)
> 
> It's documented by *all* conforming C implementations, by definition.
> Of course in practice this just means that the vast majority of C
> implementations aren't conforming. ;)

I find "unspecified" to be "less incorrect" than the current "undefined", since implementation-defined behavior is a subset of unspecified behavior: "unspecified behavior where each implementation documents how the choice is made" (C11 3.4.1p1)

But really I just wanted to make sure it's still clear that the message isn't (necessarily) theoretical, and "non-portable" to me sounds too easy to dismiss out of hand. I'm happy with whatever massaging we can come up with.

Jordan



More information about the cfe-commits mailing list