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.
hmm, ICC 8.0 on ia32-linux produces the same mangled name for the variable too.
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.
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);
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.