The following code incorrectly compiles, and worse returns incorrect result.
on i686-pc-linux-gnu, both 4.1.0 and 4.1.1

-- start snip
#include <stddef.h>

// (incomplete) template class that encapsulates an array of chars
template<int i> class CharArray
{
public:
   char d[i];
   char& operator [] ( int indx )
   {
      return d[indx];
   }
};

struct Foo
{
   int i;
   CharArray<44> caCharArray;
};


int main( int argc, char* argv[] )
{
   Foo foo;
   int i;

// Shouldn't compile, and worse results in incorrect offset.
   i = offsetof(Foo, caCharArray[0]);

}

-- end snip
variables as an array index correctly give an error, but unfortunatly not
everything that looks like an constant array index is.


-- 
           Summary: incorrectly allowing non-constant expression to
                    offsetof()
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: karl dot corbin at Summit dot Fiserv dot com


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

Reply via email to