public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3340] c++: Avoid bogus -Wunused with recent change
@ 2021-09-03 15:13 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-09-03 15:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5ec4990bc777dd191b86aee6156be3f60cf9de24

commit r12-3340-g5ec4990bc777dd191b86aee6156be3f60cf9de24
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Sep 2 17:42:32 2021 -0400

    c++: Avoid bogus -Wunused with recent change
    
    My change to make limit_bad_template_recursion avoid instantiating members
    of erroneous classes produced a bogus "used but not defined" warning for
    23_containers/unordered_set/instantiation_neg.cc; it's not defined because
    we decided not to instantiate it.  So we need to suppress that warning.
    
    gcc/cp/ChangeLog:
    
            * pt.c (limit_bad_template_recursion): Suppress -Wunused for decls
            we decide not to instantiate.

Diff:
---
 gcc/cp/pt.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 72b22d8c487..1b81501386b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -10890,15 +10890,27 @@ limit_bad_template_recursion (tree decl)
     return false;
 
   /* Avoid instantiating members of an ill-formed class.  */
-  if (DECL_CLASS_SCOPE_P (decl)
-      && CLASSTYPE_ERRONEOUS (DECL_CONTEXT (decl)))
-    return true;
+  bool refuse
+    = (DECL_CLASS_SCOPE_P (decl)
+       && CLASSTYPE_ERRONEOUS (DECL_CONTEXT (decl)));
 
-  for (; lev; lev = lev->next)
-    if (neglectable_inst_p (lev->maybe_get_node ()))
-      break;
+  if (!refuse)
+    {
+      for (; lev; lev = lev->next)
+	if (neglectable_inst_p (lev->maybe_get_node ()))
+	  break;
+      refuse = (lev && errs > lev->errors);
+    }
 
-  return (lev && errs > lev->errors);
+  if (refuse)
+    {
+      /* Don't warn about it not being defined.  */
+      suppress_warning (decl, OPT_Wunused);
+      tree clone;
+      FOR_EACH_CLONE (clone, decl)
+	suppress_warning (clone, OPT_Wunused);
+    }
+  return refuse;
 }
 
 static int tinst_depth;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-03 15:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 15:13 [gcc r12-3340] c++: Avoid bogus -Wunused with recent change Jason Merrill

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).