SOURCES: gcc-pr14912.patch (NEW) - attempt to smarter template diagnostics.

pluto pluto at pld-linux.org
Wed Apr 1 20:06:13 CEST 2009


Author: pluto                        Date: Wed Apr  1 18:06:13 2009 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- attempt to smarter template diagnostics.

---- Files affected:
SOURCES:
   gcc-pr14912.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/gcc-pr14912.patch
diff -u /dev/null SOURCES/gcc-pr14912.patch:1.1
--- /dev/null	Wed Apr  1 20:06:13 2009
+++ SOURCES/gcc-pr14912.patch	Wed Apr  1 20:06:07 2009
@@ -0,0 +1,229 @@
+Index: gcc-4_4-branch/gcc/cp/error.c
+===================================================================
+--- gcc-4_4-branch/gcc/cp/error.c	(wersja 145340)
++++ gcc-4_4-branch/gcc/cp/error.c	(kopia robocza)
+@@ -72,12 +72,14 @@
+ static void dump_parameters (tree, int);
+ static void dump_exception_spec (tree, int);
+ static void dump_template_argument (tree, int);
+-static void dump_template_argument_list (tree, int);
++static void dump_template_argument_list (tree, tree, int);
+ static void dump_template_parameter (tree, int);
+ static void dump_template_bindings (tree, tree);
+ static void dump_scope (tree, int);
+ static void dump_template_parms (tree, int, int);
+ 
++static int count_non_default_template_args (tree, tree);
++
+ static const char *function_category (tree);
+ static void maybe_print_instantiation_context (diagnostic_context *);
+ static void print_instantiation_full_context (diagnostic_context *);
+@@ -139,7 +141,7 @@
+ dump_template_argument (tree arg, int flags)
+ {
+   if (ARGUMENT_PACK_P (arg))
+-    dump_template_argument_list (ARGUMENT_PACK_ARGS (arg), flags);
++    dump_template_argument_list (ARGUMENT_PACK_ARGS (arg), NULL_TREE, flags);
+   else if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
+     dump_type (arg, flags & ~TFF_CLASS_KEY_OR_ENUM);
+   else
+@@ -151,17 +153,47 @@
+     }
+ }
+ 
++/* Count the number of template arguments ARGS whose value does not
++   match the (optional) default template parameter in PARAMS  */
++
++static int count_non_default_template_args (tree args, tree params)
++{
++  int n = TREE_VEC_LENGTH (args);
++  int last;
++
++  for (last = n - 1; last >= 0; --last)
++    {
++      tree param = TREE_VEC_ELT (params, last);
++      tree def = TREE_PURPOSE (param);
++
++      if (!def)
++        break;
++      if (uses_template_parms (def))
++	{
++	  ++processing_template_decl;
++	  def = tsubst_copy_and_build (def, args, tf_none, NULL_TREE, false, true);
++	  --processing_template_decl;
++	}
++      if (!cp_tree_equal (TREE_VEC_ELT (args, last), def))
++        break;
++    }
++
++  return last + 1;
++}
++
+ /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
+    of FLAGS.  */
+ 
+ static void
+-dump_template_argument_list (tree args, int flags)
++dump_template_argument_list (tree args, tree parms, int flags)
+ {
+-  int n = TREE_VEC_LENGTH (args);
+   int need_comma = 0;
+   int i;
++  int n = parms
++          ? count_non_default_template_args (args, parms)
++          : TREE_VEC_LENGTH (args);
+ 
+-  for (i = 0; i< n; ++i)
++  for (i = 0; i < n; ++i)
+     {
+       tree arg = TREE_VEC_ELT (args, i);
+ 
+@@ -230,40 +262,48 @@
+ dump_template_bindings (tree parms, tree args)
+ {
+   int need_comma = 0;
++  tree p;
++  int num_nondef;
++  int lvl;
++  tree lvl_args;
++  int arg_idx;
++  int i;
+ 
+   while (parms)
+     {
+-      tree p = TREE_VALUE (parms);
+-      int lvl = TMPL_PARMS_DEPTH (parms);
+-      int arg_idx = 0;
+-      int i;
++      p = TREE_VALUE (parms);
++      num_nondef = TREE_VEC_LENGTH (p);
++      lvl = TMPL_PARMS_DEPTH (parms);
++      lvl_args = NULL_TREE;
++      arg_idx = 0;
+ 
++      /* Don't crash if we had an invalid argument list.  */
++      if (TMPL_ARGS_DEPTH (args) >= lvl)
++        {
++          lvl_args = TMPL_ARGS_LEVEL (args, lvl);
++          num_nondef = count_non_default_template_args (lvl_args, p);
++        }
++
+       for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
+-	{
+-	  tree arg = NULL_TREE;
+-
+-	  /* Don't crash if we had an invalid argument list.  */
+-	  if (TMPL_ARGS_DEPTH (args) >= lvl)
+ 	    {
+-	      tree lvl_args = TMPL_ARGS_LEVEL (args, lvl);
+-	      if (NUM_TMPL_ARGS (lvl_args) > arg_idx)
+-		arg = TREE_VEC_ELT (lvl_args, arg_idx);
+-	    }
++	      tree arg = NULL_TREE;
+ 
+-	  if (need_comma)
+-	    pp_separate_with_comma (cxx_pp);
+-	  dump_template_parameter (TREE_VEC_ELT (p, i), TFF_PLAIN_IDENTIFIER);
+-	  pp_cxx_whitespace (cxx_pp);
+-	  pp_equal (cxx_pp);
+-	  pp_cxx_whitespace (cxx_pp);
+-	  if (arg)
+-	    dump_template_argument (arg, TFF_PLAIN_IDENTIFIER);
+-	  else
+-	    pp_identifier (cxx_pp, "<missing>");
++          if (lvl_args && NUM_TMPL_ARGS (lvl_args) > arg_idx)
++            arg = TREE_VEC_ELT (lvl_args, arg_idx);
++          if (need_comma)
++	        pp_separate_with_comma (cxx_pp);
++          dump_template_parameter (TREE_VEC_ELT (p, i), TFF_PLAIN_IDENTIFIER);
++          pp_cxx_whitespace (cxx_pp);
++          pp_equal (cxx_pp);
++          pp_cxx_whitespace (cxx_pp);
++          if (arg)
++            dump_template_argument (arg, TFF_PLAIN_IDENTIFIER);
++          else
++            pp_identifier (cxx_pp, "<missing>");
+ 
+-	  ++arg_idx;
+-	  need_comma = 1;
+-	}
++          ++arg_idx;
++          need_comma = 1;
++	    }
+ 
+       parms = TREE_CHAIN (parms);
+     }
+@@ -347,7 +387,7 @@
+ 	pp_cxx_cv_qualifier_seq (cxx_pp, t);
+ 	pp_cxx_tree_identifier (cxx_pp, TYPE_IDENTIFIER (t));
+ 	pp_cxx_begin_template_argument_list (cxx_pp);
+-	dump_template_argument_list (args, flags);
++	dump_template_argument_list (args, NULL_TREE, flags);
+ 	pp_cxx_end_template_argument_list (cxx_pp);
+       }
+       break;
+@@ -927,15 +967,15 @@
+ 
+     case TEMPLATE_ID_EXPR:
+       {
+-	tree name = TREE_OPERAND (t, 0);
++	    tree name = TREE_OPERAND (t, 0);
+ 
+-	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 (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), NULL_TREE, flags);
++	    pp_cxx_end_template_argument_list (cxx_pp);
+       }
+       break;
+ 
+@@ -1305,6 +1345,7 @@
+ dump_template_parms (tree info, int primary, int flags)
+ {
+   tree args = info ? TI_ARGS (info) : NULL_TREE;
++  tree params = DECL_INNERMOST_TEMPLATE_PARMS (TI_TEMPLATE (info));
+ 
+   if (primary && flags & TFF_TEMPLATE_NAME)
+     return;
+@@ -1318,13 +1359,13 @@
+       int len, ix;
+ 
+       if (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (args))
+-	args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
++	    args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
+ 
+-      len = TREE_VEC_LENGTH (args);
++      len = count_non_default_template_args (args, params);
+ 
+       for (ix = 0; ix != len; ix++)
+-	{
+-	  tree arg = TREE_VEC_ELT (args, ix);
++	  {
++	    tree arg = TREE_VEC_ELT (args, ix);
+ 
+           /* Only print a comma if we know there is an argument coming. In
+              the case of an empty template argument pack, no actual
+@@ -1333,12 +1374,12 @@
+               && (!ARGUMENT_PACK_P (arg)
+                   || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0))
+             pp_separate_with_comma (cxx_pp);
+-          
++
+           if (!arg)
+             pp_identifier (cxx_pp, "<template parameter error>");
+           else
+             dump_template_argument (arg, flags);
+-        }
++      }
+     }
+   else if (primary)
+     {
================================================================


More information about the pld-cvs-commit mailing list