We ICE on the following testcase because DECL_VINDEX expects
a FUNCTION_DECL, but we didn't check that.  The new testcase
shows that with this patch we give a proper warning.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2014-09-25  Marek Polacek  <pola...@redhat.com>

        PR c++/61945
        * class.c (warn_hidden): Check for FUNCTION_DECL.

        * g++.dg/warn/pr61945.C: New test.

diff --git gcc/cp/class.c gcc/cp/class.c
index c4ac61b..acf5768 100644
--- gcc/cp/class.c
+++ gcc/cp/class.c
@@ -2821,7 +2821,8 @@ warn_hidden (tree t)
       for (fn = fns; fn; fn = OVL_NEXT (fn))
        {
          fndecl = OVL_CURRENT (fn);
-         if (DECL_VINDEX (fndecl))
+         if (TREE_CODE (fndecl) == FUNCTION_DECL
+             && DECL_VINDEX (fndecl))
            {
              tree *prev = &base_fndecls;
 
diff --git gcc/testsuite/g++.dg/warn/pr61945.C 
gcc/testsuite/g++.dg/warn/pr61945.C
index e69de29..5584d84 100644
--- gcc/testsuite/g++.dg/warn/pr61945.C
+++ gcc/testsuite/g++.dg/warn/pr61945.C
@@ -0,0 +1,11 @@
+// PR c++/61945
+// { dg-do compile }
+// { dg-options "-Woverloaded-virtual" }
+
+class A {
+  virtual int foo ();  // { dg-warning "was hidden" }
+};
+class B : A {
+  template <typename>
+  void foo ();         // { dg-warning "by .B::foo\\(\\)." }
+};

        Marek

Reply via email to