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

Make error #2140

Closed
tanim87 opened this issue Feb 21, 2021 · 8 comments · Fixed by #2144 or sthagen/fmtlib-fmt#165
Closed

Make error #2140

tanim87 opened this issue Feb 21, 2021 · 8 comments · Fixed by #2144 or sthagen/fmtlib-fmt#165

Comments

@tanim87
Copy link

tanim87 commented Feb 21, 2021

Dear Concern,
While making the fmt, I am getting the following error:
Building CXX object test/CMakeFiles/format-test.dir/format-test.cc.o
/usr/local/src/fmt/test/format-test.cc:1487:20: error: call to 'ptr' is ambiguous

Would you please help me with it?
I am using Ubuntu 16.04

Thanks.

@alexezeder
Copy link
Contributor

Could you please provide compiler info?

@tanim87
Copy link
Author

tanim87 commented Feb 21, 2021

gcc 8.1.0

@alexezeder
Copy link
Contributor

Looks like it should just work with the master branch of {fmt} on Compiler Explorer.
Do you have full output for this error, like function candidates, since the call is ambiguous?

@tanim87
Copy link
Author

tanim87 commented Feb 21, 2021

Screenshot_2021-02-21_01-06-44
I have attached the complete screenshot. I could not find log file that would give more insight. Let me know if this will work. Thanks.

@alexezeder
Copy link
Contributor

Thanks, this definitely helped. For some reason, this specific version of GCC is able to decay function pointers to void pointers, just like MSVC, so this branch should be disabled for this GCC version too:

fmt/include/fmt/format.h

Lines 3837 to 3844 in 7e72673

#if !FMT_MSC_VER
// MSVC lets function pointers decay to void pointers, so this
// overload is unnecessary.
template <typename T, typename... Args>
inline const void* ptr(T (*fn)(Args...)) {
return detail::bit_cast<const void*>(fn);
}
#endif

You can check it locally just by commenting out the code above.

But since I don't know how to make it in a more versatile way, I think we should just wait for more experienced people for proper fix.

@vitaut
Copy link
Contributor

vitaut commented Feb 21, 2021

I think we could SFINAE this overload away on function to const void* pointer convertibility.

@alexezeder
Copy link
Contributor

Actually there is another problem with fmt::ptr and old Clang versions (<7.0) - https://godbolt.org/z/j57Kzx. Actually, this problem is even more interesting than I thought - https://godbolt.org/z/sEsTE7.

But as far as I can see, following workarounds are able to satisfy all compilers - https://godbolt.org/z/Y8sadG. I'll create a PR with this code soon.

@tanim87
Copy link
Author

tanim87 commented Feb 21, 2021

Your suggestion worked! Thanks.

alexezeder added a commit to alexezeder/fmt that referenced this issue Feb 22, 2021
fixes fmtlib#2140

- some GCC versions decay function pointers to `const void*`, exactly like
  MSVC does
- legacy Clang (prior to 7.0) treats function pointers also as `const T*`
  pointers, but unable to convert them
alexezeder added a commit to alexezeder/fmt that referenced this issue Feb 22, 2021
fixes fmtlib#2140

- some GCC versions decay function pointers to `const void*`, exactly like
  MSVC does
- legacy Clang (prior to 7.0) treats function pointers also as `const T*`
  pointers, but unable to convert them
alexezeder added a commit to alexezeder/fmt that referenced this issue Feb 23, 2021
fixes fmtlib#2140

- some GCC versions decay function pointers to `const void*`, exactly like
  MSVC does
- legacy Clang (prior to 7.0) treats function pointers also as `const T*`
  pointers, but unable to convert them
vitaut pushed a commit that referenced this issue Feb 23, 2021
fixes #2140

- some GCC versions decay function pointers to `const void*`, exactly like
  MSVC does
- legacy Clang (prior to 7.0) treats function pointers also as `const T*`
  pointers, but unable to convert them
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants