Topic: Arrays/containers and destructors that throw


Author: "Michael Pryhodko" <mpryhodko@westpac.com.au>
Date: Mon, 28 Feb 2005 11:05:22 CST
Raw View
> Can somebody please point me to the parts of the standard that say
> what happens when arrays or standard containers hold types whose
> destructors throw?

according to
http://www.stlport.org/doc/exception_safety.html
container for such objects will stop providing you with any guarantee
about exception safety.


> 17.4.3.6/2 says that behavior is undefined as follows:
>
>  for types used as template arguments when instantiating a template
>  component, if the operations on the type do not implement the
>  semantics of the applicable Requirements subclause (20.1.5, 23.1,
>  24.1, 26.1). Operations on such types can report a failure by
>  throwing an exception unless otherwise specified.
>
> Nothing I can find in the cited clauses prohibits types whose
> destructors throw.

:)
And if you read a bit further:
17.4.3.6/2
"In particular, the effects are undefined in the following cases:
..
- if any replacement function or handler function or *destructor*
operation throws an exception, unless specifically allowed in
applicable Required behavior pharagraph."

Bye.
Sincerely yours, Mike.

---
[ 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: dave@boost-consulting.com (David Abrahams)
Date: Mon, 28 Feb 2005 17:48:46 GMT
Raw View
"Michael Pryhodko" <mpryhodko@westpac.com.au> writes:

>> Can somebody please point me to the parts of the standard that say
>> what happens when arrays or standard containers hold types whose
>> destructors throw?
>
> according to
> http://www.stlport.org/doc/exception_safety.html
> container for such objects will stop providing you with any guarantee
> about exception safety.

That's a pre-standard document and shouldn't be relied on for
information about what's standard in C++98 and beyond.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

---
[ 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: Usenet@aristeia.com (Scott Meyers)
Date: Sat, 26 Feb 2005 15:41:30 GMT
Raw View
I could swear that behavior is undefined if we have an array or standard
container of a type with a destructor that throws, but I'll be darned if I
can find the wording for this.  Regarding containers, 17.4.4.8/3 says

  No destructor operation defined in the C++ Standard Library will throw
  an exception.

But that applies only to the containers themselves.

17.4.3.6/2 says that behavior is undefined as follows:

  for types used as template arguments when instantiating a template
  component, if the operations on the type do not implement the semantics
  of the applicable Requirements subclause (20.1.5, 23.1, 24.1,
  26.1). Operations on such types can report a failure by throwing an
  exception unless otherwise specified.

Nothing I can find in the cited clauses prohibits types whose destructors
throw.

Can somebody please point me to the parts of the standard that say what
happens when arrays or standard containers hold types whose destructors
throw?

Thanks,

Scott

---
[ 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: smeyers@aristeia.com (Scott Meyers)
Date: Sun, 27 Feb 2005 22:00:45 GMT
Raw View
[This is a repost as the original from two days ago has yet to appear...]

I could swear that behavior is undefined if we have an array or standard
container of a type with a destructor that throws, but I'll be darned if I
can find the wording for this.  Regarding containers, 17.4.4.8/3 says

  No destructor operation defined in the C++ Standard Library will throw
  an exception.

But that applies only to the containers themselves.

17.4.3.6/2 says that behavior is undefined as follows:

  for types used as template arguments when instantiating a template
  component, if the operations on the type do not implement the semantics
  of the applicable Requirements subclause (20.1.5, 23.1, 24.1,
  26.1). Operations on such types can report a failure by throwing an
  exception unless otherwise specified.

Nothing I can find in the cited clauses prohibits types whose destructors
throw.

Can somebody please point me to the parts of the standard that say what
happens when arrays or standard containers hold types whose destructors
throw?

Thanks,

Scott

---
[ 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: dheld@codelogicconsulting.com ("David B. Held")
Date: Sun, 27 Feb 2005 22:01:25 GMT
Raw View
Scott Meyers wrote:
> [...]
> Can somebody please point me to the parts of the standard that say what
> happens when arrays or standard containers hold types whose destructors
> throw?

I find http://kolpackov.net/projects/c++/eh/dtor-1.xhtml to be
quite informative.  Hope it helps.

Dave

---
[ 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: dave@boost-consulting.com (David Abrahams)
Date: Sun, 27 Feb 2005 22:01:45 GMT
Raw View
Usenet@aristeia.com (Scott Meyers) writes:

> I could swear that behavior is undefined if we have an array or standard
> container of a type with a destructor that throws, but I'll be darned if I
> can find the wording for this.  Regarding containers, 17.4.4.8/3 says
>
>   No destructor operation defined in the C++ Standard Library will throw
>   an exception.
>
> But that applies only to the containers themselves.
>
> 17.4.3.6/2 says that behavior is undefined as follows:
>
>   for types used as template arguments when instantiating a template
>   component, if the operations on the type do not implement the semantics
>   of the applicable Requirements subclause (20.1.5, 23.1, 24.1,
>   26.1). Operations on such types can report a failure by throwing an
>   exception unless otherwise specified.
>
> Nothing I can find in the cited clauses prohibits types whose destructors
> throw.

You just gave up reading too soon.

17.4.3.6

-1- In certain cases (replacement functions, handler functions,
 operations on types used to instantiate standard library template
 components), the C++ Standard Library depends on components supplied
 by a C++ program. If these components do not meet their requirements,
 the Standard places no requirements on the implementation.

-2- In particular, the effects are undefined in the following cases:

<snip>

    --- if any replacement function or handler function or destructor
        operation throws an exception, unless specifically allowed in
        the applicable Required behavior paragraph.

I'm not sure there's a similar rule for built-in arrays.


HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

---
[ 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                       ]