public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-9829] c++: -Wshadow=compatible-local type vs var [PR100608]
Date: Tue, 12 Apr 2022 20:14:49 +0000 (GMT)	[thread overview]
Message-ID: <20220412201449.CE03D3857806@sourceware.org> (raw)

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

commit r11-9829-gc52cd0b35d356565f67f7956f4defc022dfa2172
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Apr 5 16:02:04 2022 -0400

    c++: -Wshadow=compatible-local type vs var [PR100608]
    
    The patch for PR92024 changed -Wshadow=compatible-local to warn if either
    new or old decl was a type, but the rationale only talked about the case
    where both are types.  If only one is, they aren't compatible.
    
            PR c++/100608
    
    gcc/cp/ChangeLog:
    
            * name-lookup.c (check_local_shadow): Use -Wshadow=local
            if exactly one of 'old' and 'decl' is a type.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/warn/Wshadow-compatible-local-3.C: New test.

Diff:
---
 gcc/cp/name-lookup.c                                   |  4 ++++
 gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C | 10 ++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index e9af670c28f..2901e048b8d 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -3259,6 +3259,10 @@ check_local_shadow (tree decl)
       enum opt_code warning_code;
       if (warn_shadow)
 	warning_code = OPT_Wshadow;
+      else if ((TREE_CODE (decl) == TYPE_DECL)
+	       ^ (TREE_CODE (old) == TYPE_DECL))
+	/* If exactly one is a type, they aren't compatible.  */
+	warning_code = OPT_Wshadow_local;
       else if ((TREE_TYPE (old)
 		&& TREE_TYPE (decl)
 		&& same_type_p (TREE_TYPE (old), TREE_TYPE (decl)))
diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C b/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C
new file mode 100644
index 00000000000..0e5ece74b37
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wshadow-compatible-local-3.C
@@ -0,0 +1,10 @@
+// PR c++/100608
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-Wshadow=compatible-local" }
+
+template <typename> class X {};
+
+void foo()
+{
+  auto a = X<class a>{};	// no warning, not compatible
+}


                 reply	other threads:[~2022-04-12 20:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220412201449.CE03D3857806@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@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).