This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13510] New: Cannot inherit method from virtual base class
- From: "david dot boerschlein at pb dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Dec 2003 01:11:34 -0000
- Subject: [Bug c++/13510] New: Cannot inherit method from virtual base class
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I have a method in a virtual base class which I am calling from the derived
class. I have reproduced this problem and provided a workaround. I made
the priority high because the compiler should be able to do inheiritance.
Here is a session dialog which lists all files and messages as well as the
output when compiling with "-E":
$ buildbug.ksh
bug.cpp: In member function `void ownDerived::doit()':
bug.cpp:20: error: no matching function for call to `ownDerived::myMethod()'
bug.cpp:15: error: candidates are: virtual void ownDerived::myMethod(const
std::string&)
$ gcc --version
gcc (GCC) 3.3
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ uname -a
AIX rscipmgr21 1 5 000AD74A4C00 unknown
$ g++ -E -DBUGGY -fno-rtti -isystem -I- -I../common_utils -
I/usr/lpp/toolbox/include -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-
strings -Wsign-compare -Wstrict-prototypes -Werror -pedantic -o bug.o -c bug.cpp
$ nflist *.cpp buildbug.ksh bug.o
bug.cpp:
1:#include <string>
2:#include <iostream>
3:
4:class ownBase
5:{
6: public:
7: virtual void myMethod(const std::string& msg) = 0;
8: void myMethod(void) { myMethod("test"); }
9:};
10:
11:class ownDerived: public virtual ownBase
12:{
13: public:
14: virtual void myMethod(const std::string& msg)
15: {
16: std::cerr << msg << ": testing" << std::endl;
17: }
18: void doit(void)
19: {
20: myMethod();
21: }
22:};
23:
24:int main()
25:{
26: ownDerived der;
27: der.doit();
28: return 0;
29:}
30:
workaround.cpp:
1:#include <string>
2:#include <iostream>
3:
4:class ownBase
5:{
6: public:
7: virtual void myMethod(const std::string& msg) = 0;
8: void myMethod(void) { myMethod("test"); }
9:};
10:
11:class ownDerived: public virtual ownBase
12:{
13: public:
14: virtual void myMethod(const std::string& msg)
15: {
16: std::cerr << msg << ": testing" << std::endl;
17: }
18: void doit(void)
19: {
20: ownBase::myMethod();
21: }
22:};
23:
24:int main()
25:{
26: ownDerived der;
27: der.doit();
28: return 0;
29:}
30:
buildbug.ksh:
1:#!/bin/ksh
2:g++ -g -DBUGGY -fno-rtti -isystem -I- -I../common_utils -
I/usr/lpp/toolbox/include -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-
strings -Wsign-compare -Wstrict-prototypes -Werror -pedantic -o workaround.o -c
workaround.cpp
3:g++ -g -DBUGGY -fno-rtti -isystem -I- -I../common_utils -
I/usr/lpp/toolbox/include -Wall -W -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-
strings -Wsign-compare -Wstrict-prototypes -Werror -pedantic -o bug.o -c bug.cpp
4:
bug.o:
1:# 1 "bug.cpp"
2:# 1 "<built-in>"
3:# 1 "<command line>"
4:# 1 "bug.cpp"
5:# 1 "/opt/gcc-3.3/include/c++/3.3/string" 1 3
6:# 44 "/opt/gcc-3.3/include/c++/3.3/string" 3
7:
8:# 1 "/opt/gcc-3.3/include/c++/3.3/powerpc-ibm-
aix5.1.0.0/bits/c++config.h" 1 3
9:# 35 "/opt/gcc-3.3/include/c++/3.3/powerpc-ibm-
aix5.1.0.0/bits/c++config.h" 3
10:# 1 "/opt/gcc-3.3/include/c++/3.3/powerpc-ibm-
aix5.1.0.0/bits/os_defines.h" 1 3
11:# 36 "/opt/gcc-3.3/include/c++/3.3/powerpc-ibm-
aix5.1.0.0/bits/c++config.h" 2 3
12:# 46 "/opt/gcc-3.3/include/c++/3.3/string" 2 3
13:# 1 "/opt/gcc-3.3/include/c++/3.3/bits/stringfwd.h" 1 3
14:# 43 "/opt/gcc-3.3/include/c++/3.3/bits/stringfwd.h" 3
15:
16:
17:
18:namespace std
19:{
20: template<typename _Alloc>
21: class allocator;
22:
23: template<class _CharT>
24: struct char_traits;
25:
26: template<typename _CharT, typename _Traits = char_traits<_CharT>,
27: typename _Alloc = allocator<_CharT> >
28: class basic_string;
29:
30: template<> struct char_traits<char>;
31:
32: typedef basic_string<char> string;
33:
34:
35:
36:
37:
38:
39:}
40:# 47 "/opt/gcc-3.3/include/c++/3.3/string" 2 3
41:# 1 "/opt/gcc-3.3/include/c++/3.3/bits/char_traits.h" 1 3
42:# 44 "/opt/gcc-3.3/include/c++/3.3/bits/char_traits.h" 3
43:
44:# 1 "/opt/gcc-3.3/include/c++/3.3/cstring" 1 3
45:# 48 "/opt/gcc-3.3/include/c++/3.3/cstring" 3
46:
47:# 1 "/opt/gcc-3.3/include/c++/3.3/cstddef" 1 3
48:# 47 "/opt/gcc-3.3/include/c++/3.3/cstddef" 3
49:
50:# 1 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/stddef.h" 1 3 4
51:# 151 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/stddef.h" 3 4
52:typedef long int ptrdiff_t;
53:# 213 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/stddef.h" 3 4
54:typedef long unsigned int size_t;
55:# 49 "/opt/gcc-3.3/include/c++/3.3/cstddef" 2 3
56:
57:namespace std
58:{
59: using ::ptrdiff_t;
60: using ::size_t;
61:}
62:# 50 "/opt/gcc-3.3/include/c++/3.3/cstring" 2 3
63:
64:# 1 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/string.h" 1 3 4
65:# 35 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/string.h" 3 4
66:# 1 "/usr/include/standards.h" 1 3 4
67:# 36 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/string.h" 2 3 4
68:
69:
70:
71:# 1 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/sys/types.h" 1 3 4
72:# 38 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/sys/types.h" 3 4
73:extern "C" {
74:# 50 "/opt/gcc-3.3/lib/gcc-lib/powerpc-ibm-
aix5.1.0.0/3.3/include/sys/types.h" 3 4
75:# 1 "/usr/include/sys/inttypes.h" 1 3 4
76:# 56 "/usr/include/sys/inttypes.h" 3 4
77:extern "C" {
78:# 65 "/usr/include/sys/inttypes.h" 3 4
79:typedef signed char int8_t;
80:typedef signed short int16_t;
81:typedef signed int int32_t;
82:
83:
84:
85:
86:typedef signed long long int64_t;
87:
88:
89:
90:typedef unsigned char uint8_t;
91:typedef unsigned short uint16_t;
92:typedef unsigned int uint32_t;
93:
94:
95:
96:
97:typedef unsigned long long uint64_t;
98:# 92 "/usr/include/sys/inttypes.h" 3 4
99:typedef int64_t intmax_t;
100:typedef uint64_t uintmax_t;
101:# 104 "/usr/include/sys/inttypes.h" 3 4
102:typedef signed long intptr_t;
103:typedef unsigned long uintptr_t;
104:
105:
106:
107:
108:
109:typedef signed char int_least8_t;
110:typedef signed short int_least16_t;
111:typedef signed int int_least32_t;
112:
113:
114:
115:
116:typedef signed long long int_least64_t;
117:
118:
119:
120:typedef unsigned char uint_least8_t;
121:typedef unsigned short uint_least16_t;
122:typedef unsigned int uint_least32_t;
123:
124:
125:
126:
127:typedef unsigned long long uint_least64_t;
128:# 142 "/usr/include/sys/inttypes.h" 3 4
129:typedef int32_t intfast_t;
130:typedef uint32_t uintfast_t;
131:
132:
133:
134:typedef signed char int_fast8_t;
135:typedef int32_t int_fast16_t;
136:typedef int32_t int_fast32_t;
137:typedef uint32_t uint_fast8_t;
138:typedef uint32_t uint_fast16_t;
139:typedef uint32_t uint_fast32_t;
140:
--
Summary: Cannot inherit method from virtual base class
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: normal
Priority: P1
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: david dot boerschlein at pb dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: AIX rscipmgr21 1 5 000AD74A4C00 unknown
GCC host triplet: AIX rscipmgr21 1 5 000AD74A4C00 unknown
GCC target triplet: AIX rscipmgr21 1 5 000AD74A4C00 unknown
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13510