This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/77297] New: -Wnonnull-compare not emitted inside ternary operator


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77297

            Bug ID: 77297
           Summary: -Wnonnull-compare not emitted inside ternary operator
           Product: gcc
           Version: 6.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wipedout at yandex dot ru
  Target Milestone: ---

On http://gcc.godbolt.org/ I select gcc 6.1 and specify -O3 -Wall

Here's the code:
struct CHandle {
  int handle;
  int GetHandle() const
  {
    if (this == 0) //[-Wnonnull-compare] emitted as expected
      return handle;
    return (this == 0) ? 1 : handle; //[-Wnonnull-compare] not emitted
  }
};
int main()
{
  CHandle* h = new CHandle();//
  return h->GetHandle();
}

[-Wnonnull-compare] is emitted for "if (this == 0)" line but not for
"(this==0)?" ternary operator line. The two are completely equivalent checks.
The warning should be emitted for both. If I remove "if (this == 0) return
handle" then still no warning is emitted.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]