public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/100493] Lambda default copy capture that captures "this" cannot be used in both C++17 and C++20 modes
Date: Wed, 15 Dec 2021 19:55:37 +0000	[thread overview]
Message-ID: <bug-100493-4-05waAnoWGI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100493-4@http.gcc.gnu.org/bugzilla/>

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

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

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

commit r11-9391-gd33f68865f6f71c28cfee5dfd91765e86d471ef1
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Nov 29 07:52:47 2021 -0500

    c++: redundant explicit 'this' capture before C++20 [PR100493]

    As described in detail in the PR, in C++20 implicitly capturing 'this'
    via a '=' capture default is deprecated, and in C++17 adding an explicit
    'this' capture alongside a '=' capture default is diagnosed as redundant
    (and is strictly speaking ill-formed).  This means it's impossible to
    write, in a forward-compatible way, a C++17 lambda that has a '=' capture
    default and that also captures 'this' (implicitly or explicitly):

      [=] { this; }      // #1 deprecated in C++20, OK in C++17
                         // GCC issues a -Wdeprecated warning in C++20 mode

      [=, this] { }      // #2 ill-formed in C++17, OK in C++20
                         // GCC issues an unconditional warning in C++17 mode

    This patch resolves this dilemma by downgrading the warning for #2 into
    a -pedantic one.  In passing, move it into the -Wc++20-extensions class
    of warnings and adjust its wording accordingly.

            PR c++/100493

    gcc/cp/ChangeLog:

            * parser.c (cp_parser_lambda_introducer): In C++17, don't
            diagnose a redundant 'this' capture alongside a by-copy
            capture default unless -pedantic.  Move the diagnostic into
            -Wc++20-extensions and adjust wording accordingly.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1z/lambda-this1.C: Adjust expected diagnostics.
            * g++.dg/cpp1z/lambda-this8.C: New test.
            * g++.dg/cpp2a/lambda-this3.C: Compile with -pedantic in C++17
            to continue to diagnose redundant 'this' captures.

    (cherry picked from commit 1420ff3efcff98df0e8c6f021a7ff24b5fc65043)

  parent reply	other threads:[~2021-12-15 19:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-09 15:19 [Bug c++/100493] New: " avi@cloudius-systems.com
2021-07-21  9:26 ` [Bug c++/100493] " gcc at bmevers dot de
2021-07-21 15:36 ` redi at gcc dot gnu.org
2021-09-22 14:13 ` redbeard0531 at gmail dot com
2021-09-22 14:30 ` redbeard0531 at gmail dot com
2021-11-29 12:55 ` cvs-commit at gcc dot gnu.org
2021-11-29 13:01 ` ppalka at gcc dot gnu.org
2021-12-15 19:55 ` cvs-commit at gcc dot gnu.org [this message]
2021-12-15 19:58 ` ppalka at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-100493-4-05waAnoWGI@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).