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

[Bug c++/65845] New: typeid doesn't work consistently on pure virtual classes


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65845

            Bug ID: 65845
           Summary: typeid doesn't work consistently on pure virtual
                    classes
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: laszlo.bodor at citi dot com

#include <typeinfo>

class Interface {
public:
  virtual int size() const = 0;
};

template <class T>
class Vector {
public:
  void resize(unsigned n, T val = T()); //C++03 style resize
//  void resize(unsigned n, const T& val); //C++11 style resize
private:
  T* data;
};

int main()
{
  typeid(Interface).name();
  typeid(Interface()).name(); //GCC 4.9.2 and VS2013: doesn't compile

  typedef Interface* PtrInterf;
  PtrInterf p1 = 0;
  typeid(PtrInterf).name();
  typeid(PtrInterf()).name();
  typeid(p1).name();

  //typeid(Vector<Interface>).name(); //GCC 4.9.2 and icc 13.0.1: doesn't
compile
  typeid(Vector<Interface>()).name();

  typedef Vector<Interface>* PtrVecInterf;
  PtrVecInterf p2 = 0;
  typeid(PtrVecInterf).name(); //GCC 4.9.2: doesn't compile
  typeid(PtrVecInterf()).name();
  typeid(p2).name(); //GCC 4.9.2: doesn't compile

  return 0;
}

Compiler version:

Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.9.2/configure --disable-nls --prefix=/home/gcc4.9
--with-gnu-as --with-gnu-ld --enable-languages=c,c++,fortran --disable-multilib
--with-system-zlib --enable-checking=release --enable-__cxa_atexit
Thread model: posix
gcc version 4.9.2 (GCC)

and

Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-src/configure --disable-nls --prefix=/home/gcc5-trunk
--with-gnu-as --with-gnu-ld --enable-languages=c,c++,fortran --disable-multilib
--with-system-zlib --enable-checking=release --enable-__cxa_atexit
Thread model: posix
gcc version 6.0.0 20150421 (experimental) (GCC)


Description:
The above code compiles on GCC 4.7.3, but it doesn't compile on GCC 4.9.2 and
on a recent GCC trunk. Clang 3.7 compiles the code.
The standard doesn't seem to be very clear on this issue but we would prefer if
typeid work as many cases as possible.


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