geodynamics / aspect

A parallel, extensible finite element code to simulate convection in both 2D and 3D models.
https://aspect.geodynamics.org/
Other
227 stars 237 forks source link

Call to std::abs() is ambiguous in GPlates::update() under clang 7.0.2 in Xcode 7.2 #746

Closed spco closed 8 years ago

spco commented 8 years ago

The new GPlates::update() commit https://github.com/geodynamics/aspect/commit/fb5b371f0b4f90389d50dfb1222a1d31c718e735 doesn't compile in Xcode.

Lines 654 and 682 in source/velocity_boundary_conditions/gplates.cc give the error Call to abs() is ambiguous and suggests candidate functions abs(int) in /usr/include/stdlib.h, abs( long __x) and abs( long long __x) in cstdlib, and abs(float __lcpp_x), abs(double __lcpp_x), and abs(long double __lcpp_x) in cmath.

Google suggests this is a known conflict between the headers, but I couldn't work out a immediate fix, as I expect several of these headers may already be in use in the include chain.

Apple LLVM version 7.0.2 (clang-700.1.81) Target: x86_64-apple-darwin15.3.0 Thread model: posix

OSX El Capitan 10.11.3 (15D21)

Xcode 7.2

tjhei commented 8 years ago

The code seems to be broken (abs() of an unsigned int?). Can you try if changing the locations to

std::abs(static_cast<int>(current_file_number) - first_data_file_number)

works?

bangerth commented 8 years ago

On 02/08/2016 01:13 PM, Sam Cox wrote:

Lines 654 and 682 in |source/velocity_boundary_conditions/gplatescc| give the error |Call to abs() is ambiguous| and suggests candidate functions |abs(int)| in |/usr/include/stdlibh|, |abs( long x)| and |abs( long long x)| in |cstdlib|, and |abs(float lcpp_x)|, |abs(double __lcpp_x)|, and |abs(long double lcpp_x)| in |cmath|

Can you try and see whether this works if you write it as

std::abs(static_cast<int>(current_file_number - first_data_file_number))

in the two places?

bangerth commented 8 years ago

Ah, I come to late I see...

spco commented 8 years ago

It's also in line 676, I'd missed that. It compiles fine under @bangerth's suggestion - the brackets make a difference as @tjhei's gives the same errors. I haven't checked it with an example that uses GPlates, but it compiles and runs other examples fine.

bangerth commented 8 years ago

Great. Do you think you can put this into a pull request?

spco commented 8 years ago

Sure, I'll do that tomorrow (GMT). On 8 Feb 2016 11:03 pm, "Wolfgang Bangerth" notifications@github.com wrote:

Great. Do you think you can put this into a pull request?

— Reply to this email directly or view it on GitHub https://github.com/geodynamics/aspect/issues/746#issuecomment-181612282.