re PR c++/83825 (ICE on invalid C++ code with shadowed identifiers: in operator[...
authorJakub Jelinek <jakub@redhat.com>
Tue, 16 Jan 2018 08:43:31 +0000 (09:43 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 16 Jan 2018 08:43:31 +0000 (09:43 +0100)
PR c++/83825
* name-lookup.c (member_vec_dedup): Return early if len is 0.
(resort_type_member_vec, set_class_bindings,
insert_late_enum_def_bindings): Use vec qsort method instead of
calling qsort directly.

* g++.dg/template/pr83825.C: New test.

From-SVN: r256725

gcc/cp/ChangeLog
gcc/cp/name-lookup.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/pr83825.C [new file with mode: 0644]

index 7e437f8547bf68b98c400c3a8132c21042d7c567..2371a54d0041cfff10f60de7b5a1fe2eb0f51207 100644 (file)
@@ -1,3 +1,11 @@
+2018-01-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/83825
+       * name-lookup.c (member_vec_dedup): Return early if len is 0.
+       (resort_type_member_vec, set_class_bindings,
+       insert_late_enum_def_bindings): Use vec qsort method instead of
+       calling qsort directly.
+
 2018-01-15  Martin Sebor  <msebor@redhat.com>
 
        PR c++/83588
index cddafab29fe642bb1a73b59e051c930fbaea08bc..8d3429393277041d442ac85d37b65fc96beed544 100644 (file)
@@ -1520,8 +1520,7 @@ resort_type_member_vec (void *obj, void */*orig_obj*/,
     {
       resort_data.new_value = new_value;
       resort_data.cookie = cookie;
-      qsort (member_vec->address (), member_vec->length (),
-            sizeof (tree), resort_member_name_cmp);
+      member_vec->qsort (resort_member_name_cmp);
     }
 }
 
@@ -1597,6 +1596,9 @@ member_vec_dedup (vec<tree, va_gc> *member_vec)
   unsigned len = member_vec->length ();
   unsigned store = 0;
 
+  if (!len)
+    return;
+
   tree current = (*member_vec)[0], name = OVL_NAME (current);
   tree next = NULL_TREE, next_name = NULL_TREE;
   for (unsigned jx, ix = 0; ix < len;
@@ -1712,8 +1714,7 @@ set_class_bindings (tree klass, unsigned extra)
   if (member_vec)
     {
       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
-      qsort (member_vec->address (), member_vec->length (),
-            sizeof (tree), member_name_cmp);
+      member_vec->qsort (member_name_cmp);
       member_vec_dedup (member_vec);
     }
 }
@@ -1741,8 +1742,7 @@ insert_late_enum_def_bindings (tree klass, tree enumtype)
       else
        member_vec_append_class_fields (member_vec, klass);
       CLASSTYPE_MEMBER_VEC (klass) = member_vec;
-      qsort (member_vec->address (), member_vec->length (),
-            sizeof (tree), member_name_cmp);
+      member_vec->qsort (member_name_cmp);
       member_vec_dedup (member_vec);
     }
 }
index 6b841401d41479d71024d5ab103e548bfe6fdc67..2a44bb180808204207f7784fbdc59bd3c7c3cb14 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/83825
+       * g++.dg/template/pr83825.C: New test.
+
 2018-01-16  Richard Biener  <rguenther@suse.de>
 
        * gcc.dg/graphite/pr83435.c: Restrict to target pthread.
diff --git a/gcc/testsuite/g++.dg/template/pr83825.C b/gcc/testsuite/g++.dg/template/pr83825.C
new file mode 100644 (file)
index 0000000..ba3ff4d
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/83825
+// { dg-do compile }
+
+template <int A>
+class A {};    // { dg-error "shadows template parameter" }
+
+template <int I>
+class B
+{ 
+  void foo () { A <I> a; }
+};
+
+template void B <0>::foo ();