[CC += Martin Sebor] Hi Eugene,
On Wed, Dec 17, 2025 at 04:37:30PM +0100, Eugene Syromyatnikov wrote: > On Wed, Dec 17, 2025 at 3:42 PM Eugene Syromyatnikov <[email protected]> wrote: > > > > On Wed, Dec 17, 2025 at 2:51 PM Alejandro Colomar <[email protected]> wrote: > > > > > > > +Otherwise, > > > +the behavior was undefined. > > > > I think this statement is incorrect, or at least misleading, because > > the current reading (that includes DR460) of ISO 9899:2011 explicitly > > states that the function must fail when the condition is not satisfied > > (and that is what OpenBSD has implemented), and that also makes any > > permissive specification non-conforming wrt C11 as it is now. But that > > is also true that C11 _used to_ specify a failure to conform to this > > onerous restriction as UB, which rendered the programs malformed, but, > > on the other hand, kept libcs that implemented it permissively > > standard-conformant. > > > > I understand that I am unnecessarily conscientious here, but I think > > it is important to articulate what the standard both says and used to > > say, as it is the reference point for the language implementations, > > the totality of which an application developer can neither observe nor > > inspect, and relying on a couple of anecdotes in terms of > > implementations may lead to issues down the road. I guess the outcome > > of my rants is "don't use aligned_alloc and C11 together", or > > something along those lines. > > Correction: I was thinking that there was a published TR similar to > C++, but apparently there wasn't, so the UB-including wording has > never updated in publicly-available iterations of C11, the next > published version, that is C17, has removed the requirement > altogether, and the version with the > failing-on-size-non-multiple-of-alignment requirement was never > publicly available similar to the ways standard drafts are, while > technically the wording existed for two years before the adoption of > N2072, hence my blabber about the "final version of C11" is > nonsensical; however, the point about the standard requiring three > different things still stands. My apologies for the excessive noise. > Let's see if I'm following: C11 (or at least, the draft that I know of, which is n1570) has two cases of UB for aligned_alloc(3): - size is not multiple of alignment - alignment is unsupported (often, this means not a power of two) <https://port70.net/~nsz/c/c11/n1570.html#7.22.3.1p2> DR460 (2014) reported both cases of UB, and fixed them with a TC. <https://www.open-std.org/jtc1/sc22/wg14/www/docs/summary.htm#dr_460> N2072 (2016) reported that the restriction that the size is not a multiple of alignment is superfluous, and fixed it with a TC. <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2072.htm> C17 (or at least, the draft that I know of, which is n2176) is the first standard that incorporates both DR460 and N2076. While C17 is a different standard, it is actually a bugfix release, and both DR460 and N2072 are meant to retroactively affect C11, so all conforming implementations of C11 should in fact be conforming to C17 and not C11. However, OpenBSD conforms to C11+DR460, but not C17. From what you said, FreeBSD seems to conform to C17, but it claims to conform to C11. Please correct me if I'm wrong. Have a lovely night! Alex -- <https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature

