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++/79258] New: -Wduplicated-branches false positive?


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?

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