]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE with -Wshadow and enumerator in template [PR99120]
authorMarek Polacek <polacek@redhat.com>
Fri, 5 Mar 2021 15:41:41 +0000 (10:41 -0500)
committerMarek Polacek <polacek@redhat.com>
Fri, 5 Mar 2021 22:55:27 +0000 (17:55 -0500)
We crash here, because in a template, an enumerator doesn't have
a type until we've called finish_enum_value_list.  But our -Wshadow
implementation, check_local_shadow, is called when we pushdecl in
build_enumerator, which takes place before finish_enum_value_list.

gcc/cp/ChangeLog:

PR c++/99120
* name-lookup.c (check_local_shadow): Check if the type of decl
is non-null before checking TYPE_PTR*.

gcc/testsuite/ChangeLog:

PR c++/99120
* g++.dg/warn/Wshadow-17.C: New test.

gcc/cp/name-lookup.c
gcc/testsuite/g++.dg/warn/Wshadow-17.C [new file with mode: 0644]

index f57708700c2c0c296b9069f439e8c6fd6ad307b5..092fa6b8768ee9f7688907829a48be647119e9cb 100644 (file)
@@ -3309,7 +3309,7 @@ check_local_shadow (tree decl)
   /* Don't warn for artificial things that are not implicit typedefs.  */
   if (DECL_ARTIFICIAL (decl) && !DECL_IMPLICIT_TYPEDEF_P (decl))
     return;
-  
+
   if (nonlambda_method_basetype ())
     if (tree member = lookup_member (current_nonlambda_class_type (),
                                     DECL_NAME (decl), /*protect=*/0,
@@ -3321,8 +3321,9 @@ check_local_shadow (tree decl)
           is a function or a pointer-to-function.  */
        if (!OVL_P (member)
            || TREE_CODE (decl) == FUNCTION_DECL
-           || TYPE_PTRFN_P (TREE_TYPE (decl))
-           || TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))
+           || (TREE_TYPE (decl)
+               && (TYPE_PTRFN_P (TREE_TYPE (decl))
+                   || TYPE_PTRMEMFUNC_P (TREE_TYPE (decl)))))
          {
            auto_diagnostic_group d;
            if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wshadow,
diff --git a/gcc/testsuite/g++.dg/warn/Wshadow-17.C b/gcc/testsuite/g++.dg/warn/Wshadow-17.C
new file mode 100644 (file)
index 0000000..0dee397
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/99120
+// { dg-options "-Wshadow" }
+
+struct S {
+  void X();
+
+  template<typename T>
+  void fn () {
+    enum { X };
+  }
+};