Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 13740
Product:  
Component:  
Status: RESOLVED
Resolution: WONTFIX
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Ian Lance Taylor <ian@airs.com>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 13740 depends on: Show dependency tree
Show dependency graph
Bug 13740 blocks: 12604

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2005-07-06 01:53 Opened: 2004-01-19 14:53
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.

------- Comment #1 From Andrew Pinski 2004-01-19 15:05 -------
Confirmed, I almost want to say this is a dup of bug 11078.

------- Comment #2 From Gabriel Dos Reis 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.

-- Gaby

------- Comment #3 From Ian Lance Taylor 2004-01-19 16:42 -------
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

------- Comment #4 From Gabriel Dos Reis 2004-01-19 17:43 -------
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

------- Comment #5 From Ian Lance Taylor 2004-01-19 18:01 -------
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

------- Comment #6 From Gabriel Dos Reis 2004-01-19 18:16 -------
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

------- Comment #7 From Jens Maurer 2004-07-13 19:10 -------
*** Bug 14691 has been marked as a duplicate of this bug. ***

------- Comment #8 From Andrew Pinski 2004-10-05 11:35 -------
*** Bug 17839 has been marked as a duplicate of this bug. ***

------- Comment #9 From Andrew Pinski 2004-10-05 14:22 -------
*** Bug 17842 has been marked as a duplicate of this bug. ***

------- Comment #10 From Andrew Pinski 2006-08-20 15:20 -------
*** Bug 28783 has been marked as a duplicate of this bug. ***

------- Comment #11 From Erik Kruus 2007-04-13 18:15 -------
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

------- Comment #12 From Jason Merrill 2007-10-04 01:05 -------
The testcase works fine if I change typeof to __decltype and add the necessary
template<> template<> to the third line.

------- Comment #13 From gdr@cs.tamu.edu 2007-10-04 01:46 -------
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

------- Comment #14 From Richard Guenther 2008-01-25 15:35 -------
*** Bug 34972 has been marked as a duplicate of this bug. ***

------- Comment #15 From Paolo Carlini 2008-02-26 10:57 -------
*** Bug 35374 has been marked as a duplicate of this bug. ***

Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug