public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28573]  New: incorrectly allowing non-constant expression to offsetof()
@ 2006-08-02 15:14 karl dot corbin at Summit dot Fiserv dot com
  2006-08-02 16:05 ` [Bug c++/28573] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: karl dot corbin at Summit dot Fiserv dot com @ 2006-08-02 15:14 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-07-04 15:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
2006-08-02 16:05 ` [Bug c++/28573] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-08-06 22:12 ` bangerth at dealii dot org
2006-08-07  7:38 ` bonzini at gnu dot org
2006-08-07 11:50 ` patchapp at dberlin dot org
2006-08-17  7:03 ` bonzini at gcc dot gnu dot org
2006-11-01 18:22 ` [Bug c++/28573] [4.0/4.1 " mmitchel at gcc dot gnu dot org
2007-02-03 18:42 ` gdr at gcc dot gnu dot org
2007-02-03 20:42 ` pinskia at gcc dot gnu dot org
2007-02-14  9:32 ` mmitchel at gcc dot gnu dot org
2008-07-04 15:47 ` [Bug c++/28573] [4.1 " jsm28 at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).