Topic: argument-dependent lookup for destructors?


Author: "Krzysztof Zelechowski" <krixel@qed.pl>
Date: Fri, 27 Jan 2006 09:39:14 CST
Raw View
Suppose I have the following declaration:

void do_call_destructor(A::B &x);

How should I define it to call the destructor of x, irrelevant of what A and
B is?

The obvious and the simplest solution would be to call x.~B() but it is
ill-formed if A::B resolves to a scalar type.
If I call x.A::B::~B(), do I miss the virtual destructor?
Can I
typedef A::B AB; x.~AB()?
Is it the only possible choice?

And why is it forbidden to do argument-dependent lookup for x.~B()?  I think
x.~B() should be looked up like destroy(x), that is, members of B should not
be taken into account at all.
If B::B() is not allowed, why is b.B::~B()?
Chris

Uzytkownik <william.m.miller@gmail.com> napisal w wiadomosci
news:1138290832.021531.97330@g43g2000cwa.googlegroups.com...
> However, you are right that the Standard does not contain a coherent
> description of how this case (as well as a number of others with
> respect to destructor and pseudo-destructor name lookup) is to be
> handled. (See core language issues 244, 305, and 399, in particular.)
>
> I'll open another issue for this case.  Thanks for pointing it out.
>
> -- William M. (Mike) Miller
>   Edison Design Group
>
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]
>


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: alfps@start.no (Alf P. Steinbach)
Date: Fri, 27 Jan 2006 16:33:24 GMT
Raw View
* Krzysztof Zelechowski:
> Suppose I have the following declaration:
>
> void do_call_destructor(A::B &x);
>
> How should I define it to call the destructor of x, irrelevant of what A and
> B is?

  x.~B();

is accepted by Comeau Online; the standard is less than clear on where
qualification of B is necessary and/or disallowed; one would hope that
the infamous SomeOne (TM) would fix the standard's wording, or at least
put in some references in 12.4, to where elsewhere this is discussed.



> The obvious and the simplest solution would be to call x.~B() but it is
> ill-formed if A::B resolves to a scalar type.

Huh?


> If I call x.A::B::~B(), do I miss the virtual destructor?

You can't do that, the extra qualification is not allowed, according to
Comeau Online.  But again I'm not sure where in the standard it says so.
Would be nice with a more clear wording where you don't have to be a
super-detective to ferret out the relevant details.

If you call

  x.B::~B()

you're calling the destructor non-virtually, same as with any other
member function.


> Can I
> typedef A::B AB; x.~AB()?

Yes.


> Is it the only possible choice?

No.


> And why is it forbidden to do argument-dependent lookup for x.~B()?

Huh?


> I think
> x.~B() should be looked up like destroy(x), that is, members of B should not
> be taken into account at all.
> If B::B() is not allowed,

Huh?


> why is b.B::~B()?

That's a mystery; a qualified destructor call is not very meaningful.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "Krzysztof elechowski" <krixel@qed.pl>
Date: Fri, 27 Jan 2006 12:26:35 CST
Raw View
U   ytkownik "Alf P. Steinbach" <alfps@start.no> napisa    w wiadomo   ci
news:43da4092.505765593@news.individual.net...
>* Krzysztof Zelechowski:
>> Suppose I have the following declaration:
>>
>> void do_call_destructor(A::B &x);
>>
>> How should I define it to call the destructor of x, irrelevant of what A
>> and
>> B is?
>
>  x.~B();
>
> is accepted by Comeau Online; the standard is less than clear on where
> qualification of B is necessary and/or disallowed; one would hope that
> the infamous SomeOne (TM) would fix the standard's wording, or at least
> put in some references in 12.4, to where elsewhere this is discussed.
>
>
>
>> The obvious and the simplest solution would be to call x.~B() but it is
>> ill-formed if A::B resolves to a scalar type.
>
> Huh?
>

Because B is looked up in the context of the calling expression, which means
it is not found.

>
>> If I call x.A::B::~B(), do I miss the virtual destructor?
>
> You can't do that, the extra qualification is not allowed, according to
> Comeau Online.  But again I'm not sure where in the standard it says so.
> Would be nice with a more clear wording where you don't have to be a
> super-detective to ferret out the relevant details.

Surprise: it is the only form Microsoft Visual C++ 8 accepts.  That makes
the code dramatically unportable.

>
> If you call
>
>  x.B::~B()
>
> you're calling the destructor non-virtually, same as with any other
> member function.
>
>
>> Can I
>> typedef A::B AB; x.~AB()?
>
> Yes.
>
>
>> Is it the only possible choice?
>
> No.
>
>
>> And why is it forbidden to do argument-dependent lookup for x.~B()?
>
> Huh?
>
>
>> I think
>> x.~B() should be looked up like destroy(x), that is, members of B should
>> not
>> be taken into account at all.
>> If B::B() is not allowed,
>
> Huh?
>

I mean, you cannot write B::B() when B is a scalar type.

>
>> why is b.B::~B()?
>
> That's a mystery; a qualified destructor call is not very meaningful.
>

I guess that has something to do with virtuality but I am not sure.

Chris


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]