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

fmt::print ambiguous when used with ""_cf UDL #2738

Closed
sth opened this issue Jan 28, 2022 · 1 comment
Closed

fmt::print ambiguous when used with ""_cf UDL #2738

sth opened this issue Jan 28, 2022 · 1 comment

Comments

@sth
Copy link

sth commented Jan 28, 2022

Trying to call fmt::print with a _cf format string results in a compiler warning (or error, when compiling with -pendantic):

#include "fmt/format.h"
#include "fmt/compile.h"

using namespace fmt::literals;

int main() {
        fmt::print("{}"_cf, 1);
}

This complains about a ambiguity:

$ g++-11 -std=c++20 tst.cpp -lformat
tst.cpp: In function ‘int main()’:
tst.cpp:7:19: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
    7 |         fmt::print("{}"_cf, 1);
      |         ~~~~~~~~~~^~~~~~~~~~~~
In file included from tst.cpp:2:
libs/fmt/include/fmt/compile.h:623:6: note: candidate 1: ‘void fmt::v8::print(const S&, const Args& ...) [with S = fmt::v8::detail::udl_compiled_string<char, 3, fmt::v8::detail_exported::fixed_string<char, 3>{"{}"}>; Args = {int}; typename std::enable_if<fmt::v8::detail::is_compiled_string<S>::value, int>::type <anonymous> = 0]’
  623 | void print(const S& format_str, const Args&... args) {
      |      ^~~~~
In file included from libs/fmt/include/fmt/format.h:48,
                 from tst.cpp:1:
libs/fmt/include/fmt/core.h:3206:17: note: candidate 2: ‘void fmt::v8::print(fmt::v8::format_string<T ...>, T&& ...) [with T = {int}; fmt::v8::format_string<T ...> = fmt::v8::basic_format_string<char, int>]’
 3206 | FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
      |                 ^~~~~

Indeed, commenting out either of the two candidates makes the sample code compile and run successfully. (But that's of course not really a solution, FMT_COMPILE or plain sting literals would no longer work as format strings.)

For fmt::format there is no problem, even thogh it has overloads that look similar.

@vitaut
Copy link
Contributor

vitaut commented Feb 5, 2022

Should be fixed in e2ba01f. Thanks for reporting!

@vitaut vitaut closed this as completed Feb 5, 2022
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

No branches or pull requests

2 participants