https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111723
Bug ID: 111723
Summary: #pragma GCC system_header suppresses errors from
narrowing conversions
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: de34 at live dot cn
Target Milestone: ---
In the following program, the conversions are narrowing, but only the one for
nonstd::in_fun_result is rejected.
When -Wsystem-headers is used, then the narrowing conversion for
std::ranges::in_fun_result are correctly diagnosed. But if -pedantic-errors and
-Wsystem-headers are used together, some standard headers are rejected.
Godbolt link: https://godbolt.org/z/fT7b16eoe
```
#include <algorithm>
#include <concepts>
#include <utility>
namespace nonstd {
template<class I, class F>
struct in_fun_result {
[[no_unique_address]] I in;
[[no_unique_address]] F fun;
template<class I2, class F2>
requires std::convertible_to<const I&, I2> &&
std::convertible_to<const F&, F2>
constexpr operator in_fun_result<I2, F2>() const&
{
return {in, fun};
}
template<class I2, class F2>
requires std::convertible_to<I, I2> && std::convertible_to<F, F2>
constexpr operator in_fun_result<I2, F2>() &&
{
return {std::move(in), std::move(fun)};
}
};
}
int main()
{
std::ranges::in_fun_result<int, int> r1{};
std::ranges::in_fun_result<short, short> r2 = r1; // should be error, but
not diagnosed by default
nonstd::in_fun_result<int, int> r3{};
nonstd::in_fun_result<short, short> r4 = r3; // error, rejected with
-pedantic-errors
}
```
It seems to me that #pragma GCC system_header shouldn't suppress errors from
narrowing conversions, because the diagnostics are required by the standard.