-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Open
Labels
accepts-invalidlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Description
Conversions functions of ranges
algorithm result types are specified to copy-list-initialize the results ([algorithms.results]).
As a result, narrowing conversions should cause hard errors in the functions. However, Clang seems to suppress the errors due to #pragma GCC system_header
. Godbolt link.
#include <algorithm>
#include <concepts>
template <class I1>
struct my_in_found_result {
[[no_unique_address]] I1 in;
bool found;
template <class I2>
requires std::convertible_to<const I1&, I2>
constexpr operator my_in_found_result<I2>() const& {
return {in, found};
}
template <class I2>
requires std::convertible_to<I1, I2>
constexpr operator my_in_found_result<I2>() && {
return {std::move(in), found};
}
};
int main(int, char**) {
{
std::ranges::in_found_result<double> res{10, true};
std::ranges::in_found_result<int> res2 [[maybe_unused]] = res; // hard error suppressed
}
{
my_in_found_result<double> res{10, true};
my_in_found_result<int> res2 [[maybe_unused]] = res; // correctly rejected
}
}
Although it might deserve an LWG issue to fix the constraints, i.e. either accept narrowing conversions by not using list-initialization, or constrain harder to reject narrowing conversions in an SFINAE-friendly way, it seems to me that we shouldn't suppress -Wc++11-narrowing
in standard library headers.
Metadata
Metadata
Assignees
Labels
accepts-invalidlibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.