When moving from gcc3.3.3 to gcc4.1.0 the compiler is no longer capable of
calculate value of the offsetof macro expansion. Please find below a bare
minimum of 7 lines of code that compiles fine with gcc3.3.3 and fails on
gcc4.1.0 and gcc4.2.1.   

1. The program compiled: 
--- foo.cc
struct _mbuf_dummy {
  int xxx;
};

const unsigned long x = (const unsigned long) ( &( ((struct _mbuf_dummy *)
0)->xxx ) );

char qq[x]; // error: array bound is not an integer constant

#ifdef MORE
void foo() {
  static char zz[x]; // error: storage size of 'zz' isn't constant
}
#endif
---

2. Trace of the session using gcc4.2.1:
---
[EMAIL PROTECTED]:~> which g++
/home/qkarejo/bin/g++
[EMAIL PROTECTED]:~> g++ foo.cc
foo.cc:7: error: array bound is not an integer constant
[EMAIL PROTECTED]:~> g++ -DMORE foo.cc
foo.cc:7: error: array bound is not an integer constant
foo.cc: In function ‘void foo()’:
foo.cc:11: error: storage size of ‘zz’ isn't constant
[EMAIL PROTECTED]:~> g++ -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/home/qkarejo --enable-languages=c,c++
Thread model: posix
gcc version 4.2.1
[EMAIL PROTECTED]:~>
---

Session with "-### -S" below
---
[EMAIL PROTECTED]:~> gcc -### -S foo.cc
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/home/qkarejo --enable-languages=c,c++
Thread model: posix
gcc version 4.2.1
 "/home/qkarejo/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/cc1plus" "-quiet"
"-D_GNU_SOURCE" "foo.cc" "-quiet" "-dumpbase" "foo.cc" "-mtune=generic"
"-auxbase" "foo" "-o" "foo.s"
---


-- 
           Summary: offsetof calculation not constant in compile time (?)
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kare at modlab dot se
 GCC build triplet: x86_64-suse-linux
  GCC host triplet: x86_64-suse-linux
GCC target triplet: x86_64-suse-linux


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

Reply via email to