Bug 103402 - Compile-time less/more comparison of a pointer vs nullptr
Summary: Compile-time less/more comparison of a pointer vs nullptr
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2021-11-24 08:52 UTC by Fedor Chelnokov
Modified: 2025-03-17 22:02 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2025-03-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fedor Chelnokov 2021-11-24 08:52:35 UTC
The following code is invalid and must be rejected:
```
int main() {
    static constexpr int x = 1;
    constexpr const int * p = nullptr;
    static_assert( p < &x );
}
```
because less/more comparison with nullptr has unspecified value and cannot appear in a constant expression.

Clang correctly rejects the code, demo: https://gcc.godbolt.org/z/E4ME4zh3M
Comment 1 Drea Pinski 2021-11-24 09:02:54 UTC
Confirmed.