]>
Commit | Line | Data |
---|---|---|
b1f5b0a7 PS |
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) | |
5 | @@ -72,12 +72,14 @@ | |
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); | |
15 | ||
16 | +static int count_non_default_template_args (tree, tree); | |
17 | + | |
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 *); | |
21 | @@ -139,7 +141,7 @@ | |
22 | dump_template_argument (tree arg, int flags) | |
23 | { | |
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); | |
29 | else | |
30 | @@ -151,17 +153,47 @@ | |
31 | } | |
32 | } | |
33 | ||
34 | +/* Count the number of template arguments ARGS whose value does not | |
35 | + match the (optional) default template parameter in PARAMS */ | |
36 | + | |
37 | +static int count_non_default_template_args (tree args, tree params) | |
38 | +{ | |
39 | + int n = TREE_VEC_LENGTH (args); | |
40 | + int last; | |
41 | + | |
42 | + for (last = n - 1; last >= 0; --last) | |
43 | + { | |
44 | + tree param = TREE_VEC_ELT (params, last); | |
45 | + tree def = TREE_PURPOSE (param); | |
46 | + | |
47 | + if (!def) | |
48 | + break; | |
49 | + if (uses_template_parms (def)) | |
50 | + { | |
51 | + ++processing_template_decl; | |
52 | + def = tsubst_copy_and_build (def, args, tf_none, NULL_TREE, false, true); | |
53 | + --processing_template_decl; | |
54 | + } | |
55 | + if (!cp_tree_equal (TREE_VEC_ELT (args, last), def)) | |
56 | + break; | |
57 | + } | |
58 | + | |
59 | + return last + 1; | |
60 | +} | |
61 | + | |
62 | /* Dump a template-argument-list ARGS (always a TREE_VEC) under control | |
63 | of FLAGS. */ | |
64 | ||
65 | static void | |
66 | -dump_template_argument_list (tree args, int flags) | |
67 | +dump_template_argument_list (tree args, tree parms, int flags) | |
68 | { | |
69 | - int n = TREE_VEC_LENGTH (args); | |
70 | int need_comma = 0; | |
71 | int i; | |
72 | + int n = parms | |
73 | + ? count_non_default_template_args (args, parms) | |
74 | + : TREE_VEC_LENGTH (args); | |
75 | ||
76 | - for (i = 0; i< n; ++i) | |
77 | + for (i = 0; i < n; ++i) | |
78 | { | |
79 | tree arg = TREE_VEC_ELT (args, i); | |
80 | ||
81 | @@ -230,40 +262,48 @@ | |
82 | dump_template_bindings (tree parms, tree args) | |
83 | { | |
84 | int need_comma = 0; | |
85 | + tree p; | |
86 | + int num_nondef; | |
87 | + int lvl; | |
88 | + tree lvl_args; | |
89 | + int arg_idx; | |
90 | + int i; | |
91 | ||
92 | while (parms) | |
93 | { | |
94 | - tree p = TREE_VALUE (parms); | |
95 | - int lvl = TMPL_PARMS_DEPTH (parms); | |
96 | - int arg_idx = 0; | |
97 | - int i; | |
98 | + p = TREE_VALUE (parms); | |
99 | + num_nondef = TREE_VEC_LENGTH (p); | |
100 | + lvl = TMPL_PARMS_DEPTH (parms); | |
101 | + lvl_args = NULL_TREE; | |
102 | + arg_idx = 0; | |
103 | ||
104 | + /* Don't crash if we had an invalid argument list. */ | |
105 | + if (TMPL_ARGS_DEPTH (args) >= lvl) | |
106 | + { | |
107 | + lvl_args = TMPL_ARGS_LEVEL (args, lvl); | |
108 | + num_nondef = count_non_default_template_args (lvl_args, p); | |
109 | + } | |
110 | + | |
111 | for (i = 0; i < TREE_VEC_LENGTH (p); ++i) | |
112 | - { | |
113 | - tree arg = NULL_TREE; | |
114 | - | |
115 | - /* Don't crash if we had an invalid argument list. */ | |
116 | - if (TMPL_ARGS_DEPTH (args) >= lvl) | |
117 | { | |
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); | |
121 | - } | |
122 | + tree arg = NULL_TREE; | |
123 | ||
124 | - if (need_comma) | |
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); | |
128 | - pp_equal (cxx_pp); | |
129 | - pp_cxx_whitespace (cxx_pp); | |
130 | - if (arg) | |
131 | - dump_template_argument (arg, TFF_PLAIN_IDENTIFIER); | |
132 | - else | |
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); | |
136 | + if (need_comma) | |
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); | |
140 | + pp_equal (cxx_pp); | |
141 | + pp_cxx_whitespace (cxx_pp); | |
142 | + if (arg) | |
143 | + dump_template_argument (arg, TFF_PLAIN_IDENTIFIER); | |
144 | + else | |
145 | + pp_identifier (cxx_pp, "<missing>"); | |
146 | ||
147 | - ++arg_idx; | |
148 | - need_comma = 1; | |
149 | - } | |
150 | + ++arg_idx; | |
151 | + need_comma = 1; | |
152 | + } | |
153 | ||
154 | parms = TREE_CHAIN (parms); | |
155 | } | |
156 | @@ -347,7 +387,7 @@ | |
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); | |
163 | } | |
164 | break; | |
165 | @@ -927,15 +967,15 @@ | |
166 | ||
167 | case TEMPLATE_ID_EXPR: | |
168 | { | |
169 | - tree name = TREE_OPERAND (t, 0); | |
170 | + tree name = TREE_OPERAND (t, 0); | |
171 | ||
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); | |
186 | } | |
187 | break; | |
188 | ||
189 | @@ -1305,6 +1345,7 @@ | |
190 | dump_template_parms (tree info, int primary, int flags) | |
191 | { | |
192 | tree args = info ? TI_ARGS (info) : NULL_TREE; | |
193 | + tree params = DECL_INNERMOST_TEMPLATE_PARMS (TI_TEMPLATE (info)); | |
194 | ||
195 | if (primary && flags & TFF_TEMPLATE_NAME) | |
196 | return; | |
197 | @@ -1318,13 +1359,13 @@ | |
198 | int len, ix; | |
199 | ||
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); | |
203 | ||
204 | - len = TREE_VEC_LENGTH (args); | |
205 | + len = count_non_default_template_args (args, params); | |
206 | ||
207 | for (ix = 0; ix != len; ix++) | |
208 | - { | |
209 | - tree arg = TREE_VEC_ELT (args, ix); | |
210 | + { | |
211 | + tree arg = TREE_VEC_ELT (args, ix); | |
212 | ||
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); | |
219 | - | |
220 | + | |
221 | if (!arg) | |
222 | pp_identifier (cxx_pp, "<template parameter error>"); | |
223 | else | |
224 | dump_template_argument (arg, flags); | |
225 | - } | |
226 | + } | |
227 | } | |
228 | else if (primary) | |
229 | { |