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

             Bug #: 50312
           Summary: ICE when calling offsetof() illegally on incomplete
                    template class
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: scov...@gmail.com


The following (admittedly illegal) code:

//== begin ======
#include <cstddef>
#ifdef BUG
template <typename T=int>
#define EXTRA <>
#else
#define EXTRA
#endif
struct foo {
    int bar;
    enum { END = offsetof(foo, bar) };
};
foo EXTRA a;
//== end =======

Causes an ICE when compiled with -DBUG:
$ g++ -DBUG bug.cpp
bug.cpp: In instantiation of ‘foo<>’:
bug.cpp:12:11:   instantiated from here
bug.cpp:10:10: internal compiler error: in tree_low_cst, at tree.h:4233
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

The above is for g++-4.6.1; the same error occurs for g++-4.5.0 (but at
tree.c:6202).

Compiling without -DBUG triggers a much more helpful diagnostic:
$ g++ bug.cpp
bug.cpp:10:18: error: invalid use of incomplete type ‘struct foo {aka struct
foo}’
bug.cpp:8:8: error: forward declaration of ‘struct foo {aka struct foo}’

Reply via email to