Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix warning std::abs #991

Merged
merged 2 commits into from
Apr 10, 2015
Merged

fix warning std::abs #991

merged 2 commits into from
Apr 10, 2015

Conversation

kerautret
Copy link
Member

Small PR just to remove warning appeared from last OS X update

@rolanddenis
Copy link
Member

Actually, it is more than a simple warning: if both abs and std::abs are in scope, and without explicit use of std::abs (or of the directive using std::abs;), the compiler will choose abs that works on integers.

For example, the following code:

#include <iostream>
#include <cstdlib>
#include <cmath>

int main()
{
    double v = 2.5;
    std::cout << "abs(2.5) = " << abs(v) << std::endl;
    std::cout << "std::abs(2.5) = " << std::abs(v) << std::endl;
    return 0;
}

compile silently with g++ (v4.9.1 on Linux), even with -Wall -Wextra, and with a warning with clang++ (v3.5.0):

test.cpp:8:35: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]
    std::cout << "abs(2.5) = " << abs(v) << std::endl;
                                  ^
test.cpp:8:35: note: use function 'std::abs' instead
    std::cout << "abs(2.5) = " << abs(v) << std::endl;
                                  ^~~
                                  std::abs
1 warning generated.

but both binaries output is:

abs(2.5) = 2
std::abs(2.5) = 2.5

I've made a fast search through the DGtal source and it seems to be the only file where abs (alone) is used on floats.

@kerautret
Copy link
Member Author

yes, I also detects strange behavior with abs in my dev prog ;)

@dcoeurjo
Copy link
Member

dcoeurjo commented Apr 9, 2015

Thanks @kerautret for the PR and @rolanddenis for the explanation :)

@dcoeurjo
Copy link
Member

@kerautret could you please merge the master to this branch?

@kerautret
Copy link
Member Author

ok

@kerautret
Copy link
Member Author

@dcoeurjo done

@dcoeurjo
Copy link
Member

merging.

dcoeurjo added a commit that referenced this pull request Apr 10, 2015
@dcoeurjo dcoeurjo merged commit 6c05c16 into DGtal-team:master Apr 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants