Opened 5 years ago

Closed 3 months ago

#10946 closed build error (fixed)

redunant redeclaration of functions in file geometry.h

Reported by: ettl.martin Owned by: DS
Priority: low Milestone:
Component: wxGTK Version:
Keywords: Cc: csomor
Blocked By: Blocking:
Patch: no

Description

Hello,

while compiling my app, g++-4.4.0 brought the following warnings:

/usr/local/include/wx-2.8/wx/geometry.h:91: warning: redundant redeclaration of ‘wxPoint2DInt operator*(wxInt32, const wxPoint2DInt&)’ in same scope /usr/local/include/wx-2.8/wx/geometry.h:90: warning: previous declaration of ‘wxPoint2DInt operator*(wxInt32, const wxPoint2DInt&)’ /usr/local/include/wx-2.8/wx/geometry.h:93: warning: redundant redeclaration of ‘wxPoint2DInt operator*(const wxPoint2DInt&, wxInt32)’ in same scope /usr/local/include/wx-2.8/wx/geometry.h:92: warning: previous declaration of ‘wxPoint2DInt operator*(const wxPoint2DInt&, wxInt32)’ /usr/local/include/wx-2.8/wx/geometry.h:96: warning: redundant redeclaration of ‘wxPoint2DInt operator/(const wxPoint2DInt&, wxInt32)’ in same scope /usr/local/include/wx-2.8/wx/geometry.h:95: warning: previous declaration of ‘wxPoint2DInt operator/(const wxPoint2DInt&, wxInt32)’

These are easy to fix, take a look at file geometry.h:

inline wxPoint2DInt operator+(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2); inline wxPoint2DInt operator-(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2); inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);

inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt); inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt); inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);

inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n); inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2); inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);

inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);

Or is there a reason for the redundant delcaration??

Best regards

Martin

Change History (7)

comment:1 Changed 5 years ago by jatupper

Martin,

I'm having a bit of trouble reading your code due to the loss of line breaks. Here is the relevant chunk from geometry.h again:

inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt);
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n);
inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2);
inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);
inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n);

Looking further down for the definitions gives:

inline wxPoint2DInt operator*(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
inline wxPoint2DInt operator*(wxInt32 n , const wxPoint2DInt& pt)
inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxInt32 n)
inline wxPoint2DInt operator*(const wxPoint2DInt& pt , wxDouble n)
inline wxPoint2DInt operator/(const wxPoint2DInt& pt1 , const wxPoint2DInt& pt2)
inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxInt32 n)
inline wxPoint2DInt operator/(const wxPoint2DInt& pt , wxDouble n)

I'm guessing that after some cutting-and-pasting, the author forgot to replace three of the wxInt32 types with wxDouble. (In the declarations, not in the definitions.)

comment:2 Changed 5 years ago by jatupper

By the way, the following doesn't look right...

inline wxPoint2DInt& wxPoint2DInt::operator*=(const wxPoint2DInt& pt)
{
    m_x = m_x + pt.m_x;
    m_y = m_y + pt.m_y;
    return *this;
}

inline wxPoint2DInt& wxPoint2DInt::operator/=(const wxPoint2DInt& pt)
{
    m_x = m_x - pt.m_x;
    m_y = m_y - pt.m_y;
    return *this;
}

In the following, why are the values cast to int instead of wxInt32? (Searching for "(int)" turns up more examples of this.)

inline wxPoint2DInt operator*(wxDouble n , const wxPoint2DInt& pt)
{
    return wxPoint2DInt( (int) (pt.m_x * n) , (int) (pt.m_y * n) );
}

comment:3 Changed 5 years ago by vadz

  • Cc csomor added
  • Priority changed from normal to low
  • Status changed from new to confirmed
  • Type changed from enhancement to build error

Stefan, several things do indeed look suspicious in this code but I might be missing something here as I never looked at it before so I'd prefer if you could fix it or at least confirm that there is really nothing more than just cut-and-pasting error to it. TIA!

comment:4 Changed 5 years ago by ettl.martin

Thanks guys for your fast response.

BTW, this bug was initially found by cppcheck, a static-code analyis tool.:

http://cppcheck.wiki.sourceforge.net/

Best regards

Martin

comment:5 Changed 3 months ago by DS

In 76566:

Fix wxPoint2DInt::operator*= and wxPoint2DInt::operator/= .

These operator functions are respectively adding and subtracting their arguments. Instead let the functions multiply and divide their arguments (like their wxPoint2DDouble counterparts were doing already).

See #10946.

comment:6 Changed 3 months ago by DS

In 76567:

Cast arguments passed to wxPoint2DInt constructor.

Cast them to wxInt32 (instead of int) as that is the type of the wxPoint2DInt members m_x and m_y.

See #10946.

comment:7 Changed 3 months ago by DS

  • Owner set to DS
  • Resolution set to fixed
  • Status changed from confirmed to closed

In 76568:

Add 3 missing declarations for wxPoint2DInt non-member operator functions.

Three duplicate declarations were removed in r70493 instead of replacing them with the missing declarations.

Closes #10946.

Note: See TracTickets for help on using tickets.