#598 solaris: Overloading ambiguity between "std::abs(int/long)"

closed-fixed
nobody
None
5
2012-08-28
2012-08-27
No

Current code fails to compile on Sparc Solaris with

/opt/SUNWspro/bin/CC -DHAVE_CONFIG_H -I. -I.. -I../term -I../term -DBINDIR=\"/usr/local/bin\" -DX11_DRIVER_DIR=\"/usr/local/libexec/gnuplot/4.7\" -DQT_DRIVER_DIR=\"/usr/local/libexec/gnuplot/4.7\" -DGNUPLOT_SHARE_DIR=\"/usr/local/share/gnuplot/4.7\" -DGNUPLOT_PS_DIR=\"/usr/local/share/gnuplot/4.7/PostScript\" -DGNUPLOT_JS_DIR=\"/usr/local/share/gnuplot/4.7/js\" -DGNUPLOT_LUA_DIR=\"/usr/local/share/gnuplot/4.7/lua\" -DCONTACT=\"gnuplot-bugs@lists.sourceforge.net\" -DHELPFILE=\"/usr/local/share/gnuplot/4.7/gnuplot.gih\" -DGNUPLOT_X11=\"`echo gnuplot_x11 | sed 's,x,x,'`\" -DXAPPLRESDIR=\"/etc/X11/app-defaults/\" -I/usr/openwin/include -I/opt/csw/include -I/opt/csw/include -D_REENTRANT -D_PTHREADS -I/opt/csw/include/cairo -I/opt/csw/include/pango-1.0 -I/opt/csw/include/glib-2.0 -I/opt/csw/lib/glib-2.0/include -D_REENTRANT -D_PTHREADS -I/opt/csw/include/cairo -I/opt/csw/include/pango-1.0 -I/opt/csw/include/glib-2.0 -I/opt/csw/lib/glib-2.0/include -g -O2 -I/opt/csw/lib/wx/include/gtk2-unicode-release-2.8 -I/opt/csw/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -mt -D_REENTRANT -D_REENTRANT -D_PTHREADS -I/opt/csw/include/cairo -I/opt/csw/include/pango-1.0 -I/opt/csw/include/glib-2.0 -I/opt/csw/lib/glib-2.0/include -D_REENTRANT -D_PTHREADS -I/opt/csw/include/gtk-2.0 -I/opt/csw/lib/gtk-2.0/include -I/opt/csw/include/atk-1.0 -I/opt/csw/include/cairo -I/opt/csw/include/pango-1.0 -I/opt/csw/include/glib-2.0 -I/opt/csw/lib/glib-2.0/include -I/opt/csw/include/freetype2 -I/opt/csw/include -c -o wxt_gui.o `test -f 'wxterminal/wxt_gui.cpp' || echo './'`wxterminal/wxt_gui.cpp
"wxterminal/wxt_gui.cpp", line 1665: Warning (Anachronism): Formal argument 1 of type extern "C" void(*)() in call to std::atexit(extern "C" void(*)()) is being passed void(*)().
"wxterminal/wxt_gui.cpp", line 2797: Error: Overloading ambiguity between "std::abs(int)" and "std::abs(long)".
"wxterminal/wxt_gui.cpp", line 2797: Error: Overloading ambiguity between "std::abs(int)" and "std::abs(long)".
"wxterminal/wxt_gui.cpp", line 3826: Warning (Anachronism): Formal argument 2 of type extern "C" void(*)(int) in call to std::signal(int, extern "C" void(*)(int)) is being passed void(*)(int).
"wxterminal/wxt_gui.cpp", line 3861: Warning (Anachronism): Formal argument 2 of type extern "C" void(*)(int) in call to std::signal(int, extern "C" void(*)(int)) is being passed void(*)(int).
"wxterminal/wxt_gui.cpp", line 3861: Warning (Anachronism): Assigning extern "C" void(*)(int) to void(*)(int).
"wxterminal/wxt_gui.cpp", line 3870: Warning (Anachronism): Formal argument 2 of type extern "C" void(*)(int) in call to std::signal(int, extern "C" void(*)(int)) is being passed void(*)(int).
2 Error(s) and 5 Warning(s) detected.
*** Error code 2

The problematic commit is this one:

2012-05-21 Ethan A Merritt <merritt@u.washington.edu>

* src/term_api.h:
Core support for hypertext in interactive terminals. Terminal entry
term->hypertext(int TYPE, const char TEXT)

I'm attaching a trivial patch that solves the problem for me (suggested by Daniel Sebald):

--- src/wxterminal/wxt_gui.cpp.orig
+++ src/wxterminal/wxt_gui.cpp
@@ -2798,7 +2798,7 @@ void wxtPanel::wxt_cairo_exec_command(gp_command command)
int xnow = gnuplot_x(&plot, mouse_x);
int ynow = term->ymax - gnuplot_y(&plot, mouse_y);
int size = 3 * plot.pointsize * plot.oversampling_scale;
- if (abs(xnow-command.x1) < size && abs(ynow-command.y1) < size) {
+ if (abs(xnow-(long)command.x1) < size && abs(ynow-(long)command.y1) < size) {
wxt_display_hypertext = current_href;
wxt_display_anchor.x = command.x1;
wxt_display_anchor.y = command.y1;

I'm not exactly sure why this is needed. It seems that compiler just wants to know if it's int or long inside the abs(...).

Alternatively, "abs((int)(xnow-command.x1))" works just as well (if numbers fit into int, this might make more sense).

Discussion

  • Ethan Merritt

    Ethan Merritt - 2012-08-28
    • status: open --> closed-fixed
     
  • Ethan Merritt

    Ethan Merritt - 2012-08-28

    Neither of those patches would be correct. xnow and ynow are already (int), so casting the other operand to (long) would be creating a type conflict, not resolving one. The issue here, despite to misleading compiler warning, is signed vs unsigned. The compiler is unhappy that command.x1 is unsigned. So we will cast it to (int).
    Given that the code is chock full of signed/unsigned implicit conversions, I have no idea why this particular one triggers an error rather than a warning. gcc issues a warning, but only if you enable -Wsign-conversion

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks