GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

C++: Suppresses -Wzero-as-null-pointer-constant for spaceship operator.

Disables the `-Wzero-as-null-pointer-constant` warning when using the spaceship operator (`<=>`) in the standard way.

The compiler now avoids issuing the -Wzero-as-null-pointer-constant warning when the spaceship operator (<=>) is used in the recommended pattern (x <=> y) < 0. This pattern is used for comparisons and the warning is unnecessary, as the standard library itself uses this pattern. The warning is already suppressed within the <compare> header.

In Details

This commit modifies build_over_call in gcc/cp/call.cc to avoid the -Wzero-as-null-pointer-constant warning when it's disabled around the called function, specifically in the context of the spaceship operator (<=>). The spaceship operator returns a type that can be compared to zero, so the warning is spurious in this case.

For Context

In C++, the spaceship operator (<=>) is used for comparing two values. The standard way to use it involves comparing the result of the spaceship operator with zero. However, GCC could incorrectly issue a warning (-Wzero-as-null-pointer-constant) in this situation. This commit prevents that warning from appearing when the spaceship operator is used correctly, reducing unnecessary noise for developers.

Filed Under: c++warningspaceship operatorcode quality