public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113028] New: GCC diagnostic pop changes errors to warnings
@ 2023-12-15  4:30 dustbingtb at verizon dot net
  2023-12-15  4:53 ` [Bug c++/113028] " pinskia at gcc dot gnu.org
  2023-12-15  5:02 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: dustbingtb at verizon dot net @ 2023-12-15  4:30 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113028
           Summary: GCC diagnostic pop changes errors to warnings
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dustbingtb at verizon dot net
  Target Milestone: ---
            Target: x86_64-linux-gnu

While debugging compile errors in open-source code after upgrading gcc from
9.x, I ran into this problem with GCC diagnostic push/ignored/pop. It seems
similar to old/resolved Bug 66098/Bug 66711, except it doesn't involve any
-Werror command-line option; in fact, it can be reproduced with just "g++
testfile.cpp". This diagnostic error was added in gcc 10.x, so the specific
example isn't meaningful prior to that; however, the problem persists through
gcc 13.2 and trunk, as per godbolt.

The following code easily demonstrates all the investigative cases just by
modifying the value of TEST_CASE:
- TEST_CASE 0 shows two "error: narrowing conversion of '-2023406815' from
'int' to 'unsigned int' [-Wnarrowing]", which is apparently a correct error
diagnostic that should have been reported by earlier gcc but wasn't (at least,
earlier clang has reported this diagnostic error since at least 2012, and
handles the push/pop properly since then also, BTW).
- TEST_CASE 1 just demonstrates that, when the first error's code is removed
from compilation, the second error still fires as expected (contrast with
behavior of TEST_CASE 3).
- TEST_CASE 2 uses GCC diagnostic ignored "-Wnarrowing" to disable both errors,
which works.
- TEST_CASE 3: the bug. GCC diagnostic push/ignored suppress the first error,
but pop does NOT restore the second error; instead, the second error
mysteriously becomes a warning instead!

// 0: two errors; 1: one (2nd) error; 2: both ignored; 3: 1st ignored 2nd
warns!
#define TEST_CASE 3

int main(int argc, char *argv[])
{
    const int HEX_CONST = (int)0x87654321L;

  #if TEST_CASE == 3
    _Pragma("GCC diagnostic push")
  #endif
  #if TEST_CASE >= 2
    _Pragma("GCC diagnostic ignored \"-Wnarrowing\"")
  #endif
    unsigned uval = (unsigned)argc;
  #if TEST_CASE != 1
    switch (uval)
    {
        case HEX_CONST: ++uval;
        default: break;
    }
  #endif  // TEST_CASE != 1

  #if TEST_CASE == 3
    _Pragma("GCC diagnostic pop")
  #endif
    switch (--uval)
    {
        case HEX_CONST: return 0;
        default: return 1;
    }
}

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

* [Bug c++/113028] GCC diagnostic pop changes errors to warnings
  2023-12-15  4:30 [Bug c++/113028] New: GCC diagnostic pop changes errors to warnings dustbingtb at verizon dot net
@ 2023-12-15  4:53 ` pinskia at gcc dot gnu.org
  2023-12-15  5:02 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-15  4:53 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.

*** This bug has been marked as a duplicate of bug 111918 ***

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

* [Bug c++/113028] GCC diagnostic pop changes errors to warnings
  2023-12-15  4:30 [Bug c++/113028] New: GCC diagnostic pop changes errors to warnings dustbingtb at verizon dot net
  2023-12-15  4:53 ` [Bug c++/113028] " pinskia at gcc dot gnu.org
@ 2023-12-15  5:02 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-15  5:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Sorry if I was terse.
This is exact same issue as reported in PR 111918 and there has been a patch
that was posted to fix the issue (though I don't think it has been reviewed
yet).

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

end of thread, other threads:[~2023-12-15  5:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-15  4:30 [Bug c++/113028] New: GCC diagnostic pop changes errors to warnings dustbingtb at verizon dot net
2023-12-15  4:53 ` [Bug c++/113028] " pinskia at gcc dot gnu.org
2023-12-15  5:02 ` 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).