http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14932

--- Comment #15 from zhangjingwang at gmail dot com ---
(In reply to zhangjingwang from comment #14)
> #include <stdio.h>
> #include <stddef.h>
> 
> struct TestStruct {
>   int array[13];
> };
> 
> struct TempStruct {
>   int index;
> };
> 
> int array_offset(struct TempStruct *index)
> {
>   return offsetof(struct TestStruct, array[index->index]);
> }
> 
> int main(int argc, char **argv)
> {
>   struct TempStruct tmp = {3};
>   printf("Offset of array[3] is %d.\n", array_offset(&tmp));
> }
> 
> test.c: In function 'int array_offset(TempStruct*)':
> test.c:14: error: 'index' cannot appear in a constant-expression
> test.c:14: error: '->' cannot appear in a constant-expression
> 
> This can't be compiled by the following versions of g++ (while it is
> accepted by gcc of the same version and clang++ 3.4):
> g++ (Debian 4.4.5-8) 4.4.5
> Copyright (C) 2010 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> :AND:
> g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3)
> Copyright (C) 2010 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> 
> So I don't think this bug is fixed for those versions.

OK, I've tested the latest gcc 4.8.1 and the problem is fixed in the latest
version. g++ there will accept the code above without any problem.

Reply via email to