[cfe-commits] Initializer bug with fix?

Aaron Ballman aaron at aaronballman.com
Sat Jan 14 16:36:30 PST 2012


On Sat, Jan 14, 2012 at 6:24 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Sat, Jan 14, 2012 at 2:47 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
>> While chasing butterflies recently, I noticed the code generated by
>> clang didn't match what was created by MSVC and ICC (but does match
>> what gcc was emitting).  Here's a simplified C++ example:
>>
>> void *operator new( unsigned int size );  // note, non-throwing
>
> Per [basic.stc.dynamic.allocation]p3, an operator new which isn't
> marked throw() or noexcept is required to either succeed or throw an
> exception matching std::bad_alloc.  clang takes advantage of this by
> skipping the null check.

Good to know, thank you for pointing that out!

> Do you have some specific concern about code which doesn't follow the standard?

I just happened to notice the codegen difference for different
reasons, but can imagine a fair amount of code which totally screws up
operator new overloading, such as writing debugging code using malloc,
but failing to specify throw().  Eg)

void *operator new( size_t size ) {
  unsigned char *ret = (unsigned char *)::malloc( size + 4 );
  *((long *)ret) = kSpecialValue;
  return (ret + 4);
}

~Aaron




More information about the cfe-commits mailing list