This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77297] New: -Wnonnull-compare not emitted inside ternary operator
- From: "wipedout at yandex dot ru" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 19 Aug 2016 15:00:50 +0000
- Subject: [Bug c++/77297] New: -Wnonnull-compare not emitted inside ternary operator
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
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.