Skip to content

Wzero-as-null-pointer-constant warns when using operator<=> #43670

@davidstone

Description

@davidstone
Bugzilla Link 44325
Version unspecified
OS Linux
CC @adrianimboden,@dwblaikie,@0x8000-0000,@dvhwgumby,@mclow,@mwinterb,@mizvekov,@zygoloid,@Weverything
Fixed by commit(s) 1f06f41, 678c259

Extended Description

#include <compare>

auto b = 1 <=> 2 < 0;

Outputs:

<source>:3:20: warning: zero as null pointer constant [-Wzero-as-null-pointer-constant]

auto b = 1 <=> 2 < 0;

                   ^

                   nullptr

1 warning generated.

Compiler returned: 0

See it live: https://godbolt.org/z/9a8cnD

Technically, the warning is accurate. User code has a literal 0 that is being passed to a function accepting a nullptr. However, this is an implementation detail of the standard library and the intended interface for use (users should not use nullptr there), so we should not warn users for doing so (and definitely should not direct them to change their code).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaconfirmedVerified by a second partylibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions