New C++ warning about comparing this==NULL
New C++ warning about comparing this==NULL
- Subject: New C++ warning about comparing this==NULL
- From: Jens Alfke <email@hidden>
- Date: Wed, 02 Dec 2015 11:22:52 -0800
In Xcode 7 some C++ code of mine has started being flagged with a new warning:
Value.cc:45:13: error: 'this' pointer cannot be null in well-defined C++ code; comparison may be assumed to always evaluate to false [-Werror,-Wtautological-undefined-compare] if (this == NULL) return kNull; ^~~~ ~~~~
Did one of the newer C++ standards declare that a non-virtual method call to a NULL receiver is undefined behavior? Seems like an odd decision, since a non-virtual call is just a normal function call with an implicit ‘this’ parameter. (Obviously dereferencing any member variables of ‘this’ will produce undefined behavior, i.e. a crash, which is why you’d do the above test first if this is a supported thing in your class.)
I know I could explicitly disable that warning, but (a) it makes it harder for other people to use my code, and (b) I don’t want to go violating standards if I can help it.
—Jens |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden