gutenev@gmail.com wrote:
> Two questions on odd exception types:
>
> 1. What should this print? What should this print if throw f replaced
> by throw &f
>
> #include
>
> void f(void){}
>
> int main()
> {
> try
> {
> throw f;
> }
> catch(void(void))
> {
> printf("a");
> }
> catch(void(*)(void))
> {
> printf("b");
> }
> catch(...)
> {
> printf("c");
> }
> return 0;
> }
When the operand of throw is a "function returning T", the type is
automatically adjusted to "pointer to function returning T" (15.1/3).
Therefore, (throw f) and (throw &f) are equivalent.
Similarly, an exception handler of type "function returning T" is
adjusted to be of type "pointer to function returning T" (15.3/2).
Therefore, catch(void(void)) and catch(void(*)(void)) are equivalent.
Then it becomes evident that in both cases the program should write "a".
>
> 2. Should this compile?
>
> struct b
> {
> virtual void h() throw(int());
> };
>
> struct d : b
> {
> void h() throw(int(*)());
> };
>
I cannot find such an automatic adjustment rule for exception
specifications, so I guess b::h() and d::h() are incompatible.
Indeed, that is backed up by Comeau Online:
error: exception specification for virtual function "d::h" is
incompatible with that of overridden function "b::h"
--
Seungbeom Kim
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Questions on odd exception types