This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/79258] New: -Wduplicated-branches false positive?
- From: "sirl at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 27 Jan 2017 15:51:46 +0000
- Subject: [Bug c++/79258] New: -Wduplicated-branches false positive?
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79258
Bug ID: 79258
Summary: -Wduplicated-branches false positive?
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: sirl at gcc dot gnu.org
Target Milestone: ---
This code:
class Base
{
public:
static bool state();
};
class Derived : public Base
{
};
class MyClass
{
public:
Derived *m_Derived;
Base *m_Base;
bool state();
};
bool MyClass::state()
{
if (m_Derived != (void *) 0)
return m_Derived->state();
else
return m_Base->state();
}
results in this warning:
# g++-trunk -c -Wduplicated-branches -O2 test.c
test.c: In member function 'bool MyClass::state()':
test.c:22:2: warning: this condition has identical branches
[-Wduplicated-branches]
if (m_Derived != (void *) 0)
^~
Should the compiler really warn here?