Re: Optimization Level
Re: Optimization Level
- Subject: Re: Optimization Level
- From: Jens Alfke <email@hidden>
- Date: Mon, 17 Oct 2016 11:45:17 -0700
> On Oct 17, 2016, at 11:35 AM, Raglan T. Tiger <email@hidden> wrote:
>
> void xxxxx::Clear(apointList &list)
> {
> if ( ! &list )
> return;
> }
It’s not valid for a C++ reference value to refer to null. So the optimizer is allowed to assume that `&list` is a non-null pointer, and the test in the `if` can never be true, and optimize out the whole `if` statement. You’ll need to restructure your code so that you never pass null values as references.
I ran into a similar situation a while ago, where I had a (nonvirtual) method that accepted a null receiver, i.e. it was safe to call `foo->bar()` even if `foo` was null because the method had a test `if(!this) return;`. But the C++ standard says that it’s illegal to call a method with a null receiver, so the optimizer removed the test.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden