GNOME Bugzilla – Bug 780350
gjs 1.48.0: does not compile on macOS with clang
Last modified: 2017-05-01 04:41:30 UTC
After trying to compile gjs 1.48.0 on macOS, I encountered the following error: gi/arg.cpp:2614:13: error: call to 'abs' is ambiguous if (std::abs(arg->v_int64) > MAX_SAFE_INT64) ^~~~~~~~ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:664:1: note: candidate function abs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);} ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:668:1: note: candidate function abs(double __lcpp_x) _NOEXCEPT {return fabs(__lcpp_x);} ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:672:1: note: candidate function abs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);} ^ 1 error generated. make[1]: *** [gi/libgjs_la-arg.lo] Error 1 make[1]: *** Waiting for unfinished jobs.... The fix was easy: diff --git a/gi/arg.cpp b/gi/arg.cpp index 5502b00..aacc07d 100644 --- a/gi/arg.cpp +++ b/gi/arg.cpp @@ -37,6 +37,8 @@ #include "gjs/byteArray.h" #include "gjs/jsapi-wrapper.h" #include <util/log.h> +#include <cstdlib> +#include <cmath> bool _gjs_flags_value_is_valid(JSContext *context,
Seems reasonable. My Apple hardware is defunct right now so I haven't been testing compilation on macOS since about 2 months ago, unfortunately.
Thanks for the fix Tom, I've got my macOS system back and indeed that fixes the problem. I'll commit it later. I also got an annoying warning about --param inline-unit-growth=50 which doesn't do anything on Clang. But, the compiler also doesn't report that the flag doesn't exist, because the --param flag does exist on Clang. Following is an alternative (and in my opinion better) fix for that.
Created attachment 350423 [details] [review] jsapi-util-args: Mark functions as always-inline On GCC, we get warnings about the inline functions causing too much code growth. However, we do want these functions always inlined, since they're in a header file. Previously we dealt with the warnings by increasing --param inline-unit-growth, but that causes other warnings on Clang since Clang doesn't have that parameter. I also noticed that it requires different values on other versions of GCC, so it's not a very good solution. Instead, we use the always_inline attribute on GCC, which causes the functions to be inlined regardless of the compiler's inlining heuristics.
Review of attachment 350423 [details] [review]: Looks correct to me.
Attachment 350423 [details] pushed as bdbf717 - jsapi-util-args: Mark functions as always-inline