This is the mail archive of the gcc-prs@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]

c++/7477: Type information thrown away


>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:


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