Bug 20123 - mangled name of typeid doesn't encode cv-qualifer.
Summary: mangled name of typeid doesn't encode cv-qualifer.
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ABI
Depends on:
Blocks:
 
Reported: 2005-02-21 19:12 UTC by yanliu
Modified: 2009-03-05 18:35 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description yanliu 2005-02-21 19:12:03 UTC
Here is a testcase:
#include <typeinfo>
int const volatile v5[10] = {0};
int
main (int argc, char **argv) {
  const std::type_info& t = typeid (::v5);
}

According to Itanium C++ ABI, the mangled name of typeid(::v5) should follow 
the following grammer rules:
 <mangled-name> ::= _Z <encoding>
    <encoding> 	::= <special-name>
       <special-name> ::= TI <type>	# typeinfo structure
          <type> ::= <array-type>
             <array-type> ::= A <positive dimension number> _ <element type>

To my understanding, the element type follows the <type> rule and is used to 
encode the type of variable v5[10]:
                <type> ::= <CV-qualifiers> <type>
                   <CV-qualifiers> ::= [r] [V] [K] # restrict (C99), volatile, 
const


So the mangled name should be: __ZTIA10_VKi. But using gcc 4.0 compiler, I am 
getting "__ZTIA10_i" mangled name instead. 

Please verify the problem, thanks.
Comment 1 Andrew Pinski 2005-02-21 19:17:37 UTC
hmm, ICC 8.0 on ia32-linux produces the same mangled name for the variable too.
Comment 2 yanliu 2005-02-21 19:37:47 UTC
For function parameters, the cv-qualifers should not be mangled. I suspect GCC 
treates this typeid as a function, thus ignoring the encoding of cv-qualifers. 
At least, the C++ ABI is not clear in this aspect.  
Comment 3 Jody Hagins 2005-02-24 19:33:20 UTC
I am not on the gcc team, so feel free to take this with some reservation.

According to 5.2.8.5, the top-level cv-qualifier are stripped when calling typeid().

According to 3.9.3.[2,5], cv-qualifiers applied to array types apply to the
array elements, not to the array.

Thus, I think the name you see is correct.  In your example, you should be able
to see typeid() doing the right thing (and see that the top-level cv-qualifers
are being stripped) with...

int x[10];
assert(typeid(::v5) == typeid(int[10]));
assert(typeid(::v5) == typeid(x));
assert(strcmp(typeid(::v5).name(), typeid(x).name()) == 0);

Comment 4 Jason Merrill 2009-03-05 18:35:31 UTC
Jody's comment is correct; typeid represents the cv-unqualified type of the expression, which for an array lvalue means removing the cv qualifiers from the array.