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

Incorrect FMT_USE_STRING_VIEW logic results in libstdc++ compilation errors #1850

Closed
harrism opened this issue Sep 2, 2020 · 8 comments
Closed
Labels

Comments

@harrism
Copy link

harrism commented Sep 2, 2020

The following linked code in core.h results in compilation errors compiling with GCC (libstdc++) in our (C++14) library (https://github.com/rapidsai/cudf) which depends on spdlog, which bundles a version of fmt.

fmt/include/fmt/core.h

Lines 228 to 237 in 6cccdc2

// libc++ supports string_view in pre-c++17.
#if (FMT_HAS_INCLUDE(<string_view>) && \
(__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
# include <string_view>
# define FMT_USE_STRING_VIEW
#elif FMT_HAS_INCLUDE("experimental/string_view") && __cplusplus >= 201402L
# include <experimental/string_view>
# define FMT_USE_EXPERIMENTAL_STRING_VIEW
#endif

Specifically, while libc++ (clang) provides string_view before C++17, libstdc++ does not, it provides experimental/string_view.

Thus, I believe the || on line 230 should be &&, and making this change fixes our compilation issues.

@harrism
Copy link
Author

harrism commented Sep 2, 2020

Note that I can't produce the compilation failure in fmt's tests on the same system. I can only repro in building https://github.com/rapidsai/cudf, which depends on https://github.com/rapidsai/rmm, which depends on https://github.com/gabime/spdlog, which bundles fmt. Nevertheless, I think it's clear from inspection that || is wrong in the linked code. You want to detect that libc++ is the std implementation and that compilation is later than C++14, because otherwise it passes as long as C++ > 14 even if std is libstdc++, which makes it fail to find a compatible string_view header.

@vitaut
Copy link
Contributor

vitaut commented Sep 2, 2020

According to #686, libc++ supports string_view pre-C++17. If this is true then the check looks correct. In your case _LIBCPP_VERSION should be undefined since you are using libstdc++.

@vitaut
Copy link
Contributor

vitaut commented Sep 2, 2020

You can see that the check is correct on godbolt:

@harrism
Copy link
Author

harrism commented Sep 2, 2020

Thanks for the clue. We depend on libcudac++, which is based on libc++, and I think including that before including fmt is causing _LIBCPP_VERSION to be defined...

That said, it seems like a more conservative check like the one in #1852 is still correct and may allow use cases like ours (that have parts of both standard libraries in effect) to work.

@vitaut
Copy link
Contributor

vitaut commented Sep 2, 2020

Unfortunately the check in #1852 is not correct because std::string_view is available in libc++ pre C++17. You probably need a more cuda-specific workaround.

@vitaut vitaut closed this as completed Sep 2, 2020
@vitaut
Copy link
Contributor

vitaut commented Sep 2, 2020

Closed since it looks like an issue with libcudac++ but I'm open to a workaround that doesn't break string_view detection in normal libc++.

@harrism
Copy link
Author

harrism commented Sep 3, 2020

@vitaut thanks for your time and sorry for the noise. Looks like this is fixed in the latest libcudac++ and I should have a workaround until we are able to use the latest.

@vitaut
Copy link
Contributor

vitaut commented Sep 3, 2020

No worries, glad it's fixed.

@vitaut vitaut added the invalid label Oct 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants