Hi,

in this minor diagnostic regression we ICE in dump_decl when we try to print the template arguments, which in this case are just error_mark_node, nothing sensible, not a TREE_VEC actually (the user entered repeated <int int>).

The fix I'm proposing for 4.7.0 seems to me very safe but for 4.8 we may want to revisit these things, maybe we want to keep the invariant that even in error conditions the arguments are always stored in a TREE_VEC (I *think* we used to have it, we should investigate whether we gave up on purpose) or something else entirely, like managing to not instantiate at all.

For your immediate curiosity, the error_mark_node is created in tsubst_template_args:9687 but that is done in various situations, for packs too, I don't feel like fiddling with it just now (and simply removing it for sure leads to worse diagnostics for eg, typename7.C)

Tested x86_64-linux.

Thanks,
Paolo.

////////////////////
/cp
2012-01-26  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51370
        * error.c (dump_decl, [TEMPLATE_ID_EXPR]): Handle error_mark_node
        as TREE_OPERAND (t, 1).

/testsuite
2012-01-26  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/51370
        * g++.dg/template/crash112.C: New.
Index: testsuite/g++.dg/template/crash112.C
===================================================================
--- testsuite/g++.dg/template/crash112.C        (revision 0)
+++ testsuite/g++.dg/template/crash112.C        (revision 0)
@@ -0,0 +1,15 @@
+// PR c++/51370
+
+struct A
+{
+  template<typename> void foo() {}
+};
+
+template<void (A::*)()> struct B {}; // { dg-error "declaration" }
+
+template<int> struct C
+{
+  B<&A::foo<int int> > b; // { dg-error "declaration|type" }
+};
+
+C<0> c;
Index: cp/error.c
===================================================================
--- cp/error.c  (revision 183555)
+++ cp/error.c  (working copy)
@@ -1,7 +1,7 @@
 /* Call-backs for C++ error reporting.
    This code is non-reentrant.
    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003,
-   2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    This file is part of GCC.
 
@@ -1118,14 +1118,17 @@ dump_decl (tree t, int flags)
     case TEMPLATE_ID_EXPR:
       {
        tree name = TREE_OPERAND (t, 0);
+       tree args = TREE_OPERAND (t, 1);
 
        if (is_overloaded_fn (name))
          name = DECL_NAME (get_first_fn (name));
        dump_decl (name, flags);
        pp_cxx_begin_template_argument_list (cxx_pp);
-       if (TREE_OPERAND (t, 1))
-         dump_template_argument_list (TREE_OPERAND (t, 1), flags);
-       pp_cxx_end_template_argument_list (cxx_pp);
+       if (args == error_mark_node)
+         pp_string (cxx_pp, M_("<template arguments error>"));
+       else if (args)
+         dump_template_argument_list (args, flags);
+       pp_cxx_end_template_argument_list (cxx_pp);
       }
       break;
 

Reply via email to