[Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Jul 15 21:09:40 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
struct S { int a; int b[15]; };
int
foo (int n)
{
int m = n;
return __builtin_offsetof (S, b[m]);
}
has been rejected for years, while
struct S { int a; int b[15]; };
int
foo (int n)
{
return __builtin_offsetof (S, b[n]);
}
has been accepted.
The comment in cp/parser.c says:
/* ??? For offsetof, there is a question of what to allow here. If
offsetof is not being used in an integral constant expression context,
then we *could* get the right answer by computing the value at runtime.
If we are in an integral constant expression context, then we might
could accept any constant expression; hard to say without analysis.
Rather than open the barn door too wide right away, allow only integer
constant expressions here. */
More information about the Gcc-bugs
mailing list