[Bug c++/65299] New: Inheriting from two classes with increment operators
ieee at bk dot ru
gcc-bugzilla@gcc.gnu.org
Tue Mar 3 14:15:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65299
Bug ID: 65299
Summary: Inheriting from two classes with increment operators
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: ieee at bk dot ru
Created attachment 34936
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34936&action=edit
preprocessed file
This program does not compile.
class A
{
public:
A& operator++(){return *this;}
};
class B
{
public:
B operator++(int){return *this;}
};
class C:public A, public B
{
};
int main()
{
C c;
c++;
++c;
}
>g++ bug.cpp -save-temps
bug.cpp: In function 'int main()':
bug.cpp:20:6: error: request for member 'operator++' is ambiguous
c++;
^
bug.cpp:10:7: note: candidates are: B B::operator++(int)
B operator++(int){return *this;}
^
bug.cpp:4:8: note: A& A::operator++()
A& operator++(){return *this;}
^
bug.cpp:21:7: error: request for member 'operator++' is ambiguous
++c;
^
bug.cpp:10:7: note: candidates are: B B::operator++(int)
B operator++(int){return *this;}
^
bug.cpp:4:8: note: A& A::operator++()
A& operator++(){return *this;}
^
The calls are not really ambiguous because the operators are different, post
and pre increment. The same error occures when using decrement operators.
Clang, ICC and VC++ accept this code. I've tried different versions of gcc,
from 4.4.7 to 4.9.2 with the same result. gcc -v output:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-mageia-linux-gnu/4.8.2/lto-wrapper
Target: i586-mageia-linux-gnu
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib
--with-slibdir=/lib --with-bugurl=http://bugs.mageia.org/
--mandir=/usr/share/man --infodir=/usr/share/info --enable-checking=release
--enable-languages=c,c++,ada,fortran,objc,obj-c++,java --enable-linker-build-id
--build=i586-mageia-linux-gnu --host=i586-mageia-linux-gnu --with-cpu=generic
--with-system-zlib --enable-threads=posix --enable-shared --enable-objc-gc
--enable-long-long --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-clocale=gnu --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-gtk-cairo
--disable-libjava-multilib --enable-ssp --disable-libssp --disable-werror
--with-ppl --with-cloog --with-python-dir=/lib/python2.7/site-packages
--enable-lto
Thread model: posix
gcc version 4.8.2 (GCC)
More information about the Gcc-bugs
mailing list