[cfe-dev] [LLVMdev] RFC: Adding attribute(nonnull) to things in libc++
David.Chisnall at cl.cam.ac.uk
Tue Jun 2 02:12:47 PDT 2015
On 1 Jun 2015, at 18:52, Marshall Clow <mclow.lists at gmail.com> wrote:
>> The generic entry text of the standard section. IMO this is a standard
>> bug and someone should *please* get it fixed. It is ridiculous that zero
>> sized operations are considered UB.
> That would require a change to the C standard, and, as far as I know, there are no current plans to issue a revised C standard.
Not necessarily. Other standards, such as POSIX, are free to define behaviour that is undefined or implementation defined in C. POSIX mandates that a char is exactly 8 bits, for example, which is IB in C. The goal of UB is to give freedom to implementors. Saying that NULL arguments to memcpy are UB does not mean that we are compelled to disallow them, it just means that:
- We don’t have to accept them.
- We don’t have to be consistent in whether we accept or reject them.
- We can choose to do whatever makes implementation easiest.
If the easiest thing is to permit them as long as the length is zero (it seems to be), then that’s a perfectly valid implementation of undefined behaviour.
It is also undefined behaviour whether pointer comparisons between different objects are stable, but for the most part they are (and a lot of code would break if they weren’t), because implementers have decided that this is the easiest implementation of this particular bit of UB.
More information about the cfe-dev