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++/33878] New: Pure virtual method body omitted from template


The following stripped down code shows pure virtual method definitions for both
a normal base class and a templated base class. To my surprise, the templated
class' body is not generated, leading to a "pure virtual method called"
termination in my actual threaded code. Leaving out the "= 0" in the template
generates the body TBase<int>::pvMethod() but is inacceptable due to not
forcing implementation by the derived classes.

Regards,

Björn A. Herwig
Guntermann & Drunck GmbH Systementwicklung 
Dortmunder Str. 4a 
D-57234 Wilnsdorf - Germany

---

bah@sw5bah:~/Programming$ LC_ALL=C g++ -v -save-temps -O0 -Wall -o test
test.cpp
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr
--enable-targets=all --enable-checking=release --build=i486-linux-gnu
--host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 20071014 (prerelease) (Debian 4.2.2-3)
 /usr/lib/gcc/i486-linux-gnu/4.2.3/cc1plus -E -quiet -v -D_GNU_SOURCE test.cpp
-mtune=generic -Wall -O0 -fpch-preprocess -o test.ii
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.2
 /usr/include/c++/4.2/i486-linux-gnu
 /usr/include/c++/4.2/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.2.3/include
 /usr/include
End of search list.
 /usr/lib/gcc/i486-linux-gnu/4.2.3/cc1plus -fpreprocessed test.ii -quiet
-dumpbase test.cpp -mtune=generic -auxbase test -O0 -Wall -version -o test.s
GNU C++ version 4.2.3 20071014 (prerelease) (Debian 4.2.2-3) (i486-linux-gnu)
        compiled by GNU C version 4.2.3 20071014 (prerelease) (Debian 4.2.2-3).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c541ec01cc4b43709b709460c241205f
 as -V -Qy -o test.o test.s
GNU assembler version 2.18 (i486-linux-gnu) using BFD version (GNU Binutils for
Debian) 2.18
 /usr/lib/gcc/i486-linux-gnu/4.2.3/collect2 --eh-frame-hdr -m elf_i386
--hash-style=both -dynamic-linker /lib/ld-linux.so.2 -o test
/usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/crti.o
/usr/lib/gcc/i486-linux-gnu/4.2.3/crtbegin.o
-L/usr/lib/gcc/i486-linux-gnu/4.2.3 -L/usr/lib/gcc/i486-linux-gnu/4.2.3
-L/usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib -L/lib/../lib
-L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.2.3/../../.. test.o -lstdc++
-lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i486-linux-gnu/4.2.3/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/crtn.o
bah@sw5bah:~/Programming$ cat test.cpp
class Base
{
public:
        virtual void pvMethod() = 0;
};

void Base::pvMethod()
{
}

class Derived :
        public Base
{
public:
        void pvMethod() { }
};

template<class T>
class TBase
{
public:
        virtual void pvMethod() = 0;
};

template<class T>
void TBase<T>::pvMethod()
{
}

class TDerived :
        public TBase<int>
{
public:
        void pvMethod() { }
};

int main(int argc, char** argv)
{
        Derived d;
        TDerived td;
        return 0;
}
bah@sw5bah:~/Programming$ cat test.ii
# 1 "test.cpp"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.cpp"
class Base
{
public:
 virtual void pvMethod() = 0;
};

void Base::pvMethod()
{
}

class Derived :
 public Base
{
public:
 void pvMethod() { }
};

template<class T>
class TBase
{
public:
 virtual void pvMethod() = 0;
};

template<class T>
void TBase<T>::pvMethod()
{
}

class TDerived :
 public TBase<int>
{
public:
 void pvMethod() { }
};

int main(int argc, char** argv)
{
 Derived d;
 TDerived td;
 return 0;
}
bah@sw5bah:~/Programming$ objdump -t test | c++filt | grep ::pvMethod
08048506  w    F .text  00000005              TDerived::pvMethod()
080484c4 g     F .text  00000005              Base::pvMethod()
08048500  w    F .text  00000005              Derived::pvMethod()


-- 
           Summary: Pure virtual method body omitted from template
           Product: gcc
           Version: 4.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: herwig at gdsys dot de


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33878


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