[cfe-dev] missing optimization opportunity for const std::vector compared to std::array

James Dennett james.dennett at gmail.com
Thu Jun 5 10:29:36 PDT 2014


On Thu, Jun 5, 2014 at 3:01 AM, Dennis Luehring <dl.soluz at gmx.net> wrote:
> Am 31.05.2014 16:14, schrieb Marshall Clow:
>
>> > but i do not understand why its so hard to track overridden allocations
>> > - or why
>> > they can't be removed - in the end there is an malloc/free or
>> > __builtin_operator_new/delete
>>
>> Well, consider the following code:
>>
>>         int * foo () { return new int; }
>>
>> Does that call the default operator new?
>> Or some overridden one?
>
>
> and why is then clang 3.4.1
> even without Richard Smith latest patch with __builtin_operator_new/delete
> allowed to remove this new?
>
> #include <memory>
>
> int main()
> {
>   return *new int(10);
> }

That's using the new operator, which can be optimized away even when
operator new cannot be.  (The new operator will use operator new if
needed, but it may not need to.)

-- James



More information about the cfe-dev mailing list