This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: ambiguity in operator delete
- To: zvyagin at gams dot ihep dot su
- Subject: Re: ambiguity in operator delete
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Sat, 23 Oct 1999 12:35:19 +0200
- CC: gcc-bugs at gcc dot gnu dot org
- References: <Pine.LNX.3.96.991017090608.29515A-100000@gams.ihep.su>
> Even if my code contains some ambiguity (I do not understand why, I
> belive that objects derived from class A must be deleted via A::operator
> delete) GCC prints IDENTICAL operators that caused the ambiguity!
Thanks for your bug report. I believe this is not a bug. According to
the standard, 5.3.5/9
# Access and ambiguity control are done for both the deallocation
# function and the destructor (12.4, 12.5).
So the compiler must perform "ambiguity control". This is further
explained in 12.5/4
# ... Otherwise, if the deleteexpression is used to deallocate an
# object of class T or array thereof, the static and dynamic types of
# the object shall be identical and the deallocation function's name
# is looked up in the scope of T. ... If the result of the lookup is
# ambiguous or inaccessible, or if the lookup selects a placement
# deallocation function, the program is illformed.
The lookup referred to is detailed in 10.2. 10.2/2 says
# If the resulting set of declarations are not all from subobjects of
# the same type, or the set has a nonstatic member and includes
# members from distinct subobjects, there is an ambiguity and the
# program is illformed.
Now, please note that your class C has two sub-objects of type A: one
appearing as direct base of N, the other as virtual base of C1. Lookup
finds an operator delete for each subobject, so the lookup is
ambiguous.
Of course, these operators are both defined in the same class, but
they belong to different subobjects. In the error message, gcc does
not print the subobject for which a method was found; an experienced
C++ programmer should be able to see the problem regardless.
Hope this helps,
Martin