public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103091] New: Can't jump into scope of a variable with a nontrivial destructor in C++20
@ 2021-11-05  6:29 josephcsible at gmail dot com
  2021-11-05  6:51 ` [Bug c++/103091] [DR 2256] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: josephcsible at gmail dot com @ 2021-11-05  6:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103091

            Bug ID: 103091
           Summary: Can't jump into scope of a variable with a nontrivial
                    destructor in C++20
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: josephcsible at gmail dot com
  Target Milestone: ---

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/103091] [DR 2256] Can't jump into scope of a variable with a nontrivial destructor in C++20
  2021-11-05  6:29 [Bug c++/103091] New: Can't jump into scope of a variable with a nontrivial destructor in C++20 josephcsible at gmail dot com
@ 2021-11-05  6:51 ` pinskia at gcc dot gnu.org
  2021-11-05  6:52 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-05  6:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103091

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |94404
              Alias|cwg2256                     |C++DR2256
            Summary|Can't jump into scope of a  |[DR 2256] Can't jump into
                   |variable with a nontrivial  |scope of a variable with a
                   |destructor in C++20         |nontrivial destructor in
                   |                            |C++20

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2256


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94404
[Bug 94404] [meta-bug] C++ core issues

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/103091] [DR 2256] Can't jump into scope of a variable with a nontrivial destructor in C++20
  2021-11-05  6:29 [Bug c++/103091] New: Can't jump into scope of a variable with a nontrivial destructor in C++20 josephcsible at gmail dot com
  2021-11-05  6:51 ` [Bug c++/103091] [DR 2256] " pinskia at gcc dot gnu.org
@ 2021-11-05  6:52 ` pinskia at gcc dot gnu.org
  2021-11-05  8:07 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-05  6:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103091

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-11-05
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. The C++ spec was changed by DR2256 which is consider CD5.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/103091] [DR 2256] Can't jump into scope of a variable with a nontrivial destructor in C++20
  2021-11-05  6:29 [Bug c++/103091] New: Can't jump into scope of a variable with a nontrivial destructor in C++20 josephcsible at gmail dot com
  2021-11-05  6:51 ` [Bug c++/103091] [DR 2256] " pinskia at gcc dot gnu.org
  2021-11-05  6:52 ` pinskia at gcc dot gnu.org
@ 2021-11-05  8:07 ` redi at gcc dot gnu.org
  2023-05-07 16:09 ` cvs-commit at gcc dot gnu.org
  2023-05-07 16:10 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-05  8:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103091

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/103091] [DR 2256] Can't jump into scope of a variable with a nontrivial destructor in C++20
  2021-11-05  6:29 [Bug c++/103091] New: Can't jump into scope of a variable with a nontrivial destructor in C++20 josephcsible at gmail dot com
                   ` (2 preceding siblings ...)
  2021-11-05  8:07 ` redi at gcc dot gnu.org
@ 2023-05-07 16:09 ` cvs-commit at gcc dot gnu.org
  2023-05-07 16:10 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-07 16:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103091

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:b81785eacef2a28e17e17141fcd334f51640feec

commit r14-563-gb81785eacef2a28e17e17141fcd334f51640feec
Author: Patrick Palka <ppalka@redhat.com>
Date:   Sun May 7 12:09:03 2023 -0400

    c++: goto entering scope of obj w/ non-trivial dtor [PR103091]

    It seems ever since DR 2256 goto is permitted to cross the initialization
    of a trivially initialized object with a non-trivial destructor.  We
    already supported this as an -fpermissive extension, so this patch just
    makes us unconditionally support this.

            DR 2256
            PR c++/103091

    gcc/cp/ChangeLog:

            * decl.cc (decl_jump_unsafe): Return bool instead of int.
            Don't consider TYPE_HAS_NONTRIVIAL_DESTRUCTOR.
            (check_previous_goto_1): Simplify now that decl_jump_unsafe
            returns bool instead of int.
            (check_goto): Likewise.

    gcc/testsuite/ChangeLog:

            * g++.old-deja/g++.other/init9.C: Don't expect diagnostics for
            goto made valid by DR 2256.
            * g++.dg/init/goto4.C: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c++/103091] [DR 2256] Can't jump into scope of a variable with a nontrivial destructor in C++20
  2021-11-05  6:29 [Bug c++/103091] New: Can't jump into scope of a variable with a nontrivial destructor in C++20 josephcsible at gmail dot com
                   ` (3 preceding siblings ...)
  2023-05-07 16:09 ` cvs-commit at gcc dot gnu.org
@ 2023-05-07 16:10 ` ppalka at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2023-05-07 16:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103091

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org
                 CC|                            |ppalka at gcc dot gnu.org

--- Comment #5 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Fixed for GCC 14, thanks for the report.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-07 16:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-05  6:29 [Bug c++/103091] New: Can't jump into scope of a variable with a nontrivial destructor in C++20 josephcsible at gmail dot com
2021-11-05  6:51 ` [Bug c++/103091] [DR 2256] " pinskia at gcc dot gnu.org
2021-11-05  6:52 ` pinskia at gcc dot gnu.org
2021-11-05  8:07 ` redi at gcc dot gnu.org
2023-05-07 16:09 ` cvs-commit at gcc dot gnu.org
2023-05-07 16:10 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).