annotate gcc/cp/method.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Handle the hair of processing (but not expanding) inline functions.
kono
parents:
diff changeset
2 Also manage function and variable name overloading.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3 Copyright (C) 1987-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 This file is part of GCC.
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
10 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
11 any later version.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
16 GNU General Public License for more details.
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
19 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
20 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22
kono
parents:
diff changeset
23 /* Handle method declarations. */
kono
parents:
diff changeset
24 #include "config.h"
kono
parents:
diff changeset
25 #include "system.h"
kono
parents:
diff changeset
26 #include "coretypes.h"
kono
parents:
diff changeset
27 #include "target.h"
kono
parents:
diff changeset
28 #include "cp-tree.h"
kono
parents:
diff changeset
29 #include "stringpool.h"
kono
parents:
diff changeset
30 #include "cgraph.h"
kono
parents:
diff changeset
31 #include "varasm.h"
kono
parents:
diff changeset
32 #include "toplev.h"
kono
parents:
diff changeset
33 #include "common/common-target.h"
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 static void do_build_copy_assign (tree);
kono
parents:
diff changeset
36 static void do_build_copy_constructor (tree);
kono
parents:
diff changeset
37 static tree make_alias_for_thunk (tree);
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 /* Called once to initialize method.c. */
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 void
kono
parents:
diff changeset
42 init_method (void)
kono
parents:
diff changeset
43 {
kono
parents:
diff changeset
44 init_mangle ();
kono
parents:
diff changeset
45 }
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 /* Return a this or result adjusting thunk to FUNCTION. THIS_ADJUSTING
kono
parents:
diff changeset
48 indicates whether it is a this or result adjusting thunk.
kono
parents:
diff changeset
49 FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
kono
parents:
diff changeset
50 (see thunk_adjust). VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
kono
parents:
diff changeset
51 never is. VIRTUAL_OFFSET is the /index/ into the vtable for this
kono
parents:
diff changeset
52 adjusting thunks, we scale it to a byte offset. For covariant
kono
parents:
diff changeset
53 thunks VIRTUAL_OFFSET is the virtual binfo. You must post process
kono
parents:
diff changeset
54 the returned thunk with finish_thunk. */
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 tree
kono
parents:
diff changeset
57 make_thunk (tree function, bool this_adjusting,
kono
parents:
diff changeset
58 tree fixed_offset, tree virtual_offset)
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 HOST_WIDE_INT d;
kono
parents:
diff changeset
61 tree thunk;
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
kono
parents:
diff changeset
64 /* We can have this thunks to covariant thunks, but not vice versa. */
kono
parents:
diff changeset
65 gcc_assert (!DECL_THIS_THUNK_P (function));
kono
parents:
diff changeset
66 gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* Scale the VIRTUAL_OFFSET to be in terms of bytes. */
kono
parents:
diff changeset
69 if (this_adjusting && virtual_offset)
kono
parents:
diff changeset
70 virtual_offset
kono
parents:
diff changeset
71 = size_binop (MULT_EXPR,
kono
parents:
diff changeset
72 virtual_offset,
kono
parents:
diff changeset
73 convert (ssizetype,
kono
parents:
diff changeset
74 TYPE_SIZE_UNIT (vtable_entry_type)));
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 d = tree_to_shwi (fixed_offset);
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 /* See if we already have the thunk in question. For this_adjusting
kono
parents:
diff changeset
79 thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
kono
parents:
diff changeset
80 will be a BINFO. */
kono
parents:
diff changeset
81 for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
kono
parents:
diff changeset
82 if (DECL_THIS_THUNK_P (thunk) == this_adjusting
kono
parents:
diff changeset
83 && THUNK_FIXED_OFFSET (thunk) == d
kono
parents:
diff changeset
84 && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
kono
parents:
diff changeset
85 && (!virtual_offset
kono
parents:
diff changeset
86 || (this_adjusting
kono
parents:
diff changeset
87 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
kono
parents:
diff changeset
88 virtual_offset)
kono
parents:
diff changeset
89 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
kono
parents:
diff changeset
90 return thunk;
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 /* All thunks must be created before FUNCTION is actually emitted;
kono
parents:
diff changeset
93 the ABI requires that all thunks be emitted together with the
kono
parents:
diff changeset
94 function to which they transfer control. */
kono
parents:
diff changeset
95 gcc_assert (!TREE_ASM_WRITTEN (function));
kono
parents:
diff changeset
96 /* Likewise, we can only be adding thunks to a function declared in
kono
parents:
diff changeset
97 the class currently being laid out. */
kono
parents:
diff changeset
98 gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
kono
parents:
diff changeset
99 && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 thunk = build_decl (DECL_SOURCE_LOCATION (function),
kono
parents:
diff changeset
102 FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
kono
parents:
diff changeset
103 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
kono
parents:
diff changeset
104 cxx_dup_lang_specific_decl (thunk);
kono
parents:
diff changeset
105 DECL_VIRTUAL_P (thunk) = true;
kono
parents:
diff changeset
106 SET_DECL_THUNKS (thunk, NULL_TREE);
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
kono
parents:
diff changeset
109 TREE_READONLY (thunk) = TREE_READONLY (function);
kono
parents:
diff changeset
110 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
kono
parents:
diff changeset
111 TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
kono
parents:
diff changeset
112 SET_DECL_THUNK_P (thunk, this_adjusting);
kono
parents:
diff changeset
113 THUNK_TARGET (thunk) = function;
kono
parents:
diff changeset
114 THUNK_FIXED_OFFSET (thunk) = d;
kono
parents:
diff changeset
115 THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
kono
parents:
diff changeset
116 THUNK_ALIAS (thunk) = NULL_TREE;
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 DECL_INTERFACE_KNOWN (thunk) = 1;
kono
parents:
diff changeset
119 DECL_NOT_REALLY_EXTERN (thunk) = 1;
kono
parents:
diff changeset
120 DECL_COMDAT (thunk) = DECL_COMDAT (function);
kono
parents:
diff changeset
121 DECL_SAVED_FUNCTION_DATA (thunk) = NULL;
kono
parents:
diff changeset
122 /* The thunk itself is not a constructor or destructor, even if
kono
parents:
diff changeset
123 the thing it is thunking to is. */
kono
parents:
diff changeset
124 DECL_CXX_DESTRUCTOR_P (thunk) = 0;
kono
parents:
diff changeset
125 DECL_CXX_CONSTRUCTOR_P (thunk) = 0;
kono
parents:
diff changeset
126 DECL_EXTERNAL (thunk) = 1;
kono
parents:
diff changeset
127 DECL_ARTIFICIAL (thunk) = 1;
kono
parents:
diff changeset
128 /* The THUNK is not a pending inline, even if the FUNCTION is. */
kono
parents:
diff changeset
129 DECL_PENDING_INLINE_P (thunk) = 0;
kono
parents:
diff changeset
130 DECL_DECLARED_INLINE_P (thunk) = 0;
kono
parents:
diff changeset
131 /* Nor is it a template instantiation. */
kono
parents:
diff changeset
132 DECL_USE_TEMPLATE (thunk) = 0;
kono
parents:
diff changeset
133 DECL_TEMPLATE_INFO (thunk) = NULL;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 /* Add it to the list of thunks associated with FUNCTION. */
kono
parents:
diff changeset
136 DECL_CHAIN (thunk) = DECL_THUNKS (function);
kono
parents:
diff changeset
137 SET_DECL_THUNKS (function, thunk);
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 return thunk;
kono
parents:
diff changeset
140 }
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 /* Finish THUNK, a thunk decl. */
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 void
kono
parents:
diff changeset
145 finish_thunk (tree thunk)
kono
parents:
diff changeset
146 {
kono
parents:
diff changeset
147 tree function, name;
kono
parents:
diff changeset
148 tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
kono
parents:
diff changeset
149 tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
kono
parents:
diff changeset
152 if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
kono
parents:
diff changeset
153 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
kono
parents:
diff changeset
154 function = THUNK_TARGET (thunk);
kono
parents:
diff changeset
155 name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
kono
parents:
diff changeset
156 fixed_offset, virtual_offset, thunk);
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 /* We can end up with declarations of (logically) different
kono
parents:
diff changeset
159 covariant thunks, that do identical adjustments. The two thunks
kono
parents:
diff changeset
160 will be adjusting between within different hierarchies, which
kono
parents:
diff changeset
161 happen to have the same layout. We must nullify one of them to
kono
parents:
diff changeset
162 refer to the other. */
kono
parents:
diff changeset
163 if (DECL_RESULT_THUNK_P (thunk))
kono
parents:
diff changeset
164 {
kono
parents:
diff changeset
165 tree cov_probe;
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 for (cov_probe = DECL_THUNKS (function);
kono
parents:
diff changeset
168 cov_probe; cov_probe = DECL_CHAIN (cov_probe))
kono
parents:
diff changeset
169 if (DECL_NAME (cov_probe) == name)
kono
parents:
diff changeset
170 {
kono
parents:
diff changeset
171 gcc_assert (!DECL_THUNKS (thunk));
kono
parents:
diff changeset
172 THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
kono
parents:
diff changeset
173 ? THUNK_ALIAS (cov_probe) : cov_probe);
kono
parents:
diff changeset
174 break;
kono
parents:
diff changeset
175 }
kono
parents:
diff changeset
176 }
kono
parents:
diff changeset
177
kono
parents:
diff changeset
178 DECL_NAME (thunk) = name;
kono
parents:
diff changeset
179 SET_DECL_ASSEMBLER_NAME (thunk, name);
kono
parents:
diff changeset
180 }
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 static GTY (()) int thunk_labelno;
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 /* Create a static alias to target. */
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 tree
kono
parents:
diff changeset
187 make_alias_for (tree target, tree newid)
kono
parents:
diff changeset
188 {
kono
parents:
diff changeset
189 tree alias = build_decl (DECL_SOURCE_LOCATION (target),
kono
parents:
diff changeset
190 TREE_CODE (target), newid, TREE_TYPE (target));
kono
parents:
diff changeset
191 DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
kono
parents:
diff changeset
192 cxx_dup_lang_specific_decl (alias);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
193 DECL_CONTEXT (alias) = DECL_CONTEXT (target);
111
kono
parents:
diff changeset
194 TREE_READONLY (alias) = TREE_READONLY (target);
kono
parents:
diff changeset
195 TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
kono
parents:
diff changeset
196 TREE_PUBLIC (alias) = 0;
kono
parents:
diff changeset
197 DECL_INTERFACE_KNOWN (alias) = 1;
kono
parents:
diff changeset
198 if (DECL_LANG_SPECIFIC (alias))
kono
parents:
diff changeset
199 {
kono
parents:
diff changeset
200 DECL_NOT_REALLY_EXTERN (alias) = 1;
kono
parents:
diff changeset
201 DECL_USE_TEMPLATE (alias) = 0;
kono
parents:
diff changeset
202 DECL_TEMPLATE_INFO (alias) = NULL;
kono
parents:
diff changeset
203 }
kono
parents:
diff changeset
204 DECL_EXTERNAL (alias) = 0;
kono
parents:
diff changeset
205 DECL_ARTIFICIAL (alias) = 1;
kono
parents:
diff changeset
206 DECL_TEMPLATE_INSTANTIATED (alias) = 0;
kono
parents:
diff changeset
207 if (TREE_CODE (alias) == FUNCTION_DECL)
kono
parents:
diff changeset
208 {
kono
parents:
diff changeset
209 DECL_SAVED_FUNCTION_DATA (alias) = NULL;
kono
parents:
diff changeset
210 DECL_CXX_DESTRUCTOR_P (alias) = 0;
kono
parents:
diff changeset
211 DECL_CXX_CONSTRUCTOR_P (alias) = 0;
kono
parents:
diff changeset
212 DECL_PENDING_INLINE_P (alias) = 0;
kono
parents:
diff changeset
213 DECL_DECLARED_INLINE_P (alias) = 0;
kono
parents:
diff changeset
214 DECL_INITIAL (alias) = error_mark_node;
kono
parents:
diff changeset
215 DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
kono
parents:
diff changeset
216 }
kono
parents:
diff changeset
217 else
kono
parents:
diff changeset
218 TREE_STATIC (alias) = 1;
kono
parents:
diff changeset
219 TREE_ADDRESSABLE (alias) = 1;
kono
parents:
diff changeset
220 TREE_USED (alias) = 1;
kono
parents:
diff changeset
221 SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
kono
parents:
diff changeset
222 return alias;
kono
parents:
diff changeset
223 }
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 static tree
kono
parents:
diff changeset
226 make_alias_for_thunk (tree function)
kono
parents:
diff changeset
227 {
kono
parents:
diff changeset
228 tree alias;
kono
parents:
diff changeset
229 char buf[256];
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
kono
parents:
diff changeset
232 thunk_labelno++;
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 alias = make_alias_for (function, get_identifier (buf));
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 if (!flag_syntax_only)
kono
parents:
diff changeset
237 {
kono
parents:
diff changeset
238 struct cgraph_node *funcn, *aliasn;
kono
parents:
diff changeset
239 funcn = cgraph_node::get (function);
kono
parents:
diff changeset
240 gcc_checking_assert (funcn);
kono
parents:
diff changeset
241 aliasn = cgraph_node::create_same_body_alias (alias, function);
kono
parents:
diff changeset
242 DECL_ASSEMBLER_NAME (function);
kono
parents:
diff changeset
243 gcc_assert (aliasn != NULL);
kono
parents:
diff changeset
244 }
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 return alias;
kono
parents:
diff changeset
247 }
kono
parents:
diff changeset
248
kono
parents:
diff changeset
249 /* Emit the definition of a C++ multiple inheritance or covariant
kono
parents:
diff changeset
250 return vtable thunk. If EMIT_P is nonzero, the thunk is emitted
kono
parents:
diff changeset
251 immediately. */
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 void
kono
parents:
diff changeset
254 use_thunk (tree thunk_fndecl, bool emit_p)
kono
parents:
diff changeset
255 {
kono
parents:
diff changeset
256 tree a, t, function, alias;
kono
parents:
diff changeset
257 tree virtual_offset;
kono
parents:
diff changeset
258 HOST_WIDE_INT fixed_offset, virtual_value;
kono
parents:
diff changeset
259 bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
kono
parents:
diff changeset
260 struct cgraph_node *funcn, *thunk_node;
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 /* We should have called finish_thunk to give it a name. */
kono
parents:
diff changeset
263 gcc_assert (DECL_NAME (thunk_fndecl));
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 /* We should never be using an alias, always refer to the
kono
parents:
diff changeset
266 aliased thunk. */
kono
parents:
diff changeset
267 gcc_assert (!THUNK_ALIAS (thunk_fndecl));
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 if (TREE_ASM_WRITTEN (thunk_fndecl))
kono
parents:
diff changeset
270 return;
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 function = THUNK_TARGET (thunk_fndecl);
kono
parents:
diff changeset
273 if (DECL_RESULT (thunk_fndecl))
kono
parents:
diff changeset
274 /* We already turned this thunk into an ordinary function.
kono
parents:
diff changeset
275 There's no need to process this thunk again. */
kono
parents:
diff changeset
276 return;
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 if (DECL_THUNK_P (function))
kono
parents:
diff changeset
279 /* The target is itself a thunk, process it now. */
kono
parents:
diff changeset
280 use_thunk (function, emit_p);
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 /* Thunks are always addressable; they only appear in vtables. */
kono
parents:
diff changeset
283 TREE_ADDRESSABLE (thunk_fndecl) = 1;
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 /* Figure out what function is being thunked to. It's referenced in
kono
parents:
diff changeset
286 this translation unit. */
kono
parents:
diff changeset
287 TREE_ADDRESSABLE (function) = 1;
kono
parents:
diff changeset
288 mark_used (function);
kono
parents:
diff changeset
289 if (!emit_p)
kono
parents:
diff changeset
290 return;
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
kono
parents:
diff changeset
293 alias = make_alias_for_thunk (function);
kono
parents:
diff changeset
294 else
kono
parents:
diff changeset
295 alias = function;
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
kono
parents:
diff changeset
298 virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
kono
parents:
diff changeset
299
kono
parents:
diff changeset
300 if (virtual_offset)
kono
parents:
diff changeset
301 {
kono
parents:
diff changeset
302 if (!this_adjusting)
kono
parents:
diff changeset
303 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
kono
parents:
diff changeset
304 virtual_value = tree_to_shwi (virtual_offset);
kono
parents:
diff changeset
305 gcc_assert (virtual_value);
kono
parents:
diff changeset
306 }
kono
parents:
diff changeset
307 else
kono
parents:
diff changeset
308 virtual_value = 0;
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 /* And, if we need to emit the thunk, it's used. */
kono
parents:
diff changeset
311 mark_used (thunk_fndecl);
kono
parents:
diff changeset
312 /* This thunk is actually defined. */
kono
parents:
diff changeset
313 DECL_EXTERNAL (thunk_fndecl) = 0;
kono
parents:
diff changeset
314 /* The linkage of the function may have changed. FIXME in linkage
kono
parents:
diff changeset
315 rewrite. */
kono
parents:
diff changeset
316 gcc_assert (DECL_INTERFACE_KNOWN (function));
kono
parents:
diff changeset
317 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
kono
parents:
diff changeset
318 DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
kono
parents:
diff changeset
319 DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
kono
parents:
diff changeset
320 = DECL_VISIBILITY_SPECIFIED (function);
kono
parents:
diff changeset
321 DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
kono
parents:
diff changeset
322 DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 if (flag_syntax_only)
kono
parents:
diff changeset
325 {
kono
parents:
diff changeset
326 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
kono
parents:
diff changeset
327 return;
kono
parents:
diff changeset
328 }
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 push_to_top_level ();
kono
parents:
diff changeset
331
kono
parents:
diff changeset
332 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
kono
parents:
diff changeset
333 && targetm_common.have_named_sections)
kono
parents:
diff changeset
334 {
kono
parents:
diff changeset
335 tree fn = function;
kono
parents:
diff changeset
336 struct symtab_node *symbol;
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 if ((symbol = symtab_node::get (function))
kono
parents:
diff changeset
339 && symbol->alias)
kono
parents:
diff changeset
340 {
kono
parents:
diff changeset
341 if (symbol->analyzed)
kono
parents:
diff changeset
342 fn = symtab_node::get (function)->ultimate_alias_target ()->decl;
kono
parents:
diff changeset
343 else
kono
parents:
diff changeset
344 fn = symtab_node::get (function)->alias_target;
kono
parents:
diff changeset
345 }
kono
parents:
diff changeset
346 resolve_unique_section (fn, 0, flag_function_sections);
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 if (DECL_SECTION_NAME (fn) != NULL && DECL_ONE_ONLY (fn))
kono
parents:
diff changeset
349 {
kono
parents:
diff changeset
350 resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
kono
parents:
diff changeset
351
kono
parents:
diff changeset
352 /* Output the thunk into the same section as function. */
kono
parents:
diff changeset
353 set_decl_section_name (thunk_fndecl, DECL_SECTION_NAME (fn));
kono
parents:
diff changeset
354 symtab_node::get (thunk_fndecl)->implicit_section
kono
parents:
diff changeset
355 = symtab_node::get (fn)->implicit_section;
kono
parents:
diff changeset
356 }
kono
parents:
diff changeset
357 }
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 /* Set up cloned argument trees for the thunk. */
kono
parents:
diff changeset
360 t = NULL_TREE;
kono
parents:
diff changeset
361 for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
kono
parents:
diff changeset
362 {
kono
parents:
diff changeset
363 tree x = copy_node (a);
kono
parents:
diff changeset
364 DECL_CHAIN (x) = t;
kono
parents:
diff changeset
365 DECL_CONTEXT (x) = thunk_fndecl;
kono
parents:
diff changeset
366 SET_DECL_RTL (x, NULL);
kono
parents:
diff changeset
367 DECL_HAS_VALUE_EXPR_P (x) = 0;
kono
parents:
diff changeset
368 TREE_ADDRESSABLE (x) = 0;
kono
parents:
diff changeset
369 t = x;
kono
parents:
diff changeset
370 }
kono
parents:
diff changeset
371 a = nreverse (t);
kono
parents:
diff changeset
372 DECL_ARGUMENTS (thunk_fndecl) = a;
kono
parents:
diff changeset
373 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
kono
parents:
diff changeset
374 funcn = cgraph_node::get (function);
kono
parents:
diff changeset
375 gcc_checking_assert (funcn);
kono
parents:
diff changeset
376 thunk_node = funcn->create_thunk (thunk_fndecl, function,
kono
parents:
diff changeset
377 this_adjusting, fixed_offset, virtual_value,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
378 0, virtual_offset, alias);
111
kono
parents:
diff changeset
379 if (DECL_ONE_ONLY (function))
kono
parents:
diff changeset
380 thunk_node->add_to_same_comdat_group (funcn);
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 pop_from_top_level ();
kono
parents:
diff changeset
383 }
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 /* Code for synthesizing methods which have default semantics defined. */
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 /* True iff CTYPE has a trivial SFK. */
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 static bool
kono
parents:
diff changeset
390 type_has_trivial_fn (tree ctype, special_function_kind sfk)
kono
parents:
diff changeset
391 {
kono
parents:
diff changeset
392 switch (sfk)
kono
parents:
diff changeset
393 {
kono
parents:
diff changeset
394 case sfk_constructor:
kono
parents:
diff changeset
395 return !TYPE_HAS_COMPLEX_DFLT (ctype);
kono
parents:
diff changeset
396 case sfk_copy_constructor:
kono
parents:
diff changeset
397 return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
kono
parents:
diff changeset
398 case sfk_move_constructor:
kono
parents:
diff changeset
399 return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
kono
parents:
diff changeset
400 case sfk_copy_assignment:
kono
parents:
diff changeset
401 return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
kono
parents:
diff changeset
402 case sfk_move_assignment:
kono
parents:
diff changeset
403 return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
kono
parents:
diff changeset
404 case sfk_destructor:
kono
parents:
diff changeset
405 return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
kono
parents:
diff changeset
406 case sfk_inheriting_constructor:
kono
parents:
diff changeset
407 return false;
kono
parents:
diff changeset
408 default:
kono
parents:
diff changeset
409 gcc_unreachable ();
kono
parents:
diff changeset
410 }
kono
parents:
diff changeset
411 }
kono
parents:
diff changeset
412
kono
parents:
diff changeset
413 /* Note that CTYPE has a non-trivial SFK even though we previously thought
kono
parents:
diff changeset
414 it was trivial. */
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 static void
kono
parents:
diff changeset
417 type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
kono
parents:
diff changeset
418 {
kono
parents:
diff changeset
419 switch (sfk)
kono
parents:
diff changeset
420 {
kono
parents:
diff changeset
421 case sfk_constructor:
kono
parents:
diff changeset
422 TYPE_HAS_COMPLEX_DFLT (ctype) = true;
kono
parents:
diff changeset
423 return;
kono
parents:
diff changeset
424 case sfk_copy_constructor:
kono
parents:
diff changeset
425 TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
kono
parents:
diff changeset
426 return;
kono
parents:
diff changeset
427 case sfk_move_constructor:
kono
parents:
diff changeset
428 TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
kono
parents:
diff changeset
429 return;
kono
parents:
diff changeset
430 case sfk_copy_assignment:
kono
parents:
diff changeset
431 TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
kono
parents:
diff changeset
432 return;
kono
parents:
diff changeset
433 case sfk_move_assignment:
kono
parents:
diff changeset
434 TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
kono
parents:
diff changeset
435 return;
kono
parents:
diff changeset
436 case sfk_destructor:
kono
parents:
diff changeset
437 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
kono
parents:
diff changeset
438 return;
kono
parents:
diff changeset
439 case sfk_inheriting_constructor:
kono
parents:
diff changeset
440 default:
kono
parents:
diff changeset
441 gcc_unreachable ();
kono
parents:
diff changeset
442 }
kono
parents:
diff changeset
443 }
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 /* True iff FN is a trivial defaulted member function ([cd]tor, op=). */
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 bool
kono
parents:
diff changeset
448 trivial_fn_p (tree fn)
kono
parents:
diff changeset
449 {
kono
parents:
diff changeset
450 if (TREE_CODE (fn) == TEMPLATE_DECL)
kono
parents:
diff changeset
451 return false;
kono
parents:
diff changeset
452 if (!DECL_DEFAULTED_FN (fn))
kono
parents:
diff changeset
453 return false;
kono
parents:
diff changeset
454
kono
parents:
diff changeset
455 /* If fn is a clone, get the primary variant. */
kono
parents:
diff changeset
456 if (tree prim = DECL_CLONED_FUNCTION (fn))
kono
parents:
diff changeset
457 fn = prim;
kono
parents:
diff changeset
458 return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
kono
parents:
diff changeset
459 }
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 /* PARM is a PARM_DECL for a function which we want to forward to another
kono
parents:
diff changeset
462 function without changing its value category, a la std::forward. */
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 tree
kono
parents:
diff changeset
465 forward_parm (tree parm)
kono
parents:
diff changeset
466 {
kono
parents:
diff changeset
467 tree exp = convert_from_reference (parm);
kono
parents:
diff changeset
468 tree type = TREE_TYPE (parm);
kono
parents:
diff changeset
469 if (DECL_PACK_P (parm))
kono
parents:
diff changeset
470 type = PACK_EXPANSION_PATTERN (type);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
471 if (!TYPE_REF_P (type))
111
kono
parents:
diff changeset
472 type = cp_build_reference_type (type, /*rval=*/true);
kono
parents:
diff changeset
473 warning_sentinel w (warn_useless_cast);
kono
parents:
diff changeset
474 exp = build_static_cast (type, exp, tf_warning_or_error);
kono
parents:
diff changeset
475 if (DECL_PACK_P (parm))
kono
parents:
diff changeset
476 exp = make_pack_expansion (exp);
kono
parents:
diff changeset
477 return exp;
kono
parents:
diff changeset
478 }
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 /* Strip all inheriting constructors, if any, to return the original
kono
parents:
diff changeset
481 constructor from a (possibly indirect) base class. */
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 tree
kono
parents:
diff changeset
484 strip_inheriting_ctors (tree dfn)
kono
parents:
diff changeset
485 {
kono
parents:
diff changeset
486 if (!flag_new_inheriting_ctors)
kono
parents:
diff changeset
487 return dfn;
kono
parents:
diff changeset
488 tree fn = dfn;
kono
parents:
diff changeset
489 while (tree inh = DECL_INHERITED_CTOR (fn))
kono
parents:
diff changeset
490 fn = OVL_FIRST (inh);
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 if (TREE_CODE (fn) == TEMPLATE_DECL
kono
parents:
diff changeset
493 && TREE_CODE (dfn) == FUNCTION_DECL)
kono
parents:
diff changeset
494 fn = DECL_TEMPLATE_RESULT (fn);
kono
parents:
diff changeset
495 return fn;
kono
parents:
diff changeset
496 }
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 /* Find the binfo for the base subobject of BINFO being initialized by
kono
parents:
diff changeset
499 inherited constructor FNDECL (a member of a direct base of BINFO). */
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 static tree inherited_ctor_binfo (tree, tree);
kono
parents:
diff changeset
502 static tree
kono
parents:
diff changeset
503 inherited_ctor_binfo_1 (tree binfo, tree fndecl)
kono
parents:
diff changeset
504 {
kono
parents:
diff changeset
505 tree base = DECL_CONTEXT (fndecl);
kono
parents:
diff changeset
506 tree base_binfo;
kono
parents:
diff changeset
507 for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
508 if (BINFO_TYPE (base_binfo) == base)
kono
parents:
diff changeset
509 return inherited_ctor_binfo (base_binfo, fndecl);
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 gcc_unreachable();
kono
parents:
diff changeset
512 }
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 /* Find the binfo for the base subobject of BINFO being initialized by
kono
parents:
diff changeset
515 inheriting constructor FNDECL (a member of BINFO), or BINFO if FNDECL is not
kono
parents:
diff changeset
516 an inheriting constructor. */
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 static tree
kono
parents:
diff changeset
519 inherited_ctor_binfo (tree binfo, tree fndecl)
kono
parents:
diff changeset
520 {
kono
parents:
diff changeset
521 tree inh = DECL_INHERITED_CTOR (fndecl);
kono
parents:
diff changeset
522 if (!inh)
kono
parents:
diff changeset
523 return binfo;
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 tree results = NULL_TREE;
kono
parents:
diff changeset
526 for (ovl_iterator iter (inh); iter; ++iter)
kono
parents:
diff changeset
527 {
kono
parents:
diff changeset
528 tree one = inherited_ctor_binfo_1 (binfo, *iter);
kono
parents:
diff changeset
529 if (!results)
kono
parents:
diff changeset
530 results = one;
kono
parents:
diff changeset
531 else if (one != results)
kono
parents:
diff changeset
532 results = tree_cons (NULL_TREE, one, results);
kono
parents:
diff changeset
533 }
kono
parents:
diff changeset
534 return results;
kono
parents:
diff changeset
535 }
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 /* Find the binfo for the base subobject being initialized by inheriting
kono
parents:
diff changeset
538 constructor FNDECL, or NULL_TREE if FNDECL is not an inheriting
kono
parents:
diff changeset
539 constructor. */
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 tree
kono
parents:
diff changeset
542 inherited_ctor_binfo (tree fndecl)
kono
parents:
diff changeset
543 {
kono
parents:
diff changeset
544 if (!DECL_INHERITED_CTOR (fndecl))
kono
parents:
diff changeset
545 return NULL_TREE;
kono
parents:
diff changeset
546 tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl));
kono
parents:
diff changeset
547 return inherited_ctor_binfo (binfo, fndecl);
kono
parents:
diff changeset
548 }
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 /* True if we should omit all user-declared parameters from constructor FN,
kono
parents:
diff changeset
551 because it is a base clone of a ctor inherited from a virtual base. */
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 bool
kono
parents:
diff changeset
554 ctor_omit_inherited_parms (tree fn)
kono
parents:
diff changeset
555 {
kono
parents:
diff changeset
556 if (!flag_new_inheriting_ctors)
kono
parents:
diff changeset
557 /* We only optimize away the parameters in the new model. */
kono
parents:
diff changeset
558 return false;
kono
parents:
diff changeset
559 if (!DECL_BASE_CONSTRUCTOR_P (fn)
kono
parents:
diff changeset
560 || !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
kono
parents:
diff changeset
561 return false;
kono
parents:
diff changeset
562 if (FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn)) == void_list_node)
kono
parents:
diff changeset
563 /* No user-declared parameters to omit. */
kono
parents:
diff changeset
564 return false;
kono
parents:
diff changeset
565 tree binfo = inherited_ctor_binfo (fn);
kono
parents:
diff changeset
566 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
kono
parents:
diff changeset
567 if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
568 return true;
kono
parents:
diff changeset
569 return false;
kono
parents:
diff changeset
570 }
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 /* True iff constructor(s) INH inherited into BINFO initializes INIT_BINFO.
kono
parents:
diff changeset
573 This can be true for multiple virtual bases as well as one direct
kono
parents:
diff changeset
574 non-virtual base. */
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 static bool
kono
parents:
diff changeset
577 binfo_inherited_from (tree binfo, tree init_binfo, tree inh)
kono
parents:
diff changeset
578 {
kono
parents:
diff changeset
579 /* inh is an OVERLOAD if we inherited the same constructor along
kono
parents:
diff changeset
580 multiple paths, check all of them. */
kono
parents:
diff changeset
581 for (ovl_iterator iter (inh); iter; ++iter)
kono
parents:
diff changeset
582 {
kono
parents:
diff changeset
583 tree fn = *iter;
kono
parents:
diff changeset
584 tree base = DECL_CONTEXT (fn);
kono
parents:
diff changeset
585 tree base_binfo = NULL_TREE;
kono
parents:
diff changeset
586 for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
587 if (BINFO_TYPE (base_binfo) == base)
kono
parents:
diff changeset
588 break;
kono
parents:
diff changeset
589 if (base_binfo == init_binfo
kono
parents:
diff changeset
590 || (flag_new_inheriting_ctors
kono
parents:
diff changeset
591 && binfo_inherited_from (base_binfo, init_binfo,
kono
parents:
diff changeset
592 DECL_INHERITED_CTOR (fn))))
kono
parents:
diff changeset
593 return true;
kono
parents:
diff changeset
594 }
kono
parents:
diff changeset
595 return false;
kono
parents:
diff changeset
596 }
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 /* Subroutine of do_build_copy_constructor: Add a mem-initializer for BINFO
kono
parents:
diff changeset
599 given the parameter or parameters PARM, possibly inherited constructor
kono
parents:
diff changeset
600 base INH, or move flag MOVE_P. */
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 static tree
kono
parents:
diff changeset
603 add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
kono
parents:
diff changeset
604 tree member_init_list)
kono
parents:
diff changeset
605 {
kono
parents:
diff changeset
606 tree init;
kono
parents:
diff changeset
607 if (inh)
kono
parents:
diff changeset
608 {
kono
parents:
diff changeset
609 /* An inheriting constructor only has a mem-initializer for
kono
parents:
diff changeset
610 the base it inherits from. */
kono
parents:
diff changeset
611 if (!binfo_inherited_from (TYPE_BINFO (current_class_type), binfo, inh))
kono
parents:
diff changeset
612 return member_init_list;
kono
parents:
diff changeset
613
kono
parents:
diff changeset
614 tree *p = &init;
kono
parents:
diff changeset
615 init = NULL_TREE;
kono
parents:
diff changeset
616 for (; parm; parm = DECL_CHAIN (parm))
kono
parents:
diff changeset
617 {
kono
parents:
diff changeset
618 tree exp = forward_parm (parm);
kono
parents:
diff changeset
619 *p = build_tree_list (NULL_TREE, exp);
kono
parents:
diff changeset
620 p = &TREE_CHAIN (*p);
kono
parents:
diff changeset
621 }
kono
parents:
diff changeset
622 }
kono
parents:
diff changeset
623 else
kono
parents:
diff changeset
624 {
kono
parents:
diff changeset
625 init = build_base_path (PLUS_EXPR, parm, binfo, 1,
kono
parents:
diff changeset
626 tf_warning_or_error);
kono
parents:
diff changeset
627 if (move_p)
kono
parents:
diff changeset
628 init = move (init);
kono
parents:
diff changeset
629 init = build_tree_list (NULL_TREE, init);
kono
parents:
diff changeset
630 }
kono
parents:
diff changeset
631 return tree_cons (binfo, init, member_init_list);
kono
parents:
diff changeset
632 }
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 /* Generate code for default X(X&) or X(X&&) constructor or an inheriting
kono
parents:
diff changeset
635 constructor. */
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 static void
kono
parents:
diff changeset
638 do_build_copy_constructor (tree fndecl)
kono
parents:
diff changeset
639 {
kono
parents:
diff changeset
640 tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
kono
parents:
diff changeset
641 bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
kono
parents:
diff changeset
642 bool trivial = trivial_fn_p (fndecl);
kono
parents:
diff changeset
643 tree inh = DECL_INHERITED_CTOR (fndecl);
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 if (!inh)
kono
parents:
diff changeset
646 parm = convert_from_reference (parm);
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 if (trivial)
kono
parents:
diff changeset
649 {
kono
parents:
diff changeset
650 if (is_empty_class (current_class_type))
kono
parents:
diff changeset
651 /* Don't copy the padding byte; it might not have been allocated
kono
parents:
diff changeset
652 if *this is a base subobject. */;
kono
parents:
diff changeset
653 else if (tree_int_cst_equal (TYPE_SIZE (current_class_type),
kono
parents:
diff changeset
654 CLASSTYPE_SIZE (current_class_type)))
kono
parents:
diff changeset
655 {
kono
parents:
diff changeset
656 tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
kono
parents:
diff changeset
657 finish_expr_stmt (t);
kono
parents:
diff changeset
658 }
kono
parents:
diff changeset
659 else
kono
parents:
diff changeset
660 {
kono
parents:
diff changeset
661 /* We must only copy the non-tail padding parts. */
kono
parents:
diff changeset
662 tree base_size = CLASSTYPE_SIZE_UNIT (current_class_type);
kono
parents:
diff changeset
663 base_size = size_binop (MINUS_EXPR, base_size, size_int (1));
kono
parents:
diff changeset
664 tree array_type = build_array_type (unsigned_char_type_node,
kono
parents:
diff changeset
665 build_index_type (base_size));
kono
parents:
diff changeset
666 tree alias_set = build_int_cst (TREE_TYPE (current_class_ptr), 0);
kono
parents:
diff changeset
667 tree lhs = build2 (MEM_REF, array_type,
kono
parents:
diff changeset
668 current_class_ptr, alias_set);
kono
parents:
diff changeset
669 tree rhs = build2 (MEM_REF, array_type,
kono
parents:
diff changeset
670 TREE_OPERAND (parm, 0), alias_set);
kono
parents:
diff changeset
671 tree t = build2 (INIT_EXPR, void_type_node, lhs, rhs);
kono
parents:
diff changeset
672 finish_expr_stmt (t);
kono
parents:
diff changeset
673 }
kono
parents:
diff changeset
674 }
kono
parents:
diff changeset
675 else
kono
parents:
diff changeset
676 {
kono
parents:
diff changeset
677 tree fields = TYPE_FIELDS (current_class_type);
kono
parents:
diff changeset
678 tree member_init_list = NULL_TREE;
kono
parents:
diff changeset
679 int cvquals = cp_type_quals (TREE_TYPE (parm));
kono
parents:
diff changeset
680 int i;
kono
parents:
diff changeset
681 tree binfo, base_binfo;
kono
parents:
diff changeset
682 tree init;
kono
parents:
diff changeset
683 vec<tree, va_gc> *vbases;
kono
parents:
diff changeset
684
kono
parents:
diff changeset
685 /* Initialize all the base-classes with the parameter converted
kono
parents:
diff changeset
686 to their type so that we get their copy constructor and not
kono
parents:
diff changeset
687 another constructor that takes current_class_type. We must
kono
parents:
diff changeset
688 deal with the binfo's directly as a direct base might be
kono
parents:
diff changeset
689 inaccessible due to ambiguity. */
kono
parents:
diff changeset
690 for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
kono
parents:
diff changeset
691 vec_safe_iterate (vbases, i, &binfo); i++)
kono
parents:
diff changeset
692 {
kono
parents:
diff changeset
693 member_init_list = add_one_base_init (binfo, parm, move_p, inh,
kono
parents:
diff changeset
694 member_init_list);
kono
parents:
diff changeset
695 }
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 for (binfo = TYPE_BINFO (current_class_type), i = 0;
kono
parents:
diff changeset
698 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
699 {
kono
parents:
diff changeset
700 if (BINFO_VIRTUAL_P (base_binfo))
kono
parents:
diff changeset
701 continue;
kono
parents:
diff changeset
702 member_init_list = add_one_base_init (base_binfo, parm, move_p,
kono
parents:
diff changeset
703 inh, member_init_list);
kono
parents:
diff changeset
704 }
kono
parents:
diff changeset
705
kono
parents:
diff changeset
706 for (; fields; fields = DECL_CHAIN (fields))
kono
parents:
diff changeset
707 {
kono
parents:
diff changeset
708 tree field = fields;
kono
parents:
diff changeset
709 tree expr_type;
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 if (TREE_CODE (field) != FIELD_DECL)
kono
parents:
diff changeset
712 continue;
kono
parents:
diff changeset
713 if (inh)
kono
parents:
diff changeset
714 continue;
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 expr_type = TREE_TYPE (field);
kono
parents:
diff changeset
717 if (DECL_NAME (field))
kono
parents:
diff changeset
718 {
kono
parents:
diff changeset
719 if (VFIELD_NAME_P (DECL_NAME (field)))
kono
parents:
diff changeset
720 continue;
kono
parents:
diff changeset
721 }
kono
parents:
diff changeset
722 else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
kono
parents:
diff changeset
723 /* Just use the field; anonymous types can't have
kono
parents:
diff changeset
724 nontrivial copy ctors or assignment ops or this
kono
parents:
diff changeset
725 function would be deleted. */;
kono
parents:
diff changeset
726 else
kono
parents:
diff changeset
727 continue;
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 /* Compute the type of "init->field". If the copy-constructor
kono
parents:
diff changeset
730 parameter is, for example, "const S&", and the type of
kono
parents:
diff changeset
731 the field is "T", then the type will usually be "const
kono
parents:
diff changeset
732 T". (There are no cv-qualified variants of reference
kono
parents:
diff changeset
733 types.) */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
734 if (!TYPE_REF_P (expr_type))
111
kono
parents:
diff changeset
735 {
kono
parents:
diff changeset
736 int quals = cvquals;
kono
parents:
diff changeset
737
kono
parents:
diff changeset
738 if (DECL_MUTABLE_P (field))
kono
parents:
diff changeset
739 quals &= ~TYPE_QUAL_CONST;
kono
parents:
diff changeset
740 quals |= cp_type_quals (expr_type);
kono
parents:
diff changeset
741 expr_type = cp_build_qualified_type (expr_type, quals);
kono
parents:
diff changeset
742 }
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
745 if (move_p && !TYPE_REF_P (expr_type)
111
kono
parents:
diff changeset
746 /* 'move' breaks bit-fields, and has no effect for scalars. */
kono
parents:
diff changeset
747 && !scalarish_type_p (expr_type))
kono
parents:
diff changeset
748 init = move (init);
kono
parents:
diff changeset
749 init = build_tree_list (NULL_TREE, init);
kono
parents:
diff changeset
750
kono
parents:
diff changeset
751 member_init_list = tree_cons (field, init, member_init_list);
kono
parents:
diff changeset
752 }
kono
parents:
diff changeset
753 finish_mem_initializers (member_init_list);
kono
parents:
diff changeset
754 }
kono
parents:
diff changeset
755 }
kono
parents:
diff changeset
756
kono
parents:
diff changeset
757 static void
kono
parents:
diff changeset
758 do_build_copy_assign (tree fndecl)
kono
parents:
diff changeset
759 {
kono
parents:
diff changeset
760 tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
kono
parents:
diff changeset
761 tree compound_stmt;
kono
parents:
diff changeset
762 bool move_p = move_fn_p (fndecl);
kono
parents:
diff changeset
763 bool trivial = trivial_fn_p (fndecl);
kono
parents:
diff changeset
764 int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
kono
parents:
diff changeset
765
kono
parents:
diff changeset
766 compound_stmt = begin_compound_stmt (0);
kono
parents:
diff changeset
767 parm = convert_from_reference (parm);
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 if (trivial
kono
parents:
diff changeset
770 && is_empty_class (current_class_type))
kono
parents:
diff changeset
771 /* Don't copy the padding byte; it might not have been allocated
kono
parents:
diff changeset
772 if *this is a base subobject. */;
kono
parents:
diff changeset
773 else if (trivial)
kono
parents:
diff changeset
774 {
kono
parents:
diff changeset
775 tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
kono
parents:
diff changeset
776 finish_expr_stmt (t);
kono
parents:
diff changeset
777 }
kono
parents:
diff changeset
778 else
kono
parents:
diff changeset
779 {
kono
parents:
diff changeset
780 tree fields;
kono
parents:
diff changeset
781 int cvquals = cp_type_quals (TREE_TYPE (parm));
kono
parents:
diff changeset
782 int i;
kono
parents:
diff changeset
783 tree binfo, base_binfo;
kono
parents:
diff changeset
784
kono
parents:
diff changeset
785 /* Assign to each of the direct base classes. */
kono
parents:
diff changeset
786 for (binfo = TYPE_BINFO (current_class_type), i = 0;
kono
parents:
diff changeset
787 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
788 {
kono
parents:
diff changeset
789 tree converted_parm;
kono
parents:
diff changeset
790 vec<tree, va_gc> *parmvec;
kono
parents:
diff changeset
791
kono
parents:
diff changeset
792 /* We must convert PARM directly to the base class
kono
parents:
diff changeset
793 explicitly since the base class may be ambiguous. */
kono
parents:
diff changeset
794 converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
kono
parents:
diff changeset
795 tf_warning_or_error);
kono
parents:
diff changeset
796 if (move_p)
kono
parents:
diff changeset
797 converted_parm = move (converted_parm);
kono
parents:
diff changeset
798 /* Call the base class assignment operator. */
kono
parents:
diff changeset
799 parmvec = make_tree_vector_single (converted_parm);
kono
parents:
diff changeset
800 finish_expr_stmt
kono
parents:
diff changeset
801 (build_special_member_call (current_class_ref,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
802 assign_op_identifier,
111
kono
parents:
diff changeset
803 &parmvec,
kono
parents:
diff changeset
804 base_binfo,
kono
parents:
diff changeset
805 flags,
kono
parents:
diff changeset
806 tf_warning_or_error));
kono
parents:
diff changeset
807 release_tree_vector (parmvec);
kono
parents:
diff changeset
808 }
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 /* Assign to each of the non-static data members. */
kono
parents:
diff changeset
811 for (fields = TYPE_FIELDS (current_class_type);
kono
parents:
diff changeset
812 fields;
kono
parents:
diff changeset
813 fields = DECL_CHAIN (fields))
kono
parents:
diff changeset
814 {
kono
parents:
diff changeset
815 tree comp = current_class_ref;
kono
parents:
diff changeset
816 tree init = parm;
kono
parents:
diff changeset
817 tree field = fields;
kono
parents:
diff changeset
818 tree expr_type;
kono
parents:
diff changeset
819 int quals;
kono
parents:
diff changeset
820
kono
parents:
diff changeset
821 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
kono
parents:
diff changeset
822 continue;
kono
parents:
diff changeset
823
kono
parents:
diff changeset
824 expr_type = TREE_TYPE (field);
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 if (CP_TYPE_CONST_P (expr_type))
kono
parents:
diff changeset
827 {
kono
parents:
diff changeset
828 error ("non-static const member %q#D, can%'t use default "
kono
parents:
diff changeset
829 "assignment operator", field);
kono
parents:
diff changeset
830 continue;
kono
parents:
diff changeset
831 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
832 else if (TYPE_REF_P (expr_type))
111
kono
parents:
diff changeset
833 {
kono
parents:
diff changeset
834 error ("non-static reference member %q#D, can%'t use "
kono
parents:
diff changeset
835 "default assignment operator", field);
kono
parents:
diff changeset
836 continue;
kono
parents:
diff changeset
837 }
kono
parents:
diff changeset
838
kono
parents:
diff changeset
839 if (DECL_NAME (field))
kono
parents:
diff changeset
840 {
kono
parents:
diff changeset
841 if (VFIELD_NAME_P (DECL_NAME (field)))
kono
parents:
diff changeset
842 continue;
kono
parents:
diff changeset
843 }
kono
parents:
diff changeset
844 else if (ANON_AGGR_TYPE_P (expr_type)
kono
parents:
diff changeset
845 && TYPE_FIELDS (expr_type) != NULL_TREE)
kono
parents:
diff changeset
846 /* Just use the field; anonymous types can't have
kono
parents:
diff changeset
847 nontrivial copy ctors or assignment ops or this
kono
parents:
diff changeset
848 function would be deleted. */;
kono
parents:
diff changeset
849 else
kono
parents:
diff changeset
850 continue;
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 /* Compute the type of init->field */
kono
parents:
diff changeset
855 quals = cvquals;
kono
parents:
diff changeset
856 if (DECL_MUTABLE_P (field))
kono
parents:
diff changeset
857 quals &= ~TYPE_QUAL_CONST;
kono
parents:
diff changeset
858 expr_type = cp_build_qualified_type (expr_type, quals);
kono
parents:
diff changeset
859
kono
parents:
diff changeset
860 init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
861 if (move_p && !TYPE_REF_P (expr_type)
111
kono
parents:
diff changeset
862 /* 'move' breaks bit-fields, and has no effect for scalars. */
kono
parents:
diff changeset
863 && !scalarish_type_p (expr_type))
kono
parents:
diff changeset
864 init = move (init);
kono
parents:
diff changeset
865
kono
parents:
diff changeset
866 if (DECL_NAME (field))
kono
parents:
diff changeset
867 init = cp_build_modify_expr (input_location, comp, NOP_EXPR, init,
kono
parents:
diff changeset
868 tf_warning_or_error);
kono
parents:
diff changeset
869 else
kono
parents:
diff changeset
870 init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
kono
parents:
diff changeset
871 finish_expr_stmt (init);
kono
parents:
diff changeset
872 }
kono
parents:
diff changeset
873 }
kono
parents:
diff changeset
874 finish_return_stmt (current_class_ref);
kono
parents:
diff changeset
875 finish_compound_stmt (compound_stmt);
kono
parents:
diff changeset
876 }
kono
parents:
diff changeset
877
kono
parents:
diff changeset
878 /* Synthesize FNDECL, a non-static member function. */
kono
parents:
diff changeset
879
kono
parents:
diff changeset
880 void
kono
parents:
diff changeset
881 synthesize_method (tree fndecl)
kono
parents:
diff changeset
882 {
kono
parents:
diff changeset
883 bool nested = (current_function_decl != NULL_TREE);
kono
parents:
diff changeset
884 tree context = decl_function_context (fndecl);
kono
parents:
diff changeset
885 bool need_body = true;
kono
parents:
diff changeset
886 tree stmt;
kono
parents:
diff changeset
887 location_t save_input_location = input_location;
kono
parents:
diff changeset
888 int error_count = errorcount;
kono
parents:
diff changeset
889 int warning_count = warningcount + werrorcount;
kono
parents:
diff changeset
890
kono
parents:
diff changeset
891 /* Reset the source location, we might have been previously
kono
parents:
diff changeset
892 deferred, and thus have saved where we were first needed. */
kono
parents:
diff changeset
893 DECL_SOURCE_LOCATION (fndecl)
kono
parents:
diff changeset
894 = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
kono
parents:
diff changeset
895
kono
parents:
diff changeset
896 /* If we've been asked to synthesize a clone, just synthesize the
kono
parents:
diff changeset
897 cloned function instead. Doing so will automatically fill in the
kono
parents:
diff changeset
898 body for the clone. */
kono
parents:
diff changeset
899 if (DECL_CLONED_FUNCTION_P (fndecl))
kono
parents:
diff changeset
900 fndecl = DECL_CLONED_FUNCTION (fndecl);
kono
parents:
diff changeset
901
kono
parents:
diff changeset
902 /* We may be in the middle of deferred access check. Disable
kono
parents:
diff changeset
903 it now. */
kono
parents:
diff changeset
904 push_deferring_access_checks (dk_no_deferred);
kono
parents:
diff changeset
905
kono
parents:
diff changeset
906 if (! context)
kono
parents:
diff changeset
907 push_to_top_level ();
kono
parents:
diff changeset
908 else if (nested)
kono
parents:
diff changeset
909 push_function_context ();
kono
parents:
diff changeset
910
kono
parents:
diff changeset
911 input_location = DECL_SOURCE_LOCATION (fndecl);
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
kono
parents:
diff changeset
914 stmt = begin_function_body ();
kono
parents:
diff changeset
915
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
916 if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
917 && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
111
kono
parents:
diff changeset
918 {
kono
parents:
diff changeset
919 do_build_copy_assign (fndecl);
kono
parents:
diff changeset
920 need_body = false;
kono
parents:
diff changeset
921 }
kono
parents:
diff changeset
922 else if (DECL_CONSTRUCTOR_P (fndecl))
kono
parents:
diff changeset
923 {
kono
parents:
diff changeset
924 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
kono
parents:
diff changeset
925 if (arg_chain != void_list_node)
kono
parents:
diff changeset
926 do_build_copy_constructor (fndecl);
kono
parents:
diff changeset
927 else
kono
parents:
diff changeset
928 finish_mem_initializers (NULL_TREE);
kono
parents:
diff changeset
929 }
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 /* If we haven't yet generated the body of the function, just
kono
parents:
diff changeset
932 generate an empty compound statement. */
kono
parents:
diff changeset
933 if (need_body)
kono
parents:
diff changeset
934 {
kono
parents:
diff changeset
935 tree compound_stmt;
kono
parents:
diff changeset
936 compound_stmt = begin_compound_stmt (BCS_FN_BODY);
kono
parents:
diff changeset
937 finish_compound_stmt (compound_stmt);
kono
parents:
diff changeset
938 }
kono
parents:
diff changeset
939
kono
parents:
diff changeset
940 finish_function_body (stmt);
kono
parents:
diff changeset
941 expand_or_defer_fn (finish_function (/*inline_p=*/false));
kono
parents:
diff changeset
942
kono
parents:
diff changeset
943 input_location = save_input_location;
kono
parents:
diff changeset
944
kono
parents:
diff changeset
945 if (! context)
kono
parents:
diff changeset
946 pop_from_top_level ();
kono
parents:
diff changeset
947 else if (nested)
kono
parents:
diff changeset
948 pop_function_context ();
kono
parents:
diff changeset
949
kono
parents:
diff changeset
950 pop_deferring_access_checks ();
kono
parents:
diff changeset
951
kono
parents:
diff changeset
952 if (error_count != errorcount || warning_count != warningcount + werrorcount)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
953 inform (input_location, "synthesized method %qD first required here",
111
kono
parents:
diff changeset
954 fndecl);
kono
parents:
diff changeset
955 }
kono
parents:
diff changeset
956
kono
parents:
diff changeset
957 /* Build a reference to type TYPE with cv-quals QUALS, which is an
kono
parents:
diff changeset
958 rvalue if RVALUE is true. */
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 static tree
kono
parents:
diff changeset
961 build_stub_type (tree type, int quals, bool rvalue)
kono
parents:
diff changeset
962 {
kono
parents:
diff changeset
963 tree argtype = cp_build_qualified_type (type, quals);
kono
parents:
diff changeset
964 return cp_build_reference_type (argtype, rvalue);
kono
parents:
diff changeset
965 }
kono
parents:
diff changeset
966
kono
parents:
diff changeset
967 /* Build a dummy glvalue from dereferencing a dummy reference of type
kono
parents:
diff changeset
968 REFTYPE. */
kono
parents:
diff changeset
969
kono
parents:
diff changeset
970 static tree
kono
parents:
diff changeset
971 build_stub_object (tree reftype)
kono
parents:
diff changeset
972 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
973 if (!TYPE_REF_P (reftype))
111
kono
parents:
diff changeset
974 reftype = cp_build_reference_type (reftype, /*rval*/true);
kono
parents:
diff changeset
975 tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
kono
parents:
diff changeset
976 return convert_from_reference (stub);
kono
parents:
diff changeset
977 }
kono
parents:
diff changeset
978
kono
parents:
diff changeset
979 /* Determine which function will be called when looking up NAME in TYPE,
kono
parents:
diff changeset
980 called with a single ARGTYPE argument, or no argument if ARGTYPE is
kono
parents:
diff changeset
981 null. FLAGS and COMPLAIN are as for build_new_method_call.
kono
parents:
diff changeset
982
kono
parents:
diff changeset
983 Returns a FUNCTION_DECL if all is well.
kono
parents:
diff changeset
984 Returns NULL_TREE if overload resolution failed.
kono
parents:
diff changeset
985 Returns error_mark_node if the chosen function cannot be called. */
kono
parents:
diff changeset
986
kono
parents:
diff changeset
987 static tree
kono
parents:
diff changeset
988 locate_fn_flags (tree type, tree name, tree argtype, int flags,
kono
parents:
diff changeset
989 tsubst_flags_t complain)
kono
parents:
diff changeset
990 {
kono
parents:
diff changeset
991 tree ob, fn, fns, binfo, rval;
kono
parents:
diff changeset
992 vec<tree, va_gc> *args;
kono
parents:
diff changeset
993
kono
parents:
diff changeset
994 if (TYPE_P (type))
kono
parents:
diff changeset
995 binfo = TYPE_BINFO (type);
kono
parents:
diff changeset
996 else
kono
parents:
diff changeset
997 {
kono
parents:
diff changeset
998 binfo = type;
kono
parents:
diff changeset
999 type = BINFO_TYPE (binfo);
kono
parents:
diff changeset
1000 }
kono
parents:
diff changeset
1001
kono
parents:
diff changeset
1002 ob = build_stub_object (cp_build_reference_type (type, false));
kono
parents:
diff changeset
1003 args = make_tree_vector ();
kono
parents:
diff changeset
1004 if (argtype)
kono
parents:
diff changeset
1005 {
kono
parents:
diff changeset
1006 if (TREE_CODE (argtype) == TREE_LIST)
kono
parents:
diff changeset
1007 {
kono
parents:
diff changeset
1008 for (tree elt = argtype; elt && elt != void_list_node;
kono
parents:
diff changeset
1009 elt = TREE_CHAIN (elt))
kono
parents:
diff changeset
1010 {
kono
parents:
diff changeset
1011 tree type = TREE_VALUE (elt);
kono
parents:
diff changeset
1012 tree arg = build_stub_object (type);
kono
parents:
diff changeset
1013 vec_safe_push (args, arg);
kono
parents:
diff changeset
1014 }
kono
parents:
diff changeset
1015 }
kono
parents:
diff changeset
1016 else
kono
parents:
diff changeset
1017 {
kono
parents:
diff changeset
1018 tree arg = build_stub_object (argtype);
kono
parents:
diff changeset
1019 args->quick_push (arg);
kono
parents:
diff changeset
1020 }
kono
parents:
diff changeset
1021 }
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 fns = lookup_fnfields (binfo, name, 0);
kono
parents:
diff changeset
1024 rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
kono
parents:
diff changeset
1025
kono
parents:
diff changeset
1026 release_tree_vector (args);
kono
parents:
diff changeset
1027 if (fn && rval == error_mark_node)
kono
parents:
diff changeset
1028 return rval;
kono
parents:
diff changeset
1029 else
kono
parents:
diff changeset
1030 return fn;
kono
parents:
diff changeset
1031 }
kono
parents:
diff changeset
1032
kono
parents:
diff changeset
1033 /* Locate the dtor of TYPE. */
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 tree
kono
parents:
diff changeset
1036 get_dtor (tree type, tsubst_flags_t complain)
kono
parents:
diff changeset
1037 {
kono
parents:
diff changeset
1038 tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
kono
parents:
diff changeset
1039 LOOKUP_NORMAL, complain);
kono
parents:
diff changeset
1040 if (fn == error_mark_node)
kono
parents:
diff changeset
1041 return NULL_TREE;
kono
parents:
diff changeset
1042 return fn;
kono
parents:
diff changeset
1043 }
kono
parents:
diff changeset
1044
kono
parents:
diff changeset
1045 /* Locate the default ctor of TYPE. */
kono
parents:
diff changeset
1046
kono
parents:
diff changeset
1047 tree
kono
parents:
diff changeset
1048 locate_ctor (tree type)
kono
parents:
diff changeset
1049 {
kono
parents:
diff changeset
1050 tree fn;
kono
parents:
diff changeset
1051
kono
parents:
diff changeset
1052 push_deferring_access_checks (dk_no_check);
kono
parents:
diff changeset
1053 fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
kono
parents:
diff changeset
1054 LOOKUP_SPECULATIVE, tf_none);
kono
parents:
diff changeset
1055 pop_deferring_access_checks ();
kono
parents:
diff changeset
1056 if (fn == error_mark_node)
kono
parents:
diff changeset
1057 return NULL_TREE;
kono
parents:
diff changeset
1058 return fn;
kono
parents:
diff changeset
1059 }
kono
parents:
diff changeset
1060
kono
parents:
diff changeset
1061 /* Likewise, but give any appropriate errors. */
kono
parents:
diff changeset
1062
kono
parents:
diff changeset
1063 tree
kono
parents:
diff changeset
1064 get_default_ctor (tree type)
kono
parents:
diff changeset
1065 {
kono
parents:
diff changeset
1066 tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
kono
parents:
diff changeset
1067 LOOKUP_NORMAL, tf_warning_or_error);
kono
parents:
diff changeset
1068 if (fn == error_mark_node)
kono
parents:
diff changeset
1069 return NULL_TREE;
kono
parents:
diff changeset
1070 return fn;
kono
parents:
diff changeset
1071 }
kono
parents:
diff changeset
1072
kono
parents:
diff changeset
1073 /* Locate the copy ctor of TYPE. */
kono
parents:
diff changeset
1074
kono
parents:
diff changeset
1075 tree
kono
parents:
diff changeset
1076 get_copy_ctor (tree type, tsubst_flags_t complain)
kono
parents:
diff changeset
1077 {
kono
parents:
diff changeset
1078 int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
kono
parents:
diff changeset
1079 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
kono
parents:
diff changeset
1080 tree argtype = build_stub_type (type, quals, false);
kono
parents:
diff changeset
1081 tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
kono
parents:
diff changeset
1082 LOOKUP_NORMAL, complain);
kono
parents:
diff changeset
1083 if (fn == error_mark_node)
kono
parents:
diff changeset
1084 return NULL_TREE;
kono
parents:
diff changeset
1085 return fn;
kono
parents:
diff changeset
1086 }
kono
parents:
diff changeset
1087
kono
parents:
diff changeset
1088 /* Locate the copy assignment operator of TYPE. */
kono
parents:
diff changeset
1089
kono
parents:
diff changeset
1090 tree
kono
parents:
diff changeset
1091 get_copy_assign (tree type)
kono
parents:
diff changeset
1092 {
kono
parents:
diff changeset
1093 int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
kono
parents:
diff changeset
1094 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
kono
parents:
diff changeset
1095 tree argtype = build_stub_type (type, quals, false);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1096 tree fn = locate_fn_flags (type, assign_op_identifier, argtype,
111
kono
parents:
diff changeset
1097 LOOKUP_NORMAL, tf_warning_or_error);
kono
parents:
diff changeset
1098 if (fn == error_mark_node)
kono
parents:
diff changeset
1099 return NULL_TREE;
kono
parents:
diff changeset
1100 return fn;
kono
parents:
diff changeset
1101 }
kono
parents:
diff changeset
1102
kono
parents:
diff changeset
1103 /* walk_tree helper function for is_trivially_xible. If *TP is a call,
kono
parents:
diff changeset
1104 return it if it calls something other than a trivial special member
kono
parents:
diff changeset
1105 function. */
kono
parents:
diff changeset
1106
kono
parents:
diff changeset
1107 static tree
kono
parents:
diff changeset
1108 check_nontriv (tree *tp, int *, void *)
kono
parents:
diff changeset
1109 {
kono
parents:
diff changeset
1110 tree fn = cp_get_callee (*tp);
kono
parents:
diff changeset
1111 if (fn == NULL_TREE)
kono
parents:
diff changeset
1112 return NULL_TREE;
kono
parents:
diff changeset
1113
kono
parents:
diff changeset
1114 if (TREE_CODE (fn) == ADDR_EXPR)
kono
parents:
diff changeset
1115 fn = TREE_OPERAND (fn, 0);
kono
parents:
diff changeset
1116
kono
parents:
diff changeset
1117 if (TREE_CODE (fn) != FUNCTION_DECL
kono
parents:
diff changeset
1118 || !trivial_fn_p (fn))
kono
parents:
diff changeset
1119 return fn;
kono
parents:
diff changeset
1120 return NULL_TREE;
kono
parents:
diff changeset
1121 }
kono
parents:
diff changeset
1122
kono
parents:
diff changeset
1123 /* Return declval<T>() = declval<U>() treated as an unevaluated operand. */
kono
parents:
diff changeset
1124
kono
parents:
diff changeset
1125 static tree
kono
parents:
diff changeset
1126 assignable_expr (tree to, tree from)
kono
parents:
diff changeset
1127 {
kono
parents:
diff changeset
1128 ++cp_unevaluated_operand;
kono
parents:
diff changeset
1129 to = build_stub_object (to);
kono
parents:
diff changeset
1130 from = build_stub_object (from);
kono
parents:
diff changeset
1131 tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, tf_none);
kono
parents:
diff changeset
1132 --cp_unevaluated_operand;
kono
parents:
diff changeset
1133 return r;
kono
parents:
diff changeset
1134 }
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 /* The predicate condition for a template specialization
kono
parents:
diff changeset
1137 is_constructible<T, Args...> shall be satisfied if and only if the
kono
parents:
diff changeset
1138 following variable definition would be well-formed for some invented
kono
parents:
diff changeset
1139 variable t: T t(create<Args>()...);
kono
parents:
diff changeset
1140
kono
parents:
diff changeset
1141 Return something equivalent in well-formedness and triviality. */
kono
parents:
diff changeset
1142
kono
parents:
diff changeset
1143 static tree
kono
parents:
diff changeset
1144 constructible_expr (tree to, tree from)
kono
parents:
diff changeset
1145 {
kono
parents:
diff changeset
1146 tree expr;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1147 cp_unevaluated cp_uneval_guard;
111
kono
parents:
diff changeset
1148 if (CLASS_TYPE_P (to))
kono
parents:
diff changeset
1149 {
kono
parents:
diff changeset
1150 tree ctype = to;
kono
parents:
diff changeset
1151 vec<tree, va_gc> *args = NULL;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1152 if (!TYPE_REF_P (to))
111
kono
parents:
diff changeset
1153 to = cp_build_reference_type (to, /*rval*/false);
kono
parents:
diff changeset
1154 tree ob = build_stub_object (to);
kono
parents:
diff changeset
1155 for (; from; from = TREE_CHAIN (from))
kono
parents:
diff changeset
1156 vec_safe_push (args, build_stub_object (TREE_VALUE (from)));
kono
parents:
diff changeset
1157 expr = build_special_member_call (ob, complete_ctor_identifier, &args,
kono
parents:
diff changeset
1158 ctype, LOOKUP_NORMAL, tf_none);
kono
parents:
diff changeset
1159 if (expr == error_mark_node)
kono
parents:
diff changeset
1160 return error_mark_node;
kono
parents:
diff changeset
1161 /* The current state of the standard vis-a-vis LWG 2116 is that
kono
parents:
diff changeset
1162 is_*constructible involves destruction as well. */
kono
parents:
diff changeset
1163 if (type_build_dtor_call (ctype))
kono
parents:
diff changeset
1164 {
kono
parents:
diff changeset
1165 tree dtor = build_special_member_call (ob, complete_dtor_identifier,
kono
parents:
diff changeset
1166 NULL, ctype, LOOKUP_NORMAL,
kono
parents:
diff changeset
1167 tf_none);
kono
parents:
diff changeset
1168 if (dtor == error_mark_node)
kono
parents:
diff changeset
1169 return error_mark_node;
kono
parents:
diff changeset
1170 if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
kono
parents:
diff changeset
1171 expr = build2 (COMPOUND_EXPR, void_type_node, expr, dtor);
kono
parents:
diff changeset
1172 }
kono
parents:
diff changeset
1173 }
kono
parents:
diff changeset
1174 else
kono
parents:
diff changeset
1175 {
kono
parents:
diff changeset
1176 if (from == NULL_TREE)
kono
parents:
diff changeset
1177 return build_value_init (strip_array_types (to), tf_none);
kono
parents:
diff changeset
1178 else if (TREE_CHAIN (from))
kono
parents:
diff changeset
1179 return error_mark_node; // too many initializers
kono
parents:
diff changeset
1180 from = build_stub_object (TREE_VALUE (from));
kono
parents:
diff changeset
1181 expr = perform_direct_initialization_if_possible (to, from,
kono
parents:
diff changeset
1182 /*cast*/false,
kono
parents:
diff changeset
1183 tf_none);
kono
parents:
diff changeset
1184 }
kono
parents:
diff changeset
1185 return expr;
kono
parents:
diff changeset
1186 }
kono
parents:
diff changeset
1187
kono
parents:
diff changeset
1188 /* Returns a tree iff TO is assignable (if CODE is MODIFY_EXPR) or
kono
parents:
diff changeset
1189 constructible (otherwise) from FROM, which is a single type for
kono
parents:
diff changeset
1190 assignment or a list of types for construction. */
kono
parents:
diff changeset
1191
kono
parents:
diff changeset
1192 static tree
kono
parents:
diff changeset
1193 is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
kono
parents:
diff changeset
1194 {
kono
parents:
diff changeset
1195 if (VOID_TYPE_P (to) || ABSTRACT_CLASS_TYPE_P (to)
kono
parents:
diff changeset
1196 || (from && FUNC_OR_METHOD_TYPE_P (from)
kono
parents:
diff changeset
1197 && (TYPE_READONLY (from) || FUNCTION_REF_QUALIFIED (from))))
kono
parents:
diff changeset
1198 return error_mark_node;
kono
parents:
diff changeset
1199 tree expr;
kono
parents:
diff changeset
1200 if (code == MODIFY_EXPR)
kono
parents:
diff changeset
1201 expr = assignable_expr (to, from);
kono
parents:
diff changeset
1202 else if (trivial && from && TREE_CHAIN (from))
kono
parents:
diff changeset
1203 return error_mark_node; // only 0- and 1-argument ctors can be trivial
kono
parents:
diff changeset
1204 else
kono
parents:
diff changeset
1205 expr = constructible_expr (to, from);
kono
parents:
diff changeset
1206 return expr;
kono
parents:
diff changeset
1207 }
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 /* Returns true iff TO is trivially assignable (if CODE is MODIFY_EXPR) or
kono
parents:
diff changeset
1210 constructible (otherwise) from FROM, which is a single type for
kono
parents:
diff changeset
1211 assignment or a list of types for construction. */
kono
parents:
diff changeset
1212
kono
parents:
diff changeset
1213 bool
kono
parents:
diff changeset
1214 is_trivially_xible (enum tree_code code, tree to, tree from)
kono
parents:
diff changeset
1215 {
kono
parents:
diff changeset
1216 tree expr;
kono
parents:
diff changeset
1217 expr = is_xible_helper (code, to, from, /*trivial*/true);
kono
parents:
diff changeset
1218
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1219 if (expr == NULL_TREE || expr == error_mark_node)
111
kono
parents:
diff changeset
1220 return false;
kono
parents:
diff changeset
1221 tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
kono
parents:
diff changeset
1222 return !nt;
kono
parents:
diff changeset
1223 }
kono
parents:
diff changeset
1224
kono
parents:
diff changeset
1225 /* Returns true iff TO is assignable (if CODE is MODIFY_EXPR) or
kono
parents:
diff changeset
1226 constructible (otherwise) from FROM, which is a single type for
kono
parents:
diff changeset
1227 assignment or a list of types for construction. */
kono
parents:
diff changeset
1228
kono
parents:
diff changeset
1229 bool
kono
parents:
diff changeset
1230 is_xible (enum tree_code code, tree to, tree from)
kono
parents:
diff changeset
1231 {
kono
parents:
diff changeset
1232 tree expr = is_xible_helper (code, to, from, /*trivial*/false);
kono
parents:
diff changeset
1233 if (expr == error_mark_node)
kono
parents:
diff changeset
1234 return false;
kono
parents:
diff changeset
1235 return !!expr;
kono
parents:
diff changeset
1236 }
kono
parents:
diff changeset
1237
kono
parents:
diff changeset
1238 /* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and
kono
parents:
diff changeset
1239 DELETED_P or give an error message MSG with argument ARG. */
kono
parents:
diff changeset
1240
kono
parents:
diff changeset
1241 static void
kono
parents:
diff changeset
1242 process_subob_fn (tree fn, tree *spec_p, bool *trivial_p,
kono
parents:
diff changeset
1243 bool *deleted_p, bool *constexpr_p,
kono
parents:
diff changeset
1244 bool diag, tree arg, bool dtor_from_ctor = false)
kono
parents:
diff changeset
1245 {
kono
parents:
diff changeset
1246 if (!fn || fn == error_mark_node)
kono
parents:
diff changeset
1247 {
kono
parents:
diff changeset
1248 if (deleted_p)
kono
parents:
diff changeset
1249 *deleted_p = true;
kono
parents:
diff changeset
1250 return;
kono
parents:
diff changeset
1251 }
kono
parents:
diff changeset
1252
kono
parents:
diff changeset
1253 if (spec_p)
kono
parents:
diff changeset
1254 {
kono
parents:
diff changeset
1255 maybe_instantiate_noexcept (fn);
kono
parents:
diff changeset
1256 tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
kono
parents:
diff changeset
1257 *spec_p = merge_exception_specifiers (*spec_p, raises);
kono
parents:
diff changeset
1258 }
kono
parents:
diff changeset
1259
kono
parents:
diff changeset
1260 if (!trivial_fn_p (fn) && !dtor_from_ctor)
kono
parents:
diff changeset
1261 {
kono
parents:
diff changeset
1262 if (trivial_p)
kono
parents:
diff changeset
1263 *trivial_p = false;
kono
parents:
diff changeset
1264 if (TREE_CODE (arg) == FIELD_DECL
kono
parents:
diff changeset
1265 && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
kono
parents:
diff changeset
1266 {
kono
parents:
diff changeset
1267 if (deleted_p)
kono
parents:
diff changeset
1268 *deleted_p = true;
kono
parents:
diff changeset
1269 if (diag)
kono
parents:
diff changeset
1270 error ("union member %q+D with non-trivial %qD", arg, fn);
kono
parents:
diff changeset
1271 }
kono
parents:
diff changeset
1272 }
kono
parents:
diff changeset
1273
kono
parents:
diff changeset
1274 if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
kono
parents:
diff changeset
1275 {
kono
parents:
diff changeset
1276 *constexpr_p = false;
kono
parents:
diff changeset
1277 if (diag)
kono
parents:
diff changeset
1278 {
kono
parents:
diff changeset
1279 inform (DECL_SOURCE_LOCATION (fn),
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1280 "defaulted constructor calls non-%<constexpr%> %qD", fn);
111
kono
parents:
diff changeset
1281 explain_invalid_constexpr_fn (fn);
kono
parents:
diff changeset
1282 }
kono
parents:
diff changeset
1283 }
kono
parents:
diff changeset
1284 }
kono
parents:
diff changeset
1285
kono
parents:
diff changeset
1286 /* Subroutine of synthesized_method_walk to allow recursion into anonymous
kono
parents:
diff changeset
1287 aggregates. If DTOR_FROM_CTOR is true, we're walking subobject destructors
kono
parents:
diff changeset
1288 called from a synthesized constructor, in which case we don't consider
kono
parents:
diff changeset
1289 the triviality of the subobject destructor. */
kono
parents:
diff changeset
1290
kono
parents:
diff changeset
1291 static void
kono
parents:
diff changeset
1292 walk_field_subobs (tree fields, tree fnname, special_function_kind sfk,
kono
parents:
diff changeset
1293 int quals, bool copy_arg_p, bool move_p,
kono
parents:
diff changeset
1294 bool assign_p, tree *spec_p, bool *trivial_p,
kono
parents:
diff changeset
1295 bool *deleted_p, bool *constexpr_p,
kono
parents:
diff changeset
1296 bool diag, int flags, tsubst_flags_t complain,
kono
parents:
diff changeset
1297 bool dtor_from_ctor)
kono
parents:
diff changeset
1298 {
kono
parents:
diff changeset
1299 tree field;
kono
parents:
diff changeset
1300 for (field = fields; field; field = DECL_CHAIN (field))
kono
parents:
diff changeset
1301 {
kono
parents:
diff changeset
1302 tree mem_type, argtype, rval;
kono
parents:
diff changeset
1303
kono
parents:
diff changeset
1304 if (TREE_CODE (field) != FIELD_DECL
kono
parents:
diff changeset
1305 || DECL_ARTIFICIAL (field))
kono
parents:
diff changeset
1306 continue;
kono
parents:
diff changeset
1307
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1308 /* Variant members only affect deletedness. In particular, they don't
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1309 affect the exception-specification of a user-provided destructor,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1310 which we're figuring out via get_defaulted_eh_spec. So if we aren't
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1311 asking if this is deleted, don't even look up the function; we don't
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1312 want an error about a deleted function we aren't actually calling. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1313 if (sfk == sfk_destructor && deleted_p == NULL
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1314 && TREE_CODE (DECL_CONTEXT (field)) == UNION_TYPE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1315 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1316
111
kono
parents:
diff changeset
1317 mem_type = strip_array_types (TREE_TYPE (field));
kono
parents:
diff changeset
1318 if (assign_p)
kono
parents:
diff changeset
1319 {
kono
parents:
diff changeset
1320 bool bad = true;
kono
parents:
diff changeset
1321 if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
kono
parents:
diff changeset
1322 {
kono
parents:
diff changeset
1323 if (diag)
kono
parents:
diff changeset
1324 error ("non-static const member %q#D, can%'t use default "
kono
parents:
diff changeset
1325 "assignment operator", field);
kono
parents:
diff changeset
1326 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1327 else if (TYPE_REF_P (mem_type))
111
kono
parents:
diff changeset
1328 {
kono
parents:
diff changeset
1329 if (diag)
kono
parents:
diff changeset
1330 error ("non-static reference member %q#D, can%'t use "
kono
parents:
diff changeset
1331 "default assignment operator", field);
kono
parents:
diff changeset
1332 }
kono
parents:
diff changeset
1333 else
kono
parents:
diff changeset
1334 bad = false;
kono
parents:
diff changeset
1335
kono
parents:
diff changeset
1336 if (bad && deleted_p)
kono
parents:
diff changeset
1337 *deleted_p = true;
kono
parents:
diff changeset
1338 }
kono
parents:
diff changeset
1339 else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
kono
parents:
diff changeset
1340 {
kono
parents:
diff changeset
1341 bool bad;
kono
parents:
diff changeset
1342
kono
parents:
diff changeset
1343 if (DECL_INITIAL (field))
kono
parents:
diff changeset
1344 {
kono
parents:
diff changeset
1345 if (diag && DECL_INITIAL (field) == error_mark_node)
kono
parents:
diff changeset
1346 inform (DECL_SOURCE_LOCATION (field),
kono
parents:
diff changeset
1347 "initializer for %q#D is invalid", field);
kono
parents:
diff changeset
1348 if (trivial_p)
kono
parents:
diff changeset
1349 *trivial_p = false;
kono
parents:
diff changeset
1350 /* Core 1351: If the field has an NSDMI that could throw, the
kono
parents:
diff changeset
1351 default constructor is noexcept(false). */
kono
parents:
diff changeset
1352 if (spec_p)
kono
parents:
diff changeset
1353 {
kono
parents:
diff changeset
1354 tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
kono
parents:
diff changeset
1355 if (!expr_noexcept_p (nsdmi, complain))
kono
parents:
diff changeset
1356 *spec_p = noexcept_false_spec;
kono
parents:
diff changeset
1357 }
kono
parents:
diff changeset
1358 /* Don't do the normal processing. */
kono
parents:
diff changeset
1359 continue;
kono
parents:
diff changeset
1360 }
kono
parents:
diff changeset
1361
kono
parents:
diff changeset
1362 bad = false;
kono
parents:
diff changeset
1363 if (CP_TYPE_CONST_P (mem_type)
kono
parents:
diff changeset
1364 && default_init_uninitialized_part (mem_type))
kono
parents:
diff changeset
1365 {
kono
parents:
diff changeset
1366 if (diag)
kono
parents:
diff changeset
1367 {
kono
parents:
diff changeset
1368 error ("uninitialized const member in %q#T",
kono
parents:
diff changeset
1369 current_class_type);
kono
parents:
diff changeset
1370 inform (DECL_SOURCE_LOCATION (field),
kono
parents:
diff changeset
1371 "%q#D should be initialized", field);
kono
parents:
diff changeset
1372 }
kono
parents:
diff changeset
1373 bad = true;
kono
parents:
diff changeset
1374 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1375 else if (TYPE_REF_P (mem_type))
111
kono
parents:
diff changeset
1376 {
kono
parents:
diff changeset
1377 if (diag)
kono
parents:
diff changeset
1378 {
kono
parents:
diff changeset
1379 error ("uninitialized reference member in %q#T",
kono
parents:
diff changeset
1380 current_class_type);
kono
parents:
diff changeset
1381 inform (DECL_SOURCE_LOCATION (field),
kono
parents:
diff changeset
1382 "%q#D should be initialized", field);
kono
parents:
diff changeset
1383 }
kono
parents:
diff changeset
1384 bad = true;
kono
parents:
diff changeset
1385 }
kono
parents:
diff changeset
1386
kono
parents:
diff changeset
1387 if (bad && deleted_p)
kono
parents:
diff changeset
1388 *deleted_p = true;
kono
parents:
diff changeset
1389
kono
parents:
diff changeset
1390 /* For an implicitly-defined default constructor to be constexpr,
kono
parents:
diff changeset
1391 every member must have a user-provided default constructor or
kono
parents:
diff changeset
1392 an explicit initializer. */
kono
parents:
diff changeset
1393 if (constexpr_p && !CLASS_TYPE_P (mem_type)
kono
parents:
diff changeset
1394 && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
kono
parents:
diff changeset
1395 {
kono
parents:
diff changeset
1396 *constexpr_p = false;
kono
parents:
diff changeset
1397 if (diag)
kono
parents:
diff changeset
1398 inform (DECL_SOURCE_LOCATION (field),
kono
parents:
diff changeset
1399 "defaulted default constructor does not "
kono
parents:
diff changeset
1400 "initialize %q#D", field);
kono
parents:
diff changeset
1401 }
kono
parents:
diff changeset
1402 }
kono
parents:
diff changeset
1403 else if (sfk == sfk_copy_constructor)
kono
parents:
diff changeset
1404 {
kono
parents:
diff changeset
1405 /* 12.8p11b5 */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1406 if (TYPE_REF_P (mem_type)
111
kono
parents:
diff changeset
1407 && TYPE_REF_IS_RVALUE (mem_type))
kono
parents:
diff changeset
1408 {
kono
parents:
diff changeset
1409 if (diag)
kono
parents:
diff changeset
1410 error ("copying non-static data member %q#D of rvalue "
kono
parents:
diff changeset
1411 "reference type", field);
kono
parents:
diff changeset
1412 if (deleted_p)
kono
parents:
diff changeset
1413 *deleted_p = true;
kono
parents:
diff changeset
1414 }
kono
parents:
diff changeset
1415 }
kono
parents:
diff changeset
1416
kono
parents:
diff changeset
1417 if (!CLASS_TYPE_P (mem_type))
kono
parents:
diff changeset
1418 continue;
kono
parents:
diff changeset
1419
kono
parents:
diff changeset
1420 if (ANON_AGGR_TYPE_P (mem_type))
kono
parents:
diff changeset
1421 {
kono
parents:
diff changeset
1422 walk_field_subobs (TYPE_FIELDS (mem_type), fnname, sfk, quals,
kono
parents:
diff changeset
1423 copy_arg_p, move_p, assign_p, spec_p, trivial_p,
kono
parents:
diff changeset
1424 deleted_p, constexpr_p,
kono
parents:
diff changeset
1425 diag, flags, complain, dtor_from_ctor);
kono
parents:
diff changeset
1426 continue;
kono
parents:
diff changeset
1427 }
kono
parents:
diff changeset
1428
kono
parents:
diff changeset
1429 if (copy_arg_p)
kono
parents:
diff changeset
1430 {
kono
parents:
diff changeset
1431 int mem_quals = cp_type_quals (mem_type) | quals;
kono
parents:
diff changeset
1432 if (DECL_MUTABLE_P (field))
kono
parents:
diff changeset
1433 mem_quals &= ~TYPE_QUAL_CONST;
kono
parents:
diff changeset
1434 argtype = build_stub_type (mem_type, mem_quals, move_p);
kono
parents:
diff changeset
1435 }
kono
parents:
diff changeset
1436 else
kono
parents:
diff changeset
1437 argtype = NULL_TREE;
kono
parents:
diff changeset
1438
kono
parents:
diff changeset
1439 rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
kono
parents:
diff changeset
1440
kono
parents:
diff changeset
1441 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
kono
parents:
diff changeset
1442 constexpr_p, diag, field, dtor_from_ctor);
kono
parents:
diff changeset
1443 }
kono
parents:
diff changeset
1444 }
kono
parents:
diff changeset
1445
kono
parents:
diff changeset
1446 /* Base walker helper for synthesized_method_walk. Inspect a direct
kono
parents:
diff changeset
1447 or virtual base. BINFO is the parent type's binfo. BASE_BINFO is
kono
parents:
diff changeset
1448 the base binfo of interests. All other parms are as for
kono
parents:
diff changeset
1449 synthesized_method_walk, or its local vars. */
kono
parents:
diff changeset
1450
kono
parents:
diff changeset
1451 static tree
kono
parents:
diff changeset
1452 synthesized_method_base_walk (tree binfo, tree base_binfo,
kono
parents:
diff changeset
1453 int quals, bool copy_arg_p,
kono
parents:
diff changeset
1454 bool move_p, bool ctor_p,
kono
parents:
diff changeset
1455 tree *inheriting_ctor, tree inherited_parms,
kono
parents:
diff changeset
1456 tree fnname, int flags, bool diag,
kono
parents:
diff changeset
1457 tree *spec_p, bool *trivial_p,
kono
parents:
diff changeset
1458 bool *deleted_p, bool *constexpr_p)
kono
parents:
diff changeset
1459 {
kono
parents:
diff changeset
1460 bool inherited_binfo = false;
kono
parents:
diff changeset
1461 tree argtype = NULL_TREE;
kono
parents:
diff changeset
1462 deferring_kind defer = dk_no_deferred;
kono
parents:
diff changeset
1463
kono
parents:
diff changeset
1464 if (copy_arg_p)
kono
parents:
diff changeset
1465 argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, move_p);
kono
parents:
diff changeset
1466 else if (inheriting_ctor
kono
parents:
diff changeset
1467 && (inherited_binfo
kono
parents:
diff changeset
1468 = binfo_inherited_from (binfo, base_binfo, *inheriting_ctor)))
kono
parents:
diff changeset
1469 {
kono
parents:
diff changeset
1470 argtype = inherited_parms;
kono
parents:
diff changeset
1471 /* Don't check access on the inherited constructor. */
kono
parents:
diff changeset
1472 if (flag_new_inheriting_ctors)
kono
parents:
diff changeset
1473 defer = dk_deferred;
kono
parents:
diff changeset
1474 }
kono
parents:
diff changeset
1475 /* To be conservative, ignore access to the base dtor that
kono
parents:
diff changeset
1476 DR1658 instructs us to ignore. See the comment in
kono
parents:
diff changeset
1477 synthesized_method_walk. */
kono
parents:
diff changeset
1478 else if (cxx_dialect >= cxx14 && fnname == complete_dtor_identifier
kono
parents:
diff changeset
1479 && BINFO_VIRTUAL_P (base_binfo)
kono
parents:
diff changeset
1480 && ABSTRACT_CLASS_TYPE_P (BINFO_TYPE (binfo)))
kono
parents:
diff changeset
1481 defer = dk_no_check;
kono
parents:
diff changeset
1482
kono
parents:
diff changeset
1483 if (defer != dk_no_deferred)
kono
parents:
diff changeset
1484 push_deferring_access_checks (defer);
kono
parents:
diff changeset
1485 tree rval = locate_fn_flags (base_binfo, fnname, argtype, flags,
kono
parents:
diff changeset
1486 diag ? tf_warning_or_error : tf_none);
kono
parents:
diff changeset
1487 if (defer != dk_no_deferred)
kono
parents:
diff changeset
1488 pop_deferring_access_checks ();
kono
parents:
diff changeset
1489
kono
parents:
diff changeset
1490 /* Replace an inherited template with the appropriate specialization. */
kono
parents:
diff changeset
1491 if (inherited_binfo && rval
kono
parents:
diff changeset
1492 && DECL_P (*inheriting_ctor) && DECL_P (rval)
kono
parents:
diff changeset
1493 && DECL_CONTEXT (*inheriting_ctor) == DECL_CONTEXT (rval))
kono
parents:
diff changeset
1494 *inheriting_ctor = DECL_CLONED_FUNCTION (rval);
kono
parents:
diff changeset
1495
kono
parents:
diff changeset
1496 process_subob_fn (rval, spec_p, trivial_p, deleted_p,
kono
parents:
diff changeset
1497 constexpr_p, diag, BINFO_TYPE (base_binfo));
kono
parents:
diff changeset
1498 if (ctor_p &&
kono
parents:
diff changeset
1499 (!BINFO_VIRTUAL_P (base_binfo)
kono
parents:
diff changeset
1500 || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))))
kono
parents:
diff changeset
1501 {
kono
parents:
diff changeset
1502 /* In a constructor we also need to check the subobject
kono
parents:
diff changeset
1503 destructors for cleanup of partially constructed objects. */
kono
parents:
diff changeset
1504 tree dtor = locate_fn_flags (base_binfo, complete_dtor_identifier,
kono
parents:
diff changeset
1505 NULL_TREE, flags,
kono
parents:
diff changeset
1506 diag ? tf_warning_or_error : tf_none);
kono
parents:
diff changeset
1507 /* Note that we don't pass down trivial_p; the subobject
kono
parents:
diff changeset
1508 destructors don't affect triviality of the constructor. Nor
kono
parents:
diff changeset
1509 do they affect constexpr-ness (a constant expression doesn't
kono
parents:
diff changeset
1510 throw) or exception-specification (a throw from one of the
kono
parents:
diff changeset
1511 dtors would be a double-fault). */
kono
parents:
diff changeset
1512 process_subob_fn (dtor, NULL, NULL, deleted_p, NULL, false,
kono
parents:
diff changeset
1513 BINFO_TYPE (base_binfo), /*dtor_from_ctor*/true);
kono
parents:
diff changeset
1514 }
kono
parents:
diff changeset
1515
kono
parents:
diff changeset
1516 return rval;
kono
parents:
diff changeset
1517 }
kono
parents:
diff changeset
1518
kono
parents:
diff changeset
1519 /* The caller wants to generate an implicit declaration of SFK for
kono
parents:
diff changeset
1520 CTYPE which is const if relevant and CONST_P is set. If SPEC_P,
kono
parents:
diff changeset
1521 TRIVIAL_P, DELETED_P or CONSTEXPR_P are non-null, set their
kono
parents:
diff changeset
1522 referent appropriately. If DIAG is true, we're either being called
kono
parents:
diff changeset
1523 from maybe_explain_implicit_delete to give errors, or if
kono
parents:
diff changeset
1524 CONSTEXPR_P is non-null, from explain_invalid_constexpr_fn. */
kono
parents:
diff changeset
1525
kono
parents:
diff changeset
1526 static void
kono
parents:
diff changeset
1527 synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
kono
parents:
diff changeset
1528 tree *spec_p, bool *trivial_p, bool *deleted_p,
kono
parents:
diff changeset
1529 bool *constexpr_p, bool diag,
kono
parents:
diff changeset
1530 tree *inheriting_ctor, tree inherited_parms)
kono
parents:
diff changeset
1531 {
kono
parents:
diff changeset
1532 tree binfo, base_binfo, fnname;
kono
parents:
diff changeset
1533 int i;
kono
parents:
diff changeset
1534
kono
parents:
diff changeset
1535 if (spec_p)
kono
parents:
diff changeset
1536 *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
kono
parents:
diff changeset
1537
kono
parents:
diff changeset
1538 if (deleted_p)
kono
parents:
diff changeset
1539 {
kono
parents:
diff changeset
1540 /* "The closure type associated with a lambda-expression has a deleted
kono
parents:
diff changeset
1541 default constructor and a deleted copy assignment operator."
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1542 This is diagnosed in maybe_explain_implicit_delete.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1543 In C++2a, only lambda-expressions with lambda-captures have those
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1544 deleted. */
111
kono
parents:
diff changeset
1545 if (LAMBDA_TYPE_P (ctype)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1546 && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1547 && (cxx_dialect < cxx2a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1548 || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1549 || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1550 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
111
kono
parents:
diff changeset
1551 {
kono
parents:
diff changeset
1552 *deleted_p = true;
kono
parents:
diff changeset
1553 return;
kono
parents:
diff changeset
1554 }
kono
parents:
diff changeset
1555
kono
parents:
diff changeset
1556 *deleted_p = false;
kono
parents:
diff changeset
1557 }
kono
parents:
diff changeset
1558
kono
parents:
diff changeset
1559 bool ctor_p = false;
kono
parents:
diff changeset
1560 bool assign_p = false;
kono
parents:
diff changeset
1561 bool check_vdtor = false;
kono
parents:
diff changeset
1562 switch (sfk)
kono
parents:
diff changeset
1563 {
kono
parents:
diff changeset
1564 case sfk_move_assignment:
kono
parents:
diff changeset
1565 case sfk_copy_assignment:
kono
parents:
diff changeset
1566 assign_p = true;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1567 fnname = assign_op_identifier;
111
kono
parents:
diff changeset
1568 break;
kono
parents:
diff changeset
1569
kono
parents:
diff changeset
1570 case sfk_destructor:
kono
parents:
diff changeset
1571 check_vdtor = true;
kono
parents:
diff changeset
1572 /* The synthesized method will call base dtors, but check complete
kono
parents:
diff changeset
1573 here to avoid having to deal with VTT. */
kono
parents:
diff changeset
1574 fnname = complete_dtor_identifier;
kono
parents:
diff changeset
1575 break;
kono
parents:
diff changeset
1576
kono
parents:
diff changeset
1577 case sfk_constructor:
kono
parents:
diff changeset
1578 case sfk_move_constructor:
kono
parents:
diff changeset
1579 case sfk_copy_constructor:
kono
parents:
diff changeset
1580 case sfk_inheriting_constructor:
kono
parents:
diff changeset
1581 ctor_p = true;
kono
parents:
diff changeset
1582 fnname = complete_ctor_identifier;
kono
parents:
diff changeset
1583 break;
kono
parents:
diff changeset
1584
kono
parents:
diff changeset
1585 default:
kono
parents:
diff changeset
1586 gcc_unreachable ();
kono
parents:
diff changeset
1587 }
kono
parents:
diff changeset
1588
kono
parents:
diff changeset
1589 gcc_assert ((sfk == sfk_inheriting_constructor)
kono
parents:
diff changeset
1590 == (inheriting_ctor && *inheriting_ctor != NULL_TREE));
kono
parents:
diff changeset
1591
kono
parents:
diff changeset
1592 /* If that user-written default constructor would satisfy the
kono
parents:
diff changeset
1593 requirements of a constexpr constructor (7.1.5), the
kono
parents:
diff changeset
1594 implicitly-defined default constructor is constexpr.
kono
parents:
diff changeset
1595
kono
parents:
diff changeset
1596 The implicitly-defined copy/move assignment operator is constexpr if
kono
parents:
diff changeset
1597 - X is a literal type, and
kono
parents:
diff changeset
1598 - the assignment operator selected to copy/move each direct base class
kono
parents:
diff changeset
1599 subobject is a constexpr function, and
kono
parents:
diff changeset
1600 - for each non-static data member of X that is of class type (or array
kono
parents:
diff changeset
1601 thereof), the assignment operator selected to copy/move that
kono
parents:
diff changeset
1602 member is a constexpr function. */
kono
parents:
diff changeset
1603 if (constexpr_p)
kono
parents:
diff changeset
1604 *constexpr_p = ctor_p || (assign_p && cxx_dialect >= cxx14);
kono
parents:
diff changeset
1605
kono
parents:
diff changeset
1606 bool move_p = false;
kono
parents:
diff changeset
1607 bool copy_arg_p = false;
kono
parents:
diff changeset
1608 switch (sfk)
kono
parents:
diff changeset
1609 {
kono
parents:
diff changeset
1610 case sfk_constructor:
kono
parents:
diff changeset
1611 case sfk_destructor:
kono
parents:
diff changeset
1612 case sfk_inheriting_constructor:
kono
parents:
diff changeset
1613 break;
kono
parents:
diff changeset
1614
kono
parents:
diff changeset
1615 case sfk_move_constructor:
kono
parents:
diff changeset
1616 case sfk_move_assignment:
kono
parents:
diff changeset
1617 move_p = true;
kono
parents:
diff changeset
1618 /* FALLTHRU */
kono
parents:
diff changeset
1619 case sfk_copy_constructor:
kono
parents:
diff changeset
1620 case sfk_copy_assignment:
kono
parents:
diff changeset
1621 copy_arg_p = true;
kono
parents:
diff changeset
1622 break;
kono
parents:
diff changeset
1623
kono
parents:
diff changeset
1624 default:
kono
parents:
diff changeset
1625 gcc_unreachable ();
kono
parents:
diff changeset
1626 }
kono
parents:
diff changeset
1627
kono
parents:
diff changeset
1628 bool expected_trivial = type_has_trivial_fn (ctype, sfk);
kono
parents:
diff changeset
1629 if (trivial_p)
kono
parents:
diff changeset
1630 *trivial_p = expected_trivial;
kono
parents:
diff changeset
1631
kono
parents:
diff changeset
1632 /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
kono
parents:
diff changeset
1633 class versions and other properties of the type. But a subobject
kono
parents:
diff changeset
1634 class can be trivially copyable and yet have overload resolution
kono
parents:
diff changeset
1635 choose a template constructor for initialization, depending on
kono
parents:
diff changeset
1636 rvalueness and cv-quals. And furthermore, a member in a base might
kono
parents:
diff changeset
1637 be trivial but deleted or otherwise not callable. So we can't exit
kono
parents:
diff changeset
1638 early in C++0x. The same considerations apply in C++98/03, but
kono
parents:
diff changeset
1639 there the definition of triviality does not consider overload
kono
parents:
diff changeset
1640 resolution, so a constructor can be trivial even if it would otherwise
kono
parents:
diff changeset
1641 call a non-trivial constructor. */
kono
parents:
diff changeset
1642 if (expected_trivial
kono
parents:
diff changeset
1643 && (!copy_arg_p || cxx_dialect < cxx11))
kono
parents:
diff changeset
1644 {
kono
parents:
diff changeset
1645 if (constexpr_p && sfk == sfk_constructor)
kono
parents:
diff changeset
1646 {
kono
parents:
diff changeset
1647 bool cx = trivial_default_constructor_is_constexpr (ctype);
kono
parents:
diff changeset
1648 *constexpr_p = cx;
kono
parents:
diff changeset
1649 if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
kono
parents:
diff changeset
1650 /* A trivial constructor doesn't have any NSDMI. */
kono
parents:
diff changeset
1651 inform (input_location, "defaulted default constructor does "
kono
parents:
diff changeset
1652 "not initialize any non-static data member");
kono
parents:
diff changeset
1653 }
kono
parents:
diff changeset
1654 if (!diag && cxx_dialect < cxx11)
kono
parents:
diff changeset
1655 return;
kono
parents:
diff changeset
1656 }
kono
parents:
diff changeset
1657
kono
parents:
diff changeset
1658 ++cp_unevaluated_operand;
kono
parents:
diff changeset
1659 ++c_inhibit_evaluation_warnings;
kono
parents:
diff changeset
1660 push_deferring_access_checks (dk_no_deferred);
kono
parents:
diff changeset
1661
kono
parents:
diff changeset
1662 tree scope = push_scope (ctype);
kono
parents:
diff changeset
1663
kono
parents:
diff changeset
1664 int flags = LOOKUP_NORMAL | LOOKUP_SPECULATIVE;
kono
parents:
diff changeset
1665 if (sfk != sfk_inheriting_constructor)
kono
parents:
diff changeset
1666 flags |= LOOKUP_DEFAULTED;
kono
parents:
diff changeset
1667
kono
parents:
diff changeset
1668 tsubst_flags_t complain = diag ? tf_warning_or_error : tf_none;
kono
parents:
diff changeset
1669 if (diag && spec_p)
kono
parents:
diff changeset
1670 /* We're in get_defaulted_eh_spec; we don't actually want any walking
kono
parents:
diff changeset
1671 diagnostics, we just want complain set. */
kono
parents:
diff changeset
1672 diag = false;
kono
parents:
diff changeset
1673 int quals = const_p ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED;
kono
parents:
diff changeset
1674
kono
parents:
diff changeset
1675 for (binfo = TYPE_BINFO (ctype), i = 0;
kono
parents:
diff changeset
1676 BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
kono
parents:
diff changeset
1677 {
kono
parents:
diff changeset
1678 if (!assign_p && BINFO_VIRTUAL_P (base_binfo))
kono
parents:
diff changeset
1679 /* We'll handle virtual bases below. */
kono
parents:
diff changeset
1680 continue;
kono
parents:
diff changeset
1681
kono
parents:
diff changeset
1682 tree fn = synthesized_method_base_walk (binfo, base_binfo, quals,
kono
parents:
diff changeset
1683 copy_arg_p, move_p, ctor_p,
kono
parents:
diff changeset
1684 inheriting_ctor,
kono
parents:
diff changeset
1685 inherited_parms,
kono
parents:
diff changeset
1686 fnname, flags, diag,
kono
parents:
diff changeset
1687 spec_p, trivial_p,
kono
parents:
diff changeset
1688 deleted_p, constexpr_p);
kono
parents:
diff changeset
1689
kono
parents:
diff changeset
1690 if (diag && assign_p && move_p
kono
parents:
diff changeset
1691 && BINFO_VIRTUAL_P (base_binfo)
kono
parents:
diff changeset
1692 && fn && TREE_CODE (fn) == FUNCTION_DECL
kono
parents:
diff changeset
1693 && move_fn_p (fn) && !trivial_fn_p (fn)
kono
parents:
diff changeset
1694 && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
kono
parents:
diff changeset
1695 warning (OPT_Wvirtual_move_assign,
kono
parents:
diff changeset
1696 "defaulted move assignment for %qT calls a non-trivial "
kono
parents:
diff changeset
1697 "move assignment operator for virtual base %qT",
kono
parents:
diff changeset
1698 ctype, BINFO_TYPE (base_binfo));
kono
parents:
diff changeset
1699
kono
parents:
diff changeset
1700 if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
kono
parents:
diff changeset
1701 {
kono
parents:
diff changeset
1702 /* Unlike for base ctor/op=/dtor, for operator delete it's fine
kono
parents:
diff changeset
1703 to have a null fn (no class-specific op delete). */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1704 fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
111
kono
parents:
diff changeset
1705 ptr_type_node, flags, tf_none);
kono
parents:
diff changeset
1706 if (fn && fn == error_mark_node)
kono
parents:
diff changeset
1707 {
kono
parents:
diff changeset
1708 if (complain & tf_error)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1709 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
111
kono
parents:
diff changeset
1710 ptr_type_node, flags, complain);
kono
parents:
diff changeset
1711 if (deleted_p)
kono
parents:
diff changeset
1712 *deleted_p = true;
kono
parents:
diff changeset
1713 }
kono
parents:
diff changeset
1714 check_vdtor = false;
kono
parents:
diff changeset
1715 }
kono
parents:
diff changeset
1716 }
kono
parents:
diff changeset
1717
kono
parents:
diff changeset
1718 vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (ctype);
kono
parents:
diff changeset
1719 if (assign_p)
kono
parents:
diff changeset
1720 /* Already examined vbases above. */;
kono
parents:
diff changeset
1721 else if (vec_safe_is_empty (vbases))
kono
parents:
diff changeset
1722 /* No virtual bases to worry about. */;
kono
parents:
diff changeset
1723 else if (ABSTRACT_CLASS_TYPE_P (ctype) && cxx_dialect >= cxx14
kono
parents:
diff changeset
1724 /* DR 1658 specifies that vbases of abstract classes are
kono
parents:
diff changeset
1725 ignored for both ctors and dtors. However, that breaks
kono
parents:
diff changeset
1726 virtual dtor overriding when the ignored base has a
kono
parents:
diff changeset
1727 throwing destructor. So, ignore that piece of 1658. A
kono
parents:
diff changeset
1728 defect has been filed (no number yet). */
kono
parents:
diff changeset
1729 && sfk != sfk_destructor)
kono
parents:
diff changeset
1730 /* Vbase cdtors are not relevant. */;
kono
parents:
diff changeset
1731 else
kono
parents:
diff changeset
1732 {
kono
parents:
diff changeset
1733 if (constexpr_p)
kono
parents:
diff changeset
1734 *constexpr_p = false;
kono
parents:
diff changeset
1735
kono
parents:
diff changeset
1736 FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
kono
parents:
diff changeset
1737 synthesized_method_base_walk (binfo, base_binfo, quals,
kono
parents:
diff changeset
1738 copy_arg_p, move_p, ctor_p,
kono
parents:
diff changeset
1739 inheriting_ctor, inherited_parms,
kono
parents:
diff changeset
1740 fnname, flags, diag,
kono
parents:
diff changeset
1741 spec_p, trivial_p,
kono
parents:
diff changeset
1742 deleted_p, constexpr_p);
kono
parents:
diff changeset
1743 }
kono
parents:
diff changeset
1744
kono
parents:
diff changeset
1745 /* Now handle the non-static data members. */
kono
parents:
diff changeset
1746 walk_field_subobs (TYPE_FIELDS (ctype), fnname, sfk, quals,
kono
parents:
diff changeset
1747 copy_arg_p, move_p, assign_p, spec_p, trivial_p,
kono
parents:
diff changeset
1748 deleted_p, constexpr_p,
kono
parents:
diff changeset
1749 diag, flags, complain, /*dtor_from_ctor*/false);
kono
parents:
diff changeset
1750 if (ctor_p)
kono
parents:
diff changeset
1751 walk_field_subobs (TYPE_FIELDS (ctype), complete_dtor_identifier,
kono
parents:
diff changeset
1752 sfk_destructor, TYPE_UNQUALIFIED, false,
kono
parents:
diff changeset
1753 false, false, NULL, NULL,
kono
parents:
diff changeset
1754 deleted_p, NULL,
kono
parents:
diff changeset
1755 false, flags, complain, /*dtor_from_ctor*/true);
kono
parents:
diff changeset
1756
kono
parents:
diff changeset
1757 pop_scope (scope);
kono
parents:
diff changeset
1758
kono
parents:
diff changeset
1759 pop_deferring_access_checks ();
kono
parents:
diff changeset
1760 --cp_unevaluated_operand;
kono
parents:
diff changeset
1761 --c_inhibit_evaluation_warnings;
kono
parents:
diff changeset
1762 }
kono
parents:
diff changeset
1763
kono
parents:
diff changeset
1764 /* DECL is a defaulted function whose exception specification is now
kono
parents:
diff changeset
1765 needed. Return what it should be. */
kono
parents:
diff changeset
1766
kono
parents:
diff changeset
1767 tree
kono
parents:
diff changeset
1768 get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
kono
parents:
diff changeset
1769 {
kono
parents:
diff changeset
1770 if (DECL_CLONED_FUNCTION_P (decl))
kono
parents:
diff changeset
1771 decl = DECL_CLONED_FUNCTION (decl);
kono
parents:
diff changeset
1772 special_function_kind sfk = special_function_p (decl);
kono
parents:
diff changeset
1773 tree ctype = DECL_CONTEXT (decl);
kono
parents:
diff changeset
1774 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
kono
parents:
diff changeset
1775 tree parm_type = TREE_VALUE (parms);
kono
parents:
diff changeset
1776 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
kono
parents:
diff changeset
1777 tree spec = empty_except_spec;
kono
parents:
diff changeset
1778 bool diag = !DECL_DELETED_FN (decl) && (complain & tf_error);
kono
parents:
diff changeset
1779 tree inh = DECL_INHERITED_CTOR (decl);
kono
parents:
diff changeset
1780 synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
kono
parents:
diff changeset
1781 NULL, diag, &inh, parms);
kono
parents:
diff changeset
1782 return spec;
kono
parents:
diff changeset
1783 }
kono
parents:
diff changeset
1784
kono
parents:
diff changeset
1785 /* DECL is a deleted function. If it's implicitly deleted, explain why and
kono
parents:
diff changeset
1786 return true; else return false. */
kono
parents:
diff changeset
1787
kono
parents:
diff changeset
1788 bool
kono
parents:
diff changeset
1789 maybe_explain_implicit_delete (tree decl)
kono
parents:
diff changeset
1790 {
kono
parents:
diff changeset
1791 /* If decl is a clone, get the primary variant. */
kono
parents:
diff changeset
1792 decl = DECL_ORIGIN (decl);
kono
parents:
diff changeset
1793 gcc_assert (DECL_DELETED_FN (decl));
kono
parents:
diff changeset
1794 if (DECL_DEFAULTED_FN (decl))
kono
parents:
diff changeset
1795 {
kono
parents:
diff changeset
1796 /* Not marked GTY; it doesn't need to be GC'd or written to PCH. */
kono
parents:
diff changeset
1797 static hash_set<tree> *explained;
kono
parents:
diff changeset
1798
kono
parents:
diff changeset
1799 special_function_kind sfk;
kono
parents:
diff changeset
1800 location_t loc;
kono
parents:
diff changeset
1801 bool informed;
kono
parents:
diff changeset
1802 tree ctype;
kono
parents:
diff changeset
1803
kono
parents:
diff changeset
1804 if (!explained)
kono
parents:
diff changeset
1805 explained = new hash_set<tree>;
kono
parents:
diff changeset
1806 if (explained->add (decl))
kono
parents:
diff changeset
1807 return true;
kono
parents:
diff changeset
1808
kono
parents:
diff changeset
1809 sfk = special_function_p (decl);
kono
parents:
diff changeset
1810 ctype = DECL_CONTEXT (decl);
kono
parents:
diff changeset
1811 loc = input_location;
kono
parents:
diff changeset
1812 input_location = DECL_SOURCE_LOCATION (decl);
kono
parents:
diff changeset
1813
kono
parents:
diff changeset
1814 informed = false;
kono
parents:
diff changeset
1815 if (LAMBDA_TYPE_P (ctype))
kono
parents:
diff changeset
1816 {
kono
parents:
diff changeset
1817 informed = true;
kono
parents:
diff changeset
1818 if (sfk == sfk_constructor)
kono
parents:
diff changeset
1819 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
1820 "a lambda closure type has a deleted default constructor");
kono
parents:
diff changeset
1821 else if (sfk == sfk_copy_assignment)
kono
parents:
diff changeset
1822 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
1823 "a lambda closure type has a deleted copy assignment operator");
kono
parents:
diff changeset
1824 else
kono
parents:
diff changeset
1825 informed = false;
kono
parents:
diff changeset
1826 }
kono
parents:
diff changeset
1827 else if (DECL_ARTIFICIAL (decl)
kono
parents:
diff changeset
1828 && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
kono
parents:
diff changeset
1829 && classtype_has_move_assign_or_move_ctor_p (ctype, true))
kono
parents:
diff changeset
1830 {
kono
parents:
diff changeset
1831 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
1832 "%q#D is implicitly declared as deleted because %qT "
kono
parents:
diff changeset
1833 "declares a move constructor or move assignment operator",
kono
parents:
diff changeset
1834 decl, ctype);
kono
parents:
diff changeset
1835 informed = true;
kono
parents:
diff changeset
1836 }
kono
parents:
diff changeset
1837 else if (sfk == sfk_inheriting_constructor)
kono
parents:
diff changeset
1838 {
kono
parents:
diff changeset
1839 tree binfo = inherited_ctor_binfo (decl);
kono
parents:
diff changeset
1840 if (TREE_CODE (binfo) != TREE_BINFO)
kono
parents:
diff changeset
1841 {
kono
parents:
diff changeset
1842 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
1843 "%q#D inherits from multiple base subobjects",
kono
parents:
diff changeset
1844 decl);
kono
parents:
diff changeset
1845 informed = true;
kono
parents:
diff changeset
1846 }
kono
parents:
diff changeset
1847 }
kono
parents:
diff changeset
1848 if (!informed)
kono
parents:
diff changeset
1849 {
kono
parents:
diff changeset
1850 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
kono
parents:
diff changeset
1851 tree parm_type = TREE_VALUE (parms);
kono
parents:
diff changeset
1852 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
kono
parents:
diff changeset
1853 tree raises = NULL_TREE;
kono
parents:
diff changeset
1854 bool deleted_p = false;
kono
parents:
diff changeset
1855 tree scope = push_scope (ctype);
kono
parents:
diff changeset
1856 tree inh = DECL_INHERITED_CTOR (decl);
kono
parents:
diff changeset
1857
kono
parents:
diff changeset
1858 synthesized_method_walk (ctype, sfk, const_p,
kono
parents:
diff changeset
1859 &raises, NULL, &deleted_p, NULL, false,
kono
parents:
diff changeset
1860 &inh, parms);
kono
parents:
diff changeset
1861 if (deleted_p)
kono
parents:
diff changeset
1862 {
kono
parents:
diff changeset
1863 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
1864 "%q#D is implicitly deleted because the default "
kono
parents:
diff changeset
1865 "definition would be ill-formed:", decl);
kono
parents:
diff changeset
1866 synthesized_method_walk (ctype, sfk, const_p,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1867 NULL, NULL, &deleted_p, NULL, true,
111
kono
parents:
diff changeset
1868 &inh, parms);
kono
parents:
diff changeset
1869 }
kono
parents:
diff changeset
1870 else if (!comp_except_specs
kono
parents:
diff changeset
1871 (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
kono
parents:
diff changeset
1872 raises, ce_normal))
kono
parents:
diff changeset
1873 inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
kono
parents:
diff changeset
1874 "deleted because its exception-specification does not "
kono
parents:
diff changeset
1875 "match the implicit exception-specification %qX",
kono
parents:
diff changeset
1876 decl, raises);
kono
parents:
diff changeset
1877 else if (flag_checking)
kono
parents:
diff changeset
1878 gcc_unreachable ();
kono
parents:
diff changeset
1879
kono
parents:
diff changeset
1880 pop_scope (scope);
kono
parents:
diff changeset
1881 }
kono
parents:
diff changeset
1882
kono
parents:
diff changeset
1883 input_location = loc;
kono
parents:
diff changeset
1884 return true;
kono
parents:
diff changeset
1885 }
kono
parents:
diff changeset
1886 return false;
kono
parents:
diff changeset
1887 }
kono
parents:
diff changeset
1888
kono
parents:
diff changeset
1889 /* DECL is a defaulted function which was declared constexpr. Explain why
kono
parents:
diff changeset
1890 it can't be constexpr. */
kono
parents:
diff changeset
1891
kono
parents:
diff changeset
1892 void
kono
parents:
diff changeset
1893 explain_implicit_non_constexpr (tree decl)
kono
parents:
diff changeset
1894 {
kono
parents:
diff changeset
1895 tree parm_type = TREE_VALUE (FUNCTION_FIRST_USER_PARMTYPE (decl));
kono
parents:
diff changeset
1896 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
kono
parents:
diff changeset
1897 tree inh = DECL_INHERITED_CTOR (decl);
kono
parents:
diff changeset
1898 bool dummy;
kono
parents:
diff changeset
1899 synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
kono
parents:
diff changeset
1900 special_function_p (decl), const_p,
kono
parents:
diff changeset
1901 NULL, NULL, NULL, &dummy, true,
kono
parents:
diff changeset
1902 &inh,
kono
parents:
diff changeset
1903 FUNCTION_FIRST_USER_PARMTYPE (decl));
kono
parents:
diff changeset
1904 }
kono
parents:
diff changeset
1905
kono
parents:
diff changeset
1906 /* DECL is an instantiation of an inheriting constructor template. Deduce
kono
parents:
diff changeset
1907 the correct exception-specification and deletedness for this particular
kono
parents:
diff changeset
1908 specialization. */
kono
parents:
diff changeset
1909
kono
parents:
diff changeset
1910 void
kono
parents:
diff changeset
1911 deduce_inheriting_ctor (tree decl)
kono
parents:
diff changeset
1912 {
kono
parents:
diff changeset
1913 decl = DECL_ORIGIN (decl);
kono
parents:
diff changeset
1914 gcc_assert (DECL_INHERITED_CTOR (decl));
kono
parents:
diff changeset
1915 tree spec;
kono
parents:
diff changeset
1916 bool trivial, constexpr_, deleted;
kono
parents:
diff changeset
1917 tree inh = DECL_INHERITED_CTOR (decl);
kono
parents:
diff changeset
1918 synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
kono
parents:
diff changeset
1919 false, &spec, &trivial, &deleted, &constexpr_,
kono
parents:
diff changeset
1920 /*diag*/false,
kono
parents:
diff changeset
1921 &inh,
kono
parents:
diff changeset
1922 FUNCTION_FIRST_USER_PARMTYPE (decl));
kono
parents:
diff changeset
1923 if (TREE_CODE (inherited_ctor_binfo (decl)) != TREE_BINFO)
kono
parents:
diff changeset
1924 /* Inherited the same constructor from different base subobjects. */
kono
parents:
diff changeset
1925 deleted = true;
kono
parents:
diff changeset
1926 DECL_DELETED_FN (decl) = deleted;
kono
parents:
diff changeset
1927 TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
kono
parents:
diff changeset
1928 SET_DECL_INHERITED_CTOR (decl, inh);
kono
parents:
diff changeset
1929
kono
parents:
diff changeset
1930 tree clone;
kono
parents:
diff changeset
1931 FOR_EACH_CLONE (clone, decl)
kono
parents:
diff changeset
1932 {
kono
parents:
diff changeset
1933 DECL_DELETED_FN (clone) = deleted;
kono
parents:
diff changeset
1934 TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec);
kono
parents:
diff changeset
1935 SET_DECL_INHERITED_CTOR (clone, inh);
kono
parents:
diff changeset
1936 }
kono
parents:
diff changeset
1937 }
kono
parents:
diff changeset
1938
kono
parents:
diff changeset
1939 /* Implicitly declare the special function indicated by KIND, as a
kono
parents:
diff changeset
1940 member of TYPE. For copy constructors and assignment operators,
kono
parents:
diff changeset
1941 CONST_P indicates whether these functions should take a const
kono
parents:
diff changeset
1942 reference argument or a non-const reference. Returns the
kono
parents:
diff changeset
1943 FUNCTION_DECL for the implicitly declared function. */
kono
parents:
diff changeset
1944
kono
parents:
diff changeset
1945 tree
kono
parents:
diff changeset
1946 implicitly_declare_fn (special_function_kind kind, tree type,
kono
parents:
diff changeset
1947 bool const_p, tree inherited_ctor,
kono
parents:
diff changeset
1948 tree inherited_parms)
kono
parents:
diff changeset
1949 {
kono
parents:
diff changeset
1950 tree fn;
kono
parents:
diff changeset
1951 tree parameter_types = void_list_node;
kono
parents:
diff changeset
1952 tree return_type;
kono
parents:
diff changeset
1953 tree fn_type;
kono
parents:
diff changeset
1954 tree raises = empty_except_spec;
kono
parents:
diff changeset
1955 tree rhs_parm_type = NULL_TREE;
kono
parents:
diff changeset
1956 tree this_parm;
kono
parents:
diff changeset
1957 tree name;
kono
parents:
diff changeset
1958 HOST_WIDE_INT saved_processing_template_decl;
kono
parents:
diff changeset
1959 bool deleted_p;
kono
parents:
diff changeset
1960 bool constexpr_p;
kono
parents:
diff changeset
1961
kono
parents:
diff changeset
1962 /* Because we create declarations for implicitly declared functions
kono
parents:
diff changeset
1963 lazily, we may be creating the declaration for a member of TYPE
kono
parents:
diff changeset
1964 while in some completely different context. However, TYPE will
kono
parents:
diff changeset
1965 never be a dependent class (because we never want to do lookups
kono
parents:
diff changeset
1966 for implicitly defined functions in a dependent class).
kono
parents:
diff changeset
1967 Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
kono
parents:
diff changeset
1968 because we only create clones for constructors and destructors
kono
parents:
diff changeset
1969 when not in a template. */
kono
parents:
diff changeset
1970 gcc_assert (!dependent_type_p (type));
kono
parents:
diff changeset
1971 saved_processing_template_decl = processing_template_decl;
kono
parents:
diff changeset
1972 processing_template_decl = 0;
kono
parents:
diff changeset
1973
kono
parents:
diff changeset
1974 type = TYPE_MAIN_VARIANT (type);
kono
parents:
diff changeset
1975
kono
parents:
diff changeset
1976 if (targetm.cxx.cdtor_returns_this ())
kono
parents:
diff changeset
1977 {
kono
parents:
diff changeset
1978 if (kind == sfk_destructor)
kono
parents:
diff changeset
1979 /* See comment in check_special_function_return_type. */
kono
parents:
diff changeset
1980 return_type = build_pointer_type (void_type_node);
kono
parents:
diff changeset
1981 else
kono
parents:
diff changeset
1982 return_type = build_pointer_type (type);
kono
parents:
diff changeset
1983 }
kono
parents:
diff changeset
1984 else
kono
parents:
diff changeset
1985 return_type = void_type_node;
kono
parents:
diff changeset
1986
kono
parents:
diff changeset
1987 switch (kind)
kono
parents:
diff changeset
1988 {
kono
parents:
diff changeset
1989 case sfk_destructor:
kono
parents:
diff changeset
1990 /* Destructor. */
kono
parents:
diff changeset
1991 name = dtor_identifier;
kono
parents:
diff changeset
1992 break;
kono
parents:
diff changeset
1993
kono
parents:
diff changeset
1994 case sfk_constructor:
kono
parents:
diff changeset
1995 /* Default constructor. */
kono
parents:
diff changeset
1996 name = ctor_identifier;
kono
parents:
diff changeset
1997 break;
kono
parents:
diff changeset
1998
kono
parents:
diff changeset
1999 case sfk_copy_constructor:
kono
parents:
diff changeset
2000 case sfk_copy_assignment:
kono
parents:
diff changeset
2001 case sfk_move_constructor:
kono
parents:
diff changeset
2002 case sfk_move_assignment:
kono
parents:
diff changeset
2003 case sfk_inheriting_constructor:
kono
parents:
diff changeset
2004 {
kono
parents:
diff changeset
2005 if (kind == sfk_copy_assignment
kono
parents:
diff changeset
2006 || kind == sfk_move_assignment)
kono
parents:
diff changeset
2007 {
kono
parents:
diff changeset
2008 return_type = build_reference_type (type);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2009 name = assign_op_identifier;
111
kono
parents:
diff changeset
2010 }
kono
parents:
diff changeset
2011 else
kono
parents:
diff changeset
2012 name = ctor_identifier;
kono
parents:
diff changeset
2013
kono
parents:
diff changeset
2014 if (kind == sfk_inheriting_constructor)
kono
parents:
diff changeset
2015 parameter_types = inherited_parms;
kono
parents:
diff changeset
2016 else
kono
parents:
diff changeset
2017 {
kono
parents:
diff changeset
2018 if (const_p)
kono
parents:
diff changeset
2019 rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
kono
parents:
diff changeset
2020 else
kono
parents:
diff changeset
2021 rhs_parm_type = type;
kono
parents:
diff changeset
2022 bool move_p = (kind == sfk_move_assignment
kono
parents:
diff changeset
2023 || kind == sfk_move_constructor);
kono
parents:
diff changeset
2024 rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
kono
parents:
diff changeset
2025
kono
parents:
diff changeset
2026 parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
kono
parents:
diff changeset
2027 }
kono
parents:
diff changeset
2028 break;
kono
parents:
diff changeset
2029 }
kono
parents:
diff changeset
2030 default:
kono
parents:
diff changeset
2031 gcc_unreachable ();
kono
parents:
diff changeset
2032 }
kono
parents:
diff changeset
2033
kono
parents:
diff changeset
2034 bool trivial_p = false;
kono
parents:
diff changeset
2035
kono
parents:
diff changeset
2036 if (inherited_ctor)
kono
parents:
diff changeset
2037 {
kono
parents:
diff changeset
2038 /* For an inheriting constructor, just copy these flags from the
kono
parents:
diff changeset
2039 inherited constructor until deduce_inheriting_ctor. */
kono
parents:
diff changeset
2040 raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
kono
parents:
diff changeset
2041 deleted_p = DECL_DELETED_FN (inherited_ctor);
kono
parents:
diff changeset
2042 constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
kono
parents:
diff changeset
2043 }
kono
parents:
diff changeset
2044 else if (cxx_dialect >= cxx11)
kono
parents:
diff changeset
2045 {
kono
parents:
diff changeset
2046 raises = noexcept_deferred_spec;
kono
parents:
diff changeset
2047 synthesized_method_walk (type, kind, const_p, NULL, &trivial_p,
kono
parents:
diff changeset
2048 &deleted_p, &constexpr_p, false,
kono
parents:
diff changeset
2049 &inherited_ctor, inherited_parms);
kono
parents:
diff changeset
2050 }
kono
parents:
diff changeset
2051 else
kono
parents:
diff changeset
2052 synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
kono
parents:
diff changeset
2053 &deleted_p, &constexpr_p, false,
kono
parents:
diff changeset
2054 &inherited_ctor, inherited_parms);
kono
parents:
diff changeset
2055 /* Don't bother marking a deleted constructor as constexpr. */
kono
parents:
diff changeset
2056 if (deleted_p)
kono
parents:
diff changeset
2057 constexpr_p = false;
kono
parents:
diff changeset
2058 /* A trivial copy/move constructor is also a constexpr constructor,
kono
parents:
diff changeset
2059 unless the class has virtual bases (7.1.5p4). */
kono
parents:
diff changeset
2060 else if (trivial_p && cxx_dialect >= cxx11
kono
parents:
diff changeset
2061 && (kind == sfk_copy_constructor
kono
parents:
diff changeset
2062 || kind == sfk_move_constructor)
kono
parents:
diff changeset
2063 && !CLASSTYPE_VBASECLASSES (type))
kono
parents:
diff changeset
2064 gcc_assert (constexpr_p);
kono
parents:
diff changeset
2065
kono
parents:
diff changeset
2066 if (!trivial_p && type_has_trivial_fn (type, kind))
kono
parents:
diff changeset
2067 type_set_nontrivial_flag (type, kind);
kono
parents:
diff changeset
2068
kono
parents:
diff changeset
2069 /* Create the function. */
kono
parents:
diff changeset
2070 fn_type = build_method_type_directly (type, return_type, parameter_types);
kono
parents:
diff changeset
2071 if (raises)
kono
parents:
diff changeset
2072 fn_type = build_exception_variant (fn_type, raises);
kono
parents:
diff changeset
2073 fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
kono
parents:
diff changeset
2074 if (kind != sfk_inheriting_constructor)
kono
parents:
diff changeset
2075 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
kono
parents:
diff changeset
2076