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.