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]

Re: ambiguity in operator delete


> 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


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