This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/7112: Regression: ICE on C++ code involving templates and sizeof
- From: "M.E. O'Neill" <oneill at cs dot hmc dot edu>
- To: lerdsuwa at users dot sourceforge dot net
- Cc: gcc-gnats at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, oneill at cs dot hmc dot edu, gcc-bugs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Date: Tue, 25 Jun 2002 11:07:45 -0700 (PDT)
- Subject: Re: c++/7112: Regression: ICE on C++ code involving templates and sizeof
Kriang Lerdsuwanakij writes:
> This has to do with the ABI. Mangling of 'sizeof expr' is specified
> in the ABI and implemented in GCC, but not its companion 'sizeof(type)'.
This ABI classification seems curious to me -- if I simplify the test
by changing Foobar<sizeof(Wrapper<A>)> to Foobar<sizeof(A)> everything
compiles okay.
i.e.,
template <typename A>
Foobar<sizeof(A)> *
compiler_bug (A)
{
return 0;
}
instantiated with A=int compiles as:
__Z12compiler_bugIiEP6FoobarIXszT_EET_
which demangles as:
Foobar< sizeof(int)>* compiler_bug<int>(int)
This seems to indicate that at least some of the time, name mangling
*can* represent sizeof(TYPE) [although I'm unclear why sizeof(TYPE) or
sizeof(EXPR) would be necessary anyway -- why encode sizeof(int)
symbolically when we could say (int)4, and *would* say (int)4 in other
resonably similar circumstances?]
Similarly:
template <typename A>
Foobar<sizeof(Wrapper<int>)> *
compiler_bug (A)
{
return 0;
}
compiles with the signature I'd actually expect for this code,
__Z12compiler_bugIiEP6FoobarILi1EET_
i.e. Foobar<(int)1>* compiler_bug<int>(int)
After all, sizeof() can be evaluated at compile time, so I would
expect sizeof(Wrapper<A>) and sizeof(Wrapper<int>) to both evaluate as
1 when A=int. (Perhaps there is some subtle issue I'm missing here?)
M.E.O.
P.S. I'd no idea how to check this comment into the GNATS database,
maybe I can't (?).