| Summary: | Compile-time less/more comparison of a pointer vs nullptr | ||
|---|---|---|---|
| Product: | gcc | Reporter: | Fedor Chelnokov <fchelnokov> |
| Component: | c++ | Assignee: | Not yet assigned to anyone <unassigned> |
| Status: | NEW --- | ||
| Severity: | normal | CC: | gabravier, webrown.cpp |
| Priority: | P3 | Keywords: | accepts-invalid |
| Version: | 12.0 | ||
| Target Milestone: | --- | ||
| See Also: |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70196 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111379 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103552 |
||
| Host: | Target: | ||
| Build: | Known to work: | ||
| Known to fail: | Last reconfirmed: | 2025-03-17 00:00:00 | |
| Bug Depends on: | |||
| Bug Blocks: | 55004 | ||
Confirmed. |
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