C++ PATCH for c++/71718 (ICE with infinite instantiation and alias template)
Jason Merrill
jason@redhat.com
Fri Jul 15 16:47:00 GMT 2016
When we're trying to die due to excessive template recursion, we
shouldn't try to instantiate more templates when printing diagnostics.
The code in error.c already checks at_eof to prevent instantiation, so
let's just set that appropriately.
Tested x86_64-pc-linux-gnu, applying to trunk.
-------------- next part --------------
commit 72b9617f4d2ec4af8ab9fdcd29b3c9d065059429
Author: Jason Merrill <jason@redhat.com>
Date: Mon Jul 11 15:36:04 2016 -0400
PR c++/71718 - infinite recursion and alias template
* pt.c (push_tinst_level_loc): Set at_eof before fatal_error.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a1b0ca9..830ff0a 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -9132,10 +9132,12 @@ push_tinst_level_loc (tree d, location_t loc)
if (tinst_depth >= max_tinst_depth)
{
+ /* Tell error.c not to try to instantiate any templates. */
+ at_eof = 2;
fatal_error (input_location,
"template instantiation depth exceeds maximum of %d"
- " (use -ftemplate-depth= to increase the maximum)",
- max_tinst_depth);
+ " (use -ftemplate-depth= to increase the maximum)",
+ max_tinst_depth);
return false;
}
diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-55.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-55.C
new file mode 100644
index 0000000..c6d7ae6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-55.C
@@ -0,0 +1,23 @@
+// PR c++/71718
+// { dg-do compile { target c++11 } }
+
+template <typename T>
+class A : T{};
+
+template <typename T>
+using sp = A<T>;
+
+struct Base {};
+
+template <typename T, int num = 1>
+const sp<T>
+rec() // { dg-error "depth" }
+{
+ return rec<T, num - 1>();
+}
+
+static void f(void) {
+ rec<Base>();
+}
+
+// { dg-prune-output "compilation terminated" }
More information about the Gcc-patches
mailing list