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

Resolve ambiguous abs() call #439

Merged
merged 1 commit into from Feb 13, 2020
Merged

Resolve ambiguous abs() call #439

merged 1 commit into from Feb 13, 2020

Conversation

cwilling
Copy link
Contributor

Signed-off-by: Christoph Willing chris.willing@linux.com

This resolves compilatin problem:

error: call of overloaded 'abs(double)' is ambiguous`

by using fabs(double) from cmath rather than trying abs(int) from stdlib.h or std::abs(long long int) from cstdlib

Signed-off-by: Christoph Willing <chris.willing@linux.com>
@codecov-io
Copy link

Codecov Report

Merging #439 into develop will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #439   +/-   ##
========================================
  Coverage    42.37%   42.37%           
========================================
  Files          129      129           
  Lines        13276    13276           
========================================
  Hits          5626     5626           
  Misses        7650     7650
Impacted Files Coverage Δ
src/KeyFrame.cpp 76.65% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56af4eb...e39a1fc. Read the comment docs.

@ferdnyc
Copy link
Contributor

ferdnyc commented Feb 12, 2020

Hmmm. OOC, is the call still ambiguous if it's written as std::abs()?

I have no objection to the use of std::fabs() instead, especially if it solves build problems, just trying to get a handle on the issue. (And always on the lookout for issues potentially caused by the IMHO-bad practice of using namespace std; in our code.)

What compiler/system gave you that error, BTW? Compiling with the various GCC and Clang versions in our CI matrix didn't flag it, interestingly.

@cwilling
Copy link
Contributor Author

Yes the problem remains when using std::abs(). From the error msg the compiler seems to find only int abs(int) (from stdlib.h), or long int std::abs(long int) and long long int std::abs(long long int) (both from cstdlib). Since we want abs(double), using fabs() resolves the problem.

It could be due to age of compiler gcc-g++-5.5.0 but we're stuck with that on Slackware 14.2 until release of 15.0 which has gcc-g++-9.2.0 (probably still some months away).

Here's the full error message:

/var/tmp/SBo/libopenshot-0.2.4/src/KeyFrame.cpp: In function 'double {anonymous}::InterpolateBezierCurve(const openshot::Point&, const openshot::Point&, double, double)':
/var/tmp/SBo/libopenshot-0.2.4/src/KeyFrame.cpp:74:27: error: call of overloaded 'abs(double)' is ambiguous
    if (std::abs(target - x) < allowed_error) {
                           ^
In file included from /usr/include/c++/5.5.0/cstdlib:72:0,
                 from /usr/include/c++/5.5.0/ext/string_conversions.h:41,
                 from /usr/include/c++/5.5.0/bits/basic_string.h:5352,
                 from /usr/include/c++/5.5.0/string:52,
                 from /usr/include/c++/5.5.0/bits/locale_classes.h:40,
                 from /usr/include/c++/5.5.0/bits/ios_base.h:41,
                 from /usr/include/c++/5.5.0/ios:42,
                 from /usr/include/c++/5.5.0/ostream:38,
                 from /usr/include/c++/5.5.0/iostream:39,
                 from /var/tmp/SBo/libopenshot-0.2.4/src/../include/KeyFrame.h:34,
                 from /var/tmp/SBo/libopenshot-0.2.4/src/KeyFrame.cpp:31:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
 extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
            ^
In file included from /usr/include/c++/5.5.0/ext/string_conversions.h:41:0,
                 from /usr/include/c++/5.5.0/bits/basic_string.h:5352,
                 from /usr/include/c++/5.5.0/string:52,
                 from /usr/include/c++/5.5.0/bits/locale_classes.h:40,
                 from /usr/include/c++/5.5.0/bits/ios_base.h:41,
                 from /usr/include/c++/5.5.0/ios:42,
                 from /usr/include/c++/5.5.0/ostream:38,
                 from /usr/include/c++/5.5.0/iostream:39,
                 from /var/tmp/SBo/libopenshot-0.2.4/src/../include/KeyFrame.h:34,
                 from /var/tmp/SBo/libopenshot-0.2.4/src/KeyFrame.cpp:31:
/usr/include/c++/5.5.0/cstdlib:166:3: note: candidate: long int std::abs(long int)
   abs(long __i) { return __builtin_labs(__i); }
   ^
/usr/include/c++/5.5.0/cstdlib:174:3: note: candidate: long long int std::abs(long long int)
   abs(long long __x) { return __builtin_llabs (__x); }
   ^
src/CMakeFiles/openshot.dir/build.make:638: recipe for target 'src/CMakeFiles/openshot.dir/KeyFrame.cpp.o' failed
make[2]: *** [src/CMakeFiles/openshot.dir/KeyFrame.cpp.o] Error 1
CMakeFiles/Makefile2:161: recipe for target 'src/CMakeFiles/openshot.dir/all' failed
```

@ferdnyc
Copy link
Contributor

ferdnyc commented Feb 13, 2020

Huh... so odd that it still considers abs from stdlib.h a candidate. But since there are two std::abs() candidates, it's kind of immaterial. And, indeed, fabs() is used at multiple other points in the code. I'm good with it! Merging, thanks.

@ferdnyc ferdnyc merged commit 3d6958d into OpenShot:develop Feb 13, 2020
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.

None yet

3 participants