Skip to content

[libc++][clang] Libc++ implements std::from_chars with default argument as one more overload, is it allowed? #91268

@SainoNamkho

Description

@SainoNamkho

https://eel.is/c++draft/charconv#from.chars-1 says the signature should be

constexpr from_chars_result from_chars(const char* first, const char* last,
                                       integer-type& value, int base = 10);

But is implemented as

template <typename _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>
inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result
from_chars(const char* __first, const char* __last, _Tp& __value) {
return std::__from_chars_atoi(__first, __last, __value);
}
template <typename _Tp, __enable_if_t<is_integral<_Tp>::value, int> = 0>
inline _LIBCPP_CONSTEXPR_SINCE_CXX23 _LIBCPP_HIDE_FROM_ABI from_chars_result
from_chars(const char* __first, const char* __last, _Tp& __value, int __base) {
_LIBCPP_ASSERT_UNCATEGORIZED(2 <= __base && __base <= 36, "base not in [2, 36]");
return std::__from_chars_integral(__first, __last, __value, __base);
}

I'm not should if there's any legal ways to inspect this. And if the following code is well-formed, it does make a difference.
https://godbolt.org/z/vE95qzhEM

#include <charconv>

static_assert(requires {
    static_cast<std::from_chars_result(*)(const char*, const char*, int&)>(std::from_chars);
});

In addition, if this code is rejected, should the requires expression cause a hard error, or the code fail due to static_assert failure?

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions