This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
I get an ICE when compiling this test case with the current mainline: template<int n> class X {template<class Y> typeof(Y::y) foo(typeof(Y::y));}; class Y { public: static int y; }; typeof(Y::y) X<0>::foo<Y>(typeof(Y::y)) { } foo4.cc:3: internal compiler error: in write_type, at cp/mangle.c:1558 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions. Note that the current mangling ABI doesn't specify how to handle typeof, which is after all a GNU extension. I think that mangling this name will require an extension to the mangling ABI. I think this could be handled by adding a new unary operator, ty, which represents typeof applied to its argument. Alternatively, the use of typeof could be replaced by the resulting type when mangling the template name. I suppose that would some types of templates equivalent although they didn't look equivalent. It's hard to know how to handle an extension like this.
Confirmed, I almost want to say this is a dup of bug 11078.
Subject: Re: New: ICE when mangling template which uses typeof "ian at airs dot com" <gcc-bugzilla@gcc.gnu.org> writes: | I get an ICE when compiling this test case with the current mainline: | | template<int n> class X {template<class Y> typeof(Y::y) foo(typeof(Y::y));}; | class Y { public: static int y; }; | typeof(Y::y) X<0>::foo<Y>(typeof(Y::y)) { } | | foo4.cc:3: internal compiler error: in write_type, at cp/mangle.c:1558 | Please submit a full bug report, | with preprocessed source if appropriate. | See <URL:http://gcc.gnu.org/bugs.html> for instructions. I think this is a know bug. Nathan and I had exchanged mails on this topic when I first implemented the C++ decltype proposal on the cxx-reflection-branch. http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02242.html and I believe I have implemented that on the cxx-reflection branch. Maybe you might want to review his suggestion in the message referenced above. -- Gaby
Subject: Re: ICE when mangling template which uses typeof "gdr at integrable-solutions dot net" <gcc-bugzilla@gcc.gnu.org> writes: > ------- Additional Comments From gdr at integrable-solutions dot net 2004-01-19 16:17 ------- > Subject: Re: New: ICE when mangling template which uses typeof > > "ian at airs dot com" <gcc-bugzilla@gcc.gnu.org> writes: > > | I get an ICE when compiling this test case with the current mainline: > | > | template<int n> class X {template<class Y> typeof(Y::y) foo(typeof(Y::y));}; > | class Y { public: static int y; }; > | typeof(Y::y) X<0>::foo<Y>(typeof(Y::y)) { } > | > | foo4.cc:3: internal compiler error: in write_type, at cp/mangle.c:1558 > | Please submit a full bug report, > | with preprocessed source if appropriate. > | See <URL:http://gcc.gnu.org/bugs.html> for instructions. > > I think this is a know bug. Nathan and I had exchanged mails on this > topic when I first implemented the C++ decltype proposal on the > cxx-reflection-branch. > > http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02242.html > > and I believe I have implemented that on the cxx-reflection branch. > > Maybe you might want to review his suggestion in the message > referenced above. Thanks for the pointer. I don't think Nathan's proposal will work as-is, because 'X' is already meaningful in <template-arg> to introduce an <expression> used as a template argument. Since a <template-arg> can also be a <type>, we don't want to use 'X' in <type>, since that will make <template-arg> ambiguous. For the particular case of the GNU extension typeof, it seems to me that we can only see that extension in a template argument. Any use of typeof which appears somewhere else will be reduced to the base type for the purposes of mangling. I think typeof can be handled as a unary operator in an expression, must like sizeof(type), which is why I suggested mangling it as ty <type>. However, I gather that cxx-reflection requires the ability to mangle types in a more general manner. In particular, you need to mangle types which use expressions in some fashion. I don't really know what cxx-reflection is for, so this is a guess. Nathan's proposal is quite general but not wholly general. In particular Nathan's proposal has a nearly arbitrary number of types and expressions, but they are not put together in an arbitrary way. Your patch here: http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02226.html suggests that you need to be able to specify a single type or a single expression. To specify a single type, you can just use the existing U mangling: <type> ::= U <source-name> <type> To specify a single expression as part of a <type>, we do need an extension. We can't use 'X' for this, but we could use 'Y': <type> ::= Y <expression> E Or we could follow Nathan's suggestion, using 'Y': <type> ::= Y <digit1> <digit2> <sourcename> <type>... [n1] <expression>...[n2] There is no current mangling which works like this, though, so I think it would be more in the spirit of the current ABI to do this: <type> ::= Y <sourcename> <template-arg>+ E This would be described as a vendor-specified type which takes arbitrary arguments. The arguments are anything which is permitted in a template expansion, which permits both types and expressions. I think that ought to be sufficiently flexible. Ian
Subject: Re: ICE when mangling template which uses typeof "ian at wasabisystems dot com" <gcc-bugzilla@gcc.gnu.org> writes: | Thanks for the pointer. Thanks to *you* for the quick and extensive answer! | I don't think Nathan's proposal will work as-is, because 'X' is | already meaningful in <template-arg> to introduce an <expression> used | as a template argument. Since a <template-arg> can also be a <type>, | we don't want to use 'X' in <type>, since that will make | <template-arg> ambiguous. Aha, that is a good point. I'll change http://gcc.gnu.org/ml/gcc-patches/2003-10/msg00496.html to follow your suggestion. | For the particular case of the GNU extension typeof, it seems to me | that we can only see that extension in a template argument. Any use And in function template return type too. No? | of typeof which appears somewhere else will be reduced to the base | type for the purposes of mangling. I think typeof can be handled as a | unary operator in an expression, must like sizeof(type), which is why | I suggested mangling it as ty <type>. | | However, I gather that cxx-reflection requires the ability to mangle | types in a more general manner. In particular, you need to mangle | types which use expressions in some fashion. I don't really know what | cxx-reflection is for, so this is a guess. Your guess is basically correct. After GCC-3.3.3 is out I'll post extensive documentations for that branch and make it "alive" :-) | Nathan's proposal is quite general but not wholly general. In | particular Nathan's proposal has a nearly arbitrary number of types | and expressions, but they are not put together in an arbitrary way. | | Your patch here: | http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02226.html | suggests that you need to be able to specify a single type or a single | expression. Yes, that is true in the particular case of decltype. But we can get more "advanced" operators. For example, we may end up having __builtin_offsetof(type, member) and type or member are dependent on a template parameter. | To specify a single type, you can just use the existing U mangling: | <type> ::= U <source-name> <type> | | To specify a single expression as part of a <type>, we do need an | extension. We can't use 'X' for this, but we could use 'Y': | <type> ::= Y <expression> E | | Or we could follow Nathan's suggestion, using 'Y': | <type> ::= Y <digit1> <digit2> <sourcename> <type>... [n1] <expression>...[n2] for things like __builtin_offsetof, that might be needed. | There is no current mangling which works like this, though, so I think | it would be more in the spirit of the current ABI to do this: | <type> ::= Y <sourcename> <template-arg>+ E Yes I like its simplicity, but it would fail to support things __builtin_offsetof, no? | This would be described as a vendor-specified type which takes | arbitrary arguments. The arguments are anything which is permitted in | a template expansion, which permits both types and expressions. I | think that ought to be sufficiently flexible. Agreed. Isn't this an issue that should probably be raised on the ABI reflector or can we just go ahead set precedence? -- Gaby
Subject: Re: ICE when mangling template which uses typeof "gdr at integrable-solutions dot net" <gcc-bugzilla@gcc.gnu.org> writes: > | For the particular case of the GNU extension typeof, it seems to me > | that we can only see that extension in a template argument. Any use > > And in function template return type too. No? Yes, true. > | To specify a single type, you can just use the existing U mangling: > | <type> ::= U <source-name> <type> > | > | To specify a single expression as part of a <type>, we do need an > | extension. We can't use 'X' for this, but we could use 'Y': > | <type> ::= Y <expression> E > | > | Or we could follow Nathan's suggestion, using 'Y': > | <type> ::= Y <digit1> <digit2> <sourcename> <type>... [n1] <expression>...[n2] > > for things like __builtin_offsetof, that might be needed. > > | There is no current mangling which works like this, though, so I think > | it would be more in the spirit of the current ABI to do this: > | <type> ::= Y <sourcename> <template-arg>+ E > > Yes I like its simplicity, but it would fail to support things > __builtin_offsetof, no? I don't see why. It ought to support anythning which Nathan's suggestion would support. For example, __builtin_offsetof(foo, bar) might be Y18__builtin_offsetof3foo3barE and __builtin_offsetof(foo<int>, bar) might be Y18__builtin_offsetof3fooIiE3barE In general, this approach would let you qualify the type using anything which can appear as a template parameter, which includes any type or expression. What else would you like to see here? > | This would be described as a vendor-specified type which takes > | arbitrary arguments. The arguments are anything which is permitted in > | a template expansion, which permits both types and expressions. I > | think that ought to be sufficiently flexible. > > Agreed. Isn't this an issue that should probably be raised on the ABI > reflector or can we just go ahead set precedence? I don't know. You would have to ask somebody at CodeSourcery what they think. Ian
Subject: Re: ICE when mangling template which uses typeof "ian at wasabisystems dot com" <gcc-bugzilla@gcc.gnu.org> writes: [...] | > | There is no current mangling which works like this, though, so I think | > | it would be more in the spirit of the current ABI to do this: | > | <type> ::= Y <sourcename> <template-arg>+ E | > | > Yes I like its simplicity, but it would fail to support things | > __builtin_offsetof, no? | | I don't see why. It ought to support anythning which Nathan's | suggestion would support. For example, __builtin_offsetof(foo, bar) | might be | Y18__builtin_offsetof3foo3barE | and __builtin_offsetof(foo<int>, bar) might be | Y18__builtin_offsetof3fooIiE3barE | | In general, this approach would let you qualify the type using | anything which can appear as a template parameter, which includes any | type or expression. What else would you like to see here? Nothing. Your example washed my confusion. Thanks! I like your suggestion better. -- Gaby
*** Bug 14691 has been marked as a duplicate of this bug. ***
*** Bug 17839 has been marked as a duplicate of this bug. ***
*** Bug 17842 has been marked as a duplicate of this bug. ***
*** Bug 28783 has been marked as a duplicate of this bug. ***
A possibly shorter testcase for this bug. template <class T> void func( T x ) { struct foo { static void bar( typeof(x) a ) { ; } }; foo::bar(x); } int main(int,char**) { int i=2; func(i); } Also bugs with `typeof typedef' outside foo. But OK with `bar( T &a )' (I wanted something like this while using macros to generate __attribute__((noinline)) `bar' calls so that debug stuff in headers wouldn't kill gcc inlining --- unexecuted if(0) code counts to inlining limits and moving it to and inner foo::bar can greatly help inlining. It worked great as long as typeof has no relation to any template type parameter) This was with gcc (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8) g++ -c bug0.cc -o bug0.o // /usr/libexec/gcc/i686-redhat-linux/4.0.2/cc1plus -quiet -D_GNU_SOURCE bug0.cc -quiet -dumpbase bug0.cc -mtune=pentiumpro -auxbase-strip bug0.o -o - -frandom-seed=0
The testcase works fine if I change typeof to __decltype and add the necessary template<> template<> to the third line.
Subject: Re: ICE when mangling template which uses typeof "jason at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> writes: | The testcase works fine if I change typeof to __decltype and add the necessary | template<> template<> to the third line. That is fine with me. Should we deprecate typeof? -- Gaby
*** Bug 34972 has been marked as a duplicate of this bug. ***
*** Bug 35374 has been marked as a duplicate of this bug. ***