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++17 status.

2784. Resolution to LWG 2484 is missing "otherwise, no effects" and is hard to parse

Section: 17.9.8[except.nested]Status:C++17Submitter: Jonathan WakelyOpened: 2016-10-15Last modified: 2017-07-30

Priority:0

View all otherissues in [except.nested].

View all issues withC++17 status.

Discussion:

The discussion notes for LWG2484(i) point out there should be an "else, no effects" at the end, which didn't make it into the resolution. Without this it's unclear whether it should do nothing, or be ill-formed, or undefined.

Additionally, the precise effects of theEffects are hard to determine, because the conditions on the static type and dynamic type are intermingled, but must actually be checked separately (the static checks must be done statically and the dynamic checks must be done dynamically!) Furthermore, the obvious way to know if "the dynamic type ofe isnested_exception or is publicly and unambiguously derived fromnested_exception" is to usedynamic_cast, so we have to usedynamic_cast to find out whether to perform thedynamic_cast expression specified in theEffects. It would make more sense to specify it in terms of adynamic_cast to a pointer type, and only callrethrow_nested() if the result is not null.

The entire spec can be expressed in C++17 as:

if constexpr(is_polymorphic_v<E> && (!is_base_of_v<nested_exception, E> || is_convertible_v<E*, nested_exception*>))  if (auto p = dynamic_cast<const nested_exception*>(addressof(e)))    p->rethrow_nested();

This uses traits to perform checks on the static type, then usesdynamic_cast to perform the checks on the dynamic type. I think the spec would be clearer if it had the same structure.

[2016-11-12, Issaquah]

Sat AM: Priority 0; move to Ready

Proposed resolution:

This wording is relative to N4606.

  1. Modify 17.9.8[except.nested] p9:

    template <class E> void rethrow_if_nested(const E& e);

    -9-Effects: IfE is not a polymorphic class type,or ifnested_exception is an inaccessible or ambiguous base class ofE, there is no effect. Otherwise,if the static type or the dynamic type ofe isnested_exception or is publicly and unambiguously derived fromnested_exception, callsperforms:

    dynamic_cast<const nested_exception&>(e).rethrow_nested();if (auto p = dynamic_cast<const nested_exception*>(addressof(e)))  p->rethrow_nested();

[8]ページ先頭

©2009-2026 Movatter.jp