Hi,

in this bug, filed by Zack, we loop forever after error in constant_value_1. Straightforward thing to do, detect and break out. Tested x86_64-linux.

Thanks,
Paolo.

////////////////////
/cp
2013-11-06  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/50436
        * init.c (constant_value_1): Break out of infinite loops during
        error recovery.

/testsuite
2013-11-06  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/50436
        * g++.dg/template/pr50436.C: New.
Index: cp/init.c
===================================================================
--- cp/init.c   (revision 204447)
+++ cp/init.c   (working copy)
@@ -1968,6 +1968,7 @@ constant_value_1 (tree decl, bool integral_p, bool
                && CP_TYPE_CONST_NON_VOLATILE_P (TREE_TYPE (decl)))))
     {
       tree init;
+      tree save_decl = decl;
       /* If DECL is a static data member in a template
         specialization, we must instantiate it here.  The
         initializer for the static data member is not processed
@@ -2007,6 +2008,10 @@ constant_value_1 (tree decl, bool integral_p, bool
                  || TREE_CODE (init) == STRING_CST)))
        break;
       decl = unshare_expr (init);
+      if (decl == save_decl)
+       /* Otherwise, in some cases of excessive recursive template
+          instantation (c++/50436) we hang after error.  */
+       return error_mark_node;
     }
   return decl;
 }
Index: testsuite/g++.dg/template/pr50436.C
===================================================================
--- testsuite/g++.dg/template/pr50436.C (revision 0)
+++ testsuite/g++.dg/template/pr50436.C (working copy)
@@ -0,0 +1,17 @@
+// PR c++/50436
+
+template <bool> struct VI {};
+template <typename T>
+struct IP
+{
+  static const bool r = IP<T>::r;  // { dg-error "template|expression" }
+};
+template <typename T> struct V
+{
+  VI<IP<T>::r> vi;
+};
+struct X;
+struct Y
+{
+  V<X> v;
+};

Reply via email to