[llvm-bugs] [Bug 52416] New: Can't jump into scope of a variable with a nontrivial destructor in C++20

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 4 23:32:01 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=52416

            Bug ID: 52416
           Summary: Can't jump into scope of a variable with a nontrivial
                    destructor in C++20
           Product: clang
           Version: 13.0
          Hardware: PC
                OS: All
            Status: NEW
          Keywords: compile-fail
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: josephcsible at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211105/9a56a3b4/attachment.html>


More information about the llvm-bugs mailing list