Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#12764 closed Patch - Bug Fix (fixed)

Bug fix - compilation of abs function with latest gcc/libstdc++

Reported by: Gary Buhrmaster <gary.buhrmaster@…> Owned by: Stuart Auchterlonie
Priority: minor Milestone: 0.28.1
Component: MythTV - Video Library Version: Master Head
Severity: medium Keywords:
Cc: Ticket locked: no

Description

With recent gcc and libstdc++ compilation fails with:

visualisations/videovisualcircles.cpp: In member function ‘virtual void VideoVisualCircles::DrawPriv(MythPainter*, QPaintDevice*)’:
visualisations/videovisualcircles.cpp:26:75: error: call of overloaded ‘abs(double)’ is ambiguous
         double mag = abs((m_magnitudes[i] + m_magnitudes[i + count]) / 2.0);
                                                                           ^
In file included from /usr/include/c++/6.0.0/cstdlib:75:0,
                 from /usr/include/c++/6.0.0/bits/stl_algo.h:59,
                 from /usr/include/c++/6.0.0/algorithm:62,
                 from /usr/include/qt5/QtCore/qglobal.h:85,
                 from /usr/include/qt5/QtGui/qrgb.h:37,
                 from /usr/include/qt5/QtGui/qcolor.h:37,
                 from /usr/include/qt5/QtGui/qpen.h:37,
                 from /usr/include/qt5/QtGui/QPen:1,
                 from visualisations/videovisualcircles.cpp:1:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^~~
In file included from /usr/include/c++/6.0.0/bits/stl_algo.h:59:0,
                 from /usr/include/c++/6.0.0/algorithm:62,
                 from /usr/include/qt5/QtCore/qglobal.h:85,
                 from /usr/include/qt5/QtGui/qrgb.h:37,
                 from /usr/include/qt5/QtGui/qcolor.h:37,
                 from /usr/include/qt5/QtGui/qpen.h:37,
                 from /usr/include/qt5/QtGui/QPen:1,
                 from visualisations/videovisualcircles.cpp:1:
/usr/include/c++/6.0.0/cstdlib:185:3: note: candidate: __int128 std::abs(__int128)
   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
   ^~~
/usr/include/c++/6.0.0/cstdlib:180:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^~~
/usr/include/c++/6.0.0/cstdlib:172:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^~~

The following patch fixes the issue (lightly tested) by specifying the Qt function qAbs:

diff --git a/mythtv/libs/libmythtv/visualisations/videovisualcircles.cpp b/mythtv/libs/libmythtv/visualisations/videovisualcircles.cpp
index 1140372..e9cbf8f 100644
--- a/mythtv/libs/libmythtv/visualisations/videovisualcircles.cpp
+++ b/mythtv/libs/libmythtv/visualisations/videovisualcircles.cpp
@@ -23,7 +23,7 @@ void VideoVisualCircles::DrawPriv(MythPainter *painter, QPaintDevice* device)
     painter->Begin(device);
     for (int i = 0; i < count; i++, rad += m_range, red += incr, green -= incr)
     {
-        double mag = abs((m_magnitudes[i] + m_magnitudes[i + count]) / 2.0);
+        double mag = qAbs((m_magnitudes[i] + m_magnitudes[i + count]) / 2.0);
         if (mag > 1.0)
         {
             pen.setWidth((int)mag);

Change History (6)

comment:1 Changed 8 years ago by Stuart Auchterlonie

Milestone: unknown0.28.1
Owner: changed from JYA to Stuart Auchterlonie
Status: newassigned

Does this also work if you do the change as follows??

diff --git a/mythtv/libs/libmythtv/visualisations/videovisualcircles.cpp b/mythtv/libs/libmythtv/visualisations/videovisualcircles.cpp
index 1140372..e9cbf8f 100644
--- a/mythtv/libs/libmythtv/visualisations/videovisualcircles.cpp
+++ b/mythtv/libs/libmythtv/visualisations/videovisualcircles.cpp
@@ -23,7 +23,7 @@ void VideoVisualCircles::DrawPriv(MythPainter *painter, QPaintDevice* device)
     painter->Begin(device);
     for (int i = 0; i < count; i++, rad += m_range, red += incr, green -= incr)
     {
-        double mag = abs((m_magnitudes[i] + m_magnitudes[i + count]) / 2.0);
+        double mag = ::abs((m_magnitudes[i] + m_magnitudes[i + count]) / 2.0);
         if (mag > 1.0)
         {
             pen.setWidth((int)mag);

This forces use of the stdlib abs function

comment:2 in reply to:  1 Changed 8 years ago by Gary Buhrmaster <gary.buhrmaster@…>

Replying to stuarta:

Does this also work if you do the change as follows??

'std::abs', not '::abs', works (well, it compiles, I have no idea about the visualization results).

I was under the impression (based on the wording in the "coding standards" wiki entry) that using Qt abstraction was usually preferred, which is why I suggested the Qt variant in this case.

comment:3 Changed 8 years ago by Stuart Auchterlonie

Good point!

comment:4 Changed 8 years ago by Gary Buhrmaster <gary.buhrmaster@…>

Resolution: fixed
Status: assignedclosed

In e4f6e011b6748d1ba3ee5d09c1ffe2a382f2fe8b/mythtv:

Fixes #12764 - compilation of abs function with latest gcc/libstdc++

Signed-off-by: Stuart Auchterlonie <stuarta@…>

comment:5 Changed 8 years ago by Gary Buhrmaster <gary.buhrmaster@…>

In 812ec085711266220817426443fd899faac16363/mythtv:

Fixes #12764 - compilation of abs function with latest gcc/libstdc++

Signed-off-by: Stuart Auchterlonie <stuarta@…>
(cherry picked from commit e4f6e011b6748d1ba3ee5d09c1ffe2a382f2fe8b)

comment:6 Changed 8 years ago by Gary Buhrmaster <gary.buhrmaster@…>

In 28b7db2ed0cd165388f0bc396786e4b17f6c5774/mythtv:

Fixes #12764 - compilation of abs function with latest gcc/libstdc++

Signed-off-by: Stuart Auchterlonie <stuarta@…>
(cherry picked from commit e4f6e011b6748d1ba3ee5d09c1ffe2a382f2fe8b)

Note: See TracTickets for help on using tickets.