• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
New C++ warning about comparing this==NULL
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: New C++ warning about comparing this==NULL
      • From: Jeremy Hughes <email@hidden>
    • Re: New C++ warning about comparing this==NULL
      • From: Anders Montonen <email@hidden>
    • Re: New C++ warning about comparing this==NULL
      • From: Jonathan Prescott <email@hidden>
  • Next by Date: Re: New C++ warning about comparing this==NULL
  • Next by thread: Re: New C++ warning about comparing this==NULL
  • Index(es):
    • Date
    • Thread