Topic: questions on placement delete called after an exception.


Author: zvesko@gmail.com
Date: Wed, 6 Sep 2006 10:14:28 CST
Raw View
Ganesh wrote:

>> 1) std::uncaught_exception() should return true or false?

true :)

>> 2) what happens to the exception object as exit is called from that
>> code?

I believe that exit, after closing files and executing atexit stack,
calls abort (or something equivalent), in a purist sense would't
that be in violation of [3.7.3.2] ?

>     Destroyed I believe. Because that's the end of this process.

how would that be possible other than to register it's destructor
with atexit

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: "Ganesh" <sgganesh@gmail.com>
Date: Mon, 28 Aug 2006 10:17:32 CST
Raw View
===================================== MODERATOR'S COMMENT:
 Please don't quote moderation footers when replying.


===================================== END OF MODERATOR'S COMMENT

Shooting wrote:
> Ganesh wrote:
> > Consider the following code for Dummy class where constructor of Dummy
> > throws an exception while called with placement new:
> >
> > struct Dummy {
> >     Dummy() { throw -1;}
> > };
> >
> > void* operator new(size_t s, int i) { }
> >
> > void operator delete(void* p, int i)
> > {
> >     if(std::uncaught_exception())
> >         printf("an exception is active\n");
> >     if (i == 1234)
> >         exit(0);
> > }
> >
> > The constructor throws an exception while called thro placement new,
> > corresponding placement delete is called. In that operator delete:
> > 1) std::uncaught_exception() should return true or false?
>
>     I think it should return true because there is actually a uncaught
> exception

Looks obvious, but for my surprise, compilers differ in behaviour in
this. Shouldn't be that this specific case documented in the standard?


> > 2) what happens to the exception object as exit is called from that
> > code?
>
>     Destroyed I believe. Because that's the end of this process.

Compilers differ in behaviour with this too (in few compilers, it fails
with uncaught exception and in a few it results in normal program
termination). I think the standard should explicitly mention the
behaviour.

For this difference in compiler behaviours, I raised this question, for
I wanted to know if its a compiler defect or defect in the standard (as
it doesn't specify the behaviour in these two cases).

-Ganesh

> >
> > I checked [5.3.4], [3.7.3.2] and  [17.4.3.4], but its not clear for me.
> > (Sorry if I had missed anything obvious).
> >
> > Thanks!
> > -Ganesh
> >
> > ---
> > [ 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.comeaucomputing.com/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.comeaucomputing.com/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.comeaucomputing.com/csc/faq.html                      ]





Author: "Ganesh" <sgganesh@gmail.com>
Date: Thu, 24 Aug 2006 10:17:04 CST
Raw View
Consider the following code for Dummy class where constructor of Dummy
throws an exception while called with placement new:

struct Dummy {
    Dummy() { throw -1;}
};

void* operator new(size_t s, int i) { }

void operator delete(void* p, int i)
{
    if(std::uncaught_exception())
        printf("an exception is active\n");
    if (i == 1234)
        exit(0);
}

The constructor throws an exception while called thro placement new,
corresponding placement delete is called. In that operator delete:
1) std::uncaught_exception() should return true or false?
2) what happens to the exception object as exit is called from that
code?

I checked [5.3.4], [3.7.3.2] and  [17.4.3.4], but its not clear for me.
(Sorry if I had missed anything obvious).

Thanks!
-Ganesh

---
[ 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.comeaucomputing.com/csc/faq.html                      ]





Author: "Shooting" <Shootingsyh@gmail.com>
Date: Fri, 25 Aug 2006 09:46:49 CST
Raw View
Ganesh wrote:
> Consider the following code for Dummy class where constructor of Dummy
> throws an exception while called with placement new:
>
> struct Dummy {
>     Dummy() { throw -1;}
> };
>
> void* operator new(size_t s, int i) { }
>
> void operator delete(void* p, int i)
> {
>     if(std::uncaught_exception())
>         printf("an exception is active\n");
>     if (i == 1234)
>         exit(0);
> }
>
> The constructor throws an exception while called thro placement new,
> corresponding placement delete is called. In that operator delete:
> 1) std::uncaught_exception() should return true or false?

    I think it should return true because there is actually a uncaught
exception

> 2) what happens to the exception object as exit is called from that
> code?

    Destroyed I believe. Because that's the end of this process.

>
> I checked [5.3.4], [3.7.3.2] and  [17.4.3.4], but its not clear for me.
> (Sorry if I had missed anything obvious).
>
> Thanks!
> -Ganesh
>
> ---
> [ 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.comeaucomputing.com/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.comeaucomputing.com/csc/faq.html                      ]