Pierre Abbat
Pierre Abbat

Reputation: 523

xy::isfinite compiles on Linux, BSD, and Windows, but not SmartOS

I'm trying to port Quadlods to SmartOS. It compiles and runs on Linux and DragonFly BSD. I haven't tried running it on Windows, but other programs using the xy class with the isfinite method compile and run on Windows. However, compiling it on SmartOS, I get this error:

[ 15%] Building CXX object CMakeFiles/quadlods.dir/filltest.cpp.o
In file included from /usr/include/math.h:36,
                 from /opt/local/gcc9/include/c++/9.3.0/bits/std_abs.h:40,
                 from /opt/local/gcc9/include/c++/9.3.0/cstdlib:77,
                 from /opt/local/gcc9/include/c++/9.3.0/ext/string_conversions.h:41,
                 from /opt/local/gcc9/include/c++/9.3.0/bits/basic_string.h:6493,
                 from /opt/local/gcc9/include/c++/9.3.0/string:55,
                 from /opt/local/gcc9/include/c++/9.3.0/stdexcept:39,
                 from /opt/local/gcc9/include/c++/9.3.0/optional:38,
                 from /opt/local/gcc9/include/c++/9.3.0/bits/node_handle.h:39,
                 from /opt/local/gcc9/include/c++/9.3.0/bits/stl_tree.h:72,
                 from /opt/local/gcc9/include/c++/9.3.0/map:60,
                 from /home/phma/src/quadlods/quadlods.h:27,
                 from /home/phma/src/quadlods/filltest.h:25,
                 from /home/phma/src/quadlods/filltest.cpp:26:
/home/phma/src/quadlods/xy.h:35:8: error: expected ')' before '!=' token
   35 |   bool isfinite() const;
      |        ^~~~~~~~

The file that defines the macro, causing this bizarre error, is /usr/include/iso/math_c99.h:

#define isfinite(x) (__builtin_isfinite(x) != 0)

The class definition in the header file is

class xy
{
public:
  xy(double e,double n);
  xy();
  double getx() const;
  double gety() const;
  double length() const;
  bool isfinite() const;
  bool isnan() const;
  friend xy operator+(const xy &l,const xy &r);
  friend xy operator+=(xy &l,const xy &r);
  friend xy operator-=(xy &l,const xy &r);
  friend xy operator-(const xy &l,const xy &r);
  friend xy operator-(const xy &r);
  friend xy operator*(const xy &l,double r);
  friend xy operator*(double l,const xy &r);
  friend xy operator/(const xy &l,double r);
  friend xy operator/=(xy &l,double r);
  friend bool operator!=(const xy &l,const xy &r);
  friend bool operator==(const xy &l,const xy &r);
  friend xy turn90(xy a);
  friend xy turn(xy a,int angle);
  friend double dist(xy a,xy b);
protected:
  double x,y;
};

Is it possible to make this compile on SmartOS without renaming the method? I thought of undefining the isfinite macro, but in another program (not Quadlods, whose header file is only quadlods.h), the xy class is in a header file for the library. Besides, the isfinite method calls std::isfinite.

Upvotes: 0

Views: 43

Answers (1)

Pierre Abbat
Pierre Abbat

Reputation: 523

The solution, which Jonathan Perkin gave me on IRC, is to put #include <cmath> just after the include guard of xy.h. This undefines the macro. It now compiles on Linux, BSD, and SmartOS.

Upvotes: 0

Related Questions