Skip to content

CWG2775 [except.handle] Access checking for the constructor copying a class object might need clarification #331

Closed
cplusplus/draft
#6906
@frederick-vs-ja

Description

@frederick-vs-ja

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [except.handle]

Link to reflector thread (if any):

Issue description:

[except.handle] p14 specifies how to initialize the parameter of an exception handler, however, it seems unclear in which context the initialization is performed. Accessibility of the selected constructor (if any) affects the well-formedness when the constructor is protected or private.

There is implementation divergence (Godbolt link): GCC and MSVC don't seem to check access, while Clang checks access in the context in which the try-block or function-try-block appears.

[except.throw] p5 might be related, but the context for access checking is also unclear in that paragraph.

Suggested resolution:

There are multiple mutually exclusive suggested resolutions.

Option A (Clang's behavior):

Change [except.handle] p14 as indicated:

[...]
Access checking for the selected constructor (if any) is performed in the context in which the handler appears. The lifetime of the variable ends when the handler exits, [...]

Option B (GCC and MSVC's behavior):

Change [except.handle] p14 as indicated:

[...]
Access checking for the selected constructor (if any) is not performed. The lifetime of the variable ends when the handler exits, [...]

Option C (stricter requirement):

Change [except.handle] p14 as indicated:

[...]
Access checking for the selected constructor (if any) is performed in a context unrelated to any class. The lifetime of the variable ends when the handler exits, [...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions