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++/52953] function parameter name redeclarations not detected
Date: Tue, 05 Sep 2023 15:30:07 +0000	[thread overview]
Message-ID: <bug-52953-4-2s7NSw7xDO@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-52953-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r14-3713-gc24982689b8af19da9a64f2283fb99764a1c5db0
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Sep 5 17:26:59 2023 +0200

    c++: Diagnose [basic.scope.block]/2 violations even in compound-stmt of
function-try-block [PR52953]

    As the following testcase shows, while check_local_shadow diagnoses most of
    the [basic.scope.block]/2 violations, it doesn't diagnose when parameter's
    name is redeclared inside of the compound-stmt of a function-try-block.

    There is in that case an extra scope (sk_try with parent artificial
    sk_block with for FUNCTION_NEEDS_BODY_BLOCK another sk_block and only then
    sk_function_param).

    The in_function_try_handler case doesn't work correctly
    void
    foo (int x)
    try {
    }
    catch (int)
    {
      try {
      } catch (int x)
      {
      }
      try {
      } catch (int)
      {
        int x;
      }
    }
    (which is valid) is rejected, because
                    || (TREE_CODE (old) == PARM_DECL
                        && (current_binding_level->kind == sk_catch
                            || current_binding_level->level_chain->kind ==
sk_catch)
                        && in_function_try_handler))
    is true but nothing verified that for the first case
    current_binding_level->level_chain->kind == sk_function_params
    (with perhaps artificial scopes in between and in the latter case
    with one extra level in between).

    The patch also changes behavior where for catch handlers of
function-try-block
    the diagnostics will have the shadows function parameter wording as pedwarn
    rather than the old redeclaration permerror.

    2023-09-05  Jakub Jelinek  <jakub@redhat.com>

            PR c++/52953
            * name-lookup.h (struct cp_binding_level): Add artificial
bit-field.
            Formatting fixes.
            * name-lookup.cc (check_local_shadow): Skip artificial bindings
when
            checking if parameter scope is parent scope.  Don't special case
            FUNCTION_NEEDS_BODY_BLOCK.  Diagnose the in_function_try_handler
            cases in the b->kind == sk_function_parms test and verify no
            non-artificial intervening scopes.  Add missing
auto_diagnostic_group.
            * decl.cc (begin_function_body): Set
            current_binding_level->artificial.
            * semantics.cc (begin_function_try_block): Likewise.

            * g++.dg/diagnostic/redeclaration-1.C: Expect different diagnostic
            wording.
            * g++.dg/diagnostic/redeclaration-3.C: New test.
            * g++.dg/parse/pr31952-1.C: Expect different diagnostic wording.
            * g++.dg/parse/pr31952-3.C: Likewise.

  parent reply	other threads:[~2023-09-05 15:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-12 21:36 [Bug c++/52953] New: g++-4.7.0 fails to detect function parameter name redeclarations meng at g dot clemson.edu
2012-04-12 21:53 ` [Bug c++/52953] " meng at g dot clemson.edu
2012-04-17 18:24 ` paolo.carlini at oracle dot com
2021-08-26 23:40 ` [Bug c++/52953] function parameter name redeclarations not detected pinskia at gcc dot gnu.org
2023-08-27 18:25 ` pinskia at gcc dot gnu.org
2023-08-30 18:22 ` jakub at gcc dot gnu.org
2023-08-30 18:28 ` jakub at gcc dot gnu.org
2023-09-05 15:30 ` cvs-commit at gcc dot gnu.org [this message]
2023-09-05 15:35 ` cvs-commit at gcc dot gnu.org
2023-09-05 15:42 ` jakub at gcc dot gnu.org
2023-09-06  6:18 ` gayathri.gottumukkala.27 at gmail dot com
2023-09-06 13:44 ` redi 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-52953-4-2s7NSw7xDO@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).