[Bug c++/67376] New: Comparison with pointer to past-the-end of array fails inside constant expression
ldionne.2 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Aug 27 23:00:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67376
Bug ID: 67376
Summary: Comparison with pointer to past-the-end of array fails
inside constant expression
Product: gcc
Version: 6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ldionne.2 at gmail dot com
Target Milestone: ---
The following code fails to compile on GCC trunk:
struct array {
int elems_[1];
};
constexpr array a{{0}};
static_assert(a.elems_ != a.elems_ + 1, "");
The error (formatted to fit the report) is
[snip]: error: non-constant condition for static assertion
static_assert(a.elems_ != a.elems_ + 1, "");
^
[snip]: error: ‘(((const int*)(& a.array::elems_)) !=
(((const int*)(& a.array::elems_)) + 4u))’
is not a constant expression
static_assert(a.elems_ != a.elems_ + 1, "");
^
It seems like GCC does not like the fact that we're comparing a past-the-end
pointer. But then again, that's weird because the following code works fine:
constexpr int a[1] = {0};
static_assert(a != a + 1, "");
Live example: http://melpon.org/wandbox/permlink/4QKMVN5vm3ePJcpY
More information about the Gcc-bugs
mailing list