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 #2210 #2211

Merged
merged 5 commits into from
Apr 7, 2021
Merged

fix #2210 #2211

merged 5 commits into from
Apr 7, 2021

Conversation

apache-hb
Copy link
Contributor

No description provided.

FMT_INLINE basic_string_view(const Char* s) : data_(s) {
if (std::is_same<Char, char>::value && !detail::is_constant_evaluated())
FMT_CONSTEXPR_CHAR_TRAITS_LENGTH FMT_INLINE basic_string_view(const Char* s) : data_(s) {
if FMT_CONSTEXPR_CHAR_TRAITS_LENGTH (std::is_same<Char, char>::value && !detail::is_constant_evaluated())
Copy link
Contributor

Choose a reason for hiding this comment

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

This line becomes wrong with FMT_CONSTEXPR_CHAR_TRAITS_LENGTH replaced as FMT_CONSTEXPR, i.e. constexpr. From cppreference about std::is_constant_evaluated() (which is used inside detail::is_constant_evaluated() when supported):

When directly used as the condition of static_assert declaration or constexpr if statement, std::is_constant_evaluated() always returns true.

So it shouldn't be if constexpr, just if.

Copy link
Contributor

Choose a reason for hiding this comment

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

The correct way to fix this warning I can imagine (probably it's also very unclear): combine __cplusplus check together with __cpp_lib_is_constant_evaluated check to use if constexpr only if detail::is_constant_evaluated() unconditionally false.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just replace FMT_CONSTEXPR_CHAR_TRAITS_LENGTH with detail::const_check and revert other changes.

Comment on lines 101 to 107
// C++17's char_traits::length() is constexpr.
#if __cplusplus >= 201703L
# define FMT_CONSTEXPR_CHAR_TRAITS_LENGTH FMT_CONSTEXPR
#else
# define FMT_CONSTEXPR_CHAR_TRAITS_LENGTH
#endif

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I'm not sure if it's worth introducing this special definition to use it only once.

@@ -392,11 +399,8 @@ template <typename Char> class basic_string_view {
the size with ``std::char_traits<Char>::length``.
\endrst
*/
#if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr.
FMT_CONSTEXPR
Copy link
Contributor

Choose a reason for hiding this comment

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

And another observation, it's not about this PR, just these lines in general: probably constexpr can be used here, not FMT_CONSTEXPR, since it's already under the __cplusplus >= 201703L macro check.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this actually can be applied to this PR too, since it's also used in newly introduced macro definition.

@alexezeder
Copy link
Contributor

Anyway, feel free to ignore my review, and just wait for comments from maintainers 🙂

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

FMT_INLINE basic_string_view(const Char* s) : data_(s) {
if (std::is_same<Char, char>::value && !detail::is_constant_evaluated())
FMT_CONSTEXPR_CHAR_TRAITS_LENGTH FMT_INLINE basic_string_view(const Char* s) : data_(s) {
if FMT_CONSTEXPR_CHAR_TRAITS_LENGTH (std::is_same<Char, char>::value && !detail::is_constant_evaluated())
Copy link
Contributor

Choose a reason for hiding this comment

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

Just replace FMT_CONSTEXPR_CHAR_TRAITS_LENGTH with detail::const_check and revert other changes.

@@ -392,11 +392,12 @@ template <typename Char> class basic_string_view {
the size with ``std::char_traits<Char>::length``.
\endrst
*/
#if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr.
FMT_CONSTEXPR
// C++17's char_traits::length() is constexpr.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good but please move this comment back to the next line to avoid interfering with an apidoc comment above and apply clang-format.

@@ -392,11 +392,14 @@ template <typename Char> class basic_string_view {
the size with ``std::char_traits<Char>::length``.
\endrst
*/
#if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr.
FMT_CONSTEXPR
#if __cplusplus >= 201703L
Copy link
Contributor

Choose a reason for hiding this comment

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

Please revert back // C++17's char_traits::length() is constexpr. comment to this line.

@@ -392,11 +392,14 @@ template <typename Char> class basic_string_view {
the size with ``std::char_traits<Char>::length``.
\endrst
*/
#if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr.
FMT_CONSTEXPR
#if __cplusplus >= 201703L // C++17's char_traits::length() is constexpr.
Copy link
Contributor

Choose a reason for hiding this comment

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

Apply clang-format here, please

Comment on lines +398 to +400
FMT_INLINE
basic_string_view(const Char* s)
: data_(s) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did clang-format do this?

Copy link
Contributor

@alexezeder alexezeder Apr 7, 2021

Choose a reason for hiding this comment

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

Yeah, it's:

#if __cplusplus >= 201703L  // C++17's char_traits::length() is constexpr.
  FMT_CONSTEXPR
#endif
  FMT_INLINE
  basic_string_view(const Char* s) : data_(s) {

or:

#if __cplusplus >= 201703L  // C++17's char_traits::length() is constexpr.
  FMT_CONSTEXPR
#endif
  FMT_INLINE basic_string_view(const Char* s) : data_(s) {

or:

#if __cplusplus >= 201703L  // C++17's char_traits::length() is constexpr.
  constexpr
#endif
      FMT_INLINE
      basic_string_view(const Char* s)
      : data_(s) {

Copy link
Contributor

Choose a reason for hiding this comment

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

LOL

@vitaut vitaut merged commit 78776ee into fmtlib:master Apr 7, 2021
@vitaut
Copy link
Contributor

vitaut commented Apr 7, 2021

Merged, thanks.

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.

3 participants