public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114573] New: -Wzero-as-null-pointer-constant complains on enum with explicit cast
@ 2024-04-03 10:08 ossman at cendio dot se
  2024-04-03 11:31 ` [Bug c++/114573] " rguenth at gcc dot gnu.org
  2024-04-03 13:49 ` ossman at cendio dot se
  0 siblings, 2 replies; 3+ messages in thread
From: ossman at cendio dot se @ 2024-04-03 10:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114573
           Summary: -Wzero-as-null-pointer-constant complains on enum with
                    explicit cast
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ossman at cendio dot se
  Target Milestone: ---

g++ complains about the following code when -Wzero-as-null-pointer-constant is
given:

> enum { ZERO, ONE, TWO };
> 
> extern int func(const char *a);
> 
> void zeroenum()
> {
>     func((const char*)ZERO);
> }

Oddly enough, it also gives the wrong location for the issue:

> nulls.cxx: In function ‘void zeroenum()’:
> nulls.cxx:8:1: warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]
>     8 | }
>       | ^

clang does not complain about this, neither does older versions of gcc (tested
with 5.5.0). So it's some form of regression.


The above example is a bit contrived, but this pattern is moderately common in
that an argument can be either a pointer or an integer. E.g. CopyFromParent in
libX11, or FLTK menus.

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

* [Bug c++/114573] -Wzero-as-null-pointer-constant complains on enum with explicit cast
  2024-04-03 10:08 [Bug c++/114573] New: -Wzero-as-null-pointer-constant complains on enum with explicit cast ossman at cendio dot se
@ 2024-04-03 11:31 ` rguenth at gcc dot gnu.org
  2024-04-03 13:49 ` ossman at cendio dot se
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-03 11:31 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
   Last reconfirmed|                            |2024-04-03
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  Note this diagnostic isn't enabled with -Wall or -Wextra.

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

* [Bug c++/114573] -Wzero-as-null-pointer-constant complains on enum with explicit cast
  2024-04-03 10:08 [Bug c++/114573] New: -Wzero-as-null-pointer-constant complains on enum with explicit cast ossman at cendio dot se
  2024-04-03 11:31 ` [Bug c++/114573] " rguenth at gcc dot gnu.org
@ 2024-04-03 13:49 ` ossman at cendio dot se
  1 sibling, 0 replies; 3+ messages in thread
From: ossman at cendio dot se @ 2024-04-03 13:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Pierre Ossman <ossman at cendio dot se> ---
Indeed. It is part of an effort to have a more modern C++ style in TigerVNC.
One item was preferring nullptr over NULL, and this issue became an obstacle
there.

Right now, we did a #pragma, but if there is a better workaround, then we are
all ears.

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

end of thread, other threads:[~2024-04-03 13:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-03 10:08 [Bug c++/114573] New: -Wzero-as-null-pointer-constant complains on enum with explicit cast ossman at cendio dot se
2024-04-03 11:31 ` [Bug c++/114573] " rguenth at gcc dot gnu.org
2024-04-03 13:49 ` ossman at cendio dot se

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).