Bug 103091 (C++DR2256) - [DR 2256] Can't jump into scope of a variable with a nontrivial destructor in C++20
Summary: [DR 2256] Can't jump into scope of a variable with a nontrivial destructor in...
Status: NEW
Alias: C++DR2256
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 11.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks: c++-core-issues
  Show dependency treegraph
 
Reported: 2021-11-05 06:29 UTC by Joseph C. Sible
Modified: 2021-11-07 01:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-11-05 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph C. Sible 2021-11-05 06:29:55 UTC
The C++17 standard says "A program that jumps from a point where a variable with automatic storage duration is not in scope to a point where it is in scope is ill-formed unless the variable has scalar type, class type with a trivial default constructor and a trivial destructor, a cv-qualified version of one of these types, or an array of one of the preceding types and is declared without an initializer (11.6)."

The C++20 standard says "A program that jumps from a point where a variable with automatic storage duration is not in scope to a point where it is in scope is ill-formed unless the variable has vacuous initialization (6.7.3)." and "A variable is said to have vacuous initialization if it is default-initialized and, if it is of class type or a (possibly multi-dimensional) array thereof, that class type has a trivial default constructor."

Note that the C++17 standard mentions a trivial destructor here, but the C++20 standard does not. Now consider this code:

struct MyStruct {
    ~MyStruct() {}
};
void foo() {
    goto x;
    MyStruct s;
x:
    return;
}

It's ill-formed in C++17, but fine in C++20. However, we currently reject this program even with -std=c++20.
Comment 2 Andrew Pinski 2021-11-05 06:52:32 UTC
Confirmed. The C++ spec was changed by DR2256 which is consider CD5.
Comment 3 Jonathan Wakely 2021-11-05 08:07:25 UTC
(In reply to Andrew Pinski from comment #2)
> which is consider CD5.

That's just a detail of which draft of was included in, which doesn't mean much. More relevant is that it was approved as a DR so it applies to C++17 (and earlier) too.