Re: Optimizing away deletion of null pointers with g++

2017-08-16 Thread Jeff Law
On 08/16/2017 08:44 AM, Jonathan Wakely wrote: > On 16 August 2017 at 15:40, Jonathan Wakely wrote: >> On 16 August 2017 at 15:27, Oleg Endo wrote: >>> On Wed, 2017-08-16 at 13:30 +0200, Paolo Carlini wrote: I didn't understand why we don't already handle the easy case: constexp

Re: Optimizing away deletion of null pointers with g++

2017-08-16 Thread Jonathan Wakely
On 16 August 2017 at 15:40, Jonathan Wakely wrote: > On 16 August 2017 at 15:27, Oleg Endo wrote: >> On Wed, 2017-08-16 at 13:30 +0200, Paolo Carlini wrote: >>> >>> I didn't understand why we don't already handle the easy case: >>> >>> constexpr int* ptr = nullptr; >>> delete ptr; >>> >> >> What ab

Re: Optimizing away deletion of null pointers with g++

2017-08-16 Thread Jonathan Wakely
On 16 August 2017 at 15:27, Oleg Endo wrote: > On Wed, 2017-08-16 at 13:30 +0200, Paolo Carlini wrote: >> >> I didn't understand why we don't already handle the easy case: >> >> constexpr int* ptr = nullptr; >> delete ptr; >> > > What about overriding the global delete operator with some user defin

Re: Optimizing away deletion of null pointers with g++

2017-08-16 Thread Oleg Endo
On Wed, 2017-08-16 at 13:30 +0200, Paolo Carlini wrote: >  > I didn't understand why we don't already handle the easy case: > > constexpr int* ptr = nullptr; > delete ptr; > What about overriding the global delete operator with some user defined implementation?  Is there something in the C++ sta

Re: Optimizing away deletion of null pointers with g++

2017-08-16 Thread Paolo Carlini
Hi, On 16/08/2017 12:09, Daniel Langr wrote: When compiling the following code: int* ptr = nullptr; delete ptr; I didn't understand why we don't already handle the easy case: constexpr int* ptr = nullptr; delete ptr; and the below tiny front-end tweak would take care of it. But I'm not sure

Re: Optimizing away deletion of null pointers with g++

2017-08-16 Thread Richard Biener
On Wed, Aug 16, 2017 at 12:09 PM, Daniel Langr wrote: > When compiling the following code: > > int* ptr = nullptr; > delete ptr; > > GCC 7.1 on x86_64 generates a delete-operator-related call instruction in > the resulting program with both -O2 and -O3 optimization flags. This is a > nonsense piec

Optimizing away deletion of null pointers with g++

2017-08-16 Thread Daniel Langr
When compiling the following code: int* ptr = nullptr; delete ptr; GCC 7.1 on x86_64 generates a delete-operator-related call instruction in the resulting program with both -O2 and -O3 optimization flags. This is a nonsense piece of code, indeed, but imagine a class that has an owning raw poin