[Bug c++/37920] ICE (segv) with typename typeof in local struct

mbarrien at cs dot stanford dot edu gcc-bugzilla@gcc.gnu.org
Fri Aug 28 05:13:00 GMT 2009



------- Comment #5 from mbarrien at cs dot stanford dot edu  2009-08-28 05:12 -------
I just ran into this bug too. Before I found this bug report, I did some more
investigation to characterize the bug a little more. I am including my version
of the reduced test case, with more commentary inline.
--
// Cause: Use of __typeof__ on a templated type (dependent upon template
arguments of outer function/class) as the type of an argument for any function
in a locally defined class crashes g++. Since this successfully typechecks, I
suspect that during symbol lookup in some IR generating phase, for arguments to
a function of a local class, if a __typeof__ is involved, g++ does not properly
lookup symbols in the outer function/class symbol table.

template<typename ImplList> struct VertexData;

template<typename LM> void init() {            // Making non-templated function
eliminates ICE. (Also ICEs for non-templated member function in a templated
class.)
    VertexData<LM>* v0;                        // Making this non-template
eliminates ICE. Changing LM to int eliminates ICE.
    typedef __typeof__(v0) v0_type_;           // Using VertexData<LM> instead
of __typeof__(v0) eliminates ICE.  Using __decltype(v0) still causes ICE in GCC
4.3.4, but eliminates ICE in GCC 4.4
    struct MeshConditionalInit {               // Removing body of struct
eliminates ICE.
        MeshConditionalInit(v0_type_& v0) { }  // Removing argument eliminates
ICE. Using v0_type_ only in body and not as argument eliminates ICE.
    };                                         // ICE still occurs when used as
function argument instead of constructor argument.
    MeshConditionalInit bar138(v0);
}

int main(int argn, char ** argv) {
    init<int>();
}
--
ICE occurs with no special compile flags in the following standard distribution
packages of GCC:
4.1.3, 4.2.4, and 4.3.3 on Ubuntu 9.04
4.0.1 and 4.2.1 on Mac OS X 10.5 (the versions with XCode)
4.4.0 on Mac OS X 10.5 (MacPorts build)

And because I got bored, here's a 140-character twitterable version of an even
smaller test case (inlines the typeof into the constructor's argument, removing
the typedef, which may not be legal, but definitely still causes an ICE in
GCC):
--
/*GCC Instacrash*/ template<class T> class C;template<class U> void f() {C<U>*
i;struct S{S(__typeof__(i)& i){}}s(i);}int main(){f<int>();}


-- 


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



More information about the Gcc-bugs mailing list