https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111379

            Bug ID: 111379
           Summary: comparison between unequal pointers to void should be
                    illegal during constant evaluation
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pkeir at outlook dot com
  Target Milestone: ---

[DR 2526](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2526)
clarifies that in C++23 comparison between unequal pointers to void has
unspecified result. As unspecified behaviour cannot be executed in a constant
expression, the code below should not compile.

In fact without DR 2526, the comparison would have undefined behaviour, which
also cannot be executed in a constant expression.

constexpr bool compare_void_pointers()
{
  int a[2];
  void* vp1 = &a[0], * vp2 = &a[1];
  return vp1 < vp2;
}

static_assert(compare_void_pointers());

Reply via email to