public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111723] New: #pragma GCC system_header suppresses errors from narrowing conversions
@ 2023-10-08  2:13 de34 at live dot cn
  2023-10-08  2:21 ` [Bug c++/111723] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: de34 at live dot cn @ 2023-10-08  2:13 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/111723] #pragma GCC system_header suppresses errors from narrowing conversions
  2023-10-08  2:13 [Bug c++/111723] New: #pragma GCC system_header suppresses errors from narrowing conversions de34 at live dot cn
@ 2023-10-08  2:21 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-08  2:21 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111723

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think this is correct behavior really.
Note even clang with libc++ has the same behavior ...

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-08  2:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-08  2:13 [Bug c++/111723] New: #pragma GCC system_header suppresses errors from narrowing conversions de34 at live dot cn
2023-10-08  2:21 ` [Bug c++/111723] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).