This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/33059] New: offsetof calculation not constant in compile time (?)


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:
---
qkarejo@ulinpc181:~> which g++
/home/qkarejo/bin/g++
qkarejo@ulinpc181:~> g++ foo.cc
foo.cc:7: error: array bound is not an integer constant
qkarejo@ulinpc181:~> 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
qkarejo@ulinpc181:~> 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
qkarejo@ulinpc181:~>
---

Session with "-### -S" below
---
qkarejo@ulinpc181:~> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]