[Development] cmath, abs(), qt5 and gcc6

Lisandro Damián Nicanor Pérez Meyer perezmeyer at gmail.com
Wed Apr 27 04:40:34 CEST 2016


Suppose this simple code:

#include <QPointF>
#include <cmath>

void Foo::bar() {

  QPointF refPos, newPos;

  /// They get some values.

  if( abs(refPos.x()-newPos.x()) > abs(refPos.y()-newPos.y()) ) {
    // Do something.
  }
}


With gcc6 I will get:

error: call of overloaded ‘abs(qreal)’ is ambiguous
             if( abs(refPos.x()-newPos.x()) > abs(refPos.y()-newPos.y()) ) {
                                          ^
In file included from /usr/include/c++/6/cstdlib:75:0,
                 from /usr/include/c++/6/bits/stl_algo.h:59,
                 from /usr/include/c++/6/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:85,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qnamespace.h:37,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs.h:41,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:40,
                 from /usr/include/x86_64-linux-gnu/qt5/QtGui/qclipboard.h:37,
                 from /usr/include/x86_64-linux-gnu/qt5/QtGui/QClipboard:1,
                 from /home/lisandro/damian/debian/propios/caneda/upstream/src/cgraphicsscene.cpp:21:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
Yes, the example code might be too simplistic, but I think it's enough to get
the idea.

I know I can easily solve this by replacing cmath's abs with QGlobal's qAbs(),
but I wonder if this is a bug in gcc6, in my code or Qt.

It might be worth to note that, according to
https://gcc.gnu.org/gcc-6/porting_to.html#math.h

  Header <math.h> changes

  The C++ library now provides its own <math.h> header that wraps the C
  library header of the same name. The C++ header defines additional overloads
  of some functions and ensures that all standard functions are defined as
  real functions and not as macros. Code which assumes that sin, cos, pow,
  isfinite etc. are macros may no longer compile.

Any hints?

-- 
Lisandro Damián Nicanor Pérez Meyer
http://perezmeyer.com.ar/
http://perezmeyer.blogspot.com/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160426/1e646b38/attachment.sig>


More information about the Development mailing list