Topic: Exceptions, const-ness, xlC ...
Author: hst@pc-plus.de (Harald Stahl)
Date: 1995/06/19 Raw View
Hi,
what does the C++ language definition say about throwing a const object in a
function with a non-const throw specification?
For example, on an IBM platform (xlC, C Set ++ 02.01.02.00), the following
piece of code always leads to a call of the unexpected handler:
class A {};
void f () throw ( A )
{
const A anA;
throw anA;
}
xlC seems to think that type "const A" does not match "A" in
function f()'s throw specification - and calls the unexpected handler.
On a HP platform (HP C++ 3.50), the unexpected handler will _not_ be called,
the thrown object is passed to a catch statement.
Who is right?
--
--
Harald Stahl Tel +49 89 62030-122
pc-plus Computing GmbH Fax +49 89 62030-113
Schlierseestr. 73 email Harald.Stahl@pc-plus.de
D-81539 Muenchen
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/19 Raw View
In article 95Jun19112319@zuckerhut.pc-plus.de, hst@pc-plus.de (Harald Stahl) writes:
>
>what does the C++ language definition say about throwing a const object in a
>function with a non-const throw specification?
>
>For example, on an IBM platform (xlC, C Set ++ 02.01.02.00), the following
>piece of code always leads to a call of the unexpected handler:
>
> class A {};
>
> void f () throw ( A )
> {
> const A anA;
> throw anA;
> }
>
>xlC seems to think that type "const A" does not match "A" in
>function f()'s throw specification - and calls the unexpected handler.
I believe xlC is incorrect. The draft standard says that in initializing
the object to be thrown, the top-level cv-qualifiers of the throw parameter
are ignored. Thus, the value thrown is an int, not a const int.
---
Steve Clamage, stephen.clamage@eng.sun.com