New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some unclear wording in [except] CWG2775 #5238
Comments
I think the thrown object means the operand of the throw-expression. As the exception object is the target of initialization, it's meaningless whether it's considered as an lvalue. |
The operand of the throw-expression is an expression that does not necessarily denote an object, it can be a prvalue of a certain type, the result of which is not an object. The sentence
should be rephrased into two parts
The latter is consistent with [except.handle] p14. The lvalue purposes to otherwise specify the category of the initializer expression when copy-initializing the target where "a temporary object" would have been denoted by an xvalue in common cases. |
The first occurrence of "thrown object" in [except.throw] has been present since C++98, and the second occurrence is introduced by CWG1863 (adopted at Oct. 2015). Both occurrences are older than the adoption of P0135R1 (at Jun. 2016) which makes prvalues of classes and arrays not objects. What I meant is the first occurrence of "thrown object" might correctly mean the operand until C++17/P0135R1, but is incorrect now. It seems that the second occurrence of "thrown object" is wrong at first, because it is the exception object, whose type is never cv-qualified, that is needed to be copied, while the type of the operand of a throw-expression may be cv-qualified. Since C++20/P0848R3, a copy/move constructor may be constrained, so there may be no such constructor "selected for the copy-initialization", in which case the program is presumably ill-formed. But it seems that the current wording does not cover such cases. I want to use the following wording:
It seems that the current usage of "accessible" is also problematic, as the initialization and the copy of the exception object may happen in contexts with different access. |
what do
"accessible" is checked in the context of the first matched handler, except that the exception is rethrown, "accessible" will continue to be checked for the context of the first matched handler with which the rethrown exception matches, and so on. |
"Accessible" in [except.throw] p5 may refer to different contexts, and possibly two different constructors.
|
In general, the two constructors that need to be checked refer to them:
It seems that
However, this proposal would ignore a case that the target object of the initialization has a base class type |
the confusion use of exceptions and exception objects.[propagation] p1 states
The same meaning is also appeared in [propagation] p10, [except.throw] p4.2. However, [propagation] p8 instead says that
The currently handled exception is an exception rather than an exception object. We should clarify the relationship between an exception and the exception object. |
You're right. There can be three different constructors involved. Given CWG2711 has made some clarification, the first two cases are addressed, and there's arguably no accessibility issue - it might be implied that accessibility check is made in the context of the throw-expression or the handler (which is also clang's current behavior). The case for |
We need to "capture" the (or a) copy constructor at the point of the "throw" (which may or may not be a throw-expression), because It seems to make sense to use a "const lvalue" for the source of the copy. |
[except.throw] p3
The sentence does not specify the source of the copy-initialization. A possible improvement maybe that
[except.throw] p2
Is the following an improvement to the definition of "nearest handler"?
The improvement seems to be simpler to read.
[except.throw] p5
"thrown object" seems not to be a formal wording. Because we have defined exception object. Isn't that better to be used instead of "thrown object"?
The text was updated successfully, but these errors were encountered: