This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11078] [ABI] ICE in write_type with typeof and templates


------- Additional Comments From giovannibajo at libero dot it  2004-08-09 02:40 -------
Subject: Re:  [ABI] ICE in write_type with typeof and templates

ian at wasabisystems dot com wrote:

> The problem is that typeof can introduce expressions in cases where the
> mangling ABI does not permit them.

> template <class T1, class T2>
> typeof(T1() + T2()) add(T1 a, T2 b) { return a+b; }
> static double foo = add(3.1, 'c');
>
> When mangling add<double, char>(double, char), we need to mangle the
> return  type.  The mangling ABI requires this to be a <type>.  If we are
> going to mangle this using typeof, then we need to be able to use
> an <expression> in a <type>.
> But the mangling ABI does not provide any mechanism for that.

OK, there is no way to use it *directly*, but that would not make sense.
Instead, there are already <expression> nested within <type>, through the
IX<expression>E production.
I see the problem though. Something like this would suffice:

<type> ::= <typeof-type>
<typeof-type> ::= Y <expression> E

but this is a real ABI extension. Do we want this? I definitely *do* want it,
much better than an ICE or erroring out.
Using the built-in extension "u6typeof" does seem worse in the longer run since
it's clearly an abuse of it.

> However, I note that we don't actually have to use typeof when
> mangling this name.  When the compiler sees the template arguments,
> it can always resolve the typeof down to a basic type.
> Would it be reasonable to address the issue in that way?

No. There are many expressions that *could* be folded and simplified while
mangling the name (within a template argument), but the ABI explicitally
forbids this. Quoting: "Note that the expression is mangled without constant
folding or other simplification, and without parentheses, which are implicit in
the prefix representation. Except for the parentheses, therefore, it represents
the source token stream".

> What we need is a way to express a <type> as an
> <expr-primary>.  Since typeof only cares about the types of its
> arguments, I think we can get away with representing a type using
> the existing L <type> <value> E syntax, and always using the value "0".

I don't follow. We are trying to mangle a *type*, so we need to represent
typeof() in the context of <type>, not viceversa.

Also, notice that the example of this PR needs also *another* ABI extension,
see PR 6424 where I am going to add a comment about this.

Giovanni Bajo




-- 


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]