[Bug c++/103402] New: Compile-time less/more comparison of a pointer vs nullptr
fchelnokov at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Nov 24 08:52:35 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103402
Bug ID: 103402
Summary: Compile-time less/more comparison of a pointer vs
nullptr
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
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
More information about the Gcc-bugs
mailing list