[Bug c++/85662] New: regression since 6: "error: non-constant condition for static assertion" from __builtin_offsetof in C++
roland at gnu dot org
gcc-bugzilla@gcc.gnu.org
Sat May 5 05:20:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85662
Bug ID: 85662
Summary: regression since 6: "error: non-constant condition for
static assertion" from __builtin_offsetof in C++
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: roland at gnu dot org
CC: msebor at gcc dot gnu.org
Target Milestone: ---
This code was accepted by GCC 6 but is rejected by GCC 7, 8, and trunk.
The error message appears to complain that the result of the __builtin_offsetof
expression has pointer type rather than size_t.
$ cat foo.cc
struct foo {
unsigned long x[31];
};
struct bar {
bool b;
foo f;
};
static_assert(__builtin_offsetof(bar, f.x[31 - 1]) == 8 + ((31 - 1) * 8), "");
$ ./gcc/xgcc -Bgcc/ -O2 -S foo.cc
foo.cc:10:52: error: non-constant condition for static assertion
static_assert(__builtin_offsetof(bar, f.x[31 - 1]) == 8 + ((31 - 1) * 8), "");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
foo.cc:10:52: error: value ‘8’ of type ‘bar*’ is not a constant expression
[Exit 1]
The equivalent C code:
struct foo {
unsigned long x[31];
};
struct bar {
_Bool b;
struct foo f;
};
_Static_assert(__builtin_offsetof(struct bar, f.x[31 - 1]) == 8 + ((31 - 1) *
8), "");
is accepted without complaint.
bisected to r238909 (git cb7688247fdcff08df18baed1317fce5b0e9db13)
gcc/cp/ChangeLog
2016-07-30 Martin Sebor <msebor@redhat.com>
PR c++/60760
PR c++/71091
* constexpr.c (cxx_eval_binary_expression): Reject invalid expressions
involving null pointers.
(cxx_eval_component_reference): Reject null pointer dereferences.
(cxx_eval_indirect_ref): Reject indirecting through null pointers.
(cxx_eval_constant_expression): Reject invalid expressions involving
null pointers.
More information about the Gcc-bugs
mailing list