This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/7477: Type information thrown away
- From: d dot frey at gmx dot de
- To: gcc-gnats at gcc dot gnu dot org
- Date: 3 Aug 2002 01:47:37 -0000
- Subject: c++/7477: Type information thrown away
- Reply-to: d dot frey at gmx dot de
>Number: 7477
>Category: c++
>Synopsis: Type information thrown away
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Aug 02 18:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: d.frey@gmx.de
>Release: unknown-1.0
>Organization:
>Environment:
linux, gcc 3.1
>Description:
Consider the following code:
#include <string>
#include <iostream>
#include <typeinfo>
namespace base
{
struct string : public ::std::string
{
template< typename T >
string( const T& s )
: ::std::string( s, sizeof( s ) / sizeof( *s ) - 1 )
{
std::cout << typeid( T ).name() << std::endl;
}
};
}
void f( const base::string& s )
{
std::cout << s << std::endl;
}
int main()
{
base::string s = "Hello, world!";
std::cout << s << std::endl;
f( "Hello, world!" );
}
The output for the GCC 3.1 is:
A14_c
Hello, world!
PKc
Hel
Which is IMHO not correct. The base::string that is taken by f() should get the same type as the explicitly constructed base::string. For further discussion see the thread in csc++ where James Kanze also provided some references to the standard. I am not sure if it really is a bug, but if it isn't, please show me a reference to the standard which makes it legal to throw away the type information. :)
Regards, Daniel
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: