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++/107126] -Wc++20-compat should complain about template-id in out of class definition for destructor
Date: Sat, 10 Feb 2024 13:38:42 +0000	[thread overview]
Message-ID: <bug-107126-4-qj1qntpYXL@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107126-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

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

commit r14-8915-gcff174fabd6c980c09aee95db1d9d5c22421761f
Author: Marek Polacek <polacek@redhat.com>
Date:   Fri Feb 2 14:53:01 2024 -0500

    c++: DR2237, cdtor and template-id tweaks [PR107126]

    Since my r11-532 changes to implement DR2237, for this test:

      template<typename T>
      struct S {
        S<T>();
      };

    in C++20 we emit the ugly:

    q.C:3:8: error: expected unqualified-id before ')' token
        3 |   S<T>();

    which doesn't explain what the problem is.  This patch improves that
    diagnostic, reduces the error to a pedwarn, and adds a -Wc++20-compat
    diagnostic.  We now say:

    q.C:3:7: warning: template-id not allowed for constructor in C++20
[-Wtemplate-id-cdtor]
        3 |   S<T>();
    q.C:3:7: note: remove the '< >'

    This patch also fixes
    <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97202#c8>
    where the C++20 diagnostic was missing altogether:  The problem was that I
checked
    for CPP_TEMPLATE_ID too early, at a point at which cp_parser_template_id
may not
    have been called yet.  So let's check for it at the end of the function,
after
    the tentative parse and rollback.

    -Wc++20-compat triggered in libitm/; I sent a patch for that.

            DR 2237
            PR c++/107126
            PR c++/97202

    gcc/c-family/ChangeLog:

            * c-opts.cc (c_common_post_options): In C++20 or with
-Wc++20-compat,
            turn on -Wtemplate-id-cdtor.
            * c.opt (Wtemplate-id-cdtor): New.

    gcc/cp/ChangeLog:

            * parser.cc (cp_parser_unqualified_id): Downgrade the DR2237 error
to
            a pedwarn.
            (cp_parser_constructor_declarator_p): Likewise.

    gcc/ChangeLog:

            * doc/invoke.texi: Document -Wtemplate-id-cdtor.

    gcc/testsuite/ChangeLog:

            * g++.dg/DRs/dr2237.C: Adjust dg-error.
            * g++.dg/parse/constructor2.C: Likewise.
            * g++.dg/template/error34.C: Likewise.
            * g++.old-deja/g++.pt/ctor2.C: Likewise.
            * g++.dg/DRs/dr2237-2.C: New test.
            * g++.dg/DRs/dr2237-3.C: New test.
            * g++.dg/DRs/dr2237-4.C: New test.
            * g++.dg/DRs/dr2237-5.C: New test.
            * g++.dg/warn/Wtemplate-id-cdtor-1.C: New test.
            * g++.dg/warn/Wtemplate-id-cdtor-2.C: New test.
            * g++.dg/warn/Wtemplate-id-cdtor-3.C: New test.
            * g++.dg/warn/Wtemplate-id-cdtor-4.C: New test.

  parent reply	other threads:[~2024-02-10 13:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-02 19:11 [Bug c++/107126] New: GCC accepts invalid out of class definition for destructor with C++17 jlame646 at gmail dot com
2022-10-02 19:41 ` [Bug c++/107126] " jakub at gcc dot gnu.org
2022-10-02 20:10 ` jlame646 at gmail dot com
2022-10-02 20:34 ` jlame646 at gmail dot com
2022-10-02 20:49 ` jakub at gcc dot gnu.org
2022-10-03  6:14 ` jlame646 at gmail dot com
2022-10-03  6:40 ` jlame646 at gmail dot com
2022-10-03  9:51 ` redi at gcc dot gnu.org
2022-10-03 14:29 ` [Bug c++/107126] -Wc++20-compat should complain about template-id in out of class definition for destructor jason at gcc dot gnu.org
2024-02-01 23:36 ` mpolacek at gcc dot gnu.org
2024-02-10 13:38 ` cvs-commit at gcc dot gnu.org [this message]
2024-02-10 13:45 ` mpolacek 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-107126-4-qj1qntpYXL@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).