ambiguity in operator delete
Martin v. Loewis
martin@mira.isdn.cs.tu-berlin.de
Sat Oct 23 03:35:00 GMT 1999
> 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 deleteÃÂexpression 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 placeÃÂment
# deallocation function, the program is illÃÂformed.
The lookup referred to is detailed in 10.2. 10.2/2 says
# If the resulting set of declarations are not all from subÃÂobjects of
# the same type, or the set has a nonstatic member and includes
# members from distinct subÃÂobjects, there is an ambiguity and the
# program is illÃÂformed.
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
More information about the Gcc-bugs
mailing list