Line data Source code
1 : /* Process declarations and variables for -*- C++ -*- compiler.
2 : Copyright (C) 1988-2026 Free Software Foundation, Inc.
3 : Contributed by Michael Tiemann (tiemann@cygnus.com)
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3, or (at your option)
10 : any later version.
11 :
12 : GCC is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 :
22 : /* Process declarations and symbol lookup for C++ front end.
23 : Also constructs types; the standard scalar types at initialization,
24 : and structure, union, array and enum types when they are declared. */
25 :
26 : /* ??? not all decl nodes are given the most useful possible
27 : line numbers. For example, the CONST_DECLs for enum values. */
28 :
29 : #include "config.h"
30 : #include "system.h"
31 : #include "coretypes.h"
32 : #include "target.h"
33 : #include "c-family/c-target.h"
34 : #include "cp-tree.h"
35 : #include "timevar.h"
36 : #include "stringpool.h"
37 : #include "cgraph.h"
38 : #include "stor-layout.h"
39 : #include "varasm.h"
40 : #include "attribs.h"
41 : #include "flags.h"
42 : #include "tree-iterator.h"
43 : #include "decl.h"
44 : #include "intl.h"
45 : #include "toplev.h"
46 : #include "c-family/c-objc.h"
47 : #include "c-family/c-pragma.h"
48 : #include "c-family/c-ubsan.h"
49 : #include "cp/cp-name-hint.h"
50 : #include "debug.h"
51 : #include "plugin.h"
52 : #include "builtins.h"
53 : #include "gimplify.h"
54 : #include "asan.h"
55 : #include "gcc-rich-location.h"
56 : #include "langhooks.h"
57 : #include "context.h" /* For 'g'. */
58 : #include "omp-general.h"
59 : #include "omp-offload.h" /* For offload_vars. */
60 : #include "opts.h"
61 : #include "langhooks-def.h" /* For lhd_simulate_record_decl */
62 : #include "coroutines.h"
63 : #include "contracts.h"
64 : #include "gcc-urlifier.h"
65 : #include "diagnostic-highlight-colors.h"
66 : #include "pretty-print-markup.h"
67 :
68 : /* Possible cases of bad specifiers type used by bad_specifiers. */
69 : enum bad_spec_place {
70 : BSP_VAR, /* variable */
71 : BSP_PARM, /* parameter */
72 : BSP_TYPE, /* type */
73 : BSP_FIELD /* field */
74 : };
75 :
76 : static const char *redeclaration_error_message (tree, tree);
77 :
78 : static bool decl_jump_unsafe (tree);
79 : static bool decl_instrument_init_bypass_p (tree);
80 : static void require_complete_types_for_parms (tree);
81 : static tree grok_reference_init (tree, tree, tree, int);
82 : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
83 : int, int, int, bool, int, tree, location_t);
84 : static void check_static_variable_definition (tree, tree);
85 : static void record_unknown_type (tree, const char *);
86 : static int member_function_or_else (tree, tree, enum overload_flags);
87 : static tree local_variable_p_walkfn (tree *, int *, void *);
88 : static tree lookup_and_check_tag (enum tag_types, tree, TAG_how, bool);
89 : static void maybe_deduce_size_from_array_init (tree, tree);
90 : static void layout_var_decl (tree);
91 : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
92 : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
93 : static void copy_type_enum (tree , tree);
94 : static void check_function_type (tree, tree);
95 : static void begin_destructor_body (void);
96 : static void record_key_method_defined (tree);
97 : static tree create_array_type_for_decl (tree, tree, tree, location_t);
98 : static tree get_atexit_node (void);
99 : static tree get_dso_handle_node (void);
100 : static tree start_cleanup_fn (tree, bool, bool);
101 : static void end_cleanup_fn (void);
102 : static tree cp_make_fname_decl (location_t, tree, int);
103 : static void initialize_predefined_identifiers (void);
104 : static tree check_special_function_return_type
105 : (special_function_kind, tree, tree, int, const cp_declarator**,
106 : const location_t*);
107 : static tree push_cp_library_fn (enum tree_code, tree, int);
108 : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
109 : static void store_parm_decls (tree);
110 : static void initialize_local_var (tree, tree, bool);
111 : static void expand_static_init (tree, tree);
112 : static location_t smallest_type_location (const cp_decl_specifier_seq*);
113 : static bool identify_goto (tree, location_t, const location_t *,
114 : enum diagnostics::kind, bool);
115 :
116 : /* The following symbols are subsumed in the cp_global_trees array, and
117 : listed here individually for documentation purposes.
118 :
119 : C++ extensions
120 : tree wchar_decl_node;
121 :
122 : tree vtable_entry_type;
123 : tree delta_type_node;
124 : tree __t_desc_type_node;
125 :
126 : tree class_type_node;
127 : tree unknown_type_node;
128 :
129 : Array type `vtable_entry_type[]'
130 :
131 : tree vtbl_type_node;
132 : tree vtbl_ptr_type_node;
133 :
134 : Namespaces,
135 :
136 : tree std_node;
137 : tree std_meta_node;
138 : tree abi_node;
139 :
140 : A FUNCTION_DECL which can call `abort'. Not necessarily the
141 : one that the user will declare, but sufficient to be called
142 : by routines that want to abort the program.
143 :
144 : tree abort_fndecl;
145 :
146 : Used by RTTI
147 : tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
148 : tree tinfo_var_id; */
149 :
150 : tree cp_global_trees[CPTI_MAX];
151 :
152 : /* A list of objects which have constructors or destructors
153 : which reside in namespace scope. The decl is stored in
154 : the TREE_VALUE slot and the initializer is stored
155 : in the TREE_PURPOSE slot. */
156 : tree static_aggregates;
157 :
158 : /* Like static_aggregates, but for thread_local variables. */
159 : tree tls_aggregates;
160 :
161 : /* A hash-map mapping from variable decls to the dynamic initializer for
162 : the decl. This is currently only used by OpenMP. */
163 : decl_tree_map *dynamic_initializers;
164 :
165 : /* -- end of C++ */
166 :
167 : /* A node for the integer constant 2. */
168 :
169 : tree integer_two_node;
170 :
171 : /* vector of static decls. */
172 : vec<tree, va_gc> *static_decls;
173 :
174 : /* vector of keyed classes. */
175 : vec<tree, va_gc> *keyed_classes;
176 :
177 : /* Used in the direct_goto vector of named_label_use_entry for
178 : addresses of the LABEL_DECLs within GOTO_EXPR or asm goto
179 : for forward jumps. */
180 :
181 : struct GTY(()) named_label_fwd_direct_goto {
182 : tree *GTY((skip)) direct_goto;
183 : };
184 :
185 : /* Used in the direct_goto vector of named_label_use_entry for
186 : addresses of the LABEL_DECLs within GOTO_EXPR or asm goto
187 : for backward jumps. */
188 :
189 : struct GTY(()) named_label_bck_direct_goto {
190 : tree *GTY((skip)) direct_goto;
191 : /* Number of the decl_instrument_init_bypass_p decls in bad_decls vector
192 : at the time this backward goto has been seen. */
193 : unsigned n_bad_decls;
194 : };
195 :
196 : /* Used only for jumps to as-yet undefined labels, since jumps to
197 : defined labels can have their validity checked immediately. */
198 :
199 : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
200 : struct named_label_use_entry *next;
201 : /* The binding level to which this entry is *currently* attached.
202 : This is initially the binding level in which the goto appeared,
203 : but is modified as scopes are closed. */
204 : cp_binding_level *binding_level;
205 : /* The head of the names list that was current when the goto appeared,
206 : or the inner scope popped. These are the decls that will *not* be
207 : skipped when jumping to the label. */
208 : tree names_in_scope;
209 : /* If the use is a possible destination of a computed goto, a vec of decls
210 : that aren't destroyed, filled in by poplevel_named_label_1. */
211 : vec<tree, va_gc> *computed_goto;
212 : /* If the use is a destination of normal goto, a vec of addresses of
213 : LABEL_DECLs that might need changing for !!flag_auto_var_init
214 : forward jumps across vacuous initializers. */
215 : vec<named_label_fwd_direct_goto, va_gc> *direct_goto;
216 : /* The location of the goto, for error reporting. */
217 : location_t o_goto_locus;
218 : /* True if an OpenMP structured block scope has been closed since
219 : the goto appeared. This means that the branch from the label will
220 : illegally exit an OpenMP scope. */
221 : bool in_omp_scope;
222 : };
223 :
224 : /* A list of all LABEL_DECLs in the function that have names. Here so
225 : we can clear out their names' definitions at the end of the
226 : function, and so we can check the validity of jumps to these labels. */
227 :
228 : struct GTY((for_user)) named_label_entry {
229 :
230 : tree name; /* Name of decl. */
231 :
232 : tree label_decl; /* LABEL_DECL, unless deleted local label. */
233 :
234 : named_label_entry *outer; /* Outer shadowed chain. */
235 :
236 : /* The binding level to which the label is *currently* attached.
237 : This is initially set to the binding level in which the label
238 : is defined, but is modified as scopes are closed. */
239 : cp_binding_level *binding_level;
240 :
241 : /* The head of the names list that was current when the label was
242 : defined, or the inner scope popped. These are the decls that will
243 : be skipped when jumping to the label. */
244 : tree names_in_scope;
245 :
246 : /* A vector of all decls from all binding levels that would be
247 : crossed by a backward branch to the label. */
248 : vec<tree, va_gc> *bad_decls;
249 :
250 : /* A list of uses of the label, before the label is defined. */
251 : named_label_use_entry *uses;
252 :
253 : /* If the use is a destination of normal goto, a vec of addresses of
254 : LABEL_DECLs that might need changing for !!flag_auto_var_init
255 : backward jumps across vacuous initializers. */
256 : vec<named_label_bck_direct_goto, va_gc> *direct_goto;
257 :
258 : /* True if we've seen &&label. Apparently we can't use TREE_ADDRESSABLE for
259 : this, it has a more specific meaning for LABEL_DECL. */
260 : bool addressed : 1;
261 :
262 : /* The following bits are set after the label is defined, and are
263 : updated as scopes are popped. They indicate that a jump to the
264 : label will illegally enter a scope of the given flavor. */
265 : bool in_try_scope : 1;
266 : bool in_catch_scope : 1;
267 : bool in_omp_scope : 1;
268 : bool in_transaction_scope : 1;
269 : bool in_constexpr_if : 1;
270 : bool in_consteval_if : 1;
271 : bool in_stmt_expr : 1;
272 :
273 : /* True if bad_decls chain contains any decl_jump_unsafe decls
274 : (rather than just decl_instrument_init_bypass_p). */
275 : bool has_bad_decls : 1;
276 : };
277 :
278 : #define named_labels cp_function_chain->x_named_labels
279 :
280 : /* The number of function bodies which we are currently processing.
281 : (Zero if we are at namespace scope, one inside the body of a
282 : function, two inside the body of a function in a local class, etc.) */
283 : int function_depth;
284 :
285 : /* Whether the exception-specifier is part of a function type (i.e. C++17). */
286 : bool flag_noexcept_type;
287 :
288 : /* States indicating how grokdeclarator() should handle declspecs marked
289 : with __attribute__((deprecated)). An object declared as
290 : __attribute__((deprecated)) suppresses warnings of uses of other
291 : deprecated items. */
292 : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
293 :
294 :
295 : /* A list of VAR_DECLs whose type was incomplete at the time the
296 : variable was declared. */
297 :
298 : struct GTY(()) incomplete_var {
299 : tree decl;
300 : tree incomplete_type;
301 : };
302 :
303 :
304 : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
305 :
306 : /* Returns the kind of template specialization we are currently
307 : processing, given that it's declaration contained N_CLASS_SCOPES
308 : explicit scope qualifications. */
309 :
310 : tmpl_spec_kind
311 246582151 : current_tmpl_spec_kind (int n_class_scopes)
312 : {
313 246582151 : int n_template_parm_scopes = 0;
314 246582151 : int seen_specialization_p = 0;
315 246582151 : int innermost_specialization_p = 0;
316 246582151 : cp_binding_level *b;
317 :
318 : /* Scan through the template parameter scopes. */
319 246582151 : for (b = current_binding_level;
320 307333793 : b->kind == sk_template_parms;
321 60751642 : b = b->level_chain)
322 : {
323 : /* If we see a specialization scope inside a parameter scope,
324 : then something is wrong. That corresponds to a declaration
325 : like:
326 :
327 : template <class T> template <> ...
328 :
329 : which is always invalid since [temp.expl.spec] forbids the
330 : specialization of a class member template if the enclosing
331 : class templates are not explicitly specialized as well. */
332 60751642 : if (b->explicit_spec_p)
333 : {
334 1409211 : if (n_template_parm_scopes == 0)
335 : innermost_specialization_p = 1;
336 : else
337 1326 : seen_specialization_p = 1;
338 : }
339 59342431 : else if (seen_specialization_p == 1)
340 : return tsk_invalid_member_spec;
341 :
342 60751642 : ++n_template_parm_scopes;
343 : }
344 :
345 : /* Handle explicit instantiations. */
346 246582151 : if (processing_explicit_instantiation)
347 : {
348 1959993 : if (n_template_parm_scopes != 0)
349 : /* We've seen a template parameter list during an explicit
350 : instantiation. For example:
351 :
352 : template <class T> template void f(int);
353 :
354 : This is erroneous. */
355 : return tsk_invalid_expl_inst;
356 : else
357 1959993 : return tsk_expl_inst;
358 : }
359 :
360 244622158 : if (n_template_parm_scopes < n_class_scopes)
361 : /* We've not seen enough template headers to match all the
362 : specialized classes present. For example:
363 :
364 : template <class T> void R<T>::S<T>::f(int);
365 :
366 : This is invalid; there needs to be one set of template
367 : parameters for each class. */
368 : return tsk_insufficient_parms;
369 244622158 : else if (n_template_parm_scopes == n_class_scopes)
370 : /* We're processing a non-template declaration (even though it may
371 : be a member of a template class.) For example:
372 :
373 : template <class T> void S<T>::f(int);
374 :
375 : The `class T' matches the `S<T>', leaving no template headers
376 : corresponding to the `f'. */
377 : return tsk_none;
378 52772275 : else if (n_template_parm_scopes > n_class_scopes + 1)
379 : /* We've got too many template headers. For example:
380 :
381 : template <> template <class T> void f (T);
382 :
383 : There need to be more enclosing classes. */
384 : return tsk_excessive_parms;
385 : else
386 : /* This must be a template. It's of the form:
387 :
388 : template <class T> template <class U> void S<T>::f(U);
389 :
390 : This is a specialization if the innermost level was a
391 : specialization; otherwise it's just a definition of the
392 : template. */
393 104609573 : return innermost_specialization_p ? tsk_expl_spec : tsk_template;
394 : }
395 :
396 : /* Exit the current scope. */
397 :
398 : void
399 96242358 : finish_scope (void)
400 : {
401 96242358 : poplevel (0, 0, 0);
402 96242358 : }
403 :
404 : /* When a label goes out of scope, check to see if that label was used
405 : in a valid manner, and issue any appropriate warnings or errors. */
406 :
407 : static void
408 20670 : check_label_used (tree label)
409 : {
410 20670 : if (!processing_template_decl)
411 : {
412 20361 : if (DECL_INITIAL (label) == NULL_TREE)
413 : {
414 9 : location_t location;
415 :
416 9 : error ("label %q+D used but not defined", label);
417 9 : location = input_location;
418 : /* FIXME want (LOCATION_FILE (input_location), (line)0) */
419 : /* Avoid crashing later. */
420 9 : define_label (location, DECL_NAME (label));
421 : }
422 : else
423 20352 : warn_for_unused_label (label);
424 : }
425 20670 : }
426 :
427 : /* Helper function to sort named label entries in a vector by DECL_UID. */
428 :
429 : static int
430 232680 : sort_labels (const void *a, const void *b)
431 : {
432 232680 : tree label1 = *(tree const *) a;
433 232680 : tree label2 = *(tree const *) b;
434 :
435 : /* DECL_UIDs can never be equal. */
436 232680 : return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
437 : }
438 :
439 : static void adjust_backward_goto (named_label_entry *, tree_stmt_iterator);
440 : static named_label_entry *lookup_label_1 (tree, bool);
441 :
442 : /* Helper of pop_labels, called through cp_walk_tree. Adjust
443 : LABEL_EXPRs of named labels, if they are targets of backwards
444 : gotos jumping across vacuous initialization for
445 : !!flag_auto_var_init. */
446 :
447 : static tree
448 2909 : adjust_backward_gotos (tree *tp, int *walk_subtrees, void *data)
449 : {
450 2909 : tree t = *tp;
451 2909 : switch (TREE_CODE (t))
452 : {
453 3 : case LABEL_EXPR:
454 : /* In rare cases LABEL_EXPR can appear as the only substatement
455 : of some other statement, e.g. if body etc. In that case, we know
456 : there can't be an older if (0) wrapper with artificial initializers
457 : before it. Replace the LABEL_EXPR statement with a STATEMENT_LIST
458 : and insert the LABEL_EXPR into it, later on if (0) will be added
459 : before that. */
460 3 : if (DECL_NAME (LABEL_EXPR_LABEL (t)))
461 : {
462 3 : named_label_entry *ent
463 3 : = lookup_label_1 (DECL_NAME (LABEL_EXPR_LABEL (t)), false);
464 3 : if (ent->direct_goto)
465 : {
466 3 : *tp = alloc_stmt_list ();
467 3 : append_to_statement_list_force (t, tp);
468 3 : adjust_backward_goto (ent, tsi_last (*tp));
469 : }
470 : }
471 3 : *walk_subtrees = 0;
472 3 : break;
473 141 : case STATEMENT_LIST:
474 141 : {
475 141 : tree_stmt_iterator i;
476 141 : *walk_subtrees = 0;
477 : /* In the common case, LABEL_EXPRs appear inside of a STATEMENT_LIST.
478 : In that case pass the stmt iterator to adjust_backward_goto, so
479 : that it can insert if (0) wrapper artificial initializers before
480 : it or reuse the existing ones. */
481 915 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
482 774 : if (TREE_CODE (tsi_stmt (i)) != LABEL_EXPR)
483 737 : cp_walk_tree (tsi_stmt_ptr (i), adjust_backward_gotos,
484 : data, (hash_set<tree> *) data);
485 37 : else if (DECL_NAME (LABEL_EXPR_LABEL (tsi_stmt (i))))
486 : {
487 16 : named_label_entry *ent
488 16 : = lookup_label_1 (DECL_NAME (LABEL_EXPR_LABEL (tsi_stmt (i))),
489 : false);
490 16 : if (ent->direct_goto)
491 16 : adjust_backward_goto (ent, i);
492 : }
493 141 : break;
494 : }
495 2765 : default:
496 2765 : if (TYPE_P (t))
497 4 : *walk_subtrees = 0;
498 : }
499 2909 : return NULL_TREE;
500 : }
501 :
502 : /* At the end of a function, all labels declared within the function
503 : go out of scope. BLOCK is the top-level block for the
504 : function. */
505 :
506 : static void
507 159098187 : pop_labels (tree block)
508 : {
509 159098187 : if (!named_labels)
510 159093548 : return;
511 :
512 : /* We need to add the labels to the block chain, so debug
513 : information is emitted. But, we want the order to be stable so
514 : need to sort them first. Otherwise the debug output could be
515 : randomly ordered. I guess it's mostly stable, unless the hash
516 : table implementation changes. */
517 4639 : auto_vec<tree, 32> labels (named_labels->elements ());
518 4639 : hash_table<named_label_hash>::iterator end (named_labels->end ());
519 :
520 4639 : if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
521 687 : && !processing_template_decl)
522 : {
523 6158 : for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
524 : {
525 2426 : named_label_entry *ent = *iter;
526 2426 : if (ent->direct_goto)
527 : {
528 4 : hash_set<tree> pset;
529 4 : cp_walk_tree (&DECL_SAVED_TREE (current_function_decl),
530 : adjust_backward_gotos, &pset, &pset);
531 4 : break;
532 4 : }
533 : }
534 : }
535 :
536 45913 : for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
537 : {
538 20637 : named_label_entry *ent = *iter;
539 :
540 20637 : gcc_checking_assert (!ent->outer);
541 20637 : if (ent->label_decl)
542 20451 : labels.quick_push (ent->label_decl);
543 20637 : ggc_free (ent);
544 : }
545 4639 : named_labels = NULL;
546 4639 : labels.qsort (sort_labels);
547 :
548 25090 : while (labels.length ())
549 : {
550 20451 : tree label = labels.pop ();
551 :
552 20451 : DECL_CHAIN (label) = BLOCK_VARS (block);
553 20451 : BLOCK_VARS (block) = label;
554 :
555 20451 : check_label_used (label);
556 : }
557 4639 : }
558 :
559 : /* At the end of a block with local labels, restore the outer definition. */
560 :
561 : static void
562 219 : pop_local_label (tree id, tree label)
563 : {
564 219 : check_label_used (label);
565 219 : named_label_entry **slot = named_labels->find_slot_with_hash
566 219 : (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
567 219 : named_label_entry *ent = *slot;
568 :
569 219 : if (ent->outer)
570 : ent = ent->outer;
571 : else
572 : {
573 198 : ent = ggc_cleared_alloc<named_label_entry> ();
574 198 : ent->name = id;
575 : }
576 219 : *slot = ent;
577 219 : }
578 :
579 : /* The following two routines are used to interface to Objective-C++.
580 : The binding level is purposely treated as an opaque type. */
581 :
582 : void *
583 0 : objc_get_current_scope (void)
584 : {
585 0 : return current_binding_level;
586 : }
587 :
588 : /* The following routine is used by the NeXT-style SJLJ exceptions;
589 : variables get marked 'volatile' so as to not be clobbered by
590 : _setjmp()/_longjmp() calls. All variables in the current scope,
591 : as well as parent scopes up to (but not including) ENCLOSING_BLK
592 : shall be thusly marked. */
593 :
594 : void
595 0 : objc_mark_locals_volatile (void *enclosing_blk)
596 : {
597 0 : cp_binding_level *scope;
598 :
599 0 : for (scope = current_binding_level;
600 0 : scope && scope != enclosing_blk;
601 0 : scope = scope->level_chain)
602 : {
603 0 : tree decl;
604 :
605 0 : for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
606 0 : objc_volatilize_decl (decl);
607 :
608 : /* Do not climb up past the current function. */
609 0 : if (scope->kind == sk_function_parms)
610 : break;
611 : }
612 0 : }
613 :
614 : /* True if B is the level for the condition of a constexpr if. */
615 :
616 : static bool
617 1425482 : level_for_constexpr_if (cp_binding_level *b)
618 : {
619 1421420 : return (b->kind == sk_cond && b->this_entity
620 292 : && TREE_CODE (b->this_entity) == IF_STMT
621 1425774 : && IF_STMT_CONSTEXPR_P (b->this_entity));
622 : }
623 :
624 : /* True if B is the level for the condition of a consteval if. */
625 :
626 : static bool
627 1425458 : level_for_consteval_if (cp_binding_level *b)
628 : {
629 1421396 : return (b->kind == sk_cond && b->this_entity
630 268 : && TREE_CODE (b->this_entity) == IF_STMT
631 1425726 : && IF_STMT_CONSTEVAL_P (b->this_entity));
632 : }
633 :
634 : /* True if T is a non-static VAR_DECL that has a non-trivial destructor.
635 : See [stmt.dcl]/2. */
636 :
637 : static bool
638 25 : automatic_var_with_nontrivial_dtor_p (const_tree t)
639 : {
640 25 : if (error_operand_p (t))
641 : return false;
642 :
643 19 : return (VAR_P (t)
644 19 : && decl_storage_duration (const_cast<tree> (t)) == dk_auto
645 38 : && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
646 : }
647 :
648 : /* Update data for defined and undefined labels when leaving a scope. */
649 :
650 : int
651 155078 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
652 : {
653 155078 : named_label_entry *ent = *slot;
654 155078 : cp_binding_level *obl = bl->level_chain;
655 :
656 155078 : if (ent->binding_level == bl)
657 : {
658 10178 : tree decl;
659 :
660 : /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
661 : TREE_LISTs representing OVERLOADs, so be careful. */
662 15074 : for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
663 4969 : ? DECL_CHAIN (decl)
664 73 : : TREE_CHAIN (decl)))
665 4896 : if (decl_jump_unsafe (decl))
666 : {
667 1872 : vec_safe_push (ent->bad_decls, decl);
668 1872 : ent->has_bad_decls = true;
669 : }
670 3024 : else if (decl_instrument_init_bypass_p (decl))
671 435 : vec_safe_push (ent->bad_decls, decl);
672 :
673 10178 : ent->binding_level = obl;
674 10178 : ent->names_in_scope = obl->names;
675 10178 : switch (bl->kind)
676 : {
677 42 : case sk_try:
678 42 : ent->in_try_scope = true;
679 42 : break;
680 27 : case sk_catch:
681 27 : ent->in_catch_scope = true;
682 27 : break;
683 324 : case sk_omp:
684 324 : ent->in_omp_scope = true;
685 324 : break;
686 3 : case sk_transaction:
687 3 : ent->in_transaction_scope = true;
688 3 : break;
689 45 : case sk_stmt_expr:
690 45 : ent->in_stmt_expr = true;
691 45 : break;
692 4100 : case sk_block:
693 4100 : if (level_for_constexpr_if (obl))
694 15 : ent->in_constexpr_if = true;
695 4085 : else if (level_for_consteval_if (obl))
696 30 : ent->in_consteval_if = true;
697 : break;
698 : default:
699 : break;
700 : }
701 : }
702 144900 : else if (ent->uses)
703 : {
704 : struct named_label_use_entry *use;
705 :
706 22845 : for (use = ent->uses; use ; use = use->next)
707 15527 : if (use->binding_level == bl)
708 : {
709 5981 : if (auto &cg = use->computed_goto)
710 : {
711 57 : if (bl->kind == sk_catch)
712 3 : vec_safe_push (cg, get_identifier ("catch"));
713 66 : for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d))
714 9 : if (automatic_var_with_nontrivial_dtor_p (d))
715 6 : vec_safe_push (cg, d);
716 : }
717 :
718 5981 : use->binding_level = obl;
719 5981 : use->names_in_scope = obl->names;
720 5981 : if (bl->kind == sk_omp)
721 12 : use->in_omp_scope = true;
722 : }
723 : }
724 :
725 155078 : return 1;
726 : }
727 :
728 : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
729 : when errors were reported, except for -Werror-unused-but-set-*. */
730 : static int unused_but_set_errorcount;
731 :
732 : /* Exit a binding level.
733 : Pop the level off, and restore the state of the identifier-decl mappings
734 : that were in effect when this level was entered.
735 :
736 : If KEEP == 1, this level had explicit declarations, so
737 : and create a "block" (a BLOCK node) for the level
738 : to record its declarations and subblocks for symbol table output.
739 :
740 : If FUNCTIONBODY is nonzero, this level is the body of a function,
741 : so create a block as if KEEP were set and also clear out all
742 : label names.
743 :
744 : If REVERSE is nonzero, reverse the order of decls before putting
745 : them into the BLOCK. */
746 :
747 : tree
748 666251768 : poplevel (int keep, int reverse, int functionbody)
749 : {
750 666251768 : tree link;
751 : /* The chain of decls was accumulated in reverse order.
752 : Put it into forward order, just for cleanliness. */
753 666251768 : tree decls;
754 666251768 : tree subblocks;
755 666251768 : tree block;
756 666251768 : tree decl;
757 666251768 : scope_kind kind;
758 :
759 666251768 : auto_cond_timevar tv (TV_NAME_LOOKUP);
760 666252212 : restart:
761 :
762 666252212 : block = NULL_TREE;
763 :
764 666252212 : gcc_assert (current_binding_level->kind != sk_class
765 : && current_binding_level->kind != sk_namespace);
766 :
767 666252212 : if (current_binding_level->kind == sk_cleanup)
768 : functionbody = 0;
769 666252212 : subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
770 :
771 666252212 : gcc_assert (!vec_safe_length (current_binding_level->class_shadowed));
772 :
773 : /* We used to use KEEP == 2 to indicate that the new block should go
774 : at the beginning of the list of blocks at this binding level,
775 : rather than the end. This hack is no longer used. */
776 666252212 : gcc_assert (keep == 0 || keep == 1);
777 :
778 666252212 : if (current_binding_level->keep)
779 8206561 : keep = 1;
780 :
781 : /* Any uses of undefined labels, and any defined labels, now operate
782 : under constraints of next binding contour. */
783 666252212 : if (cfun && !functionbody && named_labels)
784 43502 : named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
785 198580 : (current_binding_level);
786 :
787 : /* Get the decls in the order they were written.
788 : Usually current_binding_level->names is in reverse order.
789 : But parameter decls were previously put in forward order. */
790 :
791 666252212 : decls = current_binding_level->names;
792 666252212 : if (reverse)
793 : {
794 365207218 : decls = nreverse (decls);
795 365207218 : current_binding_level->names = decls;
796 : }
797 :
798 : /* If there were any declarations or structure tags in that level,
799 : or if this level is a function body,
800 : create a BLOCK to record them for the life of this function. */
801 666252212 : block = NULL_TREE;
802 : /* Avoid function body block if possible. */
803 706787008 : if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
804 : keep = 0;
805 625717677 : else if (keep == 1 || functionbody)
806 200293486 : block = make_node (BLOCK);
807 200293486 : if (block != NULL_TREE)
808 : {
809 200293486 : BLOCK_VARS (block) = decls;
810 200293486 : BLOCK_SUBBLOCKS (block) = subblocks;
811 : }
812 :
813 : /* In each subblock, record that this is its superior. */
814 666252212 : if (keep >= 0)
815 747981322 : for (link = subblocks; link; link = BLOCK_CHAIN (link))
816 81729110 : BLOCK_SUPERCONTEXT (link) = block;
817 :
818 : /* Before we remove the declarations first check for unused variables. */
819 666252212 : if ((warn_unused_variable || warn_unused_but_set_variable)
820 6714880 : && current_binding_level->kind != sk_template_parms
821 5655246 : && !processing_template_decl)
822 6468116 : for (tree d = get_local_decls (); d; d = TREE_CHAIN (d))
823 : {
824 : /* There are cases where D itself is a TREE_LIST. See in
825 : push_local_binding where the list of decls returned by
826 : getdecls is built. */
827 3279339 : tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
828 3279339 : decl = strip_using_decl (udecl);
829 :
830 3279339 : tree type = TREE_TYPE (decl);
831 3279339 : if (VAR_P (decl)
832 383999 : && (!TREE_USED (decl) || !DECL_READ_P (decl))
833 3451 : && !DECL_IN_SYSTEM_HEADER (udecl)
834 : /* For structured bindings, consider only real variables, not
835 : subobjects. */
836 3439 : && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
837 3216 : : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
838 : /* Don't warn about name-independent declarations. */
839 896 : && !name_independent_decl_p (decl)
840 740 : && type != error_mark_node
841 3283484 : && (!CLASS_TYPE_P (type)
842 51 : || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
843 3 : || lookup_attribute ("warn_unused",
844 3 : TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
845 : {
846 706 : if (!TREE_USED (decl))
847 : {
848 308 : if (TREE_CODE (udecl) == USING_DECL)
849 3 : warning_at (DECL_SOURCE_LOCATION (udecl),
850 3 : OPT_Wunused_variable,
851 : "unused using-declaration %qD", udecl);
852 305 : else if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
853 3 : warning_at (DECL_SOURCE_LOCATION (decl),
854 3 : OPT_Wunused_variable,
855 : "unused structured binding declaration");
856 : else
857 302 : warning_at (DECL_SOURCE_LOCATION (decl),
858 302 : OPT_Wunused_variable, "unused variable %qD", decl);
859 308 : suppress_warning (decl, OPT_Wunused_variable);
860 : }
861 398 : else if (DECL_CONTEXT (decl) == current_function_decl
862 : // For -Wunused-but-set-variable leave references alone.
863 374 : && !TYPE_REF_P (TREE_TYPE (decl))
864 772 : && errorcount == unused_but_set_errorcount)
865 : {
866 365 : if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
867 12 : warning_at (DECL_SOURCE_LOCATION (decl),
868 12 : OPT_Wunused_but_set_variable_, "structured "
869 : "binding declaration set but not used");
870 : else
871 353 : warning_at (DECL_SOURCE_LOCATION (decl),
872 353 : OPT_Wunused_but_set_variable_,
873 : "variable %qD set but not used", decl);
874 365 : unused_but_set_errorcount = errorcount;
875 : }
876 : }
877 : }
878 :
879 : /* Remove declarations for all the DECLs in this level. */
880 1348778078 : for (link = decls; link; link = TREE_CHAIN (link))
881 : {
882 682525866 : tree name;
883 682525866 : if (TREE_CODE (link) == TREE_LIST)
884 : {
885 13047780 : decl = TREE_VALUE (link);
886 13047780 : name = TREE_PURPOSE (link);
887 13047780 : gcc_checking_assert (name);
888 : }
889 : else
890 : {
891 669478086 : decl = link;
892 669478086 : name = DECL_NAME (decl);
893 : }
894 :
895 : /* Remove the binding. */
896 682525866 : if (TREE_CODE (decl) == LABEL_DECL)
897 219 : pop_local_label (name, decl);
898 : else
899 682525647 : pop_local_binding (name, decl);
900 : }
901 :
902 : /* Restore the IDENTIFIER_TYPE_VALUEs. */
903 666252212 : for (link = current_binding_level->type_shadowed;
904 909040789 : link; link = TREE_CHAIN (link))
905 242788577 : SET_IDENTIFIER_TYPE_VALUE (TREE_PURPOSE (link), TREE_VALUE (link));
906 :
907 : /* There may be OVERLOADs (wrapped in TREE_LISTs) on the BLOCK_VARs
908 : list if a `using' declaration put them there. The debugging
909 : back ends won't understand OVERLOAD, so we remove them here.
910 : Because the BLOCK_VARS are (temporarily) shared with
911 : CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
912 : popped all the bindings. Also remove undeduced 'auto' decls,
913 : which LTO doesn't understand, and can't have been used by anything. */
914 666252212 : if (block)
915 : {
916 200293486 : tree* d;
917 :
918 528342571 : for (d = &BLOCK_VARS (block); *d; )
919 : {
920 328049085 : if (TREE_CODE (*d) == TREE_LIST
921 328049085 : || (!processing_template_decl
922 103815779 : && undeduced_auto_decl (*d)))
923 13047832 : *d = TREE_CHAIN (*d);
924 : else
925 315001253 : d = &DECL_CHAIN (*d);
926 : }
927 : }
928 :
929 : /* If the level being exited is the top level of a function,
930 : check over all the labels. */
931 666252212 : if (functionbody)
932 : {
933 159098187 : if (block)
934 : {
935 : /* Since this is the top level block of a function, the vars are
936 : the function's parameters. Don't leave them in the BLOCK
937 : because they are found in the FUNCTION_DECL instead. */
938 118563652 : BLOCK_VARS (block) = 0;
939 118563652 : pop_labels (block);
940 : }
941 : else
942 40534535 : pop_labels (subblocks);
943 : }
944 :
945 666252212 : kind = current_binding_level->kind;
946 666252212 : if (kind == sk_cleanup)
947 : {
948 444 : tree stmt;
949 :
950 : /* If this is a temporary binding created for a cleanup, then we'll
951 : have pushed a statement list level. Pop that, create a new
952 : BIND_EXPR for the block, and insert it into the stream. */
953 444 : stmt = pop_stmt_list (current_binding_level->statement_list);
954 444 : stmt = c_build_bind_expr (input_location, block, stmt);
955 444 : add_stmt (stmt);
956 : }
957 :
958 666252212 : leave_scope ();
959 666252212 : if (functionbody)
960 : {
961 : /* The current function is being defined, so its DECL_INITIAL
962 : should be error_mark_node. */
963 159098187 : gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
964 199632722 : DECL_INITIAL (current_function_decl) = block ? block : subblocks;
965 159098187 : if (subblocks)
966 : {
967 76968428 : if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
968 50234767 : && BLOCK_SUBBLOCKS (subblocks))
969 1259209 : BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
970 : else
971 39275587 : BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
972 : }
973 : }
974 507154025 : else if (block)
975 81729834 : current_binding_level->blocks
976 163459668 : = block_chainon (current_binding_level->blocks, block);
977 :
978 : /* If we did not make a block for the level just exited,
979 : any blocks made for inner levels
980 : (since they cannot be recorded as subblocks in that level)
981 : must be carried forward so they will later become subblocks
982 : of something else. */
983 425424191 : else if (subblocks)
984 18 : current_binding_level->blocks
985 36 : = block_chainon (current_binding_level->blocks, subblocks);
986 :
987 : /* Each and every BLOCK node created here in `poplevel' is important
988 : (e.g. for proper debugging information) so if we created one
989 : earlier, mark it as "used". */
990 666252212 : if (block)
991 200293486 : TREE_USED (block) = 1;
992 :
993 : /* All temporary bindings created for cleanups are popped silently. */
994 666252212 : if (kind == sk_cleanup)
995 444 : goto restart;
996 :
997 1332503536 : return block;
998 666251768 : }
999 :
1000 : /* Call wrapup_globals_declarations for the globals in NAMESPACE. */
1001 : /* Diagnose odr-used extern inline variables without definitions
1002 : in the current TU. */
1003 :
1004 : int
1005 142195 : wrapup_namespace_globals ()
1006 : {
1007 142195 : if (vec<tree, va_gc> *statics = static_decls)
1008 : {
1009 17368062 : for (tree decl : *statics)
1010 : {
1011 17251395 : if (warn_unused_function
1012 998137 : && TREE_CODE (decl) == FUNCTION_DECL
1013 748888 : && DECL_INITIAL (decl) == 0
1014 7583 : && DECL_EXTERNAL (decl)
1015 7571 : && !TREE_PUBLIC (decl)
1016 32 : && !DECL_ARTIFICIAL (decl)
1017 32 : && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
1018 9 : && !warning_suppressed_p (decl, OPT_Wunused)
1019 18249532 : && warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_function,
1020 : "%qF declared %<static%> but never defined",
1021 : decl))
1022 6 : suppress_warning (decl, OPT_Wunused);
1023 :
1024 17251395 : if (VAR_P (decl)
1025 5784504 : && DECL_EXTERNAL (decl)
1026 2005625 : && DECL_INLINE_VAR_P (decl)
1027 17251424 : && DECL_ODR_USED (decl))
1028 3 : error_at (DECL_SOURCE_LOCATION (decl),
1029 : "odr-used inline variable %qD is not defined", decl);
1030 : }
1031 :
1032 : /* Clear out the list, so we don't rescan next time. */
1033 116667 : static_decls = NULL;
1034 :
1035 : /* Write out any globals that need to be output. */
1036 116667 : return wrapup_global_declarations (statics->address (),
1037 116667 : statics->length ());
1038 : }
1039 : return 0;
1040 : }
1041 :
1042 : /* In C++, you don't have to write `struct S' to refer to `S'; you
1043 : can just use `S'. We accomplish this by creating a TYPE_DECL as
1044 : if the user had written `typedef struct S S'. Create and return
1045 : the TYPE_DECL for TYPE. */
1046 :
1047 : tree
1048 180146582 : create_implicit_typedef (tree name, tree type)
1049 : {
1050 180146582 : tree decl;
1051 :
1052 180146582 : decl = build_decl (input_location, TYPE_DECL, name, type);
1053 180146582 : DECL_ARTIFICIAL (decl) = 1;
1054 : /* There are other implicit type declarations, like the one *within*
1055 : a class that allows you to write `S::S'. We must distinguish
1056 : amongst these. */
1057 180146582 : SET_DECL_IMPLICIT_TYPEDEF_P (decl);
1058 180146582 : TYPE_NAME (type) = decl;
1059 180146582 : TYPE_STUB_DECL (type) = decl;
1060 :
1061 180146582 : return decl;
1062 : }
1063 :
1064 : /* Function-scope local entities that need discriminators. Each entry
1065 : is a {decl,name} pair. VAR_DECLs for anon unions get their name
1066 : smashed, so we cannot rely on DECL_NAME. */
1067 :
1068 : static GTY((deletable)) vec<tree, va_gc> *local_entities;
1069 :
1070 : /* Determine the mangling discriminator of local DECL. There are
1071 : generally very few of these in any particular function. */
1072 :
1073 : void
1074 718182 : determine_local_discriminator (tree decl, tree name)
1075 : {
1076 718182 : auto_cond_timevar tv (TV_NAME_LOOKUP);
1077 718182 : retrofit_lang_decl (decl);
1078 718182 : tree ctx = DECL_CONTEXT (decl);
1079 718182 : size_t nelts = vec_safe_length (local_entities);
1080 718182 : if (name == NULL_TREE)
1081 717919 : name = (TREE_CODE (decl) == TYPE_DECL
1082 1167034 : && TYPE_UNNAMED_P (TREE_TYPE (decl))
1083 1297401 : ? NULL_TREE : DECL_NAME (decl));
1084 21042236 : for (size_t i = 0; i < nelts; i += 2)
1085 : {
1086 20324531 : tree *pair = &(*local_entities)[i];
1087 20324531 : tree d = pair[0];
1088 20324531 : tree n = pair[1];
1089 20324531 : gcc_checking_assert (d != decl);
1090 20324531 : if (name == n
1091 3577531 : && TREE_CODE (decl) == TREE_CODE (d)
1092 23902053 : && ctx == DECL_CONTEXT (d))
1093 : {
1094 477 : tree disc = integer_one_node;
1095 477 : if (DECL_DISCRIMINATOR (d))
1096 250 : disc = build_int_cst (TREE_TYPE (disc),
1097 250 : TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
1098 477 : DECL_DISCRIMINATOR (decl) = disc;
1099 : /* Replace the saved decl. */
1100 477 : pair[0] = decl;
1101 477 : decl = NULL_TREE;
1102 477 : break;
1103 : }
1104 : }
1105 :
1106 718182 : if (decl)
1107 : {
1108 717705 : vec_safe_reserve (local_entities, 2);
1109 717705 : local_entities->quick_push (decl);
1110 717705 : local_entities->quick_push (name);
1111 : }
1112 718182 : }
1113 :
1114 :
1115 : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
1116 :
1117 : A non-template friend declaration with a requires-clause shall be a
1118 : definition. A friend function template with a constraint that depends on a
1119 : template parameter from an enclosing template shall be a definition. Such a
1120 : constrained friend function or function template declaration does not
1121 : declare the same function or function template as a declaration in any other
1122 : scope.
1123 :
1124 : The ABI calls this a "member-like constrained friend" and mangles it like a
1125 : member function to avoid collisions. */
1126 :
1127 : bool
1128 2434393065 : member_like_constrained_friend_p (tree decl)
1129 : {
1130 2434393065 : return (TREE_CODE (decl) == FUNCTION_DECL
1131 804139124 : && DECL_UNIQUE_FRIEND_P (decl)
1132 192121474 : && DECL_FRIEND_CONTEXT (decl)
1133 78964559 : && get_constraints (decl)
1134 6151710 : && CLASSTYPE_IMPLICIT_INSTANTIATION (DECL_FRIEND_CONTEXT (decl))
1135 2437461685 : && (!DECL_TEMPLATE_INFO (decl)
1136 3068620 : || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
1137 6454 : || (uses_outer_template_parms_in_constraints
1138 6454 : (most_general_template (decl)))));
1139 : }
1140 :
1141 : /* Returns true if functions FN1 and FN2 have equivalent trailing
1142 : requires clauses. */
1143 :
1144 : static bool
1145 69295364 : function_requirements_equivalent_p (tree newfn, tree oldfn)
1146 : {
1147 : /* [temp.friend]/9 "Such a constrained friend function does not declare the
1148 : same function as a declaration in any other scope." So no need to
1149 : actually compare the requirements. */
1150 69295364 : if (member_like_constrained_friend_p (newfn)
1151 69295364 : || member_like_constrained_friend_p (oldfn))
1152 97 : return false;
1153 :
1154 : /* Compare only trailing requirements. */
1155 69295267 : tree reqs1 = get_trailing_function_requirements (newfn);
1156 69295267 : tree reqs2 = get_trailing_function_requirements (oldfn);
1157 69295267 : if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
1158 : return false;
1159 :
1160 : /* Substitution is needed when friends are involved. */
1161 69170886 : reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
1162 69170886 : reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
1163 :
1164 69170886 : return cp_tree_equal (reqs1, reqs2);
1165 : }
1166 :
1167 : /* Two functions of the same name correspond [basic.scope.scope] if
1168 :
1169 : + both declare functions with the same non-object-parameter-type-list,
1170 : equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
1171 : specified in [temp.friend]), and, if both are non-static members, they have
1172 : corresponding object parameters, or
1173 :
1174 : + both declare function templates with equivalent
1175 : non-object-parameter-type-lists, return types (if any), template-heads, and
1176 : trailing requires-clauses (if any), and, if both are non-static members,
1177 : they have corresponding object parameters.
1178 :
1179 : This is a subset of decls_match: it identifies declarations that cannot be
1180 : overloaded with one another. This function does not consider DECL_NAME. */
1181 :
1182 : bool
1183 1523608328 : fns_correspond (tree newdecl, tree olddecl)
1184 : {
1185 1523608328 : if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
1186 : return false;
1187 :
1188 1413914675 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1189 : {
1190 1412559430 : if (!template_heads_equivalent_p (newdecl, olddecl))
1191 : return 0;
1192 336865798 : newdecl = DECL_TEMPLATE_RESULT (newdecl);
1193 336865798 : olddecl = DECL_TEMPLATE_RESULT (olddecl);
1194 : }
1195 :
1196 338221043 : tree f1 = TREE_TYPE (newdecl);
1197 338221043 : tree f2 = TREE_TYPE (olddecl);
1198 :
1199 338221043 : int rq1 = type_memfn_rqual (f1);
1200 338221043 : int rq2 = type_memfn_rqual (f2);
1201 :
1202 : /* If only one is a non-static member function, ignore ref-quals. */
1203 338221043 : if (TREE_CODE (f1) != TREE_CODE (f2))
1204 : rq1 = rq2;
1205 : /* Two non-static member functions have corresponding object parameters if:
1206 : + exactly one is an implicit object member function with no ref-qualifier
1207 : and the types of their object parameters ([dcl.fct]), after removing
1208 : top-level references, are the same, or
1209 : + their object parameters have the same type. */
1210 : /* ??? We treat member functions of different classes as corresponding even
1211 : though that means the object parameters have different types. */
1212 338221043 : else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
1213 0 : rq1 = rq2;
1214 :
1215 338221043 : bool types_match = rq1 == rq2;
1216 :
1217 338221043 : if (types_match)
1218 : {
1219 338221043 : tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1220 338221043 : tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
1221 338221043 : types_match = compparms (p1, p2);
1222 : }
1223 :
1224 : /* Two function declarations match if either has a requires-clause
1225 : then both have a requires-clause and their constraints-expressions
1226 : are equivalent. */
1227 338221043 : if (types_match && flag_concepts)
1228 41330075 : types_match = function_requirements_equivalent_p (newdecl, olddecl);
1229 :
1230 : return types_match;
1231 : }
1232 :
1233 : /* Subroutine of duplicate_decls: return truthvalue of whether
1234 : or not types of these decls match.
1235 :
1236 : For C++, we must compare the parameter list so that `int' can match
1237 : `int&' in a parameter position, but `int&' is not confused with
1238 : `const int&'. */
1239 :
1240 : int
1241 804388602 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
1242 : {
1243 804388602 : int types_match;
1244 :
1245 804388602 : if (newdecl == olddecl)
1246 : return 1;
1247 :
1248 804300392 : if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
1249 : /* If the two DECLs are not even the same kind of thing, we're not
1250 : interested in their types. */
1251 : return 0;
1252 :
1253 413203920 : gcc_assert (DECL_P (newdecl));
1254 :
1255 413203920 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
1256 : {
1257 : /* Specializations of different templates are different functions
1258 : even if they have the same type. */
1259 263919944 : tree t1 = (DECL_USE_TEMPLATE (newdecl)
1260 263919944 : ? DECL_TI_TEMPLATE (newdecl)
1261 636368 : : NULL_TREE);
1262 263919944 : tree t2 = (DECL_USE_TEMPLATE (olddecl)
1263 263919944 : ? DECL_TI_TEMPLATE (olddecl)
1264 3983229 : : NULL_TREE);
1265 263919944 : if (t1 != t2)
1266 : return 0;
1267 :
1268 260573013 : if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1269 263484146 : && ! (DECL_EXTERN_C_P (newdecl)
1270 2911133 : && DECL_EXTERN_C_P (olddecl)))
1271 : return 0;
1272 :
1273 : /* A new declaration doesn't match a built-in one unless it
1274 : is also extern "C". */
1275 239637827 : if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
1276 239637827 : && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
1277 : return 0;
1278 :
1279 238995514 : tree f1 = TREE_TYPE (newdecl);
1280 238995514 : tree f2 = TREE_TYPE (olddecl);
1281 238995514 : if (TREE_CODE (f1) != TREE_CODE (f2))
1282 : return 0;
1283 :
1284 : /* A declaration with deduced return type should use its pre-deduction
1285 : type for declaration matching. */
1286 238825471 : tree r2 = fndecl_declared_return_type (olddecl);
1287 238825471 : tree r1 = fndecl_declared_return_type (newdecl);
1288 :
1289 : /* For memchr et al, allow const void* return type (as specified by C++)
1290 : when we expect void* (as in C). */
1291 238825471 : if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
1292 6395523 : && DECL_EXTERN_C_P (olddecl)
1293 3958319 : && !same_type_p (r1, r2)
1294 70 : && TREE_CODE (r1) == POINTER_TYPE
1295 15 : && TREE_CODE (r2) == POINTER_TYPE
1296 238825483 : && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
1297 : r2 = r1;
1298 :
1299 238825471 : tree p1 = TYPE_ARG_TYPES (f1);
1300 238825471 : tree p2 = TYPE_ARG_TYPES (f2);
1301 :
1302 238825471 : if (same_type_p (r1, r2))
1303 : {
1304 164289996 : if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
1305 164289968 : && fndecl_built_in_p (olddecl))
1306 : {
1307 50 : types_match = self_promoting_args_p (p1);
1308 50 : if (p1 == void_list_node)
1309 3 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
1310 : }
1311 : else
1312 164289862 : types_match =
1313 164289862 : compparms (p1, p2)
1314 28459588 : && type_memfn_rqual (f1) == type_memfn_rqual (f2)
1315 192749152 : && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
1316 1210988 : || comp_type_attributes (TREE_TYPE (newdecl),
1317 1210988 : TREE_TYPE (olddecl)) != 0);
1318 : }
1319 : else
1320 : types_match = 0;
1321 :
1322 : /* Two function declarations match if either has a requires-clause
1323 : then both have a requires-clause and their constraints-expressions
1324 : are equivalent. */
1325 28459319 : if (types_match && flag_concepts)
1326 27965260 : types_match = function_requirements_equivalent_p (newdecl, olddecl);
1327 :
1328 : /* The decls dont match if they correspond to two different versions
1329 : of the same function. Disallow extern "C" functions to be
1330 : versions for now. */
1331 28459319 : if (types_match
1332 28271564 : && !DECL_EXTERN_C_P (newdecl)
1333 20607921 : && !DECL_EXTERN_C_P (olddecl)
1334 49063254 : && disjoint_version_decls (newdecl, olddecl))
1335 : {
1336 8850 : if (record_versions)
1337 8763 : maybe_version_functions (newdecl, olddecl);
1338 8850 : return 0;
1339 : }
1340 : }
1341 149283976 : else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1342 : {
1343 147562260 : if (!template_heads_equivalent_p (newdecl, olddecl))
1344 : return 0;
1345 :
1346 48629979 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1347 48629979 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
1348 :
1349 48629979 : if (TREE_CODE (newres) != TREE_CODE (oldres))
1350 : return 0;
1351 :
1352 : /* Two template types match if they are the same. Otherwise, compare
1353 : the underlying declarations. */
1354 48629973 : if (TREE_CODE (newres) == TYPE_DECL)
1355 30 : types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
1356 : else
1357 48629943 : types_match = decls_match (newres, oldres);
1358 : }
1359 : else
1360 : {
1361 : /* Need to check scope for variable declaration (VAR_DECL).
1362 : For typedef (TYPE_DECL), scope is ignored. */
1363 1721716 : if (VAR_P (newdecl)
1364 1179679 : && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1365 : /* [dcl.link]
1366 : Two declarations for an object with C language linkage
1367 : with the same name (ignoring the namespace that qualify
1368 : it) that appear in different namespace scopes refer to
1369 : the same object. */
1370 1908112 : && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
1371 : return 0;
1372 :
1373 1535368 : if (TREE_TYPE (newdecl) == error_mark_node)
1374 0 : types_match = TREE_TYPE (olddecl) == error_mark_node;
1375 1535368 : else if (TREE_TYPE (olddecl) == NULL_TREE)
1376 0 : types_match = TREE_TYPE (newdecl) == NULL_TREE;
1377 1535368 : else if (TREE_TYPE (newdecl) == NULL_TREE)
1378 : types_match = 0;
1379 : else
1380 1535368 : types_match = comptypes (TREE_TYPE (newdecl),
1381 1535368 : TREE_TYPE (olddecl),
1382 : COMPARE_REDECLARATION);
1383 : }
1384 :
1385 : return types_match;
1386 : }
1387 :
1388 : /* Mark DECL as versioned if it isn't already. */
1389 :
1390 : void
1391 17616 : maybe_mark_function_versioned (tree decl)
1392 : {
1393 17616 : if (!DECL_FUNCTION_VERSIONED (decl))
1394 : {
1395 : /* We need to insert function version now to make sure the correct
1396 : pre-mangled assembler name is recorded. */
1397 1053 : cgraph_node *node = cgraph_node::get_create (decl);
1398 :
1399 1053 : if (!node->function_version ())
1400 1053 : node->insert_new_function_version ();
1401 :
1402 1053 : DECL_FUNCTION_VERSIONED (decl) = 1;
1403 : /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
1404 : to include the version marker. */
1405 1053 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
1406 1047 : mangle_decl (decl);
1407 : }
1408 17616 : }
1409 :
1410 : /* NEWDECL and OLDDECL have identical signatures. If they are
1411 : different versions adjust them, record function versions, and return
1412 : true. */
1413 :
1414 : bool
1415 198202 : maybe_version_functions (tree newdecl, tree olddecl)
1416 : {
1417 198202 : if (!disjoint_version_decls (newdecl, olddecl))
1418 : return false;
1419 :
1420 8790 : maybe_mark_function_versioned (olddecl);
1421 8790 : if (DECL_LOCAL_DECL_P (olddecl))
1422 : {
1423 18 : olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
1424 18 : maybe_mark_function_versioned (olddecl);
1425 : }
1426 :
1427 8790 : maybe_mark_function_versioned (newdecl);
1428 8790 : if (DECL_LOCAL_DECL_P (newdecl))
1429 : {
1430 : /* Unfortunately, we can get here before pushdecl naturally calls
1431 : push_local_extern_decl_alias, so we need to call it directly. */
1432 18 : if (!DECL_LOCAL_DECL_ALIAS (newdecl))
1433 6 : push_local_extern_decl_alias (newdecl);
1434 18 : newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
1435 18 : maybe_mark_function_versioned (newdecl);
1436 : }
1437 :
1438 : /* Add the new version to the function version structure. */
1439 8790 : cgraph_node *fn_node = cgraph_node::get_create (olddecl);
1440 8790 : cgraph_function_version_info *fn_v = fn_node->function_version ();
1441 8790 : if (!fn_v)
1442 15 : fn_v = fn_node->insert_new_function_version ();
1443 :
1444 8790 : cgraph_node::add_function_version (fn_v, newdecl);
1445 :
1446 8790 : return true;
1447 : }
1448 :
1449 : /* If NEWDECL is `static' and an `extern' was seen previously,
1450 : warn about it. OLDDECL is the previous declaration.
1451 :
1452 : Note that this does not apply to the C++ case of declaring
1453 : a variable `extern const' and then later `const'.
1454 :
1455 : Don't complain about built-in functions, since they are beyond
1456 : the user's control. */
1457 :
1458 : void
1459 19370188 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
1460 : {
1461 19370188 : if (TREE_CODE (newdecl) == TYPE_DECL
1462 19323675 : || TREE_CODE (newdecl) == TEMPLATE_DECL
1463 15396729 : || TREE_CODE (newdecl) == CONST_DECL
1464 15396729 : || TREE_CODE (newdecl) == NAMESPACE_DECL)
1465 19370176 : return;
1466 :
1467 : /* Don't get confused by static member functions; that's a different
1468 : use of `static'. */
1469 15396729 : if (TREE_CODE (newdecl) == FUNCTION_DECL
1470 15396729 : && DECL_STATIC_FUNCTION_P (newdecl))
1471 : return;
1472 :
1473 : /* If the old declaration was `static', or the new one isn't, then
1474 : everything is OK. */
1475 15225177 : if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
1476 : return;
1477 :
1478 : /* It's OK to declare a builtin function as `static'. */
1479 12 : if (TREE_CODE (olddecl) == FUNCTION_DECL
1480 12 : && DECL_ARTIFICIAL (olddecl))
1481 : return;
1482 :
1483 12 : auto_diagnostic_group d;
1484 12 : if (permerror (DECL_SOURCE_LOCATION (newdecl),
1485 : "%qD was declared %<extern%> and later %<static%>", newdecl))
1486 12 : inform (DECL_SOURCE_LOCATION (olddecl),
1487 : "previous declaration of %qD", olddecl);
1488 12 : }
1489 :
1490 : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
1491 : function templates. If their exception specifications do not
1492 : match, issue a diagnostic. */
1493 :
1494 : static void
1495 18827584 : check_redeclaration_exception_specification (tree new_decl,
1496 : tree old_decl)
1497 : {
1498 18827584 : tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
1499 18827584 : tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
1500 :
1501 : /* Two default specs are equivalent, don't force evaluation. */
1502 7176210 : if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
1503 18971670 : && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
1504 : return;
1505 :
1506 18817877 : if (!type_dependent_expression_p (old_decl))
1507 : {
1508 11500726 : maybe_instantiate_noexcept (new_decl);
1509 11500726 : maybe_instantiate_noexcept (old_decl);
1510 : }
1511 18817877 : new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
1512 18817877 : old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
1513 :
1514 : /* [except.spec]
1515 :
1516 : If any declaration of a function has an exception-specification,
1517 : all declarations, including the definition and an explicit
1518 : specialization, of that function shall have an
1519 : exception-specification with the same set of type-ids. */
1520 18817877 : if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
1521 14980476 : && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
1522 33798210 : && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
1523 : {
1524 326 : const char *const msg
1525 : = G_("declaration of %qF has a different exception specifier");
1526 326 : bool complained = true;
1527 326 : location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
1528 326 : auto_diagnostic_group d;
1529 :
1530 : /* Be permissive about C++98 vs C++11 operator new declarations. */
1531 652 : bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
1532 1 : && CP_DECL_CONTEXT (new_decl) == global_namespace
1533 328 : && (nothrow_spec_p (new_exceptions)
1534 1 : == nothrow_spec_p (old_exceptions)));
1535 :
1536 326 : if (DECL_IN_SYSTEM_HEADER (old_decl)
1537 326 : && (global_new || DECL_EXTERN_C_P (old_decl)))
1538 : /* Don't fuss about the C library; the C library functions are not
1539 : specified to have exception specifications (just behave as if they
1540 : have them), but some implementations include them. */
1541 233 : complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
1542 93 : else if (!flag_exceptions)
1543 : /* We used to silently permit mismatched eh specs with
1544 : -fno-exceptions, so only complain if -pedantic. */
1545 3 : complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
1546 90 : else if (!new_exceptions || global_new)
1547 : /* Reduce to pedwarn for omitted exception specification. No warning
1548 : flag for this; silence the warning by correcting the code. */
1549 21 : complained = pedwarn (new_loc, 0, msg, new_decl);
1550 : else
1551 69 : error_at (new_loc, msg, new_decl);
1552 :
1553 326 : if (complained)
1554 96 : inform (DECL_SOURCE_LOCATION (old_decl),
1555 : "from previous declaration %qF", old_decl);
1556 :
1557 : /* Copy the old exception specification if new_decl has none. Unless the
1558 : old decl is extern "C", as obscure code might depend on the type of
1559 : the new declaration (e.g. noexcept-type19.C). */
1560 326 : if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
1561 20 : TREE_TYPE (new_decl)
1562 40 : = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
1563 326 : }
1564 : }
1565 :
1566 : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
1567 : Otherwise issue diagnostics. */
1568 :
1569 : bool
1570 19370697 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
1571 : {
1572 19370697 : old_decl = STRIP_TEMPLATE (old_decl);
1573 19370697 : new_decl = STRIP_TEMPLATE (new_decl);
1574 19370697 : if (!VAR_OR_FUNCTION_DECL_P (old_decl)
1575 19324160 : || !VAR_OR_FUNCTION_DECL_P (new_decl))
1576 : return true;
1577 19324160 : if (DECL_DECLARED_CONSTEXPR_P (old_decl)
1578 19324160 : == DECL_DECLARED_CONSTEXPR_P (new_decl))
1579 : {
1580 19180096 : if (TREE_CODE (old_decl) != FUNCTION_DECL)
1581 : return true;
1582 37655980 : if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1583 18827990 : == DECL_IMMEDIATE_FUNCTION_P (new_decl))
1584 : return true;
1585 : }
1586 144070 : if (TREE_CODE (old_decl) == FUNCTION_DECL)
1587 : {
1588 : /* With -fimplicit-constexpr, ignore changes in the constexpr
1589 : keyword. */
1590 69 : if (flag_implicit_constexpr
1591 69 : && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
1592 0 : == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
1593 : return true;
1594 69 : if (fndecl_built_in_p (old_decl))
1595 : {
1596 : /* Hide a built-in declaration. */
1597 0 : DECL_DECLARED_CONSTEXPR_P (old_decl)
1598 0 : = DECL_DECLARED_CONSTEXPR_P (new_decl);
1599 0 : if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
1600 0 : SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
1601 0 : return true;
1602 : }
1603 : /* 7.1.5 [dcl.constexpr]
1604 : Note: An explicit specialization can differ from the template
1605 : declaration with respect to the constexpr specifier. */
1606 69 : if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
1607 69 : && DECL_TEMPLATE_SPECIALIZATION (new_decl))
1608 : return true;
1609 :
1610 42 : const char *kind = "constexpr";
1611 42 : if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1612 72 : || DECL_IMMEDIATE_FUNCTION_P (new_decl))
1613 : kind = "consteval";
1614 42 : auto_diagnostic_group d;
1615 42 : error_at (DECL_SOURCE_LOCATION (new_decl),
1616 : "redeclaration %qD differs in %qs "
1617 : "from previous declaration", new_decl,
1618 : kind);
1619 42 : inform (DECL_SOURCE_LOCATION (old_decl),
1620 : "previous declaration %qD", old_decl);
1621 42 : return false;
1622 42 : }
1623 : return true;
1624 : }
1625 :
1626 : /* DECL is a redeclaration of a function or function template. If
1627 : it does have default arguments issue a diagnostic. Note: this
1628 : function is used to enforce the requirements in C++11 8.3.6 about
1629 : no default arguments in redeclarations. */
1630 :
1631 : static void
1632 11318674 : check_redeclaration_no_default_args (tree decl)
1633 : {
1634 11318674 : gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
1635 :
1636 11318674 : for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
1637 33372739 : t && t != void_list_node; t = TREE_CHAIN (t))
1638 22054122 : if (TREE_PURPOSE (t))
1639 : {
1640 57 : permerror (DECL_SOURCE_LOCATION (decl),
1641 : "redeclaration of %q#D may not have default "
1642 : "arguments", decl);
1643 57 : return;
1644 : }
1645 : }
1646 :
1647 : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
1648 : in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
1649 : the TEMPLATE_DECLs in case of function templates). This function is used
1650 : to enforce the final part of C++17 11.3.6/4, about a single declaration:
1651 : "If a friend declaration specifies a default argument expression, that
1652 : declaration shall be a definition and shall be the only declaration of
1653 : the function or function template in the translation unit." */
1654 :
1655 : static void
1656 6917299 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
1657 : {
1658 13135001 : if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
1659 : return;
1660 :
1661 3456856 : for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
1662 1728428 : t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1663 4588754 : t1 && t1 != void_list_node;
1664 2860326 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1665 4110616 : if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
1666 8146625 : || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
1667 : {
1668 36 : auto_diagnostic_group d;
1669 36 : if (permerror (DECL_SOURCE_LOCATION (newdecl),
1670 : "friend declaration of %q#D specifies default "
1671 : "arguments and isn%'t the only declaration", newdecl))
1672 36 : inform (DECL_SOURCE_LOCATION (olddecl),
1673 : "previous declaration of %q#D", olddecl);
1674 36 : return;
1675 36 : }
1676 : }
1677 :
1678 : /* Merge tree bits that correspond to attributes noreturn, nothrow,
1679 : const, malloc, and pure from NEWDECL with those of OLDDECL. */
1680 :
1681 : static void
1682 18270090 : merge_attribute_bits (tree newdecl, tree olddecl)
1683 : {
1684 18270090 : TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1685 18270090 : TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
1686 18270090 : TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
1687 18270090 : TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
1688 18270090 : TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1689 18270090 : TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
1690 18270090 : DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1691 18270090 : DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
1692 18270090 : DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1693 18270090 : DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
1694 18270090 : DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
1695 18270090 : DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
1696 18270090 : TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
1697 18270090 : TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
1698 18270090 : TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
1699 18270090 : TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
1700 18270090 : }
1701 :
1702 : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn) \
1703 : && lookup_attribute ("gnu_inline", \
1704 : DECL_ATTRIBUTES (fn)))
1705 :
1706 : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
1707 : ambiguates olddecl. Returns true if an error occurs. */
1708 :
1709 : static bool
1710 143635158 : duplicate_function_template_decls (tree newdecl, tree olddecl)
1711 : {
1712 143635158 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
1713 143635158 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1714 : /* Function template declarations can be differentiated by parameter
1715 : and return type. */
1716 143635158 : if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
1717 143635158 : TYPE_ARG_TYPES (TREE_TYPE (newres)))
1718 143635158 : && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
1719 : TREE_TYPE (TREE_TYPE (olddecl))))
1720 : {
1721 : /* ... and also by their template-heads and requires-clauses. */
1722 6613 : if (template_heads_equivalent_p (newdecl, olddecl)
1723 6613 : && function_requirements_equivalent_p (newres, oldres))
1724 : {
1725 0 : auto_diagnostic_group d;
1726 0 : error ("ambiguating new declaration %q+#D", newdecl);
1727 0 : inform (DECL_SOURCE_LOCATION (olddecl),
1728 : "old declaration %q#D", olddecl);
1729 0 : return true;
1730 0 : }
1731 :
1732 : /* FIXME: The types are the same but the are differences
1733 : in either the template heads or function requirements.
1734 : We should be able to diagnose a set of common errors
1735 : stemming from these declarations. For example:
1736 :
1737 : template<typename T> requires C void f(...);
1738 : template<typename T> void f(...) requires C;
1739 :
1740 : These are functionally equivalent but not equivalent. */
1741 : }
1742 :
1743 : return false;
1744 : }
1745 :
1746 : /* OLD_PARMS is the innermost set of template parameters for some template
1747 : declaration, and NEW_PARMS is the corresponding set of template parameters
1748 : for a redeclaration of that template. Merge the default arguments within
1749 : these two sets of parameters. CLASS_P is true iff the template in
1750 : question is a class template. */
1751 :
1752 : bool
1753 8688067 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
1754 : {
1755 8688067 : gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
1756 : == TREE_VEC_LENGTH (old_parms));
1757 24570408 : for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
1758 : {
1759 15882371 : tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
1760 15882371 : tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
1761 15882371 : tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
1762 15882371 : tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
1763 15882371 : if (error_operand_p (new_parm) || error_operand_p (old_parm))
1764 : return false;
1765 15882368 : if (new_default != NULL_TREE && old_default != NULL_TREE)
1766 : {
1767 27 : auto_diagnostic_group d;
1768 27 : error ("redefinition of default argument for %q+#D", new_parm);
1769 27 : inform (DECL_SOURCE_LOCATION (old_parm),
1770 : "original definition appeared here");
1771 27 : return false;
1772 27 : }
1773 15882341 : else if (new_default != NULL_TREE)
1774 : /* Update the previous template parameters (which are the ones
1775 : that will really count) with the new default value. */
1776 207742 : old_default = new_default;
1777 15674599 : else if (class_p && old_default != NULL_TREE)
1778 : /* Update the new parameters, too; they'll be used as the
1779 : parameters for any members. */
1780 1083233 : new_default = old_default;
1781 : }
1782 : return true;
1783 : }
1784 :
1785 : /* Helper function for duplicate_decls and push_local_extern_decl_alias.
1786 : Merge parameter attributes and names between NEWDECL and OLDDECL.
1787 : NEW_DEFINES_FUNCTION and TYPES_MATCH argument like variables in
1788 : duplicate_decls, EXTERN_ALIAS false for duplicate_decls and true for
1789 : push_local_extern_decl_alias. */
1790 :
1791 : void
1792 14901071 : merge_decl_arguments (tree newdecl, tree olddecl, bool new_defines_function,
1793 : bool types_match, bool extern_alias)
1794 : {
1795 14901071 : tree oldarg, newarg, type = NULL_TREE;
1796 14901071 : tree first_user_parm = NULL_TREE;
1797 14901071 : if (extern_alias)
1798 178 : first_user_parm = FUNCTION_FIRST_USER_PARM (newdecl);
1799 14901071 : for (oldarg = DECL_ARGUMENTS (olddecl), newarg = DECL_ARGUMENTS (newdecl);
1800 41713158 : oldarg && newarg;
1801 26812087 : oldarg = DECL_CHAIN (oldarg), newarg = DECL_CHAIN (newarg))
1802 : {
1803 26812087 : DECL_ATTRIBUTES (newarg)
1804 26812087 : = (*targetm.merge_decl_attributes) (oldarg, newarg);
1805 26812087 : if (lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (newarg))
1806 26812156 : && !lookup_attribute (NULL, "indeterminate",
1807 69 : DECL_ATTRIBUTES (oldarg)))
1808 : {
1809 18 : auto_diagnostic_group d;
1810 18 : error_at (DECL_SOURCE_LOCATION (newarg),
1811 : "%<indeterminate%> attribute not specified for parameter "
1812 : "%qD on the first declaration of its function", newarg);
1813 18 : inform (DECL_SOURCE_LOCATION (oldarg), "earlier declaration");
1814 18 : }
1815 : /* ??? Should attributes propagate out from a block extern? If so,
1816 : we should do that for the function itself, not just parameters. */
1817 26812087 : if (!extern_alias || flag_reflection)
1818 26811924 : DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1819 26812087 : if (!flag_reflection)
1820 26641622 : continue;
1821 : /* For extern_alias set DECL_HAS_DEFAULT_ARGUMENT_P on oldarg
1822 : if the local extern has a default argument for that parameter. */
1823 170465 : if (extern_alias)
1824 : {
1825 17 : if (newarg == first_user_parm)
1826 5 : type = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1827 12 : else if (type)
1828 12 : type = TREE_CHAIN (type);
1829 34 : if (type && TREE_PURPOSE (type))
1830 2 : DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
1831 : }
1832 : else
1833 : {
1834 : /* Otherwise propagate the flag. */
1835 170448 : if (DECL_HAS_DEFAULT_ARGUMENT_P (oldarg))
1836 0 : DECL_HAS_DEFAULT_ARGUMENT_P (newarg) = 1;
1837 170448 : if (DECL_HAS_DEFAULT_ARGUMENT_P (newarg))
1838 0 : DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
1839 : }
1840 : /* Merge names for std::meta::has_identifier and
1841 : std::meta::{,u8}identifier_of purposes. If they are different and
1842 : both oldarg and newarg are named, add flag to force that
1843 : std::meta::has_identifier returns false. If one is named and one is
1844 : unnamed, if neither is a olddecl nor newdecl is definition, propagate
1845 : DECL_NAME to both. Otherwise stash the old name into "old parm name"
1846 : artificial attribute. */
1847 170465 : if (DECL_NAME (oldarg) != DECL_NAME (newarg))
1848 : {
1849 18887 : if (DECL_NAME (oldarg) && DECL_NAME (newarg))
1850 : {
1851 : /* Different names. */
1852 4033 : MULTIPLE_NAMES_PARM_P (oldarg) = 1;
1853 4033 : MULTIPLE_NAMES_PARM_P (newarg) = 1;
1854 : }
1855 14854 : else if (!new_defines_function
1856 14854 : && types_match
1857 14854 : && DECL_INITIAL (olddecl) == NULL_TREE)
1858 : {
1859 : /* For 2 non-definitions with matching types, one is named and
1860 : one unnamed, propagate name to both. */
1861 2871 : if (DECL_NAME (oldarg))
1862 2445 : DECL_NAME (newarg) = DECL_NAME (oldarg);
1863 : else
1864 426 : DECL_NAME (oldarg) = DECL_NAME (newarg);
1865 : }
1866 : /* Depending on which PARM_DECL we'll keep, look at the other
1867 : PARM_DECL's name. */
1868 11983 : else if (tree name = ((new_defines_function || !types_match)
1869 11983 : ? DECL_NAME (oldarg) : DECL_NAME (newarg)))
1870 : {
1871 84 : tree opn = lookup_attribute ("old parm name",
1872 84 : DECL_ATTRIBUTES (oldarg));
1873 84 : if (opn)
1874 : {
1875 0 : if (TREE_VALUE (TREE_VALUE (opn)) == name)
1876 : /* Name already in "old parm name" attribute. */;
1877 : else
1878 : {
1879 : /* Different names. */
1880 0 : MULTIPLE_NAMES_PARM_P (oldarg) = 1;
1881 0 : MULTIPLE_NAMES_PARM_P (newarg) = 1;
1882 : }
1883 : }
1884 : else
1885 : {
1886 : /* Save name into attribute. */
1887 84 : DECL_ATTRIBUTES (newarg)
1888 84 : = tree_cons (get_identifier ("old parm name"),
1889 : tree_cons (NULL_TREE, name, NULL_TREE),
1890 84 : DECL_ATTRIBUTES (newarg));
1891 84 : DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1892 : }
1893 : }
1894 11899 : else if (extern_alias)
1895 1 : DECL_NAME (newarg) = DECL_NAME (oldarg);
1896 : }
1897 : }
1898 14901071 : }
1899 :
1900 : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
1901 : If the redeclaration is invalid, a diagnostic is issued, and the
1902 : error_mark_node is returned. Otherwise, OLDDECL is returned.
1903 :
1904 : If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
1905 : returned.
1906 :
1907 : HIDING is true if the new decl is being hidden. WAS_HIDDEN is true
1908 : if the old decl was hidden.
1909 :
1910 : Hidden decls can be anticipated builtins, injected friends, or
1911 : (coming soon) injected from a local-extern decl. */
1912 :
1913 : tree
1914 295355194 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
1915 : {
1916 295355194 : unsigned olddecl_uid = DECL_UID (olddecl);
1917 295355194 : int types_match = 0;
1918 295355194 : int new_defines_function = 0;
1919 295355194 : tree new_template_info;
1920 295355194 : location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
1921 295355194 : location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
1922 :
1923 295355194 : if (newdecl == olddecl)
1924 : return olddecl;
1925 :
1926 294543708 : types_match = decls_match (newdecl, olddecl);
1927 :
1928 : /* If either the type of the new decl or the type of the old decl is an
1929 : error_mark_node, then that implies that we have already issued an
1930 : error (earlier) for some bogus type specification, and in that case,
1931 : it is rather pointless to harass the user with yet more error message
1932 : about the same declaration, so just pretend the types match here. */
1933 294543708 : if (TREE_TYPE (newdecl) == error_mark_node
1934 294543708 : || TREE_TYPE (olddecl) == error_mark_node)
1935 : return error_mark_node;
1936 :
1937 : /* Check for redeclaration and other discrepancies. */
1938 294543683 : if (TREE_CODE (olddecl) == FUNCTION_DECL
1939 294543683 : && DECL_IS_UNDECLARED_BUILTIN (olddecl))
1940 : {
1941 6184598 : if (TREE_CODE (newdecl) != FUNCTION_DECL)
1942 : {
1943 : /* Avoid warnings redeclaring built-ins which have not been
1944 : explicitly declared. */
1945 189240 : if (was_hidden)
1946 : {
1947 189198 : if (TREE_PUBLIC (newdecl)
1948 189198 : && CP_DECL_CONTEXT (newdecl) == global_namespace)
1949 12 : warning_at (newdecl_loc,
1950 12 : OPT_Wbuiltin_declaration_mismatch,
1951 : "built-in function %qD declared as non-function",
1952 : newdecl);
1953 189198 : return NULL_TREE;
1954 : }
1955 :
1956 : /* If you declare a built-in or predefined function name as static,
1957 : the old definition is overridden, but optionally warn this was a
1958 : bad choice of name. */
1959 42 : if (! TREE_PUBLIC (newdecl))
1960 : {
1961 42 : warning_at (newdecl_loc,
1962 42 : OPT_Wshadow,
1963 42 : fndecl_built_in_p (olddecl)
1964 : ? G_("shadowing built-in function %q#D")
1965 : : G_("shadowing library function %q#D"), olddecl);
1966 : /* Discard the old built-in function. */
1967 42 : return NULL_TREE;
1968 : }
1969 : /* If the built-in is not ansi, then programs can override
1970 : it even globally without an error. */
1971 0 : else if (! fndecl_built_in_p (olddecl))
1972 0 : warning_at (newdecl_loc, 0,
1973 : "library function %q#D redeclared as non-function %q#D",
1974 : olddecl, newdecl);
1975 : else
1976 0 : error_at (newdecl_loc,
1977 : "declaration of %q#D conflicts with built-in "
1978 : "declaration %q#D", newdecl, olddecl);
1979 0 : return NULL_TREE;
1980 : }
1981 5995358 : else if (!types_match)
1982 : {
1983 : /* Avoid warnings redeclaring built-ins which have not been
1984 : explicitly declared. */
1985 2157957 : if (was_hidden)
1986 : {
1987 783100 : tree t1, t2;
1988 :
1989 : /* A new declaration doesn't match a built-in one unless it
1990 : is also extern "C". */
1991 783100 : gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
1992 783100 : gcc_assert (DECL_EXTERN_C_P (olddecl));
1993 783100 : if (!DECL_EXTERN_C_P (newdecl))
1994 : return NULL_TREE;
1995 :
1996 140787 : for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
1997 140787 : t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
1998 242977 : t1 || t2;
1999 102190 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
2000 : {
2001 242959 : if (!t1 || !t2)
2002 : break;
2003 : /* FILE, tm types are not known at the time
2004 : we create the builtins. */
2005 751484 : for (unsigned i = 0;
2006 994281 : i < sizeof (builtin_structptr_types)
2007 : / sizeof (builtin_structptr_type);
2008 : ++i)
2009 892085 : if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
2010 : {
2011 140601 : tree t = TREE_VALUE (t1);
2012 :
2013 140601 : if (TYPE_PTR_P (t)
2014 281202 : && TYPE_IDENTIFIER (TREE_TYPE (t))
2015 140601 : == get_identifier (builtin_structptr_types[i].str)
2016 281187 : && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
2017 : {
2018 140586 : tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2019 :
2020 140586 : TYPE_ARG_TYPES (TREE_TYPE (olddecl))
2021 140586 : = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
2022 140586 : types_match = decls_match (newdecl, olddecl);
2023 140586 : if (types_match)
2024 140586 : return duplicate_decls (newdecl, olddecl,
2025 140586 : hiding, was_hidden);
2026 0 : TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
2027 : }
2028 15 : goto next_arg;
2029 : }
2030 :
2031 102196 : if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
2032 : break;
2033 102190 : next_arg:;
2034 : }
2035 :
2036 201 : warning_at (newdecl_loc,
2037 201 : OPT_Wbuiltin_declaration_mismatch,
2038 : "declaration of %q#D conflicts with built-in "
2039 : "declaration %q#D", newdecl, olddecl);
2040 : }
2041 1374857 : else if ((DECL_EXTERN_C_P (newdecl)
2042 15 : && DECL_EXTERN_C_P (olddecl))
2043 2749699 : || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2044 1374842 : TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
2045 : {
2046 : /* Don't really override olddecl for __* prefixed builtins
2047 : except for __[^b]*_chk, the compiler might be using those
2048 : explicitly. */
2049 15 : if (fndecl_built_in_p (olddecl))
2050 : {
2051 15 : tree id = DECL_NAME (olddecl);
2052 15 : const char *name = IDENTIFIER_POINTER (id);
2053 15 : size_t len;
2054 :
2055 15 : if (name[0] == '_'
2056 15 : && name[1] == '_'
2057 30 : && (startswith (name + 2, "builtin_")
2058 6 : || (len = strlen (name)) <= strlen ("___chk")
2059 6 : || memcmp (name + len - strlen ("_chk"),
2060 : "_chk", strlen ("_chk") + 1) != 0))
2061 : {
2062 15 : if (DECL_INITIAL (newdecl))
2063 : {
2064 6 : error_at (newdecl_loc,
2065 : "definition of %q#D ambiguates built-in "
2066 : "declaration %q#D", newdecl, olddecl);
2067 6 : return error_mark_node;
2068 : }
2069 9 : auto_diagnostic_group d;
2070 9 : if (permerror (newdecl_loc,
2071 : "new declaration %q#D ambiguates built-in"
2072 : " declaration %q#D", newdecl, olddecl)
2073 9 : && flag_permissive)
2074 3 : inform (newdecl_loc,
2075 : "ignoring the %q#D declaration", newdecl);
2076 9 : return flag_permissive ? olddecl : error_mark_node;
2077 9 : }
2078 : }
2079 :
2080 : /* A near match; override the builtin. */
2081 :
2082 0 : if (TREE_PUBLIC (newdecl))
2083 0 : warning_at (newdecl_loc,
2084 0 : OPT_Wbuiltin_declaration_mismatch,
2085 : "new declaration %q#D ambiguates built-in "
2086 : "declaration %q#D", newdecl, olddecl);
2087 : else
2088 0 : warning (OPT_Wshadow,
2089 : fndecl_built_in_p (olddecl)
2090 : ? G_("shadowing built-in function %q#D")
2091 : : G_("shadowing library function %q#D"), olddecl);
2092 : }
2093 : else
2094 : /* Discard the old built-in function. */
2095 : return NULL_TREE;
2096 :
2097 : /* Replace the old RTL to avoid problems with inlining. */
2098 201 : COPY_DECL_RTL (newdecl, olddecl);
2099 : }
2100 : else
2101 : {
2102 : /* Even if the types match, prefer the new declarations type
2103 : for built-ins which have not been explicitly declared,
2104 : for exception lists, etc... */
2105 3837401 : tree type = TREE_TYPE (newdecl);
2106 3837401 : tree attribs = (*targetm.merge_type_attributes)
2107 3837401 : (TREE_TYPE (olddecl), type);
2108 :
2109 3837401 : type = cp_build_type_attribute_variant (type, attribs);
2110 3837401 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
2111 : }
2112 :
2113 : /* If a function is explicitly declared "throw ()", propagate that to
2114 : the corresponding builtin. */
2115 3837602 : if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
2116 3676867 : && was_hidden
2117 3676824 : && TREE_NOTHROW (newdecl)
2118 7256961 : && !TREE_NOTHROW (olddecl))
2119 : {
2120 27085 : enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
2121 27085 : tree tmpdecl = builtin_decl_explicit (fncode);
2122 27085 : if (tmpdecl && tmpdecl != olddecl && types_match)
2123 27085 : TREE_NOTHROW (tmpdecl) = 1;
2124 : }
2125 :
2126 : /* Whether or not the builtin can throw exceptions has no
2127 : bearing on this declarator. */
2128 3837602 : TREE_NOTHROW (olddecl) = 0;
2129 :
2130 3837602 : if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
2131 : {
2132 : /* If a builtin function is redeclared as `static', merge
2133 : the declarations, but make the original one static. */
2134 3 : DECL_THIS_STATIC (olddecl) = 1;
2135 3 : TREE_PUBLIC (olddecl) = 0;
2136 :
2137 : /* Make the old declaration consistent with the new one so
2138 : that all remnants of the builtin-ness of this function
2139 : will be banished. */
2140 3 : SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
2141 3 : COPY_DECL_RTL (newdecl, olddecl);
2142 : }
2143 : }
2144 288359085 : else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2145 : {
2146 : /* C++ Standard, 3.3, clause 4:
2147 : "[Note: a namespace name or a class template name must be unique
2148 : in its declarative region (7.3.2, clause 14). ]" */
2149 69445424 : if (TREE_CODE (olddecl) == NAMESPACE_DECL
2150 69445397 : || TREE_CODE (newdecl) == NAMESPACE_DECL)
2151 : /* Namespace conflicts with not namespace. */;
2152 34009513 : else if (DECL_TYPE_TEMPLATE_P (olddecl)
2153 103454898 : || DECL_TYPE_TEMPLATE_P (newdecl))
2154 : /* Class template conflicts. */;
2155 69445379 : else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
2156 34009513 : && DECL_TEMPLATE_RESULT (olddecl)
2157 34009513 : && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
2158 103454886 : || (TREE_CODE (newdecl) == TEMPLATE_DECL
2159 35388293 : && DECL_TEMPLATE_RESULT (newdecl)
2160 35388293 : && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
2161 : /* Variable template conflicts. */;
2162 69445370 : else if (concept_definition_p (olddecl)
2163 138890734 : || concept_definition_p (newdecl))
2164 : /* Concept conflicts. */;
2165 69445358 : else if ((TREE_CODE (newdecl) == FUNCTION_DECL
2166 34047595 : && DECL_FUNCTION_TEMPLATE_P (olddecl))
2167 69483452 : || (TREE_CODE (olddecl) == FUNCTION_DECL
2168 35388303 : && DECL_FUNCTION_TEMPLATE_P (newdecl)))
2169 : {
2170 : /* One is a function and the other is a template
2171 : function. */
2172 69397770 : if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
2173 : return NULL_TREE;
2174 :
2175 : /* There can only be one! */
2176 56245 : auto_diagnostic_group d;
2177 56245 : if (TREE_CODE (newdecl) == TEMPLATE_DECL
2178 56245 : && check_raw_literal_operator (olddecl))
2179 3 : error_at (newdecl_loc,
2180 : "literal operator %q#D conflicts with"
2181 : " raw literal operator", newdecl);
2182 56242 : else if (check_raw_literal_operator (newdecl))
2183 3 : error_at (newdecl_loc,
2184 : "raw literal operator %q#D conflicts with"
2185 : " literal operator template", newdecl);
2186 : else
2187 : return NULL_TREE;
2188 :
2189 6 : inform (olddecl_loc, "previous declaration %q#D", olddecl);
2190 6 : return error_mark_node;
2191 56245 : }
2192 47588 : else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
2193 : /* A structured binding must be unique in its declarative region. */;
2194 38242 : else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
2195 47585 : || DECL_IMPLICIT_TYPEDEF_P (newdecl))
2196 : /* One is an implicit typedef, that's ok. */
2197 : return NULL_TREE;
2198 :
2199 153 : auto_diagnostic_group d;
2200 153 : error ("%q#D redeclared as different kind of entity", newdecl);
2201 153 : inform (olddecl_loc, "previous declaration %q#D", olddecl);
2202 :
2203 153 : return error_mark_node;
2204 153 : }
2205 218913661 : else if (!types_match)
2206 : {
2207 203348830 : if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
2208 : /* These are certainly not duplicate declarations; they're
2209 : from different scopes. */
2210 : return NULL_TREE;
2211 :
2212 203348770 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2213 : {
2214 143635176 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
2215 143635176 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
2216 :
2217 : /* The name of a class template may not be declared to refer to
2218 : any other template, class, function, object, namespace, value,
2219 : or type in the same scope. */
2220 143635176 : if (TREE_CODE (oldres) == TYPE_DECL
2221 143635170 : || TREE_CODE (newres) == TYPE_DECL)
2222 : {
2223 9 : auto_diagnostic_group d;
2224 9 : error_at (newdecl_loc,
2225 : "conflicting declaration of template %q#D", newdecl);
2226 9 : inform (olddecl_loc,
2227 : "previous declaration %q#D", olddecl);
2228 9 : return error_mark_node;
2229 9 : }
2230 :
2231 143635167 : else if (TREE_CODE (oldres) == FUNCTION_DECL
2232 143635158 : && TREE_CODE (newres) == FUNCTION_DECL)
2233 : {
2234 143635158 : if (duplicate_function_template_decls (newdecl, olddecl))
2235 0 : return error_mark_node;
2236 : return NULL_TREE;
2237 : }
2238 : return NULL_TREE;
2239 : }
2240 59713594 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2241 : {
2242 59713445 : if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
2243 : {
2244 57 : auto_diagnostic_group d;
2245 57 : error_at (newdecl_loc,
2246 : "conflicting declaration of C function %q#D",
2247 : newdecl);
2248 57 : inform (olddecl_loc,
2249 : "previous declaration %q#D", olddecl);
2250 57 : return error_mark_node;
2251 57 : }
2252 : /* For function versions, params and types match, but they
2253 : are not ambiguous. */
2254 59713388 : else if (((!DECL_FUNCTION_VERSIONED (newdecl)
2255 59705084 : && !DECL_FUNCTION_VERSIONED (olddecl))
2256 8349 : || !same_type_p (fndecl_declared_return_type (newdecl),
2257 : fndecl_declared_return_type (olddecl)))
2258 : /* Let constrained hidden friends coexist for now, we'll
2259 : check satisfaction later. */
2260 59705039 : && !member_like_constrained_friend_p (newdecl)
2261 57163397 : && !member_like_constrained_friend_p (olddecl)
2262 : // The functions have the same parameter types.
2263 56713710 : && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2264 56713710 : TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
2265 : // And the same constraints.
2266 59713457 : && equivalently_constrained (newdecl, olddecl))
2267 : {
2268 69 : auto_diagnostic_group d;
2269 69 : error_at (newdecl_loc,
2270 : "ambiguating new declaration of %q#D", newdecl);
2271 69 : inform (olddecl_loc,
2272 : "old declaration %q#D", olddecl);
2273 69 : return error_mark_node;
2274 69 : }
2275 : else
2276 59713319 : return NULL_TREE;
2277 : }
2278 : else
2279 : {
2280 149 : auto_diagnostic_group d;
2281 149 : error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
2282 149 : inform (olddecl_loc,
2283 : "previous declaration as %q#D", olddecl);
2284 149 : return error_mark_node;
2285 149 : }
2286 : }
2287 15564831 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2288 15564831 : && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
2289 : {
2290 : /* OMP UDRs are never duplicates. */
2291 33 : gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
2292 33 : auto_diagnostic_group d;
2293 33 : error_at (newdecl_loc,
2294 : "redeclaration of %<pragma omp declare reduction%>");
2295 33 : inform (olddecl_loc,
2296 : "previous %<pragma omp declare reduction%> declaration");
2297 33 : return error_mark_node;
2298 33 : }
2299 15564798 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2300 15564798 : && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
2301 222 : && (!DECL_TEMPLATE_INFO (newdecl)
2302 222 : || (DECL_TI_TEMPLATE (newdecl)
2303 222 : != DECL_TI_TEMPLATE (olddecl))))
2304 11063576 : || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
2305 557758 : && (!DECL_TEMPLATE_INFO (olddecl)
2306 557758 : || (DECL_TI_TEMPLATE (olddecl)
2307 557758 : != DECL_TI_TEMPLATE (newdecl))))))
2308 : /* It's OK to have a template specialization and a non-template
2309 : with the same type, or to have specializations of two
2310 : different templates with the same type. Note that if one is a
2311 : specialization, and the other is an instantiation of the same
2312 : template, that we do not exit at this point. That situation
2313 : can occur if we instantiate a template class, and then
2314 : specialize one of its methods. This situation is valid, but
2315 : the declarations must be merged in the usual way. */
2316 : return NULL_TREE;
2317 15564798 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2318 15564798 : && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
2319 636076 : && !DECL_USE_TEMPLATE (newdecl))
2320 11063576 : || (DECL_TEMPLATE_INSTANTIATION (newdecl)
2321 78540 : && !DECL_USE_TEMPLATE (olddecl))))
2322 : /* One of the declarations is a template instantiation, and the
2323 : other is not a template at all. That's OK. */
2324 : return NULL_TREE;
2325 15564798 : else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2326 : {
2327 : /* In [namespace.alias] we have:
2328 :
2329 : In a declarative region, a namespace-alias-definition can be
2330 : used to redefine a namespace-alias declared in that declarative
2331 : region to refer only to the namespace to which it already
2332 : refers.
2333 :
2334 : Therefore, if we encounter a second alias directive for the same
2335 : alias, we can just ignore the second directive. */
2336 25 : if (DECL_NAMESPACE_ALIAS (newdecl)
2337 25 : && (DECL_NAMESPACE_ALIAS (newdecl)
2338 22 : == DECL_NAMESPACE_ALIAS (olddecl)))
2339 : return olddecl;
2340 :
2341 : /* Leave it to update_binding to merge or report error. */
2342 : return NULL_TREE;
2343 : }
2344 : /* Check if the two decls are non-mergeable versioned decls. */
2345 15564773 : else if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
2346 : && diagnose_versioned_decls (olddecl, newdecl))
2347 : return error_mark_node;
2348 : else
2349 : {
2350 15564773 : const char *errmsg = redeclaration_error_message (newdecl, olddecl);
2351 15564773 : if (errmsg)
2352 : {
2353 624 : auto_diagnostic_group d;
2354 624 : error_at (newdecl_loc, errmsg, newdecl);
2355 624 : if (DECL_NAME (olddecl) != NULL_TREE)
2356 624 : inform (olddecl_loc,
2357 624 : (DECL_INITIAL (olddecl) && namespace_bindings_p ())
2358 : ? G_("%q#D previously defined here")
2359 : : G_("%q#D previously declared here"), olddecl);
2360 624 : if (cxx_dialect >= cxx26
2361 150 : && DECL_NAME (newdecl)
2362 150 : && id_equal (DECL_NAME (newdecl), "_")
2363 637 : && !name_independent_decl_p (newdecl))
2364 : {
2365 13 : if (TREE_CODE (newdecl) == PARM_DECL)
2366 2 : inform (newdecl_loc,
2367 : "parameter declaration is not name-independent");
2368 11 : else if (DECL_DECOMPOSITION_P (newdecl))
2369 : {
2370 3 : if (at_namespace_scope_p ())
2371 2 : inform (newdecl_loc,
2372 : "structured binding at namespace scope is not "
2373 : "name-independent");
2374 1 : else if (TREE_STATIC (newdecl))
2375 1 : inform (newdecl_loc,
2376 : "static structured binding is not "
2377 : "name-independent");
2378 0 : else if (DECL_EXTERNAL (newdecl))
2379 0 : inform (newdecl_loc,
2380 : "extern structured binding is not "
2381 : "name-independent");
2382 : }
2383 8 : else if (at_class_scope_p ()
2384 0 : && VAR_P (newdecl)
2385 8 : && TREE_STATIC (newdecl))
2386 0 : inform (newdecl_loc,
2387 : "static data member is not name-independent");
2388 8 : else if (VAR_P (newdecl) && at_namespace_scope_p ())
2389 3 : inform (newdecl_loc,
2390 : "variable at namespace scope is not name-independent");
2391 5 : else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
2392 3 : inform (newdecl_loc,
2393 : "static variable is not name-independent");
2394 2 : else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
2395 0 : inform (newdecl_loc,
2396 : "extern variable is not name-independent");
2397 : }
2398 624 : return error_mark_node;
2399 624 : }
2400 15564149 : else if (TREE_CODE (olddecl) == FUNCTION_DECL
2401 11063336 : && DECL_INITIAL (olddecl) != NULL_TREE
2402 15457 : && !prototype_p (TREE_TYPE (olddecl))
2403 15564149 : && prototype_p (TREE_TYPE (newdecl)))
2404 : {
2405 : /* Prototype decl follows defn w/o prototype. */
2406 0 : auto_diagnostic_group d;
2407 0 : if (warning_at (newdecl_loc, 0,
2408 : "prototype specified for %q#D", newdecl))
2409 0 : inform (olddecl_loc,
2410 : "previous non-prototype definition here");
2411 0 : }
2412 15068313 : else if (VAR_OR_FUNCTION_DECL_P (olddecl)
2413 26627485 : && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2414 : {
2415 : /* [dcl.link]
2416 : If two declarations of the same function or object
2417 : specify different linkage-specifications ..., the program
2418 : is ill-formed.... Except for functions with C++ linkage,
2419 : a function declaration without a linkage specification
2420 : shall not precede the first linkage specification for
2421 : that function. A function can be declared without a
2422 : linkage specification after an explicit linkage
2423 : specification has been seen; the linkage explicitly
2424 : specified in the earlier declaration is not affected by
2425 : such a function declaration.
2426 :
2427 : DR 563 raises the question why the restrictions on
2428 : functions should not also apply to objects. Older
2429 : versions of G++ silently ignore the linkage-specification
2430 : for this example:
2431 :
2432 : namespace N {
2433 : extern int i;
2434 : extern "C" int i;
2435 : }
2436 :
2437 : which is clearly wrong. Therefore, we now treat objects
2438 : like functions. */
2439 1882 : if (current_lang_depth () == 0)
2440 : {
2441 : /* There is no explicit linkage-specification, so we use
2442 : the linkage from the previous declaration. */
2443 1870 : retrofit_lang_decl (newdecl);
2444 1870 : SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
2445 : }
2446 : else
2447 : {
2448 12 : auto_diagnostic_group d;
2449 12 : error_at (newdecl_loc,
2450 : "conflicting declaration of %q#D with %qL linkage",
2451 12 : newdecl, DECL_LANGUAGE (newdecl));
2452 12 : inform (olddecl_loc,
2453 : "previous declaration with %qL linkage",
2454 12 : DECL_LANGUAGE (olddecl));
2455 12 : }
2456 : }
2457 :
2458 15564149 : if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
2459 : ;
2460 14907565 : else if (TREE_CODE (olddecl) == FUNCTION_DECL)
2461 : {
2462 : /* Note: free functions, as TEMPLATE_DECLs, are handled below. */
2463 13010387 : if (DECL_FUNCTION_MEMBER_P (olddecl)
2464 10427047 : && (/* grokfndecl passes member function templates too
2465 : as FUNCTION_DECLs. */
2466 8015131 : DECL_TEMPLATE_INFO (olddecl)
2467 : /* C++11 8.3.6/6.
2468 : Default arguments for a member function of a class
2469 : template shall be specified on the initial declaration
2470 : of the member function within the class template. */
2471 679814 : || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
2472 : {
2473 7414211 : check_redeclaration_no_default_args (newdecl);
2474 :
2475 7414211 : if (DECL_TEMPLATE_INFO (olddecl)
2476 7414211 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
2477 : {
2478 2147618 : tree new_parms = DECL_TEMPLATE_INFO (newdecl)
2479 2147618 : ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
2480 2147618 : : INNERMOST_TEMPLATE_PARMS (current_template_parms);
2481 2147618 : tree old_parms
2482 2147618 : = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
2483 2147618 : merge_default_template_args (new_parms, old_parms,
2484 : /*class_p=*/false);
2485 : }
2486 : }
2487 : else
2488 : {
2489 3012836 : tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
2490 3012836 : tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
2491 3012836 : int i = 1;
2492 :
2493 7783560 : for (; t1 && t1 != void_list_node;
2494 4770724 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
2495 4772713 : if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
2496 : {
2497 57 : if (simple_cst_equal (TREE_PURPOSE (t1),
2498 57 : TREE_PURPOSE (t2)) == 1)
2499 : {
2500 24 : auto_diagnostic_group d;
2501 24 : if (permerror (newdecl_loc,
2502 : "default argument given for parameter "
2503 : "%d of %q#D", i, newdecl))
2504 24 : inform (olddecl_loc,
2505 : "previous specification in %q#D here",
2506 : olddecl);
2507 24 : }
2508 : else
2509 : {
2510 33 : auto_diagnostic_group d;
2511 33 : error_at (newdecl_loc,
2512 : "default argument given for parameter %d "
2513 : "of %q#D", i, newdecl);
2514 33 : inform (olddecl_loc,
2515 : "previous specification in %q#D here",
2516 : olddecl);
2517 33 : }
2518 : }
2519 :
2520 : /* C++17 11.3.6/4: "If a friend declaration specifies a default
2521 : argument expression, that declaration... shall be the only
2522 : declaration of the function or function template in the
2523 : translation unit." */
2524 3012836 : check_no_redeclaration_friend_default_args (olddecl, newdecl);
2525 : }
2526 : }
2527 : }
2528 :
2529 : /* Do not merge an implicit typedef with an explicit one. In:
2530 :
2531 : class A;
2532 : ...
2533 : typedef class A A __attribute__ ((foo));
2534 :
2535 : the attribute should apply only to the typedef. */
2536 19401751 : if (TREE_CODE (olddecl) == TYPE_DECL
2537 19401751 : && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
2538 46516 : || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
2539 : return NULL_TREE;
2540 :
2541 19370254 : if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
2542 : return NULL_TREE;
2543 :
2544 19370242 : if (!validate_constexpr_redeclaration (olddecl, newdecl))
2545 30 : return error_mark_node;
2546 :
2547 19370212 : if (modules_p ()
2548 49826 : && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
2549 19399813 : && TREE_CODE (olddecl) != NAMESPACE_DECL)
2550 : {
2551 29601 : if (!module_may_redeclare (olddecl, newdecl))
2552 24 : return error_mark_node;
2553 :
2554 29577 : if (!hiding)
2555 : {
2556 : /* The old declaration should match the exportingness of the new
2557 : declaration. But hidden friend declarations just keep the
2558 : exportingness of the old declaration; see CWG2588. */
2559 26103 : tree not_tmpl = STRIP_TEMPLATE (olddecl);
2560 26103 : if (DECL_LANG_SPECIFIC (not_tmpl)
2561 26034 : && DECL_MODULE_ATTACH_P (not_tmpl)
2562 : /* Typedefs are not entities and so are OK to be redeclared
2563 : as exported: see [module.interface]/p6. */
2564 26294 : && TREE_CODE (olddecl) != TYPE_DECL)
2565 : {
2566 179 : if (DECL_MODULE_EXPORT_P (newdecl)
2567 179 : && !DECL_MODULE_EXPORT_P (not_tmpl))
2568 : {
2569 15 : auto_diagnostic_group d;
2570 15 : error ("conflicting exporting for declaration %qD", newdecl);
2571 15 : inform (olddecl_loc,
2572 : "previously declared here without exporting");
2573 15 : }
2574 : }
2575 25924 : else if (DECL_MODULE_EXPORT_P (newdecl))
2576 10202 : DECL_MODULE_EXPORT_P (not_tmpl) = true;
2577 : }
2578 : }
2579 :
2580 : /* We have committed to returning OLDDECL at this point. */
2581 :
2582 : /* If new decl is `static' and an `extern' was seen previously,
2583 : warn about it. */
2584 19370188 : warn_extern_redeclared_static (newdecl, olddecl);
2585 :
2586 : /* True to merge attributes between the declarations, false to
2587 : set OLDDECL's attributes to those of NEWDECL (for template
2588 : explicit specializations that specify their own attributes
2589 : independent of those specified for the primary template). */
2590 19370188 : const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
2591 14900893 : || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
2592 19927931 : || DECL_TEMPLATE_SPECIALIZATION (olddecl));
2593 :
2594 19370188 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2595 : {
2596 14900893 : if (merge_attr)
2597 : {
2598 14343357 : {
2599 14343357 : auto_diagnostic_group d;
2600 14343357 : if (diagnose_mismatched_attributes (olddecl, newdecl))
2601 36 : inform (olddecl_loc, DECL_INITIAL (olddecl)
2602 : ? G_("previous definition of %qD here")
2603 : : G_("previous declaration of %qD here"), olddecl);
2604 14343357 : }
2605 :
2606 : /* [dcl.attr.noreturn]: The first declaration of a function shall
2607 : specify the noreturn attribute if any declaration of that function
2608 : specifies the noreturn attribute. */
2609 14343357 : tree a;
2610 14343357 : if (TREE_THIS_VOLATILE (newdecl)
2611 88933 : && !TREE_THIS_VOLATILE (olddecl)
2612 : /* This applies to [[noreturn]] only, not its GNU variants. */
2613 76 : && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
2614 54 : && cxx11_attribute_p (a)
2615 14343378 : && get_attribute_namespace (a) == NULL_TREE)
2616 : {
2617 9 : auto_diagnostic_group d;
2618 9 : error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
2619 : "but its first declaration was not", newdecl);
2620 9 : inform (olddecl_loc, "previous declaration of %qD", olddecl);
2621 9 : }
2622 : }
2623 :
2624 : /* Now that functions must hold information normally held
2625 : by field decls, there is extra work to do so that
2626 : declaration information does not get destroyed during
2627 : definition. */
2628 14900893 : if (DECL_VINDEX (olddecl))
2629 157188 : DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2630 14900893 : if (DECL_CONTEXT (olddecl))
2631 14900893 : DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2632 14900893 : DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
2633 14900893 : DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2634 14900893 : DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
2635 14900893 : DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
2636 14900893 : DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
2637 14900893 : DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
2638 14900893 : DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
2639 14900893 : DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
2640 14900893 : DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
2641 14900893 : |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
2642 14900893 : if (DECL_OVERLOADED_OPERATOR_P (olddecl))
2643 2691821 : DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
2644 5383642 : = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
2645 14900893 : new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
2646 :
2647 14900893 : check_redecl_contract (newdecl, olddecl);
2648 :
2649 : /* Optionally warn about more than one declaration for the same
2650 : name, but don't warn about a function declaration followed by a
2651 : definition. */
2652 27 : if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
2653 27 : && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2654 : /* Don't warn about extern decl followed by definition. */
2655 27 : && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
2656 : /* Don't warn if at least one is/was hidden. */
2657 27 : && !(hiding || was_hidden)
2658 : /* Don't warn about declaration followed by specialization. */
2659 14900905 : && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
2660 9 : || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
2661 : {
2662 6 : auto_diagnostic_group d;
2663 6 : if (warning_at (newdecl_loc,
2664 6 : OPT_Wredundant_decls,
2665 : "redundant redeclaration of %qD in same scope",
2666 : newdecl))
2667 6 : inform (olddecl_loc,
2668 : "previous declaration of %qD", olddecl);
2669 6 : }
2670 :
2671 : /* [dcl.fct.def.delete] A deleted definition of a function shall be the
2672 : first declaration of the function or, for an explicit specialization
2673 : of a function template, the first declaration of that
2674 : specialization. */
2675 14900893 : if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
2676 636076 : && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
2677 : {
2678 14343357 : if (DECL_DELETED_FN (newdecl))
2679 : {
2680 21 : auto_diagnostic_group d;
2681 21 : if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
2682 : "is not first declaration", newdecl))
2683 21 : inform (olddecl_loc,
2684 : "previous declaration of %qD", olddecl);
2685 21 : }
2686 14343357 : DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
2687 14343357 : if (DECL_DELETED_FN (olddecl)
2688 6 : && DECL_INITIAL (olddecl)
2689 14343363 : && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
2690 3 : DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2691 : }
2692 : }
2693 :
2694 : /* Deal with C++: must preserve virtual function table size. */
2695 19370188 : if (TREE_CODE (olddecl) == TYPE_DECL)
2696 : {
2697 46513 : tree newtype = TREE_TYPE (newdecl);
2698 46513 : tree oldtype = TREE_TYPE (olddecl);
2699 :
2700 46513 : if (newtype != error_mark_node && oldtype != error_mark_node
2701 93026 : && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2702 127452 : CLASSTYPE_FRIEND_CLASSES (newtype)
2703 42484 : = CLASSTYPE_FRIEND_CLASSES (oldtype);
2704 :
2705 46513 : DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
2706 : }
2707 :
2708 : /* Copy all the DECL_... slots specified in the new decl except for
2709 : any that we copy here from the old type. */
2710 19370188 : if (merge_attr)
2711 18812652 : DECL_ATTRIBUTES (newdecl)
2712 37625304 : = (*targetm.merge_decl_attributes) (olddecl, newdecl);
2713 : else
2714 557536 : DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2715 :
2716 : /* Transfer purviewness and importingness to the old decl. */
2717 19370188 : transfer_defining_module (olddecl, newdecl);
2718 :
2719 19370188 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2720 : {
2721 3926946 : tree old_result = DECL_TEMPLATE_RESULT (olddecl);
2722 3926946 : tree new_result = DECL_TEMPLATE_RESULT (newdecl);
2723 3926946 : TREE_TYPE (olddecl) = TREE_TYPE (old_result);
2724 :
2725 : /* The new decl should not already have gathered any
2726 : specializations. */
2727 3926946 : gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
2728 :
2729 : /* Make sure the contracts are equivalent. */
2730 3926946 : check_redecl_contract (newdecl, olddecl);
2731 :
2732 3926946 : DECL_ATTRIBUTES (old_result)
2733 3926946 : = (*targetm.merge_decl_attributes) (old_result, new_result);
2734 :
2735 3926946 : if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2736 : {
2737 3926916 : if (DECL_SOURCE_LOCATION (newdecl)
2738 3926916 : != DECL_SOURCE_LOCATION (olddecl))
2739 : {
2740 : /* Per C++11 8.3.6/4, default arguments cannot be added in
2741 : later declarations of a function template. */
2742 3904463 : check_redeclaration_no_default_args (newdecl);
2743 : /* C++17 11.3.6/4: "If a friend declaration specifies a default
2744 : argument expression, that declaration... shall be the only
2745 : declaration of the function or function template in the
2746 : translation unit." */
2747 3904463 : check_no_redeclaration_friend_default_args
2748 3904463 : (old_result, new_result);
2749 :
2750 3904463 : tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
2751 3904463 : tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
2752 3904463 : merge_default_template_args (new_parms, old_parms,
2753 : /*class_p=*/false);
2754 : }
2755 3926916 : if (!DECL_UNIQUE_FRIEND_P (new_result))
2756 2913866 : DECL_UNIQUE_FRIEND_P (old_result) = false;
2757 :
2758 3926916 : check_default_args (newdecl);
2759 :
2760 7853820 : if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
2761 3926916 : && DECL_INITIAL (new_result))
2762 : {
2763 24 : if (DECL_INITIAL (old_result))
2764 12 : DECL_UNINLINABLE (old_result) = 1;
2765 : else
2766 12 : DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
2767 24 : DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
2768 72 : DECL_NOT_REALLY_EXTERN (old_result)
2769 24 : = DECL_NOT_REALLY_EXTERN (new_result);
2770 48 : DECL_INTERFACE_KNOWN (old_result)
2771 24 : = DECL_INTERFACE_KNOWN (new_result);
2772 24 : DECL_DECLARED_INLINE_P (old_result)
2773 24 : = DECL_DECLARED_INLINE_P (new_result);
2774 24 : DECL_DISREGARD_INLINE_LIMITS (old_result)
2775 24 : |= DECL_DISREGARD_INLINE_LIMITS (new_result);
2776 : }
2777 : else
2778 : {
2779 3926892 : DECL_DECLARED_INLINE_P (old_result)
2780 3926892 : |= DECL_DECLARED_INLINE_P (new_result);
2781 3926892 : DECL_DISREGARD_INLINE_LIMITS (old_result)
2782 3926892 : |= DECL_DISREGARD_INLINE_LIMITS (new_result);
2783 3926892 : check_redeclaration_exception_specification (newdecl, olddecl);
2784 :
2785 3926892 : merge_attribute_bits (new_result, old_result);
2786 : }
2787 : }
2788 :
2789 : /* If the new declaration is a definition, update the file and
2790 : line information on the declaration, and also make
2791 : the old declaration the same definition. */
2792 3926946 : if (DECL_INITIAL (new_result) != NULL_TREE)
2793 : {
2794 5423960 : DECL_SOURCE_LOCATION (olddecl)
2795 5423960 : = DECL_SOURCE_LOCATION (old_result)
2796 2711980 : = DECL_SOURCE_LOCATION (newdecl);
2797 2711980 : DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
2798 2711980 : if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2799 : {
2800 2711980 : update_contract_arguments (new_result, old_result);
2801 :
2802 2711980 : DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
2803 9784548 : for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
2804 7072568 : DECL_CONTEXT (p) = old_result;
2805 :
2806 5423960 : if (tree fc = DECL_FRIEND_CONTEXT (new_result))
2807 18 : SET_DECL_FRIEND_CONTEXT (old_result, fc);
2808 : }
2809 : }
2810 :
2811 3926946 : return olddecl;
2812 : }
2813 :
2814 15443242 : if (types_match)
2815 : {
2816 15443041 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2817 14900692 : check_redeclaration_exception_specification (newdecl, olddecl);
2818 :
2819 : /* Automatically handles default parameters. */
2820 15443041 : tree oldtype = TREE_TYPE (olddecl);
2821 15443041 : tree newtype;
2822 :
2823 : /* For typedefs use the old type, as the new type's DECL_NAME points
2824 : at newdecl, which will be ggc_freed. */
2825 15443041 : if (TREE_CODE (newdecl) == TYPE_DECL)
2826 : {
2827 : /* But NEWTYPE might have an attribute, honor that. */
2828 46513 : tree tem = TREE_TYPE (newdecl);
2829 46513 : newtype = oldtype;
2830 :
2831 46513 : if (TYPE_USER_ALIGN (tem))
2832 : {
2833 21 : if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
2834 6 : SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
2835 21 : TYPE_USER_ALIGN (newtype) = true;
2836 : }
2837 :
2838 : /* And remove the new type from the variants list. */
2839 46513 : if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
2840 : {
2841 24 : tree remove = TREE_TYPE (newdecl);
2842 24 : if (TYPE_MAIN_VARIANT (remove) == remove)
2843 : {
2844 9 : gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
2845 : /* If remove is the main variant, no need to remove that
2846 : from the list. One of the DECL_ORIGINAL_TYPE
2847 : variants, e.g. created for aligned attribute, might still
2848 : refer to the newdecl TYPE_DECL though, so remove that one
2849 : in that case. */
2850 9 : if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
2851 6 : if (orig != remove)
2852 6 : for (tree t = TYPE_MAIN_VARIANT (orig); t;
2853 0 : t = TYPE_MAIN_VARIANT (t))
2854 6 : if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
2855 : {
2856 12 : TYPE_NEXT_VARIANT (t)
2857 6 : = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
2858 6 : break;
2859 : }
2860 : }
2861 : else
2862 15 : for (tree t = TYPE_MAIN_VARIANT (remove); ;
2863 0 : t = TYPE_NEXT_VARIANT (t))
2864 15 : if (TYPE_NEXT_VARIANT (t) == remove)
2865 : {
2866 15 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
2867 15 : break;
2868 : }
2869 : }
2870 : }
2871 15396528 : else if (merge_attr)
2872 14838992 : newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2873 : else
2874 557536 : newtype = TREE_TYPE (newdecl);
2875 :
2876 15443041 : if (VAR_P (newdecl))
2877 : {
2878 495836 : DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2879 : /* For already initialized vars, TREE_READONLY could have been
2880 : cleared in cp_finish_decl, because the var needs runtime
2881 : initialization or destruction. Make sure not to set
2882 : TREE_READONLY on it again. */
2883 495836 : if (DECL_INITIALIZED_P (olddecl)
2884 1214 : && !DECL_EXTERNAL (olddecl)
2885 495922 : && !TREE_READONLY (olddecl))
2886 31 : TREE_READONLY (newdecl) = 0;
2887 495836 : DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
2888 991672 : DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
2889 495836 : |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
2890 495836 : if (DECL_DEPENDENT_INIT_P (olddecl))
2891 104290 : SET_DECL_DEPENDENT_INIT_P (newdecl, true);
2892 991672 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
2893 495836 : |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
2894 495836 : DECL_DECLARED_CONSTEXPR_P (newdecl)
2895 495836 : |= DECL_DECLARED_CONSTEXPR_P (olddecl);
2896 991672 : DECL_DECLARED_CONSTINIT_P (newdecl)
2897 495836 : |= DECL_DECLARED_CONSTINIT_P (olddecl);
2898 :
2899 : /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
2900 495836 : if (DECL_LANG_SPECIFIC (olddecl)
2901 988091 : && CP_DECL_THREADPRIVATE_P (olddecl))
2902 : {
2903 : /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed. */
2904 41 : retrofit_lang_decl (newdecl);
2905 41 : CP_DECL_THREADPRIVATE_P (newdecl) = 1;
2906 : }
2907 : }
2908 :
2909 : /* An explicit specialization of a function template or of a member
2910 : function of a class template can be declared transaction_safe
2911 : independently of whether the corresponding template entity is declared
2912 : transaction_safe. */
2913 1204 : if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
2914 1069 : && DECL_TEMPLATE_INSTANTIATION (olddecl)
2915 78 : && DECL_TEMPLATE_SPECIALIZATION (newdecl)
2916 54 : && tx_safe_fn_type_p (newtype)
2917 15443041 : && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
2918 0 : newtype = tx_unsafe_fn_variant (newtype);
2919 :
2920 15443041 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2921 :
2922 15443041 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2923 14900692 : check_default_args (newdecl);
2924 :
2925 : /* Lay the type out, unless already done. */
2926 15443041 : if (! same_type_p (newtype, oldtype)
2927 368 : && TREE_TYPE (newdecl) != error_mark_node
2928 15443409 : && !(processing_template_decl && uses_template_parms (newdecl)))
2929 285 : layout_type (TREE_TYPE (newdecl));
2930 :
2931 15443041 : if ((VAR_P (newdecl)
2932 14947205 : || TREE_CODE (newdecl) == PARM_DECL
2933 14947205 : || TREE_CODE (newdecl) == RESULT_DECL
2934 14947205 : || TREE_CODE (newdecl) == FIELD_DECL
2935 14947205 : || TREE_CODE (newdecl) == TYPE_DECL)
2936 15489554 : && !(processing_template_decl && uses_template_parms (newdecl)))
2937 381768 : layout_decl (newdecl, 0);
2938 :
2939 : /* Merge deprecatedness. */
2940 15443041 : if (TREE_DEPRECATED (newdecl))
2941 11576 : TREE_DEPRECATED (olddecl) = 1;
2942 :
2943 : /* Merge unavailability. */
2944 15443041 : if (TREE_UNAVAILABLE (newdecl))
2945 3 : TREE_UNAVAILABLE (olddecl) = 1;
2946 :
2947 : /* Preserve function specific target and optimization options */
2948 15443041 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2949 : {
2950 14900692 : if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
2951 14900692 : && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
2952 0 : DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
2953 0 : = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
2954 :
2955 14900692 : if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
2956 14900692 : && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
2957 55 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
2958 55 : = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
2959 :
2960 14900692 : if (!DECL_UNIQUE_FRIEND_P (olddecl))
2961 14384982 : DECL_UNIQUE_FRIEND_P (newdecl) = false;
2962 : }
2963 : else
2964 : {
2965 : /* Merge the const type qualifier. */
2966 542349 : if (TREE_READONLY (newdecl))
2967 145337 : TREE_READONLY (olddecl) = 1;
2968 : /* Merge the volatile type qualifier. */
2969 542349 : if (TREE_THIS_VOLATILE (newdecl))
2970 5 : TREE_THIS_VOLATILE (olddecl) = 1;
2971 : }
2972 :
2973 : /* Merge the initialization information. */
2974 15443041 : if (DECL_INITIAL (newdecl) == NULL_TREE
2975 15443041 : && DECL_INITIAL (olddecl) != NULL_TREE)
2976 : {
2977 178792 : DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2978 178792 : DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
2979 178792 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2980 : {
2981 15373 : DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
2982 15373 : DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
2983 : }
2984 : }
2985 :
2986 15443041 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2987 : {
2988 14900692 : DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
2989 14900692 : |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
2990 14900692 : DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
2991 14900692 : if (DECL_IS_OPERATOR_NEW_P (olddecl))
2992 54349 : DECL_SET_IS_OPERATOR_NEW (newdecl, true);
2993 14900692 : DECL_LOOPING_CONST_OR_PURE_P (newdecl)
2994 14900692 : |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
2995 14900692 : DECL_IS_REPLACEABLE_OPERATOR (newdecl)
2996 14900692 : |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
2997 :
2998 14900692 : if (merge_attr)
2999 14343156 : merge_attribute_bits (newdecl, olddecl);
3000 : else
3001 : {
3002 : /* Merge the noreturn bit. */
3003 557536 : TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
3004 557536 : TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
3005 557536 : TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
3006 557536 : DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
3007 557536 : DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
3008 : }
3009 : /* Keep the old RTL. */
3010 14900692 : COPY_DECL_RTL (olddecl, newdecl);
3011 : }
3012 542349 : else if (VAR_P (newdecl)
3013 542349 : && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
3014 : {
3015 : /* Keep the old RTL. We cannot keep the old RTL if the old
3016 : declaration was for an incomplete object and the new
3017 : declaration is not since many attributes of the RTL will
3018 : change. */
3019 495762 : COPY_DECL_RTL (olddecl, newdecl);
3020 : }
3021 : }
3022 : /* If cannot merge, then use the new type and qualifiers,
3023 : and don't preserve the old rtl. */
3024 : else
3025 : {
3026 : /* Clean out any memory we had of the old declaration. */
3027 201 : tree oldstatic = value_member (olddecl, static_aggregates);
3028 201 : if (oldstatic)
3029 0 : TREE_VALUE (oldstatic) = error_mark_node;
3030 :
3031 201 : TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
3032 201 : TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
3033 201 : TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
3034 201 : TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
3035 201 : TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
3036 : }
3037 :
3038 : /* Merge the storage class information. */
3039 15443242 : merge_weak (newdecl, olddecl);
3040 :
3041 15443242 : DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
3042 15443242 : TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
3043 15443242 : TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
3044 15443242 : if (! DECL_EXTERNAL (olddecl))
3045 51153 : DECL_EXTERNAL (newdecl) = 0;
3046 15443242 : if (! DECL_COMDAT (olddecl))
3047 6589195 : DECL_COMDAT (newdecl) = 0;
3048 :
3049 15443242 : if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
3050 : {
3051 78 : if (!DECL_LOCAL_DECL_P (olddecl))
3052 : /* This can happen if olddecl was brought in from the
3053 : enclosing namespace via a using-decl. The new decl is
3054 : then not a block-scope extern at all. */
3055 3 : DECL_LOCAL_DECL_P (newdecl) = false;
3056 : else
3057 : {
3058 75 : retrofit_lang_decl (newdecl);
3059 75 : tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
3060 75 : = DECL_LOCAL_DECL_ALIAS (olddecl);
3061 75 : if (alias != error_mark_node)
3062 : {
3063 72 : DECL_ATTRIBUTES (alias)
3064 72 : = (*targetm.merge_decl_attributes) (alias, newdecl);
3065 72 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3066 42 : merge_attribute_bits (newdecl, alias);
3067 : }
3068 : }
3069 : }
3070 :
3071 15443242 : new_template_info = NULL_TREE;
3072 15443242 : if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
3073 : {
3074 15393166 : bool new_redefines_gnu_inline = false;
3075 :
3076 15393166 : if (new_defines_function
3077 15393166 : && ((DECL_INTERFACE_KNOWN (olddecl)
3078 1245 : && TREE_CODE (olddecl) == FUNCTION_DECL)
3079 9047165 : || (TREE_CODE (olddecl) == TEMPLATE_DECL
3080 0 : && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
3081 : == FUNCTION_DECL))))
3082 2490 : new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
3083 :
3084 : if (!new_redefines_gnu_inline)
3085 : {
3086 15393088 : DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
3087 15393088 : DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
3088 15393088 : DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
3089 : }
3090 :
3091 15393166 : if (TREE_CODE (newdecl) != TYPE_DECL)
3092 : {
3093 15393102 : DECL_TEMPLATE_INSTANTIATED (newdecl)
3094 15393102 : |= DECL_TEMPLATE_INSTANTIATED (olddecl);
3095 15393102 : DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
3096 :
3097 : /* If the OLDDECL is an instantiation and/or specialization,
3098 : then the NEWDECL must be too. But, it may not yet be marked
3099 : as such if the caller has created NEWDECL, but has not yet
3100 : figured out that it is a redeclaration. */
3101 15393102 : if (!DECL_USE_TEMPLATE (newdecl))
3102 14756810 : DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
3103 :
3104 15393102 : if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
3105 14835340 : DECL_INITIALIZED_IN_CLASS_P (newdecl)
3106 29670680 : |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
3107 : }
3108 :
3109 : /* Don't really know how much of the language-specific
3110 : values we should copy from old to new. */
3111 15393166 : DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
3112 :
3113 15393166 : if (LANG_DECL_HAS_MIN (newdecl))
3114 : {
3115 15393166 : DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
3116 15393166 : if (DECL_TEMPLATE_INFO (newdecl))
3117 : {
3118 636325 : new_template_info = DECL_TEMPLATE_INFO (newdecl);
3119 636325 : if (DECL_TEMPLATE_INSTANTIATION (olddecl)
3120 636325 : && DECL_TEMPLATE_SPECIALIZATION (newdecl))
3121 : /* Remember the presence of explicit specialization args. */
3122 1115078 : TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
3123 1115078 : = TINFO_USED_TEMPLATE_ID (new_template_info);
3124 : }
3125 :
3126 : /* We don't want to copy template info from a non-templated friend
3127 : (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now. */
3128 15393166 : gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
3129 : || !non_templated_friend_p (olddecl));
3130 15393166 : DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
3131 : }
3132 :
3133 15393166 : if (DECL_DECLARES_FUNCTION_P (newdecl))
3134 : {
3135 : /* Only functions have these fields. */
3136 14900893 : DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
3137 14900893 : DECL_BEFRIENDING_CLASSES (newdecl)
3138 14900893 : = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
3139 14900893 : DECL_BEFRIENDING_CLASSES (olddecl));
3140 : /* DECL_THUNKS is only valid for virtual functions,
3141 : otherwise it is a DECL_FRIEND_CONTEXT. */
3142 14900893 : if (DECL_VIRTUAL_P (newdecl))
3143 624631 : SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
3144 28552524 : else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
3145 371067 : SET_DECL_FRIEND_CONTEXT (olddecl, fc);
3146 : }
3147 492273 : else if (VAR_P (newdecl))
3148 : {
3149 : /* Only variables have this field. */
3150 492209 : if (VAR_HAD_UNKNOWN_BOUND (olddecl))
3151 196 : SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
3152 : }
3153 : }
3154 :
3155 15443242 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3156 : {
3157 14900893 : merge_decl_arguments (newdecl, olddecl, new_defines_function,
3158 : types_match, false);
3159 :
3160 14900893 : if (DECL_TEMPLATE_INSTANTIATION (olddecl)
3161 14900893 : && !DECL_TEMPLATE_INSTANTIATION (newdecl))
3162 : {
3163 : /* If newdecl is not a specialization, then it is not a
3164 : template-related function at all. And that means that we
3165 : should have exited above, returning 0. */
3166 557536 : gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
3167 :
3168 557536 : if (DECL_ODR_USED (olddecl))
3169 : /* From [temp.expl.spec]:
3170 :
3171 : If a template, a member template or the member of a class
3172 : template is explicitly specialized then that
3173 : specialization shall be declared before the first use of
3174 : that specialization that would cause an implicit
3175 : instantiation to take place, in every translation unit in
3176 : which such a use occurs. */
3177 0 : error ("explicit specialization of %qD after first use",
3178 : olddecl);
3179 :
3180 557536 : SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
3181 557536 : DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
3182 1114919 : && DECL_NONGNU_INLINE_P (newdecl));
3183 :
3184 : /* Don't propagate visibility from the template to the
3185 : specialization here. We'll do that in determine_visibility if
3186 : appropriate. */
3187 557536 : DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
3188 :
3189 : /* [temp.expl.spec/14] We don't inline explicit specialization
3190 : just because the primary template says so. */
3191 557536 : gcc_assert (!merge_attr);
3192 :
3193 557536 : DECL_DECLARED_INLINE_P (olddecl)
3194 557536 : = DECL_DECLARED_INLINE_P (newdecl);
3195 :
3196 557536 : DECL_DISREGARD_INLINE_LIMITS (olddecl)
3197 557536 : = DECL_DISREGARD_INLINE_LIMITS (newdecl);
3198 :
3199 557536 : DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
3200 : }
3201 14343357 : else if (new_defines_function && DECL_INITIAL (olddecl))
3202 : {
3203 : /* Never inline re-defined extern inline functions.
3204 : FIXME: this could be better handled by keeping both
3205 : function as separate declarations. */
3206 78 : DECL_UNINLINABLE (newdecl) = 1;
3207 : }
3208 : else
3209 : {
3210 14343279 : if (DECL_PENDING_INLINE_P (olddecl))
3211 : {
3212 6 : DECL_PENDING_INLINE_P (newdecl) = 1;
3213 6 : DECL_PENDING_INLINE_INFO (newdecl)
3214 12 : = DECL_PENDING_INLINE_INFO (olddecl);
3215 : }
3216 14343273 : else if (DECL_PENDING_INLINE_P (newdecl))
3217 : ;
3218 14343273 : else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
3219 14343273 : DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
3220 28686546 : = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
3221 :
3222 14343279 : DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
3223 :
3224 43029837 : DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
3225 28686558 : = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
3226 :
3227 28686558 : DECL_DISREGARD_INLINE_LIMITS (newdecl)
3228 14343279 : = DECL_DISREGARD_INLINE_LIMITS (olddecl)
3229 14343279 : = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
3230 28285611 : || DECL_DISREGARD_INLINE_LIMITS (olddecl));
3231 : }
3232 :
3233 : /* Preserve abstractness on cloned [cd]tors. */
3234 14900893 : DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
3235 :
3236 : /* Update newdecl's parms to point at olddecl. */
3237 47401150 : for (tree parm = DECL_ARGUMENTS (newdecl); parm;
3238 32500257 : parm = DECL_CHAIN (parm))
3239 32500257 : DECL_CONTEXT (parm) = olddecl;
3240 :
3241 14900893 : if (! types_match)
3242 : {
3243 201 : SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
3244 201 : COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
3245 201 : COPY_DECL_RTL (newdecl, olddecl);
3246 : }
3247 14900893 : if (! types_match || new_defines_function)
3248 : {
3249 : /* Update the contracts to reflect the new parameter names. */
3250 9048611 : update_contract_arguments (newdecl, olddecl);
3251 :
3252 : /* Mark the old PARM_DECLs in case std::meta::parameters_of has
3253 : been called on the old declaration and reflections of those
3254 : arguments are held across this point and used later.
3255 : Such PARM_DECLs are no longer present in
3256 : DECL_ARGUMENTS (DECL_CONTEXT (oldarg)) chain. */
3257 9048611 : for (tree oldarg = DECL_ARGUMENTS (olddecl);
3258 31734955 : oldarg; oldarg = DECL_CHAIN (oldarg))
3259 22686344 : OLD_PARM_DECL_P (oldarg) = 1;
3260 :
3261 : /* These need to be copied so that the names are available.
3262 : Note that if the types do match, we'll preserve inline
3263 : info and other bits, but if not, we won't. */
3264 9048611 : DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
3265 9048611 : DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
3266 : }
3267 : /* If redeclaring a builtin function, it stays built in
3268 : if newdecl is a gnu_inline definition, or if newdecl is just
3269 : a declaration. */
3270 14900893 : if (fndecl_built_in_p (olddecl)
3271 14957580 : && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
3272 : {
3273 3923971 : copy_decl_built_in_function (newdecl, olddecl);
3274 : /* If we're keeping the built-in definition, keep the rtl,
3275 : regardless of declaration matches. */
3276 3923971 : COPY_DECL_RTL (olddecl, newdecl);
3277 3923971 : if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
3278 : {
3279 3923965 : enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
3280 3923965 : if (builtin_decl_explicit_p (fncode))
3281 : {
3282 : /* A compatible prototype of these builtin functions
3283 : is seen, assume the runtime implements it with
3284 : the expected semantics. */
3285 3923965 : switch (fncode)
3286 : {
3287 9818 : case BUILT_IN_STPCPY:
3288 9818 : set_builtin_decl_implicit_p (fncode, true);
3289 9818 : break;
3290 3914147 : default:
3291 3914147 : set_builtin_decl_declared_p (fncode, true);
3292 3914147 : break;
3293 : }
3294 : }
3295 :
3296 3923965 : copy_attributes_to_builtin (newdecl);
3297 : }
3298 : }
3299 14900893 : if (new_defines_function)
3300 : /* If defining a function declared with other language
3301 : linkage, use the previously declared language linkage. */
3302 9048410 : SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
3303 5852483 : else if (types_match)
3304 : {
3305 5852282 : DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
3306 : /* Don't clear out the arguments if we're just redeclaring a
3307 : function. */
3308 5852282 : if (DECL_ARGUMENTS (olddecl))
3309 1896109 : DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
3310 : }
3311 : }
3312 542349 : else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
3313 0 : NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
3314 :
3315 : /* Now preserve various other info from the definition. */
3316 15443242 : TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
3317 15443242 : TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
3318 15443242 : DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
3319 15443242 : COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
3320 :
3321 : /* Warn about conflicting visibility specifications. */
3322 15443242 : if (DECL_VISIBILITY_SPECIFIED (olddecl)
3323 5437005 : && DECL_VISIBILITY_SPECIFIED (newdecl)
3324 15455018 : && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
3325 : {
3326 12 : auto_diagnostic_group d;
3327 12 : if (warning_at (newdecl_loc, OPT_Wattributes,
3328 : "%qD: visibility attribute ignored because it "
3329 : "conflicts with previous declaration", newdecl))
3330 12 : inform (olddecl_loc,
3331 : "previous declaration of %qD", olddecl);
3332 12 : }
3333 : /* Choose the declaration which specified visibility. */
3334 15443242 : if (DECL_VISIBILITY_SPECIFIED (olddecl))
3335 : {
3336 5437005 : DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
3337 5437005 : DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
3338 : }
3339 : /* Init priority used to be merged from newdecl to olddecl by the memcpy,
3340 : so keep this behavior. */
3341 15443242 : if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
3342 : {
3343 10 : SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
3344 10 : DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
3345 : }
3346 : /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED. */
3347 15443242 : if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
3348 : {
3349 54 : SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
3350 54 : DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
3351 : }
3352 15443188 : else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
3353 15443188 : && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
3354 3 : DECL_USER_ALIGN (newdecl) = 1;
3355 :
3356 15443242 : DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
3357 30886484 : if (DECL_WARN_IF_NOT_ALIGN (olddecl)
3358 15443242 : > DECL_WARN_IF_NOT_ALIGN (newdecl))
3359 0 : SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
3360 : DECL_WARN_IF_NOT_ALIGN (olddecl));
3361 15443242 : if (TREE_CODE (newdecl) == FIELD_DECL)
3362 0 : DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
3363 :
3364 : /* Merge module entity mapping information. */
3365 15443242 : if (DECL_LANG_SPECIFIC (olddecl)
3366 30836454 : && (DECL_MODULE_ENTITY_P (olddecl)
3367 15392880 : || DECL_MODULE_KEYED_DECLS_P (olddecl)))
3368 : {
3369 332 : retrofit_lang_decl (newdecl);
3370 332 : DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
3371 332 : DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
3372 : }
3373 :
3374 : /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
3375 : with that from NEWDECL below. */
3376 15443242 : if (DECL_LANG_SPECIFIC (olddecl))
3377 : {
3378 15393212 : gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
3379 : != DECL_LANG_SPECIFIC (newdecl));
3380 15393212 : ggc_free (DECL_LANG_SPECIFIC (olddecl));
3381 : }
3382 :
3383 : /* Merge the USED information. */
3384 15443242 : if (TREE_USED (olddecl))
3385 486554 : TREE_USED (newdecl) = 1;
3386 14956688 : else if (TREE_USED (newdecl))
3387 62 : TREE_USED (olddecl) = 1;
3388 :
3389 15443242 : if (VAR_P (newdecl))
3390 : {
3391 495836 : if (DECL_READ_P (olddecl))
3392 42626 : DECL_READ_P (newdecl) = 1;
3393 453210 : else if (DECL_READ_P (newdecl))
3394 3 : DECL_READ_P (olddecl) = 1;
3395 : }
3396 :
3397 15443242 : if (DECL_PRESERVE_P (olddecl))
3398 48 : DECL_PRESERVE_P (newdecl) = 1;
3399 15443194 : else if (DECL_PRESERVE_P (newdecl))
3400 75 : DECL_PRESERVE_P (olddecl) = 1;
3401 :
3402 : /* Merge the DECL_FUNCTION_VERSIONED information. newdecl will be copied
3403 : to olddecl and deleted. */
3404 15443242 : if (TREE_CODE (newdecl) == FUNCTION_DECL
3405 30344135 : && DECL_FUNCTION_VERSIONED (olddecl))
3406 : {
3407 : /* Set the flag for newdecl so that it gets copied to olddecl. */
3408 258 : DECL_FUNCTION_VERSIONED (newdecl) = 1;
3409 : /* newdecl will be purged after copying to olddecl and is no longer
3410 : a version. */
3411 258 : cgraph_node::delete_function_version_by_decl (newdecl);
3412 : }
3413 :
3414 15443242 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3415 : {
3416 14900893 : int function_size;
3417 14900893 : struct symtab_node *snode = symtab_node::get (olddecl);
3418 :
3419 14900893 : function_size = sizeof (struct tree_decl_common);
3420 :
3421 14900893 : memcpy ((char *) olddecl + sizeof (struct tree_common),
3422 : (char *) newdecl + sizeof (struct tree_common),
3423 : function_size - sizeof (struct tree_common));
3424 :
3425 14900893 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3426 : (char *) newdecl + sizeof (struct tree_decl_common),
3427 : sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
3428 :
3429 : /* Preserve symtab node mapping. */
3430 14900893 : olddecl->decl_with_vis.symtab_node = snode;
3431 :
3432 14900893 : if (new_template_info)
3433 : /* If newdecl is a template instantiation, it is possible that
3434 : the following sequence of events has occurred:
3435 :
3436 : o A friend function was declared in a class template. The
3437 : class template was instantiated.
3438 :
3439 : o The instantiation of the friend declaration was
3440 : recorded on the instantiation list, and is newdecl.
3441 :
3442 : o Later, however, instantiate_class_template called pushdecl
3443 : on the newdecl to perform name injection. But, pushdecl in
3444 : turn called duplicate_decls when it discovered that another
3445 : declaration of a global function with the same name already
3446 : existed.
3447 :
3448 : o Here, in duplicate_decls, we decided to clobber newdecl.
3449 :
3450 : If we're going to do that, we'd better make sure that
3451 : olddecl, and not newdecl, is on the list of
3452 : instantiations so that if we try to do the instantiation
3453 : again we won't get the clobbered declaration. */
3454 636316 : reregister_specialization (newdecl,
3455 : new_template_info,
3456 : olddecl);
3457 : }
3458 : else
3459 : {
3460 542349 : size_t size = tree_code_size (TREE_CODE (newdecl));
3461 :
3462 542349 : memcpy ((char *) olddecl + sizeof (struct tree_common),
3463 : (char *) newdecl + sizeof (struct tree_common),
3464 : sizeof (struct tree_decl_common) - sizeof (struct tree_common));
3465 :
3466 542349 : switch (TREE_CODE (newdecl))
3467 : {
3468 542349 : case LABEL_DECL:
3469 542349 : case VAR_DECL:
3470 542349 : case RESULT_DECL:
3471 542349 : case PARM_DECL:
3472 542349 : case FIELD_DECL:
3473 542349 : case TYPE_DECL:
3474 542349 : case CONST_DECL:
3475 542349 : {
3476 542349 : struct symtab_node *snode = NULL;
3477 :
3478 542349 : if (VAR_P (newdecl)
3479 542349 : && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
3480 3 : || DECL_EXTERNAL (olddecl)))
3481 495836 : snode = symtab_node::get (olddecl);
3482 542349 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3483 : (char *) newdecl + sizeof (struct tree_decl_common),
3484 : size - sizeof (struct tree_decl_common)
3485 542349 : + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
3486 542349 : if (VAR_P (newdecl))
3487 495836 : olddecl->decl_with_vis.symtab_node = snode;
3488 : }
3489 : break;
3490 0 : default:
3491 0 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3492 : (char *) newdecl + sizeof (struct tree_decl_common),
3493 : sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
3494 0 : + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
3495 0 : break;
3496 : }
3497 : }
3498 :
3499 15443242 : if (VAR_OR_FUNCTION_DECL_P (newdecl))
3500 : {
3501 15396729 : if (DECL_EXTERNAL (olddecl)
3502 497207 : || TREE_PUBLIC (olddecl)
3503 15396798 : || TREE_STATIC (olddecl))
3504 : {
3505 : /* Merge the section attribute.
3506 : We want to issue an error if the sections conflict but that must be
3507 : done later in decl_attributes since we are called before attributes
3508 : are assigned. */
3509 15396729 : if (DECL_SECTION_NAME (newdecl) != NULL)
3510 7 : set_decl_section_name (olddecl, newdecl);
3511 :
3512 15396729 : if (DECL_ONE_ONLY (newdecl))
3513 : {
3514 0 : struct symtab_node *oldsym, *newsym;
3515 0 : if (TREE_CODE (olddecl) == FUNCTION_DECL)
3516 0 : oldsym = cgraph_node::get_create (olddecl);
3517 : else
3518 0 : oldsym = varpool_node::get_create (olddecl);
3519 0 : newsym = symtab_node::get (newdecl);
3520 0 : oldsym->set_comdat_group (newsym->get_comdat_group ());
3521 : }
3522 : }
3523 :
3524 15396729 : if (VAR_P (newdecl)
3525 15396729 : && CP_DECL_THREAD_LOCAL_P (newdecl))
3526 : {
3527 404 : CP_DECL_THREAD_LOCAL_P (olddecl) = true;
3528 404 : if (!processing_template_decl)
3529 371 : set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
3530 : }
3531 : }
3532 :
3533 15443242 : DECL_UID (olddecl) = olddecl_uid;
3534 :
3535 : /* NEWDECL contains the merged attribute lists.
3536 : Update OLDDECL to be the same. */
3537 15443242 : DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
3538 :
3539 : /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
3540 : so that encode_section_info has a chance to look at the new decl
3541 : flags and attributes. */
3542 15443242 : if (DECL_RTL_SET_P (olddecl)
3543 15443242 : && (TREE_CODE (olddecl) == FUNCTION_DECL
3544 0 : || (VAR_P (olddecl)
3545 0 : && TREE_STATIC (olddecl))))
3546 0 : make_decl_rtl (olddecl);
3547 :
3548 : /* The NEWDECL will no longer be needed. Because every out-of-class
3549 : declaration of a member results in a call to duplicate_decls,
3550 : freeing these nodes represents in a significant savings.
3551 :
3552 : Before releasing the node, be sore to remove function from symbol
3553 : table that might have been inserted there to record comdat group.
3554 : Be sure to however do not free DECL_STRUCT_FUNCTION because this
3555 : structure is shared in between newdecl and oldecl. */
3556 15443242 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3557 14900893 : DECL_STRUCT_FUNCTION (newdecl) = NULL;
3558 15443242 : if (VAR_OR_FUNCTION_DECL_P (newdecl))
3559 : {
3560 15396729 : struct symtab_node *snode = symtab_node::get (newdecl);
3561 15396729 : if (snode)
3562 399 : snode->remove ();
3563 : }
3564 :
3565 15443242 : if (TREE_CODE (olddecl) == FUNCTION_DECL)
3566 : {
3567 14900893 : tree clone;
3568 15431831 : FOR_EACH_CLONE (clone, olddecl)
3569 : {
3570 530938 : DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
3571 530938 : DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
3572 : }
3573 : }
3574 :
3575 : /* Remove the associated constraints for newdecl, if any, before
3576 : reclaiming memory. */
3577 15443242 : if (flag_concepts)
3578 15172212 : remove_constraints (newdecl);
3579 :
3580 15443242 : if (flag_contracts)
3581 : /* Remove the specifiers, and then remove the decl from the lookup. */
3582 950941 : remove_decl_with_fn_contracts_specifiers (newdecl);
3583 :
3584 : /* And similarly for any module tracking data. */
3585 15443242 : if (modules_p ())
3586 35566 : remove_defining_module (newdecl);
3587 :
3588 15443242 : ggc_free (newdecl);
3589 :
3590 15443242 : return olddecl;
3591 : }
3592 :
3593 : /* Return zero if the declaration NEWDECL is valid
3594 : when the declaration OLDDECL (assumed to be for the same name)
3595 : has already been seen.
3596 : Otherwise return an error message format string with a %s
3597 : where the identifier should go. */
3598 :
3599 : static const char *
3600 15564773 : redeclaration_error_message (tree newdecl, tree olddecl)
3601 : {
3602 15564809 : if (TREE_CODE (newdecl) == TYPE_DECL)
3603 : {
3604 : /* Because C++ can put things into name space for free,
3605 : constructs like "typedef struct foo { ... } foo"
3606 : would look like an erroneous redeclaration. */
3607 78046 : if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
3608 : return NULL;
3609 : else
3610 : return G_("redefinition of %q#D");
3611 : }
3612 15486763 : else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3613 : {
3614 : /* If this is a pure function, its olddecl will actually be
3615 : the original initialization to `0' (which we force to call
3616 : abort()). Don't complain about redefinition in this case. */
3617 22127152 : if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
3618 11063594 : && DECL_INITIAL (olddecl) == NULL_TREE)
3619 : return NULL;
3620 :
3621 : /* If both functions come from different namespaces, this is not
3622 : a redeclaration - this is a conflict with a used function. */
3623 22127122 : if (DECL_NAMESPACE_SCOPE_P (olddecl)
3624 2595544 : && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
3625 11063564 : && ! decls_match (olddecl, newdecl))
3626 : return G_("%qD conflicts with used function");
3627 :
3628 : /* We'll complain about linkage mismatches in
3629 : warn_extern_redeclared_static. */
3630 :
3631 : /* Defining the same name twice is no good. */
3632 11063561 : if (decl_defined_p (olddecl)
3633 11063561 : && decl_defined_p (newdecl))
3634 : {
3635 306 : if (DECL_NAME (olddecl) == NULL_TREE)
3636 : return G_("%q#D not declared in class");
3637 447 : else if (!GNU_INLINE_P (olddecl)
3638 393 : || GNU_INLINE_P (newdecl))
3639 222 : return G_("redefinition of %q#D");
3640 : }
3641 :
3642 12777807 : if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
3643 : {
3644 1665041 : bool olda = GNU_INLINE_P (olddecl);
3645 1665041 : bool newa = GNU_INLINE_P (newdecl);
3646 :
3647 1665041 : if (olda != newa)
3648 : {
3649 15 : if (newa)
3650 : return G_("%q+D redeclared inline with "
3651 : "%<gnu_inline%> attribute");
3652 : else
3653 : return G_("%q+D redeclared inline without "
3654 : "%<gnu_inline%> attribute");
3655 : }
3656 : }
3657 :
3658 : /* [class.compare.default]: A definition of a comparison operator as
3659 : defaulted that appears in a class shall be the first declaration of
3660 : that function. */
3661 11063324 : special_function_kind sfk = special_function_p (olddecl);
3662 11063324 : if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
3663 : return G_("comparison operator %q+D defaulted after "
3664 : "its first declaration");
3665 :
3666 11063321 : check_abi_tag_redeclaration
3667 11063321 : (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
3668 11063321 : lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
3669 :
3670 11063321 : return NULL;
3671 : }
3672 4423187 : else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3673 : {
3674 3926985 : tree nt, ot;
3675 :
3676 3926985 : if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
3677 : return G_("redefinition of %q#D");
3678 :
3679 3926979 : if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
3680 36 : return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
3681 36 : DECL_TEMPLATE_RESULT (olddecl));
3682 :
3683 3926943 : if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
3684 : return NULL;
3685 :
3686 3926931 : nt = DECL_TEMPLATE_RESULT (newdecl);
3687 3926931 : if (DECL_TEMPLATE_INFO (nt))
3688 892283 : nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
3689 3926931 : ot = DECL_TEMPLATE_RESULT (olddecl);
3690 3926931 : if (DECL_TEMPLATE_INFO (ot))
3691 3926931 : ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
3692 6638965 : if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
3693 3926970 : && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
3694 15 : return G_("redefinition of %q#D");
3695 :
3696 6322811 : if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
3697 : {
3698 1736842 : bool olda = GNU_INLINE_P (ot);
3699 1736842 : bool newa = GNU_INLINE_P (nt);
3700 :
3701 1736842 : if (olda != newa)
3702 : {
3703 0 : if (newa)
3704 : return G_("%q+D redeclared inline with "
3705 : "%<gnu_inline%> attribute");
3706 : else
3707 : return G_("%q+D redeclared inline without "
3708 : "%<gnu_inline%> attribute");
3709 : }
3710 : }
3711 :
3712 : /* Core issue #226 (C++11):
3713 :
3714 : If a friend function template declaration specifies a
3715 : default template-argument, that declaration shall be a
3716 : definition and shall be the only declaration of the
3717 : function template in the translation unit. */
3718 3926916 : if ((cxx_dialect != cxx98)
3719 3908539 : && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
3720 4131215 : && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
3721 : /*is_primary=*/true,
3722 : /*is_partial=*/false,
3723 : /*is_friend_decl=*/2))
3724 : return G_("redeclaration of friend %q#D "
3725 : "may not have default template arguments");
3726 :
3727 3926913 : return NULL;
3728 : }
3729 496202 : else if (VAR_P (newdecl)
3730 496118 : && (CP_DECL_THREAD_LOCAL_P (newdecl)
3731 496118 : != CP_DECL_THREAD_LOCAL_P (olddecl))
3732 496249 : && (! DECL_LANG_SPECIFIC (olddecl)
3733 44 : || ! CP_DECL_THREADPRIVATE_P (olddecl)
3734 41 : || CP_DECL_THREAD_LOCAL_P (newdecl)))
3735 : {
3736 : /* Only variables can be thread-local, and all declarations must
3737 : agree on this property. */
3738 6 : if (CP_DECL_THREAD_LOCAL_P (newdecl))
3739 : return G_("thread-local declaration of %q#D follows "
3740 : "non-thread-local declaration");
3741 : else
3742 3 : return G_("non-thread-local declaration of %q#D follows "
3743 : "thread-local declaration");
3744 : }
3745 496196 : else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
3746 : {
3747 : /* The objects have been declared at namespace scope. If either
3748 : is a member of an anonymous union, then this is an invalid
3749 : redeclaration. For example:
3750 :
3751 : int i;
3752 : union { int i; };
3753 :
3754 : is invalid. */
3755 495963 : if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
3756 991995 : || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
3757 : return G_("redeclaration of %q#D");
3758 : /* If at least one declaration is a reference, there is no
3759 : conflict. For example:
3760 :
3761 : int i = 3;
3762 : extern int i;
3763 :
3764 : is valid. */
3765 496029 : if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3766 : return NULL;
3767 :
3768 : /* Static data member declared outside a class definition
3769 : if the variable is defined within the class with constexpr
3770 : specifier is declaration rather than definition (and
3771 : deprecated). */
3772 2824 : if (cxx_dialect >= cxx17
3773 2749 : && VAR_P (olddecl)
3774 2693 : && DECL_CLASS_SCOPE_P (olddecl)
3775 2649 : && DECL_DECLARED_CONSTEXPR_P (olddecl)
3776 5461 : && !DECL_INITIAL (newdecl))
3777 : {
3778 2637 : DECL_EXTERNAL (newdecl) = 1;
3779 : /* For now, only warn with explicit -Wdeprecated. */
3780 2637 : if (OPTION_SET_P (warn_deprecated))
3781 : {
3782 40 : auto_diagnostic_group d;
3783 40 : if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
3784 : "redundant redeclaration of %<constexpr%> "
3785 : "static data member %qD", newdecl))
3786 4 : inform (DECL_SOURCE_LOCATION (olddecl),
3787 : "previous declaration of %qD", olddecl);
3788 40 : }
3789 2637 : return NULL;
3790 : }
3791 :
3792 : /* Reject two definitions. */
3793 : return G_("redefinition of %q#D");
3794 : }
3795 : else
3796 : {
3797 : /* Objects declared with block scope: */
3798 : /* Reject two definitions, and reject a definition
3799 : together with an external reference. */
3800 152 : if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3801 : return G_("redeclaration of %q#D");
3802 : return NULL;
3803 : }
3804 : }
3805 :
3806 :
3807 : /* Hash and equality functions for the named_label table. */
3808 :
3809 : hashval_t
3810 78527 : named_label_hash::hash (const value_type entry)
3811 : {
3812 78527 : return IDENTIFIER_HASH_VALUE (entry->name);
3813 : }
3814 :
3815 : bool
3816 75538 : named_label_hash::equal (const value_type entry, compare_type name)
3817 : {
3818 75538 : return name == entry->name;
3819 : }
3820 :
3821 : /* Look for a label named ID in the current function. If one cannot
3822 : be found, create one. Return the named_label_entry, or NULL on
3823 : failure. */
3824 :
3825 : static named_label_entry *
3826 24119 : lookup_label_1 (tree id, bool making_local_p)
3827 : {
3828 24119 : auto_cond_timevar tv (TV_NAME_LOOKUP);
3829 :
3830 : /* You can't use labels at global scope. */
3831 24119 : if (current_function_decl == NULL_TREE)
3832 : {
3833 3 : error ("label %qE referenced outside of any function", id);
3834 3 : return NULL;
3835 : }
3836 :
3837 24116 : if (!named_labels)
3838 4648 : named_labels = hash_table<named_label_hash>::create_ggc (13);
3839 :
3840 24116 : hashval_t hash = IDENTIFIER_HASH_VALUE (id);
3841 24116 : named_label_entry **slot
3842 24116 : = named_labels->find_slot_with_hash (id, hash, INSERT);
3843 24116 : named_label_entry *old = *slot;
3844 :
3845 24116 : if (old && old->label_decl)
3846 : {
3847 3458 : if (!making_local_p)
3848 : return old;
3849 :
3850 21 : if (old->binding_level == current_binding_level)
3851 : {
3852 0 : auto_diagnostic_group d;
3853 0 : error ("local label %qE conflicts with existing label", id);
3854 0 : inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
3855 0 : return NULL;
3856 0 : }
3857 : }
3858 :
3859 : /* We are making a new decl, create or reuse the named_label_entry */
3860 20700 : named_label_entry *ent = NULL;
3861 33 : if (old && !old->label_decl)
3862 : ent = old;
3863 : else
3864 : {
3865 20667 : ent = ggc_cleared_alloc<named_label_entry> ();
3866 20667 : ent->name = id;
3867 20667 : ent->outer = old;
3868 20667 : *slot = ent;
3869 : }
3870 :
3871 : /* Now create the LABEL_DECL. */
3872 20679 : tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
3873 :
3874 20679 : DECL_CONTEXT (decl) = current_function_decl;
3875 20679 : SET_DECL_MODE (decl, VOIDmode);
3876 20679 : if (making_local_p)
3877 : {
3878 219 : C_DECLARED_LABEL_FLAG (decl) = true;
3879 219 : DECL_CHAIN (decl) = current_binding_level->names;
3880 219 : current_binding_level->names = decl;
3881 : }
3882 :
3883 20679 : ent->label_decl = decl;
3884 :
3885 20679 : return ent;
3886 24119 : }
3887 :
3888 : /* Wrapper for lookup_label_1. */
3889 :
3890 : tree
3891 2952 : lookup_label (tree id)
3892 : {
3893 2952 : named_label_entry *ent = lookup_label_1 (id, false);
3894 2952 : return ent ? ent->label_decl : NULL_TREE;
3895 : }
3896 :
3897 : /* Remember that we've seen &&ID. */
3898 :
3899 : void
3900 253 : mark_label_addressed (tree id)
3901 : {
3902 253 : named_label_entry *ent = lookup_label_1 (id, false);
3903 253 : ent->addressed = true;
3904 253 : }
3905 :
3906 : tree
3907 219 : declare_local_label (tree id)
3908 : {
3909 219 : named_label_entry *ent = lookup_label_1 (id, true);
3910 219 : return ent ? ent->label_decl : NULL_TREE;
3911 : }
3912 :
3913 : /* Returns true if it is ill-formed to jump past the declaration of DECL. */
3914 :
3915 : static bool
3916 85071 : decl_jump_unsafe (tree decl)
3917 : {
3918 : /* [stmt.dcl]/3: A program that jumps from a point where a local variable
3919 : with automatic storage duration is not in scope to a point where it is
3920 : in scope is ill-formed unless the variable has scalar type, class type
3921 : with a trivial default constructor and a trivial destructor, a
3922 : cv-qualified version of one of these types, or an array of one of the
3923 : preceding types and is declared without an initializer (8.5). */
3924 85071 : tree type = TREE_TYPE (decl);
3925 :
3926 85071 : return (type != error_mark_node
3927 85053 : && VAR_P (decl)
3928 15025 : && !TREE_STATIC (decl)
3929 99960 : && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
3930 12975 : || variably_modified_type_p (type, NULL_TREE)));
3931 : }
3932 :
3933 : /* Returns true if decl is an automatic variable with vacuous initialization
3934 : except when it is [[indeterminate]] or [[gnu::uninitialized]].
3935 : Jumps across such initialization need to be instrumented for
3936 : !!flag_auto_var_init. */
3937 :
3938 : static bool
3939 83148 : decl_instrument_init_bypass_p (tree decl)
3940 : {
3941 83148 : tree type = TREE_TYPE (decl);
3942 :
3943 83148 : return (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
3944 5920 : && !processing_template_decl
3945 5674 : && type != error_mark_node
3946 5668 : && VAR_P (decl)
3947 1053 : && !TREE_STATIC (decl)
3948 1032 : && !DECL_EXTERNAL (decl)
3949 2036 : && !(DECL_NONTRIVIALLY_INITIALIZED_P (decl)
3950 1018 : || variably_modified_type_p (type, NULL_TREE))
3951 1018 : && !lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (decl))
3952 1018 : && !lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
3953 84166 : && !DECL_HAS_VALUE_EXPR_P (decl));
3954 : }
3955 :
3956 : /* Build .DEFERRED_INIT call for DECL. */
3957 :
3958 : static tree
3959 133 : build_deferred_init_call (tree decl)
3960 : {
3961 133 : tree decl_size_arg = TYPE_SIZE_UNIT (TREE_TYPE (decl));
3962 266 : tree init_type_arg = build_int_cst (integer_type_node,
3963 133 : (int) flag_auto_var_init);
3964 133 : location_t loc = DECL_SOURCE_LOCATION (decl);
3965 133 : tree decl_name;
3966 :
3967 133 : if (DECL_NAME (decl))
3968 133 : decl_name = build_string_literal (DECL_NAME (decl));
3969 : else
3970 : {
3971 0 : char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3];
3972 0 : sprintf (decl_name_anonymous, "D.%u", DECL_UID (decl));
3973 0 : decl_name = build_string_literal (decl_name_anonymous);
3974 : }
3975 :
3976 133 : tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
3977 133 : TREE_TYPE (decl), 3,
3978 : decl_size_arg, init_type_arg,
3979 : decl_name);
3980 133 : tree ret = build2_loc (loc, MODIFY_EXPR, void_type_node, decl, call);
3981 133 : return build_stmt (loc, EXPR_STMT, ret);
3982 : }
3983 :
3984 : /* Emit before ITER (and any labels/case labels before it) code like
3985 : if (0)
3986 : {
3987 : l1:
3988 : v4 = .DEFERRED_INIT (sizeof (v4), ?, "v4");
3989 : v3 = .DEFERRED_INIT (sizeof (v3), ?, "v3");
3990 : v2 = .DEFERRED_INIT (sizeof (v2), ?, "v2");
3991 : v1 = .DEFERRED_INIT (sizeof (v1), ?, "v1");
3992 : }
3993 : and return l1 label, or if it already exists, assert it has the
3994 : .DEFERRED_INIT calls for the right decls in the right order and
3995 : amend it, either by adding extra labels in between or further
3996 : ,DEFERRED_INIT calls before the first label and extra label before
3997 : that. If CASE_LABEL is non-NULL, emit that CASE_LABEL_EXPR instead
3998 : of adding a label. DECLS points to an array of NDECLS VAR_DECLs
3999 : which should be initialized. */
4000 :
4001 : static tree
4002 121 : maybe_add_deferred_init_calls (tree_stmt_iterator iter, tree case_label,
4003 : tree *decls, unsigned ndecls)
4004 : {
4005 121 : tree lab = NULL_TREE;
4006 185 : for (; !tsi_end_p (iter); tsi_prev (&iter))
4007 : {
4008 179 : switch (TREE_CODE (tsi_stmt (iter)))
4009 : {
4010 64 : case LABEL_EXPR:
4011 64 : case CASE_LABEL_EXPR:
4012 64 : case DEBUG_BEGIN_STMT:
4013 64 : continue;
4014 : default:
4015 : break;
4016 : }
4017 : break;
4018 : }
4019 121 : if (!tsi_end_p (iter)
4020 115 : && TREE_CODE (tsi_stmt (iter)) == IF_STMT
4021 197 : && IF_STMT_VACUOUS_INIT_P (tsi_stmt (iter)))
4022 : {
4023 : /* Found IF_STMT added for this or some adjacent
4024 : LABEL_EXPR/CASE_LABEL_EXPR by an earlier call to this function.
4025 : The decls are ordered so that we can always reuse it. Sometimes
4026 : by no modifications at all and just returning the right label
4027 : which was added already before, sometimes by adding a label in
4028 : between two previously added .DEFERRED_INIT calls and sometimes
4029 : by adding extra statements (.DEFERRED_INIT calls and LABEL_EXPR
4030 : before that) before the statements in IF_STMT body. */
4031 70 : tree then_clause = THEN_CLAUSE (tsi_stmt (iter));
4032 70 : iter = tsi_last (then_clause);
4033 70 : bool add = false;
4034 378 : for (unsigned int i = 0; i < ndecls; ++i)
4035 : {
4036 308 : tree decl = decls[i];
4037 308 : if (!add)
4038 : {
4039 : /* Skip over labels/case labels after .DEFERRED_INIT for the
4040 : DECL we are looking for. */
4041 396 : while (!tsi_end_p (iter)
4042 396 : && (TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR
4043 284 : || (TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR
4044 25 : && !case_label)))
4045 118 : tsi_prev (&iter);
4046 278 : if (tsi_end_p (iter))
4047 : {
4048 : /* Reached the start, we'll need to prepend further
4049 : statements. */
4050 19 : add = true;
4051 19 : iter = tsi_start (then_clause);
4052 : }
4053 : else
4054 : {
4055 : /* Found something, assert it is .DEFERRED_INIT for
4056 : DECL. */
4057 259 : tree t = tsi_stmt (iter);
4058 259 : gcc_checking_assert (TREE_CODE (t) == EXPR_STMT);
4059 259 : t = EXPR_STMT_EXPR (t);
4060 259 : gcc_checking_assert (TREE_CODE (t) == MODIFY_EXPR
4061 : && TREE_OPERAND (t, 0) == decl
4062 : && (TREE_CODE (TREE_OPERAND (t, 1))
4063 : == CALL_EXPR));
4064 259 : t = TREE_OPERAND (t, 1);
4065 259 : gcc_checking_assert (CALL_EXPR_FN (t) == NULL_TREE
4066 : && (CALL_EXPR_IFN (t)
4067 : == IFN_DEFERRED_INIT));
4068 259 : tsi_prev (&iter);
4069 : }
4070 : }
4071 278 : if (add)
4072 : {
4073 : /* If reached the start in this or some earlier iteration,
4074 : prepend .DEFERRED_INIT call for DECL. */
4075 49 : tree t = build_deferred_init_call (decl);
4076 49 : STMT_IS_FULL_EXPR_P (t) = 1;
4077 49 : tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
4078 : }
4079 : }
4080 70 : if (!add)
4081 : {
4082 : /* If .DEFERRED_INIT calls for all the decls were already there,
4083 : skip over case labels and if we find a LABEL_EXPR, return
4084 : its label. */
4085 63 : while (!tsi_end_p (iter)
4086 63 : && !case_label
4087 117 : && TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR)
4088 12 : tsi_prev (&iter);
4089 51 : if (tsi_end_p (iter))
4090 : {
4091 : /* Only case labels were found and we are looking for normal
4092 : label, we'll need to add it. */
4093 0 : add = true;
4094 0 : iter = tsi_start (then_clause);
4095 : }
4096 51 : else if (!case_label
4097 51 : && TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR)
4098 : /* Return existing label. */
4099 21 : lab = LABEL_EXPR_LABEL (tsi_stmt (iter));
4100 : else
4101 : {
4102 : /* We'll need to add a LABEL_EXPR or move CASE_LABEL_EXPR. */
4103 30 : gcc_checking_assert (case_label
4104 : || (TREE_CODE (tsi_stmt (iter))
4105 : == EXPR_STMT));
4106 30 : add = true;
4107 30 : tsi_next (&iter);
4108 30 : gcc_checking_assert (!tsi_end_p (iter));
4109 : }
4110 : }
4111 21 : if (add)
4112 : {
4113 49 : tree t;
4114 49 : if (case_label)
4115 : t = case_label;
4116 : else
4117 : {
4118 40 : lab = create_artificial_label (UNKNOWN_LOCATION);
4119 40 : t = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
4120 : }
4121 49 : tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
4122 : }
4123 : }
4124 : else
4125 : {
4126 : /* No IF_STMT created by this function found. Create it all
4127 : from scratch, so a LABEL_EXPR (or moved CASE_LABEL_EXPR)
4128 : followed by .DEFERRED_INIT calls inside of a new if (0). */
4129 51 : tree new_then = push_stmt_list ();
4130 51 : if (!case_label)
4131 : {
4132 22 : lab = create_artificial_label (UNKNOWN_LOCATION);
4133 22 : add_stmt (build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab));
4134 : }
4135 : else
4136 29 : add_stmt (case_label);
4137 135 : for (unsigned int i = ndecls; i; --i)
4138 84 : add_stmt (build_deferred_init_call (decls[i - 1]));
4139 51 : new_then = pop_stmt_list (new_then);
4140 51 : tree stmt = build4 (IF_STMT, void_type_node, boolean_false_node,
4141 : new_then, void_node, NULL_TREE);
4142 51 : IF_STMT_VACUOUS_INIT_P (stmt) = 1;
4143 51 : if (tsi_end_p (iter))
4144 : {
4145 6 : iter = tsi_start (iter.container);
4146 6 : tsi_link_before (&iter, stmt, TSI_SAME_STMT);
4147 : }
4148 : else
4149 45 : tsi_link_after (&iter, stmt, TSI_CONTINUE_LINKING);
4150 : }
4151 121 : return lab;
4152 : }
4153 :
4154 : /* Adjust backward gotos to named label ENT if they jump over vacuous
4155 : initializers if !!flag_auto_var_init. ITER is the location of
4156 : LABEL_EXPR for that named label. */
4157 :
4158 : static void
4159 19 : adjust_backward_goto (named_label_entry *ent, tree_stmt_iterator iter)
4160 : {
4161 19 : auto_vec<tree, 4> decls;
4162 19 : unsigned int i, max_cnt = ent->direct_goto->last ().n_bad_decls;
4163 19 : tree decl;
4164 88 : FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, i, decl)
4165 88 : if (!decl_jump_unsafe (decl))
4166 : {
4167 88 : gcc_checking_assert (decl_instrument_init_bypass_p (decl));
4168 88 : decls.safe_push (decl);
4169 176 : if (decls.length () == max_cnt)
4170 : break;
4171 : }
4172 19 : named_label_bck_direct_goto *dgoto;
4173 19 : unsigned last = 0;
4174 19 : tree lab = NULL_TREE;
4175 103 : FOR_EACH_VEC_SAFE_ELT_REVERSE (ent->direct_goto, i, dgoto)
4176 : {
4177 46 : if (dgoto->n_bad_decls != last)
4178 : {
4179 40 : last = dgoto->n_bad_decls;
4180 80 : lab = maybe_add_deferred_init_calls (iter, NULL_TREE,
4181 : decls.address (), last);
4182 : }
4183 46 : *dgoto->direct_goto = lab;
4184 : }
4185 19 : }
4186 :
4187 : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
4188 : to the user. */
4189 :
4190 : static bool
4191 286 : identify_goto (tree decl, location_t loc, const location_t *locus,
4192 : enum diagnostics::kind diag_kind, bool computed)
4193 : {
4194 286 : if (computed)
4195 43 : diag_kind = diagnostics::kind::warning;
4196 286 : bool complained
4197 373 : = emit_diagnostic (diag_kind, loc, 0,
4198 : decl ? G_("jump to label %qD")
4199 : : G_("jump to case label"), decl);
4200 286 : if (complained && locus)
4201 : {
4202 199 : if (computed)
4203 43 : inform (*locus, " as a possible target of computed goto");
4204 : else
4205 156 : inform (*locus, " from here");
4206 : }
4207 286 : return complained;
4208 : }
4209 :
4210 : /* Check that a single previously seen jump to a newly defined label
4211 : is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
4212 : the jump context; NAMES are the names in scope in LEVEL at the jump
4213 : context; LOCUS is the source position of the jump or 0. COMPUTED
4214 : is a vec of decls if the jump is a computed goto. DIRECT_GOTO is a
4215 : vec of pointers to LABEL_DECLs that might need adjusting if vacuous
4216 : initializations are crossed for !!flag_auto_var_init. CASE_LABEL is
4217 : CASE_LABEL_EXPR to be moved if needed for the check_switch_goto case.
4218 : Returns non-zero if all is well, 2 if any vacuous initializers were
4219 : crossed. */
4220 :
4221 : static int
4222 1450693 : check_previous_goto_1 (tree decl, cp_binding_level *level, tree names,
4223 : bool exited_omp, const location_t *locus,
4224 : vec<tree, va_gc> *computed,
4225 : vec<named_label_fwd_direct_goto, va_gc> *direct_goto,
4226 : tree case_label)
4227 : {
4228 1450693 : auto_diagnostic_group d;
4229 1450693 : cp_binding_level *b;
4230 1450693 : bool complained = false;
4231 1450693 : int identified = 0;
4232 1450693 : bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
4233 1450693 : bool saw_ceif = false, saw_se = false;
4234 1450693 : auto_vec<tree> vacuous_decls;
4235 1450693 : bool vacuous_inits = false;
4236 :
4237 1450693 : if (exited_omp)
4238 : {
4239 12 : complained = identify_goto (decl, input_location, locus,
4240 : diagnostics::kind::error,
4241 : computed);
4242 12 : if (complained)
4243 12 : inform (input_location, " exits OpenMP structured block");
4244 : saw_omp = true;
4245 : identified = 2;
4246 : }
4247 :
4248 4323041 : for (b = current_binding_level; b ; b = b->level_chain)
4249 : {
4250 2872348 : tree new_decls, old_decls = (b == level ? names : NULL_TREE);
4251 :
4252 2952245 : for (new_decls = b->names; new_decls != old_decls;
4253 149118 : new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
4254 69221 : : TREE_CHAIN (new_decls)))
4255 : {
4256 79897 : bool problem = decl_jump_unsafe (new_decls);
4257 79897 : if (! problem)
4258 : {
4259 79852 : if (decl_instrument_init_bypass_p (new_decls))
4260 : {
4261 311 : if (direct_goto || case_label)
4262 246 : vacuous_decls.safe_push (new_decls);
4263 : vacuous_inits = true;
4264 : }
4265 79852 : continue;
4266 : }
4267 :
4268 45 : if (!identified)
4269 : {
4270 45 : complained = identify_goto (decl, input_location, locus,
4271 : diagnostics::kind::error,
4272 : computed);
4273 45 : identified = 2;
4274 : }
4275 45 : if (complained)
4276 45 : inform (DECL_SOURCE_LOCATION (new_decls),
4277 : " crosses initialization of %q#D", new_decls);
4278 : }
4279 :
4280 2872348 : if (b == level)
4281 : break;
4282 :
4283 1421655 : const char *inf = NULL;
4284 1421655 : location_t loc = input_location;
4285 1421655 : switch (b->kind)
4286 : {
4287 3 : case sk_try:
4288 3 : if (!saw_eh)
4289 : inf = G_(" enters %<try%> block");
4290 : saw_eh = true;
4291 : break;
4292 :
4293 9 : case sk_catch:
4294 9 : if (!saw_eh)
4295 : inf = G_(" enters %<catch%> block");
4296 : saw_eh = true;
4297 : break;
4298 :
4299 102 : case sk_omp:
4300 102 : if (!saw_omp)
4301 : inf = G_(" enters OpenMP structured block");
4302 : saw_omp = true;
4303 : break;
4304 :
4305 3 : case sk_transaction:
4306 3 : if (!saw_tm)
4307 : inf = G_(" enters synchronized or atomic statement");
4308 : saw_tm = true;
4309 : break;
4310 :
4311 18 : case sk_stmt_expr:
4312 18 : if (!saw_se)
4313 : inf = G_(" enters statement expression");
4314 : saw_se = true;
4315 : break;
4316 :
4317 1421385 : case sk_block:
4318 1421385 : if (!saw_cxif && level_for_constexpr_if (b->level_chain))
4319 : {
4320 9 : inf = G_(" enters %<constexpr if%> statement");
4321 9 : loc = EXPR_LOCATION (b->level_chain->this_entity);
4322 : saw_cxif = true;
4323 : }
4324 1421376 : else if (!saw_ceif && level_for_consteval_if (b->level_chain))
4325 : {
4326 18 : inf = G_(" enters %<consteval if%> statement");
4327 18 : loc = EXPR_LOCATION (b->level_chain->this_entity);
4328 : saw_ceif = true;
4329 : }
4330 : break;
4331 :
4332 : default:
4333 : break;
4334 : }
4335 :
4336 : if (inf)
4337 : {
4338 141 : if (identified < 2)
4339 141 : complained = identify_goto (decl, input_location, locus,
4340 : diagnostics::kind::error,
4341 : computed);
4342 141 : identified = 2;
4343 141 : if (complained)
4344 141 : inform (loc, inf);
4345 : }
4346 : }
4347 :
4348 1450693 : if (!vec_safe_is_empty (computed))
4349 : {
4350 9 : if (!identified)
4351 6 : complained = identify_goto (decl, input_location, locus,
4352 : diagnostics::kind::error,
4353 : computed);
4354 9 : identified = 2;
4355 9 : if (complained)
4356 18 : for (tree d : computed)
4357 : {
4358 9 : if (DECL_P (d))
4359 6 : inform (DECL_SOURCE_LOCATION (d), " does not destroy %qD", d);
4360 3 : else if (d == get_identifier ("catch"))
4361 3 : inform (*locus, " does not clean up handled exception");
4362 : }
4363 : }
4364 :
4365 1450776 : if (!vacuous_decls.is_empty () && !seen_error ())
4366 : {
4367 81 : tree_stmt_iterator iter = tsi_last (cur_stmt_list);
4368 81 : if (case_label)
4369 : {
4370 38 : gcc_checking_assert (tsi_stmt (iter) == case_label);
4371 38 : tsi_delink (&iter);
4372 38 : iter = tsi_last (cur_stmt_list);
4373 : }
4374 81 : tree lab = maybe_add_deferred_init_calls (iter, case_label,
4375 : vacuous_decls.address (),
4376 : vacuous_decls.length ());
4377 81 : if (lab)
4378 : {
4379 : unsigned int i;
4380 : named_label_fwd_direct_goto *dgoto;
4381 167 : FOR_EACH_VEC_SAFE_ELT (direct_goto, i, dgoto)
4382 43 : *dgoto->direct_goto = lab;
4383 : }
4384 : }
4385 :
4386 1450693 : if (identified)
4387 : return 0;
4388 1450489 : return vacuous_inits ? 2 : 1;
4389 1450693 : }
4390 :
4391 : static void
4392 2106 : check_previous_goto (tree decl, struct named_label_use_entry *use)
4393 : {
4394 2106 : check_previous_goto_1 (decl, use->binding_level,
4395 2106 : use->names_in_scope, use->in_omp_scope,
4396 2106 : &use->o_goto_locus, use->computed_goto,
4397 : use->direct_goto, NULL_TREE);
4398 2106 : vec_free (use->direct_goto);
4399 2106 : }
4400 :
4401 : static int
4402 1448587 : check_switch_goto (cp_binding_level *level, tree case_label)
4403 : {
4404 1448587 : return check_previous_goto_1 (NULL_TREE, level, level->names,
4405 1448587 : false, NULL, nullptr, nullptr, case_label);
4406 : }
4407 :
4408 : /* Check that a new jump to a label ENT is OK. DECLP is a pointer
4409 : to a LABEL_DECL for direct gotos and NULL for computed gotos. */
4410 :
4411 : void
4412 2830 : check_goto_1 (named_label_entry *ent, tree *declp)
4413 : {
4414 2830 : auto_diagnostic_group d;
4415 2830 : tree decl = ent->label_decl;
4416 2830 : bool computed = declp == NULL;
4417 :
4418 : /* If the label hasn't been defined yet, defer checking. */
4419 2830 : if (! DECL_INITIAL (decl))
4420 : {
4421 : /* Don't bother creating another use if the last goto had the
4422 : same data, and will therefore create the same set of errors. */
4423 2175 : if (ent->uses
4424 658 : && ent->uses->binding_level == current_binding_level
4425 60 : && ent->uses->names_in_scope == current_binding_level->names)
4426 : {
4427 60 : if (declp
4428 54 : && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
4429 11 : && !processing_template_decl)
4430 9 : vec_safe_push (ent->uses->direct_goto,
4431 9 : named_label_fwd_direct_goto { declp });
4432 60 : return;
4433 : }
4434 :
4435 2115 : named_label_use_entry *new_use
4436 2115 : = ggc_alloc<named_label_use_entry> ();
4437 2115 : new_use->binding_level = current_binding_level;
4438 2115 : new_use->names_in_scope = current_binding_level->names;
4439 2115 : new_use->o_goto_locus = input_location;
4440 2115 : new_use->in_omp_scope = false;
4441 2115 : new_use->computed_goto = computed ? make_tree_vector () : nullptr;
4442 2115 : new_use->direct_goto = nullptr;
4443 2115 : if (declp
4444 2024 : && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
4445 355 : && !processing_template_decl)
4446 298 : vec_safe_push (new_use->direct_goto,
4447 298 : named_label_fwd_direct_goto { declp });
4448 :
4449 2115 : new_use->next = ent->uses;
4450 2115 : ent->uses = new_use;
4451 2115 : return;
4452 : }
4453 :
4454 655 : bool saw_catch = false, complained = false;
4455 655 : int identified = 0;
4456 655 : tree bad;
4457 655 : unsigned ix;
4458 655 : unsigned n_bad_decls = 0;
4459 :
4460 655 : if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
4461 640 : || ent->in_constexpr_if || ent->in_consteval_if
4462 634 : || ent->in_omp_scope || ent->in_stmt_expr
4463 616 : || ent->has_bad_decls)
4464 : {
4465 45 : enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
4466 45 : if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
4467 30 : || ent->in_consteval_if || ent->in_transaction_scope
4468 24 : || ent->in_omp_scope || ent->in_stmt_expr)
4469 39 : diag_kind = diagnostics::kind::error;
4470 45 : complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4471 : &input_location, diag_kind, computed);
4472 45 : identified = 1 + (diag_kind == diagnostics::kind::error);
4473 : }
4474 :
4475 845 : FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
4476 : {
4477 190 : bool problem = decl_jump_unsafe (bad);
4478 190 : if (!problem)
4479 : {
4480 184 : gcc_checking_assert (decl_instrument_init_bypass_p (bad));
4481 184 : n_bad_decls++;
4482 184 : continue;
4483 : }
4484 :
4485 6 : if (DECL_ARTIFICIAL (bad))
4486 : {
4487 : /* Can't skip init of __exception_info. */
4488 0 : if (identified == 1)
4489 : {
4490 0 : complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4491 : &input_location,
4492 : diagnostics::kind::error,
4493 : computed);
4494 0 : identified = 2;
4495 : }
4496 0 : if (complained)
4497 0 : inform (DECL_SOURCE_LOCATION (bad), " enters %<catch%> block");
4498 : saw_catch = true;
4499 : }
4500 6 : else if (complained)
4501 6 : inform (DECL_SOURCE_LOCATION (bad),
4502 : " skips initialization of %q#D", bad);
4503 : }
4504 :
4505 655 : if (complained)
4506 : {
4507 45 : if (ent->in_try_scope)
4508 9 : inform (input_location, " enters %<try%> block");
4509 36 : else if (ent->in_catch_scope && !saw_catch)
4510 3 : inform (input_location, " enters %<catch%> block");
4511 33 : else if (ent->in_transaction_scope)
4512 3 : inform (input_location, " enters synchronized or atomic statement");
4513 30 : else if (ent->in_constexpr_if)
4514 3 : inform (input_location, " enters %<constexpr if%> statement");
4515 27 : else if (ent->in_consteval_if)
4516 3 : inform (input_location, " enters %<consteval if%> statement");
4517 24 : else if (ent->in_stmt_expr)
4518 15 : inform (input_location, " enters statement expression");
4519 : }
4520 :
4521 655 : if (ent->in_omp_scope)
4522 : {
4523 3 : if (complained)
4524 3 : inform (input_location, " enters OpenMP structured block");
4525 : }
4526 652 : else if (flag_openmp)
4527 69 : for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
4528 : {
4529 42 : if (b == ent->binding_level)
4530 : break;
4531 36 : if (b->kind == sk_omp)
4532 : {
4533 21 : if (identified < 2)
4534 : {
4535 42 : complained = identify_goto (decl,
4536 21 : DECL_SOURCE_LOCATION (decl),
4537 : &input_location,
4538 : diagnostics::kind::error,
4539 : computed);
4540 21 : identified = 2;
4541 : }
4542 21 : if (complained)
4543 21 : inform (input_location, " exits OpenMP structured block");
4544 : break;
4545 : }
4546 : }
4547 :
4548 : /* Warn if a computed goto might involve a local variable going out of scope
4549 : without being cleaned up. */
4550 655 : if (computed)
4551 : {
4552 71 : auto level = ent->binding_level;
4553 71 : auto names = ent->names_in_scope;
4554 71 : for (auto b = current_binding_level; ; b = b->level_chain)
4555 : {
4556 111 : if (b->kind == sk_catch)
4557 : {
4558 6 : if (!identified)
4559 : {
4560 6 : complained
4561 6 : = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4562 : &input_location, diagnostics::kind::error,
4563 : computed);
4564 6 : identified = 2;
4565 : }
4566 6 : if (complained)
4567 6 : inform (input_location,
4568 : " does not clean up handled exception");
4569 : }
4570 111 : tree end = b == level ? names : NULL_TREE;
4571 127 : for (tree d = b->names; d != end; d = DECL_CHAIN (d))
4572 : {
4573 16 : if (automatic_var_with_nontrivial_dtor_p (d))
4574 : {
4575 10 : if (!identified)
4576 : {
4577 10 : complained
4578 10 : = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4579 : &input_location, diagnostics::kind::error,
4580 : computed);
4581 10 : identified = 2;
4582 : }
4583 10 : if (complained)
4584 10 : inform (DECL_SOURCE_LOCATION (d),
4585 : " does not destroy %qD", d);
4586 : }
4587 : }
4588 111 : if (b == level)
4589 : break;
4590 40 : }
4591 : }
4592 :
4593 655 : if (n_bad_decls && declp)
4594 46 : vec_safe_push (ent->direct_goto,
4595 46 : named_label_bck_direct_goto { declp, n_bad_decls });
4596 2830 : }
4597 :
4598 : /* Check that a new jump to a label *DECLP is OK. Called by
4599 : finish_goto_stmt. */
4600 :
4601 : void
4602 2790 : check_goto (tree *declp)
4603 : {
4604 2790 : if (!named_labels)
4605 : return;
4606 2775 : tree decl = *declp;
4607 2775 : if (TREE_CODE (decl) != LABEL_DECL)
4608 : {
4609 : /* We don't know where a computed goto is jumping,
4610 : so check all addressable labels. */
4611 312 : for (auto iter = named_labels->begin ();
4612 425 : iter != named_labels->end ();
4613 199 : ++iter)
4614 : {
4615 199 : auto ent = *iter;
4616 199 : if (ent->addressed)
4617 168 : check_goto_1 (ent, NULL);
4618 : }
4619 : }
4620 : else
4621 : {
4622 2662 : hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
4623 2662 : named_label_entry **slot
4624 2662 : = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
4625 2662 : named_label_entry *ent = *slot;
4626 2662 : check_goto_1 (ent, declp);
4627 : }
4628 : }
4629 :
4630 : /* Check that a return is ok wrt OpenMP structured blocks.
4631 : Called by finish_return_stmt. Returns true if all is well. */
4632 :
4633 : bool
4634 278590 : check_omp_return (void)
4635 : {
4636 1105007 : for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
4637 826417 : if (b->kind == sk_omp)
4638 : {
4639 15 : error ("invalid exit from OpenMP structured block");
4640 15 : return false;
4641 : }
4642 826402 : else if (b->kind == sk_function_parms)
4643 : break;
4644 : return true;
4645 : }
4646 :
4647 : /* Define a label, specifying the location in the source file.
4648 : Return the LABEL_DECL node for the label. */
4649 :
4650 : tree
4651 20676 : define_label (location_t location, tree name)
4652 : {
4653 20676 : auto_cond_timevar tv (TV_NAME_LOOKUP);
4654 :
4655 : /* After labels, make any new cleanups in the function go into their
4656 : own new (temporary) binding contour. */
4657 20676 : for (cp_binding_level *p = current_binding_level;
4658 31316 : p->kind != sk_function_parms;
4659 10640 : p = p->level_chain)
4660 10640 : p->more_cleanups_ok = 0;
4661 :
4662 20676 : named_label_entry *ent = lookup_label_1 (name, false);
4663 20676 : tree decl = ent->label_decl;
4664 :
4665 20676 : if (DECL_INITIAL (decl) != NULL_TREE)
4666 : {
4667 6 : error ("duplicate label %qD", decl);
4668 6 : return error_mark_node;
4669 : }
4670 : else
4671 : {
4672 : /* Mark label as having been defined. */
4673 20670 : DECL_INITIAL (decl) = error_mark_node;
4674 : /* Say where in the source. */
4675 20670 : DECL_SOURCE_LOCATION (decl) = location;
4676 :
4677 20670 : ent->binding_level = current_binding_level;
4678 20670 : ent->names_in_scope = current_binding_level->names;
4679 :
4680 22776 : for (named_label_use_entry *use = ent->uses; use; use = use->next)
4681 2106 : check_previous_goto (decl, use);
4682 20670 : ent->uses = NULL;
4683 : }
4684 :
4685 20670 : return decl;
4686 20676 : }
4687 :
4688 : struct cp_switch
4689 : {
4690 : cp_binding_level *level;
4691 : struct cp_switch *next;
4692 : /* The SWITCH_STMT being built. */
4693 : tree switch_stmt;
4694 : /* A splay-tree mapping the low element of a case range to the high
4695 : element, or NULL_TREE if there is no high element. Used to
4696 : determine whether or not a new case label duplicates an old case
4697 : label. We need a tree, rather than simply a hash table, because
4698 : of the GNU case range extension. */
4699 : splay_tree cases;
4700 : /* Remember whether a default: case label has been seen. */
4701 : bool has_default_p;
4702 : /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT. */
4703 : bool break_stmt_seen_p;
4704 : /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
4705 : where BREAK_STMT doesn't belong to the SWITCH_STMT. */
4706 : bool in_loop_body_p;
4707 : };
4708 :
4709 : /* A stack of the currently active switch statements. The innermost
4710 : switch statement is on the top of the stack. There is no need to
4711 : mark the stack for garbage collection because it is only active
4712 : during the processing of the body of a function, and we never
4713 : collect at that point. */
4714 :
4715 : static struct cp_switch *switch_stack;
4716 :
4717 : /* Called right after a switch-statement condition is parsed.
4718 : SWITCH_STMT is the switch statement being parsed. */
4719 :
4720 : void
4721 669248 : push_switch (tree switch_stmt)
4722 : {
4723 669248 : struct cp_switch *p = XNEW (struct cp_switch);
4724 669248 : p->level = current_binding_level;
4725 669248 : p->next = switch_stack;
4726 669248 : p->switch_stmt = switch_stmt;
4727 669248 : p->cases = splay_tree_new (case_compare, NULL, NULL);
4728 669248 : p->has_default_p = false;
4729 669248 : p->break_stmt_seen_p = false;
4730 669248 : p->in_loop_body_p = false;
4731 669248 : switch_stack = p;
4732 669248 : }
4733 :
4734 : void
4735 669248 : pop_switch (void)
4736 : {
4737 669248 : struct cp_switch *cs = switch_stack;
4738 :
4739 : /* Emit warnings as needed. */
4740 669248 : location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
4741 669248 : tree cond = SWITCH_STMT_COND (cs->switch_stmt);
4742 669248 : const bool bool_cond_p
4743 669248 : = (SWITCH_STMT_TYPE (cs->switch_stmt)
4744 669248 : && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
4745 669248 : if (!processing_template_decl)
4746 259558 : c_do_switch_warnings (cs->cases, switch_location,
4747 259558 : SWITCH_STMT_TYPE (cs->switch_stmt), cond,
4748 : bool_cond_p);
4749 :
4750 : /* For the benefit of block_may_fallthru remember if the switch body
4751 : case labels cover all possible values and if there are break; stmts. */
4752 669248 : if (cs->has_default_p
4753 669248 : || (!processing_template_decl
4754 39369 : && c_switch_covers_all_cases_p (cs->cases,
4755 39369 : SWITCH_STMT_TYPE (cs->switch_stmt))))
4756 488886 : SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
4757 669248 : if (!cs->break_stmt_seen_p)
4758 338709 : SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
4759 : /* Now that we're done with the switch warnings, set the switch type
4760 : to the type of the condition if the index type was of scoped enum type.
4761 : (Such types don't participate in the integer promotions.) We do this
4762 : because of bit-fields whose declared type is a scoped enum type:
4763 : gimplification will use the lowered index type, but convert the
4764 : case values to SWITCH_STMT_TYPE, which would have been the declared type
4765 : and verify_gimple_switch doesn't accept that. */
4766 669248 : if (is_bitfield_expr_with_lowered_type (cond))
4767 20882 : SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
4768 669248 : gcc_assert (!cs->in_loop_body_p);
4769 669248 : splay_tree_delete (cs->cases);
4770 669248 : switch_stack = switch_stack->next;
4771 669248 : free (cs);
4772 669248 : }
4773 :
4774 : /* Note that a BREAK_STMT is about to be added. If it is inside of
4775 : a SWITCH_STMT and not inside of a loop body inside of it, note
4776 : in switch_stack we've seen a BREAK_STMT. */
4777 :
4778 : void
4779 4657397 : note_break_stmt (void)
4780 : {
4781 4657397 : if (switch_stack && !switch_stack->in_loop_body_p)
4782 2595412 : switch_stack->break_stmt_seen_p = true;
4783 4657397 : }
4784 :
4785 : /* Note the start of processing of an iteration statement's body.
4786 : The note_break_stmt function will do nothing while processing it.
4787 : Return a flag that should be passed to note_iteration_stmt_body_end. */
4788 :
4789 : bool
4790 17578933 : note_iteration_stmt_body_start (void)
4791 : {
4792 17578933 : if (!switch_stack)
4793 : return false;
4794 183495 : bool ret = switch_stack->in_loop_body_p;
4795 183495 : switch_stack->in_loop_body_p = true;
4796 183495 : return ret;
4797 : }
4798 :
4799 : /* Note the end of processing of an iteration statement's body. */
4800 :
4801 : void
4802 17578933 : note_iteration_stmt_body_end (bool prev)
4803 : {
4804 17578933 : if (switch_stack)
4805 183495 : switch_stack->in_loop_body_p = prev;
4806 17578933 : }
4807 :
4808 : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
4809 : condition. Note that if TYPE and VALUE are already integral we don't
4810 : really do the conversion because the language-independent
4811 : warning/optimization code will work better that way. */
4812 :
4813 : static tree
4814 2896850 : case_conversion (tree type, tree value)
4815 : {
4816 2896850 : if (value == NULL_TREE)
4817 : return value;
4818 :
4819 1228404 : value = mark_rvalue_use (value);
4820 :
4821 1228404 : if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
4822 952392 : type = type_promotes_to (type);
4823 :
4824 1228404 : tree ovalue = value;
4825 : /* The constant-expression VALUE shall be a converted constant expression
4826 : of the adjusted type of the switch condition, which doesn't allow
4827 : narrowing conversions. */
4828 1228404 : value = build_converted_constant_expr (type, value, tf_warning_or_error);
4829 :
4830 1228404 : if (cxx_dialect >= cxx11
4831 1228404 : && (SCOPED_ENUM_P (type)
4832 949271 : || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
4833 : /* Use the converted value. */;
4834 : else
4835 : /* The already integral case. */
4836 : value = ovalue;
4837 :
4838 1228404 : return cxx_constant_value (value);
4839 : }
4840 :
4841 : /* Note that we've seen a definition of a case label, and complain if this
4842 : is a bad place for one. */
4843 :
4844 : tree
4845 5337331 : finish_case_label (location_t loc, tree low_value, tree high_value)
4846 : {
4847 5337331 : tree cond, r;
4848 5337331 : cp_binding_level *p;
4849 5337331 : tree type;
4850 :
4851 5337331 : if (low_value == NULL_TREE && high_value == NULL_TREE)
4852 488850 : switch_stack->has_default_p = true;
4853 :
4854 5337331 : if (processing_template_decl)
4855 : {
4856 3888783 : tree label;
4857 :
4858 : /* For templates, just add the case label; we'll do semantic
4859 : analysis at instantiation-time. But diagnose case labels
4860 : in expansion statements with switch outside of it here. */
4861 3888783 : if (in_expansion_stmt)
4862 39 : for (cp_binding_level *b = current_binding_level;
4863 78 : b != switch_stack->level; b = b->level_chain)
4864 63 : if (b->kind == sk_template_for && b->this_entity)
4865 : {
4866 24 : auto_diagnostic_group d;
4867 24 : error ("jump to case label");
4868 24 : inform (EXPR_LOCATION (b->this_entity),
4869 : " enters %<template for%> statement");
4870 24 : return error_mark_node;
4871 24 : }
4872 3888759 : label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
4873 3888759 : return add_stmt (build_case_label (low_value, high_value, label));
4874 : }
4875 :
4876 : /* Find the condition on which this switch statement depends. */
4877 1448548 : cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
4878 1448548 : if (cond && TREE_CODE (cond) == TREE_LIST)
4879 0 : cond = TREE_VALUE (cond);
4880 :
4881 1448548 : int chk_switch_goto = check_switch_goto (switch_stack->level, NULL_TREE);
4882 1448548 : if (!chk_switch_goto)
4883 87 : return error_mark_node;
4884 :
4885 1448461 : type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
4886 1448461 : if (type == error_mark_node)
4887 : return error_mark_node;
4888 :
4889 1448425 : low_value = case_conversion (type, low_value);
4890 1448425 : high_value = case_conversion (type, high_value);
4891 :
4892 1448425 : r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
4893 :
4894 1448425 : if (r != error_mark_node && chk_switch_goto == 2)
4895 39 : check_switch_goto (switch_stack->level, r);
4896 :
4897 : /* After labels, make any new cleanups in the function go into their
4898 : own new (temporary) binding contour. */
4899 1448425 : for (p = current_binding_level;
4900 6139853 : p->kind != sk_function_parms;
4901 4691428 : p = p->level_chain)
4902 4691428 : p->more_cleanups_ok = 0;
4903 :
4904 : return r;
4905 : }
4906 :
4907 : struct typename_info {
4908 : tree scope;
4909 : tree name;
4910 : tree template_id;
4911 : tag_types tag_type;
4912 : };
4913 :
4914 : struct typename_hasher : ggc_ptr_hash<tree_node>
4915 : {
4916 : typedef typename_info *compare_type;
4917 :
4918 : /* Hash a TYPENAME_TYPE. */
4919 :
4920 : static hashval_t
4921 433046509 : hash (tree context, tree fullname)
4922 : {
4923 433046509 : hashval_t hash = 0;
4924 433046509 : hash = iterative_hash_object (context, hash);
4925 433046509 : hash = iterative_hash_object (fullname, hash);
4926 433046509 : return hash;
4927 : }
4928 :
4929 : static hashval_t
4930 61159362 : hash (const typename_info *ti)
4931 : {
4932 61159362 : return typename_hasher::hash (ti->scope, ti->template_id);
4933 : }
4934 :
4935 : static hashval_t
4936 371887147 : hash (tree t)
4937 : {
4938 371887147 : return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
4939 : }
4940 :
4941 : /* Compare two TYPENAME_TYPEs. */
4942 :
4943 : static bool
4944 438377273 : equal (tree t1, const typename_info *t2)
4945 : {
4946 438377273 : return (TYPE_IDENTIFIER (t1) == t2->name
4947 140147172 : && TYPE_CONTEXT (t1) == t2->scope
4948 31063586 : && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
4949 469429398 : && get_typename_tag (t1) == t2->tag_type);
4950 : }
4951 : };
4952 :
4953 : /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
4954 : the type of `T', NAME is the IDENTIFIER_NODE for `t'.
4955 :
4956 : Returns the new TYPENAME_TYPE. */
4957 :
4958 : static GTY (()) hash_table<typename_hasher> *typename_htab;
4959 :
4960 : tree
4961 61159362 : build_typename_type (tree context, tree name, tree fullname,
4962 : enum tag_types tag_type)
4963 : {
4964 61159362 : typename_info ti;
4965 :
4966 61159362 : if (typename_htab == NULL)
4967 19282 : typename_htab = hash_table<typename_hasher>::create_ggc (61);
4968 :
4969 61159362 : ti.scope = FROB_CONTEXT (context);
4970 61159362 : ti.name = name;
4971 61159362 : ti.template_id = fullname;
4972 61159362 : ti.tag_type = tag_type;
4973 61159362 : hashval_t hash = typename_hasher::hash (&ti);
4974 :
4975 : /* See if we already have this type. */
4976 61159362 : tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
4977 61159362 : tree t = *e;
4978 61159362 : if (*e)
4979 : t = *e;
4980 : else
4981 : {
4982 : /* Build the TYPENAME_TYPE. */
4983 31163543 : t = cxx_make_type (TYPENAME_TYPE);
4984 31163543 : TYPE_CONTEXT (t) = ti.scope;
4985 31163543 : TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
4986 31163543 : set_typename_tag (t, ti.tag_type);
4987 :
4988 : /* Build the corresponding TYPE_DECL. */
4989 31163543 : tree d = build_decl (input_location, TYPE_DECL, name, t);
4990 31163543 : TYPE_NAME (t) = d;
4991 31163543 : TYPE_STUB_DECL (t) = d;
4992 31163543 : DECL_CONTEXT (d) = ti.scope;
4993 31163543 : DECL_ARTIFICIAL (d) = 1;
4994 :
4995 : /* Store it in the hash table. */
4996 31163543 : *e = t;
4997 :
4998 : /* TYPENAME_TYPEs must always be compared structurally, because
4999 : they may or may not resolve down to another type depending on
5000 : the currently open classes. */
5001 31163543 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5002 : }
5003 :
5004 61159362 : return t;
5005 : }
5006 :
5007 : /* Resolve `typename CONTEXT::NAME'. TAG_TYPE indicates the tag
5008 : provided to name the type. Returns an appropriate type, unless an
5009 : error occurs, in which case error_mark_node is returned. If we
5010 : locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
5011 : return that, rather than the _TYPE it corresponds to, in other
5012 : cases we look through the type decl. If TF_ERROR is set, complain
5013 : about errors, otherwise be quiet. */
5014 :
5015 : tree
5016 253538840 : make_typename_type (tree context, tree name, enum tag_types tag_type,
5017 : tsubst_flags_t complain)
5018 : {
5019 253538840 : tree fullname;
5020 253538840 : tree t;
5021 253538840 : bool want_template;
5022 :
5023 253538840 : if (name == error_mark_node
5024 253538834 : || context == NULL_TREE
5025 253538834 : || context == error_mark_node)
5026 : return error_mark_node;
5027 :
5028 253538818 : if (TYPE_P (name))
5029 : {
5030 0 : if (!(TYPE_LANG_SPECIFIC (name)
5031 0 : && (CLASSTYPE_IS_TEMPLATE (name)
5032 0 : || CLASSTYPE_USE_TEMPLATE (name))))
5033 0 : name = TYPE_IDENTIFIER (name);
5034 : else
5035 : /* Create a TEMPLATE_ID_EXPR for the type. */
5036 0 : name = build_nt (TEMPLATE_ID_EXPR,
5037 0 : CLASSTYPE_TI_TEMPLATE (name),
5038 0 : CLASSTYPE_TI_ARGS (name));
5039 : }
5040 253538818 : else if (TREE_CODE (name) == TYPE_DECL)
5041 0 : name = DECL_NAME (name);
5042 :
5043 253538818 : fullname = name;
5044 :
5045 253538818 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
5046 : {
5047 5012455 : name = TREE_OPERAND (name, 0);
5048 5012455 : if (DECL_TYPE_TEMPLATE_P (name))
5049 0 : name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
5050 5012455 : if (TREE_CODE (name) != IDENTIFIER_NODE)
5051 : {
5052 0 : if (complain & tf_error)
5053 0 : error ("%qD is not a type", name);
5054 0 : return error_mark_node;
5055 : }
5056 : }
5057 253538818 : if (TREE_CODE (name) == TEMPLATE_DECL)
5058 : {
5059 0 : if (complain & tf_error)
5060 0 : error ("%qD used without template arguments", name);
5061 0 : return error_mark_node;
5062 : }
5063 253538818 : else if (is_overloaded_fn (name))
5064 : {
5065 3 : if (complain & tf_error)
5066 3 : error ("%qD is a function, not a type", name);
5067 3 : return error_mark_node;
5068 : }
5069 253538815 : gcc_assert (identifier_p (name));
5070 253538815 : gcc_assert (TYPE_P (context));
5071 :
5072 253538815 : if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
5073 : /* This can happen for C++17 variadic using (c++/88986). */;
5074 240712677 : else if (!MAYBE_CLASS_TYPE_P (context))
5075 : {
5076 6 : if (complain & tf_error)
5077 6 : error ("%q#T is not a class", context);
5078 6 : return error_mark_node;
5079 : }
5080 :
5081 : /* When the CONTEXT is a dependent type, NAME could refer to a
5082 : dependent base class of CONTEXT. But look inside it anyway
5083 : if CONTEXT is a currently open scope, in case it refers to a
5084 : member of the current instantiation or a non-dependent base;
5085 : lookup will stop when we hit a dependent base. */
5086 253538809 : if (!dependent_scope_p (context))
5087 : {
5088 : /* We generally don't ignore non-types during TYPENAME_TYPE lookup
5089 : (as per [temp.res.general]/3), unless
5090 : - the tag corresponds to a class-key or 'enum' so
5091 : [basic.lookup.elab] applies, or
5092 : - the tag corresponds to scope_type or tf_qualifying_scope is
5093 : set so [basic.lookup.qual]/1 applies, or
5094 : - we're inside a base-specifier so [class.derived.general]/2 applies;
5095 : the tag will already be class_type in that case.
5096 : TODO: If we'd set/track the scope_type tag thoroughly on all
5097 : TYPENAME_TYPEs that are followed by :: then we wouldn't need the
5098 : tf_qualifying_scope flag. */
5099 394120112 : bool want_type = (tag_type != none_type && tag_type != typename_type)
5100 197060056 : || (complain & tf_qualifying_scope);
5101 197060056 : t = lookup_member (context, name, /*protect=*/2, want_type, complain);
5102 : }
5103 : else
5104 : t = NULL_TREE;
5105 :
5106 272635350 : if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
5107 56479677 : return build_typename_type (context, name, fullname, tag_type);
5108 :
5109 197059132 : want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
5110 :
5111 197059132 : if (!t)
5112 : {
5113 19095617 : if (complain & tf_error)
5114 : {
5115 223 : if (!COMPLETE_TYPE_P (context))
5116 18 : cxx_incomplete_type_error (NULL_TREE, context);
5117 : else
5118 409 : error (want_template ? G_("no class template named %q#T in %q#T")
5119 : : G_("no type named %q#T in %q#T"), name, context);
5120 : }
5121 19095617 : return error_mark_node;
5122 : }
5123 :
5124 : /* Pull out the template from an injected-class-name (or multiple). */
5125 177963515 : if (want_template)
5126 3177169 : t = maybe_get_template_decl_from_type_decl (t);
5127 :
5128 177963515 : if (TREE_CODE (t) == TREE_LIST)
5129 : {
5130 3 : if (complain & tf_error)
5131 : {
5132 3 : auto_diagnostic_group d;
5133 3 : error ("lookup of %qT in %qT is ambiguous", name, context);
5134 3 : print_candidates (input_location, t);
5135 3 : }
5136 3 : return error_mark_node;
5137 : }
5138 :
5139 177963512 : if (want_template && !DECL_TYPE_TEMPLATE_P (t))
5140 : {
5141 6 : if (complain & tf_error)
5142 6 : error ("%<typename %T::%D%> names %q#T, which is not a class template",
5143 : context, name, t);
5144 6 : return error_mark_node;
5145 : }
5146 177963506 : if (!want_template && TREE_CODE (t) != TYPE_DECL)
5147 : {
5148 1469 : if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
5149 2941 : && DECL_TYPE_TEMPLATE_P (t))
5150 : /* The caller permits this typename-specifier to name a template
5151 : (because it appears in a CTAD-enabled context). */;
5152 : else
5153 : {
5154 23 : if (complain & tf_error)
5155 17 : error ("%<typename %T::%D%> names %q#D, which is not a type",
5156 : context, name, t);
5157 23 : return error_mark_node;
5158 : }
5159 : }
5160 :
5161 177963483 : if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
5162 : context, complain))
5163 46 : return error_mark_node;
5164 :
5165 177963437 : if (!want_template && DECL_TYPE_TEMPLATE_P (t))
5166 1458 : return make_template_placeholder (t);
5167 :
5168 177961979 : if (want_template)
5169 : {
5170 3177163 : t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
5171 : NULL_TREE, context,
5172 : complain | tf_user);
5173 3177163 : if (t == error_mark_node)
5174 : return error_mark_node;
5175 3177158 : t = TYPE_NAME (t);
5176 : }
5177 :
5178 177961974 : if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
5179 2166855 : t = TREE_TYPE (t);
5180 :
5181 177961974 : maybe_record_typedef_use (t);
5182 :
5183 177961974 : return t;
5184 : }
5185 :
5186 : /* Resolve `CONTEXT::template NAME'. Returns a TEMPLATE_DECL if the name
5187 : can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
5188 : in which case error_mark_node is returned.
5189 :
5190 : If PARM_LIST is non-NULL, also make sure that the template parameter
5191 : list of TEMPLATE_DECL matches.
5192 :
5193 : If COMPLAIN zero, don't complain about any errors that occur. */
5194 :
5195 : tree
5196 175950 : make_unbound_class_template (tree context, tree name, tree parm_list,
5197 : tsubst_flags_t complain)
5198 : {
5199 175950 : if (TYPE_P (name))
5200 0 : name = TYPE_IDENTIFIER (name);
5201 175950 : else if (DECL_P (name))
5202 0 : name = DECL_NAME (name);
5203 175950 : gcc_assert (identifier_p (name));
5204 :
5205 175950 : if (!dependent_type_p (context)
5206 175950 : || currently_open_class (context))
5207 : {
5208 85968 : tree tmpl = NULL_TREE;
5209 :
5210 85968 : if (MAYBE_CLASS_TYPE_P (context))
5211 85962 : tmpl = lookup_field (context, name, 0, false);
5212 :
5213 85962 : if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
5214 3 : tmpl = maybe_get_template_decl_from_type_decl (tmpl);
5215 :
5216 85956 : if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
5217 : {
5218 12 : if (complain & tf_error)
5219 9 : error ("no class template named %q#T in %q#T", name, context);
5220 12 : return error_mark_node;
5221 : }
5222 :
5223 85956 : if (parm_list
5224 85956 : && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
5225 : {
5226 0 : if (complain & tf_error)
5227 : {
5228 0 : auto_diagnostic_group d;
5229 0 : error ("template parameters do not match template %qD", tmpl);
5230 0 : inform (DECL_SOURCE_LOCATION (tmpl),
5231 : "%qD declared here", tmpl);
5232 0 : }
5233 0 : return error_mark_node;
5234 : }
5235 :
5236 85956 : if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
5237 : complain))
5238 0 : return error_mark_node;
5239 :
5240 : return tmpl;
5241 : }
5242 :
5243 89982 : return make_unbound_class_template_raw (context, name, parm_list);
5244 : }
5245 :
5246 : /* Build an UNBOUND_CLASS_TEMPLATE. */
5247 :
5248 : tree
5249 90034 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
5250 : {
5251 : /* Build the UNBOUND_CLASS_TEMPLATE. */
5252 90034 : tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
5253 90034 : TYPE_CONTEXT (t) = FROB_CONTEXT (context);
5254 90034 : TREE_TYPE (t) = NULL_TREE;
5255 90034 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5256 :
5257 : /* Build the corresponding TEMPLATE_DECL. */
5258 90034 : tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
5259 90034 : TYPE_NAME (t) = d;
5260 90034 : TYPE_STUB_DECL (t) = d;
5261 90034 : DECL_CONTEXT (d) = TYPE_CONTEXT (t);
5262 90034 : DECL_ARTIFICIAL (d) = 1;
5263 90034 : DECL_TEMPLATE_PARMS (d) = parm_list;
5264 :
5265 90034 : return t;
5266 : }
5267 :
5268 :
5269 :
5270 : /* Push the declarations of builtin types into the global namespace.
5271 : RID_INDEX is the index of the builtin type in the array
5272 : RID_POINTERS. NAME is the name used when looking up the builtin
5273 : type. TYPE is the _TYPE node for the builtin type.
5274 :
5275 : The calls to set_global_binding below should be
5276 : eliminated. Built-in types should not be looked up name; their
5277 : names are keywords that the parser can recognize. However, there
5278 : is code in c-common.cc that uses identifier_global_value to look up
5279 : built-in types by name. */
5280 :
5281 : void
5282 4076913 : record_builtin_type (enum rid rid_index,
5283 : const char* name,
5284 : tree type)
5285 : {
5286 4076913 : tree decl = NULL_TREE;
5287 :
5288 4076913 : if (name)
5289 : {
5290 2405252 : tree tname = get_identifier (name);
5291 2405252 : tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
5292 2405252 : DECL_ARTIFICIAL (tdecl) = 1;
5293 2405252 : set_global_binding (tdecl);
5294 2405252 : decl = tdecl;
5295 : }
5296 :
5297 4076913 : if ((int) rid_index < (int) RID_MAX)
5298 2503006 : if (tree rname = ridpointers[(int) rid_index])
5299 1913008 : if (!decl || DECL_NAME (decl) != rname)
5300 : {
5301 1376662 : tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
5302 1376662 : DECL_ARTIFICIAL (rdecl) = 1;
5303 1376662 : set_global_binding (rdecl);
5304 1376662 : if (!decl)
5305 : decl = rdecl;
5306 : }
5307 :
5308 3781914 : if (decl)
5309 : {
5310 3486915 : if (!TYPE_NAME (type))
5311 2896917 : TYPE_NAME (type) = decl;
5312 3486915 : debug_hooks->type_decl (decl, 0);
5313 : }
5314 4076913 : }
5315 :
5316 : /* Push a type into the namespace so that the back ends ignore it. */
5317 :
5318 : static void
5319 294999 : record_unknown_type (tree type, const char* name)
5320 : {
5321 294999 : tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
5322 : TYPE_DECL, get_identifier (name), type));
5323 : /* Make sure the "unknown type" typedecl gets ignored for debug info. */
5324 294999 : DECL_IGNORED_P (decl) = 1;
5325 294999 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
5326 294999 : TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
5327 294999 : SET_TYPE_ALIGN (type, 1);
5328 294999 : TYPE_USER_ALIGN (type) = 0;
5329 294999 : SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
5330 294999 : }
5331 :
5332 : /* Create all the predefined identifiers. */
5333 :
5334 : static void
5335 98333 : initialize_predefined_identifiers (void)
5336 : {
5337 98333 : struct predefined_identifier
5338 : {
5339 : const char *name; /* Name. */
5340 : tree *node; /* Node to store it in. */
5341 : cp_identifier_kind kind; /* Kind of identifier. */
5342 : };
5343 :
5344 : /* A table of identifiers to create at startup. */
5345 98333 : static const predefined_identifier predefined_identifiers[] = {
5346 : {"C++", &lang_name_cplusplus, cik_normal},
5347 : {"C", &lang_name_c, cik_normal},
5348 : /* Some of these names have a trailing space so that it is
5349 : impossible for them to conflict with names written by users. */
5350 : {"__ct ", &ctor_identifier, cik_ctor},
5351 : {"__ct_base ", &base_ctor_identifier, cik_ctor},
5352 : {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
5353 : {"__dt ", &dtor_identifier, cik_dtor},
5354 : {"__dt_base ", &base_dtor_identifier, cik_dtor},
5355 : {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
5356 : {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
5357 : {"__conv_op ", &conv_op_identifier, cik_conv_op},
5358 : {"__in_chrg", &in_charge_identifier, cik_normal},
5359 : {"__as_base ", &as_base_identifier, cik_normal},
5360 : {"this", &this_identifier, cik_normal},
5361 : {"__delta", &delta_identifier, cik_normal},
5362 : {"__pfn", &pfn_identifier, cik_normal},
5363 : {"_vptr", &vptr_identifier, cik_normal},
5364 : {"__vtt_parm", &vtt_parm_identifier, cik_normal},
5365 : {"::", &global_identifier, cik_normal},
5366 : /* The demangler expects anonymous namespaces to be called
5367 : something starting with '_GLOBAL__N_'. It no longer needs
5368 : to be unique to the TU. */
5369 : {"_GLOBAL__N_1", &anon_identifier, cik_normal},
5370 : {"auto", &auto_identifier, cik_normal},
5371 : {"decltype(auto)", &decltype_auto_identifier, cik_normal},
5372 : {"initializer_list", &init_list_identifier, cik_normal},
5373 : {"__for_range ", &for_range__identifier, cik_normal},
5374 : {"__for_begin ", &for_begin__identifier, cik_normal},
5375 : {"__for_end ", &for_end__identifier, cik_normal},
5376 : {"__for_range", &for_range_identifier, cik_normal},
5377 : {"__for_begin", &for_begin_identifier, cik_normal},
5378 : {"__for_end", &for_end_identifier, cik_normal},
5379 : {"abi_tag", &abi_tag_identifier, cik_normal},
5380 : {"aligned", &aligned_identifier, cik_normal},
5381 : {"begin", &begin_identifier, cik_normal},
5382 : {"end", &end_identifier, cik_normal},
5383 : {"get", &get__identifier, cik_normal},
5384 : {"gnu", &gnu_identifier, cik_normal},
5385 : {"tuple_element", &tuple_element_identifier, cik_normal},
5386 : {"tuple_size", &tuple_size_identifier, cik_normal},
5387 : {"type", &type_identifier, cik_normal},
5388 : {"value", &value_identifier, cik_normal},
5389 : {"_FUN", &fun_identifier, cik_normal},
5390 : {"__closure", &closure_identifier, cik_normal},
5391 : {"heap uninit", &heap_uninit_identifier, cik_normal},
5392 : {"heap ", &heap_identifier, cik_normal},
5393 : {"heap deleted", &heap_deleted_identifier, cik_normal},
5394 : {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
5395 : {"heap []", &heap_vec_identifier, cik_normal},
5396 : {"omp", &omp_identifier, cik_normal},
5397 : {"internal ", &internal_identifier, cik_normal},
5398 : {"annotation ", &annotation_identifier, cik_normal},
5399 : {NULL, NULL, cik_normal}
5400 : };
5401 :
5402 4818317 : for (const predefined_identifier *pid = predefined_identifiers;
5403 4818317 : pid->name; ++pid)
5404 : {
5405 4719984 : *pid->node = get_identifier (pid->name);
5406 : /* Some of these identifiers already have a special kind. */
5407 4719984 : if (pid->kind != cik_normal)
5408 786664 : set_identifier_kind (*pid->node, pid->kind);
5409 : }
5410 98333 : }
5411 :
5412 : /* Build a specific variant of operator new. */
5413 :
5414 : static void
5415 175537 : cxx_build_operator_new (tree newtype)
5416 : {
5417 175537 : tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
5418 175537 : DECL_IS_MALLOC (opnew) = 1;
5419 175537 : DECL_SET_IS_OPERATOR_NEW (opnew, true);
5420 175537 : DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
5421 175537 : opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
5422 175537 : DECL_IS_MALLOC (opnew) = 1;
5423 175537 : DECL_SET_IS_OPERATOR_NEW (opnew, true);
5424 175537 : DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
5425 175537 : }
5426 :
5427 : /* Build a specific variant of operator delete. */
5428 :
5429 : static void
5430 331226 : cxx_build_operator_delete (tree deltype)
5431 : {
5432 331226 : tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
5433 331226 : DECL_SET_IS_OPERATOR_DELETE (opdel, true);
5434 331226 : DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
5435 331226 : opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
5436 331226 : DECL_SET_IS_OPERATOR_DELETE (opdel, true);
5437 331226 : DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
5438 331226 : }
5439 :
5440 : /* Declare all variants of operator new and delete. */
5441 :
5442 : static void
5443 98333 : cxx_init_operator_new_delete_decls (void)
5444 : {
5445 98333 : tree newattrs, extvisattr;
5446 98333 : tree newtype, deltype;
5447 98333 : tree ptr_ftype_sizetype;
5448 98333 : tree new_eh_spec;
5449 98333 : tree void_ftype_ptr = build_function_type_list (void_type_node,
5450 : ptr_type_node, NULL_TREE);
5451 98333 : void_ftype_ptr
5452 98333 : = build_exception_variant (void_ftype_ptr, empty_except_spec);
5453 :
5454 98333 : ptr_ftype_sizetype
5455 98333 : = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
5456 98333 : if (cxx_dialect == cxx98)
5457 : {
5458 14193 : tree bad_alloc_id;
5459 14193 : tree bad_alloc_type_node;
5460 14193 : tree bad_alloc_decl;
5461 :
5462 14193 : push_nested_namespace (std_node);
5463 14193 : bad_alloc_id = get_identifier ("bad_alloc");
5464 14193 : bad_alloc_type_node = make_class_type (RECORD_TYPE);
5465 14193 : TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
5466 14193 : bad_alloc_decl
5467 14193 : = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
5468 14193 : DECL_CONTEXT (bad_alloc_decl) = current_namespace;
5469 14193 : pop_nested_namespace (std_node);
5470 :
5471 14193 : new_eh_spec
5472 14193 : = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
5473 : }
5474 : else
5475 84140 : new_eh_spec = noexcept_false_spec;
5476 :
5477 98333 : extvisattr = build_tree_list (get_identifier ("externally_visible"),
5478 : NULL_TREE);
5479 98333 : newattrs = tree_cons (get_identifier ("alloc_size"),
5480 : build_tree_list (NULL_TREE, integer_one_node),
5481 : extvisattr);
5482 98333 : newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
5483 98333 : newtype = build_exception_variant (newtype, new_eh_spec);
5484 98333 : deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
5485 98333 : deltype = build_exception_variant (deltype, empty_except_spec);
5486 98333 : cxx_build_operator_new (newtype);
5487 98333 : cxx_build_operator_delete (deltype);
5488 98333 : if (flag_sized_deallocation)
5489 : {
5490 : /* Also push the sized deallocation variants:
5491 : void operator delete(void*, std::size_t) throw();
5492 : void operator delete[](void*, std::size_t) throw(); */
5493 78490 : tree void_ftype_ptr_size
5494 78490 : = build_function_type_list (void_type_node, ptr_type_node,
5495 : size_type_node, NULL_TREE);
5496 78490 : deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
5497 : extvisattr);
5498 78490 : deltype = build_exception_variant (deltype, empty_except_spec);
5499 78490 : cxx_build_operator_delete (deltype);
5500 : }
5501 :
5502 98333 : if (aligned_new_threshold)
5503 : {
5504 77204 : push_nested_namespace (std_node);
5505 77204 : tree align_id = get_identifier ("align_val_t");
5506 77204 : align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
5507 : NULL_TREE, /*scoped*/true, NULL);
5508 77204 : pop_nested_namespace (std_node);
5509 :
5510 : /* operator new (size_t, align_val_t); */
5511 77204 : newtype = build_function_type_list (ptr_type_node, size_type_node,
5512 : align_type_node, NULL_TREE);
5513 77204 : newtype = cp_build_type_attribute_variant (newtype, newattrs);
5514 77204 : newtype = build_exception_variant (newtype, new_eh_spec);
5515 77204 : cxx_build_operator_new (newtype);
5516 :
5517 : /* operator delete (void *, align_val_t); */
5518 77204 : deltype = build_function_type_list (void_type_node, ptr_type_node,
5519 : align_type_node, NULL_TREE);
5520 77204 : deltype = cp_build_type_attribute_variant (deltype, extvisattr);
5521 77204 : deltype = build_exception_variant (deltype, empty_except_spec);
5522 77204 : cxx_build_operator_delete (deltype);
5523 :
5524 77204 : if (flag_sized_deallocation)
5525 : {
5526 : /* operator delete (void *, size_t, align_val_t); */
5527 77199 : deltype = build_function_type_list (void_type_node, ptr_type_node,
5528 : size_type_node, align_type_node,
5529 : NULL_TREE);
5530 77199 : deltype = cp_build_type_attribute_variant (deltype, extvisattr);
5531 77199 : deltype = build_exception_variant (deltype, empty_except_spec);
5532 77199 : cxx_build_operator_delete (deltype);
5533 : }
5534 : }
5535 98333 : }
5536 :
5537 : /* Create the predefined scalar types of C,
5538 : and some nodes representing standard constants (0, 1, (void *)0).
5539 : Initialize the global binding level.
5540 : Make definitions for built-in primitive functions. */
5541 :
5542 : void
5543 98333 : cxx_init_decl_processing (void)
5544 : {
5545 98333 : tree void_ftype;
5546 :
5547 : /* Create all the identifiers we need. */
5548 98333 : initialize_predefined_identifiers ();
5549 :
5550 : /* Create the global variables. */
5551 98333 : push_to_top_level ();
5552 :
5553 98333 : current_function_decl = NULL_TREE;
5554 98333 : current_binding_level = NULL;
5555 : /* Enter the global namespace. */
5556 98333 : gcc_assert (global_namespace == NULL_TREE);
5557 98333 : global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
5558 : void_type_node);
5559 98333 : TREE_PUBLIC (global_namespace) = true;
5560 98333 : DECL_MODULE_EXPORT_P (global_namespace) = true;
5561 98333 : DECL_CONTEXT (global_namespace)
5562 98333 : = build_translation_unit_decl (get_identifier (main_input_filename));
5563 : /* Remember whether we want the empty class passing ABI change warning
5564 : in this TU. */
5565 98333 : TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
5566 124076 : = warn_abi && abi_version_crosses (12);
5567 98333 : debug_hooks->register_main_translation_unit
5568 98333 : (DECL_CONTEXT (global_namespace));
5569 98333 : begin_scope (sk_namespace, global_namespace);
5570 98333 : current_namespace = global_namespace;
5571 :
5572 98333 : if (flag_visibility_ms_compat)
5573 6 : default_visibility = VISIBILITY_HIDDEN;
5574 :
5575 : /* Initially, C. */
5576 98333 : current_lang_name = lang_name_c;
5577 :
5578 : /* Create the `std' namespace. */
5579 98333 : push_namespace (get_identifier ("std"));
5580 98333 : std_node = current_namespace;
5581 98333 : pop_namespace ();
5582 :
5583 98333 : flag_noexcept_type = (cxx_dialect >= cxx17);
5584 :
5585 98333 : c_common_nodes_and_builtins ();
5586 :
5587 98333 : tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
5588 98333 : tree decl
5589 98333 : = add_builtin_function ("__builtin_is_constant_evaluated",
5590 : bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
5591 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5592 98333 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5593 :
5594 : /* The concrete return type of __builtin_source_location is
5595 : const std::source_location::__impl*, but we can't form the type
5596 : at this point. So we initially declare it with an auto return
5597 : type which we then "deduce" from require_deduced_type upon first use. */
5598 98333 : tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
5599 98333 : decl = add_builtin_function ("__builtin_source_location",
5600 : auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
5601 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5602 98333 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5603 :
5604 98333 : tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
5605 : NULL_TREE);
5606 98333 : decl
5607 98333 : = add_builtin_function ("__builtin_is_corresponding_member",
5608 : bool_vaftype,
5609 : CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
5610 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5611 98333 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5612 :
5613 98333 : decl
5614 98333 : = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
5615 : bool_vaftype,
5616 : CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
5617 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5618 98333 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5619 :
5620 98333 : if (cxx_dialect >= cxx26)
5621 : {
5622 23666 : tree void_ptrintftype
5623 23666 : = build_function_type_list (void_type_node, ptr_type_node,
5624 : integer_type_node, NULL_TREE);
5625 23666 : decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
5626 : void_ptrintftype,
5627 : CP_BUILT_IN_EH_PTR_ADJUST_REF,
5628 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5629 23666 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5630 :
5631 : /* Similar case to __builtin_source_location above. The concrete
5632 : return type is std::exception_ptr, but we can't form the type
5633 : at this point, so it is deduced later. */
5634 23666 : decl = add_builtin_function ("__builtin_current_exception",
5635 : auto_ftype, CP_BUILT_IN_CURRENT_EXCEPTION,
5636 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5637 23666 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5638 :
5639 23666 : tree int_ftype = build_function_type_list (integer_type_node, NULL_TREE);
5640 23666 : decl = add_builtin_function ("__builtin_uncaught_exceptions",
5641 : int_ftype, CP_BUILT_IN_UNCAUGHT_EXCEPTIONS,
5642 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5643 23666 : set_call_expr_flags (decl, ECF_PURE | ECF_NOTHROW | ECF_LEAF);
5644 : }
5645 :
5646 98333 : decl
5647 98333 : = add_builtin_function ("__builtin_is_string_literal",
5648 : bool_vaftype,
5649 : CP_BUILT_IN_IS_STRING_LITERAL,
5650 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5651 98333 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5652 :
5653 98333 : tree void_vaintftype = build_varargs_function_type_list (void_type_node,
5654 : integer_type_node,
5655 : NULL_TREE);
5656 98333 : decl = add_builtin_function ("__builtin_constexpr_diag",
5657 : void_vaintftype,
5658 : CP_BUILT_IN_CONSTEXPR_DIAG,
5659 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5660 98333 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5661 :
5662 98333 : integer_two_node = build_int_cst (NULL_TREE, 2);
5663 :
5664 : /* Guess at the initial static decls size. */
5665 98333 : vec_alloc (static_decls, 500);
5666 :
5667 : /* ... and keyed classes. */
5668 98333 : vec_alloc (keyed_classes, 100);
5669 :
5670 98333 : record_builtin_type (RID_BOOL, "bool", boolean_type_node);
5671 98333 : truthvalue_type_node = boolean_type_node;
5672 98333 : truthvalue_false_node = boolean_false_node;
5673 98333 : truthvalue_true_node = boolean_true_node;
5674 :
5675 98333 : empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
5676 98333 : noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
5677 98333 : noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
5678 98333 : noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
5679 : NULL_TREE);
5680 :
5681 : #if 0
5682 : record_builtin_type (RID_MAX, NULL, string_type_node);
5683 : #endif
5684 :
5685 98333 : delta_type_node = ptrdiff_type_node;
5686 98333 : vtable_index_type = ptrdiff_type_node;
5687 :
5688 98333 : vtt_parm_type = build_pointer_type (const_ptr_type_node);
5689 98333 : void_ftype = build_function_type_list (void_type_node, NULL_TREE);
5690 :
5691 : /* Create the conversion operator marker. This operator's DECL_NAME
5692 : is in the identifier table, so we can use identifier equality to
5693 : find it. */
5694 98333 : conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
5695 : void_ftype);
5696 :
5697 : /* C++ extensions */
5698 :
5699 98333 : unknown_type_node = make_node (LANG_TYPE);
5700 98333 : record_unknown_type (unknown_type_node, "unknown type");
5701 :
5702 : /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
5703 98333 : TREE_TYPE (unknown_type_node) = unknown_type_node;
5704 :
5705 : /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
5706 : result. */
5707 98333 : TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
5708 98333 : TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
5709 :
5710 98333 : init_list_type_node = make_node (LANG_TYPE);
5711 98333 : record_unknown_type (init_list_type_node, "init list");
5712 :
5713 : /* Used when parsing to distinguish parameter-lists () and (void). */
5714 98333 : explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
5715 :
5716 98333 : {
5717 : /* Make sure we get a unique function type, so we can give
5718 : its pointer type a name. (This wins for gdb.) */
5719 98333 : tree vfunc_type = make_node (FUNCTION_TYPE);
5720 98333 : TREE_TYPE (vfunc_type) = integer_type_node;
5721 98333 : TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
5722 98333 : layout_type (vfunc_type);
5723 :
5724 98333 : vtable_entry_type = build_pointer_type (vfunc_type);
5725 : }
5726 98333 : record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
5727 :
5728 98333 : vtbl_type_node
5729 98333 : = build_cplus_array_type (vtable_entry_type, NULL_TREE);
5730 98333 : layout_type (vtbl_type_node);
5731 98333 : vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
5732 98333 : record_builtin_type (RID_MAX, NULL, vtbl_type_node);
5733 98333 : vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
5734 98333 : layout_type (vtbl_ptr_type_node);
5735 98333 : record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
5736 :
5737 98333 : push_namespace (get_identifier ("__cxxabiv1"));
5738 98333 : abi_node = current_namespace;
5739 98333 : pop_namespace ();
5740 :
5741 98333 : any_targ_node = make_node (LANG_TYPE);
5742 98333 : record_unknown_type (any_targ_node, "any type");
5743 :
5744 : /* Now, C++. */
5745 98333 : current_lang_name = lang_name_cplusplus;
5746 :
5747 98333 : if (aligned_new_threshold > 1
5748 98333 : && !pow2p_hwi (aligned_new_threshold))
5749 : {
5750 0 : error ("%<-faligned-new=%d%> is not a power of two",
5751 : aligned_new_threshold);
5752 0 : aligned_new_threshold = 1;
5753 : }
5754 98333 : if (aligned_new_threshold == -1)
5755 119448 : aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
5756 98333 : if (aligned_new_threshold == 1)
5757 77201 : aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
5758 :
5759 : /* Ensure attribs.cc is initialized. */
5760 98333 : init_attributes ();
5761 98333 : cxx_init_operator_new_delete_decls ();
5762 :
5763 : /* C++-specific nullptr initialization. */
5764 98333 : if (abi_version_at_least (9))
5765 98162 : SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
5766 98333 : record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
5767 :
5768 98333 : if (! supports_one_only ())
5769 0 : flag_weak = 0;
5770 :
5771 98333 : abort_fndecl
5772 98333 : = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
5773 : ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
5774 98333 : if (flag_weak)
5775 : /* If no definition is available, resolve references to NULL. */
5776 98303 : declare_weak (abort_fndecl);
5777 :
5778 : /* Perform other language dependent initializations. */
5779 98333 : init_class_processing ();
5780 98333 : init_rtti_processing ();
5781 98333 : init_template_processing ();
5782 :
5783 98333 : if (flag_exceptions)
5784 97078 : init_exception_processing ();
5785 :
5786 98333 : if (flag_contracts)
5787 23711 : init_contracts ();
5788 :
5789 98333 : if (modules_p ())
5790 4854 : init_modules (parse_in);
5791 :
5792 98333 : if (flag_reflection)
5793 579 : init_reflection ();
5794 :
5795 98333 : make_fname_decl = cp_make_fname_decl;
5796 98333 : start_fname_decls ();
5797 :
5798 : /* Show we use EH for cleanups. */
5799 98333 : if (flag_exceptions)
5800 97078 : using_eh_for_cleanups ();
5801 :
5802 : /* Check that the hardware interference sizes are at least
5803 : alignof(max_align_t), as required by the standard. */
5804 98333 : const int max_align = max_align_t_align () / BITS_PER_UNIT;
5805 98333 : if (OPTION_SET_P (param_destruct_interfere_size))
5806 : {
5807 0 : if (param_destruct_interfere_size < max_align)
5808 0 : error ("%<--param destructive-interference-size=%d%> is less than "
5809 : "%d", param_destruct_interfere_size, max_align);
5810 0 : else if (param_destruct_interfere_size < param_l1_cache_line_size)
5811 0 : warning (OPT_Winterference_size,
5812 : "%<--param destructive-interference-size=%d%> "
5813 : "is less than %<--param l1-cache-line-size=%d%>",
5814 : param_destruct_interfere_size, param_l1_cache_line_size);
5815 : }
5816 98333 : else if (param_destruct_interfere_size)
5817 : /* Assume the internal value is OK. */;
5818 0 : else if (param_l1_cache_line_size >= max_align)
5819 0 : param_destruct_interfere_size = param_l1_cache_line_size;
5820 : /* else leave it unset. */
5821 :
5822 98333 : if (OPTION_SET_P (param_construct_interfere_size))
5823 : {
5824 0 : if (param_construct_interfere_size < max_align)
5825 0 : error ("%<--param constructive-interference-size=%d%> is less than "
5826 : "%d", param_construct_interfere_size, max_align);
5827 0 : else if (param_construct_interfere_size > param_l1_cache_line_size
5828 0 : && param_l1_cache_line_size >= max_align)
5829 0 : warning (OPT_Winterference_size,
5830 : "%<--param constructive-interference-size=%d%> "
5831 : "is greater than %<--param l1-cache-line-size=%d%>",
5832 : param_construct_interfere_size, param_l1_cache_line_size);
5833 : }
5834 98333 : else if (param_construct_interfere_size)
5835 : /* Assume the internal value is OK. */;
5836 0 : else if (param_l1_cache_line_size >= max_align)
5837 0 : param_construct_interfere_size = param_l1_cache_line_size;
5838 98333 : }
5839 :
5840 : /* Enter an abi node in global-module context. returns a cookie to
5841 : give to pop_abi_namespace. */
5842 :
5843 : unsigned
5844 57368 : push_abi_namespace (tree node)
5845 : {
5846 57368 : push_nested_namespace (node);
5847 57368 : push_visibility ("default", 2);
5848 57368 : unsigned flags = module_kind;
5849 57368 : module_kind = 0;
5850 57368 : return flags;
5851 : }
5852 :
5853 : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
5854 : you. */
5855 :
5856 : void
5857 57368 : pop_abi_namespace (unsigned flags, tree node)
5858 : {
5859 57368 : module_kind = flags;
5860 57368 : pop_visibility (2);
5861 57368 : pop_nested_namespace (node);
5862 57368 : }
5863 :
5864 : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
5865 : the decl, LOC is the location to give the decl, NAME is the
5866 : initialization string and TYPE_DEP indicates whether NAME depended
5867 : on the type of the function. We make use of that to detect
5868 : __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
5869 : at the point of first use, so we mustn't push the decl now. */
5870 :
5871 : static tree
5872 172054 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
5873 : {
5874 172054 : tree domain = NULL_TREE;
5875 172054 : tree init = NULL_TREE;
5876 :
5877 172054 : if (!(type_dep && current_function_decl && in_template_context))
5878 : {
5879 46624 : const char *name = NULL;
5880 46624 : bool release_name = false;
5881 :
5882 46624 : if (current_function_decl == NULL_TREE)
5883 : name = "top level";
5884 46610 : else if (type_dep == 0)
5885 : {
5886 : /* __FUNCTION__ */
5887 581 : name = fname_as_string (type_dep);
5888 581 : release_name = true;
5889 : }
5890 : else
5891 : {
5892 : /* __PRETTY_FUNCTION__ */
5893 46029 : gcc_checking_assert (type_dep == 1);
5894 46029 : name = cxx_printable_name (current_function_decl, 2);
5895 : }
5896 :
5897 46610 : if (!release_name)
5898 : {
5899 46043 : cpp_string cstr = { 0, 0 }, strname;
5900 46043 : size_t len = strlen (name) + 3; /* Two for '"'s. One for NULL. */
5901 46043 : char *namep = XNEWVEC (char, len);
5902 46043 : snprintf (namep, len, "\"%s\"", name);
5903 46043 : strname.text = (unsigned char *) namep;
5904 46043 : strname.len = len - 1;
5905 46043 : if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
5906 : {
5907 46043 : name = (const char *) cstr.text;
5908 46043 : release_name = true;
5909 : }
5910 :
5911 46043 : XDELETEVEC (namep);
5912 : }
5913 :
5914 46624 : size_t length = strlen (name);
5915 46624 : domain = build_index_type (size_int (length));
5916 46624 : init = build_string (length + 1, name);
5917 46624 : if (release_name)
5918 46624 : free (const_cast<char *> (name));
5919 : }
5920 :
5921 172054 : tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
5922 172054 : type = build_cplus_array_type (type, domain);
5923 :
5924 172054 : if (init)
5925 46624 : TREE_TYPE (init) = type;
5926 : else
5927 125430 : init = error_mark_node;
5928 :
5929 172054 : tree decl = build_decl (loc, VAR_DECL, id, type);
5930 :
5931 172054 : TREE_READONLY (decl) = 1;
5932 172054 : DECL_ARTIFICIAL (decl) = 1;
5933 172054 : DECL_DECLARED_CONSTEXPR_P (decl) = 1;
5934 172054 : TREE_STATIC (decl) = 1;
5935 :
5936 172054 : TREE_USED (decl) = 1;
5937 :
5938 172054 : SET_DECL_VALUE_EXPR (decl, init);
5939 172054 : DECL_HAS_VALUE_EXPR_P (decl) = 1;
5940 : /* For decl_constant_var_p. */
5941 172054 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
5942 :
5943 172054 : if (current_function_decl)
5944 : {
5945 172040 : DECL_CONTEXT (decl) = current_function_decl;
5946 172040 : decl = pushdecl_outermost_localscope (decl);
5947 172040 : if (decl != error_mark_node)
5948 172037 : add_decl_expr (decl);
5949 : else
5950 3 : gcc_assert (seen_error ());
5951 : }
5952 : else
5953 : {
5954 14 : DECL_THIS_STATIC (decl) = true;
5955 14 : decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
5956 : }
5957 :
5958 172054 : return decl;
5959 : }
5960 :
5961 : /* Install DECL as a builtin function at current global scope. Return
5962 : the new decl (if we found an existing version). Also installs it
5963 : into ::std, if it's not '_*'. */
5964 :
5965 : tree
5966 227778755 : cxx_builtin_function (tree decl)
5967 : {
5968 227778755 : retrofit_lang_decl (decl);
5969 :
5970 227778755 : DECL_ARTIFICIAL (decl) = 1;
5971 227778755 : SET_DECL_LANGUAGE (decl, lang_c);
5972 : /* Runtime library routines are, by definition, available in an
5973 : external shared object. */
5974 227778755 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
5975 227778755 : DECL_VISIBILITY_SPECIFIED (decl) = 1;
5976 :
5977 227778755 : tree id = DECL_NAME (decl);
5978 227778755 : const char *name = IDENTIFIER_POINTER (id);
5979 227778755 : bool hiding = false;
5980 227778755 : if (name[0] != '_' || name[1] != '_')
5981 : /* In the user's namespace, it must be declared before use. */
5982 : hiding = true;
5983 191033385 : else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
5984 191033385 : && !startswith (name + 2, "builtin_")
5985 213901463 : && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
5986 : "_chk", strlen ("_chk") + 1))
5987 : /* Treat __*_chk fortification functions as anticipated as well,
5988 : unless they are __builtin_*_chk. */
5989 : hiding = true;
5990 :
5991 : /* All builtins that don't begin with an '_' should additionally
5992 : go in the 'std' namespace. */
5993 227778755 : if (name[0] != '_')
5994 : {
5995 36611143 : tree std_decl = copy_decl (decl);
5996 :
5997 36611143 : push_nested_namespace (std_node);
5998 36611143 : DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
5999 36611143 : pushdecl (std_decl, hiding);
6000 36611143 : pop_nested_namespace (std_node);
6001 : }
6002 :
6003 227778755 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
6004 227778755 : decl = pushdecl (decl, hiding);
6005 :
6006 227778755 : return decl;
6007 : }
6008 :
6009 : /* Like cxx_builtin_function, but guarantee the function is added to the global
6010 : scope. This is to allow function specific options to add new machine
6011 : dependent builtins when the target ISA changes via attribute((target(...)))
6012 : which saves space on program startup if the program does not use non-generic
6013 : ISAs. */
6014 :
6015 : tree
6016 757172 : cxx_builtin_function_ext_scope (tree decl)
6017 : {
6018 757172 : push_nested_namespace (global_namespace);
6019 757172 : decl = cxx_builtin_function (decl);
6020 757172 : pop_nested_namespace (global_namespace);
6021 :
6022 757172 : return decl;
6023 : }
6024 :
6025 : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL. */
6026 :
6027 : tree
6028 0 : cxx_simulate_builtin_function_decl (tree decl)
6029 : {
6030 0 : retrofit_lang_decl (decl);
6031 :
6032 0 : DECL_ARTIFICIAL (decl) = 1;
6033 0 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
6034 0 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
6035 0 : return pushdecl (decl);
6036 : }
6037 :
6038 : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
6039 : function. Not called directly. */
6040 :
6041 : static tree
6042 1582874 : build_library_fn (tree name, enum tree_code operator_code, tree type,
6043 : int ecf_flags)
6044 : {
6045 1582874 : tree fn = build_lang_decl (FUNCTION_DECL, name, type);
6046 1582874 : DECL_EXTERNAL (fn) = 1;
6047 1582874 : TREE_PUBLIC (fn) = 1;
6048 1582874 : DECL_ARTIFICIAL (fn) = 1;
6049 1582874 : DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
6050 1582874 : = OVL_OP_INFO (false, operator_code)->ovl_op_code;
6051 1582874 : SET_DECL_LANGUAGE (fn, lang_c);
6052 : /* Runtime library routines are, by definition, available in an
6053 : external shared object. */
6054 1582874 : DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
6055 1582874 : DECL_VISIBILITY_SPECIFIED (fn) = 1;
6056 1582874 : set_call_expr_flags (fn, ecf_flags);
6057 1582874 : return fn;
6058 : }
6059 :
6060 : /* Returns the _DECL for a library function with C++ linkage. */
6061 :
6062 : static tree
6063 1110797 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
6064 : int ecf_flags)
6065 : {
6066 1110797 : tree fn = build_library_fn (name, operator_code, type, ecf_flags);
6067 1110797 : DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
6068 1110797 : SET_DECL_LANGUAGE (fn, lang_cplusplus);
6069 1110797 : return fn;
6070 : }
6071 :
6072 : /* Like build_library_fn, but takes a C string instead of an
6073 : IDENTIFIER_NODE. */
6074 :
6075 : tree
6076 103086 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
6077 : {
6078 103086 : return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
6079 : }
6080 :
6081 : /* Like build_cp_library_fn, but takes a C string instead of an
6082 : IDENTIFIER_NODE. */
6083 :
6084 : tree
6085 97271 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
6086 : {
6087 97271 : return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
6088 97271 : ecf_flags);
6089 : }
6090 :
6091 : /* Like build_library_fn, but also pushes the function so that we will
6092 : be able to find it via get_global_binding. Also, the function
6093 : may throw exceptions listed in RAISES. */
6094 :
6095 : tree
6096 368991 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
6097 : {
6098 368991 : if (raises)
6099 40956 : type = build_exception_variant (type, raises);
6100 :
6101 368991 : tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
6102 368991 : return pushdecl_top_level (fn);
6103 : }
6104 :
6105 : /* Like build_cp_library_fn, but also pushes the function so that it
6106 : will be found by normal lookup. */
6107 :
6108 : static tree
6109 1013526 : push_cp_library_fn (enum tree_code operator_code, tree type,
6110 : int ecf_flags)
6111 : {
6112 1013526 : tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
6113 : operator_code, type, ecf_flags);
6114 1013526 : pushdecl (fn);
6115 1013526 : if (flag_tm)
6116 3040 : apply_tm_attr (fn, get_identifier ("transaction_safe"));
6117 1013526 : return fn;
6118 : }
6119 :
6120 : /* Like push_library_fn, but also note that this function throws
6121 : and does not return. Used for __throw_foo and the like. */
6122 :
6123 : tree
6124 107848 : push_throw_library_fn (tree name, tree type)
6125 : {
6126 107848 : tree fn = push_library_fn (name, type, NULL_TREE,
6127 : ECF_NORETURN | ECF_XTHROW | ECF_COLD);
6128 107848 : return fn;
6129 : }
6130 :
6131 : /* When we call finish_struct for an anonymous union, we create
6132 : default copy constructors and such. But, an anonymous union
6133 : shouldn't have such things; this function undoes the damage to the
6134 : anonymous union type T.
6135 :
6136 : (The reason that we create the synthesized methods is that we don't
6137 : distinguish `union { int i; }' from `typedef union { int i; } U'.
6138 : The first is an anonymous union; the second is just an ordinary
6139 : union type.) */
6140 :
6141 : void
6142 172172 : fixup_anonymous_aggr (tree t)
6143 : {
6144 : /* Wipe out memory of synthesized methods. */
6145 172172 : TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
6146 172172 : TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
6147 172172 : TYPE_HAS_COPY_CTOR (t) = 0;
6148 172172 : TYPE_HAS_CONST_COPY_CTOR (t) = 0;
6149 172172 : TYPE_HAS_COPY_ASSIGN (t) = 0;
6150 172172 : TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
6151 :
6152 : /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
6153 : invalid members. */
6154 1006616 : for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
6155 : {
6156 834444 : if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
6157 0 : *prev_p = DECL_CHAIN (probe);
6158 : else
6159 834444 : prev_p = &DECL_CHAIN (probe);
6160 :
6161 834444 : if (DECL_ARTIFICIAL (probe)
6162 834444 : && (!DECL_IMPLICIT_TYPEDEF_P (probe)
6163 75142 : || TYPE_ANON_P (TREE_TYPE (probe))))
6164 282509 : continue;
6165 :
6166 551935 : if (TREE_CODE (probe) != FIELD_DECL
6167 551881 : || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
6168 : {
6169 : /* We already complained about static data members in
6170 : finish_static_data_member_decl. */
6171 66 : if (!VAR_P (probe))
6172 : {
6173 51 : auto_diagnostic_group d;
6174 51 : if (permerror (DECL_SOURCE_LOCATION (probe),
6175 51 : TREE_CODE (t) == UNION_TYPE
6176 : ? "%q#D invalid; an anonymous union may "
6177 : "only have public non-static data members"
6178 : : "%q#D invalid; an anonymous struct may "
6179 : "only have public non-static data members", probe))
6180 : {
6181 51 : static bool hint;
6182 51 : if (flag_permissive && !hint)
6183 : {
6184 6 : hint = true;
6185 6 : inform (DECL_SOURCE_LOCATION (probe),
6186 : "this flexibility is deprecated and will be "
6187 : "removed");
6188 : }
6189 : }
6190 51 : }
6191 : }
6192 : }
6193 :
6194 : /* Splice all functions out of CLASSTYPE_MEMBER_VEC. */
6195 172172 : vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
6196 172172 : unsigned store = 0;
6197 513035 : for (tree elt : vec)
6198 340863 : if (!is_overloaded_fn (elt))
6199 340842 : (*vec)[store++] = elt;
6200 172172 : vec_safe_truncate (vec, store);
6201 :
6202 : /* Wipe RTTI info. */
6203 172172 : CLASSTYPE_TYPEINFO_VAR (t) = NULL_TREE;
6204 :
6205 : /* Anonymous aggregates cannot have fields with ctors, dtors or complex
6206 : assignment operators (because they cannot have these methods themselves).
6207 : For anonymous unions this is already checked because they are not allowed
6208 : in any union, otherwise we have to check it. */
6209 172172 : if (TREE_CODE (t) != UNION_TYPE)
6210 : {
6211 36893 : tree field, type;
6212 :
6213 36893 : if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
6214 : {
6215 9 : error_at (location_of (t), "anonymous struct with base classes");
6216 : /* Avoid ICE after error on anon-struct9.C. */
6217 9 : TYPE_NEEDS_CONSTRUCTING (t) = false;
6218 : }
6219 :
6220 148404 : for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
6221 111511 : if (TREE_CODE (field) == FIELD_DECL)
6222 : {
6223 74517 : type = TREE_TYPE (field);
6224 74517 : if (CLASS_TYPE_P (type))
6225 : {
6226 61 : if (TYPE_NEEDS_CONSTRUCTING (type))
6227 6 : error ("member %q+#D with constructor not allowed "
6228 : "in anonymous aggregate", field);
6229 61 : if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
6230 0 : error ("member %q+#D with destructor not allowed "
6231 : "in anonymous aggregate", field);
6232 61 : if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
6233 0 : error ("member %q+#D with copy assignment operator "
6234 : "not allowed in anonymous aggregate", field);
6235 : }
6236 : }
6237 : }
6238 172172 : }
6239 :
6240 : /* Warn for an attribute located at LOCATION that appertains to the
6241 : class type CLASS_TYPE that has not been properly placed after its
6242 : class-key, in it class-specifier. */
6243 :
6244 : void
6245 109 : warn_misplaced_attr_for_class_type (location_t location,
6246 : tree class_type)
6247 : {
6248 109 : gcc_assert (OVERLOAD_TYPE_P (class_type));
6249 :
6250 109 : auto_diagnostic_group d;
6251 109 : if (warning_at (location, OPT_Wattributes,
6252 : "attribute ignored in declaration "
6253 : "of %q#T", class_type))
6254 109 : inform (location,
6255 : "attribute for %q#T must follow the %qs keyword",
6256 : class_type, class_key_or_enum_as_string (class_type));
6257 109 : }
6258 :
6259 : /* Returns the cv-qualifiers that apply to the type specified
6260 : by the DECLSPECS. */
6261 :
6262 : static int
6263 1027432581 : get_type_quals (const cp_decl_specifier_seq *declspecs)
6264 : {
6265 1027432581 : int type_quals = TYPE_UNQUALIFIED;
6266 :
6267 1027432581 : if (decl_spec_seq_has_spec_p (declspecs, ds_const))
6268 106515315 : type_quals |= TYPE_QUAL_CONST;
6269 1027432581 : if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
6270 1704832 : type_quals |= TYPE_QUAL_VOLATILE;
6271 1027432581 : if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
6272 34 : type_quals |= TYPE_QUAL_RESTRICT;
6273 :
6274 1027432581 : return type_quals;
6275 : }
6276 :
6277 : /* Make sure that a declaration with no declarator is well-formed, i.e.
6278 : just declares a tagged type or anonymous union.
6279 :
6280 : Returns the type declared; or NULL_TREE if none. */
6281 :
6282 : tree
6283 36872941 : check_tag_decl (cp_decl_specifier_seq *declspecs,
6284 : bool explicit_type_instantiation_p)
6285 : {
6286 36872941 : int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
6287 36872941 : int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
6288 : /* If a class, struct, or enum type is declared by the DECLSPECS
6289 : (i.e, if a class-specifier, enum-specifier, or non-typename
6290 : elaborated-type-specifier appears in the DECLSPECS),
6291 : DECLARED_TYPE is set to the corresponding type. */
6292 36872941 : tree declared_type = NULL_TREE;
6293 36872941 : bool error_p = false;
6294 :
6295 36872941 : if (declspecs->multiple_types_p)
6296 26 : error_at (smallest_type_location (declspecs),
6297 : "multiple types in one declaration");
6298 36872915 : else if (declspecs->redefined_builtin_type)
6299 : {
6300 21 : location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
6301 21 : if (!in_system_header_at (loc))
6302 9 : permerror (loc, "redeclaration of C++ built-in type %qT",
6303 : declspecs->redefined_builtin_type);
6304 21 : return NULL_TREE;
6305 : }
6306 :
6307 36872920 : if (declspecs->type
6308 36872905 : && TYPE_P (declspecs->type)
6309 73394946 : && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
6310 36521262 : && MAYBE_CLASS_TYPE_P (declspecs->type))
6311 1846229 : || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
6312 : declared_type = declspecs->type;
6313 351703 : else if (declspecs->type == error_mark_node)
6314 1499 : error_p = true;
6315 :
6316 36872920 : if (type_uses_auto (declared_type))
6317 : {
6318 8 : error_at (declspecs->locations[ds_type_spec],
6319 : "%<auto%> can only be specified for variables "
6320 : "or function declarations");
6321 8 : return error_mark_node;
6322 : }
6323 :
6324 36872912 : if (declared_type && !OVERLOAD_TYPE_P (declared_type))
6325 : declared_type = NULL_TREE;
6326 :
6327 36872912 : if (!declared_type && !saw_friend && !error_p)
6328 91 : permerror (input_location, "declaration does not declare anything");
6329 : /* Check for an anonymous union. */
6330 36521182 : else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
6331 106396523 : && TYPE_UNNAMED_P (declared_type))
6332 : {
6333 : /* 7/3 In a simple-declaration, the optional init-declarator-list
6334 : can be omitted only when declaring a class (clause 9) or
6335 : enumeration (7.2), that is, when the decl-specifier-seq contains
6336 : either a class-specifier, an elaborated-type-specifier with
6337 : a class-key (9.1), or an enum-specifier. In these cases and
6338 : whenever a class-specifier or enum-specifier is present in the
6339 : decl-specifier-seq, the identifiers in these specifiers are among
6340 : the names being declared by the declaration (as class-name,
6341 : enum-names, or enumerators, depending on the syntax). In such
6342 : cases, and except for the declaration of an unnamed bit-field (9.6),
6343 : the decl-specifier-seq shall introduce one or more names into the
6344 : program, or shall redeclare a name introduced by a previous
6345 : declaration. [Example:
6346 : enum { }; // ill-formed
6347 : typedef class { }; // ill-formed
6348 : --end example] */
6349 172178 : if (saw_typedef)
6350 : {
6351 6 : error_at (declspecs->locations[ds_typedef],
6352 : "missing type-name in typedef-declaration");
6353 6 : return NULL_TREE;
6354 : }
6355 172172 : /* Anonymous unions are objects, so they can have specifiers. */;
6356 172172 : SET_ANON_AGGR_TYPE_P (declared_type);
6357 :
6358 172172 : if (TREE_CODE (declared_type) != UNION_TYPE)
6359 36893 : pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
6360 36893 : OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
6361 : }
6362 :
6363 : else
6364 : {
6365 36700643 : if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
6366 9 : error_at (declspecs->locations[ds_inline],
6367 : "%<inline%> can only be specified for functions");
6368 36700634 : else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
6369 3 : error_at (declspecs->locations[ds_virtual],
6370 : "%<virtual%> can only be specified for functions");
6371 36700631 : else if (saw_friend
6372 36700631 : && (!current_class_type
6373 2052097 : || current_scope () != current_class_type))
6374 0 : error_at (declspecs->locations[ds_friend],
6375 : "%<friend%> can only be specified inside a class");
6376 36700631 : else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
6377 3 : error_at (declspecs->locations[ds_explicit],
6378 : "%<explicit%> can only be specified for constructors");
6379 36700628 : else if (declspecs->storage_class)
6380 3 : error_at (declspecs->locations[ds_storage_class],
6381 : "a storage class can only be specified for objects "
6382 : "and functions");
6383 36700625 : else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
6384 9 : error_at (declspecs->locations[ds_const],
6385 : "%<const%> can only be specified for objects and "
6386 : "functions");
6387 36700616 : else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
6388 3 : error_at (declspecs->locations[ds_volatile],
6389 : "%<volatile%> can only be specified for objects and "
6390 : "functions");
6391 36700613 : else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
6392 3 : error_at (declspecs->locations[ds_restrict],
6393 : "%<__restrict%> can only be specified for objects and "
6394 : "functions");
6395 36700610 : else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
6396 3 : error_at (declspecs->locations[ds_thread],
6397 : "%<__thread%> can only be specified for objects "
6398 : "and functions");
6399 36700607 : else if (saw_typedef)
6400 24 : warning_at (declspecs->locations[ds_typedef], 0,
6401 : "%<typedef%> was ignored in this declaration");
6402 36700583 : else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
6403 9 : error_at (declspecs->locations[ds_constexpr],
6404 : "%qs cannot be used for type declarations", "constexpr");
6405 36700574 : else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
6406 3 : error_at (declspecs->locations[ds_constinit],
6407 : "%qs cannot be used for type declarations", "constinit");
6408 36700571 : else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
6409 3 : error_at (declspecs->locations[ds_consteval],
6410 : "%qs cannot be used for type declarations", "consteval");
6411 : }
6412 :
6413 36872906 : if (declspecs->attributes && warn_attributes && declared_type)
6414 : {
6415 30 : location_t loc;
6416 24 : if (!CLASS_TYPE_P (declared_type)
6417 54 : || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
6418 : /* For a non-template class, use the name location. */
6419 21 : loc = location_of (declared_type);
6420 : else
6421 : /* For a template class (an explicit instantiation), use the
6422 : current location. */
6423 9 : loc = input_location;
6424 :
6425 30 : if (explicit_type_instantiation_p)
6426 : /* [dcl.attr.grammar]/4:
6427 :
6428 : No attribute-specifier-seq shall appertain to an explicit
6429 : instantiation. */
6430 : {
6431 6 : auto_diagnostic_group d;
6432 6 : if (warning_at (loc, OPT_Wattributes,
6433 : "attribute ignored in explicit instantiation %q#T",
6434 : declared_type))
6435 6 : inform (loc,
6436 : "no attribute can be applied to "
6437 : "an explicit instantiation");
6438 6 : }
6439 : else
6440 24 : warn_misplaced_attr_for_class_type (loc, declared_type);
6441 : }
6442 :
6443 36872906 : if (declspecs->std_attributes
6444 85 : && declared_type
6445 36872988 : && any_nonignored_attribute_p (declspecs->std_attributes))
6446 : {
6447 82 : auto_diagnostic_group d;
6448 82 : if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
6449 : "attribute ignored"))
6450 82 : inform (declspecs->locations[ds_std_attribute],
6451 : "an attribute that appertains to a type-specifier is ignored");
6452 82 : }
6453 :
6454 : return declared_type;
6455 : }
6456 :
6457 : /* Called when a declaration is seen that contains no names to declare.
6458 : If its type is a reference to a structure, union or enum inherited
6459 : from a containing scope, shadow that tag name for the current scope
6460 : with a forward reference.
6461 : If its type defines a new named structure or union
6462 : or defines an enum, it is valid but we need not do anything here.
6463 : Otherwise, it is an error.
6464 :
6465 : C++: may have to grok the declspecs to learn about static,
6466 : complain for anonymous unions.
6467 :
6468 : Returns the TYPE declared -- or NULL_TREE if none. */
6469 :
6470 : tree
6471 32293161 : shadow_tag (cp_decl_specifier_seq *declspecs)
6472 : {
6473 32293161 : tree t = check_tag_decl (declspecs,
6474 : /*explicit_type_instantiation_p=*/false);
6475 :
6476 32293161 : if (!t)
6477 : return NULL_TREE;
6478 :
6479 32291648 : t = maybe_process_partial_specialization (t);
6480 32291648 : if (t == error_mark_node)
6481 : return NULL_TREE;
6482 :
6483 : /* This is where the variables in an anonymous union are
6484 : declared. An anonymous union declaration looks like:
6485 : union { ... } ;
6486 : because there is no declarator after the union, the parser
6487 : sends that declaration here. */
6488 32289810 : if (ANON_AGGR_TYPE_P (t))
6489 : {
6490 316 : fixup_anonymous_aggr (t);
6491 :
6492 316 : if (TYPE_FIELDS (t))
6493 : {
6494 316 : tree decl = grokdeclarator (/*declarator=*/NULL,
6495 : declspecs, NORMAL, 0, NULL);
6496 316 : finish_anon_union (decl);
6497 : }
6498 : }
6499 :
6500 : return t;
6501 : }
6502 :
6503 : /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
6504 :
6505 : tree
6506 401024026 : groktypename (cp_decl_specifier_seq *type_specifiers,
6507 : const cp_declarator *declarator,
6508 : bool is_template_arg)
6509 : {
6510 401024026 : tree attrs;
6511 401024026 : tree type;
6512 66330816 : enum decl_context context
6513 401024026 : = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
6514 401024026 : attrs = type_specifiers->attributes;
6515 401024026 : type_specifiers->attributes = NULL_TREE;
6516 401024026 : type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
6517 401024026 : if (attrs && type != error_mark_node)
6518 : {
6519 635 : if (CLASS_TYPE_P (type))
6520 6 : warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
6521 : "outside of definition", type);
6522 629 : else if (MAYBE_CLASS_TYPE_P (type))
6523 : /* A template type parameter or other dependent type. */
6524 9 : warning (OPT_Wattributes, "ignoring attributes applied to dependent "
6525 : "type %qT without an associated declaration", type);
6526 : else
6527 620 : cplus_decl_attributes (&type, attrs, 0);
6528 : }
6529 401024026 : return type;
6530 : }
6531 :
6532 : /* Process a DECLARATOR for a function-scope or namespace-scope
6533 : variable or function declaration.
6534 : (Function definitions go through start_function; class member
6535 : declarations appearing in the body of the class go through
6536 : grokfield.) The DECL corresponding to the DECLARATOR is returned.
6537 : If an error occurs, the error_mark_node is returned instead.
6538 :
6539 : DECLSPECS are the decl-specifiers for the declaration. INITIALIZED is
6540 : SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
6541 : for an explicitly defaulted function, or SD_DELETED for an explicitly
6542 : deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
6543 : implicitly initialized via a default constructor. It can also be
6544 : SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
6545 : mark the new decl as DECL_DECOMPOSITION_P.
6546 :
6547 : ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
6548 : declaration.
6549 :
6550 : The scope represented by the context of the returned DECL is pushed
6551 : (if it is not the global namespace) and is assigned to
6552 : *PUSHED_SCOPE_P. The caller is then responsible for calling
6553 : pop_scope on *PUSHED_SCOPE_P if it is set. */
6554 :
6555 : tree
6556 126264396 : start_decl (const cp_declarator *declarator,
6557 : cp_decl_specifier_seq *declspecs,
6558 : int initialized,
6559 : tree attributes,
6560 : tree prefix_attributes,
6561 : tree *pushed_scope_p)
6562 : {
6563 126264396 : tree decl;
6564 126264396 : tree context;
6565 126264396 : bool was_public;
6566 126264396 : int flags;
6567 126264396 : bool alias;
6568 126264396 : tree initial;
6569 :
6570 126264396 : *pushed_scope_p = NULL_TREE;
6571 :
6572 126264396 : if (prefix_attributes != error_mark_node)
6573 126264394 : attributes = attr_chainon (attributes, prefix_attributes);
6574 :
6575 126264396 : decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
6576 : &attributes);
6577 :
6578 126264396 : if (decl == NULL_TREE || VOID_TYPE_P (decl)
6579 126264396 : || decl == error_mark_node
6580 126262245 : || prefix_attributes == error_mark_node)
6581 2153 : return error_mark_node;
6582 :
6583 126262243 : context = CP_DECL_CONTEXT (decl);
6584 126262243 : if (context != global_namespace)
6585 21964831 : *pushed_scope_p = push_scope (context);
6586 :
6587 126262243 : if (initialized && TREE_CODE (decl) == TYPE_DECL)
6588 : {
6589 27 : error_at (DECL_SOURCE_LOCATION (decl),
6590 : "typedef %qD is initialized (use %qs instead)",
6591 : decl, "decltype");
6592 27 : return error_mark_node;
6593 : }
6594 :
6595 126262216 : if (flag_contracts
6596 9135700 : && TREE_CODE (decl) == FUNCTION_DECL
6597 2579394 : && !processing_template_decl
6598 2082326 : && DECL_RESULT (decl)
6599 128340195 : && is_auto (TREE_TYPE (DECL_RESULT (decl))))
6600 32 : for (tree ca = get_fn_contract_specifiers (decl); ca; ca = TREE_CHAIN (ca))
6601 6 : if (POSTCONDITION_P (CONTRACT_STATEMENT (ca))
6602 6 : && POSTCONDITION_IDENTIFIER (CONTRACT_STATEMENT (ca)))
6603 : {
6604 2 : error_at (DECL_SOURCE_LOCATION (decl),
6605 : "postconditions with deduced result name types must only"
6606 : " appear on function definitions");
6607 2 : return error_mark_node;
6608 : }
6609 : /* Save the DECL_INITIAL value in case it gets clobbered to assist
6610 : with attribute validation. */
6611 126262214 : initial = DECL_INITIAL (decl);
6612 :
6613 126262214 : if (initialized)
6614 : {
6615 60846405 : if (! toplevel_bindings_p ()
6616 60846405 : && DECL_EXTERNAL (decl))
6617 3 : warning (0, "declaration of %q#D has %<extern%> and is initialized",
6618 : decl);
6619 60846405 : DECL_EXTERNAL (decl) = 0;
6620 60846405 : if (toplevel_bindings_p ())
6621 7217021 : TREE_STATIC (decl) = 1;
6622 : /* Tell 'cplus_decl_attributes' this is an initialized decl,
6623 : even though we might not yet have the initializer expression. */
6624 60846405 : if (!DECL_INITIAL (decl))
6625 60282648 : DECL_INITIAL (decl) = error_mark_node;
6626 : }
6627 126262214 : alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
6628 :
6629 126262214 : if (alias && TREE_CODE (decl) == FUNCTION_DECL)
6630 3987 : record_key_method_defined (decl);
6631 :
6632 : /* If this is a typedef that names the class for linkage purposes
6633 : (7.1.3p8), apply any attributes directly to the type. */
6634 126262214 : if (TREE_CODE (decl) == TYPE_DECL
6635 126262214 : && TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl))
6636 : flags = ATTR_FLAG_TYPE_IN_PLACE;
6637 : else
6638 : flags = 0;
6639 :
6640 : /* Set attributes here so if duplicate decl, will have proper attributes. */
6641 126262214 : cplus_decl_attributes (&decl, attributes, flags);
6642 :
6643 : /* Restore the original DECL_INITIAL that we may have clobbered earlier to
6644 : assist with attribute validation. */
6645 126262214 : DECL_INITIAL (decl) = initial;
6646 :
6647 : /* Dllimported symbols cannot be defined. Static data members (which
6648 : can be initialized in-class and dllimported) go through grokfield,
6649 : not here, so we don't need to exclude those decls when checking for
6650 : a definition. */
6651 126262214 : if (initialized && DECL_DLLIMPORT_P (decl))
6652 : {
6653 0 : error_at (DECL_SOURCE_LOCATION (decl),
6654 : "definition of %q#D is marked %<dllimport%>", decl);
6655 0 : DECL_DLLIMPORT_P (decl) = 0;
6656 : }
6657 :
6658 : /* If #pragma weak was used, mark the decl weak now. */
6659 126262214 : if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
6660 46319106 : maybe_apply_pragma_weak (decl);
6661 :
6662 126262214 : if (TREE_CODE (decl) == FUNCTION_DECL
6663 37504125 : && DECL_DECLARED_INLINE_P (decl)
6664 3202096 : && DECL_UNINLINABLE (decl)
6665 126262214 : && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
6666 : {
6667 0 : auto_urlify_attributes sentinel;
6668 0 : warning_at (DECL_SOURCE_LOCATION (decl), 0,
6669 : "inline function %qD given attribute %qs", decl, "noinline");
6670 0 : }
6671 :
6672 126262214 : if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
6673 : {
6674 847744 : bool this_tmpl = (current_template_depth
6675 847744 : > template_class_depth (context));
6676 847744 : if (VAR_P (decl))
6677 : {
6678 492226 : tree field = lookup_field (context, DECL_NAME (decl), 0, false);
6679 492226 : if (field == NULL_TREE
6680 492226 : || !(VAR_P (field) || variable_template_p (field)))
6681 6 : error ("%q+#D is not a static data member of %q#T", decl, context);
6682 492220 : else if (variable_template_p (field)
6683 492220 : && (DECL_LANG_SPECIFIC (decl)
6684 147 : && DECL_TEMPLATE_SPECIALIZATION (decl)))
6685 : /* OK, specialization was already checked. */;
6686 492151 : else if (variable_template_p (field) && !this_tmpl)
6687 : {
6688 3 : auto_diagnostic_group d;
6689 3 : error_at (DECL_SOURCE_LOCATION (decl),
6690 : "non-member-template declaration of %qD", decl);
6691 3 : inform (DECL_SOURCE_LOCATION (field), "does not match "
6692 : "member template declaration here");
6693 3 : return error_mark_node;
6694 3 : }
6695 : else
6696 : {
6697 492148 : if (variable_template_p (field))
6698 75 : field = DECL_TEMPLATE_RESULT (field);
6699 :
6700 492148 : if (DECL_CONTEXT (field) != context)
6701 : {
6702 3 : if (!same_type_p (DECL_CONTEXT (field), context))
6703 3 : permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
6704 : "to be defined as %<%T::%D%>",
6705 3 : DECL_CONTEXT (field), DECL_NAME (decl),
6706 3 : context, DECL_NAME (decl));
6707 3 : DECL_CONTEXT (decl) = DECL_CONTEXT (field);
6708 : }
6709 :
6710 492148 : if (modules_p () && !module_may_redeclare (field))
6711 30 : return error_mark_node;
6712 :
6713 : /* Static data member are tricky; an in-class initialization
6714 : still doesn't provide a definition, so the in-class
6715 : declaration will have DECL_EXTERNAL set, but will have an
6716 : initialization. Thus, duplicate_decls won't warn
6717 : about this situation, and so we check here. */
6718 492118 : if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
6719 9 : error ("duplicate initialization of %qD", decl);
6720 492118 : field = duplicate_decls (decl, field);
6721 492118 : if (field == error_mark_node)
6722 : return error_mark_node;
6723 492062 : else if (field)
6724 492062 : decl = field;
6725 : }
6726 : }
6727 : else
6728 : {
6729 355530 : tree field = check_classfn (context, decl,
6730 : this_tmpl
6731 12 : ? current_template_parms
6732 : : NULL_TREE);
6733 355443 : if (field && field != error_mark_node
6734 710961 : && duplicate_decls (decl, field))
6735 355443 : decl = field;
6736 : }
6737 :
6738 : /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
6739 847655 : DECL_IN_AGGR_P (decl) = 0;
6740 : /* Do not mark DECL as an explicit specialization if it was not
6741 : already marked as an instantiation; a declaration should
6742 : never be marked as a specialization unless we know what
6743 : template is being specialized. */
6744 847655 : if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
6745 : {
6746 353491 : SET_DECL_TEMPLATE_SPECIALIZATION (decl);
6747 353491 : if (TREE_CODE (decl) == FUNCTION_DECL)
6748 333148 : DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
6749 333148 : && DECL_NONGNU_INLINE_P (decl));
6750 : else
6751 20343 : DECL_COMDAT (decl) = false;
6752 :
6753 : /* [temp.expl.spec] An explicit specialization of a static data
6754 : member of a template is a definition if the declaration
6755 : includes an initializer; otherwise, it is a declaration.
6756 :
6757 : We check for processing_specialization so this only applies
6758 : to the new specialization syntax. */
6759 353491 : if (!initialized && processing_specialization)
6760 353289 : DECL_EXTERNAL (decl) = 1;
6761 : }
6762 :
6763 1200992 : if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
6764 : /* Aliases are definitions. */
6765 847691 : && !alias)
6766 : {
6767 9 : permerror (declarator->id_loc,
6768 : "declaration of %q#D outside of class is not definition",
6769 : decl);
6770 : }
6771 : }
6772 :
6773 : /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works. */
6774 126262125 : if (initialized == SD_DECOMPOSITION)
6775 442313 : fit_decomposition_lang_decl (decl, NULL_TREE);
6776 :
6777 126262125 : was_public = TREE_PUBLIC (decl);
6778 :
6779 215013932 : if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
6780 126825906 : && current_function_decl)
6781 : {
6782 : /* A function-scope decl of some namespace-scope decl. */
6783 60458 : DECL_LOCAL_DECL_P (decl) = true;
6784 60458 : if (named_module_attach_p ())
6785 3 : error_at (declarator->id_loc,
6786 : "block-scope extern declaration %q#D must not be"
6787 : " attached to a named module", decl);
6788 : }
6789 :
6790 : /* Enter this declaration into the symbol table. Don't push the plain
6791 : VAR_DECL for a variable template. */
6792 126262125 : if (!template_parm_scope_p ()
6793 126262125 : || !VAR_P (decl))
6794 122253862 : decl = maybe_push_decl (decl);
6795 :
6796 126262125 : if (processing_template_decl)
6797 79937563 : decl = push_template_decl (decl);
6798 :
6799 126262125 : if (decl == error_mark_node)
6800 : return error_mark_node;
6801 :
6802 126261695 : if (VAR_P (decl)
6803 66996151 : && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
6804 67142 : && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
6805 : /* But not templated variables. */
6806 126289986 : && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
6807 : {
6808 : /* This is a const variable with implicit 'static'. Set
6809 : DECL_THIS_STATIC so we can tell it from variables that are
6810 : !TREE_PUBLIC because of the anonymous namespace. */
6811 28291 : gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
6812 28291 : DECL_THIS_STATIC (decl) = 1;
6813 : }
6814 :
6815 71252392 : if (current_function_decl && VAR_P (decl)
6816 58975629 : && maybe_constexpr_fn (current_function_decl)
6817 140964153 : && cxx_dialect < cxx23)
6818 : {
6819 12640390 : bool ok = false;
6820 12640390 : if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
6821 : {
6822 9 : if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
6823 18 : error_at (DECL_SOURCE_LOCATION (decl),
6824 : "%qD defined %<thread_local%> in %qs function only "
6825 : "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
6826 9 : DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
6827 : ? "consteval" : "constexpr");
6828 : }
6829 12640381 : else if (TREE_STATIC (decl))
6830 : {
6831 50 : if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
6832 72 : error_at (DECL_SOURCE_LOCATION (decl),
6833 : "%qD defined %<static%> in %qs function only available "
6834 : "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
6835 36 : DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
6836 : ? "consteval" : "constexpr");
6837 : }
6838 : else
6839 : ok = true;
6840 45 : if (!ok)
6841 59 : cp_function_chain->invalid_constexpr = true;
6842 : }
6843 :
6844 126261695 : if (!processing_template_decl && VAR_P (decl))
6845 8453001 : start_decl_1 (decl, initialized);
6846 :
6847 126261692 : return decl;
6848 : }
6849 :
6850 : /* Process the declaration of a variable DECL. INITIALIZED is true
6851 : iff DECL is explicitly initialized. (INITIALIZED is false if the
6852 : variable is initialized via an implicitly-called constructor.)
6853 : This function must be called for ordinary variables (including, for
6854 : example, implicit instantiations of templates), but must not be
6855 : called for template declarations. */
6856 :
6857 : void
6858 8461214 : start_decl_1 (tree decl, bool initialized)
6859 : {
6860 8461214 : gcc_checking_assert (!processing_template_decl);
6861 :
6862 8461214 : if (error_operand_p (decl))
6863 : return;
6864 :
6865 8461199 : gcc_checking_assert (VAR_P (decl));
6866 :
6867 8461199 : tree type = TREE_TYPE (decl);
6868 8461199 : bool complete_p = COMPLETE_TYPE_P (type);
6869 8461199 : bool aggregate_definition_p
6870 8461199 : = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
6871 :
6872 : /* If an explicit initializer is present, or if this is a definition
6873 : of an aggregate, then we need a complete type at this point.
6874 : (Scalars are always complete types, so there is nothing to
6875 : check.) This code just sets COMPLETE_P; errors (if necessary)
6876 : are issued below. */
6877 4375137 : if ((initialized || aggregate_definition_p)
6878 7444382 : && !complete_p
6879 5999141 : && COMPLETE_TYPE_P (complete_type (type)))
6880 : {
6881 329433 : complete_p = true;
6882 : /* We will not yet have set TREE_READONLY on DECL if the type
6883 : was "const", but incomplete, before this point. But, now, we
6884 : have a complete type, so we can try again. */
6885 329433 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
6886 : }
6887 :
6888 8461196 : if (initialized)
6889 : /* Is it valid for this decl to have an initializer at all? */
6890 : {
6891 : /* Don't allow initializations for incomplete types except for
6892 : arrays which might be completed by the initialization. */
6893 6706665 : if (complete_p)
6894 : ; /* A complete type is ok. */
6895 1294334 : else if (type_uses_auto (type))
6896 : ; /* An auto type is ok. */
6897 119776 : else if (TREE_CODE (type) != ARRAY_TYPE)
6898 : {
6899 27 : auto_diagnostic_group d;
6900 27 : error ("variable %q#D has initializer but incomplete type", decl);
6901 48 : maybe_suggest_missing_header (input_location,
6902 27 : TYPE_IDENTIFIER (type),
6903 27 : CP_TYPE_CONTEXT (type));
6904 27 : type = TREE_TYPE (decl) = error_mark_node;
6905 27 : }
6906 119749 : else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
6907 : {
6908 0 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
6909 0 : error ("elements of array %q#D have incomplete type", decl);
6910 : /* else we already gave an error in start_decl. */
6911 : }
6912 : }
6913 1754531 : else if (aggregate_definition_p && !complete_p)
6914 : {
6915 234 : if (type_uses_auto (type))
6916 69 : gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
6917 : else
6918 : {
6919 165 : auto_diagnostic_group d;
6920 165 : error ("aggregate %q#D has incomplete type and cannot be defined",
6921 : decl);
6922 285 : maybe_suggest_missing_header (input_location,
6923 165 : TYPE_IDENTIFIER (type),
6924 165 : CP_TYPE_CONTEXT (type));
6925 : /* Change the type so that assemble_variable will give
6926 : DECL an rtl we can live with: (mem (const_int 0)). */
6927 165 : type = TREE_TYPE (decl) = error_mark_node;
6928 165 : }
6929 : }
6930 :
6931 : /* Create a new scope to hold this declaration if necessary.
6932 : Whether or not a new scope is necessary cannot be determined
6933 : until after the type has been completed; if the type is a
6934 : specialization of a class template it is not until after
6935 : instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
6936 : will be set correctly. */
6937 8461196 : maybe_push_cleanup_level (type);
6938 : }
6939 :
6940 : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
6941 : C++20 P0960. TYPE is the type of the object we're initializing. */
6942 :
6943 : tree
6944 295 : do_aggregate_paren_init (tree init, tree type)
6945 : {
6946 295 : tree val = TREE_VALUE (init);
6947 :
6948 295 : if (TREE_CHAIN (init) == NULL_TREE)
6949 : {
6950 : /* If the list has a single element and it's a string literal,
6951 : then it's the initializer for the array as a whole. */
6952 179 : if (TREE_CODE (type) == ARRAY_TYPE
6953 179 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
6954 225 : && TREE_CODE (tree_strip_any_location_wrapper (val))
6955 : == STRING_CST)
6956 : return val;
6957 : /* Handle non-standard extensions like compound literals. This also
6958 : prevents triggering aggregate parenthesized-initialization in
6959 : compiler-generated code for =default. */
6960 140 : else if (same_type_ignoring_top_level_qualifiers_p (type,
6961 140 : TREE_TYPE (val)))
6962 : return val;
6963 : }
6964 :
6965 200 : init = build_constructor_from_list (init_list_type_node, init);
6966 200 : CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
6967 200 : CONSTRUCTOR_IS_PAREN_INIT (init) = true;
6968 200 : return init;
6969 : }
6970 :
6971 : /* Handle initialization of references. DECL, TYPE, and INIT have the
6972 : same meaning as in cp_finish_decl. *CLEANUP must be NULL on entry,
6973 : but will be set to a new CLEANUP_STMT if a temporary is created
6974 : that must be destroyed subsequently.
6975 :
6976 : Returns an initializer expression to use to initialize DECL, or
6977 : NULL if the initialization can be performed statically.
6978 :
6979 : Quotes on semantics can be found in ARM 8.4.3. */
6980 :
6981 : static tree
6982 359810 : grok_reference_init (tree decl, tree type, tree init, int flags)
6983 : {
6984 359810 : if (init == NULL_TREE)
6985 : {
6986 15 : if ((DECL_LANG_SPECIFIC (decl) == 0
6987 3 : || DECL_IN_AGGR_P (decl) == 0)
6988 18 : && ! DECL_THIS_EXTERN (decl))
6989 15 : error_at (DECL_SOURCE_LOCATION (decl),
6990 : "%qD declared as reference but not initialized", decl);
6991 15 : return NULL_TREE;
6992 : }
6993 :
6994 359795 : tree ttype = TREE_TYPE (type);
6995 359795 : if (TREE_CODE (init) == TREE_LIST)
6996 : {
6997 : /* This handles (C++20 only) code like
6998 :
6999 : const A& r(1, 2, 3);
7000 :
7001 : where we treat the parenthesized list as a CONSTRUCTOR. */
7002 1167 : if (TREE_TYPE (init) == NULL_TREE
7003 1167 : && CP_AGGREGATE_TYPE_P (ttype)
7004 69 : && !DECL_DECOMPOSITION_P (decl)
7005 1233 : && (cxx_dialect >= cxx20))
7006 : {
7007 : /* We don't know yet if we should treat const A& r(1) as
7008 : const A& r{1}. */
7009 60 : if (list_length (init) == 1)
7010 : {
7011 39 : flags |= LOOKUP_AGGREGATE_PAREN_INIT;
7012 39 : init = build_x_compound_expr_from_list (init, ELK_INIT,
7013 : tf_warning_or_error);
7014 : }
7015 : /* If the list had more than one element, the code is ill-formed
7016 : pre-C++20, so we can build a constructor right away. */
7017 : else
7018 21 : init = do_aggregate_paren_init (init, ttype);
7019 : }
7020 : else
7021 1107 : init = build_x_compound_expr_from_list (init, ELK_INIT,
7022 : tf_warning_or_error);
7023 : }
7024 :
7025 359795 : if (TREE_CODE (ttype) != ARRAY_TYPE
7026 359795 : && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
7027 : /* Note: default conversion is only called in very special cases. */
7028 12 : init = decay_conversion (init, tf_warning_or_error);
7029 :
7030 : /* check_initializer handles this for non-reference variables, but for
7031 : references we need to do it here or the initializer will get the
7032 : incomplete array type and confuse later calls to
7033 : cp_complete_array_type. */
7034 359795 : if (TREE_CODE (ttype) == ARRAY_TYPE
7035 22537 : && TYPE_DOMAIN (ttype) == NULL_TREE
7036 359878 : && (BRACE_ENCLOSED_INITIALIZER_P (init)
7037 50 : || TREE_CODE (init) == STRING_CST))
7038 : {
7039 33 : cp_complete_array_type (&ttype, init, false);
7040 33 : if (ttype != TREE_TYPE (type))
7041 33 : type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
7042 : }
7043 :
7044 : /* Convert INIT to the reference type TYPE. This may involve the
7045 : creation of a temporary, whose lifetime must be the same as that
7046 : of the reference. If so, a DECL_EXPR for the temporary will be
7047 : added just after the DECL_EXPR for DECL. That's why we don't set
7048 : DECL_INITIAL for local references (instead assigning to them
7049 : explicitly); we need to allow the temporary to be initialized
7050 : first. */
7051 359795 : return initialize_reference (type, init, flags,
7052 359795 : tf_warning_or_error);
7053 : }
7054 :
7055 : /* Designated initializers in arrays are not supported in GNU C++.
7056 : The parser cannot detect this error since it does not know whether
7057 : a given brace-enclosed initializer is for a class type or for an
7058 : array. This function checks that CE does not use a designated
7059 : initializer. If it does, an error is issued. Returns true if CE
7060 : is valid, i.e., does not have a designated initializer. */
7061 :
7062 : bool
7063 148771694 : check_array_designated_initializer (constructor_elt *ce,
7064 : unsigned HOST_WIDE_INT index)
7065 : {
7066 : /* Designated initializers for array elements are not supported. */
7067 148771694 : if (ce->index)
7068 : {
7069 : /* The parser only allows identifiers as designated
7070 : initializers. */
7071 100391889 : if (ce->index == error_mark_node)
7072 : {
7073 0 : error ("name used in a GNU-style designated "
7074 : "initializer for an array");
7075 0 : return false;
7076 : }
7077 100391889 : else if (identifier_p (ce->index))
7078 : {
7079 19 : error ("name %qD used in a GNU-style designated "
7080 : "initializer for an array", ce->index);
7081 19 : ce->index = error_mark_node;
7082 19 : return false;
7083 : }
7084 :
7085 100391870 : tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
7086 : ce->index, true);
7087 100391870 : if (ce_index
7088 100391867 : && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
7089 200783734 : && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
7090 : == INTEGER_CST))
7091 : {
7092 : /* A C99 designator is OK if it matches the current index. */
7093 100391864 : if (wi::to_wide (ce_index) == index)
7094 : {
7095 100391858 : ce->index = ce_index;
7096 100391858 : return true;
7097 : }
7098 : else
7099 6 : sorry ("non-trivial designated initializers not supported");
7100 : }
7101 : else
7102 6 : error_at (cp_expr_loc_or_input_loc (ce->index),
7103 : "C99 designator %qE is not an integral constant-expression",
7104 : ce->index);
7105 :
7106 12 : return false;
7107 : }
7108 :
7109 : return true;
7110 : }
7111 :
7112 : /* When parsing `int a[] = {1, 2};' we don't know the size of the
7113 : array until we finish parsing the initializer. If that's the
7114 : situation we're in, update DECL accordingly. */
7115 :
7116 : static void
7117 72568229 : maybe_deduce_size_from_array_init (tree decl, tree init)
7118 : {
7119 72568229 : tree type = TREE_TYPE (decl);
7120 :
7121 72568229 : if (TREE_CODE (type) == ARRAY_TYPE
7122 925819 : && TYPE_DOMAIN (type) == NULL_TREE
7123 73168856 : && TREE_CODE (decl) != TYPE_DECL)
7124 : {
7125 : /* do_default is really a C-ism to deal with tentative definitions.
7126 : But let's leave it here to ease the eventual merge. */
7127 600627 : int do_default = !DECL_EXTERNAL (decl);
7128 600627 : tree initializer = init ? init : DECL_INITIAL (decl);
7129 600627 : int failure = 0;
7130 :
7131 : /* Check that there are no designated initializers in INIT, as
7132 : those are not supported in GNU C++, and as the middle-end
7133 : will crash if presented with a non-numeric designated
7134 : initializer. */
7135 600627 : if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
7136 : {
7137 141589 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
7138 141589 : constructor_elt *ce;
7139 141589 : HOST_WIDE_INT i, j = 0;
7140 46660189 : FOR_EACH_VEC_SAFE_ELT (v, i, ce)
7141 : {
7142 46519331 : if (instantiation_dependent_expression_p (ce->index))
7143 72568229 : return;
7144 46519325 : if (!check_array_designated_initializer (ce, j))
7145 1 : failure = 1;
7146 : /* If an un-designated initializer is type-dependent, we can't
7147 : check brace elision yet. */
7148 46519325 : if (ce->index == NULL_TREE
7149 46519325 : && type_dependent_expression_p (ce->value))
7150 : return;
7151 46518600 : if (TREE_CODE (ce->value) == RAW_DATA_CST)
7152 200 : j += RAW_DATA_LENGTH (ce->value);
7153 : else
7154 46518400 : ++j;
7155 : }
7156 : }
7157 :
7158 140858 : if (failure)
7159 1 : TREE_TYPE (decl) = error_mark_node;
7160 : else
7161 : {
7162 599895 : failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
7163 : do_default);
7164 599895 : if (failure == 1)
7165 : {
7166 33 : error_at (cp_expr_loc_or_loc (initializer,
7167 30 : DECL_SOURCE_LOCATION (decl)),
7168 : "initializer fails to determine size of %qD", decl);
7169 : }
7170 599865 : else if (failure == 2)
7171 : {
7172 30 : if (do_default)
7173 : {
7174 6 : error_at (DECL_SOURCE_LOCATION (decl),
7175 : "array size missing in %qD", decl);
7176 : }
7177 : /* If a `static' var's size isn't known, make it extern as
7178 : well as static, so it does not get allocated. If it's not
7179 : `static', then don't mark it extern; finish_incomplete_decl
7180 : will give it a default size and it will get allocated. */
7181 24 : else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
7182 0 : DECL_EXTERNAL (decl) = 1;
7183 : }
7184 599835 : else if (failure == 3)
7185 : {
7186 6 : error_at (DECL_SOURCE_LOCATION (decl),
7187 : "zero-size array %qD", decl);
7188 : }
7189 : }
7190 :
7191 599896 : cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
7192 :
7193 599896 : relayout_decl (decl);
7194 :
7195 : /* Update the type of the corresponding TEMPLATE_DECL to match. */
7196 599896 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
7197 : {
7198 208 : tree tmpl = template_for_substitution (decl);
7199 208 : if (DECL_TEMPLATE_RESULT (tmpl) == decl)
7200 50 : TREE_TYPE (tmpl) = TREE_TYPE (decl);
7201 : }
7202 : }
7203 : }
7204 :
7205 : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
7206 : any appropriate error messages regarding the layout. */
7207 :
7208 : static void
7209 62083345 : layout_var_decl (tree decl)
7210 : {
7211 62083345 : tree type;
7212 :
7213 62083345 : type = TREE_TYPE (decl);
7214 62083345 : if (type == error_mark_node)
7215 : return;
7216 :
7217 : /* If we haven't already laid out this declaration, do so now.
7218 : Note that we must not call complete type for an external object
7219 : because it's type might involve templates that we are not
7220 : supposed to instantiate yet. (And it's perfectly valid to say
7221 : `extern X x' for some incomplete type `X'.) */
7222 62083298 : if (!DECL_EXTERNAL (decl))
7223 51890961 : complete_type (type);
7224 62083298 : if (!DECL_SIZE (decl)
7225 606336 : && TREE_TYPE (decl) != error_mark_node
7226 62689634 : && complete_or_array_type_p (type))
7227 460379 : layout_decl (decl, 0);
7228 :
7229 62083298 : if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
7230 : {
7231 : /* An automatic variable with an incomplete type: that is an error.
7232 : Don't talk about array types here, since we took care of that
7233 : message in grokdeclarator. */
7234 17 : error_at (DECL_SOURCE_LOCATION (decl),
7235 : "storage size of %qD isn%'t known", decl);
7236 17 : TREE_TYPE (decl) = error_mark_node;
7237 : }
7238 : #if 0
7239 : /* Keep this code around in case we later want to control debug info
7240 : based on whether a type is "used". (jason 1999-11-11) */
7241 :
7242 : else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
7243 : /* Let debugger know it should output info for this type. */
7244 : note_debug_info_needed (ttype);
7245 :
7246 : if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
7247 : note_debug_info_needed (DECL_CONTEXT (decl));
7248 : #endif
7249 :
7250 113974259 : if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
7251 38311465 : && DECL_SIZE (decl) != NULL_TREE
7252 100118286 : && ! TREE_CONSTANT (DECL_SIZE (decl)))
7253 : {
7254 6 : if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
7255 6 : && !DECL_LOCAL_DECL_P (decl))
7256 0 : constant_expression_warning (DECL_SIZE (decl));
7257 : else
7258 : {
7259 6 : error_at (DECL_SOURCE_LOCATION (decl),
7260 : "storage size of %qD isn%'t constant", decl);
7261 6 : TREE_TYPE (decl) = error_mark_node;
7262 6 : type = error_mark_node;
7263 : }
7264 : }
7265 :
7266 : /* If the final element initializes a flexible array field, adjust
7267 : the size of the DECL with the initializer based on whether the
7268 : DECL is a union or a structure. */
7269 62083298 : if (type != error_mark_node
7270 62083292 : && DECL_INITIAL (decl)
7271 36717576 : && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
7272 5055987 : && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
7273 3408251 : && DECL_SIZE (decl) != NULL_TREE
7274 3408251 : && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
7275 3408251 : && COMPLETE_TYPE_P (type)
7276 3408251 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
7277 65491549 : && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
7278 : {
7279 3408251 : constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
7280 3408251 : if (elt.index)
7281 : {
7282 1237861 : tree itype = TREE_TYPE (elt.index);
7283 1237861 : tree vtype = TREE_TYPE (elt.value);
7284 1237861 : if (TREE_CODE (itype) == ARRAY_TYPE
7285 80880 : && TYPE_DOMAIN (itype) == NULL
7286 275 : && TREE_CODE (vtype) == ARRAY_TYPE
7287 1238136 : && COMPLETE_TYPE_P (vtype))
7288 : {
7289 : /* For a structure, add the size of the initializer to the DECL's
7290 : size. */
7291 275 : if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
7292 : {
7293 260 : DECL_SIZE (decl)
7294 260 : = size_binop (PLUS_EXPR, DECL_SIZE (decl),
7295 : TYPE_SIZE (vtype));
7296 260 : DECL_SIZE_UNIT (decl)
7297 520 : = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
7298 : TYPE_SIZE_UNIT (vtype));
7299 : }
7300 : /* For a union, the DECL's size is the maximum of the current size
7301 : and the size of the initializer. */
7302 : else
7303 : {
7304 15 : DECL_SIZE (decl)
7305 15 : = size_binop (MAX_EXPR, DECL_SIZE (decl),
7306 : TYPE_SIZE (vtype));
7307 15 : DECL_SIZE_UNIT (decl)
7308 30 : = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
7309 : TYPE_SIZE_UNIT (vtype));
7310 : }
7311 : }
7312 : }
7313 : }
7314 : }
7315 :
7316 : /* If a local static variable is declared in an inline function, or if
7317 : we have a weak definition, we must endeavor to create only one
7318 : instance of the variable at link-time. */
7319 :
7320 : void
7321 76350476 : maybe_commonize_var (tree decl)
7322 : {
7323 : /* Don't mess with __FUNCTION__ and similar. But do handle structured
7324 : bindings. */
7325 76350476 : if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
7326 : return;
7327 :
7328 : /* Static data in a function with comdat linkage also has comdat
7329 : linkage. */
7330 71168537 : if ((TREE_STATIC (decl)
7331 47115298 : && DECL_FUNCTION_SCOPE_P (decl)
7332 136070 : && vague_linkage_p (DECL_CONTEXT (decl)))
7333 165585373 : || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
7334 : {
7335 41211729 : if (flag_weak)
7336 : {
7337 : /* With weak symbols, we simply make the variable COMDAT;
7338 : that will cause copies in multiple translations units to
7339 : be merged. */
7340 41211702 : comdat_linkage (decl);
7341 : }
7342 : else
7343 : {
7344 27 : if (DECL_INITIAL (decl) == NULL_TREE
7345 27 : || DECL_INITIAL (decl) == error_mark_node)
7346 : {
7347 : /* Without weak symbols, we can use COMMON to merge
7348 : uninitialized variables. */
7349 24 : TREE_PUBLIC (decl) = 1;
7350 24 : DECL_COMMON (decl) = 1;
7351 : }
7352 : else
7353 : {
7354 : /* While for initialized variables, we must use internal
7355 : linkage -- which means that multiple copies will not
7356 : be merged. */
7357 3 : TREE_PUBLIC (decl) = 0;
7358 3 : DECL_COMMON (decl) = 0;
7359 3 : DECL_INTERFACE_KNOWN (decl) = 1;
7360 3 : const char *msg;
7361 3 : if (DECL_INLINE_VAR_P (decl))
7362 : msg = G_("sorry: semantics of inline variable "
7363 : "%q#D are wrong (you%'ll wind up with "
7364 : "multiple copies)");
7365 : else
7366 : msg = G_("sorry: semantics of inline function "
7367 : "static data %q#D are wrong (you%'ll wind "
7368 : "up with multiple copies)");
7369 3 : auto_diagnostic_group d;
7370 3 : if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
7371 : msg, decl))
7372 3 : inform (DECL_SOURCE_LOCATION (decl),
7373 : "you can work around this by removing the initializer");
7374 3 : }
7375 : }
7376 : }
7377 : }
7378 :
7379 : /* Issue an error message if DECL is an uninitialized const variable.
7380 : CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
7381 : context from potential_constant_expression. Returns true if all is well,
7382 : false otherwise. */
7383 :
7384 : bool
7385 8554520 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
7386 : tsubst_flags_t complain)
7387 : {
7388 8554520 : tree type = strip_array_types (TREE_TYPE (decl));
7389 :
7390 : /* ``Unless explicitly declared extern, a const object does not have
7391 : external linkage and must be initialized. ($8.4; $12.1)'' ARM
7392 : 7.1.6 */
7393 8554520 : if (VAR_P (decl)
7394 8554520 : && !TYPE_REF_P (type)
7395 8510969 : && (CP_TYPE_CONST_P (type)
7396 : /* C++20 permits trivial default initialization in constexpr
7397 : context (P1331R2). */
7398 6604134 : || (cxx_dialect < cxx20
7399 136339 : && (constexpr_context_p
7400 122969 : || var_in_constexpr_fn (decl))))
7401 10476806 : && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
7402 : {
7403 631617 : tree field = default_init_uninitialized_part (type);
7404 631617 : if (!field)
7405 : return true;
7406 :
7407 3899 : auto_diagnostic_group d;
7408 3899 : bool show_notes = true;
7409 :
7410 3899 : if (!constexpr_context_p || cxx_dialect >= cxx20)
7411 : {
7412 173 : if (CP_TYPE_CONST_P (type))
7413 : {
7414 90 : if (complain & tf_error)
7415 84 : show_notes = permerror (DECL_SOURCE_LOCATION (decl),
7416 : "uninitialized %<const %D%>", decl);
7417 : }
7418 : else
7419 : {
7420 83 : if (!is_instantiation_of_constexpr (current_function_decl)
7421 83 : && (complain & tf_error))
7422 21 : error_at (DECL_SOURCE_LOCATION (decl),
7423 : "uninitialized variable %qD in %<constexpr%> "
7424 : "function", decl);
7425 : else
7426 : show_notes = false;
7427 83 : cp_function_chain->invalid_constexpr = true;
7428 : }
7429 : }
7430 3726 : else if (complain & tf_error)
7431 2 : error_at (DECL_SOURCE_LOCATION (decl),
7432 : "uninitialized variable %qD in %<constexpr%> context",
7433 : decl);
7434 :
7435 3899 : if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
7436 : {
7437 62 : tree defaulted_ctor;
7438 :
7439 62 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
7440 : "%q#T has no user-provided default constructor", type);
7441 62 : defaulted_ctor = in_class_defaulted_default_constructor (type);
7442 62 : if (defaulted_ctor)
7443 33 : inform (DECL_SOURCE_LOCATION (defaulted_ctor),
7444 : "constructor is not user-provided because it is "
7445 : "explicitly defaulted in the class body");
7446 62 : inform (DECL_SOURCE_LOCATION (field),
7447 : "and the implicitly-defined constructor does not "
7448 : "initialize %q#D", field);
7449 : }
7450 :
7451 3899 : return false;
7452 3899 : }
7453 :
7454 : return true;
7455 : }
7456 :
7457 : /* Structure holding the current initializer being processed by reshape_init.
7458 : CUR is a pointer to the current element being processed, END is a pointer
7459 : after the last element present in the initializer and RAW_IDX is index into
7460 : RAW_DATA_CST if that is CUR elt. */
7461 : struct reshape_iter
7462 : {
7463 : constructor_elt *cur;
7464 : constructor_elt *end;
7465 : unsigned raw_idx;
7466 : };
7467 :
7468 : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
7469 :
7470 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
7471 : returned is the next FIELD_DECL (possibly FIELD itself) that can be
7472 : initialized as if for an aggregate class. If there are no more such fields,
7473 : the return value will be NULL. */
7474 :
7475 : tree
7476 13293333 : next_aggregate_field (tree field)
7477 : {
7478 13293333 : while (field
7479 52753724 : && (TREE_CODE (field) != FIELD_DECL
7480 8251846 : || DECL_UNNAMED_BIT_FIELD (field)
7481 8251691 : || (DECL_ARTIFICIAL (field)
7482 : /* In C++17, aggregates can have bases. */
7483 179515 : && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
7484 39460391 : field = DECL_CHAIN (field);
7485 :
7486 13293333 : return field;
7487 : }
7488 :
7489 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
7490 : returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
7491 : to a subobject. If there are no more such fields, the return value will be
7492 : NULL. */
7493 :
7494 : tree
7495 64875262 : next_subobject_field (tree field)
7496 : {
7497 64875262 : while (field
7498 835317151 : && (TREE_CODE (field) != FIELD_DECL
7499 28799380 : || DECL_UNNAMED_BIT_FIELD (field)
7500 28799248 : || (DECL_ARTIFICIAL (field)
7501 8120909 : && !DECL_FIELD_IS_BASE (field)
7502 1755273 : && !DECL_VIRTUAL_P (field))))
7503 770441889 : field = DECL_CHAIN (field);
7504 :
7505 64875262 : return field;
7506 : }
7507 :
7508 : /* Return true for [dcl.init.list] direct-list-initialization from
7509 : single element of enumeration with a fixed underlying type. */
7510 :
7511 : bool
7512 178319820 : is_direct_enum_init (tree type, tree init)
7513 : {
7514 178319820 : if (cxx_dialect >= cxx17
7515 176261652 : && TREE_CODE (type) == ENUMERAL_TYPE
7516 7233309 : && ENUM_FIXED_UNDERLYING_TYPE_P (type)
7517 4903482 : && TREE_CODE (init) == CONSTRUCTOR
7518 400927 : && CONSTRUCTOR_IS_DIRECT_INIT (init)
7519 194973 : && CONSTRUCTOR_NELTS (init) == 1
7520 216 : && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
7521 : /* DR 2374: The single element needs to be implicitly
7522 : convertible to the underlying type of the enum. */
7523 216 : && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
7524 178320034 : && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
7525 214 : TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
7526 214 : CONSTRUCTOR_ELT (init, 0)->value,
7527 : LOOKUP_IMPLICIT, tf_none))
7528 : return true;
7529 : return false;
7530 : }
7531 :
7532 : /* Helper function for reshape_init*. Split first element of
7533 : RAW_DATA_CST or return NULL for other elements. Set *INC_CUR
7534 : to true if the whole d->cur has been consumed. */
7535 :
7536 : static tree
7537 59166219 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
7538 : {
7539 59166219 : *inc_cur = true;
7540 59166219 : if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
7541 : return NULL_TREE;
7542 30720 : tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
7543 30720 : if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
7544 30588 : *inc_cur = false;
7545 : else
7546 132 : d->raw_idx = 0;
7547 : return ret;
7548 : }
7549 :
7550 : /* Wrapper around that which for RAW_DATA_CST in INIT
7551 : (as well as in D->cur->value) peels off the first element
7552 : of the raw data and returns it, otherwise increments
7553 : D->cur and returns INIT. */
7554 :
7555 : static tree
7556 59166203 : consume_init (tree init, reshape_iter *d)
7557 : {
7558 59166203 : bool inc_cur;
7559 59166203 : if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
7560 30720 : init = raw_init;
7561 59166203 : if (inc_cur)
7562 59135615 : d->cur++;
7563 59166203 : return init;
7564 : }
7565 :
7566 : /* Subroutine of reshape_init_array and reshape_init_vector, which does
7567 : the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
7568 : INTEGER_CST representing the size of the array minus one (the maximum index),
7569 : or NULL_TREE if the array was declared without specifying the size. D is
7570 : the iterator within the constructor. */
7571 :
7572 : static tree
7573 450737 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
7574 : tree first_initializer_p, bool vector_p,
7575 : tsubst_flags_t complain)
7576 : {
7577 450737 : tree new_init;
7578 450737 : bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
7579 450737 : unsigned HOST_WIDE_INT max_index_cst = 0;
7580 450737 : unsigned HOST_WIDE_INT index;
7581 :
7582 : /* The initializer for an array is always a CONSTRUCTOR. If this is the
7583 : outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
7584 : to build a new one. But don't reuse if not complaining; if this is
7585 : tentative, we might also reshape to another type (95319). */
7586 450737 : bool reuse = (first_initializer_p
7587 395804 : && (complain & tf_error)
7588 394558 : && !CP_AGGREGATE_TYPE_P (elt_type)
7589 782769 : && !TREE_SIDE_EFFECTS (first_initializer_p));
7590 123253 : if (reuse)
7591 : new_init = first_initializer_p;
7592 : else
7593 123253 : new_init = build_constructor (init_list_type_node, NULL);
7594 :
7595 450737 : if (sized_array_p)
7596 : {
7597 269152 : poly_uint64 midx;
7598 : /* Minus 1 is used for zero sized arrays. */
7599 269152 : if (integer_all_onesp (max_index))
7600 24 : return new_init;
7601 :
7602 269128 : if (tree_fits_poly_uint64_p (max_index))
7603 269128 : midx = tree_to_poly_uint64 (max_index);
7604 : /* sizetype is sign extended, not zero extended. */
7605 : else
7606 0 : midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
7607 :
7608 : /* For VLA vectors, we restict the number of elements in the constructor
7609 : to lower bound of the VLA elements. */
7610 269128 : max_index_cst = constant_lower_bound (midx);
7611 : }
7612 :
7613 450713 : constructor_elt *first_cur = d->cur;
7614 : /* Loop until there are no more initializers. */
7615 54380471 : for (index = 0;
7616 54380471 : d->cur != d->end && (!sized_array_p || index <= max_index_cst);
7617 : ++index)
7618 : {
7619 53929938 : tree elt_init;
7620 53929938 : constructor_elt *old_cur = d->cur;
7621 53929938 : unsigned int old_raw_idx = d->raw_idx;
7622 53929938 : bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
7623 :
7624 53929938 : if (d->cur->index)
7625 5571303 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7626 53929938 : check_array_designated_initializer (d->cur, index);
7627 53929938 : if (TREE_CODE (d->cur->value) == RAW_DATA_CST
7628 32732 : && (TREE_CODE (elt_type) == INTEGER_TYPE
7629 10233 : || is_byte_access_type (elt_type))
7630 22499 : && TYPE_PRECISION (elt_type) == CHAR_BIT
7631 1838 : && (!sized_array_p || index < max_index_cst)
7632 53931764 : && !vector_p)
7633 : {
7634 506 : elt_init = d->cur->value;
7635 506 : unsigned int off = d->raw_idx;
7636 506 : unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
7637 506 : if (!sized_array_p || len <= max_index_cst - index + 1)
7638 : {
7639 497 : d->cur++;
7640 497 : d->raw_idx = 0;
7641 : }
7642 : else
7643 : {
7644 9 : len = max_index_cst - index + 1;
7645 9 : d->raw_idx += len;
7646 : }
7647 506 : if (!reuse || off || d->cur == old_cur)
7648 : {
7649 27 : elt_init = copy_node (elt_init);
7650 27 : RAW_DATA_LENGTH (elt_init) = len;
7651 27 : RAW_DATA_POINTER (elt_init) += off;
7652 : }
7653 506 : TREE_TYPE (elt_init) = elt_type;
7654 : }
7655 : else
7656 53929432 : elt_init = reshape_init_r (elt_type, d,
7657 : /*first_initializer_p=*/NULL_TREE,
7658 : complain);
7659 53929938 : if (elt_init == error_mark_node)
7660 : return error_mark_node;
7661 53929761 : tree idx = size_int (index);
7662 53929761 : if (reuse && old_raw_data_cst && d->cur == old_cur)
7663 : {
7664 : /* We need to stop reusing as some RAW_DATA_CST in the original
7665 : ctor had to be split. */
7666 72 : new_init = build_constructor (init_list_type_node, NULL);
7667 72 : if (index)
7668 : {
7669 72 : vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
7670 72 : memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
7671 72 : (d->cur - first_cur)
7672 : * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
7673 72 : if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
7674 : {
7675 : unsigned int j;
7676 : tree nidx, nval;
7677 4 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
7678 : j, nidx, nval)
7679 4 : if (nidx)
7680 : {
7681 4 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
7682 4 : (void) nval;
7683 4 : break;
7684 : }
7685 : }
7686 : }
7687 : reuse = false;
7688 : }
7689 53929689 : if (reuse)
7690 : {
7691 52751849 : old_cur->index = idx;
7692 52751849 : old_cur->value = elt_init;
7693 : }
7694 : else
7695 1177912 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
7696 : idx, elt_init);
7697 53929761 : if (!TREE_CONSTANT (elt_init))
7698 185572 : TREE_CONSTANT (new_init) = false;
7699 :
7700 : /* This can happen with an invalid initializer (c++/54501). */
7701 53929761 : if (d->cur == old_cur
7702 32082 : && !sized_array_p
7703 14085 : && d->raw_idx == old_raw_idx)
7704 : break;
7705 :
7706 53929758 : if (TREE_CODE (elt_init) == RAW_DATA_CST)
7707 506 : index += RAW_DATA_LENGTH (elt_init) - 1;
7708 : }
7709 :
7710 : return new_init;
7711 : }
7712 :
7713 : /* Subroutine of reshape_init_r, processes the initializers for arrays.
7714 : Parameters are the same of reshape_init_r. */
7715 :
7716 : static tree
7717 402786 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
7718 : tsubst_flags_t complain)
7719 : {
7720 402786 : tree max_index = NULL_TREE;
7721 :
7722 402786 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
7723 :
7724 402786 : if (TYPE_DOMAIN (type))
7725 221249 : max_index = array_type_nelts_minus_one (type);
7726 :
7727 402786 : return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
7728 402786 : first_initializer_p, false, complain);
7729 : }
7730 :
7731 : /* Subroutine of reshape_init_r, processes the initializers for vectors.
7732 : Parameters are the same of reshape_init_r. */
7733 :
7734 : static tree
7735 47951 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
7736 : {
7737 47951 : tree max_index = NULL_TREE;
7738 :
7739 47951 : gcc_assert (VECTOR_TYPE_P (type));
7740 :
7741 47951 : if (COMPOUND_LITERAL_P (d->cur->value))
7742 : {
7743 0 : tree value = d->cur->value;
7744 0 : if (!same_type_p (TREE_TYPE (value), type))
7745 : {
7746 0 : if (complain & tf_error)
7747 0 : error ("invalid type %qT as initializer for a vector of type %qT",
7748 0 : TREE_TYPE (d->cur->value), type);
7749 0 : value = error_mark_node;
7750 : }
7751 0 : ++d->cur;
7752 0 : return value;
7753 : }
7754 :
7755 : /* For a vector, we initialize it as an array of the appropriate size. */
7756 47951 : if (VECTOR_TYPE_P (type))
7757 47951 : max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
7758 :
7759 47951 : return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
7760 47951 : NULL_TREE, true, complain);
7761 : }
7762 :
7763 : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
7764 : INIT, in isolation from any designator or other initializers. */
7765 :
7766 : static tree
7767 488507 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
7768 : {
7769 : /* We could also implement this by wrapping init in a new CONSTRUCTOR and
7770 : calling reshape_init, but this way can just live on the stack. */
7771 488507 : constructor_elt elt = { /*index=*/NULL_TREE, init };
7772 488507 : reshape_iter iter = { &elt, &elt + 1, 0 };
7773 488507 : return reshape_init_r (type, &iter,
7774 : /*first_initializer_p=*/NULL_TREE,
7775 488507 : complain);
7776 : }
7777 :
7778 : /* Subroutine of reshape_init_r, processes the initializers for classes
7779 : or union. Parameters are the same of reshape_init_r. */
7780 :
7781 : static tree
7782 3194887 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
7783 : tsubst_flags_t complain)
7784 : {
7785 3194887 : tree field;
7786 3194887 : tree new_init;
7787 :
7788 3194887 : gcc_assert (CLASS_TYPE_P (type));
7789 :
7790 : /* The initializer for a class is always a CONSTRUCTOR. */
7791 3194887 : new_init = build_constructor (init_list_type_node, NULL);
7792 :
7793 3194887 : int binfo_idx = -1;
7794 3194887 : tree binfo = TYPE_BINFO (type);
7795 3194887 : tree base_binfo = NULL_TREE;
7796 3194887 : if (cxx_dialect >= cxx17 && uses_template_parms (type))
7797 : {
7798 : /* We get here from maybe_aggr_guide for C++20 class template argument
7799 : deduction. In this case we need to look through the binfo because a
7800 : template doesn't have base fields. */
7801 1413 : binfo_idx = 0;
7802 1413 : BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
7803 : }
7804 67 : if (base_binfo)
7805 : field = base_binfo;
7806 : else
7807 3194820 : field = next_aggregate_field (TYPE_FIELDS (type));
7808 :
7809 3194887 : if (!field)
7810 : {
7811 : /* [dcl.init.aggr]
7812 :
7813 : An initializer for an aggregate member that is an
7814 : empty class shall have the form of an empty
7815 : initializer-list {}. */
7816 322 : if (!first_initializer_p)
7817 : {
7818 268 : if (complain & tf_error)
7819 13 : error ("initializer for %qT must be brace-enclosed", type);
7820 268 : return error_mark_node;
7821 : }
7822 : return new_init;
7823 : }
7824 :
7825 : /* For C++20 CTAD, handle pack expansions in the base list. */
7826 : tree last_was_pack_expansion = NULL_TREE;
7827 :
7828 : /* Loop through the initializable fields, gathering initializers. */
7829 9557253 : while (d->cur != d->end)
7830 : {
7831 6467523 : tree field_init;
7832 6467523 : constructor_elt *old_cur = d->cur;
7833 6467523 : unsigned old_raw_idx = d->raw_idx;
7834 6467523 : bool direct_desig = false;
7835 :
7836 : /* Handle C++20 designated initializers. */
7837 6467523 : if (d->cur->index)
7838 : {
7839 488673 : if (d->cur->index == error_mark_node)
7840 : return error_mark_node;
7841 :
7842 488667 : if (TREE_CODE (d->cur->index) == FIELD_DECL)
7843 : {
7844 : /* We already reshaped this; we should have returned early from
7845 : reshape_init. */
7846 0 : gcc_checking_assert (false);
7847 : if (field != d->cur->index)
7848 : {
7849 : if (tree id = DECL_NAME (d->cur->index))
7850 : gcc_checking_assert (d->cur->index
7851 : == get_class_binding (type, id));
7852 : field = d->cur->index;
7853 : }
7854 : }
7855 488667 : else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
7856 : {
7857 488661 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7858 488661 : field = get_class_binding (type, d->cur->index);
7859 488661 : direct_desig = true;
7860 : }
7861 : else
7862 : {
7863 6 : if (complain & tf_error)
7864 6 : error ("%<[%E] =%> used in a GNU-style designated initializer"
7865 : " for class %qT", d->cur->index, type);
7866 6 : return error_mark_node;
7867 : }
7868 :
7869 488661 : if (!field && ANON_AGGR_TYPE_P (type))
7870 : /* Apparently the designator isn't for a member of this anonymous
7871 : struct, so head back to the enclosing class. */
7872 : break;
7873 :
7874 488658 : if (!field || TREE_CODE (field) != FIELD_DECL)
7875 : {
7876 18 : if (complain & tf_error)
7877 : {
7878 6 : if (field && TREE_CODE (field) == TREE_LIST)
7879 : {
7880 3 : auto_diagnostic_group g;
7881 3 : error ("request for member %qD is ambiguous",
7882 3 : d->cur->index);
7883 3 : print_candidates (input_location, field);
7884 3 : }
7885 : else
7886 3 : error ("%qT has no non-static data member named %qD", type,
7887 3 : d->cur->index);
7888 : }
7889 18 : return error_mark_node;
7890 : }
7891 :
7892 : /* If the element is an anonymous union object and the initializer
7893 : list is a designated-initializer-list, the anonymous union object
7894 : is initialized by the designated-initializer-list { D }, where D
7895 : is the designated-initializer-clause naming a member of the
7896 : anonymous union object. */
7897 488640 : tree ictx = DECL_CONTEXT (field);
7898 488640 : if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
7899 : {
7900 : /* Find the anon aggr that is a direct member of TYPE. */
7901 146 : while (ANON_AGGR_TYPE_P (ictx))
7902 : {
7903 143 : tree cctx = TYPE_CONTEXT (ictx);
7904 143 : if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
7905 130 : goto found;
7906 : ictx = cctx;
7907 : }
7908 :
7909 : /* Not found, e.g. FIELD is a member of a base class. */
7910 3 : if (complain & tf_error)
7911 3 : error ("%qD is not a direct member of %qT", field, type);
7912 3 : return error_mark_node;
7913 :
7914 130 : found:
7915 : /* Now find the TYPE member with that anon aggr type. */
7916 130 : tree aafield = TYPE_FIELDS (type);
7917 1110 : for (; aafield; aafield = TREE_CHAIN (aafield))
7918 1110 : if (TREE_TYPE (aafield) == ictx)
7919 : break;
7920 0 : gcc_assert (aafield);
7921 : field = aafield;
7922 : direct_desig = false;
7923 : }
7924 : }
7925 :
7926 : /* If we processed all the member of the class, we are done. */
7927 6467357 : if (!field)
7928 : break;
7929 :
7930 12934055 : last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
7931 6467037 : ? field : NULL_TREE);
7932 6467037 : if (last_was_pack_expansion)
7933 : /* Each non-trailing aggregate element that is a pack expansion is
7934 : assumed to correspond to no elements of the initializer list. */
7935 19 : goto continue_;
7936 :
7937 6467018 : if (direct_desig)
7938 : {
7939 : /* The designated field F is initialized from this one element.
7940 :
7941 : Note that we don't want to do this if we found the designator
7942 : inside an anon aggr above; we use the normal code to implement:
7943 :
7944 : "If the element is an anonymous union member and the initializer
7945 : list is a brace-enclosed designated- initializer-list, the element
7946 : is initialized by the designated-initializer-list { D }, where D
7947 : is the designated- initializer-clause naming a member of the
7948 : anonymous union member." */
7949 488507 : gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
7950 488507 : field_init = reshape_single_init (TREE_TYPE (field),
7951 : d->cur->value, complain);
7952 488507 : d->cur++;
7953 : }
7954 : else
7955 5978511 : field_init = reshape_init_r (TREE_TYPE (field), d,
7956 : /*first_initializer_p=*/NULL_TREE,
7957 : complain);
7958 :
7959 6467018 : if (field_init == error_mark_node)
7960 : return error_mark_node;
7961 :
7962 6466731 : if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
7963 : {
7964 : /* This can happen with an invalid initializer for a flexible
7965 : array member (c++/54441). */
7966 0 : if (complain & tf_error)
7967 0 : error ("invalid initializer for %q#D", field);
7968 0 : return error_mark_node;
7969 : }
7970 :
7971 6466731 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
7972 :
7973 : /* [dcl.init.aggr]
7974 :
7975 : When a union is initialized with a brace-enclosed
7976 : initializer, the braces shall only contain an
7977 : initializer for the first member of the union. */
7978 6466731 : if (TREE_CODE (type) == UNION_TYPE)
7979 : break;
7980 :
7981 6362669 : continue_:
7982 6362688 : if (base_binfo)
7983 : {
7984 82 : if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
7985 : field = base_binfo;
7986 : else
7987 35 : field = next_aggregate_field (TYPE_FIELDS (type));
7988 : }
7989 : else
7990 6362606 : field = next_aggregate_field (DECL_CHAIN (field));
7991 : }
7992 :
7993 : /* A trailing aggregate element that is a pack expansion is assumed to
7994 : correspond to all remaining elements of the initializer list (if any). */
7995 3194245 : if (last_was_pack_expansion)
7996 : {
7997 16 : tree init = d->cur->value;
7998 16 : bool inc_cur;
7999 16 : if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
8000 0 : init = raw_init;
8001 16 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
8002 : last_was_pack_expansion, init);
8003 46 : while (d->cur != d->end)
8004 30 : d->cur++;
8005 : }
8006 :
8007 : return new_init;
8008 : }
8009 :
8010 : /* Subroutine of reshape_init_r. We're in a context where C99 initializer
8011 : designators are not valid; either complain or return true to indicate
8012 : that reshape_init_r should return error_mark_node. */
8013 :
8014 : static bool
8015 241429 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
8016 : {
8017 241429 : if (d->cur->index)
8018 : {
8019 30 : if (complain & tf_error)
8020 45 : error_at (cp_expr_loc_or_input_loc (d->cur->index),
8021 : "C99 designator %qE outside aggregate initializer",
8022 : d->cur->index);
8023 : else
8024 : return true;
8025 : }
8026 : return false;
8027 : }
8028 :
8029 : /* Subroutine of reshape_init, which processes a single initializer (part of
8030 : a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
8031 : iterator within the CONSTRUCTOR which points to the initializer to process.
8032 : If this is the first initializer of the outermost CONSTRUCTOR node,
8033 : FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE. */
8034 :
8035 : static tree
8036 64275564 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
8037 : tsubst_flags_t complain)
8038 : {
8039 64275564 : tree init = d->cur->value;
8040 :
8041 64275564 : if (error_operand_p (init))
8042 130 : return error_mark_node;
8043 :
8044 3878987 : if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
8045 64516684 : && has_designator_problem (d, complain))
8046 0 : return error_mark_node;
8047 :
8048 64275434 : tree stripped_init = tree_strip_any_location_wrapper (init);
8049 :
8050 64275434 : if (TREE_CODE (type) == COMPLEX_TYPE)
8051 : {
8052 : /* A complex type can be initialized from one or two initializers,
8053 : but braces are not elided. */
8054 678 : init = consume_init (init, d);
8055 678 : if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
8056 : {
8057 9 : if (CONSTRUCTOR_NELTS (stripped_init) > 2)
8058 : {
8059 0 : if (complain & tf_error)
8060 0 : error ("too many initializers for %qT", type);
8061 : else
8062 0 : return error_mark_node;
8063 : }
8064 : }
8065 669 : else if (first_initializer_p && d->cur != d->end)
8066 : {
8067 36 : if (error_operand_p (d->cur->value)
8068 36 : || has_designator_problem (d, complain))
8069 0 : return error_mark_node;
8070 36 : vec<constructor_elt, va_gc> *v = 0;
8071 36 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
8072 36 : init = consume_init (d->cur->value, d);
8073 36 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
8074 36 : init = build_constructor (init_list_type_node, v);
8075 : }
8076 678 : return init;
8077 : }
8078 :
8079 : /* A non-aggregate type is always initialized with a single
8080 : initializer. */
8081 128492757 : if (!CP_AGGREGATE_TYPE_P (type)
8082 : /* As is an array with dependent bound, which we can see
8083 : during C++20 aggregate CTAD. */
8084 69331831 : || (cxx_dialect >= cxx20
8085 5008836 : && TREE_CODE (type) == ARRAY_TYPE
8086 494695 : && uses_template_parms (TYPE_DOMAIN (type))))
8087 : {
8088 : /* It is invalid to initialize a non-aggregate type with a
8089 : brace-enclosed initializer before C++0x.
8090 : We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
8091 : of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
8092 : a CONSTRUCTOR (with a record type). */
8093 59160937 : if (TREE_CODE (stripped_init) == CONSTRUCTOR
8094 : /* Don't complain about a capture-init. */
8095 293471 : && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
8096 59444507 : && BRACE_ENCLOSED_INITIALIZER_P (stripped_init)) /* p7626.C */
8097 : {
8098 283531 : if (SCALAR_TYPE_P (type))
8099 : {
8100 477 : if (cxx_dialect < cxx11)
8101 : {
8102 16 : if (complain & tf_error)
8103 16 : error ("braces around scalar initializer for type %qT",
8104 : type);
8105 16 : init = error_mark_node;
8106 : }
8107 461 : else if (first_initializer_p
8108 461 : || (CONSTRUCTOR_NELTS (stripped_init) > 0
8109 296 : && (BRACE_ENCLOSED_INITIALIZER_P
8110 : (CONSTRUCTOR_ELT (stripped_init,0)->value))))
8111 : {
8112 13 : if (complain & tf_error)
8113 13 : error ("too many braces around scalar initializer "
8114 : "for type %qT", type);
8115 13 : init = error_mark_node;
8116 : }
8117 : }
8118 : else
8119 283054 : maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
8120 : }
8121 59160937 : return consume_init (init, d);
8122 : }
8123 :
8124 : /* "If T is a class type and the initializer list has a single element of
8125 : type cv U, where U is T or a class derived from T, the object is
8126 : initialized from that element." Even if T is an aggregate. */
8127 5089811 : if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
8128 4569605 : && first_initializer_p
8129 : /* But not if it's a designated init. */
8130 3227322 : && !d->cur->index
8131 2982150 : && d->end - d->cur == 1
8132 565493 : && TREE_CODE (init) != RAW_DATA_CST
8133 5679312 : && reference_related_p (type, TREE_TYPE (init)))
8134 : {
8135 416 : d->cur++;
8136 416 : return init;
8137 : }
8138 :
8139 : /* [dcl.init.aggr]
8140 :
8141 : All implicit type conversions (clause _conv_) are considered when
8142 : initializing the aggregate member with an initializer from an
8143 : initializer-list. If the initializer can initialize a member,
8144 : the member is initialized. Otherwise, if the member is itself a
8145 : non-empty subaggregate, brace elision is assumed and the
8146 : initializer is considered for the initialization of the first
8147 : member of the subaggregate. */
8148 2077234 : if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
8149 : /* But don't try this for the first initializer, since that would be
8150 : looking through the outermost braces; A a2 = { a1 }; is not a
8151 : valid aggregate initialization. */
8152 3036232 : && !first_initializer_p
8153 5127153 : && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
8154 9234 : || can_convert_arg (type, TREE_TYPE (init),
8155 9234 : TREE_CODE (init) == RAW_DATA_CST
8156 5115009 : ? build_int_cst (integer_type_node,
8157 1606 : *(const unsigned char *)
8158 1606 : RAW_DATA_POINTER (init))
8159 : : init,
8160 : LOOKUP_NORMAL, complain)))
8161 4552 : return consume_init (init, d);
8162 :
8163 : /* [dcl.init.string]
8164 :
8165 : A char array (whether plain char, signed char, or unsigned char)
8166 : can be initialized by a string-literal (optionally enclosed in
8167 : braces); a wchar_t array can be initialized by a wide
8168 : string-literal (optionally enclosed in braces). */
8169 5108851 : if (TREE_CODE (type) == ARRAY_TYPE
8170 5108851 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
8171 : {
8172 123224 : tree str_init = init;
8173 123224 : tree stripped_str_init = stripped_init;
8174 123224 : reshape_iter stripd = {};
8175 :
8176 : /* Strip one level of braces if and only if they enclose a single
8177 : element (as allowed by [dcl.init.string]). */
8178 123224 : if (!first_initializer_p
8179 11884 : && TREE_CODE (stripped_str_init) == CONSTRUCTOR
8180 133972 : && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
8181 : {
8182 392 : stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
8183 392 : str_init = stripd.cur->value;
8184 392 : stripped_str_init = tree_strip_any_location_wrapper (str_init);
8185 : }
8186 :
8187 : /* If it's a string literal, then it's the initializer for the array
8188 : as a whole. Otherwise, continue with normal initialization for
8189 : array types (one value per array element). */
8190 123224 : if (TREE_CODE (stripped_str_init) == STRING_CST)
8191 : {
8192 72 : if ((first_initializer_p && has_designator_problem (d, complain))
8193 1062 : || (stripd.cur && has_designator_problem (&stripd, complain)))
8194 990 : return error_mark_node;
8195 990 : d->cur++;
8196 990 : return str_init;
8197 : }
8198 : }
8199 :
8200 : /* The following cases are about aggregates. If we are not within a full
8201 : initializer already, and there is not a CONSTRUCTOR, it means that there
8202 : is a missing set of braces (that is, we are processing the case for
8203 : which reshape_init exists). */
8204 5107861 : bool braces_elided_p = false;
8205 5107861 : if (!first_initializer_p)
8206 : {
8207 1470612 : if (TREE_CODE (stripped_init) == CONSTRUCTOR)
8208 : {
8209 1462268 : tree init_type = TREE_TYPE (init);
8210 1462268 : if (init_type && TYPE_PTRMEMFUNC_P (init_type))
8211 : /* There is no need to call reshape_init for pointer-to-member
8212 : function initializers, as they are always constructed correctly
8213 : by the front end. Here we have e.g. {.__pfn=0B, .__delta=0},
8214 : which is missing outermost braces. We should warn below, and
8215 : one of the routines below will wrap it in additional { }. */;
8216 : /* For a nested compound literal, proceed to specialized routines,
8217 : to handle initialization of arrays and similar. */
8218 1462259 : else if (COMPOUND_LITERAL_P (stripped_init))
8219 7 : gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
8220 : /* If we have an unresolved designator, we need to find the member it
8221 : designates within TYPE, so proceed to the routines below. For
8222 : FIELD_DECL or INTEGER_CST designators, we're already initializing
8223 : the designated element. */
8224 1462252 : else if (d->cur->index
8225 30 : && TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
8226 : /* Brace elision with designators is only permitted for anonymous
8227 : aggregates. */
8228 15 : gcc_checking_assert (ANON_AGGR_TYPE_P (type));
8229 : /* A CONSTRUCTOR of the target's type is a previously
8230 : digested initializer. */
8231 1462237 : else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
8232 : {
8233 0 : ++d->cur;
8234 0 : return init;
8235 : }
8236 : else
8237 : {
8238 : /* Something that hasn't been reshaped yet. */
8239 1462237 : ++d->cur;
8240 1462237 : gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
8241 1462237 : return reshape_init (type, init, complain);
8242 : }
8243 : }
8244 :
8245 8375 : if (complain & tf_warning)
8246 7221 : warning (OPT_Wmissing_braces,
8247 : "missing braces around initializer for %qT",
8248 : type);
8249 : braces_elided_p = true;
8250 : }
8251 :
8252 : /* Dispatch to specialized routines. */
8253 3645624 : tree new_init;
8254 3645624 : if (CLASS_TYPE_P (type))
8255 3194887 : new_init = reshape_init_class (type, d, first_initializer_p, complain);
8256 450737 : else if (TREE_CODE (type) == ARRAY_TYPE)
8257 402786 : new_init = reshape_init_array (type, d, first_initializer_p, complain);
8258 47951 : else if (VECTOR_TYPE_P (type))
8259 47951 : new_init = reshape_init_vector (type, d, complain);
8260 : else
8261 0 : gcc_unreachable ();
8262 :
8263 3645624 : if (braces_elided_p
8264 8375 : && TREE_CODE (new_init) == CONSTRUCTOR)
8265 8101 : CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
8266 :
8267 : return new_init;
8268 : }
8269 :
8270 : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
8271 : brace-enclosed aggregate initializer.
8272 :
8273 : INIT is the CONSTRUCTOR containing the list of initializers describing
8274 : a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
8275 : It may not presently match the shape of the TYPE; for example:
8276 :
8277 : struct S { int a; int b; };
8278 : struct S a[] = { 1, 2, 3, 4 };
8279 :
8280 : Here INIT will hold a vector of four elements, rather than a
8281 : vector of two elements, each itself a vector of two elements. This
8282 : routine transforms INIT from the former form into the latter. The
8283 : revised CONSTRUCTOR node is returned. */
8284 :
8285 : tree
8286 11458218 : reshape_init (tree type, tree init, tsubst_flags_t complain)
8287 : {
8288 11458218 : vec<constructor_elt, va_gc> *v;
8289 11458218 : reshape_iter d;
8290 11458218 : tree new_init;
8291 :
8292 11458218 : gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
8293 :
8294 11458218 : v = CONSTRUCTOR_ELTS (init);
8295 :
8296 : /* An empty constructor does not need reshaping, and it is always a valid
8297 : initializer. */
8298 11458969 : if (vec_safe_is_empty (v))
8299 : return init;
8300 :
8301 3880073 : if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
8302 : /* Already reshaped. */
8303 : return init;
8304 :
8305 : /* Brace elision is not performed for a CONSTRUCTOR representing
8306 : parenthesized aggregate initialization. */
8307 3879927 : if (CONSTRUCTOR_IS_PAREN_INIT (init))
8308 : {
8309 639 : tree elt = (*v)[0].value;
8310 : /* If we're initializing a char array from a string-literal that is
8311 : enclosed in braces, unwrap it here. */
8312 639 : if (TREE_CODE (type) == ARRAY_TYPE
8313 266 : && vec_safe_length (v) == 1
8314 144 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
8315 678 : && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
8316 : return elt;
8317 605 : return init;
8318 : }
8319 :
8320 : /* Handle [dcl.init.list] direct-list-initialization from
8321 : single element of enumeration with a fixed underlying type. */
8322 3879288 : if (is_direct_enum_init (type, init))
8323 : {
8324 174 : tree elt = CONSTRUCTOR_ELT (init, 0)->value;
8325 174 : type = cv_unqualified (type);
8326 174 : if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
8327 : {
8328 159 : warning_sentinel w (warn_useless_cast);
8329 159 : warning_sentinel w2 (warn_ignored_qualifiers);
8330 159 : return cp_build_c_cast (input_location, type, elt,
8331 : tf_warning_or_error);
8332 159 : }
8333 : else
8334 15 : return error_mark_node;
8335 : }
8336 :
8337 : /* Recurse on this CONSTRUCTOR. */
8338 3879114 : d.cur = &(*v)[0];
8339 3879114 : d.end = d.cur + v->length ();
8340 3879114 : d.raw_idx = 0;
8341 :
8342 3879114 : new_init = reshape_init_r (type, &d, init, complain);
8343 3879114 : if (new_init == error_mark_node)
8344 : return error_mark_node;
8345 :
8346 : /* Make sure all the element of the constructor were used. Otherwise,
8347 : issue an error about exceeding initializers. */
8348 3878490 : if (d.cur != d.end)
8349 : {
8350 206 : if (complain & tf_error)
8351 63 : error ("too many initializers for %qT", type);
8352 206 : return error_mark_node;
8353 : }
8354 :
8355 3878284 : if (CONSTRUCTOR_IS_DIRECT_INIT (init)
8356 3878284 : && BRACE_ENCLOSED_INITIALIZER_P (new_init))
8357 502606 : CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
8358 3878284 : if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
8359 3878284 : && BRACE_ENCLOSED_INITIALIZER_P (new_init))
8360 51814 : gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
8361 : || seen_error ());
8362 :
8363 : return new_init;
8364 : }
8365 :
8366 : /* Verify array initializer. Returns true if errors have been reported. */
8367 :
8368 : bool
8369 957878 : check_array_initializer (tree decl, tree type, tree init)
8370 : {
8371 957878 : tree element_type = TREE_TYPE (type);
8372 :
8373 : /* Structured binding when initialized with an array type needs
8374 : to have complete type. */
8375 957878 : if (decl
8376 946936 : && DECL_DECOMPOSITION_P (decl)
8377 3269 : && DECL_DECOMP_IS_BASE (decl)
8378 961147 : && !COMPLETE_TYPE_P (type))
8379 : {
8380 0 : error_at (DECL_SOURCE_LOCATION (decl),
8381 : "structured binding has incomplete type %qT", type);
8382 0 : TREE_TYPE (decl) = error_mark_node;
8383 0 : return true;
8384 : }
8385 :
8386 : /* The array type itself need not be complete, because the
8387 : initializer may tell us how many elements are in the array.
8388 : But, the elements of the array must be complete. */
8389 957878 : if (!COMPLETE_TYPE_P (complete_type (element_type)))
8390 : {
8391 15 : if (decl)
8392 9 : error_at (DECL_SOURCE_LOCATION (decl),
8393 : "elements of array %q#D have incomplete type", decl);
8394 : else
8395 6 : error ("elements of array %q#T have incomplete type", type);
8396 15 : return true;
8397 : }
8398 :
8399 957863 : location_t loc = (decl ? location_of (decl) : input_location);
8400 957863 : if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
8401 : return true;
8402 :
8403 : /* A compound literal can't have variable size. */
8404 957863 : if (init && !decl
8405 957863 : && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
8406 10933 : || !TREE_CONSTANT (TYPE_SIZE (element_type))))
8407 : {
8408 3 : error ("variable-sized compound literal");
8409 3 : return true;
8410 : }
8411 : return false;
8412 : }
8413 :
8414 : /* Subroutine of check_initializer; args are passed down from that function.
8415 : Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init. */
8416 :
8417 : static tree
8418 2871281 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
8419 : {
8420 2871281 : gcc_assert (stmts_are_full_exprs_p ());
8421 2871281 : if (init)
8422 2334806 : maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
8423 2871281 : return build_aggr_init (decl, init, flags, tf_warning_or_error);
8424 : }
8425 :
8426 : /* Verify INIT (the initializer for DECL), and record the
8427 : initialization in DECL_INITIAL, if appropriate. CLEANUP is as for
8428 : grok_reference_init.
8429 :
8430 : If the return value is non-NULL, it is an expression that must be
8431 : evaluated dynamically to initialize DECL. */
8432 :
8433 : static tree
8434 55350269 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
8435 : {
8436 55350269 : tree type;
8437 55350269 : tree init_code = NULL;
8438 55350269 : tree core_type;
8439 :
8440 : /* Things that are going to be initialized need to have complete
8441 : type. */
8442 55350269 : TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
8443 :
8444 55350269 : if (DECL_HAS_VALUE_EXPR_P (decl))
8445 : {
8446 : /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
8447 : it doesn't have storage to be initialized. */
8448 108 : gcc_assert (init == NULL_TREE);
8449 : return NULL_TREE;
8450 : }
8451 :
8452 55350161 : if (type == error_mark_node)
8453 : /* We will have already complained. */
8454 : return NULL_TREE;
8455 :
8456 55350161 : if (TREE_CODE (type) == ARRAY_TYPE)
8457 : {
8458 946936 : if (check_array_initializer (decl, type, init))
8459 : return NULL_TREE;
8460 : }
8461 54403225 : else if (!COMPLETE_TYPE_P (type))
8462 : {
8463 37 : error_at (DECL_SOURCE_LOCATION (decl),
8464 : "%q#D has incomplete type", decl);
8465 37 : TREE_TYPE (decl) = error_mark_node;
8466 37 : return NULL_TREE;
8467 : }
8468 : else
8469 : /* There is no way to make a variable-sized class type in GNU C++. */
8470 54403188 : gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
8471 :
8472 55350115 : if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
8473 : {
8474 2766853 : int init_len = CONSTRUCTOR_NELTS (init);
8475 2766853 : if (SCALAR_TYPE_P (type))
8476 : {
8477 64144 : if (init_len == 0)
8478 : {
8479 32417 : maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
8480 32417 : init = build_zero_init (type, NULL_TREE, false);
8481 : }
8482 31727 : else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
8483 : {
8484 12 : error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
8485 : "scalar object %qD requires one element in "
8486 : "initializer", decl);
8487 6 : TREE_TYPE (decl) = error_mark_node;
8488 6 : return NULL_TREE;
8489 : }
8490 : }
8491 : }
8492 :
8493 55350109 : if (TREE_CODE (decl) == CONST_DECL)
8494 : {
8495 0 : gcc_assert (!TYPE_REF_P (type));
8496 :
8497 0 : DECL_INITIAL (decl) = init;
8498 :
8499 0 : gcc_assert (init != NULL_TREE);
8500 : init = NULL_TREE;
8501 : }
8502 55350109 : else if (!init && DECL_REALLY_EXTERN (decl))
8503 : ;
8504 55350109 : else if (flag_openmp
8505 188095 : && VAR_P (decl)
8506 188095 : && DECL_LANG_SPECIFIC (decl)
8507 110458 : && DECL_OMP_DECLARE_MAPPER_P (decl)
8508 55350109 : && TREE_CODE (init) == OMP_DECLARE_MAPPER)
8509 : return NULL_TREE;
8510 4046752 : else if (init || type_build_ctor_call (type)
8511 58860383 : || TYPE_REF_P (type))
8512 : {
8513 51839850 : if (TYPE_REF_P (type))
8514 : {
8515 359810 : init = grok_reference_init (decl, type, init, flags);
8516 359810 : flags |= LOOKUP_ALREADY_DIGESTED;
8517 : }
8518 51480040 : else if (!init)
8519 536478 : check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
8520 : tf_warning_or_error);
8521 : /* Do not reshape constructors of vectors (they don't need to be
8522 : reshaped. */
8523 50943562 : else if (BRACE_ENCLOSED_INITIALIZER_P (init))
8524 : {
8525 2734090 : if (is_std_init_list (type))
8526 : {
8527 333 : init = perform_implicit_conversion (type, init,
8528 : tf_warning_or_error);
8529 333 : flags |= LOOKUP_ALREADY_DIGESTED;
8530 : }
8531 2733757 : else if (TYPE_NON_AGGREGATE_CLASS (type))
8532 : {
8533 : /* Don't reshape if the class has constructors. */
8534 432732 : if (cxx_dialect == cxx98)
8535 6 : error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
8536 : "in C++98 %qD must be initialized by "
8537 : "constructor, not by %<{...}%>",
8538 : decl);
8539 : }
8540 2301025 : else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
8541 : {
8542 0 : error ("opaque vector types cannot be initialized");
8543 0 : init = error_mark_node;
8544 : }
8545 : else
8546 : {
8547 2301025 : init = reshape_init (type, init, tf_warning_or_error);
8548 2301025 : flags |= LOOKUP_NO_NARROWING;
8549 : }
8550 : }
8551 : /* [dcl.init] "Otherwise, if the destination type is an array, the object
8552 : is initialized as follows..." So handle things like
8553 :
8554 : int a[](1, 2, 3);
8555 :
8556 : which is permitted in C++20 by P0960. */
8557 48209472 : else if (TREE_CODE (init) == TREE_LIST
8558 725872 : && TREE_TYPE (init) == NULL_TREE
8559 725872 : && TREE_CODE (type) == ARRAY_TYPE
8560 174 : && !DECL_DECOMPOSITION_P (decl)
8561 48209616 : && (cxx_dialect >= cxx20))
8562 134 : init = do_aggregate_paren_init (init, type);
8563 48209338 : else if (TREE_CODE (init) == TREE_LIST
8564 725738 : && TREE_TYPE (init) != unknown_type_node
8565 48935076 : && !MAYBE_CLASS_TYPE_P (type))
8566 : {
8567 127867 : gcc_assert (TREE_CODE (decl) != RESULT_DECL);
8568 :
8569 : /* We get here with code like `int a (2);' */
8570 127867 : init = build_x_compound_expr_from_list (init, ELK_INIT,
8571 : tf_warning_or_error);
8572 : }
8573 :
8574 : /* If DECL has an array type without a specific bound, deduce the
8575 : array size from the initializer. */
8576 51839850 : maybe_deduce_size_from_array_init (decl, init);
8577 51839850 : type = TREE_TYPE (decl);
8578 51839850 : if (type == error_mark_node)
8579 : return NULL_TREE;
8580 :
8581 100416517 : if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
8582 4929963 : && !(flags & LOOKUP_ALREADY_DIGESTED)
8583 4929630 : && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
8584 2495524 : && CP_AGGREGATE_TYPE_P (type)
8585 2062792 : && (CLASS_TYPE_P (type)
8586 : /* The call to build_aggr_init below could end up
8587 : calling build_vec_init, which may break when we
8588 : are processing a template. */
8589 1392 : || processing_template_decl
8590 1323 : || !TYPE_NEEDS_CONSTRUCTING (type)
8591 1291 : || type_has_extended_temps (type))))
8592 100811623 : || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
8593 : {
8594 2871281 : init_code = build_aggr_init_full_exprs (decl, init, flags);
8595 :
8596 : /* A constructor call is a non-trivial initializer even if
8597 : it isn't explicitly written. */
8598 2871281 : if (TREE_SIDE_EFFECTS (init_code))
8599 2849047 : DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
8600 :
8601 : /* If this is a constexpr initializer, expand_default_init will
8602 : have returned an INIT_EXPR rather than a CALL_EXPR. In that
8603 : case, pull the initializer back out and pass it down into
8604 : store_init_value. */
8605 7593693 : while (true)
8606 : {
8607 7593693 : if (TREE_CODE (init_code) == EXPR_STMT
8608 4749989 : || TREE_CODE (init_code) == STMT_EXPR
8609 4713577 : || TREE_CODE (init_code) == CONVERT_EXPR)
8610 4686088 : init_code = TREE_OPERAND (init_code, 0);
8611 2907605 : else if (TREE_CODE (init_code) == BIND_EXPR)
8612 36324 : init_code = BIND_EXPR_BODY (init_code);
8613 : else
8614 : break;
8615 : }
8616 2871281 : if (TREE_CODE (init_code) == INIT_EXPR)
8617 : {
8618 : /* In C++20, the call to build_aggr_init could have created
8619 : an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
8620 : A(1, 2). */
8621 1828068 : tree rhs = TREE_OPERAND (init_code, 1);
8622 1828068 : if (processing_template_decl && TREE_CODE (rhs) == TARGET_EXPR)
8623 : /* Avoid leaking TARGET_EXPR into template trees. */
8624 18196 : rhs = build_implicit_conv_flags (type, init, flags);
8625 1828068 : init = rhs;
8626 :
8627 1828068 : init_code = NULL_TREE;
8628 : /* Don't call digest_init; it's unnecessary and will complain
8629 : about aggregate initialization of non-aggregate classes. */
8630 1828044 : flags |= LOOKUP_ALREADY_DIGESTED;
8631 : }
8632 1043213 : else if (DECL_DECLARED_CONSTEXPR_P (decl)
8633 2067957 : || DECL_DECLARED_CONSTINIT_P (decl))
8634 : {
8635 : /* Declared constexpr or constinit, but no suitable initializer;
8636 : massage init appropriately so we can pass it into
8637 : store_init_value for the error. */
8638 18487 : tree new_init = NULL_TREE;
8639 18487 : if (!processing_template_decl
8640 294 : && TREE_CODE (init_code) == CALL_EXPR)
8641 235 : new_init = build_cplus_new (type, init_code, tf_none);
8642 18228 : else if (CLASS_TYPE_P (type)
8643 36480 : && (!init || TREE_CODE (init) == TREE_LIST))
8644 18127 : new_init = build_functional_cast (input_location, type,
8645 : init, tf_none);
8646 18362 : if (new_init)
8647 : {
8648 18362 : init = new_init;
8649 18362 : if (TREE_CODE (init) == TARGET_EXPR
8650 260 : && !(flags & LOOKUP_ONLYCONVERTING))
8651 260 : TARGET_EXPR_DIRECT_INIT_P (init) = true;
8652 : }
8653 : init_code = NULL_TREE;
8654 : }
8655 : else
8656 : init = NULL_TREE;
8657 : }
8658 :
8659 50815120 : if (init && TREE_CODE (init) != TREE_VEC)
8660 : {
8661 50815105 : init_code = store_init_value (decl, init, cleanups, flags);
8662 :
8663 50812408 : if (DECL_INITIAL (decl)
8664 36836347 : && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
8665 53734495 : && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
8666 : {
8667 1274214 : tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
8668 1274214 : if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
8669 1274214 : && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
8670 36 : cp_complete_array_type (&TREE_TYPE (elt), elt, false);
8671 : }
8672 :
8673 1756034 : if (pedantic && TREE_CODE (type) == ARRAY_TYPE
8674 56055 : && DECL_INITIAL (decl)
8675 55533 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8676 50864419 : && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
8677 6 : warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
8678 3 : DECL_SOURCE_LOCATION (decl)),
8679 3 : 0, "array %qD initialized by parenthesized "
8680 : "string literal %qE",
8681 3 : decl, DECL_INITIAL (decl));
8682 : init = NULL_TREE;
8683 : }
8684 : }
8685 3510259 : else if (!init && REFLECTION_TYPE_P (type))
8686 : {
8687 : /* [dcl.init.general]: To default-initialize an object of type
8688 : std::meta::info means that the object is zero-initialized. */
8689 76 : DECL_INITIAL (decl)
8690 76 : = build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
8691 76 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
8692 76 : TREE_CONSTANT (decl) = true;
8693 76 : init = NULL_TREE;
8694 : }
8695 : else
8696 : {
8697 7020366 : if (CLASS_TYPE_P (core_type = strip_array_types (type))
8698 4227705 : && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
8699 717509 : || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
8700 19 : diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
8701 : /*complain=*/true);
8702 :
8703 3510183 : check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
8704 : tf_warning_or_error);
8705 : }
8706 :
8707 76 : if (init && init != error_mark_node)
8708 0 : init_code = cp_build_init_expr (decl, init);
8709 :
8710 15137505 : if (init_code && !TREE_SIDE_EFFECTS (init_code)
8711 55402093 : && init_code != error_mark_node)
8712 : init_code = NULL_TREE;
8713 :
8714 55294981 : if (init_code)
8715 : {
8716 : /* We might have set these in cp_finish_decl. */
8717 15085078 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
8718 15085078 : TREE_CONSTANT (decl) = false;
8719 : }
8720 :
8721 15085078 : if (init_code
8722 15085078 : && DECL_IN_AGGR_P (decl)
8723 6 : && DECL_INITIALIZED_IN_CLASS_P (decl))
8724 : {
8725 0 : static int explained = 0;
8726 :
8727 0 : auto_diagnostic_group d;
8728 0 : if (cxx_dialect < cxx11)
8729 0 : error ("initializer invalid for static member with constructor");
8730 0 : else if (cxx_dialect < cxx17)
8731 0 : error ("non-constant in-class initialization invalid for static "
8732 : "member %qD", decl);
8733 : else
8734 0 : error ("non-constant in-class initialization invalid for non-inline "
8735 : "static member %qD", decl);
8736 0 : if (!explained)
8737 : {
8738 0 : inform (input_location,
8739 : "(an out of class initialization is required)");
8740 0 : explained = 1;
8741 : }
8742 0 : return NULL_TREE;
8743 0 : }
8744 :
8745 : return init_code;
8746 : }
8747 :
8748 : /* If DECL is not a local variable, give it RTL. */
8749 :
8750 : static void
8751 118761003 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
8752 : {
8753 118761003 : int toplev = toplevel_bindings_p ();
8754 118761003 : int defer_p;
8755 :
8756 : /* Set the DECL_ASSEMBLER_NAME for the object. */
8757 118761003 : if (asmspec)
8758 : {
8759 : /* The `register' keyword, when used together with an
8760 : asm-specification, indicates that the variable should be
8761 : placed in a particular register. */
8762 988830 : if (VAR_P (decl) && DECL_REGISTER (decl))
8763 : {
8764 87 : if (TREE_ADDRESSABLE (decl))
8765 3 : error_at (DECL_SOURCE_LOCATION (decl),
8766 : "address of explicit register variable %qD requested",
8767 : decl);
8768 : else
8769 : {
8770 84 : set_user_assembler_name (decl, asmspec);
8771 84 : DECL_HARD_REGISTER (decl) = 1;
8772 : }
8773 : }
8774 : else
8775 : {
8776 988743 : if (TREE_CODE (decl) == FUNCTION_DECL
8777 988743 : && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
8778 78120 : set_builtin_user_assembler_name (decl, asmspec);
8779 988743 : set_user_assembler_name (decl, asmspec);
8780 988743 : if (DECL_LOCAL_DECL_P (decl))
8781 6 : if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
8782 : /* We have to propagate the name to the ns-alias.
8783 : This is horrible, as we're affecting a
8784 : possibly-shared decl. Again, a one-true-decl
8785 : model breaks down. */
8786 6 : if (ns_decl != error_mark_node)
8787 6 : set_user_assembler_name (ns_decl, asmspec);
8788 : }
8789 : }
8790 :
8791 : /* Handle non-variables up front. */
8792 118761003 : if (!VAR_P (decl))
8793 : {
8794 56822048 : rest_of_decl_compilation (decl, toplev, at_eof);
8795 56822048 : return;
8796 : }
8797 :
8798 : /* If we see a class member here, it should be a static data
8799 : member. */
8800 61938955 : if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
8801 : {
8802 5428383 : gcc_assert (TREE_STATIC (decl));
8803 : /* An in-class declaration of a static data member should be
8804 : external; it is only a declaration, and not a definition. */
8805 5428383 : if (init == NULL_TREE)
8806 5428355 : gcc_assert (DECL_EXTERNAL (decl)
8807 : || !TREE_PUBLIC (decl));
8808 : }
8809 :
8810 : /* We don't create any RTL for local variables. */
8811 61938955 : if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
8812 : return;
8813 :
8814 : /* Don't output reflection variables. */
8815 38167252 : if (consteval_only_p (decl))
8816 : {
8817 : /* Disable assemble_variable. */
8818 757 : DECL_EXTERNAL (decl) = true;
8819 : /* Undo make_decl_one_only. */
8820 757 : if (DECL_COMDAT_GROUP (decl))
8821 : {
8822 131 : symtab_node *node = symtab_node::get (decl);
8823 131 : node->set_comdat_group (NULL);
8824 131 : node->dissolve_same_comdat_group_list ();
8825 : }
8826 757 : return;
8827 : }
8828 :
8829 : /* We defer emission of local statics until the corresponding
8830 : DECL_EXPR is expanded. But with constexpr its function might never
8831 : be expanded, so go ahead and tell cgraph about the variable now. */
8832 76332990 : defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
8833 136293 : && !var_in_maybe_constexpr_fn (decl))
8834 76197364 : || DECL_VIRTUAL_P (decl));
8835 :
8836 : /* Defer template instantiations. */
8837 38166495 : if (DECL_LANG_SPECIFIC (decl)
8838 38166495 : && DECL_IMPLICIT_INSTANTIATION (decl))
8839 : defer_p = 1;
8840 :
8841 : /* If we're not deferring, go ahead and assemble the variable. */
8842 19591154 : if (!defer_p)
8843 17245566 : rest_of_decl_compilation (decl, toplev, at_eof);
8844 : }
8845 :
8846 : /* walk_tree helper for wrap_temporary_cleanups, below. */
8847 :
8848 : static tree
8849 10609393 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
8850 : {
8851 : /* Stop at types or full-expression boundaries. */
8852 10609393 : if (TYPE_P (*stmt_p)
8853 10609181 : || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
8854 : {
8855 442 : *walk_subtrees = 0;
8856 442 : return NULL_TREE;
8857 : }
8858 :
8859 10608951 : if (TREE_CODE (*stmt_p) == TARGET_EXPR)
8860 : {
8861 221130 : tree guard = (tree)data;
8862 221130 : tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
8863 :
8864 110534 : if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
8865 328405 : && !expr_noexcept_p (tcleanup, tf_none))
8866 : {
8867 145 : tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
8868 : /* Tell honor_protect_cleanup_actions to handle this as a separate
8869 : cleanup. */
8870 145 : TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
8871 145 : TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
8872 : }
8873 : }
8874 :
8875 : return NULL_TREE;
8876 : }
8877 :
8878 : /* We're initializing a local variable which has a cleanup GUARD. If there
8879 : are any temporaries used in the initializer INIT of this variable, we
8880 : need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
8881 : variable will be cleaned up properly if one of them throws.
8882 :
8883 : Unfortunately, there's no way to express this properly in terms of
8884 : nesting, as the regions for the temporaries overlap the region for the
8885 : variable itself; if there are two temporaries, the variable needs to be
8886 : the first thing destroyed if either of the temporary destructors throws.
8887 : However, we only want to run the variable's cleanup if it actually got
8888 : constructed. So we need to guard the temporary cleanups with the
8889 : variable's cleanup if they are run on the normal path, but not if they
8890 : are run on the exceptional path. We implement this by telling
8891 : honor_protect_cleanup_actions to strip the variable cleanup from the
8892 : exceptional path.
8893 :
8894 : Another approach could be to make the variable cleanup region enclose
8895 : initialization, but depend on a flag to indicate that the variable is
8896 : initialized; that's effectively what we do for arrays. But the current
8897 : approach works fine for non-arrays, and has no code overhead in the usual
8898 : case where the temporary destructors are noexcept. */
8899 :
8900 : static void
8901 956109 : wrap_temporary_cleanups (tree init, tree guard)
8902 : {
8903 956109 : if (TREE_CODE (guard) == BIND_EXPR)
8904 : {
8905 : /* An array cleanup region already encloses any temporary cleanups,
8906 : don't wrap it around them again. */
8907 407 : gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
8908 : return;
8909 : }
8910 955702 : cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
8911 : }
8912 :
8913 : /* Generate code to initialize DECL (a local variable). */
8914 :
8915 : static void
8916 23771685 : initialize_local_var (tree decl, tree init, bool decomp)
8917 : {
8918 23771685 : tree type = TREE_TYPE (decl);
8919 23771685 : tree cleanup;
8920 23771685 : int already_used;
8921 :
8922 23771685 : gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
8923 23771685 : gcc_assert (!TREE_STATIC (decl));
8924 :
8925 23771685 : if (DECL_SIZE (decl) == NULL_TREE)
8926 : {
8927 : /* If we used it already as memory, it must stay in memory. */
8928 0 : DECL_INITIAL (decl) = NULL_TREE;
8929 0 : TREE_ADDRESSABLE (decl) = TREE_USED (decl);
8930 0 : return;
8931 : }
8932 :
8933 23771685 : if (type == error_mark_node)
8934 : return;
8935 :
8936 : /* Compute and store the initial value. */
8937 23771685 : already_used = TREE_USED (decl) || TREE_USED (type);
8938 23771685 : if (TREE_USED (type))
8939 32 : DECL_READ_P (decl) = 1;
8940 :
8941 : /* Generate a cleanup, if necessary. */
8942 23771685 : cleanup = (decomp ? NULL_TREE
8943 23739027 : : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
8944 :
8945 : /* Perform the initialization. */
8946 23771685 : if (init)
8947 : {
8948 15070777 : tree rinit = (TREE_CODE (init) == INIT_EXPR
8949 15070777 : ? TREE_OPERAND (init, 1) : NULL_TREE);
8950 13810178 : if (rinit && !TREE_SIDE_EFFECTS (rinit)
8951 21395150 : && TREE_OPERAND (init, 0) == decl)
8952 : {
8953 : /* Stick simple initializers in DECL_INITIAL so that
8954 : -Wno-init-self works (c++/34772). */
8955 7584972 : DECL_INITIAL (decl) = rinit;
8956 :
8957 7584972 : if (warn_init_self && TYPE_REF_P (type))
8958 : {
8959 2469 : STRIP_NOPS (rinit);
8960 2469 : if (rinit == decl)
8961 3 : warning_at (DECL_SOURCE_LOCATION (decl),
8962 3 : OPT_Winit_self,
8963 : "reference %qD is initialized with itself", decl);
8964 : }
8965 : }
8966 : else
8967 : {
8968 7485805 : int saved_stmts_are_full_exprs_p;
8969 :
8970 : /* If we're only initializing a single object, guard the
8971 : destructors of any temporaries used in its initializer with
8972 : its destructor. */
8973 7485805 : if (cleanup)
8974 953420 : wrap_temporary_cleanups (init, cleanup);
8975 :
8976 7485805 : gcc_assert (building_stmt_list_p ());
8977 7485805 : saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
8978 : /* Avoid CLEANUP_POINT_EXPR for the structured binding
8979 : bases, those will have CLEANUP_POINT_EXPR at the end of
8980 : code emitted by cp_finish_decomp. */
8981 7485805 : if (decomp)
8982 32205 : current_stmt_tree ()->stmts_are_full_exprs_p = 0;
8983 : else
8984 7453600 : current_stmt_tree ()->stmts_are_full_exprs_p = 1;
8985 7485805 : finish_expr_stmt (init);
8986 7485805 : current_stmt_tree ()->stmts_are_full_exprs_p
8987 7485805 : = saved_stmts_are_full_exprs_p;
8988 : }
8989 : }
8990 :
8991 : /* Set this to 0 so we can tell whether an aggregate which was
8992 : initialized was ever used. Don't do this if it has a
8993 : destructor, so we don't complain about the 'resource
8994 : allocation is initialization' idiom. Now set
8995 : attribute((unused)) on types so decls of that type will be
8996 : marked used. (see TREE_USED, above.) */
8997 23771685 : if (TYPE_NEEDS_CONSTRUCTING (type)
8998 2082950 : && ! already_used
8999 5586 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
9000 23775044 : && DECL_NAME (decl))
9001 3313 : TREE_USED (decl) = 0;
9002 23768372 : else if (already_used)
9003 20833494 : TREE_USED (decl) = 1;
9004 :
9005 23771685 : if (cleanup)
9006 966697 : finish_decl_cleanup (decl, cleanup);
9007 : }
9008 :
9009 : /* DECL is a VAR_DECL for a compiler-generated variable with static
9010 : storage duration (like a virtual table) whose initializer is a
9011 : compile-time constant. Initialize the variable and provide it to the
9012 : back end. */
9013 :
9014 : void
9015 2170390 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
9016 : {
9017 2170390 : tree init;
9018 2170390 : gcc_assert (DECL_ARTIFICIAL (decl));
9019 2170390 : init = build_constructor (TREE_TYPE (decl), v);
9020 2170390 : gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
9021 2170390 : DECL_INITIAL (decl) = init;
9022 2170390 : DECL_INITIALIZED_P (decl) = 1;
9023 : /* Mark the decl as constexpr so that we can access its content
9024 : at compile time. */
9025 2170390 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
9026 2170390 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
9027 2170390 : determine_visibility (decl);
9028 2170390 : layout_var_decl (decl);
9029 2170390 : maybe_commonize_var (decl);
9030 2170390 : make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
9031 2170390 : }
9032 :
9033 : /* INIT is the initializer for a variable, as represented by the
9034 : parser. Returns true iff INIT is value-dependent. */
9035 :
9036 : static bool
9037 9437214 : value_dependent_init_p (tree init)
9038 : {
9039 9437214 : if (TREE_CODE (init) == TREE_LIST)
9040 : /* A parenthesized initializer, e.g.: int i (3, 2); ? */
9041 20143 : return any_value_dependent_elements_p (init);
9042 9417071 : else if (TREE_CODE (init) == CONSTRUCTOR)
9043 : /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
9044 : {
9045 69561 : if (dependent_type_p (TREE_TYPE (init)))
9046 : return true;
9047 :
9048 69555 : vec<constructor_elt, va_gc> *elts;
9049 69555 : size_t nelts;
9050 69555 : size_t i;
9051 :
9052 69555 : elts = CONSTRUCTOR_ELTS (init);
9053 69555 : nelts = vec_safe_length (elts);
9054 603637 : for (i = 0; i < nelts; ++i)
9055 561999 : if (value_dependent_init_p ((*elts)[i].value))
9056 : return true;
9057 : }
9058 : else
9059 : /* It must be a simple expression, e.g., int i = 3; */
9060 9347510 : return value_dependent_expression_p (init);
9061 :
9062 : return false;
9063 : }
9064 :
9065 : /* A helper function to be called via walk_tree. If any label exists
9066 : under *TP, it is (going to be) forced. Set has_forced_label_in_static. */
9067 :
9068 : static tree
9069 337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
9070 : {
9071 337 : if (TYPE_P (*tp))
9072 0 : *walk_subtrees = 0;
9073 337 : if (TREE_CODE (*tp) == LABEL_DECL)
9074 6 : cfun->has_forced_label_in_static = 1;
9075 337 : return NULL_TREE;
9076 : }
9077 :
9078 : /* Return true if DECL has either a trivial destructor, or for C++20
9079 : is constexpr and has a constexpr destructor. */
9080 :
9081 : static bool
9082 60273808 : decl_maybe_constant_destruction (tree decl, tree type)
9083 : {
9084 60273808 : return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
9085 60273808 : || (cxx_dialect >= cxx20
9086 3984696 : && VAR_P (decl)
9087 3984385 : && DECL_DECLARED_CONSTEXPR_P (decl)
9088 370 : && type_has_constexpr_destructor (strip_array_types (type))));
9089 : }
9090 :
9091 : static tree declare_simd_adjust_this (tree *, int *, void *);
9092 :
9093 : /* Helper function of omp_declare_variant_finalize. Finalize one
9094 : "omp declare variant base" attribute. Return true if it should be
9095 : removed. */
9096 :
9097 : static bool
9098 1751 : omp_declare_variant_finalize_one (tree decl, tree attr)
9099 : {
9100 1751 : if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
9101 : {
9102 164 : walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
9103 : DECL_ARGUMENTS (decl), NULL);
9104 164 : walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
9105 : DECL_ARGUMENTS (decl), NULL);
9106 : }
9107 :
9108 1751 : tree ctx = TREE_VALUE (TREE_VALUE (attr));
9109 1751 : tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
9110 : OMP_TRAIT_CONSTRUCT_SIMD);
9111 1751 : if (simd)
9112 : {
9113 51 : TREE_VALUE (simd)
9114 51 : = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
9115 51 : OMP_TS_PROPERTIES (simd));
9116 : /* FIXME, adjusting simd args unimplemented. */
9117 51 : return true;
9118 : }
9119 :
9120 1700 : tree chain = TREE_CHAIN (TREE_VALUE (attr));
9121 1700 : location_t varid_loc
9122 1700 : = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
9123 1700 : location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
9124 1700 : cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
9125 1700 : tree variant = TREE_PURPOSE (TREE_VALUE (attr));
9126 :
9127 1700 : location_t save_loc = input_location;
9128 1700 : input_location = varid_loc;
9129 :
9130 1700 : releasing_vec args;
9131 1700 : tree parm = DECL_ARGUMENTS (decl);
9132 1700 : if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
9133 164 : parm = DECL_CHAIN (parm);
9134 3022 : for (; parm; parm = DECL_CHAIN (parm))
9135 1322 : vec_safe_push (args, forward_parm (parm));
9136 :
9137 1700 : unsigned nappend_args = 0;
9138 1700 : tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
9139 1700 : if (append_args_list)
9140 : {
9141 354 : append_args_list = TREE_VALUE (append_args_list);
9142 354 : append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
9143 591 : ? TREE_VALUE (TREE_CHAIN (append_args_list))
9144 : : NULL_TREE);
9145 741 : for (tree t = append_args_list; t; t = TREE_CHAIN (t))
9146 387 : nappend_args++;
9147 354 : if (nappend_args)
9148 : {
9149 237 : tree type;
9150 237 : if ((type = lookup_qualified_name (global_namespace,
9151 : "omp_interop_t",
9152 : LOOK_want::NORMAL,
9153 : /*complain*/false)) == NULL_TREE
9154 237 : || !c_omp_interop_t_p (TREE_TYPE (type)))
9155 : {
9156 24 : location_t loc = input_location;
9157 24 : variant = tree_strip_any_location_wrapper (variant);
9158 24 : if (!identifier_p (variant))
9159 : {
9160 21 : if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
9161 21 : variant = OVL_FIRST (variant);
9162 21 : loc = EXPR_LOC_OR_LOC (variant,
9163 : DECL_SOURCE_LOCATION (variant));
9164 : }
9165 24 : error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
9166 24 : args->length () + 1, variant);
9167 24 : inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
9168 : "%<append_args%> specified here");
9169 24 : return true;
9170 : }
9171 564 : for (unsigned i = 0; i < nappend_args; i++)
9172 351 : vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
9173 : }
9174 : }
9175 :
9176 1676 : bool koenig_p = false;
9177 1676 : if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
9178 : {
9179 1606 : if (identifier_p (variant)
9180 : /* In C++20, we may need to perform ADL for a template
9181 : name. */
9182 1582 : || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
9183 18 : && identifier_p (TREE_OPERAND (variant, 0))))
9184 : {
9185 24 : if (!args->is_empty ())
9186 : {
9187 24 : koenig_p = true;
9188 24 : if (!any_type_dependent_arguments_p (args))
9189 21 : variant = perform_koenig_lookup (variant, args,
9190 : tf_warning_or_error);
9191 : }
9192 : else
9193 0 : variant = unqualified_fn_lookup_error (variant);
9194 : }
9195 1582 : else if (!args->is_empty () && is_overloaded_fn (variant))
9196 : {
9197 830 : tree fn = get_first_fn (variant);
9198 830 : fn = STRIP_TEMPLATE (fn);
9199 830 : if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
9200 830 : || DECL_FUNCTION_MEMBER_P (fn)
9201 717 : || DECL_LOCAL_DECL_P (fn)))
9202 : {
9203 717 : koenig_p = true;
9204 717 : if (!any_type_dependent_arguments_p (args))
9205 666 : variant = perform_koenig_lookup (variant, args,
9206 : tf_warning_or_error);
9207 : }
9208 : }
9209 : }
9210 :
9211 1676 : if (idk == CP_ID_KIND_QUALIFIED)
9212 6 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
9213 : koenig_p, tf_warning_or_error);
9214 1670 : else if (idk == CP_ID_KIND_NONE
9215 64 : && TREE_CODE (variant) == FUNCTION_DECL
9216 64 : && DECL_IOBJ_MEMBER_FUNCTION_P (variant)
9217 1718 : && CLASS_TYPE_P (DECL_CONTEXT (decl)))
9218 : {
9219 48 : tree saved_ccp = current_class_ptr;
9220 48 : tree saved_ccr = current_class_ref;
9221 48 : current_class_ptr = NULL_TREE;
9222 48 : current_class_ref = NULL_TREE;
9223 48 : inject_this_parameter (DECL_CONTEXT (decl), TYPE_UNQUALIFIED);
9224 48 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
9225 : koenig_p, tf_warning_or_error);
9226 48 : current_class_ptr = saved_ccp;
9227 48 : current_class_ref = saved_ccr;
9228 : }
9229 : else
9230 1622 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
9231 : koenig_p, tf_warning_or_error);
9232 1676 : if (variant == error_mark_node && !processing_template_decl)
9233 : return true;
9234 :
9235 1610 : if (TREE_CODE (variant) == TARGET_EXPR)
9236 9 : variant = TARGET_EXPR_INITIAL (variant);
9237 :
9238 3211 : variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
9239 1610 : input_location = save_loc;
9240 :
9241 1610 : if (variant == decl)
9242 : {
9243 0 : error_at (varid_loc, "variant %qD is the same as base function",
9244 : variant);
9245 0 : return true;
9246 : }
9247 :
9248 1610 : if (variant)
9249 : {
9250 1526 : bool fail;
9251 1526 : const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
9252 1526 : if (!nappend_args)
9253 1367 : fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
9254 : COMPARE_STRICT);
9255 : else
9256 : {
9257 159 : unsigned nbase_args = 0;
9258 159 : for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
9259 756 : t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
9260 240 : nbase_args++;
9261 159 : tree vargs, varg;
9262 159 : vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
9263 399 : for (unsigned i = 0; i < nbase_args && varg;
9264 240 : i++, varg = TREE_CHAIN (varg))
9265 240 : vargs = varg;
9266 417 : for (unsigned i = 0; i < nappend_args && varg; i++)
9267 258 : varg = TREE_CHAIN (varg);
9268 159 : tree saved_vargs;
9269 159 : int saved_no_named_args_stdarg = 0;
9270 159 : if (nbase_args)
9271 : {
9272 111 : saved_vargs = TREE_CHAIN (vargs);
9273 111 : TREE_CHAIN (vargs) = varg;
9274 : }
9275 : else
9276 : {
9277 48 : saved_vargs = vargs;
9278 48 : TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
9279 48 : saved_no_named_args_stdarg
9280 48 : = TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant));
9281 48 : if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl))
9282 48 : && varg == NULL_TREE)
9283 2 : TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1;
9284 : }
9285 : /* Skip assert check that TYPE_CANONICAL is the same. */
9286 159 : fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
9287 : COMPARE_STRUCTURAL);
9288 159 : if (nbase_args)
9289 111 : TREE_CHAIN (vargs) = saved_vargs;
9290 : else
9291 : {
9292 48 : TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
9293 48 : TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant))
9294 96 : = saved_no_named_args_stdarg;
9295 : }
9296 159 : varg = saved_vargs;
9297 159 : if (!fail && !processing_template_decl)
9298 402 : for (unsigned i = 0; i < nappend_args;
9299 246 : i++, varg = TREE_CHAIN (varg))
9300 507 : if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
9301 : {
9302 9 : error_at (DECL_SOURCE_LOCATION (variant),
9303 : "argument %d of %qD must be of %<omp_interop_t%>",
9304 9 : nbase_args + i + 1, variant);
9305 9 : inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
9306 : "%<append_args%> specified here");
9307 9 : break;
9308 : }
9309 : }
9310 1526 : if (fail)
9311 : {
9312 69 : error_at (varid_loc, "variant %qD and base %qD have incompatible "
9313 : "types", variant, decl);
9314 69 : return true;
9315 : }
9316 1457 : if (fndecl_built_in_p (variant)
9317 1457 : && (startswith (varname, "__builtin_")
9318 0 : || startswith (varname, "__sync_")
9319 0 : || startswith (varname, "__atomic_")))
9320 : {
9321 6 : error_at (varid_loc, "variant %qD is a built-in", variant);
9322 6 : return true;
9323 : }
9324 : else
9325 : {
9326 1451 : tree construct
9327 1451 : = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
9328 1451 : omp_mark_declare_variant (match_loc, variant, construct);
9329 1451 : if (!omp_context_selector_matches (ctx, NULL_TREE, false))
9330 : return true;
9331 1039 : TREE_PURPOSE (TREE_VALUE (attr)) = variant;
9332 :
9333 : // Prepend adjust_args list to variant attributes
9334 1039 : tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
9335 1039 : if (adjust_args_list != NULL_TREE)
9336 : {
9337 507 : if (DECL_NONSTATIC_MEMBER_P (variant)
9338 285 : && TREE_VALUE (adjust_args_list))
9339 : {
9340 : /* Shift arg position for the added 'this' pointer. */
9341 : /* Handle need_device_ptr */
9342 21 : for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
9343 51 : t; t = TREE_CHAIN (t))
9344 30 : TREE_VALUE (t)
9345 30 : = build_int_cst (TREE_TYPE (t),
9346 30 : tree_to_uhwi (TREE_VALUE (t)) + 1);
9347 : }
9348 264 : if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
9349 : {
9350 : /* Shift likewise the number of args after which the
9351 : interop object should be added. */
9352 6 : tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
9353 6 : TREE_PURPOSE (nargs)
9354 6 : = build_int_cst (TREE_TYPE (nargs),
9355 6 : tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
9356 : }
9357 528 : for (tree t = append_args_list; t; t = TREE_CHAIN (t))
9358 264 : TREE_VALUE (t)
9359 264 : = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
9360 528 : DECL_ATTRIBUTES (variant) = tree_cons (
9361 : get_identifier ("omp declare variant variant args"),
9362 528 : TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
9363 : }
9364 : }
9365 : }
9366 84 : else if (!processing_template_decl)
9367 : {
9368 0 : error_at (varid_loc, "could not find variant declaration");
9369 0 : return true;
9370 : }
9371 :
9372 : return false;
9373 1700 : }
9374 :
9375 : /* Helper function, finish up "omp declare variant base" attribute
9376 : now that there is a DECL. ATTR is the first "omp declare variant base"
9377 : attribute. */
9378 :
9379 : void
9380 1546 : omp_declare_variant_finalize (tree decl, tree attr)
9381 : {
9382 1546 : size_t attr_len = strlen ("omp declare variant base");
9383 1546 : tree *list = &DECL_ATTRIBUTES (decl);
9384 1546 : bool remove_all = false;
9385 1546 : location_t match_loc = DECL_SOURCE_LOCATION (decl);
9386 1546 : if (TREE_CHAIN (TREE_VALUE (attr))
9387 1546 : && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
9388 3092 : && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
9389 1546 : match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
9390 3092 : if (DECL_CONSTRUCTOR_P (decl))
9391 : {
9392 27 : error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
9393 27 : remove_all = true;
9394 : }
9395 1519 : else if (DECL_DESTRUCTOR_P (decl))
9396 : {
9397 9 : error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
9398 9 : remove_all = true;
9399 : }
9400 1510 : else if (DECL_DEFAULTED_FN (decl))
9401 : {
9402 2 : error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
9403 2 : remove_all = true;
9404 : }
9405 1508 : else if (DECL_DELETED_FN (decl))
9406 : {
9407 2 : error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
9408 2 : remove_all = true;
9409 : }
9410 1506 : else if (DECL_VIRTUAL_P (decl))
9411 : {
9412 0 : error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
9413 0 : remove_all = true;
9414 : }
9415 : /* This loop is like private_lookup_attribute, except that it works
9416 : with tree * rather than tree, as we might want to remove the
9417 : attributes that are diagnosed as errorneous. */
9418 3349 : while (*list)
9419 : {
9420 1803 : tree attr = get_attribute_name (*list);
9421 1803 : size_t ident_len = IDENTIFIER_LENGTH (attr);
9422 4729 : if (cmp_attribs ("omp declare variant base", attr_len,
9423 1803 : IDENTIFIER_POINTER (attr), ident_len))
9424 : {
9425 1791 : if (remove_all || omp_declare_variant_finalize_one (decl, *list))
9426 : {
9427 668 : *list = TREE_CHAIN (*list);
9428 668 : continue;
9429 : }
9430 : }
9431 1135 : list = &TREE_CHAIN (*list);
9432 : }
9433 1546 : }
9434 :
9435 : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
9436 :
9437 : /* Finish processing of a declaration;
9438 : install its line number and initial value.
9439 : If the length of an array type is not known before,
9440 : it must be determined now, from the initial value, or it is an error.
9441 :
9442 : INIT is the initializer (if any) for DECL. If INIT_CONST_EXPR_P is
9443 : true, then INIT is an integral constant expression.
9444 :
9445 : FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
9446 : if the (init) syntax was used.
9447 :
9448 : DECOMP is first identifier's DECL and identifier count in a structured
9449 : bindings, nullptr if not a structured binding. */
9450 :
9451 : void
9452 320655845 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
9453 : tree asmspec_tree, int flags, cp_decomp *decomp)
9454 : {
9455 320655845 : vec<tree, va_gc> *cleanups = NULL;
9456 320655845 : const char *asmspec = NULL;
9457 320655845 : int was_readonly = 0;
9458 320655845 : bool var_definition_p = false;
9459 320655845 : tree auto_node;
9460 320655845 : auto_vec<tree> extra_cleanups;
9461 320655845 : tree aggregates1 = NULL_TREE;
9462 320655845 : struct decomp_cleanup {
9463 : tree decl;
9464 : cp_decomp *&decomp;
9465 320653148 : ~decomp_cleanup ()
9466 : {
9467 320653148 : if (decomp && DECL_DECOMPOSITION_P (decl))
9468 215052 : cp_finish_decomp (decl, decomp);
9469 320653148 : }
9470 320655845 : } decomp_cl = { decl, decomp };
9471 :
9472 320655845 : if (decl == error_mark_node)
9473 : return;
9474 320655805 : else if (! decl)
9475 : {
9476 0 : if (init)
9477 0 : error ("assignment (not initialization) in declaration");
9478 0 : return;
9479 : }
9480 :
9481 320655805 : gcc_assert (TREE_CODE (decl) != RESULT_DECL);
9482 : /* Parameters are handled by store_parm_decls, not cp_finish_decl. */
9483 320655805 : gcc_assert (TREE_CODE (decl) != PARM_DECL);
9484 :
9485 320655805 : tree type = TREE_TYPE (decl);
9486 320655805 : if (type == error_mark_node)
9487 : return;
9488 :
9489 320655206 : if (VAR_P (decl) && is_copy_initialization (init))
9490 95152735 : flags |= LOOKUP_ONLYCONVERTING;
9491 :
9492 : /* Warn about register storage specifiers except when in GNU global
9493 : or local register variable extension. */
9494 320655206 : if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
9495 : {
9496 1931 : if (cxx_dialect >= cxx17)
9497 1282 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
9498 : "ISO C++17 does not allow %<register%> storage "
9499 : "class specifier");
9500 : else
9501 649 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
9502 : "%<register%> storage class specifier used");
9503 : }
9504 :
9505 : /* If a name was specified, get the string. */
9506 320655206 : if (at_namespace_scope_p ())
9507 69292811 : asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
9508 320655206 : if (asmspec_tree && asmspec_tree != error_mark_node)
9509 988839 : asmspec = TREE_STRING_POINTER (asmspec_tree);
9510 :
9511 320655206 : bool in_class_decl
9512 320655206 : = (current_class_type
9513 201509803 : && CP_DECL_CONTEXT (decl) == current_class_type
9514 134188069 : && TYPE_BEING_DEFINED (current_class_type)
9515 452803107 : && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
9516 :
9517 127140824 : if (in_class_decl
9518 127140824 : && (DECL_INITIAL (decl) || init))
9519 93246619 : DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
9520 :
9521 320655206 : if (VAR_P (decl)
9522 320655206 : && (auto_node = type_uses_auto (type)))
9523 : {
9524 13238529 : tree d_init;
9525 13238529 : if (init == NULL_TREE)
9526 : {
9527 2796 : if (DECL_LANG_SPECIFIC (decl)
9528 2713 : && DECL_TEMPLATE_INSTANTIATION (decl)
9529 5506 : && !DECL_TEMPLATE_INSTANTIATED (decl))
9530 : {
9531 : /* init is null because we're deferring instantiating the
9532 : initializer until we need it. Well, we need it now. */
9533 2704 : instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
9534 2704 : return;
9535 : }
9536 :
9537 92 : if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
9538 : /* Class deduction with no initializer is OK. */;
9539 : else
9540 : {
9541 : /* Ordinary auto deduction without an initializer, a situation
9542 : which grokdeclarator already detects and rejects for the most
9543 : part. But we can still get here if we're instantiating a
9544 : variable template before we've fully parsed (and attached) its
9545 : initializer, e.g. template<class> auto x = x<int>; */
9546 3 : error_at (DECL_SOURCE_LOCATION (decl),
9547 : "declaration of %q#D has no initializer", decl);
9548 3 : TREE_TYPE (decl) = error_mark_node;
9549 3 : return;
9550 : }
9551 : }
9552 13235822 : d_init = init;
9553 13235822 : if (d_init)
9554 : {
9555 13235733 : if (TREE_CODE (d_init) == TREE_LIST
9556 13287074 : && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
9557 27898 : d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
9558 : tf_warning_or_error);
9559 13235733 : d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
9560 : /* Force auto deduction now. Use tf_none to avoid redundant warnings
9561 : on deprecated-14.C. */
9562 13235733 : mark_single_function (d_init, tf_none);
9563 : }
9564 13235822 : enum auto_deduction_context adc = adc_variable_type;
9565 13235822 : if (DECL_DECOMPOSITION_P (decl))
9566 : adc = adc_decomp_type;
9567 13235822 : tree outer_targs = NULL_TREE;
9568 13235822 : if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
9569 303 : && DECL_LANG_SPECIFIC (decl)
9570 126 : && DECL_TEMPLATE_INFO (decl)
9571 13235879 : && !DECL_FUNCTION_SCOPE_P (decl))
9572 : /* The outer template arguments might be needed for satisfaction.
9573 : (For function scope variables, do_auto_deduction will obtain the
9574 : outer template arguments from current_function_decl.) */
9575 57 : outer_targs = DECL_TI_ARGS (decl);
9576 13235822 : type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
9577 : tf_warning_or_error, adc,
9578 : outer_targs, flags);
9579 13235822 : if (type == error_mark_node)
9580 : return;
9581 13234835 : if (TREE_CODE (type) == FUNCTION_TYPE)
9582 : {
9583 3 : error ("initializer for %<decltype(auto) %D%> has function type; "
9584 : "did you forget the %<()%>?", decl);
9585 3 : TREE_TYPE (decl) = error_mark_node;
9586 3 : return;
9587 : }
9588 : /* As in start_decl_1, complete so TREE_READONLY is set properly. */
9589 13234832 : if (!processing_template_decl
9590 3027724 : && !type_uses_auto (type)
9591 16262549 : && !COMPLETE_TYPE_P (complete_type (type)))
9592 : {
9593 18 : auto_diagnostic_group d;
9594 18 : error_at (location_of (decl),
9595 : "deduced type %qT for %qD is incomplete", type, decl);
9596 18 : cxx_incomplete_type_inform (type);
9597 18 : TREE_TYPE (decl) = error_mark_node;
9598 18 : return;
9599 18 : }
9600 :
9601 : /* Now that we have a type, try these again. */
9602 13234814 : layout_decl (decl, 0);
9603 13234814 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
9604 :
9605 : /* Update the type of the corresponding TEMPLATE_DECL to match. */
9606 13234814 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
9607 : {
9608 34904 : tree tmpl = template_for_substitution (decl);
9609 34904 : if (DECL_TEMPLATE_RESULT (tmpl) == decl)
9610 31170 : TREE_TYPE (tmpl) = type;
9611 : }
9612 : }
9613 :
9614 320651491 : if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
9615 : {
9616 65 : DECL_DECLARED_CONSTEXPR_P (decl) = 0;
9617 65 : if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
9618 : {
9619 6 : init = NULL_TREE;
9620 6 : DECL_EXTERNAL (decl) = 1;
9621 : }
9622 : }
9623 :
9624 320651491 : if (VAR_P (decl)
9625 120546975 : && DECL_CLASS_SCOPE_P (decl)
9626 19599084 : && verify_type_context (DECL_SOURCE_LOCATION (decl),
9627 : TCTX_STATIC_STORAGE, type)
9628 340250575 : && DECL_INITIALIZED_IN_CLASS_P (decl))
9629 18263002 : check_static_variable_definition (decl, type);
9630 :
9631 320651491 : if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
9632 : {
9633 35999414 : type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
9634 35999414 : ? TCTX_THREAD_STORAGE
9635 : : TCTX_STATIC_STORAGE);
9636 35999414 : verify_type_context (input_location, context, TREE_TYPE (decl));
9637 : }
9638 :
9639 320651491 : if (init && TREE_CODE (decl) == FUNCTION_DECL)
9640 : {
9641 563766 : tree clone;
9642 563766 : if (init == ridpointers[(int)RID_DELETE]
9643 563766 : || (TREE_CODE (init) == STRING_CST
9644 30 : && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
9645 : {
9646 : /* FIXME check this is 1st decl. */
9647 541390 : if (UNLIKELY (DECL_MAIN_P (decl)))
9648 : {
9649 : /* [basic.start.main]/3: A program that defines main as deleted
9650 : is ill-formed. */
9651 6 : error ("%<::main%> cannot be deleted");
9652 6 : DECL_INITIAL (decl) = error_mark_node;
9653 : }
9654 : else
9655 : {
9656 541384 : DECL_DELETED_FN (decl) = 1;
9657 541384 : DECL_DECLARED_INLINE_P (decl) = 1;
9658 541384 : DECL_INITIAL (decl)
9659 541384 : = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
9660 541402 : FOR_EACH_CLONE (clone, decl)
9661 : {
9662 18 : DECL_DELETED_FN (clone) = 1;
9663 18 : DECL_DECLARED_INLINE_P (clone) = 1;
9664 18 : DECL_INITIAL (clone) = DECL_INITIAL (decl);
9665 : }
9666 : }
9667 541390 : init = NULL_TREE;
9668 : }
9669 22376 : else if (init == ridpointers[(int)RID_DEFAULT])
9670 : {
9671 22364 : if (defaultable_fn_check (decl))
9672 22340 : DECL_DEFAULTED_FN (decl) = 1;
9673 : else
9674 24 : DECL_INITIAL (decl) = NULL_TREE;
9675 : }
9676 : }
9677 :
9678 320651491 : if (init && VAR_P (decl))
9679 : {
9680 104668947 : DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
9681 : /* If DECL is a reference, then we want to know whether init is a
9682 : reference constant; init_const_expr_p as passed tells us whether
9683 : it's an rvalue constant. */
9684 104668947 : if (TYPE_REF_P (type))
9685 2267845 : init_const_expr_p = potential_constant_expression (init);
9686 104668947 : if (init_const_expr_p)
9687 : {
9688 : /* Set these flags now for templates. We'll update the flags in
9689 : store_init_value for instantiations. */
9690 92092488 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
9691 92092488 : if (decl_maybe_constant_var_p (decl)
9692 : /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
9693 92092488 : && !TYPE_REF_P (type))
9694 40330838 : TREE_CONSTANT (decl) = true;
9695 : }
9696 : /* This is handled mostly by gimplify.cc, but we have to deal with
9697 : not warning about int x = x; as it is a GCC extension to turn off
9698 : this warning but only if warn_init_self is zero. */
9699 104668947 : if (!DECL_EXTERNAL (decl)
9700 103066410 : && !TREE_STATIC (decl)
9701 69879316 : && decl == tree_strip_any_location_wrapper (init)
9702 104672767 : && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
9703 3796 : suppress_warning (decl, OPT_Winit_self);
9704 : }
9705 215982544 : else if (VAR_P (decl)
9706 15878028 : && COMPLETE_TYPE_P (type)
9707 12416907 : && !TYPE_REF_P (type)
9708 12416542 : && !dependent_type_p (type)
9709 228101849 : && is_really_empty_class (type, /*ignore_vptr*/false))
9710 : /* We have no initializer but there's nothing to initialize anyway.
9711 : Treat DECL as constant due to c++/109876. */
9712 573827 : TREE_CONSTANT (decl) = true;
9713 :
9714 320651491 : if (flag_openmp
9715 841839 : && TREE_CODE (decl) == FUNCTION_DECL
9716 : /* #pragma omp declare variant on methods handled in finish_struct
9717 : instead. */
9718 321014295 : && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
9719 139342 : || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
9720 223925 : if (tree attr = lookup_attribute ("omp declare variant base",
9721 223925 : DECL_ATTRIBUTES (decl)))
9722 970 : omp_declare_variant_finalize (decl, attr);
9723 :
9724 320651491 : if (processing_template_decl)
9725 : {
9726 184190989 : bool type_dependent_p;
9727 :
9728 : /* Add this declaration to the statement-tree. */
9729 184190989 : if (at_function_scope_p ())
9730 66490296 : add_decl_expr (decl);
9731 :
9732 184190989 : type_dependent_p = dependent_type_p (type);
9733 :
9734 184190989 : if (check_for_bare_parameter_packs (init))
9735 : {
9736 3 : init = NULL_TREE;
9737 3 : DECL_INITIAL (decl) = NULL_TREE;
9738 : }
9739 :
9740 : /* Generally, initializers in templates are expanded when the
9741 : template is instantiated. But, if DECL is a variable constant
9742 : then it can be used in future constant expressions, so its value
9743 : must be available. */
9744 :
9745 184190989 : bool dep_init = false;
9746 :
9747 184190989 : if (!VAR_P (decl) || type_dependent_p)
9748 : /* We can't do anything if the decl has dependent type. */;
9749 23019043 : else if (init
9750 21344492 : && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
9751 17368635 : && !TYPE_REF_P (type)
9752 17336561 : && decl_maybe_constant_var_p (decl)
9753 31894258 : && !(dep_init = value_dependent_init_p (init)))
9754 : {
9755 : /* This variable seems to be a non-dependent constant, so process
9756 : its initializer. If check_initializer returns non-null the
9757 : initialization wasn't constant after all. */
9758 2290664 : tree init_code;
9759 2290664 : cleanups = make_tree_vector ();
9760 2290664 : init_code = check_initializer (decl, init, flags, &cleanups);
9761 2290664 : if (init_code == NULL_TREE)
9762 2290664 : init = NULL_TREE;
9763 2290664 : release_tree_vector (cleanups);
9764 : }
9765 : else
9766 : {
9767 20728379 : gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
9768 : /* Try to deduce array size. */
9769 20728379 : maybe_deduce_size_from_array_init (decl, init);
9770 : /* And complain about multiple initializers. */
9771 19053828 : if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
9772 20828771 : && !MAYBE_CLASS_TYPE_P (type))
9773 7 : init = build_x_compound_expr_from_list (init, ELK_INIT,
9774 : tf_warning_or_error);
9775 : }
9776 :
9777 184190989 : if (init)
9778 55041040 : DECL_INITIAL (decl) = init;
9779 :
9780 184190989 : if (dep_init)
9781 : {
9782 6584551 : retrofit_lang_decl (decl);
9783 6584551 : SET_DECL_DEPENDENT_INIT_P (decl, true);
9784 : }
9785 :
9786 184190989 : if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
9787 : {
9788 9 : if (TREE_ADDRESSABLE (decl))
9789 3 : error_at (DECL_SOURCE_LOCATION (decl),
9790 : "address of explicit register variable %qD requested",
9791 : decl);
9792 : else
9793 : {
9794 6 : set_user_assembler_name (decl, asmspec);
9795 6 : DECL_HARD_REGISTER (decl) = 1;
9796 : }
9797 : }
9798 184190989 : return;
9799 : }
9800 :
9801 : /* Just store non-static data member initializers for later. */
9802 136460502 : if (init && TREE_CODE (decl) == FIELD_DECL)
9803 586367 : DECL_INITIAL (decl) = init;
9804 :
9805 : /* Take care of TYPE_DECLs up front. */
9806 136460502 : if (TREE_CODE (decl) == TYPE_DECL)
9807 : {
9808 10708373 : if (type != error_mark_node
9809 10708373 : && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
9810 : {
9811 5185482 : if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
9812 0 : warning (0, "shadowing previous type declaration of %q#D", decl);
9813 5185482 : set_identifier_type_value (DECL_NAME (decl), decl);
9814 : }
9815 :
9816 : /* If we have installed this as the canonical typedef for this
9817 : type, and that type has not been defined yet, delay emitting
9818 : the debug information for it, as we will emit it later. */
9819 10708373 : if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
9820 10708373 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
9821 575218 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
9822 :
9823 10708373 : rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
9824 : at_eof);
9825 10708373 : return;
9826 : }
9827 :
9828 : /* A reference will be modified here, as it is initialized. */
9829 125752129 : if (! DECL_EXTERNAL (decl)
9830 61206030 : && TREE_READONLY (decl)
9831 162321249 : && TYPE_REF_P (type))
9832 : {
9833 237746 : was_readonly = 1;
9834 237746 : TREE_READONLY (decl) = 0;
9835 : }
9836 :
9837 : /* This needs to happen before extend_ref_init_temps. */
9838 125752129 : if (VAR_OR_FUNCTION_DECL_P (decl))
9839 : {
9840 116593334 : if (VAR_P (decl))
9841 59771286 : maybe_commonize_var (decl);
9842 116593334 : determine_visibility (decl);
9843 : }
9844 :
9845 125752129 : if (VAR_P (decl))
9846 : {
9847 59771286 : duration_kind dk = decl_storage_duration (decl);
9848 : /* [dcl.constinit]/1 "The constinit specifier shall be applied
9849 : only to a declaration of a variable with static or thread storage
9850 : duration." */
9851 59771286 : if (DECL_DECLARED_CONSTINIT_P (decl)
9852 59771286 : && !(dk == dk_thread || dk == dk_static))
9853 : {
9854 24 : error_at (DECL_SOURCE_LOCATION (decl),
9855 : "%<constinit%> can only be applied to a variable with "
9856 : "static or thread storage duration");
9857 24 : return;
9858 : }
9859 :
9860 59771262 : if (decomp)
9861 : {
9862 42944 : if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
9863 40 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
9864 : "%<constinit%> can be applied to structured binding "
9865 : "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
9866 42944 : cp_maybe_mangle_decomp (decl, decomp);
9867 42944 : if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
9868 : {
9869 501 : if (CP_DECL_THREAD_LOCAL_P (decl))
9870 37 : aggregates1 = tls_aggregates;
9871 : else
9872 464 : aggregates1 = static_aggregates;
9873 : }
9874 : }
9875 :
9876 : /* Detect stuff like 'info r = ^^int;' outside a manifestly
9877 : constant-evaluated context. */
9878 59771262 : check_out_of_consteval_use (decl);
9879 :
9880 : /* If this is a local variable that will need a mangled name,
9881 : register it now. We must do this before processing the
9882 : initializer for the variable, since the initialization might
9883 : require a guard variable, and since the mangled name of the
9884 : guard variable will depend on the mangled name of this
9885 : variable. */
9886 119542524 : if (DECL_FUNCTION_SCOPE_P (decl)
9887 23908082 : && TREE_STATIC (decl)
9888 59907641 : && !DECL_ARTIFICIAL (decl))
9889 : {
9890 : /* The variable holding an anonymous union will have had its
9891 : discriminator set in finish_anon_union, after which it's
9892 : NAME will have been cleared. */
9893 135747 : if (DECL_NAME (decl))
9894 135702 : determine_local_discriminator (decl);
9895 : /* Normally has_forced_label_in_static is set during GIMPLE
9896 : lowering, but [cd]tors are never actually compiled directly.
9897 : We need to set this early so we can deal with the label
9898 : address extension. */
9899 135747 : if ((DECL_CONSTRUCTOR_P (current_function_decl)
9900 135718 : || DECL_DESTRUCTOR_P (current_function_decl))
9901 135757 : && init)
9902 : {
9903 29 : walk_tree (&init, notice_forced_label_r, NULL, NULL);
9904 29 : add_local_decl (cfun, decl);
9905 : }
9906 135747 : if (!consteval_only_p (decl))
9907 : /* And make sure it's in the symbol table for
9908 : c_parse_final_cleanups to find. */
9909 135675 : varpool_node::get_create (decl);
9910 : }
9911 :
9912 59771262 : if (flag_openmp
9913 192677 : && VAR_P (decl)
9914 192677 : && DECL_LANG_SPECIFIC (decl)
9915 115326 : && DECL_OMP_DECLARE_MAPPER_P (decl)
9916 59771266 : && init)
9917 : {
9918 3 : gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
9919 3 : DECL_INITIAL (decl) = init;
9920 : }
9921 : /* Convert the initializer to the type of DECL, if we have not
9922 : already initialized DECL. */
9923 59771259 : else if (!DECL_INITIALIZED_P (decl)
9924 : /* If !DECL_EXTERNAL then DECL is being defined. In the
9925 : case of a static data member initialized inside the
9926 : class-specifier, there can be an initializer even if DECL
9927 : is *not* defined. */
9928 59771259 : && (!DECL_EXTERNAL (decl) || init))
9929 : {
9930 53059605 : cleanups = make_tree_vector ();
9931 53059605 : init = check_initializer (decl, init, flags, &cleanups);
9932 :
9933 : /* Handle:
9934 :
9935 : [dcl.init]
9936 :
9937 : The memory occupied by any object of static storage
9938 : duration is zero-initialized at program startup before
9939 : any other initialization takes place.
9940 :
9941 : We cannot create an appropriate initializer until after
9942 : the type of DECL is finalized. If DECL_INITIAL is set,
9943 : then the DECL is statically initialized, and any
9944 : necessary zero-initialization has already been performed. */
9945 53056908 : if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
9946 502266 : DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
9947 : /*nelts=*/NULL_TREE,
9948 : /*static_storage_p=*/true);
9949 : /* Remember that the initialization for this variable has
9950 : taken place. */
9951 53056908 : DECL_INITIALIZED_P (decl) = 1;
9952 : /* This declaration is the definition of this variable,
9953 : unless we are initializing a static data member within
9954 : the class specifier. */
9955 53056908 : if (!DECL_EXTERNAL (decl))
9956 59768565 : var_definition_p = true;
9957 : }
9958 : /* If the variable has an array type, lay out the type, even if
9959 : there is no initializer. It is valid to index through the
9960 : array, and we must get TYPE_ALIGN set correctly on the array
9961 : type. */
9962 6711654 : else if (TREE_CODE (type) == ARRAY_TYPE)
9963 213525 : layout_type (type);
9964 :
9965 59768565 : if (TREE_STATIC (decl)
9966 35444857 : && !at_function_scope_p ()
9967 95077043 : && current_function_decl == NULL)
9968 : /* So decl is a global variable or a static member of a
9969 : non local class. Record the types it uses
9970 : so that we can decide later to emit debug info for them. */
9971 35308466 : record_types_used_by_current_var_decl (decl);
9972 : }
9973 :
9974 : /* Add this declaration to the statement-tree. This needs to happen
9975 : after the call to check_initializer so that the DECL_EXPR for a
9976 : reference temp is added before the DECL_EXPR for the reference itself. */
9977 125749408 : if (DECL_FUNCTION_SCOPE_P (decl))
9978 : {
9979 : /* If we're building a variable sized type, and we might be
9980 : reachable other than via the top of the current binding
9981 : level, then create a new BIND_EXPR so that we deallocate
9982 : the object at the right time. */
9983 23908082 : if (VAR_P (decl)
9984 23908082 : && DECL_SIZE (decl)
9985 23848160 : && !TREE_CONSTANT (DECL_SIZE (decl))
9986 23909112 : && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
9987 : {
9988 3 : tree bind;
9989 3 : bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
9990 3 : TREE_SIDE_EFFECTS (bind) = 1;
9991 3 : add_stmt (bind);
9992 3 : BIND_EXPR_BODY (bind) = push_stmt_list ();
9993 : }
9994 23908082 : add_decl_expr (decl);
9995 : }
9996 :
9997 125749408 : tree decomp_init = NULL_TREE;
9998 : /* Let the middle end know about variables and functions -- but not
9999 : static data members in uninstantiated class templates. */
10000 125749408 : if (VAR_OR_FUNCTION_DECL_P (decl))
10001 : {
10002 116590613 : if (VAR_P (decl))
10003 : {
10004 59768565 : layout_var_decl (decl);
10005 59768565 : if (!flag_weak)
10006 : /* Check again now that we have an initializer. */
10007 57 : maybe_commonize_var (decl);
10008 : /* A class-scope constexpr variable with an out-of-class declaration.
10009 : C++17 makes them implicitly inline, but still force it out. */
10010 80742496 : if (DECL_INLINE_VAR_P (decl)
10011 27964283 : && !DECL_VAR_DECLARED_INLINE_P (decl)
10012 12679613 : && !DECL_TEMPLATE_INSTANTIATION (decl)
10013 45032891 : && !in_class_decl)
10014 103 : mark_needed (decl);
10015 : }
10016 :
10017 116590613 : if (var_definition_p
10018 : /* With -fmerge-all-constants, gimplify_init_constructor
10019 : might add TREE_STATIC to aggregate variables. */
10020 51889716 : && (TREE_STATIC (decl)
10021 23771848 : || (flag_merge_constants >= 2
10022 38 : && AGGREGATE_TYPE_P (type))))
10023 : {
10024 : /* If a TREE_READONLY variable needs initialization
10025 : at runtime, it is no longer readonly and we need to
10026 : avoid MEM_READONLY_P being set on RTL created for it. */
10027 28117871 : if (init)
10028 : {
10029 14293 : if (TREE_READONLY (decl))
10030 510 : TREE_READONLY (decl) = 0;
10031 : was_readonly = 0;
10032 : }
10033 28103578 : else if (was_readonly)
10034 2439 : TREE_READONLY (decl) = 1;
10035 :
10036 : /* Likewise if it needs destruction. */
10037 28117871 : if (!decl_maybe_constant_destruction (decl, type))
10038 3458 : TREE_READONLY (decl) = 0;
10039 : }
10040 88472742 : else if (VAR_P (decl)
10041 31650694 : && CP_DECL_THREAD_LOCAL_P (decl)
10042 18694 : && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
10043 18694 : && (was_readonly || TREE_READONLY (decl))
10044 88472757 : && var_needs_tls_wrapper (decl))
10045 : {
10046 : /* TLS variables need dynamic initialization by the TLS wrapper
10047 : function, we don't want to hoist accesses to it before the
10048 : wrapper. */
10049 6 : was_readonly = 0;
10050 6 : TREE_READONLY (decl) = 0;
10051 : }
10052 :
10053 116590613 : make_rtl_for_nonlocal_decl (decl, init, asmspec);
10054 :
10055 : /* Check for abstractness of the type. */
10056 116590613 : if (var_definition_p)
10057 51889716 : abstract_virtuals_error (decl, type);
10058 :
10059 116590613 : if (decomp && !cp_finish_decomp (decl, decomp, true))
10060 10039 : decomp = NULL;
10061 :
10062 116590613 : if (TREE_TYPE (decl) == error_mark_node)
10063 : /* No initialization required. */
10064 : ;
10065 116590543 : else if (TREE_CODE (decl) == FUNCTION_DECL)
10066 : {
10067 56822048 : if (init)
10068 : {
10069 584 : if (init == ridpointers[(int)RID_DEFAULT])
10070 : {
10071 : /* An out-of-class default definition is defined at
10072 : the point where it is explicitly defaulted. */
10073 572 : if (DECL_DELETED_FN (decl))
10074 6 : maybe_explain_implicit_delete (decl);
10075 566 : else if (DECL_INITIAL (decl) == error_mark_node)
10076 542 : synthesize_method (decl);
10077 : }
10078 : else
10079 24 : error_at (cp_expr_loc_or_loc (init,
10080 12 : DECL_SOURCE_LOCATION (decl)),
10081 : "function %q#D is initialized like a variable",
10082 : decl);
10083 : }
10084 : /* else no initialization required. */
10085 : }
10086 59768495 : else if (DECL_EXTERNAL (decl)
10087 59768495 : && ! (DECL_LANG_SPECIFIC (decl)
10088 7576812 : && DECL_NOT_REALLY_EXTERN (decl)))
10089 : {
10090 : /* check_initializer will have done any constant initialization. */
10091 : }
10092 : /* A variable definition. */
10093 53769834 : else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
10094 : {
10095 : /* Initialize the local variable. */
10096 23771685 : if (!decomp)
10097 23739027 : initialize_local_var (decl, init, false);
10098 : else
10099 : {
10100 32658 : tree cleanup = NULL_TREE;
10101 32658 : if (DECL_SIZE (decl))
10102 32658 : cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
10103 : /* If cp_finish_decomp needs to emit any code, we need to emit that
10104 : code after code emitted by initialize_local_var in a single
10105 : CLEANUP_POINT_EXPR, so that temporaries are destructed only
10106 : after the cp_finish_decomp emitted code.
10107 : If there are any cleanups, either extend_ref_init_temps
10108 : created ones or e.g. array destruction, push those first
10109 : with the cleanups guarded on a bool temporary, initially
10110 : set to false and set to true after initialize_local_var
10111 : emitted code. */
10112 32658 : tree guard = NULL_TREE;
10113 32658 : if (cleanups || cleanup)
10114 : {
10115 32658 : guard = get_internal_target_expr (boolean_false_node);
10116 32658 : add_stmt (guard);
10117 32658 : guard = TARGET_EXPR_SLOT (guard);
10118 : }
10119 32658 : tree sl = push_stmt_list ();
10120 32658 : initialize_local_var (decl, init, true);
10121 32658 : if (guard)
10122 : {
10123 32658 : add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
10124 : guard, boolean_true_node));
10125 32676 : for (tree &t : *cleanups)
10126 18 : t = build3 (COND_EXPR, void_type_node,
10127 : guard, t, void_node);
10128 32658 : if (cleanup)
10129 25 : cleanup = build3 (COND_EXPR, void_type_node,
10130 : guard, cleanup, void_node);
10131 : }
10132 32658 : unsigned before = stmt_list_stack->length ();
10133 32658 : cp_finish_decomp (decl, decomp);
10134 32658 : decomp = NULL;
10135 32658 : unsigned n_extra_cleanups = stmt_list_stack->length () - before;
10136 32658 : sl = pop_stmt_list (sl);
10137 32658 : if (n_extra_cleanups)
10138 : {
10139 : /* If cp_finish_decomp needs any cleanups, such as for
10140 : extend_ref_init_temps created vars, pop_stmt_list
10141 : popped that all, so push those extra cleanups around
10142 : the whole sequence with a guard variable. */
10143 15 : gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
10144 15 : guard = get_internal_target_expr (integer_zero_node);
10145 15 : add_stmt (guard);
10146 15 : guard = TARGET_EXPR_SLOT (guard);
10147 63 : for (unsigned i = 0; i < n_extra_cleanups; ++i)
10148 : {
10149 48 : tree_stmt_iterator tsi = tsi_last (sl);
10150 48 : gcc_assert (!tsi_end_p (tsi));
10151 48 : tree last = tsi_stmt (tsi);
10152 48 : gcc_assert (TREE_CODE (last) == CLEANUP_STMT
10153 : && !CLEANUP_EH_ONLY (last));
10154 48 : tree cst = build_int_cst (integer_type_node, i + 1);
10155 96 : tree cl = build3 (COND_EXPR, void_type_node,
10156 : build2 (GE_EXPR, boolean_type_node,
10157 : guard, cst),
10158 48 : CLEANUP_EXPR (last), void_node);
10159 48 : extra_cleanups.safe_push (cl);
10160 48 : tsi_link_before (&tsi, build2 (MODIFY_EXPR,
10161 : integer_type_node,
10162 : guard, cst),
10163 : TSI_SAME_STMT);
10164 48 : tree sl2 = CLEANUP_BODY (last);
10165 48 : gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
10166 48 : tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
10167 48 : tsi_delink (&tsi);
10168 : }
10169 : }
10170 32658 : decomp_init = maybe_cleanup_point_expr_void (sl);
10171 32658 : if (cleanup)
10172 25 : finish_decl_cleanup (decl, cleanup);
10173 : }
10174 : }
10175 :
10176 : /* If a variable is defined, and then a subsequent
10177 : definition with external linkage is encountered, we will
10178 : get here twice for the same variable. We want to avoid
10179 : calling expand_static_init more than once. For variables
10180 : that are not static data members, we can call
10181 : expand_static_init only when we actually process the
10182 : initializer. It is not legal to redeclare a static data
10183 : member, so this issue does not arise in that case. */
10184 29998149 : else if (var_definition_p && TREE_STATIC (decl))
10185 : {
10186 28117102 : if (decomp && DECL_FUNCTION_SCOPE_P (decl))
10187 : {
10188 102 : tree sl = push_stmt_list ();
10189 102 : auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
10190 102 : current_stmt_tree ()->stmts_are_full_exprs_p = 0;
10191 102 : expand_static_init (decl, init);
10192 102 : current_stmt_tree ()->stmts_are_full_exprs_p
10193 102 : = saved_stmts_are_full_exprs_p;
10194 102 : cp_finish_decomp (decl, decomp);
10195 102 : decomp = NULL;
10196 102 : sl = pop_stmt_list (sl);
10197 102 : sl = maybe_cleanup_point_expr_void (sl);
10198 102 : add_stmt (sl);
10199 : }
10200 : else
10201 28117000 : expand_static_init (decl, init);
10202 : }
10203 : }
10204 :
10205 : /* If a CLEANUP_STMT was created to destroy a temporary bound to a
10206 : reference, insert it in the statement-tree now. */
10207 125749408 : if (cleanups)
10208 : {
10209 53059597 : for (tree t : *cleanups)
10210 : {
10211 2689 : push_cleanup (NULL_TREE, t, false);
10212 : /* As in initialize_local_var. */
10213 2689 : wrap_temporary_cleanups (init, t);
10214 : }
10215 53056908 : release_tree_vector (cleanups);
10216 : }
10217 :
10218 125749486 : for (tree t : &extra_cleanups)
10219 48 : push_cleanup (NULL_TREE, t, false);
10220 :
10221 125749408 : if (decomp_init)
10222 32658 : add_stmt (decomp_init);
10223 :
10224 125749408 : if (decomp
10225 145 : && var_definition_p
10226 145 : && TREE_STATIC (decl)
10227 125749553 : && !DECL_FUNCTION_SCOPE_P (decl))
10228 : {
10229 145 : tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
10230 145 : ? tls_aggregates : static_aggregates);
10231 145 : tree aggregates2 = aggregates3;
10232 145 : if (aggregates2 != aggregates1)
10233 : {
10234 66 : cp_finish_decomp (decl, decomp);
10235 66 : decomp = NULL;
10236 66 : if (aggregates3 != aggregates2)
10237 : {
10238 : /* If there are dynamic initializers for the structured
10239 : binding base or associated extended ref temps and also
10240 : dynamic initializers for the structured binding non-base
10241 : vars, mark them. */
10242 267 : for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
10243 204 : STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
10244 150 : for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
10245 87 : STATIC_INIT_DECOMP_BASE_P (t) = 1;
10246 : }
10247 : }
10248 : }
10249 :
10250 125749408 : if (was_readonly)
10251 237177 : TREE_READONLY (decl) = 1;
10252 :
10253 125749408 : if (flag_openmp
10254 435792 : && VAR_P (decl)
10255 125942085 : && lookup_attribute ("omp declare target implicit",
10256 192677 : DECL_ATTRIBUTES (decl)))
10257 : {
10258 52 : DECL_ATTRIBUTES (decl)
10259 52 : = remove_attribute ("omp declare target implicit",
10260 52 : DECL_ATTRIBUTES (decl));
10261 52 : complete_type (TREE_TYPE (decl));
10262 52 : if (!omp_mappable_type (TREE_TYPE (decl)))
10263 : {
10264 30 : auto_diagnostic_group d;
10265 30 : error ("%q+D in declare target directive does not have mappable"
10266 : " type", decl);
10267 30 : if (TREE_TYPE (decl) != error_mark_node
10268 30 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
10269 30 : cxx_incomplete_type_inform (TREE_TYPE (decl));
10270 30 : }
10271 22 : else if (!lookup_attribute ("omp declare target",
10272 22 : DECL_ATTRIBUTES (decl))
10273 44 : && !lookup_attribute ("omp declare target link",
10274 22 : DECL_ATTRIBUTES (decl)))
10275 : {
10276 22 : DECL_ATTRIBUTES (decl)
10277 22 : = tree_cons (get_identifier ("omp declare target"),
10278 22 : NULL_TREE, DECL_ATTRIBUTES (decl));
10279 22 : symtab_node *node = symtab_node::get (decl);
10280 22 : if (node != NULL)
10281 : {
10282 19 : node->offloadable = 1;
10283 19 : if (ENABLE_OFFLOADING)
10284 : {
10285 : g->have_offload = true;
10286 : if (is_a <varpool_node *> (node))
10287 : vec_safe_push (offload_vars, decl);
10288 : }
10289 : }
10290 : }
10291 : }
10292 :
10293 : /* This is the last point we can lower alignment so give the target the
10294 : chance to do so. */
10295 125749408 : if (VAR_P (decl)
10296 59768565 : && !is_global_var (decl)
10297 149521256 : && !DECL_HARD_REGISTER (decl))
10298 23771795 : targetm.lower_local_decl_alignment (decl);
10299 :
10300 125749408 : invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
10301 320653148 : }
10302 :
10303 : /* For class TYPE return itself or some its bases that contain
10304 : any direct non-static data members. Return error_mark_node if an
10305 : error has been diagnosed. */
10306 :
10307 : static tree
10308 15700 : find_decomp_class_base (location_t loc, tree type, tree ret,
10309 : tsubst_flags_t complain)
10310 : {
10311 31400 : if (LAMBDA_TYPE_P (type))
10312 : {
10313 12 : if (complain & tf_error)
10314 : {
10315 12 : auto_diagnostic_group d;
10316 12 : error_at (loc, "cannot decompose lambda closure type %qT", type);
10317 12 : inform (location_of (type), "lambda declared here");
10318 12 : }
10319 12 : return error_mark_node;
10320 : }
10321 :
10322 15688 : bool member_seen = false;
10323 147973 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
10324 232590 : if (TREE_CODE (field) != FIELD_DECL
10325 32194 : || DECL_ARTIFICIAL (field)
10326 164418 : || DECL_UNNAMED_BIT_FIELD (field))
10327 100266 : continue;
10328 32058 : else if (ret)
10329 : return type;
10330 32032 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
10331 : {
10332 8 : if ((complain & tf_error) == 0)
10333 0 : return error_mark_node;
10334 8 : auto_diagnostic_group d;
10335 8 : if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
10336 4 : error_at (loc, "cannot decompose class type %qT because it has an "
10337 : "anonymous struct member", type);
10338 : else
10339 4 : error_at (loc, "cannot decompose class type %qT because it has an "
10340 : "anonymous union member", type);
10341 8 : inform (DECL_SOURCE_LOCATION (field), "declared here");
10342 8 : return error_mark_node;
10343 8 : }
10344 32024 : else if (!accessible_p (type, field, true))
10345 : {
10346 5 : if ((complain & tf_error) == 0)
10347 0 : return error_mark_node;
10348 5 : auto_diagnostic_group d;
10349 5 : error_at (loc, "cannot decompose inaccessible member %qD of %qT",
10350 : field, type);
10351 5 : inform (DECL_SOURCE_LOCATION (field),
10352 5 : TREE_PRIVATE (field)
10353 : ? G_("declared private here")
10354 : : G_("declared protected here"));
10355 5 : return error_mark_node;
10356 5 : }
10357 : else
10358 : member_seen = true;
10359 :
10360 15649 : tree base_binfo, binfo;
10361 15649 : tree orig_ret = ret;
10362 15649 : int i;
10363 15649 : if (member_seen)
10364 15547 : ret = type;
10365 15713 : for (binfo = TYPE_BINFO (type), i = 0;
10366 15713 : BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
10367 : {
10368 84 : auto_diagnostic_group d;
10369 84 : tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret,
10370 : complain);
10371 84 : if (t == error_mark_node)
10372 : {
10373 3 : if (complain & tf_error)
10374 3 : inform (location_of (type), "in base class of %qT", type);
10375 3 : return error_mark_node;
10376 : }
10377 81 : if (t != NULL_TREE && t != ret)
10378 : {
10379 54 : if (ret == type)
10380 : {
10381 10 : if (complain & tf_error)
10382 10 : error_at (loc, "cannot decompose class type %qT: both it and "
10383 : "its base class %qT have non-static data "
10384 : "members", type, t);
10385 10 : return error_mark_node;
10386 : }
10387 44 : else if (orig_ret != NULL_TREE)
10388 : return t;
10389 44 : else if (ret != NULL_TREE)
10390 : {
10391 7 : if (complain & tf_error)
10392 7 : error_at (loc, "cannot decompose class type %qT: its base "
10393 : "classes %qT and %qT have non-static data "
10394 : "members", type, ret, t);
10395 7 : return error_mark_node;
10396 : }
10397 : else
10398 : ret = t;
10399 : }
10400 84 : }
10401 : return ret;
10402 : }
10403 :
10404 : /* Return std::tuple_size<TYPE>::value. */
10405 :
10406 : static tree
10407 90996 : get_tuple_size (tree type)
10408 : {
10409 90996 : tree args = make_tree_vec (1);
10410 90996 : TREE_VEC_ELT (args, 0) = type;
10411 90996 : tree inst = lookup_template_class (tuple_size_identifier, args,
10412 : /*in_decl*/NULL_TREE,
10413 : /*context*/std_node,
10414 : tf_none);
10415 90996 : inst = complete_type (inst);
10416 90996 : if (inst == error_mark_node
10417 89525 : || !COMPLETE_TYPE_P (inst)
10418 166334 : || !CLASS_TYPE_P (inst))
10419 : return NULL_TREE;
10420 75338 : tree val = lookup_qualified_name (inst, value_identifier,
10421 : LOOK_want::NORMAL, /*complain*/false);
10422 75338 : if (val == error_mark_node)
10423 : return NULL_TREE;
10424 75332 : if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
10425 75332 : val = maybe_constant_value (val, NULL_TREE, mce_true);
10426 75332 : if (TREE_CODE (val) == INTEGER_CST)
10427 : return val;
10428 : else
10429 6 : return error_mark_node;
10430 : }
10431 :
10432 : /* Return std::tuple_element<I,TYPE>::type. */
10433 :
10434 : static tree
10435 85497 : get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i)
10436 : {
10437 85497 : tree args = make_tree_vec (2);
10438 85497 : TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
10439 85497 : TREE_VEC_ELT (args, 1) = type;
10440 85497 : tree inst = lookup_template_class (tuple_element_identifier, args,
10441 : /*in_decl*/NULL_TREE,
10442 : /*context*/std_node,
10443 : tf_warning_or_error);
10444 85497 : return make_typename_type (inst, type_identifier,
10445 85497 : none_type, tf_warning_or_error);
10446 : }
10447 :
10448 : /* Return e.get<i>() or get<i>(e). */
10449 :
10450 : static tree
10451 85506 : get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i)
10452 : {
10453 85506 : tree targs = make_tree_vec (1);
10454 85506 : TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
10455 :
10456 85506 : tree etype = TREE_TYPE (decl);
10457 85506 : tree e = convert_from_reference (decl);
10458 :
10459 : /* [The id-expression] e is an lvalue if the type of the entity e is an
10460 : lvalue reference and an xvalue otherwise. */
10461 85506 : if (!TYPE_REF_P (etype)
10462 85506 : || TYPE_REF_IS_RVALUE (etype))
10463 84207 : e = move (e);
10464 :
10465 85506 : tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
10466 : LOOK_want::NORMAL, /*complain*/false);
10467 85506 : bool use_member_get = false;
10468 :
10469 : /* To use a member get, member lookup must find at least one
10470 : declaration that is a function template
10471 : whose first template parameter is a non-type parameter. */
10472 254049 : for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
10473 : {
10474 85506 : tree fn = *iter;
10475 85506 : if (TREE_CODE (fn) == TEMPLATE_DECL)
10476 : {
10477 2472 : tree tparms = DECL_TEMPLATE_PARMS (fn);
10478 2472 : tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
10479 2472 : if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
10480 : {
10481 : use_member_get = true;
10482 : break;
10483 : }
10484 : }
10485 : }
10486 :
10487 85506 : if (use_member_get)
10488 : {
10489 2469 : fns = lookup_template_function (fns, targs);
10490 2469 : return build_new_method_call (e, fns, /*args*/NULL,
10491 : /*path*/NULL_TREE, LOOKUP_NORMAL,
10492 2469 : /*fn_p*/NULL, tf_warning_or_error);
10493 : }
10494 : else
10495 : {
10496 83037 : releasing_vec args (make_tree_vector_single (e));
10497 83037 : fns = lookup_template_function (get__identifier, targs);
10498 83037 : fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
10499 83037 : return finish_call_expr (fns, &args, /*novirt*/false,
10500 : /*koenig*/true, tf_warning_or_error);
10501 83037 : }
10502 : }
10503 :
10504 : /* It's impossible to recover the decltype of a tuple decomposition variable
10505 : based on the actual type of the variable, so store it in a hash table. */
10506 :
10507 : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
10508 :
10509 : tree
10510 622 : lookup_decomp_type (tree v)
10511 : {
10512 622 : if (decomp_type_table)
10513 495 : if (tree *slot = decomp_type_table->get (v))
10514 431 : return *slot;
10515 : return NULL_TREE;
10516 : }
10517 :
10518 : /* Mangle a decomposition declaration if needed. Arguments like
10519 : in cp_finish_decomp. */
10520 :
10521 : static void
10522 42944 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
10523 : {
10524 42944 : if (!processing_template_decl
10525 42944 : && !error_operand_p (decl)
10526 85888 : && TREE_STATIC (decl))
10527 : {
10528 764 : auto_vec<tree, 16> v;
10529 764 : v.safe_grow (decomp->count, true);
10530 764 : tree d = decomp->decl;
10531 2641 : for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
10532 1877 : v[decomp->count - i - 1] = d;
10533 764 : if (DECL_FUNCTION_SCOPE_P (decl))
10534 : {
10535 : size_t sz = 3;
10536 919 : for (unsigned int i = 0; i < decomp->count; ++i)
10537 656 : sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
10538 263 : char *name = XALLOCAVEC (char, sz);
10539 263 : name[0] = 'D';
10540 263 : name[1] = 'C';
10541 263 : char *p = name + 2;
10542 919 : for (unsigned int i = 0; i < decomp->count; ++i)
10543 : {
10544 656 : size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
10545 656 : *p++ = ' ';
10546 656 : memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
10547 656 : p += len;
10548 : }
10549 263 : *p = '\0';
10550 263 : determine_local_discriminator (decl, get_identifier (name));
10551 : }
10552 764 : SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
10553 764 : maybe_apply_pragma_weak (decl);
10554 764 : }
10555 42944 : }
10556 :
10557 : /* Append #i to DECL_NAME (decl) or for name independent decls
10558 : clear DECL_NAME (decl). */
10559 :
10560 : static void
10561 14842 : set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i)
10562 : {
10563 14842 : if (name_independent_decl_p (decl))
10564 : /* Only "_" names are treated as name independent, "_#0" etc. is not and
10565 : because we pushdecl the individual decl elements of structured binding
10566 : pack, we could get redeclaration errors if there are 2 or more name
10567 : independent structured binding packs in the same scope. */
10568 312 : DECL_NAME (decl) = NULL_TREE;
10569 : else
10570 : {
10571 14530 : tree name = DECL_NAME (decl);
10572 14530 : size_t len = IDENTIFIER_LENGTH (name) + 22;
10573 14530 : char *n = XALLOCAVEC (char, len);
10574 14530 : snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED,
10575 14530 : IDENTIFIER_POINTER (name), i);
10576 14530 : DECL_NAME (decl) = get_identifier (n);
10577 : }
10578 14842 : }
10579 :
10580 : /* Return structured binding size of TYPE or -1 if erroneous. */
10581 :
10582 : HOST_WIDE_INT
10583 528 : cp_decomp_size (location_t loc, tree type, tsubst_flags_t complain)
10584 : {
10585 528 : if (TYPE_REF_P (type))
10586 : {
10587 0 : type = complete_type (TREE_TYPE (type));
10588 0 : if (type == error_mark_node)
10589 : return -1;
10590 0 : if (!COMPLETE_TYPE_P (type))
10591 : {
10592 0 : if (complain & tf_error)
10593 0 : error_at (loc, "structured binding refers to incomplete type %qT",
10594 : type);
10595 0 : return -1;
10596 : }
10597 : }
10598 :
10599 528 : unsigned HOST_WIDE_INT eltscnt = 0;
10600 528 : if (TREE_CODE (type) == ARRAY_TYPE)
10601 : {
10602 306 : if (TYPE_DOMAIN (type) == NULL_TREE)
10603 : {
10604 9 : if (complain & tf_error)
10605 6 : error_at (loc, "cannot decompose array of unknown bound %qT",
10606 : type);
10607 9 : return -1;
10608 : }
10609 297 : tree nelts = array_type_nelts_top (type);
10610 297 : if (nelts == error_mark_node)
10611 : return -1;
10612 297 : if (!tree_fits_shwi_p (nelts))
10613 : {
10614 3 : if (complain & tf_error)
10615 3 : error_at (loc, "cannot decompose variable length array %qT", type);
10616 3 : return -1;
10617 : }
10618 294 : return tree_to_shwi (nelts);
10619 : }
10620 : /* 2 GNU extensions. */
10621 222 : else if (TREE_CODE (type) == COMPLEX_TYPE)
10622 : return 2;
10623 216 : else if (TREE_CODE (type) == VECTOR_TYPE)
10624 : {
10625 12 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
10626 : {
10627 : if (complain & tf_error)
10628 : error_at (loc, "cannot decompose variable length vector %qT", type);
10629 : return -1;
10630 : }
10631 12 : return eltscnt;
10632 : }
10633 204 : else if (tree tsize = get_tuple_size (type))
10634 : {
10635 33 : if (tsize == error_mark_node
10636 27 : || !tree_fits_shwi_p (tsize)
10637 60 : || tree_int_cst_sgn (tsize) < 0)
10638 : {
10639 9 : if (complain & tf_error)
10640 9 : error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
10641 : "constant expression", type);
10642 9 : return -1;
10643 : }
10644 24 : return tree_to_shwi (tsize);
10645 : }
10646 171 : else if (TREE_CODE (type) == UNION_TYPE)
10647 : {
10648 3 : if (complain & tf_error)
10649 3 : error_at (loc, "cannot decompose union type %qT", type);
10650 3 : return -1;
10651 : }
10652 168 : else if (!CLASS_TYPE_P (type))
10653 : {
10654 21 : if (complain & tf_error)
10655 18 : error_at (loc, "cannot decompose non-array non-class type %qT", type);
10656 21 : return -1;
10657 : }
10658 147 : else if (processing_template_decl && complete_type (type) == error_mark_node)
10659 : return -1;
10660 147 : else if (!COMPLETE_TYPE_P (type))
10661 : {
10662 3 : if (complain & tf_error)
10663 3 : error_at (loc, "structured binding refers to incomplete class type "
10664 : "%qT", type);
10665 3 : return -1;
10666 : }
10667 : else
10668 : {
10669 144 : tree btype = find_decomp_class_base (loc, type, NULL_TREE, complain);
10670 144 : if (btype == error_mark_node)
10671 : return -1;
10672 123 : else if (btype == NULL_TREE)
10673 : return 0;
10674 102 : if (btype != type)
10675 : {
10676 6 : tree binfo = lookup_base (type, btype, ba_check, NULL, complain);
10677 6 : if (binfo == NULL_TREE || binfo == error_mark_node)
10678 : return -1;
10679 : }
10680 1082 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
10681 1633 : if (TREE_CODE (field) != FIELD_DECL
10682 351 : || DECL_ARTIFICIAL (field)
10683 1337 : || DECL_UNNAMED_BIT_FIELD (field))
10684 647 : continue;
10685 : else
10686 339 : eltscnt++;
10687 96 : return eltscnt;
10688 : }
10689 : }
10690 :
10691 : /* Finish a decomposition declaration. DECL is the underlying declaration
10692 : "e", FIRST is the head of a chain of decls for the individual identifiers
10693 : chained through DECL_CHAIN in reverse order and COUNT is the number of
10694 : those decls. If TEST_P is true, return true if any code would need to be
10695 : actually emitted but don't emit it. Return false otherwise. */
10696 :
10697 : bool
10698 291662 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
10699 : {
10700 291662 : tree first = decomp->decl;
10701 291662 : unsigned count = decomp->count;
10702 291662 : if (error_operand_p (decl))
10703 : {
10704 63 : error_out:
10705 616 : while (count--)
10706 : {
10707 420 : TREE_TYPE (first) = error_mark_node;
10708 420 : if (DECL_HAS_VALUE_EXPR_P (first))
10709 : {
10710 9 : SET_DECL_VALUE_EXPR (first, NULL_TREE);
10711 9 : DECL_HAS_VALUE_EXPR_P (first) = 0;
10712 : }
10713 420 : first = DECL_CHAIN (first);
10714 : }
10715 196 : if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
10716 51 : SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
10717 196 : return false;
10718 : }
10719 :
10720 291599 : location_t loc = DECL_SOURCE_LOCATION (decl);
10721 291599 : if (type_dependent_expression_p (decl)
10722 : /* This happens for range for when not in templates.
10723 : Still add the DECL_VALUE_EXPRs for later processing. */
10724 291599 : || (!processing_template_decl
10725 76124 : && type_uses_auto (TREE_TYPE (decl))))
10726 : {
10727 590425 : for (unsigned int i = 0; i < count; i++)
10728 : {
10729 393545 : if (!DECL_HAS_VALUE_EXPR_P (first))
10730 : {
10731 393545 : tree v = build_nt (ARRAY_REF, decl,
10732 393545 : size_int (count - i - 1),
10733 : NULL_TREE, NULL_TREE);
10734 393545 : SET_DECL_VALUE_EXPR (first, v);
10735 393545 : DECL_HAS_VALUE_EXPR_P (first) = 1;
10736 : }
10737 393545 : if (processing_template_decl)
10738 392920 : fit_decomposition_lang_decl (first, decl);
10739 393545 : first = DECL_CHAIN (first);
10740 : }
10741 : return false;
10742 : }
10743 :
10744 94719 : auto_vec<tree, 16> v;
10745 94719 : v.safe_grow (count, true);
10746 94719 : tree d = first;
10747 94719 : int pack = -1;
10748 282901 : for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
10749 : {
10750 188182 : v[count - i - 1] = d;
10751 188182 : fit_decomposition_lang_decl (d, decl);
10752 188182 : if (DECL_PACK_P (d))
10753 3879 : pack = count - i - 1;
10754 : }
10755 :
10756 94719 : tree type = TREE_TYPE (decl);
10757 94719 : tree dexp = decl;
10758 :
10759 94719 : if (TYPE_REF_P (type))
10760 : {
10761 1860 : dexp = convert_from_reference (dexp);
10762 1860 : type = complete_type (TREE_TYPE (type));
10763 1860 : if (type == error_mark_node)
10764 133 : goto error_out;
10765 1860 : if (!COMPLETE_TYPE_P (type))
10766 : {
10767 3 : error_at (loc, "structured binding refers to incomplete type %qT",
10768 : type);
10769 3 : goto error_out;
10770 : }
10771 : }
10772 :
10773 94716 : tree eltype = NULL_TREE;
10774 94716 : unsigned HOST_WIDE_INT eltscnt = 0;
10775 : /* Structured binding packs when initializer is non-dependent should
10776 : have their DECL_VALUE_EXPR set to a TREE_VEC. First two elements
10777 : of that TREE_VEC are the base and index, what is normally represented
10778 : as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index
10779 : of the pack first element. The remaining elements of the TREE_VEC
10780 : are VAR_DECLs for the pack elements. */
10781 94716 : tree packv = NULL_TREE;
10782 :
10783 94716 : if (TREE_CODE (type) == ARRAY_TYPE)
10784 : {
10785 3786 : tree nelts;
10786 3786 : nelts = array_type_nelts_top (type);
10787 3786 : if (nelts == error_mark_node)
10788 0 : goto error_out;
10789 3786 : if (DECL_DECOMP_BASE (decl))
10790 : {
10791 9 : error_at (loc, "array initializer for structured binding "
10792 : "declaration in condition");
10793 9 : goto error_out;
10794 : }
10795 3777 : if (!tree_fits_uhwi_p (nelts))
10796 : {
10797 3 : error_at (loc, "cannot decompose variable length array %qT", type);
10798 3 : goto error_out;
10799 : }
10800 3774 : eltscnt = tree_to_uhwi (nelts);
10801 3774 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10802 : {
10803 11 : cnt_mismatch:
10804 38 : auto_diagnostic_group d;
10805 38 : if (count > eltscnt)
10806 27 : error_n (loc, count,
10807 : "%u name provided for structured binding",
10808 : "%u names provided for structured binding", count);
10809 : else
10810 11 : error_n (loc, count,
10811 : "only %u name provided for structured binding",
10812 : "only %u names provided for structured binding", count);
10813 38 : inform_n (loc, eltscnt,
10814 : "while %qT decomposes into %wu element",
10815 : "while %qT decomposes into %wu elements",
10816 : type, eltscnt);
10817 38 : goto error_out;
10818 : }
10819 3763 : eltype = TREE_TYPE (type);
10820 8948 : for (unsigned int i = 0; i < count; i++)
10821 : {
10822 5185 : if ((unsigned) pack == i)
10823 : {
10824 2956 : packv = make_tree_vec (eltscnt - count + 3);
10825 15743 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10826 : {
10827 12787 : tree t;
10828 12787 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10829 12787 : set_sb_pack_name (t, j);
10830 12787 : maybe_push_decl (t);
10831 12787 : TREE_TYPE (t) = eltype;
10832 12787 : layout_decl (t, 0);
10833 12787 : if (!processing_template_decl)
10834 : {
10835 12700 : tree a = unshare_expr (dexp);
10836 12700 : a = build4 (ARRAY_REF, eltype, a, size_int (j + pack),
10837 : NULL_TREE, NULL_TREE);
10838 12700 : SET_DECL_VALUE_EXPR (t, a);
10839 12700 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10840 : }
10841 : }
10842 5185 : continue;
10843 2956 : }
10844 2229 : TREE_TYPE (v[i]) = eltype;
10845 2229 : layout_decl (v[i], 0);
10846 2229 : if (processing_template_decl)
10847 136 : continue;
10848 2093 : tree t = unshare_expr (dexp);
10849 2093 : unsigned HOST_WIDE_INT j = i;
10850 2093 : if (pack != -1 && (unsigned) pack < i)
10851 64 : j = i + eltscnt - count;
10852 2093 : t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
10853 2093 : SET_DECL_VALUE_EXPR (v[i], t);
10854 2093 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10855 : }
10856 : }
10857 : /* 2 GNU extensions. */
10858 90930 : else if (TREE_CODE (type) == COMPLEX_TYPE)
10859 : {
10860 78 : eltscnt = 2;
10861 78 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10862 3 : goto cnt_mismatch;
10863 75 : eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
10864 213 : for (unsigned int i = 0; i < count; i++)
10865 : {
10866 138 : if ((unsigned) pack == i)
10867 : {
10868 60 : packv = make_tree_vec (eltscnt - count + 3);
10869 132 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10870 : {
10871 72 : tree t;
10872 72 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10873 72 : set_sb_pack_name (t, j);
10874 72 : maybe_push_decl (t);
10875 72 : TREE_TYPE (t) = eltype;
10876 72 : layout_decl (t, 0);
10877 72 : if (!processing_template_decl)
10878 : {
10879 72 : tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype,
10880 : unshare_expr (dexp));
10881 48 : SET_DECL_VALUE_EXPR (t, a);
10882 48 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10883 : }
10884 : }
10885 60 : continue;
10886 60 : }
10887 78 : TREE_TYPE (v[i]) = eltype;
10888 78 : layout_decl (v[i], 0);
10889 78 : if (processing_template_decl)
10890 16 : continue;
10891 62 : tree t = unshare_expr (dexp);
10892 62 : unsigned HOST_WIDE_INT j = i;
10893 62 : if (pack != -1 && (unsigned) pack < i)
10894 16 : j = i + eltscnt - count;
10895 93 : t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
10896 62 : SET_DECL_VALUE_EXPR (v[i], t);
10897 62 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10898 : }
10899 : }
10900 90852 : else if (TREE_CODE (type) == VECTOR_TYPE)
10901 : {
10902 60 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
10903 : {
10904 : error_at (loc, "cannot decompose variable length vector %qT", type);
10905 : goto error_out;
10906 : }
10907 60 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10908 3 : goto cnt_mismatch;
10909 57 : eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
10910 249 : for (unsigned int i = 0; i < count; i++)
10911 : {
10912 192 : if ((unsigned) pack == i)
10913 : {
10914 48 : packv = make_tree_vec (eltscnt - count + 3);
10915 708 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10916 : {
10917 660 : tree t;
10918 660 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10919 660 : set_sb_pack_name (t, j);
10920 660 : maybe_push_decl (t);
10921 660 : TREE_TYPE (t) = eltype;
10922 660 : layout_decl (t, 0);
10923 660 : if (!processing_template_decl)
10924 : {
10925 440 : tree a = unshare_expr (dexp);
10926 440 : location_t loc = DECL_SOURCE_LOCATION (t);
10927 440 : tree s = size_int (j + pack);
10928 440 : convert_vector_to_array_for_subscript (loc, &a, s);
10929 440 : a = build4 (ARRAY_REF, eltype, a, s,
10930 : NULL_TREE, NULL_TREE);
10931 440 : SET_DECL_VALUE_EXPR (t, a);
10932 440 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10933 : }
10934 : }
10935 84 : continue;
10936 48 : }
10937 144 : TREE_TYPE (v[i]) = eltype;
10938 144 : layout_decl (v[i], 0);
10939 144 : if (processing_template_decl)
10940 36 : continue;
10941 108 : tree t = unshare_expr (dexp);
10942 108 : unsigned HOST_WIDE_INT j = i;
10943 108 : if (pack != -1 && (unsigned) pack < i)
10944 24 : j = i + eltscnt - count;
10945 108 : convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
10946 108 : &t, size_int (j));
10947 108 : t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
10948 108 : SET_DECL_VALUE_EXPR (v[i], t);
10949 108 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10950 : }
10951 : }
10952 90792 : else if (tree tsize = get_tuple_size (type))
10953 : {
10954 75299 : if (tsize == error_mark_node)
10955 : {
10956 0 : error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
10957 : "constant expression", type);
10958 0 : goto error_out;
10959 : }
10960 75299 : if (!tree_fits_uhwi_p (tsize))
10961 : {
10962 12 : auto_diagnostic_group d;
10963 12 : error_n (loc, count,
10964 : "%u name provided for structured binding",
10965 : "%u names provided for structured binding", count);
10966 12 : inform (loc, "while %qT decomposes into %E elements",
10967 : type, tsize);
10968 12 : goto error_out;
10969 12 : }
10970 75287 : eltscnt = tree_to_uhwi (tsize);
10971 75287 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10972 6 : goto cnt_mismatch;
10973 75281 : if (test_p && eltscnt)
10974 94586 : return true;
10975 42376 : if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt)
10976 : {
10977 : /* For structured bindings used in conditions we need to evaluate
10978 : the conversion of decl (aka e in the standard) to bool or
10979 : integral/enumeral type (the latter for switch conditions)
10980 : before the get methods. */
10981 86 : tree cond = convert_from_reference (decl);
10982 86 : if (integer_onep (DECL_DECOMP_BASE (decl)))
10983 : /* switch condition. */
10984 18 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
10985 : cond, true);
10986 : else
10987 : /* if/while/for condition. */
10988 68 : cond = contextual_conv_bool (cond, tf_warning_or_error);
10989 86 : if (cond && !error_operand_p (cond))
10990 : {
10991 : /* Wrap that value into a TARGET_EXPR, emit it right
10992 : away and save for later uses in the cp_parse_condition
10993 : or its instantiation. */
10994 86 : cond = get_internal_target_expr (cond);
10995 86 : add_stmt (cond);
10996 86 : DECL_DECOMP_BASE (decl) = cond;
10997 : }
10998 : }
10999 42376 : int save_read = DECL_READ_P (decl);
11000 127354 : for (unsigned i = 0; i < count; ++i)
11001 : {
11002 84999 : location_t sloc = input_location;
11003 84999 : location_t dloc = DECL_SOURCE_LOCATION (v[i]);
11004 :
11005 84999 : if ((unsigned) pack == i)
11006 : {
11007 320 : packv = make_tree_vec (eltscnt - count + 3);
11008 1147 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
11009 : {
11010 827 : tree t;
11011 827 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
11012 827 : set_sb_pack_name (t, j);
11013 827 : input_location = dloc;
11014 827 : tree init = get_tuple_decomp_init (decl, j + pack);
11015 827 : tree eltype = (init == error_mark_node ? error_mark_node
11016 827 : : get_tuple_element_type (type, j + pack));
11017 827 : input_location = sloc;
11018 :
11019 827 : if (VOID_TYPE_P (eltype))
11020 : {
11021 0 : error ("%<std::tuple_element<%wu, %T>::type%> is "
11022 : "%<void%>", j + pack, type);
11023 0 : eltype = error_mark_node;
11024 : }
11025 827 : if (init == error_mark_node || eltype == error_mark_node)
11026 : {
11027 0 : inform (dloc, "in initialization of structured binding "
11028 0 : "pack %qD", v[pack]);
11029 0 : goto error_out;
11030 : }
11031 827 : maybe_push_decl (t);
11032 : /* Save the decltype away before reference collapse. */
11033 827 : hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
11034 827 : if (glvalue_p (init))
11035 770 : eltype = cp_build_reference_type (eltype, !lvalue_p (init));
11036 827 : TREE_TYPE (t) = eltype;
11037 827 : layout_decl (t, 0);
11038 827 : DECL_HAS_VALUE_EXPR_P (t) = 0;
11039 827 : if (!processing_template_decl)
11040 : {
11041 597 : copy_linkage (t, decl);
11042 597 : tree name = DECL_NAME (t);
11043 597 : if (TREE_STATIC (decl))
11044 44 : DECL_NAME (t) = DECL_NAME (v[pack]);
11045 597 : cp_finish_decl (t, init, /*constexpr*/false,
11046 : /*asm*/NULL_TREE, LOOKUP_NORMAL);
11047 597 : if (TREE_STATIC (decl))
11048 : {
11049 44 : DECL_ASSEMBLER_NAME (t);
11050 44 : DECL_NAME (t) = name;
11051 : }
11052 : }
11053 : }
11054 320 : continue;
11055 320 : }
11056 :
11057 84679 : unsigned HOST_WIDE_INT j = i;
11058 84679 : if (pack != -1 && (unsigned) pack < i)
11059 235 : j = i + eltscnt - count;
11060 84679 : input_location = dloc;
11061 84679 : tree init = get_tuple_decomp_init (decl, j);
11062 84679 : tree eltype = (init == error_mark_node ? error_mark_node
11063 84670 : : get_tuple_element_type (type, j));
11064 84679 : input_location = sloc;
11065 :
11066 84679 : if (VOID_TYPE_P (eltype))
11067 : {
11068 3 : error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>",
11069 : j, type);
11070 3 : eltype = error_mark_node;
11071 : }
11072 84679 : if (init == error_mark_node || eltype == error_mark_node)
11073 : {
11074 21 : inform (dloc, "in initialization of structured binding "
11075 21 : "variable %qD", v[i]);
11076 21 : goto error_out;
11077 : }
11078 : /* Save the decltype away before reference collapse. */
11079 84658 : hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
11080 84658 : if (glvalue_p (init))
11081 84316 : eltype = cp_build_reference_type (eltype, !lvalue_p (init));
11082 84658 : TREE_TYPE (v[i]) = eltype;
11083 84658 : layout_decl (v[i], 0);
11084 84658 : if (DECL_HAS_VALUE_EXPR_P (v[i]))
11085 : {
11086 : /* In this case the names are variables, not just proxies. */
11087 220 : SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
11088 220 : DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
11089 : }
11090 84658 : if (!processing_template_decl)
11091 : {
11092 65738 : copy_linkage (v[i], decl);
11093 65738 : cp_finish_decl (v[i], init, /*constexpr*/false,
11094 : /*asm*/NULL_TREE, LOOKUP_NORMAL);
11095 : }
11096 : }
11097 : /* Ignore reads from the underlying decl performed during initialization
11098 : of the individual variables. If those will be read, we'll mark
11099 : the underlying decl as read at that point. */
11100 42355 : DECL_READ_P (decl) = save_read;
11101 : }
11102 15493 : else if (TREE_CODE (type) == UNION_TYPE)
11103 : {
11104 3 : error_at (loc, "cannot decompose union type %qT", type);
11105 3 : goto error_out;
11106 : }
11107 15490 : else if (!CLASS_TYPE_P (type))
11108 : {
11109 16 : error_at (loc, "cannot decompose non-array non-class type %qT", type);
11110 16 : goto error_out;
11111 : }
11112 15474 : else if (processing_template_decl && complete_type (type) == error_mark_node)
11113 0 : goto error_out;
11114 15474 : else if (processing_template_decl && !COMPLETE_TYPE_P (type))
11115 2 : pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
11116 : type);
11117 : else
11118 : {
11119 15472 : tree btype = find_decomp_class_base (loc, type, NULL_TREE,
11120 : tf_warning_or_error);
11121 15472 : if (btype == error_mark_node)
11122 21 : goto error_out;
11123 15451 : else if (btype == NULL_TREE)
11124 : {
11125 23 : if (pack == 0 && count == 1)
11126 : {
11127 16 : eltscnt = 0;
11128 16 : packv = make_tree_vec (2);
11129 16 : goto done;
11130 : }
11131 7 : error_at (loc, "cannot decompose class type %qT without non-static "
11132 : "data members", type);
11133 7 : goto error_out;
11134 : }
11135 145222 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
11136 227946 : if (TREE_CODE (field) != FIELD_DECL
11137 31658 : || DECL_ARTIFICIAL (field)
11138 161448 : || DECL_UNNAMED_BIT_FIELD (field))
11139 98152 : continue;
11140 : else
11141 31642 : eltscnt++;
11142 15428 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
11143 15 : goto cnt_mismatch;
11144 15413 : tree t = dexp;
11145 15413 : if (type != btype)
11146 : {
11147 18 : t = convert_to_base (t, btype, /*check_access*/true,
11148 : /*nonnull*/false, tf_warning_or_error);
11149 18 : type = btype;
11150 : }
11151 15413 : unsigned HOST_WIDE_INT j = 0;
11152 15413 : unsigned int i = 0;
11153 145011 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
11154 227591 : if (TREE_CODE (field) != FIELD_DECL
11155 31621 : || DECL_ARTIFICIAL (field)
11156 161215 : || DECL_UNNAMED_BIT_FIELD (field))
11157 97993 : continue;
11158 : else
11159 : {
11160 31605 : tree tt = finish_non_static_data_member (field, unshare_expr (t),
11161 : NULL_TREE);
11162 31605 : if (REFERENCE_REF_P (tt))
11163 30 : tt = TREE_OPERAND (tt, 0);
11164 31605 : if (pack != -1 && j >= (unsigned) pack)
11165 : {
11166 677 : if (j == (unsigned) pack)
11167 : {
11168 225 : packv = make_tree_vec (eltscnt - count + 3);
11169 225 : i++;
11170 : }
11171 677 : if (j < (unsigned) pack + eltscnt - (count - 1))
11172 : {
11173 496 : tree t;
11174 496 : TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]);
11175 496 : set_sb_pack_name (t, j + 1 - i);
11176 496 : maybe_push_decl (t);
11177 496 : TREE_TYPE (t) = TREE_TYPE (tt);
11178 496 : layout_decl (t, 0);
11179 496 : if (!processing_template_decl)
11180 : {
11181 375 : SET_DECL_VALUE_EXPR (t, tt);
11182 375 : DECL_HAS_VALUE_EXPR_P (t) = 1;
11183 : }
11184 : else
11185 121 : DECL_HAS_VALUE_EXPR_P (t) = 0;
11186 496 : j++;
11187 496 : continue;
11188 496 : }
11189 : }
11190 31109 : TREE_TYPE (v[i]) = TREE_TYPE (tt);
11191 31109 : layout_decl (v[i], 0);
11192 31109 : if (!processing_template_decl)
11193 : {
11194 12631 : SET_DECL_VALUE_EXPR (v[i], tt);
11195 12631 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11196 : }
11197 31109 : i++;
11198 31109 : j++;
11199 : }
11200 15413 : if (pack != -1 && j == (unsigned) pack)
11201 : {
11202 20 : gcc_checking_assert (eltscnt == count - 1);
11203 20 : packv = make_tree_vec (2);
11204 : }
11205 : }
11206 61681 : done:
11207 61681 : if (packv)
11208 : {
11209 3645 : gcc_checking_assert (pack != -1);
11210 3645 : TREE_VEC_ELT (packv, 0) = decl;
11211 3645 : TREE_VEC_ELT (packv, 1) = size_int (pack);
11212 3645 : SET_DECL_VALUE_EXPR (v[pack], packv);
11213 3645 : DECL_HAS_VALUE_EXPR_P (v[pack]) = 1;
11214 3645 : DECL_IGNORED_P (v[pack]) = 1;
11215 3645 : if (!processing_template_decl)
11216 17540 : for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i)
11217 14160 : pushdecl (TREE_VEC_ELT (packv, 2 + i));
11218 : }
11219 61681 : if (processing_template_decl)
11220 : {
11221 56689 : for (unsigned int i = 0; i < count; i++)
11222 37853 : if (!DECL_HAS_VALUE_EXPR_P (v[i]))
11223 : {
11224 37441 : tree a = build_nt (ARRAY_REF, decl, size_int (i),
11225 : NULL_TREE, NULL_TREE);
11226 37441 : SET_DECL_VALUE_EXPR (v[i], a);
11227 37441 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11228 : }
11229 : }
11230 42845 : else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
11231 : {
11232 367 : tree attr = NULL_TREE, *pa = &attr;
11233 1281 : for (unsigned int i = 0; i < count; i++)
11234 914 : if ((unsigned) pack != i
11235 914 : && DECL_HAS_VALUE_EXPR_P (v[i])
11236 1488 : && !DECL_IGNORED_P (v[i]))
11237 : {
11238 574 : (*debug_hooks->early_global_decl) (v[i]);
11239 574 : *pa = build_tree_list (NULL_TREE, v[i]);
11240 574 : pa = &TREE_CHAIN (*pa);
11241 : }
11242 367 : if (attr)
11243 252 : DECL_ATTRIBUTES (decl)
11244 504 : = tree_cons (get_identifier ("structured bindings"),
11245 252 : attr, DECL_ATTRIBUTES (decl));
11246 : }
11247 : return false;
11248 : }
11249 :
11250 : /* Returns a declaration for a VAR_DECL as if:
11251 :
11252 : extern "C" TYPE NAME;
11253 :
11254 : had been seen. Used to create compiler-generated global
11255 : variables. */
11256 :
11257 : static tree
11258 2234 : declare_global_var (tree name, tree type)
11259 : {
11260 2234 : auto cookie = push_abi_namespace (global_namespace);
11261 2234 : tree decl = build_decl (input_location, VAR_DECL, name, type);
11262 2234 : TREE_PUBLIC (decl) = 1;
11263 2234 : DECL_EXTERNAL (decl) = 1;
11264 2234 : DECL_ARTIFICIAL (decl) = 1;
11265 2234 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
11266 : /* If the user has explicitly declared this variable (perhaps
11267 : because the code we are compiling is part of a low-level runtime
11268 : library), then it is possible that our declaration will be merged
11269 : with theirs by pushdecl. */
11270 2234 : decl = pushdecl (decl);
11271 2234 : cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
11272 2234 : pop_abi_namespace (cookie, global_namespace);
11273 :
11274 2234 : return decl;
11275 : }
11276 :
11277 : /* Returns the type for the argument to "atexit" corresponding to the function
11278 : to be called when the program exits. */
11279 :
11280 : static tree
11281 24 : get_atexit_fn_ptr_type ()
11282 : {
11283 24 : if (!atexit_fn_ptr_type_node)
11284 : {
11285 12 : tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
11286 12 : atexit_fn_ptr_type_node = build_pointer_type (fn_type);
11287 : }
11288 :
11289 24 : return atexit_fn_ptr_type_node;
11290 : }
11291 :
11292 : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
11293 : or "__cxa_throw" corresponding to the destructor to be called when the
11294 : program exits. */
11295 :
11296 : tree
11297 18527 : get_cxa_atexit_fn_ptr_type ()
11298 : {
11299 18527 : if (!cleanup_type)
11300 : {
11301 13938 : tree fntype = build_function_type_list (void_type_node,
11302 : ptr_type_node, NULL_TREE);
11303 13938 : fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
11304 13938 : cleanup_type = build_pointer_type (fntype);
11305 : }
11306 :
11307 18527 : return cleanup_type;
11308 : }
11309 :
11310 : /* Returns a pointer to the `atexit' function. Note that if
11311 : FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
11312 : `__cxa_atexit' function specified in the IA64 C++ ABI. */
11313 :
11314 : static tree
11315 3383 : get_atexit_node (void)
11316 : {
11317 3383 : tree atexit_fndecl;
11318 3383 : tree fn_type;
11319 3383 : tree fn_ptr_type;
11320 3383 : const char *name;
11321 3383 : bool use_aeabi_atexit;
11322 3383 : tree ctx = global_namespace;
11323 :
11324 3383 : if (atexit_node)
11325 : return atexit_node;
11326 :
11327 2197 : if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
11328 : {
11329 : /* The declaration for `__cxa_atexit' is:
11330 :
11331 : int __cxa_atexit (void (*)(void *), void *, void *)
11332 :
11333 : We build up the argument types and then the function type
11334 : itself. */
11335 2185 : tree argtype0, argtype1, argtype2;
11336 :
11337 2185 : use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
11338 : /* First, build the pointer-to-function type for the first
11339 : argument. */
11340 2185 : fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
11341 : /* Then, build the rest of the argument types. */
11342 2185 : argtype2 = ptr_type_node;
11343 2185 : if (use_aeabi_atexit)
11344 : {
11345 : argtype1 = fn_ptr_type;
11346 : argtype0 = ptr_type_node;
11347 : }
11348 : else
11349 : {
11350 2185 : argtype1 = ptr_type_node;
11351 2185 : argtype0 = fn_ptr_type;
11352 : }
11353 : /* And the final __cxa_atexit type. */
11354 2185 : fn_type = build_function_type_list (integer_type_node,
11355 : argtype0, argtype1, argtype2,
11356 : NULL_TREE);
11357 : /* ... which needs noexcept. */
11358 2185 : fn_type = build_exception_variant (fn_type, noexcept_true_spec);
11359 2185 : if (use_aeabi_atexit)
11360 : {
11361 0 : name = "__aeabi_atexit";
11362 0 : push_to_top_level ();
11363 0 : int n = push_namespace (get_identifier ("__aeabiv1"), false);
11364 0 : ctx = current_namespace;
11365 0 : while (n--)
11366 0 : pop_namespace ();
11367 0 : pop_from_top_level ();
11368 : }
11369 : else
11370 : {
11371 2185 : name = "__cxa_atexit";
11372 2185 : ctx = abi_node;
11373 : }
11374 : }
11375 : else
11376 : {
11377 : /* The declaration for `atexit' is:
11378 :
11379 : int atexit (void (*)());
11380 :
11381 : We build up the argument types and then the function type
11382 : itself. */
11383 12 : fn_ptr_type = get_atexit_fn_ptr_type ();
11384 : /* Build the final atexit type. */
11385 12 : fn_type = build_function_type_list (integer_type_node,
11386 : fn_ptr_type, NULL_TREE);
11387 : /* ... which needs noexcept. */
11388 12 : fn_type = build_exception_variant (fn_type, noexcept_true_spec);
11389 12 : name = "atexit";
11390 : }
11391 :
11392 : /* Now, build the function declaration. */
11393 2197 : push_lang_context (lang_name_c);
11394 2197 : auto cookie = push_abi_namespace (ctx);
11395 2197 : atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
11396 2197 : DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
11397 : /* Install as hidden builtin so we're (a) more relaxed about
11398 : exception spec matching and (b) will not give a confusing location
11399 : in diagnostic and (c) won't magically appear in user-visible name
11400 : lookups. */
11401 2197 : DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
11402 2197 : atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
11403 2197 : pop_abi_namespace (cookie, ctx);
11404 2197 : mark_used (atexit_fndecl);
11405 2197 : pop_lang_context ();
11406 2197 : atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
11407 :
11408 2197 : return atexit_node;
11409 : }
11410 :
11411 : /* Like get_atexit_node, but for thread-local cleanups. */
11412 :
11413 : static tree
11414 98 : get_thread_atexit_node (void)
11415 : {
11416 98 : if (thread_atexit_node)
11417 : return thread_atexit_node;
11418 :
11419 : /* The declaration for `__cxa_thread_atexit' is:
11420 :
11421 : int __cxa_thread_atexit (void (*)(void *), void *, void *) */
11422 59 : tree fn_type = build_function_type_list (integer_type_node,
11423 : get_cxa_atexit_fn_ptr_type (),
11424 : ptr_type_node, ptr_type_node,
11425 : NULL_TREE);
11426 :
11427 : /* Now, build the function declaration, as with __cxa_atexit. */
11428 59 : unsigned flags = push_abi_namespace ();
11429 59 : tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
11430 : ECF_LEAF | ECF_NOTHROW);
11431 59 : DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
11432 59 : DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
11433 59 : atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
11434 59 : pop_abi_namespace (flags);
11435 59 : mark_used (atexit_fndecl);
11436 59 : thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
11437 :
11438 59 : return thread_atexit_node;
11439 : }
11440 :
11441 : /* Returns the __dso_handle VAR_DECL. */
11442 :
11443 : static tree
11444 3469 : get_dso_handle_node (void)
11445 : {
11446 3469 : if (dso_handle_node)
11447 : return dso_handle_node;
11448 :
11449 : /* Declare the variable. */
11450 2234 : dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
11451 : ptr_type_node);
11452 :
11453 : #ifdef HAVE_GAS_HIDDEN
11454 2234 : if (dso_handle_node != error_mark_node)
11455 : {
11456 2231 : DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
11457 2231 : DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
11458 : }
11459 : #endif
11460 :
11461 2234 : return dso_handle_node;
11462 : }
11463 :
11464 : /* Begin a new function with internal linkage whose job will be simply
11465 : to destroy some particular DECL. OB_PARM is true if object pointer
11466 : is passed to the cleanup function, otherwise no argument is passed. */
11467 :
11468 : static tree
11469 370 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
11470 : {
11471 370 : push_to_top_level ();
11472 :
11473 : /* No need to mangle this. */
11474 370 : push_lang_context (lang_name_c);
11475 :
11476 : /* Build the name of the function. */
11477 370 : gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
11478 370 : const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
11479 370 : dname = targetm.strip_name_encoding (dname);
11480 737 : char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
11481 :
11482 370 : tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
11483 : : get_atexit_fn_ptr_type ());
11484 : /* Build the function declaration. */
11485 370 : tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
11486 370 : DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
11487 : /* It's a function with internal linkage, generated by the
11488 : compiler. */
11489 370 : TREE_PUBLIC (fndecl) = 0;
11490 370 : DECL_ARTIFICIAL (fndecl) = 1;
11491 : /* Make the function `inline' so that it is only emitted if it is
11492 : actually needed. It is unlikely that it will be inlined, since
11493 : it is only called via a function pointer, but we avoid unnecessary
11494 : emissions this way. */
11495 370 : DECL_DECLARED_INLINE_P (fndecl) = 1;
11496 370 : DECL_INTERFACE_KNOWN (fndecl) = 1;
11497 370 : if (ob_parm)
11498 : {
11499 : /* Build the parameter. */
11500 358 : tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
11501 358 : TREE_USED (parmdecl) = 1;
11502 358 : DECL_READ_P (parmdecl) = 1;
11503 358 : DECL_ARGUMENTS (fndecl) = parmdecl;
11504 : }
11505 :
11506 370 : fndecl = pushdecl (fndecl, /*hidden=*/true);
11507 370 : if (omp_target)
11508 : {
11509 3 : DECL_ATTRIBUTES (fndecl)
11510 3 : = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
11511 3 : DECL_ATTRIBUTES (fndecl));
11512 3 : DECL_ATTRIBUTES (fndecl)
11513 6 : = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
11514 3 : DECL_ATTRIBUTES (fndecl));
11515 : }
11516 370 : start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
11517 :
11518 370 : pop_lang_context ();
11519 :
11520 370 : return current_function_decl;
11521 : }
11522 :
11523 : /* Finish the cleanup function begun by start_cleanup_fn. */
11524 :
11525 : static void
11526 370 : end_cleanup_fn (void)
11527 : {
11528 370 : expand_or_defer_fn (finish_function (/*inline_p=*/false));
11529 :
11530 370 : pop_from_top_level ();
11531 370 : }
11532 :
11533 : /* Generate code to handle the destruction of DECL, an object with
11534 : static storage duration. */
11535 :
11536 : tree
11537 15133 : register_dtor_fn (tree decl, bool omp_target)
11538 : {
11539 15133 : tree cleanup;
11540 15133 : tree addr;
11541 15133 : tree compound_stmt;
11542 15133 : tree fcall;
11543 15133 : tree type;
11544 15133 : bool ob_parm, dso_parm, use_dtor;
11545 15133 : tree arg0, arg1, arg2;
11546 15133 : tree atex_node;
11547 :
11548 15133 : type = TREE_TYPE (decl);
11549 15133 : if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
11550 11652 : return void_node;
11551 :
11552 3481 : if (decl_maybe_constant_destruction (decl, type)
11553 3481 : && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
11554 : {
11555 0 : cxx_maybe_build_cleanup (decl, tf_warning_or_error);
11556 0 : return void_node;
11557 : }
11558 :
11559 : /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
11560 : "__aeabi_atexit"), and DECL is a class object, we can just pass the
11561 : destructor to "__cxa_atexit"; we don't have to build a temporary
11562 : function to do the cleanup. */
11563 6962 : dso_parm = (flag_use_cxa_atexit
11564 3481 : && !targetm.cxx.use_atexit_for_cxa_atexit ());
11565 3481 : ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
11566 3469 : use_dtor = ob_parm && CLASS_TYPE_P (type);
11567 3481 : if (use_dtor)
11568 : {
11569 3111 : cleanup = get_class_binding (type, complete_dtor_identifier);
11570 :
11571 : /* Make sure it is accessible. */
11572 3111 : perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
11573 : tf_warning_or_error);
11574 : }
11575 : else
11576 : {
11577 : /* Call build_cleanup before we enter the anonymous function so
11578 : that any access checks will be done relative to the current
11579 : scope, rather than the scope of the anonymous function. */
11580 370 : build_cleanup (decl);
11581 :
11582 : /* Now start the function. */
11583 370 : cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
11584 :
11585 : /* Now, recompute the cleanup. It may contain SAVE_EXPRs that refer
11586 : to the original function, rather than the anonymous one. That
11587 : will make the back end think that nested functions are in use,
11588 : which causes confusion. */
11589 370 : push_deferring_access_checks (dk_no_check);
11590 370 : fcall = build_cleanup (decl);
11591 370 : pop_deferring_access_checks ();
11592 :
11593 : /* Create the body of the anonymous function. */
11594 370 : compound_stmt = begin_compound_stmt (BCS_FN_BODY);
11595 370 : finish_expr_stmt (fcall);
11596 370 : finish_compound_stmt (compound_stmt);
11597 370 : end_cleanup_fn ();
11598 : }
11599 :
11600 : /* Call atexit with the cleanup function. */
11601 3481 : mark_used (cleanup);
11602 3481 : cleanup = build_address (cleanup);
11603 :
11604 3481 : if (CP_DECL_THREAD_LOCAL_P (decl))
11605 98 : atex_node = get_thread_atexit_node ();
11606 : else
11607 3383 : atex_node = get_atexit_node ();
11608 :
11609 3481 : if (use_dtor)
11610 : {
11611 : /* We must convert CLEANUP to the type that "__cxa_atexit"
11612 : expects. */
11613 3111 : cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
11614 : /* "__cxa_atexit" will pass the address of DECL to the
11615 : cleanup function. */
11616 3111 : mark_used (decl);
11617 3111 : addr = build_address (decl);
11618 : /* The declared type of the parameter to "__cxa_atexit" is
11619 : "void *". For plain "T*", we could just let the
11620 : machinery in cp_build_function_call convert it -- but if the
11621 : type is "cv-qualified T *", then we need to convert it
11622 : before passing it in, to avoid spurious errors. */
11623 3111 : addr = build_nop (ptr_type_node, addr);
11624 : }
11625 : else
11626 : /* Since the cleanup functions we build ignore the address
11627 : they're given, there's no reason to pass the actual address
11628 : in, and, in general, it's cheaper to pass NULL than any
11629 : other value. */
11630 370 : addr = null_pointer_node;
11631 :
11632 3481 : if (dso_parm)
11633 3469 : arg2 = cp_build_addr_expr (get_dso_handle_node (),
11634 : tf_warning_or_error);
11635 12 : else if (ob_parm)
11636 : /* Just pass NULL to the dso handle parm if we don't actually
11637 : have a DSO handle on this target. */
11638 0 : arg2 = null_pointer_node;
11639 : else
11640 : arg2 = NULL_TREE;
11641 :
11642 3469 : if (ob_parm)
11643 : {
11644 3469 : if (!CP_DECL_THREAD_LOCAL_P (decl)
11645 3469 : && targetm.cxx.use_aeabi_atexit ())
11646 : {
11647 : arg1 = cleanup;
11648 : arg0 = addr;
11649 : }
11650 : else
11651 : {
11652 : arg1 = addr;
11653 : arg0 = cleanup;
11654 : }
11655 : }
11656 : else
11657 : {
11658 : arg0 = cleanup;
11659 : arg1 = NULL_TREE;
11660 : }
11661 3481 : return cp_build_function_call_nary (atex_node, tf_warning_or_error,
11662 3481 : arg0, arg1, arg2, NULL_TREE);
11663 : }
11664 :
11665 : /* DECL is a VAR_DECL with static storage duration. INIT, if present,
11666 : is its initializer. Generate code to handle the construction
11667 : and destruction of DECL. */
11668 :
11669 : static void
11670 28117102 : expand_static_init (tree decl, tree init)
11671 : {
11672 28117102 : gcc_assert (VAR_P (decl));
11673 28117102 : gcc_assert (TREE_STATIC (decl));
11674 :
11675 : /* Some variables require no dynamic initialization. */
11676 28117102 : if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
11677 : {
11678 : /* Make sure the destructor is callable. */
11679 28113647 : cxx_maybe_build_cleanup (decl, tf_warning_or_error);
11680 28113647 : if (!init)
11681 : return;
11682 : }
11683 :
11684 16002 : if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
11685 15079 : && !DECL_FUNCTION_SCOPE_P (decl))
11686 : {
11687 15 : auto_diagnostic_group d;
11688 15 : location_t dloc = DECL_SOURCE_LOCATION (decl);
11689 15 : if (init)
11690 12 : error_at (dloc, "non-local variable %qD declared %<__thread%> "
11691 : "needs dynamic initialization", decl);
11692 : else
11693 3 : error_at (dloc, "non-local variable %qD declared %<__thread%> "
11694 : "has a non-trivial destructor", decl);
11695 15 : static bool informed;
11696 15 : if (!informed)
11697 : {
11698 6 : inform (dloc, "C++11 %<thread_local%> allows dynamic "
11699 : "initialization and destruction");
11700 6 : informed = true;
11701 : }
11702 15 : return;
11703 15 : }
11704 :
11705 15035 : if (DECL_FUNCTION_SCOPE_P (decl))
11706 : {
11707 : /* Emit code to perform this initialization but once. */
11708 3919 : tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
11709 3919 : tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
11710 3919 : tree guard, guard_addr;
11711 3919 : tree flag, begin;
11712 : /* We don't need thread-safety code for thread-local vars. */
11713 3919 : bool thread_guard = (flag_threadsafe_statics
11714 3919 : && !CP_DECL_THREAD_LOCAL_P (decl));
11715 :
11716 : /* Emit code to perform this initialization but once. This code
11717 : looks like:
11718 :
11719 : static <type> guard;
11720 : if (!__atomic_load (guard.first_byte)) {
11721 : if (__cxa_guard_acquire (&guard)) {
11722 : bool flag = false;
11723 : try {
11724 : // Do initialization.
11725 : flag = true; __cxa_guard_release (&guard);
11726 : // Register variable for destruction at end of program.
11727 : } catch {
11728 : if (!flag) __cxa_guard_abort (&guard);
11729 : }
11730 : }
11731 : }
11732 :
11733 : Note that the `flag' variable is only set to 1 *after* the
11734 : initialization is complete. This ensures that an exception,
11735 : thrown during the construction, will cause the variable to
11736 : reinitialized when we pass through this code again, as per:
11737 :
11738 : [stmt.dcl]
11739 :
11740 : If the initialization exits by throwing an exception, the
11741 : initialization is not complete, so it will be tried again
11742 : the next time control enters the declaration.
11743 :
11744 : This process should be thread-safe, too; multiple threads
11745 : should not be able to initialize the variable more than
11746 : once. */
11747 :
11748 : /* Create the guard variable. */
11749 3919 : guard = get_guard (decl);
11750 :
11751 : /* Begin the conditional initialization. */
11752 3919 : if_stmt = begin_if_stmt ();
11753 :
11754 3919 : finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
11755 3919 : then_clause = begin_compound_stmt (BCS_NO_SCOPE);
11756 :
11757 3919 : if (thread_guard)
11758 : {
11759 3774 : tree vfntype = NULL_TREE;
11760 3774 : tree acquire_name, release_name, abort_name;
11761 3774 : tree acquire_fn, release_fn, abort_fn;
11762 3774 : guard_addr = build_address (guard);
11763 :
11764 3774 : acquire_name = get_identifier ("__cxa_guard_acquire");
11765 3774 : release_name = get_identifier ("__cxa_guard_release");
11766 3774 : abort_name = get_identifier ("__cxa_guard_abort");
11767 3774 : acquire_fn = get_global_binding (acquire_name);
11768 3774 : release_fn = get_global_binding (release_name);
11769 3774 : abort_fn = get_global_binding (abort_name);
11770 3774 : if (!acquire_fn)
11771 2171 : acquire_fn = push_library_fn
11772 2171 : (acquire_name, build_function_type_list (integer_type_node,
11773 2171 : TREE_TYPE (guard_addr),
11774 : NULL_TREE),
11775 : NULL_TREE, ECF_NOTHROW);
11776 3774 : if (!release_fn || !abort_fn)
11777 2174 : vfntype = build_function_type_list (void_type_node,
11778 2174 : TREE_TYPE (guard_addr),
11779 : NULL_TREE);
11780 2174 : if (!release_fn)
11781 2174 : release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
11782 : ECF_NOTHROW);
11783 3774 : if (!abort_fn)
11784 2174 : abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
11785 : ECF_NOTHROW | ECF_LEAF);
11786 :
11787 3774 : inner_if_stmt = begin_if_stmt ();
11788 3774 : finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
11789 : inner_if_stmt);
11790 :
11791 3774 : inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
11792 3774 : begin = get_internal_target_expr (boolean_false_node);
11793 3774 : flag = TARGET_EXPR_SLOT (begin);
11794 :
11795 3774 : TARGET_EXPR_CLEANUP (begin)
11796 3774 : = build3 (COND_EXPR, void_type_node, flag,
11797 : void_node,
11798 : build_call_n (abort_fn, 1, guard_addr));
11799 3774 : CLEANUP_EH_ONLY (begin) = 1;
11800 :
11801 : /* Do the initialization itself. */
11802 3774 : init = add_stmt_to_compound (begin, init);
11803 3774 : init = add_stmt_to_compound (init,
11804 : build2 (MODIFY_EXPR, void_type_node,
11805 : flag, boolean_true_node));
11806 :
11807 : /* Use atexit to register a function for destroying this static
11808 : variable. Do this before calling __cxa_guard_release. */
11809 3774 : init = add_stmt_to_compound (init, register_dtor_fn (decl));
11810 :
11811 3774 : init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
11812 : guard_addr));
11813 : }
11814 : else
11815 : {
11816 145 : init = add_stmt_to_compound (init, set_guard (guard));
11817 :
11818 : /* Use atexit to register a function for destroying this static
11819 : variable. */
11820 145 : init = add_stmt_to_compound (init, register_dtor_fn (decl));
11821 : }
11822 :
11823 3919 : finish_expr_stmt (init);
11824 :
11825 3919 : if (thread_guard)
11826 : {
11827 3774 : finish_compound_stmt (inner_then_clause);
11828 3774 : finish_then_clause (inner_if_stmt);
11829 3774 : finish_if_stmt (inner_if_stmt);
11830 : }
11831 :
11832 3919 : finish_compound_stmt (then_clause);
11833 3919 : finish_then_clause (if_stmt);
11834 3919 : finish_if_stmt (if_stmt);
11835 : }
11836 11116 : else if (CP_DECL_THREAD_LOCAL_P (decl))
11837 795 : tls_aggregates = tree_cons (init, decl, tls_aggregates);
11838 : else
11839 10321 : static_aggregates = tree_cons (init, decl, static_aggregates);
11840 : }
11841 :
11842 :
11843 : /* Make TYPE a complete type based on INITIAL_VALUE.
11844 : Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
11845 : 2 if there was no information (in which case assume 0 if DO_DEFAULT),
11846 : 3 if the initializer list is empty (in pedantic mode). */
11847 :
11848 : int
11849 601621 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
11850 : {
11851 601621 : int failure;
11852 601621 : tree type, elt_type;
11853 :
11854 : /* Don't get confused by a CONSTRUCTOR for some other type. */
11855 601591 : if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
11856 142526 : && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
11857 601951 : && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
11858 : return 1;
11859 :
11860 601618 : if (initial_value)
11861 : {
11862 : /* An array of character type can be initialized from a
11863 : brace-enclosed string constant so call reshape_init to
11864 : remove the optional braces from a braced string literal. */
11865 601588 : if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
11866 601588 : && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
11867 48754 : initial_value = reshape_init (*ptype, initial_value,
11868 : tf_warning_or_error);
11869 :
11870 : /* If any of the elements are parameter packs, we can't actually
11871 : complete this type now because the array size is dependent. */
11872 601588 : if (TREE_CODE (initial_value) == CONSTRUCTOR)
11873 46951889 : for (auto &e: CONSTRUCTOR_ELTS (initial_value))
11874 46524727 : if (PACK_EXPANSION_P (e.value))
11875 : return 0;
11876 : }
11877 :
11878 601618 : failure = complete_array_type (ptype, initial_value, do_default);
11879 :
11880 : /* We can create the array before the element type is complete, which
11881 : means that we didn't have these two bits set in the original type
11882 : either. In completing the type, we are expected to propagate these
11883 : bits. See also complete_type which does the same thing for arrays
11884 : of fixed size. */
11885 601618 : type = *ptype;
11886 1203233 : if (type != error_mark_node && TYPE_DOMAIN (type))
11887 : {
11888 601591 : elt_type = TREE_TYPE (type);
11889 601591 : TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
11890 1203182 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
11891 601591 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
11892 : }
11893 :
11894 : return failure;
11895 : }
11896 :
11897 : /* As above, but either give an error or reject zero-size arrays, depending
11898 : on COMPLAIN. */
11899 :
11900 : int
11901 1194 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
11902 : bool do_default, tsubst_flags_t complain)
11903 : {
11904 1194 : int failure;
11905 1194 : bool sfinae = !(complain & tf_error);
11906 : /* In SFINAE context we can't be lenient about zero-size arrays. */
11907 1194 : if (sfinae)
11908 3 : ++pedantic;
11909 1194 : failure = cp_complete_array_type (ptype, initial_value, do_default);
11910 1194 : if (sfinae)
11911 3 : --pedantic;
11912 1194 : if (failure)
11913 : {
11914 3 : if (sfinae)
11915 : /* Not an error. */;
11916 0 : else if (failure == 1)
11917 0 : error ("initializer fails to determine size of %qT", *ptype);
11918 0 : else if (failure == 2)
11919 : {
11920 0 : if (do_default)
11921 0 : error ("array size missing in %qT", *ptype);
11922 : }
11923 0 : else if (failure == 3)
11924 0 : error ("zero-size array %qT", *ptype);
11925 3 : *ptype = error_mark_node;
11926 : }
11927 1194 : return failure;
11928 : }
11929 :
11930 : /* Return zero if something is declared to be a member of type
11931 : CTYPE when in the context of CUR_TYPE. STRING is the error
11932 : message to print in that case. Otherwise, quietly return 1. */
11933 :
11934 : static int
11935 26190813 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
11936 : {
11937 26190813 : if (ctype && ctype != cur_type)
11938 : {
11939 0 : if (flags == DTOR_FLAG)
11940 0 : error ("destructor for alien class %qT cannot be a member", ctype);
11941 : else
11942 0 : error ("constructor for alien class %qT cannot be a member", ctype);
11943 0 : return 0;
11944 : }
11945 : return 1;
11946 : }
11947 :
11948 : /* Subroutine of `grokdeclarator'. */
11949 :
11950 : /* Generate errors possibly applicable for a given set of specifiers.
11951 : This is for ARM $7.1.2. */
11952 :
11953 : static void
11954 437871335 : bad_specifiers (tree object,
11955 : enum bad_spec_place type,
11956 : int virtualp,
11957 : int quals,
11958 : int inlinep,
11959 : int friendp,
11960 : int raises,
11961 : const location_t* locations)
11962 : {
11963 437871335 : switch (type)
11964 : {
11965 67475549 : case BSP_VAR:
11966 67475549 : if (virtualp)
11967 0 : error_at (locations[ds_virtual],
11968 : "%qD declared as a %<virtual%> variable", object);
11969 67475549 : if (quals)
11970 3 : error ("%<const%> and %<volatile%> function specifiers on "
11971 : "%qD invalid in variable declaration", object);
11972 : break;
11973 291063487 : case BSP_PARM:
11974 291063487 : if (virtualp)
11975 0 : error_at (locations[ds_virtual],
11976 : "%qD declared as a %<virtual%> parameter", object);
11977 291063487 : if (inlinep)
11978 6 : error_at (locations[ds_inline],
11979 : "%qD declared as an %<inline%> parameter", object);
11980 291063487 : if (quals)
11981 3 : error ("%<const%> and %<volatile%> function specifiers on "
11982 : "%qD invalid in parameter declaration", object);
11983 : break;
11984 46796310 : case BSP_TYPE:
11985 46796310 : if (virtualp)
11986 0 : error_at (locations[ds_virtual],
11987 : "%qD declared as a %<virtual%> type", object);
11988 46796310 : if (inlinep)
11989 6 : error_at (locations[ds_inline],
11990 : "%qD declared as an %<inline%> type", object);
11991 46796310 : if (quals)
11992 0 : error ("%<const%> and %<volatile%> function specifiers on "
11993 : "%qD invalid in type declaration", object);
11994 : break;
11995 32535989 : case BSP_FIELD:
11996 32535989 : if (virtualp)
11997 6 : error_at (locations[ds_virtual],
11998 : "%qD declared as a %<virtual%> field", object);
11999 32535989 : if (inlinep)
12000 6 : error_at (locations[ds_inline],
12001 : "%qD declared as an %<inline%> field", object);
12002 32535989 : if (quals)
12003 0 : error ("%<const%> and %<volatile%> function specifiers on "
12004 : "%qD invalid in field declaration", object);
12005 : break;
12006 0 : default:
12007 0 : gcc_unreachable();
12008 : }
12009 437871335 : if (friendp)
12010 0 : error ("%q+D declared as a friend", object);
12011 437871335 : if (raises
12012 113 : && !flag_noexcept_type
12013 437871356 : && (TREE_CODE (object) == TYPE_DECL
12014 15 : || (!TYPE_PTRFN_P (TREE_TYPE (object))
12015 5 : && !TYPE_REFFN_P (TREE_TYPE (object))
12016 4 : && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
12017 6 : error ("%q+D declared with an exception specification", object);
12018 437871335 : }
12019 :
12020 : /* DECL is a member function or static data member and is presently
12021 : being defined. Check that the definition is taking place in a
12022 : valid namespace. */
12023 :
12024 : static void
12025 96177419 : check_class_member_definition_namespace (tree decl)
12026 : {
12027 : /* These checks only apply to member functions and static data
12028 : members. */
12029 96177419 : gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
12030 : /* We check for problems with specializations in pt.cc in
12031 : check_specialization_namespace, where we can issue better
12032 : diagnostics. */
12033 96177419 : if (processing_specialization)
12034 : return;
12035 : /* We check this in check_explicit_instantiation_namespace. */
12036 96037356 : if (processing_explicit_instantiation)
12037 : return;
12038 : /* [class.mfct]
12039 :
12040 : A member function definition that appears outside of the
12041 : class definition shall appear in a namespace scope enclosing
12042 : the class definition.
12043 :
12044 : [class.static.data]
12045 :
12046 : The definition for a static data member shall appear in a
12047 : namespace scope enclosing the member's class definition. */
12048 96037276 : if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
12049 18 : permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
12050 18 : decl, DECL_CONTEXT (decl));
12051 : }
12052 :
12053 : /* Build a PARM_DECL for the "this" parameter of FN. TYPE is the
12054 : METHOD_TYPE for a non-static member function; QUALS are the
12055 : cv-qualifiers that apply to the function. */
12056 :
12057 : tree
12058 233654409 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
12059 : {
12060 233654409 : tree this_type;
12061 233654409 : tree qual_type;
12062 233654409 : tree parm;
12063 233654409 : cp_cv_quals this_quals;
12064 :
12065 233654409 : if (CLASS_TYPE_P (type))
12066 : {
12067 102448686 : this_type
12068 102448686 : = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
12069 102448686 : this_type = build_pointer_type (this_type);
12070 : }
12071 : else
12072 131205723 : this_type = type_of_this_parm (type);
12073 : /* The `this' parameter is implicitly `const'; it cannot be
12074 : assigned to. */
12075 233654409 : this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
12076 233654409 : qual_type = cp_build_qualified_type (this_type, this_quals);
12077 233654409 : parm = build_artificial_parm (fn, this_identifier, qual_type);
12078 233654409 : cp_apply_type_quals_to_decl (this_quals, parm);
12079 233654409 : return parm;
12080 : }
12081 :
12082 : /* DECL is a static member function. Complain if it was declared
12083 : with function-cv-quals. */
12084 :
12085 : static void
12086 10364695 : check_static_quals (tree decl, cp_cv_quals quals)
12087 : {
12088 0 : if (quals != TYPE_UNQUALIFIED)
12089 6 : error ("static member function %q#D declared with type qualifiers",
12090 : decl);
12091 0 : }
12092 :
12093 : /* Helper function. Replace the temporary this parameter injected
12094 : during cp_finish_omp_declare_simd with the real this parameter. */
12095 :
12096 : static tree
12097 2692 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
12098 : {
12099 2692 : tree this_parm = (tree) data;
12100 2692 : if (TREE_CODE (*tp) == PARM_DECL
12101 450 : && DECL_NAME (*tp) == this_identifier
12102 2965 : && *tp != this_parm)
12103 273 : *tp = this_parm;
12104 2419 : else if (TYPE_P (*tp))
12105 33 : *walk_subtrees = 0;
12106 2692 : return NULL_TREE;
12107 : }
12108 :
12109 : /* CTYPE is class type, or null if non-class.
12110 : TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
12111 : or METHOD_TYPE.
12112 : DECLARATOR is the function's name.
12113 : PARMS is a chain of PARM_DECLs for the function.
12114 : VIRTUALP is truthvalue of whether the function is virtual or not.
12115 : FLAGS are to be passed through to `grokclassfn'.
12116 : QUALS are qualifiers indicating whether the function is `const'
12117 : or `volatile'.
12118 : RAISES is a list of exceptions that this function can raise.
12119 : CHECK is 1 if we must find this method in CTYPE, 0 if we should
12120 : not look, and -1 if we should not call `grokclassfn' at all.
12121 :
12122 : SFK is the kind of special function (if any) for the new function.
12123 :
12124 : Returns `NULL_TREE' if something goes wrong, after issuing
12125 : applicable error messages. */
12126 :
12127 : static tree
12128 186050242 : grokfndecl (tree ctype,
12129 : tree type,
12130 : tree declarator,
12131 : tree parms,
12132 : tree orig_declarator,
12133 : const cp_decl_specifier_seq *declspecs,
12134 : tree decl_reqs,
12135 : int virtualp,
12136 : enum overload_flags flags,
12137 : cp_cv_quals quals,
12138 : cp_ref_qualifier rqual,
12139 : tree raises,
12140 : int check,
12141 : int friendp,
12142 : int publicp,
12143 : int inlinep,
12144 : int initialized,
12145 : bool xobj_func_p,
12146 : special_function_kind sfk,
12147 : bool funcdef_flag,
12148 : bool late_return_type_p,
12149 : int template_count,
12150 : tree in_namespace,
12151 : tree* attrlist,
12152 : tree contract_specifiers,
12153 : location_t location)
12154 : {
12155 186050242 : tree decl;
12156 186050242 : tree t;
12157 :
12158 186050242 : if (location == UNKNOWN_LOCATION)
12159 0 : location = input_location;
12160 :
12161 : /* Was the concept specifier present? */
12162 186050242 : bool concept_p = inlinep & 4;
12163 :
12164 186050242 : if (concept_p)
12165 : {
12166 15 : error_at (location, "function concepts are no longer supported");
12167 15 : return NULL_TREE;
12168 : }
12169 :
12170 186050227 : type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
12171 :
12172 186050227 : decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
12173 :
12174 : /* Set the constraints on the declaration. */
12175 186050227 : if (flag_concepts)
12176 : {
12177 181774074 : tree tmpl_reqs = NULL_TREE;
12178 181774074 : tree ctx = friendp ? current_class_type : ctype;
12179 181774074 : bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
12180 181774074 : bool memtmpl = (!block_local
12181 181774074 : && (current_template_depth
12182 181718124 : > template_class_depth (ctx)));
12183 50036734 : if (memtmpl)
12184 : {
12185 50036734 : if (!current_template_parms)
12186 : /* If there are no template parameters, something must have
12187 : gone wrong. */
12188 0 : gcc_assert (seen_error ());
12189 : else
12190 50036734 : tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
12191 : }
12192 181774074 : tree ci = build_constraints (tmpl_reqs, decl_reqs);
12193 : /* C++20 CA378: Remove non-templated constrained functions. */
12194 : /* [temp.friend]/9 A non-template friend declaration with a
12195 : requires-clause shall be a definition. A friend function template with
12196 : a constraint that depends on a template parameter from an enclosing
12197 : template shall be a definition. */
12198 181774074 : if (ci
12199 9387382 : && (block_local
12200 9387379 : || !processing_template_decl
12201 9387319 : || (friendp && !memtmpl && !funcdef_flag)))
12202 : {
12203 72 : if (!friendp || !processing_template_decl)
12204 63 : error_at (location, "constraints on a non-templated function");
12205 : else
12206 9 : error_at (location, "constrained non-template friend declaration"
12207 : " must be a definition");
12208 : ci = NULL_TREE;
12209 : }
12210 181774074 : set_constraints (decl, ci);
12211 1156788 : if (ci && friendp && memtmpl && !funcdef_flag
12212 181810372 : && uses_outer_template_parms_in_constraints (decl, ctx))
12213 6 : error_at (location, "friend function template with constraints that "
12214 : "depend on outer template parameters must be a definition");
12215 : }
12216 :
12217 186050227 : if (TREE_CODE (type) == METHOD_TYPE)
12218 : {
12219 100537009 : tree parm = build_this_parm (decl, type, quals);
12220 100537009 : DECL_CHAIN (parm) = parms;
12221 100537009 : parms = parm;
12222 :
12223 : /* Allocate space to hold the vptr bit if needed. */
12224 100537009 : SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
12225 : }
12226 :
12227 186050227 : DECL_ARGUMENTS (decl) = parms;
12228 562282231 : for (t = parms; t; t = DECL_CHAIN (t))
12229 : {
12230 376232004 : DECL_CONTEXT (t) = decl;
12231 376232004 : if (flag_reflection
12232 3459328 : && initialized == SD_INITIALIZED
12233 376922995 : && DECL_ATTRIBUTES (t))
12234 1625 : for (tree a = DECL_ATTRIBUTES (t);
12235 1627 : (a = lookup_attribute ("internal ", "annotation ", a));
12236 2 : a = TREE_CHAIN (a))
12237 : {
12238 2 : gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
12239 : /* Mark TREE_PURPOSE of the value that it is an annotation
12240 : on an argument of a function definition (rather than
12241 : annotation from function declaration). For function parameter
12242 : reflection all annotations are listed, while for variable_of
12243 : only those marked here. Annotation is marked as coming from
12244 : function definition's argument if it has TREE_PURPOSE
12245 : void_node or INTEGER_CST with signed type. */
12246 2 : tree val = TREE_VALUE (a);
12247 2 : gcc_assert (TREE_PURPOSE (val) == NULL_TREE);
12248 2 : TREE_PURPOSE (val) = void_node;
12249 : }
12250 : }
12251 :
12252 : /* Propagate volatile out from type to decl. */
12253 186050227 : if (TYPE_VOLATILE (type))
12254 0 : TREE_THIS_VOLATILE (decl) = 1;
12255 :
12256 : /* Setup decl according to sfk. */
12257 186050227 : switch (sfk)
12258 : {
12259 23914041 : case sfk_constructor:
12260 23914041 : case sfk_copy_constructor:
12261 23914041 : case sfk_move_constructor:
12262 23914041 : DECL_CXX_CONSTRUCTOR_P (decl) = 1;
12263 23914041 : DECL_NAME (decl) = ctor_identifier;
12264 23914041 : break;
12265 3227661 : case sfk_destructor:
12266 3227661 : DECL_CXX_DESTRUCTOR_P (decl) = 1;
12267 3227661 : DECL_NAME (decl) = dtor_identifier;
12268 3227661 : break;
12269 1183331 : case sfk_deduction_guide:
12270 : /* Give deduction guides a definition even though they don't really
12271 : have one: the restriction that you can't repeat a deduction guide
12272 : makes them more like a definition anyway. */
12273 1183331 : DECL_INITIAL (decl) = void_node;
12274 : /* But to ensure that external-linkage deduction guides in header units
12275 : don't fall afoul of [module.import] p6, mark them as inline. */
12276 1183331 : DECL_DECLARED_INLINE_P (decl) = true;
12277 1183331 : break;
12278 : default:
12279 : break;
12280 : }
12281 :
12282 186050227 : if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
12283 : {
12284 92088 : if (funcdef_flag)
12285 3 : error_at (location,
12286 : "defining explicit specialization %qD in friend declaration",
12287 : orig_declarator);
12288 : else
12289 : {
12290 92085 : tree fns = TREE_OPERAND (orig_declarator, 0);
12291 92085 : tree args = TREE_OPERAND (orig_declarator, 1);
12292 :
12293 92085 : if (PROCESSING_REAL_TEMPLATE_DECL_P ())
12294 : {
12295 : /* Something like `template <class T> friend void f<T>()'. */
12296 6 : error_at (location,
12297 : "invalid use of template-id %qD in declaration "
12298 : "of primary template",
12299 : orig_declarator);
12300 6 : return NULL_TREE;
12301 : }
12302 :
12303 : /* A friend declaration of the form friend void f<>(). Record
12304 : the information in the TEMPLATE_ID_EXPR. */
12305 92079 : SET_DECL_IMPLICIT_INSTANTIATION (decl);
12306 :
12307 92079 : gcc_assert (identifier_p (fns) || OVL_P (fns));
12308 92079 : DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
12309 :
12310 : /* Remember the befriending class like push_template_decl does for
12311 : template friends. */
12312 92079 : gcc_checking_assert (!DECL_CHAIN (decl));
12313 92079 : DECL_CHAIN (decl) = current_scope ();
12314 :
12315 298363 : for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
12316 206289 : if (TREE_PURPOSE (t)
12317 206289 : && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
12318 : {
12319 5 : error_at (defparse_location (TREE_PURPOSE (t)),
12320 : "default arguments are not allowed in declaration "
12321 : "of friend template specialization %qD",
12322 : decl);
12323 5 : return NULL_TREE;
12324 : }
12325 :
12326 92074 : if (inlinep & 1)
12327 : {
12328 5 : error_at (declspecs->locations[ds_inline],
12329 : "%<inline%> is not allowed in declaration of friend "
12330 : "template specialization %qD",
12331 : decl);
12332 5 : return NULL_TREE;
12333 : }
12334 : }
12335 : }
12336 :
12337 : /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
12338 : expression, that declaration shall be a definition..." */
12339 186050211 : if (friendp && !funcdef_flag)
12340 : {
12341 1794716 : bool has_errored = false;
12342 1794716 : for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
12343 5040608 : t && t != void_list_node; t = TREE_CHAIN (t))
12344 3245892 : if (TREE_PURPOSE (t))
12345 : {
12346 51 : enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
12347 : /* For templates, mark the default argument as erroneous and give a
12348 : hard error. */
12349 51 : if (processing_template_decl)
12350 : {
12351 33 : diag_kind = diagnostics::kind::error;
12352 33 : TREE_PURPOSE (t) = error_mark_node;
12353 : }
12354 51 : if (!has_errored)
12355 : {
12356 48 : has_errored = true;
12357 48 : emit_diagnostic (diag_kind,
12358 48 : DECL_SOURCE_LOCATION (decl),
12359 48 : /*diagnostics::option_id=*/0,
12360 : "friend declaration of %qD specifies default "
12361 : "arguments and isn%'t a definition", decl);
12362 : }
12363 : }
12364 : }
12365 :
12366 : /* If this decl has namespace scope, set that up. */
12367 186050211 : if (in_namespace)
12368 223895 : set_decl_namespace (decl, in_namespace, friendp);
12369 185826316 : else if (ctype)
12370 110803971 : DECL_CONTEXT (decl) = ctype;
12371 : else
12372 75022345 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
12373 :
12374 : /* `main' and builtins have implicit 'C' linkage. */
12375 186050211 : if (ctype == NULL_TREE
12376 75246240 : && DECL_FILE_SCOPE_P (decl)
12377 31245098 : && current_lang_name == lang_name_cplusplus
12378 189007759 : && (MAIN_NAME_P (declarator)
12379 2924118 : || (IDENTIFIER_LENGTH (declarator) > 10
12380 2100358 : && IDENTIFIER_POINTER (declarator)[0] == '_'
12381 1637918 : && IDENTIFIER_POINTER (declarator)[1] == '_'
12382 345724 : && startswith (IDENTIFIER_POINTER (declarator) + 2,
12383 : "builtin_"))
12384 2924100 : || (targetcm.cxx_implicit_extern_c
12385 0 : && (targetcm.cxx_implicit_extern_c
12386 0 : (IDENTIFIER_POINTER (declarator))))))
12387 33448 : SET_DECL_LANGUAGE (decl, lang_c);
12388 :
12389 186050211 : DECL_STATIC_FUNCTION_P (decl)
12390 186050211 : = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
12391 186050211 : DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
12392 :
12393 186050211 : if (initialized == SD_DELETED)
12394 4129092 : DECL_DELETED_FN (decl) = 1;
12395 :
12396 186050211 : if (ctype && funcdef_flag)
12397 95685104 : check_class_member_definition_namespace (decl);
12398 :
12399 186050211 : if (ctype == NULL_TREE && DECL_MAIN_P (decl))
12400 : {
12401 33436 : if (PROCESSING_REAL_TEMPLATE_DECL_P())
12402 9 : error_at (location, "cannot declare %<::main%> to be a template");
12403 33436 : if (inlinep & 1)
12404 3 : error_at (declspecs->locations[ds_inline],
12405 : "cannot declare %<::main%> to be inline");
12406 33436 : if (inlinep & 2)
12407 6 : error_at (declspecs->locations[ds_constexpr],
12408 : "cannot declare %<::main%> to be %qs", "constexpr");
12409 33436 : if (inlinep & 8)
12410 3 : error_at (declspecs->locations[ds_consteval],
12411 : "cannot declare %<::main%> to be %qs", "consteval");
12412 33436 : if (!publicp)
12413 0 : error_at (location, "cannot declare %<::main%> to be static");
12414 33436 : if (current_lang_name != lang_name_cplusplus)
12415 12 : pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
12416 : " linkage specification other than %<extern \"C++\"%>");
12417 33436 : if (module_attach_p ())
12418 : {
12419 3 : auto_diagnostic_group adg;
12420 3 : error_at (location, "cannot attach %<::main%> to a named module");
12421 3 : inform (location, "use %<extern \"C++\"%> to attach it to the "
12422 : "global module instead");
12423 3 : }
12424 : inlinep = 0;
12425 : publicp = 1;
12426 : }
12427 :
12428 : /* Members of anonymous types and local classes have no linkage; make
12429 : them internal. If a typedef is made later, this will be changed. */
12430 186050211 : if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
12431 : publicp = 0;
12432 186037085 : else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
12433 : /* But members of local classes in a module CMI should have their
12434 : definitions exported, in case they are (directly or indirectly)
12435 : used by an importer. We don't just use module_has_cmi_p here
12436 : because for entities in the GMF we don't yet know whether this
12437 : module will have a CMI, so we'll conservatively assume it might. */
12438 2161623 : publicp = module_maybe_has_cmi_p ();
12439 :
12440 186037085 : if (publicp && cxx_dialect == cxx98)
12441 : {
12442 : /* [basic.link]: A name with no linkage (notably, the name of a class
12443 : or enumeration declared in a local scope) shall not be used to
12444 : declare an entity with linkage.
12445 :
12446 : DR 757 relaxes this restriction for C++0x. */
12447 1147000 : no_linkage_error (decl);
12448 : }
12449 :
12450 186050211 : TREE_PUBLIC (decl) = publicp;
12451 186050211 : if (! publicp)
12452 : {
12453 2277745 : DECL_INTERFACE_KNOWN (decl) = 1;
12454 2277745 : DECL_NOT_REALLY_EXTERN (decl) = 1;
12455 : }
12456 :
12457 : /* If the declaration was declared inline, mark it as such. */
12458 186050211 : if (inlinep)
12459 : {
12460 70258787 : DECL_DECLARED_INLINE_P (decl) = 1;
12461 70258787 : if (publicp)
12462 70018901 : DECL_COMDAT (decl) = 1;
12463 : }
12464 70258787 : if (inlinep & 2)
12465 51377516 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
12466 134672695 : else if (inlinep & 8)
12467 : {
12468 959133 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
12469 959133 : SET_DECL_IMMEDIATE_FUNCTION_P (decl);
12470 : }
12471 :
12472 186050211 : DECL_EXTERNAL (decl) = 1;
12473 186050211 : if (TREE_CODE (type) == FUNCTION_TYPE)
12474 : {
12475 85513202 : if (quals || rqual)
12476 272 : TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
12477 : TYPE_UNQUALIFIED,
12478 : REF_QUAL_NONE);
12479 85513202 : auto_diagnostic_group d;
12480 85513202 : if (quals)
12481 423 : error (!ctype
12482 : ? G_("non-member function %qD cannot have cv-qualifier")
12483 : : !xobj_func_p
12484 198 : ? G_("static member function %qD cannot have cv-qualifier")
12485 : : G_("explicit object member function "
12486 : "%qD cannot have cv-qualifier"),
12487 : decl);
12488 85513202 : if (rqual)
12489 355 : error (!ctype
12490 : ? G_("non-member function %qD cannot have ref-qualifier")
12491 : : !xobj_func_p
12492 176 : ? G_("static member function %qD cannot have ref-qualifier")
12493 : : G_("explicit object member function "
12494 : "%qD cannot have ref-qualifier"),
12495 : decl);
12496 :
12497 85513202 : if (xobj_func_p && (quals || rqual))
12498 242 : inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
12499 : "explicit object parameter declared here");
12500 85513202 : quals = TYPE_UNQUALIFIED;
12501 85513202 : rqual = REF_QUAL_NONE;
12502 :
12503 85513202 : }
12504 :
12505 186050211 : if (deduction_guide_p (decl))
12506 : {
12507 1183331 : tree type = TREE_TYPE (DECL_NAME (decl));
12508 1183331 : if (in_namespace == NULL_TREE
12509 1183331 : && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
12510 : {
12511 3 : auto_diagnostic_group d;
12512 3 : error_at (location, "deduction guide %qD must be declared in the "
12513 : "same scope as %qT", decl, type);
12514 3 : inform (location_of (type), " declared here");
12515 3 : return NULL_TREE;
12516 3 : }
12517 2366656 : if (DECL_CLASS_SCOPE_P (decl)
12518 1183368 : && current_access_specifier != declared_access (TYPE_NAME (type)))
12519 : {
12520 3 : auto_diagnostic_group d;
12521 3 : error_at (location, "deduction guide %qD must have the same access "
12522 : "as %qT", decl, type);
12523 3 : inform (location_of (type), " declared here");
12524 3 : }
12525 1183328 : if (funcdef_flag)
12526 3 : error_at (location,
12527 : "deduction guide %qD must not have a function body", decl);
12528 : }
12529 344922079 : else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
12530 196553266 : && !grok_op_properties (decl, /*complain=*/true))
12531 : return NULL_TREE;
12532 184866733 : else if (UDLIT_OPER_P (DECL_NAME (decl)))
12533 : {
12534 303483 : bool long_long_unsigned_p;
12535 303483 : bool long_double_p;
12536 303483 : const char *suffix = NULL;
12537 : /* [over.literal]/6: Literal operators shall not have C linkage. */
12538 303483 : if (DECL_LANGUAGE (decl) == lang_c)
12539 : {
12540 6 : auto_diagnostic_group d;
12541 6 : error_at (location, "literal operator with C linkage");
12542 6 : maybe_show_extern_c_location ();
12543 6 : return NULL_TREE;
12544 6 : }
12545 :
12546 303477 : if (DECL_NAMESPACE_SCOPE_P (decl))
12547 : {
12548 303471 : if (!check_literal_operator_args (decl, &long_long_unsigned_p,
12549 : &long_double_p))
12550 : {
12551 42 : error_at (location, "%qD has invalid argument list", decl);
12552 42 : return NULL_TREE;
12553 : }
12554 :
12555 303429 : suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
12556 303429 : if (long_long_unsigned_p)
12557 : {
12558 45527 : if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
12559 68 : warning_at (location, 0, "integer suffix %qs"
12560 : " shadowed by implementation", suffix);
12561 : }
12562 257902 : else if (long_double_p)
12563 : {
12564 83689 : if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
12565 80 : warning_at (location, 0, "floating-point suffix %qs"
12566 : " shadowed by implementation", suffix);
12567 : }
12568 : /* 17.6.3.3.5 */
12569 303429 : if (suffix[0] != '_'
12570 302854 : && !current_function_decl && !(friendp && !funcdef_flag))
12571 302848 : warning_at (location, OPT_Wliteral_suffix,
12572 : "literal operator suffixes not preceded by %<_%>"
12573 : " are reserved for future standardization");
12574 : }
12575 : else
12576 : {
12577 6 : error_at (location, "%qD must be a non-member function", decl);
12578 6 : return NULL_TREE;
12579 : }
12580 : }
12581 :
12582 184866682 : if (funcdef_flag)
12583 : /* Make the init_value nonzero so pushdecl knows this is not
12584 : tentative. error_mark_node is replaced later with the BLOCK. */
12585 130965007 : DECL_INITIAL (decl) = error_mark_node;
12586 :
12587 186050007 : if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
12588 70608722 : TREE_NOTHROW (decl) = 1;
12589 :
12590 186050007 : if (flag_openmp || flag_openmp_simd)
12591 : {
12592 : /* Adjust "omp declare simd" attributes. */
12593 473747 : tree ods = lookup_attribute ("omp declare simd", *attrlist);
12594 473747 : if (ods)
12595 : {
12596 : tree attr;
12597 2033 : for (attr = ods; attr;
12598 1078 : attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
12599 : {
12600 1078 : if (TREE_CODE (type) == METHOD_TYPE)
12601 204 : walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
12602 : DECL_ARGUMENTS (decl), NULL);
12603 1078 : if (TREE_VALUE (attr) != NULL_TREE)
12604 : {
12605 872 : tree cl = TREE_VALUE (TREE_VALUE (attr));
12606 872 : cl = c_omp_declare_simd_clauses_to_numbers
12607 872 : (DECL_ARGUMENTS (decl), cl);
12608 872 : if (cl)
12609 872 : TREE_VALUE (TREE_VALUE (attr)) = cl;
12610 : else
12611 0 : TREE_VALUE (attr) = NULL_TREE;
12612 : }
12613 : }
12614 : }
12615 : }
12616 :
12617 : /* Caller will do the rest of this. */
12618 186050007 : if (check < 0)
12619 : {
12620 6298717 : if (decl && decl != error_mark_node && contract_specifiers)
12621 16 : set_fn_contract_specifiers (decl, contract_specifiers);
12622 6298717 : return decl;
12623 : }
12624 :
12625 179751290 : if (ctype != NULL_TREE)
12626 110803665 : grokclassfn (ctype, decl, flags);
12627 :
12628 : /* 12.4/3 */
12629 179751290 : if (cxx_dialect >= cxx11
12630 357227728 : && DECL_DESTRUCTOR_P (decl)
12631 3206245 : && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
12632 179915520 : && !processing_template_decl)
12633 84084 : deduce_noexcept_on_destructor (decl);
12634 :
12635 179751290 : set_originating_module (decl);
12636 :
12637 179751290 : decl = check_explicit_specialization (orig_declarator, decl,
12638 : template_count,
12639 179751290 : 2 * funcdef_flag +
12640 179751290 : 4 * (friendp != 0),
12641 : *attrlist);
12642 179751290 : if (decl == error_mark_node)
12643 : return NULL_TREE;
12644 :
12645 179751043 : if (DECL_STATIC_FUNCTION_P (decl))
12646 10193366 : check_static_quals (decl, quals);
12647 :
12648 179751043 : if (attrlist)
12649 : {
12650 179751043 : cplus_decl_attributes (&decl, *attrlist, 0);
12651 179751043 : *attrlist = NULL_TREE;
12652 : }
12653 :
12654 : /* Update now we have a decl and maybe know the return type. */
12655 179751043 : if (contract_specifiers)
12656 : {
12657 550 : tree t = decl;
12658 550 : if (TREE_CODE (decl) == TEMPLATE_DECL)
12659 2 : t = DECL_TEMPLATE_RESULT (decl);
12660 550 : set_fn_contract_specifiers (t, contract_specifiers);
12661 550 : rebuild_postconditions (t);
12662 : }
12663 :
12664 : /* Check main's type after attributes have been applied. */
12665 179751043 : if (ctype == NULL_TREE && DECL_MAIN_P (decl))
12666 : {
12667 33424 : if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
12668 : integer_type_node))
12669 : {
12670 19 : tree dtype = TREE_TYPE (decl);
12671 19 : tree oldtypeargs = TYPE_ARG_TYPES (dtype);
12672 19 : tree newtype;
12673 19 : error_at (declspecs->locations[ds_type_spec],
12674 : "%<::main%> must return %<int%>");
12675 57 : newtype = build_function_type (integer_type_node, oldtypeargs,
12676 19 : TYPE_NO_NAMED_ARGS_STDARG_P (dtype));
12677 19 : TREE_TYPE (decl) = newtype;
12678 : }
12679 33424 : if (warn_main)
12680 33402 : check_main_parameter_types (decl);
12681 : }
12682 :
12683 179751043 : if (ctype != NULL_TREE && check)
12684 : {
12685 8864688 : tree old_decl = check_classfn (ctype, decl,
12686 8864688 : (current_template_depth
12687 8864688 : > template_class_depth (ctype))
12688 2148842 : ? current_template_parms
12689 : : NULL_TREE);
12690 :
12691 8864688 : if (old_decl == error_mark_node)
12692 : return NULL_TREE;
12693 :
12694 8864580 : if (old_decl)
12695 : {
12696 8471217 : tree ok;
12697 8471217 : tree pushed_scope;
12698 :
12699 8471217 : if (TREE_CODE (old_decl) == TEMPLATE_DECL)
12700 : /* Because grokfndecl is always supposed to return a
12701 : FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
12702 : here. We depend on our callers to figure out that its
12703 : really a template that's being returned. */
12704 2148830 : old_decl = DECL_TEMPLATE_RESULT (old_decl);
12705 :
12706 8471217 : if (DECL_STATIC_FUNCTION_P (old_decl)
12707 8471217 : && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
12708 : {
12709 : /* Remove the `this' parm added by grokclassfn. */
12710 171329 : revert_static_member_fn (decl);
12711 171329 : check_static_quals (decl, quals);
12712 : }
12713 8471217 : if (DECL_ARTIFICIAL (old_decl))
12714 : {
12715 9 : error ("definition of implicitly-declared %qD", old_decl);
12716 9 : return NULL_TREE;
12717 : }
12718 8471208 : else if (DECL_DEFAULTED_FN (old_decl))
12719 : {
12720 3 : auto_diagnostic_group d;
12721 3 : error ("definition of explicitly-defaulted %q+D", decl);
12722 3 : inform (DECL_SOURCE_LOCATION (old_decl),
12723 : "%q#D explicitly defaulted here", old_decl);
12724 3 : return NULL_TREE;
12725 3 : }
12726 :
12727 8471205 : if (modules_p () && !module_may_redeclare (old_decl))
12728 : return NULL_TREE;
12729 :
12730 : /* Since we've smashed OLD_DECL to its
12731 : DECL_TEMPLATE_RESULT, we must do the same to DECL. */
12732 8471145 : if (TREE_CODE (decl) == TEMPLATE_DECL)
12733 1188 : decl = DECL_TEMPLATE_RESULT (decl);
12734 :
12735 : /* Attempt to merge the declarations. This can fail, in
12736 : the case of some invalid specialization declarations. */
12737 8471145 : pushed_scope = push_scope (ctype);
12738 8471145 : ok = duplicate_decls (decl, old_decl);
12739 8471145 : if (pushed_scope)
12740 8471145 : pop_scope (pushed_scope);
12741 8471145 : if (!ok)
12742 : {
12743 0 : error ("no %q#D member function declared in class %qT",
12744 : decl, ctype);
12745 0 : return NULL_TREE;
12746 : }
12747 8471145 : if (ok == error_mark_node)
12748 : return NULL_TREE;
12749 : return old_decl;
12750 : }
12751 : }
12752 :
12753 342559436 : if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
12754 : return NULL_TREE;
12755 :
12756 : /* Don't call check_consteval_only_fn for defaulted functions. Those are
12757 : immediate-escalating functions but at this point DECL_DEFAULTED_P has
12758 : not been set. */
12759 171279715 : if (initialized != SD_DEFAULTED)
12760 164800575 : check_consteval_only_fn (decl);
12761 :
12762 171279715 : if (ctype == NULL_TREE || check)
12763 69340798 : return decl;
12764 :
12765 101938917 : if (virtualp)
12766 4118544 : DECL_VIRTUAL_P (decl) = 1;
12767 :
12768 101938917 : return decl;
12769 : }
12770 :
12771 : /* decl is a FUNCTION_DECL.
12772 : specifiers are the parsed virt-specifiers.
12773 :
12774 : Set flags to reflect the virt-specifiers.
12775 :
12776 : Returns decl. */
12777 :
12778 : static tree
12779 108237731 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
12780 : {
12781 108237731 : if (decl == NULL_TREE)
12782 : return decl;
12783 108237634 : if (specifiers & VIRT_SPEC_OVERRIDE)
12784 322437 : DECL_OVERRIDE_P (decl) = 1;
12785 108237634 : if (specifiers & VIRT_SPEC_FINAL)
12786 9626 : DECL_FINAL_P (decl) = 1;
12787 : return decl;
12788 : }
12789 :
12790 : /* DECL is a VAR_DECL for a static data member. Set flags to reflect
12791 : the linkage that DECL will receive in the object file. */
12792 :
12793 : static void
12794 13362862 : set_linkage_for_static_data_member (tree decl)
12795 : {
12796 : /* A static data member always has static storage duration and
12797 : external linkage. Note that static data members are forbidden in
12798 : local classes -- the only situation in which a class has
12799 : non-external linkage. */
12800 13362862 : TREE_PUBLIC (decl) = 1;
12801 13362862 : TREE_STATIC (decl) = 1;
12802 : /* For non-template classes, static data members are always put
12803 : out in exactly those files where they are defined, just as
12804 : with ordinary namespace-scope variables. */
12805 13362862 : if (!processing_template_decl)
12806 10184824 : DECL_INTERFACE_KNOWN (decl) = 1;
12807 13362862 : }
12808 :
12809 : /* Create a VAR_DECL named NAME with the indicated TYPE.
12810 :
12811 : If SCOPE is non-NULL, it is the class type or namespace containing
12812 : the variable. If SCOPE is NULL, the variable should is created in
12813 : the innermost enclosing scope. */
12814 :
12815 : static tree
12816 67475601 : grokvardecl (tree type,
12817 : tree name,
12818 : tree orig_declarator,
12819 : const cp_decl_specifier_seq *declspecs,
12820 : int initialized,
12821 : int type_quals,
12822 : int inlinep,
12823 : bool conceptp,
12824 : int template_count,
12825 : tree scope,
12826 : location_t location)
12827 : {
12828 67475601 : tree decl;
12829 67475601 : tree explicit_scope;
12830 :
12831 67475601 : gcc_assert (!name || identifier_p (name));
12832 :
12833 67475601 : bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
12834 67475601 : bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
12835 :
12836 : /* Compute the scope in which to place the variable, but remember
12837 : whether or not that scope was explicitly specified by the user. */
12838 67475601 : explicit_scope = scope;
12839 67475601 : if (!scope)
12840 : {
12841 : /* An explicit "extern" specifier indicates a namespace-scope
12842 : variable. */
12843 66969071 : if (declspecs->storage_class == sc_extern)
12844 550067 : scope = current_decl_namespace ();
12845 66419004 : else if (!at_function_scope_p ())
12846 6965646 : scope = current_scope ();
12847 : }
12848 :
12849 66969071 : if (scope
12850 8022243 : && (/* If the variable is a namespace-scope variable declared in a
12851 : template, we need DECL_LANG_SPECIFIC. */
12852 8022243 : (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
12853 : /* Similarly for namespace-scope variables with language linkage
12854 : other than C++. */
12855 7529928 : || (TREE_CODE (scope) == NAMESPACE_DECL
12856 4351318 : && current_lang_name != lang_name_cplusplus)
12857 : /* Similarly for static data members. */
12858 4612057 : || TYPE_P (scope)
12859 : /* Similarly for explicit specializations. */
12860 4119742 : || (orig_declarator
12861 4119080 : && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
12862 4732365 : decl = build_lang_decl_loc (location, VAR_DECL, name, type);
12863 : else
12864 62743236 : decl = build_decl (location, VAR_DECL, name, type);
12865 :
12866 67475601 : if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
12867 14215 : set_decl_namespace (decl, explicit_scope, 0);
12868 : else
12869 67461386 : DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
12870 :
12871 67475601 : if (declspecs->storage_class == sc_extern)
12872 : {
12873 550067 : DECL_THIS_EXTERN (decl) = 1;
12874 550067 : DECL_EXTERNAL (decl) = !initialized;
12875 : }
12876 :
12877 67475601 : if (DECL_CLASS_SCOPE_P (decl))
12878 : {
12879 492315 : set_linkage_for_static_data_member (decl);
12880 : /* This function is only called with out-of-class definitions. */
12881 492315 : DECL_EXTERNAL (decl) = 0;
12882 492315 : check_class_member_definition_namespace (decl);
12883 : }
12884 : /* At top level, either `static' or no s.c. makes a definition
12885 : (perhaps tentative), and absence of `static' makes it public. */
12886 66983286 : else if (toplevel_bindings_p ())
12887 : {
12888 15057550 : TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
12889 7528775 : && (DECL_THIS_EXTERN (decl)
12890 6940904 : || ! constp
12891 6940904 : || volatilep
12892 6864641 : || inlinep
12893 525900 : || in_template_context
12894 28525 : || processing_specialization
12895 28456 : || module_attach_p ()));
12896 7528775 : TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
12897 : }
12898 : /* Not at top level, only `static' makes a static definition. */
12899 : else
12900 : {
12901 59454511 : TREE_STATIC (decl) = declspecs->storage_class == sc_static;
12902 59454511 : TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
12903 : }
12904 :
12905 67475601 : set_originating_module (decl);
12906 :
12907 67475601 : if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
12908 : {
12909 19474 : if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
12910 : {
12911 19466 : CP_DECL_THREAD_LOCAL_P (decl) = true;
12912 : // NB: Set a tentative TLS model to avoid tls_model attribute
12913 : // warnings due to lack of thread storage duration. It will
12914 : // be updated by cplus_decl_attributes later.
12915 19466 : if (!processing_template_decl)
12916 19342 : set_decl_tls_model (decl, TLS_MODEL_REAL);
12917 : }
12918 19474 : if (declspecs->gnu_thread_keyword_p)
12919 18478 : SET_DECL_GNU_TLS_P (decl);
12920 : }
12921 :
12922 : /* If the type of the decl has no linkage, make sure that we'll
12923 : notice that in mark_used. */
12924 67475601 : if (cxx_dialect > cxx98
12925 67174130 : && decl_linkage (decl) != lk_none
12926 66496991 : && DECL_LANG_SPECIFIC (decl) == NULL
12927 61686938 : && !DECL_EXTERN_C_P (decl)
12928 129162539 : && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
12929 4257 : retrofit_lang_decl (decl);
12930 :
12931 67475601 : if (TREE_PUBLIC (decl))
12932 : {
12933 : /* [basic.link]: A name with no linkage (notably, the name of a class
12934 : or enumeration declared in a local scope) shall not be used to
12935 : declare an entity with linkage.
12936 :
12937 : DR 757 relaxes this restriction for C++0x. */
12938 7954837 : if (cxx_dialect < cxx11)
12939 22848 : no_linkage_error (decl);
12940 : }
12941 : else
12942 59520764 : DECL_INTERFACE_KNOWN (decl) = 1;
12943 :
12944 67475601 : if (DECL_NAME (decl)
12945 67475601 : && MAIN_NAME_P (DECL_NAME (decl)))
12946 : {
12947 12 : if (scope == global_namespace)
12948 6 : error_at (DECL_SOURCE_LOCATION (decl),
12949 : "cannot declare %<::main%> to be a global variable");
12950 6 : else if (DECL_EXTERN_C_P (decl))
12951 3 : error_at (DECL_SOURCE_LOCATION (decl),
12952 : "an entity named %<main%> cannot be declared with "
12953 : "C language linkage");
12954 : }
12955 :
12956 : /* Check if a variable is being declared as a concept. */
12957 67475601 : if (conceptp)
12958 : {
12959 30 : if (!processing_template_decl)
12960 13 : error_at (declspecs->locations[ds_concept],
12961 : "a non-template variable cannot be %<concept%>");
12962 17 : else if (!at_namespace_scope_p ())
12963 2 : error_at (declspecs->locations[ds_concept],
12964 : "concept must be defined at namespace scope");
12965 : else
12966 15 : error_at (declspecs->locations[ds_concept],
12967 : "variable concepts are no longer supported");
12968 30 : return NULL_TREE;
12969 : }
12970 67475571 : else if (flag_concepts
12971 67475571 : && current_template_depth > template_class_depth (scope))
12972 : {
12973 58000767 : tree ci = current_template_constraints ();
12974 58000767 : set_constraints (decl, ci);
12975 : }
12976 :
12977 : // Handle explicit specializations and instantiations of variable templates.
12978 67475571 : if (orig_declarator)
12979 66789207 : decl = check_explicit_specialization (orig_declarator, decl,
12980 : template_count, 0);
12981 :
12982 67475571 : return decl != error_mark_node ? decl : NULL_TREE;
12983 : }
12984 :
12985 : /* Create and return a canonical pointer to member function type, for
12986 : TYPE, which is a POINTER_TYPE to a METHOD_TYPE. */
12987 :
12988 : tree
12989 3118260 : build_ptrmemfunc_type (tree type)
12990 : {
12991 3118260 : tree field, fields;
12992 3118260 : tree t;
12993 :
12994 3118260 : if (type == error_mark_node)
12995 : return type;
12996 :
12997 : /* Make sure that we always have the unqualified pointer-to-member
12998 : type first. */
12999 3118260 : if (cp_cv_quals quals = cp_type_quals (type))
13000 : {
13001 0 : tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
13002 0 : return cp_build_qualified_type (unqual, quals);
13003 : }
13004 :
13005 : /* If a canonical type already exists for this type, use it. We use
13006 : this method instead of type_hash_canon, because it only does a
13007 : simple equality check on the list of field members. */
13008 :
13009 3118260 : t = TYPE_PTRMEMFUNC_TYPE (type);
13010 3118260 : if (t)
13011 : return t;
13012 :
13013 1033377 : t = make_node (RECORD_TYPE);
13014 :
13015 : /* Let the front end know this is a pointer to member function. */
13016 1033377 : TYPE_PTRMEMFUNC_FLAG (t) = 1;
13017 :
13018 1033377 : field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
13019 1033377 : DECL_NONADDRESSABLE_P (field) = 1;
13020 1033377 : fields = field;
13021 :
13022 1033377 : field = build_decl (input_location, FIELD_DECL, delta_identifier,
13023 : delta_type_node);
13024 1033377 : DECL_NONADDRESSABLE_P (field) = 1;
13025 1033377 : DECL_CHAIN (field) = fields;
13026 1033377 : fields = field;
13027 :
13028 1033377 : finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
13029 :
13030 : /* Zap out the name so that the back end will give us the debugging
13031 : information for this anonymous RECORD_TYPE. */
13032 1033377 : TYPE_NAME (t) = NULL_TREE;
13033 :
13034 : /* Cache this pointer-to-member type so that we can find it again
13035 : later. */
13036 1033377 : TYPE_PTRMEMFUNC_TYPE (type) = t;
13037 :
13038 1033377 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
13039 500156 : SET_TYPE_STRUCTURAL_EQUALITY (t);
13040 533221 : else if (TYPE_CANONICAL (type) != type)
13041 347494 : TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
13042 :
13043 : return t;
13044 : }
13045 :
13046 : /* Create and return a pointer to data member type. */
13047 :
13048 : tree
13049 320281 : build_ptrmem_type (tree class_type, tree member_type)
13050 : {
13051 320281 : if (TREE_CODE (member_type) == METHOD_TYPE)
13052 : {
13053 58527 : cp_cv_quals quals = type_memfn_quals (member_type);
13054 58527 : cp_ref_qualifier rqual = type_memfn_rqual (member_type);
13055 58527 : member_type = build_memfn_type (member_type, class_type, quals, rqual);
13056 58527 : return build_ptrmemfunc_type (build_pointer_type (member_type));
13057 : }
13058 : else
13059 : {
13060 261754 : gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
13061 261754 : return build_offset_type (class_type, member_type);
13062 : }
13063 : }
13064 :
13065 : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
13066 : Check to see that the definition is valid. Issue appropriate error
13067 : messages. */
13068 :
13069 : static void
13070 18263002 : check_static_variable_definition (tree decl, tree type)
13071 : {
13072 : /* Avoid redundant diagnostics on out-of-class definitions. */
13073 18263002 : if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
13074 : ;
13075 : /* Can't check yet if we don't know the type. */
13076 16908427 : else if (dependent_type_p (type))
13077 : ;
13078 : /* If DECL is declared constexpr, we'll do the appropriate checks
13079 : in check_initializer. Similarly for inline static data members. */
13080 16382112 : else if (DECL_P (decl)
13081 16382112 : && (DECL_DECLARED_CONSTEXPR_P (decl)
13082 2645651 : || DECL_VAR_DECLARED_INLINE_P (decl)))
13083 : ;
13084 2645175 : else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
13085 : {
13086 56 : if (!COMPLETE_TYPE_P (type))
13087 11 : error_at (DECL_SOURCE_LOCATION (decl),
13088 : "in-class initialization of static data member %q#D of "
13089 : "incomplete type", decl);
13090 45 : else if (literal_type_p (type))
13091 39 : permerror (DECL_SOURCE_LOCATION (decl),
13092 : "%<constexpr%> needed for in-class initialization of "
13093 : "static data member %q#D of non-integral type", decl);
13094 : else
13095 6 : error_at (DECL_SOURCE_LOCATION (decl),
13096 : "in-class initialization of static data member %q#D of "
13097 : "non-literal type", decl);
13098 : }
13099 : /* Motion 10 at San Diego: If a static const integral data member is
13100 : initialized with an integral constant expression, the initializer
13101 : may appear either in the declaration (within the class), or in
13102 : the definition, but not both. If it appears in the class, the
13103 : member is a member constant. The file-scope definition is always
13104 : required. */
13105 2645119 : else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
13106 11 : error_at (DECL_SOURCE_LOCATION (decl),
13107 : "invalid in-class initialization of static data member "
13108 : "of non-integral type %qT",
13109 : type);
13110 2645108 : else if (!CP_TYPE_CONST_P (type))
13111 5 : error_at (DECL_SOURCE_LOCATION (decl),
13112 : "ISO C++ forbids in-class initialization of non-const "
13113 : "static member %qD",
13114 : decl);
13115 2645103 : else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
13116 5 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
13117 : "ISO C++ forbids initialization of member constant "
13118 : "%qD of non-integral type %qT", decl, type);
13119 18263002 : }
13120 :
13121 : /* *expr_p is part of the TYPE_SIZE of a variably-sized array. If any
13122 : SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
13123 : expressions out into temporary variables so that walk_tree doesn't
13124 : step into them (c++/15764). */
13125 :
13126 : static tree
13127 3404 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
13128 : {
13129 3404 : hash_set<tree> *pset = (hash_set<tree> *)data;
13130 3404 : tree expr = *expr_p;
13131 3404 : if (TREE_CODE (expr) == SAVE_EXPR)
13132 : {
13133 1483 : tree op = TREE_OPERAND (expr, 0);
13134 1483 : cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
13135 1483 : if (TREE_SIDE_EFFECTS (op))
13136 56 : TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
13137 1483 : *walk_subtrees = 0;
13138 : }
13139 1921 : else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
13140 1746 : *walk_subtrees = 0;
13141 3404 : return NULL;
13142 : }
13143 :
13144 : /* Entry point for the above. */
13145 :
13146 : static void
13147 1542 : stabilize_vla_size (tree size)
13148 : {
13149 1542 : hash_set<tree> pset;
13150 : /* Break out any function calls into temporary variables. */
13151 1542 : cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
13152 1542 : }
13153 :
13154 : /* Reduce a SIZEOF_EXPR to its value. */
13155 :
13156 : tree
13157 11529284 : fold_sizeof_expr (tree t)
13158 : {
13159 11529284 : tree r;
13160 11529284 : if (SIZEOF_EXPR_TYPE_P (t))
13161 10973062 : r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
13162 10973062 : TREE_TYPE (TREE_OPERAND (t, 0)),
13163 : SIZEOF_EXPR, false, false);
13164 556222 : else if (TYPE_P (TREE_OPERAND (t, 0)))
13165 0 : r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
13166 0 : TREE_OPERAND (t, 0), SIZEOF_EXPR,
13167 : false, false);
13168 : else
13169 556222 : r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
13170 556222 : TREE_OPERAND (t, 0), SIZEOF_EXPR,
13171 : false, false);
13172 11529284 : if (r == error_mark_node)
13173 67 : r = size_one_node;
13174 11529284 : r = cp_fold_convert (size_type_node, r);
13175 11529284 : return r;
13176 : }
13177 :
13178 : /* Given the SIZE (i.e., number of elements) in an array, compute
13179 : an appropriate index type for the array. If non-NULL, NAME is
13180 : the name of the entity being declared. */
13181 :
13182 : static tree
13183 3309843 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
13184 : tsubst_flags_t complain)
13185 : {
13186 3309843 : if (error_operand_p (size))
13187 34 : return error_mark_node;
13188 :
13189 : /* The type of the index being computed. */
13190 3309809 : tree itype;
13191 :
13192 : /* The original numeric size as seen in the source code before
13193 : conversion to size_t. */
13194 3309809 : tree origsize = size;
13195 :
13196 3309809 : location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
13197 :
13198 3309809 : if (!type_dependent_expression_p (size))
13199 : {
13200 3264327 : origsize = size = mark_rvalue_use (size);
13201 :
13202 38608 : if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
13203 3264487 : && TREE_SIDE_EFFECTS (size))
13204 : /* In C++98, we mark a non-constant array bound with a magic
13205 : NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case. */;
13206 : else
13207 : {
13208 3264326 : size = build_converted_constant_expr (size_type_node, size, complain);
13209 : /* Pedantically a constant expression is required here and so
13210 : __builtin_is_constant_evaluated () should fold to true if it
13211 : is successfully folded into a constant. */
13212 3264326 : size = fold_non_dependent_expr (size, complain,
13213 : /*manifestly_const_eval=*/true);
13214 :
13215 3264326 : if (!TREE_CONSTANT (size))
13216 127037 : size = origsize;
13217 : }
13218 :
13219 3264327 : if (error_operand_p (size))
13220 3 : return error_mark_node;
13221 :
13222 : /* The array bound must be an integer type. */
13223 3264324 : tree type = TREE_TYPE (size);
13224 3264324 : if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
13225 : {
13226 21 : if (!(complain & tf_error))
13227 0 : return error_mark_node;
13228 21 : if (name)
13229 18 : error_at (loc, "size of array %qD has non-integral type %qT",
13230 : name, type);
13231 : else
13232 3 : error_at (loc, "size of array has non-integral type %qT", type);
13233 21 : size = integer_one_node;
13234 : }
13235 : }
13236 :
13237 : /* A type is dependent if it is...an array type constructed from any
13238 : dependent type or whose size is specified by a constant expression
13239 : that is value-dependent. */
13240 : /* We can only call value_dependent_expression_p on integral constant
13241 : expressions. */
13242 3309806 : if (processing_template_decl
13243 1469092 : && potential_constant_expression (size)
13244 4778873 : && value_dependent_expression_p (size))
13245 : {
13246 : /* Just build the index type and mark that it requires
13247 : structural equality checks. */
13248 842592 : in_template:
13249 842592 : itype = build_index_type (build_min (MINUS_EXPR, sizetype,
13250 : size, size_one_node));
13251 842592 : TYPE_DEPENDENT_P (itype) = 1;
13252 842592 : TYPE_DEPENDENT_P_VALID (itype) = 1;
13253 842592 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
13254 842592 : return itype;
13255 : }
13256 :
13257 2478362 : if (TREE_CODE (size) != INTEGER_CST)
13258 : {
13259 13089 : tree folded = cp_fully_fold (size);
13260 13089 : if (TREE_CODE (folded) == INTEGER_CST)
13261 : {
13262 217 : if (name)
13263 143 : pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
13264 : "integral constant-expression", name);
13265 : else
13266 74 : pedwarn (loc, OPT_Wpedantic,
13267 : "size of array is not an integral constant-expression");
13268 : }
13269 13089 : if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
13270 : /* We might have lost the TREE_CONSTANT flag e.g. when we are
13271 : folding a conversion from a pointer to integral type. In that
13272 : case issue an error below and don't treat this as a VLA. */;
13273 : else
13274 : /* Use the folded result for VLAs, too; it will have resolved
13275 : SIZEOF_EXPR. */
13276 : size = folded;
13277 : }
13278 :
13279 : /* Normally, the array-bound will be a constant. */
13280 2478362 : if (TREE_CODE (size) == INTEGER_CST)
13281 : {
13282 : /* The size to use in diagnostics that reflects the constant
13283 : size used in the source, rather than SIZE massaged above. */
13284 2465490 : tree diagsize = size;
13285 :
13286 : /* If the original size before conversion to size_t was signed
13287 : and negative, convert it to ssizetype to restore the sign. */
13288 2465490 : if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
13289 : && TREE_CODE (size) == INTEGER_CST
13290 2465490 : && tree_int_cst_sign_bit (size))
13291 : {
13292 236 : diagsize = fold_convert (ssizetype, size);
13293 :
13294 : /* Clear the overflow bit that may have been set as a result
13295 : of the conversion from the sizetype of the new size to
13296 : ssizetype. */
13297 236 : TREE_OVERFLOW (diagsize) = false;
13298 : }
13299 :
13300 : /* Verify that the array has a positive number of elements
13301 : and issue the appropriate diagnostic if it doesn't. */
13302 2465490 : if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
13303 : {
13304 467 : if (!(complain & tf_error))
13305 15 : return error_mark_node;
13306 452 : size = integer_one_node;
13307 : }
13308 : /* As an extension we allow zero-sized arrays. */
13309 2465023 : else if (integer_zerop (size))
13310 : {
13311 3200 : if (!(complain & tf_error))
13312 : /* We must fail if performing argument deduction (as
13313 : indicated by the state of complain), so that
13314 : another substitution can be found. */
13315 8 : return error_mark_node;
13316 3192 : else if (name)
13317 2913 : pedwarn (loc, OPT_Wpedantic,
13318 : "ISO C++ forbids zero-size array %qD", name);
13319 : else
13320 279 : pedwarn (loc, OPT_Wpedantic,
13321 : "ISO C++ forbids zero-size array");
13322 : }
13323 : }
13324 12872 : else if (TREE_CONSTANT (size)
13325 : /* We don't allow VLAs at non-function scopes, or during
13326 : tentative template substitution. */
13327 12857 : || !at_function_scope_p ()
13328 25568 : || !(complain & tf_error))
13329 : {
13330 182 : if (!(complain & tf_error))
13331 134 : return error_mark_node;
13332 : /* `(int) &fn' is not a valid array bound. */
13333 48 : if (name)
13334 37 : error_at (loc,
13335 : "size of array %qD is not an integral constant-expression",
13336 : name);
13337 : else
13338 11 : error_at (loc, "size of array is not an integral constant-expression");
13339 48 : size = integer_one_node;
13340 : }
13341 12690 : else if (pedantic && warn_vla != 0)
13342 : {
13343 30 : if (name)
13344 15 : pedwarn (name_loc, OPT_Wvla,
13345 : "ISO C++ forbids variable length array %qD", name);
13346 : else
13347 15 : pedwarn (input_location, OPT_Wvla,
13348 : "ISO C++ forbids variable length array");
13349 : }
13350 12660 : else if (warn_vla > 0)
13351 : {
13352 3 : if (name)
13353 3 : warning_at (name_loc, OPT_Wvla,
13354 : "variable length array %qD is used", name);
13355 : else
13356 0 : warning (OPT_Wvla,
13357 : "variable length array is used");
13358 : }
13359 :
13360 2478205 : if (processing_template_decl && !TREE_CONSTANT (size))
13361 11148 : goto in_template;
13362 : else
13363 : {
13364 2467057 : if (!TREE_CONSTANT (size))
13365 : {
13366 : /* A variable sized array. Arrange for the SAVE_EXPR on the inside
13367 : of the MINUS_EXPR, which allows the -1 to get folded with the +1
13368 : that happens when building TYPE_SIZE. */
13369 1542 : size = variable_size (size);
13370 1542 : stabilize_vla_size (size);
13371 : }
13372 :
13373 : /* Compute the index of the largest element in the array. It is
13374 : one less than the number of elements in the array. We save
13375 : and restore PROCESSING_TEMPLATE_DECL so that computations in
13376 : cp_build_binary_op will be appropriately folded. */
13377 2467057 : {
13378 2467057 : processing_template_decl_sentinel s;
13379 2467057 : itype = cp_build_binary_op (input_location,
13380 : MINUS_EXPR,
13381 : cp_convert (ssizetype, size, complain),
13382 : cp_convert (ssizetype, integer_one_node,
13383 : complain),
13384 : complain);
13385 2467057 : itype = maybe_constant_value (itype, NULL_TREE, mce_true);
13386 2467057 : }
13387 :
13388 2467057 : if (!TREE_CONSTANT (itype))
13389 : {
13390 1542 : if (sanitize_flags_p (SANITIZE_VLA)
13391 1542 : && current_function_decl != NULL_TREE)
13392 : {
13393 : /* We have to add 1 -- in the ubsan routine we generate
13394 : LE_EXPR rather than LT_EXPR. */
13395 78 : tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
13396 : build_one_cst (TREE_TYPE (itype)));
13397 78 : t = ubsan_instrument_vla (input_location, t);
13398 78 : finish_expr_stmt (t);
13399 : }
13400 : }
13401 : /* Make sure that there was no overflow when creating to a signed
13402 : index type. (For example, on a 32-bit machine, an array with
13403 : size 2^32 - 1 is too big.) */
13404 2465515 : else if (TREE_CODE (itype) == INTEGER_CST
13405 2465515 : && TREE_OVERFLOW (itype))
13406 : {
13407 0 : if (!(complain & tf_error))
13408 0 : return error_mark_node;
13409 0 : error ("overflow in array dimension");
13410 0 : TREE_OVERFLOW (itype) = 0;
13411 : }
13412 : }
13413 :
13414 : /* Create and return the appropriate index type. */
13415 2467057 : itype = build_index_type (itype);
13416 :
13417 : /* If the index type were dependent, we would have returned early, so
13418 : remember that it isn't. */
13419 2467057 : TYPE_DEPENDENT_P (itype) = 0;
13420 2467057 : TYPE_DEPENDENT_P_VALID (itype) = 1;
13421 2467057 : return itype;
13422 : }
13423 :
13424 : tree
13425 574389 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
13426 : {
13427 574389 : return compute_array_index_type_loc (input_location, name, size, complain);
13428 : }
13429 :
13430 : /* Returns the scope (if any) in which the entity declared by
13431 : DECLARATOR will be located. If the entity was declared with an
13432 : unqualified name, NULL_TREE is returned. */
13433 :
13434 : tree
13435 742816835 : get_scope_of_declarator (const cp_declarator *declarator)
13436 : {
13437 860773322 : while (declarator && declarator->kind != cdk_id)
13438 117956487 : declarator = declarator->declarator;
13439 :
13440 : /* If the declarator-id is a SCOPE_REF, the scope in which the
13441 : declaration occurs is the first operand. */
13442 742816835 : if (declarator
13443 741607336 : && declarator->u.id.qualifying_scope)
13444 : return declarator->u.id.qualifying_scope;
13445 :
13446 : /* Otherwise, the declarator is not a qualified name; the entity will
13447 : be declared in the current scope. */
13448 : return NULL_TREE;
13449 : }
13450 :
13451 : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
13452 : indicated TYPE. If non-NULL, NAME is the NAME of the declaration
13453 : with this type. */
13454 :
13455 : static tree
13456 3529803 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
13457 : {
13458 3529803 : tree itype = NULL_TREE;
13459 :
13460 : /* If things have already gone awry, bail now. */
13461 3529803 : if (type == error_mark_node || size == error_mark_node)
13462 : return error_mark_node;
13463 :
13464 : /* [dcl.type.class.deduct] prohibits forming an array of placeholder
13465 : for a deduced class type. */
13466 3529740 : if (template_placeholder_p (type))
13467 : {
13468 6 : if (name)
13469 0 : error_at (loc, "%qD declared as array of template placeholder "
13470 : "type %qT", name, type);
13471 : else
13472 6 : error ("creating array of template placeholder type %qT", type);
13473 6 : return error_mark_node;
13474 : }
13475 :
13476 : /* If there are some types which cannot be array elements,
13477 : issue an error-message and return. */
13478 3529734 : switch (TREE_CODE (type))
13479 : {
13480 3 : case VOID_TYPE:
13481 3 : if (name)
13482 0 : error_at (loc, "declaration of %qD as array of void", name);
13483 : else
13484 3 : error ("creating array of void");
13485 3 : return error_mark_node;
13486 :
13487 6 : case FUNCTION_TYPE:
13488 6 : if (name)
13489 6 : error_at (loc, "declaration of %qD as array of functions", name);
13490 : else
13491 0 : error ("creating array of functions");
13492 6 : return error_mark_node;
13493 :
13494 21 : case REFERENCE_TYPE:
13495 21 : if (name)
13496 15 : error_at (loc, "declaration of %qD as array of references", name);
13497 : else
13498 6 : error ("creating array of references");
13499 21 : return error_mark_node;
13500 :
13501 0 : case METHOD_TYPE:
13502 0 : if (name)
13503 0 : error_at (loc, "declaration of %qD as array of function members",
13504 : name);
13505 : else
13506 0 : error ("creating array of function members");
13507 0 : return error_mark_node;
13508 :
13509 3529704 : default:
13510 3529704 : break;
13511 : }
13512 :
13513 3529704 : if (!verify_type_context (name ? loc : input_location,
13514 : TCTX_ARRAY_ELEMENT, type))
13515 0 : return error_mark_node;
13516 :
13517 : /* [dcl.array]
13518 :
13519 : The constant expressions that specify the bounds of the arrays
13520 : can be omitted only for the first member of the sequence. */
13521 3529704 : if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
13522 : {
13523 30 : if (name)
13524 24 : error_at (loc, "declaration of %qD as multidimensional array must "
13525 : "have bounds for all dimensions except the first",
13526 : name);
13527 : else
13528 6 : error ("multidimensional array must have bounds for all "
13529 : "dimensions except the first");
13530 :
13531 30 : return error_mark_node;
13532 : }
13533 :
13534 : /* Figure out the index type for the array. */
13535 3529674 : if (size)
13536 : {
13537 2735454 : itype = compute_array_index_type_loc (loc, name, size,
13538 : tf_warning_or_error);
13539 2735454 : if (type_uses_auto (type)
13540 2735454 : && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
13541 : {
13542 9 : sorry_at (loc, "variable-length array of %<auto%>");
13543 9 : return error_mark_node;
13544 : }
13545 : }
13546 :
13547 3529665 : return build_cplus_array_type (type, itype);
13548 : }
13549 :
13550 : /* Returns the smallest location that is not UNKNOWN_LOCATION. */
13551 :
13552 : static location_t
13553 1029137636 : min_location (location_t loca, location_t locb)
13554 : {
13555 1029137636 : if (loca == UNKNOWN_LOCATION
13556 1029137636 : || (locb != UNKNOWN_LOCATION
13557 107974600 : && linemap_location_before_p (line_table, locb, loca)))
13558 922324447 : return locb;
13559 : return loca;
13560 : }
13561 :
13562 : /* Returns the smallest location != UNKNOWN_LOCATION among the
13563 : three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
13564 : and LOCATIONS[ds_restrict]. */
13565 :
13566 : static location_t
13567 1027432683 : smallest_type_quals_location (int type_quals, const location_t* locations)
13568 : {
13569 1027432683 : location_t loc = UNKNOWN_LOCATION;
13570 :
13571 1027432683 : if (type_quals & TYPE_QUAL_CONST)
13572 106515348 : loc = locations[ds_const];
13573 :
13574 1027432683 : if (type_quals & TYPE_QUAL_VOLATILE)
13575 1704862 : loc = min_location (loc, locations[ds_volatile]);
13576 :
13577 1027432683 : if (type_quals & TYPE_QUAL_RESTRICT)
13578 43 : loc = min_location (loc, locations[ds_restrict]);
13579 :
13580 1027432683 : return loc;
13581 : }
13582 :
13583 : /* Returns the smallest among the latter and locations[ds_type_spec]. */
13584 :
13585 : static location_t
13586 1027432662 : smallest_type_location (int type_quals, const location_t* locations)
13587 : {
13588 1027432662 : location_t loc = smallest_type_quals_location (type_quals, locations);
13589 1027432662 : return min_location (loc, locations[ds_type_spec]);
13590 : }
13591 :
13592 : static location_t
13593 26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
13594 : {
13595 26 : int type_quals = get_type_quals (declspecs);
13596 26 : return smallest_type_location (type_quals, declspecs->locations);
13597 : }
13598 :
13599 : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
13600 : strip out the pointer/reference declarator(s). */
13601 :
13602 : static bool
13603 29329700 : maybe_strip_indirect_ref (const cp_declarator** declarator)
13604 : {
13605 29329700 : bool indirect_ref_p = false;
13606 58659547 : while (declarator && *declarator
13607 29329847 : && ((*declarator)->kind == cdk_pointer
13608 29329847 : || (*declarator)->kind == cdk_reference))
13609 : {
13610 147 : indirect_ref_p = true;
13611 147 : *declarator = (*declarator)->declarator;
13612 : }
13613 29329700 : return indirect_ref_p;
13614 : }
13615 :
13616 : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
13617 : and DECLARATOR. SFK indicates the kind of special function (if any) that
13618 : this function is. OPTYPE is the type given in a conversion operator
13619 : declaration, or the class type for a constructor/destructor.
13620 : Returns the actual return type of the function; that may be different
13621 : than TYPE if an error occurs, or for certain special functions. */
13622 :
13623 : static tree
13624 29329700 : check_special_function_return_type (special_function_kind sfk,
13625 : tree type,
13626 : tree optype,
13627 : int type_quals,
13628 : const cp_declarator** declarator,
13629 : const location_t* locations)
13630 : {
13631 29329700 : gcc_assert (declarator);
13632 29329700 : location_t rettype_loc = (type
13633 29329700 : ? smallest_type_location (type_quals, locations)
13634 29329619 : : (*declarator)->id_loc);
13635 29329700 : switch (sfk)
13636 : {
13637 23914083 : case sfk_constructor:
13638 23914083 : if (maybe_strip_indirect_ref (declarator) || type)
13639 81 : error_at (rettype_loc,
13640 : "return type specification for constructor invalid");
13641 23914002 : else if (type_quals != TYPE_UNQUALIFIED)
13642 15 : error_at (smallest_type_quals_location (type_quals, locations),
13643 : "qualifiers are not allowed on constructor declaration");
13644 :
13645 23914083 : if (targetm.cxx.cdtor_returns_this ())
13646 0 : type = build_pointer_type (optype);
13647 : else
13648 23914083 : type = void_type_node;
13649 : break;
13650 :
13651 3227712 : case sfk_destructor:
13652 3227712 : if (maybe_strip_indirect_ref (declarator) || type)
13653 45 : error_at (rettype_loc,
13654 : "return type specification for destructor invalid");
13655 3227667 : else if (type_quals != TYPE_UNQUALIFIED)
13656 3 : error_at (smallest_type_quals_location (type_quals, locations),
13657 : "qualifiers are not allowed on destructor declaration");
13658 :
13659 : /* We can't use the proper return type here because we run into
13660 : problems with ambiguous bases and covariant returns. */
13661 3227712 : if (targetm.cxx.cdtor_returns_this ())
13662 0 : type = build_pointer_type (void_type_node);
13663 : else
13664 3227712 : type = void_type_node;
13665 : break;
13666 :
13667 1004568 : case sfk_conversion:
13668 1004568 : if (maybe_strip_indirect_ref (declarator) || type)
13669 42 : error_at (rettype_loc,
13670 : "return type specified for %<operator %T%>", optype);
13671 1004526 : else if (type_quals != TYPE_UNQUALIFIED)
13672 3 : error_at (smallest_type_quals_location (type_quals, locations),
13673 : "qualifiers are not allowed on declaration of "
13674 : "%<operator %T%>", optype);
13675 :
13676 : type = optype;
13677 : break;
13678 :
13679 1183337 : case sfk_deduction_guide:
13680 1183337 : if (maybe_strip_indirect_ref (declarator) || type)
13681 0 : error_at (rettype_loc,
13682 : "return type specified for deduction guide");
13683 1183337 : else if (type_quals != TYPE_UNQUALIFIED)
13684 0 : error_at (smallest_type_quals_location (type_quals, locations),
13685 : "qualifiers are not allowed on declaration of "
13686 : "deduction guide");
13687 1183337 : if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
13688 : {
13689 3 : error ("template template parameter %qT in declaration of "
13690 : "deduction guide", optype);
13691 3 : type = error_mark_node;
13692 : }
13693 : else
13694 1183334 : type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
13695 31950099 : for (int i = 0; i < ds_last; ++i)
13696 30766762 : if (i != ds_explicit && locations[i])
13697 3 : error_at (locations[i],
13698 : "%<decl-specifier%> in declaration of deduction guide");
13699 : break;
13700 :
13701 0 : default:
13702 0 : gcc_unreachable ();
13703 : }
13704 :
13705 29329700 : return type;
13706 : }
13707 :
13708 : /* A variable or data member (whose unqualified name is IDENTIFIER)
13709 : has been declared with the indicated TYPE. If the TYPE is not
13710 : acceptable, issue an error message and return a type to use for
13711 : error-recovery purposes. */
13712 :
13713 : tree
13714 322231246 : check_var_type (tree identifier, tree type, location_t loc)
13715 : {
13716 322231246 : if (VOID_TYPE_P (type))
13717 : {
13718 86 : if (!identifier)
13719 0 : error_at (loc, "unnamed variable or field declared void");
13720 86 : else if (identifier_p (identifier))
13721 : {
13722 86 : gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
13723 86 : error_at (loc, "variable or field %qE declared void",
13724 : identifier);
13725 : }
13726 : else
13727 0 : error_at (loc, "variable or field declared void");
13728 86 : type = error_mark_node;
13729 : }
13730 :
13731 322231246 : return type;
13732 : }
13733 :
13734 : /* Handle declaring DECL as an inline variable. */
13735 :
13736 : static void
13737 6515564 : mark_inline_variable (tree decl, location_t loc)
13738 : {
13739 6515564 : bool inlinep = true;
13740 6515564 : if (! toplevel_bindings_p ())
13741 : {
13742 24 : error_at (loc, "%<inline%> specifier invalid for variable "
13743 : "%qD declared at block scope", decl);
13744 24 : inlinep = false;
13745 : }
13746 6515540 : else if (cxx_dialect < cxx17)
13747 648 : pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
13748 : "with %<-std=c++17%> or %<-std=gnu++17%>");
13749 672 : if (inlinep)
13750 : {
13751 6515540 : retrofit_lang_decl (decl);
13752 6515540 : SET_DECL_VAR_DECLARED_INLINE_P (decl);
13753 : }
13754 6515564 : }
13755 :
13756 :
13757 : /* Diagnose -Wnon-c-typedef-for-linkage pedwarn. TYPE is the unnamed class
13758 : with a typedef name for linkage purposes with freshly updated TYPE_NAME,
13759 : ORIG is the anonymous TYPE_NAME before that change. */
13760 :
13761 : static bool
13762 42 : diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
13763 : {
13764 42 : gcc_rich_location richloc (DECL_SOURCE_LOCATION (orig));
13765 42 : tree name = DECL_NAME (TYPE_NAME (type));
13766 42 : richloc.add_fixit_insert_before (IDENTIFIER_POINTER (name));
13767 42 : return pedwarn (&richloc, OPT_Wnon_c_typedef_for_linkage,
13768 : "anonymous non-C-compatible type given name for linkage "
13769 42 : "purposes by %<typedef%> declaration");
13770 42 : }
13771 :
13772 : /* Diagnose -Wnon-c-typedef-for-linkage violations on T. TYPE and ORIG
13773 : like for diagnose_non_c_class_typedef_for_linkage, T is initially equal
13774 : to TYPE but during recursion can be set to nested classes. */
13775 :
13776 : static bool
13777 510975 : maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
13778 : {
13779 510975 : if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
13780 : {
13781 6 : auto_diagnostic_group d;
13782 6 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13783 9 : inform (type == t ? DECL_SOURCE_LOCATION (orig)
13784 3 : : DECL_SOURCE_LOCATION (TYPE_NAME (t)),
13785 : "type is not C-compatible because it has a base class");
13786 6 : return true;
13787 6 : }
13788 2401398 : for (tree field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
13789 1890490 : switch (TREE_CODE (field))
13790 : {
13791 9 : case VAR_DECL:
13792 : /* static data members have been diagnosed already. */
13793 9 : continue;
13794 1257424 : case FIELD_DECL:
13795 1257424 : if (DECL_INITIAL (field))
13796 : {
13797 4 : auto_diagnostic_group d;
13798 4 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13799 4 : inform (DECL_SOURCE_LOCATION (field),
13800 : "type is not C-compatible because %qD has default "
13801 : "member initializer", field);
13802 4 : return true;
13803 4 : }
13804 1257420 : continue;
13805 9 : case CONST_DECL:
13806 9 : continue;
13807 632971 : case TYPE_DECL:
13808 632971 : if (DECL_SELF_REFERENCE_P (field))
13809 510943 : continue;
13810 122028 : if (DECL_IMPLICIT_TYPEDEF_P (field))
13811 : {
13812 122018 : if (TREE_CODE (TREE_TYPE (field)) == ENUMERAL_TYPE)
13813 3 : continue;
13814 122015 : if (CLASS_TYPE_P (TREE_TYPE (field)))
13815 : {
13816 122015 : tree tf = TREE_TYPE (field);
13817 122015 : if (maybe_diagnose_non_c_class_typedef_for_linkage (type, orig,
13818 : tf))
13819 : return true;
13820 121990 : continue;
13821 121990 : }
13822 : }
13823 : /* FALLTHRU */
13824 32 : case FUNCTION_DECL:
13825 32 : case TEMPLATE_DECL:
13826 32 : {
13827 32 : auto_diagnostic_group d;
13828 32 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13829 32 : inform (DECL_SOURCE_LOCATION (field),
13830 : "type is not C-compatible because it contains %qD "
13831 : "declaration", field);
13832 32 : return true;
13833 32 : }
13834 : default:
13835 : break;
13836 1257438 : }
13837 : return false;
13838 : }
13839 :
13840 : /* Assign a typedef-given name to a class or enumeration type declared
13841 : as anonymous at first. This was split out of grokdeclarator
13842 : because it is also used in libcc1. */
13843 :
13844 : void
13845 390756 : name_unnamed_type (tree type, tree decl)
13846 : {
13847 1172268 : gcc_assert (TYPE_UNNAMED_P (type)
13848 : || enum_with_enumerator_for_linkage_p (type));
13849 :
13850 390756 : tree orig = TYPE_NAME (type);
13851 390756 : if (flag_reflection)
13852 : {
13853 : /* For -freflection for typedef struct { ... } S; ^^S needs to be
13854 : a reflection of a type alias. So, TREE_TYPE (DECL) can't be
13855 : TYPE. Instead of what we do below, override DECL_NAME (orig). */
13856 7109 : DECL_NAME (orig) = DECL_NAME (decl);
13857 7109 : TYPE_DECL_FOR_LINKAGE_PURPOSES_P (orig) = 1;
13858 : }
13859 : else
13860 : /* Replace the anonymous decl with the real decl. Be careful not to
13861 : rename other typedefs (such as the self-reference) of type. */
13862 1149215 : for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
13863 765568 : if (TYPE_NAME (t) == orig)
13864 383647 : TYPE_NAME (t) = decl;
13865 390756 : TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl) = 1;
13866 :
13867 : /* If this is a typedef within a template class, the nested
13868 : type is a (non-primary) template. The name for the
13869 : template needs updating as well. */
13870 390756 : if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
13871 64 : DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
13872 :
13873 : /* Adjust linkage now that we aren't unnamed anymore. */
13874 390756 : reset_type_linkage (type);
13875 :
13876 390756 : if (CLASS_TYPE_P (type) && warn_non_c_typedef_for_linkage)
13877 388960 : maybe_diagnose_non_c_class_typedef_for_linkage (type, orig, type);
13878 :
13879 : /* FIXME remangle member functions; member functions of a
13880 : type with external linkage have external linkage. */
13881 :
13882 : /* Check that our job is done, and that it would fail if we
13883 : attempted to do it again. */
13884 781512 : gcc_assert (!TYPE_UNNAMED_P (type)
13885 : && !enum_with_enumerator_for_linkage_p (type));
13886 390756 : }
13887 :
13888 : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
13889 : is allowed. TYPE might contain a decltype(auto). Returns true if
13890 : there was a problem, false otherwise. */
13891 :
13892 : static bool
13893 626116900 : check_decltype_auto (location_t loc, tree type)
13894 : {
13895 626116900 : if (tree a = type_uses_auto (type))
13896 : {
13897 17125368 : if (AUTO_IS_DECLTYPE (a))
13898 : {
13899 598300 : if (a != type)
13900 : {
13901 33 : error_at (loc, "%qT as type rather than plain "
13902 : "%<decltype(auto)%>", type);
13903 33 : return true;
13904 : }
13905 598267 : else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
13906 : {
13907 37 : error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
13908 37 : return true;
13909 : }
13910 : }
13911 : }
13912 : return false;
13913 : }
13914 :
13915 : /* Issue an error about two mutually incompatible declspecs
13916 : with the given names and locations
13917 : e.g. "error: `signed' and `unsigned' specified together" */
13918 :
13919 : static void
13920 66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
13921 : const char *name_b, location_t loc_b)
13922 : {
13923 66 : gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
13924 66 : richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
13925 : nullptr, highlight_colors::rhs);
13926 66 : pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
13927 66 : pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
13928 66 : error_at (&richloc, "%e and %e specified together",
13929 : &e_name_a, &e_name_b);
13930 66 : }
13931 :
13932 : /* Given declspecs and a declarator (abstract or otherwise), determine
13933 : the name and type of the object declared and construct a DECL node
13934 : for it.
13935 :
13936 : DECLSPECS points to the representation of declaration-specifier
13937 : sequence that precedes declarator.
13938 :
13939 : DECL_CONTEXT says which syntactic context this declaration is in:
13940 : NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
13941 : FUNCDEF for a function definition. Like NORMAL but a few different
13942 : error messages in each case. Return value may be zero meaning
13943 : this definition is too screwy to try to parse.
13944 : MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
13945 : handle member functions (which have FIELD context).
13946 : Return value may be zero meaning this definition is too screwy to
13947 : try to parse.
13948 : PARM for a parameter declaration (either within a function prototype
13949 : or before a function body). Make a PARM_DECL, or return void_type_node.
13950 : TPARM for a template parameter declaration.
13951 : CATCHPARM for a parameter declaration before a catch clause.
13952 : TYPENAME if for a typename (in a cast or sizeof).
13953 : Don't make a DECL node; just return the ..._TYPE node.
13954 : FIELD for a struct or union field; make a FIELD_DECL.
13955 : BITFIELD for a field with specified width.
13956 :
13957 : INITIALIZED is as for start_decl.
13958 :
13959 : ATTRLIST is a pointer to the list of attributes, which may be NULL
13960 : if there are none; *ATTRLIST may be modified if attributes from inside
13961 : the declarator should be applied to the declaration.
13962 :
13963 : When this function is called, scoping variables (such as
13964 : CURRENT_CLASS_TYPE) should reflect the scope in which the
13965 : declaration occurs, not the scope in which the new declaration will
13966 : be placed. For example, on:
13967 :
13968 : void S::f() { ... }
13969 :
13970 : when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
13971 : should not be `S'.
13972 :
13973 : Returns a DECL (if a declarator is present), a TYPE (if there is no
13974 : declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
13975 : error occurs. */
13976 :
13977 : tree
13978 1027432555 : grokdeclarator (const cp_declarator *declarator,
13979 : cp_decl_specifier_seq *declspecs,
13980 : enum decl_context decl_context,
13981 : int initialized,
13982 : tree* attrlist)
13983 : {
13984 1027432555 : tree type = NULL_TREE;
13985 1027432555 : int longlong = 0;
13986 1027432555 : int explicit_intN = 0;
13987 1027432555 : int int_n_alt = 0;
13988 1027432555 : int virtualp, explicitp, friendp, inlinep, staticp;
13989 1027432555 : int explicit_int = 0;
13990 1027432555 : int explicit_char = 0;
13991 1027432555 : int defaulted_int = 0;
13992 :
13993 1027432555 : tree typedef_decl = NULL_TREE;
13994 1027432555 : const char *name = NULL;
13995 1027432555 : tree typedef_type = NULL_TREE;
13996 : /* True if this declarator is a function definition. */
13997 1027432555 : bool funcdef_flag = false;
13998 1027432555 : cp_declarator_kind innermost_code = cdk_error;
13999 1027432555 : int bitfield = 0;
14000 : #if 0
14001 : /* See the code below that used this. */
14002 : tree decl_attr = NULL_TREE;
14003 : #endif
14004 :
14005 : /* Keep track of what sort of function is being processed
14006 : so that we can warn about default return values, or explicit
14007 : return values which do not match prescribed defaults. */
14008 1027432555 : special_function_kind sfk = sfk_none;
14009 :
14010 1027432555 : tree dname = NULL_TREE;
14011 1027432555 : tree ctor_return_type = NULL_TREE;
14012 1027432555 : enum overload_flags flags = NO_SPECIAL;
14013 : /* cv-qualifiers that apply to the declarator, for a declaration of
14014 : a member function. */
14015 1027432555 : cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
14016 : /* virt-specifiers that apply to the declarator, for a declaration of
14017 : a member function. */
14018 1027432555 : cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
14019 : /* ref-qualifier that applies to the declarator, for a declaration of
14020 : a member function. */
14021 1027432555 : cp_ref_qualifier rqual = REF_QUAL_NONE;
14022 : /* cv-qualifiers that apply to the type specified by the DECLSPECS. */
14023 1027432555 : int type_quals = get_type_quals (declspecs);
14024 1027432555 : tree raises = NULL_TREE;
14025 1027432555 : int template_count = 0;
14026 1027432555 : tree returned_attrs = NULL_TREE;
14027 1027432555 : tree contract_specifiers = NULL_TREE;
14028 1027432555 : tree parms = NULL_TREE;
14029 1027432555 : const cp_declarator *id_declarator;
14030 : /* The unqualified name of the declarator; either an
14031 : IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR. */
14032 1027432555 : tree unqualified_id;
14033 : /* The class type, if any, in which this entity is located,
14034 : or NULL_TREE if none. Note that this value may be different from
14035 : the current class type; for example if an attempt is made to declare
14036 : "A::f" inside "B", this value will be "A". */
14037 1027432555 : tree ctype = current_class_type;
14038 : /* The NAMESPACE_DECL for the namespace in which this entity is
14039 : located. If an unqualified name is used to declare the entity,
14040 : this value will be NULL_TREE, even if the entity is located at
14041 : namespace scope. */
14042 1027432555 : tree in_namespace = NULL_TREE;
14043 1027432555 : cp_storage_class storage_class;
14044 1027432555 : bool unsigned_p, signed_p, short_p, long_p, thread_p;
14045 1027432555 : bool type_was_error_mark_node = false;
14046 1027432555 : bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
14047 1027432555 : bool template_type_arg = false;
14048 1027432555 : bool template_parm_flag = false;
14049 1027432555 : bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
14050 1027432555 : bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
14051 1027432555 : bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
14052 1027432555 : bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
14053 1027432555 : bool late_return_type_p = false;
14054 1027432555 : bool array_parameter_p = false;
14055 1027432555 : tree reqs = NULL_TREE;
14056 :
14057 1027432555 : signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
14058 1027432555 : unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
14059 1027432555 : short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
14060 1027432555 : long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
14061 1027432555 : longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
14062 1027432555 : explicit_intN = declspecs->explicit_intN_p;
14063 1027432555 : int_n_alt = declspecs->int_n_alt;
14064 1027432555 : thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
14065 :
14066 : // Was concept_p specified? Note that ds_concept
14067 : // implies ds_constexpr!
14068 1027432555 : bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
14069 1027432555 : if (concept_p)
14070 117 : constexpr_p = true;
14071 :
14072 1027432555 : if (decl_context == FUNCDEF)
14073 : funcdef_flag = true, decl_context = NORMAL;
14074 : else if (decl_context == MEMFUNCDEF)
14075 : funcdef_flag = true, decl_context = FIELD;
14076 : else if (decl_context == BITFIELD)
14077 : bitfield = 1, decl_context = FIELD;
14078 : else if (decl_context == TEMPLATE_TYPE_ARG)
14079 : template_type_arg = true, decl_context = TYPENAME;
14080 : else if (decl_context == TPARM)
14081 10831782 : template_parm_flag = true, decl_context = PARM;
14082 :
14083 1027432555 : if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
14084 10820156 : funcdef_flag = true;
14085 :
14086 1027432555 : location_t typespec_loc = loc_or_input_loc (smallest_type_location
14087 : (type_quals,
14088 1027432555 : declspecs->locations));
14089 1027432555 : location_t id_loc;
14090 1027432555 : location_t init_loc;
14091 1027432555 : if (declarator)
14092 : {
14093 620378645 : id_loc = loc_or_input_loc (declarator->id_loc);
14094 620378645 : init_loc = loc_or_input_loc (declarator->init_loc);
14095 : }
14096 : else
14097 407053910 : init_loc = id_loc = input_location;
14098 :
14099 : /* Look inside a declarator for the name being declared
14100 : and get it as a string, for an error message. */
14101 1027432555 : for (id_declarator = declarator;
14102 1411458091 : id_declarator;
14103 384025536 : id_declarator = id_declarator->declarator)
14104 : {
14105 963268730 : if (id_declarator->kind != cdk_id)
14106 384025561 : innermost_code = id_declarator->kind;
14107 :
14108 963268730 : switch (id_declarator->kind)
14109 : {
14110 188384495 : case cdk_function:
14111 188384495 : if (id_declarator->declarator
14112 188018557 : && id_declarator->declarator->kind == cdk_id)
14113 : {
14114 186189205 : sfk = id_declarator->declarator->u.id.sfk;
14115 186189205 : if (sfk == sfk_destructor)
14116 3227715 : flags = DTOR_FLAG;
14117 : }
14118 : break;
14119 :
14120 579243169 : case cdk_id:
14121 579243169 : {
14122 579243169 : tree qualifying_scope = id_declarator->u.id.qualifying_scope;
14123 579243169 : tree decl = id_declarator->u.id.unqualified_name;
14124 579243169 : if (!decl)
14125 : break;
14126 579243169 : if (qualifying_scope)
14127 : {
14128 9595657 : if (check_for_bare_parameter_packs (qualifying_scope,
14129 9595657 : id_declarator->id_loc))
14130 6 : return error_mark_node;
14131 9595651 : if (at_function_scope_p ())
14132 : {
14133 : /* [dcl.meaning]
14134 :
14135 : A declarator-id shall not be qualified except
14136 : for ...
14137 :
14138 : None of the cases are permitted in block
14139 : scope. */
14140 0 : if (qualifying_scope == global_namespace)
14141 0 : error ("invalid use of qualified-name %<::%D%>",
14142 : decl);
14143 0 : else if (TYPE_P (qualifying_scope))
14144 0 : error ("invalid use of qualified-name %<%T::%D%>",
14145 : qualifying_scope, decl);
14146 : else
14147 0 : error ("invalid use of qualified-name %<%D::%D%>",
14148 : qualifying_scope, decl);
14149 0 : return error_mark_node;
14150 : }
14151 9595651 : else if (TYPE_P (qualifying_scope))
14152 : {
14153 9357499 : ctype = qualifying_scope;
14154 9357499 : if (!MAYBE_CLASS_TYPE_P (ctype))
14155 : {
14156 6 : error_at (id_declarator->id_loc,
14157 : "%q#T is not a class or namespace", ctype);
14158 6 : ctype = NULL_TREE;
14159 : }
14160 9357493 : else if (innermost_code != cdk_function
14161 492366 : && current_class_type
14162 9357508 : && !uniquely_derived_from_p (ctype,
14163 : current_class_type))
14164 : {
14165 9 : error_at (id_declarator->id_loc,
14166 : "invalid use of qualified-name %<%T::%D%>",
14167 : qualifying_scope, decl);
14168 9 : return error_mark_node;
14169 : }
14170 : }
14171 238152 : else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
14172 579243154 : in_namespace = qualifying_scope;
14173 : }
14174 579243154 : switch (TREE_CODE (decl))
14175 : {
14176 3227730 : case BIT_NOT_EXPR:
14177 3227730 : {
14178 3227730 : if (innermost_code != cdk_function)
14179 : {
14180 6 : error_at (EXPR_LOCATION (decl),
14181 : "declaration of %qE as non-function", decl);
14182 6 : return error_mark_node;
14183 : }
14184 3227724 : else if (!qualifying_scope
14185 3227724 : && !(current_class_type && at_class_scope_p ()))
14186 : {
14187 9 : error_at (EXPR_LOCATION (decl),
14188 : "declaration of %qE as non-member", decl);
14189 9 : return error_mark_node;
14190 : }
14191 :
14192 3227715 : tree type = TREE_OPERAND (decl, 0);
14193 3227715 : if (TYPE_P (type))
14194 3227712 : type = constructor_name (type);
14195 3227715 : name = identifier_to_locale (IDENTIFIER_POINTER (type));
14196 3227715 : dname = decl;
14197 : }
14198 3227715 : break;
14199 :
14200 2730461 : case TEMPLATE_ID_EXPR:
14201 2730461 : {
14202 2730461 : tree fns = TREE_OPERAND (decl, 0);
14203 :
14204 2730461 : dname = fns;
14205 3677820 : if (!identifier_p (dname))
14206 2730437 : dname = OVL_NAME (dname);
14207 : }
14208 : /* Fall through. */
14209 :
14210 576015424 : case IDENTIFIER_NODE:
14211 576015424 : if (identifier_p (decl))
14212 573284963 : dname = decl;
14213 :
14214 576015424 : if (IDENTIFIER_KEYWORD_P (dname))
14215 : {
14216 0 : error ("declarator-id missing; using reserved word %qD",
14217 : dname);
14218 0 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14219 : }
14220 576015424 : else if (!IDENTIFIER_CONV_OP_P (dname))
14221 575010853 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14222 : else
14223 : {
14224 1004571 : gcc_assert (flags == NO_SPECIAL);
14225 1004571 : flags = TYPENAME_FLAG;
14226 1004571 : sfk = sfk_conversion;
14227 1004571 : tree glob = get_global_binding (dname);
14228 1004571 : if (glob && TREE_CODE (glob) == TYPE_DECL)
14229 0 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14230 : else
14231 : name = "<invalid operator>";
14232 : }
14233 : break;
14234 :
14235 0 : default:
14236 0 : gcc_unreachable ();
14237 : }
14238 : break;
14239 : }
14240 :
14241 : case cdk_array:
14242 : case cdk_pointer:
14243 : case cdk_reference:
14244 : case cdk_ptrmem:
14245 : break;
14246 :
14247 : case cdk_decomp:
14248 963268675 : name = "structured binding";
14249 : break;
14250 :
14251 25 : case cdk_error:
14252 25 : return error_mark_node;
14253 :
14254 0 : default:
14255 0 : gcc_unreachable ();
14256 : }
14257 963268675 : if (id_declarator->kind == cdk_id)
14258 : break;
14259 : }
14260 :
14261 : /* [dcl.fct.edf]
14262 :
14263 : The declarator in a function-definition shall have the form
14264 : D1 ( parameter-declaration-clause) ... */
14265 1027432500 : if (funcdef_flag && innermost_code != cdk_function)
14266 : {
14267 3 : error_at (id_loc, "function definition does not declare parameters");
14268 3 : return error_mark_node;
14269 : }
14270 :
14271 1027432497 : if (flags == TYPENAME_FLAG
14272 1027432497 : && innermost_code != cdk_function
14273 3 : && ! (ctype && !declspecs->any_specifiers_p))
14274 : {
14275 3 : error_at (id_loc, "declaration of %qD as non-function", dname);
14276 3 : return error_mark_node;
14277 : }
14278 :
14279 1027432494 : if (dname && identifier_p (dname))
14280 : {
14281 576015418 : if (UDLIT_OPER_P (dname)
14282 576015418 : && innermost_code != cdk_function)
14283 : {
14284 6 : error_at (id_loc, "declaration of %qD as non-function", dname);
14285 6 : return error_mark_node;
14286 : }
14287 :
14288 576015412 : if (IDENTIFIER_ANY_OP_P (dname))
14289 : {
14290 36498126 : if (typedef_p)
14291 : {
14292 3 : error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
14293 3 : return error_mark_node;
14294 : }
14295 36498123 : else if (decl_context == PARM || decl_context == CATCHPARM)
14296 : {
14297 15 : error_at (id_loc, "declaration of %qD as parameter", dname);
14298 15 : return error_mark_node;
14299 : }
14300 : }
14301 : }
14302 :
14303 : /* Anything declared one level down from the top level
14304 : must be one of the parameters of a function
14305 : (because the body is at least two levels down). */
14306 :
14307 : /* This heuristic cannot be applied to C++ nodes! Fixed, however,
14308 : by not allowing C++ class definitions to specify their parameters
14309 : with xdecls (must be spec.d in the parmlist).
14310 :
14311 : Since we now wait to push a class scope until we are sure that
14312 : we are in a legitimate method context, we must set oldcname
14313 : explicitly (since current_class_name is not yet alive).
14314 :
14315 : We also want to avoid calling this a PARM if it is in a namespace. */
14316 :
14317 1027432470 : if (decl_context == NORMAL && !toplevel_bindings_p ())
14318 : {
14319 71252873 : cp_binding_level *b = current_binding_level;
14320 71252873 : current_binding_level = b->level_chain;
14321 71252873 : if (current_binding_level != 0 && toplevel_bindings_p ())
14322 : decl_context = PARM;
14323 71252873 : current_binding_level = b;
14324 : }
14325 :
14326 1027432470 : if (name == NULL)
14327 447968519 : name = decl_context == PARM ? "parameter" : "type name";
14328 :
14329 1027432470 : if (consteval_p && constexpr_p)
14330 : {
14331 6 : error_at (declspecs->locations[ds_consteval],
14332 : "both %qs and %qs specified", "constexpr", "consteval");
14333 6 : return error_mark_node;
14334 : }
14335 :
14336 1027432464 : if (concept_p && typedef_p)
14337 : {
14338 9 : error_at (declspecs->locations[ds_concept],
14339 : "%qs cannot appear in a typedef declaration", "concept");
14340 9 : return error_mark_node;
14341 : }
14342 :
14343 1027432455 : if (constexpr_p && typedef_p)
14344 : {
14345 3 : error_at (declspecs->locations[ds_constexpr],
14346 : "%qs cannot appear in a typedef declaration", "constexpr");
14347 3 : return error_mark_node;
14348 : }
14349 :
14350 1027432452 : if (consteval_p && typedef_p)
14351 : {
14352 3 : error_at (declspecs->locations[ds_consteval],
14353 : "%qs cannot appear in a typedef declaration", "consteval");
14354 3 : return error_mark_node;
14355 : }
14356 :
14357 1027432449 : if (constinit_p && typedef_p)
14358 : {
14359 3 : error_at (declspecs->locations[ds_constinit],
14360 : "%qs cannot appear in a typedef declaration", "constinit");
14361 3 : return error_mark_node;
14362 : }
14363 :
14364 : /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
14365 : keywords shall appear in a decl-specifier-seq." */
14366 1027432446 : if (constinit_p && constexpr_p)
14367 : {
14368 6 : gcc_rich_location richloc (declspecs->locations[ds_constinit]);
14369 6 : richloc.add_range (declspecs->locations[ds_constexpr]);
14370 6 : error_at (&richloc,
14371 : "can use at most one of the %<constinit%> and %<constexpr%> "
14372 : "specifiers");
14373 6 : return error_mark_node;
14374 6 : }
14375 :
14376 : /* If there were multiple types specified in the decl-specifier-seq,
14377 : issue an error message. */
14378 1027432440 : if (declspecs->multiple_types_p)
14379 : {
14380 1501 : error_at (typespec_loc,
14381 : "two or more data types in declaration of %qs", name);
14382 1501 : return error_mark_node;
14383 : }
14384 :
14385 1027430939 : if (declspecs->conflicting_specifiers_p)
14386 31 : return error_mark_node;
14387 :
14388 : /* Extract the basic type from the decl-specifier-seq. */
14389 1027430908 : type = declspecs->type;
14390 1027430908 : if (type == error_mark_node)
14391 : {
14392 1188 : type = NULL_TREE;
14393 1188 : type_was_error_mark_node = true;
14394 : }
14395 :
14396 : /* Ignore erroneous attributes. */
14397 1027430908 : if (attrlist && *attrlist == error_mark_node)
14398 12 : *attrlist = NULL_TREE;
14399 :
14400 : /* An object declared as __attribute__((unavailable)) suppresses
14401 : any reports of being declared with unavailable or deprecated
14402 : items. An object declared as __attribute__((deprecated))
14403 : suppresses warnings of uses of other deprecated items. */
14404 1027430908 : auto ds = make_temp_override (deprecated_state);
14405 1027430908 : if (attrlist && lookup_attribute ("unavailable", *attrlist))
14406 171 : deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
14407 1027430737 : else if (attrlist && lookup_attribute ("deprecated", *attrlist))
14408 789455 : deprecated_state = DEPRECATED_SUPPRESS;
14409 :
14410 1027430908 : cp_handle_deprecated_or_unavailable (type);
14411 1027430908 : if (type && TREE_CODE (type) == TYPE_DECL)
14412 : {
14413 715521571 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
14414 715521571 : typedef_decl = type;
14415 715521571 : type = TREE_TYPE (typedef_decl);
14416 715521571 : if (DECL_ARTIFICIAL (typedef_decl))
14417 520137768 : cp_handle_deprecated_or_unavailable (type);
14418 : }
14419 : /* No type at all: default to `int', and set DEFAULTED_INT
14420 : because it was not a user-defined typedef. */
14421 1027430908 : if (type == NULL_TREE)
14422 : {
14423 38359295 : if (signed_p || unsigned_p || long_p || short_p)
14424 : {
14425 : /* These imply 'int'. */
14426 9028007 : type = integer_type_node;
14427 9028007 : defaulted_int = 1;
14428 : }
14429 : /* If we just have "complex", it is equivalent to "complex double". */
14430 29331288 : else if (!longlong && !explicit_intN
14431 29331288 : && decl_spec_seq_has_spec_p (declspecs, ds_complex))
14432 : {
14433 81 : type = double_type_node;
14434 81 : pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
14435 : "ISO C++ does not support plain %<complex%> meaning "
14436 : "%<double complex%>");
14437 : }
14438 : }
14439 : /* Gather flags. */
14440 1027430908 : explicit_int = declspecs->explicit_int_p;
14441 1027430908 : explicit_char = declspecs->explicit_char_p;
14442 :
14443 : #if 0
14444 : /* See the code below that used this. */
14445 : if (typedef_decl)
14446 : decl_attr = DECL_ATTRIBUTES (typedef_decl);
14447 : #endif
14448 1027430908 : typedef_type = type;
14449 :
14450 1027430908 : if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
14451 2187905 : ctor_return_type = TREE_TYPE (dname);
14452 : else
14453 : ctor_return_type = ctype;
14454 :
14455 1027430908 : if (sfk != sfk_none)
14456 : {
14457 29329700 : type = check_special_function_return_type (sfk, type,
14458 : ctor_return_type,
14459 : type_quals,
14460 : &declarator,
14461 : declspecs->locations);
14462 29329700 : type_quals = TYPE_UNQUALIFIED;
14463 : }
14464 998101208 : else if (type == NULL_TREE)
14465 : {
14466 1588 : int is_main;
14467 :
14468 1588 : explicit_int = -1;
14469 :
14470 : /* We handle `main' specially here, because 'main () { }' is so
14471 : common. With no options, it is allowed. With -Wreturn-type,
14472 : it is a warning. It is only an error with -pedantic-errors. */
14473 3176 : is_main = (funcdef_flag
14474 3410 : && dname && identifier_p (dname)
14475 234 : && MAIN_NAME_P (dname)
14476 68 : && ctype == NULL_TREE
14477 68 : && in_namespace == NULL_TREE
14478 1656 : && current_namespace == global_namespace);
14479 :
14480 1588 : if (type_was_error_mark_node)
14481 : /* We've already issued an error, don't complain more. */;
14482 400 : else if (in_system_header_at (id_loc) || flag_ms_extensions)
14483 : /* Allow it, sigh. */;
14484 338 : else if (! is_main)
14485 276 : permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
14486 : name);
14487 62 : else if (pedantic)
14488 4 : pedwarn (id_loc, OPT_Wpedantic,
14489 : "ISO C++ forbids declaration of %qs with no type", name);
14490 : else
14491 58 : warning_at (id_loc, OPT_Wreturn_type,
14492 : "ISO C++ forbids declaration of %qs with no type", name);
14493 :
14494 1588 : if (type_was_error_mark_node && template_parm_flag)
14495 : /* FIXME we should be able to propagate the error_mark_node as is
14496 : for other contexts too. */
14497 149 : type = error_mark_node;
14498 : else
14499 1439 : type = integer_type_node;
14500 : }
14501 :
14502 1027430908 : ctype = NULL_TREE;
14503 :
14504 1027430908 : if (explicit_intN)
14505 : {
14506 1090183 : if (! int_n_enabled_p[declspecs->int_n_idx])
14507 : {
14508 0 : error_at (declspecs->locations[ds_type_spec],
14509 : "%<__int%d%> is not supported by this target",
14510 0 : int_n_data[declspecs->int_n_idx].bitsize);
14511 0 : explicit_intN = false;
14512 : }
14513 : /* Don't pedwarn if the alternate "__intN__" form has been used instead
14514 : of "__intN". */
14515 1090183 : else if (!int_n_alt && pedantic)
14516 6794 : pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
14517 : "ISO C++ does not support %<__int%d%> for %qs",
14518 6794 : int_n_data[declspecs->int_n_idx].bitsize, name);
14519 : }
14520 :
14521 : /* Now process the modifiers that were specified
14522 : and check for invalid combinations. */
14523 :
14524 : /* Long double is a special combination. */
14525 1027430908 : if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
14526 : {
14527 8725560 : long_p = false;
14528 8725560 : type = cp_build_qualified_type (long_double_type_node,
14529 : cp_type_quals (type));
14530 : }
14531 :
14532 : /* Check all other uses of type modifiers. */
14533 :
14534 1027430908 : if (unsigned_p || signed_p || long_p || short_p)
14535 : {
14536 20908291 : location_t loc;
14537 20908291 : const char *key;
14538 20908291 : if (unsigned_p)
14539 : {
14540 14198257 : key = "unsigned";
14541 14198257 : loc = declspecs->locations[ds_unsigned];
14542 : }
14543 6710034 : else if (signed_p)
14544 : {
14545 1031684 : key = "signed";
14546 1031684 : loc = declspecs->locations[ds_signed];
14547 : }
14548 5678350 : else if (longlong)
14549 : {
14550 2211898 : key = "long long";
14551 2211898 : loc = declspecs->locations[ds_long_long];
14552 : }
14553 3466452 : else if (long_p)
14554 : {
14555 2915213 : key = "long";
14556 2915213 : loc = declspecs->locations[ds_long];
14557 : }
14558 : else /* if (short_p) */
14559 : {
14560 551239 : key = "short";
14561 551239 : loc = declspecs->locations[ds_short];
14562 : }
14563 :
14564 20908291 : int ok = 0;
14565 :
14566 20908291 : if (signed_p && unsigned_p)
14567 54 : complain_about_incompatible_declspecs
14568 54 : ("signed", declspecs->locations[ds_signed],
14569 : "unsigned", declspecs->locations[ds_unsigned]);
14570 20908237 : else if (long_p && short_p)
14571 12 : complain_about_incompatible_declspecs
14572 12 : ("long", declspecs->locations[ds_long],
14573 : "short", declspecs->locations[ds_short]);
14574 20908225 : else if (TREE_CODE (type) != INTEGER_TYPE
14575 20908212 : || type == char8_type_node
14576 20908188 : || type == char16_type_node
14577 20908164 : || type == char32_type_node
14578 20908140 : || ((long_p || short_p)
14579 10967187 : && (explicit_char || explicit_intN)))
14580 418 : error_at (loc, "%qs specified with %qT", key, type);
14581 20907807 : else if (!explicit_int && !defaulted_int
14582 20907807 : && !explicit_char && !explicit_intN)
14583 : {
14584 30 : if (typedef_decl)
14585 : {
14586 27 : pedwarn (loc, OPT_Wpedantic,
14587 : "%qs specified with typedef-name %qD",
14588 : key, typedef_decl);
14589 27 : ok = !flag_pedantic_errors;
14590 : /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
14591 : and is not built as a typedef. */
14592 27 : if (is_typedef_decl (typedef_decl))
14593 18 : type = DECL_ORIGINAL_TYPE (typedef_decl);
14594 : }
14595 3 : else if (declspecs->decltype_p)
14596 0 : error_at (loc, "%qs specified with %<decltype%>", key);
14597 : else
14598 3 : error_at (loc, "%qs specified with %<typeof%>", key);
14599 : }
14600 : else
14601 : ok = 1;
14602 :
14603 : /* Discard the type modifiers if they are invalid. */
14604 514 : if (! ok)
14605 : {
14606 : unsigned_p = false;
14607 : signed_p = false;
14608 : long_p = false;
14609 : short_p = false;
14610 : longlong = 0;
14611 : }
14612 : }
14613 :
14614 : /* Decide whether an integer type is signed or not.
14615 : Optionally treat bitfields as signed by default. */
14616 1027430418 : if (unsigned_p
14617 : /* [class.bit]
14618 :
14619 : It is implementation-defined whether a plain (neither
14620 : explicitly signed or unsigned) char, short, int, or long
14621 : bit-field is signed or unsigned.
14622 :
14623 : Naturally, we extend this to long long as well. Note that
14624 : this does not include wchar_t. */
14625 1027430908 : || (bitfield && !flag_signed_bitfields
14626 18 : && !signed_p
14627 : /* A typedef for plain `int' without `signed' can be
14628 : controlled just like plain `int', but a typedef for
14629 : `signed int' cannot be so controlled. */
14630 18 : && !(typedef_decl
14631 18 : && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
14632 13 : && TREE_CODE (type) == INTEGER_TYPE
14633 10 : && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
14634 : {
14635 14198042 : if (explicit_intN)
14636 515238 : type = int_n_trees[declspecs->int_n_idx].unsigned_type;
14637 13682804 : else if (longlong)
14638 1404140 : type = long_long_unsigned_type_node;
14639 12278664 : else if (long_p)
14640 2284075 : type = long_unsigned_type_node;
14641 9994589 : else if (short_p)
14642 1395553 : type = short_unsigned_type_node;
14643 8599036 : else if (type == char_type_node)
14644 1885155 : type = unsigned_char_type_node;
14645 6713881 : else if (typedef_decl)
14646 25 : type = c_common_unsigned_type (type);
14647 : else
14648 6713856 : type = unsigned_type_node;
14649 : }
14650 1013232866 : else if (signed_p && type == char_type_node)
14651 684215 : type = signed_char_type_node;
14652 1012548651 : else if (explicit_intN)
14653 574945 : type = int_n_trees[declspecs->int_n_idx].signed_type;
14654 1011973706 : else if (longlong)
14655 2273986 : type = long_long_integer_type_node;
14656 1009699720 : else if (long_p)
14657 2981220 : type = long_integer_type_node;
14658 1006718500 : else if (short_p)
14659 627880 : type = short_integer_type_node;
14660 1006090620 : else if (signed_p && typedef_decl)
14661 9 : type = c_common_signed_type (type);
14662 :
14663 1027430908 : if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
14664 : {
14665 1178103 : if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
14666 3 : error_at (declspecs->locations[ds_complex],
14667 : "complex invalid for %qs", name);
14668 : /* If a modifier is specified, the resulting complex is the complex
14669 : form of TYPE. E.g, "complex short" is "complex short int". */
14670 1178100 : else if (type == integer_type_node)
14671 171 : type = complex_integer_type_node;
14672 1177929 : else if (type == float_type_node)
14673 336977 : type = complex_float_type_node;
14674 840952 : else if (type == double_type_node)
14675 337514 : type = complex_double_type_node;
14676 503438 : else if (type == long_double_type_node)
14677 337018 : type = complex_long_double_type_node;
14678 : else
14679 166420 : type = build_complex_type (type);
14680 : }
14681 :
14682 : /* If we're using the injected-class-name to form a compound type or a
14683 : declaration, replace it with the underlying class so we don't get
14684 : redundant typedefs in the debug output. But if we are returning the
14685 : type unchanged, leave it alone so that it's available to
14686 : maybe_get_template_decl_from_type_decl. */
14687 202133443 : if (CLASS_TYPE_P (type)
14688 202070713 : && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
14689 34334221 : && type == TREE_TYPE (TYPE_NAME (type))
14690 1061765129 : && (declarator || type_quals))
14691 32840249 : type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
14692 :
14693 1027430908 : type_quals |= cp_type_quals (type);
14694 2054861816 : type = cp_build_qualified_type
14695 2054861816 : (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
14696 832047105 : || declspecs->decltype_p)
14697 : ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
14698 : /* We might have ignored or rejected some of the qualifiers. */
14699 1027430908 : type_quals = cp_type_quals (type);
14700 :
14701 1011864598 : if (cxx_dialect >= cxx17 && type && is_auto (type)
14702 22032393 : && innermost_code != cdk_function
14703 : /* Placeholder in parm gets a better error below. */
14704 13792756 : && !(decl_context == PARM || decl_context == CATCHPARM)
14705 1041195286 : && id_declarator && declarator != id_declarator)
14706 1130072 : if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
14707 : {
14708 16 : auto_diagnostic_group g;
14709 16 : gcc_rich_location richloc (typespec_loc);
14710 16 : richloc.add_fixit_insert_after ("<>");
14711 16 : error_at (&richloc, "missing template argument list after %qE; "
14712 : "for deduction, template placeholder must be followed "
14713 : "by a simple declarator-id", tmpl);
14714 16 : inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
14715 16 : type = error_mark_node;
14716 16 : }
14717 :
14718 1027430908 : staticp = 0;
14719 1027430908 : inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
14720 1027430908 : virtualp = decl_spec_seq_has_spec_p (declspecs, ds_virtual);
14721 1027430908 : explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
14722 :
14723 1027430908 : storage_class = declspecs->storage_class;
14724 1027430908 : if (storage_class == sc_static)
14725 23377915 : staticp = 1 + (decl_context == FIELD);
14726 1004052993 : else if (decl_context == FIELD && sfk == sfk_deduction_guide)
14727 : /* Treat class-scope deduction guides as static member functions
14728 : so that they get a FUNCTION_TYPE instead of a METHOD_TYPE. */
14729 23056398 : staticp = 2;
14730 :
14731 1027430908 : if (virtualp)
14732 : {
14733 4118667 : if (staticp == 2)
14734 : {
14735 21 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
14736 21 : richloc.add_range (declspecs->locations[ds_storage_class]);
14737 21 : error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
14738 : "and %<static%>", dname);
14739 21 : storage_class = sc_none;
14740 21 : staticp = 0;
14741 21 : }
14742 4118667 : if (constexpr_p && pedantic && cxx_dialect < cxx20)
14743 : {
14744 6 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
14745 6 : richloc.add_range (declspecs->locations[ds_constexpr]);
14746 6 : pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
14747 : "declared both %<virtual%> and %<constexpr%> only in "
14748 : "%<-std=c++20%> or %<-std=gnu++20%>", dname);
14749 6 : }
14750 : }
14751 1027430908 : friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
14752 :
14753 : /* Issue errors about use of storage classes for parameters. */
14754 1027430908 : if (decl_context == PARM)
14755 : {
14756 291063638 : if (typedef_p)
14757 : {
14758 24 : error_at (declspecs->locations[ds_typedef],
14759 : "typedef declaration invalid in parameter declaration");
14760 24 : return error_mark_node;
14761 : }
14762 291063614 : else if (template_parm_flag && storage_class != sc_none)
14763 : {
14764 16 : error_at (min_location (declspecs->locations[ds_thread],
14765 : declspecs->locations[ds_storage_class]),
14766 : "storage class specified for template parameter %qs",
14767 : name);
14768 16 : return error_mark_node;
14769 : }
14770 291063598 : else if (storage_class == sc_static
14771 291063598 : || storage_class == sc_extern
14772 291063595 : || thread_p)
14773 : {
14774 9 : error_at (min_location (declspecs->locations[ds_thread],
14775 : declspecs->locations[ds_storage_class]),
14776 : "storage class specified for parameter %qs", name);
14777 9 : return error_mark_node;
14778 : }
14779 :
14780 : /* Function parameters cannot be concept. */
14781 291063589 : if (concept_p)
14782 : {
14783 9 : error_at (declspecs->locations[ds_concept],
14784 : "a parameter cannot be declared %qs", "concept");
14785 9 : concept_p = 0;
14786 9 : constexpr_p = 0;
14787 : }
14788 : /* Function parameters cannot be constexpr. If we saw one, moan
14789 : and pretend it wasn't there. */
14790 291063580 : else if (constexpr_p)
14791 : {
14792 9 : error_at (declspecs->locations[ds_constexpr],
14793 : "a parameter cannot be declared %qs", "constexpr");
14794 9 : constexpr_p = 0;
14795 : }
14796 291063589 : if (constinit_p)
14797 : {
14798 6 : error_at (declspecs->locations[ds_constinit],
14799 : "a parameter cannot be declared %qs", "constinit");
14800 6 : constinit_p = 0;
14801 : }
14802 291063589 : if (consteval_p)
14803 : {
14804 3 : error_at (declspecs->locations[ds_consteval],
14805 : "a parameter cannot be declared %qs", "consteval");
14806 3 : consteval_p = 0;
14807 : }
14808 : }
14809 :
14810 : /* Give error if `virtual' is used outside of class declaration. */
14811 1027430859 : if (virtualp
14812 4118667 : && (current_class_name == NULL_TREE || decl_context != FIELD))
14813 : {
14814 68 : error_at (declspecs->locations[ds_virtual],
14815 : "%<virtual%> outside class declaration");
14816 68 : virtualp = 0;
14817 : }
14818 :
14819 1027430859 : if (innermost_code == cdk_decomp)
14820 : {
14821 211048 : location_t loc = (declarator->kind == cdk_reference
14822 220842 : ? declarator->declarator->id_loc : declarator->id_loc);
14823 220842 : if (inlinep)
14824 29 : error_at (declspecs->locations[ds_inline],
14825 : "structured binding declaration cannot be %qs", "inline");
14826 220842 : if (typedef_p)
14827 29 : error_at (declspecs->locations[ds_typedef],
14828 : "structured binding declaration cannot be %qs", "typedef");
14829 220842 : if (constexpr_p && !concept_p && cxx_dialect < cxx26)
14830 99 : pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
14831 : "structured binding declaration can be %qs only with "
14832 : "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
14833 220842 : if (consteval_p)
14834 13 : error_at (declspecs->locations[ds_consteval], "structured "
14835 : "binding declaration cannot be %qs", "consteval");
14836 220842 : if (thread_p && cxx_dialect < cxx20)
14837 75 : pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
14838 : "structured binding declaration can be %qs only in "
14839 : "%<-std=c++20%> or %<-std=gnu++20%>",
14840 75 : declspecs->gnu_thread_keyword_p
14841 : ? "__thread" : "thread_local");
14842 220842 : if (concept_p)
14843 : {
14844 0 : error_at (declspecs->locations[ds_concept],
14845 : "structured binding declaration cannot be %qs", "concept");
14846 0 : constexpr_p = 0;
14847 : }
14848 : /* [dcl.struct.bind] "A cv that includes volatile is deprecated." */
14849 220842 : if (type_quals & TYPE_QUAL_VOLATILE)
14850 26 : warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
14851 : "%<volatile%>-qualified structured binding is deprecated");
14852 220842 : switch (storage_class)
14853 : {
14854 : case sc_none:
14855 : break;
14856 28 : case sc_register:
14857 28 : error_at (loc, "structured binding declaration cannot be %qs",
14858 : "register");
14859 28 : break;
14860 246 : case sc_static:
14861 246 : if (cxx_dialect < cxx20)
14862 185 : pedwarn (loc, OPT_Wc__20_extensions,
14863 : "structured binding declaration can be %qs only in "
14864 : "%<-std=c++20%> or %<-std=gnu++20%>", "static");
14865 : break;
14866 29 : case sc_extern:
14867 29 : error_at (loc, "structured binding declaration cannot be %qs",
14868 : "extern");
14869 29 : break;
14870 28 : case sc_mutable:
14871 28 : error_at (loc, "structured binding declaration cannot be %qs",
14872 : "mutable");
14873 28 : break;
14874 0 : case sc_auto:
14875 0 : error_at (loc, "structured binding declaration cannot be "
14876 : "C++98 %<auto%>");
14877 0 : break;
14878 0 : default:
14879 0 : gcc_unreachable ();
14880 : }
14881 220842 : if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
14882 220842 : || TYPE_IDENTIFIER (type) != auto_identifier)
14883 : {
14884 3 : if (type != error_mark_node)
14885 : {
14886 3 : auto_diagnostic_group d;
14887 3 : error_at (loc, "structured binding declaration cannot have "
14888 : "type %qT", type);
14889 3 : inform (loc,
14890 : "type must be cv-qualified %<auto%> or reference to "
14891 : "cv-qualified %<auto%>");
14892 3 : }
14893 3 : type = build_qualified_type (make_auto (), type_quals);
14894 3 : declspecs->type = type;
14895 : }
14896 220839 : else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
14897 51 : pedwarn (loc, OPT_Wpedantic,
14898 : "structured binding declaration cannot have constrained "
14899 : "%<auto%> type %qT", type);
14900 220842 : inlinep = 0;
14901 220842 : typedef_p = 0;
14902 220842 : consteval_p = 0;
14903 220842 : concept_p = 0;
14904 220842 : if (storage_class != sc_static)
14905 : {
14906 220596 : storage_class = sc_none;
14907 220596 : declspecs->storage_class = sc_none;
14908 : }
14909 : }
14910 :
14911 : /* Static anonymous unions are dealt with here. */
14912 1027430859 : if (staticp && decl_context == TYPENAME
14913 0 : && declspecs->type
14914 1027430859 : && ANON_AGGR_TYPE_P (declspecs->type))
14915 : decl_context = FIELD;
14916 :
14917 : /* Warn about storage classes that are invalid for certain
14918 : kinds of declarations (parameters, typenames, etc.). */
14919 1027430859 : if (thread_p
14920 19919 : && ((storage_class
14921 19919 : && storage_class != sc_extern
14922 526 : && storage_class != sc_static)
14923 19908 : || typedef_p))
14924 : {
14925 17 : location_t loc
14926 17 : = min_location (declspecs->locations[ds_thread],
14927 : declspecs->locations[ds_storage_class]);
14928 17 : error_at (loc, "multiple storage classes in declaration of %qs", name);
14929 17 : thread_p = false;
14930 : }
14931 1027430859 : if (decl_context != NORMAL
14932 860859130 : && ((storage_class != sc_none
14933 860859130 : && storage_class != sc_mutable)
14934 837802745 : || thread_p))
14935 : {
14936 23056388 : if ((decl_context == PARM || decl_context == CATCHPARM)
14937 36 : && (storage_class == sc_register
14938 36 : || storage_class == sc_auto))
14939 : ;
14940 23056352 : else if (typedef_p)
14941 : ;
14942 23056352 : else if (decl_context == FIELD
14943 : /* C++ allows static class elements. */
14944 23056352 : && storage_class == sc_static)
14945 : /* C++ also allows inlines and signed and unsigned elements,
14946 : but in those cases we don't come in here. */
14947 : ;
14948 : else
14949 : {
14950 15 : location_t loc
14951 15 : = min_location (declspecs->locations[ds_thread],
14952 : declspecs->locations[ds_storage_class]);
14953 15 : if (decl_context == FIELD)
14954 15 : error_at (loc, "storage class specified for %qs", name);
14955 0 : else if (decl_context == PARM || decl_context == CATCHPARM)
14956 0 : error_at (loc, "storage class specified for parameter %qs", name);
14957 : else
14958 0 : error_at (loc, "storage class specified for typename");
14959 15 : if (storage_class == sc_register
14960 15 : || storage_class == sc_auto
14961 15 : || storage_class == sc_extern
14962 3 : || thread_p)
14963 15 : storage_class = sc_none;
14964 : }
14965 : }
14966 1004374471 : else if (storage_class == sc_extern && funcdef_flag
14967 1004374471 : && ! toplevel_bindings_p ())
14968 0 : error ("nested function %qs declared %<extern%>", name);
14969 1004374471 : else if (toplevel_bindings_p ())
14970 : {
14971 467415048 : if (storage_class == sc_auto)
14972 2 : error_at (declspecs->locations[ds_storage_class],
14973 : "top-level declaration of %qs specifies %<auto%>", name);
14974 : }
14975 536959423 : else if (thread_p
14976 536959423 : && storage_class != sc_extern
14977 237 : && storage_class != sc_static)
14978 : {
14979 204 : if (declspecs->gnu_thread_keyword_p)
14980 49 : pedwarn (declspecs->locations[ds_thread],
14981 49 : 0, "function-scope %qs implicitly auto and "
14982 : "declared %<__thread%>", name);
14983 :
14984 : /* When thread_local is applied to a variable of block scope the
14985 : storage-class-specifier static is implied if it does not appear
14986 : explicitly. */
14987 204 : storage_class = declspecs->storage_class = sc_static;
14988 204 : staticp = 1;
14989 : }
14990 :
14991 1027430859 : if (storage_class && friendp)
14992 : {
14993 12 : error_at (min_location (declspecs->locations[ds_thread],
14994 : declspecs->locations[ds_storage_class]),
14995 : "storage class specifiers invalid in friend function "
14996 : "declarations");
14997 12 : storage_class = sc_none;
14998 12 : staticp = 0;
14999 : }
15000 :
15001 1027430859 : if (!id_declarator)
15002 : unqualified_id = NULL_TREE;
15003 : else
15004 : {
15005 579241578 : unqualified_id = id_declarator->u.id.unqualified_name;
15006 579241578 : switch (TREE_CODE (unqualified_id))
15007 : {
15008 3227715 : case BIT_NOT_EXPR:
15009 3227715 : unqualified_id = TREE_OPERAND (unqualified_id, 0);
15010 3227715 : if (TYPE_P (unqualified_id))
15011 3227712 : unqualified_id = constructor_name (unqualified_id);
15012 : break;
15013 :
15014 : case IDENTIFIER_NODE:
15015 : case TEMPLATE_ID_EXPR:
15016 : break;
15017 :
15018 0 : default:
15019 0 : gcc_unreachable ();
15020 : }
15021 : }
15022 :
15023 1027430859 : if (declspecs->std_attributes)
15024 : {
15025 723 : location_t attr_loc = declspecs->locations[ds_std_attribute];
15026 723 : auto_diagnostic_group d;
15027 723 : if (any_nonignored_attribute_p (declspecs->std_attributes)
15028 723 : && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
15029 720 : inform (attr_loc, "an attribute that appertains to a type-specifier "
15030 : "is ignored");
15031 723 : }
15032 :
15033 : /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn. */
15034 : bool is_xobj_member_function = false;
15035 : /* Determine the type of the entity declared by recurring on the
15036 : declarator. */
15037 1411233541 : for (; declarator; declarator = declarator->declarator)
15038 : {
15039 963265128 : const cp_declarator *inner_declarator;
15040 963265128 : tree attrs;
15041 :
15042 963265128 : if (type == error_mark_node)
15043 604 : return error_mark_node;
15044 :
15045 963264801 : attrs = declarator->attributes;
15046 963264801 : if (attrs)
15047 : {
15048 13638 : int attr_flags;
15049 :
15050 13638 : attr_flags = 0;
15051 13638 : if (declarator->kind == cdk_id)
15052 12930 : attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
15053 13638 : if (declarator->kind == cdk_function)
15054 691 : attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
15055 13638 : if (declarator->kind == cdk_array)
15056 2 : attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
15057 13638 : tree late_attrs = NULL_TREE;
15058 13638 : if (decl_context != PARM && decl_context != TYPENAME)
15059 : /* Assume that any attributes that get applied late to
15060 : templates will DTRT when applied to the declaration
15061 : as a whole. */
15062 13626 : late_attrs = splice_template_attributes (&attrs, type);
15063 13638 : returned_attrs = decl_attributes (&type,
15064 : attr_chainon (returned_attrs,
15065 : attrs),
15066 : attr_flags);
15067 13638 : returned_attrs = attr_chainon (late_attrs, returned_attrs);
15068 : }
15069 :
15070 963264801 : inner_declarator = declarator->declarator;
15071 :
15072 : /* We don't want to warn in parameter context because we don't
15073 : yet know if the parse will succeed, and this might turn out
15074 : to be a constructor call. */
15075 963264801 : if (decl_context != PARM
15076 963264801 : && decl_context != TYPENAME
15077 559082114 : && !typedef_p
15078 511188927 : && declarator->parenthesized != UNKNOWN_LOCATION
15079 : /* If the type is class-like and the inner name used a
15080 : global namespace qualifier, we need the parens.
15081 : Unfortunately all we can tell is whether a qualified name
15082 : was used or not. */
15083 963264982 : && !(inner_declarator
15084 126 : && inner_declarator->kind == cdk_id
15085 108 : && inner_declarator->u.id.qualifying_scope
15086 18 : && (MAYBE_CLASS_TYPE_P (type)
15087 12 : || TREE_CODE (type) == ENUMERAL_TYPE)))
15088 : {
15089 169 : auto_diagnostic_group d;
15090 169 : if (warning_at (declarator->parenthesized, OPT_Wparentheses,
15091 : "unnecessary parentheses in declaration of %qs",
15092 : name))
15093 : {
15094 42 : gcc_rich_location iloc (declarator->parenthesized);
15095 42 : iloc.add_fixit_remove (get_start (declarator->parenthesized));
15096 42 : iloc.add_fixit_remove (get_finish (declarator->parenthesized));
15097 42 : inform (&iloc, "remove parentheses");
15098 42 : }
15099 169 : }
15100 963264801 : if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
15101 : break;
15102 :
15103 383802959 : switch (declarator->kind)
15104 : {
15105 3529803 : case cdk_array:
15106 7059606 : type = create_array_type_for_decl (dname, type,
15107 3529803 : declarator->u.array.bounds,
15108 3529803 : declarator->id_loc);
15109 3529803 : if (!valid_array_size_p (dname
15110 : ? declarator->id_loc : input_location,
15111 : type, dname))
15112 267 : type = error_mark_node;
15113 :
15114 3529803 : if (declarator->std_attributes)
15115 : /* [dcl.array]/1:
15116 :
15117 : The optional attribute-specifier-seq appertains to the
15118 : array type. */
15119 193 : cplus_decl_attributes (&type, declarator->std_attributes, 0);
15120 : break;
15121 :
15122 188384459 : case cdk_function:
15123 188384459 : {
15124 188384459 : tree arg_types;
15125 188384459 : int funcdecl_p;
15126 :
15127 : /* Declaring a function type. */
15128 :
15129 : /* Pick up type qualifiers which should be applied to `this'. */
15130 188384459 : memfn_quals = declarator->u.function.qualifiers;
15131 : /* Pick up virt-specifiers. */
15132 188384459 : virt_specifiers = declarator->u.function.virt_specifiers;
15133 : /* And ref-qualifier, too */
15134 188384459 : rqual = declarator->u.function.ref_qualifier;
15135 : /* And tx-qualifier. */
15136 188384459 : tree tx_qual = declarator->u.function.tx_qualifier;
15137 : /* Pick up the exception specifications. */
15138 188384459 : raises = declarator->u.function.exception_specification;
15139 : /* If the exception-specification is ill-formed, let's pretend
15140 : there wasn't one. */
15141 188384459 : if (raises == error_mark_node)
15142 9 : raises = NULL_TREE;
15143 :
15144 376768918 : auto find_xobj_parm = [](tree parm_list)
15145 : {
15146 : /* There is no need to iterate over the list,
15147 : only the first parm can be a valid xobj parm. */
15148 376546716 : if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
15149 : return NULL_TREE;
15150 : /* If we make it here, we are looking at an xobj parm.
15151 :
15152 : Non-null 'purpose' usually means the parm has a default
15153 : argument, we don't want to violate this assumption. */
15154 74923 : TREE_PURPOSE (parm_list) = NULL_TREE;
15155 74923 : return TREE_VALUE (parm_list);
15156 : };
15157 :
15158 188384459 : tree xobj_parm
15159 188384459 : = find_xobj_parm (declarator->u.function.parameters);
15160 188384459 : is_xobj_member_function = xobj_parm;
15161 :
15162 188384459 : if (xobj_parm && cxx_dialect < cxx23)
15163 42168 : pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
15164 : "explicit object member function only available "
15165 : "with %<-std=c++23%> or %<-std=gnu++23%>");
15166 :
15167 188384459 : if (xobj_parm && decl_context == TYPENAME)
15168 : {
15169 : /* We inform in every case, just differently depending on what
15170 : case it is. */
15171 6 : auto_diagnostic_group d;
15172 6 : bool ptr_type = true;
15173 : /* If declarator->kind is cdk_function and we are at the end of
15174 : the declarator chain, we are looking at a function type. */
15175 6 : if (!declarator->declarator)
15176 : {
15177 2 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15178 : "a function type cannot "
15179 : "have an explicit object parameter");
15180 2 : ptr_type = false;
15181 : }
15182 4 : else if (declarator->declarator->kind == cdk_pointer)
15183 2 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15184 : "a pointer to function type cannot "
15185 : "have an explicit object parameter");
15186 2 : else if (declarator->declarator->kind == cdk_ptrmem)
15187 2 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15188 : "a pointer to member function type "
15189 : "cannot have an explicit object parameter");
15190 : else
15191 0 : gcc_unreachable ();
15192 :
15193 : /* The locations being used here are probably not correct. */
15194 4 : if (ptr_type)
15195 4 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15196 : "the type of a pointer to explicit object member "
15197 : "function is a regular pointer to function type");
15198 : else
15199 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15200 : "the type of an explicit object "
15201 : "member function is a regular function type");
15202 : /* Ideally we should synthesize the correct syntax
15203 : for the user, perhaps this could be added later. */
15204 6 : }
15205 : /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
15206 : the first parm node will never erroneously be detected here. */
15207 188384459 : {
15208 188384459 : auto_diagnostic_group d;
15209 188384459 : bool bad_xobj_parm_encountered = false;
15210 188384459 : for (tree parm = declarator->u.function.parameters;
15211 467723986 : parm && parm != void_list_node;
15212 279339527 : parm = TREE_CHAIN (parm))
15213 : {
15214 279339527 : if (TREE_PURPOSE (parm) != this_identifier)
15215 279339521 : continue;
15216 6 : bad_xobj_parm_encountered = true;
15217 6 : TREE_PURPOSE (parm) = NULL_TREE;
15218 6 : gcc_rich_location bad_xobj_parm
15219 6 : (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
15220 6 : error_at (&bad_xobj_parm,
15221 : "only the first parameter of a member function "
15222 : "can be declared as an explicit object parameter");
15223 6 : }
15224 188384459 : if (bad_xobj_parm_encountered && xobj_parm)
15225 0 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15226 : "valid explicit object parameter declared here");
15227 188384459 : }
15228 :
15229 188384459 : if (reqs)
15230 3 : error_at (location_of (reqs), "requires-clause on return type");
15231 188384459 : reqs = declarator->u.function.requires_clause;
15232 :
15233 : /* Say it's a definition only for the CALL_EXPR
15234 : closest to the identifier. */
15235 188384459 : funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
15236 :
15237 : /* Handle a late-specified return type. */
15238 188384459 : tree late_return_type = declarator->u.function.late_return_type;
15239 188384459 : if (tree auto_node = type_uses_auto (type))
15240 : {
15241 8251084 : if (!late_return_type)
15242 : {
15243 4737979 : if (!funcdecl_p)
15244 : /* auto (*fp)() = f; is OK. */;
15245 4737945 : else if (current_class_type
15246 8692443 : && LAMBDA_TYPE_P (current_class_type))
15247 : /* OK for C++11 lambdas. */;
15248 3110689 : else if (cxx_dialect < cxx14)
15249 : {
15250 7 : auto_diagnostic_group d;
15251 7 : error_at (typespec_loc, "%qs function uses "
15252 : "%<auto%> type specifier without "
15253 : "trailing return type", name);
15254 7 : inform (typespec_loc,
15255 : "deduced return type only available "
15256 : "with %<-std=c++14%> or %<-std=gnu++14%>");
15257 7 : }
15258 3110682 : else if (virtualp)
15259 : {
15260 6 : error_at (typespec_loc, "virtual function "
15261 : "cannot have deduced return type");
15262 6 : virtualp = false;
15263 : }
15264 : }
15265 3513105 : else if (!is_auto (type) && sfk != sfk_conversion)
15266 : {
15267 15 : error_at (typespec_loc, "%qs function with trailing "
15268 : "return type has %qT as its type rather "
15269 : "than plain %<auto%>", name, type);
15270 274 : return error_mark_node;
15271 : }
15272 3513090 : else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
15273 : {
15274 9 : if (funcdecl_p)
15275 3 : error_at (typespec_loc,
15276 : "%qs function with trailing return type "
15277 : "has %<decltype(auto)%> as its type "
15278 : "rather than plain %<auto%>", name);
15279 : else
15280 6 : error_at (typespec_loc,
15281 : "invalid use of %<decltype(auto)%>");
15282 9 : return error_mark_node;
15283 : }
15284 3513081 : else if (is_constrained_auto (type))
15285 : {
15286 6 : if (funcdecl_p)
15287 3 : error_at (typespec_loc,
15288 : "%qs function with trailing return type "
15289 : "has constrained %<auto%> type specifier "
15290 : "rather than plain %<auto%>",
15291 : name);
15292 : else
15293 3 : error_at (typespec_loc,
15294 : "invalid use of constrained %<auto%> type");
15295 6 : return error_mark_node;
15296 : }
15297 8251054 : tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
15298 8251054 : if (!tmpl)
15299 7067713 : if (tree late_auto = type_uses_auto (late_return_type))
15300 35454 : tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
15301 7067713 : if (tmpl)
15302 : {
15303 1183346 : if (!funcdecl_p || !dguide_name_p (unqualified_id))
15304 : {
15305 12 : auto_diagnostic_group g;
15306 12 : error_at (typespec_loc, "deduced class "
15307 : "type %qD in function return type",
15308 12 : DECL_NAME (tmpl));
15309 12 : inform (DECL_SOURCE_LOCATION (tmpl),
15310 : "%qD declared here", tmpl);
15311 12 : return error_mark_node;
15312 12 : }
15313 1183334 : else if (!late_return_type)
15314 : {
15315 3 : auto_diagnostic_group d;
15316 3 : error_at (declarator->id_loc, "deduction guide "
15317 : "for %qT must have trailing return "
15318 3 : "type", TREE_TYPE (tmpl));
15319 3 : inform (DECL_SOURCE_LOCATION (tmpl),
15320 : "%qD declared here", tmpl);
15321 3 : return error_mark_node;
15322 3 : }
15323 1183331 : else if (CLASS_TYPE_P (late_return_type)
15324 1183331 : && CLASSTYPE_TEMPLATE_INFO (late_return_type)
15325 2366662 : && (CLASSTYPE_TI_TEMPLATE (late_return_type)
15326 : == tmpl))
15327 : /* OK */;
15328 : else
15329 0 : error ("trailing return type %qT of deduction guide "
15330 : "is not a specialization of %qT",
15331 0 : late_return_type, TREE_TYPE (tmpl));
15332 : }
15333 : }
15334 180133375 : else if (late_return_type
15335 180133375 : && sfk != sfk_conversion)
15336 : {
15337 37 : if (late_return_type == error_mark_node)
15338 : return error_mark_node;
15339 37 : if (cxx_dialect < cxx11)
15340 : /* Not using maybe_warn_cpp0x because this should
15341 : always be an error. */
15342 1 : error_at (typespec_loc,
15343 : "trailing return type only available "
15344 : "with %<-std=c++11%> or %<-std=gnu++11%>");
15345 : else
15346 36 : error_at (typespec_loc, "%qs function with trailing "
15347 : "return type not declared with %<auto%> "
15348 : "type specifier", name);
15349 37 : return error_mark_node;
15350 : }
15351 188384377 : if (late_return_type && sfk == sfk_conversion)
15352 : {
15353 14 : error ("a conversion function cannot have a trailing return type");
15354 14 : return error_mark_node;
15355 : }
15356 188384363 : type = splice_late_return_type (type, late_return_type);
15357 188384363 : if (type == error_mark_node)
15358 : return error_mark_node;
15359 :
15360 188384286 : if (late_return_type)
15361 : {
15362 3512985 : late_return_type_p = true;
15363 3512985 : type_quals = cp_type_quals (type);
15364 : }
15365 :
15366 188384286 : if (type_quals != TYPE_UNQUALIFIED)
15367 : {
15368 : /* It's wrong, for instance, to issue a -Wignored-qualifiers
15369 : warning for
15370 : static_assert(!is_same_v<void(*)(), const void(*)()>);
15371 : because there the qualifier matters. */
15372 11796 : if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
15373 232 : warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
15374 : "qualifiers ignored on function return type");
15375 : /* [dcl.fct] "A volatile-qualified return type is
15376 : deprecated." */
15377 11796 : if (type_quals & TYPE_QUAL_VOLATILE)
15378 599 : warning_at (typespec_loc, OPT_Wvolatile,
15379 : "%<volatile%>-qualified return type is "
15380 : "deprecated");
15381 :
15382 : /* We now know that the TYPE_QUALS don't apply to the
15383 : decl, but to its return type. */
15384 : type_quals = TYPE_UNQUALIFIED;
15385 : }
15386 :
15387 : /* Error about some types functions can't return. */
15388 :
15389 188384286 : if (TREE_CODE (type) == FUNCTION_TYPE)
15390 : {
15391 30 : error_at (typespec_loc, "%qs declared as function returning "
15392 : "a function", name);
15393 30 : return error_mark_node;
15394 : }
15395 188384256 : if (TREE_CODE (type) == ARRAY_TYPE)
15396 : {
15397 6 : error_at (typespec_loc, "%qs declared as function returning "
15398 : "an array", name);
15399 6 : return error_mark_node;
15400 : }
15401 188384250 : if (constinit_p && funcdecl_p)
15402 : {
15403 15 : error_at (declspecs->locations[ds_constinit],
15404 : "%<constinit%> on function return type is not "
15405 : "allowed");
15406 15 : return error_mark_node;
15407 : }
15408 :
15409 188384235 : if (check_decltype_auto (typespec_loc, type))
15410 50 : return error_mark_node;
15411 :
15412 188384185 : if (ctype == NULL_TREE
15413 188384185 : && decl_context == FIELD
15414 : && funcdecl_p
15415 108550519 : && friendp == 0)
15416 101939200 : ctype = current_class_type;
15417 :
15418 188384185 : if (ctype && (sfk == sfk_constructor
15419 101939200 : || sfk == sfk_destructor))
15420 : {
15421 : /* We are within a class's scope. If our declarator name
15422 : is the same as the class name, and we are defining
15423 : a function, then it is a constructor/destructor, and
15424 : therefore returns a void type. */
15425 :
15426 : /* ISO C++ 12.4/2. A destructor may not be declared
15427 : const or volatile. A destructor may not be static.
15428 : A destructor may not be declared with ref-qualifier.
15429 :
15430 : ISO C++ 12.1. A constructor may not be declared
15431 : const or volatile. A constructor may not be
15432 : virtual. A constructor may not be static.
15433 : A constructor may not be declared with ref-qualifier. */
15434 26190813 : if (staticp == 2)
15435 9 : error_at (declspecs->locations[ds_storage_class],
15436 : (flags == DTOR_FLAG)
15437 : ? G_("destructor cannot be static member "
15438 : "function")
15439 : : G_("constructor cannot be static member "
15440 : "function"));
15441 26190813 : if (memfn_quals)
15442 : {
15443 9 : error ((flags == DTOR_FLAG)
15444 : ? G_("destructors may not be cv-qualified")
15445 : : G_("constructors may not be cv-qualified"));
15446 9 : memfn_quals = TYPE_UNQUALIFIED;
15447 : }
15448 :
15449 26190813 : if (rqual)
15450 : {
15451 6 : maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
15452 6 : error ((flags == DTOR_FLAG)
15453 : ? G_("destructors may not be ref-qualified")
15454 : : G_("constructors may not be ref-qualified"));
15455 6 : rqual = REF_QUAL_NONE;
15456 : }
15457 :
15458 26190813 : if (decl_context == FIELD
15459 26190813 : && !member_function_or_else (ctype,
15460 : current_class_type,
15461 : flags))
15462 0 : return error_mark_node;
15463 :
15464 26190813 : if (flags != DTOR_FLAG)
15465 : {
15466 : /* It's a constructor. */
15467 23128837 : if (explicitp == 1)
15468 5439881 : explicitp = 2;
15469 23128837 : if (virtualp)
15470 : {
15471 3 : permerror (declspecs->locations[ds_virtual],
15472 : "constructors cannot be declared %<virtual%>");
15473 3 : virtualp = 0;
15474 : }
15475 23128837 : if (decl_context == FIELD
15476 23128837 : && sfk != sfk_constructor)
15477 0 : return error_mark_node;
15478 : }
15479 26190813 : if (decl_context == FIELD)
15480 26190813 : staticp = 0;
15481 : }
15482 162193372 : else if (friendp)
15483 : {
15484 6298808 : if (virtualp)
15485 : {
15486 : /* Cannot be both friend and virtual. */
15487 12 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
15488 12 : richloc.add_range (declspecs->locations[ds_friend]);
15489 12 : error_at (&richloc, "virtual functions cannot be friends");
15490 12 : friendp = 0;
15491 12 : }
15492 6298808 : if (decl_context == NORMAL)
15493 0 : error_at (declarator->id_loc,
15494 : "friend declaration not in class definition");
15495 6298808 : if (current_function_decl && funcdef_flag)
15496 : {
15497 9 : error_at (declarator->id_loc,
15498 : "cannot define friend function %qs in a local "
15499 : "class definition", name);
15500 9 : friendp = 0;
15501 : }
15502 : /* [class.friend]/6: A function can be defined in a friend
15503 : declaration if the function name is unqualified. */
15504 6298808 : if (funcdef_flag && in_namespace)
15505 : {
15506 6 : if (in_namespace == global_namespace)
15507 3 : error_at (declarator->id_loc,
15508 : "friend function definition %qs cannot have "
15509 : "a name qualified with %<::%>", name);
15510 : else
15511 3 : error_at (declarator->id_loc,
15512 : "friend function definition %qs cannot have "
15513 : "a name qualified with %<%D::%>", name,
15514 : in_namespace);
15515 : }
15516 : }
15517 155894564 : else if (ctype && sfk == sfk_conversion)
15518 : {
15519 1004099 : if (explicitp == 1)
15520 : {
15521 470000 : maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
15522 470000 : explicitp = 2;
15523 : }
15524 : }
15525 154890465 : else if (sfk == sfk_deduction_guide)
15526 : {
15527 1183331 : if (explicitp == 1)
15528 188384185 : explicitp = 2;
15529 : }
15530 :
15531 188384185 : if (xobj_parm)
15532 : {
15533 74923 : if (!ctype
15534 74923 : && decl_context == NORMAL
15535 49 : && (in_namespace
15536 49 : || !declarator->declarator->u.id.qualifying_scope))
15537 4 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15538 : "a non-member function cannot have "
15539 : "an explicit object parameter");
15540 : else
15541 : {
15542 74919 : if (virtualp)
15543 : {
15544 16 : auto_diagnostic_group d;
15545 16 : error_at (declspecs->locations[ds_virtual],
15546 : "an explicit object member function cannot "
15547 : "be %<virtual%>");
15548 16 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15549 : "explicit object parameter declared here");
15550 16 : virtualp = false;
15551 16 : }
15552 74919 : if (staticp >= 2)
15553 : {
15554 2 : auto_diagnostic_group d;
15555 2 : error_at (declspecs->locations[ds_storage_class],
15556 : "an explicit object member function cannot "
15557 : "be %<static%>");
15558 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15559 : "explicit object parameter declared here");
15560 2 : }
15561 74919 : if (unqualified_id
15562 188459098 : && identifier_p (unqualified_id)
15563 149832 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
15564 8 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15565 : "%qD cannot be an explicit object member "
15566 : "function", unqualified_id);
15567 : }
15568 : }
15569 188384185 : tree pushed_scope = NULL_TREE;
15570 188384185 : if (funcdecl_p
15571 188384185 : && decl_context != FIELD
15572 77950934 : && inner_declarator->u.id.qualifying_scope
15573 197250293 : && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
15574 8864781 : pushed_scope
15575 8864781 : = push_scope (inner_declarator->u.id.qualifying_scope);
15576 :
15577 188384185 : arg_types = grokparms (declarator->u.function.parameters, &parms);
15578 :
15579 188384185 : if (pushed_scope)
15580 8864781 : pop_scope (pushed_scope);
15581 :
15582 188384185 : if (inner_declarator
15583 188018264 : && inner_declarator->kind == cdk_id
15584 186188942 : && inner_declarator->u.id.sfk == sfk_destructor
15585 3227706 : && arg_types != void_list_node)
15586 : {
15587 20 : error_at (declarator->id_loc,
15588 : "destructors may not have parameters");
15589 20 : arg_types = void_list_node;
15590 20 : parms = NULL_TREE;
15591 20 : is_xobj_member_function = false;
15592 : }
15593 :
15594 188384185 : type = cp_build_function_type (type, arg_types);
15595 :
15596 188384185 : tree attrs = declarator->std_attributes;
15597 188384185 : if (tx_qual)
15598 : {
15599 242 : tree att = build_tree_list (tx_qual, NULL_TREE);
15600 : /* transaction_safe applies to the type, but
15601 : transaction_safe_dynamic applies to the function. */
15602 242 : if (is_attribute_p ("transaction_safe", tx_qual))
15603 213 : attrs = attr_chainon (attrs, att);
15604 : else
15605 29 : returned_attrs = attr_chainon (returned_attrs, att);
15606 : }
15607 :
15608 : /* Actually apply the contract attributes to the declaration. */
15609 188384185 : if (flag_contracts)
15610 14251862 : contract_specifiers
15611 14251862 : = attr_chainon (contract_specifiers,
15612 14251862 : declarator->u.function.contract_specifiers);
15613 :
15614 188384185 : if (attrs)
15615 : /* [dcl.fct]/2:
15616 :
15617 : The optional attribute-specifier-seq appertains to
15618 : the function type. */
15619 497 : cplus_decl_attributes (&type, attrs, 0);
15620 :
15621 188384185 : if (raises)
15622 75089840 : type = build_exception_variant (type, raises);
15623 : }
15624 188384185 : break;
15625 :
15626 191888697 : case cdk_pointer:
15627 191888697 : case cdk_reference:
15628 191888697 : case cdk_ptrmem:
15629 : /* Filter out pointers-to-references and references-to-references.
15630 : We can get these if a TYPE_DECL is used. */
15631 :
15632 191888697 : if (TYPE_REF_P (type))
15633 : {
15634 239 : if (declarator->kind != cdk_reference)
15635 : {
15636 3 : error ("cannot declare pointer to %q#T", type);
15637 3 : type = TREE_TYPE (type);
15638 : }
15639 :
15640 : /* In C++0x, we allow reference to reference declarations
15641 : that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
15642 : and template type arguments [14.3.1/4 temp.arg.type]. The
15643 : check for direct reference to reference declarations, which
15644 : are still forbidden, occurs below. Reasoning behind the change
15645 : can be found in DR106, DR540, and the rvalue reference
15646 : proposals. */
15647 236 : else if (cxx_dialect == cxx98)
15648 : {
15649 0 : error ("cannot declare reference to %q#T", type);
15650 0 : type = TREE_TYPE (type);
15651 : }
15652 : }
15653 191888458 : else if (VOID_TYPE_P (type))
15654 : {
15655 5068752 : if (declarator->kind == cdk_reference)
15656 4 : error ("cannot declare reference to %q#T", type);
15657 5068748 : else if (declarator->kind == cdk_ptrmem)
15658 3 : error ("cannot declare pointer to %q#T member", type);
15659 : }
15660 :
15661 : /* We now know that the TYPE_QUALS don't apply to the decl,
15662 : but to the target of the pointer. */
15663 191888697 : type_quals = TYPE_UNQUALIFIED;
15664 :
15665 : /* This code used to handle METHOD_TYPE, but I don't think it's
15666 : possible to get it here anymore. */
15667 191888697 : gcc_assert (TREE_CODE (type) != METHOD_TYPE);
15668 191888697 : if (declarator->kind == cdk_ptrmem
15669 1100064 : && TREE_CODE (type) == FUNCTION_TYPE)
15670 : {
15671 890828 : memfn_quals |= type_memfn_quals (type);
15672 1781656 : type = build_memfn_type (type,
15673 890828 : declarator->u.pointer.class_type,
15674 : memfn_quals,
15675 : rqual);
15676 890828 : if (type == error_mark_node)
15677 : return error_mark_node;
15678 :
15679 : rqual = REF_QUAL_NONE;
15680 : memfn_quals = TYPE_UNQUALIFIED;
15681 : }
15682 :
15683 191888694 : if (TREE_CODE (type) == FUNCTION_TYPE
15684 191888694 : && (type_memfn_quals (type) != TYPE_UNQUALIFIED
15685 1010616 : || type_memfn_rqual (type) != REF_QUAL_NONE))
15686 15 : error (declarator->kind == cdk_reference
15687 : ? G_("cannot declare reference to qualified function type %qT")
15688 : : G_("cannot declare pointer to qualified function type %qT"),
15689 : type);
15690 :
15691 : /* When the pointed-to type involves components of variable size,
15692 : care must be taken to ensure that the size evaluation code is
15693 : emitted early enough to dominate all the possible later uses
15694 : and late enough for the variables on which it depends to have
15695 : been assigned.
15696 :
15697 : This is expected to happen automatically when the pointed-to
15698 : type has a name/declaration of it's own, but special attention
15699 : is required if the type is anonymous.
15700 :
15701 : We handle the NORMAL and FIELD contexts here by inserting a
15702 : dummy statement that just evaluates the size at a safe point
15703 : and ensures it is not deferred until e.g. within a deeper
15704 : conditional context (c++/43555).
15705 :
15706 : We expect nothing to be needed here for PARM or TYPENAME.
15707 : Evaluating the size at this point for TYPENAME would
15708 : actually be incorrect, as we might be in the middle of an
15709 : expression with side effects on the pointed-to type size
15710 : "arguments" prior to the pointer declaration point and the
15711 : size evaluation could end up prior to the side effects. */
15712 :
15713 191888694 : if (!TYPE_NAME (type)
15714 5445810 : && (decl_context == NORMAL || decl_context == FIELD)
15715 611257 : && at_function_scope_p ()
15716 191929040 : && variably_modified_type_p (type, NULL_TREE))
15717 : {
15718 119 : TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
15719 : NULL_TREE, type);
15720 119 : add_decl_expr (TYPE_NAME (type));
15721 : }
15722 :
15723 191888694 : if (declarator->kind == cdk_reference)
15724 : {
15725 : /* In C++0x, the type we are creating a reference to might be
15726 : a typedef which is itself a reference type. In that case,
15727 : we follow the reference collapsing rules in
15728 : [7.1.3/8 dcl.typedef] to create the final reference type:
15729 :
15730 : "If a typedef TD names a type that is a reference to a type
15731 : T, an attempt to create the type 'lvalue reference to cv TD'
15732 : creates the type 'lvalue reference to T,' while an attempt
15733 : to create the type "rvalue reference to cv TD' creates the
15734 : type TD."
15735 : */
15736 128367737 : if (VOID_TYPE_P (type))
15737 : /* We already gave an error. */;
15738 128367733 : else if (TYPE_REF_P (type))
15739 : {
15740 236 : if (declarator->u.reference.rvalue_ref)
15741 : /* Leave type alone. */;
15742 : else
15743 116 : type = cp_build_reference_type (TREE_TYPE (type), false);
15744 : }
15745 : else
15746 128367497 : type = cp_build_reference_type
15747 128367497 : (type, declarator->u.reference.rvalue_ref);
15748 :
15749 : /* In C++0x, we need this check for direct reference to
15750 : reference declarations, which are forbidden by
15751 : [8.3.2/5 dcl.ref]. Reference to reference declarations
15752 : are only allowed indirectly through typedefs and template
15753 : type arguments. Example:
15754 :
15755 : void foo(int & &); // invalid ref-to-ref decl
15756 :
15757 : typedef int & int_ref;
15758 : void foo(int_ref &); // valid ref-to-ref decl
15759 : */
15760 128367737 : if (inner_declarator && inner_declarator->kind == cdk_reference)
15761 1 : error ("cannot declare reference to %q#T, which is not "
15762 : "a typedef or a template type argument", type);
15763 : }
15764 63520957 : else if (TREE_CODE (type) == METHOD_TYPE)
15765 890825 : type = build_ptrmemfunc_type (build_pointer_type (type));
15766 62630132 : else if (declarator->kind == cdk_ptrmem)
15767 : {
15768 209236 : gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
15769 : != NAMESPACE_DECL);
15770 209236 : if (declarator->u.pointer.class_type == error_mark_node)
15771 : /* We will already have complained. */
15772 3 : type = error_mark_node;
15773 : else
15774 209233 : type = build_ptrmem_type (declarator->u.pointer.class_type,
15775 : type);
15776 : }
15777 : else
15778 62420896 : type = build_pointer_type (type);
15779 :
15780 : /* Process a list of type modifier keywords (such as
15781 : const or volatile) that were given inside the `*' or `&'. */
15782 :
15783 191888694 : if (declarator->u.pointer.qualifiers)
15784 : {
15785 8452279 : type
15786 8452279 : = cp_build_qualified_type (type,
15787 : declarator->u.pointer.qualifiers);
15788 8452279 : type_quals = cp_type_quals (type);
15789 : }
15790 :
15791 : /* Apply C++11 attributes to the pointer, and not to the
15792 : type pointed to. This is unlike what is done for GNU
15793 : attributes above. It is to comply with [dcl.ptr]/1:
15794 :
15795 : [the optional attribute-specifier-seq (7.6.1) appertains
15796 : to the pointer and not to the object pointed to]. */
15797 191888694 : if (declarator->std_attributes)
15798 173 : cplus_decl_attributes (&type, declarator->std_attributes, 0);
15799 :
15800 : ctype = NULL_TREE;
15801 : break;
15802 :
15803 : case cdk_error:
15804 : break;
15805 :
15806 0 : default:
15807 0 : gcc_unreachable ();
15808 : }
15809 : }
15810 :
15811 1027430255 : id_loc = declarator ? declarator->id_loc : input_location;
15812 :
15813 1027430255 : if (innermost_code != cdk_function
15814 : /* Don't check this if it can be the artifical decltype(auto)
15815 : we created when building a constraint in a compound-requirement:
15816 : that the type-constraint is plain is going to be checked in
15817 : cp_parser_compound_requirement. */
15818 1027430255 : && decl_context != TYPENAME
15819 1027430255 : && check_decltype_auto (id_loc, type))
15820 20 : return error_mark_node;
15821 :
15822 : /* A `constexpr' specifier used in an object declaration declares
15823 : the object as `const'. */
15824 1027430235 : if (constexpr_p && innermost_code != cdk_function)
15825 : {
15826 : /* DR1688 says that a `constexpr' specifier in combination with
15827 : `volatile' is valid. */
15828 :
15829 19307538 : if (!TYPE_REF_P (type))
15830 : {
15831 19292669 : type_quals |= TYPE_QUAL_CONST;
15832 19292669 : type = cp_build_qualified_type (type, type_quals);
15833 : }
15834 : }
15835 :
15836 579240983 : if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
15837 2730459 : && !FUNC_OR_METHOD_TYPE_P (type)
15838 1029213311 : && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
15839 : {
15840 0 : error ("template-id %qD used as a declarator",
15841 : unqualified_id);
15842 0 : unqualified_id = dname;
15843 : }
15844 :
15845 : /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
15846 : qualified with a class-name, turn it into a METHOD_TYPE, unless
15847 : we know that the function is static. We take advantage of this
15848 : opportunity to do other processing that pertains to entities
15849 : explicitly declared to be class members. Note that if DECLARATOR
15850 : is non-NULL, we know it is a cdk_id declarator; otherwise, we
15851 : would not have exited the loop above. */
15852 1027430235 : if (declarator
15853 579461825 : && declarator->kind == cdk_id
15854 579240983 : && declarator->u.id.qualifying_scope
15855 1037025877 : && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
15856 : {
15857 9357484 : ctype = declarator->u.id.qualifying_scope;
15858 9357484 : ctype = TYPE_MAIN_VARIANT (ctype);
15859 9357484 : template_count = num_template_headers_for_class (ctype);
15860 :
15861 9357484 : if (ctype == current_class_type)
15862 : {
15863 54 : if (friendp)
15864 : {
15865 15 : permerror (declspecs->locations[ds_friend],
15866 : "member functions are implicitly "
15867 : "friends of their class");
15868 15 : friendp = 0;
15869 : }
15870 : else
15871 39 : permerror (id_loc, "extra qualification %<%T::%> on member %qs",
15872 : ctype, name);
15873 : }
15874 9357430 : else if (/* If the qualifying type is already complete, then we
15875 : can skip the following checks. */
15876 9357430 : !COMPLETE_TYPE_P (ctype)
15877 154 : && (/* If the function is being defined, then
15878 : qualifying type must certainly be complete. */
15879 : funcdef_flag
15880 : /* A friend declaration of "T::f" is OK, even if
15881 : "T" is a template parameter. But, if this
15882 : function is not a friend, the qualifying type
15883 : must be a class. */
15884 117 : || (!friendp && !CLASS_TYPE_P (ctype))
15885 : /* For a declaration, the type need not be
15886 : complete, if either it is dependent (since there
15887 : is no meaningful definition of complete in that
15888 : case) or the qualifying class is currently being
15889 : defined. */
15890 129 : || !(dependent_type_p (ctype)
15891 24 : || currently_open_class (ctype)))
15892 : /* Check that the qualifying type is complete. */
15893 9357494 : && !complete_type_or_else (ctype, NULL_TREE))
15894 64 : return error_mark_node;
15895 9357366 : else if (TREE_CODE (type) == FUNCTION_TYPE)
15896 : {
15897 8865030 : if (current_class_type
15898 276 : && (!friendp || funcdef_flag || initialized))
15899 : {
15900 57 : error_at (id_loc, funcdef_flag || initialized
15901 : ? G_("cannot define member function %<%T::%s%> "
15902 : "within %qT")
15903 : : G_("cannot declare member function %<%T::%s%> "
15904 : "within %qT"),
15905 : ctype, name, current_class_type);
15906 48 : return error_mark_node;
15907 : }
15908 : }
15909 492336 : else if (typedef_p && current_class_type)
15910 : {
15911 0 : error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
15912 : ctype, name, current_class_type);
15913 0 : return error_mark_node;
15914 : }
15915 : }
15916 :
15917 1027430123 : if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
15918 57570526 : ctype = current_class_type;
15919 :
15920 : /* Now TYPE has the actual type. */
15921 :
15922 1027430123 : if (returned_attrs)
15923 : {
15924 2938 : if (attrlist)
15925 2938 : *attrlist = attr_chainon (returned_attrs, *attrlist);
15926 : else
15927 : attrlist = &returned_attrs;
15928 : }
15929 :
15930 1027430123 : if (declarator
15931 579461713 : && declarator->kind == cdk_id
15932 579240871 : && declarator->std_attributes
15933 558056 : && attrlist != NULL)
15934 : {
15935 : /* [dcl.meaning]/1: The optional attribute-specifier-seq following
15936 : a declarator-id appertains to the entity that is declared. */
15937 558053 : if (declarator->std_attributes != error_mark_node)
15938 : {
15939 558035 : if (flag_reflection
15940 : && declarator->std_attributes != error_mark_node
15941 12914 : && lookup_attribute ("internal ", "annotation ",
15942 : declarator->std_attributes)
15943 20 : && *attrlist != error_mark_node
15944 558055 : && lookup_attribute ("internal ", "annotation ", *attrlist))
15945 : /* If there are annotations in both lists, ensure
15946 : declarator->std_attributes go after *attrlist. See
15947 : PR124399. */
15948 7 : *attrlist = chainon (copy_list (*attrlist),
15949 7 : declarator->std_attributes);
15950 : else
15951 558028 : *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
15952 : }
15953 : else
15954 : /* We should have already diagnosed the issue (c++/78344). */
15955 18 : gcc_assert (seen_error ());
15956 : }
15957 :
15958 : /* Handle parameter packs. */
15959 1027430123 : if (parameter_pack_p)
15960 : {
15961 3010620 : if (decl_context == PARM)
15962 : /* Turn the type into a pack expansion.*/
15963 3010620 : type = make_pack_expansion (type);
15964 : else
15965 0 : error ("non-parameter %qs cannot be a parameter pack", name);
15966 : }
15967 :
15968 1027430123 : if ((decl_context == FIELD || decl_context == PARM)
15969 456871979 : && !processing_template_decl
15970 1173661848 : && variably_modified_type_p (type, NULL_TREE))
15971 : {
15972 12 : if (decl_context == FIELD)
15973 6 : error_at (id_loc,
15974 : "data member may not have variably modified type %qT", type);
15975 : else
15976 6 : error_at (id_loc,
15977 : "parameter may not have variably modified type %qT", type);
15978 12 : type = error_mark_node;
15979 : }
15980 :
15981 1027430123 : if (explicitp == 1 || (explicitp && friendp))
15982 : {
15983 : /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
15984 : in the declaration of a constructor or conversion function within
15985 : a class definition. */
15986 74 : if (!current_class_type)
15987 59 : error_at (declspecs->locations[ds_explicit],
15988 : "%<explicit%> outside class declaration");
15989 15 : else if (friendp)
15990 12 : error_at (declspecs->locations[ds_explicit],
15991 : "%<explicit%> in friend declaration");
15992 : else
15993 3 : error_at (declspecs->locations[ds_explicit],
15994 : "only declarations of constructors and conversion operators "
15995 : "can be %<explicit%>");
15996 : explicitp = 0;
15997 : }
15998 :
15999 1027430123 : if (storage_class == sc_mutable)
16000 : {
16001 148430 : location_t sloc = declspecs->locations[ds_storage_class];
16002 148430 : if (decl_context != FIELD || friendp)
16003 : {
16004 30 : error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
16005 : name);
16006 30 : storage_class = sc_none;
16007 : }
16008 148400 : else if (decl_context == TYPENAME || typedef_p)
16009 : {
16010 0 : error_at (sloc,
16011 : "non-object member %qs cannot be declared %<mutable%>",
16012 : name);
16013 0 : storage_class = sc_none;
16014 : }
16015 148400 : else if (FUNC_OR_METHOD_TYPE_P (type))
16016 : {
16017 3 : error_at (sloc, "function %qs cannot be declared %<mutable%>",
16018 : name);
16019 3 : storage_class = sc_none;
16020 : }
16021 148397 : else if (staticp)
16022 : {
16023 0 : error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
16024 : name);
16025 0 : storage_class = sc_none;
16026 : }
16027 148397 : else if (type_quals & TYPE_QUAL_CONST)
16028 : {
16029 9 : error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
16030 : name);
16031 9 : storage_class = sc_none;
16032 : }
16033 148388 : else if (TYPE_REF_P (type))
16034 : {
16035 6 : permerror (sloc, "reference %qs cannot be declared %<mutable%>",
16036 : name);
16037 6 : storage_class = sc_none;
16038 : }
16039 : }
16040 :
16041 : /* If this is declaring a typedef name, return a TYPE_DECL. */
16042 1027430123 : if (typedef_p && decl_context != TYPENAME)
16043 : {
16044 46796316 : bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
16045 46796316 : tree decl;
16046 :
16047 46796316 : if (funcdef_flag)
16048 : {
16049 6 : if (decl_context == NORMAL)
16050 3 : error_at (id_loc,
16051 : "typedef may not be a function definition");
16052 : else
16053 3 : error_at (id_loc,
16054 : "typedef may not be a member function definition");
16055 6 : return error_mark_node;
16056 : }
16057 :
16058 : /* This declaration:
16059 :
16060 : typedef void f(int) const;
16061 :
16062 : declares a function type which is not a member of any
16063 : particular class, but which is cv-qualified; for
16064 : example "f S::*" declares a pointer to a const-qualified
16065 : member function of S. We record the cv-qualification in the
16066 : function type. */
16067 46796310 : if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
16068 : {
16069 62 : type = apply_memfn_quals (type, memfn_quals, rqual);
16070 :
16071 : /* We have now dealt with these qualifiers. */
16072 62 : memfn_quals = TYPE_UNQUALIFIED;
16073 62 : rqual = REF_QUAL_NONE;
16074 : }
16075 :
16076 46796310 : if (type_uses_auto (type))
16077 : {
16078 62 : if (alias_p)
16079 20 : error_at (declspecs->locations[ds_type_spec],
16080 : "%<auto%> not allowed in alias declaration");
16081 : else
16082 42 : error_at (declspecs->locations[ds_type_spec],
16083 : "typedef declared %<auto%>");
16084 62 : type = error_mark_node;
16085 : }
16086 :
16087 46796310 : if (reqs)
16088 3 : error_at (location_of (reqs), "requires-clause on typedef");
16089 :
16090 46796310 : if (id_declarator && declarator->u.id.qualifying_scope)
16091 : {
16092 21 : error_at (id_loc, "typedef name may not be a nested-name-specifier");
16093 21 : type = error_mark_node;
16094 : }
16095 :
16096 46796310 : if (decl_context == FIELD)
16097 25034676 : decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
16098 : else
16099 21761634 : decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
16100 :
16101 46796310 : if (decl_context != FIELD)
16102 : {
16103 21761634 : if (!current_function_decl)
16104 9544137 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
16105 12217497 : else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
16106 : /* The TYPE_DECL is "abstract" because there will be
16107 : clones of this constructor/destructor, and there will
16108 : be copies of this TYPE_DECL generated in those
16109 : clones. The decloning optimization (for space) may
16110 : revert this subsequently if it determines that
16111 : the clones should share a common implementation. */
16112 155526 : DECL_ABSTRACT_P (decl) = true;
16113 :
16114 21761634 : set_originating_module (decl);
16115 : }
16116 25034676 : else if (current_class_type
16117 25034676 : && constructor_name_p (unqualified_id, current_class_type))
16118 3 : permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
16119 : "as enclosing class",
16120 : unqualified_id);
16121 :
16122 : /* If the user declares "typedef struct {...} foo" then the
16123 : struct will have an anonymous name. Fill that name in now.
16124 : Nothing can refer to it, so nothing needs know about the name
16125 : change. */
16126 46796310 : if (type != error_mark_node
16127 46796227 : && unqualified_id
16128 46796224 : && TYPE_NAME (type)
16129 43546307 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16130 86972053 : && (TYPE_UNNAMED_P (type)
16131 : /* An enum may have previously used an enumerator for linkage
16132 : purposes, but we want the typedef name to take priority. */
16133 43155873 : || enum_with_enumerator_for_linkage_p (type))
16134 390850 : && declspecs->type_definition_p
16135 390777 : && attributes_naming_typedef_ok (*attrlist)
16136 47187084 : && cp_type_quals (type) == TYPE_UNQUALIFIED)
16137 390756 : name_unnamed_type (type, decl);
16138 :
16139 46796310 : if (signed_p
16140 46796310 : || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
16141 374724 : C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
16142 :
16143 46796310 : bad_specifiers (decl, BSP_TYPE, virtualp,
16144 : memfn_quals != TYPE_UNQUALIFIED,
16145 : inlinep, friendp, raises != NULL_TREE,
16146 : declspecs->locations);
16147 :
16148 46796310 : if (alias_p)
16149 : /* Acknowledge that this was written:
16150 : `using analias = atype;'. */
16151 20978127 : TYPE_DECL_ALIAS_P (decl) = 1;
16152 :
16153 46796310 : return decl;
16154 : }
16155 :
16156 : /* Detect the case of an array type of unspecified size
16157 : which came, as such, direct from a typedef name.
16158 : We must copy the type, so that the array's domain can be
16159 : individually set by the object's initializer. */
16160 :
16161 980633807 : if (type && typedef_type
16162 951302799 : && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
16163 981220157 : && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
16164 81 : type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
16165 :
16166 : /* Detect where we're using a typedef of function type to declare a
16167 : function. PARMS will not be set, so we must create it now. */
16168 :
16169 980633807 : if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
16170 : {
16171 15530 : tree decls = NULL_TREE;
16172 15530 : tree args;
16173 :
16174 15530 : for (args = TYPE_ARG_TYPES (type);
16175 33527 : args && args != void_list_node;
16176 17997 : args = TREE_CHAIN (args))
16177 : {
16178 17997 : tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
16179 17997 : TREE_VALUE (args));
16180 :
16181 17997 : DECL_CHAIN (decl) = decls;
16182 17997 : decls = decl;
16183 : }
16184 :
16185 15530 : parms = nreverse (decls);
16186 :
16187 15530 : if (decl_context != TYPENAME)
16188 : {
16189 : /* The qualifiers on the function type become the qualifiers on
16190 : the non-static member function. */
16191 14814 : memfn_quals |= type_memfn_quals (type);
16192 14814 : rqual = type_memfn_rqual (type);
16193 14814 : type_quals = TYPE_UNQUALIFIED;
16194 14814 : raises = TYPE_RAISES_EXCEPTIONS (type);
16195 : }
16196 : }
16197 :
16198 : /* If this is a type name (such as, in a cast or sizeof),
16199 : compute the type and return it now. */
16200 :
16201 980633091 : if (decl_context == TYPENAME)
16202 : {
16203 : /* Note that here we don't care about type_quals. */
16204 :
16205 : /* Special case: "friend class foo" looks like a TYPENAME context. */
16206 403508310 : if (friendp)
16207 : {
16208 0 : if (inlinep)
16209 : {
16210 0 : error ("%<inline%> specified for friend class declaration");
16211 0 : inlinep = 0;
16212 : }
16213 :
16214 0 : if (!current_aggr)
16215 : {
16216 : /* Don't allow friend declaration without a class-key. */
16217 0 : if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
16218 0 : permerror (input_location, "template parameters cannot be friends");
16219 0 : else if (TREE_CODE (type) == TYPENAME_TYPE)
16220 0 : permerror (input_location, "friend declaration requires class-key, "
16221 : "i.e. %<friend class %T::%D%>",
16222 0 : TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
16223 : else
16224 0 : permerror (input_location, "friend declaration requires class-key, "
16225 : "i.e. %<friend %#T%>",
16226 : type);
16227 : }
16228 :
16229 : /* Only try to do this stuff if we didn't already give up. */
16230 0 : if (type != integer_type_node)
16231 : {
16232 : /* A friendly class? */
16233 0 : if (current_class_type)
16234 0 : make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
16235 : /*complain=*/true);
16236 : else
16237 0 : error ("trying to make class %qT a friend of global scope",
16238 : type);
16239 :
16240 0 : type = void_type_node;
16241 : }
16242 : }
16243 403508310 : else if (memfn_quals || rqual)
16244 : {
16245 10362 : if (ctype == NULL_TREE
16246 10362 : && TREE_CODE (type) == METHOD_TYPE)
16247 0 : ctype = TYPE_METHOD_BASETYPE (type);
16248 :
16249 10362 : if (ctype)
16250 0 : type = build_memfn_type (type, ctype, memfn_quals, rqual);
16251 : /* Core issue #547: need to allow this in template type args.
16252 : Allow it in general in C++11 for alias-declarations. */
16253 10362 : else if ((template_type_arg || cxx_dialect >= cxx11)
16254 10360 : && TREE_CODE (type) == FUNCTION_TYPE)
16255 10358 : type = apply_memfn_quals (type, memfn_quals, rqual);
16256 : else
16257 4 : error ("invalid qualifiers on non-member function type");
16258 : }
16259 :
16260 403508310 : if (reqs)
16261 3 : error_at (location_of (reqs), "requires-clause on type-id");
16262 :
16263 403508310 : return type;
16264 : }
16265 577125497 : else if (unqualified_id == NULL_TREE && decl_context != PARM
16266 820130 : && decl_context != CATCHPARM
16267 354915 : && TREE_CODE (type) != UNION_TYPE
16268 354608 : && ! bitfield
16269 354608 : && innermost_code != cdk_decomp)
16270 : {
16271 9 : error ("abstract declarator %qT used as declaration", type);
16272 9 : return error_mark_node;
16273 : }
16274 :
16275 577125488 : if (!FUNC_OR_METHOD_TYPE_P (type))
16276 : {
16277 : /* Only functions may be declared using an operator-function-id. */
16278 390975255 : if (dname && IDENTIFIER_ANY_OP_P (dname))
16279 : {
16280 8 : error_at (id_loc, "declaration of %qD as non-function", dname);
16281 8 : return error_mark_node;
16282 : }
16283 :
16284 390975247 : if (reqs)
16285 15 : error_at (location_of (reqs),
16286 : "requires-clause on declaration of non-function type %qT",
16287 : type);
16288 : }
16289 :
16290 : /* We don't check parameter types here because we can emit a better
16291 : error message later. */
16292 577125480 : if (decl_context != PARM)
16293 : {
16294 286061993 : type = check_var_type (unqualified_id, type, id_loc);
16295 286061993 : if (type == error_mark_node)
16296 : return error_mark_node;
16297 : }
16298 :
16299 : /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
16300 : or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
16301 :
16302 577125400 : if (decl_context == PARM || decl_context == CATCHPARM)
16303 : {
16304 291542031 : if (ctype || in_namespace)
16305 0 : error ("cannot use %<::%> in parameter declaration");
16306 :
16307 291542031 : tree auto_node = type_uses_auto (type);
16308 291542031 : if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
16309 : {
16310 120 : bool err_p = true;
16311 120 : if (cxx_dialect >= cxx14)
16312 : {
16313 212 : if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
16314 3 : error_at (typespec_loc,
16315 : "cannot declare a parameter with %<decltype(auto)%>");
16316 109 : else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
16317 : {
16318 5 : auto_diagnostic_group g;
16319 5 : gcc_rich_location richloc (typespec_loc);
16320 5 : richloc.add_fixit_insert_after ("<>");
16321 5 : error_at (&richloc,
16322 : "missing template argument list after %qE; template "
16323 : "placeholder not permitted in parameter", c);
16324 5 : if (decl_context == PARM && cxx_dialect >= cxx20)
16325 4 : inform (typespec_loc, "or use %<auto%> for an "
16326 : "abbreviated function template");
16327 5 : inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
16328 5 : }
16329 104 : else if (decl_context == CATCHPARM || template_parm_flag)
16330 14 : error_at (typespec_loc,
16331 : "%<auto%> parameter not permitted in this context");
16332 : else
16333 : /* Do not issue an error while tentatively parsing a function
16334 : parameter: for T t(auto(a), 42);, when we just saw the 1st
16335 : parameter, we don't know yet that this construct won't be
16336 : a function declaration. Defer the checking to
16337 : cp_parser_parameter_declaration_clause. */
16338 : err_p = false;
16339 : }
16340 : else
16341 8 : error_at (typespec_loc, "parameter declared %<auto%>");
16342 30 : if (err_p)
16343 30 : type = error_mark_node;
16344 : }
16345 :
16346 : /* A parameter declared as an array of T is really a pointer to T.
16347 : One declared as a function is really a pointer to a function.
16348 : One declared as a member is really a pointer to member. */
16349 :
16350 291542031 : if (TREE_CODE (type) == ARRAY_TYPE)
16351 : {
16352 : /* Transfer const-ness of array into that of type pointed to. */
16353 757533 : type = build_pointer_type (TREE_TYPE (type));
16354 757533 : type_quals = TYPE_UNQUALIFIED;
16355 757533 : array_parameter_p = true;
16356 : }
16357 290784498 : else if (TREE_CODE (type) == FUNCTION_TYPE)
16358 99931 : type = build_pointer_type (type);
16359 : }
16360 :
16361 143832326 : if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
16362 : /* Don't convert xobj member functions to METHOD_TYPE. */
16363 110804016 : && !is_xobj_member_function
16364 677668701 : && !(unqualified_id
16365 201079971 : && identifier_p (unqualified_id)
16366 100542917 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
16367 : {
16368 100537054 : cp_cv_quals real_quals = memfn_quals;
16369 100537054 : if (cxx_dialect < cxx14 && constexpr_p
16370 709911 : && sfk != sfk_constructor && sfk != sfk_destructor)
16371 3820 : real_quals |= TYPE_QUAL_CONST;
16372 100537054 : type = build_memfn_type (type, ctype, real_quals, rqual);
16373 : }
16374 :
16375 577125400 : {
16376 577125400 : tree decl = NULL_TREE;
16377 :
16378 577125400 : if (decl_context == PARM)
16379 : {
16380 291063487 : decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
16381 291063487 : DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
16382 :
16383 291063487 : bad_specifiers (decl, BSP_PARM, virtualp,
16384 : memfn_quals != TYPE_UNQUALIFIED,
16385 : inlinep, friendp, raises != NULL_TREE,
16386 : declspecs->locations);
16387 : }
16388 286061913 : else if (decl_context == FIELD)
16389 : {
16390 140773801 : if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
16391 19665448 : if (tree auto_node = type_uses_auto (type))
16392 : {
16393 24 : location_t tloc = declspecs->locations[ds_type_spec];
16394 24 : if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
16395 6 : error_at (tloc, "invalid use of template-name %qE without an "
16396 : "argument list",
16397 6 : CLASS_PLACEHOLDER_TEMPLATE (auto_node));
16398 : else
16399 18 : error_at (tloc, "non-static data member declared with "
16400 : "placeholder %qT", auto_node);
16401 24 : type = error_mark_node;
16402 : }
16403 :
16404 : /* The C99 flexible array extension. */
16405 117717448 : if (!staticp && TREE_CODE (type) == ARRAY_TYPE
16406 141883527 : && TYPE_DOMAIN (type) == NULL_TREE)
16407 : {
16408 1399 : if (ctype
16409 1399 : && (TREE_CODE (ctype) == UNION_TYPE
16410 1399 : || TREE_CODE (ctype) == QUAL_UNION_TYPE))
16411 84 : pedwarn (id_loc, OPT_Wpedantic,
16412 : "flexible array member in union is a GCC extension");
16413 :
16414 : else
16415 : {
16416 : /* Array is a flexible member. */
16417 1315 : if (name)
16418 1315 : pedwarn (id_loc, OPT_Wpedantic,
16419 : "ISO C++ forbids flexible array member %qs", name);
16420 : else
16421 : pedwarn (input_location, OPT_Wpedantic,
16422 : "ISO C++ forbids flexible array members");
16423 :
16424 : /* Flexible array member has a null domain. */
16425 1315 : type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
16426 : }
16427 : }
16428 :
16429 140773801 : if (type == error_mark_node)
16430 : {
16431 : /* Happens when declaring arrays of sizes which
16432 : are error_mark_node, for example. */
16433 24 : decl = NULL_TREE;
16434 : }
16435 140773777 : else if (in_namespace && !friendp)
16436 : {
16437 : /* Something like struct S { int N::j; }; */
16438 6 : error_at (id_loc, "invalid use of %<::%>");
16439 6 : return error_mark_node;
16440 : }
16441 140773771 : else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
16442 : {
16443 108237785 : int publicp = 0;
16444 108237785 : tree function_context;
16445 :
16446 108237785 : if (friendp == 0)
16447 : {
16448 : /* This should never happen in pure C++ (the check
16449 : could be an assert). It could happen in
16450 : Objective-C++ if someone writes invalid code that
16451 : uses a function declaration for an instance
16452 : variable or property (instance variables and
16453 : properties are parsed as FIELD_DECLs, but they are
16454 : part of an Objective-C class, not a C++ class).
16455 : That code is invalid and is caught by this
16456 : check. */
16457 101939034 : if (!ctype)
16458 : {
16459 0 : error ("declaration of function %qD in invalid context",
16460 : unqualified_id);
16461 0 : return error_mark_node;
16462 : }
16463 :
16464 : /* ``A union may [ ... ] not [ have ] virtual functions.''
16465 : ARM 9.5 */
16466 101939034 : if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
16467 : {
16468 3 : error_at (declspecs->locations[ds_virtual],
16469 : "function %qD declared %<virtual%> inside a union",
16470 : unqualified_id);
16471 3 : return error_mark_node;
16472 : }
16473 :
16474 4118553 : if (virtualp
16475 112356335 : && identifier_p (unqualified_id)
16476 4118553 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16477 : {
16478 9 : error_at (declspecs->locations[ds_virtual],
16479 : "%qD cannot be declared %<virtual%>, since it "
16480 : "is always static", unqualified_id);
16481 9 : virtualp = 0;
16482 : }
16483 : }
16484 :
16485 : /* Check that the name used for a destructor makes sense. */
16486 108237782 : if (sfk == sfk_destructor)
16487 : {
16488 3062012 : tree uqname = id_declarator->u.id.unqualified_name;
16489 :
16490 3062012 : if (!ctype)
16491 : {
16492 12 : gcc_assert (friendp);
16493 12 : error_at (id_loc, "expected qualified name in friend "
16494 : "declaration for destructor %qD", uqname);
16495 12 : return error_mark_node;
16496 : }
16497 :
16498 3062000 : if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
16499 : {
16500 9 : error_at (id_loc, "declaration of %qD as member of %qT",
16501 : uqname, ctype);
16502 9 : return error_mark_node;
16503 : }
16504 3061991 : if (concept_p)
16505 : {
16506 9 : error_at (declspecs->locations[ds_concept],
16507 : "a destructor cannot be %qs", "concept");
16508 9 : return error_mark_node;
16509 : }
16510 3061982 : if (constexpr_p && cxx_dialect < cxx20)
16511 : {
16512 6 : error_at (declspecs->locations[ds_constexpr],
16513 : "%<constexpr%> destructors only available"
16514 : " with %<-std=c++20%> or %<-std=gnu++20%>");
16515 6 : return error_mark_node;
16516 : }
16517 3061976 : if (consteval_p)
16518 : {
16519 3 : error_at (declspecs->locations[ds_consteval],
16520 : "a destructor cannot be %qs", "consteval");
16521 3 : return error_mark_node;
16522 : }
16523 : }
16524 105175770 : else if (sfk == sfk_constructor && friendp && !ctype)
16525 : {
16526 0 : error ("expected qualified name in friend declaration "
16527 : "for constructor %qD",
16528 0 : id_declarator->u.id.unqualified_name);
16529 0 : return error_mark_node;
16530 : }
16531 108237743 : if (sfk == sfk_constructor)
16532 23128861 : if (concept_p)
16533 : {
16534 9 : error_at (declspecs->locations[ds_concept],
16535 : "a constructor cannot be %<concept%>");
16536 9 : return error_mark_node;
16537 : }
16538 85108882 : if (concept_p)
16539 : {
16540 9 : error_at (declspecs->locations[ds_concept],
16541 : "a concept cannot be a member function");
16542 9 : concept_p = false;
16543 : }
16544 108237725 : else if (consteval_p
16545 108974356 : && identifier_p (unqualified_id)
16546 108974347 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16547 : {
16548 9 : error_at (declspecs->locations[ds_consteval],
16549 : "%qD cannot be %qs", unqualified_id, "consteval");
16550 9 : consteval_p = false;
16551 : }
16552 :
16553 108237734 : if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16554 : {
16555 92109 : tree tmpl = TREE_OPERAND (unqualified_id, 0);
16556 92109 : if (variable_template_p (tmpl))
16557 : {
16558 3 : auto_diagnostic_group d;
16559 3 : error_at (id_loc, "specialization of variable template "
16560 : "%qD declared as function", tmpl);
16561 3 : inform (DECL_SOURCE_LOCATION (tmpl),
16562 : "variable template declared here");
16563 3 : return error_mark_node;
16564 3 : }
16565 : }
16566 :
16567 : /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
16568 108237731 : function_context
16569 : = (ctype != NULL_TREE
16570 108237731 : ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
16571 216475462 : publicp = ((! friendp || ! staticp)
16572 108237731 : && function_context == NULL_TREE);
16573 :
16574 108237731 : decl = grokfndecl (ctype, type,
16575 108237731 : TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
16576 : ? unqualified_id : dname,
16577 : parms,
16578 : unqualified_id,
16579 : declspecs,
16580 : reqs,
16581 : virtualp, flags, memfn_quals, rqual, raises,
16582 : friendp ? -1 : 0, friendp, publicp,
16583 108237731 : inlinep | (2 * constexpr_p) | (4 * concept_p)
16584 108237731 : | (8 * consteval_p),
16585 : initialized,
16586 : is_xobj_member_function, sfk,
16587 : funcdef_flag, late_return_type_p,
16588 : template_count, in_namespace,
16589 : attrlist, contract_specifiers, id_loc);
16590 108237731 : decl = set_virt_specifiers (decl, virt_specifiers);
16591 108237731 : if (decl == NULL_TREE)
16592 97 : return error_mark_node;
16593 : #if 0
16594 : /* This clobbers the attrs stored in `decl' from `attrlist'. */
16595 : /* The decl and setting of decl_attr is also turned off. */
16596 : decl = build_decl_attribute_variant (decl, decl_attr);
16597 : #endif
16598 :
16599 : /* [class.conv.ctor]
16600 :
16601 : A constructor declared without the function-specifier
16602 : explicit that can be called with a single parameter
16603 : specifies a conversion from the type of its first
16604 : parameter to the type of its class. Such a constructor
16605 : is called a converting constructor. */
16606 108237634 : if (explicitp == 2)
16607 5909881 : DECL_NONCONVERTING_P (decl) = 1;
16608 :
16609 108237634 : if (declspecs->explicit_specifier)
16610 394698 : store_explicit_specifier (decl, declspecs->explicit_specifier);
16611 : }
16612 32535986 : else if (!staticp
16613 32535986 : && ((current_class_type
16614 19665439 : && same_type_p (TYPE_MAIN_VARIANT (type),
16615 : current_class_type))
16616 19665343 : || (!dependent_type_p (type)
16617 11950564 : && !COMPLETE_TYPE_P (complete_type (type))
16618 1447 : && (!complete_or_array_type_p (type)
16619 1372 : || initialized == SD_UNINITIALIZED))))
16620 : {
16621 1510 : if (TREE_CODE (type) != ARRAY_TYPE
16622 1510 : || !COMPLETE_TYPE_P (TREE_TYPE (type)))
16623 : {
16624 171 : if (unqualified_id)
16625 : {
16626 126 : auto_diagnostic_group d;
16627 126 : error_at (id_loc, "field %qD has incomplete type %qT",
16628 : unqualified_id, type);
16629 126 : cxx_incomplete_type_inform (strip_array_types (type));
16630 126 : }
16631 : else
16632 45 : error ("name %qT has incomplete type", type);
16633 :
16634 171 : type = error_mark_node;
16635 171 : decl = NULL_TREE;
16636 : }
16637 : }
16638 52198393 : else if (!verify_type_context (input_location,
16639 : staticp
16640 : ? TCTX_STATIC_STORAGE
16641 : : TCTX_FIELD, type))
16642 : {
16643 0 : type = error_mark_node;
16644 0 : decl = NULL_TREE;
16645 : }
16646 : else
16647 : {
16648 32534470 : if (friendp)
16649 : {
16650 12 : if (unqualified_id)
16651 9 : error_at (id_loc,
16652 : "%qE is neither function nor member function; "
16653 : "cannot be declared friend", unqualified_id);
16654 : else
16655 3 : error ("unnamed field is neither function nor member "
16656 : "function; cannot be declared friend");
16657 12 : return error_mark_node;
16658 : }
16659 32534458 : decl = NULL_TREE;
16660 : }
16661 :
16662 140773626 : if (friendp)
16663 : {
16664 6298720 : if (flag_reflection && !funcdef_flag && decl)
16665 : {
16666 6681 : if (attrlist
16667 6681 : && lookup_attribute ("internal ", "annotation ",
16668 : *attrlist))
16669 : {
16670 : /* Remove the annotations to avoid spurious warning
16671 : below. */
16672 4 : *attrlist = remove_attribute ("internal ", "annotation ",
16673 : *attrlist);
16674 4 : error_at (id_loc, "annotation applied to non-defining "
16675 : "friend declaration %qD", decl);
16676 : }
16677 6681 : for (tree arg = DECL_ARGUMENTS (decl);
16678 15257 : arg; arg = DECL_CHAIN (arg))
16679 8576 : if (lookup_attribute ("internal ", "annotation ",
16680 8576 : DECL_ATTRIBUTES (arg)))
16681 4 : error_at (DECL_SOURCE_LOCATION (arg),
16682 : "annotation applied to parameter %qD of "
16683 : "non-defining friend declaration", arg);
16684 : }
16685 : /* Packages tend to use GNU attributes on friends, so we only
16686 : warn for standard attributes. */
16687 6298720 : if (attrlist
16688 6298720 : && !funcdef_flag
16689 6298720 : && cxx11_attribute_p (*attrlist))
16690 : {
16691 27 : *attrlist = NULL_TREE;
16692 27 : auto_diagnostic_group d;
16693 27 : if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
16694 27 : inform (id_loc, "an attribute that appertains to a friend "
16695 : "declaration that is not a definition is ignored");
16696 27 : }
16697 : /* Friends are treated specially. */
16698 6298720 : if (ctype == current_class_type)
16699 : ; /* We already issued a permerror. */
16700 6298720 : else if (decl && DECL_NAME (decl))
16701 : {
16702 6298717 : set_originating_module (decl, true);
16703 :
16704 6298717 : if (initialized)
16705 : /* Kludge: We need funcdef_flag to be true in do_friend for
16706 : in-class defaulted functions, but that breaks grokfndecl.
16707 : So set it here. */
16708 209042 : funcdef_flag = true;
16709 :
16710 6298717 : cplus_decl_attributes (&decl, *attrlist, 0);
16711 6298717 : *attrlist = NULL_TREE;
16712 :
16713 6298717 : tree scope = ctype ? ctype : in_namespace;
16714 6298717 : decl = do_friend (scope, unqualified_id, decl,
16715 : flags, funcdef_flag);
16716 6298717 : return decl;
16717 : }
16718 : else
16719 3 : return error_mark_node;
16720 : }
16721 :
16722 : /* Structure field. It may not be a function, except for C++. */
16723 :
16724 134474906 : if (decl == NULL_TREE)
16725 : {
16726 32535989 : if (staticp)
16727 : {
16728 : /* C++ allows static class members. All other work
16729 : for this is done by grokfield. */
16730 12870547 : decl = build_lang_decl_loc (id_loc, VAR_DECL,
16731 : dname, type);
16732 12870547 : if (unqualified_id
16733 12870544 : && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16734 : {
16735 41654 : decl = check_explicit_specialization (unqualified_id, decl,
16736 : template_count,
16737 : concept_p * 8);
16738 41654 : if (decl == error_mark_node)
16739 : return error_mark_node;
16740 : }
16741 12870547 : set_linkage_for_static_data_member (decl);
16742 12870547 : if (concept_p)
16743 15 : error_at (declspecs->locations[ds_concept],
16744 : "static data member %qE declared %qs",
16745 : unqualified_id, "concept");
16746 12870532 : else if (constexpr_p && !initialized)
16747 : {
16748 9 : error_at (DECL_SOURCE_LOCATION (decl),
16749 : "%<constexpr%> static data member %qD must "
16750 : "have an initializer", decl);
16751 9 : constexpr_p = false;
16752 : }
16753 12870547 : if (consteval_p)
16754 3 : error_at (declspecs->locations[ds_consteval],
16755 : "static data member %qE declared %qs",
16756 : unqualified_id, "consteval");
16757 :
16758 12870547 : if (inlinep)
16759 21823 : mark_inline_variable (decl, declspecs->locations[ds_inline]);
16760 :
16761 12870547 : if (!DECL_VAR_DECLARED_INLINE_P (decl)
16762 12870547 : && !(cxx_dialect >= cxx17 && constexpr_p))
16763 : /* Even if there is an in-class initialization, DECL
16764 : is considered undefined until an out-of-class
16765 : definition is provided, unless this is an inline
16766 : variable. */
16767 1821772 : DECL_EXTERNAL (decl) = 1;
16768 :
16769 12870547 : if (thread_p)
16770 : {
16771 421 : CP_DECL_THREAD_LOCAL_P (decl) = true;
16772 421 : if (!processing_template_decl)
16773 375 : set_decl_tls_model (decl, decl_default_tls_model (decl));
16774 421 : if (declspecs->gnu_thread_keyword_p)
16775 34 : SET_DECL_GNU_TLS_P (decl);
16776 : }
16777 :
16778 : /* Set the constraints on the declaration. */
16779 12870547 : bool memtmpl = (current_template_depth
16780 12870547 : > template_class_depth (current_class_type));
16781 12870547 : if (memtmpl)
16782 : {
16783 370637 : tree ci = current_template_constraints ();
16784 370637 : set_constraints (decl, ci);
16785 : }
16786 : }
16787 : else
16788 : {
16789 19665442 : if (concept_p)
16790 : {
16791 12 : error_at (declspecs->locations[ds_concept],
16792 : "non-static data member %qE declared %qs",
16793 : unqualified_id, "concept");
16794 12 : concept_p = false;
16795 12 : constexpr_p = false;
16796 : }
16797 19665430 : else if (constexpr_p)
16798 : {
16799 9 : error_at (declspecs->locations[ds_constexpr],
16800 : "non-static data member %qE declared %qs",
16801 : unqualified_id, "constexpr");
16802 9 : constexpr_p = false;
16803 : }
16804 19665442 : if (constinit_p)
16805 : {
16806 6 : error_at (declspecs->locations[ds_constinit],
16807 : "non-static data member %qE declared %qs",
16808 : unqualified_id, "constinit");
16809 6 : constinit_p = false;
16810 : }
16811 19665442 : if (consteval_p)
16812 : {
16813 3 : error_at (declspecs->locations[ds_consteval],
16814 : "non-static data member %qE declared %qs",
16815 : unqualified_id, "consteval");
16816 3 : consteval_p = false;
16817 : }
16818 19665442 : decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
16819 19665442 : DECL_NONADDRESSABLE_P (decl) = bitfield;
16820 19665442 : if (bitfield && !unqualified_id)
16821 133748 : DECL_PADDING_P (decl) = 1;
16822 :
16823 19665442 : if (storage_class == sc_mutable)
16824 : {
16825 148382 : DECL_MUTABLE_P (decl) = 1;
16826 148382 : storage_class = sc_none;
16827 : }
16828 :
16829 19665442 : if (initialized)
16830 : {
16831 : /* An attempt is being made to initialize a non-static
16832 : member. This is new in C++11. */
16833 2240151 : maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
16834 :
16835 : /* If this has been parsed with static storage class, but
16836 : errors forced staticp to be cleared, ensure NSDMI is
16837 : not present. */
16838 2240151 : if (declspecs->storage_class == sc_static)
16839 3 : DECL_INITIAL (decl) = error_mark_node;
16840 : }
16841 : }
16842 :
16843 52201431 : bad_specifiers (decl, BSP_FIELD, virtualp,
16844 : memfn_quals != TYPE_UNQUALIFIED,
16845 : staticp ? false : inlinep, friendp,
16846 : raises != NULL_TREE,
16847 : declspecs->locations);
16848 : }
16849 : }
16850 145288112 : else if (FUNC_OR_METHOD_TYPE_P (type))
16851 : {
16852 77812511 : tree original_name;
16853 77812511 : int publicp = 0;
16854 :
16855 77812511 : if (!unqualified_id)
16856 0 : return error_mark_node;
16857 :
16858 77812511 : if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16859 : original_name = dname;
16860 : else
16861 76957243 : original_name = unqualified_id;
16862 : // FIXME:gcc_assert (original_name == dname);
16863 :
16864 77812511 : if (storage_class == sc_auto)
16865 1 : error_at (declspecs->locations[ds_storage_class],
16866 : "storage class %<auto%> invalid for function %qs", name);
16867 77812510 : else if (storage_class == sc_register)
16868 7 : error_at (declspecs->locations[ds_storage_class],
16869 : "storage class %<register%> invalid for function %qs",
16870 : name);
16871 77812503 : else if (thread_p)
16872 : {
16873 12 : if (declspecs->gnu_thread_keyword_p)
16874 12 : error_at (declspecs->locations[ds_thread],
16875 : "storage class %<__thread%> invalid for function %qs",
16876 : name);
16877 : else
16878 0 : error_at (declspecs->locations[ds_thread],
16879 : "storage class %<thread_local%> invalid for "
16880 : "function %qs", name);
16881 : }
16882 77812491 : else if (constinit_p)
16883 3 : error_at (declspecs->locations[ds_constinit],
16884 : "%<constinit%> specifier invalid for function %qs", name);
16885 :
16886 77812511 : if (virt_specifiers)
16887 6 : error ("virt-specifiers in %qs not allowed outside a class "
16888 : "definition", name);
16889 : /* Function declaration not at top level.
16890 : Storage classes other than `extern' are not allowed
16891 : and `extern' makes no difference. */
16892 77812511 : if (! toplevel_bindings_p ()
16893 59329 : && (storage_class == sc_static
16894 59320 : || decl_spec_seq_has_spec_p (declspecs, ds_inline))
16895 77812523 : && pedantic)
16896 : {
16897 9 : if (storage_class == sc_static)
16898 6 : pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
16899 : "%<static%> specifier invalid for function %qs "
16900 : "declared out of global scope", name);
16901 : else
16902 3 : pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
16903 : "%<inline%> specifier invalid for function %qs "
16904 : "declared out of global scope", name);
16905 : }
16906 :
16907 77812511 : if (ctype == NULL_TREE)
16908 : {
16909 68947763 : if (virtualp)
16910 : {
16911 0 : error ("virtual non-class function %qs", name);
16912 0 : virtualp = 0;
16913 : }
16914 68947763 : else if (sfk == sfk_constructor
16915 68947763 : || sfk == sfk_destructor)
16916 : {
16917 3 : error (funcdef_flag
16918 : ? G_("%qs defined in a non-class scope")
16919 : : G_("%qs declared in a non-class scope"), name);
16920 3 : sfk = sfk_none;
16921 : }
16922 : }
16923 77812511 : if (consteval_p
16924 78034174 : && identifier_p (unqualified_id)
16925 78034174 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16926 : {
16927 9 : error_at (declspecs->locations[ds_consteval],
16928 : "%qD cannot be %qs", unqualified_id, "consteval");
16929 9 : consteval_p = false;
16930 : }
16931 :
16932 : /* Record whether the function is public. */
16933 77812511 : publicp = (ctype != NULL_TREE
16934 77812511 : || storage_class != sc_static);
16935 :
16936 155625022 : decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
16937 : declspecs, reqs, virtualp, flags, memfn_quals, rqual, raises,
16938 : 1, friendp,
16939 : publicp,
16940 77812511 : inlinep | (2 * constexpr_p) | (4 * concept_p)
16941 77812511 : | (8 * consteval_p),
16942 : initialized,
16943 : is_xobj_member_function, sfk,
16944 : funcdef_flag,
16945 : late_return_type_p,
16946 : template_count, in_namespace, attrlist,
16947 : contract_specifiers, id_loc);
16948 77812511 : if (decl == NULL_TREE)
16949 592 : return error_mark_node;
16950 :
16951 77811919 : if (explicitp == 2)
16952 10441 : DECL_NONCONVERTING_P (decl) = 1;
16953 77811919 : if (staticp == 1)
16954 : {
16955 111366 : int invalid_static = 0;
16956 :
16957 : /* Don't allow a static member function in a class, and forbid
16958 : declaring main to be static. */
16959 111366 : if (TREE_CODE (type) == METHOD_TYPE)
16960 : {
16961 0 : permerror (input_location, "cannot declare member function %qD to have "
16962 : "static linkage", decl);
16963 0 : invalid_static = 1;
16964 : }
16965 111366 : else if (current_function_decl)
16966 : {
16967 : /* 7.1.1: There can be no static function declarations within a
16968 : block. */
16969 9 : error_at (declspecs->locations[ds_storage_class],
16970 : "cannot declare static function inside another function");
16971 9 : invalid_static = 1;
16972 : }
16973 :
16974 9 : if (invalid_static)
16975 : {
16976 77811919 : staticp = 0;
16977 : storage_class = sc_none;
16978 : }
16979 : }
16980 77811919 : if (declspecs->explicit_specifier)
16981 3 : store_explicit_specifier (decl, declspecs->explicit_specifier);
16982 : }
16983 : else
16984 : {
16985 : /* It's a variable. */
16986 :
16987 : /* An uninitialized decl with `extern' is a reference. */
16988 134458887 : decl = grokvardecl (type, dname, unqualified_id,
16989 : declspecs,
16990 : initialized,
16991 : type_quals,
16992 : inlinep,
16993 : concept_p,
16994 : template_count,
16995 : ctype ? ctype : in_namespace,
16996 : id_loc);
16997 67475601 : if (decl == NULL_TREE)
16998 52 : return error_mark_node;
16999 :
17000 67475549 : bad_specifiers (decl, BSP_VAR, virtualp,
17001 : memfn_quals != TYPE_UNQUALIFIED,
17002 : inlinep, friendp, raises != NULL_TREE,
17003 : declspecs->locations);
17004 :
17005 67475549 : if (ctype)
17006 : {
17007 492309 : DECL_CONTEXT (decl) = ctype;
17008 492309 : if (staticp == 1)
17009 : {
17010 6 : permerror (declspecs->locations[ds_storage_class],
17011 : "%<static%> may not be used when defining "
17012 : "(as opposed to declaring) a static data member");
17013 6 : staticp = 0;
17014 6 : storage_class = sc_none;
17015 : }
17016 492309 : if (storage_class == sc_register && TREE_STATIC (decl))
17017 : {
17018 0 : error ("static member %qD declared %<register%>", decl);
17019 0 : storage_class = sc_none;
17020 : }
17021 492309 : if (storage_class == sc_extern && pedantic)
17022 : {
17023 0 : pedwarn (input_location, OPT_Wpedantic,
17024 : "cannot explicitly declare member %q#D to have "
17025 : "extern linkage", decl);
17026 0 : storage_class = sc_none;
17027 : }
17028 : }
17029 66983240 : else if (constexpr_p && DECL_EXTERNAL (decl))
17030 : {
17031 12 : error_at (DECL_SOURCE_LOCATION (decl),
17032 : "declaration of %<constexpr%> variable %qD "
17033 : "is not a definition", decl);
17034 12 : constexpr_p = false;
17035 : }
17036 67475549 : if (consteval_p)
17037 : {
17038 13 : error_at (DECL_SOURCE_LOCATION (decl),
17039 : "a variable cannot be declared %<consteval%>");
17040 13 : consteval_p = false;
17041 : }
17042 :
17043 67475549 : if (inlinep)
17044 6493741 : mark_inline_variable (decl, declspecs->locations[ds_inline]);
17045 67475549 : if (innermost_code == cdk_decomp)
17046 : {
17047 220842 : gcc_assert (declarator && declarator->kind == cdk_decomp);
17048 220842 : DECL_SOURCE_LOCATION (decl) = id_loc;
17049 220842 : DECL_ARTIFICIAL (decl) = 1;
17050 220842 : fit_decomposition_lang_decl (decl, NULL_TREE);
17051 : }
17052 : }
17053 :
17054 570825861 : if (VAR_P (decl) && !initialized)
17055 7408124 : if (tree auto_node = type_uses_auto (type))
17056 99 : if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
17057 : {
17058 18 : location_t loc = declspecs->locations[ds_type_spec];
17059 18 : error_at (loc, "declaration of %q#D has no initializer", decl);
17060 18 : TREE_TYPE (decl) = error_mark_node;
17061 : }
17062 :
17063 570825861 : if (storage_class == sc_extern && initialized && !funcdef_flag)
17064 : {
17065 267 : if (toplevel_bindings_p ())
17066 : {
17067 : /* It's common practice (and completely valid) to have a const
17068 : be initialized and declared extern. */
17069 243 : if (!(type_quals & TYPE_QUAL_CONST))
17070 19 : warning_at (DECL_SOURCE_LOCATION (decl), 0,
17071 : "%qs initialized and declared %<extern%>", name);
17072 : }
17073 : else
17074 : {
17075 24 : error_at (DECL_SOURCE_LOCATION (decl),
17076 : "%qs has both %<extern%> and initializer", name);
17077 24 : return error_mark_node;
17078 : }
17079 : }
17080 :
17081 : /* Record `register' declaration for warnings on &
17082 : and in case doing stupid register allocation. */
17083 :
17084 570825837 : if (storage_class == sc_register)
17085 : {
17086 2069 : DECL_REGISTER (decl) = 1;
17087 : /* Warn about register storage specifiers on PARM_DECLs. */
17088 2069 : if (TREE_CODE (decl) == PARM_DECL)
17089 : {
17090 35 : if (cxx_dialect >= cxx17)
17091 24 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
17092 : "ISO C++17 does not allow %<register%> storage "
17093 : "class specifier");
17094 : else
17095 11 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
17096 : "%<register%> storage class specifier used");
17097 : }
17098 : }
17099 570823768 : else if (storage_class == sc_extern)
17100 30696537 : DECL_THIS_EXTERN (decl) = 1;
17101 540127231 : else if (storage_class == sc_static)
17102 23378020 : DECL_THIS_STATIC (decl) = 1;
17103 :
17104 570825837 : if (VAR_P (decl))
17105 : {
17106 : /* Set constexpr flag on vars (functions got it in grokfndecl). */
17107 80346072 : if (constexpr_p)
17108 19307466 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
17109 : /* And the constinit flag (which only applies to variables). */
17110 61038606 : else if (constinit_p)
17111 438 : DECL_DECLARED_CONSTINIT_P (decl) = true;
17112 : }
17113 490479765 : else if (TREE_CODE (decl) == FUNCTION_DECL)
17114 : {
17115 : /* If we saw a return type, record its location. */
17116 179750836 : location_t loc = declspecs->locations[ds_type_spec];
17117 179750836 : if (loc == UNKNOWN_LOCATION)
17118 : /* Build DECL_RESULT in start_preparsed_function. */;
17119 147143605 : else if (!DECL_RESULT (decl))
17120 : {
17121 147106504 : tree restype = TREE_TYPE (TREE_TYPE (decl));
17122 147106504 : tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
17123 147106504 : DECL_ARTIFICIAL (resdecl) = 1;
17124 147106504 : DECL_IGNORED_P (resdecl) = 1;
17125 147106504 : DECL_RESULT (decl) = resdecl;
17126 : }
17127 37101 : else if (funcdef_flag)
17128 3 : DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
17129 : }
17130 :
17131 : /* Record constancy and volatility on the DECL itself . There's
17132 : no need to do this when processing a template; we'll do this
17133 : for the instantiated declaration based on the type of DECL. */
17134 570825837 : if (!processing_template_decl
17135 : /* Don't do it for instantiated variable templates either,
17136 : cp_apply_type_quals_to_decl should have been called on it
17137 : already and might have been overridden in cp_finish_decl
17138 : if initializer needs runtime initialization. */
17139 570825837 : && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
17140 191336080 : cp_apply_type_quals_to_decl (type_quals, decl);
17141 :
17142 570825837 : return decl;
17143 : }
17144 1027430902 : }
17145 :
17146 : /* Subroutine of start_function. Ensure that each of the parameter
17147 : types (as listed in PARMS) is complete, as is required for a
17148 : function definition. */
17149 :
17150 : static void
17151 159098223 : require_complete_types_for_parms (tree parms)
17152 : {
17153 471521612 : for (; parms; parms = DECL_CHAIN (parms))
17154 : {
17155 312423389 : if (dependent_type_p (TREE_TYPE (parms)))
17156 175118326 : continue;
17157 137305063 : if (!VOID_TYPE_P (TREE_TYPE (parms))
17158 137305063 : && complete_type_or_else (TREE_TYPE (parms), parms))
17159 : {
17160 137304982 : relayout_decl (parms);
17161 137304982 : DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
17162 :
17163 137304982 : abstract_virtuals_error (parms, TREE_TYPE (parms));
17164 137304982 : maybe_warn_parm_abi (TREE_TYPE (parms),
17165 137304982 : DECL_SOURCE_LOCATION (parms));
17166 : }
17167 : else
17168 : /* grokparms or complete_type_or_else will have already issued
17169 : an error. */
17170 81 : TREE_TYPE (parms) = error_mark_node;
17171 : }
17172 159098223 : }
17173 :
17174 : /* Returns nonzero if T is a local variable. */
17175 :
17176 : int
17177 168911200 : local_variable_p (const_tree t)
17178 : {
17179 168911200 : if ((VAR_P (t)
17180 64217366 : && (DECL_LOCAL_DECL_P (t)
17181 64217366 : || !DECL_CONTEXT (t)
17182 64176248 : || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
17183 174308547 : || (TREE_CODE (t) == PARM_DECL))
17184 150434039 : return 1;
17185 :
17186 : return 0;
17187 : }
17188 :
17189 : /* Like local_variable_p, but suitable for use as a tree-walking
17190 : function. */
17191 :
17192 : static tree
17193 5410910 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
17194 : void * /*data*/)
17195 : {
17196 5410910 : if (unevaluated_p (TREE_CODE (*tp)))
17197 : {
17198 : /* DR 2082 permits local variables in unevaluated contexts
17199 : within a default argument. */
17200 22 : *walk_subtrees = 0;
17201 22 : return NULL_TREE;
17202 : }
17203 :
17204 5410888 : if (local_variable_p (*tp)
17205 5410888 : && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
17206 : return *tp;
17207 5410888 : else if (TYPE_P (*tp))
17208 30 : *walk_subtrees = 0;
17209 :
17210 : return NULL_TREE;
17211 : }
17212 :
17213 : /* Check that ARG, which is a default-argument expression for a
17214 : parameter DECL, is valid. Returns ARG, or ERROR_MARK_NODE, if
17215 : something goes wrong. DECL may also be a _TYPE node, rather than a
17216 : DECL, if there is no DECL available. */
17217 :
17218 : tree
17219 2698058 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
17220 : {
17221 2698058 : tree var;
17222 2698058 : tree decl_type;
17223 :
17224 2698058 : if (TREE_CODE (arg) == DEFERRED_PARSE)
17225 : /* We get a DEFERRED_PARSE when looking at an in-class declaration
17226 : with a default argument. Ignore the argument for now; we'll
17227 : deal with it after the class is complete. */
17228 : return arg;
17229 :
17230 1903544 : if (TYPE_P (decl))
17231 : {
17232 : decl_type = decl;
17233 : decl = NULL_TREE;
17234 : }
17235 : else
17236 567153 : decl_type = TREE_TYPE (decl);
17237 :
17238 1903544 : if (arg == error_mark_node
17239 1903424 : || decl == error_mark_node
17240 1903415 : || TREE_TYPE (arg) == error_mark_node
17241 3806959 : || decl_type == error_mark_node)
17242 : /* Something already went wrong. There's no need to check
17243 : further. */
17244 : return error_mark_node;
17245 :
17246 : /* [dcl.fct.default]
17247 :
17248 : A default argument expression is implicitly converted to the
17249 : parameter type. */
17250 1903415 : ++cp_unevaluated_operand;
17251 : /* Avoid digest_init clobbering the initializer. */
17252 1903415 : tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
17253 1903415 : perform_implicit_conversion_flags (decl_type, carg, complain,
17254 : LOOKUP_IMPLICIT);
17255 1903415 : --cp_unevaluated_operand;
17256 :
17257 : /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
17258 : the call sites. */
17259 1513286 : if (TYPE_PTR_OR_PTRMEM_P (decl_type)
17260 390144 : && null_ptr_cst_p (arg)
17261 : /* Don't lose side-effects as in PR90473. */
17262 2272169 : && !TREE_SIDE_EFFECTS (arg))
17263 368751 : return nullptr_node;
17264 :
17265 : /* [dcl.fct.default]
17266 :
17267 : Local variables shall not be used in default argument
17268 : expressions.
17269 :
17270 : The keyword `this' shall not be used in a default argument of a
17271 : member function. */
17272 1534664 : var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
17273 1534664 : if (var)
17274 : {
17275 0 : if (complain & tf_warning_or_error)
17276 : {
17277 0 : if (DECL_NAME (var) == this_identifier)
17278 0 : permerror (input_location, "default argument %qE uses %qD",
17279 : arg, var);
17280 : else
17281 0 : error ("default argument %qE uses local variable %qD", arg, var);
17282 : }
17283 0 : return error_mark_node;
17284 : }
17285 :
17286 : /* All is well. */
17287 1534664 : return arg;
17288 : }
17289 :
17290 : /* Returns a deprecated type used within TYPE, or NULL_TREE if none. */
17291 :
17292 : static tree
17293 278414340 : type_is_deprecated (tree type)
17294 : {
17295 410673619 : enum tree_code code;
17296 410673619 : if (TREE_DEPRECATED (type))
17297 : return type;
17298 410633542 : if (TYPE_NAME (type))
17299 : {
17300 274258500 : if (TREE_DEPRECATED (TYPE_NAME (type)))
17301 : return type;
17302 : else
17303 : {
17304 274258494 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
17305 274258494 : return NULL_TREE;
17306 : }
17307 : }
17308 :
17309 : /* Do warn about using typedefs to a deprecated class. */
17310 136375042 : if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
17311 0 : return type_is_deprecated (TYPE_MAIN_VARIANT (type));
17312 :
17313 136375042 : code = TREE_CODE (type);
17314 :
17315 136375042 : if (code == POINTER_TYPE || code == REFERENCE_TYPE
17316 136375042 : || code == OFFSET_TYPE || code == FUNCTION_TYPE
17317 : || code == METHOD_TYPE || code == ARRAY_TYPE)
17318 132143550 : return type_is_deprecated (TREE_TYPE (type));
17319 :
17320 115729 : if (TYPE_PTRMEMFUNC_P (type))
17321 115729 : return type_is_deprecated
17322 115729 : (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
17323 :
17324 : return NULL_TREE;
17325 : }
17326 :
17327 : /* Returns an unavailable type used within TYPE, or NULL_TREE if none. */
17328 :
17329 : static tree
17330 279613576 : type_is_unavailable (tree type)
17331 : {
17332 412589424 : enum tree_code code;
17333 412589424 : if (TREE_UNAVAILABLE (type))
17334 : return type;
17335 412589418 : if (TYPE_NAME (type))
17336 : {
17337 275497753 : if (TREE_UNAVAILABLE (TYPE_NAME (type)))
17338 : return type;
17339 : else
17340 : {
17341 275497747 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
17342 275497747 : return NULL_TREE;
17343 : }
17344 : }
17345 :
17346 : /* Do warn about using typedefs to a deprecated class. */
17347 137091665 : if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
17348 0 : return type_is_deprecated (TYPE_MAIN_VARIANT (type));
17349 :
17350 137091665 : code = TREE_CODE (type);
17351 :
17352 137091665 : if (code == POINTER_TYPE || code == REFERENCE_TYPE
17353 137091665 : || code == OFFSET_TYPE || code == FUNCTION_TYPE
17354 : || code == METHOD_TYPE || code == ARRAY_TYPE)
17355 132751575 : return type_is_unavailable (TREE_TYPE (type));
17356 :
17357 224273 : if (TYPE_PTRMEMFUNC_P (type))
17358 224273 : return type_is_unavailable
17359 224273 : (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
17360 :
17361 : return NULL_TREE;
17362 : }
17363 :
17364 : /* Decode the list of parameter types for a function type.
17365 : Given the list of things declared inside the parens,
17366 : return a list of types.
17367 :
17368 : If this parameter does not end with an ellipsis, we append
17369 : void_list_node.
17370 :
17371 : *PARMS is set to the chain of PARM_DECLs created. */
17372 :
17373 : tree
17374 191228928 : grokparms (tree parmlist, tree *parms)
17375 : {
17376 191228928 : tree result = NULL_TREE;
17377 191228928 : tree decls = NULL_TREE;
17378 191228928 : tree parm;
17379 191228928 : int any_error = 0;
17380 :
17381 471459769 : for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
17382 : {
17383 469071939 : tree type = NULL_TREE;
17384 469071939 : tree init = TREE_PURPOSE (parm);
17385 469071939 : tree decl = TREE_VALUE (parm);
17386 :
17387 469071939 : if (parm == void_list_node || parm == explicit_void_list_node)
17388 : break;
17389 :
17390 280230855 : if (! decl || TREE_TYPE (decl) == error_mark_node)
17391 : {
17392 186 : any_error = 1;
17393 186 : continue;
17394 : }
17395 :
17396 280230669 : type = TREE_TYPE (decl);
17397 280230669 : if (VOID_TYPE_P (type))
17398 : {
17399 80 : if (same_type_p (type, void_type_node)
17400 71 : && !init
17401 59 : && !DECL_NAME (decl) && !result
17402 106 : && TREE_CHAIN (parm) == void_list_node)
17403 : /* DR 577: A parameter list consisting of a single
17404 : unnamed parameter of non-dependent type 'void'. */
17405 : break;
17406 66 : else if (cv_qualified_p (type))
17407 9 : error_at (DECL_SOURCE_LOCATION (decl),
17408 : "invalid use of cv-qualified type %qT in "
17409 : "parameter declaration", type);
17410 : else
17411 57 : error_at (DECL_SOURCE_LOCATION (decl),
17412 : "invalid use of type %<void%> in parameter "
17413 : "declaration");
17414 : /* It's not a good idea to actually create parameters of
17415 : type `void'; other parts of the compiler assume that a
17416 : void type terminates the parameter list. */
17417 66 : type = error_mark_node;
17418 66 : TREE_TYPE (decl) = error_mark_node;
17419 : }
17420 :
17421 280230655 : if (type != error_mark_node)
17422 : {
17423 280230589 : if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
17424 : {
17425 279613576 : tree unavailtype = type_is_unavailable (type);
17426 279613576 : if (unavailtype)
17427 12 : cp_handle_deprecated_or_unavailable (unavailtype);
17428 : }
17429 280230589 : if (deprecated_state != DEPRECATED_SUPPRESS
17430 280230589 : && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
17431 : {
17432 278414340 : tree deptype = type_is_deprecated (type);
17433 278414340 : if (deptype)
17434 40083 : cp_handle_deprecated_or_unavailable (deptype);
17435 : }
17436 :
17437 : /* [dcl.fct] "A parameter with volatile-qualified type is
17438 : deprecated." */
17439 280230589 : if (CP_TYPE_VOLATILE_P (type))
17440 504 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
17441 : "%<volatile%>-qualified parameter is "
17442 : "deprecated");
17443 :
17444 : /* Top-level qualifiers on the parameters are
17445 : ignored for function types. */
17446 280230589 : type = cp_build_qualified_type (type, 0);
17447 280230589 : if (TREE_CODE (type) == METHOD_TYPE)
17448 : {
17449 0 : error ("parameter %qD invalidly declared method type", decl);
17450 0 : type = build_pointer_type (type);
17451 0 : TREE_TYPE (decl) = type;
17452 : }
17453 280230589 : else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
17454 : {
17455 : /* Before C++17 DR 393:
17456 : [dcl.fct]/6, parameter types cannot contain pointers
17457 : (references) to arrays of unknown bound. */
17458 1731504 : tree t = TREE_TYPE (type);
17459 1731504 : int ptr = TYPE_PTR_P (type);
17460 :
17461 1898294 : while (1)
17462 : {
17463 1814899 : if (TYPE_PTR_P (t))
17464 : ptr = 1;
17465 1734715 : else if (TREE_CODE (t) != ARRAY_TYPE)
17466 : break;
17467 3221 : else if (!TYPE_DOMAIN (t))
17468 : break;
17469 83395 : t = TREE_TYPE (t);
17470 : }
17471 1731504 : if (TREE_CODE (t) == ARRAY_TYPE)
17472 16 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
17473 : ptr
17474 : ? G_("parameter %qD includes pointer to array of "
17475 : "unknown bound %qT")
17476 : : G_("parameter %qD includes reference to array of "
17477 : "unknown bound %qT"),
17478 : decl, t);
17479 : }
17480 :
17481 280230589 : if (init && !processing_template_decl)
17482 1361658 : init = check_default_argument (decl, init, tf_warning_or_error);
17483 : }
17484 :
17485 280230655 : DECL_CHAIN (decl) = decls;
17486 280230655 : decls = decl;
17487 280230655 : result = tree_cons (init, type, result);
17488 : }
17489 191228928 : decls = nreverse (decls);
17490 191228928 : result = nreverse (result);
17491 191228928 : if (parm)
17492 188841098 : result = chainon (result, void_list_node);
17493 191228928 : *parms = decls;
17494 191228928 : if (any_error)
17495 172 : result = NULL_TREE;
17496 :
17497 172 : if (any_error)
17498 : /* We had parm errors, recover by giving the function (...) type. */
17499 172 : result = NULL_TREE;
17500 :
17501 191228928 : return result;
17502 : }
17503 :
17504 :
17505 : /* D is a constructor or overloaded `operator='.
17506 :
17507 : Let T be the class in which D is declared. Then, this function
17508 : returns:
17509 :
17510 : -1 if D's is an ill-formed constructor or copy assignment operator
17511 : whose first parameter is of type `T'.
17512 : 0 if D is not a copy constructor or copy assignment
17513 : operator.
17514 : 1 if D is a copy constructor or copy assignment operator whose
17515 : first parameter is a reference to non-const qualified T.
17516 : 2 if D is a copy constructor or copy assignment operator whose
17517 : first parameter is a reference to const qualified T.
17518 :
17519 : This function can be used as a predicate. Positive values indicate
17520 : a copy constructor and nonzero values indicate a copy assignment
17521 : operator. */
17522 :
17523 : int
17524 334547090 : copy_fn_p (const_tree d)
17525 : {
17526 334547090 : tree args;
17527 334547090 : tree arg_type;
17528 334547090 : int result = 1;
17529 :
17530 334547090 : gcc_assert (DECL_FUNCTION_MEMBER_P (d));
17531 :
17532 334547090 : if (TREE_CODE (d) == TEMPLATE_DECL
17533 334547090 : || (DECL_TEMPLATE_INFO (d)
17534 148849010 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
17535 : /* Instantiations of template member functions are never copy
17536 : functions. Note that member functions of templated classes are
17537 : represented as template functions internally, and we must
17538 : accept those as copy functions. */
17539 : return 0;
17540 :
17541 282929193 : if (!DECL_CONSTRUCTOR_P (d)
17542 282929193 : && DECL_NAME (d) != assign_op_identifier)
17543 : return 0;
17544 :
17545 282131640 : if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
17546 : {
17547 126 : tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
17548 126 : if (!TYPE_REF_P (object_param)
17549 120 : || TYPE_REF_IS_RVALUE (object_param)
17550 : /* Reject unrelated object parameters. */
17551 108 : || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
17552 234 : || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
17553 24 : return 0;
17554 102 : args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
17555 : }
17556 : else
17557 282131514 : args = FUNCTION_FIRST_USER_PARMTYPE (d);
17558 282131616 : if (!args)
17559 : return 0;
17560 :
17561 282124092 : arg_type = TREE_VALUE (args);
17562 282124092 : if (arg_type == error_mark_node)
17563 : return 0;
17564 :
17565 282124057 : if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
17566 : {
17567 : /* Pass by value copy assignment operator. */
17568 : result = -1;
17569 : }
17570 282122814 : else if (TYPE_REF_P (arg_type)
17571 178381966 : && !TYPE_REF_IS_RVALUE (arg_type)
17572 395190946 : && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
17573 : {
17574 90545386 : if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
17575 90380206 : result = 2;
17576 : }
17577 : else
17578 : return 0;
17579 :
17580 90546629 : args = TREE_CHAIN (args);
17581 :
17582 93338985 : if (args && args != void_list_node && !TREE_PURPOSE (args))
17583 : /* There are more non-optional args. */
17584 : return 0;
17585 :
17586 : return result;
17587 : }
17588 :
17589 : /* D is a constructor or overloaded `operator='.
17590 :
17591 : Let T be the class in which D is declared. Then, this function
17592 : returns true when D is a move constructor or move assignment
17593 : operator, false otherwise. */
17594 :
17595 : bool
17596 154239584 : move_fn_p (const_tree d)
17597 : {
17598 154239584 : if (cxx_dialect == cxx98)
17599 : /* There are no move constructors if we are in C++98 mode. */
17600 : return false;
17601 :
17602 154164127 : if (TREE_CODE (d) == TEMPLATE_DECL
17603 154164127 : || (DECL_TEMPLATE_INFO (d)
17604 62856950 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
17605 : /* Instantiations of template member functions are never move
17606 : functions. Note that member functions of templated classes are
17607 : represented as template functions internally, and we must
17608 : accept those as move functions. */
17609 : return 0;
17610 :
17611 125681150 : return move_signature_fn_p (d);
17612 : }
17613 :
17614 : /* D is a constructor or overloaded `operator='.
17615 :
17616 : Then, this function returns true when D has the same signature as a move
17617 : constructor or move assignment operator (because either it is such a
17618 : ctor/op= or it is a template specialization with the same signature),
17619 : false otherwise. */
17620 :
17621 : bool
17622 125681150 : move_signature_fn_p (const_tree d)
17623 : {
17624 125681150 : tree args;
17625 125681150 : tree arg_type;
17626 125681150 : bool result = false;
17627 :
17628 125681150 : if (!DECL_CONSTRUCTOR_P (d)
17629 125681150 : && DECL_NAME (d) != assign_op_identifier)
17630 : return 0;
17631 :
17632 125681081 : if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
17633 : {
17634 68 : tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
17635 68 : if (!TYPE_REF_P (object_param)
17636 64 : || TYPE_REF_IS_RVALUE (object_param)
17637 : /* Reject unrelated object parameters. */
17638 56 : || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
17639 124 : || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
17640 16 : return 0;
17641 52 : args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
17642 : }
17643 : else
17644 125681013 : args = FUNCTION_FIRST_USER_PARMTYPE (d);
17645 125681065 : if (!args)
17646 : return 0;
17647 :
17648 125678275 : arg_type = TREE_VALUE (args);
17649 125678275 : if (arg_type == error_mark_node)
17650 : return 0;
17651 :
17652 125678267 : if (TYPE_REF_P (arg_type)
17653 63916364 : && TYPE_REF_IS_RVALUE (arg_type)
17654 175462959 : && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
17655 : DECL_CONTEXT (d)))
17656 : result = true;
17657 :
17658 125678267 : args = TREE_CHAIN (args);
17659 :
17660 140388186 : if (args && args != void_list_node && !TREE_PURPOSE (args))
17661 : /* There are more non-optional args. */
17662 : return false;
17663 :
17664 : return result;
17665 : }
17666 :
17667 : /* Remember any special properties of member function DECL. */
17668 :
17669 : void
17670 344469493 : grok_special_member_properties (tree decl)
17671 : {
17672 344469493 : tree class_type;
17673 :
17674 344469493 : if (TREE_CODE (decl) == USING_DECL
17675 344469493 : || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
17676 : return;
17677 :
17678 323518633 : class_type = DECL_CONTEXT (decl);
17679 323518633 : if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
17680 : {
17681 145918313 : int ctor = copy_fn_p (decl);
17682 :
17683 145918313 : if (!DECL_ARTIFICIAL (decl))
17684 101956472 : TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
17685 :
17686 145918313 : if (ctor > 0)
17687 : {
17688 : /* [class.copy]
17689 :
17690 : A non-template constructor for class X is a copy
17691 : constructor if its first parameter is of type X&, const
17692 : X&, volatile X& or const volatile X&, and either there
17693 : are no other parameters or else all other parameters have
17694 : default arguments. */
17695 29621579 : TYPE_HAS_COPY_CTOR (class_type) = 1;
17696 29621579 : if (ctor > 1)
17697 29544800 : TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
17698 : }
17699 :
17700 145918313 : if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
17701 30982807 : TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
17702 :
17703 145918313 : if (is_list_ctor (decl))
17704 1497119 : TYPE_HAS_LIST_CTOR (class_type) = 1;
17705 :
17706 145918313 : if (maybe_constexpr_fn (decl)
17707 145918313 : && !ctor && !move_fn_p (decl))
17708 52495261 : TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
17709 : }
17710 177600320 : else if (DECL_NAME (decl) == assign_op_identifier)
17711 : {
17712 : /* [class.copy]
17713 :
17714 : A non-template assignment operator for class X is a copy
17715 : assignment operator if its parameter is of type X, X&, const
17716 : X&, volatile X& or const volatile X&. */
17717 :
17718 14846443 : int assop = copy_fn_p (decl);
17719 :
17720 14846443 : if (assop)
17721 : {
17722 7563834 : TYPE_HAS_COPY_ASSIGN (class_type) = 1;
17723 7563834 : if (assop != 1)
17724 7535994 : TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
17725 : }
17726 : }
17727 162753877 : else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
17728 2672127 : TYPE_HAS_CONVERSION (class_type) = true;
17729 :
17730 : /* Destructors are handled in check_methods. */
17731 : }
17732 :
17733 : /* Check a constructor DECL has the correct form. Complains
17734 : if the class has a constructor of the form X(X). */
17735 :
17736 : bool
17737 47182403 : grok_ctor_properties (const_tree ctype, const_tree decl)
17738 : {
17739 47182403 : int ctor_parm = copy_fn_p (decl);
17740 :
17741 47182403 : if (ctor_parm < 0)
17742 : {
17743 : /* [class.copy]
17744 :
17745 : A declaration of a constructor for a class X is ill-formed if
17746 : its first parameter is of type (optionally cv-qualified) X
17747 : and either there are no other parameters or else all other
17748 : parameters have default arguments.
17749 :
17750 : We *don't* complain about member template instantiations that
17751 : have this form, though; they can occur as we try to decide
17752 : what constructor to use during overload resolution. Since
17753 : overload resolution will never prefer such a constructor to
17754 : the non-template copy constructor (which is either explicitly
17755 : or implicitly defined), there's no need to worry about their
17756 : existence. Theoretically, they should never even be
17757 : instantiated, but that's hard to forestall. */
17758 9 : error_at (DECL_SOURCE_LOCATION (decl),
17759 : "invalid constructor; you probably meant %<%T (const %T&)%>",
17760 : ctype, ctype);
17761 9 : return false;
17762 : }
17763 :
17764 : return true;
17765 : }
17766 :
17767 : /* DECL is a declaration for an overloaded or conversion operator. If
17768 : COMPLAIN is true, errors are issued for invalid declarations. */
17769 :
17770 : bool
17771 58607728 : grok_op_properties (tree decl, bool complain)
17772 : {
17773 58607728 : tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
17774 58607728 : bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
17775 58607728 : tree name = DECL_NAME (decl);
17776 58607728 : location_t loc = DECL_SOURCE_LOCATION (decl);
17777 :
17778 58607728 : tree class_type = DECL_CONTEXT (decl);
17779 58607728 : if (class_type && !CLASS_TYPE_P (class_type))
17780 : class_type = NULL_TREE;
17781 :
17782 58607728 : tree_code operator_code;
17783 58607728 : unsigned op_flags;
17784 58607728 : if (IDENTIFIER_CONV_OP_P (name))
17785 : {
17786 : /* Conversion operators are TYPE_EXPR for the purposes of this
17787 : function. */
17788 : operator_code = TYPE_EXPR;
17789 : op_flags = OVL_OP_FLAG_UNARY;
17790 : }
17791 : else
17792 : {
17793 56308580 : const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
17794 :
17795 56308580 : operator_code = ovl_op->tree_code;
17796 56308580 : op_flags = ovl_op->flags;
17797 56308580 : gcc_checking_assert (operator_code != ERROR_MARK);
17798 56308580 : DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
17799 : }
17800 :
17801 56308580 : if (op_flags & OVL_OP_FLAG_ALLOC)
17802 : {
17803 : /* operator new and operator delete are quite special. */
17804 333505 : if (class_type)
17805 7399 : switch (op_flags)
17806 : {
17807 4989 : case OVL_OP_FLAG_ALLOC:
17808 4989 : TYPE_HAS_NEW_OPERATOR (class_type) = 1;
17809 4989 : break;
17810 :
17811 2139 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
17812 2139 : TYPE_GETS_DELETE (class_type) |= 1;
17813 2139 : break;
17814 :
17815 132 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
17816 132 : TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
17817 132 : break;
17818 :
17819 139 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
17820 139 : TYPE_GETS_DELETE (class_type) |= 2;
17821 139 : break;
17822 :
17823 0 : default:
17824 0 : gcc_unreachable ();
17825 : }
17826 :
17827 : /* [basic.std.dynamic.allocation]/1:
17828 :
17829 : A program is ill-formed if an allocation function is declared
17830 : in a namespace scope other than global scope or declared
17831 : static in global scope.
17832 :
17833 : The same also holds true for deallocation functions. */
17834 333505 : if (DECL_NAMESPACE_SCOPE_P (decl))
17835 : {
17836 326106 : if (CP_DECL_CONTEXT (decl) != global_namespace)
17837 : {
17838 6 : error_at (loc, "%qD may not be declared within a namespace",
17839 : decl);
17840 6 : return false;
17841 : }
17842 :
17843 326100 : if (!TREE_PUBLIC (decl))
17844 : {
17845 6 : error_at (loc, "%qD may not be declared as static", decl);
17846 6 : return false;
17847 : }
17848 : }
17849 :
17850 : /* Check for replaceable global new/delete operators with
17851 : const std::nothrow_t & last argument, other replaceable global
17852 : new/delete operators are marked in cxx_init_decl_processing. */
17853 333493 : if (CP_DECL_CONTEXT (decl) == global_namespace)
17854 : {
17855 326094 : tree args = argtypes;
17856 326094 : if (args
17857 326082 : && args != void_list_node
17858 978240 : && same_type_p (TREE_VALUE (args),
17859 : (op_flags & OVL_OP_FLAG_DELETE)
17860 : ? ptr_type_node : size_type_node))
17861 : {
17862 326052 : args = TREE_CHAIN (args);
17863 326052 : if (aligned_allocation_fn_p (decl))
17864 104956 : args = TREE_CHAIN (args);
17865 326052 : if (args
17866 326046 : && args != void_list_node
17867 543673 : && TREE_CHAIN (args) == void_list_node)
17868 : {
17869 191338 : tree t = TREE_VALUE (args);
17870 191338 : if (TYPE_REF_P (t)
17871 108539 : && !TYPE_REF_IS_RVALUE (t)
17872 108539 : && (t = TREE_TYPE (t))
17873 108539 : && TYPE_QUALS (t) == TYPE_QUAL_CONST
17874 299417 : && is_std_class (t, "nothrow_t"))
17875 108079 : DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
17876 : }
17877 : }
17878 : }
17879 :
17880 333493 : if (op_flags & OVL_OP_FLAG_DELETE)
17881 : {
17882 190972 : DECL_SET_IS_OPERATOR_DELETE (decl, true);
17883 190972 : coerce_delete_type (decl, loc);
17884 : }
17885 : else
17886 : {
17887 142521 : DECL_SET_IS_OPERATOR_NEW (decl, true);
17888 142521 : TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
17889 : }
17890 :
17891 333493 : return true;
17892 : }
17893 :
17894 : /* An operator function must either be a non-static member function
17895 : or have at least one parameter of a class, a reference to a class,
17896 : an enumeration, or a reference to an enumeration. 13.4.0.6 */
17897 58274223 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
17898 : {
17899 15042802 : if (operator_code == TYPE_EXPR
17900 15042802 : || operator_code == COMPONENT_REF
17901 15042781 : || operator_code == NOP_EXPR)
17902 : {
17903 33 : error_at (loc, "%qD must be a non-static member function", decl);
17904 33 : return false;
17905 : }
17906 :
17907 15042769 : if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
17908 : {
17909 128166 : if (! DECL_STATIC_FUNCTION_P (decl))
17910 : {
17911 12 : error_at (loc, "%qD must be a member function", decl);
17912 12 : return false;
17913 : }
17914 128154 : if (cxx_dialect < cxx23
17915 : /* For lambdas we diagnose static lambda specifier elsewhere. */
17916 213064 : && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
17917 : /* For instantiations, we have diagnosed this already. */
17918 234672 : && ! DECL_USE_TEMPLATE (decl))
17919 106512 : pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
17920 : "function only with %<-std=c++23%> or %<-std=gnu++23%>",
17921 : decl);
17922 128154 : if (operator_code == ARRAY_REF)
17923 : /* static operator[] should have exactly one argument
17924 : for C++20 and earlier, so that it isn't multidimensional. */
17925 : op_flags = OVL_OP_FLAG_UNARY;
17926 : }
17927 14914603 : else if (DECL_STATIC_FUNCTION_P (decl))
17928 : {
17929 9 : error_at (loc, "%qD must be either a non-static member "
17930 : "function or a non-member function", decl);
17931 9 : return false;
17932 : }
17933 : else
17934 410724 : for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
17935 : {
17936 15325318 : if (!arg || arg == void_list_node)
17937 : {
17938 18 : if (complain)
17939 15 : error_at (loc, "%qD must have an argument of class or "
17940 : "enumerated type", decl);
17941 18 : return false;
17942 : }
17943 :
17944 15325300 : tree type = non_reference (TREE_VALUE (arg));
17945 15325300 : if (type == error_mark_node)
17946 : return false;
17947 :
17948 : /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
17949 : because these checks are performed even on template
17950 : functions. */
17951 15325297 : if (MAYBE_CLASS_TYPE_P (type)
17952 1394520 : || TREE_CODE (type) == ENUMERAL_TYPE)
17953 : break;
17954 410724 : }
17955 : }
17956 :
17957 58272224 : if (operator_code == CALL_EXPR)
17958 : /* There are no further restrictions on the arguments to an overloaded
17959 : "operator ()". */
17960 : return true;
17961 :
17962 : /* C++23 allows an arbitrary number of parameters and default arguments for
17963 : operator[], and none of the other checks below apply. */
17964 48740705 : if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
17965 : return true;
17966 :
17967 48526948 : if (operator_code == COND_EXPR)
17968 : {
17969 : /* 13.4.0.3 */
17970 6 : error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
17971 6 : return false;
17972 : }
17973 :
17974 : /* Count the number of arguments and check for ellipsis. */
17975 : int arity = 0;
17976 137957745 : for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
17977 : {
17978 89430818 : if (!arg)
17979 : {
17980 15 : error_at (loc, "%qD must not have variable number of arguments",
17981 : decl);
17982 15 : return false;
17983 : }
17984 89430803 : ++arity;
17985 : }
17986 : /* FIXME: We need tests for these errors with xobj member functions. */
17987 : /* Verify correct number of arguments. */
17988 48526927 : switch (op_flags)
17989 : {
17990 10010599 : case OVL_OP_FLAG_AMBIARY:
17991 10010599 : if (arity == 1)
17992 : {
17993 : /* We have a unary instance of an ambi-ary op. Remap to the
17994 : unary one. */
17995 4308042 : unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
17996 4308042 : const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
17997 4308042 : gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
17998 4308042 : operator_code = ovl_op->tree_code;
17999 4308042 : DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
18000 : }
18001 5702557 : else if (arity != 2)
18002 : {
18003 : /* This was an ambiguous operator but is invalid. */
18004 3 : error_at (loc,
18005 : methodp
18006 : ? G_("%qD must have either zero or one argument")
18007 : : G_("%qD must have either one or two arguments"), decl);
18008 3 : return false;
18009 : }
18010 5702554 : else if ((operator_code == POSTINCREMENT_EXPR
18011 5702554 : || operator_code == POSTDECREMENT_EXPR)
18012 2648502 : && ! processing_template_decl
18013 : /* x++ and x--'s second argument must be an int. */
18014 7446571 : && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
18015 : integer_type_node))
18016 : {
18017 15 : error_at (loc,
18018 : methodp
18019 : ? G_("postfix %qD must have %<int%> as its argument")
18020 : : G_("postfix %qD must have %<int%> as its second argument"),
18021 : decl);
18022 15 : return false;
18023 : }
18024 : break;
18025 :
18026 3315039 : case OVL_OP_FLAG_UNARY:
18027 3315039 : if (arity != 1)
18028 : {
18029 9 : error_at (loc,
18030 : methodp
18031 : ? G_("%qD must have no arguments")
18032 : : G_("%qD must have exactly one argument"), decl);
18033 9 : return false;
18034 : }
18035 : break;
18036 :
18037 35201289 : case OVL_OP_FLAG_BINARY:
18038 35201289 : if (arity != 2)
18039 : {
18040 3 : error_at (loc,
18041 : methodp
18042 : ? G_("%qD must have exactly one argument")
18043 : : G_("%qD must have exactly two arguments"), decl);
18044 3 : return false;
18045 : }
18046 : break;
18047 :
18048 0 : default:
18049 0 : gcc_unreachable ();
18050 : }
18051 :
18052 : /* There can be no default arguments. */
18053 137957604 : for (tree arg = argtypes; arg && arg != void_list_node;
18054 89430707 : arg = TREE_CHAIN (arg))
18055 89430722 : if (TREE_PURPOSE (arg))
18056 : {
18057 15 : TREE_PURPOSE (arg) = NULL_TREE;
18058 15 : error_at (loc, "%qD cannot have default arguments", decl);
18059 15 : return false;
18060 : }
18061 :
18062 : /* At this point the declaration is well-formed. It may not be
18063 : sensible though. */
18064 :
18065 : /* Check member function warnings only on the in-class declaration.
18066 : There's no point warning on an out-of-class definition. */
18067 48526882 : if (class_type && class_type != current_class_type)
18068 : return true;
18069 :
18070 : /* Warn about conversion operators that will never be used. */
18071 46679332 : if (IDENTIFIER_CONV_OP_P (name)
18072 2298684 : && ! DECL_TEMPLATE_INFO (decl)
18073 47683422 : && warn_class_conversion)
18074 : {
18075 1004057 : tree t = TREE_TYPE (name);
18076 1004057 : int ref = TYPE_REF_P (t);
18077 :
18078 1004057 : if (ref)
18079 21053 : t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
18080 :
18081 1004057 : if (VOID_TYPE_P (t))
18082 9 : warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
18083 : "will never use a type conversion operator", class_type);
18084 1004048 : else if (class_type)
18085 : {
18086 1004048 : if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
18087 24 : warning_at (loc, OPT_Wclass_conversion,
18088 : ref
18089 : ? G_("converting %qT to a reference to the same type "
18090 : "will never use a type conversion operator")
18091 : : G_("converting %qT to the same type "
18092 : "will never use a type conversion operator"),
18093 : class_type);
18094 : /* Don't force t to be complete here. */
18095 1004033 : else if (MAYBE_CLASS_TYPE_P (t)
18096 574356 : && COMPLETE_TYPE_P (t)
18097 153764 : && DERIVED_FROM_P (t, class_type))
18098 30 : warning_at (loc, OPT_Wclass_conversion,
18099 : ref
18100 : ? G_("converting %qT to a reference to a base class "
18101 : "%qT will never use a type conversion operator")
18102 : : G_("converting %qT to a base class %qT "
18103 : "will never use a type conversion operator"),
18104 : class_type, t);
18105 : }
18106 : }
18107 :
18108 46679332 : if (!warn_ecpp)
18109 : return true;
18110 :
18111 : /* Effective C++ rules below. */
18112 :
18113 : /* More Effective C++ rule 7. */
18114 54 : if (operator_code == TRUTH_ANDIF_EXPR
18115 54 : || operator_code == TRUTH_ORIF_EXPR
18116 54 : || operator_code == COMPOUND_EXPR)
18117 0 : warning_at (loc, OPT_Weffc__,
18118 : "user-defined %qD always evaluates both arguments", decl);
18119 :
18120 : /* More Effective C++ rule 6. */
18121 54 : if (operator_code == POSTINCREMENT_EXPR
18122 : || operator_code == POSTDECREMENT_EXPR
18123 : || operator_code == PREINCREMENT_EXPR
18124 54 : || operator_code == PREDECREMENT_EXPR)
18125 : {
18126 0 : tree arg = TREE_VALUE (argtypes);
18127 0 : tree ret = TREE_TYPE (TREE_TYPE (decl));
18128 0 : if (methodp || TYPE_REF_P (arg))
18129 0 : arg = TREE_TYPE (arg);
18130 0 : arg = TYPE_MAIN_VARIANT (arg);
18131 :
18132 0 : if (operator_code == PREINCREMENT_EXPR
18133 : || operator_code == PREDECREMENT_EXPR)
18134 : {
18135 0 : if (!TYPE_REF_P (ret)
18136 0 : || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
18137 0 : warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
18138 : build_reference_type (arg));
18139 : }
18140 : else
18141 : {
18142 0 : if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
18143 0 : warning_at (loc, OPT_Weffc__,
18144 : "postfix %qD should return %qT", decl, arg);
18145 : }
18146 : }
18147 :
18148 : /* Effective C++ rule 23. */
18149 54 : if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
18150 : && (operator_code == PLUS_EXPR
18151 9 : || operator_code == MINUS_EXPR
18152 9 : || operator_code == TRUNC_DIV_EXPR
18153 : || operator_code == MULT_EXPR
18154 : || operator_code == TRUNC_MOD_EXPR)
18155 60 : && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
18156 3 : warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
18157 :
18158 : return true;
18159 : }
18160 :
18161 : /* Return a string giving the keyword associate with CODE. */
18162 :
18163 : const char *
18164 3375 : tag_name (enum tag_types code)
18165 : {
18166 3375 : switch (code)
18167 : {
18168 : case record_type:
18169 : return "struct";
18170 107 : case class_type:
18171 107 : return "class";
18172 3 : case union_type:
18173 3 : return "union";
18174 9 : case enum_type:
18175 9 : return "enum";
18176 3167 : case typename_type:
18177 3167 : case none_type:
18178 3167 : return "typename";
18179 29 : case scope_type:
18180 29 : return nullptr;
18181 : }
18182 0 : gcc_unreachable ();
18183 : }
18184 :
18185 : /* Name lookup in an elaborated-type-specifier (after the keyword
18186 : indicated by TAG_CODE) has found the TYPE_DECL DECL. If the
18187 : elaborated-type-specifier is invalid, issue a diagnostic and return
18188 : error_mark_node; otherwise, return the *_TYPE to which it referred.
18189 : If ALLOW_TEMPLATE_P is true, TYPE may be a class template. */
18190 :
18191 : tree
18192 12005466 : check_elaborated_type_specifier (enum tag_types tag_code,
18193 : tree decl,
18194 : bool allow_template_p)
18195 : {
18196 12005466 : tree type;
18197 :
18198 : /* In the case of:
18199 :
18200 : struct S { struct S *p; };
18201 :
18202 : name lookup will find the TYPE_DECL for the implicit "S::S"
18203 : typedef. Adjust for that here. */
18204 12005466 : if (DECL_SELF_REFERENCE_P (decl))
18205 407558 : decl = TYPE_NAME (TREE_TYPE (decl));
18206 :
18207 12005466 : type = TREE_TYPE (decl);
18208 :
18209 : /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
18210 : is false for this case as well. */
18211 12005466 : if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
18212 : {
18213 9 : error ("using template type parameter %qT after %qs",
18214 : type, tag_name (tag_code));
18215 9 : return error_mark_node;
18216 : }
18217 : /* Accept template template parameters. */
18218 12005457 : else if (allow_template_p
18219 6735966 : && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
18220 6735954 : || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
18221 : ;
18222 : /* [dcl.type.elab]
18223 :
18224 : If the identifier resolves to a typedef-name or the
18225 : simple-template-id resolves to an alias template
18226 : specialization, the elaborated-type-specifier is ill-formed.
18227 :
18228 : In other words, the only legitimate declaration to use in the
18229 : elaborated type specifier is the implicit typedef created when
18230 : the type is declared. */
18231 12005442 : else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
18232 407682 : && !DECL_SELF_REFERENCE_P (decl)
18233 12005566 : && tag_code != typename_type)
18234 : {
18235 78 : auto_diagnostic_group d;
18236 78 : if (alias_template_specialization_p (type, nt_opaque))
18237 21 : error ("using alias template specialization %qT after %qs",
18238 : type, tag_name (tag_code));
18239 : else
18240 57 : error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
18241 78 : inform (DECL_SOURCE_LOCATION (decl),
18242 : "%qD has a previous declaration here", decl);
18243 78 : return error_mark_node;
18244 78 : }
18245 12005364 : else if (TREE_CODE (type) != RECORD_TYPE
18246 12005364 : && TREE_CODE (type) != UNION_TYPE
18247 : && tag_code != enum_type
18248 70434 : && tag_code != typename_type)
18249 : {
18250 6 : auto_diagnostic_group d;
18251 6 : error ("%qT referred to as %qs", type, tag_name (tag_code));
18252 6 : inform (location_of (type), "%qT has a previous declaration here", type);
18253 6 : return error_mark_node;
18254 6 : }
18255 12005358 : else if (TREE_CODE (type) != ENUMERAL_TYPE
18256 11934966 : && tag_code == enum_type)
18257 : {
18258 3 : auto_diagnostic_group d;
18259 3 : error ("%qT referred to as enum", type);
18260 3 : inform (location_of (type), "%qT has a previous declaration here", type);
18261 3 : return error_mark_node;
18262 3 : }
18263 12005355 : else if (!allow_template_p
18264 5269431 : && TREE_CODE (type) == RECORD_TYPE
18265 17152341 : && CLASSTYPE_IS_TEMPLATE (type))
18266 : {
18267 : /* If a class template appears as elaborated type specifier
18268 : without a template header such as:
18269 :
18270 : template <class T> class C {};
18271 : void f(class C); // No template header here
18272 :
18273 : then the required template argument is missing. */
18274 18 : error ("template argument required for %<%s %T%>",
18275 : tag_name (tag_code),
18276 18 : DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
18277 18 : return error_mark_node;
18278 : }
18279 :
18280 : return type;
18281 : }
18282 :
18283 : /* Lookup NAME of an elaborated type specifier according to SCOPE and
18284 : issue diagnostics if necessary. Return *_TYPE node upon success,
18285 : NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
18286 : error. */
18287 :
18288 : static tree
18289 25876271 : lookup_and_check_tag (enum tag_types tag_code, tree name,
18290 : TAG_how how, bool template_header_p)
18291 : {
18292 25876271 : tree decl;
18293 25876271 : if (how == TAG_how::GLOBAL)
18294 : {
18295 : /* First try ordinary name lookup, ignoring hidden class name
18296 : injected via friend declaration. */
18297 2120028 : decl = lookup_name (name, LOOK_want::TYPE);
18298 : /* If that fails, the name will be placed in the smallest
18299 : non-class, non-function-prototype scope according to 3.3.1/5.
18300 : We may already have a hidden name declared as friend in this
18301 : scope. So lookup again but not ignoring hidden names.
18302 : If we find one, that name will be made visible rather than
18303 : creating a new tag. */
18304 2120028 : if (!decl)
18305 18326 : decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
18306 : }
18307 : else
18308 23756243 : decl = lookup_elaborated_type (name, how);
18309 :
18310 23774569 : if (!decl)
18311 : /* We found nothing. */
18312 : return NULL_TREE;
18313 :
18314 5880844 : if (TREE_CODE (decl) == TREE_LIST)
18315 : {
18316 3 : auto_diagnostic_group d;
18317 3 : error ("reference to %qD is ambiguous", name);
18318 3 : print_candidates (input_location, decl);
18319 3 : return error_mark_node;
18320 3 : }
18321 :
18322 2368487 : if (DECL_CLASS_TEMPLATE_P (decl)
18323 2368481 : && !template_header_p
18324 8249322 : && how == TAG_how::CURRENT_ONLY)
18325 : {
18326 12 : auto_diagnostic_group d;
18327 12 : error ("class template %qD redeclared as non-template", name);
18328 12 : inform (location_of (decl), "previous declaration here");
18329 12 : CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
18330 12 : return error_mark_node;
18331 12 : }
18332 :
18333 2368475 : if (DECL_CLASS_TEMPLATE_P (decl)
18334 : /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
18335 : so ignore a template template parameter. */
18336 5880835 : || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
18337 2368472 : decl = DECL_TEMPLATE_RESULT (decl);
18338 :
18339 5880829 : if (TREE_CODE (decl) != TYPE_DECL)
18340 : /* Found not-a-type. */
18341 : return NULL_TREE;
18342 :
18343 : /* Look for invalid nested type:
18344 : class C {
18345 : class C {};
18346 : }; */
18347 5880808 : if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
18348 : {
18349 6 : error ("%qD has the same name as the class in which it is "
18350 : "declared", decl);
18351 6 : return error_mark_node;
18352 : }
18353 :
18354 : /* Two cases we need to consider when deciding if a class
18355 : template is allowed as an elaborated type specifier:
18356 : 1. It is a self reference to its own class.
18357 : 2. It comes with a template header.
18358 :
18359 : For example:
18360 :
18361 : template <class T> class C {
18362 : class C *c1; // DECL_SELF_REFERENCE_P is true
18363 : class D;
18364 : };
18365 : template <class U> class C; // template_header_p is true
18366 : template <class T> class C<T>::D {
18367 : class C *c2; // DECL_SELF_REFERENCE_P is true
18368 : }; */
18369 :
18370 17642406 : tree t = check_elaborated_type_specifier (tag_code, decl,
18371 : template_header_p
18372 11354061 : | DECL_SELF_REFERENCE_P (decl));
18373 2541386 : if (template_header_p && t && CLASS_TYPE_P (t)
18374 8422170 : && (!CLASSTYPE_TEMPLATE_INFO (t)
18375 2541350 : || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
18376 : {
18377 21 : auto_diagnostic_group d;
18378 21 : error ("%qT is not a template", t);
18379 21 : inform (location_of (t), "previous declaration here");
18380 42 : if (TYPE_CLASS_SCOPE_P (t)
18381 24 : && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
18382 3 : inform (input_location,
18383 : "perhaps you want to explicitly add %<%T::%>",
18384 3 : TYPE_CONTEXT (t));
18385 21 : return error_mark_node;
18386 21 : }
18387 :
18388 : return t;
18389 : }
18390 :
18391 : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
18392 : Define the tag as a forward-reference if it is not defined.
18393 :
18394 : If a declaration is given, process it here, and report an error if
18395 : multiple declarations are not identical.
18396 :
18397 : SCOPE is TS_CURRENT when this is also a definition. Only look in
18398 : the current frame for the name (since C++ allows new names in any
18399 : scope.) It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
18400 : declaration. Only look beginning from the current scope outward up
18401 : till the nearest non-class scope. Otherwise it is TS_GLOBAL.
18402 :
18403 : TEMPLATE_HEADER_P is true when this declaration is preceded by
18404 : a set of template parameters. */
18405 :
18406 : tree
18407 25750696 : xref_tag (enum tag_types tag_code, tree name,
18408 : TAG_how how, bool template_header_p)
18409 : {
18410 25750696 : enum tree_code code;
18411 25750696 : tree context = NULL_TREE;
18412 :
18413 25750696 : auto_cond_timevar tv (TV_NAME_LOOKUP);
18414 :
18415 25750696 : gcc_assert (identifier_p (name));
18416 :
18417 25750696 : switch (tag_code)
18418 : {
18419 : case record_type:
18420 : case class_type:
18421 : code = RECORD_TYPE;
18422 : break;
18423 : case union_type:
18424 : code = UNION_TYPE;
18425 : break;
18426 : case enum_type:
18427 : code = ENUMERAL_TYPE;
18428 : break;
18429 0 : default:
18430 0 : gcc_unreachable ();
18431 : }
18432 :
18433 : /* In case of anonymous name, xref_tag is only called to
18434 : make type node and push name. Name lookup is not required. */
18435 25750696 : tree t = NULL_TREE;
18436 25750696 : if (!IDENTIFIER_ANON_P (name))
18437 23571215 : t = lookup_and_check_tag (tag_code, name, how, template_header_p);
18438 :
18439 25750696 : if (t == error_mark_node)
18440 : return error_mark_node;
18441 :
18442 2832436 : if (how != TAG_how::CURRENT_ONLY && t && current_class_type
18443 1347018 : && template_class_depth (current_class_type)
18444 26348712 : && template_header_p)
18445 : {
18446 353254 : if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
18447 : return t;
18448 :
18449 : /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
18450 : a definition of this tag. Since, in addition, we are
18451 : currently processing a (member) template declaration of a
18452 : template class, we must be very careful; consider:
18453 :
18454 : template <class X> struct S1
18455 :
18456 : template <class U> struct S2
18457 : {
18458 : template <class V> friend struct S1;
18459 : };
18460 :
18461 : Here, the S2::S1 declaration should not be confused with the
18462 : outer declaration. In particular, the inner version should
18463 : have a template parameter of level 2, not level 1.
18464 :
18465 : On the other hand, when presented with:
18466 :
18467 : template <class T> struct S1
18468 : {
18469 : template <class U> struct S2 {};
18470 : template <class U> friend struct S2;
18471 : };
18472 :
18473 : the friend must find S1::S2 eventually. We accomplish this
18474 : by making sure that the new type we create to represent this
18475 : declaration has the right TYPE_CONTEXT. */
18476 353251 : context = TYPE_CONTEXT (t);
18477 353251 : t = NULL_TREE;
18478 : }
18479 :
18480 25750582 : if (! t)
18481 : {
18482 : /* If no such tag is yet defined, create a forward-reference node
18483 : and record it as the "definition".
18484 : When a real declaration of this type is found,
18485 : the forward-reference will be altered into a real type. */
18486 20257712 : if (code == ENUMERAL_TYPE)
18487 : {
18488 13 : error ("use of enum %q#D without previous declaration", name);
18489 13 : return error_mark_node;
18490 : }
18491 :
18492 20257699 : t = make_class_type (code);
18493 20257699 : TYPE_CONTEXT (t) = context;
18494 20257699 : if (IDENTIFIER_LAMBDA_P (name))
18495 : /* Mark it as a lambda type right now. Our caller will
18496 : correct the value. */
18497 1453590 : SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
18498 20257699 : t = pushtag (name, t, how);
18499 : }
18500 : else
18501 : {
18502 5492870 : if (template_header_p && MAYBE_CLASS_TYPE_P (t))
18503 : {
18504 : /* Check that we aren't trying to overload a class with different
18505 : constraints. */
18506 2188096 : if (!redeclare_class_template (t, current_template_parms,
18507 : current_template_constraints ()))
18508 60 : return error_mark_node;
18509 : }
18510 3304774 : else if (!processing_template_decl
18511 2976122 : && CLASS_TYPE_P (t)
18512 6254538 : && CLASSTYPE_IS_TEMPLATE (t))
18513 : {
18514 0 : auto_diagnostic_group d;
18515 0 : error ("redeclaration of %qT as a non-template", t);
18516 0 : inform (location_of (t), "previous declaration %qD", t);
18517 0 : return error_mark_node;
18518 0 : }
18519 :
18520 5492810 : if (modules_p ()
18521 5492810 : && how == TAG_how::CURRENT_ONLY)
18522 : {
18523 9874 : tree decl = TYPE_NAME (t);
18524 9874 : if (!module_may_redeclare (decl))
18525 15 : return error_mark_node;
18526 :
18527 9859 : tree not_tmpl = STRIP_TEMPLATE (decl);
18528 9859 : if (DECL_LANG_SPECIFIC (not_tmpl)
18529 4403 : && DECL_MODULE_ATTACH_P (not_tmpl)
18530 54 : && !DECL_MODULE_EXPORT_P (not_tmpl)
18531 9901 : && module_exporting_p ())
18532 : {
18533 6 : auto_diagnostic_group d;
18534 6 : error ("conflicting exporting for declaration %qD", decl);
18535 6 : inform (DECL_SOURCE_LOCATION (decl),
18536 : "previously declared here without exporting");
18537 6 : }
18538 :
18539 9859 : tree maybe_tmpl = decl;
18540 9859 : if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
18541 7318 : maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
18542 :
18543 : /* FIXME: we should do a more precise check for redefinitions
18544 : of a conflicting using-declaration here, as these diagnostics
18545 : are not ideal. */
18546 9859 : if (DECL_LANG_SPECIFIC (decl)
18547 4403 : && DECL_MODULE_IMPORT_P (decl)
18548 9913 : && CP_DECL_CONTEXT (decl) == current_namespace)
18549 : {
18550 : /* Push it into this TU's symbol slot. */
18551 51 : if (maybe_tmpl != decl)
18552 : /* We're in the template parm binding level.
18553 : Pushtag has logic to slide under that, but we're
18554 : not pushing a *new* type. */
18555 20 : push_nested_namespace (CP_DECL_CONTEXT (decl));
18556 :
18557 51 : pushdecl (maybe_tmpl);
18558 51 : if (maybe_tmpl != decl)
18559 20 : pop_nested_namespace (CP_DECL_CONTEXT (decl));
18560 : }
18561 :
18562 9859 : set_instantiating_module (maybe_tmpl);
18563 : }
18564 : }
18565 :
18566 : return t;
18567 25750696 : }
18568 :
18569 : /* Create the binfo hierarchy for REF with (possibly NULL) base list
18570 : BASE_LIST. For each element on BASE_LIST the TREE_PURPOSE is an
18571 : access_* node, and the TREE_VALUE is the type of the base-class.
18572 : Non-NULL TREE_TYPE indicates virtual inheritance. */
18573 :
18574 : void
18575 69693869 : xref_basetypes (tree ref, tree base_list)
18576 : {
18577 69693869 : tree *basep;
18578 69693869 : tree binfo, base_binfo;
18579 69693869 : unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases. */
18580 69693869 : unsigned max_bases = 0; /* Maximum direct bases. */
18581 69693869 : unsigned max_dvbases = 0; /* Maximum direct virtual bases. */
18582 : /* Highest direct base index with annotations. */
18583 69693869 : unsigned max_annotated_base = 0;
18584 69693869 : int i;
18585 69693869 : tree default_access;
18586 69693869 : tree igo_prev; /* Track Inheritance Graph Order. */
18587 :
18588 69693869 : if (ref == error_mark_node)
18589 12 : return;
18590 :
18591 : /* The base of a derived class is private by default, all others are
18592 : public. */
18593 69693869 : default_access = (TREE_CODE (ref) == RECORD_TYPE
18594 69101681 : && CLASSTYPE_DECLARED_CLASS (ref)
18595 69693869 : ? access_private_node : access_public_node);
18596 :
18597 : /* First, make sure that any templates in base-classes are
18598 : instantiated. This ensures that if we call ourselves recursively
18599 : we do not get confused about which classes are marked and which
18600 : are not. */
18601 69693869 : basep = &base_list;
18602 102332620 : while (*basep)
18603 : {
18604 32638751 : tree basetype = TREE_VALUE (*basep);
18605 :
18606 : /* The dependent_type_p call below should really be dependent_scope_p
18607 : so that we give a hard error about using an incomplete type as a
18608 : base, but we allow it with a pedwarn for backward
18609 : compatibility. */
18610 32638751 : if (processing_template_decl
18611 32638751 : && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
18612 3 : cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
18613 : diagnostics::kind::pedwarn);
18614 32638751 : if (!dependent_type_p (basetype)
18615 32638751 : && !complete_type_or_else (basetype, NULL))
18616 : /* An incomplete type. Remove it from the list. */
18617 15 : *basep = TREE_CHAIN (*basep);
18618 : else
18619 : {
18620 32638736 : max_bases++;
18621 32638736 : if (TREE_CODE (TREE_PURPOSE (*basep)) == TREE_LIST)
18622 14 : max_annotated_base = max_bases;
18623 32638736 : if (TREE_TYPE (*basep))
18624 67886 : max_dvbases++;
18625 32638736 : if (CLASS_TYPE_P (basetype))
18626 31853772 : max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
18627 32638736 : basep = &TREE_CHAIN (*basep);
18628 : }
18629 : }
18630 69693869 : max_vbases += max_dvbases;
18631 :
18632 69693869 : TYPE_MARKED_P (ref) = 1;
18633 :
18634 : /* The binfo slot should be empty, unless this is an (ill-formed)
18635 : redefinition. */
18636 69693869 : gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
18637 :
18638 69693869 : gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
18639 :
18640 69693869 : binfo = make_tree_binfo (max_bases);
18641 :
18642 69693869 : TYPE_BINFO (ref) = binfo;
18643 69693869 : BINFO_OFFSET (binfo) = size_zero_node;
18644 69693869 : BINFO_TYPE (binfo) = ref;
18645 :
18646 : /* Apply base-class info set up to the variants of this type. */
18647 69693869 : fixup_type_variants (ref);
18648 :
18649 69693869 : if (max_bases)
18650 : {
18651 31733727 : vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases + max_annotated_base);
18652 31733727 : BINFO_BASE_ACCESSES (binfo)->quick_grow (max_bases + max_annotated_base);
18653 : /* A C++98 POD cannot have base classes. */
18654 31733727 : CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
18655 :
18656 31733727 : if (TREE_CODE (ref) == UNION_TYPE)
18657 : {
18658 12 : error ("derived union %qT invalid", ref);
18659 12 : return;
18660 : }
18661 : }
18662 :
18663 31733715 : if (max_bases > 1)
18664 716591 : warning (OPT_Wmultiple_inheritance,
18665 : "%qT defined with multiple direct bases", ref);
18666 :
18667 69693857 : if (max_vbases)
18668 : {
18669 : /* An aggregate can't have virtual base classes. */
18670 202287 : CLASSTYPE_NON_AGGREGATE (ref) = true;
18671 :
18672 202287 : vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
18673 :
18674 202287 : if (max_dvbases)
18675 66679 : warning (OPT_Wvirtual_inheritance,
18676 : "%qT defined with direct virtual base", ref);
18677 : }
18678 :
18679 102332581 : for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
18680 : {
18681 32638724 : tree access = TREE_PURPOSE (base_list);
18682 32638724 : tree annotations = NULL_TREE;
18683 32638724 : if (TREE_CODE (access) == TREE_LIST)
18684 : {
18685 14 : annotations = TREE_VALUE (access);
18686 14 : access = TREE_PURPOSE (access);
18687 39 : for (tree *d = &annotations; *d; )
18688 : {
18689 25 : if (annotation_p (*d))
18690 : {
18691 25 : tree name = get_attribute_name (*d);
18692 25 : tree args = TREE_VALUE (*d);
18693 25 : const attribute_spec *as
18694 25 : = lookup_attribute_spec (TREE_PURPOSE (*d));
18695 25 : bool no_add_attrs = false;
18696 25 : as->handler (&binfo, name, args, 0, &no_add_attrs);
18697 25 : if (no_add_attrs)
18698 : {
18699 1 : *d = TREE_CHAIN (*d);
18700 1 : continue;
18701 : }
18702 : }
18703 24 : d = &TREE_CHAIN (*d);
18704 : }
18705 : }
18706 32638724 : int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
18707 32638724 : tree basetype = TREE_VALUE (base_list);
18708 :
18709 32638724 : if (access == access_default_node)
18710 4427317 : access = default_access;
18711 :
18712 : /* Before C++17, an aggregate cannot have base classes. In C++17, an
18713 : aggregate can't have virtual, private, or protected base classes. */
18714 32638724 : if (cxx_dialect < cxx17
18715 32420005 : || access != access_public_node
18716 31442348 : || via_virtual)
18717 1260948 : CLASSTYPE_NON_AGGREGATE (ref) = true;
18718 :
18719 32638724 : if (PACK_EXPANSION_P (basetype))
18720 28450 : basetype = PACK_EXPANSION_PATTERN (basetype);
18721 32638724 : if (TREE_CODE (basetype) == TYPE_DECL)
18722 0 : basetype = TREE_TYPE (basetype);
18723 32638724 : if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
18724 : {
18725 24 : error ("base type %qT fails to be a struct or class type",
18726 : basetype);
18727 24 : goto dropped_base;
18728 : }
18729 :
18730 32638700 : base_binfo = NULL_TREE;
18731 32638700 : if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
18732 : {
18733 25801483 : base_binfo = TYPE_BINFO (basetype);
18734 : /* The original basetype could have been a typedef'd type. */
18735 25801483 : basetype = BINFO_TYPE (base_binfo);
18736 :
18737 : /* Inherit flags from the base. */
18738 77404449 : TYPE_HAS_NEW_OPERATOR (ref)
18739 25801483 : |= TYPE_HAS_NEW_OPERATOR (basetype);
18740 77404449 : TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
18741 25801483 : |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
18742 25801483 : TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
18743 25801483 : TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
18744 77404449 : CLASSTYPE_DIAMOND_SHAPED_P (ref)
18745 25801483 : |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
18746 77404449 : CLASSTYPE_REPEATED_BASE_P (ref)
18747 25801483 : |= CLASSTYPE_REPEATED_BASE_P (basetype);
18748 : }
18749 :
18750 : /* We must do this test after we've seen through a typedef
18751 : type. */
18752 32638700 : if (TYPE_MARKED_P (basetype))
18753 : {
18754 18 : if (basetype == ref)
18755 0 : error ("recursive type %qT undefined", basetype);
18756 : else
18757 18 : error ("duplicate base type %qT invalid", basetype);
18758 18 : goto dropped_base;
18759 : }
18760 :
18761 32638682 : if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
18762 : /* Regenerate the pack expansion for the bases. */
18763 28450 : basetype = make_pack_expansion (basetype);
18764 :
18765 32638682 : TYPE_MARKED_P (basetype) = 1;
18766 :
18767 32638682 : base_binfo = copy_binfo (base_binfo, basetype, ref,
18768 : &igo_prev, via_virtual);
18769 32638682 : if (!BINFO_INHERITANCE_CHAIN (base_binfo))
18770 32570811 : BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
18771 :
18772 32638682 : unsigned len;
18773 32638682 : len = BINFO_N_BASE_BINFOS (binfo);
18774 32638682 : BINFO_BASE_APPEND (binfo, base_binfo);
18775 32638682 : BINFO_BASE_ACCESS (binfo, len) = access;
18776 32638682 : if (len < max_annotated_base)
18777 17 : BINFO_BASE_ACCESS (binfo, max_bases + len) = annotations;
18778 32638682 : continue;
18779 :
18780 42 : dropped_base:
18781 : /* Update max_vbases to reflect the reality that we are dropping
18782 : this base: if it reaches zero we want to undo the vec_alloc
18783 : above to avoid inconsistencies during error-recovery: eg, in
18784 : build_special_member_call, CLASSTYPE_VBASECLASSES non null
18785 : and vtt null (c++/27952). */
18786 42 : if (via_virtual)
18787 12 : max_vbases--;
18788 42 : if (CLASS_TYPE_P (basetype))
18789 30 : max_vbases
18790 33 : -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
18791 32638682 : }
18792 :
18793 69693857 : unsigned len = BINFO_N_BASE_BINFOS (binfo);
18794 69693857 : if (len < max_bases)
18795 : {
18796 42 : if (len && max_annotated_base)
18797 0 : memmove (&BINFO_BASE_ACCESS (binfo, len),
18798 0 : &BINFO_BASE_ACCESS (binfo, max_bases),
18799 0 : MIN (max_annotated_base, len) * sizeof (tree));
18800 42 : BINFO_BASE_ACCESSES (binfo)->truncate (len + MIN (max_annotated_base,
18801 : len));
18802 : }
18803 :
18804 69693857 : if (CLASSTYPE_VBASECLASSES (ref)
18805 69693857 : && max_vbases == 0)
18806 24 : vec_free (CLASSTYPE_VBASECLASSES (ref));
18807 :
18808 69896132 : if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
18809 : /* If we didn't get max_vbases vbases, we must have shared at
18810 : least one of them, and are therefore diamond shaped. */
18811 21974 : CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
18812 :
18813 : /* Unmark all the types. */
18814 102332539 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
18815 32638682 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
18816 69693857 : TYPE_MARKED_P (ref) = 0;
18817 :
18818 : /* Now see if we have a repeated base type. */
18819 69693857 : if (!CLASSTYPE_REPEATED_BASE_P (ref))
18820 : {
18821 176127073 : for (base_binfo = binfo; base_binfo;
18822 106433650 : base_binfo = TREE_CHAIN (base_binfo))
18823 : {
18824 106434366 : if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
18825 : {
18826 716 : CLASSTYPE_REPEATED_BASE_P (ref) = 1;
18827 716 : break;
18828 : }
18829 106433650 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
18830 : }
18831 176127073 : for (base_binfo = binfo; base_binfo;
18832 106433650 : base_binfo = TREE_CHAIN (base_binfo))
18833 106434366 : if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
18834 106433650 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
18835 : else
18836 : break;
18837 : }
18838 : }
18839 :
18840 :
18841 : /* Copies the enum-related properties from type SRC to type DST.
18842 : Used with the underlying type of an enum and the enum itself. */
18843 : static void
18844 1953336 : copy_type_enum (tree dst, tree src)
18845 : {
18846 1953336 : tree t;
18847 3906690 : for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
18848 : {
18849 1953354 : TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
18850 1953354 : TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
18851 1953354 : TYPE_SIZE (t) = TYPE_SIZE (src);
18852 1953354 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
18853 1953354 : SET_TYPE_MODE (dst, TYPE_MODE (src));
18854 1953354 : TYPE_PRECISION (t) = TYPE_PRECISION (src);
18855 1953354 : unsigned valign = TYPE_ALIGN (src);
18856 1953354 : if (TYPE_USER_ALIGN (t))
18857 12 : valign = MAX (valign, TYPE_ALIGN (t));
18858 : else
18859 1953342 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
18860 1953354 : SET_TYPE_ALIGN (t, valign);
18861 1953354 : TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
18862 : }
18863 1953336 : }
18864 :
18865 : /* Begin compiling the definition of an enumeration type.
18866 : NAME is its name,
18867 :
18868 : if ENUMTYPE is not NULL_TREE then the type has alredy been found.
18869 :
18870 : UNDERLYING_TYPE is the type that will be used as the storage for
18871 : the enumeration type. This should be NULL_TREE if no storage type
18872 : was specified.
18873 :
18874 : ATTRIBUTES are any attributes specified after the enum-key.
18875 :
18876 : SCOPED_ENUM_P is true if this is a scoped enumeration type.
18877 :
18878 : if IS_NEW is not NULL, gets TRUE iff a new type is created.
18879 :
18880 : Returns the type object, as yet incomplete.
18881 : Also records info about it so that build_enumerator
18882 : may be used to declare the individual values as they are read. */
18883 :
18884 : tree
18885 2305192 : start_enum (tree name, tree enumtype, tree underlying_type,
18886 : tree attributes, bool scoped_enum_p, bool *is_new)
18887 : {
18888 2305192 : tree prevtype = NULL_TREE;
18889 2305192 : gcc_assert (identifier_p (name));
18890 :
18891 2305192 : if (is_new)
18892 1862042 : *is_new = false;
18893 : /* [C++0x dcl.enum]p5:
18894 :
18895 : If not explicitly specified, the underlying type of a scoped
18896 : enumeration type is int. */
18897 2305192 : if (!underlying_type && scoped_enum_p)
18898 169617 : underlying_type = integer_type_node;
18899 :
18900 2305192 : if (underlying_type)
18901 582092 : underlying_type = cv_unqualified (underlying_type);
18902 :
18903 : /* If this is the real definition for a previous forward reference,
18904 : fill in the contents in the same object that used to be the
18905 : forward reference. */
18906 2305192 : if (!enumtype)
18907 2305056 : enumtype = lookup_and_check_tag (enum_type, name,
18908 : /*tag_scope=*/TAG_how::CURRENT_ONLY,
18909 : /*template_header_p=*/false);
18910 :
18911 : /* In case of a template_decl, the only check that should be deferred
18912 : to instantiation time is the comparison of underlying types. */
18913 2305192 : if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
18914 : {
18915 : /* Attempt to set the declaring module. */
18916 34721 : if (modules_p ())
18917 : {
18918 178 : tree decl = TYPE_NAME (enumtype);
18919 178 : if (!module_may_redeclare (decl))
18920 3 : enumtype = error_mark_node;
18921 : else
18922 175 : set_instantiating_module (decl);
18923 : }
18924 :
18925 34721 : if (enumtype == error_mark_node)
18926 : ;
18927 34925 : else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
18928 : {
18929 6 : auto_diagnostic_group d;
18930 6 : error_at (input_location, "scoped/unscoped mismatch "
18931 : "in enum %q#T", enumtype);
18932 6 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18933 : "previous definition here");
18934 6 : enumtype = error_mark_node;
18935 6 : }
18936 34712 : else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
18937 : {
18938 0 : auto_diagnostic_group d;
18939 0 : error_at (input_location, "underlying type mismatch "
18940 : "in enum %q#T", enumtype);
18941 0 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18942 : "previous definition here");
18943 0 : enumtype = error_mark_node;
18944 0 : }
18945 34697 : else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
18946 69409 : && !same_type_p (underlying_type,
18947 : ENUM_UNDERLYING_TYPE (enumtype)))
18948 : {
18949 29 : auto_diagnostic_group d;
18950 29 : error_at (input_location, "different underlying type "
18951 : "in enum %q#T", enumtype);
18952 29 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18953 : "previous definition here");
18954 29 : underlying_type = NULL_TREE;
18955 29 : }
18956 : }
18957 :
18958 2305192 : if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
18959 34712 : || processing_template_decl)
18960 : {
18961 : /* In case of error, make a dummy enum to allow parsing to
18962 : continue. */
18963 2270573 : if (enumtype == error_mark_node)
18964 : {
18965 9 : name = make_anon_name ();
18966 9 : enumtype = NULL_TREE;
18967 : }
18968 :
18969 : /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
18970 : of an opaque enum, or an opaque enum of an already defined
18971 : enumeration (C++11).
18972 : In any other case, it'll be NULL_TREE. */
18973 2270573 : if (!enumtype)
18974 : {
18975 2270477 : if (is_new)
18976 1827330 : *is_new = true;
18977 : }
18978 2270573 : prevtype = enumtype;
18979 :
18980 : /* Do not push the decl more than once. */
18981 2270573 : if (!enumtype
18982 96 : || TREE_CODE (enumtype) != ENUMERAL_TYPE)
18983 : {
18984 2270480 : enumtype = cxx_make_type (ENUMERAL_TYPE);
18985 2270480 : enumtype = pushtag (name, enumtype);
18986 :
18987 2270480 : if (enumtype != error_mark_node)
18988 : {
18989 : /* The enum is considered opaque until the opening '{' of the
18990 : enumerator list. */
18991 2270462 : SET_OPAQUE_ENUM_P (enumtype, true);
18992 2270462 : ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
18993 :
18994 : /* std::byte aliases anything. */
18995 2270462 : if (TYPE_CONTEXT (enumtype) == std_node
18996 2621193 : && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
18997 12964 : TYPE_ALIAS_SET (enumtype) = 0;
18998 : }
18999 : }
19000 : else
19001 93 : enumtype = xref_tag (enum_type, name);
19002 :
19003 2270573 : if (enumtype == error_mark_node)
19004 : return error_mark_node;
19005 : }
19006 :
19007 2305174 : SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
19008 :
19009 2305174 : cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
19010 :
19011 2305174 : if (underlying_type)
19012 : {
19013 582060 : if (ENUM_UNDERLYING_TYPE (enumtype))
19014 : /* We already checked that it matches, don't change it to a different
19015 : typedef variant. */;
19016 547392 : else if (CP_INTEGRAL_TYPE_P (underlying_type))
19017 : {
19018 547323 : copy_type_enum (enumtype, underlying_type);
19019 547323 : ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
19020 : }
19021 69 : else if (dependent_type_p (underlying_type))
19022 56 : ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
19023 : else
19024 : {
19025 13 : error ("underlying type %qT of %qT must be an integral type",
19026 : underlying_type, enumtype);
19027 13 : copy_type_enum (enumtype, integer_type_node);
19028 13 : ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
19029 : }
19030 : }
19031 :
19032 : /* If into a template class, the returned enum is always the first
19033 : declaration (opaque or not) seen. This way all the references to
19034 : this type will be to the same declaration. The following ones are used
19035 : only to check for definition errors. */
19036 2305174 : if (prevtype && processing_template_decl)
19037 : return prevtype;
19038 : else
19039 2305081 : return enumtype;
19040 : }
19041 :
19042 : /* Returns true if TYPE is an enum that uses an enumerator name for
19043 : linkage purposes at namespace scope. The term is defined in [dcl.enum]/12
19044 : for all enums, not just those at namespace scope, but for backward ABI
19045 : compatibility we want to treat those not at namespace scope the old way
19046 : and e.g. mangle the class scope ones based on their position within the
19047 : class rather than the first enumerator. */
19048 :
19049 : bool
19050 399055871 : enum_with_enumerator_for_linkage_p (tree type)
19051 : {
19052 399055871 : return (cxx_dialect >= cxx20
19053 394434601 : && UNSCOPED_ENUM_P (type)
19054 19551730 : && TYPE_ANON_P (type)
19055 2930105 : && TYPE_VALUES (type)
19056 400856342 : && TYPE_NAMESPACE_SCOPE_P (type));
19057 : }
19058 :
19059 : /* After processing and defining all the values of an enumeration type,
19060 : install their decls in the enumeration type.
19061 : ENUMTYPE is the type object. */
19062 :
19063 : void
19064 2204023 : finish_enum_value_list (tree enumtype)
19065 : {
19066 2204023 : tree values;
19067 2204023 : tree underlying_type;
19068 2204023 : tree decl;
19069 2204023 : tree value;
19070 2204023 : tree minnode, maxnode;
19071 2204023 : tree t;
19072 :
19073 2204023 : ENUM_BEING_DEFINED_P (enumtype) = 0;
19074 :
19075 2204023 : bool fixed_underlying_type_p
19076 2204023 : = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
19077 :
19078 : /* We built up the VALUES in reverse order. */
19079 2204023 : TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
19080 :
19081 : /* For an enum defined in a template, just set the type of the values;
19082 : all further processing is postponed until the template is
19083 : instantiated. We need to set the type so that tsubst of a CONST_DECL
19084 : works. */
19085 2204023 : if (processing_template_decl)
19086 : {
19087 437666 : for (values = TYPE_VALUES (enumtype);
19088 782338 : values;
19089 437666 : values = TREE_CHAIN (values))
19090 437666 : TREE_TYPE (TREE_VALUE (values)) = enumtype;
19091 : return;
19092 : }
19093 :
19094 : /* Determine the minimum and maximum values of the enumerators. */
19095 1859351 : if (TYPE_VALUES (enumtype))
19096 : {
19097 : minnode = maxnode = NULL_TREE;
19098 :
19099 11221448 : for (values = TYPE_VALUES (enumtype);
19100 13045431 : values;
19101 11221448 : values = TREE_CHAIN (values))
19102 : {
19103 11221448 : decl = TREE_VALUE (values);
19104 :
19105 : /* [dcl.enum]: Following the closing brace of an enum-specifier,
19106 : each enumerator has the type of its enumeration. Prior to the
19107 : closing brace, the type of each enumerator is the type of its
19108 : initializing value. */
19109 11221448 : TREE_TYPE (decl) = enumtype;
19110 :
19111 : /* Update the minimum and maximum values, if appropriate. */
19112 11221448 : value = DECL_INITIAL (decl);
19113 11221448 : if (!value || TREE_CODE (value) != INTEGER_CST)
19114 7 : value = integer_zero_node;
19115 : /* Figure out what the minimum and maximum values of the
19116 : enumerators are. */
19117 11221448 : if (!minnode)
19118 : minnode = maxnode = value;
19119 9397465 : else if (tree_int_cst_lt (maxnode, value))
19120 : maxnode = value;
19121 1471456 : else if (tree_int_cst_lt (value, minnode))
19122 165692 : minnode = value;
19123 : }
19124 : }
19125 : else
19126 : /* [dcl.enum]
19127 :
19128 : If the enumerator-list is empty, the underlying type is as if
19129 : the enumeration had a single enumerator with value 0. */
19130 35368 : minnode = maxnode = integer_zero_node;
19131 :
19132 1859351 : if (!fixed_underlying_type_p)
19133 : {
19134 : /* Compute the number of bits require to represent all values of the
19135 : enumeration. We must do this before the type of MINNODE and
19136 : MAXNODE are transformed, since tree_int_cst_min_precision relies
19137 : on the TREE_TYPE of the value it is passed. */
19138 1406000 : signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
19139 1406000 : int lowprec = tree_int_cst_min_precision (minnode, sgn);
19140 1406000 : int highprec = tree_int_cst_min_precision (maxnode, sgn);
19141 1406000 : int precision = MAX (lowprec, highprec);
19142 1406000 : unsigned int itk;
19143 1406000 : bool use_short_enum;
19144 :
19145 : /* Determine the underlying type of the enumeration.
19146 :
19147 : [dcl.enum]
19148 :
19149 : The underlying type of an enumeration is an integral type that
19150 : can represent all the enumerator values defined in the
19151 : enumeration. It is implementation-defined which integral type is
19152 : used as the underlying type for an enumeration except that the
19153 : underlying type shall not be larger than int unless the value of
19154 : an enumerator cannot fit in an int or unsigned int.
19155 :
19156 : We use "int" or an "unsigned int" as the underlying type, even if
19157 : a smaller integral type would work, unless the user has
19158 : explicitly requested that we use the smallest possible type. The
19159 : user can request that for all enumerations with a command line
19160 : flag, or for just one enumeration with an attribute. */
19161 :
19162 2812000 : use_short_enum = flag_short_enums
19163 1406000 : || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
19164 :
19165 : /* If the precision of the type was specified with an attribute and it
19166 : was too small, give an error. Otherwise, use it. */
19167 1406000 : if (TYPE_PRECISION (enumtype))
19168 : {
19169 11 : if (precision > TYPE_PRECISION (enumtype))
19170 0 : error ("specified mode too small for enumerated values");
19171 : else
19172 : {
19173 11 : use_short_enum = true;
19174 11 : precision = TYPE_PRECISION (enumtype);
19175 : }
19176 : }
19177 :
19178 2732722 : for (itk = (use_short_enum ? itk_char : itk_int);
19179 2732722 : itk != itk_none;
19180 : itk++)
19181 : {
19182 2732719 : underlying_type = integer_types[itk];
19183 2732719 : if (underlying_type != NULL_TREE
19184 2732701 : && TYPE_PRECISION (underlying_type) >= precision
19185 5463359 : && TYPE_SIGN (underlying_type) == sgn)
19186 : break;
19187 : }
19188 1406000 : if (itk == itk_none)
19189 : {
19190 : /* DR 377
19191 :
19192 : IF no integral type can represent all the enumerator values, the
19193 : enumeration is ill-formed. */
19194 3 : error ("no integral type can represent all of the enumerator values "
19195 : "for %qT", enumtype);
19196 3 : precision = TYPE_PRECISION (long_long_integer_type_node);
19197 3 : underlying_type = integer_types[itk_unsigned_long_long];
19198 : }
19199 :
19200 : /* [dcl.enum]
19201 :
19202 : The value of sizeof() applied to an enumeration type, an object
19203 : of an enumeration type, or an enumerator, is the value of sizeof()
19204 : applied to the underlying type. */
19205 1406000 : copy_type_enum (enumtype, underlying_type);
19206 :
19207 : /* Compute the minimum and maximum values for the type.
19208 :
19209 : [dcl.enum]
19210 :
19211 : For an enumeration where emin is the smallest enumerator and emax
19212 : is the largest, the values of the enumeration are the values of the
19213 : underlying type in the range bmin to bmax, where bmin and bmax are,
19214 : respectively, the smallest and largest values of the smallest bit-
19215 : field that can store emin and emax. */
19216 :
19217 : /* The middle-end currently assumes that types with TYPE_PRECISION
19218 : narrower than their underlying type are suitably zero or sign
19219 : extended to fill their mode. Similarly, it assumes that the front
19220 : end assures that a value of a particular type must be within
19221 : TYPE_MIN_VALUE and TYPE_MAX_VALUE.
19222 :
19223 : We used to set these fields based on bmin and bmax, but that led
19224 : to invalid assumptions like optimizing away bounds checking. So
19225 : now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
19226 : TYPE_MAX_VALUE to the values for the mode above and only restrict
19227 : the ENUM_UNDERLYING_TYPE for the benefit of diagnostics. */
19228 1406000 : ENUM_UNDERLYING_TYPE (enumtype)
19229 1406000 : = build_distinct_type_copy (underlying_type);
19230 1406000 : TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
19231 1406000 : set_min_and_max_values_for_integral_type
19232 1406000 : (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
19233 :
19234 : /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE. */
19235 1406000 : if (flag_strict_enums)
19236 38 : set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
19237 :
19238 1406000 : if (use_short_enum)
19239 : {
19240 122 : TYPE_PACKED (enumtype) = use_short_enum;
19241 122 : fixup_attribute_variants (enumtype);
19242 : }
19243 : }
19244 : else
19245 453351 : underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
19246 :
19247 : /* If the enum is exported, mark the consts too. */
19248 1859351 : bool export_p = (UNSCOPED_ENUM_P (enumtype)
19249 1480479 : && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
19250 1859934 : && at_namespace_scope_p ());
19251 :
19252 : /* Convert each of the enumerators to the type of the underlying
19253 : type of the enumeration. */
19254 13080799 : for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
19255 : {
19256 11221448 : decl = TREE_VALUE (values);
19257 11221448 : iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
19258 11221448 : if (fixed_underlying_type_p)
19259 : /* If the enumeration type has a fixed underlying type, we
19260 : already checked all of the enumerator values. */
19261 3856470 : value = DECL_INITIAL (decl);
19262 : else
19263 7364978 : value = perform_implicit_conversion (underlying_type,
19264 7364978 : DECL_INITIAL (decl),
19265 : tf_warning_or_error);
19266 11221448 : if (!value)
19267 3 : value = integer_zero_node;
19268 : /* Do not clobber shared ints. But do share identical enumerators. */
19269 11221448 : value = fold_convert (enumtype, value);
19270 :
19271 11221448 : DECL_INITIAL (decl) = value;
19272 11221448 : if (export_p)
19273 3570 : DECL_MODULE_EXPORT_P (decl) = true;
19274 11221448 : }
19275 :
19276 : /* Fix up all variant types of this enum type. */
19277 3718731 : for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
19278 1859380 : TYPE_VALUES (t) = TYPE_VALUES (enumtype);
19279 :
19280 1859351 : if (at_class_scope_p ()
19281 993523 : && COMPLETE_TYPE_P (current_class_type)
19282 1859415 : && UNSCOPED_ENUM_P (enumtype))
19283 : {
19284 45 : insert_late_enum_def_bindings (current_class_type, enumtype);
19285 : /* TYPE_FIELDS needs fixup. */
19286 45 : fixup_type_variants (current_class_type);
19287 : }
19288 :
19289 : /* P2115: An unnamed enum uses the name of its first enumerator for
19290 : linkage purposes; reset the type linkage if that is the case. */
19291 1859351 : if (enum_with_enumerator_for_linkage_p (enumtype))
19292 331590 : reset_type_linkage (enumtype);
19293 :
19294 : /* Finish debugging output for this type. */
19295 1859351 : rest_of_type_compilation (enumtype, namespace_bindings_p ());
19296 :
19297 : /* Each enumerator now has the type of its enumeration. Clear the cache
19298 : so that this change in types doesn't confuse us later on. */
19299 1859351 : clear_cv_and_fold_caches ();
19300 : }
19301 :
19302 : /* Finishes the enum type. This is called only the first time an
19303 : enumeration is seen, be it opaque or odinary.
19304 : ENUMTYPE is the type object. */
19305 :
19306 : void
19307 2193216 : finish_enum (tree enumtype)
19308 : {
19309 2193216 : if (processing_template_decl)
19310 : {
19311 344700 : if (at_function_scope_p ())
19312 9208 : add_stmt (build_min (TAG_DEFN, enumtype));
19313 344700 : return;
19314 : }
19315 :
19316 : /* If this is a forward declaration, there should not be any variants,
19317 : though we can get a variant in the middle of an enum-specifier with
19318 : wacky code like 'enum E { e = sizeof(const E*) };' */
19319 3697032 : gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
19320 : && (TYPE_VALUES (enumtype)
19321 : || !TYPE_NEXT_VARIANT (enumtype)));
19322 : }
19323 :
19324 : /* Build and install a CONST_DECL for an enumeration constant of the
19325 : enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
19326 : Apply ATTRIBUTES if available. LOC is the location of NAME.
19327 : Assignment of sequential values by default is handled here. */
19328 :
19329 : tree
19330 11659088 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
19331 : location_t loc)
19332 : {
19333 11659088 : tree decl;
19334 11659088 : tree context;
19335 11659088 : tree type;
19336 :
19337 : /* scalar_constant_value will pull out this expression, so make sure
19338 : it's folded as appropriate.
19339 :
19340 : Creating a TARGET_EXPR in a template breaks when substituting, and
19341 : here we would create it for instance when using a class prvalue with
19342 : a user-defined conversion function. So don't use such a tree. We
19343 : instantiate VALUE here to get errors about bad enumerators even in
19344 : a template that does not get instantiated. */
19345 11659088 : if (processing_template_decl)
19346 437666 : value = maybe_fold_non_dependent_expr (value);
19347 :
19348 : /* If the VALUE was erroneous, pretend it wasn't there; that will
19349 : result in the enum being assigned the next value in sequence. */
19350 11659088 : if (value == error_mark_node)
19351 : value = NULL_TREE;
19352 :
19353 : /* Remove no-op casts from the value. */
19354 11659050 : if (value)
19355 8715780 : STRIP_TYPE_NOPS (value);
19356 :
19357 11659088 : if (! processing_template_decl)
19358 : {
19359 : /* Validate and default VALUE. */
19360 11221422 : if (value != NULL_TREE)
19361 : {
19362 5000132 : if (!ENUM_UNDERLYING_TYPE (enumtype))
19363 : {
19364 2605384 : tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
19365 : value, true);
19366 2605384 : if (tmp_value)
19367 5000132 : value = tmp_value;
19368 : }
19369 2394748 : else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
19370 : (TREE_TYPE (value)))
19371 39 : value = perform_implicit_conversion_flags
19372 39 : (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
19373 : LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
19374 :
19375 5000132 : if (value == error_mark_node)
19376 : value = NULL_TREE;
19377 :
19378 5000111 : if (value != NULL_TREE)
19379 : {
19380 5000111 : if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
19381 : (TREE_TYPE (value)))
19382 : {
19383 17 : error_at (cp_expr_loc_or_input_loc (value),
19384 : "enumerator value for %qD must have integral or "
19385 : "unscoped enumeration type", name);
19386 17 : value = NULL_TREE;
19387 : }
19388 : else
19389 : {
19390 5000094 : value = cxx_constant_value (value);
19391 :
19392 5000094 : if (TREE_CODE (value) != INTEGER_CST)
19393 : {
19394 47 : error ("enumerator value for %qD is not an integer "
19395 : "constant", name);
19396 47 : value = NULL_TREE;
19397 : }
19398 : }
19399 : }
19400 : }
19401 :
19402 : /* Default based on previous value. */
19403 64 : if (value == NULL_TREE)
19404 : {
19405 6221375 : if (TYPE_VALUES (enumtype))
19406 : {
19407 5687028 : tree prev_value;
19408 :
19409 : /* C++03 7.2/4: If no initializer is specified for the first
19410 : enumerator, the type is an unspecified integral
19411 : type. Otherwise the type is the same as the type of the
19412 : initializing value of the preceding enumerator unless the
19413 : incremented value is not representable in that type, in
19414 : which case the type is an unspecified integral type
19415 : sufficient to contain the incremented value. */
19416 5687028 : prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
19417 5687028 : if (TREE_CODE (prev_value) != INTEGER_CST)
19418 2 : value = error_mark_node;
19419 : else
19420 : {
19421 5687026 : wi::overflow_type overflowed;
19422 5687026 : tree type = TREE_TYPE (prev_value);
19423 5687026 : signop sgn = TYPE_SIGN (type);
19424 5687026 : widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
19425 5687026 : &overflowed);
19426 5687026 : if (!overflowed)
19427 : {
19428 5687026 : bool pos = !wi::neg_p (wi, sgn);
19429 5687026 : if (!wi::fits_to_tree_p (wi, type))
19430 : {
19431 : unsigned int itk;
19432 53 : for (itk = itk_int; itk != itk_none; itk++)
19433 : {
19434 53 : type = integer_types[itk];
19435 53 : if (type != NULL_TREE
19436 53 : && (pos || !TYPE_UNSIGNED (type))
19437 106 : && wi::fits_to_tree_p (wi, type))
19438 : break;
19439 : }
19440 17 : if (type && cxx_dialect < cxx11
19441 6 : && itk > itk_unsigned_long)
19442 3 : pedwarn (input_location, OPT_Wlong_long,
19443 : pos ? G_("\
19444 : incremented enumerator value is too large for %<unsigned long%>") : G_("\
19445 : incremented enumerator value is too large for %<long%>"));
19446 : }
19447 5687026 : if (type == NULL_TREE)
19448 0 : overflowed = wi::OVF_UNKNOWN;
19449 : else
19450 5687026 : value = wide_int_to_tree (type, wi);
19451 : }
19452 :
19453 5687026 : if (overflowed)
19454 : {
19455 0 : error ("overflow in enumeration values at %qD", name);
19456 0 : value = error_mark_node;
19457 : }
19458 5687026 : }
19459 : }
19460 : else
19461 534347 : value = integer_zero_node;
19462 : }
19463 :
19464 : /* Remove no-op casts from the value. */
19465 11221422 : STRIP_TYPE_NOPS (value);
19466 :
19467 : /* If the underlying type of the enum is fixed, check whether
19468 : the enumerator values fits in the underlying type. If it
19469 : does not fit, the program is ill-formed [C++0x dcl.enum]. */
19470 11221422 : if (ENUM_UNDERLYING_TYPE (enumtype)
19471 : && value
19472 11221422 : && TREE_CODE (value) == INTEGER_CST)
19473 : {
19474 3856442 : if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
19475 9 : error ("enumerator value %qE is outside the range of underlying "
19476 9 : "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
19477 :
19478 : /* Convert the value to the appropriate type. */
19479 3856442 : value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
19480 : }
19481 : }
19482 :
19483 : /* C++ associates enums with global, function, or class declarations. */
19484 11659088 : context = current_scope ();
19485 :
19486 : /* Build the actual enumeration constant. Note that the enumeration
19487 : constants have the underlying type of the enum (if it is fixed)
19488 : or the type of their initializer (if the underlying type of the
19489 : enum is not fixed):
19490 :
19491 : [ C++0x dcl.enum ]
19492 :
19493 : If the underlying type is fixed, the type of each enumerator
19494 : prior to the closing brace is the underlying type; if the
19495 : initializing value of an enumerator cannot be represented by
19496 : the underlying type, the program is ill-formed. If the
19497 : underlying type is not fixed, the type of each enumerator is
19498 : the type of its initializing value.
19499 :
19500 : If the underlying type is not fixed, it will be computed by
19501 : finish_enum and we will reset the type of this enumerator. Of
19502 : course, if we're processing a template, there may be no value. */
19503 11659088 : type = value ? TREE_TYPE (value) : NULL_TREE;
19504 :
19505 11659088 : decl = build_decl (loc, CONST_DECL, name, type);
19506 :
19507 11659088 : DECL_CONTEXT (decl) = enumtype;
19508 11659088 : TREE_CONSTANT (decl) = 1;
19509 11659088 : TREE_READONLY (decl) = 1;
19510 11659088 : DECL_INITIAL (decl) = value;
19511 :
19512 11659088 : if (attributes)
19513 124196 : cplus_decl_attributes (&decl, attributes, 0);
19514 :
19515 11659088 : if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
19516 : {
19517 : /* In something like `struct S { enum E { i = 7 }; };' we put `i'
19518 : on the TYPE_FIELDS list for `S'. (That's so that you can say
19519 : things like `S::i' later.) */
19520 :
19521 : /* The enumerator may be getting declared outside of its enclosing
19522 : class, like so:
19523 :
19524 : class S { public: enum E : int; }; enum S::E : int { i = 7; };
19525 :
19526 : For which case we need to make sure that the access of `S::i'
19527 : matches the access of `S::E'. */
19528 2031476 : auto cas = make_temp_override (current_access_specifier);
19529 2031476 : set_current_access_from_decl (TYPE_NAME (enumtype));
19530 2031476 : finish_member_declaration (decl);
19531 2031476 : }
19532 : else
19533 9627612 : pushdecl (decl);
19534 :
19535 : /* Add this enumeration constant to the list for this type. */
19536 11659088 : TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
19537 :
19538 11659088 : return decl;
19539 : }
19540 :
19541 : /* Look for an enumerator with the given NAME within the enumeration
19542 : type ENUMTYPE. This routine is used primarily for qualified name
19543 : lookup into an enumerator in C++0x, e.g.,
19544 :
19545 : enum class Color { Red, Green, Blue };
19546 :
19547 : Color color = Color::Red;
19548 :
19549 : Returns the value corresponding to the enumerator, or
19550 : NULL_TREE if no such enumerator was found. */
19551 : tree
19552 27186123 : lookup_enumerator (tree enumtype, tree name)
19553 : {
19554 27186123 : tree e;
19555 27186123 : gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
19556 :
19557 27186123 : e = purpose_member (name, TYPE_VALUES (enumtype));
19558 54372149 : return e? TREE_VALUE (e) : NULL_TREE;
19559 : }
19560 :
19561 : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL. */
19562 :
19563 : tree
19564 0 : cxx_simulate_enum_decl (location_t loc, const char *name,
19565 : vec<string_int_pair> *values)
19566 : {
19567 0 : location_t saved_loc = input_location;
19568 0 : input_location = loc;
19569 :
19570 0 : tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
19571 : NULL_TREE, false, NULL);
19572 0 : if (!OPAQUE_ENUM_P (enumtype))
19573 : {
19574 0 : auto_diagnostic_group d;
19575 0 : error_at (loc, "multiple definition of %q#T", enumtype);
19576 0 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
19577 : "previous definition here");
19578 0 : return enumtype;
19579 0 : }
19580 0 : SET_OPAQUE_ENUM_P (enumtype, false);
19581 0 : DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
19582 :
19583 0 : for (const string_int_pair &value : values)
19584 0 : build_enumerator (get_identifier (value.first),
19585 0 : build_int_cst (integer_type_node, value.second),
19586 : enumtype, NULL_TREE, loc);
19587 :
19588 0 : finish_enum_value_list (enumtype);
19589 0 : finish_enum (enumtype);
19590 :
19591 0 : input_location = saved_loc;
19592 0 : return enumtype;
19593 : }
19594 :
19595 : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL. */
19596 :
19597 : tree
19598 0 : cxx_simulate_record_decl (location_t loc, const char *name,
19599 : array_slice<const tree> fields)
19600 : {
19601 0 : iloc_sentinel ils (loc);
19602 :
19603 0 : tree ident = get_identifier (name);
19604 0 : tree type = xref_tag (/*tag_code=*/record_type, ident);
19605 0 : if (type != error_mark_node
19606 0 : && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
19607 : {
19608 0 : error ("redefinition of %q#T", type);
19609 0 : type = error_mark_node;
19610 : }
19611 0 : if (type == error_mark_node)
19612 0 : return lhd_simulate_record_decl (loc, name, fields);
19613 :
19614 0 : xref_basetypes (type, NULL_TREE);
19615 0 : type = begin_class_definition (type);
19616 0 : if (type == error_mark_node)
19617 0 : return lhd_simulate_record_decl (loc, name, fields);
19618 :
19619 0 : for (tree field : fields)
19620 0 : finish_member_declaration (field);
19621 :
19622 0 : type = finish_struct (type, NULL_TREE);
19623 :
19624 0 : tree decl = build_decl (loc, TYPE_DECL, ident, type);
19625 0 : set_underlying_type (decl);
19626 0 : lang_hooks.decls.pushdecl (decl);
19627 :
19628 0 : return type;
19629 0 : }
19630 :
19631 : /* We're defining DECL. Make sure that its type is OK. */
19632 :
19633 : static void
19634 159098223 : check_function_type (tree decl, tree current_function_parms)
19635 : {
19636 159098223 : tree fntype = TREE_TYPE (decl);
19637 159098223 : tree return_type = complete_type (TREE_TYPE (fntype));
19638 :
19639 : /* In a function definition, arg types must be complete. */
19640 159098223 : require_complete_types_for_parms (current_function_parms);
19641 :
19642 159098223 : if (dependent_type_p (return_type)
19643 159098223 : || type_uses_auto (return_type))
19644 50169319 : return;
19645 108928904 : if (!COMPLETE_OR_VOID_TYPE_P (return_type))
19646 : {
19647 12 : tree args = TYPE_ARG_TYPES (fntype);
19648 :
19649 12 : error ("return type %q#T is incomplete", return_type);
19650 :
19651 : /* Make it return void instead. */
19652 12 : if (TREE_CODE (fntype) == METHOD_TYPE)
19653 3 : fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
19654 : void_type_node,
19655 3 : TREE_CHAIN (args));
19656 : else
19657 18 : fntype = build_function_type (void_type_node, args,
19658 9 : TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
19659 12 : fntype = (cp_build_type_attribute_variant
19660 12 : (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
19661 12 : fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
19662 12 : TREE_TYPE (decl) = fntype;
19663 : }
19664 : else
19665 : {
19666 108928892 : abstract_virtuals_error (decl, TREE_TYPE (fntype));
19667 108928892 : maybe_warn_parm_abi (TREE_TYPE (fntype),
19668 108928892 : DECL_SOURCE_LOCATION (decl));
19669 : }
19670 : }
19671 :
19672 : /* True iff FN is an implicitly-defined default constructor. */
19673 :
19674 : static bool
19675 16689749 : implicit_default_ctor_p (tree fn)
19676 : {
19677 16689749 : return (DECL_CONSTRUCTOR_P (fn)
19678 16689749 : && !user_provided_p (fn)
19679 18542894 : && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
19680 : }
19681 :
19682 : /* Clobber the contents of *this to let the back end know that the object
19683 : storage is dead when we enter the constructor or leave the destructor. */
19684 :
19685 : static tree
19686 1437142 : build_clobber_this (clobber_kind kind)
19687 : {
19688 : /* Clobbering an empty base is pointless, and harmful if its one byte
19689 : TYPE_SIZE overlays real data. */
19690 1437142 : if (is_empty_class (current_class_type))
19691 0 : return void_node;
19692 :
19693 : /* If we have virtual bases, clobber the whole object, but only if we're in
19694 : charge. If we don't have virtual bases, clobber the as-base type so we
19695 : don't mess with tail padding. */
19696 1437142 : bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
19697 :
19698 1437142 : tree ctype = current_class_type;
19699 1437142 : if (!vbases)
19700 1430005 : ctype = CLASSTYPE_AS_BASE (ctype);
19701 :
19702 1437142 : tree clobber = build_clobber (ctype, kind);
19703 :
19704 1437142 : tree thisref = current_class_ref;
19705 1437142 : if (ctype != current_class_type)
19706 : {
19707 168672 : thisref = build_nop (build_reference_type (ctype), current_class_ptr);
19708 168672 : thisref = convert_from_reference (thisref);
19709 : }
19710 :
19711 1437142 : tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
19712 1437142 : if (kind == CLOBBER_OBJECT_BEGIN)
19713 0 : TREE_SET_CODE (exprstmt, INIT_EXPR);
19714 1437142 : if (vbases)
19715 7137 : exprstmt = build_if_in_charge (exprstmt);
19716 :
19717 : return exprstmt;
19718 : }
19719 :
19720 : /* Create the FUNCTION_DECL for a function definition.
19721 : DECLSPECS and DECLARATOR are the parts of the declaration;
19722 : they describe the function's name and the type it returns,
19723 : but twisted together in a fashion that parallels the syntax of C.
19724 :
19725 : FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
19726 : DECLARATOR is really the DECL for the function we are about to
19727 : process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
19728 : indicating that the function is an inline defined in-class.
19729 :
19730 : This function creates a binding context for the function body
19731 : as well as setting up the FUNCTION_DECL in current_function_decl.
19732 :
19733 : For C++, we must first check whether that datum makes any sense.
19734 : For example, "class A local_a(1,2);" means that variable local_a
19735 : is an aggregate of type A, which should have a constructor
19736 : applied to it with the argument list [1, 2].
19737 :
19738 : On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
19739 : or may be a BLOCK if the function has been defined previously
19740 : in this translation unit. On exit, DECL_INITIAL (decl1) will be
19741 : error_mark_node if the function has never been defined, or
19742 : a BLOCK if the function has been defined somewhere. */
19743 :
19744 : bool
19745 159098259 : start_preparsed_function (tree decl1, tree attrs, int flags)
19746 : {
19747 159098259 : tree ctype = NULL_TREE;
19748 159098259 : bool doing_friend = false;
19749 :
19750 : /* Sanity check. */
19751 159098259 : gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
19752 159098259 : gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
19753 :
19754 159098259 : tree fntype = TREE_TYPE (decl1);
19755 159098259 : if (DECL_CLASS_SCOPE_P (decl1))
19756 117269556 : ctype = DECL_CONTEXT (decl1);
19757 : else
19758 : {
19759 83657406 : ctype = DECL_FRIEND_CONTEXT (decl1);
19760 :
19761 41828702 : if (ctype)
19762 159098259 : doing_friend = true;
19763 : }
19764 :
19765 : /* Adjust for #pragma target/optimize if this is an artificial function that
19766 : (probably) didn't go through grokfndecl. We particularly don't want this
19767 : for deferred instantiations, which should match their template. */
19768 159098259 : if (DECL_ARTIFICIAL (decl1))
19769 3586032 : decl_attributes (&decl1, NULL_TREE, 0);
19770 :
19771 159098259 : if (DECL_DECLARED_INLINE_P (decl1)
19772 159098259 : && lookup_attribute ("noinline", attrs))
19773 : {
19774 0 : auto_urlify_attributes sentinel;
19775 0 : warning_at (DECL_SOURCE_LOCATION (decl1), 0,
19776 : "inline function %qD given attribute %qs", decl1, "noinline");
19777 0 : }
19778 :
19779 : /* Handle gnu_inline attribute. */
19780 159098259 : if (GNU_INLINE_P (decl1))
19781 : {
19782 1885653 : DECL_EXTERNAL (decl1) = 1;
19783 1885653 : DECL_NOT_REALLY_EXTERN (decl1) = 0;
19784 1885653 : DECL_INTERFACE_KNOWN (decl1) = 1;
19785 1885653 : DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
19786 : }
19787 :
19788 159098259 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
19789 : /* This is a constructor, we must ensure that any default args
19790 : introduced by this definition are propagated to the clones
19791 : now. The clones are used directly in overload resolution. */
19792 19949641 : adjust_clone_args (decl1);
19793 :
19794 : /* Sometimes we don't notice that a function is a static member, and
19795 : build a METHOD_TYPE for it. Fix that up now. */
19796 159098259 : gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
19797 : && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
19798 :
19799 : /* Set up current_class_type, and enter the scope of the class, if
19800 : appropriate. */
19801 159098259 : if (ctype)
19802 121692932 : push_nested_class (ctype);
19803 :
19804 : /* Now that we have entered the scope of the class, we must restore
19805 : the bindings for any template parameters surrounding DECL1, if it
19806 : is an inline member template. (Order is important; consider the
19807 : case where a template parameter has the same name as a field of
19808 : the class.) It is not until after this point that
19809 : PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly. */
19810 159098259 : if (flags & SF_INCLASS_INLINE)
19811 81596154 : maybe_begin_member_template_processing (decl1);
19812 :
19813 : /* Effective C++ rule 15. */
19814 159098259 : if (warn_ecpp
19815 123 : && DECL_ASSIGNMENT_OPERATOR_P (decl1)
19816 30 : && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
19817 159098289 : && VOID_TYPE_P (TREE_TYPE (fntype)))
19818 0 : warning (OPT_Weffc__,
19819 : "%<operator=%> should return a reference to %<*this%>");
19820 :
19821 : /* Make the init_value nonzero so pushdecl knows this is not tentative.
19822 : error_mark_node is replaced below (in poplevel) with the BLOCK. */
19823 159098259 : if (!DECL_INITIAL (decl1))
19824 34406795 : DECL_INITIAL (decl1) = error_mark_node;
19825 :
19826 : /* This function exists in static storage.
19827 : (This does not mean `static' in the C sense!) */
19828 159098259 : TREE_STATIC (decl1) = 1;
19829 :
19830 : /* We must call push_template_decl after current_class_type is set
19831 : up. (If we are processing inline definitions after exiting a
19832 : class scope, current_class_type will be NULL_TREE until set above
19833 : by push_nested_class.) */
19834 159098259 : if (processing_template_decl)
19835 : {
19836 93446641 : tree newdecl1 = push_template_decl (decl1, doing_friend);
19837 93446641 : if (newdecl1 == error_mark_node)
19838 : {
19839 36 : if (ctype)
19840 9 : pop_nested_class ();
19841 36 : return false;
19842 : }
19843 93446605 : decl1 = newdecl1;
19844 : }
19845 :
19846 : /* Make sure the parameter and return types are reasonable. When
19847 : you declare a function, these types can be incomplete, but they
19848 : must be complete when you define the function. */
19849 159098223 : check_function_type (decl1, DECL_ARGUMENTS (decl1));
19850 :
19851 : /* Build the return declaration for the function. */
19852 159098223 : tree restype = TREE_TYPE (fntype);
19853 :
19854 159098223 : if (DECL_RESULT (decl1) == NULL_TREE)
19855 : {
19856 : /* In a template instantiation, copy the return type location. When
19857 : parsing, the location will be set in grokdeclarator. */
19858 65418861 : location_t loc = input_location;
19859 65418861 : if (DECL_TEMPLATE_INSTANTIATION (decl1))
19860 : {
19861 30978691 : tree tmpl = template_for_substitution (decl1);
19862 30978691 : if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
19863 30102616 : loc = DECL_SOURCE_LOCATION (res);
19864 : }
19865 :
19866 65418861 : tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
19867 65418861 : DECL_ARTIFICIAL (resdecl) = 1;
19868 65418861 : DECL_IGNORED_P (resdecl) = 1;
19869 65418861 : DECL_RESULT (decl1) = resdecl;
19870 :
19871 65418861 : cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
19872 : }
19873 :
19874 : /* Record the decl so that the function name is defined.
19875 : If we already have a decl for this name, and it is a FUNCTION_DECL,
19876 : use the old decl. */
19877 159098223 : if (!processing_template_decl && !(flags & SF_PRE_PARSED))
19878 : {
19879 : /* A specialization is not used to guide overload resolution. */
19880 19730040 : if (!DECL_FUNCTION_MEMBER_P (decl1)
19881 19710767 : && !(DECL_USE_TEMPLATE (decl1) &&
19882 12670 : PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
19883 : {
19884 9443230 : tree olddecl = pushdecl (decl1);
19885 :
19886 9443230 : if (olddecl == error_mark_node)
19887 : /* If something went wrong when registering the declaration,
19888 : use DECL1; we have to have a FUNCTION_DECL to use when
19889 : parsing the body of the function. */
19890 : ;
19891 : else
19892 : {
19893 : /* Otherwise, OLDDECL is either a previous declaration
19894 : of the same function or DECL1 itself. */
19895 :
19896 9443017 : if (warn_missing_declarations
19897 21 : && olddecl == decl1
19898 15 : && !DECL_MAIN_P (decl1)
19899 15 : && TREE_PUBLIC (decl1)
19900 9443029 : && !DECL_DECLARED_INLINE_P (decl1))
19901 : {
19902 9 : tree context;
19903 :
19904 : /* Check whether DECL1 is in an anonymous
19905 : namespace. */
19906 9 : for (context = DECL_CONTEXT (decl1);
19907 18 : context;
19908 9 : context = DECL_CONTEXT (context))
19909 : {
19910 12 : if (TREE_CODE (context) == NAMESPACE_DECL
19911 12 : && DECL_NAME (context) == NULL_TREE)
19912 : break;
19913 : }
19914 :
19915 9 : if (context == NULL)
19916 6 : warning_at (DECL_SOURCE_LOCATION (decl1),
19917 6 : OPT_Wmissing_declarations,
19918 : "no previous declaration for %qD", decl1);
19919 : }
19920 :
19921 9443017 : decl1 = olddecl;
19922 : }
19923 : }
19924 : else
19925 : {
19926 : /* We need to set the DECL_CONTEXT. */
19927 811637 : if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
19928 0 : DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
19929 : }
19930 10254867 : fntype = TREE_TYPE (decl1);
19931 10254867 : restype = TREE_TYPE (fntype);
19932 :
19933 : /* If #pragma weak applies, mark the decl appropriately now.
19934 : The pragma only applies to global functions. Because
19935 : determining whether or not the #pragma applies involves
19936 : computing the mangled name for the declaration, we cannot
19937 : apply the pragma until after we have merged this declaration
19938 : with any previous declarations; if the original declaration
19939 : has a linkage specification, that specification applies to
19940 : the definition as well, and may affect the mangled name. */
19941 10254867 : if (DECL_FILE_SCOPE_P (decl1))
19942 2509569 : maybe_apply_pragma_weak (decl1);
19943 : }
19944 :
19945 : /* We are now in the scope of the function being defined. */
19946 159098223 : current_function_decl = decl1;
19947 :
19948 : /* Save the parm names or decls from this function's declarator
19949 : where store_parm_decls will find them. */
19950 159098223 : tree current_function_parms = DECL_ARGUMENTS (decl1);
19951 :
19952 : /* Let the user know we're compiling this function. */
19953 159098223 : announce_function (decl1);
19954 :
19955 159098223 : gcc_assert (DECL_INITIAL (decl1));
19956 :
19957 : /* This function may already have been parsed, in which case just
19958 : return; our caller will skip over the body without parsing. */
19959 159098223 : if (DECL_INITIAL (decl1) != error_mark_node)
19960 : return true;
19961 :
19962 : /* Initialize RTL machinery. We cannot do this until
19963 : CURRENT_FUNCTION_DECL and DECL_RESULT are set up. We do this
19964 : even when processing a template; this is how we get
19965 : CFUN set up, and our per-function variables initialized.
19966 : FIXME factor out the non-RTL stuff. */
19967 159098223 : cp_binding_level *bl = current_binding_level;
19968 159098223 : allocate_struct_function (decl1, processing_template_decl);
19969 :
19970 : /* Initialize the language data structures. Whenever we start
19971 : a new function, we destroy temporaries in the usual way. */
19972 159098223 : cfun->language = ggc_cleared_alloc<language_function> ();
19973 159098223 : current_stmt_tree ()->stmts_are_full_exprs_p = 1;
19974 159098223 : current_binding_level = bl;
19975 :
19976 : /* If we are (erroneously) defining a function that we have already
19977 : defined before, wipe out what we knew before. */
19978 159098223 : gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
19979 159098223 : FNDECL_USED_AUTO (decl1) = false;
19980 159098223 : DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
19981 :
19982 159098223 : if (!processing_template_decl && type_uses_auto (restype))
19983 : {
19984 887590 : FNDECL_USED_AUTO (decl1) = true;
19985 887590 : DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
19986 : }
19987 :
19988 : /* Start the statement-tree, start the tree now. */
19989 159098223 : DECL_SAVED_TREE (decl1) = push_stmt_list ();
19990 :
19991 159098223 : if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
19992 : {
19993 : /* We know that this was set up by `grokclassfn'. We do not
19994 : wait until `store_parm_decls', since evil parse errors may
19995 : never get us to that point. Here we keep the consistency
19996 : between `current_class_type' and `current_class_ptr'. */
19997 103495081 : tree t = DECL_ARGUMENTS (decl1);
19998 :
19999 103495081 : gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
20000 103495081 : gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
20001 :
20002 103495081 : cp_function_chain->x_current_class_ref
20003 103495081 : = cp_build_fold_indirect_ref (t);
20004 : /* Set this second to avoid shortcut in cp_build_indirect_ref. */
20005 103495081 : cp_function_chain->x_current_class_ptr = t;
20006 :
20007 : /* Constructors and destructors need to know whether they're "in
20008 : charge" of initializing virtual base classes. */
20009 103495081 : t = DECL_CHAIN (t);
20010 103495081 : if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
20011 : {
20012 16767 : current_in_charge_parm = t;
20013 16767 : t = DECL_CHAIN (t);
20014 : }
20015 103495081 : if (DECL_HAS_VTT_PARM_P (decl1))
20016 : {
20017 33593 : gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
20018 33593 : current_vtt_parm = t;
20019 : }
20020 : }
20021 :
20022 287201688 : bool honor_interface = (!DECL_TEMPLOID_INSTANTIATION (decl1)
20023 : /* Implicitly-defined methods (like the
20024 : destructor for a class in which no destructor
20025 : is explicitly declared) must not be defined
20026 : until their definition is needed. So, we
20027 : ignore interface specifications for
20028 : compiler-generated functions. */
20029 193680903 : && !DECL_ARTIFICIAL (decl1));
20030 159098223 : struct c_fileinfo *finfo
20031 159098223 : = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
20032 :
20033 159098223 : if (processing_template_decl)
20034 : /* Don't mess with interface flags. */;
20035 65651618 : else if (DECL_INTERFACE_KNOWN (decl1))
20036 : {
20037 19227710 : tree ctx = decl_function_context (decl1);
20038 :
20039 19227710 : if (DECL_NOT_REALLY_EXTERN (decl1))
20040 15331717 : DECL_EXTERNAL (decl1) = 0;
20041 :
20042 19227710 : if (ctx != NULL_TREE && vague_linkage_p (ctx))
20043 : /* This is a function in a local class in an extern inline
20044 : or template function. */
20045 2902774 : comdat_linkage (decl1);
20046 : }
20047 : /* If this function belongs to an interface, it is public.
20048 : If it belongs to someone else's interface, it is also external.
20049 : This only affects inlines and template instantiations. */
20050 46423908 : else if (!finfo->interface_unknown && honor_interface)
20051 : {
20052 106 : if (DECL_DECLARED_INLINE_P (decl1)
20053 106 : || DECL_TEMPLOID_INSTANTIATION (decl1))
20054 : {
20055 82 : DECL_EXTERNAL (decl1)
20056 164 : = (finfo->interface_only
20057 82 : || (DECL_DECLARED_INLINE_P (decl1)
20058 36 : && ! flag_implement_inlines
20059 0 : && !DECL_VINDEX (decl1)));
20060 :
20061 : /* For WIN32 we also want to put these in linkonce sections. */
20062 82 : maybe_make_one_only (decl1);
20063 : }
20064 : else
20065 24 : DECL_EXTERNAL (decl1) = 0;
20066 106 : DECL_INTERFACE_KNOWN (decl1) = 1;
20067 : /* If this function is in an interface implemented in this file,
20068 : make sure that the back end knows to emit this function
20069 : here. */
20070 106 : if (!DECL_EXTERNAL (decl1))
20071 60 : mark_needed (decl1);
20072 : }
20073 46423802 : else if (finfo->interface_unknown && finfo->interface_only
20074 0 : && honor_interface)
20075 : {
20076 : /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
20077 : interface, we will have both finfo->interface_unknown and
20078 : finfo->interface_only set. In that case, we don't want to
20079 : use the normal heuristics because someone will supply a
20080 : #pragma implementation elsewhere, and deducing it here would
20081 : produce a conflict. */
20082 0 : comdat_linkage (decl1);
20083 0 : DECL_EXTERNAL (decl1) = 0;
20084 0 : DECL_INTERFACE_KNOWN (decl1) = 1;
20085 0 : DECL_DEFER_OUTPUT (decl1) = 1;
20086 : }
20087 : else
20088 : {
20089 : /* This is a definition, not a reference.
20090 : So clear DECL_EXTERNAL, unless this is a GNU extern inline. */
20091 46423802 : if (!GNU_INLINE_P (decl1))
20092 46423799 : DECL_EXTERNAL (decl1) = 0;
20093 :
20094 46423802 : if ((DECL_DECLARED_INLINE_P (decl1)
20095 1861027 : || DECL_TEMPLOID_INSTANTIATION (decl1))
20096 48046170 : && ! DECL_INTERFACE_KNOWN (decl1))
20097 46185143 : DECL_DEFER_OUTPUT (decl1) = 1;
20098 : else
20099 238659 : DECL_INTERFACE_KNOWN (decl1) = 1;
20100 : }
20101 :
20102 : /* Determine the ELF visibility attribute for the function. We must not
20103 : do this before calling "pushdecl", as we must allow "duplicate_decls"
20104 : to merge any attributes appropriately. We also need to wait until
20105 : linkage is set. */
20106 159098223 : if (!DECL_CLONED_FUNCTION_P (decl1))
20107 143288525 : determine_visibility (decl1);
20108 :
20109 159098223 : if (!processing_template_decl)
20110 65651618 : maybe_instantiate_noexcept (decl1);
20111 :
20112 159098223 : begin_scope (sk_function_parms, decl1);
20113 :
20114 159098223 : ++function_depth;
20115 :
20116 159098223 : start_fname_decls ();
20117 :
20118 159098223 : store_parm_decls (current_function_parms);
20119 :
20120 159098223 : start_function_contracts (decl1);
20121 :
20122 159098223 : if (!processing_template_decl
20123 65651618 : && flag_lifetime_dse > 1
20124 131293924 : && DECL_CONSTRUCTOR_P (decl1)
20125 : /* Clobbering an empty base is harmful if it overlays real data. */
20126 18522284 : && !is_empty_class (current_class_type)
20127 : /* We can't clobber safely for an implicitly-defined default constructor
20128 : because part of the initialization might happen before we enter the
20129 : constructor, via AGGR_INIT_ZERO_FIRST (c++/68006). */
20130 16689115 : && !implicit_default_ctor_p (decl1)
20131 174664980 : && !lookup_attribute ("clobber *this",
20132 15566757 : DECL_ATTRIBUTES (current_class_ptr)))
20133 15557477 : DECL_ATTRIBUTES (current_class_ptr)
20134 31114954 : = tree_cons (get_identifier ("clobber *this"), NULL_TREE,
20135 15557477 : DECL_ATTRIBUTES (current_class_ptr));
20136 :
20137 159098223 : if (!processing_template_decl
20138 131303236 : && DECL_CONSTRUCTOR_P (decl1)
20139 18523526 : && sanitize_flags_p (SANITIZE_VPTR)
20140 1902 : && !DECL_CLONED_FUNCTION_P (decl1)
20141 159098857 : && !implicit_default_ctor_p (decl1))
20142 480 : cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
20143 :
20144 159098223 : if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
20145 159097654 : start_lambda_scope (decl1);
20146 :
20147 : return true;
20148 : }
20149 :
20150 :
20151 : /* Like start_preparsed_function, except that instead of a
20152 : FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
20153 :
20154 : Returns true on success. If the DECLARATOR is not suitable
20155 : for a function, we return false, which tells the parser to
20156 : skip the entire function. */
20157 :
20158 : bool
20159 38348510 : start_function (cp_decl_specifier_seq *declspecs,
20160 : const cp_declarator *declarator,
20161 : tree attrs)
20162 : {
20163 38348510 : tree decl1;
20164 :
20165 38348510 : decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
20166 38348510 : invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
20167 38348510 : if (decl1 == error_mark_node)
20168 : return false;
20169 :
20170 38348145 : if (DECL_MAIN_P (decl1))
20171 : /* main must return int. grokfndecl should have corrected it
20172 : (and issued a diagnostic) if the user got it wrong. */
20173 33376 : gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
20174 : integer_type_node));
20175 :
20176 38348145 : return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
20177 : }
20178 :
20179 : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
20180 : FN. */
20181 :
20182 : bool
20183 304395404 : use_eh_spec_block (tree fn)
20184 : {
20185 302463048 : return (flag_exceptions && flag_enforce_eh_specs
20186 302463048 : && !processing_template_decl
20187 : /* We insert the EH_SPEC_BLOCK only in the original
20188 : function; then, it is copied automatically to the
20189 : clones. */
20190 114449258 : && !DECL_CLONED_FUNCTION_P (fn)
20191 : /* Implicitly-generated constructors and destructors have
20192 : exception specifications. However, those specifications
20193 : are the union of the possible exceptions specified by the
20194 : constructors/destructors for bases and members, so no
20195 : unallowed exception will ever reach this function. By
20196 : not creating the EH_SPEC_BLOCK we save a little memory,
20197 : and we avoid spurious warnings about unreachable
20198 : code. */
20199 98680557 : && !DECL_DEFAULTED_FN (fn)
20200 400642485 : && !type_throw_all_p (TREE_TYPE (fn)));
20201 : }
20202 :
20203 : /* Helper function to push ARGS into the current lexical scope. DECL
20204 : is the function declaration. NONPARMS is used to handle enum
20205 : constants. */
20206 :
20207 : void
20208 154477063 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
20209 : {
20210 : /* If we're doing semantic analysis, then we'll call pushdecl
20211 : for each of these. We must do them in reverse order so that
20212 : they end in the correct forward order. */
20213 154477063 : args = nreverse (args);
20214 :
20215 154477063 : tree next;
20216 473998849 : for (tree parm = args; parm; parm = next)
20217 : {
20218 319521786 : next = DECL_CHAIN (parm);
20219 319521786 : if (TREE_CODE (parm) == PARM_DECL)
20220 319521786 : pushdecl (parm);
20221 0 : else if (nonparms)
20222 : {
20223 : /* If we find an enum constant or a type tag, put it aside for
20224 : the moment. */
20225 0 : TREE_CHAIN (parm) = NULL_TREE;
20226 0 : *nonparms = chainon (*nonparms, parm);
20227 : }
20228 : }
20229 :
20230 : /* Get the decls in their original chain order and record in the
20231 : function. This is all and only the PARM_DECLs that were
20232 : pushed into scope by the loop above. */
20233 154477063 : DECL_ARGUMENTS (decl) = get_local_decls ();
20234 154477063 : }
20235 :
20236 : /* Store the parameter declarations into the current function declaration.
20237 : This is called after parsing the parameter declarations, before
20238 : digesting the body of the function.
20239 :
20240 : Also install to binding contour return value identifier, if any. */
20241 :
20242 : static void
20243 159098223 : store_parm_decls (tree current_function_parms)
20244 : {
20245 159098223 : tree fndecl = current_function_decl;
20246 :
20247 : /* This is a chain of any other decls that came in among the parm
20248 : declarations. If a parm is declared with enum {foo, bar} x;
20249 : then CONST_DECLs for foo and bar are put here. */
20250 159098223 : tree nonparms = NULL_TREE;
20251 :
20252 159098223 : if (current_function_parms)
20253 : {
20254 : /* This case is when the function was defined with an ANSI prototype.
20255 : The parms already have decls, so we need not do anything here
20256 : except record them as in effect
20257 : and complain if any redundant old-style parm decls were written. */
20258 :
20259 151121718 : tree specparms = current_function_parms;
20260 :
20261 : /* Must clear this because it might contain TYPE_DECLs declared
20262 : at class level. */
20263 151121718 : current_binding_level->names = NULL;
20264 :
20265 151121718 : do_push_parm_decls (fndecl, specparms, &nonparms);
20266 : }
20267 : else
20268 7976505 : DECL_ARGUMENTS (fndecl) = NULL_TREE;
20269 :
20270 : /* Now store the final chain of decls for the arguments
20271 : as the decl-chain of the current lexical scope.
20272 : Put the enumerators in as well, at the front so that
20273 : DECL_ARGUMENTS is not modified. */
20274 159098223 : current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
20275 :
20276 159098223 : if (use_eh_spec_block (current_function_decl))
20277 24428519 : current_eh_spec_block = begin_eh_spec_block ();
20278 159098223 : }
20279 :
20280 :
20281 : /* Mark CDTOR's implicit THIS argument for returning, if required by
20282 : the ABI.. Return the decl for THIS, if it is to be returned, and
20283 : NULL otherwise. */
20284 :
20285 : tree
20286 136048512 : maybe_prepare_return_this (tree cdtor)
20287 : {
20288 136048512 : if (targetm.cxx.cdtor_returns_this ())
20289 0 : if (tree val = DECL_ARGUMENTS (cdtor))
20290 : {
20291 0 : suppress_warning (val, OPT_Wuse_after_free);
20292 0 : return val;
20293 : }
20294 :
20295 : return NULL_TREE;
20296 : }
20297 :
20298 : /* Set the return value of the [cd]tor if the ABI wants that. */
20299 :
20300 : void
20301 8046229 : maybe_return_this ()
20302 : {
20303 8046229 : if (tree val = maybe_prepare_return_this (current_function_decl))
20304 : {
20305 : /* Return the address of the object. */
20306 0 : val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
20307 0 : val = build2 (MODIFY_EXPR, TREE_TYPE (val),
20308 0 : DECL_RESULT (current_function_decl), val);
20309 0 : tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
20310 0 : add_stmt (exprstmt);
20311 : }
20312 8046229 : }
20313 :
20314 : /* Do all the processing for the beginning of a destructor; set up the
20315 : vtable pointers and cleanups for bases and members. */
20316 :
20317 : static void
20318 1575735 : begin_destructor_body (void)
20319 : {
20320 1575735 : tree compound_stmt;
20321 :
20322 : /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
20323 : issued an error message. We still want to try to process the
20324 : body of the function, but initialize_vtbl_ptrs will crash if
20325 : TYPE_BINFO is NULL. */
20326 1575735 : if (COMPLETE_TYPE_P (current_class_type))
20327 : {
20328 1575735 : compound_stmt = begin_compound_stmt (0);
20329 : /* Make all virtual function table pointers in non-virtual base
20330 : classes point to CURRENT_CLASS_TYPE's virtual function
20331 : tables. */
20332 1575735 : initialize_vtbl_ptrs (current_class_ptr);
20333 1575735 : finish_compound_stmt (compound_stmt);
20334 :
20335 1575735 : if (flag_lifetime_dse
20336 : /* Clobbering an empty base is harmful if it overlays real data. */
20337 1575735 : && !is_empty_class (current_class_type))
20338 : {
20339 1437205 : if (sanitize_flags_p (SANITIZE_VPTR)
20340 235 : && (flag_sanitize_recover & SANITIZE_VPTR) == 0
20341 1437268 : && TYPE_CONTAINS_VPTR_P (current_class_type))
20342 : {
20343 63 : tree binfo = TYPE_BINFO (current_class_type);
20344 63 : tree ref
20345 63 : = cp_build_fold_indirect_ref (current_class_ptr);
20346 :
20347 63 : tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
20348 63 : tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
20349 63 : tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
20350 : NOP_EXPR, vtbl,
20351 : tf_warning_or_error);
20352 : /* If the vptr is shared with some virtual nearly empty base,
20353 : don't clear it if not in charge, the dtor of the virtual
20354 : nearly empty base will do that later. */
20355 63 : if (CLASSTYPE_VBASECLASSES (current_class_type))
20356 : {
20357 : tree c = current_class_type;
20358 66 : while (CLASSTYPE_PRIMARY_BINFO (c))
20359 : {
20360 63 : if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
20361 : {
20362 36 : stmt = convert_to_void (stmt, ICV_STATEMENT,
20363 : tf_warning_or_error);
20364 36 : stmt = build_if_in_charge (stmt);
20365 36 : break;
20366 : }
20367 27 : c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
20368 : }
20369 : }
20370 63 : finish_decl_cleanup (NULL_TREE, stmt);
20371 : }
20372 : else
20373 1437142 : finish_decl_cleanup (NULL_TREE,
20374 : build_clobber_this (CLOBBER_OBJECT_END));
20375 : }
20376 :
20377 : /* And insert cleanups for our bases and members so that they
20378 : will be properly destroyed if we throw. */
20379 1575735 : push_base_cleanups ();
20380 : }
20381 1575735 : }
20382 :
20383 : /* Do the necessary processing for the beginning of a function body, which
20384 : in this case includes member-initializers, but not the catch clauses of
20385 : a function-try-block. Currently, this means opening a binding level
20386 : for the member-initializers (in a ctor), member cleanups (in a dtor),
20387 : and capture proxies (in a lambda operator()). */
20388 :
20389 : tree
20390 125226584 : begin_function_body (void)
20391 : {
20392 257691494 : if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
20393 : return NULL_TREE;
20394 :
20395 24433029 : if (processing_template_decl)
20396 : /* Do nothing now. */;
20397 : else
20398 : /* Always keep the BLOCK node associated with the outermost pair of
20399 : curly braces of a function. These are needed for correct
20400 : operation of dwarfout.c. */
20401 8150411 : keep_next_level (true);
20402 :
20403 24433029 : tree stmt = begin_compound_stmt (BCS_FN_BODY);
20404 24433029 : current_binding_level->artificial = 1;
20405 :
20406 24433029 : if (processing_template_decl)
20407 : /* Do nothing now. */;
20408 16300822 : else if (DECL_DESTRUCTOR_P (current_function_decl))
20409 1575735 : begin_destructor_body ();
20410 :
20411 : return stmt;
20412 : }
20413 :
20414 : /* Do the processing for the end of a function body. Currently, this means
20415 : closing out the cleanups for fully-constructed bases and members, and in
20416 : the case of the destructor, deleting the object if desired. Again, this
20417 : is only meaningful for [cd]tors, since they are the only functions where
20418 : there is a significant distinction between the main body and any
20419 : function catch clauses. Handling, say, main() return semantics here
20420 : would be wrong, as flowing off the end of a function catch clause for
20421 : main() would also need to return 0. */
20422 :
20423 : void
20424 125226560 : finish_function_body (tree compstmt)
20425 : {
20426 125226560 : if (compstmt == NULL_TREE)
20427 : return;
20428 :
20429 : /* Close the block. */
20430 24433029 : finish_compound_stmt (compstmt);
20431 :
20432 24433029 : if (processing_template_decl)
20433 : /* Do nothing now. */;
20434 8150411 : else if (DECL_CONSTRUCTOR_P (current_function_decl)
20435 8150411 : || DECL_DESTRUCTOR_P (current_function_decl))
20436 7745771 : maybe_return_this ();
20437 : }
20438 :
20439 : /* Given a function, returns the BLOCK corresponding to the outermost level
20440 : of curly braces, skipping the artificial block created for constructor
20441 : initializers. */
20442 :
20443 : tree
20444 336330 : outer_curly_brace_block (tree fndecl)
20445 : {
20446 336330 : tree block = DECL_INITIAL (fndecl);
20447 336330 : if (BLOCK_OUTER_CURLY_BRACE_P (block))
20448 : return block;
20449 1041 : block = BLOCK_SUBBLOCKS (block);
20450 1041 : if (BLOCK_OUTER_CURLY_BRACE_P (block))
20451 : return block;
20452 0 : block = BLOCK_SUBBLOCKS (block);
20453 0 : gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
20454 : return block;
20455 : }
20456 :
20457 : /* If FNDECL is a class's key method, add the class to the list of
20458 : keyed classes that should be emitted. */
20459 :
20460 : static void
20461 159102174 : record_key_method_defined (tree fndecl)
20462 : {
20463 214709243 : if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
20464 103570765 : && DECL_VIRTUAL_P (fndecl)
20465 161823883 : && !processing_template_decl)
20466 : {
20467 1389786 : tree fnclass = DECL_CONTEXT (fndecl);
20468 1389786 : if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
20469 : {
20470 19655 : tree classdecl = TYPE_NAME (fnclass);
20471 : /* Classes attached to a named module are already handled. */
20472 19655 : if (!DECL_LANG_SPECIFIC (classdecl)
20473 19964 : || !DECL_MODULE_ATTACH_P (classdecl))
20474 19610 : vec_safe_push (keyed_classes, fnclass);
20475 : }
20476 : }
20477 159102174 : }
20478 :
20479 : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
20480 : of "return *this;" immediately before its location, using FNDECL's
20481 : first statement (if any) to give the indentation, if appropriate. */
20482 :
20483 : static void
20484 18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
20485 : {
20486 18 : location_t indent = UNKNOWN_LOCATION;
20487 18 : tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
20488 18 : if (stmts)
20489 9 : indent = EXPR_LOCATION (stmts);
20490 18 : richloc->add_fixit_insert_formatted ("return *this;",
20491 : richloc->get_loc (),
20492 : indent);
20493 18 : }
20494 :
20495 : /* Finish up a function declaration and compile that function
20496 : all the way to assembler language output. The free the storage
20497 : for the function definition. INLINE_P is TRUE if we just
20498 : finished processing the body of an in-class inline function
20499 : definition. (This processing will have taken place after the
20500 : class definition is complete.) */
20501 :
20502 : tree
20503 159098187 : finish_function (bool inline_p)
20504 : {
20505 159098187 : tree fndecl = current_function_decl;
20506 159098187 : tree fntype, ctype = NULL_TREE;
20507 159098187 : tree resumer = NULL_TREE, destroyer = NULL_TREE;
20508 :
20509 : /* When we get some parse errors, we can end up without a
20510 : current_function_decl, so cope. */
20511 159098187 : if (fndecl == NULL_TREE || fndecl == error_mark_node)
20512 0 : return error_mark_node;
20513 :
20514 159098187 : if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20515 159097618 : finish_lambda_scope ();
20516 :
20517 159098187 : if (c_dialect_objc ())
20518 0 : objc_finish_function ();
20519 :
20520 159098187 : record_key_method_defined (fndecl);
20521 :
20522 159098187 : fntype = TREE_TYPE (fndecl);
20523 :
20524 : /* TREE_READONLY (fndecl) = 1;
20525 : This caused &foo to be of type ptr-to-const-function
20526 : which then got a warning when stored in a ptr-to-function variable. */
20527 :
20528 159098187 : gcc_assert (building_stmt_list_p ());
20529 : /* The current function is being defined, so its DECL_INITIAL should
20530 : be set, and unless there's a multiple definition, it should be
20531 : error_mark_node. */
20532 159098187 : gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
20533 :
20534 159098187 : cp_coroutine_transform *coroutine = nullptr;
20535 159098187 : if (flag_coroutines
20536 156321060 : && !processing_template_decl
20537 63870111 : && DECL_COROUTINE_P (fndecl)
20538 159103089 : && !DECL_RAMP_FN (fndecl))
20539 : {
20540 1690 : gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
20541 : && !DECL_DEFAULTED_FN (fndecl));
20542 1690 : coroutine = new cp_coroutine_transform (fndecl, inline_p);
20543 1690 : if (coroutine && coroutine->cp_valid_coroutine ())
20544 1690 : coroutine->apply_transforms ();
20545 :
20546 : /* We should handle coroutine IFNs in middle end lowering. */
20547 1690 : cfun->coroutine_component = true;
20548 :
20549 : /* Do not try to process the ramp's EH unless outlining succeeded. */
20550 1690 : if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
20551 360 : finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
20552 : (TREE_TYPE (fndecl)),
20553 360 : current_eh_spec_block);
20554 :
20555 : /* If outlining succeeded, then add contracts handling if needed. */
20556 1690 : if (coroutine->cp_valid_coroutine ())
20557 1606 : maybe_apply_function_contracts (fndecl);
20558 : }
20559 : else
20560 : /* For a cloned function, we've already got all the code we need;
20561 : there's no need to add any extra bits. */
20562 159096497 : if (!DECL_CLONED_FUNCTION_P (fndecl))
20563 : {
20564 : /* Make it so that `main' always returns 0 by default. */
20565 143286799 : if (DECL_MAIN_FREESTANDING_P (current_function_decl)
20566 143320160 : && !TREE_THIS_VOLATILE (current_function_decl))
20567 33361 : finish_return_stmt (integer_zero_node);
20568 :
20569 143286799 : if (use_eh_spec_block (current_function_decl))
20570 24428156 : finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
20571 : (TREE_TYPE (current_function_decl)),
20572 24428156 : current_eh_spec_block);
20573 :
20574 143286799 : maybe_apply_function_contracts (current_function_decl);
20575 :
20576 : }
20577 :
20578 : /* If we're saving up tree structure, tie off the function now. */
20579 159098187 : DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
20580 :
20581 159098187 : finish_fname_decls ();
20582 :
20583 : /* This must come after expand_function_end because cleanups might
20584 : have declarations (from inline functions) that need to go into
20585 : this function's blocks. */
20586 :
20587 : /* If the current binding level isn't the outermost binding level
20588 : for this function, either there is a bug, or we have experienced
20589 : syntax errors and the statement tree is malformed. */
20590 159098187 : if (current_binding_level->kind != sk_function_parms)
20591 : {
20592 : /* Make sure we have already experienced errors. */
20593 12 : gcc_assert (errorcount);
20594 :
20595 : /* Throw away the broken statement tree and extra binding
20596 : levels. */
20597 12 : DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
20598 :
20599 27 : while (current_binding_level->kind != sk_function_parms)
20600 : {
20601 15 : if (current_binding_level->kind == sk_class)
20602 0 : pop_nested_class ();
20603 : else
20604 15 : poplevel (0, 0, 0);
20605 : }
20606 : }
20607 159098187 : poplevel (1, 0, 1);
20608 :
20609 : /* Statements should always be full-expressions at the outermost set
20610 : of curly braces for a function. */
20611 159098187 : gcc_assert (stmts_are_full_exprs_p ());
20612 :
20613 : /* If there are no return statements in a function with auto return type,
20614 : the return type is void. But if the declared type is something like
20615 : auto*, this is an error. */
20616 65651582 : if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
20617 159985777 : && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20618 : {
20619 120557 : if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20620 120542 : && !current_function_returns_value
20621 240894 : && !current_function_returns_null)
20622 : {
20623 : /* We haven't applied return type deduction because we haven't
20624 : seen any return statements. Do that now. */
20625 120337 : tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
20626 120337 : do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
20627 : void_node, node, tf_warning_or_error,
20628 : adc_return_type);
20629 :
20630 120337 : apply_deduced_return_type (fndecl, void_type_node);
20631 120337 : fntype = TREE_TYPE (fndecl);
20632 : }
20633 220 : else if (!current_function_returns_value
20634 6 : && !current_function_returns_null)
20635 : {
20636 6 : auto_diagnostic_group d;
20637 12 : error ("no return statements in function returning %qT",
20638 6 : DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
20639 6 : inform (input_location, "only plain %<auto%> return type can be "
20640 : "deduced to %<void%>");
20641 6 : }
20642 : }
20643 :
20644 159098187 : if (FNDECL_USED_AUTO (fndecl)
20645 159098187 : && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20646 887370 : if (location_t fcloc = failed_completion_location (fndecl))
20647 : {
20648 6 : auto_diagnostic_group adg;
20649 6 : if (warning (OPT_Wsfinae_incomplete_,
20650 : "defining %qD, which previously failed to be deduced "
20651 : "in a SFINAE context", fndecl)
20652 6 : && warn_sfinae_incomplete == 1)
20653 6 : inform (fcloc, "here. Use %qs for a diagnostic at that point",
20654 : "-Wsfinae-incomplete=2");
20655 6 : }
20656 :
20657 : /* Remember that we were in class scope. */
20658 159098187 : if (current_class_name)
20659 121692920 : ctype = current_class_type;
20660 :
20661 159098187 : if (DECL_DELETED_FN (fndecl))
20662 : {
20663 90 : DECL_INITIAL (fndecl) = error_mark_node;
20664 90 : DECL_SAVED_TREE (fndecl) = NULL_TREE;
20665 90 : goto cleanup;
20666 : }
20667 :
20668 159098097 : if (flag_openmp)
20669 323313 : if (tree attr = lookup_attribute ("omp declare variant base",
20670 323313 : DECL_ATTRIBUTES (fndecl)))
20671 265 : omp_declare_variant_finalize (fndecl, attr);
20672 :
20673 : /* Complain if there's just no return statement. */
20674 159098097 : if ((warn_return_type
20675 46999 : || (cxx_dialect >= cxx14
20676 38992 : && DECL_DECLARED_CONSTEXPR_P (fndecl)))
20677 159068310 : && !VOID_TYPE_P (TREE_TYPE (fntype))
20678 99928610 : && !dependent_type_p (TREE_TYPE (fntype))
20679 50651899 : && !current_function_returns_value && !current_function_returns_null
20680 : /* Don't complain if we abort or throw. */
20681 30878 : && !current_function_returns_abnormally
20682 : /* Don't complain if there's an infinite loop. */
20683 945 : && !current_function_infinite_loop
20684 : /* Don't complain if we are declared noreturn. */
20685 877 : && !TREE_THIS_VOLATILE (fndecl)
20686 871 : && !DECL_NAME (DECL_RESULT (fndecl))
20687 871 : && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
20688 : /* Structor return values (if any) are set by the compiler. */
20689 1254 : && !DECL_CONSTRUCTOR_P (fndecl)
20690 627 : && !DECL_DESTRUCTOR_P (fndecl)
20691 159098724 : && targetm.warn_func_return (fndecl))
20692 : {
20693 621 : gcc_rich_location richloc (input_location);
20694 : /* Potentially add a "return *this;" fix-it hint for
20695 : assignment operators. */
20696 621 : if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
20697 : {
20698 39 : tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
20699 39 : if (TREE_CODE (valtype) == REFERENCE_TYPE
20700 32 : && current_class_ref
20701 26 : && same_type_ignoring_top_level_qualifiers_p
20702 26 : (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
20703 71 : && global_dc->option_enabled_p (OPT_Wreturn_type))
20704 18 : add_return_star_this_fixit (&richloc, fndecl);
20705 : }
20706 621 : if (cxx_dialect >= cxx14
20707 621 : && DECL_DECLARED_CONSTEXPR_P (fndecl))
20708 2 : error_at (&richloc, "no return statement in %<constexpr%> function "
20709 : "returning non-void");
20710 619 : else if (warning_at (&richloc, OPT_Wreturn_type,
20711 : "no return statement in function returning "
20712 : "non-void"))
20713 169 : suppress_warning (fndecl, OPT_Wreturn_type);
20714 621 : }
20715 :
20716 : /* Lambda closure members are implicitly constexpr if possible. */
20717 159098097 : if (cxx_dialect >= cxx17
20718 275126581 : && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
20719 1746408 : DECL_DECLARED_CONSTEXPR_P (fndecl)
20720 1746408 : = ((processing_template_decl
20721 545393 : || is_valid_constexpr_fn (fndecl, /*complain*/false))
20722 3491926 : && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
20723 :
20724 : /* Invoke the pre-genericize plugin before we start munging things. */
20725 159098097 : if (!processing_template_decl)
20726 65651492 : invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
20727 :
20728 : /* Fold away non-ODR usages of constants so that we don't need to
20729 : try and stream them in modules if they're internal. */
20730 159098097 : if (!processing_template_decl)
20731 65651492 : cp_fold_function_non_odr_use (fndecl);
20732 :
20733 : /* Save constexpr function body before it gets munged by
20734 : the NRV transformation. */
20735 159098097 : maybe_save_constexpr_fundef (fndecl);
20736 :
20737 : /* Perform delayed folding before NRV transformation. */
20738 159098097 : if (!processing_template_decl
20739 131302984 : && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
20740 223792732 : && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20741 64694196 : cp_fold_function (fndecl);
20742 :
20743 : /* Set up the named return value optimization, if we can. Candidate
20744 : variables are selected in check_return_expr. */
20745 159098097 : if (tree r = current_function_return_value)
20746 : {
20747 41812308 : if (r != error_mark_node)
20748 216222 : finalize_nrv (fndecl, r);
20749 41812308 : current_function_return_value = NULL_TREE;
20750 : }
20751 :
20752 : /* Must mark the RESULT_DECL as being in this function. */
20753 159098097 : DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
20754 :
20755 : /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
20756 : to the FUNCTION_DECL node itself. */
20757 159098097 : BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
20758 :
20759 : /* Store the end of the function, so that we get good line number
20760 : info for the epilogue. */
20761 159098097 : cfun->function_end_locus = input_location;
20762 :
20763 : /* Complain about parameters that are only set, but never otherwise used. */
20764 159098097 : if (warn_unused_but_set_parameter
20765 995006 : && !processing_template_decl
20766 507759 : && errorcount == unused_but_set_errorcount
20767 159605853 : && !DECL_CLONED_FUNCTION_P (fndecl))
20768 : {
20769 396204 : tree decl;
20770 :
20771 396204 : for (decl = DECL_ARGUMENTS (fndecl);
20772 1055915 : decl;
20773 659711 : decl = DECL_CHAIN (decl))
20774 659711 : if (TREE_USED (decl)
20775 547208 : && TREE_CODE (decl) == PARM_DECL
20776 547208 : && !DECL_READ_P (decl)
20777 225 : && DECL_NAME (decl)
20778 225 : && !DECL_ARTIFICIAL (decl)
20779 225 : && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
20780 225 : && !DECL_IN_SYSTEM_HEADER (decl)
20781 225 : && TREE_TYPE (decl) != error_mark_node
20782 225 : && !TYPE_REF_P (TREE_TYPE (decl))
20783 659936 : && (!CLASS_TYPE_P (TREE_TYPE (decl))
20784 0 : || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
20785 225 : warning_at (DECL_SOURCE_LOCATION (decl),
20786 225 : OPT_Wunused_but_set_parameter_,
20787 : "parameter %qD set but not used", decl);
20788 396204 : unused_but_set_errorcount = errorcount;
20789 : }
20790 :
20791 : /* Complain about locally defined typedefs that are not used in this
20792 : function. */
20793 159098097 : maybe_warn_unused_local_typedefs ();
20794 :
20795 : /* Possibly warn about unused parameters. */
20796 159098097 : if (warn_unused_parameter
20797 725624 : && !processing_template_decl
20798 159448460 : && !DECL_CLONED_FUNCTION_P (fndecl))
20799 268661 : do_warn_unused_parameter (fndecl);
20800 :
20801 : /* Genericize before inlining. */
20802 159098097 : if (!processing_template_decl
20803 131302984 : && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
20804 223791002 : && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20805 64692466 : cp_genericize (fndecl);
20806 :
20807 : /* If this function can't throw any exceptions, remember that. */
20808 159098097 : if (!processing_template_decl
20809 65651492 : && !cp_function_chain->can_throw
20810 50272793 : && !flag_non_call_exceptions
20811 50264044 : && !decl_replaceable_p (fndecl,
20812 50264044 : opt_for_fn (fndecl, flag_semantic_interposition))
20813 209120665 : && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
20814 50020079 : TREE_NOTHROW (fndecl) = 1;
20815 :
20816 159098187 : cleanup:
20817 :
20818 : /* We're leaving the context of this function, so zap cfun. It's still in
20819 : DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation. */
20820 159098187 : set_cfun (NULL);
20821 159098187 : current_function_decl = NULL;
20822 :
20823 : /* If this is an in-class inline definition, we may have to pop the
20824 : bindings for the template parameters that we added in
20825 : maybe_begin_member_template_processing when start_function was
20826 : called. */
20827 159098187 : if (inline_p)
20828 81596582 : maybe_end_member_template_processing ();
20829 :
20830 : /* Leave the scope of the class. */
20831 159098187 : if (ctype)
20832 121692920 : pop_nested_class ();
20833 :
20834 159098187 : --function_depth;
20835 :
20836 : /* Clean up. */
20837 159098187 : invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
20838 :
20839 : /* Build outlined functions for coroutines and contracts. */
20840 :
20841 159098187 : if (coroutine)
20842 : {
20843 : /* Emit the resumer and destroyer functions now, providing that we have
20844 : not encountered some fatal error. */
20845 1690 : if (coroutine->cp_valid_coroutine ())
20846 : {
20847 1606 : coroutine->finish_transforms ();
20848 1606 : resumer = coroutine->get_resumer ();
20849 1606 : destroyer = coroutine->get_destroyer ();
20850 1606 : expand_or_defer_fn (resumer);
20851 1606 : expand_or_defer_fn (destroyer);
20852 : }
20853 1690 : delete coroutine;
20854 : }
20855 :
20856 : /* If we have used outlined contracts checking functions, build and emit
20857 : them here. */
20858 159098187 : finish_function_outlined_contracts (fndecl);
20859 :
20860 159098187 : return fndecl;
20861 : }
20862 :
20863 : /* Create the FUNCTION_DECL for a function definition.
20864 : DECLSPECS and DECLARATOR are the parts of the declaration;
20865 : they describe the return type and the name of the function,
20866 : but twisted together in a fashion that parallels the syntax of C.
20867 :
20868 : This function creates a binding context for the function body
20869 : as well as setting up the FUNCTION_DECL in current_function_decl.
20870 :
20871 : Returns a FUNCTION_DECL on success.
20872 :
20873 : If the DECLARATOR is not suitable for a function (it defines a datum
20874 : instead), we return 0, which tells yyparse to report a parse error.
20875 :
20876 : May return void_type_node indicating that this method is actually
20877 : a friend. See grokfield for more details.
20878 :
20879 : Came here with a `.pushlevel' .
20880 :
20881 : DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
20882 : CHANGES TO CODE IN `grokfield'. */
20883 :
20884 : tree
20885 81796606 : grokmethod (cp_decl_specifier_seq *declspecs,
20886 : const cp_declarator *declarator, tree attrlist)
20887 : {
20888 81796606 : tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
20889 81796606 : &attrlist);
20890 :
20891 81796606 : if (fndecl == error_mark_node)
20892 : return error_mark_node;
20893 :
20894 81796502 : if (attrlist)
20895 0 : cplus_decl_attributes (&fndecl, attrlist, 0);
20896 :
20897 : /* Pass friends other than inline friend functions back. */
20898 81796502 : if (fndecl == void_type_node)
20899 : return fndecl;
20900 :
20901 81796502 : if (DECL_IN_AGGR_P (fndecl))
20902 : {
20903 0 : if (DECL_CLASS_SCOPE_P (fndecl))
20904 0 : error ("%qD is already defined in class %qT", fndecl,
20905 0 : DECL_CONTEXT (fndecl));
20906 0 : return error_mark_node;
20907 : }
20908 :
20909 81796502 : check_template_shadow (fndecl);
20910 :
20911 : /* p1779 ABI-Isolation makes inline not a default for in-class
20912 : definitions attached to a named module. If the user explicitly
20913 : made it inline, grokdeclarator will already have done the right
20914 : things. */
20915 81796502 : if ((!named_module_attach_p ()
20916 921 : || flag_module_implicit_inline
20917 : /* Lambda's operator function remains inline. */
20918 1806 : || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
20919 : /* If the user explicitly asked for this to be inline, we don't
20920 : need to do more, but more importantly we want to warn if we
20921 : can't inline it. */
20922 81796051 : && !DECL_DECLARED_INLINE_P (fndecl))
20923 : {
20924 46995026 : if (TREE_PUBLIC (fndecl))
20925 45008532 : DECL_COMDAT (fndecl) = 1;
20926 46995026 : DECL_DECLARED_INLINE_P (fndecl) = 1;
20927 : /* It's ok if we can't inline this. */
20928 46995026 : DECL_NO_INLINE_WARNING_P (fndecl) = 1;
20929 : }
20930 :
20931 : /* We process method specializations in finish_struct_1. */
20932 81796502 : if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
20933 : {
20934 : /* Avoid calling decl_spec_seq... until we have to. */
20935 65646741 : bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
20936 65646741 : fndecl = push_template_decl (fndecl, friendp);
20937 65646741 : if (fndecl == error_mark_node)
20938 : return fndecl;
20939 : }
20940 :
20941 81796494 : if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
20942 : {
20943 0 : fndecl = copy_node (fndecl);
20944 0 : TREE_CHAIN (fndecl) = NULL_TREE;
20945 : }
20946 :
20947 81796494 : cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
20948 :
20949 81796494 : DECL_IN_AGGR_P (fndecl) = 1;
20950 81796494 : return fndecl;
20951 : }
20952 :
20953 :
20954 : /* VAR is a VAR_DECL. If its type is incomplete, remember VAR so that
20955 : we can lay it out later, when and if its type becomes complete.
20956 :
20957 : Also handle constexpr variables where the initializer involves
20958 : an unlowered PTRMEM_CST because the class isn't complete yet. */
20959 :
20960 : void
20961 101095166 : maybe_register_incomplete_var (tree var)
20962 : {
20963 101095166 : gcc_assert (VAR_P (var));
20964 :
20965 : /* Keep track of variables with incomplete types. */
20966 44307539 : if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
20967 145400974 : && DECL_EXTERNAL (var))
20968 : {
20969 6471504 : tree inner_type = TREE_TYPE (var);
20970 :
20971 6625497 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
20972 153993 : inner_type = TREE_TYPE (inner_type);
20973 6471504 : inner_type = TYPE_MAIN_VARIANT (inner_type);
20974 :
20975 6617078 : if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
20976 : /* RTTI TD entries are created while defining the type_info. */
20977 6471504 : || (TYPE_LANG_SPECIFIC (inner_type)
20978 2312679 : && TYPE_BEING_DEFINED (inner_type)))
20979 : {
20980 145574 : incomplete_var iv = {var, inner_type};
20981 145574 : vec_safe_push (incomplete_vars, iv);
20982 : }
20983 12351982 : else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
20984 3472618 : && DECL_CLASS_SCOPE_P (var)
20985 1085134 : && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
20986 1085134 : && decl_constant_var_p (var)
20987 7021374 : && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
20988 : {
20989 : /* When the outermost open class is complete we can resolve any
20990 : pointers-to-members. */
20991 20 : tree context = outermost_open_class ();
20992 20 : incomplete_var iv = {var, context};
20993 20 : vec_safe_push (incomplete_vars, iv);
20994 : }
20995 : }
20996 101095166 : }
20997 :
20998 : /* Called when a class type (given by TYPE) is defined. If there are
20999 : any existing VAR_DECLs whose type has been completed by this
21000 : declaration, update them now. */
21001 :
21002 : void
21003 69559716 : complete_vars (tree type)
21004 : {
21005 69559716 : unsigned ix;
21006 69559716 : incomplete_var *iv;
21007 :
21008 70087363 : for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
21009 : {
21010 527647 : if (same_type_p (type, iv->incomplete_type))
21011 : {
21012 144428 : tree var = iv->decl;
21013 144428 : tree type = TREE_TYPE (var);
21014 :
21015 144428 : if (type != error_mark_node
21016 144428 : && (TYPE_MAIN_VARIANT (strip_array_types (type))
21017 144425 : == iv->incomplete_type))
21018 : {
21019 : /* Complete the type of the variable. */
21020 144405 : complete_type (type);
21021 144405 : cp_apply_type_quals_to_decl (cp_type_quals (type), var);
21022 144405 : if (COMPLETE_TYPE_P (type))
21023 144390 : layout_var_decl (var);
21024 : }
21025 :
21026 : /* Remove this entry from the list. */
21027 144428 : incomplete_vars->unordered_remove (ix);
21028 : }
21029 : else
21030 383219 : ix++;
21031 : }
21032 69559716 : }
21033 :
21034 : /* If DECL is of a type which needs a cleanup, build and return an
21035 : expression to perform that cleanup here. Return NULL_TREE if no
21036 : cleanup need be done. DECL can also be a _REF when called from
21037 : split_nonconstant_init_1. */
21038 :
21039 : tree
21040 86600911 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
21041 : {
21042 86600911 : tree type;
21043 86600911 : tree attr;
21044 86600911 : tree cleanup;
21045 :
21046 : /* Assume no cleanup is required. */
21047 86600911 : cleanup = NULL_TREE;
21048 :
21049 86600911 : if (!decl || error_operand_p (decl))
21050 : return cleanup;
21051 :
21052 : /* Handle "__attribute__((cleanup))". We run the cleanup function
21053 : before the destructor since the destructor is what actually
21054 : terminates the lifetime of the object. */
21055 86600911 : if (DECL_P (decl))
21056 86337953 : attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
21057 : else
21058 : attr = NULL_TREE;
21059 86337953 : if (attr)
21060 : {
21061 159 : tree id;
21062 159 : tree fn;
21063 159 : tree arg;
21064 :
21065 : /* Get the name specified by the user for the cleanup function. */
21066 159 : id = TREE_VALUE (TREE_VALUE (attr));
21067 : /* Look up the name to find the cleanup function to call. It is
21068 : important to use lookup_name here because that is what is
21069 : used in c-common.cc:handle_cleanup_attribute when performing
21070 : initial checks on the attribute. Note that those checks
21071 : include ensuring that the function found is not an overloaded
21072 : function, or an object with an overloaded call operator,
21073 : etc.; we can rely on the fact that the function found is an
21074 : ordinary FUNCTION_DECL. */
21075 159 : fn = lookup_name (id);
21076 159 : arg = build_address (decl);
21077 159 : if (!mark_used (decl, complain) && !(complain & tf_error))
21078 0 : return error_mark_node;
21079 159 : cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
21080 159 : if (cleanup == error_mark_node)
21081 : return error_mark_node;
21082 : }
21083 : /* Handle ordinary C++ destructors. */
21084 86600899 : type = TREE_TYPE (decl);
21085 86600899 : if (type_build_dtor_call (type))
21086 : {
21087 6752159 : int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
21088 6752159 : tree addr;
21089 6752159 : tree call;
21090 :
21091 6752159 : if (TREE_CODE (type) == ARRAY_TYPE)
21092 : addr = decl;
21093 : else
21094 6748826 : addr = build_address (decl);
21095 :
21096 6752159 : call = build_delete (input_location, TREE_TYPE (addr), addr,
21097 : sfk_complete_destructor, flags, 0, complain);
21098 6752159 : if (call == error_mark_node)
21099 : cleanup = error_mark_node;
21100 6752114 : else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
21101 : /* Discard the call. */;
21102 4035354 : else if (decl_maybe_constant_destruction (decl, type)
21103 4035515 : && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
21104 161 : cxx_constant_dtor (call, decl);
21105 4035193 : else if (cleanup)
21106 3 : cleanup = cp_build_compound_expr (cleanup, call, complain);
21107 : else
21108 : cleanup = call;
21109 : }
21110 :
21111 : /* build_delete sets the location of the destructor call to the
21112 : current location, even though the destructor is going to be
21113 : called later, at the end of the current scope. This can lead to
21114 : a "jumpy" behavior for users of debuggers when they step around
21115 : the end of the block. So let's unset the location of the
21116 : destructor call instead. */
21117 86600899 : protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
21118 86600899 : if (cleanup && CONVERT_EXPR_P (cleanup))
21119 0 : protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
21120 :
21121 0 : if (cleanup
21122 4035382 : && DECL_P (decl)
21123 4034942 : && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
21124 : /* Treat objects with destructors as used; the destructor may do
21125 : something substantive. */
21126 4034936 : && !mark_used (decl, complain) && !(complain & tf_error))
21127 0 : return error_mark_node;
21128 :
21129 4035382 : if (cleanup && cfun && !processing_template_decl
21130 90178096 : && !expr_noexcept_p (cleanup, tf_none))
21131 5493 : cp_function_chain->throwing_cleanup = true;
21132 :
21133 : return cleanup;
21134 : }
21135 :
21136 :
21137 : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
21138 : FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
21139 : METHOD_TYPE or FUNCTION_TYPE, or pointer to member function. */
21140 :
21141 : tree
21142 5737846 : static_fn_type (tree memfntype)
21143 : {
21144 5737846 : tree fntype;
21145 5737846 : tree args;
21146 :
21147 5737846 : if (TYPE_PTRMEMFUNC_P (memfntype))
21148 20140 : memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
21149 5737846 : if (INDIRECT_TYPE_P (memfntype)
21150 5026964 : || TREE_CODE (memfntype) == FUNCTION_DECL)
21151 5571390 : memfntype = TREE_TYPE (memfntype);
21152 5737846 : if (TREE_CODE (memfntype) == FUNCTION_TYPE)
21153 : return memfntype;
21154 554701 : gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
21155 554701 : args = TYPE_ARG_TYPES (memfntype);
21156 554701 : fntype = cp_build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
21157 554701 : fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
21158 554701 : fntype = (cp_build_type_attribute_variant
21159 554701 : (fntype, TYPE_ATTRIBUTES (memfntype)));
21160 554701 : fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
21161 554701 : return fntype;
21162 : }
21163 :
21164 : /* DECL was originally constructed as a non-static member function,
21165 : but turned out to be static. Update it accordingly. */
21166 :
21167 : void
21168 172602 : revert_static_member_fn (tree decl)
21169 : {
21170 172602 : tree stype = static_fn_type (decl);
21171 172602 : cp_cv_quals quals = type_memfn_quals (stype);
21172 172602 : cp_ref_qualifier rqual = type_memfn_rqual (stype);
21173 :
21174 172602 : if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
21175 9 : stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
21176 :
21177 172602 : TREE_TYPE (decl) = stype;
21178 :
21179 172602 : if (DECL_ARGUMENTS (decl))
21180 172602 : DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
21181 172602 : DECL_STATIC_FUNCTION_P (decl) = 1;
21182 172602 : }
21183 :
21184 : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
21185 : one of the language-independent trees. */
21186 :
21187 : enum cp_tree_node_structure_enum
21188 36714420789 : cp_tree_node_structure (union lang_tree_node * t)
21189 : {
21190 36714420789 : switch (TREE_CODE (&t->generic))
21191 : {
21192 : case ARGUMENT_PACK_SELECT: return TS_CP_ARGUMENT_PACK_SELECT;
21193 151879911 : case BASELINK: return TS_CP_BASELINK;
21194 75832085 : case CONSTRAINT_INFO: return TS_CP_CONSTRAINT_INFO;
21195 11008643 : case DEFERRED_NOEXCEPT: return TS_CP_DEFERRED_NOEXCEPT;
21196 5752820 : case DEFERRED_PARSE: return TS_CP_DEFERRED_PARSE;
21197 1976663912 : case IDENTIFIER_NODE: return TS_CP_IDENTIFIER;
21198 2947977 : case LAMBDA_EXPR: return TS_CP_LAMBDA_EXPR;
21199 260986 : case BINDING_VECTOR: return TS_CP_BINDING_VECTOR;
21200 687485826 : case OVERLOAD: return TS_CP_OVERLOAD;
21201 674 : case PTRMEM_CST: return TS_CP_PTRMEM;
21202 15086623 : case STATIC_ASSERT: return TS_CP_STATIC_ASSERT;
21203 647478021 : case TEMPLATE_DECL: return TS_CP_TEMPLATE_DECL;
21204 1500499119 : case TEMPLATE_INFO: return TS_CP_TEMPLATE_INFO;
21205 658296717 : case TEMPLATE_PARM_INDEX: return TS_CP_TPI;
21206 14713846 : case TRAIT_EXPR: return TS_CP_TRAIT_EXPR;
21207 6 : case TU_LOCAL_ENTITY: return TS_CP_TU_LOCAL_ENTITY;
21208 3553450 : case USERDEF_LITERAL: return TS_CP_USERDEF_LITERAL;
21209 30962960173 : default: return TS_CP_GENERIC;
21210 : }
21211 : }
21212 :
21213 : bool
21214 8960 : cp_missing_noreturn_ok_p (tree decl)
21215 : {
21216 : /* A missing noreturn is ok for the `main' function. */
21217 8960 : return DECL_MAIN_P (decl);
21218 : }
21219 :
21220 : /* Return the decl used to identify the COMDAT group into which DECL should
21221 : be placed. */
21222 :
21223 : tree
21224 121850744 : cxx_comdat_group (tree decl)
21225 : {
21226 : /* Virtual tables, construction virtual tables, and virtual table
21227 : tables all go in a single COMDAT group, named after the primary
21228 : virtual table. */
21229 121850744 : if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
21230 516010 : decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
21231 : /* For all other DECLs, the COMDAT group is the mangled name of the
21232 : declaration itself. */
21233 : else
21234 : {
21235 121334734 : while (DECL_THUNK_P (decl))
21236 : {
21237 : /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
21238 : into the same section as the target function. In that case
21239 : we must return target's name. */
21240 0 : tree target = THUNK_TARGET (decl);
21241 0 : if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
21242 0 : && DECL_SECTION_NAME (target) != NULL
21243 0 : && DECL_ONE_ONLY (target))
21244 : decl = target;
21245 : else
21246 : break;
21247 : }
21248 : /* If a ctor/dtor has already set the comdat group by
21249 : maybe_clone_body, don't override it. */
21250 121334734 : if (SUPPORTS_ONE_ONLY
21251 121334734 : && TREE_CODE (decl) == FUNCTION_DECL
21252 121334734 : && DECL_CLONED_FUNCTION_P (decl))
21253 17769089 : if (tree comdat = DECL_COMDAT_GROUP (decl))
21254 : return comdat;
21255 : }
21256 :
21257 : return decl;
21258 : }
21259 :
21260 : /* Returns the return type for FN as written by the user, which may include
21261 : a placeholder for a deduced return type. */
21262 :
21263 : tree
21264 485912523 : fndecl_declared_return_type (tree fn)
21265 : {
21266 485912523 : fn = STRIP_TEMPLATE (fn);
21267 485912523 : if (FNDECL_USED_AUTO (fn))
21268 117392 : return DECL_SAVED_AUTO_RETURN_TYPE (fn);
21269 :
21270 485795131 : return TREE_TYPE (TREE_TYPE (fn));
21271 : }
21272 :
21273 : /* Returns true iff DECL is a variable or function declared with an auto type
21274 : that has not yet been deduced to a real type. */
21275 :
21276 : bool
21277 935262369 : undeduced_auto_decl (tree decl)
21278 : {
21279 935262369 : if (cxx_dialect < cxx11)
21280 : return false;
21281 932667871 : STRIP_ANY_LOCATION_WRAPPER (decl);
21282 413296287 : return ((VAR_OR_FUNCTION_DECL_P (decl)
21283 92632115 : || TREE_CODE (decl) == TEMPLATE_DECL)
21284 1253555726 : && type_uses_auto (TREE_TYPE (decl)));
21285 : }
21286 :
21287 : /* Complain if DECL has an undeduced return type. */
21288 :
21289 : bool
21290 302805094 : require_deduced_type (tree decl, tsubst_flags_t complain)
21291 : {
21292 302805094 : if (undeduced_auto_decl (decl))
21293 : {
21294 11396 : if (TREE_CODE (decl) == FUNCTION_DECL
21295 11396 : && fndecl_built_in_p (decl, CP_BUILT_IN_SOURCE_LOCATION,
21296 : BUILT_IN_FRONTEND))
21297 : {
21298 : /* Set the return type of __builtin_source_location. */
21299 9495 : tree type = get_source_location_impl_type ();
21300 9495 : if (type == error_mark_node)
21301 : {
21302 33 : inform (input_location, "using %qs", "__builtin_source_location");
21303 33 : return false;
21304 : }
21305 9462 : type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
21306 9462 : type = build_pointer_type (type);
21307 9462 : apply_deduced_return_type (decl, type);
21308 9462 : return true;
21309 : }
21310 :
21311 1901 : if (TREE_CODE (decl) == FUNCTION_DECL
21312 1901 : && fndecl_built_in_p (decl, CP_BUILT_IN_CURRENT_EXCEPTION,
21313 : BUILT_IN_FRONTEND))
21314 : {
21315 : /* Set the return type of __builtin_current_exception. */
21316 1273 : tree name = get_identifier ("exception_ptr");
21317 1273 : tree eptr = lookup_qualified_name (std_node, name);
21318 1273 : tree fld;
21319 1273 : if (TREE_CODE (eptr) != TYPE_DECL
21320 1273 : || !CLASS_TYPE_P (TREE_TYPE (eptr))
21321 1273 : || !COMPLETE_TYPE_P (TREE_TYPE (eptr))
21322 1273 : || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (eptr))))
21323 1273 : || DECL_ARTIFICIAL (fld)
21324 1273 : || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE
21325 1273 : || next_aggregate_field (DECL_CHAIN (fld))
21326 2546 : || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (eptr)),
21327 1273 : TYPE_SIZE (TREE_TYPE (fld))))
21328 : {
21329 0 : error ("%qs used without %qs declaration",
21330 : "__builtin_current_exception", "std::exception_ptr");
21331 0 : return false;
21332 : }
21333 :
21334 1273 : apply_deduced_return_type (decl, TREE_TYPE (eptr));
21335 1273 : return true;
21336 : }
21337 :
21338 628 : if (warning_suppressed_p (decl) && seen_error ())
21339 : /* We probably already complained about deduction failure. */;
21340 475 : else if (complain & tf_error)
21341 70 : error ("use of %qD before deduction of %<auto%>", decl);
21342 628 : note_failed_type_completion (decl, complain);
21343 628 : return false;
21344 : }
21345 : return true;
21346 : }
21347 :
21348 : /* Create a representation of the explicit-specifier with
21349 : constant-expression of EXPR. COMPLAIN is as for tsubst. */
21350 :
21351 : tree
21352 8076530 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
21353 : {
21354 8076530 : if (check_for_bare_parameter_packs (expr))
21355 3 : return error_mark_node;
21356 :
21357 8076527 : if (instantiation_dependent_expression_p (expr))
21358 : /* Wait for instantiation, tsubst_function_decl will handle it. */
21359 : return expr;
21360 :
21361 6546680 : expr = build_converted_constant_bool_expr (expr, complain);
21362 6546680 : expr = instantiate_non_dependent_expr (expr, complain);
21363 6546680 : expr = cxx_constant_value (expr, complain);
21364 6546680 : return expr;
21365 : }
21366 :
21367 : #include "gt-cp-decl.h"
|