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

Bug with {fmt} integration #213

Open
YarikTH opened this issue Sep 26, 2023 · 2 comments
Open

Bug with {fmt} integration #213

YarikTH opened this issue Sep 26, 2023 · 2 comments

Comments

@YarikTH
Copy link
Contributor

YarikTH commented Sep 26, 2023

Integration with {fmt} has a problem if only <fmt/core.h> is included. Because it defines FMT_VERSION that triggers {fmt} integration, but does not provides fmt::to_string which is defined in <fmt/format.h>

https://godbolt.org/z/3WTE6f3b6

<source>: In static member function 'static std::string ApprovalTests::FmtToString::toString(const T&)':
<source>:1028:25: error: 'to_string' is not a member of 'fmt'; did you mean 'std::__cxx11::to_string'?
 1028 |             return fmt::to_string(printable);
      |                         ^~~~~~~~~
In file included from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/string:54,
                 from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/locale_classes.h:40,
                 from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/ios_base.h:41,
                 from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/streambuf:43,
                 from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/streambuf_iterator.h:35,
                 from /opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/iterator:66,
                 from /opt/compiler-explorer/libs/fmt/10.1.1/include/fmt/core.h:14,
                 from <source>:1:
/opt/compiler-explorer/gcc-13.2.0/include/c++/13.2.0/bits/basic_string.h:4249:3: note: 'std::__cxx11::to_string' declared here
 4249 |   to_string(long double __val)
      |   ^~~~~~~~~
Compiler returned: 1
@YarikTH
Copy link
Contributor Author

YarikTH commented Sep 26, 2023

#124

@YarikTH
Copy link
Contributor Author

YarikTH commented Sep 26, 2023

Possible solutions:

  1. Include <fmt/format.h> if FMT_VERSION is detected
  2. Redo fmt detection to use FMT_FORMAT_H_ define guard (looks unstable)
  3. Include <fmt/format.h> and fmt integration manually instead of autodetect. For e.g. #ifdef APPROVALS_USE_FMT. At least integration with other testing frameworks is done this way instead of using hacky detections

1st looks more stable for v10, while I would prefer 3rd option as a v11 solution. I personally bumped up in this bug, when I included header that includes <fmt/core.h> in the approvals based test code. It is not the best way to bump into library feature

YarikTH added a commit to YarikTH/ApprovalTests.cpp that referenced this issue Sep 26, 2023
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

1 participant