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

Fix #2034 #2037

Merged
merged 2 commits into from
Aug 9, 2021
Merged

Fix #2034 #2037

merged 2 commits into from
Aug 9, 2021

Conversation

dkavolis
Copy link
Contributor

@dkavolis dkavolis commented Aug 9, 2021

For some reason clang doesn't like a disabled constructor in std::is_convertible so conversion to format strings has to be replaced by conversion to equivalent string views as in fmt.

This time also tested with Clang 12.0.1 C++20. Might be a good idea to add C++20 to CI.

Fixes #2034

@boxerab
Copy link

boxerab commented Aug 9, 2021

@dkavolis thank you! this patch fixed errors I started getting from clang 12 and c++20 after updating to latest v1.x version.

template<class T>
struct is_convertible_to_wformat_string : std::is_convertible<T, fmt::wformat_string<>>
{};
using is_convertible_to_wformat_string = is_convertible_to_basic_format_string<T, wchar_t>;
Copy link
Owner

@gabime gabime Aug 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it compile if SPDLOG_WCHAR_TO_UTF8_SUPPORT (and hence is_convertible_to_wformat_string ) are not defined ? Or does SFINAE allows it?

Anyway I think it is cleaner just to remove the all those is_convertible_to_wformat_string definitions completely (lines 134-147) and do something like:

template<class T>
struct is_convertible_to_any_format_string
    : std::integral_constant<bool, is_convertible_to_basic_format_string<T, char>::value || is_convertible_to_basic_format_string<T, wchar>::value>
{};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_convertible_to_wformat_string is defined the same way as is_convertible_to_wstring_view but a quick search in the repo showed no uses of either outside of logger::log SFINAE check if msg is convertible to a string view or format string. I used is_convertible_to_wstring_view as an example for is_convertible_to_wformat_string since they are both very similar. Might be cleaner to remove both in this case.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. please remove them

@dkavolis
Copy link
Contributor Author

dkavolis commented Aug 9, 2021

Also removed the SFINAE check for string view conversion in logger::log since format strings already check for it.

@gabime gabime merged commit 45e3b67 into gabime:v1.x Aug 9, 2021
@gabime
Copy link
Owner

gabime commented Aug 9, 2021

Thanks @dkavolis

@gabime
Copy link
Owner

gabime commented Aug 10, 2021

@dkavolis I added CI to test c++20 but it fails here: https://travis-ci.com/github/gabime/spdlog/jobs/530329470

Could you please take a look please? (I tried fixing with wrapping with fmt::runtime the problematic line but it didn't help)

@dkavolis
Copy link
Contributor Author

dkavolis commented Aug 10, 2021

Seems like an issue with clang, the error happens when using std::strlen at compile time

  FMT_CONSTEXPR_CHAR_TRAITS
  FMT_INLINE
  basic_string_view(const Char* s) : data_(s) {
    if (detail::const_check(std::is_same<Char, char>::value &&
                            !detail::is_constant_evaluated()))
      size_ = std::strlen(reinterpret_cast<const char*>(s));
    else
      size_ = std::char_traits<Char>::length(s);
  }

But the only way this can happen is if either __cpp_lib_is_constant_evaluated is undefined, std::is_constant_evaluated() returns false or clang tries to evaluate the discarded branch in constant expression, neither of which should happen.

Can it be due to the old libstdc++ version? GCC is only version 7.5.0 and __cpp_lib_is_constant_evaluated needs GCC 9.0.

@gabime
Copy link
Owner

gabime commented Aug 10, 2021

So I will try replace the ci to gcc and see what happens

Update:
@dkavolis seems you are right. I added gcc-11 CI test and it passes (https://travis-ci.com/github/gabime/spdlog/jobs/530467284).

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.

spdlog v1.9.1 and clang 12.0.1 (libc++) compilation failure
3 participants