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


> This is slightly changed code - I removed keyword "virtual". The
> error message remains the same.
> File b2.c:
> class A           { public: void operator delete (void *ptr); };
> class N:  public A             {                };
> class C1: public A             { public: ~C1(); };
> class C2: public C1, public N  { public: ~C2(); };
> C2::~C2(){}

To remove the error message, you must use virtual in both places.

> This your statement will remain true for default operator delete also!

No. The default operator delete is a global function, not a method.
Lookup of functions does not take objects (or sub-objects) into
account.

> One more argument.

Please understand that arguing about C++ is not something useful for
gcc-bugs@gcc.gnu.org. As a developer of a C++ compiler, my primary
concern is not what users think how C++ should work, but what the
standard says how C++ works. 

So pointing me to the right place in the standard would have more
easily convinced me: 12.5/6 says

# Any deallocation function for a class X is a static member (even if
# not explicitly declared static).

Since the delete operator is  a static function, 10.2/5 applies, which
says that your  code is correct, and that g++  is wrong in complaining
about an ambiguity.

Regards,
Martin


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