1 Index: gcc-4_4-branch/gcc/cp/error.c
2 ===================================================================
3 --- gcc-4_4-branch/gcc/cp/error.c (wersja 145340)
4 +++ gcc-4_4-branch/gcc/cp/error.c (kopia robocza)
6 static void dump_parameters (tree, int);
7 static void dump_exception_spec (tree, int);
8 static void dump_template_argument (tree, int);
9 -static void dump_template_argument_list (tree, int);
10 +static void dump_template_argument_list (tree, tree, int);
11 static void dump_template_parameter (tree, int);
12 static void dump_template_bindings (tree, tree);
13 static void dump_scope (tree, int);
14 static void dump_template_parms (tree, int, int);
16 +static int count_non_default_template_args (tree, tree);
18 static const char *function_category (tree);
19 static void maybe_print_instantiation_context (diagnostic_context *);
20 static void print_instantiation_full_context (diagnostic_context *);
22 dump_template_argument (tree arg, int flags)
24 if (ARGUMENT_PACK_P (arg))
25 - dump_template_argument_list (ARGUMENT_PACK_ARGS (arg), flags);
26 + dump_template_argument_list (ARGUMENT_PACK_ARGS (arg), NULL_TREE, flags);
27 else if (TYPE_P (arg) || TREE_CODE (arg) == TEMPLATE_DECL)
28 dump_type (arg, flags & ~TFF_CLASS_KEY_OR_ENUM);
34 +/* Count the number of template arguments ARGS whose value does not
35 + match the (optional) default template parameter in PARAMS */
37 +static int count_non_default_template_args (tree args, tree params)
39 + int n = TREE_VEC_LENGTH (args);
42 + for (last = n - 1; last >= 0; --last)
44 + tree param = TREE_VEC_ELT (params, last);
45 + tree def = TREE_PURPOSE (param);
49 + if (uses_template_parms (def))
51 + ++processing_template_decl;
52 + def = tsubst_copy_and_build (def, args, tf_none, NULL_TREE, false, true);
53 + --processing_template_decl;
55 + if (!cp_tree_equal (TREE_VEC_ELT (args, last), def))
62 /* Dump a template-argument-list ARGS (always a TREE_VEC) under control
66 -dump_template_argument_list (tree args, int flags)
67 +dump_template_argument_list (tree args, tree parms, int flags)
69 - int n = TREE_VEC_LENGTH (args);
73 + ? count_non_default_template_args (args, parms)
74 + : TREE_VEC_LENGTH (args);
76 - for (i = 0; i< n; ++i)
77 + for (i = 0; i < n; ++i)
79 tree arg = TREE_VEC_ELT (args, i);
82 dump_template_bindings (tree parms, tree args)
94 - tree p = TREE_VALUE (parms);
95 - int lvl = TMPL_PARMS_DEPTH (parms);
98 + p = TREE_VALUE (parms);
99 + num_nondef = TREE_VEC_LENGTH (p);
100 + lvl = TMPL_PARMS_DEPTH (parms);
101 + lvl_args = NULL_TREE;
104 + /* Don't crash if we had an invalid argument list. */
105 + if (TMPL_ARGS_DEPTH (args) >= lvl)
107 + lvl_args = TMPL_ARGS_LEVEL (args, lvl);
108 + num_nondef = count_non_default_template_args (lvl_args, p);
111 for (i = 0; i < TREE_VEC_LENGTH (p); ++i)
113 - tree arg = NULL_TREE;
115 - /* Don't crash if we had an invalid argument list. */
116 - if (TMPL_ARGS_DEPTH (args) >= lvl)
118 - tree lvl_args = TMPL_ARGS_LEVEL (args, lvl);
119 - if (NUM_TMPL_ARGS (lvl_args) > arg_idx)
120 - arg = TREE_VEC_ELT (lvl_args, arg_idx);
122 + tree arg = NULL_TREE;
125 - pp_separate_with_comma (cxx_pp);
126 - dump_template_parameter (TREE_VEC_ELT (p, i), TFF_PLAIN_IDENTIFIER);
127 - pp_cxx_whitespace (cxx_pp);
129 - pp_cxx_whitespace (cxx_pp);
131 - dump_template_argument (arg, TFF_PLAIN_IDENTIFIER);
133 - pp_identifier (cxx_pp, "<missing>");
134 + if (lvl_args && NUM_TMPL_ARGS (lvl_args) > arg_idx)
135 + arg = TREE_VEC_ELT (lvl_args, arg_idx);
137 + pp_separate_with_comma (cxx_pp);
138 + dump_template_parameter (TREE_VEC_ELT (p, i), TFF_PLAIN_IDENTIFIER);
139 + pp_cxx_whitespace (cxx_pp);
141 + pp_cxx_whitespace (cxx_pp);
143 + dump_template_argument (arg, TFF_PLAIN_IDENTIFIER);
145 + pp_identifier (cxx_pp, "<missing>");
154 parms = TREE_CHAIN (parms);
157 pp_cxx_cv_qualifier_seq (cxx_pp, t);
158 pp_cxx_tree_identifier (cxx_pp, TYPE_IDENTIFIER (t));
159 pp_cxx_begin_template_argument_list (cxx_pp);
160 - dump_template_argument_list (args, flags);
161 + dump_template_argument_list (args, NULL_TREE, flags);
162 pp_cxx_end_template_argument_list (cxx_pp);
165 @@ -927,15 +967,15 @@
167 case TEMPLATE_ID_EXPR:
169 - tree name = TREE_OPERAND (t, 0);
170 + tree name = TREE_OPERAND (t, 0);
172 - if (is_overloaded_fn (name))
173 - name = DECL_NAME (get_first_fn (name));
174 - dump_decl (name, flags);
175 - pp_cxx_begin_template_argument_list (cxx_pp);
176 - if (TREE_OPERAND (t, 1))
177 - dump_template_argument_list (TREE_OPERAND (t, 1), flags);
178 - pp_cxx_end_template_argument_list (cxx_pp);
179 + if (is_overloaded_fn (name))
180 + name = DECL_NAME (get_first_fn (name));
181 + dump_decl (name, flags);
182 + pp_cxx_begin_template_argument_list (cxx_pp);
183 + if (TREE_OPERAND (t, 1))
184 + dump_template_argument_list (TREE_OPERAND (t, 1), NULL_TREE, flags);
185 + pp_cxx_end_template_argument_list (cxx_pp);
189 @@ -1305,6 +1345,7 @@
190 dump_template_parms (tree info, int primary, int flags)
192 tree args = info ? TI_ARGS (info) : NULL_TREE;
193 + tree params = DECL_INNERMOST_TEMPLATE_PARMS (TI_TEMPLATE (info));
195 if (primary && flags & TFF_TEMPLATE_NAME)
197 @@ -1318,13 +1359,13 @@
200 if (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (args))
201 - args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
202 + args = TREE_VEC_ELT (args, TREE_VEC_LENGTH (args) - 1);
204 - len = TREE_VEC_LENGTH (args);
205 + len = count_non_default_template_args (args, params);
207 for (ix = 0; ix != len; ix++)
209 - tree arg = TREE_VEC_ELT (args, ix);
211 + tree arg = TREE_VEC_ELT (args, ix);
213 /* Only print a comma if we know there is an argument coming. In
214 the case of an empty template argument pack, no actual
215 @@ -1333,12 +1374,12 @@
216 && (!ARGUMENT_PACK_P (arg)
217 || TREE_VEC_LENGTH (ARGUMENT_PACK_ARGS (arg)) > 0))
218 pp_separate_with_comma (cxx_pp);
222 pp_identifier (cxx_pp, "<template parameter error>");
224 dump_template_argument (arg, flags);