annotate gcc/cp/method.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
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.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
3 Copyright (C) 1987-2020 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"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
33 #include "intl.h"
111
kono
parents:
diff changeset
34 #include "common/common-target.h"
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 static void do_build_copy_assign (tree);
kono
parents:
diff changeset
37 static void do_build_copy_constructor (tree);
kono
parents:
diff changeset
38 static tree make_alias_for_thunk (tree);
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 /* Called once to initialize method.c. */
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 void
kono
parents:
diff changeset
43 init_method (void)
kono
parents:
diff changeset
44 {
kono
parents:
diff changeset
45 init_mangle ();
kono
parents:
diff changeset
46 }
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 /* Return a this or result adjusting thunk to FUNCTION. THIS_ADJUSTING
kono
parents:
diff changeset
49 indicates whether it is a this or result adjusting thunk.
kono
parents:
diff changeset
50 FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
kono
parents:
diff changeset
51 (see thunk_adjust). VIRTUAL_OFFSET can be NULL, but FIXED_OFFSET
kono
parents:
diff changeset
52 never is. VIRTUAL_OFFSET is the /index/ into the vtable for this
kono
parents:
diff changeset
53 adjusting thunks, we scale it to a byte offset. For covariant
kono
parents:
diff changeset
54 thunks VIRTUAL_OFFSET is the virtual binfo. You must post process
kono
parents:
diff changeset
55 the returned thunk with finish_thunk. */
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 tree
kono
parents:
diff changeset
58 make_thunk (tree function, bool this_adjusting,
kono
parents:
diff changeset
59 tree fixed_offset, tree virtual_offset)
kono
parents:
diff changeset
60 {
kono
parents:
diff changeset
61 HOST_WIDE_INT d;
kono
parents:
diff changeset
62 tree thunk;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 gcc_assert (TREE_CODE (function) == FUNCTION_DECL);
kono
parents:
diff changeset
65 /* We can have this thunks to covariant thunks, but not vice versa. */
kono
parents:
diff changeset
66 gcc_assert (!DECL_THIS_THUNK_P (function));
kono
parents:
diff changeset
67 gcc_assert (!DECL_RESULT_THUNK_P (function) || this_adjusting);
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 /* Scale the VIRTUAL_OFFSET to be in terms of bytes. */
kono
parents:
diff changeset
70 if (this_adjusting && virtual_offset)
kono
parents:
diff changeset
71 virtual_offset
kono
parents:
diff changeset
72 = size_binop (MULT_EXPR,
kono
parents:
diff changeset
73 virtual_offset,
kono
parents:
diff changeset
74 convert (ssizetype,
kono
parents:
diff changeset
75 TYPE_SIZE_UNIT (vtable_entry_type)));
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 d = tree_to_shwi (fixed_offset);
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* See if we already have the thunk in question. For this_adjusting
kono
parents:
diff changeset
80 thunks VIRTUAL_OFFSET will be an INTEGER_CST, for covariant thunks it
kono
parents:
diff changeset
81 will be a BINFO. */
kono
parents:
diff changeset
82 for (thunk = DECL_THUNKS (function); thunk; thunk = DECL_CHAIN (thunk))
kono
parents:
diff changeset
83 if (DECL_THIS_THUNK_P (thunk) == this_adjusting
kono
parents:
diff changeset
84 && THUNK_FIXED_OFFSET (thunk) == d
kono
parents:
diff changeset
85 && !virtual_offset == !THUNK_VIRTUAL_OFFSET (thunk)
kono
parents:
diff changeset
86 && (!virtual_offset
kono
parents:
diff changeset
87 || (this_adjusting
kono
parents:
diff changeset
88 ? tree_int_cst_equal (THUNK_VIRTUAL_OFFSET (thunk),
kono
parents:
diff changeset
89 virtual_offset)
kono
parents:
diff changeset
90 : THUNK_VIRTUAL_OFFSET (thunk) == virtual_offset)))
kono
parents:
diff changeset
91 return thunk;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 /* All thunks must be created before FUNCTION is actually emitted;
kono
parents:
diff changeset
94 the ABI requires that all thunks be emitted together with the
kono
parents:
diff changeset
95 function to which they transfer control. */
kono
parents:
diff changeset
96 gcc_assert (!TREE_ASM_WRITTEN (function));
kono
parents:
diff changeset
97 /* Likewise, we can only be adding thunks to a function declared in
kono
parents:
diff changeset
98 the class currently being laid out. */
kono
parents:
diff changeset
99 gcc_assert (TYPE_SIZE (DECL_CONTEXT (function))
kono
parents:
diff changeset
100 && TYPE_BEING_DEFINED (DECL_CONTEXT (function)));
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 thunk = build_decl (DECL_SOURCE_LOCATION (function),
kono
parents:
diff changeset
103 FUNCTION_DECL, NULL_TREE, TREE_TYPE (function));
kono
parents:
diff changeset
104 DECL_LANG_SPECIFIC (thunk) = DECL_LANG_SPECIFIC (function);
kono
parents:
diff changeset
105 cxx_dup_lang_specific_decl (thunk);
kono
parents:
diff changeset
106 DECL_VIRTUAL_P (thunk) = true;
kono
parents:
diff changeset
107 SET_DECL_THUNKS (thunk, NULL_TREE);
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 DECL_CONTEXT (thunk) = DECL_CONTEXT (function);
kono
parents:
diff changeset
110 TREE_READONLY (thunk) = TREE_READONLY (function);
kono
parents:
diff changeset
111 TREE_THIS_VOLATILE (thunk) = TREE_THIS_VOLATILE (function);
kono
parents:
diff changeset
112 TREE_PUBLIC (thunk) = TREE_PUBLIC (function);
kono
parents:
diff changeset
113 SET_DECL_THUNK_P (thunk, this_adjusting);
kono
parents:
diff changeset
114 THUNK_TARGET (thunk) = function;
kono
parents:
diff changeset
115 THUNK_FIXED_OFFSET (thunk) = d;
kono
parents:
diff changeset
116 THUNK_VIRTUAL_OFFSET (thunk) = virtual_offset;
kono
parents:
diff changeset
117 THUNK_ALIAS (thunk) = NULL_TREE;
kono
parents:
diff changeset
118
kono
parents:
diff changeset
119 DECL_INTERFACE_KNOWN (thunk) = 1;
kono
parents:
diff changeset
120 DECL_NOT_REALLY_EXTERN (thunk) = 1;
kono
parents:
diff changeset
121 DECL_COMDAT (thunk) = DECL_COMDAT (function);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
122 DECL_SAVED_AUTO_RETURN_TYPE (thunk) = NULL;
111
kono
parents:
diff changeset
123 /* The thunk itself is not a constructor or destructor, even if
kono
parents:
diff changeset
124 the thing it is thunking to is. */
kono
parents:
diff changeset
125 DECL_CXX_DESTRUCTOR_P (thunk) = 0;
kono
parents:
diff changeset
126 DECL_CXX_CONSTRUCTOR_P (thunk) = 0;
kono
parents:
diff changeset
127 DECL_EXTERNAL (thunk) = 1;
kono
parents:
diff changeset
128 DECL_ARTIFICIAL (thunk) = 1;
kono
parents:
diff changeset
129 /* The THUNK is not a pending inline, even if the FUNCTION is. */
kono
parents:
diff changeset
130 DECL_PENDING_INLINE_P (thunk) = 0;
kono
parents:
diff changeset
131 DECL_DECLARED_INLINE_P (thunk) = 0;
kono
parents:
diff changeset
132 /* Nor is it a template instantiation. */
kono
parents:
diff changeset
133 DECL_USE_TEMPLATE (thunk) = 0;
kono
parents:
diff changeset
134 DECL_TEMPLATE_INFO (thunk) = NULL;
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 /* Add it to the list of thunks associated with FUNCTION. */
kono
parents:
diff changeset
137 DECL_CHAIN (thunk) = DECL_THUNKS (function);
kono
parents:
diff changeset
138 SET_DECL_THUNKS (function, thunk);
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 return thunk;
kono
parents:
diff changeset
141 }
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 /* Finish THUNK, a thunk decl. */
kono
parents:
diff changeset
144
kono
parents:
diff changeset
145 void
kono
parents:
diff changeset
146 finish_thunk (tree thunk)
kono
parents:
diff changeset
147 {
kono
parents:
diff changeset
148 tree function, name;
kono
parents:
diff changeset
149 tree fixed_offset = ssize_int (THUNK_FIXED_OFFSET (thunk));
kono
parents:
diff changeset
150 tree virtual_offset = THUNK_VIRTUAL_OFFSET (thunk);
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 gcc_assert (!DECL_NAME (thunk) && DECL_THUNK_P (thunk));
kono
parents:
diff changeset
153 if (virtual_offset && DECL_RESULT_THUNK_P (thunk))
kono
parents:
diff changeset
154 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
kono
parents:
diff changeset
155 function = THUNK_TARGET (thunk);
kono
parents:
diff changeset
156 name = mangle_thunk (function, DECL_THIS_THUNK_P (thunk),
kono
parents:
diff changeset
157 fixed_offset, virtual_offset, thunk);
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 /* We can end up with declarations of (logically) different
kono
parents:
diff changeset
160 covariant thunks, that do identical adjustments. The two thunks
kono
parents:
diff changeset
161 will be adjusting between within different hierarchies, which
kono
parents:
diff changeset
162 happen to have the same layout. We must nullify one of them to
kono
parents:
diff changeset
163 refer to the other. */
kono
parents:
diff changeset
164 if (DECL_RESULT_THUNK_P (thunk))
kono
parents:
diff changeset
165 {
kono
parents:
diff changeset
166 tree cov_probe;
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 for (cov_probe = DECL_THUNKS (function);
kono
parents:
diff changeset
169 cov_probe; cov_probe = DECL_CHAIN (cov_probe))
kono
parents:
diff changeset
170 if (DECL_NAME (cov_probe) == name)
kono
parents:
diff changeset
171 {
kono
parents:
diff changeset
172 gcc_assert (!DECL_THUNKS (thunk));
kono
parents:
diff changeset
173 THUNK_ALIAS (thunk) = (THUNK_ALIAS (cov_probe)
kono
parents:
diff changeset
174 ? THUNK_ALIAS (cov_probe) : cov_probe);
kono
parents:
diff changeset
175 break;
kono
parents:
diff changeset
176 }
kono
parents:
diff changeset
177 }
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 DECL_NAME (thunk) = name;
kono
parents:
diff changeset
180 SET_DECL_ASSEMBLER_NAME (thunk, name);
kono
parents:
diff changeset
181 }
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 static GTY (()) int thunk_labelno;
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 /* Create a static alias to target. */
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 tree
kono
parents:
diff changeset
188 make_alias_for (tree target, tree newid)
kono
parents:
diff changeset
189 {
kono
parents:
diff changeset
190 tree alias = build_decl (DECL_SOURCE_LOCATION (target),
kono
parents:
diff changeset
191 TREE_CODE (target), newid, TREE_TYPE (target));
kono
parents:
diff changeset
192 DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
kono
parents:
diff changeset
193 cxx_dup_lang_specific_decl (alias);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
194 DECL_CONTEXT (alias) = DECL_CONTEXT (target);
111
kono
parents:
diff changeset
195 TREE_READONLY (alias) = TREE_READONLY (target);
kono
parents:
diff changeset
196 TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
kono
parents:
diff changeset
197 TREE_PUBLIC (alias) = 0;
kono
parents:
diff changeset
198 DECL_INTERFACE_KNOWN (alias) = 1;
kono
parents:
diff changeset
199 if (DECL_LANG_SPECIFIC (alias))
kono
parents:
diff changeset
200 {
kono
parents:
diff changeset
201 DECL_NOT_REALLY_EXTERN (alias) = 1;
kono
parents:
diff changeset
202 DECL_USE_TEMPLATE (alias) = 0;
kono
parents:
diff changeset
203 DECL_TEMPLATE_INFO (alias) = NULL;
kono
parents:
diff changeset
204 }
kono
parents:
diff changeset
205 DECL_EXTERNAL (alias) = 0;
kono
parents:
diff changeset
206 DECL_ARTIFICIAL (alias) = 1;
kono
parents:
diff changeset
207 DECL_TEMPLATE_INSTANTIATED (alias) = 0;
kono
parents:
diff changeset
208 if (TREE_CODE (alias) == FUNCTION_DECL)
kono
parents:
diff changeset
209 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
210 DECL_SAVED_AUTO_RETURN_TYPE (alias) = NULL;
111
kono
parents:
diff changeset
211 DECL_CXX_DESTRUCTOR_P (alias) = 0;
kono
parents:
diff changeset
212 DECL_CXX_CONSTRUCTOR_P (alias) = 0;
kono
parents:
diff changeset
213 DECL_PENDING_INLINE_P (alias) = 0;
kono
parents:
diff changeset
214 DECL_DECLARED_INLINE_P (alias) = 0;
kono
parents:
diff changeset
215 DECL_INITIAL (alias) = error_mark_node;
kono
parents:
diff changeset
216 DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
kono
parents:
diff changeset
217 }
kono
parents:
diff changeset
218 else
kono
parents:
diff changeset
219 TREE_STATIC (alias) = 1;
kono
parents:
diff changeset
220 TREE_ADDRESSABLE (alias) = 1;
kono
parents:
diff changeset
221 TREE_USED (alias) = 1;
kono
parents:
diff changeset
222 SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
kono
parents:
diff changeset
223 return alias;
kono
parents:
diff changeset
224 }
kono
parents:
diff changeset
225
kono
parents:
diff changeset
226 static tree
kono
parents:
diff changeset
227 make_alias_for_thunk (tree function)
kono
parents:
diff changeset
228 {
kono
parents:
diff changeset
229 tree alias;
kono
parents:
diff changeset
230 char buf[256];
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 targetm.asm_out.generate_internal_label (buf, "LTHUNK", thunk_labelno);
kono
parents:
diff changeset
233 thunk_labelno++;
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 alias = make_alias_for (function, get_identifier (buf));
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 if (!flag_syntax_only)
kono
parents:
diff changeset
238 {
kono
parents:
diff changeset
239 struct cgraph_node *funcn, *aliasn;
kono
parents:
diff changeset
240 funcn = cgraph_node::get (function);
kono
parents:
diff changeset
241 gcc_checking_assert (funcn);
kono
parents:
diff changeset
242 aliasn = cgraph_node::create_same_body_alias (alias, function);
kono
parents:
diff changeset
243 DECL_ASSEMBLER_NAME (function);
kono
parents:
diff changeset
244 gcc_assert (aliasn != NULL);
kono
parents:
diff changeset
245 }
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247 return alias;
kono
parents:
diff changeset
248 }
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 /* Emit the definition of a C++ multiple inheritance or covariant
kono
parents:
diff changeset
251 return vtable thunk. If EMIT_P is nonzero, the thunk is emitted
kono
parents:
diff changeset
252 immediately. */
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 void
kono
parents:
diff changeset
255 use_thunk (tree thunk_fndecl, bool emit_p)
kono
parents:
diff changeset
256 {
kono
parents:
diff changeset
257 tree a, t, function, alias;
kono
parents:
diff changeset
258 tree virtual_offset;
kono
parents:
diff changeset
259 HOST_WIDE_INT fixed_offset, virtual_value;
kono
parents:
diff changeset
260 bool this_adjusting = DECL_THIS_THUNK_P (thunk_fndecl);
kono
parents:
diff changeset
261 struct cgraph_node *funcn, *thunk_node;
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 /* We should have called finish_thunk to give it a name. */
kono
parents:
diff changeset
264 gcc_assert (DECL_NAME (thunk_fndecl));
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 /* We should never be using an alias, always refer to the
kono
parents:
diff changeset
267 aliased thunk. */
kono
parents:
diff changeset
268 gcc_assert (!THUNK_ALIAS (thunk_fndecl));
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 if (TREE_ASM_WRITTEN (thunk_fndecl))
kono
parents:
diff changeset
271 return;
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 function = THUNK_TARGET (thunk_fndecl);
kono
parents:
diff changeset
274 if (DECL_RESULT (thunk_fndecl))
kono
parents:
diff changeset
275 /* We already turned this thunk into an ordinary function.
kono
parents:
diff changeset
276 There's no need to process this thunk again. */
kono
parents:
diff changeset
277 return;
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 if (DECL_THUNK_P (function))
kono
parents:
diff changeset
280 /* The target is itself a thunk, process it now. */
kono
parents:
diff changeset
281 use_thunk (function, emit_p);
kono
parents:
diff changeset
282
kono
parents:
diff changeset
283 /* Thunks are always addressable; they only appear in vtables. */
kono
parents:
diff changeset
284 TREE_ADDRESSABLE (thunk_fndecl) = 1;
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 /* Figure out what function is being thunked to. It's referenced in
kono
parents:
diff changeset
287 this translation unit. */
kono
parents:
diff changeset
288 TREE_ADDRESSABLE (function) = 1;
kono
parents:
diff changeset
289 mark_used (function);
kono
parents:
diff changeset
290 if (!emit_p)
kono
parents:
diff changeset
291 return;
kono
parents:
diff changeset
292
kono
parents:
diff changeset
293 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function))
kono
parents:
diff changeset
294 alias = make_alias_for_thunk (function);
kono
parents:
diff changeset
295 else
kono
parents:
diff changeset
296 alias = function;
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 fixed_offset = THUNK_FIXED_OFFSET (thunk_fndecl);
kono
parents:
diff changeset
299 virtual_offset = THUNK_VIRTUAL_OFFSET (thunk_fndecl);
kono
parents:
diff changeset
300
kono
parents:
diff changeset
301 if (virtual_offset)
kono
parents:
diff changeset
302 {
kono
parents:
diff changeset
303 if (!this_adjusting)
kono
parents:
diff changeset
304 virtual_offset = BINFO_VPTR_FIELD (virtual_offset);
kono
parents:
diff changeset
305 virtual_value = tree_to_shwi (virtual_offset);
kono
parents:
diff changeset
306 gcc_assert (virtual_value);
kono
parents:
diff changeset
307 }
kono
parents:
diff changeset
308 else
kono
parents:
diff changeset
309 virtual_value = 0;
kono
parents:
diff changeset
310
kono
parents:
diff changeset
311 /* And, if we need to emit the thunk, it's used. */
kono
parents:
diff changeset
312 mark_used (thunk_fndecl);
kono
parents:
diff changeset
313 /* This thunk is actually defined. */
kono
parents:
diff changeset
314 DECL_EXTERNAL (thunk_fndecl) = 0;
kono
parents:
diff changeset
315 /* The linkage of the function may have changed. FIXME in linkage
kono
parents:
diff changeset
316 rewrite. */
kono
parents:
diff changeset
317 gcc_assert (DECL_INTERFACE_KNOWN (function));
kono
parents:
diff changeset
318 TREE_PUBLIC (thunk_fndecl) = TREE_PUBLIC (function);
kono
parents:
diff changeset
319 DECL_VISIBILITY (thunk_fndecl) = DECL_VISIBILITY (function);
kono
parents:
diff changeset
320 DECL_VISIBILITY_SPECIFIED (thunk_fndecl)
kono
parents:
diff changeset
321 = DECL_VISIBILITY_SPECIFIED (function);
kono
parents:
diff changeset
322 DECL_COMDAT (thunk_fndecl) = DECL_COMDAT (function);
kono
parents:
diff changeset
323 DECL_WEAK (thunk_fndecl) = DECL_WEAK (function);
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 if (flag_syntax_only)
kono
parents:
diff changeset
326 {
kono
parents:
diff changeset
327 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
kono
parents:
diff changeset
328 return;
kono
parents:
diff changeset
329 }
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 push_to_top_level ();
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 if (TARGET_USE_LOCAL_THUNK_ALIAS_P (function)
kono
parents:
diff changeset
334 && targetm_common.have_named_sections)
kono
parents:
diff changeset
335 {
kono
parents:
diff changeset
336 tree fn = function;
kono
parents:
diff changeset
337 struct symtab_node *symbol;
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 if ((symbol = symtab_node::get (function))
kono
parents:
diff changeset
340 && symbol->alias)
kono
parents:
diff changeset
341 {
kono
parents:
diff changeset
342 if (symbol->analyzed)
kono
parents:
diff changeset
343 fn = symtab_node::get (function)->ultimate_alias_target ()->decl;
kono
parents:
diff changeset
344 else
kono
parents:
diff changeset
345 fn = symtab_node::get (function)->alias_target;
kono
parents:
diff changeset
346 }
kono
parents:
diff changeset
347 resolve_unique_section (fn, 0, flag_function_sections);
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 if (DECL_SECTION_NAME (fn) != NULL && DECL_ONE_ONLY (fn))
kono
parents:
diff changeset
350 {
kono
parents:
diff changeset
351 resolve_unique_section (thunk_fndecl, 0, flag_function_sections);
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 /* Output the thunk into the same section as function. */
kono
parents:
diff changeset
354 set_decl_section_name (thunk_fndecl, DECL_SECTION_NAME (fn));
kono
parents:
diff changeset
355 symtab_node::get (thunk_fndecl)->implicit_section
kono
parents:
diff changeset
356 = symtab_node::get (fn)->implicit_section;
kono
parents:
diff changeset
357 }
kono
parents:
diff changeset
358 }
kono
parents:
diff changeset
359
kono
parents:
diff changeset
360 /* Set up cloned argument trees for the thunk. */
kono
parents:
diff changeset
361 t = NULL_TREE;
kono
parents:
diff changeset
362 for (a = DECL_ARGUMENTS (function); a; a = DECL_CHAIN (a))
kono
parents:
diff changeset
363 {
kono
parents:
diff changeset
364 tree x = copy_node (a);
kono
parents:
diff changeset
365 DECL_CHAIN (x) = t;
kono
parents:
diff changeset
366 DECL_CONTEXT (x) = thunk_fndecl;
kono
parents:
diff changeset
367 SET_DECL_RTL (x, NULL);
kono
parents:
diff changeset
368 DECL_HAS_VALUE_EXPR_P (x) = 0;
kono
parents:
diff changeset
369 TREE_ADDRESSABLE (x) = 0;
kono
parents:
diff changeset
370 t = x;
kono
parents:
diff changeset
371 }
kono
parents:
diff changeset
372 a = nreverse (t);
kono
parents:
diff changeset
373 DECL_ARGUMENTS (thunk_fndecl) = a;
kono
parents:
diff changeset
374 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
kono
parents:
diff changeset
375 funcn = cgraph_node::get (function);
kono
parents:
diff changeset
376 gcc_checking_assert (funcn);
kono
parents:
diff changeset
377 thunk_node = funcn->create_thunk (thunk_fndecl, function,
kono
parents:
diff changeset
378 this_adjusting, fixed_offset, virtual_value,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
379 0, virtual_offset, alias);
111
kono
parents:
diff changeset
380 if (DECL_ONE_ONLY (function))
kono
parents:
diff changeset
381 thunk_node->add_to_same_comdat_group (funcn);
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 pop_from_top_level ();
kono
parents:
diff changeset
384 }
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 /* Code for synthesizing methods which have default semantics defined. */
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 /* True iff CTYPE has a trivial SFK. */
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 static bool
kono
parents:
diff changeset
391 type_has_trivial_fn (tree ctype, special_function_kind sfk)
kono
parents:
diff changeset
392 {
kono
parents:
diff changeset
393 switch (sfk)
kono
parents:
diff changeset
394 {
kono
parents:
diff changeset
395 case sfk_constructor:
kono
parents:
diff changeset
396 return !TYPE_HAS_COMPLEX_DFLT (ctype);
kono
parents:
diff changeset
397 case sfk_copy_constructor:
kono
parents:
diff changeset
398 return !TYPE_HAS_COMPLEX_COPY_CTOR (ctype);
kono
parents:
diff changeset
399 case sfk_move_constructor:
kono
parents:
diff changeset
400 return !TYPE_HAS_COMPLEX_MOVE_CTOR (ctype);
kono
parents:
diff changeset
401 case sfk_copy_assignment:
kono
parents:
diff changeset
402 return !TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype);
kono
parents:
diff changeset
403 case sfk_move_assignment:
kono
parents:
diff changeset
404 return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype);
kono
parents:
diff changeset
405 case sfk_destructor:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
406 case sfk_virtual_destructor:
111
kono
parents:
diff changeset
407 return !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype);
kono
parents:
diff changeset
408 case sfk_inheriting_constructor:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
409 case sfk_comparison:
111
kono
parents:
diff changeset
410 return false;
kono
parents:
diff changeset
411 default:
kono
parents:
diff changeset
412 gcc_unreachable ();
kono
parents:
diff changeset
413 }
kono
parents:
diff changeset
414 }
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 /* Note that CTYPE has a non-trivial SFK even though we previously thought
kono
parents:
diff changeset
417 it was trivial. */
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 static void
kono
parents:
diff changeset
420 type_set_nontrivial_flag (tree ctype, special_function_kind sfk)
kono
parents:
diff changeset
421 {
kono
parents:
diff changeset
422 switch (sfk)
kono
parents:
diff changeset
423 {
kono
parents:
diff changeset
424 case sfk_constructor:
kono
parents:
diff changeset
425 TYPE_HAS_COMPLEX_DFLT (ctype) = true;
kono
parents:
diff changeset
426 return;
kono
parents:
diff changeset
427 case sfk_copy_constructor:
kono
parents:
diff changeset
428 TYPE_HAS_COMPLEX_COPY_CTOR (ctype) = true;
kono
parents:
diff changeset
429 return;
kono
parents:
diff changeset
430 case sfk_move_constructor:
kono
parents:
diff changeset
431 TYPE_HAS_COMPLEX_MOVE_CTOR (ctype) = true;
kono
parents:
diff changeset
432 return;
kono
parents:
diff changeset
433 case sfk_copy_assignment:
kono
parents:
diff changeset
434 TYPE_HAS_COMPLEX_COPY_ASSIGN (ctype) = true;
kono
parents:
diff changeset
435 return;
kono
parents:
diff changeset
436 case sfk_move_assignment:
kono
parents:
diff changeset
437 TYPE_HAS_COMPLEX_MOVE_ASSIGN (ctype) = true;
kono
parents:
diff changeset
438 return;
kono
parents:
diff changeset
439 case sfk_destructor:
kono
parents:
diff changeset
440 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype) = true;
kono
parents:
diff changeset
441 return;
kono
parents:
diff changeset
442 case sfk_inheriting_constructor:
kono
parents:
diff changeset
443 default:
kono
parents:
diff changeset
444 gcc_unreachable ();
kono
parents:
diff changeset
445 }
kono
parents:
diff changeset
446 }
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 /* True iff FN is a trivial defaulted member function ([cd]tor, op=). */
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 bool
kono
parents:
diff changeset
451 trivial_fn_p (tree fn)
kono
parents:
diff changeset
452 {
kono
parents:
diff changeset
453 if (TREE_CODE (fn) == TEMPLATE_DECL)
kono
parents:
diff changeset
454 return false;
kono
parents:
diff changeset
455 if (!DECL_DEFAULTED_FN (fn))
kono
parents:
diff changeset
456 return false;
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 /* If fn is a clone, get the primary variant. */
kono
parents:
diff changeset
459 if (tree prim = DECL_CLONED_FUNCTION (fn))
kono
parents:
diff changeset
460 fn = prim;
kono
parents:
diff changeset
461 return type_has_trivial_fn (DECL_CONTEXT (fn), special_function_p (fn));
kono
parents:
diff changeset
462 }
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 /* PARM is a PARM_DECL for a function which we want to forward to another
kono
parents:
diff changeset
465 function without changing its value category, a la std::forward. */
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 tree
kono
parents:
diff changeset
468 forward_parm (tree parm)
kono
parents:
diff changeset
469 {
kono
parents:
diff changeset
470 tree exp = convert_from_reference (parm);
kono
parents:
diff changeset
471 tree type = TREE_TYPE (parm);
kono
parents:
diff changeset
472 if (DECL_PACK_P (parm))
kono
parents:
diff changeset
473 type = PACK_EXPANSION_PATTERN (type);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
474 if (!TYPE_REF_P (type))
111
kono
parents:
diff changeset
475 type = cp_build_reference_type (type, /*rval=*/true);
kono
parents:
diff changeset
476 warning_sentinel w (warn_useless_cast);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
477 exp = build_static_cast (input_location, type, exp,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
478 tf_warning_or_error);
111
kono
parents:
diff changeset
479 if (DECL_PACK_P (parm))
kono
parents:
diff changeset
480 exp = make_pack_expansion (exp);
kono
parents:
diff changeset
481 return exp;
kono
parents:
diff changeset
482 }
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 /* Strip all inheriting constructors, if any, to return the original
kono
parents:
diff changeset
485 constructor from a (possibly indirect) base class. */
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 tree
kono
parents:
diff changeset
488 strip_inheriting_ctors (tree dfn)
kono
parents:
diff changeset
489 {
kono
parents:
diff changeset
490 if (!flag_new_inheriting_ctors)
kono
parents:
diff changeset
491 return dfn;
kono
parents:
diff changeset
492 tree fn = dfn;
kono
parents:
diff changeset
493 while (tree inh = DECL_INHERITED_CTOR (fn))
kono
parents:
diff changeset
494 fn = OVL_FIRST (inh);
kono
parents:
diff changeset
495
kono
parents:
diff changeset
496 if (TREE_CODE (fn) == TEMPLATE_DECL
kono
parents:
diff changeset
497 && TREE_CODE (dfn) == FUNCTION_DECL)
kono
parents:
diff changeset
498 fn = DECL_TEMPLATE_RESULT (fn);
kono
parents:
diff changeset
499 return fn;
kono
parents:
diff changeset
500 }
kono
parents:
diff changeset
501
kono
parents:
diff changeset
502 /* Find the binfo for the base subobject of BINFO being initialized by
kono
parents:
diff changeset
503 inherited constructor FNDECL (a member of a direct base of BINFO). */
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 static tree inherited_ctor_binfo (tree, tree);
kono
parents:
diff changeset
506 static tree
kono
parents:
diff changeset
507 inherited_ctor_binfo_1 (tree binfo, tree fndecl)
kono
parents:
diff changeset
508 {
kono
parents:
diff changeset
509 tree base = DECL_CONTEXT (fndecl);
kono
parents:
diff changeset
510 tree base_binfo;
kono
parents:
diff changeset
511 for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
512 if (BINFO_TYPE (base_binfo) == base)
kono
parents:
diff changeset
513 return inherited_ctor_binfo (base_binfo, fndecl);
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 gcc_unreachable();
kono
parents:
diff changeset
516 }
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 /* Find the binfo for the base subobject of BINFO being initialized by
kono
parents:
diff changeset
519 inheriting constructor FNDECL (a member of BINFO), or BINFO if FNDECL is not
kono
parents:
diff changeset
520 an inheriting constructor. */
kono
parents:
diff changeset
521
kono
parents:
diff changeset
522 static tree
kono
parents:
diff changeset
523 inherited_ctor_binfo (tree binfo, tree fndecl)
kono
parents:
diff changeset
524 {
kono
parents:
diff changeset
525 tree inh = DECL_INHERITED_CTOR (fndecl);
kono
parents:
diff changeset
526 if (!inh)
kono
parents:
diff changeset
527 return binfo;
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 tree results = NULL_TREE;
kono
parents:
diff changeset
530 for (ovl_iterator iter (inh); iter; ++iter)
kono
parents:
diff changeset
531 {
kono
parents:
diff changeset
532 tree one = inherited_ctor_binfo_1 (binfo, *iter);
kono
parents:
diff changeset
533 if (!results)
kono
parents:
diff changeset
534 results = one;
kono
parents:
diff changeset
535 else if (one != results)
kono
parents:
diff changeset
536 results = tree_cons (NULL_TREE, one, results);
kono
parents:
diff changeset
537 }
kono
parents:
diff changeset
538 return results;
kono
parents:
diff changeset
539 }
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 /* Find the binfo for the base subobject being initialized by inheriting
kono
parents:
diff changeset
542 constructor FNDECL, or NULL_TREE if FNDECL is not an inheriting
kono
parents:
diff changeset
543 constructor. */
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 tree
kono
parents:
diff changeset
546 inherited_ctor_binfo (tree fndecl)
kono
parents:
diff changeset
547 {
kono
parents:
diff changeset
548 if (!DECL_INHERITED_CTOR (fndecl))
kono
parents:
diff changeset
549 return NULL_TREE;
kono
parents:
diff changeset
550 tree binfo = TYPE_BINFO (DECL_CONTEXT (fndecl));
kono
parents:
diff changeset
551 return inherited_ctor_binfo (binfo, fndecl);
kono
parents:
diff changeset
552 }
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 /* True if we should omit all user-declared parameters from constructor FN,
kono
parents:
diff changeset
555 because it is a base clone of a ctor inherited from a virtual base. */
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 bool
kono
parents:
diff changeset
558 ctor_omit_inherited_parms (tree fn)
kono
parents:
diff changeset
559 {
kono
parents:
diff changeset
560 if (!flag_new_inheriting_ctors)
kono
parents:
diff changeset
561 /* We only optimize away the parameters in the new model. */
kono
parents:
diff changeset
562 return false;
kono
parents:
diff changeset
563 if (!DECL_BASE_CONSTRUCTOR_P (fn)
kono
parents:
diff changeset
564 || !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn)))
kono
parents:
diff changeset
565 return false;
kono
parents:
diff changeset
566 if (FUNCTION_FIRST_USER_PARMTYPE (DECL_ORIGIN (fn)) == void_list_node)
kono
parents:
diff changeset
567 /* No user-declared parameters to omit. */
kono
parents:
diff changeset
568 return false;
kono
parents:
diff changeset
569 tree binfo = inherited_ctor_binfo (fn);
kono
parents:
diff changeset
570 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
kono
parents:
diff changeset
571 if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
572 return true;
kono
parents:
diff changeset
573 return false;
kono
parents:
diff changeset
574 }
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 /* True iff constructor(s) INH inherited into BINFO initializes INIT_BINFO.
kono
parents:
diff changeset
577 This can be true for multiple virtual bases as well as one direct
kono
parents:
diff changeset
578 non-virtual base. */
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 static bool
kono
parents:
diff changeset
581 binfo_inherited_from (tree binfo, tree init_binfo, tree inh)
kono
parents:
diff changeset
582 {
kono
parents:
diff changeset
583 /* inh is an OVERLOAD if we inherited the same constructor along
kono
parents:
diff changeset
584 multiple paths, check all of them. */
kono
parents:
diff changeset
585 for (ovl_iterator iter (inh); iter; ++iter)
kono
parents:
diff changeset
586 {
kono
parents:
diff changeset
587 tree fn = *iter;
kono
parents:
diff changeset
588 tree base = DECL_CONTEXT (fn);
kono
parents:
diff changeset
589 tree base_binfo = NULL_TREE;
kono
parents:
diff changeset
590 for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
591 if (BINFO_TYPE (base_binfo) == base)
kono
parents:
diff changeset
592 break;
kono
parents:
diff changeset
593 if (base_binfo == init_binfo
kono
parents:
diff changeset
594 || (flag_new_inheriting_ctors
kono
parents:
diff changeset
595 && binfo_inherited_from (base_binfo, init_binfo,
kono
parents:
diff changeset
596 DECL_INHERITED_CTOR (fn))))
kono
parents:
diff changeset
597 return true;
kono
parents:
diff changeset
598 }
kono
parents:
diff changeset
599 return false;
kono
parents:
diff changeset
600 }
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 /* Subroutine of do_build_copy_constructor: Add a mem-initializer for BINFO
kono
parents:
diff changeset
603 given the parameter or parameters PARM, possibly inherited constructor
kono
parents:
diff changeset
604 base INH, or move flag MOVE_P. */
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 static tree
kono
parents:
diff changeset
607 add_one_base_init (tree binfo, tree parm, bool move_p, tree inh,
kono
parents:
diff changeset
608 tree member_init_list)
kono
parents:
diff changeset
609 {
kono
parents:
diff changeset
610 tree init;
kono
parents:
diff changeset
611 if (inh)
kono
parents:
diff changeset
612 {
kono
parents:
diff changeset
613 /* An inheriting constructor only has a mem-initializer for
kono
parents:
diff changeset
614 the base it inherits from. */
kono
parents:
diff changeset
615 if (!binfo_inherited_from (TYPE_BINFO (current_class_type), binfo, inh))
kono
parents:
diff changeset
616 return member_init_list;
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 tree *p = &init;
kono
parents:
diff changeset
619 init = NULL_TREE;
kono
parents:
diff changeset
620 for (; parm; parm = DECL_CHAIN (parm))
kono
parents:
diff changeset
621 {
kono
parents:
diff changeset
622 tree exp = forward_parm (parm);
kono
parents:
diff changeset
623 *p = build_tree_list (NULL_TREE, exp);
kono
parents:
diff changeset
624 p = &TREE_CHAIN (*p);
kono
parents:
diff changeset
625 }
kono
parents:
diff changeset
626 }
kono
parents:
diff changeset
627 else
kono
parents:
diff changeset
628 {
kono
parents:
diff changeset
629 init = build_base_path (PLUS_EXPR, parm, binfo, 1,
kono
parents:
diff changeset
630 tf_warning_or_error);
kono
parents:
diff changeset
631 if (move_p)
kono
parents:
diff changeset
632 init = move (init);
kono
parents:
diff changeset
633 init = build_tree_list (NULL_TREE, init);
kono
parents:
diff changeset
634 }
kono
parents:
diff changeset
635 return tree_cons (binfo, init, member_init_list);
kono
parents:
diff changeset
636 }
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 /* Generate code for default X(X&) or X(X&&) constructor or an inheriting
kono
parents:
diff changeset
639 constructor. */
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 static void
kono
parents:
diff changeset
642 do_build_copy_constructor (tree fndecl)
kono
parents:
diff changeset
643 {
kono
parents:
diff changeset
644 tree parm = FUNCTION_FIRST_USER_PARM (fndecl);
kono
parents:
diff changeset
645 bool move_p = DECL_MOVE_CONSTRUCTOR_P (fndecl);
kono
parents:
diff changeset
646 bool trivial = trivial_fn_p (fndecl);
kono
parents:
diff changeset
647 tree inh = DECL_INHERITED_CTOR (fndecl);
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 if (!inh)
kono
parents:
diff changeset
650 parm = convert_from_reference (parm);
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 if (trivial)
kono
parents:
diff changeset
653 {
kono
parents:
diff changeset
654 if (is_empty_class (current_class_type))
kono
parents:
diff changeset
655 /* Don't copy the padding byte; it might not have been allocated
kono
parents:
diff changeset
656 if *this is a base subobject. */;
kono
parents:
diff changeset
657 else if (tree_int_cst_equal (TYPE_SIZE (current_class_type),
kono
parents:
diff changeset
658 CLASSTYPE_SIZE (current_class_type)))
kono
parents:
diff changeset
659 {
kono
parents:
diff changeset
660 tree t = build2 (INIT_EXPR, void_type_node, current_class_ref, parm);
kono
parents:
diff changeset
661 finish_expr_stmt (t);
kono
parents:
diff changeset
662 }
kono
parents:
diff changeset
663 else
kono
parents:
diff changeset
664 {
kono
parents:
diff changeset
665 /* We must only copy the non-tail padding parts. */
kono
parents:
diff changeset
666 tree base_size = CLASSTYPE_SIZE_UNIT (current_class_type);
kono
parents:
diff changeset
667 base_size = size_binop (MINUS_EXPR, base_size, size_int (1));
kono
parents:
diff changeset
668 tree array_type = build_array_type (unsigned_char_type_node,
kono
parents:
diff changeset
669 build_index_type (base_size));
kono
parents:
diff changeset
670 tree alias_set = build_int_cst (TREE_TYPE (current_class_ptr), 0);
kono
parents:
diff changeset
671 tree lhs = build2 (MEM_REF, array_type,
kono
parents:
diff changeset
672 current_class_ptr, alias_set);
kono
parents:
diff changeset
673 tree rhs = build2 (MEM_REF, array_type,
kono
parents:
diff changeset
674 TREE_OPERAND (parm, 0), alias_set);
kono
parents:
diff changeset
675 tree t = build2 (INIT_EXPR, void_type_node, lhs, rhs);
kono
parents:
diff changeset
676 finish_expr_stmt (t);
kono
parents:
diff changeset
677 }
kono
parents:
diff changeset
678 }
kono
parents:
diff changeset
679 else
kono
parents:
diff changeset
680 {
kono
parents:
diff changeset
681 tree member_init_list = NULL_TREE;
kono
parents:
diff changeset
682 int i;
kono
parents:
diff changeset
683 tree binfo, base_binfo;
kono
parents:
diff changeset
684 vec<tree, va_gc> *vbases;
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 /* Initialize all the base-classes with the parameter converted
kono
parents:
diff changeset
687 to their type so that we get their copy constructor and not
kono
parents:
diff changeset
688 another constructor that takes current_class_type. We must
kono
parents:
diff changeset
689 deal with the binfo's directly as a direct base might be
kono
parents:
diff changeset
690 inaccessible due to ambiguity. */
kono
parents:
diff changeset
691 for (vbases = CLASSTYPE_VBASECLASSES (current_class_type), i = 0;
kono
parents:
diff changeset
692 vec_safe_iterate (vbases, i, &binfo); i++)
kono
parents:
diff changeset
693 {
kono
parents:
diff changeset
694 member_init_list = add_one_base_init (binfo, parm, move_p, inh,
kono
parents:
diff changeset
695 member_init_list);
kono
parents:
diff changeset
696 }
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 for (binfo = TYPE_BINFO (current_class_type), i = 0;
kono
parents:
diff changeset
699 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
700 {
kono
parents:
diff changeset
701 if (BINFO_VIRTUAL_P (base_binfo))
kono
parents:
diff changeset
702 continue;
kono
parents:
diff changeset
703 member_init_list = add_one_base_init (base_binfo, parm, move_p,
kono
parents:
diff changeset
704 inh, member_init_list);
kono
parents:
diff changeset
705 }
kono
parents:
diff changeset
706
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
707 if (!inh)
111
kono
parents:
diff changeset
708 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
709 int cvquals = cp_type_quals (TREE_TYPE (parm));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
710
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
711 for (tree fields = TYPE_FIELDS (current_class_type);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
712 fields; fields = DECL_CHAIN (fields))
111
kono
parents:
diff changeset
713 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
714 tree field = fields;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
715 tree expr_type;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
716
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
717 if (TREE_CODE (field) != FIELD_DECL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
718 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
719
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
720 expr_type = TREE_TYPE (field);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
721 if (DECL_NAME (field))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
722 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
723 if (VFIELD_NAME_P (DECL_NAME (field)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
724 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
725 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
726 else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
727 /* Just use the field; anonymous types can't have
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
728 nontrivial copy ctors or assignment ops or this
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
729 function would be deleted. */;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
730 else
111
kono
parents:
diff changeset
731 continue;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
732
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
733 /* Compute the type of "init->field". If the copy-constructor
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
734 parameter is, for example, "const S&", and the type of
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
735 the field is "T", then the type will usually be "const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
736 T". (There are no cv-qualified variants of reference
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
737 types.) */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
738 if (!TYPE_REF_P (expr_type))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
739 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
740 int quals = cvquals;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
741
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
742 if (DECL_MUTABLE_P (field))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
743 quals &= ~TYPE_QUAL_CONST;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
744 quals |= cp_type_quals (expr_type);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
745 expr_type = cp_build_qualified_type (expr_type, quals);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
746 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
747
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
748 tree init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
749 if (move_p && !TYPE_REF_P (expr_type)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
750 /* 'move' breaks bit-fields, and has no effect for scalars. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
751 && !scalarish_type_p (expr_type))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
752 init = move (init);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
753 init = build_tree_list (NULL_TREE, init);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
754
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
755 member_init_list = tree_cons (field, init, member_init_list);
111
kono
parents:
diff changeset
756 }
kono
parents:
diff changeset
757 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
758
111
kono
parents:
diff changeset
759 finish_mem_initializers (member_init_list);
kono
parents:
diff changeset
760 }
kono
parents:
diff changeset
761 }
kono
parents:
diff changeset
762
kono
parents:
diff changeset
763 static void
kono
parents:
diff changeset
764 do_build_copy_assign (tree fndecl)
kono
parents:
diff changeset
765 {
kono
parents:
diff changeset
766 tree parm = DECL_CHAIN (DECL_ARGUMENTS (fndecl));
kono
parents:
diff changeset
767 tree compound_stmt;
kono
parents:
diff changeset
768 bool move_p = move_fn_p (fndecl);
kono
parents:
diff changeset
769 bool trivial = trivial_fn_p (fndecl);
kono
parents:
diff changeset
770 int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
kono
parents:
diff changeset
771
kono
parents:
diff changeset
772 compound_stmt = begin_compound_stmt (0);
kono
parents:
diff changeset
773 parm = convert_from_reference (parm);
kono
parents:
diff changeset
774
kono
parents:
diff changeset
775 if (trivial
kono
parents:
diff changeset
776 && is_empty_class (current_class_type))
kono
parents:
diff changeset
777 /* Don't copy the padding byte; it might not have been allocated
kono
parents:
diff changeset
778 if *this is a base subobject. */;
kono
parents:
diff changeset
779 else if (trivial)
kono
parents:
diff changeset
780 {
kono
parents:
diff changeset
781 tree t = build2 (MODIFY_EXPR, void_type_node, current_class_ref, parm);
kono
parents:
diff changeset
782 finish_expr_stmt (t);
kono
parents:
diff changeset
783 }
kono
parents:
diff changeset
784 else
kono
parents:
diff changeset
785 {
kono
parents:
diff changeset
786 tree fields;
kono
parents:
diff changeset
787 int cvquals = cp_type_quals (TREE_TYPE (parm));
kono
parents:
diff changeset
788 int i;
kono
parents:
diff changeset
789 tree binfo, base_binfo;
kono
parents:
diff changeset
790
kono
parents:
diff changeset
791 /* Assign to each of the direct base classes. */
kono
parents:
diff changeset
792 for (binfo = TYPE_BINFO (current_class_type), i = 0;
kono
parents:
diff changeset
793 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
794 {
kono
parents:
diff changeset
795 tree converted_parm;
kono
parents:
diff changeset
796
kono
parents:
diff changeset
797 /* We must convert PARM directly to the base class
kono
parents:
diff changeset
798 explicitly since the base class may be ambiguous. */
kono
parents:
diff changeset
799 converted_parm = build_base_path (PLUS_EXPR, parm, base_binfo, 1,
kono
parents:
diff changeset
800 tf_warning_or_error);
kono
parents:
diff changeset
801 if (move_p)
kono
parents:
diff changeset
802 converted_parm = move (converted_parm);
kono
parents:
diff changeset
803 /* Call the base class assignment operator. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
804 releasing_vec parmvec (make_tree_vector_single (converted_parm));
111
kono
parents:
diff changeset
805 finish_expr_stmt
kono
parents:
diff changeset
806 (build_special_member_call (current_class_ref,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
807 assign_op_identifier,
111
kono
parents:
diff changeset
808 &parmvec,
kono
parents:
diff changeset
809 base_binfo,
kono
parents:
diff changeset
810 flags,
kono
parents:
diff changeset
811 tf_warning_or_error));
kono
parents:
diff changeset
812 }
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814 /* Assign to each of the non-static data members. */
kono
parents:
diff changeset
815 for (fields = TYPE_FIELDS (current_class_type);
kono
parents:
diff changeset
816 fields;
kono
parents:
diff changeset
817 fields = DECL_CHAIN (fields))
kono
parents:
diff changeset
818 {
kono
parents:
diff changeset
819 tree comp = current_class_ref;
kono
parents:
diff changeset
820 tree init = parm;
kono
parents:
diff changeset
821 tree field = fields;
kono
parents:
diff changeset
822 tree expr_type;
kono
parents:
diff changeset
823 int quals;
kono
parents:
diff changeset
824
kono
parents:
diff changeset
825 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
kono
parents:
diff changeset
826 continue;
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 expr_type = TREE_TYPE (field);
kono
parents:
diff changeset
829
kono
parents:
diff changeset
830 if (CP_TYPE_CONST_P (expr_type))
kono
parents:
diff changeset
831 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
832 error ("non-static const member %q#D, cannot use default "
111
kono
parents:
diff changeset
833 "assignment operator", field);
kono
parents:
diff changeset
834 continue;
kono
parents:
diff changeset
835 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
836 else if (TYPE_REF_P (expr_type))
111
kono
parents:
diff changeset
837 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
838 error ("non-static reference member %q#D, cannot use "
111
kono
parents:
diff changeset
839 "default assignment operator", field);
kono
parents:
diff changeset
840 continue;
kono
parents:
diff changeset
841 }
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 if (DECL_NAME (field))
kono
parents:
diff changeset
844 {
kono
parents:
diff changeset
845 if (VFIELD_NAME_P (DECL_NAME (field)))
kono
parents:
diff changeset
846 continue;
kono
parents:
diff changeset
847 }
kono
parents:
diff changeset
848 else if (ANON_AGGR_TYPE_P (expr_type)
kono
parents:
diff changeset
849 && TYPE_FIELDS (expr_type) != NULL_TREE)
kono
parents:
diff changeset
850 /* Just use the field; anonymous types can't have
kono
parents:
diff changeset
851 nontrivial copy ctors or assignment ops or this
kono
parents:
diff changeset
852 function would be deleted. */;
kono
parents:
diff changeset
853 else
kono
parents:
diff changeset
854 continue;
kono
parents:
diff changeset
855
kono
parents:
diff changeset
856 comp = build3 (COMPONENT_REF, expr_type, comp, field, NULL_TREE);
kono
parents:
diff changeset
857
kono
parents:
diff changeset
858 /* Compute the type of init->field */
kono
parents:
diff changeset
859 quals = cvquals;
kono
parents:
diff changeset
860 if (DECL_MUTABLE_P (field))
kono
parents:
diff changeset
861 quals &= ~TYPE_QUAL_CONST;
kono
parents:
diff changeset
862 expr_type = cp_build_qualified_type (expr_type, quals);
kono
parents:
diff changeset
863
kono
parents:
diff changeset
864 init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
865 if (move_p && !TYPE_REF_P (expr_type)
111
kono
parents:
diff changeset
866 /* 'move' breaks bit-fields, and has no effect for scalars. */
kono
parents:
diff changeset
867 && !scalarish_type_p (expr_type))
kono
parents:
diff changeset
868 init = move (init);
kono
parents:
diff changeset
869
kono
parents:
diff changeset
870 if (DECL_NAME (field))
kono
parents:
diff changeset
871 init = cp_build_modify_expr (input_location, comp, NOP_EXPR, init,
kono
parents:
diff changeset
872 tf_warning_or_error);
kono
parents:
diff changeset
873 else
kono
parents:
diff changeset
874 init = build2 (MODIFY_EXPR, TREE_TYPE (comp), comp, init);
kono
parents:
diff changeset
875 finish_expr_stmt (init);
kono
parents:
diff changeset
876 }
kono
parents:
diff changeset
877 }
kono
parents:
diff changeset
878 finish_return_stmt (current_class_ref);
kono
parents:
diff changeset
879 finish_compound_stmt (compound_stmt);
kono
parents:
diff changeset
880 }
kono
parents:
diff changeset
881
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
882 /* C++20 <compare> comparison category types. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
883
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
884 enum comp_cat_tag
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
885 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
886 cc_partial_ordering,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
887 cc_weak_ordering,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
888 cc_strong_ordering,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
889 cc_last
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
890 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
891
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
892 /* Names of the comparison categories and their value members, to be indexed by
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
893 comp_cat_tag enumerators. genericize_spaceship below relies on the ordering
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
894 of the members. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
895
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
896 struct comp_cat_info_t
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
897 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
898 const char *name;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
899 const char *members[4];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
900 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
901 static const comp_cat_info_t comp_cat_info[cc_last]
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
902 = {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
903 { "partial_ordering", "equivalent", "greater", "less", "unordered" },
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
904 { "weak_ordering", "equivalent", "greater", "less" },
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
905 { "strong_ordering", "equal", "greater", "less" }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
906 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
907
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
908 /* A cache of the category types to speed repeated lookups. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
909
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
910 static GTY((deletable)) tree comp_cat_cache[cc_last];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
911
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
912 /* Look up one of the result variables in the comparison category type. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
913
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
914 static tree
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
915 lookup_comparison_result (tree type, const char *name_str,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
916 tsubst_flags_t complain = tf_warning_or_error)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
917 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
918 tree name = get_identifier (name_str);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
919 tree decl = lookup_qualified_name (type, name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
920 if (TREE_CODE (decl) != VAR_DECL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
921 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
922 if (complain & tf_error)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
923 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
924 auto_diagnostic_group d;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
925 if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
926 qualified_name_lookup_error (type, name, decl, input_location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
927 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
928 error ("%qD is not a static data member", decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
929 inform (input_location, "determining value of %qs", "operator<=>");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
930 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
931 return error_mark_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
932 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
933 return decl;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
934 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
935
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
936 /* Look up a <compare> comparison category type in std. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
937
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
938 static tree
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
939 lookup_comparison_category (comp_cat_tag tag,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
940 tsubst_flags_t complain = tf_warning_or_error)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
941 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
942 if (tree cached = comp_cat_cache[tag])
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
943 return cached;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
944
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
945 tree name = get_identifier (comp_cat_info[tag].name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
946 tree decl = lookup_qualified_name (std_node, name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
947 if (TREE_CODE (decl) != TYPE_DECL)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
948 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
949 if (complain & tf_error)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
950 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
951 auto_diagnostic_group d;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
952 if (decl == error_mark_node || TREE_CODE (decl) == TREE_LIST)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
953 qualified_name_lookup_error (std_node, name, decl, input_location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
954 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
955 error ("%qD is not a type", decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
956 inform (input_location, "forming type of %qs", "operator<=>");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
957 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
958 return error_mark_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
959 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
960 /* Also make sure we can look up the value members now, since we won't
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
961 really use them until genericize time. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
962 tree type = TREE_TYPE (decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
963 for (int i = 0; i < 4; ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
964 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
965 const char *p = comp_cat_info[tag].members[i];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
966 if (!p) break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
967 if (lookup_comparison_result (type, p, complain)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
968 == error_mark_node)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
969 return error_mark_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
970 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
971 return comp_cat_cache[tag] = type;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
972 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
973
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
974 /* Wrapper that takes the tag rather than the type. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
975
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
976 static tree
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
977 lookup_comparison_result (comp_cat_tag tag, const char *name_str,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
978 tsubst_flags_t complain = tf_warning_or_error)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
979 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
980 tree type = lookup_comparison_category (tag, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
981 return lookup_comparison_result (type, name_str, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
982 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
983
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
984 /* Wrapper that takes the index into the members array instead of the name. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
985
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
986 static tree
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
987 lookup_comparison_result (comp_cat_tag tag, tree type, int idx)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
988 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
989 const char *name_str = comp_cat_info[tag].members[idx];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
990 if (!name_str)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
991 return NULL_TREE;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
992 return lookup_comparison_result (type, name_str);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
993 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
994
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
995 /* Does TYPE correspond to TAG? */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
996
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
997 static bool
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
998 is_cat (tree type, comp_cat_tag tag)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
999 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1000 tree name = TYPE_LINKAGE_IDENTIFIER (type);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1001 return id_equal (name, comp_cat_info[tag].name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1002 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1003
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1004 /* Return the comp_cat_tag for TYPE. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1005
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1006 static comp_cat_tag
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1007 cat_tag_for (tree type)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1008 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1009 for (int i = 0; i < cc_last; ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1010 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1011 comp_cat_tag tag = (comp_cat_tag)i;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1012 if (is_cat (type, tag))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1013 return tag;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1014 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1015 return cc_last;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1016 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1017
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1018 /* Return the comparison category tag of a <=> expression with non-class type
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1019 OPTYPE. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1020
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1021 static comp_cat_tag
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1022 spaceship_comp_cat (tree optype)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1023 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1024 if (INTEGRAL_OR_ENUMERATION_TYPE_P (optype) || TYPE_PTROBV_P (optype))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1025 return cc_strong_ordering;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1026 else if (TREE_CODE (optype) == REAL_TYPE)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1027 return cc_partial_ordering;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1028
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1029 /* ??? should vector <=> produce a vector of one of the above? */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1030 gcc_unreachable ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1031 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1032
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1033 /* Return the comparison category type of a <=> expression with non-class type
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1034 OPTYPE. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1035
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1036 tree
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1037 spaceship_type (tree optype, tsubst_flags_t complain)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1038 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1039 comp_cat_tag tag = spaceship_comp_cat (optype);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1040 return lookup_comparison_category (tag, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1041 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1042
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1043 /* Turn <=> with type TYPE and operands OP0 and OP1 into GENERIC. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1044
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1045 tree
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1046 genericize_spaceship (tree type, tree op0, tree op1)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1047 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1048 /* ??? maybe optimize based on knowledge of representation? */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1049 comp_cat_tag tag = cat_tag_for (type);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1050 gcc_checking_assert (tag < cc_last);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1051
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1052 tree r;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1053 op0 = save_expr (op0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1054 op1 = save_expr (op1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1055
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1056 tree gt = lookup_comparison_result (tag, type, 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1057
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1058 if (tag == cc_partial_ordering)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1059 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1060 /* op0 == op1 ? equivalent : op0 < op1 ? less :
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1061 op0 > op1 ? greater : unordered */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1062 tree uo = lookup_comparison_result (tag, type, 3);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1063 tree comp = fold_build2 (GT_EXPR, boolean_type_node, op0, op1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1064 r = fold_build3 (COND_EXPR, type, comp, gt, uo);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1065 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1066 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1067 /* op0 == op1 ? equal : op0 < op1 ? less : greater */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1068 r = gt;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1069
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1070 tree lt = lookup_comparison_result (tag, type, 2);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1071 tree comp = fold_build2 (LT_EXPR, boolean_type_node, op0, op1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1072 r = fold_build3 (COND_EXPR, type, comp, lt, r);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1073
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1074 tree eq = lookup_comparison_result (tag, type, 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1075 comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1076 r = fold_build3 (COND_EXPR, type, comp, eq, r);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1077
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1078 /* Wrap the whole thing in a TARGET_EXPR like build_conditional_expr_1. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1079 r = get_target_expr (r);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1080
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1081 return r;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1082 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1083
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1084 /* Check that the signature of a defaulted comparison operator is
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1085 well-formed. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1086
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1087 static bool
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1088 early_check_defaulted_comparison (tree fn)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1089 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1090 location_t loc = DECL_SOURCE_LOCATION (fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1091 tree ctx;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1092 if (DECL_CLASS_SCOPE_P (fn))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1093 ctx = DECL_CONTEXT (fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1094 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1095 ctx = DECL_FRIEND_CONTEXT (fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1096 bool ok = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1097
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1098 if (cxx_dialect < cxx2a)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1099 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1100 error_at (loc, "defaulted %qD only available with %<-std=c++2a%> or "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1101 "%<-std=gnu++2a%>", fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1102 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1103 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1104
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1105 if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1106 && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1107 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1108 diagnostic_t kind = DK_UNSPECIFIED;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1109 int opt = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1110 if (is_auto (TREE_TYPE (fn)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1111 kind = DK_PEDWARN;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1112 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1113 kind = DK_ERROR;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1114 emit_diagnostic (kind, loc, opt,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1115 "defaulted %qD must return %<bool%>", fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1116 if (kind == DK_ERROR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1117 ok = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1118 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1119
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1120 bool mem = DECL_NONSTATIC_MEMBER_FUNCTION_P (fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1121 if (mem && type_memfn_quals (TREE_TYPE (fn)) != TYPE_QUAL_CONST)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1122 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1123 error_at (loc, "defaulted %qD must be %<const%>", fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1124 ok = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1125 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1126 tree parmnode = FUNCTION_FIRST_USER_PARMTYPE (fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1127 bool saw_byval = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1128 bool saw_byref = mem;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1129 bool saw_bad = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1130 for (; parmnode != void_list_node; parmnode = TREE_CHAIN (parmnode))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1131 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1132 tree parmtype = TREE_VALUE (parmnode);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1133 if (same_type_p (parmtype, ctx))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1134 saw_byval = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1135 else if (TREE_CODE (parmtype) != REFERENCE_TYPE
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1136 || TYPE_QUALS (TREE_TYPE (parmtype)) != TYPE_QUAL_CONST
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1137 || !(same_type_ignoring_top_level_qualifiers_p
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1138 (TREE_TYPE (parmtype), ctx)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1139 saw_bad = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1140 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1141 saw_byref = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1142 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1143
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1144 if (saw_bad || (saw_byval && saw_byref))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1145 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1146 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1147 error_at (loc, "defaulted member %qD must have parameter type "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1148 "%<const %T&%>", fn, ctx);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1149 else if (saw_bad)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1150 error_at (loc, "defaulted %qD must have parameters of either type "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1151 "%<const %T&%> or %qT", fn, ctx, ctx);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1152 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1153 error_at (loc, "defaulted %qD must have parameters of either type "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1154 "%<const %T&%> or %qT, not both", fn, ctx, ctx);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1155 ok = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1156 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1157
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1158 /* We still need to deduce deleted/constexpr/noexcept and maybe return. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1159 DECL_MAYBE_DELETED (fn) = ok;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1160
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1161 return ok;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1162 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1163
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1164 /* Subroutine of build_comparison_op. Given the vec of memberwise
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1165 comparisons COMPS, calculate the overall comparison category for
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1166 operator<=>. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1167
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1168 static tree
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1169 common_comparison_type (vec<tree> &comps)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1170 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1171 tree seen[cc_last] = {};
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1172
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1173 for (unsigned i = 0; i < comps.length(); ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1174 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1175 tree comp = comps[i];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1176 tree ctype = TREE_TYPE (comp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1177 comp_cat_tag tag = cat_tag_for (ctype);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1178 if (tag < cc_last)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1179 seen[tag] = ctype;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1180 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1181 /* If any Ti is not a comparison category type, U is void. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1182 return void_type_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1183 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1184
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1185 /* Otherwise, if at least one T i is std::partial_ordering, U is
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1186 std::partial_ordering. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1187 if (tree t = seen[cc_partial_ordering]) return t;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1188
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1189 /* Otherwise, if at least one T i is std::weak_ordering, U is
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1190 std::weak_ordering. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1191 if (tree t = seen[cc_weak_ordering]) return t;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1192
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1193 /* Otherwise, U is std::strong_ordering. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1194 if (tree t = seen[cc_strong_ordering]) return t;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1195 return lookup_comparison_category (cc_strong_ordering);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1196 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1197
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1198 /* Data structure for build_comparison_op. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1199
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1200 struct comp_info
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1201 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1202 tree fndecl;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1203 location_t loc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1204 bool defining;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1205 bool first_time;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1206 bool constexp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1207 bool was_constexp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1208 bool noex;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1209
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1210 comp_info (tree fndecl, tsubst_flags_t &complain)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1211 : fndecl (fndecl)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1212 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1213 loc = DECL_SOURCE_LOCATION (fndecl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1214
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1215 /* We only have tf_error set when we're called from
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1216 explain_invalid_constexpr_fn or maybe_explain_implicit_delete. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1217 defining = !(complain & tf_error);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1218
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1219 first_time = DECL_MAYBE_DELETED (fndecl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1220 DECL_MAYBE_DELETED (fndecl) = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1221
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1222 /* Do we want to try to set constexpr? */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1223 was_constexp = DECL_DECLARED_CONSTEXPR_P (fndecl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1224 constexp = first_time;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1225 if (constexp)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1226 /* Set this for var_in_constexpr_fn. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1227 DECL_DECLARED_CONSTEXPR_P (fndecl) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1228
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1229 /* Do we want to try to set noexcept? */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1230 noex = first_time;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1231 if (noex)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1232 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1233 tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1234 if (raises && !UNEVALUATED_NOEXCEPT_SPEC_P (raises))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1235 /* There was an explicit exception-specification. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1236 noex = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1237 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1238 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1239
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1240 /* EXPR is an expression built as part of the function body.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1241 Adjust the properties appropriately. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1242 void check (tree expr)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1243 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1244 if (expr == error_mark_node)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1245 DECL_DELETED_FN (fndecl) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1246 if ((constexp || was_constexp)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1247 && !potential_rvalue_constant_expression (expr))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1248 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1249 if (was_constexp)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1250 require_potential_rvalue_constant_expression (expr);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1251 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1252 constexp = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1253 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1254 if (noex && !expr_noexcept_p (expr, tf_none))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1255 noex = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1256 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1257
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1258 ~comp_info ()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1259 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1260 if (first_time)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1261 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1262 DECL_DECLARED_CONSTEXPR_P (fndecl) = constexp || was_constexp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1263 tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fndecl));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1264 if (!raises || UNEVALUATED_NOEXCEPT_SPEC_P (raises))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1265 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1266 raises = noex ? noexcept_true_spec : noexcept_false_spec;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1267 TREE_TYPE (fndecl) = build_exception_variant (TREE_TYPE (fndecl),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1268 raises);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1269 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1270 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1271 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1272 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1273
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1274 /* Build up the definition of a defaulted comparison operator. Unlike other
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1275 defaulted functions that use synthesized_method_walk to determine whether
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1276 the function is e.g. deleted, for comparisons we use the same code. We try
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1277 to use synthesize_method at the earliest opportunity and bail out if the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1278 function ends up being deleted. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1279
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1280 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1281 build_comparison_op (tree fndecl, tsubst_flags_t complain)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1282 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1283 comp_info info (fndecl, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1284
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1285 if (!info.defining && !(complain & tf_error) && !DECL_MAYBE_DELETED (fndecl))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1286 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1287
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1288 int flags = LOOKUP_NORMAL | LOOKUP_NONVIRTUAL | LOOKUP_DEFAULTED;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1289 const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (DECL_NAME (fndecl));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1290 tree_code code = op->tree_code;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1291
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1292 tree lhs = DECL_ARGUMENTS (fndecl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1293 tree rhs = DECL_CHAIN (lhs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1294 if (is_this_parameter (lhs))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1295 lhs = cp_build_fold_indirect_ref (lhs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1296 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1297 lhs = convert_from_reference (lhs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1298 rhs = convert_from_reference (rhs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1299 tree ctype = TYPE_MAIN_VARIANT (TREE_TYPE (lhs));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1300
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1301 iloc_sentinel ils (info.loc);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1302
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1303 /* A defaulted comparison operator function for class C is defined as
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1304 deleted if ... C is a union-like class. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1305 if (TREE_CODE (ctype) == UNION_TYPE)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1306 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1307 if (complain & tf_error)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1308 inform (info.loc, "cannot default compare union %qT", ctype);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1309 DECL_DELETED_FN (fndecl) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1310 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1311 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1312
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1313 tree compound_stmt = NULL_TREE;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1314 if (info.defining)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1315 compound_stmt = begin_compound_stmt (0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1316 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1317 ++cp_unevaluated_operand;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1318
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1319 tree rettype = TREE_TYPE (TREE_TYPE (fndecl));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1320 if (code != SPACESHIP_EXPR && is_auto (rettype))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1321 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1322 rettype = boolean_type_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1323 apply_deduced_return_type (fndecl, rettype);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1324 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1325
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1326 if (code == EQ_EXPR || code == SPACESHIP_EXPR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1327 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1328 auto_vec<tree> comps;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1329
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1330 /* Compare each of the subobjects. Note that we get bases from
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1331 next_initializable_field because we're past C++17. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1332 for (tree field = next_initializable_field (TYPE_FIELDS (ctype));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1333 field;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1334 field = next_initializable_field (DECL_CHAIN (field)))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1335 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1336 tree expr_type = TREE_TYPE (field);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1337
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1338 /* A defaulted comparison operator function for class C is defined as
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1339 deleted if any non-static data member of C is of reference type or
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1340 C is a union-like class. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1341 if (TREE_CODE (expr_type) == REFERENCE_TYPE)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1342 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1343 if (complain & tf_error)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1344 inform (DECL_SOURCE_LOCATION (field), "cannot default compare "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1345 "reference member %qD", field);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1346 DECL_DELETED_FN (fndecl) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1347 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1348 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1349 else if (ANON_UNION_TYPE_P (expr_type))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1350 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1351 if (complain & tf_error)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1352 inform (DECL_SOURCE_LOCATION (field), "cannot default compare "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1353 "anonymous union member");
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1354 DECL_DELETED_FN (fndecl) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1355 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1356 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1357
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1358 tree lhs_mem = build3 (COMPONENT_REF, expr_type, lhs, field,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1359 NULL_TREE);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1360 tree rhs_mem = build3 (COMPONENT_REF, expr_type, rhs, field,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1361 NULL_TREE);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1362 tree comp = build_new_op (info.loc, code, flags, lhs_mem, rhs_mem,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1363 NULL_TREE, NULL, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1364 if (comp == error_mark_node)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1365 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1366 DECL_DELETED_FN (fndecl) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1367 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1368 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1369 comps.safe_push (comp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1370 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1371 if (code == SPACESHIP_EXPR && is_auto (rettype))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1372 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1373 rettype = common_comparison_type (comps);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1374 apply_deduced_return_type (fndecl, rettype);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1375 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1376 for (unsigned i = 0; i < comps.length(); ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1377 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1378 tree comp = comps[i];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1379 tree eq, retval = NULL_TREE, if_ = NULL_TREE;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1380 if (info.defining)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1381 if_ = begin_if_stmt ();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1382 /* Spaceship is specified to use !=, but for the comparison category
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1383 types, != is equivalent to !(==), so let's use == directly. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1384 if (code == EQ_EXPR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1385 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1386 /* if (x==y); else return false; */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1387 eq = comp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1388 retval = boolean_false_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1389 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1390 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1391 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1392 /* if (auto v = x<=>y, v == 0); else return v; */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1393 if (TREE_CODE (comp) == SPACESHIP_EXPR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1394 TREE_TYPE (comp) = rettype;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1395 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1396 comp = build_static_cast (input_location, rettype, comp,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1397 complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1398 info.check (comp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1399 if (info.defining)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1400 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1401 tree var = create_temporary_var (rettype);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1402 pushdecl (var);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1403 cp_finish_decl (var, comp, false, NULL_TREE, flags);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1404 comp = retval = var;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1405 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1406 eq = build_new_op (info.loc, EQ_EXPR, flags, comp,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1407 integer_zero_node, NULL_TREE, NULL,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1408 complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1409 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1410 tree ceq = contextual_conv_bool (eq, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1411 info.check (ceq);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1412 if (info.defining)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1413 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1414 finish_if_stmt_cond (ceq, if_);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1415 finish_then_clause (if_);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1416 begin_else_clause (if_);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1417 finish_return_stmt (retval);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1418 finish_else_clause (if_);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1419 finish_if_stmt (if_);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1420 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1421 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1422 if (info.defining)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1423 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1424 tree val;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1425 if (code == EQ_EXPR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1426 val = boolean_true_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1427 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1428 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1429 tree seql = lookup_comparison_result (cc_strong_ordering,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1430 "equal", complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1431 val = build_static_cast (input_location, rettype, seql,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1432 complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1433 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1434 finish_return_stmt (val);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1435 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1436 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1437 else if (code == NE_EXPR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1438 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1439 tree comp = build_new_op (info.loc, EQ_EXPR, flags, lhs, rhs,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1440 NULL_TREE, NULL, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1441 comp = contextual_conv_bool (comp, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1442 info.check (comp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1443 if (info.defining)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1444 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1445 tree neg = build1 (TRUTH_NOT_EXPR, boolean_type_node, comp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1446 finish_return_stmt (neg);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1447 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1448 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1449 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1450 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1451 tree comp = build_new_op (info.loc, SPACESHIP_EXPR, flags, lhs, rhs,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1452 NULL_TREE, NULL, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1453 tree comp2 = build_new_op (info.loc, code, flags, comp, integer_zero_node,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1454 NULL_TREE, NULL, complain);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1455 info.check (comp2);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1456 if (info.defining)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1457 finish_return_stmt (comp2);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1458 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1459
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1460 if (info.defining)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1461 finish_compound_stmt (compound_stmt);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1462 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1463 --cp_unevaluated_operand;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1464 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1465
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1466 /* True iff DECL is an implicitly-declared special member function with no real
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1467 source location, so we can use its DECL_SOURCE_LOCATION to remember where we
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1468 triggered its synthesis. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1469
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1470 bool
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1471 decl_remember_implicit_trigger_p (tree decl)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1472 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1473 if (!DECL_ARTIFICIAL (decl))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1474 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1475 special_function_kind sfk = special_function_p (decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1476 /* Inherited constructors have the location of their using-declaration, and
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1477 operator== has the location of the corresponding operator<=>. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1478 return (sfk != sfk_inheriting_constructor
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1479 && sfk != sfk_comparison);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1480 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1481
111
kono
parents:
diff changeset
1482 /* Synthesize FNDECL, a non-static member function. */
kono
parents:
diff changeset
1483
kono
parents:
diff changeset
1484 void
kono
parents:
diff changeset
1485 synthesize_method (tree fndecl)
kono
parents:
diff changeset
1486 {
kono
parents:
diff changeset
1487 bool nested = (current_function_decl != NULL_TREE);
kono
parents:
diff changeset
1488 tree context = decl_function_context (fndecl);
kono
parents:
diff changeset
1489 bool need_body = true;
kono
parents:
diff changeset
1490 tree stmt;
kono
parents:
diff changeset
1491 location_t save_input_location = input_location;
kono
parents:
diff changeset
1492 int error_count = errorcount;
kono
parents:
diff changeset
1493 int warning_count = warningcount + werrorcount;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1494 special_function_kind sfk = special_function_p (fndecl);
111
kono
parents:
diff changeset
1495
kono
parents:
diff changeset
1496 /* Reset the source location, we might have been previously
kono
parents:
diff changeset
1497 deferred, and thus have saved where we were first needed. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1498 if (decl_remember_implicit_trigger_p (fndecl))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1499 DECL_SOURCE_LOCATION (fndecl)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1500 = DECL_SOURCE_LOCATION (TYPE_NAME (DECL_CONTEXT (fndecl)));
111
kono
parents:
diff changeset
1501
kono
parents:
diff changeset
1502 /* If we've been asked to synthesize a clone, just synthesize the
kono
parents:
diff changeset
1503 cloned function instead. Doing so will automatically fill in the
kono
parents:
diff changeset
1504 body for the clone. */
kono
parents:
diff changeset
1505 if (DECL_CLONED_FUNCTION_P (fndecl))
kono
parents:
diff changeset
1506 fndecl = DECL_CLONED_FUNCTION (fndecl);
kono
parents:
diff changeset
1507
kono
parents:
diff changeset
1508 /* We may be in the middle of deferred access check. Disable
kono
parents:
diff changeset
1509 it now. */
kono
parents:
diff changeset
1510 push_deferring_access_checks (dk_no_deferred);
kono
parents:
diff changeset
1511
kono
parents:
diff changeset
1512 if (! context)
kono
parents:
diff changeset
1513 push_to_top_level ();
kono
parents:
diff changeset
1514 else if (nested)
kono
parents:
diff changeset
1515 push_function_context ();
kono
parents:
diff changeset
1516
kono
parents:
diff changeset
1517 input_location = DECL_SOURCE_LOCATION (fndecl);
kono
parents:
diff changeset
1518
kono
parents:
diff changeset
1519 start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
kono
parents:
diff changeset
1520 stmt = begin_function_body ();
kono
parents:
diff changeset
1521
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1522 if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1523 && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
111
kono
parents:
diff changeset
1524 {
kono
parents:
diff changeset
1525 do_build_copy_assign (fndecl);
kono
parents:
diff changeset
1526 need_body = false;
kono
parents:
diff changeset
1527 }
kono
parents:
diff changeset
1528 else if (DECL_CONSTRUCTOR_P (fndecl))
kono
parents:
diff changeset
1529 {
kono
parents:
diff changeset
1530 tree arg_chain = FUNCTION_FIRST_USER_PARMTYPE (fndecl);
kono
parents:
diff changeset
1531 if (arg_chain != void_list_node)
kono
parents:
diff changeset
1532 do_build_copy_constructor (fndecl);
kono
parents:
diff changeset
1533 else
kono
parents:
diff changeset
1534 finish_mem_initializers (NULL_TREE);
kono
parents:
diff changeset
1535 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1536 else if (sfk == sfk_comparison)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1537 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1538 /* Pass tf_none so the function is just deleted if there's a problem. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1539 build_comparison_op (fndecl, tf_none);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1540 need_body = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1541 }
111
kono
parents:
diff changeset
1542
kono
parents:
diff changeset
1543 /* If we haven't yet generated the body of the function, just
kono
parents:
diff changeset
1544 generate an empty compound statement. */
kono
parents:
diff changeset
1545 if (need_body)
kono
parents:
diff changeset
1546 {
kono
parents:
diff changeset
1547 tree compound_stmt;
kono
parents:
diff changeset
1548 compound_stmt = begin_compound_stmt (BCS_FN_BODY);
kono
parents:
diff changeset
1549 finish_compound_stmt (compound_stmt);
kono
parents:
diff changeset
1550 }
kono
parents:
diff changeset
1551
kono
parents:
diff changeset
1552 finish_function_body (stmt);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1553 finish_function (/*inline_p=*/false);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1554
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1555 if (!DECL_DELETED_FN (fndecl))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1556 expand_or_defer_fn (fndecl);
111
kono
parents:
diff changeset
1557
kono
parents:
diff changeset
1558 input_location = save_input_location;
kono
parents:
diff changeset
1559
kono
parents:
diff changeset
1560 if (! context)
kono
parents:
diff changeset
1561 pop_from_top_level ();
kono
parents:
diff changeset
1562 else if (nested)
kono
parents:
diff changeset
1563 pop_function_context ();
kono
parents:
diff changeset
1564
kono
parents:
diff changeset
1565 pop_deferring_access_checks ();
kono
parents:
diff changeset
1566
kono
parents:
diff changeset
1567 if (error_count != errorcount || warning_count != warningcount + werrorcount)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1568 if (DECL_ARTIFICIAL (fndecl))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1569 inform (input_location, "synthesized method %qD first required here",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1570 fndecl);
111
kono
parents:
diff changeset
1571 }
kono
parents:
diff changeset
1572
kono
parents:
diff changeset
1573 /* Build a reference to type TYPE with cv-quals QUALS, which is an
kono
parents:
diff changeset
1574 rvalue if RVALUE is true. */
kono
parents:
diff changeset
1575
kono
parents:
diff changeset
1576 static tree
kono
parents:
diff changeset
1577 build_stub_type (tree type, int quals, bool rvalue)
kono
parents:
diff changeset
1578 {
kono
parents:
diff changeset
1579 tree argtype = cp_build_qualified_type (type, quals);
kono
parents:
diff changeset
1580 return cp_build_reference_type (argtype, rvalue);
kono
parents:
diff changeset
1581 }
kono
parents:
diff changeset
1582
kono
parents:
diff changeset
1583 /* Build a dummy glvalue from dereferencing a dummy reference of type
kono
parents:
diff changeset
1584 REFTYPE. */
kono
parents:
diff changeset
1585
kono
parents:
diff changeset
1586 static tree
kono
parents:
diff changeset
1587 build_stub_object (tree reftype)
kono
parents:
diff changeset
1588 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1589 if (!TYPE_REF_P (reftype))
111
kono
parents:
diff changeset
1590 reftype = cp_build_reference_type (reftype, /*rval*/true);
kono
parents:
diff changeset
1591 tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
kono
parents:
diff changeset
1592 return convert_from_reference (stub);
kono
parents:
diff changeset
1593 }
kono
parents:
diff changeset
1594
kono
parents:
diff changeset
1595 /* Determine which function will be called when looking up NAME in TYPE,
kono
parents:
diff changeset
1596 called with a single ARGTYPE argument, or no argument if ARGTYPE is
kono
parents:
diff changeset
1597 null. FLAGS and COMPLAIN are as for build_new_method_call.
kono
parents:
diff changeset
1598
kono
parents:
diff changeset
1599 Returns a FUNCTION_DECL if all is well.
kono
parents:
diff changeset
1600 Returns NULL_TREE if overload resolution failed.
kono
parents:
diff changeset
1601 Returns error_mark_node if the chosen function cannot be called. */
kono
parents:
diff changeset
1602
kono
parents:
diff changeset
1603 static tree
kono
parents:
diff changeset
1604 locate_fn_flags (tree type, tree name, tree argtype, int flags,
kono
parents:
diff changeset
1605 tsubst_flags_t complain)
kono
parents:
diff changeset
1606 {
kono
parents:
diff changeset
1607 tree ob, fn, fns, binfo, rval;
kono
parents:
diff changeset
1608
kono
parents:
diff changeset
1609 if (TYPE_P (type))
kono
parents:
diff changeset
1610 binfo = TYPE_BINFO (type);
kono
parents:
diff changeset
1611 else
kono
parents:
diff changeset
1612 {
kono
parents:
diff changeset
1613 binfo = type;
kono
parents:
diff changeset
1614 type = BINFO_TYPE (binfo);
kono
parents:
diff changeset
1615 }
kono
parents:
diff changeset
1616
kono
parents:
diff changeset
1617 ob = build_stub_object (cp_build_reference_type (type, false));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1618 releasing_vec args;
111
kono
parents:
diff changeset
1619 if (argtype)
kono
parents:
diff changeset
1620 {
kono
parents:
diff changeset
1621 if (TREE_CODE (argtype) == TREE_LIST)
kono
parents:
diff changeset
1622 {
kono
parents:
diff changeset
1623 for (tree elt = argtype; elt && elt != void_list_node;
kono
parents:
diff changeset
1624 elt = TREE_CHAIN (elt))
kono
parents:
diff changeset
1625 {
kono
parents:
diff changeset
1626 tree type = TREE_VALUE (elt);
kono
parents:
diff changeset
1627 tree arg = build_stub_object (type);
kono
parents:
diff changeset
1628 vec_safe_push (args, arg);
kono
parents:
diff changeset
1629 }
kono
parents:
diff changeset
1630 }
kono
parents:
diff changeset
1631 else
kono
parents:
diff changeset
1632 {
kono
parents:
diff changeset
1633 tree arg = build_stub_object (argtype);
kono
parents:
diff changeset
1634 args->quick_push (arg);
kono
parents:
diff changeset
1635 }
kono
parents:
diff changeset
1636 }
kono
parents:
diff changeset
1637
kono
parents:
diff changeset
1638 fns = lookup_fnfields (binfo, name, 0);
kono
parents:
diff changeset
1639 rval = build_new_method_call (ob, fns, &args, binfo, flags, &fn, complain);
kono
parents:
diff changeset
1640
kono
parents:
diff changeset
1641 if (fn && rval == error_mark_node)
kono
parents:
diff changeset
1642 return rval;
kono
parents:
diff changeset
1643 else
kono
parents:
diff changeset
1644 return fn;
kono
parents:
diff changeset
1645 }
kono
parents:
diff changeset
1646
kono
parents:
diff changeset
1647 /* Locate the dtor of TYPE. */
kono
parents:
diff changeset
1648
kono
parents:
diff changeset
1649 tree
kono
parents:
diff changeset
1650 get_dtor (tree type, tsubst_flags_t complain)
kono
parents:
diff changeset
1651 {
kono
parents:
diff changeset
1652 tree fn = locate_fn_flags (type, complete_dtor_identifier, NULL_TREE,
kono
parents:
diff changeset
1653 LOOKUP_NORMAL, complain);
kono
parents:
diff changeset
1654 if (fn == error_mark_node)
kono
parents:
diff changeset
1655 return NULL_TREE;
kono
parents:
diff changeset
1656 return fn;
kono
parents:
diff changeset
1657 }
kono
parents:
diff changeset
1658
kono
parents:
diff changeset
1659 /* Locate the default ctor of TYPE. */
kono
parents:
diff changeset
1660
kono
parents:
diff changeset
1661 tree
kono
parents:
diff changeset
1662 locate_ctor (tree type)
kono
parents:
diff changeset
1663 {
kono
parents:
diff changeset
1664 tree fn;
kono
parents:
diff changeset
1665
kono
parents:
diff changeset
1666 push_deferring_access_checks (dk_no_check);
kono
parents:
diff changeset
1667 fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
kono
parents:
diff changeset
1668 LOOKUP_SPECULATIVE, tf_none);
kono
parents:
diff changeset
1669 pop_deferring_access_checks ();
kono
parents:
diff changeset
1670 if (fn == error_mark_node)
kono
parents:
diff changeset
1671 return NULL_TREE;
kono
parents:
diff changeset
1672 return fn;
kono
parents:
diff changeset
1673 }
kono
parents:
diff changeset
1674
kono
parents:
diff changeset
1675 /* Likewise, but give any appropriate errors. */
kono
parents:
diff changeset
1676
kono
parents:
diff changeset
1677 tree
kono
parents:
diff changeset
1678 get_default_ctor (tree type)
kono
parents:
diff changeset
1679 {
kono
parents:
diff changeset
1680 tree fn = locate_fn_flags (type, complete_ctor_identifier, NULL_TREE,
kono
parents:
diff changeset
1681 LOOKUP_NORMAL, tf_warning_or_error);
kono
parents:
diff changeset
1682 if (fn == error_mark_node)
kono
parents:
diff changeset
1683 return NULL_TREE;
kono
parents:
diff changeset
1684 return fn;
kono
parents:
diff changeset
1685 }
kono
parents:
diff changeset
1686
kono
parents:
diff changeset
1687 /* Locate the copy ctor of TYPE. */
kono
parents:
diff changeset
1688
kono
parents:
diff changeset
1689 tree
kono
parents:
diff changeset
1690 get_copy_ctor (tree type, tsubst_flags_t complain)
kono
parents:
diff changeset
1691 {
kono
parents:
diff changeset
1692 int quals = (TYPE_HAS_CONST_COPY_CTOR (type)
kono
parents:
diff changeset
1693 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
kono
parents:
diff changeset
1694 tree argtype = build_stub_type (type, quals, false);
kono
parents:
diff changeset
1695 tree fn = locate_fn_flags (type, complete_ctor_identifier, argtype,
kono
parents:
diff changeset
1696 LOOKUP_NORMAL, complain);
kono
parents:
diff changeset
1697 if (fn == error_mark_node)
kono
parents:
diff changeset
1698 return NULL_TREE;
kono
parents:
diff changeset
1699 return fn;
kono
parents:
diff changeset
1700 }
kono
parents:
diff changeset
1701
kono
parents:
diff changeset
1702 /* Locate the copy assignment operator of TYPE. */
kono
parents:
diff changeset
1703
kono
parents:
diff changeset
1704 tree
kono
parents:
diff changeset
1705 get_copy_assign (tree type)
kono
parents:
diff changeset
1706 {
kono
parents:
diff changeset
1707 int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
kono
parents:
diff changeset
1708 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
kono
parents:
diff changeset
1709 tree argtype = build_stub_type (type, quals, false);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1710 tree fn = locate_fn_flags (type, assign_op_identifier, argtype,
111
kono
parents:
diff changeset
1711 LOOKUP_NORMAL, tf_warning_or_error);
kono
parents:
diff changeset
1712 if (fn == error_mark_node)
kono
parents:
diff changeset
1713 return NULL_TREE;
kono
parents:
diff changeset
1714 return fn;
kono
parents:
diff changeset
1715 }
kono
parents:
diff changeset
1716
kono
parents:
diff changeset
1717 /* walk_tree helper function for is_trivially_xible. If *TP is a call,
kono
parents:
diff changeset
1718 return it if it calls something other than a trivial special member
kono
parents:
diff changeset
1719 function. */
kono
parents:
diff changeset
1720
kono
parents:
diff changeset
1721 static tree
kono
parents:
diff changeset
1722 check_nontriv (tree *tp, int *, void *)
kono
parents:
diff changeset
1723 {
kono
parents:
diff changeset
1724 tree fn = cp_get_callee (*tp);
kono
parents:
diff changeset
1725 if (fn == NULL_TREE)
kono
parents:
diff changeset
1726 return NULL_TREE;
kono
parents:
diff changeset
1727
kono
parents:
diff changeset
1728 if (TREE_CODE (fn) == ADDR_EXPR)
kono
parents:
diff changeset
1729 fn = TREE_OPERAND (fn, 0);
kono
parents:
diff changeset
1730
kono
parents:
diff changeset
1731 if (TREE_CODE (fn) != FUNCTION_DECL
kono
parents:
diff changeset
1732 || !trivial_fn_p (fn))
kono
parents:
diff changeset
1733 return fn;
kono
parents:
diff changeset
1734 return NULL_TREE;
kono
parents:
diff changeset
1735 }
kono
parents:
diff changeset
1736
kono
parents:
diff changeset
1737 /* Return declval<T>() = declval<U>() treated as an unevaluated operand. */
kono
parents:
diff changeset
1738
kono
parents:
diff changeset
1739 static tree
kono
parents:
diff changeset
1740 assignable_expr (tree to, tree from)
kono
parents:
diff changeset
1741 {
kono
parents:
diff changeset
1742 ++cp_unevaluated_operand;
kono
parents:
diff changeset
1743 to = build_stub_object (to);
kono
parents:
diff changeset
1744 from = build_stub_object (from);
kono
parents:
diff changeset
1745 tree r = cp_build_modify_expr (input_location, to, NOP_EXPR, from, tf_none);
kono
parents:
diff changeset
1746 --cp_unevaluated_operand;
kono
parents:
diff changeset
1747 return r;
kono
parents:
diff changeset
1748 }
kono
parents:
diff changeset
1749
kono
parents:
diff changeset
1750 /* The predicate condition for a template specialization
kono
parents:
diff changeset
1751 is_constructible<T, Args...> shall be satisfied if and only if the
kono
parents:
diff changeset
1752 following variable definition would be well-formed for some invented
kono
parents:
diff changeset
1753 variable t: T t(create<Args>()...);
kono
parents:
diff changeset
1754
kono
parents:
diff changeset
1755 Return something equivalent in well-formedness and triviality. */
kono
parents:
diff changeset
1756
kono
parents:
diff changeset
1757 static tree
kono
parents:
diff changeset
1758 constructible_expr (tree to, tree from)
kono
parents:
diff changeset
1759 {
kono
parents:
diff changeset
1760 tree expr;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1761 cp_unevaluated cp_uneval_guard;
111
kono
parents:
diff changeset
1762 if (CLASS_TYPE_P (to))
kono
parents:
diff changeset
1763 {
kono
parents:
diff changeset
1764 tree ctype = to;
kono
parents:
diff changeset
1765 vec<tree, va_gc> *args = NULL;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1766 if (!TYPE_REF_P (to))
111
kono
parents:
diff changeset
1767 to = cp_build_reference_type (to, /*rval*/false);
kono
parents:
diff changeset
1768 tree ob = build_stub_object (to);
kono
parents:
diff changeset
1769 for (; from; from = TREE_CHAIN (from))
kono
parents:
diff changeset
1770 vec_safe_push (args, build_stub_object (TREE_VALUE (from)));
kono
parents:
diff changeset
1771 expr = build_special_member_call (ob, complete_ctor_identifier, &args,
kono
parents:
diff changeset
1772 ctype, LOOKUP_NORMAL, tf_none);
kono
parents:
diff changeset
1773 if (expr == error_mark_node)
kono
parents:
diff changeset
1774 return error_mark_node;
kono
parents:
diff changeset
1775 /* The current state of the standard vis-a-vis LWG 2116 is that
kono
parents:
diff changeset
1776 is_*constructible involves destruction as well. */
kono
parents:
diff changeset
1777 if (type_build_dtor_call (ctype))
kono
parents:
diff changeset
1778 {
kono
parents:
diff changeset
1779 tree dtor = build_special_member_call (ob, complete_dtor_identifier,
kono
parents:
diff changeset
1780 NULL, ctype, LOOKUP_NORMAL,
kono
parents:
diff changeset
1781 tf_none);
kono
parents:
diff changeset
1782 if (dtor == error_mark_node)
kono
parents:
diff changeset
1783 return error_mark_node;
kono
parents:
diff changeset
1784 if (!TYPE_HAS_TRIVIAL_DESTRUCTOR (ctype))
kono
parents:
diff changeset
1785 expr = build2 (COMPOUND_EXPR, void_type_node, expr, dtor);
kono
parents:
diff changeset
1786 }
kono
parents:
diff changeset
1787 }
kono
parents:
diff changeset
1788 else
kono
parents:
diff changeset
1789 {
kono
parents:
diff changeset
1790 if (from == NULL_TREE)
kono
parents:
diff changeset
1791 return build_value_init (strip_array_types (to), tf_none);
kono
parents:
diff changeset
1792 else if (TREE_CHAIN (from))
kono
parents:
diff changeset
1793 return error_mark_node; // too many initializers
kono
parents:
diff changeset
1794 from = build_stub_object (TREE_VALUE (from));
kono
parents:
diff changeset
1795 expr = perform_direct_initialization_if_possible (to, from,
kono
parents:
diff changeset
1796 /*cast*/false,
kono
parents:
diff changeset
1797 tf_none);
kono
parents:
diff changeset
1798 }
kono
parents:
diff changeset
1799 return expr;
kono
parents:
diff changeset
1800 }
kono
parents:
diff changeset
1801
kono
parents:
diff changeset
1802 /* Returns a tree iff TO is assignable (if CODE is MODIFY_EXPR) or
kono
parents:
diff changeset
1803 constructible (otherwise) from FROM, which is a single type for
kono
parents:
diff changeset
1804 assignment or a list of types for construction. */
kono
parents:
diff changeset
1805
kono
parents:
diff changeset
1806 static tree
kono
parents:
diff changeset
1807 is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
kono
parents:
diff changeset
1808 {
kono
parents:
diff changeset
1809 if (VOID_TYPE_P (to) || ABSTRACT_CLASS_TYPE_P (to)
kono
parents:
diff changeset
1810 || (from && FUNC_OR_METHOD_TYPE_P (from)
kono
parents:
diff changeset
1811 && (TYPE_READONLY (from) || FUNCTION_REF_QUALIFIED (from))))
kono
parents:
diff changeset
1812 return error_mark_node;
kono
parents:
diff changeset
1813 tree expr;
kono
parents:
diff changeset
1814 if (code == MODIFY_EXPR)
kono
parents:
diff changeset
1815 expr = assignable_expr (to, from);
kono
parents:
diff changeset
1816 else if (trivial && from && TREE_CHAIN (from))
kono
parents:
diff changeset
1817 return error_mark_node; // only 0- and 1-argument ctors can be trivial
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1818 else if (TREE_CODE (to) == ARRAY_TYPE && !TYPE_DOMAIN (to))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1819 return error_mark_node; // can't construct an array of unknown bound
111
kono
parents:
diff changeset
1820 else
kono
parents:
diff changeset
1821 expr = constructible_expr (to, from);
kono
parents:
diff changeset
1822 return expr;
kono
parents:
diff changeset
1823 }
kono
parents:
diff changeset
1824
kono
parents:
diff changeset
1825 /* Returns true iff TO is trivially assignable (if CODE is MODIFY_EXPR) or
kono
parents:
diff changeset
1826 constructible (otherwise) from FROM, which is a single type for
kono
parents:
diff changeset
1827 assignment or a list of types for construction. */
kono
parents:
diff changeset
1828
kono
parents:
diff changeset
1829 bool
kono
parents:
diff changeset
1830 is_trivially_xible (enum tree_code code, tree to, tree from)
kono
parents:
diff changeset
1831 {
kono
parents:
diff changeset
1832 tree expr;
kono
parents:
diff changeset
1833 expr = is_xible_helper (code, to, from, /*trivial*/true);
kono
parents:
diff changeset
1834
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1835 if (expr == NULL_TREE || expr == error_mark_node)
111
kono
parents:
diff changeset
1836 return false;
kono
parents:
diff changeset
1837 tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
kono
parents:
diff changeset
1838 return !nt;
kono
parents:
diff changeset
1839 }
kono
parents:
diff changeset
1840
kono
parents:
diff changeset
1841 /* Returns true iff TO is assignable (if CODE is MODIFY_EXPR) or
kono
parents:
diff changeset
1842 constructible (otherwise) from FROM, which is a single type for
kono
parents:
diff changeset
1843 assignment or a list of types for construction. */
kono
parents:
diff changeset
1844
kono
parents:
diff changeset
1845 bool
kono
parents:
diff changeset
1846 is_xible (enum tree_code code, tree to, tree from)
kono
parents:
diff changeset
1847 {
kono
parents:
diff changeset
1848 tree expr = is_xible_helper (code, to, from, /*trivial*/false);
kono
parents:
diff changeset
1849 if (expr == error_mark_node)
kono
parents:
diff changeset
1850 return false;
kono
parents:
diff changeset
1851 return !!expr;
kono
parents:
diff changeset
1852 }
kono
parents:
diff changeset
1853
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1854 /* Categorize various special_function_kinds. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1855 #define SFK_CTOR_P(sfk) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1856 ((sfk) >= sfk_constructor && (sfk) <= sfk_move_constructor)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1857 #define SFK_DTOR_P(sfk) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1858 ((sfk) == sfk_destructor || (sfk) == sfk_virtual_destructor)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1859 #define SFK_ASSIGN_P(sfk) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1860 ((sfk) == sfk_copy_assignment || (sfk) == sfk_move_assignment)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1861 #define SFK_COPY_P(sfk) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1862 ((sfk) == sfk_copy_constructor || (sfk) == sfk_copy_assignment)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1863 #define SFK_MOVE_P(sfk) \
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1864 ((sfk) == sfk_move_constructor || (sfk) == sfk_move_assignment)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1865
111
kono
parents:
diff changeset
1866 /* Subroutine of synthesized_method_walk. Update SPEC_P, TRIVIAL_P and
kono
parents:
diff changeset
1867 DELETED_P or give an error message MSG with argument ARG. */
kono
parents:
diff changeset
1868
kono
parents:
diff changeset
1869 static void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1870 process_subob_fn (tree fn, special_function_kind sfk, tree *spec_p,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1871 bool *trivial_p, bool *deleted_p, bool *constexpr_p,
111
kono
parents:
diff changeset
1872 bool diag, tree arg, bool dtor_from_ctor = false)
kono
parents:
diff changeset
1873 {
kono
parents:
diff changeset
1874 if (!fn || fn == error_mark_node)
kono
parents:
diff changeset
1875 {
kono
parents:
diff changeset
1876 if (deleted_p)
kono
parents:
diff changeset
1877 *deleted_p = true;
kono
parents:
diff changeset
1878 return;
kono
parents:
diff changeset
1879 }
kono
parents:
diff changeset
1880
kono
parents:
diff changeset
1881 if (spec_p)
kono
parents:
diff changeset
1882 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1883 if (!maybe_instantiate_noexcept (fn))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1884 *spec_p = error_mark_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1885 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1886 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1887 tree raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1888 *spec_p = merge_exception_specifiers (*spec_p, raises);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1889 }
111
kono
parents:
diff changeset
1890 }
kono
parents:
diff changeset
1891
kono
parents:
diff changeset
1892 if (!trivial_fn_p (fn) && !dtor_from_ctor)
kono
parents:
diff changeset
1893 {
kono
parents:
diff changeset
1894 if (trivial_p)
kono
parents:
diff changeset
1895 *trivial_p = false;
kono
parents:
diff changeset
1896 if (TREE_CODE (arg) == FIELD_DECL
kono
parents:
diff changeset
1897 && TREE_CODE (DECL_CONTEXT (arg)) == UNION_TYPE)
kono
parents:
diff changeset
1898 {
kono
parents:
diff changeset
1899 if (deleted_p)
kono
parents:
diff changeset
1900 *deleted_p = true;
kono
parents:
diff changeset
1901 if (diag)
kono
parents:
diff changeset
1902 error ("union member %q+D with non-trivial %qD", arg, fn);
kono
parents:
diff changeset
1903 }
kono
parents:
diff changeset
1904 }
kono
parents:
diff changeset
1905
kono
parents:
diff changeset
1906 if (constexpr_p && !DECL_DECLARED_CONSTEXPR_P (fn))
kono
parents:
diff changeset
1907 {
kono
parents:
diff changeset
1908 *constexpr_p = false;
kono
parents:
diff changeset
1909 if (diag)
kono
parents:
diff changeset
1910 {
kono
parents:
diff changeset
1911 inform (DECL_SOURCE_LOCATION (fn),
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1912 SFK_DTOR_P (sfk)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1913 ? G_("defaulted destructor calls non-%<constexpr%> %qD")
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1914 : G_("defaulted constructor calls non-%<constexpr%> %qD"),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1915 fn);
111
kono
parents:
diff changeset
1916 explain_invalid_constexpr_fn (fn);
kono
parents:
diff changeset
1917 }
kono
parents:
diff changeset
1918 }
kono
parents:
diff changeset
1919 }
kono
parents:
diff changeset
1920
kono
parents:
diff changeset
1921 /* Subroutine of synthesized_method_walk to allow recursion into anonymous
kono
parents:
diff changeset
1922 aggregates. If DTOR_FROM_CTOR is true, we're walking subobject destructors
kono
parents:
diff changeset
1923 called from a synthesized constructor, in which case we don't consider
kono
parents:
diff changeset
1924 the triviality of the subobject destructor. */
kono
parents:
diff changeset
1925
kono
parents:
diff changeset
1926 static void
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1927 walk_field_subobs (tree fields, special_function_kind sfk, tree fnname,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1928 int quals, tree *spec_p, bool *trivial_p,
111
kono
parents:
diff changeset
1929 bool *deleted_p, bool *constexpr_p,
kono
parents:
diff changeset
1930 bool diag, int flags, tsubst_flags_t complain,
kono
parents:
diff changeset
1931 bool dtor_from_ctor)
kono
parents:
diff changeset
1932 {
kono
parents:
diff changeset
1933 tree field;
kono
parents:
diff changeset
1934 for (field = fields; field; field = DECL_CHAIN (field))
kono
parents:
diff changeset
1935 {
kono
parents:
diff changeset
1936 tree mem_type, argtype, rval;
kono
parents:
diff changeset
1937
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1938 if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
111
kono
parents:
diff changeset
1939 continue;
kono
parents:
diff changeset
1940
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1941 /* Variant members only affect deletedness. In particular, they don't
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1942 affect the exception-specification of a user-provided destructor,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1943 which we're figuring out via get_defaulted_eh_spec. So if we aren't
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1944 asking if this is deleted, don't even look up the function; we don't
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1945 want an error about a deleted function we aren't actually calling. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1946 if (sfk == sfk_destructor && deleted_p == NULL
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1947 && TREE_CODE (DECL_CONTEXT (field)) == UNION_TYPE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1948 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1949
111
kono
parents:
diff changeset
1950 mem_type = strip_array_types (TREE_TYPE (field));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1951 if (SFK_ASSIGN_P (sfk))
111
kono
parents:
diff changeset
1952 {
kono
parents:
diff changeset
1953 bool bad = true;
kono
parents:
diff changeset
1954 if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
kono
parents:
diff changeset
1955 {
kono
parents:
diff changeset
1956 if (diag)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1957 error ("non-static const member %q#D, cannot use default "
111
kono
parents:
diff changeset
1958 "assignment operator", field);
kono
parents:
diff changeset
1959 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1960 else if (TYPE_REF_P (mem_type))
111
kono
parents:
diff changeset
1961 {
kono
parents:
diff changeset
1962 if (diag)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1963 error ("non-static reference member %q#D, cannot use "
111
kono
parents:
diff changeset
1964 "default assignment operator", field);
kono
parents:
diff changeset
1965 }
kono
parents:
diff changeset
1966 else
kono
parents:
diff changeset
1967 bad = false;
kono
parents:
diff changeset
1968
kono
parents:
diff changeset
1969 if (bad && deleted_p)
kono
parents:
diff changeset
1970 *deleted_p = true;
kono
parents:
diff changeset
1971 }
kono
parents:
diff changeset
1972 else if (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)
kono
parents:
diff changeset
1973 {
kono
parents:
diff changeset
1974 bool bad;
kono
parents:
diff changeset
1975
kono
parents:
diff changeset
1976 if (DECL_INITIAL (field))
kono
parents:
diff changeset
1977 {
kono
parents:
diff changeset
1978 if (diag && DECL_INITIAL (field) == error_mark_node)
kono
parents:
diff changeset
1979 inform (DECL_SOURCE_LOCATION (field),
kono
parents:
diff changeset
1980 "initializer for %q#D is invalid", field);
kono
parents:
diff changeset
1981 if (trivial_p)
kono
parents:
diff changeset
1982 *trivial_p = false;
kono
parents:
diff changeset
1983 /* Core 1351: If the field has an NSDMI that could throw, the
kono
parents:
diff changeset
1984 default constructor is noexcept(false). */
kono
parents:
diff changeset
1985 if (spec_p)
kono
parents:
diff changeset
1986 {
kono
parents:
diff changeset
1987 tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1988 if (nsdmi == error_mark_node)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1989 *spec_p = error_mark_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1990 else if (*spec_p != error_mark_node
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1991 && !expr_noexcept_p (nsdmi, complain))
111
kono
parents:
diff changeset
1992 *spec_p = noexcept_false_spec;
kono
parents:
diff changeset
1993 }
kono
parents:
diff changeset
1994 /* Don't do the normal processing. */
kono
parents:
diff changeset
1995 continue;
kono
parents:
diff changeset
1996 }
kono
parents:
diff changeset
1997
kono
parents:
diff changeset
1998 bad = false;
kono
parents:
diff changeset
1999 if (CP_TYPE_CONST_P (mem_type)
kono
parents:
diff changeset
2000 && default_init_uninitialized_part (mem_type))
kono
parents:
diff changeset
2001 {
kono
parents:
diff changeset
2002 if (diag)
kono
parents:
diff changeset
2003 {
kono
parents:
diff changeset
2004 error ("uninitialized const member in %q#T",
kono
parents:
diff changeset
2005 current_class_type);
kono
parents:
diff changeset
2006 inform (DECL_SOURCE_LOCATION (field),
kono
parents:
diff changeset
2007 "%q#D should be initialized", field);
kono
parents:
diff changeset
2008 }
kono
parents:
diff changeset
2009 bad = true;
kono
parents:
diff changeset
2010 }
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2011 else if (TYPE_REF_P (mem_type))
111
kono
parents:
diff changeset
2012 {
kono
parents:
diff changeset
2013 if (diag)
kono
parents:
diff changeset
2014 {
kono
parents:
diff changeset
2015 error ("uninitialized reference member in %q#T",
kono
parents:
diff changeset
2016 current_class_type);
kono
parents:
diff changeset
2017 inform (DECL_SOURCE_LOCATION (field),
kono
parents:
diff changeset
2018 "%q#D should be initialized", field);
kono
parents:
diff changeset
2019 }
kono
parents:
diff changeset
2020 bad = true;
kono
parents:
diff changeset
2021 }
kono
parents:
diff changeset
2022
kono
parents:
diff changeset
2023 if (bad && deleted_p)
kono
parents:
diff changeset
2024 *deleted_p = true;
kono
parents:
diff changeset
2025
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2026 /* Before C++20, for an implicitly-defined default constructor to
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2027 be constexpr, every member must have a user-provided default
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2028 constructor or an explicit initializer. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2029 if (constexpr_p
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2030 && cxx_dialect < cxx2a
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2031 && !CLASS_TYPE_P (mem_type)
111
kono
parents:
diff changeset
2032 && TREE_CODE (DECL_CONTEXT (field)) != UNION_TYPE)
kono
parents:
diff changeset
2033 {
kono
parents:
diff changeset
2034 *constexpr_p = false;
kono
parents:
diff changeset
2035 if (diag)
kono
parents:
diff changeset
2036 inform (DECL_SOURCE_LOCATION (field),
kono
parents:
diff changeset
2037 "defaulted default constructor does not "
kono
parents:
diff changeset
2038 "initialize %q#D", field);
kono
parents:
diff changeset
2039 }
kono
parents:
diff changeset
2040 }
kono
parents:
diff changeset
2041 else if (sfk == sfk_copy_constructor)
kono
parents:
diff changeset
2042 {
kono
parents:
diff changeset
2043 /* 12.8p11b5 */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2044 if (TYPE_REF_P (mem_type)
111
kono
parents:
diff changeset
2045 && TYPE_REF_IS_RVALUE (mem_type))
kono
parents:
diff changeset
2046 {
kono
parents:
diff changeset
2047 if (diag)
kono
parents:
diff changeset
2048 error ("copying non-static data member %q#D of rvalue "
kono
parents:
diff changeset
2049 "reference type", field);
kono
parents:
diff changeset
2050 if (deleted_p)
kono
parents:
diff changeset
2051 *deleted_p = true;
kono
parents:
diff changeset
2052 }
kono
parents:
diff changeset
2053 }
kono
parents:
diff changeset
2054
kono
parents:
diff changeset
2055 if (!CLASS_TYPE_P (mem_type))
kono
parents:
diff changeset
2056 continue;
kono
parents:
diff changeset
2057
kono
parents:
diff changeset
2058 if (ANON_AGGR_TYPE_P (mem_type))
kono
parents:
diff changeset
2059 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2060 walk_field_subobs (TYPE_FIELDS (mem_type), sfk, fnname, quals,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2061 spec_p, trivial_p, deleted_p, constexpr_p,
111
kono
parents:
diff changeset
2062 diag, flags, complain, dtor_from_ctor);
kono
parents:
diff changeset
2063 continue;
kono
parents:
diff changeset
2064 }
kono
parents:
diff changeset
2065
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2066 if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
111
kono
parents:
diff changeset
2067 {
kono
parents:
diff changeset
2068 int mem_quals = cp_type_quals (mem_type) | quals;
kono
parents:
diff changeset
2069 if (DECL_MUTABLE_P (field))
kono
parents:
diff changeset
2070 mem_quals &= ~TYPE_QUAL_CONST;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2071 argtype = build_stub_type (mem_type, mem_quals, SFK_MOVE_P (sfk));
111
kono
parents:
diff changeset
2072 }
kono
parents:
diff changeset
2073 else
kono
parents:
diff changeset
2074 argtype = NULL_TREE;
kono
parents:
diff changeset
2075
kono
parents:
diff changeset
2076 rval = locate_fn_flags (mem_type, fnname, argtype, flags, complain);
kono
parents:
diff changeset
2077
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2078 process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
111
kono
parents:
diff changeset
2079 constexpr_p, diag, field, dtor_from_ctor);
kono
parents:
diff changeset
2080 }
kono
parents:
diff changeset
2081 }
kono
parents:
diff changeset
2082
kono
parents:
diff changeset
2083 /* Base walker helper for synthesized_method_walk. Inspect a direct
kono
parents:
diff changeset
2084 or virtual base. BINFO is the parent type's binfo. BASE_BINFO is
kono
parents:
diff changeset
2085 the base binfo of interests. All other parms are as for
kono
parents:
diff changeset
2086 synthesized_method_walk, or its local vars. */
kono
parents:
diff changeset
2087
kono
parents:
diff changeset
2088 static tree
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2089 synthesized_method_base_walk (tree binfo, tree base_binfo,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2090 special_function_kind sfk, tree fnname, int quals,
111
kono
parents:
diff changeset
2091 tree *inheriting_ctor, tree inherited_parms,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2092 int flags, bool diag,
111
kono
parents:
diff changeset
2093 tree *spec_p, bool *trivial_p,
kono
parents:
diff changeset
2094 bool *deleted_p, bool *constexpr_p)
kono
parents:
diff changeset
2095 {
kono
parents:
diff changeset
2096 bool inherited_binfo = false;
kono
parents:
diff changeset
2097 tree argtype = NULL_TREE;
kono
parents:
diff changeset
2098 deferring_kind defer = dk_no_deferred;
kono
parents:
diff changeset
2099
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2100 if (SFK_COPY_P (sfk) || SFK_MOVE_P (sfk))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2101 argtype = build_stub_type (BINFO_TYPE (base_binfo), quals, SFK_MOVE_P (sfk));
111
kono
parents:
diff changeset
2102 else if (inheriting_ctor
kono
parents:
diff changeset
2103 && (inherited_binfo
kono
parents:
diff changeset
2104 = binfo_inherited_from (binfo, base_binfo, *inheriting_ctor)))
kono
parents:
diff changeset
2105 {
kono
parents:
diff changeset
2106 argtype = inherited_parms;
kono
parents:
diff changeset
2107 /* Don't check access on the inherited constructor. */
kono
parents:
diff changeset
2108 if (flag_new_inheriting_ctors)
kono
parents:
diff changeset
2109 defer = dk_deferred;
kono
parents:
diff changeset
2110 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2111 else if (cxx_dialect >= cxx14 && sfk == sfk_virtual_destructor
111
kono
parents:
diff changeset
2112 && BINFO_VIRTUAL_P (base_binfo)
kono
parents:
diff changeset
2113 && ABSTRACT_CLASS_TYPE_P (BINFO_TYPE (binfo)))
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2114 /* Don't check access when looking at vbases of abstract class's
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2115 virtual destructor. */
111
kono
parents:
diff changeset
2116 defer = dk_no_check;
kono
parents:
diff changeset
2117
kono
parents:
diff changeset
2118 if (defer != dk_no_deferred)
kono
parents:
diff changeset
2119 push_deferring_access_checks (defer);
kono
parents:
diff changeset
2120 tree rval = locate_fn_flags (base_binfo, fnname, argtype, flags,
kono
parents:
diff changeset
2121 diag ? tf_warning_or_error : tf_none);
kono
parents:
diff changeset
2122 if (defer != dk_no_deferred)
kono
parents:
diff changeset
2123 pop_deferring_access_checks ();
kono
parents:
diff changeset
2124
kono
parents:
diff changeset
2125 /* Replace an inherited template with the appropriate specialization. */
kono
parents:
diff changeset
2126 if (inherited_binfo && rval
kono
parents:
diff changeset
2127 && DECL_P (*inheriting_ctor) && DECL_P (rval)
kono
parents:
diff changeset
2128 && DECL_CONTEXT (*inheriting_ctor) == DECL_CONTEXT (rval))
kono
parents:
diff changeset
2129 *inheriting_ctor = DECL_CLONED_FUNCTION (rval);
kono
parents:
diff changeset
2130
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2131 process_subob_fn (rval, sfk, spec_p, trivial_p, deleted_p,
111
kono
parents:
diff changeset
2132 constexpr_p, diag, BINFO_TYPE (base_binfo));
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2133 if (SFK_CTOR_P (sfk)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2134 && (!BINFO_VIRTUAL_P (base_binfo)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2135 || TYPE_HAS_NONTRIVIAL_DESTRUCTOR (BINFO_TYPE (base_binfo))))
111
kono
parents:
diff changeset
2136 {
kono
parents:
diff changeset
2137 /* In a constructor we also need to check the subobject
kono
parents:
diff changeset
2138 destructors for cleanup of partially constructed objects. */
kono
parents:
diff changeset
2139 tree dtor = locate_fn_flags (base_binfo, complete_dtor_identifier,
kono
parents:
diff changeset
2140 NULL_TREE, flags,
kono
parents:
diff changeset
2141 diag ? tf_warning_or_error : tf_none);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2142 /* Note that we don't pass down trivial_p; the subobject
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2143 destructors don't affect triviality of the constructor. Nor
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2144 do they affect constexpr-ness (a constant expression doesn't
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2145 throw) or exception-specification (a throw from one of the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2146 dtors would be a double-fault). */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2147 process_subob_fn (dtor, sfk, NULL, NULL, deleted_p, NULL, false,
111
kono
parents:
diff changeset
2148 BINFO_TYPE (base_binfo), /*dtor_from_ctor*/true);
kono
parents:
diff changeset
2149 }
kono
parents:
diff changeset
2150
kono
parents:
diff changeset
2151 return rval;
kono
parents:
diff changeset
2152 }
kono
parents:
diff changeset
2153
kono
parents:
diff changeset
2154 /* The caller wants to generate an implicit declaration of SFK for
kono
parents:
diff changeset
2155 CTYPE which is const if relevant and CONST_P is set. If SPEC_P,
kono
parents:
diff changeset
2156 TRIVIAL_P, DELETED_P or CONSTEXPR_P are non-null, set their
kono
parents:
diff changeset
2157 referent appropriately. If DIAG is true, we're either being called
kono
parents:
diff changeset
2158 from maybe_explain_implicit_delete to give errors, or if
kono
parents:
diff changeset
2159 CONSTEXPR_P is non-null, from explain_invalid_constexpr_fn. */
kono
parents:
diff changeset
2160
kono
parents:
diff changeset
2161 static void
kono
parents:
diff changeset
2162 synthesized_method_walk (tree ctype, special_function_kind sfk, bool const_p,
kono
parents:
diff changeset
2163 tree *spec_p, bool *trivial_p, bool *deleted_p,
kono
parents:
diff changeset
2164 bool *constexpr_p, bool diag,
kono
parents:
diff changeset
2165 tree *inheriting_ctor, tree inherited_parms)
kono
parents:
diff changeset
2166 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2167 tree binfo, base_binfo;
111
kono
parents:
diff changeset
2168 int i;
kono
parents:
diff changeset
2169
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2170 /* SFK must be exactly one category. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2171 gcc_checking_assert (SFK_DTOR_P(sfk) + SFK_CTOR_P(sfk)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2172 + SFK_ASSIGN_P(sfk) == 1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2173
111
kono
parents:
diff changeset
2174 if (spec_p)
kono
parents:
diff changeset
2175 *spec_p = (cxx_dialect >= cxx11 ? noexcept_true_spec : empty_except_spec);
kono
parents:
diff changeset
2176
kono
parents:
diff changeset
2177 if (deleted_p)
kono
parents:
diff changeset
2178 {
kono
parents:
diff changeset
2179 /* "The closure type associated with a lambda-expression has a deleted
kono
parents:
diff changeset
2180 default constructor and a deleted copy assignment operator."
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2181 This is diagnosed in maybe_explain_implicit_delete.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2182 In C++2a, only lambda-expressions with lambda-captures have those
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2183 deleted. */
111
kono
parents:
diff changeset
2184 if (LAMBDA_TYPE_P (ctype)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2185 && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2186 && (cxx_dialect < cxx2a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2187 || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2188 || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2189 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
111
kono
parents:
diff changeset
2190 {
kono
parents:
diff changeset
2191 *deleted_p = true;
kono
parents:
diff changeset
2192 return;
kono
parents:
diff changeset
2193 }
kono
parents:
diff changeset
2194
kono
parents:
diff changeset
2195 *deleted_p = false;
kono
parents:
diff changeset
2196 }
kono
parents:
diff changeset
2197
kono
parents:
diff changeset
2198 bool check_vdtor = false;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2199 tree fnname;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2200
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2201 if (SFK_DTOR_P (sfk))
111
kono
parents:
diff changeset
2202 {
kono
parents:
diff changeset
2203 check_vdtor = true;
kono
parents:
diff changeset
2204 /* The synthesized method will call base dtors, but check complete
kono
parents:
diff changeset
2205 here to avoid having to deal with VTT. */
kono
parents:
diff changeset
2206 fnname = complete_dtor_identifier;
kono
parents:
diff changeset
2207 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2208 else if (SFK_ASSIGN_P (sfk))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2209 fnname = assign_op_identifier;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2210 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2211 fnname = complete_ctor_identifier;
111
kono
parents:
diff changeset
2212
kono
parents:
diff changeset
2213 gcc_assert ((sfk == sfk_inheriting_constructor)
kono
parents:
diff changeset
2214 == (inheriting_ctor && *inheriting_ctor != NULL_TREE));
kono
parents:
diff changeset
2215
kono
parents:
diff changeset
2216 /* If that user-written default constructor would satisfy the
kono
parents:
diff changeset
2217 requirements of a constexpr constructor (7.1.5), the
kono
parents:
diff changeset
2218 implicitly-defined default constructor is constexpr.
kono
parents:
diff changeset
2219
kono
parents:
diff changeset
2220 The implicitly-defined copy/move assignment operator is constexpr if
kono
parents:
diff changeset
2221 - X is a literal type, and
kono
parents:
diff changeset
2222 - the assignment operator selected to copy/move each direct base class
kono
parents:
diff changeset
2223 subobject is a constexpr function, and
kono
parents:
diff changeset
2224 - for each non-static data member of X that is of class type (or array
kono
parents:
diff changeset
2225 thereof), the assignment operator selected to copy/move that
kono
parents:
diff changeset
2226 member is a constexpr function. */
kono
parents:
diff changeset
2227 if (constexpr_p)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2228 *constexpr_p = (SFK_CTOR_P (sfk)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2229 || (SFK_ASSIGN_P (sfk) && cxx_dialect >= cxx14)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2230 || (SFK_DTOR_P (sfk) && cxx_dialect >= cxx2a));
111
kono
parents:
diff changeset
2231
kono
parents:
diff changeset
2232 bool expected_trivial = type_has_trivial_fn (ctype, sfk);
kono
parents:
diff changeset
2233 if (trivial_p)
kono
parents:
diff changeset
2234 *trivial_p = expected_trivial;
kono
parents:
diff changeset
2235
kono
parents:
diff changeset
2236 /* The TYPE_HAS_COMPLEX_* flags tell us about constraints from base
kono
parents:
diff changeset
2237 class versions and other properties of the type. But a subobject
kono
parents:
diff changeset
2238 class can be trivially copyable and yet have overload resolution
kono
parents:
diff changeset
2239 choose a template constructor for initialization, depending on
kono
parents:
diff changeset
2240 rvalueness and cv-quals. And furthermore, a member in a base might
kono
parents:
diff changeset
2241 be trivial but deleted or otherwise not callable. So we can't exit
kono
parents:
diff changeset
2242 early in C++0x. The same considerations apply in C++98/03, but
kono
parents:
diff changeset
2243 there the definition of triviality does not consider overload
kono
parents:
diff changeset
2244 resolution, so a constructor can be trivial even if it would otherwise
kono
parents:
diff changeset
2245 call a non-trivial constructor. */
kono
parents:
diff changeset
2246 if (expected_trivial
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2247 && (!(SFK_COPY_P (sfk) || SFK_MOVE_P (sfk)) || cxx_dialect < cxx11))
111
kono
parents:
diff changeset
2248 {
kono
parents:
diff changeset
2249 if (constexpr_p && sfk == sfk_constructor)
kono
parents:
diff changeset
2250 {
kono
parents:
diff changeset
2251 bool cx = trivial_default_constructor_is_constexpr (ctype);
kono
parents:
diff changeset
2252 *constexpr_p = cx;
kono
parents:
diff changeset
2253 if (diag && !cx && TREE_CODE (ctype) == UNION_TYPE)
kono
parents:
diff changeset
2254 /* A trivial constructor doesn't have any NSDMI. */
kono
parents:
diff changeset
2255 inform (input_location, "defaulted default constructor does "
kono
parents:
diff changeset
2256 "not initialize any non-static data member");
kono
parents:
diff changeset
2257 }
kono
parents:
diff changeset
2258 if (!diag && cxx_dialect < cxx11)
kono
parents:
diff changeset
2259 return;
kono
parents:
diff changeset
2260 }
kono
parents:
diff changeset
2261
kono
parents:
diff changeset
2262 ++cp_unevaluated_operand;
kono
parents:
diff changeset
2263 ++c_inhibit_evaluation_warnings;
kono
parents:
diff changeset
2264 push_deferring_access_checks (dk_no_deferred);
kono
parents:
diff changeset
2265
kono
parents:
diff changeset
2266 tree scope = push_scope (ctype);
kono
parents:
diff changeset
2267
kono
parents:
diff changeset
2268 int flags = LOOKUP_NORMAL | LOOKUP_SPECULATIVE;
kono
parents:
diff changeset
2269 if (sfk != sfk_inheriting_constructor)
kono
parents:
diff changeset
2270 flags |= LOOKUP_DEFAULTED;
kono
parents:
diff changeset
2271
kono
parents:
diff changeset
2272 tsubst_flags_t complain = diag ? tf_warning_or_error : tf_none;
kono
parents:
diff changeset
2273 if (diag && spec_p)
kono
parents:
diff changeset
2274 /* We're in get_defaulted_eh_spec; we don't actually want any walking
kono
parents:
diff changeset
2275 diagnostics, we just want complain set. */
kono
parents:
diff changeset
2276 diag = false;
kono
parents:
diff changeset
2277 int quals = const_p ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED;
kono
parents:
diff changeset
2278
kono
parents:
diff changeset
2279 for (binfo = TYPE_BINFO (ctype), i = 0;
kono
parents:
diff changeset
2280 BINFO_BASE_ITERATE (binfo, i, base_binfo); ++i)
kono
parents:
diff changeset
2281 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2282 if (!SFK_ASSIGN_P (sfk) && BINFO_VIRTUAL_P (base_binfo))
111
kono
parents:
diff changeset
2283 /* We'll handle virtual bases below. */
kono
parents:
diff changeset
2284 continue;
kono
parents:
diff changeset
2285
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2286 tree fn = synthesized_method_base_walk (binfo, base_binfo,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2287 sfk, fnname, quals,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2288 inheriting_ctor, inherited_parms,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2289 flags, diag, spec_p, trivial_p,
111
kono
parents:
diff changeset
2290 deleted_p, constexpr_p);
kono
parents:
diff changeset
2291
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2292 if (diag && SFK_ASSIGN_P (sfk) && SFK_MOVE_P (sfk)
111
kono
parents:
diff changeset
2293 && BINFO_VIRTUAL_P (base_binfo)
kono
parents:
diff changeset
2294 && fn && TREE_CODE (fn) == FUNCTION_DECL
kono
parents:
diff changeset
2295 && move_fn_p (fn) && !trivial_fn_p (fn)
kono
parents:
diff changeset
2296 && vbase_has_user_provided_move_assign (BINFO_TYPE (base_binfo)))
kono
parents:
diff changeset
2297 warning (OPT_Wvirtual_move_assign,
kono
parents:
diff changeset
2298 "defaulted move assignment for %qT calls a non-trivial "
kono
parents:
diff changeset
2299 "move assignment operator for virtual base %qT",
kono
parents:
diff changeset
2300 ctype, BINFO_TYPE (base_binfo));
kono
parents:
diff changeset
2301
kono
parents:
diff changeset
2302 if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
kono
parents:
diff changeset
2303 {
kono
parents:
diff changeset
2304 /* Unlike for base ctor/op=/dtor, for operator delete it's fine
kono
parents:
diff changeset
2305 to have a null fn (no class-specific op delete). */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2306 fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
111
kono
parents:
diff changeset
2307 ptr_type_node, flags, tf_none);
kono
parents:
diff changeset
2308 if (fn && fn == error_mark_node)
kono
parents:
diff changeset
2309 {
kono
parents:
diff changeset
2310 if (complain & tf_error)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2311 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
111
kono
parents:
diff changeset
2312 ptr_type_node, flags, complain);
kono
parents:
diff changeset
2313 if (deleted_p)
kono
parents:
diff changeset
2314 *deleted_p = true;
kono
parents:
diff changeset
2315 }
kono
parents:
diff changeset
2316 check_vdtor = false;
kono
parents:
diff changeset
2317 }
kono
parents:
diff changeset
2318 }
kono
parents:
diff changeset
2319
kono
parents:
diff changeset
2320 vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (ctype);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2321 if (SFK_ASSIGN_P (sfk))
111
kono
parents:
diff changeset
2322 /* Already examined vbases above. */;
kono
parents:
diff changeset
2323 else if (vec_safe_is_empty (vbases))
kono
parents:
diff changeset
2324 /* No virtual bases to worry about. */;
kono
parents:
diff changeset
2325 else if (ABSTRACT_CLASS_TYPE_P (ctype) && cxx_dialect >= cxx14
kono
parents:
diff changeset
2326 /* DR 1658 specifies that vbases of abstract classes are
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2327 ignored for both ctors and dtors. Except DR 2336
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2328 overrides that skipping when determing the eh-spec of a
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2329 virtual destructor. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2330 && sfk != sfk_virtual_destructor)
111
kono
parents:
diff changeset
2331 /* Vbase cdtors are not relevant. */;
kono
parents:
diff changeset
2332 else
kono
parents:
diff changeset
2333 {
kono
parents:
diff changeset
2334 if (constexpr_p)
kono
parents:
diff changeset
2335 *constexpr_p = false;
kono
parents:
diff changeset
2336
kono
parents:
diff changeset
2337 FOR_EACH_VEC_ELT (*vbases, i, base_binfo)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2338 synthesized_method_base_walk (binfo, base_binfo, sfk, fnname, quals,
111
kono
parents:
diff changeset
2339 inheriting_ctor, inherited_parms,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2340 flags, diag,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2341 spec_p, trivial_p, deleted_p, constexpr_p);
111
kono
parents:
diff changeset
2342 }
kono
parents:
diff changeset
2343
kono
parents:
diff changeset
2344 /* Now handle the non-static data members. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2345 walk_field_subobs (TYPE_FIELDS (ctype), sfk, fnname, quals,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2346 spec_p, trivial_p, deleted_p, constexpr_p,
111
kono
parents:
diff changeset
2347 diag, flags, complain, /*dtor_from_ctor*/false);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2348 if (SFK_CTOR_P (sfk))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2349 walk_field_subobs (TYPE_FIELDS (ctype), sfk_destructor,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2350 complete_dtor_identifier, TYPE_UNQUALIFIED,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2351 NULL, NULL, deleted_p, NULL,
111
kono
parents:
diff changeset
2352 false, flags, complain, /*dtor_from_ctor*/true);
kono
parents:
diff changeset
2353
kono
parents:
diff changeset
2354 pop_scope (scope);
kono
parents:
diff changeset
2355
kono
parents:
diff changeset
2356 pop_deferring_access_checks ();
kono
parents:
diff changeset
2357 --cp_unevaluated_operand;
kono
parents:
diff changeset
2358 --c_inhibit_evaluation_warnings;
kono
parents:
diff changeset
2359 }
kono
parents:
diff changeset
2360
kono
parents:
diff changeset
2361 /* DECL is a defaulted function whose exception specification is now
kono
parents:
diff changeset
2362 needed. Return what it should be. */
kono
parents:
diff changeset
2363
kono
parents:
diff changeset
2364 tree
kono
parents:
diff changeset
2365 get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
kono
parents:
diff changeset
2366 {
kono
parents:
diff changeset
2367 if (DECL_CLONED_FUNCTION_P (decl))
kono
parents:
diff changeset
2368 decl = DECL_CLONED_FUNCTION (decl);
kono
parents:
diff changeset
2369 special_function_kind sfk = special_function_p (decl);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2370 if (sfk == sfk_comparison)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2371 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2372 /* We're in synthesize_method. Start with NULL_TREE, build_comparison_op
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2373 will adjust as needed. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2374 gcc_assert (decl == current_function_decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2375 return NULL_TREE;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2376 }
111
kono
parents:
diff changeset
2377 tree ctype = DECL_CONTEXT (decl);
kono
parents:
diff changeset
2378 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
kono
parents:
diff changeset
2379 tree parm_type = TREE_VALUE (parms);
kono
parents:
diff changeset
2380 bool const_p = CP_TYPE_CONST_P (non_reference (parm_type));
kono
parents:
diff changeset
2381 tree spec = empty_except_spec;
kono
parents:
diff changeset
2382 bool diag = !DECL_DELETED_FN (decl) && (complain & tf_error);
kono
parents:
diff changeset
2383 tree inh = DECL_INHERITED_CTOR (decl);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2384 if (SFK_DTOR_P (sfk) && DECL_VIRTUAL_P (decl))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2385 /* We have to examine virtual bases even if abstract. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2386 sfk = sfk_virtual_destructor;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2387 bool pushed = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2388 if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2389 pushed = push_tinst_level (decl);
111
kono
parents:
diff changeset
2390 synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
kono
parents:
diff changeset
2391 NULL, diag, &inh, parms);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2392 if (pushed)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2393 pop_tinst_level ();
111
kono
parents:
diff changeset
2394 return spec;
kono
parents:
diff changeset
2395 }
kono
parents:
diff changeset
2396
kono
parents:
diff changeset
2397 /* DECL is a deleted function. If it's implicitly deleted, explain why and
kono
parents:
diff changeset
2398 return true; else return false. */
kono
parents:
diff changeset
2399
kono
parents:
diff changeset
2400 bool
kono
parents:
diff changeset
2401 maybe_explain_implicit_delete (tree decl)
kono
parents:
diff changeset
2402 {
kono
parents:
diff changeset
2403 /* If decl is a clone, get the primary variant. */
kono
parents:
diff changeset
2404 decl = DECL_ORIGIN (decl);
kono
parents:
diff changeset
2405 gcc_assert (DECL_DELETED_FN (decl));
kono
parents:
diff changeset
2406 if (DECL_DEFAULTED_FN (decl))
kono
parents:
diff changeset
2407 {
kono
parents:
diff changeset
2408 /* Not marked GTY; it doesn't need to be GC'd or written to PCH. */
kono
parents:
diff changeset
2409 static hash_set<tree> *explained;
kono
parents:
diff changeset
2410
kono
parents:
diff changeset
2411 special_function_kind sfk;
kono
parents:
diff changeset
2412 location_t loc;
kono
parents:
diff changeset
2413 bool informed;
kono
parents:
diff changeset
2414 tree ctype;
kono
parents:
diff changeset
2415
kono
parents:
diff changeset
2416 if (!explained)
kono
parents:
diff changeset
2417 explained = new hash_set<tree>;
kono
parents:
diff changeset
2418 if (explained->add (decl))
kono
parents:
diff changeset
2419 return true;
kono
parents:
diff changeset
2420
kono
parents:
diff changeset
2421 sfk = special_function_p (decl);
kono
parents:
diff changeset
2422 ctype = DECL_CONTEXT (decl);
kono
parents:
diff changeset
2423 loc = input_location;
kono
parents:
diff changeset
2424 input_location = DECL_SOURCE_LOCATION (decl);
kono
parents:
diff changeset
2425
kono
parents:
diff changeset
2426 informed = false;
kono
parents:
diff changeset
2427 if (LAMBDA_TYPE_P (ctype))
kono
parents:
diff changeset
2428 {
kono
parents:
diff changeset
2429 informed = true;
kono
parents:
diff changeset
2430 if (sfk == sfk_constructor)
kono
parents:
diff changeset
2431 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
2432 "a lambda closure type has a deleted default constructor");
kono
parents:
diff changeset
2433 else if (sfk == sfk_copy_assignment)
kono
parents:
diff changeset
2434 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
2435 "a lambda closure type has a deleted copy assignment operator");
kono
parents:
diff changeset
2436 else
kono
parents:
diff changeset
2437 informed = false;
kono
parents:
diff changeset
2438 }
kono
parents:
diff changeset
2439 else if (DECL_ARTIFICIAL (decl)
kono
parents:
diff changeset
2440 && (sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
kono
parents:
diff changeset
2441 && classtype_has_move_assign_or_move_ctor_p (ctype, true))
kono
parents:
diff changeset
2442 {
kono
parents:
diff changeset
2443 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
2444 "%q#D is implicitly declared as deleted because %qT "
kono
parents:
diff changeset
2445 "declares a move constructor or move assignment operator",
kono
parents:
diff changeset
2446 decl, ctype);
kono
parents:
diff changeset
2447 informed = true;
kono
parents:
diff changeset
2448 }
kono
parents:
diff changeset
2449 else if (sfk == sfk_inheriting_constructor)
kono
parents:
diff changeset
2450 {
kono
parents:
diff changeset
2451 tree binfo = inherited_ctor_binfo (decl);
kono
parents:
diff changeset
2452 if (TREE_CODE (binfo) != TREE_BINFO)
kono
parents:
diff changeset
2453 {
kono
parents:
diff changeset
2454 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
2455 "%q#D inherits from multiple base subobjects",
kono
parents:
diff changeset
2456 decl);
kono
parents:
diff changeset
2457 informed = true;
kono
parents:
diff changeset
2458 }
kono
parents:
diff changeset
2459 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2460 if (!informed && sfk == sfk_comparison)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2461 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2462 inform (DECL_SOURCE_LOCATION (decl),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2463 "%q#D is implicitly deleted because the default "
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2464 "definition would be ill-formed:", decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2465 build_comparison_op (decl, tf_warning_or_error);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2466 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2467 else if (!informed)
111
kono
parents:
diff changeset
2468 {
kono
parents:
diff changeset
2469 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2470 bool const_p = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2471 if (parms)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2472 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2473 tree parm_type = TREE_VALUE (parms);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2474 const_p = CP_TYPE_CONST_P (non_reference (parm_type));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2475 }
111
kono
parents:
diff changeset
2476 tree raises = NULL_TREE;
kono
parents:
diff changeset
2477 bool deleted_p = false;
kono
parents:
diff changeset
2478 tree scope = push_scope (ctype);
kono
parents:
diff changeset
2479 tree inh = DECL_INHERITED_CTOR (decl);
kono
parents:
diff changeset
2480
kono
parents:
diff changeset
2481 synthesized_method_walk (ctype, sfk, const_p,
kono
parents:
diff changeset
2482 &raises, NULL, &deleted_p, NULL, false,
kono
parents:
diff changeset
2483 &inh, parms);
kono
parents:
diff changeset
2484 if (deleted_p)
kono
parents:
diff changeset
2485 {
kono
parents:
diff changeset
2486 inform (DECL_SOURCE_LOCATION (decl),
kono
parents:
diff changeset
2487 "%q#D is implicitly deleted because the default "
kono
parents:
diff changeset
2488 "definition would be ill-formed:", decl);
kono
parents:
diff changeset
2489 synthesized_method_walk (ctype, sfk, const_p,
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2490 NULL, NULL, &deleted_p, NULL, true,
111
kono
parents:
diff changeset
2491 &inh, parms);
kono
parents:
diff changeset
2492 }
kono
parents:
diff changeset
2493 else if (!comp_except_specs
kono
parents:
diff changeset
2494 (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
kono
parents:
diff changeset
2495 raises, ce_normal))
kono
parents:
diff changeset
2496 inform (DECL_SOURCE_LOCATION (decl), "%q#F is implicitly "
kono
parents:
diff changeset
2497 "deleted because its exception-specification does not "
kono
parents:
diff changeset
2498 "match the implicit exception-specification %qX",
kono
parents:
diff changeset
2499 decl, raises);
kono
parents:
diff changeset
2500 else if (flag_checking)
kono
parents:
diff changeset
2501 gcc_unreachable ();
kono
parents:
diff changeset
2502
kono
parents:
diff changeset
2503 pop_scope (scope);
kono
parents:
diff changeset
2504 }
kono
parents:
diff changeset
2505
kono
parents:
diff changeset
2506 input_location = loc;
kono
parents:
diff changeset
2507 return true;
kono
parents:
diff changeset
2508 }
kono
parents:
diff changeset
2509 return false;
kono
parents:
diff changeset
2510 }
kono
parents:
diff changeset
2511
kono
parents:
diff changeset
2512 /* DECL is a defaulted function which was declared constexpr. Explain why
kono
parents:
diff changeset
2513 it can't be constexpr. */
kono
parents:
diff changeset
2514
kono
parents:
diff changeset
2515 void
kono
parents:
diff changeset
2516 explain_implicit_non_constexpr (tree decl)
kono
parents:
diff changeset
2517 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2518 tree parms = FUNCTION_FIRST_USER_PARMTYPE (decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2519 bool const_p = CP_TYPE_CONST_P (non_reference (TREE_VALUE (parms)));
111
kono
parents:
diff changeset
2520 tree inh = DECL_INHERITED_CTOR (decl);
kono
parents:
diff changeset
2521 bool dummy;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2522 special_function_kind sfk = special_function_p (decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2523 if (sfk == sfk_comparison)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2524 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2525 DECL_DECLARED_CONSTEXPR_P (decl) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2526 build_comparison_op (decl, tf_warning_or_error);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2527 DECL_DECLARED_CONSTEXPR_P (decl) = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2528 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2529 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2530 synthesized_method_walk (DECL_CLASS_CONTEXT (decl),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2531 sfk, const_p,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2532 NULL, NULL, NULL, &dummy, true,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2533 &inh, parms);
111
kono
parents:
diff changeset
2534 }
kono
parents:
diff changeset
2535
kono
parents:
diff changeset
2536 /* DECL is an instantiation of an inheriting constructor template. Deduce
kono
parents:
diff changeset
2537 the correct exception-specification and deletedness for this particular
kono
parents:
diff changeset
2538 specialization. */
kono
parents:
diff changeset
2539
kono
parents:
diff changeset
2540 void
kono
parents:
diff changeset
2541 deduce_inheriting_ctor (tree decl)
kono
parents:
diff changeset
2542 {
kono
parents:
diff changeset
2543 decl = DECL_ORIGIN (decl);
kono
parents:
diff changeset
2544 gcc_assert (DECL_INHERITED_CTOR (decl));
kono
parents:
diff changeset
2545 tree spec;
kono
parents:
diff changeset
2546 bool trivial, constexpr_, deleted;
kono
parents:
diff changeset
2547 tree inh = DECL_INHERITED_CTOR (decl);
kono
parents:
diff changeset
2548 synthesized_method_walk (DECL_CONTEXT (decl), sfk_inheriting_constructor,
kono
parents:
diff changeset
2549 false, &spec, &trivial, &deleted, &constexpr_,
kono
parents:
diff changeset
2550 /*diag*/false,
kono
parents:
diff changeset
2551 &inh,
kono
parents:
diff changeset
2552 FUNCTION_FIRST_USER_PARMTYPE (decl));
kono
parents:
diff changeset
2553 if (TREE_CODE (inherited_ctor_binfo (decl)) != TREE_BINFO)
kono
parents:
diff changeset
2554 /* Inherited the same constructor from different base subobjects. */
kono
parents:
diff changeset
2555 deleted = true;
kono
parents:
diff changeset
2556 DECL_DELETED_FN (decl) = deleted;
kono
parents:
diff changeset
2557 TREE_TYPE (decl) = build_exception_variant (TREE_TYPE (decl), spec);
kono
parents:
diff changeset
2558 SET_DECL_INHERITED_CTOR (decl, inh);
kono
parents:
diff changeset
2559
kono
parents:
diff changeset
2560 tree clone;
kono
parents:
diff changeset
2561 FOR_EACH_CLONE (clone, decl)
kono
parents:
diff changeset
2562 {
kono
parents:
diff changeset
2563 DECL_DELETED_FN (clone) = deleted;
kono
parents:
diff changeset
2564 TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), spec);
kono
parents:
diff changeset
2565 SET_DECL_INHERITED_CTOR (clone, inh);
kono
parents:
diff changeset
2566 }
kono
parents:
diff changeset
2567 }
kono
parents:
diff changeset
2568
kono
parents:
diff changeset
2569 /* Implicitly declare the special function indicated by KIND, as a
kono
parents:
diff changeset
2570 member of TYPE. For copy constructors and assignment operators,
kono
parents:
diff changeset
2571 CONST_P indicates whether these functions should take a const
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2572 reference argument or a non-const reference.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2573 Returns the FUNCTION_DECL for the implicitly declared function. */
111
kono
parents:
diff changeset
2574
kono
parents:
diff changeset
2575 tree
kono
parents:
diff changeset
2576 implicitly_declare_fn (special_function_kind kind, tree type,
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2577 bool const_p, tree pattern_fn,
111
kono
parents:
diff changeset
2578 tree inherited_parms)
kono
parents:
diff changeset
2579 {
kono
parents:
diff changeset
2580 tree fn;
kono
parents:
diff changeset
2581 tree parameter_types = void_list_node;
kono
parents:
diff changeset
2582 tree return_type;
kono
parents:
diff changeset
2583 tree fn_type;
kono
parents:
diff changeset
2584 tree raises = empty_except_spec;
kono
parents:
diff changeset
2585 tree rhs_parm_type = NULL_TREE;
kono
parents:
diff changeset
2586 tree this_parm;
kono
parents:
diff changeset
2587 tree name;
kono
parents:
diff changeset
2588 HOST_WIDE_INT saved_processing_template_decl;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2589 bool deleted_p = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2590 bool constexpr_p = false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2591 bool friend_p = (kind == sfk_comparison && DECL_FRIEND_P (pattern_fn));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2592 tree inherited_ctor = (kind == sfk_inheriting_constructor
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2593 ? pattern_fn : NULL_TREE);
111
kono
parents:
diff changeset
2594
kono
parents:
diff changeset
2595 /* Because we create declarations for implicitly declared functions
kono
parents:
diff changeset
2596 lazily, we may be creating the declaration for a member of TYPE
kono
parents:
diff changeset
2597 while in some completely different context. However, TYPE will
kono
parents:
diff changeset
2598 never be a dependent class (because we never want to do lookups
kono
parents:
diff changeset
2599 for implicitly defined functions in a dependent class).
kono
parents:
diff changeset
2600 Furthermore, we must set PROCESSING_TEMPLATE_DECL to zero here
kono
parents:
diff changeset
2601 because we only create clones for constructors and destructors
kono
parents:
diff changeset
2602 when not in a template. */
kono
parents:
diff changeset
2603 gcc_assert (!dependent_type_p (type));
kono
parents:
diff changeset
2604 saved_processing_template_decl = processing_template_decl;
kono
parents:
diff changeset
2605 processing_template_decl = 0;
kono
parents:
diff changeset
2606
kono
parents:
diff changeset
2607 type = TYPE_MAIN_VARIANT (type);
kono
parents:
diff changeset
2608
kono
parents:
diff changeset
2609 if (targetm.cxx.cdtor_returns_this ())
kono
parents:
diff changeset
2610 {
kono
parents:
diff changeset
2611 if (kind == sfk_destructor)
kono
parents:
diff changeset
2612 /* See comment in check_special_function_return_type. */
kono
parents:
diff changeset
2613 return_type = build_pointer_type (void_type_node);
kono
parents:
diff changeset
2614 else
kono
parents:
diff changeset
2615 return_type = build_pointer_type (type);
kono
parents:
diff changeset
2616 }
kono
parents:
diff changeset
2617 else
kono
parents:
diff changeset
2618 return_type = void_type_node;
kono
parents:
diff changeset
2619
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2620 int this_quals = TYPE_UNQUALIFIED;
111
kono
parents:
diff changeset
2621 switch (kind)
kono
parents:
diff changeset
2622 {
kono
parents:
diff changeset
2623 case sfk_destructor:
kono
parents:
diff changeset
2624 /* Destructor. */
kono
parents:
diff changeset
2625 name = dtor_identifier;
kono
parents:
diff changeset
2626 break;
kono
parents:
diff changeset
2627
kono
parents:
diff changeset
2628 case sfk_constructor:
kono
parents:
diff changeset
2629 /* Default constructor. */
kono
parents:
diff changeset
2630 name = ctor_identifier;
kono
parents:
diff changeset
2631 break;
kono
parents:
diff changeset
2632
kono
parents:
diff changeset
2633 case sfk_copy_constructor:
kono
parents:
diff changeset
2634 case sfk_copy_assignment:
kono
parents:
diff changeset
2635 case sfk_move_constructor:
kono
parents:
diff changeset
2636 case sfk_move_assignment:
kono
parents:
diff changeset
2637 case sfk_inheriting_constructor:
kono
parents:
diff changeset
2638 {
kono
parents:
diff changeset
2639 if (kind == sfk_copy_assignment
kono
parents:
diff changeset
2640 || kind == sfk_move_assignment)
kono
parents:
diff changeset
2641 {
kono
parents:
diff changeset
2642 return_type = build_reference_type (type);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2643 name = assign_op_identifier;
111
kono
parents:
diff changeset
2644 }
kono
parents:
diff changeset
2645 else
kono
parents:
diff changeset
2646 name = ctor_identifier;
kono
parents:
diff changeset
2647
kono
parents:
diff changeset
2648 if (kind == sfk_inheriting_constructor)
kono
parents:
diff changeset
2649 parameter_types = inherited_parms;
kono
parents:
diff changeset
2650 else
kono
parents:
diff changeset
2651 {
kono
parents:
diff changeset
2652 if (const_p)
kono
parents:
diff changeset
2653 rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
kono
parents:
diff changeset
2654 else
kono
parents:
diff changeset
2655 rhs_parm_type = type;
kono
parents:
diff changeset
2656 bool move_p = (kind == sfk_move_assignment
kono
parents:
diff changeset
2657 || kind == sfk_move_constructor);
kono
parents:
diff changeset
2658 rhs_parm_type = cp_build_reference_type (rhs_parm_type, move_p);
kono
parents:
diff changeset
2659
kono
parents:
diff changeset
2660 parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
kono
parents:
diff changeset
2661 }
kono
parents:
diff changeset
2662 break;
kono
parents:
diff changeset
2663 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2664
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2665 case sfk_comparison:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2666 /* If the class definition does not explicitly declare an == operator
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2667 function, but declares a defaulted three-way comparison operator
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2668 function, an == operator function is declared implicitly with the same
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2669 access as the three-way comparison operator function.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2670
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2671 The implicitly-declared == operator for a class X is an inline member
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2672 and is defined as defaulted in the definition of X.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2673
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2674 If the three-way comparison operator function is declared as a
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2675 non-static const member, the implicitly-declared == operator function
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2676 is a member of the form
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2677
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2678 bool X::operator==(const X&) const;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2679
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2680 Otherwise, the implicitly-declared == operator function is of the form
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2681
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2682 friend bool operator==(const X&, const X&); */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2683 /* No other comparison operator is implicitly declared. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2684 name = ovl_op_identifier (false, EQ_EXPR);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2685 return_type = boolean_type_node;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2686 rhs_parm_type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2687 rhs_parm_type = cp_build_reference_type (rhs_parm_type, false);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2688 parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2689 if (friend_p)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2690 parameter_types = tree_cons (NULL_TREE, rhs_parm_type, parameter_types);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2691 this_quals = TYPE_QUAL_CONST;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2692 break;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2693
111
kono
parents:
diff changeset
2694 default:
kono
parents:
diff changeset
2695 gcc_unreachable ();
kono
parents:
diff changeset
2696 }
kono
parents:
diff changeset
2697
kono
parents:
diff changeset
2698 bool trivial_p = false;
kono
parents:
diff changeset
2699
kono
parents:
diff changeset
2700 if (inherited_ctor)
kono
parents:
diff changeset
2701 {
kono
parents:
diff changeset
2702 /* For an inheriting constructor, just copy these flags from the
kono
parents:
diff changeset
2703 inherited constructor until deduce_inheriting_ctor. */
kono
parents:
diff changeset
2704 raises = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (inherited_ctor));
kono
parents:
diff changeset
2705 deleted_p = DECL_DELETED_FN (inherited_ctor);
kono
parents:
diff changeset
2706 constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
kono
parents:
diff changeset
2707 }
kono
parents:
diff changeset
2708 else if (cxx_dialect >= cxx11)
kono
parents:
diff changeset
2709 {
kono
parents:
diff changeset
2710 raises = noexcept_deferred_spec;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2711 if (kind != sfk_comparison)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2712 synthesized_method_walk (type, kind, const_p, NULL, &trivial_p,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2713 &deleted_p, &constexpr_p, false,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2714 &inherited_ctor, inherited_parms);
111
kono
parents:
diff changeset
2715 }
kono
parents:
diff changeset
2716 else
kono
parents:
diff changeset
2717 synthesized_method_walk (type, kind, const_p, &raises, &trivial_p,
kono
parents:
diff changeset
2718 &deleted_p, &constexpr_p, false,
kono
parents:
diff changeset
2719 &inherited_ctor, inherited_parms);
kono
parents:
diff changeset
2720 /* Don't bother marking a deleted constructor as constexpr. */
kono
parents:
diff changeset
2721 if (deleted_p)
kono
parents:
diff changeset
2722 constexpr_p = false;
kono
parents:
diff changeset
2723 /* A trivial copy/move constructor is also a constexpr constructor,
kono
parents:
diff changeset
2724 unless the class has virtual bases (7.1.5p4). */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2725 else if (trivial_p
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2726 && cxx_dialect >= cxx11
111
kono
parents:
diff changeset
2727 && (kind == sfk_copy_constructor
kono
parents:
diff changeset
2728 || kind == sfk_move_constructor)
kono
parents:
diff changeset
2729 && !CLASSTYPE_VBASECLASSES (type))
kono
parents:
diff changeset
2730 gcc_assert (constexpr_p);
kono
parents:
diff changeset
2731
kono
parents:
diff changeset
2732 if (!trivial_p && type_has_trivial_fn (type, kind))
kono
parents:
diff changeset
2733 type_set_nontrivial_flag (type, kind);
kono
parents:
diff changeset
2734
kono
parents:
diff changeset
2735 /* Create the function. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2736 if (friend_p)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2737 fn_type = build_function_type (return_type, parameter_types);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2738 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2739 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2740 tree this_type = cp_build_qualified_type (type, this_quals);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2741 fn_type = build_method_type_directly (this_type, return_type,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2742 parameter_types);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2743 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2744
111
kono
parents:
diff changeset
2745 if (raises)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2746 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2747 if (raises != error_mark_node)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2748 fn_type = build_exception_variant (fn_type, raises);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2749 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2750 /* Can happen, eg, in C++98 mode for an ill-formed non-static data
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2751 member initializer (c++/89914). */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2752 gcc_assert (seen_error ());
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2753 }
111
kono
parents:
diff changeset
2754 fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2755 if (kind == sfk_comparison)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2756 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2757 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (pattern_fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2758 DECL_MAYBE_DELETED (fn) = true;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2759 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2760 else if (kind != sfk_inheriting_constructor)
111
kono
parents:
diff changeset
2761 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
kono
parents:
diff changeset
2762
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2763 if (IDENTIFIER_OVL_OP_P (name))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2764 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2765 const ovl_op_info_t *op = IDENTIFIER_OVL_OP_INFO (name);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2766 DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = op->ovl_op_code;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2767 }
111
kono
parents:
diff changeset
2768 else if (IDENTIFIER_CTOR_P (name))
kono
parents:
diff changeset
2769 DECL_CXX_CONSTRUCTOR_P (fn) = true;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2770 else if (IDENTIFIER_DTOR_P (name))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2771 DECL_CXX_DESTRUCTOR_P (fn) = true;
111
kono
parents:
diff changeset
2772 else
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2773 gcc_unreachable ();
111
kono
parents:
diff changeset
2774
kono
parents:
diff changeset
2775 SET_DECL_ALIGN (fn, MINIMUM_METHOD_BOUNDARY);
kono
parents:
diff changeset
2776
kono
parents:
diff changeset
2777 /* Create the explicit arguments. */
kono
parents:
diff changeset
2778 if (rhs_parm_type)
kono
parents:
diff changeset
2779 {
kono
parents:
diff changeset
2780 /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we
kono
parents:
diff changeset
2781 want its type to be included in the mangled function
kono
parents:
diff changeset
2782 name. */
kono
parents:
diff changeset
2783 tree decl = cp_build_parm_decl (fn, NULL_TREE, rhs_parm_type);
kono
parents:
diff changeset
2784 TREE_READONLY (decl) = 1;
kono
parents:
diff changeset
2785 retrofit_lang_decl (decl);
kono
parents:
diff changeset
2786 DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1;
kono
parents:
diff changeset
2787 DECL_ARGUMENTS (fn) = decl;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2788 if (friend_p)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2789 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2790 /* The second parm of friend op==. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2791 tree decl2 = copy_decl (decl);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2792 DECL_CHAIN (decl) = decl2;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2793 DECL_PARM_INDEX (decl2) = 2;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2794 }
111
kono
parents:
diff changeset
2795 }
kono
parents:
diff changeset
2796 else if (kind == sfk_inheriting_constructor)
kono
parents:
diff changeset
2797 {
kono
parents:
diff changeset
2798 tree *p = &DECL_ARGUMENTS (fn);
kono
parents:
diff changeset
2799 int index = 1;
kono
parents:
diff changeset
2800 for (tree parm = inherited_parms; parm && parm != void_list_node;
kono
parents:
diff changeset
2801 parm = TREE_CHAIN (parm))
kono
parents:
diff changeset
2802 {
kono
parents:
diff changeset
2803 *p = cp_build_parm_decl (fn, NULL_TREE, TREE_VALUE (parm));
kono
parents:
diff changeset
2804 retrofit_lang_decl (*p);
kono
parents:
diff changeset
2805 DECL_PARM_LEVEL (*p) = 1;
kono
parents:
diff changeset
2806 DECL_PARM_INDEX (*p) = index++;
kono
parents:
diff changeset
2807 p = &DECL_CHAIN (*p);
kono
parents:
diff changeset
2808 }
kono
parents:
diff changeset
2809 SET_DECL_INHERITED_CTOR (fn, inherited_ctor);
kono
parents:
diff changeset
2810 DECL_NONCONVERTING_P (fn) = DECL_NONCONVERTING_P (inherited_ctor);
kono
parents:
diff changeset
2811 /* A constructor so declared has the same access as the corresponding
kono
parents:
diff changeset
2812 constructor in X. */
kono
parents:
diff changeset
2813 TREE_PRIVATE (fn) = TREE_PRIVATE (inherited_ctor);
kono
parents:
diff changeset
2814 TREE_PROTECTED (fn) = TREE_PROTECTED (inherited_ctor);
kono
parents:
diff changeset
2815 /* Copy constexpr from the inherited constructor even if the
kono
parents:
diff changeset
2816 inheriting constructor doesn't satisfy the requirements. */
kono
parents:
diff changeset
2817 constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor);
kono
parents:
diff changeset
2818 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2819
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2820 if (friend_p)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2821 DECL_CONTEXT (fn) = DECL_CONTEXT (pattern_fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2822 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2823 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2824 /* Add the "this" parameter. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2825 this_parm = build_this_parm (fn, fn_type, this_quals);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2826 DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2827 DECL_ARGUMENTS (fn) = this_parm;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2828
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2829 grokclassfn (type, fn, kind == sfk_destructor ? DTOR_FLAG : NO_SPECIAL);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2830 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2831
111
kono
parents:
diff changeset
2832 DECL_IN_AGGR_P (fn) = 1;
kono
parents:
diff changeset
2833 DECL_ARTIFICIAL (fn) = 1;
kono
parents:
diff changeset
2834 DECL_DEFAULTED_FN (fn) = 1;
kono
parents:
diff changeset
2835 if (cxx_dialect >= cxx11)
kono
parents:
diff changeset
2836 {
kono
parents:
diff changeset
2837 DECL_DELETED_FN (fn) = deleted_p;
kono
parents:
diff changeset
2838 DECL_DECLARED_CONSTEXPR_P (fn) = constexpr_p;
kono
parents:
diff changeset
2839 }
kono
parents:
diff changeset
2840 DECL_EXTERNAL (fn) = true;
kono
parents:
diff changeset
2841 DECL_NOT_REALLY_EXTERN (fn) = 1;
kono
parents:
diff changeset
2842 DECL_DECLARED_INLINE_P (fn) = 1;
kono
parents:
diff changeset
2843 set_linkage_according_to_type (type, fn);
kono
parents:
diff changeset
2844 if (TREE_PUBLIC (fn))
kono
parents:
diff changeset
2845 DECL_COMDAT (fn) = 1;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2846 if (kind == sfk_comparison && !friend_p)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2847 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2848 /* The implicit op== has the same access as the op<=>. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2849 TREE_PRIVATE (fn) = TREE_PRIVATE (pattern_fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2850 TREE_PROTECTED (fn) = TREE_PROTECTED (pattern_fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2851 }
111
kono
parents:
diff changeset
2852 rest_of_decl_compilation (fn, namespace_bindings_p (), at_eof);
kono
parents:
diff changeset
2853 gcc_assert (!TREE_USED (fn));
kono
parents:
diff changeset
2854
kono
parents:
diff changeset
2855 /* Propagate constraints from the inherited constructor. */
kono
parents:
diff changeset
2856 if (flag_concepts && inherited_ctor)
kono
parents:
diff changeset
2857 if (tree orig_ci = get_constraints (inherited_ctor))
kono
parents:
diff changeset
2858 {
kono
parents:
diff changeset
2859 tree new_ci = copy_node (orig_ci);
kono
parents:
diff changeset
2860 set_constraints (fn, new_ci);
kono
parents:
diff changeset
2861 }
kono
parents:
diff changeset
2862
kono
parents:
diff changeset
2863 /* Restore PROCESSING_TEMPLATE_DECL. */
kono
parents:
diff changeset
2864 processing_template_decl = saved_processing_template_decl;
kono
parents:
diff changeset
2865
kono
parents:
diff changeset
2866 if (inherited_ctor && TREE_CODE (inherited_ctor) == TEMPLATE_DECL)
kono
parents:
diff changeset
2867 fn = add_inherited_template_parms (fn, inherited_ctor);
kono
parents:
diff changeset
2868
kono
parents:
diff changeset
2869 /* Warn about calling a non-trivial move assignment in a virtual base. */
kono
parents:
diff changeset
2870 if (kind == sfk_move_assignment && !deleted_p && !trivial_p
kono
parents:
diff changeset
2871 && CLASSTYPE_VBASECLASSES (type))
kono
parents:
diff changeset
2872 {
kono
parents:
diff changeset
2873 location_t loc = input_location;
kono
parents:
diff changeset
2874 input_location = DECL_SOURCE_LOCATION (fn);
kono
parents:
diff changeset
2875 synthesized_method_walk (type, kind, const_p,
kono
parents:
diff changeset
2876 NULL, NULL, NULL, NULL, true,
kono
parents:
diff changeset
2877 NULL, NULL_TREE);
kono
parents:
diff changeset
2878 input_location = loc;
kono
parents:
diff changeset
2879 }
kono
parents:
diff changeset
2880
kono
parents:
diff changeset
2881 return fn;
kono
parents:
diff changeset
2882 }
kono
parents:
diff changeset
2883
kono
parents:
diff changeset
2884 /* Gives any errors about defaulted functions which need to be deferred
kono
parents:
diff changeset
2885 until the containing class is complete. */
kono
parents:
diff changeset
2886
kono
parents:
diff changeset
2887 void
kono
parents:
diff changeset
2888 defaulted_late_check (tree fn)
kono
parents:
diff changeset
2889 {
kono
parents:
diff changeset
2890 /* Complain about invalid signature for defaulted fn. */
kono
parents:
diff changeset
2891 tree ctx = DECL_CONTEXT (fn);
kono
parents:
diff changeset
2892 special_function_kind kind = special_function_p (fn);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2893
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2894 if (kind == sfk_comparison)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2895 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2896 /* If the function was declared constexpr, check that the definition
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2897 qualifies. Otherwise we can define the function lazily. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2898 if (DECL_DECLARED_CONSTEXPR_P (fn))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2899 synthesize_method (fn);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2900 return;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2901 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2902
111
kono
parents:
diff changeset
2903 bool fn_const_p = (copy_fn_p (fn) == 2);
kono
parents:
diff changeset
2904 tree implicit_fn = implicitly_declare_fn (kind, ctx, fn_const_p,
kono
parents:
diff changeset
2905 NULL, NULL);
kono
parents:
diff changeset
2906 tree eh_spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (implicit_fn));
kono
parents:
diff changeset
2907
kono
parents:
diff changeset
2908 if (!same_type_p (TREE_TYPE (TREE_TYPE (fn)),
kono
parents:
diff changeset
2909 TREE_TYPE (TREE_TYPE (implicit_fn)))
kono
parents:
diff changeset
2910 || !compparms (TYPE_ARG_TYPES (TREE_TYPE (fn)),
kono
parents:
diff changeset
2911 TYPE_ARG_TYPES (TREE_TYPE (implicit_fn))))
kono
parents:
diff changeset
2912 {
kono
parents:
diff changeset
2913 error ("defaulted declaration %q+D does not match the "
kono
parents:
diff changeset
2914 "expected signature", fn);
kono
parents:
diff changeset
2915 inform (DECL_SOURCE_LOCATION (fn),
kono
parents:
diff changeset
2916 "expected signature: %qD", implicit_fn);
kono
parents:
diff changeset
2917 }
kono
parents:
diff changeset
2918
kono
parents:
diff changeset
2919 if (DECL_DELETED_FN (implicit_fn))
kono
parents:
diff changeset
2920 {
kono
parents:
diff changeset
2921 DECL_DELETED_FN (fn) = 1;
kono
parents:
diff changeset
2922 return;
kono
parents:
diff changeset
2923 }
kono
parents:
diff changeset
2924
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2925 /* If a function is explicitly defaulted on its first declaration without an
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2926 exception-specification, it is implicitly considered to have the same
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2927 exception-specification as if it had been implicitly declared. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2928 if (!TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2929 && DECL_DEFAULTED_IN_CLASS_P (fn))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2930 TREE_TYPE (fn) = build_exception_variant (TREE_TYPE (fn), eh_spec);
111
kono
parents:
diff changeset
2931
kono
parents:
diff changeset
2932 if (DECL_DEFAULTED_IN_CLASS_P (fn)
kono
parents:
diff changeset
2933 && DECL_DECLARED_CONSTEXPR_P (implicit_fn))
kono
parents:
diff changeset
2934 {
kono
parents:
diff changeset
2935 /* Hmm...should we do this for out-of-class too? Should it be OK to
kono
parents:
diff changeset
2936 add constexpr later like inline, rather than requiring
kono
parents:
diff changeset
2937 declarations to match? */
kono
parents:
diff changeset
2938 DECL_DECLARED_CONSTEXPR_P (fn) = true;
kono
parents:
diff changeset
2939 if (kind == sfk_constructor)
kono
parents:
diff changeset
2940 TYPE_HAS_CONSTEXPR_CTOR (ctx) = true;
kono
parents:
diff changeset
2941 }
kono
parents:
diff changeset
2942
kono
parents:
diff changeset
2943 if (!DECL_DECLARED_CONSTEXPR_P (implicit_fn)
kono
parents:
diff changeset
2944 && DECL_DECLARED_CONSTEXPR_P (fn))
kono
parents:
diff changeset
2945 {
kono
parents:
diff changeset
2946 if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
kono
parents:
diff changeset
2947 {
kono
parents:
diff changeset
2948 error ("explicitly defaulted function %q+D cannot be declared "
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2949 "%qs because the implicit declaration is not %qs:", fn,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2950 DECL_IMMEDIATE_FUNCTION_P (fn) ? "consteval" : "constexpr",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2951 "constexpr");
111
kono
parents:
diff changeset
2952 explain_implicit_non_constexpr (fn);
kono
parents:
diff changeset
2953 }
kono
parents:
diff changeset
2954 DECL_DECLARED_CONSTEXPR_P (fn) = false;
kono
parents:
diff changeset
2955 }
kono
parents:
diff changeset
2956 }
kono
parents:
diff changeset
2957
kono
parents:
diff changeset
2958 /* Returns true iff FN can be explicitly defaulted, and gives any
kono
parents:
diff changeset
2959 errors if defaulting FN is ill-formed. */
kono
parents:
diff changeset
2960
kono
parents:
diff changeset
2961 bool
kono
parents:
diff changeset
2962 defaultable_fn_check (tree fn)
kono
parents:
diff changeset
2963 {
kono
parents:
diff changeset
2964 special_function_kind kind = sfk_none;
kono
parents:
diff changeset
2965
kono
parents:
diff changeset
2966 if (template_parm_scope_p ())
kono
parents:
diff changeset
2967 {
kono
parents:
diff changeset
2968 error ("a template cannot be defaulted");
kono
parents:
diff changeset
2969 return false;
kono
parents:
diff changeset
2970 }
kono
parents:
diff changeset
2971
kono
parents:
diff changeset
2972 if (DECL_CONSTRUCTOR_P (fn))
kono
parents:
diff changeset
2973 {
kono
parents:
diff changeset
2974 if (FUNCTION_FIRST_USER_PARMTYPE (fn) == void_list_node)
kono
parents:
diff changeset
2975 kind = sfk_constructor;
kono
parents:
diff changeset
2976 else if (copy_fn_p (fn) > 0
kono
parents:
diff changeset
2977 && (TREE_CHAIN (FUNCTION_FIRST_USER_PARMTYPE (fn))
kono
parents:
diff changeset
2978 == void_list_node))
kono
parents:
diff changeset
2979 kind = sfk_copy_constructor;
kono
parents:
diff changeset
2980 else if (move_fn_p (fn))
kono
parents:
diff changeset
2981 kind = sfk_move_constructor;
kono
parents:
diff changeset
2982 }
kono
parents:
diff changeset
2983 else if (DECL_DESTRUCTOR_P (fn))
kono
parents:
diff changeset
2984 kind = sfk_destructor;
kono
parents:
diff changeset
2985 else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2986 && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
111
kono
parents:
diff changeset
2987 {
kono
parents:
diff changeset
2988 if (copy_fn_p (fn))
kono
parents:
diff changeset
2989 kind = sfk_copy_assignment;
kono
parents:
diff changeset
2990 else if (move_fn_p (fn))
kono
parents:
diff changeset
2991 kind = sfk_move_assignment;
kono
parents:
diff changeset
2992 }
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2993 else if (DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) >= OVL_OP_EQ_EXPR
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2994 && DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) <= OVL_OP_SPACESHIP_EXPR)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2995 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2996 kind = sfk_comparison;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2997 if (!early_check_defaulted_comparison (fn))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2998 return false;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2999 }
111
kono
parents:
diff changeset
3000
kono
parents:
diff changeset
3001 if (kind == sfk_none)
kono
parents:
diff changeset
3002 {
kono
parents:
diff changeset
3003 error ("%qD cannot be defaulted", fn);
kono
parents:
diff changeset
3004 return false;
kono
parents:
diff changeset
3005 }
kono
parents:
diff changeset
3006 else
kono
parents:
diff changeset
3007 {
kono
parents:
diff changeset
3008 for (tree t = FUNCTION_FIRST_USER_PARMTYPE (fn);
kono
parents:
diff changeset
3009 t && t != void_list_node; t = TREE_CHAIN (t))
kono
parents:
diff changeset
3010 if (TREE_PURPOSE (t))
kono
parents:
diff changeset
3011 {
kono
parents:
diff changeset
3012 error ("defaulted function %q+D with default argument", fn);
kono
parents:
diff changeset
3013 break;
kono
parents:
diff changeset
3014 }
kono
parents:
diff changeset
3015
kono
parents:
diff changeset
3016 /* Avoid do_warn_unused_parameter warnings. */
kono
parents:
diff changeset
3017 for (tree p = FUNCTION_FIRST_USER_PARM (fn); p; p = DECL_CHAIN (p))
kono
parents:
diff changeset
3018 if (DECL_NAME (p))
kono
parents:
diff changeset
3019 TREE_NO_WARNING (p) = 1;
kono
parents:
diff changeset
3020
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
3021 if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
111
kono
parents:
diff changeset
3022 /* Defer checking. */;
kono
parents:
diff changeset
3023 else if (!processing_template_decl)
kono
parents:
diff changeset
3024 defaulted_late_check (fn);
kono
parents:
diff changeset
3025
kono
parents:
diff changeset
3026 return true;
kono
parents:
diff changeset
3027 }
kono
parents:
diff changeset
3028 }
kono
parents:
diff changeset
3029
kono
parents:
diff changeset
3030 /* Add an implicit declaration to TYPE for the kind of function
kono
parents:
diff changeset
3031 indicated by SFK. Return the FUNCTION_DECL for the new implicit
kono
parents:
diff changeset
3032 declaration. */
kono
parents:
diff changeset
3033
kono
parents:
diff changeset
3034 tree
kono
parents:
diff changeset
3035 lazily_declare_fn (special_function_kind sfk, tree type)
kono
parents:
diff changeset
3036 {
kono
parents:
diff changeset
3037 tree fn;
kono
parents:
diff changeset
3038 /* Whether or not the argument has a const reference type. */
kono
parents:
diff changeset
3039 bool const_p = false;
kono
parents:
diff changeset
3040
kono
parents:
diff changeset
3041 type = TYPE_MAIN_VARIANT (type);
kono
parents:
diff changeset
3042
kono
parents:
diff changeset
3043 switch (sfk)
kono
parents:
diff changeset
3044 {
kono
parents:
diff changeset
3045 case sfk_constructor:
kono
parents:
diff changeset
3046 CLASSTYPE_LAZY_DEFAULT_CTOR (type) = 0;
kono
parents:
diff changeset
3047 break;
kono
parents:
diff changeset
3048 case sfk_copy_constructor:
kono
parents:
diff changeset
3049 const_p = TYPE_HAS_CONST_COPY_CTOR (type);
kono
parents:
diff changeset
3050 CLASSTYPE_LAZY_COPY_CTOR (type) = 0;
kono
parents:
diff changeset
3051 break;
kono
parents:
diff changeset
3052 case sfk_move_constructor:
kono
parents:
diff changeset
3053 CLASSTYPE_LAZY_MOVE_CTOR (type) = 0;
kono
parents:
diff changeset
3054 break;
kono
parents:
diff changeset
3055 case sfk_copy_assignment:
kono
parents:
diff changeset
3056 const_p = TYPE_HAS_CONST_COPY_ASSIGN (type);
kono
parents:
diff changeset
3057 CLASSTYPE_LAZY_COPY_ASSIGN (type) = 0;
kono
parents:
diff changeset
3058 break;
kono
parents:
diff changeset
3059 case sfk_move_assignment:
kono
parents:
diff changeset
3060 CLASSTYPE_LAZY_MOVE_ASSIGN (type) = 0;
kono
parents:
diff changeset
3061 break;
kono
parents:
diff changeset
3062 case sfk_destructor:
kono
parents:
diff changeset
3063 CLASSTYPE_LAZY_DESTRUCTOR (type) = 0;
kono
parents:
diff changeset
3064 break;
kono
parents:
diff changeset
3065 default:
kono
parents:
diff changeset
3066 gcc_unreachable ();
kono
parents:
diff changeset
3067 }
kono
parents:
diff changeset
3068
kono
parents:
diff changeset
3069 /* Declare the function. */
kono
parents:
diff changeset
3070 fn = implicitly_declare_fn (sfk, type, const_p, NULL, NULL);
kono
parents:
diff changeset
3071
kono
parents:
diff changeset
3072 /* [class.copy]/8 If the class definition declares a move constructor or
kono
parents:
diff changeset
3073 move assignment operator, the implicitly declared copy constructor is
kono
parents:
diff changeset
3074 defined as deleted.... */
kono
parents:
diff changeset
3075 if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3076 && cxx_dialect >= cxx11)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3077 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3078 if (classtype_has_move_assign_or_move_ctor_p (type, true))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3079 DECL_DELETED_FN (fn) = true;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
3080 else if (classtype_has_depr_implicit_copy (type))
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3081 /* The implicit definition of a copy constructor as defaulted is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3082 deprecated if the class has a user-declared copy assignment operator
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3083 or a user-declared destructor. The implicit definition of a copy
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3084 assignment operator as defaulted is deprecated if the class has a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3085 user-declared copy constructor or a user-declared destructor (15.4,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3086 15.8). */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3087 TREE_DEPRECATED (fn) = true;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3088 }
111
kono
parents:
diff changeset
3089
kono
parents:
diff changeset
3090 /* Destructors and assignment operators may be virtual. */
kono
parents:
diff changeset
3091 if (sfk == sfk_destructor
kono
parents:
diff changeset
3092 || sfk == sfk_move_assignment
kono
parents:
diff changeset
3093 || sfk == sfk_copy_assignment)
kono
parents:
diff changeset
3094 check_for_override (fn, type);
kono
parents:
diff changeset
3095
kono
parents:
diff changeset
3096 /* Add it to the class */
kono
parents:
diff changeset
3097 bool added = add_method (type, fn, false);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3098 gcc_assert (added || errorcount);
111
kono
parents:
diff changeset
3099
kono
parents:
diff changeset
3100 /* Add it to TYPE_FIELDS. */
kono
parents:
diff changeset
3101 if (sfk == sfk_destructor
kono
parents:
diff changeset
3102 && DECL_VIRTUAL_P (fn))
kono
parents:
diff changeset
3103 /* The ABI requires that a virtual destructor go at the end of the
kono
parents:
diff changeset
3104 vtable. */
kono
parents:
diff changeset
3105 TYPE_FIELDS (type) = chainon (TYPE_FIELDS (type), fn);
kono
parents:
diff changeset
3106 else
kono
parents:
diff changeset
3107 {
kono
parents:
diff changeset
3108 DECL_CHAIN (fn) = TYPE_FIELDS (type);
kono
parents:
diff changeset
3109 TYPE_FIELDS (type) = fn;
kono
parents:
diff changeset
3110 }
kono
parents:
diff changeset
3111 /* Propagate TYPE_FIELDS. */
kono
parents:
diff changeset
3112 fixup_type_variants (type);
kono
parents:
diff changeset
3113
kono
parents:
diff changeset
3114 maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3115 if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
111
kono
parents:
diff changeset
3116 /* Create appropriate clones. */
kono
parents:
diff changeset
3117 clone_function_decl (fn, /*update_methods=*/true);
kono
parents:
diff changeset
3118
kono
parents:
diff changeset
3119 return fn;
kono
parents:
diff changeset
3120 }
kono
parents:
diff changeset
3121
kono
parents:
diff changeset
3122 /* Given a FUNCTION_DECL FN and a chain LIST, skip as many elements of LIST
kono
parents:
diff changeset
3123 as there are artificial parms in FN. */
kono
parents:
diff changeset
3124
kono
parents:
diff changeset
3125 tree
kono
parents:
diff changeset
3126 skip_artificial_parms_for (const_tree fn, tree list)
kono
parents:
diff changeset
3127 {
kono
parents:
diff changeset
3128 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
kono
parents:
diff changeset
3129 list = TREE_CHAIN (list);
kono
parents:
diff changeset
3130 else
kono
parents:
diff changeset
3131 return list;
kono
parents:
diff changeset
3132
kono
parents:
diff changeset
3133 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
kono
parents:
diff changeset
3134 list = TREE_CHAIN (list);
kono
parents:
diff changeset
3135 if (DECL_HAS_VTT_PARM_P (fn))
kono
parents:
diff changeset
3136 list = TREE_CHAIN (list);
kono
parents:
diff changeset
3137 return list;
kono
parents:
diff changeset
3138 }
kono
parents:
diff changeset
3139
kono
parents:
diff changeset
3140 /* Given a FUNCTION_DECL FN and a chain LIST, return the number of
kono
parents:
diff changeset
3141 artificial parms in FN. */
kono
parents:
diff changeset
3142
kono
parents:
diff changeset
3143 int
kono
parents:
diff changeset
3144 num_artificial_parms_for (const_tree fn)
kono
parents:
diff changeset
3145 {
kono
parents:
diff changeset
3146 int count = 0;
kono
parents:
diff changeset
3147
kono
parents:
diff changeset
3148 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
kono
parents:
diff changeset
3149 count++;
kono
parents:
diff changeset
3150 else
kono
parents:
diff changeset
3151 return 0;
kono
parents:
diff changeset
3152
kono
parents:
diff changeset
3153 if (DECL_HAS_IN_CHARGE_PARM_P (fn))
kono
parents:
diff changeset
3154 count++;
kono
parents:
diff changeset
3155 if (DECL_HAS_VTT_PARM_P (fn))
kono
parents:
diff changeset
3156 count++;
kono
parents:
diff changeset
3157 return count;
kono
parents:
diff changeset
3158 }
kono
parents:
diff changeset
3159
kono
parents:
diff changeset
3160
kono
parents:
diff changeset
3161 #include "gt-cp-method.h"