Movatterモバイル変換


[0]ホーム

URL:



This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++11 status.

471. result ofwhat() implementation-defined

Section: 17.9.3[exception]Status:C++11Submitter: Martin SeborOpened: 2004-06-28Last modified: 2016-01-28

Priority:Not Prioritized

View all otherissues in [exception].

View all issues withC++11 status.

Discussion:

[lib.exception] specifies the following:

    exception (const exception&) throw();    exception& operator= (const exception&) throw();    -4- Effects: Copies an exception object.    -5- Notes: The effects of calling what() after assignment        are implementation-defined.

First, does the Note only apply to the assignment operator? If so,what are the effects of calling what() on a copy of an object? Isthe returned pointer supposed to point to an identical copy ofthe NTBS returned by what() called on the original object or not?

Second, is this Note intended to extend to all the derived classesin section 19? I.e., does the standard provide any guarantee forthe effects of what() called on a copy of any of the derived classdescribed in section 19?

Finally, if the answer to the first question is no, I believe itconstitutes a defect since throwing an exception object typicallyimplies invoking the copy ctor on the object. If the answer is yes,then I believe the standard ought to be clarified to spell outexactly what the effects are on the copy (i.e., after the copyctor was called).

[Redmond: Yes, this is fuzzy. The issue of derived classes is fuzzy too.]

[Batavia: Howard provided wording.]

[Bellevue:]

Eric concerned this is unimplementable, due to nothrow guarantees.Suggested implementation would involve reference counting.

Is the implied reference counting subtle enough to call out a note onimplementation? Probably not.

If reference counting required, could we tighten specification furtherto require same pointer value? Probably an overspecification, especiallyif exception classes defer evalutation of final string to calls towhat().

Remember issue moved open and not resolved at Batavia, but cannotremember who objected to canvas a disenting opinion - please speak up ifyou disagree while reading these minutes!

Move to Ready as we are accepting words unmodified.

[Sophia Antipolis:]

The issue was pulled from Ready. It needs to make clear that only homogenous copyingis intended to be supported, not coping from a derived to a base.

[Batavia (2009-05):]

Howard supplied the following replacement wordingfor paragraph 7 of the proposed resolution:

-7-Postcondition:what() shall return the same NTBS as would be obtained by usingstatic_cast to cast the rhs to the same types as the lhs and then callingwhat() on that possibly sliced object.

Pete asks what "the same NTBS" means.

[2009-07-30 Niels adds:]

Further discussion in the thread starting with c++std-lib-24512.

[2009-09-24 Niels provided updated wording:]

I think the resolution should at least guaranteethat the result ofwhat() is independent of whether the compiler doescopy-elision. And for any class derived fromstd::excepion that has aconstructor that allows specifying awhat_arg, it should make sure thatthe text of a user-providedwhat_arg is preserved, when the object iscopied. Note that all the implementations I've tested already appear tosatisfy the proposed resolution, including MSVC 2008 SP1, Apachestdcxx-4.2.1, GCC 4.1.2, GCC 4.3.2, and CodeGear C++ 6.13.

The proposed resolution was updated with help from Daniel Krügler;the update aims to clarify that the proposed postcondition onlyapplies to homogeneous copying.

[2009-10 Santa Cruz:]

Moved to Ready after inserting "publicly accessible" in two places.

Proposed resolution:

Change 17.9.3[exception] to:

-1- The classexception defines the base class for the types ofobjects thrown as exceptions by C++ standard library components, andcertain expressions, to report errors detected during program execution.

Each standard library classT that derives from classexception shall have a publicly accessible copy constructor and a publicly accessible copy assignmentoperator that do not exit with an exception. These member functionsshall preserve the following postcondition: If two objectslhsandrhs both have dynamic typeT, andlhs is acopy ofrhs, thenstrcmp(lhs.what(),rhs.what()) == 0.

...

exception(const exception&rhs) throw();exception& operator=(const exception&rhs) throw();

-4-Effects: Copies an exception object.

-5-Remarks: The effects of callingwhat() after assignmentare implementation-defined.

-5-Postcondition:If*thisandrhs both have dynamic typeexceptionthenstrcmp(what(),rhs.what()) == 0.


[8]ページ先頭

©2009-2026 Movatter.jp