https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97145
Bug ID: 97145
Summary: Sanitizer pointer-subtract breaks constexpr functions
subtracting pointers
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: chfast at gmail dot com
Target Milestone: ---
Having a constexpr function that subtracts two pointers does not work in
constexpr context when building with -fsanitize=address,pointer-subtract.
GCC version: starts with 8.1 where pointer-subtract was introduced, up to
trunk.
Minimal code:
constexpr char* a = nullptr;
constexpr auto d = a - a;
<source>:3:22: error: '__builtin___sanitizer_ptr_sub(0, 0)' is not a constant
expression
3 | constexpr auto d = a - a;
| ~~^~~
https://godbolt.org/z/qWxT9v