Line data Source code
1 : /* Process declarations and variables for the 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 261908275 : current_tmpl_spec_kind (int n_class_scopes)
312 : {
313 261908275 : int n_template_parm_scopes = 0;
314 261908275 : int seen_specialization_p = 0;
315 261908275 : int innermost_specialization_p = 0;
316 261908275 : cp_binding_level *b;
317 :
318 : /* Scan through the template parameter scopes. */
319 261908275 : for (b = current_binding_level;
320 326725268 : b->kind == sk_template_parms;
321 64816993 : 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 64816993 : if (b->explicit_spec_p)
333 : {
334 1555457 : if (n_template_parm_scopes == 0)
335 : innermost_specialization_p = 1;
336 : else
337 1343 : seen_specialization_p = 1;
338 : }
339 63261536 : else if (seen_specialization_p == 1)
340 : return tsk_invalid_member_spec;
341 :
342 64816993 : ++n_template_parm_scopes;
343 : }
344 :
345 : /* Handle explicit instantiations. */
346 261908275 : if (processing_explicit_instantiation)
347 : {
348 2061053 : 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 2061053 : return tsk_expl_inst;
358 : }
359 :
360 259847222 : 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 259847222 : 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 56383299 : 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 56383299 : return innermost_specialization_p ? tsk_expl_spec : tsk_template;
394 : }
395 :
396 : /* Exit the current scope. */
397 :
398 : void
399 102922921 : finish_scope (void)
400 : {
401 102922921 : poplevel (0, 0, 0);
402 102922921 : }
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 20967 : check_label_used (tree label)
409 : {
410 20967 : if (!processing_template_decl)
411 : {
412 20658 : 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 20649 : warn_for_unused_label (label);
424 : }
425 20967 : }
426 :
427 : /* Helper function to sort named label entries in a vector by DECL_UID. */
428 :
429 : static int
430 235747 : sort_labels (const void *a, const void *b)
431 : {
432 235747 : tree label1 = *(tree const *) a;
433 235747 : tree label2 = *(tree const *) b;
434 :
435 : /* DECL_UIDs can never be equal. */
436 235747 : 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 169405604 : pop_labels (tree block)
508 : {
509 169405604 : if (!named_labels)
510 169400887 : 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 4717 : auto_vec<tree, 32> labels (named_labels->elements ());
518 4717 : hash_table<named_label_hash>::iterator end (named_labels->end ());
519 :
520 4717 : if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
521 720 : && !processing_template_decl)
522 : {
523 3920 : for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
524 : {
525 2544 : named_label_entry *ent = *iter;
526 2544 : 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 25651 : for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
537 : {
538 20934 : named_label_entry *ent = *iter;
539 :
540 20934 : gcc_checking_assert (!ent->outer);
541 20934 : if (ent->label_decl)
542 20748 : labels.quick_push (ent->label_decl);
543 20934 : ggc_free (ent);
544 : }
545 4717 : named_labels = NULL;
546 4717 : labels.qsort (sort_labels);
547 :
548 25465 : while (labels.length ())
549 : {
550 20748 : tree label = labels.pop ();
551 :
552 20748 : DECL_CHAIN (label) = BLOCK_VARS (block);
553 20748 : BLOCK_VARS (block) = label;
554 :
555 20748 : check_label_used (label);
556 : }
557 4717 : }
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 1806552 : level_for_constexpr_if (cp_binding_level *b)
618 : {
619 1802412 : return (b->kind == sk_cond && b->this_entity
620 302 : && TREE_CODE (b->this_entity) == IF_STMT
621 1806854 : && 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 1806528 : level_for_consteval_if (cp_binding_level *b)
628 : {
629 1802388 : return (b->kind == sk_cond && b->this_entity
630 278 : && TREE_CODE (b->this_entity) == IF_STMT
631 1806806 : && 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 156964 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
652 : {
653 156964 : named_label_entry *ent = *slot;
654 156964 : cp_binding_level *obl = bl->level_chain;
655 :
656 156964 : if (ent->binding_level == bl)
657 : {
658 10337 : tree decl;
659 :
660 : /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
661 : TREE_LISTs representing OVERLOADs, so be careful. */
662 15294 : for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
663 5030 : ? DECL_CHAIN (decl)
664 73 : : TREE_CHAIN (decl)))
665 4957 : if (decl_jump_unsafe (decl))
666 : {
667 1906 : vec_safe_push (ent->bad_decls, decl);
668 1906 : ent->has_bad_decls = true;
669 : }
670 3051 : else if (decl_instrument_init_bypass_p (decl))
671 442 : vec_safe_push (ent->bad_decls, decl);
672 :
673 10337 : ent->binding_level = obl;
674 10337 : ent->names_in_scope = obl->names;
675 10337 : 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 4188 : case sk_block:
693 4188 : if (level_for_constexpr_if (obl))
694 15 : ent->in_constexpr_if = true;
695 4173 : else if (level_for_consteval_if (obl))
696 30 : ent->in_consteval_if = true;
697 : break;
698 : default:
699 : break;
700 : }
701 : }
702 146627 : else if (ent->uses)
703 : {
704 : struct named_label_use_entry *use;
705 :
706 23019 : for (use = ent->uses; use ; use = use->next)
707 15614 : if (use->binding_level == bl)
708 : {
709 6045 : 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 6045 : use->binding_level = obl;
719 6045 : use->names_in_scope = obl->names;
720 6045 : if (bl->kind == sk_omp)
721 12 : use->in_omp_scope = true;
722 : }
723 : }
724 :
725 156964 : 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 712383314 : poplevel (int keep, int reverse, int functionbody)
749 : {
750 712383314 : tree link;
751 : /* The chain of decls was accumulated in reverse order.
752 : Put it into forward order, just for cleanliness. */
753 712383314 : tree decls;
754 712383314 : tree subblocks;
755 712383314 : tree block;
756 712383314 : tree decl;
757 712383314 : scope_kind kind;
758 :
759 712383314 : auto_cond_timevar tv (TV_NAME_LOOKUP);
760 712383763 : restart:
761 :
762 712383763 : block = NULL_TREE;
763 :
764 712383763 : gcc_assert (current_binding_level->kind != sk_class
765 : && current_binding_level->kind != sk_namespace);
766 :
767 712383763 : if (current_binding_level->kind == sk_cleanup)
768 : functionbody = 0;
769 712383763 : subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
770 :
771 712383763 : 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 712383763 : gcc_assert (keep == 0 || keep == 1);
777 :
778 712383763 : if (current_binding_level->keep)
779 8776069 : keep = 1;
780 :
781 : /* Any uses of undefined labels, and any defined labels, now operate
782 : under constraints of next binding contour. */
783 712383763 : if (cfun && !functionbody && named_labels)
784 43999 : named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
785 200963 : (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 712383763 : decls = current_binding_level->names;
792 712383763 : if (reverse)
793 : {
794 391141491 : decls = nreverse (decls);
795 391141491 : 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 712383763 : block = NULL_TREE;
802 : /* Avoid function body block if possible. */
803 755567585 : if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
804 : keep = 0;
805 669200205 : else if (keep == 1 || functionbody)
806 213902661 : block = make_node (BLOCK);
807 213902661 : if (block != NULL_TREE)
808 : {
809 213902661 : BLOCK_VARS (block) = decls;
810 213902661 : BLOCK_SUBBLOCKS (block) = subblocks;
811 : }
812 :
813 : /* In each subblock, record that this is its superior. */
814 712383763 : if (keep >= 0)
815 800063643 : for (link = subblocks; link; link = BLOCK_CHAIN (link))
816 87679880 : BLOCK_SUPERCONTEXT (link) = block;
817 :
818 : /* Before we remove the declarations first check for unused variables. */
819 712383763 : if ((warn_unused_variable || warn_unused_but_set_variable)
820 6787560 : && current_binding_level->kind != sk_template_parms
821 5722271 : && !processing_template_decl)
822 6566426 : 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 3327692 : tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
828 3327692 : decl = strip_using_decl (udecl);
829 :
830 3327692 : tree type = TREE_TYPE (decl);
831 3327692 : if (VAR_P (decl)
832 388591 : && (!TREE_USED (decl) || !DECL_READ_P (decl))
833 3613 : && !DECL_IN_SYSTEM_HEADER (udecl)
834 : /* For structured bindings, consider only real variables, not
835 : subobjects. */
836 3601 : && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
837 3378 : : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
838 : /* Don't warn about name-independent declarations. */
839 899 : && !name_independent_decl_p (decl)
840 743 : && type != error_mark_node
841 3332002 : && (!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 709 : 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 401 : else if (DECL_CONTEXT (decl) == current_function_decl
862 : // For -Wunused-but-set-variable leave references alone.
863 377 : && !TYPE_REF_P (TREE_TYPE (decl))
864 778 : && errorcount == unused_but_set_errorcount)
865 : {
866 368 : 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 356 : warning_at (DECL_SOURCE_LOCATION (decl),
872 356 : OPT_Wunused_but_set_variable_,
873 : "variable %qD set but not used", decl);
874 368 : unused_but_set_errorcount = errorcount;
875 : }
876 : }
877 : }
878 :
879 : /* Remove declarations for all the DECLs in this level. */
880 1439482378 : for (link = decls; link; link = TREE_CHAIN (link))
881 : {
882 727098615 : tree name;
883 727098615 : if (TREE_CODE (link) == TREE_LIST)
884 : {
885 13947075 : decl = TREE_VALUE (link);
886 13947075 : name = TREE_PURPOSE (link);
887 13947075 : gcc_checking_assert (name);
888 : }
889 : else
890 : {
891 713151540 : decl = link;
892 713151540 : name = DECL_NAME (decl);
893 : }
894 :
895 : /* Remove the binding. */
896 727098615 : if (TREE_CODE (decl) == LABEL_DECL)
897 219 : pop_local_label (name, decl);
898 : else
899 727098396 : pop_local_binding (name, decl);
900 : }
901 :
902 : /* Restore the IDENTIFIER_TYPE_VALUEs. */
903 712383763 : for (link = current_binding_level->type_shadowed;
904 970660738 : link; link = TREE_CHAIN (link))
905 258276975 : 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 712383763 : if (block)
915 : {
916 213902661 : tree* d;
917 :
918 562929726 : for (d = &BLOCK_VARS (block); *d; )
919 : {
920 349027065 : if (TREE_CODE (*d) == TREE_LIST
921 349027065 : || (!processing_template_decl
922 110398026 : && undeduced_auto_decl (*d)))
923 13947127 : *d = TREE_CHAIN (*d);
924 : else
925 335079938 : 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 712383763 : if (functionbody)
932 : {
933 169405604 : 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 126222046 : BLOCK_VARS (block) = 0;
939 126222046 : pop_labels (block);
940 : }
941 : else
942 43183558 : pop_labels (subblocks);
943 : }
944 :
945 712383763 : kind = current_binding_level->kind;
946 712383763 : if (kind == sk_cleanup)
947 : {
948 449 : 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 449 : stmt = pop_stmt_list (current_binding_level->statement_list);
954 449 : stmt = c_build_bind_expr (input_location, block, stmt);
955 449 : add_stmt (stmt);
956 : }
957 :
958 712383763 : leave_scope ();
959 712383763 : if (functionbody)
960 : {
961 : /* The current function is being defined, so its DECL_INITIAL
962 : should be error_mark_node. */
963 169405604 : gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
964 212589162 : DECL_INITIAL (current_function_decl) = block ? block : subblocks;
965 169405604 : if (subblocks)
966 : {
967 82170898 : if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
968 53662035 : && BLOCK_SUBBLOCKS (subblocks))
969 1397375 : BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
970 : else
971 41786447 : BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
972 : }
973 : }
974 542978159 : else if (block)
975 87680615 : current_binding_level->blocks
976 175361230 : = 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 455297544 : 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 712383763 : if (block)
991 213902661 : TREE_USED (block) = 1;
992 :
993 : /* All temporary bindings created for cleanups are popped silently. */
994 712383763 : if (kind == sk_cleanup)
995 449 : goto restart;
996 :
997 1424766628 : return block;
998 712383314 : }
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 147503 : wrapup_namespace_globals ()
1006 : {
1007 147503 : if (vec<tree, va_gc> *statics = static_decls)
1008 : {
1009 18506362 : for (tree decl : *statics)
1010 : {
1011 : /* Rewrite the REFLECT_EXPR with 0 so that the ME can process it. */
1012 18385818 : if (flag_reflection && DECL_INITIAL (decl))
1013 302860 : rewrite_null_reflection (DECL_INITIAL (decl));
1014 :
1015 18385818 : if (warn_unused_function
1016 1014810 : && TREE_CODE (decl) == FUNCTION_DECL
1017 765465 : && DECL_INITIAL (decl) == 0
1018 7626 : && DECL_EXTERNAL (decl)
1019 7614 : && !TREE_PUBLIC (decl)
1020 34 : && !DECL_ARTIFICIAL (decl)
1021 34 : && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
1022 9 : && !warning_suppressed_p (decl, OPT_Wunused)
1023 19400628 : && warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_function,
1024 : "%qF declared %<static%> but never defined",
1025 : decl))
1026 6 : suppress_warning (decl, OPT_Wunused);
1027 :
1028 18385818 : if (VAR_P (decl)
1029 6074457 : && DECL_EXTERNAL (decl)
1030 : /* We mark consteval-only variables DECL_EXTERNAL, but
1031 : extern constexpr inline std::meta::info i{};
1032 : is a definition (the extern is redundant). */
1033 2090132 : && !DECL_INITIAL (decl)
1034 2088961 : && DECL_INLINE_VAR_P (decl)
1035 18385847 : && DECL_ODR_USED (decl))
1036 3 : error_at (DECL_SOURCE_LOCATION (decl),
1037 : "odr-used inline variable %qD is not defined", decl);
1038 : }
1039 :
1040 : /* Clear out the list, so we don't rescan next time. */
1041 120544 : static_decls = NULL;
1042 :
1043 : /* Write out any globals that need to be output. */
1044 120544 : return wrapup_global_declarations (statics->address (),
1045 120544 : statics->length ());
1046 : }
1047 : return 0;
1048 : }
1049 :
1050 : /* In C++, you don't have to write `struct S' to refer to `S'; you
1051 : can just use `S'. We accomplish this by creating a TYPE_DECL as
1052 : if the user had written `typedef struct S S'. Create and return
1053 : the TYPE_DECL for TYPE. */
1054 :
1055 : tree
1056 191449519 : create_implicit_typedef (tree name, tree type)
1057 : {
1058 191449519 : tree decl;
1059 :
1060 191449519 : decl = build_decl (input_location, TYPE_DECL, name, type);
1061 191449519 : DECL_ARTIFICIAL (decl) = 1;
1062 : /* There are other implicit type declarations, like the one *within*
1063 : a class that allows you to write `S::S'. We must distinguish
1064 : amongst these. */
1065 191449519 : SET_DECL_IMPLICIT_TYPEDEF_P (decl);
1066 191449519 : TYPE_NAME (type) = decl;
1067 191449519 : TYPE_STUB_DECL (type) = decl;
1068 :
1069 191449519 : return decl;
1070 : }
1071 :
1072 : /* Function-scope local entities that need discriminators. Each entry
1073 : is a {decl,name} pair. VAR_DECLs for anon unions get their name
1074 : smashed, so we cannot rely on DECL_NAME. */
1075 :
1076 : static GTY((deletable)) vec<tree, va_gc> *local_entities;
1077 :
1078 : /* Determine the mangling discriminator of local DECL. There are
1079 : generally very few of these in any particular function. */
1080 :
1081 : void
1082 779483 : determine_local_discriminator (tree decl, tree name)
1083 : {
1084 779483 : auto_cond_timevar tv (TV_NAME_LOOKUP);
1085 779483 : retrofit_lang_decl (decl);
1086 779483 : tree ctx = DECL_CONTEXT (decl);
1087 779483 : size_t nelts = vec_safe_length (local_entities);
1088 779483 : if (name == NULL_TREE)
1089 779216 : name = (TREE_CODE (decl) == TYPE_DECL
1090 1274855 : && TYPE_UNNAMED_P (TREE_TYPE (decl))
1091 1412220 : ? NULL_TREE : DECL_NAME (decl));
1092 22961977 : for (size_t i = 0; i < nelts; i += 2)
1093 : {
1094 22183174 : tree *pair = &(*local_entities)[i];
1095 22183174 : tree d = pair[0];
1096 22183174 : tree n = pair[1];
1097 22183174 : gcc_checking_assert (d != decl);
1098 22183174 : if (name == n
1099 4008832 : && TREE_CODE (decl) == TREE_CODE (d)
1100 26191997 : && ctx == DECL_CONTEXT (d))
1101 : {
1102 680 : tree disc = integer_one_node;
1103 680 : if (DECL_DISCRIMINATOR (d))
1104 375 : disc = build_int_cst (TREE_TYPE (disc),
1105 375 : TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
1106 680 : DECL_DISCRIMINATOR (decl) = disc;
1107 : /* Replace the saved decl. */
1108 680 : pair[0] = decl;
1109 680 : decl = NULL_TREE;
1110 680 : break;
1111 : }
1112 : }
1113 :
1114 779483 : if (decl)
1115 : {
1116 778803 : vec_safe_reserve (local_entities, 2);
1117 778803 : local_entities->quick_push (decl);
1118 778803 : local_entities->quick_push (name);
1119 : }
1120 779483 : }
1121 :
1122 :
1123 : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
1124 :
1125 : A non-template friend declaration with a requires-clause shall be a
1126 : definition. A friend function template with a constraint that depends on a
1127 : template parameter from an enclosing template shall be a definition. Such a
1128 : constrained friend function or function template declaration does not
1129 : declare the same function or function template as a declaration in any other
1130 : scope.
1131 :
1132 : The ABI calls this a "member-like constrained friend" and mangles it like a
1133 : member function to avoid collisions. */
1134 :
1135 : bool
1136 2622559154 : member_like_constrained_friend_p (tree decl)
1137 : {
1138 2622559154 : return (TREE_CODE (decl) == FUNCTION_DECL
1139 899646228 : && DECL_UNIQUE_FRIEND_P (decl)
1140 295183812 : && DECL_FRIEND_CONTEXT (decl)
1141 129740006 : && get_constraints (decl)
1142 18764818 : && CLASSTYPE_IMPLICIT_INSTANTIATION (DECL_FRIEND_CONTEXT (decl))
1143 2631919717 : && (!DECL_TEMPLATE_INFO (decl)
1144 9360563 : || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
1145 8723 : || (uses_outer_template_parms_in_constraints
1146 8723 : (most_general_template (decl)))));
1147 : }
1148 :
1149 : /* Returns true if functions FN1 and FN2 have equivalent trailing
1150 : requires clauses. */
1151 :
1152 : static bool
1153 73294608 : function_requirements_equivalent_p (tree newfn, tree oldfn)
1154 : {
1155 : /* [temp.friend]/9 "Such a constrained friend function does not declare the
1156 : same function as a declaration in any other scope." So no need to
1157 : actually compare the requirements. */
1158 73294608 : if (member_like_constrained_friend_p (newfn)
1159 73294608 : || member_like_constrained_friend_p (oldfn))
1160 : return false;
1161 :
1162 : /* Compare only trailing requirements. */
1163 73294487 : tree reqs1 = get_trailing_function_requirements (newfn);
1164 73294487 : tree reqs2 = get_trailing_function_requirements (oldfn);
1165 73294487 : if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
1166 : return false;
1167 :
1168 : /* Substitution is needed when friends are involved. */
1169 73156501 : reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
1170 73156501 : reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
1171 :
1172 73156501 : return cp_tree_equal (reqs1, reqs2);
1173 : }
1174 :
1175 : /* Two functions of the same name correspond [basic.scope.scope] if
1176 :
1177 : + both declare functions with the same non-object-parameter-type-list,
1178 : equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
1179 : specified in [temp.friend]), and, if both are non-static members, they have
1180 : corresponding object parameters, or
1181 :
1182 : + both declare function templates with equivalent
1183 : non-object-parameter-type-lists, return types (if any), template-heads, and
1184 : trailing requires-clauses (if any), and, if both are non-static members,
1185 : they have corresponding object parameters.
1186 :
1187 : This is a subset of decls_match: it identifies declarations that cannot be
1188 : overloaded with one another. This function does not consider DECL_NAME. */
1189 :
1190 : bool
1191 1583549349 : fns_correspond (tree newdecl, tree olddecl)
1192 : {
1193 1583549349 : if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
1194 : return false;
1195 :
1196 1472270714 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1197 : {
1198 1470906818 : if (!template_heads_equivalent_p (newdecl, olddecl))
1199 : return 0;
1200 349566039 : newdecl = DECL_TEMPLATE_RESULT (newdecl);
1201 349566039 : olddecl = DECL_TEMPLATE_RESULT (olddecl);
1202 : }
1203 :
1204 350929935 : tree f1 = TREE_TYPE (newdecl);
1205 350929935 : tree f2 = TREE_TYPE (olddecl);
1206 :
1207 350929935 : int rq1 = type_memfn_rqual (f1);
1208 350929935 : int rq2 = type_memfn_rqual (f2);
1209 :
1210 : /* If only one is a non-static member function, ignore ref-quals. */
1211 350929935 : if (TREE_CODE (f1) != TREE_CODE (f2))
1212 : rq1 = rq2;
1213 : /* Two non-static member functions have corresponding object parameters if:
1214 : + exactly one is an implicit object member function with no ref-qualifier
1215 : and the types of their object parameters ([dcl.fct]), after removing
1216 : top-level references, are the same, or
1217 : + their object parameters have the same type. */
1218 : /* ??? We treat member functions of different classes as corresponding even
1219 : though that means the object parameters have different types. */
1220 350929935 : else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
1221 0 : rq1 = rq2;
1222 :
1223 350929935 : bool types_match = rq1 == rq2;
1224 :
1225 350929935 : if (types_match)
1226 : {
1227 350929935 : tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1228 350929935 : tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
1229 350929935 : types_match = compparms (p1, p2);
1230 : }
1231 :
1232 : /* Two function declarations match if either has a requires-clause
1233 : then both have a requires-clause and their constraints-expressions
1234 : are equivalent. */
1235 350929935 : if (types_match && flag_concepts)
1236 43300219 : types_match = function_requirements_equivalent_p (newdecl, olddecl);
1237 :
1238 : return types_match;
1239 : }
1240 :
1241 : /* Subroutine of duplicate_decls: return truthvalue of whether
1242 : or not types of these decls match.
1243 :
1244 : For C++, we must compare the parameter list so that `int' can match
1245 : `int&' in a parameter position, but `int&' is not confused with
1246 : `const int&'. */
1247 :
1248 : int
1249 828824332 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
1250 : {
1251 879723660 : int types_match;
1252 :
1253 879723660 : if (newdecl == olddecl)
1254 : return 1;
1255 :
1256 879602854 : if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
1257 : /* If the two DECLs are not even the same kind of thing, we're not
1258 : interested in their types. */
1259 : return 0;
1260 :
1261 464029491 : gcc_assert (DECL_P (newdecl));
1262 :
1263 464029491 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
1264 : {
1265 : /* Specializations of different templates are different functions
1266 : even if they have the same type. */
1267 306715751 : tree t1 = (DECL_USE_TEMPLATE (newdecl)
1268 306715751 : ? DECL_TI_TEMPLATE (newdecl)
1269 667033 : : NULL_TREE);
1270 306715751 : tree t2 = (DECL_USE_TEMPLATE (olddecl)
1271 306715751 : ? DECL_TI_TEMPLATE (olddecl)
1272 4248495 : : NULL_TREE);
1273 306715751 : if (t1 != t2)
1274 : return 0;
1275 :
1276 303134206 : if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1277 303134206 : && ! (DECL_EXTERN_C_P (newdecl)
1278 3030179 : && DECL_EXTERN_C_P (olddecl)))
1279 : return 0;
1280 :
1281 : /* A new declaration doesn't match a built-in one unless it
1282 : is also extern "C". */
1283 281040356 : if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
1284 281040356 : && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
1285 : return 0;
1286 :
1287 280372839 : tree f1 = TREE_TYPE (newdecl);
1288 280372839 : tree f2 = TREE_TYPE (olddecl);
1289 280372839 : if (TREE_CODE (f1) != TREE_CODE (f2))
1290 : return 0;
1291 :
1292 : /* A declaration with deduced return type should use its pre-deduction
1293 : type for declaration matching. */
1294 280189425 : tree r2 = fndecl_declared_return_type (olddecl);
1295 280189425 : tree r1 = fndecl_declared_return_type (newdecl);
1296 :
1297 : /* For memchr et al, allow const void* return type (as specified by C++)
1298 : when we expect void* (as in C). */
1299 280189425 : if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
1300 6739166 : && DECL_EXTERN_C_P (olddecl)
1301 4147465 : && !same_type_p (r1, r2)
1302 70 : && TREE_CODE (r1) == POINTER_TYPE
1303 15 : && TREE_CODE (r2) == POINTER_TYPE
1304 280189437 : && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
1305 : r2 = r1;
1306 :
1307 280189425 : tree p1 = TYPE_ARG_TYPES (f1);
1308 280189425 : tree p2 = TYPE_ARG_TYPES (f2);
1309 :
1310 280189425 : if (same_type_p (r1, r2))
1311 : {
1312 179942882 : if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
1313 179942854 : && fndecl_built_in_p (olddecl))
1314 : {
1315 50 : types_match = self_promoting_args_p (p1);
1316 50 : if (p1 == void_list_node)
1317 3 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
1318 : }
1319 : else
1320 179942748 : types_match =
1321 179942748 : compparms (p1, p2)
1322 30505184 : && type_memfn_rqual (f1) == type_memfn_rqual (f2)
1323 210447536 : && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
1324 1281815 : || comp_type_attributes (TREE_TYPE (newdecl),
1325 1281815 : TREE_TYPE (olddecl)) != 0);
1326 : }
1327 : else
1328 : types_match = 0;
1329 :
1330 : /* Two function declarations match if either has a requires-clause
1331 : then both have a requires-clause and their constraints-expressions
1332 : are equivalent. */
1333 30504817 : if (types_match && flag_concepts)
1334 29994357 : types_match = function_requirements_equivalent_p (newdecl, olddecl);
1335 :
1336 : /* The decls dont match if they correspond to two different versions
1337 : of the same function. Disallow extern "C" functions to be
1338 : versions for now. */
1339 30504817 : if (types_match
1340 30298782 : && !DECL_EXTERN_C_P (newdecl)
1341 21783241 : && !DECL_EXTERN_C_P (olddecl)
1342 52284058 : && disjoint_version_decls (newdecl, olddecl))
1343 : {
1344 8880 : if (record_versions)
1345 8793 : maybe_version_functions (newdecl, olddecl);
1346 : return 0;
1347 : }
1348 : }
1349 157313740 : else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1350 : {
1351 155461207 : if (!template_heads_equivalent_p (newdecl, olddecl))
1352 : return 0;
1353 :
1354 50899364 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1355 50899364 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
1356 :
1357 50899364 : if (TREE_CODE (newres) != TREE_CODE (oldres))
1358 : return 0;
1359 :
1360 : /* Two template types match if they are the same. Otherwise, compare
1361 : the underlying declarations. */
1362 50899358 : if (TREE_CODE (newres) == TYPE_DECL)
1363 30 : types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
1364 : else
1365 : types_match = decls_match (newres, oldres);
1366 : }
1367 : else
1368 : {
1369 : /* Need to check scope for variable declaration (VAR_DECL).
1370 : For typedef (TYPE_DECL), scope is ignored. */
1371 1852533 : if (VAR_P (newdecl)
1372 1248863 : && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1373 : /* [dcl.link]
1374 : Two declarations for an object with C language linkage
1375 : with the same name (ignoring the namespace that qualify
1376 : it) that appear in different namespace scopes refer to
1377 : the same object. */
1378 2046419 : && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
1379 : return 0;
1380 :
1381 1658695 : if (TREE_TYPE (newdecl) == error_mark_node)
1382 0 : types_match = TREE_TYPE (olddecl) == error_mark_node;
1383 1658695 : else if (TREE_TYPE (olddecl) == NULL_TREE)
1384 0 : types_match = TREE_TYPE (newdecl) == NULL_TREE;
1385 1658695 : else if (TREE_TYPE (newdecl) == NULL_TREE)
1386 : types_match = 0;
1387 : else
1388 1658695 : types_match = comptypes (TREE_TYPE (newdecl),
1389 1658695 : TREE_TYPE (olddecl),
1390 : COMPARE_REDECLARATION);
1391 : }
1392 :
1393 : return types_match;
1394 : }
1395 :
1396 : /* Mark DECL as versioned if it isn't already. */
1397 :
1398 : void
1399 17676 : maybe_mark_function_versioned (tree decl)
1400 : {
1401 17676 : if (!DECL_FUNCTION_VERSIONED (decl))
1402 : {
1403 : /* We need to insert function version now to make sure the correct
1404 : pre-mangled assembler name is recorded. */
1405 1068 : cgraph_node *node = cgraph_node::get_create (decl);
1406 :
1407 1068 : if (!node->function_version ())
1408 1068 : node->insert_new_function_version ();
1409 :
1410 1068 : DECL_FUNCTION_VERSIONED (decl) = 1;
1411 : /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
1412 : to include the version marker. */
1413 1068 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
1414 1062 : mangle_decl (decl);
1415 : }
1416 17676 : }
1417 :
1418 : /* NEWDECL and OLDDECL have identical signatures. If they are
1419 : different versions adjust them, record function versions, and return
1420 : true. */
1421 :
1422 : bool
1423 209459 : maybe_version_functions (tree newdecl, tree olddecl)
1424 : {
1425 209459 : if (!disjoint_version_decls (newdecl, olddecl))
1426 : return false;
1427 :
1428 8820 : maybe_mark_function_versioned (olddecl);
1429 8820 : if (DECL_LOCAL_DECL_P (olddecl))
1430 : {
1431 18 : olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
1432 18 : maybe_mark_function_versioned (olddecl);
1433 : }
1434 :
1435 8820 : maybe_mark_function_versioned (newdecl);
1436 8820 : if (DECL_LOCAL_DECL_P (newdecl))
1437 : {
1438 : /* Unfortunately, we can get here before pushdecl naturally calls
1439 : push_local_extern_decl_alias, so we need to call it directly. */
1440 18 : if (!DECL_LOCAL_DECL_ALIAS (newdecl))
1441 6 : push_local_extern_decl_alias (newdecl);
1442 18 : newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
1443 18 : maybe_mark_function_versioned (newdecl);
1444 : }
1445 :
1446 : /* Add the new version to the function version structure. */
1447 8820 : cgraph_node *fn_node = cgraph_node::get_create (olddecl);
1448 8820 : cgraph_function_version_info *fn_v = fn_node->function_version ();
1449 8820 : if (!fn_v)
1450 15 : fn_v = fn_node->insert_new_function_version ();
1451 :
1452 8820 : cgraph_node::add_function_version (fn_v, newdecl);
1453 :
1454 8820 : return true;
1455 : }
1456 :
1457 : /* If NEWDECL is `static' and an `extern' was seen previously,
1458 : warn about it. OLDDECL is the previous declaration.
1459 :
1460 : Note that this does not apply to the C++ case of declaring
1461 : a variable `extern const' and then later `const'.
1462 :
1463 : Don't complain about built-in functions, since they are beyond
1464 : the user's control. */
1465 :
1466 : void
1467 20635068 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
1468 : {
1469 20635068 : if (TREE_CODE (newdecl) == TYPE_DECL
1470 : || TREE_CODE (newdecl) == TEMPLATE_DECL
1471 : || TREE_CODE (newdecl) == CONST_DECL
1472 : || TREE_CODE (newdecl) == NAMESPACE_DECL)
1473 20635056 : return;
1474 :
1475 : /* Don't get confused by static member functions; that's a different
1476 : use of `static'. */
1477 : if (TREE_CODE (newdecl) == FUNCTION_DECL
1478 15859391 : && DECL_STATIC_FUNCTION_P (newdecl))
1479 : return;
1480 :
1481 : /* If the old declaration was `static', or the new one isn't, then
1482 : everything is OK. */
1483 16203102 : if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
1484 : return;
1485 :
1486 : /* It's OK to declare a builtin function as `static'. */
1487 12 : if (TREE_CODE (olddecl) == FUNCTION_DECL
1488 12 : && DECL_ARTIFICIAL (olddecl))
1489 : return;
1490 :
1491 12 : auto_diagnostic_group d;
1492 12 : if (permerror (DECL_SOURCE_LOCATION (newdecl),
1493 : "%qD was declared %<extern%> and later %<static%>", newdecl))
1494 12 : inform (DECL_SOURCE_LOCATION (olddecl),
1495 : "previous declaration of %qD", olddecl);
1496 12 : }
1497 :
1498 : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
1499 : function templates. If their exception specifications do not
1500 : match, issue a diagnostic. */
1501 :
1502 : static void
1503 20058037 : check_redeclaration_exception_specification (tree new_decl,
1504 : tree old_decl)
1505 : {
1506 20058037 : tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
1507 20058037 : tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
1508 :
1509 : /* Two default specs are equivalent, don't force evaluation. */
1510 7744657 : if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
1511 20207753 : && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
1512 : return;
1513 :
1514 20047969 : if (!type_dependent_expression_p (old_decl))
1515 : {
1516 12307964 : maybe_instantiate_noexcept (new_decl);
1517 12307964 : maybe_instantiate_noexcept (old_decl);
1518 : }
1519 20047969 : new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
1520 20047969 : old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
1521 :
1522 : /* [except.spec]
1523 :
1524 : If any declaration of a function has an exception-specification,
1525 : all declarations, including the definition and an explicit
1526 : specialization, of that function shall have an
1527 : exception-specification with the same set of type-ids. */
1528 20047969 : if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
1529 16025242 : && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
1530 36073066 : && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
1531 : {
1532 329 : const char *const msg
1533 : = G_("declaration of %qF has a different exception specifier");
1534 329 : bool complained = true;
1535 329 : location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
1536 329 : auto_diagnostic_group d;
1537 :
1538 : /* Be permissive about C++98 vs C++11 operator new declarations. */
1539 658 : bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
1540 1 : && CP_DECL_CONTEXT (new_decl) == global_namespace
1541 331 : && (nothrow_spec_p (new_exceptions)
1542 1 : == nothrow_spec_p (old_exceptions)));
1543 :
1544 329 : if (DECL_IN_SYSTEM_HEADER (old_decl)
1545 329 : && (global_new || DECL_EXTERN_C_P (old_decl)))
1546 : /* Don't fuss about the C library; the C library functions are not
1547 : specified to have exception specifications (just behave as if they
1548 : have them), but some implementations include them. */
1549 233 : complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
1550 96 : else if (!flag_exceptions)
1551 : /* We used to silently permit mismatched eh specs with
1552 : -fno-exceptions, so only complain if -pedantic. */
1553 3 : complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
1554 93 : else if (!new_exceptions || global_new)
1555 : /* Reduce to pedwarn for omitted exception specification. No warning
1556 : flag for this; silence the warning by correcting the code. */
1557 18 : complained = pedwarn (new_loc, 0, msg, new_decl);
1558 : else
1559 75 : error_at (new_loc, msg, new_decl);
1560 :
1561 329 : if (complained)
1562 99 : inform (DECL_SOURCE_LOCATION (old_decl),
1563 : "from previous declaration %qF", old_decl);
1564 :
1565 : /* Copy the old exception specification if new_decl has none. Unless the
1566 : old decl is extern "C", as obscure code might depend on the type of
1567 : the new declaration (e.g. noexcept-type19.C). */
1568 329 : if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
1569 17 : TREE_TYPE (new_decl)
1570 34 : = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
1571 329 : }
1572 : }
1573 :
1574 : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
1575 : Otherwise issue diagnostics. */
1576 :
1577 : bool
1578 20635594 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
1579 : {
1580 20635594 : old_decl = STRIP_TEMPLATE (old_decl);
1581 20635594 : new_decl = STRIP_TEMPLATE (new_decl);
1582 20635594 : if (!VAR_OR_FUNCTION_DECL_P (old_decl)
1583 20585369 : || !VAR_OR_FUNCTION_DECL_P (new_decl))
1584 : return true;
1585 20585369 : if (DECL_DECLARED_CONSTEXPR_P (old_decl)
1586 20585369 : == DECL_DECLARED_CONSTEXPR_P (new_decl))
1587 : {
1588 20429162 : if (TREE_CODE (old_decl) != FUNCTION_DECL)
1589 : return true;
1590 40116904 : if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1591 20058452 : == DECL_IMMEDIATE_FUNCTION_P (new_decl))
1592 : return true;
1593 : }
1594 156213 : if (TREE_CODE (old_decl) == FUNCTION_DECL)
1595 : {
1596 : /* With -fimplicit-constexpr, ignore changes in the constexpr
1597 : keyword. */
1598 71 : if (flag_implicit_constexpr
1599 71 : && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
1600 0 : == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
1601 : return true;
1602 71 : if (fndecl_built_in_p (old_decl))
1603 : {
1604 : /* Hide a built-in declaration. */
1605 0 : DECL_DECLARED_CONSTEXPR_P (old_decl)
1606 0 : = DECL_DECLARED_CONSTEXPR_P (new_decl);
1607 0 : if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
1608 0 : SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
1609 : return true;
1610 : }
1611 : /* 7.1.5 [dcl.constexpr]
1612 : Note: An explicit specialization can differ from the template
1613 : declaration with respect to the constexpr specifier. */
1614 71 : if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
1615 71 : && DECL_TEMPLATE_SPECIALIZATION (new_decl))
1616 : return true;
1617 :
1618 42 : const char *kind = "constexpr";
1619 42 : if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1620 72 : || DECL_IMMEDIATE_FUNCTION_P (new_decl))
1621 : kind = "consteval";
1622 42 : auto_diagnostic_group d;
1623 42 : error_at (DECL_SOURCE_LOCATION (new_decl),
1624 : "redeclaration %qD differs in %qs "
1625 : "from previous declaration", new_decl,
1626 : kind);
1627 42 : inform (DECL_SOURCE_LOCATION (old_decl),
1628 : "previous declaration %qD", old_decl);
1629 42 : return false;
1630 42 : }
1631 : return true;
1632 : }
1633 :
1634 : /* DECL is a redeclaration of a function or function template. If
1635 : it does have default arguments issue a diagnostic. Note: this
1636 : function is used to enforce the requirements in C++11 8.3.6 about
1637 : no default arguments in redeclarations. */
1638 :
1639 : static void
1640 12015659 : check_redeclaration_no_default_args (tree decl)
1641 : {
1642 12015659 : gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
1643 :
1644 12015659 : for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
1645 35374699 : t && t != void_list_node; t = TREE_CHAIN (t))
1646 23359097 : if (TREE_PURPOSE (t))
1647 : {
1648 57 : permerror (DECL_SOURCE_LOCATION (decl),
1649 : "redeclaration of %q#D may not have default "
1650 : "arguments", decl);
1651 57 : return;
1652 : }
1653 : }
1654 :
1655 : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
1656 : in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
1657 : the TEMPLATE_DECLs in case of function templates). This function is used
1658 : to enforce the final part of C++17 11.3.6/4, about a single declaration:
1659 : "If a friend declaration specifies a default argument expression, that
1660 : declaration shall be a definition and shall be the only declaration of
1661 : the function or function template in the translation unit." */
1662 :
1663 : static void
1664 7504856 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
1665 : {
1666 14281667 : if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
1667 : return;
1668 :
1669 1876200 : for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
1670 1876200 : t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1671 4962256 : t1 && t1 != void_list_node;
1672 3086056 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1673 4387425 : if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
1674 8804937 : || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
1675 : {
1676 36 : auto_diagnostic_group d;
1677 36 : if (permerror (DECL_SOURCE_LOCATION (newdecl),
1678 : "friend declaration of %q#D specifies default "
1679 : "arguments and isn%'t the only declaration", newdecl))
1680 36 : inform (DECL_SOURCE_LOCATION (olddecl),
1681 : "previous declaration of %q#D", olddecl);
1682 36 : return;
1683 36 : }
1684 : }
1685 :
1686 : /* Merge tree bits that correspond to attributes noreturn, nothrow,
1687 : const, malloc, and pure from NEWDECL with those of OLDDECL. */
1688 :
1689 : static void
1690 19476511 : merge_attribute_bits (tree newdecl, tree olddecl)
1691 : {
1692 19476511 : TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1693 19476511 : TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
1694 19476511 : TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
1695 19476511 : TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
1696 19476511 : TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1697 19476511 : TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
1698 19476511 : DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1699 19476511 : DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
1700 19476511 : DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1701 19476511 : DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
1702 19476511 : DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
1703 19476511 : DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
1704 19476511 : TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
1705 19476511 : TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
1706 19476511 : TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
1707 19476511 : TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
1708 19476511 : }
1709 :
1710 : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn) \
1711 : && lookup_attribute ("gnu_inline", \
1712 : DECL_ATTRIBUTES (fn)))
1713 :
1714 : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
1715 : ambiguates olddecl. Returns true if an error occurs. */
1716 :
1717 : static bool
1718 151262150 : duplicate_function_template_decls (tree newdecl, tree olddecl)
1719 : {
1720 151262150 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
1721 151262150 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1722 : /* Function template declarations can be differentiated by parameter
1723 : and return type. */
1724 151262150 : if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
1725 151262150 : TYPE_ARG_TYPES (TREE_TYPE (newres)))
1726 151262150 : && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
1727 : TREE_TYPE (TREE_TYPE (olddecl))))
1728 : {
1729 : /* ... and also by their template-heads and requires-clauses. */
1730 7342 : if (template_heads_equivalent_p (newdecl, olddecl)
1731 7342 : && function_requirements_equivalent_p (newres, oldres))
1732 : {
1733 0 : auto_diagnostic_group d;
1734 0 : error ("ambiguating new declaration %q+#D", newdecl);
1735 0 : inform (DECL_SOURCE_LOCATION (olddecl),
1736 : "old declaration %q#D", olddecl);
1737 0 : return true;
1738 0 : }
1739 :
1740 : /* FIXME: The types are the same but the are differences
1741 : in either the template heads or function requirements.
1742 : We should be able to diagnose a set of common errors
1743 : stemming from these declarations. For example:
1744 :
1745 : template<typename T> requires C void f(...);
1746 : template<typename T> void f(...) requires C;
1747 :
1748 : These are functionally equivalent but not equivalent. */
1749 : }
1750 :
1751 : return false;
1752 : }
1753 :
1754 : /* OLD_PARMS is the innermost set of template parameters for some template
1755 : declaration, and NEW_PARMS is the corresponding set of template parameters
1756 : for a redeclaration of that template. Merge the default arguments within
1757 : these two sets of parameters. CLASS_P is true iff the template in
1758 : question is a class template. */
1759 :
1760 : bool
1761 9383680 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
1762 : {
1763 9383680 : gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
1764 : == TREE_VEC_LENGTH (old_parms));
1765 26490877 : for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
1766 : {
1767 17107227 : tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
1768 17107227 : tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
1769 17107227 : tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
1770 17107227 : tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
1771 17107227 : if (error_operand_p (new_parm) || error_operand_p (old_parm))
1772 : return false;
1773 17107224 : if (new_default != NULL_TREE && old_default != NULL_TREE)
1774 : {
1775 27 : auto_diagnostic_group d;
1776 27 : error ("redefinition of default argument for %q+#D", new_parm);
1777 27 : inform (DECL_SOURCE_LOCATION (old_parm),
1778 : "original definition appeared here");
1779 27 : return false;
1780 27 : }
1781 17107197 : else if (new_default != NULL_TREE)
1782 : /* Update the previous template parameters (which are the ones
1783 : that will really count) with the new default value. */
1784 240643 : old_default = new_default;
1785 16866554 : else if (class_p && old_default != NULL_TREE)
1786 : /* Update the new parameters, too; they'll be used as the
1787 : parameters for any members. */
1788 1043638 : new_default = old_default;
1789 : }
1790 : return true;
1791 : }
1792 :
1793 : /* Helper function for duplicate_decls and push_local_extern_decl_alias.
1794 : Merge parameter attributes and names between NEWDECL and OLDDECL.
1795 : NEW_DEFINES_FUNCTION and TYPES_MATCH argument like variables in
1796 : duplicate_decls, EXTERN_ALIAS false for duplicate_decls and true for
1797 : push_local_extern_decl_alias. */
1798 :
1799 : void
1800 15859580 : merge_decl_arguments (tree newdecl, tree olddecl, bool new_defines_function,
1801 : bool types_match, bool extern_alias)
1802 : {
1803 15859580 : tree oldarg, newarg, type = NULL_TREE;
1804 15859580 : tree first_user_parm = NULL_TREE;
1805 15859580 : if (extern_alias)
1806 189 : first_user_parm = FUNCTION_FIRST_USER_PARM (newdecl);
1807 15859580 : for (oldarg = DECL_ARGUMENTS (olddecl), newarg = DECL_ARGUMENTS (newdecl);
1808 44517451 : oldarg && newarg;
1809 28657871 : oldarg = DECL_CHAIN (oldarg), newarg = DECL_CHAIN (newarg))
1810 : {
1811 28657871 : DECL_ATTRIBUTES (newarg)
1812 28657871 : = (*targetm.merge_decl_attributes) (oldarg, newarg);
1813 28657871 : if (lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (newarg))
1814 28657940 : && !lookup_attribute (NULL, "indeterminate",
1815 69 : DECL_ATTRIBUTES (oldarg)))
1816 : {
1817 18 : auto_diagnostic_group d;
1818 18 : error_at (DECL_SOURCE_LOCATION (newarg),
1819 : "%<indeterminate%> attribute not specified for parameter "
1820 : "%qD on the first declaration of its function", newarg);
1821 18 : inform (DECL_SOURCE_LOCATION (oldarg), "earlier declaration");
1822 18 : }
1823 : /* ??? Should attributes propagate out from a block extern? If so,
1824 : we should do that for the function itself, not just parameters. */
1825 28657871 : if (!extern_alias || flag_reflection)
1826 28657704 : DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1827 28657871 : if (!flag_reflection)
1828 28250095 : continue;
1829 : /* For extern_alias set DECL_HAS_DEFAULT_ARGUMENT_P on oldarg
1830 : if the local extern has a default argument for that parameter. */
1831 407776 : if (extern_alias)
1832 : {
1833 36 : if (newarg == first_user_parm)
1834 12 : type = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1835 24 : else if (type)
1836 24 : type = TREE_CHAIN (type);
1837 72 : if (type && TREE_PURPOSE (type))
1838 4 : DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
1839 : }
1840 : else
1841 : {
1842 : /* Otherwise propagate the flag. */
1843 407740 : if (DECL_HAS_DEFAULT_ARGUMENT_P (oldarg))
1844 0 : DECL_HAS_DEFAULT_ARGUMENT_P (newarg) = 1;
1845 407740 : if (DECL_HAS_DEFAULT_ARGUMENT_P (newarg))
1846 0 : DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
1847 : }
1848 : /* Merge names for std::meta::has_identifier and
1849 : std::meta::{,u8}identifier_of purposes. If they are different and
1850 : both oldarg and newarg are named, add flag to force that
1851 : std::meta::has_identifier returns false. If one is named and one is
1852 : unnamed, if neither is a olddecl nor newdecl is definition, propagate
1853 : DECL_NAME to both. Otherwise stash the old name into "old parm name"
1854 : artificial attribute. */
1855 407776 : if (DECL_NAME (oldarg) != DECL_NAME (newarg))
1856 : {
1857 45490 : if (DECL_NAME (oldarg) && DECL_NAME (newarg))
1858 : {
1859 : /* Different names. */
1860 10250 : MULTIPLE_NAMES_PARM_P (oldarg) = 1;
1861 10250 : MULTIPLE_NAMES_PARM_P (newarg) = 1;
1862 : }
1863 35240 : else if (!new_defines_function
1864 35240 : && types_match
1865 35240 : && DECL_INITIAL (olddecl) == NULL_TREE)
1866 : {
1867 : /* For 2 non-definitions with matching types, one is named and
1868 : one unnamed, propagate name to both. */
1869 6654 : if (DECL_NAME (oldarg))
1870 5574 : DECL_NAME (newarg) = DECL_NAME (oldarg);
1871 : else
1872 1080 : DECL_NAME (oldarg) = DECL_NAME (newarg);
1873 : }
1874 : /* Depending on which PARM_DECL we'll keep, look at the other
1875 : PARM_DECL's name. */
1876 28586 : else if (tree name = ((new_defines_function || !types_match)
1877 28586 : ? DECL_NAME (oldarg) : DECL_NAME (newarg)))
1878 : {
1879 234 : tree opn = lookup_attribute ("old parm name",
1880 234 : DECL_ATTRIBUTES (oldarg));
1881 234 : if (opn)
1882 : {
1883 4 : if (TREE_VALUE (TREE_VALUE (opn)) == name)
1884 : /* Name already in "old parm name" attribute. */;
1885 : else
1886 : {
1887 : /* Different names. */
1888 0 : MULTIPLE_NAMES_PARM_P (oldarg) = 1;
1889 0 : MULTIPLE_NAMES_PARM_P (newarg) = 1;
1890 : }
1891 : }
1892 : else
1893 : {
1894 : /* Save name into attribute. */
1895 230 : DECL_ATTRIBUTES (newarg)
1896 230 : = tree_cons (get_identifier ("old parm name"),
1897 : tree_cons (NULL_TREE, name, NULL_TREE),
1898 230 : DECL_ATTRIBUTES (newarg));
1899 230 : DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1900 : }
1901 : }
1902 28352 : else if (extern_alias)
1903 2 : DECL_NAME (newarg) = DECL_NAME (oldarg);
1904 : }
1905 : }
1906 15859580 : }
1907 :
1908 : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
1909 : If the redeclaration is invalid, a diagnostic is issued, and the
1910 : error_mark_node is returned. Otherwise, OLDDECL is returned.
1911 :
1912 : If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
1913 : returned.
1914 :
1915 : HIDING is true if the new decl is being hidden. WAS_HIDDEN is true
1916 : if the old decl was hidden.
1917 :
1918 : Hidden decls can be anticipated builtins, injected friends, or
1919 : (coming soon) injected from a local-extern decl. */
1920 :
1921 : tree
1922 338564714 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
1923 : {
1924 338713877 : unsigned olddecl_uid = DECL_UID (olddecl);
1925 338713877 : int types_match = 0;
1926 338713877 : int new_defines_function = 0;
1927 338713877 : tree new_template_info;
1928 338713877 : location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
1929 338713877 : location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
1930 :
1931 338713877 : if (newdecl == olddecl)
1932 : return olddecl;
1933 :
1934 337850230 : types_match = decls_match (newdecl, olddecl);
1935 :
1936 : /* If either the type of the new decl or the type of the old decl is an
1937 : error_mark_node, then that implies that we have already issued an
1938 : error (earlier) for some bogus type specification, and in that case,
1939 : it is rather pointless to harass the user with yet more error message
1940 : about the same declaration, so just pretend the types match here. */
1941 337850230 : if (TREE_TYPE (newdecl) == error_mark_node
1942 337850230 : || TREE_TYPE (olddecl) == error_mark_node)
1943 : return error_mark_node;
1944 :
1945 : /* Check for redeclaration and other discrepancies. */
1946 337850204 : if (TREE_CODE (olddecl) == FUNCTION_DECL
1947 337850204 : && DECL_IS_UNDECLARED_BUILTIN (olddecl))
1948 : {
1949 6482899 : if (TREE_CODE (newdecl) != FUNCTION_DECL)
1950 : {
1951 : /* Avoid warnings redeclaring built-ins which have not been
1952 : explicitly declared. */
1953 203173 : if (was_hidden)
1954 : {
1955 203015 : if (TREE_PUBLIC (newdecl)
1956 203015 : && CP_DECL_CONTEXT (newdecl) == global_namespace)
1957 12 : warning_at (newdecl_loc,
1958 12 : OPT_Wbuiltin_declaration_mismatch,
1959 : "built-in function %qD declared as non-function",
1960 : newdecl);
1961 : return NULL_TREE;
1962 : }
1963 :
1964 : /* If you declare a built-in or predefined function name as static,
1965 : the old definition is overridden, but optionally warn this was a
1966 : bad choice of name. */
1967 158 : if (! TREE_PUBLIC (newdecl))
1968 : {
1969 158 : warning_at (newdecl_loc,
1970 158 : OPT_Wshadow,
1971 158 : fndecl_built_in_p (olddecl)
1972 : ? G_("shadowing built-in function %q#D")
1973 : : G_("shadowing library function %q#D"), olddecl);
1974 : /* Discard the old built-in function. */
1975 158 : return NULL_TREE;
1976 : }
1977 : /* If the built-in is not ansi, then programs can override
1978 : it even globally without an error. */
1979 0 : else if (! fndecl_built_in_p (olddecl))
1980 0 : warning_at (newdecl_loc, 0,
1981 : "library function %q#D redeclared as non-function %q#D",
1982 : olddecl, newdecl);
1983 : else
1984 0 : error_at (newdecl_loc,
1985 : "declaration of %q#D conflicts with built-in "
1986 : "declaration %q#D", newdecl, olddecl);
1987 : return NULL_TREE;
1988 : }
1989 6279726 : else if (!types_match)
1990 : {
1991 : /* Avoid warnings redeclaring built-ins which have not been
1992 : explicitly declared. */
1993 2256999 : if (was_hidden)
1994 : {
1995 816881 : tree t1, t2;
1996 :
1997 : /* A new declaration doesn't match a built-in one unless it
1998 : is also extern "C". */
1999 816881 : gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
2000 816881 : gcc_assert (DECL_EXTERN_C_P (olddecl));
2001 816881 : if (!DECL_EXTERN_C_P (newdecl))
2002 : return NULL_TREE;
2003 :
2004 149364 : for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2005 149364 : t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2006 257792 : t1 || t2;
2007 108428 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
2008 : {
2009 257774 : if (!t1 || !t2)
2010 : break;
2011 : /* FILE, tm types are not known at the time
2012 : we create the builtins. */
2013 794420 : for (unsigned i = 0;
2014 1052032 : i < sizeof (builtin_structptr_types)
2015 : / sizeof (builtin_structptr_type);
2016 : ++i)
2017 943598 : if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
2018 : {
2019 149178 : tree t = TREE_VALUE (t1);
2020 :
2021 149178 : if (TYPE_PTR_P (t)
2022 298356 : && TYPE_IDENTIFIER (TREE_TYPE (t))
2023 149178 : == get_identifier (builtin_structptr_types[i].str)
2024 298341 : && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
2025 : {
2026 149163 : tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2027 :
2028 149163 : TYPE_ARG_TYPES (TREE_TYPE (olddecl))
2029 149163 : = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
2030 149163 : types_match = decls_match (newdecl, olddecl);
2031 149163 : if (types_match)
2032 : return duplicate_decls (newdecl, olddecl,
2033 : hiding, was_hidden);
2034 0 : TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
2035 : }
2036 15 : goto next_arg;
2037 : }
2038 :
2039 108434 : if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
2040 : break;
2041 108428 : next_arg:;
2042 : }
2043 :
2044 201 : warning_at (newdecl_loc,
2045 201 : OPT_Wbuiltin_declaration_mismatch,
2046 : "declaration of %q#D conflicts with built-in "
2047 : "declaration %q#D", newdecl, olddecl);
2048 : }
2049 1440118 : else if ((DECL_EXTERN_C_P (newdecl)
2050 15 : && DECL_EXTERN_C_P (olddecl))
2051 2880221 : || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2052 1440103 : TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
2053 : {
2054 : /* Don't really override olddecl for __* prefixed builtins
2055 : except for __[^b]*_chk, the compiler might be using those
2056 : explicitly. */
2057 15 : if (fndecl_built_in_p (olddecl))
2058 : {
2059 15 : tree id = DECL_NAME (olddecl);
2060 15 : const char *name = IDENTIFIER_POINTER (id);
2061 15 : size_t len;
2062 :
2063 15 : if (name[0] == '_'
2064 15 : && name[1] == '_'
2065 30 : && (startswith (name + 2, "builtin_")
2066 6 : || (len = strlen (name)) <= strlen ("___chk")
2067 6 : || memcmp (name + len - strlen ("_chk"),
2068 : "_chk", strlen ("_chk") + 1) != 0))
2069 : {
2070 15 : if (DECL_INITIAL (newdecl))
2071 : {
2072 6 : error_at (newdecl_loc,
2073 : "definition of %q#D ambiguates built-in "
2074 : "declaration %q#D", newdecl, olddecl);
2075 6 : return error_mark_node;
2076 : }
2077 9 : auto_diagnostic_group d;
2078 9 : if (permerror (newdecl_loc,
2079 : "new declaration %q#D ambiguates built-in"
2080 : " declaration %q#D", newdecl, olddecl)
2081 9 : && flag_permissive)
2082 3 : inform (newdecl_loc,
2083 : "ignoring the %q#D declaration", newdecl);
2084 9 : return flag_permissive ? olddecl : error_mark_node;
2085 9 : }
2086 : }
2087 :
2088 : /* A near match; override the builtin. */
2089 :
2090 0 : if (TREE_PUBLIC (newdecl))
2091 0 : warning_at (newdecl_loc,
2092 0 : OPT_Wbuiltin_declaration_mismatch,
2093 : "new declaration %q#D ambiguates built-in "
2094 : "declaration %q#D", newdecl, olddecl);
2095 : else
2096 0 : warning (OPT_Wshadow,
2097 : fndecl_built_in_p (olddecl)
2098 : ? G_("shadowing built-in function %q#D")
2099 : : G_("shadowing library function %q#D"), olddecl);
2100 : }
2101 : else
2102 : /* Discard the old built-in function. */
2103 : return NULL_TREE;
2104 :
2105 : /* Replace the old RTL to avoid problems with inlining. */
2106 201 : COPY_DECL_RTL (newdecl, olddecl);
2107 : }
2108 : else
2109 : {
2110 : /* Even if the types match, prefer the new declarations type
2111 : for built-ins which have not been explicitly declared,
2112 : for exception lists, etc... */
2113 4022727 : tree type = TREE_TYPE (newdecl);
2114 4022727 : tree attribs = (*targetm.merge_type_attributes)
2115 4022727 : (TREE_TYPE (olddecl), type);
2116 :
2117 4022727 : type = cp_build_type_attribute_variant (type, attribs);
2118 4022727 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
2119 : }
2120 :
2121 : /* If a function is explicitly declared "throw ()", propagate that to
2122 : the corresponding builtin. */
2123 4022928 : if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
2124 3848859 : && was_hidden
2125 3848816 : && TREE_NOTHROW (newdecl)
2126 7598188 : && !TREE_NOTHROW (olddecl))
2127 : {
2128 28159 : enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
2129 28159 : tree tmpdecl = builtin_decl_explicit (fncode);
2130 28159 : if (tmpdecl && tmpdecl != olddecl && types_match)
2131 28159 : TREE_NOTHROW (tmpdecl) = 1;
2132 : }
2133 :
2134 : /* Whether or not the builtin can throw exceptions has no
2135 : bearing on this declarator. */
2136 4022928 : TREE_NOTHROW (olddecl) = 0;
2137 :
2138 4022928 : if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
2139 : {
2140 : /* If a builtin function is redeclared as `static', merge
2141 : the declarations, but make the original one static. */
2142 3 : DECL_THIS_STATIC (olddecl) = 1;
2143 3 : TREE_PUBLIC (olddecl) = 0;
2144 :
2145 : /* Make the old declaration consistent with the new one so
2146 : that all remnants of the builtin-ness of this function
2147 : will be banished. */
2148 3 : SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
2149 3 : COPY_DECL_RTL (newdecl, olddecl);
2150 : }
2151 : }
2152 331367305 : else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2153 : {
2154 : /* C++ Standard, 3.3, clause 4:
2155 : "[Note: a namespace name or a class template name must be unique
2156 : in its declarative region (7.3.2, clause 14). ]" */
2157 73996265 : if (TREE_CODE (olddecl) == NAMESPACE_DECL
2158 73996238 : || TREE_CODE (newdecl) == NAMESPACE_DECL)
2159 : /* Namespace conflicts with not namespace. */;
2160 36199974 : else if (DECL_TYPE_TEMPLATE_P (olddecl)
2161 110196200 : || DECL_TYPE_TEMPLATE_P (newdecl))
2162 : /* Class template conflicts. */;
2163 73996220 : else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
2164 36199974 : && DECL_TEMPLATE_RESULT (olddecl)
2165 36199974 : && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
2166 110196188 : || (TREE_CODE (newdecl) == TEMPLATE_DECL
2167 37746842 : && DECL_TEMPLATE_RESULT (newdecl)
2168 37746842 : && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
2169 : /* Variable template conflicts. */;
2170 73996211 : else if (concept_definition_p (olddecl)
2171 147992416 : || concept_definition_p (newdecl))
2172 : /* Concept conflicts. */;
2173 73996199 : else if ((TREE_CODE (newdecl) == FUNCTION_DECL
2174 36239524 : && DECL_FUNCTION_TEMPLATE_P (olddecl))
2175 74035761 : || (TREE_CODE (olddecl) == FUNCTION_DECL
2176 37746855 : && DECL_FUNCTION_TEMPLATE_P (newdecl)))
2177 : {
2178 : /* One is a function and the other is a template
2179 : function. */
2180 73946780 : if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
2181 : return NULL_TREE;
2182 :
2183 : /* There can only be one! */
2184 58405 : auto_diagnostic_group d;
2185 58405 : if (TREE_CODE (newdecl) == TEMPLATE_DECL
2186 58405 : && check_raw_literal_operator (olddecl))
2187 3 : error_at (newdecl_loc,
2188 : "literal operator %q#D conflicts with"
2189 : " raw literal operator", newdecl);
2190 58402 : else if (check_raw_literal_operator (newdecl))
2191 3 : error_at (newdecl_loc,
2192 : "raw literal operator %q#D conflicts with"
2193 : " literal operator template", newdecl);
2194 : else
2195 : return NULL_TREE;
2196 :
2197 6 : inform (olddecl_loc, "previous declaration %q#D", olddecl);
2198 6 : return error_mark_node;
2199 58405 : }
2200 49419 : else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
2201 : /* A structured binding must be unique in its declarative region. */;
2202 39712 : else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
2203 49416 : || DECL_IMPLICIT_TYPEDEF_P (newdecl))
2204 : /* One is an implicit typedef, that's ok. */
2205 : return NULL_TREE;
2206 :
2207 153 : auto_diagnostic_group d;
2208 153 : error ("%q#D redeclared as different kind of entity", newdecl);
2209 153 : inform (olddecl_loc, "previous declaration %q#D", olddecl);
2210 :
2211 153 : return error_mark_node;
2212 153 : }
2213 257371040 : else if (!types_match)
2214 : {
2215 240724366 : if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
2216 : /* These are certainly not duplicate declarations; they're
2217 : from different scopes. */
2218 : return NULL_TREE;
2219 :
2220 240724306 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2221 : {
2222 151262168 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
2223 151262168 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
2224 :
2225 : /* The name of a class template may not be declared to refer to
2226 : any other template, class, function, object, namespace, value,
2227 : or type in the same scope. */
2228 151262168 : if (TREE_CODE (oldres) == TYPE_DECL
2229 151262162 : || TREE_CODE (newres) == TYPE_DECL)
2230 : {
2231 9 : auto_diagnostic_group d;
2232 9 : error_at (newdecl_loc,
2233 : "conflicting declaration of template %q#D", newdecl);
2234 9 : inform (olddecl_loc,
2235 : "previous declaration %q#D", olddecl);
2236 9 : return error_mark_node;
2237 9 : }
2238 :
2239 151262159 : else if (TREE_CODE (oldres) == FUNCTION_DECL
2240 151262150 : && TREE_CODE (newres) == FUNCTION_DECL)
2241 : {
2242 151262150 : if (duplicate_function_template_decls (newdecl, olddecl))
2243 0 : return error_mark_node;
2244 : return NULL_TREE;
2245 : }
2246 : return NULL_TREE;
2247 : }
2248 89462138 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2249 : {
2250 89461981 : if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
2251 : {
2252 57 : auto_diagnostic_group d;
2253 57 : error_at (newdecl_loc,
2254 : "conflicting declaration of C function %q#D",
2255 : newdecl);
2256 57 : inform (olddecl_loc,
2257 : "previous declaration %q#D", olddecl);
2258 57 : return error_mark_node;
2259 57 : }
2260 : /* For function versions, params and types match, but they
2261 : are not ambiguous. */
2262 89461924 : else if (((!DECL_FUNCTION_VERSIONED (newdecl)
2263 89453590 : && !DECL_FUNCTION_VERSIONED (olddecl))
2264 8379 : || !same_type_p (fndecl_declared_return_type (newdecl),
2265 : fndecl_declared_return_type (olddecl)))
2266 : /* Let constrained hidden friends coexist for now, we'll
2267 : check satisfaction later. */
2268 89453545 : && !member_like_constrained_friend_p (newdecl)
2269 81901783 : && !member_like_constrained_friend_p (olddecl)
2270 : // The functions have the same parameter types.
2271 80160926 : && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2272 80160926 : TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
2273 : // And the same constraints.
2274 89461993 : && equivalently_constrained (newdecl, olddecl))
2275 : {
2276 69 : auto_diagnostic_group d;
2277 69 : error_at (newdecl_loc,
2278 : "ambiguating new declaration of %q#D", newdecl);
2279 69 : inform (olddecl_loc,
2280 : "old declaration %q#D", olddecl);
2281 69 : return error_mark_node;
2282 69 : }
2283 : else
2284 : return NULL_TREE;
2285 : }
2286 : else
2287 : {
2288 157 : auto_diagnostic_group d;
2289 157 : error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
2290 157 : inform (olddecl_loc,
2291 : "previous declaration as %q#D", olddecl);
2292 157 : return error_mark_node;
2293 157 : }
2294 : }
2295 16646674 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2296 16646674 : && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
2297 : {
2298 : /* OMP UDRs are never duplicates. */
2299 33 : gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
2300 33 : auto_diagnostic_group d;
2301 33 : error_at (newdecl_loc,
2302 : "redeclaration of %<pragma omp declare reduction%>");
2303 33 : inform (olddecl_loc,
2304 : "previous %<pragma omp declare reduction%> declaration");
2305 33 : return error_mark_node;
2306 33 : }
2307 16646641 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2308 16646641 : && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
2309 224 : && (!DECL_TEMPLATE_INFO (newdecl)
2310 224 : || (DECL_TI_TEMPLATE (newdecl)
2311 224 : != DECL_TI_TEMPLATE (olddecl))))
2312 11836748 : || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
2313 581792 : && (!DECL_TEMPLATE_INFO (olddecl)
2314 581792 : || (DECL_TI_TEMPLATE (olddecl)
2315 581792 : != DECL_TI_TEMPLATE (newdecl))))))
2316 : /* It's OK to have a template specialization and a non-template
2317 : with the same type, or to have specializations of two
2318 : different templates with the same type. Note that if one is a
2319 : specialization, and the other is an instantiation of the same
2320 : template, that we do not exit at this point. That situation
2321 : can occur if we instantiate a template class, and then
2322 : specialize one of its methods. This situation is valid, but
2323 : the declarations must be merged in the usual way. */
2324 : return NULL_TREE;
2325 16646641 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2326 16646641 : && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
2327 666726 : && !DECL_USE_TEMPLATE (newdecl))
2328 11836748 : || (DECL_TEMPLATE_INSTANTIATION (newdecl)
2329 85158 : && !DECL_USE_TEMPLATE (olddecl))))
2330 : /* One of the declarations is a template instantiation, and the
2331 : other is not a template at all. That's OK. */
2332 : return NULL_TREE;
2333 16646641 : else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2334 : {
2335 : /* In [namespace.alias] we have:
2336 :
2337 : In a declarative region, a namespace-alias-definition can be
2338 : used to redefine a namespace-alias declared in that declarative
2339 : region to refer only to the namespace to which it already
2340 : refers.
2341 :
2342 : Therefore, if we encounter a second alias directive for the same
2343 : alias, we can just ignore the second directive. */
2344 30 : if (DECL_NAMESPACE_ALIAS (newdecl)
2345 30 : && (DECL_NAMESPACE_ALIAS (newdecl)
2346 27 : == DECL_NAMESPACE_ALIAS (olddecl)))
2347 21 : return olddecl;
2348 :
2349 : /* Leave it to update_binding to merge or report error. */
2350 : return NULL_TREE;
2351 : }
2352 : /* Check if the two decls are non-mergeable versioned decls. */
2353 16646611 : else if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
2354 : && diagnose_versioned_decls (olddecl, newdecl))
2355 : return error_mark_node;
2356 : else
2357 : {
2358 16646611 : const char *errmsg = redeclaration_error_message (newdecl, olddecl);
2359 16646611 : if (errmsg)
2360 : {
2361 621 : auto_diagnostic_group d;
2362 621 : error_at (newdecl_loc, errmsg, newdecl);
2363 621 : if (DECL_NAME (olddecl) != NULL_TREE)
2364 621 : inform (olddecl_loc,
2365 621 : (DECL_INITIAL (olddecl) && namespace_bindings_p ())
2366 : ? G_("%q#D previously defined here")
2367 : : G_("%q#D previously declared here"), olddecl);
2368 621 : if (cxx_dialect >= cxx26
2369 147 : && DECL_NAME (newdecl)
2370 147 : && id_equal (DECL_NAME (newdecl), "_")
2371 634 : && !name_independent_decl_p (newdecl))
2372 : {
2373 13 : if (TREE_CODE (newdecl) == PARM_DECL)
2374 2 : inform (newdecl_loc,
2375 : "parameter declaration is not name-independent");
2376 11 : else if (DECL_DECOMPOSITION_P (newdecl))
2377 : {
2378 3 : if (at_namespace_scope_p ())
2379 2 : inform (newdecl_loc,
2380 : "structured binding at namespace scope is not "
2381 : "name-independent");
2382 1 : else if (TREE_STATIC (newdecl))
2383 1 : inform (newdecl_loc,
2384 : "static structured binding is not "
2385 : "name-independent");
2386 0 : else if (DECL_EXTERNAL (newdecl))
2387 0 : inform (newdecl_loc,
2388 : "extern structured binding is not "
2389 : "name-independent");
2390 : }
2391 8 : else if (at_class_scope_p ()
2392 0 : && VAR_P (newdecl)
2393 8 : && TREE_STATIC (newdecl))
2394 0 : inform (newdecl_loc,
2395 : "static data member is not name-independent");
2396 8 : else if (VAR_P (newdecl) && at_namespace_scope_p ())
2397 3 : inform (newdecl_loc,
2398 : "variable at namespace scope is not name-independent");
2399 5 : else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
2400 3 : inform (newdecl_loc,
2401 : "static variable is not name-independent");
2402 2 : else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
2403 0 : inform (newdecl_loc,
2404 : "extern variable is not name-independent");
2405 : }
2406 621 : return error_mark_node;
2407 621 : }
2408 16645990 : else if (TREE_CODE (olddecl) == FUNCTION_DECL
2409 11836508 : && DECL_INITIAL (olddecl) != NULL_TREE
2410 17592 : && !prototype_p (TREE_TYPE (olddecl))
2411 16645990 : && prototype_p (TREE_TYPE (newdecl)))
2412 : {
2413 : /* Prototype decl follows defn w/o prototype. */
2414 0 : auto_diagnostic_group d;
2415 0 : if (warning_at (newdecl_loc, 0,
2416 : "prototype specified for %q#D", newdecl))
2417 0 : inform (olddecl_loc,
2418 : "previous non-prototype definition here");
2419 0 : }
2420 16119415 : else if (VAR_OR_FUNCTION_DECL_P (olddecl)
2421 28482498 : && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2422 : {
2423 : /* [dcl.link]
2424 : If two declarations of the same function or object
2425 : specify different linkage-specifications ..., the program
2426 : is ill-formed.... Except for functions with C++ linkage,
2427 : a function declaration without a linkage specification
2428 : shall not precede the first linkage specification for
2429 : that function. A function can be declared without a
2430 : linkage specification after an explicit linkage
2431 : specification has been seen; the linkage explicitly
2432 : specified in the earlier declaration is not affected by
2433 : such a function declaration.
2434 :
2435 : DR 563 raises the question why the restrictions on
2436 : functions should not also apply to objects. Older
2437 : versions of G++ silently ignore the linkage-specification
2438 : for this example:
2439 :
2440 : namespace N {
2441 : extern int i;
2442 : extern "C" int i;
2443 : }
2444 :
2445 : which is clearly wrong. Therefore, we now treat objects
2446 : like functions. */
2447 1889 : if (current_lang_depth () == 0)
2448 : {
2449 : /* There is no explicit linkage-specification, so we use
2450 : the linkage from the previous declaration. */
2451 1877 : retrofit_lang_decl (newdecl);
2452 1877 : SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
2453 : }
2454 : else
2455 : {
2456 12 : auto_diagnostic_group d;
2457 12 : error_at (newdecl_loc,
2458 : "conflicting declaration of %q#D with %qL linkage",
2459 12 : newdecl, DECL_LANGUAGE (newdecl));
2460 12 : inform (olddecl_loc,
2461 : "previous declaration with %qL linkage",
2462 12 : DECL_LANGUAGE (olddecl));
2463 12 : }
2464 : }
2465 :
2466 16645990 : if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
2467 : ;
2468 15957948 : else if (TREE_CODE (olddecl) == FUNCTION_DECL)
2469 : {
2470 : /* Note: free functions, as TEMPLATE_DECLs, are handled below. */
2471 14050285 : if (DECL_FUNCTION_MEMBER_P (olddecl)
2472 11169567 : && (/* grokfndecl passes member function templates too
2473 : as FUNCTION_DECLs. */
2474 8471605 : DECL_TEMPLATE_INFO (olddecl)
2475 : /* C++11 8.3.6/6.
2476 : Default arguments for a member function of a class
2477 : template shall be specified on the initial declaration
2478 : of the member function within the class template. */
2479 712596 : || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
2480 : {
2481 7840185 : check_redeclaration_no_default_args (newdecl);
2482 :
2483 7840185 : if (DECL_TEMPLATE_INFO (olddecl)
2484 7840185 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
2485 : {
2486 2337463 : tree new_parms = DECL_TEMPLATE_INFO (newdecl)
2487 2337463 : ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
2488 2337463 : : INNERMOST_TEMPLATE_PARMS (current_template_parms);
2489 2337463 : tree old_parms
2490 2337463 : = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
2491 2337463 : merge_default_template_args (new_parms, old_parms,
2492 : /*class_p=*/false);
2493 : }
2494 : }
2495 : else
2496 : {
2497 3329382 : tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
2498 3329382 : tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
2499 3329382 : int i = 1;
2500 :
2501 12010798 : for (; t1 && t1 != void_list_node;
2502 5352034 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
2503 5354049 : if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
2504 : {
2505 57 : if (simple_cst_equal (TREE_PURPOSE (t1),
2506 57 : TREE_PURPOSE (t2)) == 1)
2507 : {
2508 24 : auto_diagnostic_group d;
2509 24 : if (permerror (newdecl_loc,
2510 : "default argument given for parameter "
2511 : "%d of %q#D", i, newdecl))
2512 24 : inform (olddecl_loc,
2513 : "previous specification in %q#D here",
2514 : olddecl);
2515 24 : }
2516 : else
2517 : {
2518 33 : auto_diagnostic_group d;
2519 33 : error_at (newdecl_loc,
2520 : "default argument given for parameter %d "
2521 : "of %q#D", i, newdecl);
2522 33 : inform (olddecl_loc,
2523 : "previous specification in %q#D here",
2524 : olddecl);
2525 33 : }
2526 : }
2527 :
2528 : /* C++17 11.3.6/4: "If a friend declaration specifies a default
2529 : argument expression, that declaration... shall be the only
2530 : declaration of the function or function template in the
2531 : translation unit." */
2532 3329382 : check_no_redeclaration_friend_default_args (olddecl, newdecl);
2533 : }
2534 : }
2535 : }
2536 :
2537 : /* Do not merge an implicit typedef with an explicit one. In:
2538 :
2539 : class A;
2540 : ...
2541 : typedef class A A __attribute__ ((foo));
2542 :
2543 : the attribute should apply only to the typedef. */
2544 20668918 : if (TREE_CODE (olddecl) == TYPE_DECL
2545 20668918 : && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
2546 50204 : || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
2547 : return NULL_TREE;
2548 :
2549 20635134 : if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
2550 : return NULL_TREE;
2551 :
2552 20635122 : if (!validate_constexpr_redeclaration (olddecl, newdecl))
2553 30 : return error_mark_node;
2554 :
2555 20635092 : if (modules_p ()
2556 64009 : && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
2557 20672740 : && TREE_CODE (olddecl) != NAMESPACE_DECL)
2558 : {
2559 37648 : if (!module_may_redeclare (olddecl, newdecl))
2560 24 : return error_mark_node;
2561 :
2562 37624 : if (!hiding)
2563 : {
2564 : /* The old declaration should match the exportingness of the new
2565 : declaration. But hidden friend declarations just keep the
2566 : exportingness of the old declaration; see CWG2588. */
2567 33110 : tree not_tmpl = STRIP_TEMPLATE (olddecl);
2568 33110 : if (DECL_LANG_SPECIFIC (not_tmpl)
2569 32998 : && DECL_MODULE_ATTACH_P (not_tmpl)
2570 : /* Typedefs are not entities and so are OK to be redeclared
2571 : as exported: see [module.interface]/p6. */
2572 33301 : && TREE_CODE (olddecl) != TYPE_DECL)
2573 : {
2574 179 : if (DECL_MODULE_EXPORT_P (newdecl)
2575 179 : && !DECL_MODULE_EXPORT_P (not_tmpl))
2576 : {
2577 15 : auto_diagnostic_group d;
2578 15 : error ("conflicting exporting for declaration %qD", newdecl);
2579 15 : inform (olddecl_loc,
2580 : "previously declared here without exporting");
2581 15 : }
2582 : }
2583 32931 : else if (DECL_MODULE_EXPORT_P (newdecl))
2584 10473 : DECL_MODULE_EXPORT_P (not_tmpl) = true;
2585 : }
2586 : }
2587 :
2588 : /* We have committed to returning OLDDECL at this point. */
2589 :
2590 : /* If new decl is `static' and an `extern' was seen previously,
2591 : warn about it. */
2592 20635068 : warn_extern_redeclared_static (newdecl, olddecl);
2593 :
2594 : /* True to merge attributes between the declarations, false to
2595 : set OLDDECL's attributes to those of NEWDECL (for template
2596 : explicit specializations that specify their own attributes
2597 : independent of those specified for the primary template). */
2598 20635068 : const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
2599 15859391 : || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
2600 21216845 : || DECL_TEMPLATE_SPECIALIZATION (olddecl));
2601 :
2602 20635068 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2603 : {
2604 15859391 : if (merge_attr)
2605 : {
2606 15277823 : {
2607 15277823 : auto_diagnostic_group d;
2608 15277823 : if (diagnose_mismatched_attributes (olddecl, newdecl))
2609 36 : inform (olddecl_loc, DECL_INITIAL (olddecl)
2610 : ? G_("previous definition of %qD here")
2611 : : G_("previous declaration of %qD here"), olddecl);
2612 15277823 : }
2613 :
2614 : /* [dcl.attr.noreturn]: The first declaration of a function shall
2615 : specify the noreturn attribute if any declaration of that function
2616 : specifies the noreturn attribute. */
2617 15277823 : tree a;
2618 15277823 : if (TREE_THIS_VOLATILE (newdecl)
2619 100147 : && !TREE_THIS_VOLATILE (olddecl)
2620 : /* This applies to [[noreturn]] only, not its GNU variants. */
2621 76 : && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
2622 54 : && cxx11_attribute_p (a)
2623 15277844 : && get_attribute_namespace (a) == NULL_TREE)
2624 : {
2625 9 : auto_diagnostic_group d;
2626 9 : error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
2627 : "but its first declaration was not", newdecl);
2628 9 : inform (olddecl_loc, "previous declaration of %qD", olddecl);
2629 9 : }
2630 : }
2631 :
2632 : /* Now that functions must hold information normally held
2633 : by field decls, there is extra work to do so that
2634 : declaration information does not get destroyed during
2635 : definition. */
2636 15859391 : if (DECL_VINDEX (olddecl))
2637 163219 : DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2638 15859391 : if (DECL_CONTEXT (olddecl))
2639 15859391 : DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2640 15859391 : DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
2641 15859391 : DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2642 15859391 : DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
2643 15859391 : DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
2644 15859391 : DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
2645 15859391 : DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
2646 15859391 : DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
2647 15859391 : DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
2648 15859391 : DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
2649 15859391 : |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
2650 15859391 : if (DECL_OVERLOADED_OPERATOR_P (olddecl))
2651 2807693 : DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
2652 5615386 : = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
2653 15859391 : new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
2654 :
2655 15859391 : check_redecl_contract (newdecl, olddecl);
2656 :
2657 : /* Optionally warn about more than one declaration for the same
2658 : name, but don't warn about a function declaration followed by a
2659 : definition. */
2660 27 : if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
2661 27 : && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2662 : /* Don't warn about extern decl followed by definition. */
2663 27 : && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
2664 : /* Don't warn if at least one is/was hidden. */
2665 27 : && !(hiding || was_hidden)
2666 : /* Don't warn about declaration followed by specialization. */
2667 15859403 : && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
2668 9 : || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
2669 : {
2670 6 : auto_diagnostic_group d;
2671 6 : if (warning_at (newdecl_loc,
2672 6 : OPT_Wredundant_decls,
2673 : "redundant redeclaration of %qD in same scope",
2674 : newdecl))
2675 6 : inform (olddecl_loc,
2676 : "previous declaration of %qD", olddecl);
2677 6 : }
2678 :
2679 : /* [dcl.fct.def.delete] A deleted definition of a function shall be the
2680 : first declaration of the function or, for an explicit specialization
2681 : of a function template, the first declaration of that
2682 : specialization. */
2683 15859391 : if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
2684 666726 : && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
2685 : {
2686 15277823 : if (DECL_DELETED_FN (newdecl))
2687 : {
2688 21 : auto_diagnostic_group d;
2689 21 : if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
2690 : "is not first declaration", newdecl))
2691 21 : inform (olddecl_loc,
2692 : "previous declaration of %qD", olddecl);
2693 21 : }
2694 15277823 : DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
2695 15277823 : if (DECL_DELETED_FN (olddecl)
2696 6 : && DECL_INITIAL (olddecl)
2697 15277829 : && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
2698 3 : DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2699 : }
2700 : }
2701 :
2702 : /* Deal with C++: must preserve virtual function table size. */
2703 20635068 : if (TREE_CODE (olddecl) == TYPE_DECL)
2704 : {
2705 50201 : tree newtype = TREE_TYPE (newdecl);
2706 50201 : tree oldtype = TREE_TYPE (olddecl);
2707 :
2708 50201 : if (newtype != error_mark_node && oldtype != error_mark_node
2709 100402 : && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2710 138567 : CLASSTYPE_FRIEND_CLASSES (newtype)
2711 46189 : = CLASSTYPE_FRIEND_CLASSES (oldtype);
2712 :
2713 50201 : DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
2714 : }
2715 :
2716 : /* Copy all the DECL_... slots specified in the new decl except for
2717 : any that we copy here from the old type. */
2718 20635068 : if (merge_attr)
2719 20053500 : DECL_ATTRIBUTES (newdecl)
2720 40107000 : = (*targetm.merge_decl_attributes) (olddecl, newdecl);
2721 : else
2722 581568 : DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2723 :
2724 : /* Transfer purviewness and importingness to the old decl. */
2725 20635068 : transfer_defining_module (olddecl, newdecl);
2726 :
2727 20635068 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2728 : {
2729 4198901 : tree old_result = DECL_TEMPLATE_RESULT (olddecl);
2730 4198901 : tree new_result = DECL_TEMPLATE_RESULT (newdecl);
2731 4198901 : TREE_TYPE (olddecl) = TREE_TYPE (old_result);
2732 :
2733 : /* The new decl should not already have gathered any
2734 : specializations. */
2735 4198901 : gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
2736 :
2737 : /* Make sure the contracts are equivalent. */
2738 4198901 : check_redecl_contract (newdecl, olddecl);
2739 :
2740 4198901 : DECL_ATTRIBUTES (old_result)
2741 4198901 : = (*targetm.merge_decl_attributes) (old_result, new_result);
2742 :
2743 4198901 : if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2744 : {
2745 4198871 : if (DECL_SOURCE_LOCATION (newdecl)
2746 4198871 : != DECL_SOURCE_LOCATION (olddecl))
2747 : {
2748 : /* Per C++11 8.3.6/4, default arguments cannot be added in
2749 : later declarations of a function template. */
2750 4175474 : check_redeclaration_no_default_args (newdecl);
2751 : /* C++17 11.3.6/4: "If a friend declaration specifies a default
2752 : argument expression, that declaration... shall be the only
2753 : declaration of the function or function template in the
2754 : translation unit." */
2755 4175474 : check_no_redeclaration_friend_default_args
2756 4175474 : (old_result, new_result);
2757 :
2758 4175474 : tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
2759 4175474 : tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
2760 4175474 : merge_default_template_args (new_parms, old_parms,
2761 : /*class_p=*/false);
2762 : }
2763 4198871 : if (!DECL_UNIQUE_FRIEND_P (new_result))
2764 3077372 : DECL_UNIQUE_FRIEND_P (old_result) = false;
2765 :
2766 4198871 : check_default_args (newdecl);
2767 :
2768 8397730 : if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
2769 4198871 : && DECL_INITIAL (new_result))
2770 : {
2771 24 : if (DECL_INITIAL (old_result))
2772 12 : DECL_UNINLINABLE (old_result) = 1;
2773 : else
2774 12 : DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
2775 24 : DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
2776 72 : DECL_NOT_REALLY_EXTERN (old_result)
2777 24 : = DECL_NOT_REALLY_EXTERN (new_result);
2778 48 : DECL_INTERFACE_KNOWN (old_result)
2779 24 : = DECL_INTERFACE_KNOWN (new_result);
2780 24 : DECL_DECLARED_INLINE_P (old_result)
2781 24 : = DECL_DECLARED_INLINE_P (new_result);
2782 24 : DECL_DISREGARD_INLINE_LIMITS (old_result)
2783 24 : |= DECL_DISREGARD_INLINE_LIMITS (new_result);
2784 : }
2785 : else
2786 : {
2787 4198847 : DECL_DECLARED_INLINE_P (old_result)
2788 4198847 : |= DECL_DECLARED_INLINE_P (new_result);
2789 4198847 : DECL_DISREGARD_INLINE_LIMITS (old_result)
2790 4198847 : |= DECL_DISREGARD_INLINE_LIMITS (new_result);
2791 4198847 : check_redeclaration_exception_specification (newdecl, olddecl);
2792 :
2793 4198847 : merge_attribute_bits (new_result, old_result);
2794 : }
2795 : }
2796 :
2797 : /* If the new declaration is a definition, update the file and
2798 : line information on the declaration, and also make
2799 : the old declaration the same definition. */
2800 4198901 : if (DECL_INITIAL (new_result) != NULL_TREE)
2801 : {
2802 5710222 : DECL_SOURCE_LOCATION (olddecl)
2803 5710222 : = DECL_SOURCE_LOCATION (old_result)
2804 2855111 : = DECL_SOURCE_LOCATION (newdecl);
2805 2855111 : DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
2806 2855111 : if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2807 : {
2808 2855111 : update_contract_arguments (new_result, old_result);
2809 :
2810 2855111 : DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
2811 10287976 : for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
2812 7432865 : DECL_CONTEXT (p) = old_result;
2813 :
2814 5710222 : if (tree fc = DECL_FRIEND_CONTEXT (new_result))
2815 18 : SET_DECL_FRIEND_CONTEXT (old_result, fc);
2816 : }
2817 : }
2818 :
2819 : return olddecl;
2820 : }
2821 :
2822 16436167 : if (types_match)
2823 : {
2824 16435966 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2825 15859190 : check_redeclaration_exception_specification (newdecl, olddecl);
2826 :
2827 : /* Automatically handles default parameters. */
2828 16435966 : tree oldtype = TREE_TYPE (olddecl);
2829 16435966 : tree newtype;
2830 :
2831 : /* For typedefs use the old type, as the new type's DECL_NAME points
2832 : at newdecl, which will be ggc_freed. */
2833 16435966 : if (TREE_CODE (newdecl) == TYPE_DECL)
2834 : {
2835 : /* But NEWTYPE might have an attribute, honor that. */
2836 50201 : tree tem = TREE_TYPE (newdecl);
2837 50201 : newtype = oldtype;
2838 :
2839 50201 : if (TYPE_USER_ALIGN (tem))
2840 : {
2841 21 : if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
2842 6 : SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
2843 21 : TYPE_USER_ALIGN (newtype) = true;
2844 : }
2845 :
2846 : /* And remove the new type from the variants list. */
2847 50201 : if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
2848 : {
2849 24 : tree remove = TREE_TYPE (newdecl);
2850 24 : if (TYPE_MAIN_VARIANT (remove) == remove)
2851 : {
2852 9 : gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
2853 : /* If remove is the main variant, no need to remove that
2854 : from the list. One of the DECL_ORIGINAL_TYPE
2855 : variants, e.g. created for aligned attribute, might still
2856 : refer to the newdecl TYPE_DECL though, so remove that one
2857 : in that case. */
2858 9 : if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
2859 6 : if (orig != remove)
2860 6 : for (tree t = TYPE_MAIN_VARIANT (orig); t;
2861 0 : t = TYPE_MAIN_VARIANT (t))
2862 6 : if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
2863 : {
2864 12 : TYPE_NEXT_VARIANT (t)
2865 6 : = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
2866 6 : break;
2867 : }
2868 : }
2869 : else
2870 15 : for (tree t = TYPE_MAIN_VARIANT (remove); ;
2871 0 : t = TYPE_NEXT_VARIANT (t))
2872 15 : if (TYPE_NEXT_VARIANT (t) == remove)
2873 : {
2874 15 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
2875 15 : break;
2876 : }
2877 : }
2878 : }
2879 16385765 : else if (merge_attr)
2880 15804197 : newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2881 : else
2882 581568 : newtype = TREE_TYPE (newdecl);
2883 :
2884 16435966 : if (VAR_P (newdecl))
2885 : {
2886 526575 : DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2887 : /* For already initialized vars, TREE_READONLY could have been
2888 : cleared in cp_finish_decl, because the var needs runtime
2889 : initialization or destruction. Make sure not to set
2890 : TREE_READONLY on it again. */
2891 526575 : if (DECL_INITIALIZED_P (olddecl)
2892 1217 : && !DECL_EXTERNAL (olddecl)
2893 526662 : && !TREE_READONLY (olddecl))
2894 32 : TREE_READONLY (newdecl) = 0;
2895 526575 : DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
2896 1053150 : DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
2897 526575 : |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
2898 526575 : if (DECL_DEPENDENT_INIT_P (olddecl))
2899 111280 : SET_DECL_DEPENDENT_INIT_P (newdecl, true);
2900 1053150 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
2901 526575 : |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
2902 526575 : DECL_DECLARED_CONSTEXPR_P (newdecl)
2903 526575 : |= DECL_DECLARED_CONSTEXPR_P (olddecl);
2904 1053150 : DECL_DECLARED_CONSTINIT_P (newdecl)
2905 526575 : |= DECL_DECLARED_CONSTINIT_P (olddecl);
2906 :
2907 : /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
2908 526575 : if (DECL_LANG_SPECIFIC (olddecl)
2909 1049552 : && CP_DECL_THREADPRIVATE_P (olddecl))
2910 : {
2911 : /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed. */
2912 41 : retrofit_lang_decl (newdecl);
2913 41 : CP_DECL_THREADPRIVATE_P (newdecl) = 1;
2914 : }
2915 : }
2916 :
2917 : /* An explicit specialization of a function template or of a member
2918 : function of a class template can be declared transaction_safe
2919 : independently of whether the corresponding template entity is declared
2920 : transaction_safe. */
2921 1207 : if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
2922 1072 : && DECL_TEMPLATE_INSTANTIATION (olddecl)
2923 78 : && DECL_TEMPLATE_SPECIALIZATION (newdecl)
2924 54 : && tx_safe_fn_type_p (newtype)
2925 16435966 : && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
2926 0 : newtype = tx_unsafe_fn_variant (newtype);
2927 :
2928 16435966 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2929 :
2930 16435966 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2931 15859190 : check_default_args (newdecl);
2932 :
2933 : /* Lay the type out, unless already done. */
2934 16435966 : if (! same_type_p (newtype, oldtype)
2935 370 : && TREE_TYPE (newdecl) != error_mark_node
2936 16436336 : && !(processing_template_decl && uses_template_parms (newdecl)))
2937 287 : layout_type (TREE_TYPE (newdecl));
2938 :
2939 16435966 : if ((VAR_P (newdecl)
2940 15909391 : || TREE_CODE (newdecl) == PARM_DECL
2941 15909391 : || TREE_CODE (newdecl) == RESULT_DECL
2942 15909391 : || TREE_CODE (newdecl) == FIELD_DECL
2943 15909391 : || TREE_CODE (newdecl) == TYPE_DECL)
2944 16486167 : && !(processing_template_decl && uses_template_parms (newdecl)))
2945 405351 : layout_decl (newdecl, 0);
2946 :
2947 : /* Merge deprecatedness. */
2948 16435966 : if (TREE_DEPRECATED (newdecl))
2949 12059 : TREE_DEPRECATED (olddecl) = 1;
2950 :
2951 : /* Merge unavailability. */
2952 16435966 : if (TREE_UNAVAILABLE (newdecl))
2953 3 : TREE_UNAVAILABLE (olddecl) = 1;
2954 :
2955 : /* Preserve function specific target and optimization options */
2956 16435966 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2957 : {
2958 15859190 : if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
2959 15859190 : && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
2960 0 : DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
2961 0 : = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
2962 :
2963 15859190 : if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
2964 15859190 : && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
2965 55 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
2966 55 : = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
2967 :
2968 15859190 : if (!DECL_UNIQUE_FRIEND_P (olddecl))
2969 15322514 : DECL_UNIQUE_FRIEND_P (newdecl) = false;
2970 : }
2971 : else
2972 : {
2973 : /* Merge the const type qualifier. */
2974 576776 : if (TREE_READONLY (newdecl))
2975 157478 : TREE_READONLY (olddecl) = 1;
2976 : /* Merge the volatile type qualifier. */
2977 576776 : if (TREE_THIS_VOLATILE (newdecl))
2978 5 : TREE_THIS_VOLATILE (olddecl) = 1;
2979 : }
2980 :
2981 : /* Merge the initialization information. */
2982 16435966 : if (DECL_INITIAL (newdecl) == NULL_TREE
2983 16435966 : && DECL_INITIAL (olddecl) != NULL_TREE)
2984 : {
2985 191976 : DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2986 191976 : DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
2987 191976 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2988 : {
2989 17508 : DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
2990 17508 : DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
2991 : }
2992 : }
2993 :
2994 16435966 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2995 : {
2996 15859190 : DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
2997 15859190 : |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
2998 15859190 : DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
2999 15859190 : if (DECL_IS_OPERATOR_NEW_P (olddecl))
3000 58802 : DECL_SET_IS_OPERATOR_NEW (newdecl, true);
3001 15859190 : DECL_LOOPING_CONST_OR_PURE_P (newdecl)
3002 15859190 : |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
3003 15859190 : DECL_IS_REPLACEABLE_OPERATOR (newdecl)
3004 15859190 : |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
3005 :
3006 15859190 : if (merge_attr)
3007 15277622 : merge_attribute_bits (newdecl, olddecl);
3008 : else
3009 : {
3010 : /* Merge the noreturn bit. */
3011 581568 : TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
3012 581568 : TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
3013 581568 : TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
3014 581568 : DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
3015 581568 : DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
3016 : }
3017 : /* Keep the old RTL. */
3018 15859190 : COPY_DECL_RTL (olddecl, newdecl);
3019 : }
3020 576776 : else if (VAR_P (newdecl)
3021 576776 : && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
3022 : {
3023 : /* Keep the old RTL. We cannot keep the old RTL if the old
3024 : declaration was for an incomplete object and the new
3025 : declaration is not since many attributes of the RTL will
3026 : change. */
3027 526501 : COPY_DECL_RTL (olddecl, newdecl);
3028 : }
3029 : }
3030 : /* If cannot merge, then use the new type and qualifiers,
3031 : and don't preserve the old rtl. */
3032 : else
3033 : {
3034 : /* Clean out any memory we had of the old declaration. */
3035 201 : tree oldstatic = value_member (olddecl, static_aggregates);
3036 201 : if (oldstatic)
3037 0 : TREE_VALUE (oldstatic) = error_mark_node;
3038 :
3039 201 : TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
3040 201 : TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
3041 201 : TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
3042 201 : TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
3043 201 : TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
3044 : }
3045 :
3046 : /* Merge the storage class information. */
3047 16436167 : merge_weak (newdecl, olddecl);
3048 :
3049 16436167 : DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
3050 16436167 : TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
3051 16436167 : TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
3052 16436167 : if (! DECL_EXTERNAL (olddecl))
3053 54866 : DECL_EXTERNAL (newdecl) = 0;
3054 16436167 : if (! DECL_COMDAT (olddecl))
3055 7072903 : DECL_COMDAT (newdecl) = 0;
3056 :
3057 16436167 : if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
3058 : {
3059 78 : if (!DECL_LOCAL_DECL_P (olddecl))
3060 : /* This can happen if olddecl was brought in from the
3061 : enclosing namespace via a using-decl. The new decl is
3062 : then not a block-scope extern at all. */
3063 3 : DECL_LOCAL_DECL_P (newdecl) = false;
3064 : else
3065 : {
3066 75 : retrofit_lang_decl (newdecl);
3067 75 : tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
3068 75 : = DECL_LOCAL_DECL_ALIAS (olddecl);
3069 75 : if (alias != error_mark_node)
3070 : {
3071 72 : DECL_ATTRIBUTES (alias)
3072 72 : = (*targetm.merge_decl_attributes) (alias, newdecl);
3073 72 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3074 42 : merge_attribute_bits (newdecl, alias);
3075 : }
3076 : }
3077 : }
3078 :
3079 16436167 : new_template_info = NULL_TREE;
3080 16436167 : if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
3081 : {
3082 16382386 : bool new_redefines_gnu_inline = false;
3083 :
3084 16382386 : if (new_defines_function
3085 16382386 : && ((DECL_INTERFACE_KNOWN (olddecl)
3086 1245 : && TREE_CODE (olddecl) == FUNCTION_DECL)
3087 9550545 : || (TREE_CODE (olddecl) == TEMPLATE_DECL
3088 0 : && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
3089 : == FUNCTION_DECL))))
3090 2490 : new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
3091 :
3092 : if (!new_redefines_gnu_inline)
3093 : {
3094 16382308 : DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
3095 16382308 : DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
3096 16382308 : DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
3097 : }
3098 :
3099 16382386 : if (TREE_CODE (newdecl) != TYPE_DECL)
3100 : {
3101 16382322 : DECL_TEMPLATE_INSTANTIATED (newdecl)
3102 16382322 : |= DECL_TEMPLATE_INSTANTIATED (olddecl);
3103 16382322 : DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
3104 :
3105 : /* If the OLDDECL is an instantiation and/or specialization,
3106 : then the NEWDECL must be too. But, it may not yet be marked
3107 : as such if the caller has created NEWDECL, but has not yet
3108 : figured out that it is a redeclaration. */
3109 16382322 : if (!DECL_USE_TEMPLATE (newdecl))
3110 15715378 : DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
3111 :
3112 16382322 : if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
3113 15800526 : DECL_INITIALIZED_IN_CLASS_P (newdecl)
3114 31601052 : |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
3115 : }
3116 :
3117 : /* Don't really know how much of the language-specific
3118 : values we should copy from old to new. */
3119 16382386 : DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
3120 :
3121 16382386 : if (LANG_DECL_HAS_MIN (newdecl))
3122 : {
3123 16382386 : DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
3124 16382386 : if (DECL_TEMPLATE_INFO (newdecl))
3125 : {
3126 666977 : new_template_info = DECL_TEMPLATE_INFO (newdecl);
3127 666977 : if (DECL_TEMPLATE_INSTANTIATION (olddecl)
3128 666977 : && DECL_TEMPLATE_SPECIALIZATION (newdecl))
3129 : /* Remember the presence of explicit specialization args. */
3130 1163142 : TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
3131 1163142 : = TINFO_USED_TEMPLATE_ID (new_template_info);
3132 : }
3133 :
3134 : /* We don't want to copy template info from a non-templated friend
3135 : (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now. */
3136 16382386 : gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
3137 : || !non_templated_friend_p (olddecl));
3138 16382386 : DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
3139 : }
3140 :
3141 16382386 : if (DECL_DECLARES_FUNCTION_P (newdecl))
3142 : {
3143 : /* Only functions have these fields. */
3144 15859391 : DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
3145 15859391 : DECL_BEFRIENDING_CLASSES (newdecl)
3146 15859391 : = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
3147 15859391 : DECL_BEFRIENDING_CLASSES (olddecl));
3148 : /* DECL_THUNKS is only valid for virtual functions,
3149 : otherwise it is a DECL_FRIEND_CONTEXT. */
3150 15859391 : if (DECL_VIRTUAL_P (newdecl))
3151 649361 : SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
3152 30420060 : else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
3153 385678 : SET_DECL_FRIEND_CONTEXT (olddecl, fc);
3154 : }
3155 522995 : else if (VAR_P (newdecl))
3156 : {
3157 : /* Only variables have this field. */
3158 522931 : if (VAR_HAD_UNKNOWN_BOUND (olddecl))
3159 198 : SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
3160 : }
3161 : }
3162 :
3163 16436167 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3164 : {
3165 15859391 : merge_decl_arguments (newdecl, olddecl, new_defines_function,
3166 : types_match, false);
3167 :
3168 15859391 : if (DECL_TEMPLATE_INSTANTIATION (olddecl)
3169 15859391 : && !DECL_TEMPLATE_INSTANTIATION (newdecl))
3170 : {
3171 : /* If newdecl is not a specialization, then it is not a
3172 : template-related function at all. And that means that we
3173 : should have exited above, returning 0. */
3174 581568 : gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
3175 :
3176 581568 : if (DECL_ODR_USED (olddecl))
3177 : /* From [temp.expl.spec]:
3178 :
3179 : If a template, a member template or the member of a class
3180 : template is explicitly specialized then that
3181 : specialization shall be declared before the first use of
3182 : that specialization that would cause an implicit
3183 : instantiation to take place, in every translation unit in
3184 : which such a use occurs. */
3185 0 : error ("explicit specialization of %qD after first use",
3186 : olddecl);
3187 :
3188 581568 : SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
3189 581568 : DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
3190 1162983 : && DECL_NONGNU_INLINE_P (newdecl));
3191 :
3192 : /* Don't propagate visibility from the template to the
3193 : specialization here. We'll do that in determine_visibility if
3194 : appropriate. */
3195 581568 : DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
3196 :
3197 : /* [temp.expl.spec/14] We don't inline explicit specialization
3198 : just because the primary template says so. */
3199 581568 : gcc_assert (!merge_attr);
3200 :
3201 581568 : DECL_DECLARED_INLINE_P (olddecl)
3202 581568 : = DECL_DECLARED_INLINE_P (newdecl);
3203 :
3204 581568 : DECL_DISREGARD_INLINE_LIMITS (olddecl)
3205 581568 : = DECL_DISREGARD_INLINE_LIMITS (newdecl);
3206 :
3207 581568 : DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
3208 : }
3209 15277823 : else if (new_defines_function && DECL_INITIAL (olddecl))
3210 : {
3211 : /* Never inline re-defined extern inline functions.
3212 : FIXME: this could be better handled by keeping both
3213 : function as separate declarations. */
3214 78 : DECL_UNINLINABLE (newdecl) = 1;
3215 : }
3216 : else
3217 : {
3218 15277745 : if (DECL_PENDING_INLINE_P (olddecl))
3219 : {
3220 6 : DECL_PENDING_INLINE_P (newdecl) = 1;
3221 6 : DECL_PENDING_INLINE_INFO (newdecl)
3222 12 : = DECL_PENDING_INLINE_INFO (olddecl);
3223 : }
3224 15277739 : else if (DECL_PENDING_INLINE_P (newdecl))
3225 : ;
3226 15277739 : else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
3227 15277739 : DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
3228 30555478 : = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
3229 :
3230 15277745 : DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
3231 :
3232 45833235 : DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
3233 30555490 : = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
3234 :
3235 30555490 : DECL_DISREGARD_INLINE_LIMITS (newdecl)
3236 15277745 : = DECL_DISREGARD_INLINE_LIMITS (olddecl)
3237 15277745 : = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
3238 30067850 : || DECL_DISREGARD_INLINE_LIMITS (olddecl));
3239 : }
3240 :
3241 : /* Preserve abstractness on cloned [cd]tors. */
3242 15859391 : DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
3243 :
3244 : /* Update newdecl's parms to point at olddecl. */
3245 50480454 : for (tree parm = DECL_ARGUMENTS (newdecl); parm;
3246 34621063 : parm = DECL_CHAIN (parm))
3247 34621063 : DECL_CONTEXT (parm) = olddecl;
3248 :
3249 15859391 : if (! types_match)
3250 : {
3251 201 : SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
3252 201 : COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
3253 201 : COPY_DECL_RTL (newdecl, olddecl);
3254 : }
3255 15859391 : if (! types_match || new_defines_function)
3256 : {
3257 : /* Update the contracts to reflect the new parameter names. */
3258 9551991 : update_contract_arguments (newdecl, olddecl);
3259 :
3260 : /* Mark the old PARM_DECLs in case std::meta::parameters_of has
3261 : been called on the old declaration and reflections of those
3262 : arguments are held across this point and used later.
3263 : Such PARM_DECLs are no longer present in
3264 : DECL_ARGUMENTS (DECL_CONTEXT (oldarg)) chain. */
3265 9551991 : for (tree oldarg = DECL_ARGUMENTS (olddecl);
3266 33530510 : oldarg; oldarg = DECL_CHAIN (oldarg))
3267 23978519 : OLD_PARM_DECL_P (oldarg) = 1;
3268 :
3269 : /* These need to be copied so that the names are available.
3270 : Note that if the types do match, we'll preserve inline
3271 : info and other bits, but if not, we won't. */
3272 9551991 : DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
3273 9551991 : DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
3274 : }
3275 : /* If redeclaring a builtin function, it stays built in
3276 : if newdecl is a gnu_inline definition, or if newdecl is just
3277 : a declaration. */
3278 15859391 : if (fndecl_built_in_p (olddecl)
3279 15918155 : && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
3280 : {
3281 4108056 : copy_decl_built_in_function (newdecl, olddecl);
3282 : /* If we're keeping the built-in definition, keep the rtl,
3283 : regardless of declaration matches. */
3284 4108056 : COPY_DECL_RTL (olddecl, newdecl);
3285 4108056 : if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
3286 : {
3287 4108050 : enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
3288 4108050 : if (builtin_decl_explicit_p (fncode))
3289 : {
3290 : /* A compatible prototype of these builtin functions
3291 : is seen, assume the runtime implements it with
3292 : the expected semantics. */
3293 4108050 : switch (fncode)
3294 : {
3295 10177 : case BUILT_IN_STPCPY:
3296 10177 : set_builtin_decl_implicit_p (fncode, true);
3297 10177 : break;
3298 4097873 : default:
3299 4097873 : set_builtin_decl_declared_p (fncode, true);
3300 4097873 : break;
3301 : }
3302 : }
3303 :
3304 4108050 : copy_attributes_to_builtin (newdecl);
3305 : }
3306 : }
3307 15859391 : if (new_defines_function)
3308 : /* If defining a function declared with other language
3309 : linkage, use the previously declared language linkage. */
3310 9551790 : SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
3311 6307601 : else if (types_match)
3312 : {
3313 6307400 : DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
3314 : /* Don't clear out the arguments if we're just redeclaring a
3315 : function. */
3316 6307400 : if (DECL_ARGUMENTS (olddecl))
3317 2160313 : DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
3318 : }
3319 : }
3320 576776 : else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
3321 0 : NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
3322 :
3323 : /* Now preserve various other info from the definition. */
3324 16436167 : TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
3325 16436167 : TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
3326 16436167 : DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
3327 16436167 : COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
3328 :
3329 : /* Warn about conflicting visibility specifications. */
3330 16436167 : if (DECL_VISIBILITY_SPECIFIED (olddecl)
3331 5723023 : && DECL_VISIBILITY_SPECIFIED (newdecl)
3332 16448417 : && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
3333 : {
3334 12 : auto_diagnostic_group d;
3335 12 : if (warning_at (newdecl_loc, OPT_Wattributes,
3336 : "%qD: visibility attribute ignored because it "
3337 : "conflicts with previous declaration", newdecl))
3338 12 : inform (olddecl_loc,
3339 : "previous declaration of %qD", olddecl);
3340 12 : }
3341 : /* Choose the declaration which specified visibility. */
3342 16436167 : if (DECL_VISIBILITY_SPECIFIED (olddecl))
3343 : {
3344 5723023 : DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
3345 5723023 : DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
3346 : }
3347 : /* Init priority used to be merged from newdecl to olddecl by the memcpy,
3348 : so keep this behavior. */
3349 16436167 : if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
3350 : {
3351 10 : SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
3352 10 : DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
3353 : }
3354 : /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED. */
3355 16436167 : if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
3356 : {
3357 54 : SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
3358 54 : DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
3359 : }
3360 16436113 : else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
3361 16436113 : && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
3362 3 : DECL_USER_ALIGN (newdecl) = 1;
3363 :
3364 16436167 : DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
3365 32872334 : if (DECL_WARN_IF_NOT_ALIGN (olddecl)
3366 16436167 : > DECL_WARN_IF_NOT_ALIGN (newdecl))
3367 0 : SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
3368 : DECL_WARN_IF_NOT_ALIGN (olddecl));
3369 16436167 : if (TREE_CODE (newdecl) == FIELD_DECL)
3370 0 : DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
3371 :
3372 : /* Merge module entity mapping information. */
3373 16436167 : if (DECL_LANG_SPECIFIC (olddecl)
3374 32818599 : && (DECL_MODULE_ENTITY_P (olddecl)
3375 16382096 : || DECL_MODULE_KEYED_DECLS_P (olddecl)))
3376 : {
3377 336 : retrofit_lang_decl (newdecl);
3378 336 : DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
3379 336 : DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
3380 : }
3381 :
3382 : /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
3383 : with that from NEWDECL below. */
3384 16436167 : if (DECL_LANG_SPECIFIC (olddecl))
3385 : {
3386 16382432 : gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
3387 : != DECL_LANG_SPECIFIC (newdecl));
3388 16382432 : ggc_free (DECL_LANG_SPECIFIC (olddecl));
3389 : }
3390 :
3391 : /* Merge the USED information. */
3392 16436167 : if (TREE_USED (olddecl))
3393 513733 : TREE_USED (newdecl) = 1;
3394 15922434 : else if (TREE_USED (newdecl))
3395 62 : TREE_USED (olddecl) = 1;
3396 :
3397 16436167 : if (VAR_P (newdecl))
3398 : {
3399 526575 : if (DECL_READ_P (olddecl))
3400 45193 : DECL_READ_P (newdecl) = 1;
3401 481382 : else if (DECL_READ_P (newdecl))
3402 3 : DECL_READ_P (olddecl) = 1;
3403 : }
3404 :
3405 16436167 : if (DECL_PRESERVE_P (olddecl))
3406 48 : DECL_PRESERVE_P (newdecl) = 1;
3407 16436119 : else if (DECL_PRESERVE_P (newdecl))
3408 75 : DECL_PRESERVE_P (olddecl) = 1;
3409 :
3410 : /* Merge the DECL_FUNCTION_VERSIONED information. newdecl will be copied
3411 : to olddecl and deleted. */
3412 16436167 : if (TREE_CODE (newdecl) == FUNCTION_DECL
3413 32295558 : && DECL_FUNCTION_VERSIONED (olddecl))
3414 : {
3415 : /* Set the flag for newdecl so that it gets copied to olddecl. */
3416 258 : DECL_FUNCTION_VERSIONED (newdecl) = 1;
3417 : /* newdecl will be purged after copying to olddecl and is no longer
3418 : a version. */
3419 258 : cgraph_node::delete_function_version_by_decl (newdecl);
3420 : }
3421 :
3422 16436167 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3423 : {
3424 15859391 : int function_size;
3425 15859391 : struct symtab_node *snode = symtab_node::get (olddecl);
3426 :
3427 15859391 : function_size = sizeof (struct tree_decl_common);
3428 :
3429 15859391 : memcpy ((char *) olddecl + sizeof (struct tree_common),
3430 : (char *) newdecl + sizeof (struct tree_common),
3431 : function_size - sizeof (struct tree_common));
3432 :
3433 15859391 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3434 : (char *) newdecl + sizeof (struct tree_decl_common),
3435 : sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
3436 :
3437 : /* Preserve symtab node mapping. */
3438 15859391 : olddecl->decl_with_vis.symtab_node = snode;
3439 :
3440 15859391 : if (new_template_info)
3441 : /* If newdecl is a template instantiation, it is possible that
3442 : the following sequence of events has occurred:
3443 :
3444 : o A friend function was declared in a class template. The
3445 : class template was instantiated.
3446 :
3447 : o The instantiation of the friend declaration was
3448 : recorded on the instantiation list, and is newdecl.
3449 :
3450 : o Later, however, instantiate_class_template called pushdecl
3451 : on the newdecl to perform name injection. But, pushdecl in
3452 : turn called duplicate_decls when it discovered that another
3453 : declaration of a global function with the same name already
3454 : existed.
3455 :
3456 : o Here, in duplicate_decls, we decided to clobber newdecl.
3457 :
3458 : If we're going to do that, we'd better make sure that
3459 : olddecl, and not newdecl, is on the list of
3460 : instantiations so that if we try to do the instantiation
3461 : again we won't get the clobbered declaration. */
3462 666968 : reregister_specialization (newdecl,
3463 : new_template_info,
3464 : olddecl);
3465 : }
3466 : else
3467 : {
3468 576776 : size_t size = tree_code_size (TREE_CODE (newdecl));
3469 :
3470 576776 : memcpy ((char *) olddecl + sizeof (struct tree_common),
3471 : (char *) newdecl + sizeof (struct tree_common),
3472 : sizeof (struct tree_decl_common) - sizeof (struct tree_common));
3473 :
3474 576776 : switch (TREE_CODE (newdecl))
3475 : {
3476 576776 : case LABEL_DECL:
3477 576776 : case VAR_DECL:
3478 576776 : case RESULT_DECL:
3479 576776 : case PARM_DECL:
3480 576776 : case FIELD_DECL:
3481 576776 : case TYPE_DECL:
3482 576776 : case CONST_DECL:
3483 576776 : {
3484 576776 : struct symtab_node *snode = NULL;
3485 :
3486 576776 : if (VAR_P (newdecl)
3487 576776 : && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
3488 3 : || DECL_EXTERNAL (olddecl)))
3489 526575 : snode = symtab_node::get (olddecl);
3490 576776 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3491 : (char *) newdecl + sizeof (struct tree_decl_common),
3492 : size - sizeof (struct tree_decl_common)
3493 576776 : + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
3494 576776 : if (VAR_P (newdecl))
3495 526575 : olddecl->decl_with_vis.symtab_node = snode;
3496 : }
3497 : break;
3498 0 : default:
3499 0 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3500 : (char *) newdecl + sizeof (struct tree_decl_common),
3501 : sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
3502 0 : + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
3503 0 : break;
3504 : }
3505 : }
3506 :
3507 16436167 : if (VAR_OR_FUNCTION_DECL_P (newdecl))
3508 : {
3509 16385966 : if (DECL_EXTERNAL (olddecl)
3510 527952 : || TREE_PUBLIC (olddecl)
3511 16386035 : || TREE_STATIC (olddecl))
3512 : {
3513 : /* Merge the section attribute.
3514 : We want to issue an error if the sections conflict but that must be
3515 : done later in decl_attributes since we are called before attributes
3516 : are assigned. */
3517 16385966 : if (DECL_SECTION_NAME (newdecl) != NULL)
3518 7 : set_decl_section_name (olddecl, newdecl);
3519 :
3520 16385966 : if (DECL_ONE_ONLY (newdecl))
3521 : {
3522 0 : struct symtab_node *oldsym, *newsym;
3523 0 : if (TREE_CODE (olddecl) == FUNCTION_DECL)
3524 0 : oldsym = cgraph_node::get_create (olddecl);
3525 : else
3526 0 : oldsym = varpool_node::get_create (olddecl);
3527 0 : newsym = symtab_node::get (newdecl);
3528 0 : oldsym->set_comdat_group (newsym->get_comdat_group ());
3529 : }
3530 : }
3531 :
3532 16385966 : if (VAR_P (newdecl)
3533 16385966 : && CP_DECL_THREAD_LOCAL_P (newdecl))
3534 : {
3535 404 : CP_DECL_THREAD_LOCAL_P (olddecl) = true;
3536 404 : if (!processing_template_decl)
3537 371 : set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
3538 : }
3539 : }
3540 :
3541 16436167 : DECL_UID (olddecl) = olddecl_uid;
3542 :
3543 : /* NEWDECL contains the merged attribute lists.
3544 : Update OLDDECL to be the same. */
3545 16436167 : DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
3546 :
3547 : /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
3548 : so that encode_section_info has a chance to look at the new decl
3549 : flags and attributes. */
3550 16436167 : if (DECL_RTL_SET_P (olddecl)
3551 16436182 : && (TREE_CODE (olddecl) == FUNCTION_DECL
3552 15 : || (VAR_P (olddecl)
3553 15 : && TREE_STATIC (olddecl))))
3554 15 : make_decl_rtl (olddecl);
3555 :
3556 : /* The NEWDECL will no longer be needed. Because every out-of-class
3557 : declaration of a member results in a call to duplicate_decls,
3558 : freeing these nodes represents in a significant savings.
3559 :
3560 : Before releasing the node, be sore to remove function from symbol
3561 : table that might have been inserted there to record comdat group.
3562 : Be sure to however do not free DECL_STRUCT_FUNCTION because this
3563 : structure is shared in between newdecl and oldecl. */
3564 16436167 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3565 15859391 : DECL_STRUCT_FUNCTION (newdecl) = NULL;
3566 16436167 : if (VAR_OR_FUNCTION_DECL_P (newdecl))
3567 : {
3568 16385966 : struct symtab_node *snode = symtab_node::get (newdecl);
3569 16385966 : if (snode)
3570 399 : snode->remove ();
3571 : }
3572 :
3573 16436167 : if (TREE_CODE (olddecl) == FUNCTION_DECL)
3574 : {
3575 15859391 : tree clone;
3576 16413322 : FOR_EACH_CLONE (clone, olddecl)
3577 : {
3578 553931 : DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
3579 553931 : DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
3580 : }
3581 : }
3582 :
3583 : /* Remove the associated constraints for newdecl, if any, before
3584 : reclaiming memory. */
3585 16436167 : if (flag_concepts)
3586 16157167 : remove_constraints (newdecl);
3587 :
3588 16436167 : if (flag_contracts)
3589 : /* Remove the specifiers, and then remove the decl from the lookup. */
3590 1539794 : remove_decl_with_fn_contracts_specifiers (newdecl);
3591 :
3592 : /* And similarly for any module tracking data. */
3593 16436167 : if (modules_p ())
3594 45640 : remove_defining_module (newdecl);
3595 :
3596 16436167 : ggc_free (newdecl);
3597 :
3598 16436167 : return olddecl;
3599 : }
3600 :
3601 : /* Return zero if the declaration NEWDECL is valid
3602 : when the declaration OLDDECL (assumed to be for the same name)
3603 : has already been seen.
3604 : Otherwise return an error message format string with a %s
3605 : where the identifier should go. */
3606 :
3607 : static const char *
3608 16646611 : redeclaration_error_message (tree newdecl, tree olddecl)
3609 : {
3610 16646647 : if (TREE_CODE (newdecl) == TYPE_DECL)
3611 : {
3612 : /* Because C++ can put things into name space for free,
3613 : constructs like "typedef struct foo { ... } foo"
3614 : would look like an erroneous redeclaration. */
3615 84021 : if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
3616 : return NULL;
3617 : else
3618 0 : return G_("redefinition of %q#D");
3619 : }
3620 16562626 : else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3621 : {
3622 : /* If this is a pure function, its olddecl will actually be
3623 : the original initialization to `0' (which we force to call
3624 : abort()). Don't complain about redefinition in this case. */
3625 23673496 : if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
3626 11836766 : && DECL_INITIAL (olddecl) == NULL_TREE)
3627 : return NULL;
3628 :
3629 : /* If both functions come from different namespaces, this is not
3630 : a redeclaration - this is a conflict with a used function. */
3631 23673466 : if (DECL_NAMESPACE_SCOPE_P (olddecl)
3632 2894273 : && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
3633 11836736 : && ! decls_match (olddecl, newdecl))
3634 : return G_("%qD conflicts with used function");
3635 :
3636 : /* We'll complain about linkage mismatches in
3637 : warn_extern_redeclared_static. */
3638 :
3639 : /* Defining the same name twice is no good. */
3640 11836733 : if (decl_defined_p (olddecl)
3641 11836733 : && decl_defined_p (newdecl))
3642 : {
3643 306 : if (DECL_NAME (olddecl) == NULL_TREE)
3644 : return G_("%q#D not declared in class");
3645 447 : else if (!GNU_INLINE_P (olddecl)
3646 393 : || GNU_INLINE_P (newdecl))
3647 : return G_("redefinition of %q#D");
3648 : }
3649 :
3650 13732279 : if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
3651 : {
3652 1842791 : bool olda = GNU_INLINE_P (olddecl);
3653 1842791 : bool newa = GNU_INLINE_P (newdecl);
3654 :
3655 1842791 : if (olda != newa)
3656 : {
3657 15 : if (newa)
3658 : return G_("%q+D redeclared inline with "
3659 : "%<gnu_inline%> attribute");
3660 : else
3661 9 : return G_("%q+D redeclared inline without "
3662 : "%<gnu_inline%> attribute");
3663 : }
3664 : }
3665 :
3666 : /* [class.compare.default]: A definition of a comparison operator as
3667 : defaulted that appears in a class shall be the first declaration of
3668 : that function. */
3669 11836496 : special_function_kind sfk = special_function_p (olddecl);
3670 11836496 : if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
3671 : return G_("comparison operator %q+D defaulted after "
3672 : "its first declaration");
3673 :
3674 11836493 : check_abi_tag_redeclaration
3675 11836493 : (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
3676 11836493 : lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
3677 :
3678 11836493 : return NULL;
3679 : }
3680 4725878 : else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3681 : {
3682 4198940 : tree nt, ot;
3683 :
3684 4198940 : if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
3685 : return G_("redefinition of %q#D");
3686 :
3687 4198934 : if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
3688 36 : return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
3689 36 : DECL_TEMPLATE_RESULT (olddecl));
3690 :
3691 4198898 : if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
3692 : return NULL;
3693 :
3694 4198886 : nt = DECL_TEMPLATE_RESULT (newdecl);
3695 4198886 : if (DECL_TEMPLATE_INFO (nt))
3696 1003835 : nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
3697 4198886 : ot = DECL_TEMPLATE_RESULT (olddecl);
3698 4198886 : if (DECL_TEMPLATE_INFO (ot))
3699 4198886 : ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
3700 7054051 : if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
3701 4198925 : && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
3702 : return G_("redefinition of %q#D");
3703 :
3704 6815036 : if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
3705 : {
3706 1910727 : bool olda = GNU_INLINE_P (ot);
3707 1910727 : bool newa = GNU_INLINE_P (nt);
3708 :
3709 1910727 : if (olda != newa)
3710 : {
3711 0 : if (newa)
3712 : return G_("%q+D redeclared inline with "
3713 : "%<gnu_inline%> attribute");
3714 : else
3715 0 : return G_("%q+D redeclared inline without "
3716 : "%<gnu_inline%> attribute");
3717 : }
3718 : }
3719 :
3720 : /* Core issue #226 (C++11):
3721 :
3722 : If a friend function template declaration specifies a
3723 : default template-argument, that declaration shall be a
3724 : definition and shall be the only declaration of the
3725 : function template in the translation unit. */
3726 4198871 : if ((cxx_dialect != cxx98)
3727 4180087 : && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
3728 4411575 : && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
3729 : /*is_primary=*/true,
3730 : /*is_partial=*/false,
3731 : /*is_friend_decl=*/2))
3732 3 : return G_("redeclaration of friend %q#D "
3733 : "may not have default template arguments");
3734 :
3735 : return NULL;
3736 : }
3737 526938 : else if (VAR_P (newdecl)
3738 526854 : && (CP_DECL_THREAD_LOCAL_P (newdecl)
3739 526854 : != CP_DECL_THREAD_LOCAL_P (olddecl))
3740 526985 : && (! DECL_LANG_SPECIFIC (olddecl)
3741 44 : || ! CP_DECL_THREADPRIVATE_P (olddecl)
3742 41 : || CP_DECL_THREAD_LOCAL_P (newdecl)))
3743 : {
3744 : /* Only variables can be thread-local, and all declarations must
3745 : agree on this property. */
3746 6 : if (CP_DECL_THREAD_LOCAL_P (newdecl))
3747 : return G_("thread-local declaration of %q#D follows "
3748 : "non-thread-local declaration");
3749 : else
3750 3 : return G_("non-thread-local declaration of %q#D follows "
3751 : "thread-local declaration");
3752 : }
3753 526932 : else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
3754 : {
3755 : /* The objects have been declared at namespace scope. If either
3756 : is a member of an anonymous union, then this is an invalid
3757 : redeclaration. For example:
3758 :
3759 : int i;
3760 : union { int i; };
3761 :
3762 : is invalid. */
3763 526698 : if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
3764 1053465 : || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
3765 : return G_("redeclaration of %q#D");
3766 : /* If at least one declaration is a reference, there is no
3767 : conflict. For example:
3768 :
3769 : int i = 3;
3770 : extern int i;
3771 :
3772 : is valid. */
3773 526764 : if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3774 : return NULL;
3775 :
3776 : /* Static data member declared outside a class definition
3777 : if the variable is defined within the class with constexpr
3778 : specifier is declaration rather than definition (and
3779 : deprecated). */
3780 2827 : if (cxx_dialect >= cxx17
3781 2754 : && VAR_P (olddecl)
3782 2698 : && DECL_CLASS_SCOPE_P (olddecl)
3783 2656 : && DECL_DECLARED_CONSTEXPR_P (olddecl)
3784 5471 : && !DECL_INITIAL (newdecl))
3785 : {
3786 2644 : DECL_EXTERNAL (newdecl) = 1;
3787 : /* For now, only warn with explicit -Wdeprecated. */
3788 2644 : if (OPTION_SET_P (warn_deprecated))
3789 : {
3790 40 : auto_diagnostic_group d;
3791 40 : if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
3792 : "redundant redeclaration of %<constexpr%> "
3793 : "static data member %qD", newdecl))
3794 4 : inform (DECL_SOURCE_LOCATION (olddecl),
3795 : "previous declaration of %qD", olddecl);
3796 40 : }
3797 : return NULL;
3798 : }
3799 :
3800 : /* Reject two definitions. */
3801 : return G_("redefinition of %q#D");
3802 : }
3803 : else
3804 : {
3805 : /* Objects declared with block scope: */
3806 : /* Reject two definitions, and reject a definition
3807 : together with an external reference. */
3808 153 : if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3809 153 : return G_("redeclaration of %q#D");
3810 : return NULL;
3811 : }
3812 : }
3813 :
3814 :
3815 : /* Hash and equality functions for the named_label table. */
3816 :
3817 : hashval_t
3818 79607 : named_label_hash::hash (const value_type entry)
3819 : {
3820 79607 : return IDENTIFIER_HASH_VALUE (entry->name);
3821 : }
3822 :
3823 : bool
3824 76526 : named_label_hash::equal (const value_type entry, compare_type name)
3825 : {
3826 76526 : return name == entry->name;
3827 : }
3828 :
3829 : /* Look for a label named ID in the current function. If one cannot
3830 : be found, create one. Return the named_label_entry, or NULL on
3831 : failure. */
3832 :
3833 : static named_label_entry *
3834 24479 : lookup_label_1 (tree id, bool making_local_p)
3835 : {
3836 24479 : auto_cond_timevar tv (TV_NAME_LOOKUP);
3837 :
3838 : /* You can't use labels at global scope. */
3839 24479 : if (current_function_decl == NULL_TREE)
3840 : {
3841 3 : error ("label %qE referenced outside of any function", id);
3842 3 : return NULL;
3843 : }
3844 :
3845 24476 : if (!named_labels)
3846 4726 : named_labels = hash_table<named_label_hash>::create_ggc (13);
3847 :
3848 24476 : hashval_t hash = IDENTIFIER_HASH_VALUE (id);
3849 24476 : named_label_entry **slot
3850 24476 : = named_labels->find_slot_with_hash (id, hash, INSERT);
3851 24476 : named_label_entry *old = *slot;
3852 :
3853 24476 : if (old && old->label_decl)
3854 : {
3855 3521 : if (!making_local_p)
3856 : return old;
3857 :
3858 21 : if (old->binding_level == current_binding_level)
3859 : {
3860 0 : auto_diagnostic_group d;
3861 0 : error ("local label %qE conflicts with existing label", id);
3862 0 : inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
3863 0 : return NULL;
3864 0 : }
3865 : }
3866 :
3867 : /* We are making a new decl, create or reuse the named_label_entry */
3868 20997 : named_label_entry *ent = NULL;
3869 33 : if (old && !old->label_decl)
3870 : ent = old;
3871 : else
3872 : {
3873 20964 : ent = ggc_cleared_alloc<named_label_entry> ();
3874 20964 : ent->name = id;
3875 20964 : ent->outer = old;
3876 20964 : *slot = ent;
3877 : }
3878 :
3879 : /* Now create the LABEL_DECL. */
3880 20976 : tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
3881 :
3882 20976 : DECL_CONTEXT (decl) = current_function_decl;
3883 20976 : SET_DECL_MODE (decl, VOIDmode);
3884 20976 : if (making_local_p)
3885 : {
3886 219 : C_DECLARED_LABEL_FLAG (decl) = true;
3887 219 : DECL_CHAIN (decl) = current_binding_level->names;
3888 219 : current_binding_level->names = decl;
3889 : }
3890 :
3891 20976 : ent->label_decl = decl;
3892 :
3893 20976 : return ent;
3894 24479 : }
3895 :
3896 : /* Wrapper for lookup_label_1. */
3897 :
3898 : tree
3899 3006 : lookup_label (tree id)
3900 : {
3901 3006 : named_label_entry *ent = lookup_label_1 (id, false);
3902 3006 : return ent ? ent->label_decl : NULL_TREE;
3903 : }
3904 :
3905 : /* Remember that we've seen &&ID. */
3906 :
3907 : void
3908 262 : mark_label_addressed (tree id)
3909 : {
3910 262 : named_label_entry *ent = lookup_label_1 (id, false);
3911 262 : ent->addressed = true;
3912 262 : }
3913 :
3914 : tree
3915 219 : declare_local_label (tree id)
3916 : {
3917 219 : named_label_entry *ent = lookup_label_1 (id, true);
3918 219 : return ent ? ent->label_decl : NULL_TREE;
3919 : }
3920 :
3921 : /* Returns true if it is ill-formed to jump past the declaration of DECL. */
3922 :
3923 : static bool
3924 2971500 : decl_jump_unsafe (tree decl)
3925 : {
3926 : /* [stmt.dcl]/3: A program that jumps from a point where a local variable
3927 : with automatic storage duration is not in scope to a point where it is
3928 : in scope is ill-formed unless the variable has scalar type, class type
3929 : with a trivial default constructor and a trivial destructor, a
3930 : cv-qualified version of one of these types, or an array of one of the
3931 : preceding types and is declared without an initializer (8.5). */
3932 2971500 : tree type = TREE_TYPE (decl);
3933 :
3934 2971500 : return (type != error_mark_node
3935 2971482 : && VAR_P (decl)
3936 15082 : && !TREE_STATIC (decl)
3937 2986446 : && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
3938 12998 : || variably_modified_type_p (type, NULL_TREE)));
3939 : }
3940 :
3941 : /* Returns true if decl is an automatic variable with vacuous initialization
3942 : except when it is [[indeterminate]] or [[gnu::uninitialized]].
3943 : Jumps across such initialization need to be instrumented for
3944 : !!flag_auto_var_init. */
3945 :
3946 : static bool
3947 2969543 : decl_instrument_init_bypass_p (tree decl)
3948 : {
3949 2969543 : tree type = TREE_TYPE (decl);
3950 :
3951 2969543 : return (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
3952 2212163 : && !processing_template_decl
3953 2211917 : && type != error_mark_node
3954 2211911 : && VAR_P (decl)
3955 1072 : && !TREE_STATIC (decl)
3956 1051 : && !DECL_EXTERNAL (decl)
3957 2074 : && !(DECL_NONTRIVIALLY_INITIALIZED_P (decl)
3958 1037 : || variably_modified_type_p (type, NULL_TREE))
3959 1037 : && !lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (decl))
3960 1037 : && !lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
3961 2970580 : && !DECL_HAS_VALUE_EXPR_P (decl));
3962 : }
3963 :
3964 : /* Build .DEFERRED_INIT call for DECL. */
3965 :
3966 : static tree
3967 140 : build_deferred_init_call (tree decl)
3968 : {
3969 140 : tree decl_size_arg = TYPE_SIZE_UNIT (TREE_TYPE (decl));
3970 280 : tree init_type_arg = build_int_cst (integer_type_node,
3971 140 : (int) flag_auto_var_init);
3972 140 : location_t loc = DECL_SOURCE_LOCATION (decl);
3973 140 : tree decl_name;
3974 :
3975 140 : if (DECL_NAME (decl))
3976 140 : decl_name = build_string_literal (DECL_NAME (decl));
3977 : else
3978 : {
3979 0 : char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3];
3980 0 : sprintf (decl_name_anonymous, "D.%u", DECL_UID (decl));
3981 0 : decl_name = build_string_literal (decl_name_anonymous);
3982 : }
3983 :
3984 140 : tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
3985 140 : TREE_TYPE (decl), 3,
3986 : decl_size_arg, init_type_arg,
3987 : decl_name);
3988 140 : tree ret = build2_loc (loc, MODIFY_EXPR, void_type_node, decl, call);
3989 140 : return build_stmt (loc, EXPR_STMT, ret);
3990 : }
3991 :
3992 : /* Emit before ITER (and any labels/case labels before it) code like
3993 : if (0)
3994 : {
3995 : l1:
3996 : v4 = .DEFERRED_INIT (sizeof (v4), ?, "v4");
3997 : v3 = .DEFERRED_INIT (sizeof (v3), ?, "v3");
3998 : v2 = .DEFERRED_INIT (sizeof (v2), ?, "v2");
3999 : v1 = .DEFERRED_INIT (sizeof (v1), ?, "v1");
4000 : }
4001 : and return l1 label, or if it already exists, assert it has the
4002 : .DEFERRED_INIT calls for the right decls in the right order and
4003 : amend it, either by adding extra labels in between or further
4004 : ,DEFERRED_INIT calls before the first label and extra label before
4005 : that. If CASE_LABEL is non-NULL, emit that CASE_LABEL_EXPR instead
4006 : of adding a label. DECLS points to an array of NDECLS VAR_DECLs
4007 : which should be initialized. */
4008 :
4009 : static tree
4010 127 : maybe_add_deferred_init_calls (tree_stmt_iterator iter, tree case_label,
4011 : tree *decls, unsigned ndecls)
4012 : {
4013 127 : tree lab = NULL_TREE;
4014 191 : for (; !tsi_end_p (iter); tsi_prev (&iter))
4015 : {
4016 185 : switch (TREE_CODE (tsi_stmt (iter)))
4017 : {
4018 64 : case LABEL_EXPR:
4019 64 : case CASE_LABEL_EXPR:
4020 64 : case DEBUG_BEGIN_STMT:
4021 64 : continue;
4022 : default:
4023 : break;
4024 : }
4025 : break;
4026 : }
4027 127 : if (!tsi_end_p (iter)
4028 121 : && TREE_CODE (tsi_stmt (iter)) == IF_STMT
4029 204 : && IF_STMT_VACUOUS_INIT_P (tsi_stmt (iter)))
4030 : {
4031 : /* Found IF_STMT added for this or some adjacent
4032 : LABEL_EXPR/CASE_LABEL_EXPR by an earlier call to this function.
4033 : The decls are ordered so that we can always reuse it. Sometimes
4034 : by no modifications at all and just returning the right label
4035 : which was added already before, sometimes by adding a label in
4036 : between two previously added .DEFERRED_INIT calls and sometimes
4037 : by adding extra statements (.DEFERRED_INIT calls and LABEL_EXPR
4038 : before that) before the statements in IF_STMT body. */
4039 71 : tree then_clause = THEN_CLAUSE (tsi_stmt (iter));
4040 71 : iter = tsi_last (then_clause);
4041 71 : bool add = false;
4042 452 : for (unsigned int i = 0; i < ndecls; ++i)
4043 : {
4044 310 : tree decl = decls[i];
4045 310 : if (!add)
4046 : {
4047 : /* Skip over labels/case labels after .DEFERRED_INIT for the
4048 : DECL we are looking for. */
4049 399 : while (!tsi_end_p (iter)
4050 399 : && (TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR
4051 286 : || (TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR
4052 26 : && !case_label)))
4053 119 : tsi_prev (&iter);
4054 280 : if (tsi_end_p (iter))
4055 : {
4056 : /* Reached the start, we'll need to prepend further
4057 : statements. */
4058 20 : add = true;
4059 20 : iter = tsi_start (then_clause);
4060 : }
4061 : else
4062 : {
4063 : /* Found something, assert it is .DEFERRED_INIT for
4064 : DECL. */
4065 260 : tree t = tsi_stmt (iter);
4066 260 : gcc_checking_assert (TREE_CODE (t) == EXPR_STMT);
4067 260 : t = EXPR_STMT_EXPR (t);
4068 260 : gcc_checking_assert (TREE_CODE (t) == MODIFY_EXPR
4069 : && TREE_OPERAND (t, 0) == decl
4070 : && (TREE_CODE (TREE_OPERAND (t, 1))
4071 : == CALL_EXPR));
4072 260 : t = TREE_OPERAND (t, 1);
4073 260 : gcc_checking_assert (CALL_EXPR_FN (t) == NULL_TREE
4074 : && (CALL_EXPR_IFN (t)
4075 : == IFN_DEFERRED_INIT));
4076 260 : tsi_prev (&iter);
4077 : }
4078 : }
4079 280 : if (add)
4080 : {
4081 : /* If reached the start in this or some earlier iteration,
4082 : prepend .DEFERRED_INIT call for DECL. */
4083 50 : tree t = build_deferred_init_call (decl);
4084 50 : STMT_IS_FULL_EXPR_P (t) = 1;
4085 50 : tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
4086 : }
4087 : }
4088 71 : if (!add)
4089 : {
4090 : /* If .DEFERRED_INIT calls for all the decls were already there,
4091 : skip over case labels and if we find a LABEL_EXPR, return
4092 : its label. */
4093 63 : while (!tsi_end_p (iter)
4094 63 : && !case_label
4095 117 : && TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR)
4096 12 : tsi_prev (&iter);
4097 51 : if (tsi_end_p (iter))
4098 : {
4099 : /* Only case labels were found and we are looking for normal
4100 : label, we'll need to add it. */
4101 0 : add = true;
4102 0 : iter = tsi_start (then_clause);
4103 : }
4104 51 : else if (!case_label
4105 51 : && TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR)
4106 : /* Return existing label. */
4107 21 : lab = LABEL_EXPR_LABEL (tsi_stmt (iter));
4108 : else
4109 : {
4110 : /* We'll need to add a LABEL_EXPR or move CASE_LABEL_EXPR. */
4111 30 : gcc_checking_assert (case_label
4112 : || (TREE_CODE (tsi_stmt (iter))
4113 : == EXPR_STMT));
4114 30 : add = true;
4115 30 : tsi_next (&iter);
4116 30 : gcc_checking_assert (!tsi_end_p (iter));
4117 : }
4118 : }
4119 21 : if (add)
4120 : {
4121 50 : tree t;
4122 50 : if (case_label)
4123 : t = case_label;
4124 : else
4125 : {
4126 41 : lab = create_artificial_label (UNKNOWN_LOCATION);
4127 41 : t = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
4128 : }
4129 50 : tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
4130 : }
4131 : }
4132 : else
4133 : {
4134 : /* No IF_STMT created by this function found. Create it all
4135 : from scratch, so a LABEL_EXPR (or moved CASE_LABEL_EXPR)
4136 : followed by .DEFERRED_INIT calls inside of a new if (0). */
4137 56 : tree new_then = push_stmt_list ();
4138 56 : if (!case_label)
4139 : {
4140 23 : lab = create_artificial_label (UNKNOWN_LOCATION);
4141 23 : add_stmt (build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab));
4142 : }
4143 : else
4144 33 : add_stmt (case_label);
4145 146 : for (unsigned int i = ndecls; i; --i)
4146 90 : add_stmt (build_deferred_init_call (decls[i - 1]));
4147 56 : new_then = pop_stmt_list (new_then);
4148 56 : tree stmt = build4 (IF_STMT, void_type_node, boolean_false_node,
4149 : new_then, void_node, NULL_TREE);
4150 56 : IF_STMT_VACUOUS_INIT_P (stmt) = 1;
4151 56 : if (tsi_end_p (iter))
4152 : {
4153 6 : iter = tsi_start (iter.container);
4154 6 : tsi_link_before (&iter, stmt, TSI_SAME_STMT);
4155 : }
4156 : else
4157 50 : tsi_link_after (&iter, stmt, TSI_CONTINUE_LINKING);
4158 : }
4159 127 : return lab;
4160 : }
4161 :
4162 : /* Adjust backward gotos to named label ENT if they jump over vacuous
4163 : initializers if !!flag_auto_var_init. ITER is the location of
4164 : LABEL_EXPR for that named label. */
4165 :
4166 : static void
4167 19 : adjust_backward_goto (named_label_entry *ent, tree_stmt_iterator iter)
4168 : {
4169 19 : auto_vec<tree, 4> decls;
4170 19 : unsigned int i, max_cnt = ent->direct_goto->last ().n_bad_decls;
4171 19 : tree decl;
4172 107 : FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, i, decl)
4173 88 : if (!decl_jump_unsafe (decl))
4174 : {
4175 88 : gcc_checking_assert (decl_instrument_init_bypass_p (decl));
4176 88 : decls.safe_push (decl);
4177 176 : if (decls.length () == max_cnt)
4178 : break;
4179 : }
4180 19 : named_label_bck_direct_goto *dgoto;
4181 19 : unsigned last = 0;
4182 19 : tree lab = NULL_TREE;
4183 103 : FOR_EACH_VEC_SAFE_ELT_REVERSE (ent->direct_goto, i, dgoto)
4184 : {
4185 46 : if (dgoto->n_bad_decls != last)
4186 : {
4187 40 : last = dgoto->n_bad_decls;
4188 80 : lab = maybe_add_deferred_init_calls (iter, NULL_TREE,
4189 : decls.address (), last);
4190 : }
4191 46 : *dgoto->direct_goto = lab;
4192 : }
4193 19 : }
4194 :
4195 : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
4196 : to the user. */
4197 :
4198 : static bool
4199 286 : identify_goto (tree decl, location_t loc, const location_t *locus,
4200 : enum diagnostics::kind diag_kind, bool computed)
4201 : {
4202 286 : if (computed)
4203 43 : diag_kind = diagnostics::kind::warning;
4204 286 : auto_diagnostic_group d;
4205 286 : bool complained
4206 373 : = emit_diagnostic (diag_kind, loc, 0,
4207 : decl ? G_("jump to label %qD")
4208 : : G_("jump to case label"), decl);
4209 286 : if (complained && locus)
4210 : {
4211 199 : if (computed)
4212 43 : inform (*locus, " as a possible target of computed goto");
4213 : else
4214 156 : inform (*locus, " from here");
4215 : }
4216 572 : return complained;
4217 286 : }
4218 :
4219 : /* Check that a single previously seen jump to a newly defined label
4220 : is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
4221 : the jump context; NAMES are the names in scope in LEVEL at the jump
4222 : context; LOCUS is the source position of the jump or 0. COMPUTED
4223 : is a vec of decls if the jump is a computed goto. DIRECT_GOTO is a
4224 : vec of pointers to LABEL_DECLs that might need adjusting if vacuous
4225 : initializations are crossed for !!flag_auto_var_init. CASE_LABEL is
4226 : CASE_LABEL_EXPR to be moved if needed for the check_switch_goto case.
4227 : Returns non-zero if all is well, 2 if any vacuous initializers were
4228 : crossed. */
4229 :
4230 : static int
4231 1832076 : check_previous_goto_1 (tree decl, cp_binding_level *level, tree names,
4232 : bool exited_omp, const location_t *locus,
4233 : vec<tree, va_gc> *computed,
4234 : vec<named_label_fwd_direct_goto, va_gc> *direct_goto,
4235 : tree case_label)
4236 : {
4237 1832076 : auto_diagnostic_group d;
4238 1832076 : cp_binding_level *b;
4239 1832076 : bool complained = false;
4240 1832076 : int identified = 0;
4241 1832076 : bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
4242 1832076 : bool saw_ceif = false, saw_se = false;
4243 1832076 : auto_vec<tree> vacuous_decls;
4244 1832076 : bool vacuous_inits = false;
4245 :
4246 1832076 : if (exited_omp)
4247 : {
4248 12 : complained = identify_goto (decl, input_location, locus,
4249 : diagnostics::kind::error,
4250 : computed);
4251 12 : if (complained)
4252 12 : inform (input_location, " exits OpenMP structured block");
4253 : saw_omp = true;
4254 : identified = 2;
4255 : }
4256 :
4257 3634718 : for (b = current_binding_level; b ; b = b->level_chain)
4258 : {
4259 3634718 : tree new_decls, old_decls = (b == level ? names : NULL_TREE);
4260 :
4261 6600983 : for (new_decls = b->names; new_decls != old_decls;
4262 5921842 : new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
4263 2955577 : : TREE_CHAIN (new_decls)))
4264 : {
4265 2966265 : bool problem = decl_jump_unsafe (new_decls);
4266 2966265 : if (! problem)
4267 : {
4268 2966220 : if (decl_instrument_init_bypass_p (new_decls))
4269 : {
4270 323 : if (direct_goto || case_label)
4271 254 : vacuous_decls.safe_push (new_decls);
4272 : vacuous_inits = true;
4273 : }
4274 2966220 : continue;
4275 : }
4276 :
4277 45 : if (!identified)
4278 : {
4279 45 : complained = identify_goto (decl, input_location, locus,
4280 : diagnostics::kind::error,
4281 : computed);
4282 45 : identified = 2;
4283 : }
4284 45 : if (complained)
4285 45 : inform (DECL_SOURCE_LOCATION (new_decls),
4286 : " crosses initialization of %q#D", new_decls);
4287 : }
4288 :
4289 3634718 : if (b == level)
4290 : break;
4291 :
4292 1802642 : const char *inf = NULL;
4293 1802642 : location_t loc = input_location;
4294 1802642 : switch (b->kind)
4295 : {
4296 3 : case sk_try:
4297 3 : if (!saw_eh)
4298 : inf = G_(" enters %<try%> block");
4299 : saw_eh = true;
4300 : break;
4301 :
4302 9 : case sk_catch:
4303 9 : if (!saw_eh)
4304 : inf = G_(" enters %<catch%> block");
4305 : saw_eh = true;
4306 : break;
4307 :
4308 102 : case sk_omp:
4309 102 : if (!saw_omp)
4310 : inf = G_(" enters OpenMP structured block");
4311 : saw_omp = true;
4312 : break;
4313 :
4314 3 : case sk_transaction:
4315 3 : if (!saw_tm)
4316 : inf = G_(" enters synchronized or atomic statement");
4317 : saw_tm = true;
4318 : break;
4319 :
4320 18 : case sk_stmt_expr:
4321 18 : if (!saw_se)
4322 : inf = G_(" enters statement expression");
4323 : saw_se = true;
4324 : break;
4325 :
4326 1802367 : case sk_block:
4327 1802367 : if (!saw_cxif && level_for_constexpr_if (b->level_chain))
4328 : {
4329 9 : inf = G_(" enters %<constexpr if%> statement");
4330 9 : loc = EXPR_LOCATION (b->level_chain->this_entity);
4331 : saw_cxif = true;
4332 : }
4333 1802358 : else if (!saw_ceif && level_for_consteval_if (b->level_chain))
4334 : {
4335 18 : inf = G_(" enters %<consteval if%> statement");
4336 18 : loc = EXPR_LOCATION (b->level_chain->this_entity);
4337 : saw_ceif = true;
4338 : }
4339 : break;
4340 :
4341 : default:
4342 : break;
4343 : }
4344 :
4345 27 : if (inf)
4346 : {
4347 141 : if (identified < 2)
4348 141 : complained = identify_goto (decl, input_location, locus,
4349 : diagnostics::kind::error,
4350 : computed);
4351 141 : identified = 2;
4352 141 : if (complained)
4353 141 : inform (loc, inf);
4354 : }
4355 : }
4356 :
4357 1832076 : if (!vec_safe_is_empty (computed))
4358 : {
4359 9 : if (!identified)
4360 6 : complained = identify_goto (decl, input_location, locus,
4361 : diagnostics::kind::error,
4362 : computed);
4363 9 : identified = 2;
4364 9 : if (complained)
4365 18 : for (tree d : computed)
4366 : {
4367 9 : if (DECL_P (d))
4368 6 : inform (DECL_SOURCE_LOCATION (d), " does not destroy %qD", d);
4369 3 : else if (d == get_identifier ("catch"))
4370 3 : inform (*locus, " does not clean up handled exception");
4371 : }
4372 : }
4373 :
4374 1832165 : if (!vacuous_decls.is_empty () && !seen_error ())
4375 : {
4376 87 : tree_stmt_iterator iter = tsi_last (cur_stmt_list);
4377 87 : if (case_label)
4378 : {
4379 42 : gcc_checking_assert (tsi_stmt (iter) == case_label);
4380 42 : tsi_delink (&iter);
4381 42 : iter = tsi_last (cur_stmt_list);
4382 : }
4383 87 : tree lab = maybe_add_deferred_init_calls (iter, case_label,
4384 : vacuous_decls.address (),
4385 : vacuous_decls.length ());
4386 87 : if (lab)
4387 : {
4388 : unsigned int i;
4389 : named_label_fwd_direct_goto *dgoto;
4390 177 : FOR_EACH_VEC_SAFE_ELT (direct_goto, i, dgoto)
4391 45 : *dgoto->direct_goto = lab;
4392 : }
4393 : }
4394 :
4395 1832076 : if (identified)
4396 : return 0;
4397 1831872 : return vacuous_inits ? 2 : 1;
4398 1832076 : }
4399 :
4400 : static void
4401 2142 : check_previous_goto (tree decl, struct named_label_use_entry *use)
4402 : {
4403 2142 : check_previous_goto_1 (decl, use->binding_level,
4404 : use->names_in_scope, use->in_omp_scope,
4405 2142 : &use->o_goto_locus, use->computed_goto,
4406 : use->direct_goto, NULL_TREE);
4407 2142 : vec_free (use->direct_goto);
4408 2142 : }
4409 :
4410 : static int
4411 1829934 : check_switch_goto (cp_binding_level *level, tree case_label)
4412 : {
4413 1829934 : return check_previous_goto_1 (NULL_TREE, level, level->names,
4414 1829934 : false, NULL, nullptr, nullptr, case_label);
4415 : }
4416 :
4417 : /* Check that a new jump to a label ENT is OK. DECLP is a pointer
4418 : to a LABEL_DECL for direct gotos and NULL for computed gotos. */
4419 :
4420 : void
4421 2884 : check_goto_1 (named_label_entry *ent, tree *declp)
4422 : {
4423 2884 : auto_diagnostic_group d;
4424 2884 : tree decl = ent->label_decl;
4425 2884 : bool computed = declp == NULL;
4426 :
4427 : /* If the label hasn't been defined yet, defer checking. */
4428 2884 : if (! DECL_INITIAL (decl))
4429 : {
4430 : /* Don't bother creating another use if the last goto had the
4431 : same data, and will therefore create the same set of errors. */
4432 2214 : if (ent->uses
4433 661 : && ent->uses->binding_level == current_binding_level
4434 63 : && ent->uses->names_in_scope == current_binding_level->names)
4435 : {
4436 63 : if (declp
4437 57 : && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
4438 12 : && !processing_template_decl)
4439 10 : vec_safe_push (ent->uses->direct_goto,
4440 10 : named_label_fwd_direct_goto { declp });
4441 : return;
4442 : }
4443 :
4444 2151 : named_label_use_entry *new_use
4445 2151 : = ggc_alloc<named_label_use_entry> ();
4446 2151 : new_use->binding_level = current_binding_level;
4447 2151 : new_use->names_in_scope = current_binding_level->names;
4448 2151 : new_use->o_goto_locus = input_location;
4449 2151 : new_use->in_omp_scope = false;
4450 2151 : new_use->computed_goto = computed ? make_tree_vector () : nullptr;
4451 2151 : new_use->direct_goto = nullptr;
4452 2151 : if (declp
4453 2060 : && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
4454 368 : && !processing_template_decl)
4455 311 : vec_safe_push (new_use->direct_goto,
4456 311 : named_label_fwd_direct_goto { declp });
4457 :
4458 2151 : new_use->next = ent->uses;
4459 2151 : ent->uses = new_use;
4460 2151 : return;
4461 : }
4462 :
4463 670 : bool saw_catch = false, complained = false;
4464 670 : int identified = 0;
4465 670 : tree bad;
4466 670 : unsigned ix;
4467 670 : unsigned n_bad_decls = 0;
4468 :
4469 670 : if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
4470 655 : || ent->in_constexpr_if || ent->in_consteval_if
4471 649 : || ent->in_omp_scope || ent->in_stmt_expr
4472 631 : || ent->has_bad_decls)
4473 : {
4474 45 : enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
4475 45 : if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
4476 30 : || ent->in_consteval_if || ent->in_transaction_scope
4477 24 : || ent->in_omp_scope || ent->in_stmt_expr)
4478 39 : diag_kind = diagnostics::kind::error;
4479 45 : complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4480 : &input_location, diag_kind, computed);
4481 45 : identified = 1 + (diag_kind == diagnostics::kind::error);
4482 : }
4483 :
4484 860 : FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
4485 : {
4486 190 : bool problem = decl_jump_unsafe (bad);
4487 190 : if (!problem)
4488 : {
4489 184 : gcc_checking_assert (decl_instrument_init_bypass_p (bad));
4490 184 : n_bad_decls++;
4491 184 : continue;
4492 : }
4493 :
4494 6 : if (DECL_ARTIFICIAL (bad))
4495 : {
4496 : /* Can't skip init of __exception_info. */
4497 0 : if (identified == 1)
4498 : {
4499 0 : complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4500 : &input_location,
4501 : diagnostics::kind::error,
4502 : computed);
4503 0 : identified = 2;
4504 : }
4505 0 : if (complained)
4506 0 : inform (DECL_SOURCE_LOCATION (bad), " enters %<catch%> block");
4507 : saw_catch = true;
4508 : }
4509 6 : else if (complained)
4510 6 : inform (DECL_SOURCE_LOCATION (bad),
4511 : " skips initialization of %q#D", bad);
4512 : }
4513 :
4514 670 : if (complained)
4515 : {
4516 45 : if (ent->in_try_scope)
4517 9 : inform (input_location, " enters %<try%> block");
4518 36 : else if (ent->in_catch_scope && !saw_catch)
4519 3 : inform (input_location, " enters %<catch%> block");
4520 33 : else if (ent->in_transaction_scope)
4521 3 : inform (input_location, " enters synchronized or atomic statement");
4522 30 : else if (ent->in_constexpr_if)
4523 3 : inform (input_location, " enters %<constexpr if%> statement");
4524 27 : else if (ent->in_consteval_if)
4525 3 : inform (input_location, " enters %<consteval if%> statement");
4526 24 : else if (ent->in_stmt_expr)
4527 15 : inform (input_location, " enters statement expression");
4528 : }
4529 :
4530 670 : if (ent->in_omp_scope)
4531 : {
4532 3 : if (complained)
4533 3 : inform (input_location, " enters OpenMP structured block");
4534 : }
4535 667 : else if (flag_openmp)
4536 42 : for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
4537 : {
4538 42 : if (b == ent->binding_level)
4539 : break;
4540 36 : if (b->kind == sk_omp)
4541 : {
4542 21 : if (identified < 2)
4543 : {
4544 42 : complained = identify_goto (decl,
4545 21 : DECL_SOURCE_LOCATION (decl),
4546 : &input_location,
4547 : diagnostics::kind::error,
4548 : computed);
4549 21 : identified = 2;
4550 : }
4551 21 : if (complained)
4552 21 : inform (input_location, " exits OpenMP structured block");
4553 : break;
4554 : }
4555 : }
4556 :
4557 : /* Warn if a computed goto might involve a local variable going out of scope
4558 : without being cleaned up. */
4559 670 : if (computed)
4560 : {
4561 80 : auto level = ent->binding_level;
4562 80 : auto names = ent->names_in_scope;
4563 80 : for (auto b = current_binding_level; ; b = b->level_chain)
4564 : {
4565 138 : if (b->kind == sk_catch)
4566 : {
4567 6 : if (!identified)
4568 : {
4569 6 : complained
4570 6 : = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4571 : &input_location, diagnostics::kind::error,
4572 : computed);
4573 6 : identified = 2;
4574 : }
4575 6 : if (complained)
4576 6 : inform (input_location,
4577 : " does not clean up handled exception");
4578 : }
4579 138 : tree end = b == level ? names : NULL_TREE;
4580 154 : for (tree d = b->names; d != end; d = DECL_CHAIN (d))
4581 : {
4582 16 : if (automatic_var_with_nontrivial_dtor_p (d))
4583 : {
4584 10 : if (!identified)
4585 : {
4586 10 : complained
4587 10 : = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4588 : &input_location, diagnostics::kind::error,
4589 : computed);
4590 10 : identified = 2;
4591 : }
4592 10 : if (complained)
4593 10 : inform (DECL_SOURCE_LOCATION (d),
4594 : " does not destroy %qD", d);
4595 : }
4596 : }
4597 138 : if (b == level)
4598 : break;
4599 58 : }
4600 : }
4601 :
4602 670 : if (n_bad_decls && declp)
4603 46 : vec_safe_push (ent->direct_goto,
4604 46 : named_label_bck_direct_goto { declp, n_bad_decls });
4605 2884 : }
4606 :
4607 : /* Check that a new jump to a label *DECLP is OK. Called by
4608 : finish_goto_stmt. */
4609 :
4610 : void
4611 2844 : check_goto (tree *declp)
4612 : {
4613 2844 : if (!named_labels)
4614 : return;
4615 2829 : tree decl = *declp;
4616 2829 : if (TREE_CODE (decl) != LABEL_DECL)
4617 : {
4618 : /* We don't know where a computed goto is jumping,
4619 : so check all addressable labels. */
4620 330 : for (auto iter = named_labels->begin ();
4621 452 : iter != named_labels->end ();
4622 208 : ++iter)
4623 : {
4624 208 : auto ent = *iter;
4625 208 : if (ent->addressed)
4626 177 : check_goto_1 (ent, NULL);
4627 : }
4628 : }
4629 : else
4630 : {
4631 2707 : hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
4632 2707 : named_label_entry **slot
4633 2707 : = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
4634 2707 : named_label_entry *ent = *slot;
4635 2707 : check_goto_1 (ent, declp);
4636 : }
4637 : }
4638 :
4639 : /* Check that a return is ok wrt OpenMP structured blocks.
4640 : Called by finish_return_stmt. Returns true if all is well. */
4641 :
4642 : bool
4643 281799 : check_omp_return (void)
4644 : {
4645 837306 : for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
4646 837306 : if (b->kind == sk_omp)
4647 : {
4648 15 : error ("invalid exit from OpenMP structured block");
4649 15 : return false;
4650 : }
4651 837291 : else if (b->kind == sk_function_parms)
4652 : break;
4653 : return true;
4654 : }
4655 :
4656 : /* Define a label, specifying the location in the source file.
4657 : Return the LABEL_DECL node for the label. */
4658 :
4659 : tree
4660 20973 : define_label (location_t location, tree name)
4661 : {
4662 20973 : auto_cond_timevar tv (TV_NAME_LOOKUP);
4663 :
4664 : /* After labels, make any new cleanups in the function go into their
4665 : own new (temporary) binding contour. */
4666 20973 : for (cp_binding_level *p = current_binding_level;
4667 31772 : p->kind != sk_function_parms;
4668 10799 : p = p->level_chain)
4669 10799 : p->more_cleanups_ok = 0;
4670 :
4671 20973 : named_label_entry *ent = lookup_label_1 (name, false);
4672 20973 : tree decl = ent->label_decl;
4673 :
4674 20973 : if (DECL_INITIAL (decl) != NULL_TREE)
4675 : {
4676 6 : error ("duplicate label %qD", decl);
4677 6 : return error_mark_node;
4678 : }
4679 : else
4680 : {
4681 : /* Mark label as having been defined. */
4682 20967 : DECL_INITIAL (decl) = error_mark_node;
4683 : /* Say where in the source. */
4684 20967 : DECL_SOURCE_LOCATION (decl) = location;
4685 :
4686 20967 : ent->binding_level = current_binding_level;
4687 20967 : ent->names_in_scope = current_binding_level->names;
4688 :
4689 23109 : for (named_label_use_entry *use = ent->uses; use; use = use->next)
4690 2142 : check_previous_goto (decl, use);
4691 20967 : ent->uses = NULL;
4692 : }
4693 :
4694 20967 : return decl;
4695 20973 : }
4696 :
4697 : struct cp_switch
4698 : {
4699 : cp_binding_level *level;
4700 : struct cp_switch *next;
4701 : /* The SWITCH_STMT being built. */
4702 : tree switch_stmt;
4703 : /* A splay-tree mapping the low element of a case range to the high
4704 : element, or NULL_TREE if there is no high element. Used to
4705 : determine whether or not a new case label duplicates an old case
4706 : label. We need a tree, rather than simply a hash table, because
4707 : of the GNU case range extension. */
4708 : splay_tree cases;
4709 : /* Remember whether a default: case label has been seen. */
4710 : bool has_default_p;
4711 : /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT. */
4712 : bool break_stmt_seen_p;
4713 : /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
4714 : where BREAK_STMT doesn't belong to the SWITCH_STMT. */
4715 : bool in_loop_body_p;
4716 : };
4717 :
4718 : /* A stack of the currently active switch statements. The innermost
4719 : switch statement is on the top of the stack. There is no need to
4720 : mark the stack for garbage collection because it is only active
4721 : during the processing of the body of a function, and we never
4722 : collect at that point. */
4723 :
4724 : static struct cp_switch *switch_stack;
4725 :
4726 : /* Called right after a switch-statement condition is parsed.
4727 : SWITCH_STMT is the switch statement being parsed. */
4728 :
4729 : void
4730 741367 : push_switch (tree switch_stmt)
4731 : {
4732 741367 : struct cp_switch *p = XNEW (struct cp_switch);
4733 741367 : p->level = current_binding_level;
4734 741367 : p->next = switch_stack;
4735 741367 : p->switch_stmt = switch_stmt;
4736 741367 : p->cases = splay_tree_new (case_compare, NULL, NULL);
4737 741367 : p->has_default_p = false;
4738 741367 : p->break_stmt_seen_p = false;
4739 741367 : p->in_loop_body_p = false;
4740 741367 : switch_stack = p;
4741 741367 : }
4742 :
4743 : void
4744 741367 : pop_switch (void)
4745 : {
4746 741367 : struct cp_switch *cs = switch_stack;
4747 :
4748 : /* Emit warnings as needed. */
4749 741367 : location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
4750 741367 : tree cond = SWITCH_STMT_COND (cs->switch_stmt);
4751 741367 : const bool bool_cond_p
4752 741367 : = (SWITCH_STMT_TYPE (cs->switch_stmt)
4753 741367 : && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
4754 741367 : if (!processing_template_decl)
4755 302825 : c_do_switch_warnings (cs->cases, switch_location,
4756 302825 : SWITCH_STMT_TYPE (cs->switch_stmt), cond,
4757 : bool_cond_p);
4758 :
4759 : /* For the benefit of block_may_fallthru remember if the switch body
4760 : case labels cover all possible values and if there are break; stmts. */
4761 741367 : if (cs->has_default_p
4762 741367 : || (!processing_template_decl
4763 42718 : && c_switch_covers_all_cases_p (cs->cases,
4764 42718 : SWITCH_STMT_TYPE (cs->switch_stmt))))
4765 551227 : SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
4766 741367 : if (!cs->break_stmt_seen_p)
4767 385354 : SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
4768 : /* Now that we're done with the switch warnings, set the switch type
4769 : to the type of the condition if the index type was of scoped enum type.
4770 : (Such types don't participate in the integer promotions.) We do this
4771 : because of bit-fields whose declared type is a scoped enum type:
4772 : gimplification will use the lowered index type, but convert the
4773 : case values to SWITCH_STMT_TYPE, which would have been the declared type
4774 : and verify_gimple_switch doesn't accept that. */
4775 741367 : if (is_bitfield_expr_with_lowered_type (cond))
4776 32922 : SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
4777 741367 : gcc_assert (!cs->in_loop_body_p);
4778 741367 : splay_tree_delete (cs->cases);
4779 741367 : switch_stack = switch_stack->next;
4780 741367 : free (cs);
4781 741367 : }
4782 :
4783 : /* Note that a BREAK_STMT is about to be added. If it is inside of
4784 : a SWITCH_STMT and not inside of a loop body inside of it, note
4785 : in switch_stack we've seen a BREAK_STMT. */
4786 :
4787 : void
4788 4951946 : note_break_stmt (void)
4789 : {
4790 4951946 : if (switch_stack && !switch_stack->in_loop_body_p)
4791 2782683 : switch_stack->break_stmt_seen_p = true;
4792 4951946 : }
4793 :
4794 : /* Note the start of processing of an iteration statement's body.
4795 : The note_break_stmt function will do nothing while processing it.
4796 : Return a flag that should be passed to note_iteration_stmt_body_end. */
4797 :
4798 : bool
4799 18703252 : note_iteration_stmt_body_start (void)
4800 : {
4801 18703252 : if (!switch_stack)
4802 : return false;
4803 198493 : bool ret = switch_stack->in_loop_body_p;
4804 198493 : switch_stack->in_loop_body_p = true;
4805 198493 : return ret;
4806 : }
4807 :
4808 : /* Note the end of processing of an iteration statement's body. */
4809 :
4810 : void
4811 18703252 : note_iteration_stmt_body_end (bool prev)
4812 : {
4813 18703252 : if (switch_stack)
4814 198493 : switch_stack->in_loop_body_p = prev;
4815 18703252 : }
4816 :
4817 : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
4818 : condition. Note that if TYPE and VALUE are already integral we don't
4819 : really do the conversion because the language-independent
4820 : warning/optimization code will work better that way. */
4821 :
4822 : static tree
4823 3659536 : case_conversion (tree type, tree value)
4824 : {
4825 3659536 : if (value == NULL_TREE)
4826 : return value;
4827 :
4828 1569834 : value = mark_rvalue_use (value);
4829 :
4830 1569834 : if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
4831 1126814 : type = type_promotes_to (type);
4832 :
4833 1569834 : tree ovalue = value;
4834 : /* The constant-expression VALUE shall be a converted constant expression
4835 : of the adjusted type of the switch condition, which doesn't allow
4836 : narrowing conversions. */
4837 1569834 : value = build_converted_constant_expr (type, value, tf_warning_or_error);
4838 :
4839 1569834 : if (cxx_dialect >= cxx11
4840 1569834 : && (SCOPED_ENUM_P (type)
4841 1123716 : || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
4842 : /* Use the converted value. */;
4843 : else
4844 : /* The already integral case. */
4845 : value = ovalue;
4846 :
4847 1569834 : return cxx_constant_value (value);
4848 : }
4849 :
4850 : /* Note that we've seen a definition of a case label, and complain if this
4851 : is a bad place for one. */
4852 :
4853 : tree
4854 6030364 : finish_case_label (location_t loc, tree low_value, tree high_value)
4855 : {
4856 6030364 : tree cond, r;
4857 6030364 : cp_binding_level *p;
4858 6030364 : tree type;
4859 :
4860 6030364 : if (low_value == NULL_TREE && high_value == NULL_TREE)
4861 551191 : switch_stack->has_default_p = true;
4862 :
4863 6030364 : if (processing_template_decl)
4864 : {
4865 4200473 : tree label;
4866 :
4867 : /* For templates, just add the case label; we'll do semantic
4868 : analysis at instantiation-time. But diagnose case labels
4869 : in expansion statements with switch outside of it here. */
4870 4200473 : if (in_expansion_stmt)
4871 39 : for (cp_binding_level *b = current_binding_level;
4872 78 : b != switch_stack->level; b = b->level_chain)
4873 63 : if (b->kind == sk_template_for && b->this_entity)
4874 : {
4875 24 : auto_diagnostic_group d;
4876 24 : error ("jump to case label");
4877 24 : inform (EXPR_LOCATION (b->this_entity),
4878 : " enters %<template for%> statement");
4879 24 : return error_mark_node;
4880 24 : }
4881 4200449 : label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
4882 4200449 : return add_stmt (build_case_label (low_value, high_value, label));
4883 : }
4884 :
4885 : /* Find the condition on which this switch statement depends. */
4886 1829891 : cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
4887 1829891 : if (cond && TREE_CODE (cond) == TREE_LIST)
4888 0 : cond = TREE_VALUE (cond);
4889 :
4890 1829891 : int chk_switch_goto = check_switch_goto (switch_stack->level, NULL_TREE);
4891 1829891 : if (!chk_switch_goto)
4892 87 : return error_mark_node;
4893 :
4894 1829804 : type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
4895 1829804 : if (type == error_mark_node)
4896 : return error_mark_node;
4897 :
4898 1829768 : low_value = case_conversion (type, low_value);
4899 1829768 : high_value = case_conversion (type, high_value);
4900 :
4901 1829768 : r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
4902 :
4903 1829768 : if (r != error_mark_node && chk_switch_goto == 2)
4904 43 : check_switch_goto (switch_stack->level, r);
4905 :
4906 : /* After labels, make any new cleanups in the function go into their
4907 : own new (temporary) binding contour. */
4908 1829768 : for (p = current_binding_level;
4909 7686918 : p->kind != sk_function_parms;
4910 5857150 : p = p->level_chain)
4911 5857150 : p->more_cleanups_ok = 0;
4912 :
4913 : return r;
4914 : }
4915 :
4916 : struct typename_info {
4917 : tree scope;
4918 : tree name;
4919 : tree template_id;
4920 : tag_types tag_type;
4921 : };
4922 :
4923 : struct typename_hasher : ggc_ptr_hash<tree_node>
4924 : {
4925 : typedef typename_info *compare_type;
4926 :
4927 : /* Hash a TYPENAME_TYPE. */
4928 :
4929 : static hashval_t
4930 507761807 : hash (tree context, tree fullname)
4931 : {
4932 507761807 : hashval_t hash = 0;
4933 507761807 : hash = iterative_hash_hashval_t (TYPE_HASH (context), hash);
4934 : /* FULLNAME could be a template-id, so use iterative_hash_template_arg here.
4935 : And might as well set comparing_specializations for stronger hashing. */
4936 507761807 : ++comparing_specializations;
4937 507761807 : hash = iterative_hash_template_arg (fullname, hash);
4938 507761807 : --comparing_specializations;
4939 507761807 : return hash;
4940 : }
4941 :
4942 : static hashval_t
4943 65946090 : hash (const typename_info *ti)
4944 : {
4945 65946090 : return typename_hasher::hash (ti->scope, ti->template_id);
4946 : }
4947 :
4948 : static hashval_t
4949 441815717 : hash (tree t)
4950 : {
4951 441815717 : return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
4952 : }
4953 :
4954 : /* Compare two TYPENAME_TYPEs. */
4955 :
4956 : static bool
4957 511660300 : equal (tree t1, const typename_info *t2)
4958 : {
4959 511660300 : return (TYPE_IDENTIFIER (t1) == t2->name
4960 147147150 : && TYPE_CONTEXT (t1) == t2->scope
4961 34564212 : && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
4962 545503699 : && get_typename_tag (t1) == t2->tag_type);
4963 : }
4964 : };
4965 :
4966 : /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
4967 : the type of `T', NAME is the IDENTIFIER_NODE for `t'.
4968 :
4969 : Returns the new TYPENAME_TYPE. */
4970 :
4971 : static GTY (()) hash_table<typename_hasher> *typename_htab;
4972 :
4973 : tree
4974 65946090 : build_typename_type (tree context, tree name, tree fullname,
4975 : enum tag_types tag_type)
4976 : {
4977 65946090 : typename_info ti;
4978 :
4979 65946090 : if (typename_htab == NULL)
4980 20527 : typename_htab = hash_table<typename_hasher>::create_ggc (61);
4981 :
4982 65946090 : ti.scope = FROB_CONTEXT (context);
4983 65946090 : ti.name = name;
4984 65946090 : ti.template_id = fullname;
4985 65946090 : ti.tag_type = tag_type;
4986 65946090 : hashval_t hash = typename_hasher::hash (&ti);
4987 :
4988 : /* See if we already have this type. */
4989 65946090 : tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
4990 65946090 : tree t = *e;
4991 65946090 : if (*e)
4992 : t = *e;
4993 : else
4994 : {
4995 : /* Build the TYPENAME_TYPE. */
4996 33293875 : t = cxx_make_type (TYPENAME_TYPE);
4997 33293875 : TYPE_CONTEXT (t) = ti.scope;
4998 33293875 : TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
4999 33293875 : set_typename_tag (t, ti.tag_type);
5000 :
5001 : /* Build the corresponding TYPE_DECL. */
5002 33293875 : tree d = build_decl (input_location, TYPE_DECL, name, t);
5003 33293875 : TYPE_NAME (t) = d;
5004 33293875 : TYPE_STUB_DECL (t) = d;
5005 33293875 : DECL_CONTEXT (d) = ti.scope;
5006 33293875 : DECL_ARTIFICIAL (d) = 1;
5007 :
5008 : /* Store it in the hash table. */
5009 33293875 : *e = t;
5010 :
5011 : /* TYPENAME_TYPEs must always be compared structurally, because
5012 : they may or may not resolve down to another type depending on
5013 : the currently open classes. */
5014 33293875 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5015 : }
5016 :
5017 65946090 : return t;
5018 : }
5019 :
5020 : /* Resolve `typename CONTEXT::NAME'. TAG_TYPE indicates the tag
5021 : provided to name the type. Returns an appropriate type, unless an
5022 : error occurs, in which case error_mark_node is returned. If we
5023 : locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
5024 : return that, rather than the _TYPE it corresponds to, in other
5025 : cases we look through the type decl. If TF_ERROR is set, complain
5026 : about errors, otherwise be quiet. */
5027 :
5028 : tree
5029 279337230 : make_typename_type (tree context, tree name, enum tag_types tag_type,
5030 : tsubst_flags_t complain)
5031 : {
5032 279337230 : tree fullname;
5033 279337230 : tree t;
5034 279337230 : bool want_template;
5035 :
5036 279337230 : if (name == error_mark_node
5037 279337224 : || context == NULL_TREE
5038 279337224 : || context == error_mark_node)
5039 : return error_mark_node;
5040 :
5041 279337208 : if (TYPE_P (name))
5042 : {
5043 0 : if (!(TYPE_LANG_SPECIFIC (name)
5044 0 : && (CLASSTYPE_IS_TEMPLATE (name)
5045 0 : || CLASSTYPE_USE_TEMPLATE (name))))
5046 0 : name = TYPE_IDENTIFIER (name);
5047 : else
5048 : /* Create a TEMPLATE_ID_EXPR for the type. */
5049 0 : name = build_nt (TEMPLATE_ID_EXPR,
5050 0 : CLASSTYPE_TI_TEMPLATE (name),
5051 0 : CLASSTYPE_TI_ARGS (name));
5052 : }
5053 279337208 : else if (TREE_CODE (name) == TYPE_DECL)
5054 0 : name = DECL_NAME (name);
5055 :
5056 279337208 : fullname = name;
5057 :
5058 279337208 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
5059 : {
5060 5447082 : name = TREE_OPERAND (name, 0);
5061 5447082 : if (DECL_TYPE_TEMPLATE_P (name))
5062 0 : name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
5063 5447082 : if (TREE_CODE (name) != IDENTIFIER_NODE)
5064 : {
5065 0 : if (complain & tf_error)
5066 0 : error ("%qD is not a type", name);
5067 0 : return error_mark_node;
5068 : }
5069 : }
5070 279337208 : if (TREE_CODE (name) == TEMPLATE_DECL)
5071 : {
5072 0 : if (complain & tf_error)
5073 0 : error ("%qD used without template arguments", name);
5074 0 : return error_mark_node;
5075 : }
5076 279337208 : else if (is_overloaded_fn (name))
5077 : {
5078 3 : if (complain & tf_error)
5079 3 : error ("%qD is a function, not a type", name);
5080 3 : return error_mark_node;
5081 : }
5082 279337205 : gcc_assert (identifier_p (name));
5083 279337205 : gcc_assert (TYPE_P (context));
5084 :
5085 279337205 : if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
5086 : /* This can happen for C++17 variadic using (c++/88986). */;
5087 265762845 : else if (!MAYBE_CLASS_TYPE_P (context))
5088 : {
5089 6 : if (complain & tf_error)
5090 6 : error ("%q#T is not a class", context);
5091 6 : return error_mark_node;
5092 : }
5093 :
5094 : /* When the CONTEXT is a dependent type, NAME could refer to a
5095 : dependent base class of CONTEXT. But look inside it anyway
5096 : if CONTEXT is a currently open scope, in case it refers to a
5097 : member of the current instantiation or a non-dependent base;
5098 : lookup will stop when we hit a dependent base. */
5099 279337199 : if (!dependent_scope_p (context))
5100 : {
5101 : /* We generally don't ignore non-types during TYPENAME_TYPE lookup
5102 : (as per [temp.res.general]/3), unless
5103 : - the tag corresponds to a class-key or 'enum' so
5104 : [basic.lookup.elab] applies, or
5105 : - the tag corresponds to scope_type or tf_qualifying_scope is
5106 : set so [basic.lookup.qual]/1 applies, or
5107 : - we're inside a base-specifier so [class.derived.general]/2 applies;
5108 : the tag will already be class_type in that case.
5109 : TODO: If we'd set/track the scope_type tag thoroughly on all
5110 : TYPENAME_TYPEs that are followed by :: then we wouldn't need the
5111 : tf_qualifying_scope flag. */
5112 436704466 : bool want_type = (tag_type != none_type && tag_type != typename_type)
5113 218352233 : || (complain & tf_qualifying_scope);
5114 218352233 : t = lookup_member (context, name, /*protect=*/2, want_type, complain);
5115 : }
5116 : else
5117 : t = NULL_TREE;
5118 :
5119 279337199 : if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
5120 60985987 : return build_typename_type (context, name, fullname, tag_type);
5121 :
5122 218351212 : want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
5123 :
5124 218351212 : if (!t)
5125 : {
5126 19825279 : if (complain & tf_error)
5127 : {
5128 223 : if (!COMPLETE_TYPE_P (context))
5129 18 : cxx_incomplete_type_error (NULL_TREE, context);
5130 : else
5131 409 : error (want_template ? G_("no class template named %q#T in %q#T")
5132 : : G_("no type named %q#T in %q#T"), name, context);
5133 : }
5134 19825279 : return error_mark_node;
5135 : }
5136 :
5137 : /* Pull out the template from an injected-class-name (or multiple). */
5138 198525933 : if (want_template)
5139 3466323 : t = maybe_get_template_decl_from_type_decl (t);
5140 :
5141 198525933 : if (TREE_CODE (t) == TREE_LIST)
5142 : {
5143 3 : if (complain & tf_error)
5144 : {
5145 3 : auto_diagnostic_group d;
5146 3 : error ("lookup of %qT in %qT is ambiguous", name, context);
5147 3 : print_candidates (input_location, t);
5148 3 : }
5149 3 : return error_mark_node;
5150 : }
5151 :
5152 198525930 : if (want_template && !DECL_TYPE_TEMPLATE_P (t))
5153 : {
5154 6 : if (complain & tf_error)
5155 6 : error ("%<typename %T::%D%> names %q#T, which is not a class template",
5156 : context, name, t);
5157 6 : return error_mark_node;
5158 : }
5159 198525924 : if (!want_template && TREE_CODE (t) != TYPE_DECL)
5160 : {
5161 2187 : if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
5162 4377 : && DECL_TYPE_TEMPLATE_P (t))
5163 : /* The caller permits this typename-specifier to name a template
5164 : (because it appears in a CTAD-enabled context). */;
5165 : else
5166 : {
5167 23 : if (complain & tf_error)
5168 17 : error ("%<typename %T::%D%> names %q#D, which is not a type",
5169 : context, name, t);
5170 23 : return error_mark_node;
5171 : }
5172 : }
5173 :
5174 198525901 : if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
5175 : context, complain))
5176 42 : return error_mark_node;
5177 :
5178 198525859 : if (!want_template && DECL_TYPE_TEMPLATE_P (t))
5179 2176 : return make_template_placeholder (t);
5180 :
5181 198523683 : if (want_template)
5182 : {
5183 3466317 : t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
5184 : NULL_TREE, context,
5185 : complain | tf_user);
5186 3466317 : if (t == error_mark_node)
5187 : return error_mark_node;
5188 3466312 : t = TYPE_NAME (t);
5189 : }
5190 :
5191 198523678 : if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
5192 2415113 : t = TREE_TYPE (t);
5193 :
5194 198523678 : maybe_record_typedef_use (t);
5195 :
5196 198523678 : return t;
5197 : }
5198 :
5199 : /* Resolve `CONTEXT::template NAME'. Returns a TEMPLATE_DECL if the name
5200 : can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
5201 : in which case error_mark_node is returned.
5202 :
5203 : If PARM_LIST is non-NULL, also make sure that the template parameter
5204 : list of TEMPLATE_DECL matches.
5205 :
5206 : If COMPLAIN zero, don't complain about any errors that occur. */
5207 :
5208 : tree
5209 189561 : make_unbound_class_template (tree context, tree name, tree parm_list,
5210 : tsubst_flags_t complain)
5211 : {
5212 189561 : if (TYPE_P (name))
5213 0 : name = TYPE_IDENTIFIER (name);
5214 189561 : else if (DECL_P (name))
5215 0 : name = DECL_NAME (name);
5216 189561 : gcc_assert (identifier_p (name));
5217 :
5218 189561 : if (!dependent_type_p (context)
5219 189561 : || currently_open_class (context))
5220 : {
5221 93532 : tree tmpl = NULL_TREE;
5222 :
5223 93532 : if (MAYBE_CLASS_TYPE_P (context))
5224 93526 : tmpl = lookup_field (context, name, 0, false);
5225 :
5226 93526 : if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
5227 3 : tmpl = maybe_get_template_decl_from_type_decl (tmpl);
5228 :
5229 93520 : if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
5230 : {
5231 12 : if (complain & tf_error)
5232 9 : error ("no class template named %q#T in %q#T", name, context);
5233 12 : return error_mark_node;
5234 : }
5235 :
5236 93520 : if (parm_list
5237 93520 : && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
5238 : {
5239 0 : if (complain & tf_error)
5240 : {
5241 0 : auto_diagnostic_group d;
5242 0 : error ("template parameters do not match template %qD", tmpl);
5243 0 : inform (DECL_SOURCE_LOCATION (tmpl),
5244 : "%qD declared here", tmpl);
5245 0 : }
5246 0 : return error_mark_node;
5247 : }
5248 :
5249 93520 : if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
5250 : complain))
5251 0 : return error_mark_node;
5252 :
5253 : return tmpl;
5254 : }
5255 :
5256 96029 : return make_unbound_class_template_raw (context, name, parm_list);
5257 : }
5258 :
5259 : /* Build an UNBOUND_CLASS_TEMPLATE. */
5260 :
5261 : tree
5262 96081 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
5263 : {
5264 : /* Build the UNBOUND_CLASS_TEMPLATE. */
5265 96081 : tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
5266 96081 : TYPE_CONTEXT (t) = FROB_CONTEXT (context);
5267 96081 : TREE_TYPE (t) = NULL_TREE;
5268 96081 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5269 :
5270 : /* Build the corresponding TEMPLATE_DECL. */
5271 96081 : tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
5272 96081 : TYPE_NAME (t) = d;
5273 96081 : TYPE_STUB_DECL (t) = d;
5274 96081 : DECL_CONTEXT (d) = TYPE_CONTEXT (t);
5275 96081 : DECL_ARTIFICIAL (d) = 1;
5276 96081 : DECL_TEMPLATE_PARMS (d) = parm_list;
5277 :
5278 96081 : return t;
5279 : }
5280 :
5281 :
5282 :
5283 : /* Push the declarations of builtin types into the global namespace.
5284 : RID_INDEX is the index of the builtin type in the array
5285 : RID_POINTERS. NAME is the name used when looking up the builtin
5286 : type. TYPE is the _TYPE node for the builtin type.
5287 :
5288 : The calls to set_global_binding below should be
5289 : eliminated. Built-in types should not be looked up name; their
5290 : names are keywords that the parser can recognize. However, there
5291 : is code in c-common.cc that uses identifier_global_value to look up
5292 : built-in types by name. */
5293 :
5294 : void
5295 4210114 : record_builtin_type (enum rid rid_index,
5296 : const char* name,
5297 : tree type)
5298 : {
5299 4210114 : tree decl = NULL_TREE;
5300 :
5301 4210114 : if (name)
5302 : {
5303 2484614 : tree tname = get_identifier (name);
5304 2484614 : tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
5305 2484614 : DECL_ARTIFICIAL (tdecl) = 1;
5306 2484614 : set_global_binding (tdecl);
5307 2484614 : decl = tdecl;
5308 : }
5309 :
5310 4210114 : if ((int) rid_index < (int) RID_MAX)
5311 2584778 : if (tree rname = ridpointers[(int) rid_index])
5312 1975778 : if (!decl || DECL_NAME (decl) != rname)
5313 : {
5314 1421000 : tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
5315 1421000 : DECL_ARTIFICIAL (rdecl) = 1;
5316 1421000 : set_global_binding (rdecl);
5317 1421000 : if (!decl)
5318 : decl = rdecl;
5319 : }
5320 :
5321 3905614 : if (decl)
5322 : {
5323 3601114 : if (!TYPE_NAME (type))
5324 2992114 : TYPE_NAME (type) = decl;
5325 3601114 : debug_hooks->type_decl (decl, 0);
5326 : }
5327 4210114 : }
5328 :
5329 : /* Push a type into the namespace so that the back ends ignore it. */
5330 :
5331 : static void
5332 304500 : record_unknown_type (tree type, const char* name)
5333 : {
5334 304500 : tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
5335 : TYPE_DECL, get_identifier (name), type));
5336 : /* Make sure the "unknown type" typedecl gets ignored for debug info. */
5337 304500 : DECL_IGNORED_P (decl) = 1;
5338 304500 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
5339 304500 : TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
5340 304500 : SET_TYPE_ALIGN (type, 1);
5341 304500 : TYPE_USER_ALIGN (type) = 0;
5342 304500 : SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
5343 304500 : }
5344 :
5345 : /* Create all the predefined identifiers. */
5346 :
5347 : static void
5348 101500 : initialize_predefined_identifiers (void)
5349 : {
5350 101500 : struct predefined_identifier
5351 : {
5352 : const char *name; /* Name. */
5353 : tree *node; /* Node to store it in. */
5354 : cp_identifier_kind kind; /* Kind of identifier. */
5355 : };
5356 :
5357 : /* A table of identifiers to create at startup. */
5358 101500 : static const predefined_identifier predefined_identifiers[] = {
5359 : {"C++", &lang_name_cplusplus, cik_normal},
5360 : {"C", &lang_name_c, cik_normal},
5361 : /* Some of these names have a trailing space so that it is
5362 : impossible for them to conflict with names written by users. */
5363 : {"__ct ", &ctor_identifier, cik_ctor},
5364 : {"__ct_base ", &base_ctor_identifier, cik_ctor},
5365 : {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
5366 : {"__dt ", &dtor_identifier, cik_dtor},
5367 : {"__dt_base ", &base_dtor_identifier, cik_dtor},
5368 : {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
5369 : {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
5370 : {"__conv_op ", &conv_op_identifier, cik_conv_op},
5371 : {"__in_chrg", &in_charge_identifier, cik_normal},
5372 : {"__as_base ", &as_base_identifier, cik_normal},
5373 : {"this", &this_identifier, cik_normal},
5374 : {"__delta", &delta_identifier, cik_normal},
5375 : {"__pfn", &pfn_identifier, cik_normal},
5376 : {"_vptr", &vptr_identifier, cik_normal},
5377 : {"__vtt_parm", &vtt_parm_identifier, cik_normal},
5378 : {"::", &global_identifier, cik_normal},
5379 : /* The demangler expects anonymous namespaces to be called
5380 : something starting with '_GLOBAL__N_'. It no longer needs
5381 : to be unique to the TU. */
5382 : {"_GLOBAL__N_1", &anon_identifier, cik_normal},
5383 : {"auto", &auto_identifier, cik_normal},
5384 : {"decltype(auto)", &decltype_auto_identifier, cik_normal},
5385 : {"initializer_list", &init_list_identifier, cik_normal},
5386 : {"__for_range ", &for_range__identifier, cik_normal},
5387 : {"__for_begin ", &for_begin__identifier, cik_normal},
5388 : {"__for_end ", &for_end__identifier, cik_normal},
5389 : {"__for_range", &for_range_identifier, cik_normal},
5390 : {"__for_begin", &for_begin_identifier, cik_normal},
5391 : {"__for_end", &for_end_identifier, cik_normal},
5392 : {"abi_tag", &abi_tag_identifier, cik_normal},
5393 : {"aligned", &aligned_identifier, cik_normal},
5394 : {"begin", &begin_identifier, cik_normal},
5395 : {"end", &end_identifier, cik_normal},
5396 : {"get", &get__identifier, cik_normal},
5397 : {"gnu", &gnu_identifier, cik_normal},
5398 : {"tuple_element", &tuple_element_identifier, cik_normal},
5399 : {"tuple_size", &tuple_size_identifier, cik_normal},
5400 : {"type", &type_identifier, cik_normal},
5401 : {"value", &value_identifier, cik_normal},
5402 : {"_FUN", &fun_identifier, cik_normal},
5403 : {"__closure", &closure_identifier, cik_normal},
5404 : {"heap uninit", &heap_uninit_identifier, cik_normal},
5405 : {"heap ", &heap_identifier, cik_normal},
5406 : {"heap deleted", &heap_deleted_identifier, cik_normal},
5407 : {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
5408 : {"heap []", &heap_vec_identifier, cik_normal},
5409 : {"omp", &omp_identifier, cik_normal},
5410 : {"internal ", &internal_identifier, cik_normal},
5411 : {"annotation ", &annotation_identifier, cik_normal},
5412 : {NULL, NULL, cik_normal}
5413 : };
5414 :
5415 4973500 : for (const predefined_identifier *pid = predefined_identifiers;
5416 4973500 : pid->name; ++pid)
5417 : {
5418 4872000 : *pid->node = get_identifier (pid->name);
5419 : /* Some of these identifiers already have a special kind. */
5420 4872000 : if (pid->kind != cik_normal)
5421 812000 : set_identifier_kind (*pid->node, pid->kind);
5422 : }
5423 101500 : }
5424 :
5425 : /* Build a specific variant of operator new. */
5426 :
5427 : static void
5428 181600 : cxx_build_operator_new (tree newtype)
5429 : {
5430 181600 : tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
5431 181600 : DECL_IS_MALLOC (opnew) = 1;
5432 181600 : DECL_SET_IS_OPERATOR_NEW (opnew, true);
5433 181600 : DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
5434 181600 : opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
5435 181600 : DECL_IS_MALLOC (opnew) = 1;
5436 181600 : DECL_SET_IS_OPERATOR_NEW (opnew, true);
5437 181600 : DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
5438 181600 : }
5439 :
5440 : /* Build a specific variant of operator delete. */
5441 :
5442 : static void
5443 343121 : cxx_build_operator_delete (tree deltype)
5444 : {
5445 343121 : tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
5446 343121 : DECL_SET_IS_OPERATOR_DELETE (opdel, true);
5447 343121 : DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
5448 343121 : opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
5449 343121 : DECL_SET_IS_OPERATOR_DELETE (opdel, true);
5450 343121 : DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
5451 343121 : }
5452 :
5453 : /* Declare all variants of operator new and delete. */
5454 :
5455 : static void
5456 101500 : cxx_init_operator_new_delete_decls (void)
5457 : {
5458 101500 : tree newattrs, extvisattr;
5459 101500 : tree newtype, deltype;
5460 101500 : tree ptr_ftype_sizetype;
5461 101500 : tree new_eh_spec;
5462 101500 : tree void_ftype_ptr = build_function_type_list (void_type_node,
5463 : ptr_type_node, NULL_TREE);
5464 101500 : void_ftype_ptr
5465 101500 : = build_exception_variant (void_ftype_ptr, empty_except_spec);
5466 :
5467 101500 : ptr_ftype_sizetype
5468 101500 : = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
5469 101500 : if (cxx_dialect == cxx98)
5470 : {
5471 14312 : tree bad_alloc_id;
5472 14312 : tree bad_alloc_type_node;
5473 14312 : tree bad_alloc_decl;
5474 :
5475 14312 : push_nested_namespace (std_node);
5476 14312 : bad_alloc_id = get_identifier ("bad_alloc");
5477 14312 : bad_alloc_type_node = make_class_type (RECORD_TYPE);
5478 14312 : TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
5479 14312 : bad_alloc_decl
5480 14312 : = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
5481 14312 : DECL_CONTEXT (bad_alloc_decl) = current_namespace;
5482 14312 : pop_nested_namespace (std_node);
5483 :
5484 14312 : new_eh_spec
5485 14312 : = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
5486 : }
5487 : else
5488 87188 : new_eh_spec = noexcept_false_spec;
5489 :
5490 101500 : extvisattr = build_tree_list (get_identifier ("externally_visible"),
5491 : NULL_TREE);
5492 101500 : newattrs = tree_cons (get_identifier ("alloc_size"),
5493 : build_tree_list (NULL_TREE, integer_one_node),
5494 : extvisattr);
5495 101500 : newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
5496 101500 : newtype = build_exception_variant (newtype, new_eh_spec);
5497 101500 : deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
5498 101500 : deltype = build_exception_variant (deltype, empty_except_spec);
5499 101500 : cxx_build_operator_new (newtype);
5500 101500 : cxx_build_operator_delete (deltype);
5501 101500 : if (flag_sized_deallocation)
5502 : {
5503 : /* Also push the sized deallocation variants:
5504 : void operator delete(void*, std::size_t) throw();
5505 : void operator delete[](void*, std::size_t) throw(); */
5506 81426 : tree void_ftype_ptr_size
5507 81426 : = build_function_type_list (void_type_node, ptr_type_node,
5508 : size_type_node, NULL_TREE);
5509 81426 : deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
5510 : extvisattr);
5511 81426 : deltype = build_exception_variant (deltype, empty_except_spec);
5512 81426 : cxx_build_operator_delete (deltype);
5513 : }
5514 :
5515 101500 : if (aligned_new_threshold)
5516 : {
5517 80100 : push_nested_namespace (std_node);
5518 80100 : tree align_id = get_identifier ("align_val_t");
5519 80100 : align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
5520 : NULL_TREE, /*scoped*/true, NULL);
5521 80100 : pop_nested_namespace (std_node);
5522 :
5523 : /* operator new (size_t, align_val_t); */
5524 80100 : newtype = build_function_type_list (ptr_type_node, size_type_node,
5525 : align_type_node, NULL_TREE);
5526 80100 : newtype = cp_build_type_attribute_variant (newtype, newattrs);
5527 80100 : newtype = build_exception_variant (newtype, new_eh_spec);
5528 80100 : cxx_build_operator_new (newtype);
5529 :
5530 : /* operator delete (void *, align_val_t); */
5531 80100 : deltype = build_function_type_list (void_type_node, ptr_type_node,
5532 : align_type_node, NULL_TREE);
5533 80100 : deltype = cp_build_type_attribute_variant (deltype, extvisattr);
5534 80100 : deltype = build_exception_variant (deltype, empty_except_spec);
5535 80100 : cxx_build_operator_delete (deltype);
5536 :
5537 80100 : if (flag_sized_deallocation)
5538 : {
5539 : /* operator delete (void *, size_t, align_val_t); */
5540 80095 : deltype = build_function_type_list (void_type_node, ptr_type_node,
5541 : size_type_node, align_type_node,
5542 : NULL_TREE);
5543 80095 : deltype = cp_build_type_attribute_variant (deltype, extvisattr);
5544 80095 : deltype = build_exception_variant (deltype, empty_except_spec);
5545 80095 : cxx_build_operator_delete (deltype);
5546 : }
5547 : }
5548 101500 : }
5549 :
5550 : /* Create the predefined scalar types of C,
5551 : and some nodes representing standard constants (0, 1, (void *)0).
5552 : Initialize the global binding level.
5553 : Make definitions for built-in primitive functions. */
5554 :
5555 : void
5556 101500 : cxx_init_decl_processing (void)
5557 : {
5558 101500 : tree void_ftype;
5559 :
5560 : /* Create all the identifiers we need. */
5561 101500 : initialize_predefined_identifiers ();
5562 :
5563 : /* Create the global variables. */
5564 101500 : push_to_top_level ();
5565 :
5566 101500 : current_function_decl = NULL_TREE;
5567 101500 : current_binding_level = NULL;
5568 : /* Enter the global namespace. */
5569 101500 : gcc_assert (global_namespace == NULL_TREE);
5570 101500 : global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
5571 : void_type_node);
5572 101500 : TREE_PUBLIC (global_namespace) = true;
5573 101500 : DECL_MODULE_EXPORT_P (global_namespace) = true;
5574 101500 : DECL_CONTEXT (global_namespace)
5575 101500 : = build_translation_unit_decl (get_identifier (main_input_filename));
5576 : /* Remember whether we want the empty class passing ABI change warning
5577 : in this TU. */
5578 101500 : TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
5579 128494 : = warn_abi && abi_version_crosses (12);
5580 101500 : debug_hooks->register_main_translation_unit
5581 101500 : (DECL_CONTEXT (global_namespace));
5582 101500 : begin_scope (sk_namespace, global_namespace);
5583 101500 : current_namespace = global_namespace;
5584 :
5585 101500 : if (flag_visibility_ms_compat)
5586 6 : default_visibility = VISIBILITY_HIDDEN;
5587 :
5588 : /* Initially, C. */
5589 101500 : current_lang_name = lang_name_c;
5590 :
5591 : /* Create the `std' namespace. */
5592 101500 : push_namespace (get_identifier ("std"));
5593 101500 : std_node = current_namespace;
5594 101500 : pop_namespace ();
5595 :
5596 101500 : flag_noexcept_type = (cxx_dialect >= cxx17);
5597 :
5598 101500 : c_common_nodes_and_builtins ();
5599 :
5600 : /* Call the target stack_protect_guard hook if the stack protection
5601 : guard is declared as a global symbol. */
5602 101500 : if (targetm.stack_protect_guard_symbol_p ())
5603 24 : pushdecl (targetm.stack_protect_guard ());
5604 :
5605 101500 : tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
5606 101500 : tree decl
5607 101500 : = add_builtin_function ("__builtin_is_constant_evaluated",
5608 : bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
5609 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5610 101500 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5611 :
5612 : /* The concrete return type of __builtin_source_location is
5613 : const std::source_location::__impl*, but we can't form the type
5614 : at this point. So we initially declare it with an auto return
5615 : type which we then "deduce" from require_deduced_type upon first use. */
5616 101500 : tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
5617 101500 : decl = add_builtin_function ("__builtin_source_location",
5618 : auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
5619 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5620 101500 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5621 :
5622 101500 : tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
5623 : NULL_TREE);
5624 101500 : decl
5625 101500 : = add_builtin_function ("__builtin_is_corresponding_member",
5626 : bool_vaftype,
5627 : CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
5628 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5629 101500 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5630 :
5631 101500 : decl
5632 101500 : = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
5633 : bool_vaftype,
5634 : CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
5635 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5636 101500 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5637 :
5638 101500 : if (cxx_dialect >= cxx26)
5639 : {
5640 25485 : tree void_ptrintftype
5641 25485 : = build_function_type_list (void_type_node, ptr_type_node,
5642 : integer_type_node, NULL_TREE);
5643 25485 : decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
5644 : void_ptrintftype,
5645 : CP_BUILT_IN_EH_PTR_ADJUST_REF,
5646 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5647 25485 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5648 :
5649 : /* Similar case to __builtin_source_location above. The concrete
5650 : return type is std::exception_ptr, but we can't form the type
5651 : at this point, so it is deduced later. */
5652 25485 : decl = add_builtin_function ("__builtin_current_exception",
5653 : auto_ftype, CP_BUILT_IN_CURRENT_EXCEPTION,
5654 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5655 25485 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5656 :
5657 25485 : tree int_ftype = build_function_type_list (integer_type_node, NULL_TREE);
5658 25485 : decl = add_builtin_function ("__builtin_uncaught_exceptions",
5659 : int_ftype, CP_BUILT_IN_UNCAUGHT_EXCEPTIONS,
5660 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5661 25485 : set_call_expr_flags (decl, ECF_PURE | ECF_NOTHROW | ECF_LEAF);
5662 : }
5663 :
5664 101500 : decl
5665 101500 : = add_builtin_function ("__builtin_is_string_literal",
5666 : bool_vaftype,
5667 : CP_BUILT_IN_IS_STRING_LITERAL,
5668 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5669 101500 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5670 :
5671 101500 : tree void_vaintftype = build_varargs_function_type_list (void_type_node,
5672 : integer_type_node,
5673 : NULL_TREE);
5674 101500 : decl = add_builtin_function ("__builtin_constexpr_diag",
5675 : void_vaintftype,
5676 : CP_BUILT_IN_CONSTEXPR_DIAG,
5677 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5678 101500 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5679 :
5680 101500 : decl = add_builtin_function ("__builtin_is_within_lifetime",
5681 : bool_vaftype, CP_BUILT_IN_IS_WITHIN_LIFETIME,
5682 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5683 101500 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5684 101500 : SET_DECL_IMMEDIATE_FUNCTION_P (decl);
5685 :
5686 101500 : tree void_vaftype = build_varargs_function_type_list (void_type_node,
5687 : NULL_TREE);
5688 101500 : decl = add_builtin_function ("__builtin_start_lifetime",
5689 : void_vaftype, CP_BUILT_IN_START_LIFETIME,
5690 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5691 101500 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5692 :
5693 101500 : integer_two_node = build_int_cst (integer_type_node, 2);
5694 :
5695 : /* Guess at the initial static decls size. */
5696 101500 : vec_alloc (static_decls, 500);
5697 :
5698 : /* ... and keyed classes. */
5699 101500 : vec_alloc (keyed_classes, 100);
5700 :
5701 101500 : record_builtin_type (RID_BOOL, "bool", boolean_type_node);
5702 101500 : truthvalue_type_node = boolean_type_node;
5703 101500 : truthvalue_false_node = boolean_false_node;
5704 101500 : truthvalue_true_node = boolean_true_node;
5705 :
5706 101500 : empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
5707 101500 : noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
5708 101500 : noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
5709 101500 : noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
5710 : NULL_TREE);
5711 :
5712 : #if 0
5713 : record_builtin_type (RID_MAX, NULL, string_type_node);
5714 : #endif
5715 :
5716 101500 : delta_type_node = ptrdiff_type_node;
5717 101500 : vtable_index_type = ptrdiff_type_node;
5718 :
5719 101500 : vtt_parm_type = build_pointer_type (const_ptr_type_node);
5720 101500 : void_ftype = build_function_type_list (void_type_node, NULL_TREE);
5721 :
5722 : /* Create the conversion operator marker. This operator's DECL_NAME
5723 : is in the identifier table, so we can use identifier equality to
5724 : find it. */
5725 101500 : conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
5726 : void_ftype);
5727 :
5728 : /* C++ extensions */
5729 :
5730 101500 : unknown_type_node = make_node (LANG_TYPE);
5731 101500 : record_unknown_type (unknown_type_node, "unknown type");
5732 :
5733 : /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
5734 101500 : TREE_TYPE (unknown_type_node) = unknown_type_node;
5735 :
5736 : /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
5737 : result. */
5738 101500 : TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
5739 101500 : TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
5740 :
5741 101500 : init_list_type_node = make_node (LANG_TYPE);
5742 101500 : record_unknown_type (init_list_type_node, "init list");
5743 :
5744 : /* Used when parsing to distinguish parameter-lists () and (void). */
5745 101500 : explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
5746 :
5747 101500 : {
5748 : /* Make sure we get a unique function type, so we can give
5749 : its pointer type a name. (This wins for gdb.) */
5750 101500 : tree vfunc_type = make_node (FUNCTION_TYPE);
5751 101500 : TREE_TYPE (vfunc_type) = integer_type_node;
5752 101500 : TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
5753 101500 : layout_type (vfunc_type);
5754 :
5755 101500 : vtable_entry_type = build_pointer_type (vfunc_type);
5756 : }
5757 101500 : record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
5758 :
5759 101500 : vtbl_type_node
5760 101500 : = build_cplus_array_type (vtable_entry_type, NULL_TREE);
5761 101500 : layout_type (vtbl_type_node);
5762 101500 : vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
5763 101500 : record_builtin_type (RID_MAX, NULL, vtbl_type_node);
5764 101500 : vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
5765 101500 : layout_type (vtbl_ptr_type_node);
5766 101500 : record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
5767 :
5768 101500 : push_namespace (get_identifier ("__cxxabiv1"));
5769 101500 : abi_node = current_namespace;
5770 101500 : pop_namespace ();
5771 :
5772 101500 : any_targ_node = make_node (LANG_TYPE);
5773 101500 : record_unknown_type (any_targ_node, "any type");
5774 :
5775 : /* Now, C++. */
5776 101500 : current_lang_name = lang_name_cplusplus;
5777 :
5778 101500 : if (aligned_new_threshold > 1
5779 101500 : && !pow2p_hwi (aligned_new_threshold))
5780 : {
5781 0 : error ("%<-faligned-new=%d%> is not a power of two",
5782 : aligned_new_threshold);
5783 0 : aligned_new_threshold = 1;
5784 : }
5785 101500 : if (aligned_new_threshold == -1)
5786 122886 : aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
5787 101500 : if (aligned_new_threshold == 1)
5788 80097 : aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
5789 :
5790 : /* Ensure attribs.cc is initialized. */
5791 101500 : init_attributes ();
5792 101500 : cxx_init_operator_new_delete_decls ();
5793 :
5794 : /* C++-specific nullptr initialization. */
5795 101500 : if (abi_version_at_least (9))
5796 101329 : SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
5797 101500 : record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
5798 :
5799 101500 : if (! supports_one_only ())
5800 0 : flag_weak = 0;
5801 :
5802 101500 : abort_fndecl
5803 101500 : = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
5804 : ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
5805 101500 : if (flag_weak)
5806 : /* If no definition is available, resolve references to NULL. */
5807 101470 : declare_weak (abort_fndecl);
5808 :
5809 : /* Perform other language dependent initializations. */
5810 101500 : init_class_processing ();
5811 101500 : init_rtti_processing ();
5812 101500 : init_template_processing ();
5813 :
5814 101500 : if (flag_exceptions)
5815 100243 : init_exception_processing ();
5816 :
5817 101500 : if (flag_contracts)
5818 25530 : init_contracts ();
5819 :
5820 101500 : if (modules_p ())
5821 4973 : init_modules (parse_in);
5822 :
5823 101500 : if (flag_reflection)
5824 1336 : init_reflection ();
5825 :
5826 101500 : make_fname_decl = cp_make_fname_decl;
5827 101500 : start_fname_decls ();
5828 :
5829 : /* Show we use EH for cleanups. */
5830 101500 : if (flag_exceptions)
5831 100243 : using_eh_for_cleanups ();
5832 :
5833 : /* Check that the hardware interference sizes are at least
5834 : alignof(max_align_t), as required by the standard. */
5835 101500 : const int max_align = max_align_t_align () / BITS_PER_UNIT;
5836 101500 : if (OPTION_SET_P (param_destruct_interfere_size))
5837 : {
5838 0 : if (param_destruct_interfere_size < max_align)
5839 0 : error ("%<--param destructive-interference-size=%d%> is less than "
5840 : "%d", param_destruct_interfere_size, max_align);
5841 0 : else if (param_destruct_interfere_size < param_l1_cache_line_size)
5842 0 : warning (OPT_Winterference_size,
5843 : "%<--param destructive-interference-size=%d%> "
5844 : "is less than %<--param l1-cache-line-size=%d%>",
5845 : param_destruct_interfere_size, param_l1_cache_line_size);
5846 : }
5847 101500 : else if (param_destruct_interfere_size)
5848 : /* Assume the internal value is OK. */;
5849 0 : else if (param_l1_cache_line_size >= max_align)
5850 0 : param_destruct_interfere_size = param_l1_cache_line_size;
5851 : /* else leave it unset. */
5852 :
5853 101500 : if (OPTION_SET_P (param_construct_interfere_size))
5854 : {
5855 0 : if (param_construct_interfere_size < max_align)
5856 0 : error ("%<--param constructive-interference-size=%d%> is less than "
5857 : "%d", param_construct_interfere_size, max_align);
5858 0 : else if (param_construct_interfere_size > param_l1_cache_line_size
5859 0 : && param_l1_cache_line_size >= max_align)
5860 0 : warning (OPT_Winterference_size,
5861 : "%<--param constructive-interference-size=%d%> "
5862 : "is greater than %<--param l1-cache-line-size=%d%>",
5863 : param_construct_interfere_size, param_l1_cache_line_size);
5864 : }
5865 101500 : else if (param_construct_interfere_size)
5866 : /* Assume the internal value is OK. */;
5867 0 : else if (param_l1_cache_line_size >= max_align)
5868 0 : param_construct_interfere_size = param_l1_cache_line_size;
5869 101500 : }
5870 :
5871 : /* Enter an abi node in global-module context. returns a cookie to
5872 : give to pop_abi_namespace. */
5873 :
5874 : unsigned
5875 60167 : push_abi_namespace (tree node)
5876 : {
5877 60167 : push_nested_namespace (node);
5878 60167 : push_visibility ("default", 2);
5879 60167 : unsigned flags = module_kind;
5880 60167 : module_kind = 0;
5881 60167 : return flags;
5882 : }
5883 :
5884 : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
5885 : you. */
5886 :
5887 : void
5888 60167 : pop_abi_namespace (unsigned flags, tree node)
5889 : {
5890 60167 : module_kind = flags;
5891 60167 : pop_visibility (2);
5892 60167 : pop_nested_namespace (node);
5893 60167 : }
5894 :
5895 : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
5896 : the decl, LOC is the location to give the decl, NAME is the
5897 : initialization string and TYPE_DEP indicates whether NAME depended
5898 : on the type of the function. We make use of that to detect
5899 : __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
5900 : at the point of first use, so we mustn't push the decl now. */
5901 :
5902 : static tree
5903 243292 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
5904 : {
5905 243292 : tree domain = NULL_TREE;
5906 243292 : tree init = NULL_TREE;
5907 :
5908 243292 : if (!(type_dep && current_function_decl && in_template_context))
5909 : {
5910 60313 : const char *name = NULL;
5911 60313 : bool release_name = false;
5912 :
5913 60313 : if (current_function_decl == NULL_TREE)
5914 : name = "top level";
5915 60299 : else if (type_dep == 0)
5916 : {
5917 : /* __FUNCTION__ */
5918 838 : name = fname_as_string (type_dep);
5919 838 : release_name = true;
5920 : }
5921 : else
5922 : {
5923 : /* __PRETTY_FUNCTION__ */
5924 59461 : gcc_checking_assert (type_dep == 1);
5925 59461 : name = cxx_printable_name (current_function_decl, 2);
5926 : }
5927 :
5928 60299 : if (!release_name)
5929 : {
5930 59475 : cpp_string cstr = { 0, 0 }, strname;
5931 59475 : strname.text
5932 59475 : = const_cast <unsigned char *> ((const unsigned char *) name);
5933 59475 : strname.len = strlen (name) + 1;
5934 59475 : if (cpp_translate_string (parse_in, &strname, &cstr, CPP_STRING,
5935 : false))
5936 : {
5937 59475 : name = (const char *) cstr.text;
5938 59475 : release_name = true;
5939 : }
5940 : }
5941 :
5942 60313 : size_t length = strlen (name);
5943 60313 : domain = build_index_type (size_int (length));
5944 60313 : init = build_string (length + 1, name);
5945 60313 : if (release_name)
5946 60313 : free (const_cast<char *> (name));
5947 : }
5948 :
5949 243292 : tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
5950 243292 : type = build_cplus_array_type (type, domain);
5951 :
5952 243292 : if (init)
5953 60313 : TREE_TYPE (init) = type;
5954 : else
5955 182979 : init = error_mark_node;
5956 :
5957 243292 : tree decl = build_decl (loc, VAR_DECL, id, type);
5958 :
5959 243292 : TREE_READONLY (decl) = 1;
5960 243292 : DECL_ARTIFICIAL (decl) = 1;
5961 243292 : DECL_DECLARED_CONSTEXPR_P (decl) = 1;
5962 243292 : TREE_STATIC (decl) = 1;
5963 :
5964 243292 : TREE_USED (decl) = 1;
5965 :
5966 243292 : SET_DECL_VALUE_EXPR (decl, init);
5967 243292 : DECL_HAS_VALUE_EXPR_P (decl) = 1;
5968 : /* For decl_constant_var_p. */
5969 243292 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
5970 :
5971 243292 : if (current_function_decl)
5972 : {
5973 243278 : DECL_CONTEXT (decl) = current_function_decl;
5974 243278 : decl = pushdecl_outermost_localscope (decl);
5975 243278 : if (decl != error_mark_node)
5976 243275 : add_decl_expr (decl);
5977 : else
5978 3 : gcc_assert (seen_error ());
5979 : }
5980 : else
5981 : {
5982 14 : DECL_THIS_STATIC (decl) = true;
5983 14 : decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
5984 : }
5985 :
5986 243292 : return decl;
5987 : }
5988 :
5989 : /* Install DECL as a builtin function at current global scope. Return
5990 : the new decl (if we found an existing version). Also installs it
5991 : into ::std, if it's not '_*'. */
5992 :
5993 : tree
5994 236361917 : cxx_builtin_function (tree decl)
5995 : {
5996 236361917 : retrofit_lang_decl (decl);
5997 :
5998 236361917 : DECL_ARTIFICIAL (decl) = 1;
5999 236361917 : SET_DECL_LANGUAGE (decl, lang_c);
6000 : /* Runtime library routines are, by definition, available in an
6001 : external shared object. */
6002 236361917 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
6003 236361917 : DECL_VISIBILITY_SPECIFIED (decl) = 1;
6004 :
6005 236361917 : tree id = DECL_NAME (decl);
6006 236361917 : const char *name = IDENTIFIER_POINTER (id);
6007 236361917 : bool hiding = false;
6008 236361917 : if (name[0] != '_' || name[1] != '_')
6009 : /* In the user's namespace, it must be declared before use. */
6010 : hiding = true;
6011 198396807 : else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
6012 198396807 : && !startswith (name + 2, "builtin_")
6013 221983743 : && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
6014 : "_chk", strlen ("_chk") + 1))
6015 : /* Treat __*_chk fortification functions as anticipated as well,
6016 : unless they are __builtin_*_chk. */
6017 : hiding = true;
6018 :
6019 : /* All builtins that don't begin with an '_' should additionally
6020 : go in the 'std' namespace. */
6021 236361917 : if (name[0] != '_')
6022 : {
6023 37826504 : tree std_decl = copy_decl (decl);
6024 :
6025 37826504 : push_nested_namespace (std_node);
6026 37826504 : DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
6027 37826504 : pushdecl (std_decl, hiding);
6028 37826504 : pop_nested_namespace (std_node);
6029 : }
6030 :
6031 236361917 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
6032 236361917 : decl = pushdecl (decl, hiding);
6033 :
6034 236361917 : return decl;
6035 : }
6036 :
6037 : /* Like cxx_builtin_function, but guarantee the function is added to the global
6038 : scope. This is to allow function specific options to add new machine
6039 : dependent builtins when the target ISA changes via attribute((target(...)))
6040 : which saves space on program startup if the program does not use non-generic
6041 : ISAs. */
6042 :
6043 : tree
6044 832320 : cxx_builtin_function_ext_scope (tree decl)
6045 : {
6046 832320 : push_nested_namespace (global_namespace);
6047 832320 : decl = cxx_builtin_function (decl);
6048 832320 : pop_nested_namespace (global_namespace);
6049 :
6050 832320 : return decl;
6051 : }
6052 :
6053 : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL. */
6054 :
6055 : tree
6056 0 : cxx_simulate_builtin_function_decl (tree decl)
6057 : {
6058 0 : retrofit_lang_decl (decl);
6059 :
6060 0 : DECL_ARTIFICIAL (decl) = 1;
6061 0 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
6062 0 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
6063 0 : return pushdecl (decl);
6064 : }
6065 :
6066 : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
6067 : function. Not called directly. */
6068 :
6069 : static tree
6070 1640118 : build_library_fn (tree name, enum tree_code operator_code, tree type,
6071 : int ecf_flags)
6072 : {
6073 1640118 : tree fn = build_lang_decl (FUNCTION_DECL, name, type);
6074 1640118 : DECL_EXTERNAL (fn) = 1;
6075 1640118 : TREE_PUBLIC (fn) = 1;
6076 1640118 : DECL_ARTIFICIAL (fn) = 1;
6077 1640118 : DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
6078 1640118 : = OVL_OP_INFO (false, operator_code)->ovl_op_code;
6079 1640118 : SET_DECL_LANGUAGE (fn, lang_c);
6080 : /* Runtime library routines are, by definition, available in an
6081 : external shared object. */
6082 1640118 : DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
6083 1640118 : DECL_VISIBILITY_SPECIFIED (fn) = 1;
6084 1640118 : set_call_expr_flags (fn, ecf_flags);
6085 1640118 : return fn;
6086 : }
6087 :
6088 : /* Returns the _DECL for a library function with C++ linkage. */
6089 :
6090 : static tree
6091 1149945 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
6092 : int ecf_flags)
6093 : {
6094 1149945 : tree fn = build_library_fn (name, operator_code, type, ecf_flags);
6095 1149945 : DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
6096 1149945 : SET_DECL_LANGUAGE (fn, lang_cplusplus);
6097 1149945 : return fn;
6098 : }
6099 :
6100 : /* Like build_library_fn, but takes a C string instead of an
6101 : IDENTIFIER_NODE. */
6102 :
6103 : tree
6104 106669 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
6105 : {
6106 106669 : return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
6107 : }
6108 :
6109 : /* Like build_cp_library_fn, but takes a C string instead of an
6110 : IDENTIFIER_NODE. */
6111 :
6112 : tree
6113 100503 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
6114 : {
6115 100503 : return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
6116 100503 : ecf_flags);
6117 : }
6118 :
6119 : /* Like build_library_fn, but also pushes the function so that we will
6120 : be able to find it via get_global_binding. Also, the function
6121 : may throw exceptions listed in RAISES. */
6122 :
6123 : tree
6124 383504 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
6125 : {
6126 383504 : if (raises)
6127 43483 : type = build_exception_variant (type, raises);
6128 :
6129 383504 : tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
6130 383504 : return pushdecl_top_level (fn);
6131 : }
6132 :
6133 : /* Like build_cp_library_fn, but also pushes the function so that it
6134 : will be found by normal lookup. */
6135 :
6136 : static tree
6137 1049442 : push_cp_library_fn (enum tree_code operator_code, tree type,
6138 : int ecf_flags)
6139 : {
6140 1049442 : tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
6141 : operator_code, type, ecf_flags);
6142 1049442 : pushdecl (fn);
6143 1049442 : if (flag_tm)
6144 3052 : apply_tm_attr (fn, get_identifier ("transaction_safe"));
6145 1049442 : return fn;
6146 : }
6147 :
6148 : /* Like push_library_fn, but also note that this function throws
6149 : and does not return. Used for __throw_foo and the like. */
6150 :
6151 : tree
6152 111452 : push_throw_library_fn (tree name, tree type)
6153 : {
6154 111452 : tree fn = push_library_fn (name, type, NULL_TREE,
6155 : ECF_NORETURN | ECF_XTHROW | ECF_COLD);
6156 111452 : return fn;
6157 : }
6158 :
6159 : /* When we call finish_struct for an anonymous union, we create
6160 : default copy constructors and such. But, an anonymous union
6161 : shouldn't have such things; this function undoes the damage to the
6162 : anonymous union type T.
6163 :
6164 : (The reason that we create the synthesized methods is that we don't
6165 : distinguish `union { int i; }' from `typedef union { int i; } U'.
6166 : The first is an anonymous union; the second is just an ordinary
6167 : union type.) */
6168 :
6169 : void
6170 181596 : fixup_anonymous_aggr (tree t)
6171 : {
6172 : /* Wipe out memory of synthesized methods. */
6173 181596 : TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
6174 181596 : TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
6175 181596 : TYPE_HAS_COPY_CTOR (t) = 0;
6176 181596 : TYPE_HAS_CONST_COPY_CTOR (t) = 0;
6177 181596 : TYPE_HAS_COPY_ASSIGN (t) = 0;
6178 181596 : TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
6179 :
6180 : /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
6181 : invalid members. */
6182 1059999 : for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
6183 : {
6184 878403 : if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
6185 0 : *prev_p = DECL_CHAIN (probe);
6186 : else
6187 878403 : prev_p = &DECL_CHAIN (probe);
6188 :
6189 878403 : if (DECL_ARTIFICIAL (probe)
6190 878403 : && (!DECL_IMPLICIT_TYPEDEF_P (probe)
6191 78636 : || TYPE_ANON_P (TREE_TYPE (probe))))
6192 298261 : continue;
6193 :
6194 580142 : if (TREE_CODE (probe) != FIELD_DECL
6195 580088 : || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
6196 : {
6197 : /* We already complained about static data members in
6198 : finish_static_data_member_decl. */
6199 66 : if (!VAR_P (probe))
6200 : {
6201 51 : auto_diagnostic_group d;
6202 51 : if (permerror (DECL_SOURCE_LOCATION (probe),
6203 51 : TREE_CODE (t) == UNION_TYPE
6204 : ? "%q#D invalid; an anonymous union may "
6205 : "only have public non-static data members"
6206 : : "%q#D invalid; an anonymous struct may "
6207 : "only have public non-static data members", probe))
6208 : {
6209 51 : static bool hint;
6210 51 : if (flag_permissive && !hint)
6211 : {
6212 6 : hint = true;
6213 6 : inform (DECL_SOURCE_LOCATION (probe),
6214 : "this flexibility is deprecated and will be "
6215 : "removed");
6216 : }
6217 : }
6218 51 : }
6219 : }
6220 : }
6221 :
6222 : /* Splice all functions out of CLASSTYPE_MEMBER_VEC. */
6223 181596 : vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
6224 181596 : unsigned store = 0;
6225 536350 : for (tree elt : vec)
6226 354754 : if (!is_overloaded_fn (elt))
6227 354733 : (*vec)[store++] = elt;
6228 181596 : vec_safe_truncate (vec, store);
6229 :
6230 : /* Wipe RTTI info. */
6231 181596 : SET_CLASSTYPE_TYPEINFO_VAR (t, NULL_TREE);
6232 :
6233 : /* Anonymous aggregates cannot have fields with ctors, dtors or complex
6234 : assignment operators (because they cannot have these methods themselves).
6235 : For anonymous unions this is already checked because they are not allowed
6236 : in any union, otherwise we have to check it. */
6237 181596 : if (TREE_CODE (t) != UNION_TYPE)
6238 : {
6239 38337 : tree field, type;
6240 :
6241 38337 : if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
6242 : {
6243 9 : error_at (location_of (t), "anonymous struct with base classes");
6244 : /* Avoid ICE after error on anon-struct9.C. */
6245 9 : TYPE_NEEDS_CONSTRUCTING (t) = false;
6246 : }
6247 :
6248 154192 : for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
6249 115855 : if (TREE_CODE (field) == FIELD_DECL)
6250 : {
6251 77417 : type = TREE_TYPE (field);
6252 77417 : if (CLASS_TYPE_P (type))
6253 : {
6254 61 : if (TYPE_NEEDS_CONSTRUCTING (type))
6255 6 : error ("member %q+#D with constructor not allowed "
6256 : "in anonymous aggregate", field);
6257 61 : if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
6258 0 : error ("member %q+#D with destructor not allowed "
6259 : "in anonymous aggregate", field);
6260 61 : if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
6261 0 : error ("member %q+#D with copy assignment operator "
6262 : "not allowed in anonymous aggregate", field);
6263 : }
6264 : }
6265 : }
6266 181596 : }
6267 :
6268 : /* Warn for an attribute located at LOCATION that appertains to the
6269 : class type CLASS_TYPE that has not been properly placed after its
6270 : class-key, in it class-specifier. */
6271 :
6272 : void
6273 117 : warn_misplaced_attr_for_class_type (location_t location,
6274 : tree class_type)
6275 : {
6276 117 : gcc_assert (OVERLOAD_TYPE_P (class_type));
6277 :
6278 117 : auto_diagnostic_group d;
6279 117 : if (warning_at (location, OPT_Wattributes,
6280 : "attribute ignored in declaration "
6281 : "of %q#T", class_type))
6282 117 : inform (location,
6283 : "attribute for %q#T must follow the %qs keyword",
6284 : class_type, class_key_or_enum_as_string (class_type));
6285 117 : }
6286 :
6287 : /* Returns the cv-qualifiers that apply to the type specified
6288 : by the DECLSPECS. */
6289 :
6290 : static int
6291 1092299108 : get_type_quals (const cp_decl_specifier_seq *declspecs)
6292 : {
6293 1092299108 : int type_quals = TYPE_UNQUALIFIED;
6294 :
6295 1092299108 : if (decl_spec_seq_has_spec_p (declspecs, ds_const))
6296 112880535 : type_quals |= TYPE_QUAL_CONST;
6297 1092299108 : if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
6298 1821795 : type_quals |= TYPE_QUAL_VOLATILE;
6299 1092299108 : if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
6300 34 : type_quals |= TYPE_QUAL_RESTRICT;
6301 :
6302 1092299108 : return type_quals;
6303 : }
6304 :
6305 : /* Make sure that a declaration with no declarator is well-formed, i.e.
6306 : just declares a tagged type or anonymous union.
6307 :
6308 : Returns the type declared; or NULL_TREE if none. */
6309 :
6310 : tree
6311 39408465 : check_tag_decl (cp_decl_specifier_seq *declspecs,
6312 : bool explicit_type_instantiation_p)
6313 : {
6314 39408465 : int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
6315 39408465 : int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
6316 : /* If a class, struct, or enum type is declared by the DECLSPECS
6317 : (i.e, if a class-specifier, enum-specifier, or non-typename
6318 : elaborated-type-specifier appears in the DECLSPECS),
6319 : DECLARED_TYPE is set to the corresponding type. */
6320 39408465 : tree declared_type = NULL_TREE;
6321 39408465 : bool error_p = false;
6322 :
6323 39408465 : if (declspecs->multiple_types_p)
6324 26 : error_at (smallest_type_location (declspecs),
6325 : "multiple types in one declaration");
6326 39408439 : else if (declspecs->redefined_builtin_type)
6327 : {
6328 21 : location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
6329 21 : if (!in_system_header_at (loc))
6330 9 : permerror (loc, "redeclaration of C++ built-in type %qT",
6331 : declspecs->redefined_builtin_type);
6332 : return NULL_TREE;
6333 : }
6334 :
6335 39408444 : if (declspecs->type
6336 39408429 : && TYPE_P (declspecs->type)
6337 78433619 : && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
6338 39024128 : && MAYBE_CLASS_TYPE_P (declspecs->type))
6339 1970282 : || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
6340 : declared_type = declspecs->type;
6341 384361 : else if (declspecs->type == error_mark_node)
6342 1502 : error_p = true;
6343 :
6344 39408444 : if (type_uses_auto (declared_type))
6345 : {
6346 8 : error_at (declspecs->locations[ds_type_spec],
6347 : "%<auto%> can only be specified for variables "
6348 : "or function declarations");
6349 8 : return error_mark_node;
6350 : }
6351 :
6352 39408436 : if (declared_type && !OVERLOAD_TYPE_P (declared_type))
6353 : declared_type = NULL_TREE;
6354 :
6355 39408436 : if (!declared_type && !saw_friend && !error_p)
6356 91 : permerror (input_location, "declaration does not declare anything");
6357 : /* Check for an anonymous union. */
6358 39024048 : else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
6359 113699663 : && TYPE_UNNAMED_P (declared_type))
6360 : {
6361 : /* 7/3 In a simple-declaration, the optional init-declarator-list
6362 : can be omitted only when declaring a class (clause 9) or
6363 : enumeration (7.2), that is, when the decl-specifier-seq contains
6364 : either a class-specifier, an elaborated-type-specifier with
6365 : a class-key (9.1), or an enum-specifier. In these cases and
6366 : whenever a class-specifier or enum-specifier is present in the
6367 : decl-specifier-seq, the identifiers in these specifiers are among
6368 : the names being declared by the declaration (as class-name,
6369 : enum-names, or enumerators, depending on the syntax). In such
6370 : cases, and except for the declaration of an unnamed bit-field (9.6),
6371 : the decl-specifier-seq shall introduce one or more names into the
6372 : program, or shall redeclare a name introduced by a previous
6373 : declaration. [Example:
6374 : enum { }; // ill-formed
6375 : typedef class { }; // ill-formed
6376 : --end example] */
6377 181602 : if (saw_typedef)
6378 : {
6379 6 : error_at (declspecs->locations[ds_typedef],
6380 : "missing type-name in typedef-declaration");
6381 6 : return NULL_TREE;
6382 : }
6383 181596 : /* Anonymous unions are objects, so they can have specifiers. */;
6384 181596 : SET_ANON_AGGR_TYPE_P (declared_type);
6385 :
6386 181596 : if (TREE_CODE (declared_type) != UNION_TYPE)
6387 38337 : pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
6388 38337 : OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
6389 : }
6390 :
6391 : else
6392 : {
6393 39226743 : if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
6394 9 : error_at (declspecs->locations[ds_inline],
6395 : "%<inline%> can only be specified for functions");
6396 39226734 : else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
6397 3 : error_at (declspecs->locations[ds_virtual],
6398 : "%<virtual%> can only be specified for functions");
6399 39226731 : else if (saw_friend
6400 39226731 : && (!current_class_type
6401 2199549 : || current_scope () != current_class_type))
6402 0 : error_at (declspecs->locations[ds_friend],
6403 : "%<friend%> can only be specified inside a class");
6404 39226731 : else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
6405 3 : error_at (declspecs->locations[ds_explicit],
6406 : "%<explicit%> can only be specified for constructors");
6407 39226728 : else if (declspecs->storage_class)
6408 3 : error_at (declspecs->locations[ds_storage_class],
6409 : "a storage class can only be specified for objects "
6410 : "and functions");
6411 39226725 : else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
6412 9 : error_at (declspecs->locations[ds_const],
6413 : "%<const%> can only be specified for objects and "
6414 : "functions");
6415 39226716 : else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
6416 3 : error_at (declspecs->locations[ds_volatile],
6417 : "%<volatile%> can only be specified for objects and "
6418 : "functions");
6419 39226713 : else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
6420 3 : error_at (declspecs->locations[ds_restrict],
6421 : "%<__restrict%> can only be specified for objects and "
6422 : "functions");
6423 39226710 : else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
6424 3 : error_at (declspecs->locations[ds_thread],
6425 : "%<__thread%> can only be specified for objects "
6426 : "and functions");
6427 39226707 : else if (saw_typedef)
6428 24 : warning_at (declspecs->locations[ds_typedef], 0,
6429 : "%<typedef%> was ignored in this declaration");
6430 39226683 : else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
6431 9 : error_at (declspecs->locations[ds_constexpr],
6432 : "%qs cannot be used for type declarations", "constexpr");
6433 39226674 : else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
6434 3 : error_at (declspecs->locations[ds_constinit],
6435 : "%qs cannot be used for type declarations", "constinit");
6436 39226671 : else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
6437 3 : error_at (declspecs->locations[ds_consteval],
6438 : "%qs cannot be used for type declarations", "consteval");
6439 : }
6440 :
6441 39408430 : if (declspecs->attributes && warn_attributes && declared_type)
6442 : {
6443 30 : location_t loc;
6444 24 : if (!CLASS_TYPE_P (declared_type)
6445 54 : || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
6446 : /* For a non-template class, use the name location. */
6447 21 : loc = location_of (declared_type);
6448 : else
6449 : /* For a template class (an explicit instantiation), use the
6450 : current location. */
6451 9 : loc = input_location;
6452 :
6453 30 : if (explicit_type_instantiation_p)
6454 : /* [dcl.attr.grammar]/4:
6455 :
6456 : No attribute-specifier-seq shall appertain to an explicit
6457 : instantiation. */
6458 : {
6459 6 : auto_diagnostic_group d;
6460 6 : if (warning_at (loc, OPT_Wattributes,
6461 : "attribute ignored in explicit instantiation %q#T",
6462 : declared_type))
6463 6 : inform (loc,
6464 : "no attribute can be applied to "
6465 : "an explicit instantiation");
6466 6 : }
6467 : else
6468 24 : warn_misplaced_attr_for_class_type (loc, declared_type);
6469 : }
6470 :
6471 39408430 : if (declspecs->std_attributes
6472 93 : && declared_type
6473 39408520 : && any_nonignored_attribute_p (declspecs->std_attributes))
6474 : {
6475 90 : auto_diagnostic_group d;
6476 90 : if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
6477 : "attribute ignored"))
6478 90 : inform (declspecs->locations[ds_std_attribute],
6479 : "an attribute that appertains to a type-specifier is ignored");
6480 90 : }
6481 :
6482 : return declared_type;
6483 : }
6484 :
6485 : /* Called when a declaration is seen that contains no names to declare.
6486 : If its type is a reference to a structure, union or enum inherited
6487 : from a containing scope, shadow that tag name for the current scope
6488 : with a forward reference.
6489 : If its type defines a new named structure or union
6490 : or defines an enum, it is valid but we need not do anything here.
6491 : Otherwise, it is an error.
6492 :
6493 : C++: may have to grok the declspecs to learn about static,
6494 : complain for anonymous unions.
6495 :
6496 : Returns the TYPE declared -- or NULL_TREE if none. */
6497 :
6498 : tree
6499 34535665 : shadow_tag (cp_decl_specifier_seq *declspecs)
6500 : {
6501 34535665 : tree t = check_tag_decl (declspecs,
6502 : /*explicit_type_instantiation_p=*/false);
6503 :
6504 34535665 : if (!t)
6505 : return NULL_TREE;
6506 :
6507 34534150 : t = maybe_process_partial_specialization (t);
6508 34534150 : if (t == error_mark_node)
6509 : return NULL_TREE;
6510 :
6511 : /* This is where the variables in an anonymous union are
6512 : declared. An anonymous union declaration looks like:
6513 : union { ... } ;
6514 : because there is no declarator after the union, the parser
6515 : sends that declaration here. */
6516 34532239 : if (ANON_AGGR_TYPE_P (t))
6517 : {
6518 392 : fixup_anonymous_aggr (t);
6519 :
6520 392 : if (TYPE_FIELDS (t))
6521 : {
6522 392 : tree decl = grokdeclarator (/*declarator=*/NULL,
6523 : declspecs, NORMAL, 0, NULL);
6524 392 : finish_anon_union (decl);
6525 : }
6526 : }
6527 :
6528 : return t;
6529 : }
6530 :
6531 : /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
6532 :
6533 : tree
6534 427023192 : groktypename (cp_decl_specifier_seq *type_specifiers,
6535 : const cp_declarator *declarator,
6536 : bool is_template_arg)
6537 : {
6538 427023192 : tree attrs;
6539 427023192 : tree type;
6540 70807985 : enum decl_context context
6541 427023192 : = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
6542 427023192 : attrs = type_specifiers->attributes;
6543 427023192 : type_specifiers->attributes = NULL_TREE;
6544 427023192 : type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
6545 427023192 : if (attrs && type != error_mark_node)
6546 : {
6547 673 : if (CLASS_TYPE_P (type))
6548 6 : warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
6549 : "outside of definition", type);
6550 667 : else if (MAYBE_CLASS_TYPE_P (type))
6551 : /* A template type parameter or other dependent type. */
6552 9 : warning (OPT_Wattributes, "ignoring attributes applied to dependent "
6553 : "type %qT without an associated declaration", type);
6554 : else
6555 658 : cplus_decl_attributes (&type, attrs, 0);
6556 : }
6557 427023192 : return type;
6558 : }
6559 :
6560 : /* Process a DECLARATOR for a function-scope or namespace-scope
6561 : variable or function declaration.
6562 : (Function definitions go through start_function; class member
6563 : declarations appearing in the body of the class go through
6564 : grokfield.) The DECL corresponding to the DECLARATOR is returned.
6565 : If an error occurs, the error_mark_node is returned instead.
6566 :
6567 : DECLSPECS are the decl-specifiers for the declaration. INITIALIZED is
6568 : SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
6569 : for an explicitly defaulted function, or SD_DELETED for an explicitly
6570 : deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
6571 : implicitly initialized via a default constructor. It can also be
6572 : SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
6573 : mark the new decl as DECL_DECOMPOSITION_P.
6574 :
6575 : ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
6576 : declaration.
6577 :
6578 : The scope represented by the context of the returned DECL is pushed
6579 : (if it is not the global namespace) and is assigned to
6580 : *PUSHED_SCOPE_P. The caller is then responsible for calling
6581 : pop_scope on *PUSHED_SCOPE_P if it is set. */
6582 :
6583 : tree
6584 134098669 : start_decl (const cp_declarator *declarator,
6585 : cp_decl_specifier_seq *declspecs,
6586 : int initialized,
6587 : tree attributes,
6588 : tree prefix_attributes,
6589 : tree *pushed_scope_p)
6590 : {
6591 134098669 : tree decl;
6592 134098669 : tree context;
6593 134098669 : bool was_public;
6594 134098669 : int flags;
6595 134098669 : bool alias;
6596 134098669 : tree initial;
6597 :
6598 134098669 : *pushed_scope_p = NULL_TREE;
6599 :
6600 134098669 : if (prefix_attributes != error_mark_node)
6601 134098667 : attributes = attr_chainon (attributes, prefix_attributes);
6602 :
6603 134098669 : decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
6604 : &attributes);
6605 :
6606 134098669 : if (decl == NULL_TREE || VOID_TYPE_P (decl)
6607 134098669 : || decl == error_mark_node
6608 134096514 : || prefix_attributes == error_mark_node)
6609 2157 : return error_mark_node;
6610 :
6611 134096512 : context = CP_DECL_CONTEXT (decl);
6612 134096512 : if (context != global_namespace)
6613 23524171 : *pushed_scope_p = push_scope (context);
6614 :
6615 134096512 : if (initialized && TREE_CODE (decl) == TYPE_DECL)
6616 : {
6617 27 : error_at (DECL_SOURCE_LOCATION (decl),
6618 : "typedef %qD is initialized (use %qs instead)",
6619 : decl, "decltype");
6620 27 : return error_mark_node;
6621 : }
6622 :
6623 134096485 : if (flag_contracts
6624 14632500 : && TREE_CODE (decl) == FUNCTION_DECL
6625 4111564 : && !processing_template_decl
6626 3327549 : && DECL_RESULT (decl)
6627 137417587 : && is_auto (TREE_TYPE (DECL_RESULT (decl))))
6628 36 : if (tree specs = get_fn_contract_specifiers (decl))
6629 12 : for (tree ca : tree_vec_range (specs))
6630 9 : if (POSTCONDITION_P (ca) && POSTCONDITION_IDENTIFIER (ca))
6631 : {
6632 3 : error_at (DECL_SOURCE_LOCATION (decl),
6633 : "postconditions with deduced result name types must only"
6634 : " appear on function definitions");
6635 3 : return error_mark_node;
6636 : }
6637 : /* Save the DECL_INITIAL value in case it gets clobbered to assist
6638 : with attribute validation. */
6639 134096482 : initial = DECL_INITIAL (decl);
6640 :
6641 134096482 : if (initialized)
6642 : {
6643 65039764 : if (! toplevel_bindings_p ()
6644 65039764 : && DECL_EXTERNAL (decl))
6645 3 : warning (0, "declaration of %q#D has %<extern%> and is initialized",
6646 : decl);
6647 65039764 : DECL_EXTERNAL (decl) = 0;
6648 65039764 : if (toplevel_bindings_p ())
6649 7817753 : TREE_STATIC (decl) = 1;
6650 : /* Tell 'cplus_decl_attributes' this is an initialized decl,
6651 : even though we might not yet have the initializer expression. */
6652 65039764 : if (!DECL_INITIAL (decl))
6653 64440928 : DECL_INITIAL (decl) = error_mark_node;
6654 : }
6655 134096482 : alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
6656 :
6657 134096482 : if (alias && TREE_CODE (decl) == FUNCTION_DECL)
6658 3984 : record_key_method_defined (decl);
6659 :
6660 : /* If this is a typedef that names the class for linkage purposes
6661 : (7.1.3p8), apply any attributes directly to the type. */
6662 134096482 : if (TREE_CODE (decl) == TYPE_DECL
6663 134096482 : && TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl))
6664 : flags = ATTR_FLAG_TYPE_IN_PLACE;
6665 : else
6666 : flags = 0;
6667 :
6668 : /* Set attributes here so if duplicate decl, will have proper attributes. */
6669 134096482 : cplus_decl_attributes (&decl, attributes, flags);
6670 :
6671 : /* Restore the original DECL_INITIAL that we may have clobbered earlier to
6672 : assist with attribute validation. */
6673 134096482 : DECL_INITIAL (decl) = initial;
6674 :
6675 : /* Dllimported symbols cannot be defined. Static data members (which
6676 : can be initialized in-class and dllimported) go through grokfield,
6677 : not here, so we don't need to exclude those decls when checking for
6678 : a definition. */
6679 134096482 : if (initialized && DECL_DLLIMPORT_P (decl))
6680 : {
6681 0 : error_at (DECL_SOURCE_LOCATION (decl),
6682 : "definition of %q#D is marked %<dllimport%>", decl);
6683 0 : DECL_DLLIMPORT_P (decl) = 0;
6684 : }
6685 :
6686 : /* If #pragma weak was used, mark the decl weak now. */
6687 134096482 : if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
6688 48955359 : maybe_apply_pragma_weak (decl);
6689 :
6690 134096482 : if (TREE_CODE (decl) == FUNCTION_DECL
6691 39688966 : && DECL_DECLARED_INLINE_P (decl)
6692 3581736 : && DECL_UNINLINABLE (decl)
6693 134096482 : && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
6694 : {
6695 0 : auto_urlify_attributes sentinel;
6696 0 : warning_at (DECL_SOURCE_LOCATION (decl), 0,
6697 : "inline function %qD given attribute %qs", decl, "noinline");
6698 0 : }
6699 :
6700 134096482 : if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
6701 : {
6702 892730 : bool this_tmpl = (current_template_depth
6703 892730 : > template_class_depth (context));
6704 892730 : if (VAR_P (decl))
6705 : {
6706 522947 : tree field = lookup_field (context, DECL_NAME (decl), 0, false);
6707 522947 : if (field == NULL_TREE
6708 522947 : || !(VAR_P (field) || variable_template_p (field)))
6709 6 : error ("%q+#D is not a static data member of %q#T", decl, context);
6710 522941 : else if (variable_template_p (field)
6711 522941 : && (DECL_LANG_SPECIFIC (decl)
6712 149 : && DECL_TEMPLATE_SPECIALIZATION (decl)))
6713 : /* OK, specialization was already checked. */;
6714 522870 : else if (variable_template_p (field) && !this_tmpl)
6715 : {
6716 3 : auto_diagnostic_group d;
6717 3 : error_at (DECL_SOURCE_LOCATION (decl),
6718 : "non-member-template declaration of %qD", decl);
6719 3 : inform (DECL_SOURCE_LOCATION (field), "does not match "
6720 : "member template declaration here");
6721 3 : return error_mark_node;
6722 3 : }
6723 : else
6724 : {
6725 522867 : if (variable_template_p (field))
6726 75 : field = DECL_TEMPLATE_RESULT (field);
6727 :
6728 522867 : if (DECL_CONTEXT (field) != context)
6729 : {
6730 3 : if (!same_type_p (DECL_CONTEXT (field), context))
6731 3 : permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
6732 : "to be defined as %<%T::%D%>",
6733 3 : DECL_CONTEXT (field), DECL_NAME (decl),
6734 3 : context, DECL_NAME (decl));
6735 3 : DECL_CONTEXT (decl) = DECL_CONTEXT (field);
6736 : }
6737 :
6738 522867 : if (modules_p () && !module_may_redeclare (field))
6739 30 : return error_mark_node;
6740 :
6741 : /* Static data member are tricky; an in-class initialization
6742 : still doesn't provide a definition, so the in-class
6743 : declaration will have DECL_EXTERNAL set, but will have an
6744 : initialization. Thus, duplicate_decls won't warn
6745 : about this situation, and so we check here. */
6746 522837 : if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
6747 9 : error ("duplicate initialization of %qD", decl);
6748 522837 : field = duplicate_decls (decl, field);
6749 522837 : if (field == error_mark_node)
6750 : return error_mark_node;
6751 522781 : else if (field)
6752 522781 : decl = field;
6753 : }
6754 : }
6755 : else
6756 : {
6757 369795 : tree field = check_classfn (context, decl,
6758 : this_tmpl
6759 12 : ? current_template_parms
6760 : : NULL_TREE);
6761 369708 : if (field && field != error_mark_node
6762 739491 : && duplicate_decls (decl, field))
6763 369708 : decl = field;
6764 : }
6765 :
6766 : /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
6767 892641 : DECL_IN_AGGR_P (decl) = 0;
6768 : /* Do not mark DECL as an explicit specialization if it was not
6769 : already marked as an instantiation; a declaration should
6770 : never be marked as a specialization unless we know what
6771 : template is being specialized. */
6772 892641 : if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
6773 : {
6774 367605 : SET_DECL_TEMPLATE_SPECIALIZATION (decl);
6775 367605 : if (TREE_CODE (decl) == FUNCTION_DECL)
6776 346454 : DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
6777 346454 : && DECL_NONGNU_INLINE_P (decl));
6778 : else
6779 21151 : DECL_COMDAT (decl) = false;
6780 :
6781 : /* [temp.expl.spec] An explicit specialization of a static data
6782 : member of a template is a definition if the declaration
6783 : includes an initializer; otherwise, it is a declaration.
6784 :
6785 : We check for processing_specialization so this only applies
6786 : to the new specialization syntax. */
6787 367605 : if (!initialized && processing_specialization)
6788 367401 : DECL_EXTERNAL (decl) = 1;
6789 : }
6790 :
6791 1260090 : if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
6792 : /* Aliases are definitions. */
6793 892677 : && !alias)
6794 : {
6795 9 : permerror (declarator->id_loc,
6796 : "declaration of %q#D outside of class is not definition",
6797 : decl);
6798 : }
6799 : }
6800 :
6801 : /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works. */
6802 134096393 : if (initialized == SD_DECOMPOSITION)
6803 495669 : fit_decomposition_lang_decl (decl, NULL_TREE);
6804 :
6805 134096393 : was_public = TREE_PUBLIC (decl);
6806 :
6807 228514667 : if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
6808 134695256 : && current_function_decl)
6809 : {
6810 : /* A function-scope decl of some namespace-scope decl. */
6811 63744 : DECL_LOCAL_DECL_P (decl) = true;
6812 63744 : if (named_module_attach_p ())
6813 3 : error_at (declarator->id_loc,
6814 : "block-scope extern declaration %q#D must not be"
6815 : " attached to a named module", decl);
6816 : }
6817 :
6818 : /* Enter this declaration into the symbol table. Don't push the plain
6819 : VAR_DECL for a variable template. */
6820 134096393 : if (!template_parm_scope_p ()
6821 134096393 : || !VAR_P (decl))
6822 129675173 : decl = maybe_push_decl (decl);
6823 :
6824 134096393 : if (processing_template_decl)
6825 85132971 : decl = push_template_decl (decl);
6826 :
6827 134096393 : if (decl == error_mark_node)
6828 : return error_mark_node;
6829 :
6830 134095953 : if (VAR_P (decl)
6831 71438433 : && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
6832 70632 : && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
6833 : /* But not templated variables. */
6834 134127366 : && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
6835 : {
6836 : /* This is a const variable with implicit 'static'. Set
6837 : DECL_THIS_STATIC so we can tell it from variables that are
6838 : !TREE_PUBLIC because of the anonymous namespace. */
6839 31413 : gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
6840 31413 : DECL_THIS_STATIC (decl) = 1;
6841 : }
6842 :
6843 75690175 : if (current_function_decl && VAR_P (decl)
6844 62792329 : && maybe_constexpr_fn (current_function_decl)
6845 150560112 : && cxx_dialect < cxx23)
6846 : {
6847 12991131 : bool ok = false;
6848 12991131 : if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
6849 : {
6850 9 : if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
6851 18 : error_at (DECL_SOURCE_LOCATION (decl),
6852 : "%qD defined %<thread_local%> in %qs function only "
6853 : "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
6854 9 : DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
6855 : ? "consteval" : "constexpr");
6856 : }
6857 12991122 : else if (TREE_STATIC (decl))
6858 : {
6859 50 : if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
6860 72 : error_at (DECL_SOURCE_LOCATION (decl),
6861 : "%qD defined %<static%> in %qs function only available "
6862 : "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
6863 36 : DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
6864 : ? "consteval" : "constexpr");
6865 : }
6866 : else
6867 : ok = true;
6868 45 : if (!ok)
6869 59 : cp_function_chain->invalid_constexpr = true;
6870 : }
6871 :
6872 134095953 : if (!processing_template_decl && VAR_P (decl))
6873 8936712 : start_decl_1 (decl, initialized);
6874 :
6875 134095950 : return decl;
6876 : }
6877 :
6878 : /* Process the declaration of a variable DECL. INITIALIZED is true
6879 : iff DECL is explicitly initialized. (INITIALIZED is false if the
6880 : variable is initialized via an implicitly-called constructor.)
6881 : This function must be called for ordinary variables (including, for
6882 : example, implicit instantiations of templates), but must not be
6883 : called for template declarations. */
6884 :
6885 : void
6886 8946763 : start_decl_1 (tree decl, bool initialized)
6887 : {
6888 8946763 : gcc_checking_assert (!processing_template_decl);
6889 :
6890 8946763 : if (error_operand_p (decl))
6891 : return;
6892 :
6893 8946748 : gcc_checking_assert (VAR_P (decl));
6894 :
6895 8946748 : tree type = TREE_TYPE (decl);
6896 8946748 : bool complete_p = COMPLETE_TYPE_P (type);
6897 8946748 : bool aggregate_definition_p
6898 8946748 : = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
6899 :
6900 : /* If an explicit initializer is present, or if this is a definition
6901 : of an aggregate, then we need a complete type at this point.
6902 : (Scalars are always complete types, so there is nothing to
6903 : check.) This code just sets COMPLETE_P; errors (if necessary)
6904 : are issued below. */
6905 4641909 : if ((initialized || aggregate_definition_p)
6906 7892187 : && !complete_p
6907 6319152 : && COMPLETE_TYPE_P (complete_type (type)))
6908 : {
6909 343120 : complete_p = true;
6910 : /* We will not yet have set TREE_READONLY on DECL if the type
6911 : was "const", but incomplete, before this point. But, now, we
6912 : have a complete type, so we can try again. */
6913 343120 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
6914 : }
6915 :
6916 8946745 : if (initialized)
6917 : /* Is it valid for this decl to have an initializer at all? */
6918 : {
6919 : /* Don't allow initializations for incomplete types except for
6920 : arrays which might be completed by the initialization. */
6921 7113720 : if (complete_p)
6922 : ; /* A complete type is ok. */
6923 1333882 : else if (type_uses_auto (type))
6924 : ; /* An auto type is ok. */
6925 123745 : else if (TREE_CODE (type) != ARRAY_TYPE)
6926 : {
6927 27 : auto_diagnostic_group d;
6928 27 : error ("variable %q#D has initializer but incomplete type", decl);
6929 48 : maybe_suggest_missing_header (input_location,
6930 27 : TYPE_IDENTIFIER (type),
6931 27 : CP_TYPE_CONTEXT (type));
6932 27 : type = TREE_TYPE (decl) = error_mark_node;
6933 27 : }
6934 123718 : else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
6935 : {
6936 0 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
6937 0 : error ("elements of array %q#D have incomplete type", decl);
6938 : /* else we already gave an error in start_decl. */
6939 : }
6940 : }
6941 1833025 : else if (aggregate_definition_p && !complete_p)
6942 : {
6943 238 : if (type_uses_auto (type))
6944 71 : gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
6945 : else
6946 : {
6947 167 : auto_diagnostic_group d;
6948 167 : error ("aggregate %q#D has incomplete type and cannot be defined",
6949 : decl);
6950 289 : maybe_suggest_missing_header (input_location,
6951 167 : TYPE_IDENTIFIER (type),
6952 167 : CP_TYPE_CONTEXT (type));
6953 : /* Change the type so that assemble_variable will give
6954 : DECL an rtl we can live with: (mem (const_int 0)). */
6955 167 : type = TREE_TYPE (decl) = error_mark_node;
6956 167 : }
6957 : }
6958 :
6959 : /* Create a new scope to hold this declaration if necessary.
6960 : Whether or not a new scope is necessary cannot be determined
6961 : until after the type has been completed; if the type is a
6962 : specialization of a class template it is not until after
6963 : instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
6964 : will be set correctly. */
6965 8946745 : maybe_push_cleanup_level (type);
6966 : }
6967 :
6968 : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
6969 : C++20 P0960. TYPE is the type of the object we're initializing. */
6970 :
6971 : tree
6972 309 : do_aggregate_paren_init (tree init, tree type)
6973 : {
6974 309 : tree val = TREE_VALUE (init);
6975 :
6976 309 : if (TREE_CHAIN (init) == NULL_TREE)
6977 : {
6978 : /* If the list has a single element and it's a string literal,
6979 : then it's the initializer for the array as a whole. */
6980 193 : if (TREE_CODE (type) == ARRAY_TYPE
6981 193 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
6982 239 : && TREE_CODE (tree_strip_any_location_wrapper (val))
6983 : == STRING_CST)
6984 : return val;
6985 : /* Handle non-standard extensions like compound literals. This also
6986 : prevents triggering aggregate parenthesized-initialization in
6987 : compiler-generated code for =default. */
6988 154 : else if (same_type_ignoring_top_level_qualifiers_p (type,
6989 154 : TREE_TYPE (val)))
6990 : return val;
6991 : }
6992 :
6993 208 : init = build_constructor_from_list (init_list_type_node, init);
6994 208 : CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
6995 208 : CONSTRUCTOR_IS_PAREN_INIT (init) = true;
6996 208 : return init;
6997 : }
6998 :
6999 : /* Handle initialization of references. DECL, TYPE, and INIT have the
7000 : same meaning as in cp_finish_decl. *CLEANUP must be NULL on entry,
7001 : but will be set to a new CLEANUP_STMT if a temporary is created
7002 : that must be destroyed subsequently.
7003 :
7004 : Returns an initializer expression to use to initialize DECL, or
7005 : NULL if the initialization can be performed statically.
7006 :
7007 : Quotes on semantics can be found in ARM 8.4.3. */
7008 :
7009 : static tree
7010 387825 : grok_reference_init (tree decl, tree type, tree init, int flags)
7011 : {
7012 387825 : if (init == NULL_TREE)
7013 : {
7014 15 : if ((DECL_LANG_SPECIFIC (decl) == 0
7015 3 : || DECL_IN_AGGR_P (decl) == 0)
7016 18 : && ! DECL_THIS_EXTERN (decl))
7017 15 : error_at (DECL_SOURCE_LOCATION (decl),
7018 : "%qD declared as reference but not initialized", decl);
7019 : return NULL_TREE;
7020 : }
7021 :
7022 387810 : tree ttype = TREE_TYPE (type);
7023 387810 : if (TREE_CODE (init) == TREE_LIST)
7024 : {
7025 : /* This handles (C++20 only) code like
7026 :
7027 : const A& r(1, 2, 3);
7028 :
7029 : where we treat the parenthesized list as a CONSTRUCTOR. */
7030 1262 : if (TREE_TYPE (init) == NULL_TREE
7031 1262 : && CP_AGGREGATE_TYPE_P (ttype)
7032 102 : && !DECL_DECOMPOSITION_P (decl)
7033 1361 : && (cxx_dialect >= cxx20))
7034 : {
7035 : /* We don't know yet if we should treat const A& r(1) as
7036 : const A& r{1}. */
7037 93 : if (list_length (init) == 1)
7038 : {
7039 72 : flags |= LOOKUP_AGGREGATE_PAREN_INIT;
7040 72 : init = build_x_compound_expr_from_list (init, ELK_INIT,
7041 : tf_warning_or_error);
7042 : }
7043 : /* If the list had more than one element, the code is ill-formed
7044 : pre-C++20, so we can build a constructor right away. */
7045 : else
7046 21 : init = do_aggregate_paren_init (init, ttype);
7047 : }
7048 : else
7049 1169 : init = build_x_compound_expr_from_list (init, ELK_INIT,
7050 : tf_warning_or_error);
7051 : }
7052 :
7053 387810 : if (TREE_CODE (ttype) != ARRAY_TYPE
7054 387810 : && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
7055 : /* Note: default conversion is only called in very special cases. */
7056 12 : init = decay_conversion (init, tf_warning_or_error);
7057 :
7058 : /* check_initializer handles this for non-reference variables, but for
7059 : references we need to do it here or the initializer will get the
7060 : incomplete array type and confuse later calls to
7061 : cp_complete_array_type. */
7062 387810 : if (TREE_CODE (ttype) == ARRAY_TYPE
7063 22694 : && TYPE_DOMAIN (ttype) == NULL_TREE
7064 387893 : && (BRACE_ENCLOSED_INITIALIZER_P (init)
7065 50 : || TREE_CODE (init) == STRING_CST))
7066 : {
7067 33 : cp_complete_array_type (&ttype, init, false);
7068 33 : if (ttype != TREE_TYPE (type))
7069 33 : type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
7070 : }
7071 :
7072 : /* Convert INIT to the reference type TYPE. This may involve the
7073 : creation of a temporary, whose lifetime must be the same as that
7074 : of the reference. If so, a DECL_EXPR for the temporary will be
7075 : added just after the DECL_EXPR for DECL. That's why we don't set
7076 : DECL_INITIAL for local references (instead assigning to them
7077 : explicitly); we need to allow the temporary to be initialized
7078 : first. */
7079 387810 : return initialize_reference (type, init, flags,
7080 387810 : tf_warning_or_error);
7081 : }
7082 :
7083 : /* Designated initializers in arrays are not supported in GNU C++.
7084 : The parser cannot detect this error since it does not know whether
7085 : a given brace-enclosed initializer is for a class type or for an
7086 : array. This function checks that CE does not use a designated
7087 : initializer. If it does, an error is issued. Returns true if CE
7088 : is valid, i.e., does not have a designated initializer. */
7089 :
7090 : bool
7091 157395821 : check_array_designated_initializer (constructor_elt *ce,
7092 : unsigned HOST_WIDE_INT index)
7093 : {
7094 : /* Designated initializers for array elements are not supported. */
7095 157395821 : if (ce->index)
7096 : {
7097 : /* The parser only allows identifiers as designated
7098 : initializers. */
7099 106254169 : if (ce->index == error_mark_node)
7100 : {
7101 0 : error ("name used in a GNU-style designated "
7102 : "initializer for an array");
7103 0 : return false;
7104 : }
7105 106254169 : else if (identifier_p (ce->index))
7106 : {
7107 19 : error ("name %qD used in a GNU-style designated "
7108 : "initializer for an array", ce->index);
7109 19 : ce->index = error_mark_node;
7110 19 : return false;
7111 : }
7112 :
7113 106254150 : tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
7114 : ce->index, true);
7115 106254150 : if (ce_index
7116 106254147 : && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
7117 212508294 : && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
7118 : == INTEGER_CST))
7119 : {
7120 : /* A C99 designator is OK if it matches the current index. */
7121 106254144 : if (wi::to_wide (ce_index) == index)
7122 : {
7123 106254138 : ce->index = ce_index;
7124 106254138 : return true;
7125 : }
7126 : else
7127 6 : sorry ("non-trivial designated initializers not supported");
7128 : }
7129 : else
7130 6 : error_at (cp_expr_loc_or_input_loc (ce->index),
7131 : "C99 designator %qE is not an integral constant-expression",
7132 : ce->index);
7133 :
7134 : return false;
7135 : }
7136 :
7137 : return true;
7138 : }
7139 :
7140 : /* When parsing `int a[] = {1, 2};' we don't know the size of the
7141 : array until we finish parsing the initializer. If that's the
7142 : situation we're in, update DECL accordingly. */
7143 :
7144 : static void
7145 77655011 : maybe_deduce_size_from_array_init (tree decl, tree init)
7146 : {
7147 77655011 : tree type = TREE_TYPE (decl);
7148 :
7149 77655011 : if (TREE_CODE (type) == ARRAY_TYPE
7150 995679 : && TYPE_DOMAIN (type) == NULL_TREE
7151 78285813 : && TREE_CODE (decl) != TYPE_DECL)
7152 : {
7153 : /* do_default is really a C-ism to deal with tentative definitions.
7154 : But let's leave it here to ease the eventual merge. */
7155 630802 : int do_default = !DECL_EXTERNAL (decl);
7156 630802 : tree initializer = init ? init : DECL_INITIAL (decl);
7157 630802 : int failure = 0;
7158 :
7159 : /* Check that there are no designated initializers in INIT, as
7160 : those are not supported in GNU C++, and as the middle-end
7161 : will crash if presented with a non-numeric designated
7162 : initializer. */
7163 630802 : if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
7164 : {
7165 150075 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
7166 150075 : constructor_elt *ce;
7167 150075 : HOST_WIDE_INT i, j = 0;
7168 49385686 : FOR_EACH_VEC_SAFE_ELT (v, i, ce)
7169 : {
7170 49236645 : if (instantiation_dependent_expression_p (ce->index))
7171 77655011 : return;
7172 49236639 : if (!check_array_designated_initializer (ce, j))
7173 1 : failure = 1;
7174 : /* If an un-designated initializer is type-dependent, we can't
7175 : check brace elision yet. */
7176 49236639 : if (ce->index == NULL_TREE
7177 49236639 : && type_dependent_expression_p (ce->value))
7178 : return;
7179 49235611 : if (TREE_CODE (ce->value) == RAW_DATA_CST)
7180 210 : j += RAW_DATA_LENGTH (ce->value);
7181 : else
7182 49235401 : ++j;
7183 : }
7184 : }
7185 :
7186 149041 : if (failure)
7187 1 : TREE_TYPE (decl) = error_mark_node;
7188 : else
7189 : {
7190 629767 : failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
7191 : do_default);
7192 629767 : if (failure == 1)
7193 : {
7194 33 : error_at (cp_expr_loc_or_loc (initializer,
7195 30 : DECL_SOURCE_LOCATION (decl)),
7196 : "initializer fails to determine size of %qD", decl);
7197 : }
7198 629737 : else if (failure == 2)
7199 : {
7200 30 : if (do_default)
7201 : {
7202 6 : error_at (DECL_SOURCE_LOCATION (decl),
7203 : "array size missing in %qD", decl);
7204 : }
7205 : /* If a `static' var's size isn't known, make it extern as
7206 : well as static, so it does not get allocated. If it's not
7207 : `static', then don't mark it extern; finish_incomplete_decl
7208 : will give it a default size and it will get allocated. */
7209 24 : else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
7210 0 : DECL_EXTERNAL (decl) = 1;
7211 : }
7212 629707 : else if (failure == 3)
7213 : {
7214 6 : error_at (DECL_SOURCE_LOCATION (decl),
7215 : "zero-size array %qD", decl);
7216 : }
7217 : }
7218 :
7219 629768 : cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
7220 :
7221 629768 : relayout_decl (decl);
7222 :
7223 : /* Update the type of the corresponding TEMPLATE_DECL to match. */
7224 629768 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
7225 : {
7226 212 : tree tmpl = template_for_substitution (decl);
7227 212 : if (DECL_TEMPLATE_RESULT (tmpl) == decl)
7228 50 : TREE_TYPE (tmpl) = TREE_TYPE (decl);
7229 : }
7230 : }
7231 : }
7232 :
7233 : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
7234 : any appropriate error messages regarding the layout. */
7235 :
7236 : static void
7237 66384335 : layout_var_decl (tree decl)
7238 : {
7239 66384335 : tree type;
7240 :
7241 66384335 : type = TREE_TYPE (decl);
7242 66384335 : if (type == error_mark_node)
7243 : return;
7244 :
7245 : /* If we haven't already laid out this declaration, do so now.
7246 : Note that we must not call complete type for an external object
7247 : because it's type might involve templates that we are not
7248 : supposed to instantiate yet. (And it's perfectly valid to say
7249 : `extern X x' for some incomplete type `X'.) */
7250 66384288 : if (!DECL_EXTERNAL (decl))
7251 55667301 : complete_type (type);
7252 66384288 : if (!DECL_SIZE (decl)
7253 638027 : && TREE_TYPE (decl) != error_mark_node
7254 67022315 : && complete_or_array_type_p (type))
7255 479860 : layout_decl (decl, 0);
7256 :
7257 66384288 : if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
7258 : {
7259 : /* An automatic variable with an incomplete type: that is an error.
7260 : Don't talk about array types here, since we took care of that
7261 : message in grokdeclarator. */
7262 17 : error_at (DECL_SOURCE_LOCATION (decl),
7263 : "storage size of %qD isn%'t known", decl);
7264 17 : TREE_TYPE (decl) = error_mark_node;
7265 : }
7266 : #if 0
7267 : /* Keep this code around in case we later want to control debug info
7268 : based on whether a type is "used". (jason 1999-11-11) */
7269 :
7270 : else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
7271 : /* Let debugger know it should output info for this type. */
7272 : note_debug_info_needed (ttype);
7273 :
7274 : if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
7275 : note_debug_info_needed (DECL_CONTEXT (decl));
7276 : #endif
7277 :
7278 122051589 : if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
7279 40993245 : && DECL_SIZE (decl) != NULL_TREE
7280 107083080 : && ! TREE_CONSTANT (DECL_SIZE (decl)))
7281 : {
7282 6 : if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
7283 6 : && !DECL_LOCAL_DECL_P (decl))
7284 0 : constant_expression_warning (DECL_SIZE (decl));
7285 : else
7286 : {
7287 6 : error_at (DECL_SOURCE_LOCATION (decl),
7288 : "storage size of %qD isn%'t constant", decl);
7289 6 : TREE_TYPE (decl) = error_mark_node;
7290 6 : type = error_mark_node;
7291 : }
7292 : }
7293 :
7294 : /* If the final element initializes a flexible array field, adjust
7295 : the size of the DECL with the initializer based on whether the
7296 : DECL is a union or a structure. */
7297 66384288 : if (type != error_mark_node
7298 66384282 : && DECL_INITIAL (decl)
7299 39331774 : && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
7300 5399248 : && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
7301 3630657 : && DECL_SIZE (decl) != NULL_TREE
7302 3630657 : && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
7303 3630657 : && COMPLETE_TYPE_P (type)
7304 3630657 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
7305 70014945 : && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
7306 : {
7307 3630657 : constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
7308 3630657 : if (elt.index)
7309 : {
7310 1361429 : tree itype = TREE_TYPE (elt.index);
7311 1361429 : tree vtype = TREE_TYPE (elt.value);
7312 1361429 : if (TREE_CODE (itype) == ARRAY_TYPE
7313 86688 : && TYPE_DOMAIN (itype) == NULL
7314 275 : && TREE_CODE (vtype) == ARRAY_TYPE
7315 1361704 : && COMPLETE_TYPE_P (vtype))
7316 : {
7317 : /* For a structure, add the size of the initializer to the DECL's
7318 : size. */
7319 275 : if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
7320 : {
7321 260 : DECL_SIZE (decl)
7322 260 : = size_binop (PLUS_EXPR, DECL_SIZE (decl),
7323 : TYPE_SIZE (vtype));
7324 260 : DECL_SIZE_UNIT (decl)
7325 520 : = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
7326 : TYPE_SIZE_UNIT (vtype));
7327 : }
7328 : /* For a union, the DECL's size is the maximum of the current size
7329 : and the size of the initializer. */
7330 : else
7331 : {
7332 15 : DECL_SIZE (decl)
7333 15 : = size_binop (MAX_EXPR, DECL_SIZE (decl),
7334 : TYPE_SIZE (vtype));
7335 15 : DECL_SIZE_UNIT (decl)
7336 30 : = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
7337 : TYPE_SIZE_UNIT (vtype));
7338 : }
7339 : }
7340 : }
7341 : }
7342 : }
7343 :
7344 : /* If a local static variable is declared in an inline function, or if
7345 : we have a weak definition, we must endeavor to create only one
7346 : instance of the variable at link-time. */
7347 :
7348 : void
7349 81755686 : maybe_commonize_var (tree decl)
7350 : {
7351 : /* Don't mess with __FUNCTION__ and similar. But do handle structured
7352 : bindings. */
7353 81755686 : if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
7354 : return;
7355 :
7356 : /* Static data in a function with comdat linkage also has comdat
7357 : linkage. */
7358 76321333 : if ((TREE_STATIC (decl)
7359 50652511 : && DECL_FUNCTION_SCOPE_P (decl)
7360 142472 : && vague_linkage_p (DECL_CONTEXT (decl)))
7361 177809706 : || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
7362 : {
7363 44396652 : if (flag_weak)
7364 : {
7365 : /* With weak symbols, we simply make the variable COMDAT;
7366 : that will cause copies in multiple translations units to
7367 : be merged. */
7368 44396625 : comdat_linkage (decl);
7369 : }
7370 : else
7371 : {
7372 27 : if (DECL_INITIAL (decl) == NULL_TREE
7373 27 : || DECL_INITIAL (decl) == error_mark_node)
7374 : {
7375 : /* Without weak symbols, we can use COMMON to merge
7376 : uninitialized variables. */
7377 24 : TREE_PUBLIC (decl) = 1;
7378 24 : DECL_COMMON (decl) = 1;
7379 : }
7380 : else
7381 : {
7382 : /* While for initialized variables, we must use internal
7383 : linkage -- which means that multiple copies will not
7384 : be merged. */
7385 3 : TREE_PUBLIC (decl) = 0;
7386 3 : DECL_COMMON (decl) = 0;
7387 3 : DECL_INTERFACE_KNOWN (decl) = 1;
7388 3 : const char *msg;
7389 3 : if (DECL_INLINE_VAR_P (decl))
7390 : msg = G_("sorry: semantics of inline variable "
7391 : "%q#D are wrong (you%'ll wind up with "
7392 : "multiple copies)");
7393 : else
7394 : msg = G_("sorry: semantics of inline function "
7395 : "static data %q#D are wrong (you%'ll wind "
7396 : "up with multiple copies)");
7397 3 : auto_diagnostic_group d;
7398 3 : if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
7399 : msg, decl))
7400 3 : inform (DECL_SOURCE_LOCATION (decl),
7401 : "you can work around this by removing the initializer");
7402 3 : }
7403 : }
7404 : }
7405 : }
7406 :
7407 : /* Issue an error message if DECL is an uninitialized const variable.
7408 : CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
7409 : context from potential_constant_expression. Returns true if all is well,
7410 : false otherwise. */
7411 :
7412 : bool
7413 9426486 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
7414 : tsubst_flags_t complain)
7415 : {
7416 9426486 : tree type = strip_array_types (TREE_TYPE (decl));
7417 :
7418 : /* ``Unless explicitly declared extern, a const object does not have
7419 : external linkage and must be initialized. ($8.4; $12.1)'' ARM
7420 : 7.1.6 */
7421 9426486 : if (VAR_P (decl)
7422 9426486 : && !TYPE_REF_P (type)
7423 9377703 : && (CP_TYPE_CONST_P (type)
7424 : /* C++20 permits trivial default initialization in constexpr
7425 : context (P1331R2). */
7426 7291739 : || (cxx_dialect < cxx20
7427 139196 : && (constexpr_context_p
7428 124444 : || var_in_constexpr_fn (decl))))
7429 11529315 : && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
7430 : {
7431 671170 : tree field = default_init_uninitialized_part (type);
7432 671170 : if (!field)
7433 : return true;
7434 :
7435 5124 : auto_diagnostic_group d;
7436 5124 : bool show_notes = true;
7437 :
7438 5124 : if (!constexpr_context_p || cxx_dialect >= cxx20)
7439 : {
7440 188 : if (CP_TYPE_CONST_P (type))
7441 : {
7442 90 : if (complain & tf_error)
7443 84 : show_notes = permerror (DECL_SOURCE_LOCATION (decl),
7444 : "uninitialized %<const %D%>", decl);
7445 : }
7446 : else
7447 : {
7448 98 : if (!is_instantiation_of_constexpr (current_function_decl)
7449 98 : && (complain & tf_error))
7450 21 : error_at (DECL_SOURCE_LOCATION (decl),
7451 : "uninitialized variable %qD in %<constexpr%> "
7452 : "function", decl);
7453 : else
7454 : show_notes = false;
7455 98 : cp_function_chain->invalid_constexpr = true;
7456 : }
7457 : }
7458 4936 : else if (complain & tf_error)
7459 2 : error_at (DECL_SOURCE_LOCATION (decl),
7460 : "uninitialized variable %qD in %<constexpr%> context",
7461 : decl);
7462 :
7463 5124 : if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
7464 : {
7465 62 : tree defaulted_ctor;
7466 :
7467 62 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
7468 : "%q#T has no user-provided default constructor", type);
7469 62 : defaulted_ctor = in_class_defaulted_default_constructor (type);
7470 62 : if (defaulted_ctor)
7471 33 : inform (DECL_SOURCE_LOCATION (defaulted_ctor),
7472 : "constructor is not user-provided because it is "
7473 : "explicitly defaulted in the class body");
7474 62 : inform (DECL_SOURCE_LOCATION (field),
7475 : "and the implicitly-defined constructor does not "
7476 : "initialize %q#D", field);
7477 : }
7478 :
7479 5124 : return false;
7480 5124 : }
7481 :
7482 : return true;
7483 : }
7484 :
7485 : /* Structure holding the current initializer being processed by reshape_init.
7486 : CUR is a pointer to the current element being processed, END is a pointer
7487 : after the last element present in the initializer and RAW_IDX is index into
7488 : RAW_DATA_CST if that is CUR elt. */
7489 : struct reshape_iter
7490 : {
7491 : constructor_elt *cur;
7492 : constructor_elt *end;
7493 : unsigned raw_idx;
7494 : };
7495 :
7496 : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
7497 : static tree reshape_single_init (tree, tree, tsubst_flags_t);
7498 :
7499 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
7500 : returned is the next FIELD_DECL (possibly FIELD itself) that can be
7501 : initialized as if for an aggregate class. If there are no more such fields,
7502 : the return value will be NULL. */
7503 :
7504 : tree
7505 15723379 : next_aggregate_field (tree field)
7506 : {
7507 15723379 : while (field
7508 65207890 : && (TREE_CODE (field) != FIELD_DECL
7509 9855647 : || DECL_UNNAMED_BIT_FIELD (field)
7510 9855486 : || (DECL_ARTIFICIAL (field)
7511 : /* In C++17, aggregates can have bases. */
7512 217661 : && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
7513 49484511 : field = DECL_CHAIN (field);
7514 :
7515 15723379 : return field;
7516 : }
7517 :
7518 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
7519 : returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
7520 : to a subobject. If there are no more such fields, the return value will be
7521 : NULL. */
7522 :
7523 : tree
7524 68802101 : next_subobject_field (tree field)
7525 : {
7526 68802101 : while (field
7527 892893621 : && (TREE_CODE (field) != FIELD_DECL
7528 30569905 : || DECL_UNNAMED_BIT_FIELD (field)
7529 30569766 : || (DECL_ARTIFICIAL (field)
7530 8519061 : && !DECL_FIELD_IS_BASE (field)
7531 1838410 : && !DECL_VIRTUAL_P (field))))
7532 824091520 : field = DECL_CHAIN (field);
7533 :
7534 68802101 : return field;
7535 : }
7536 :
7537 : /* Return true for [dcl.init.list] direct-list-initialization from
7538 : single element of enumeration with a fixed underlying type. */
7539 :
7540 : bool
7541 191292644 : is_direct_enum_init (tree type, tree init)
7542 : {
7543 191292644 : if (cxx_dialect >= cxx17
7544 189201126 : && TREE_CODE (type) == ENUMERAL_TYPE
7545 7744727 : && ENUM_FIXED_UNDERLYING_TYPE_P (type)
7546 5286686 : && TREE_CODE (init) == CONSTRUCTOR
7547 454835 : && CONSTRUCTOR_IS_DIRECT_INIT (init)
7548 231200 : && CONSTRUCTOR_NELTS (init) == 1
7549 217 : && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
7550 : /* DR 2374: The single element needs to be implicitly
7551 : convertible to the underlying type of the enum. */
7552 217 : && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
7553 191292859 : && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
7554 215 : TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
7555 215 : CONSTRUCTOR_ELT (init, 0)->value,
7556 : LOOKUP_IMPLICIT, tf_none))
7557 : return true;
7558 : return false;
7559 : }
7560 :
7561 : /* Helper function for reshape_init*. Split first element of
7562 : RAW_DATA_CST or return NULL for other elements. Set *INC_CUR
7563 : to true if the whole d->cur has been consumed. */
7564 :
7565 : static tree
7566 63136952 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
7567 : {
7568 63136952 : *inc_cur = true;
7569 63136952 : if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
7570 : return NULL_TREE;
7571 30720 : tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
7572 30720 : if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
7573 30588 : *inc_cur = false;
7574 : else
7575 132 : d->raw_idx = 0;
7576 : return ret;
7577 : }
7578 :
7579 : /* Wrapper around that which for RAW_DATA_CST in INIT
7580 : (as well as in D->cur->value) peels off the first element
7581 : of the raw data and returns it, otherwise increments
7582 : D->cur and returns INIT. */
7583 :
7584 : static tree
7585 63136935 : consume_init (tree init, reshape_iter *d)
7586 : {
7587 63136935 : bool inc_cur;
7588 63136935 : if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
7589 30720 : init = raw_init;
7590 63136935 : if (inc_cur)
7591 63106347 : d->cur++;
7592 63136935 : return init;
7593 : }
7594 :
7595 : /* Subroutine of reshape_init_array and reshape_init_vector, which does
7596 : the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
7597 : INTEGER_CST representing the size of the array minus one (the maximum index),
7598 : or NULL_TREE if the array was declared without specifying the size. D is
7599 : the iterator within the constructor. */
7600 :
7601 : static tree
7602 471598 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
7603 : tree first_initializer_p, bool vector_p,
7604 : tsubst_flags_t complain)
7605 : {
7606 471598 : tree new_init;
7607 471598 : bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
7608 471598 : unsigned HOST_WIDE_INT max_index_cst = 0;
7609 471598 : unsigned HOST_WIDE_INT index;
7610 :
7611 : /* The initializer for an array is always a CONSTRUCTOR. If this is the
7612 : outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
7613 : to build a new one. But don't reuse if not complaining; if this is
7614 : tentative, we might also reshape to another type (95319). */
7615 471598 : bool reuse = (first_initializer_p
7616 412632 : && (complain & tf_error)
7617 411347 : && !CP_AGGREGATE_TYPE_P (elt_type)
7618 817485 : && !TREE_SIDE_EFFECTS (first_initializer_p));
7619 129465 : if (reuse)
7620 : new_init = first_initializer_p;
7621 : else
7622 129465 : new_init = build_constructor (init_list_type_node, NULL);
7623 :
7624 471598 : if (sized_array_p)
7625 : {
7626 280903 : poly_uint64 midx;
7627 : /* Minus 1 is used for zero sized arrays. */
7628 280903 : if (integer_all_onesp (max_index))
7629 24 : return new_init;
7630 :
7631 280879 : if (tree_fits_poly_uint64_p (max_index))
7632 280879 : midx = tree_to_poly_uint64 (max_index);
7633 : /* sizetype is sign extended, not zero extended. */
7634 : else
7635 0 : midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
7636 :
7637 : /* For VLA vectors, we restrict the number of elements in the constructor
7638 : to lower bound of the VLA elements. */
7639 280879 : max_index_cst = constant_lower_bound (midx);
7640 : }
7641 :
7642 471574 : constructor_elt *first_cur = d->cur;
7643 : /* Loop until there are no more initializers. */
7644 57527029 : for (index = 0;
7645 57527029 : d->cur != d->end && (!sized_array_p || index <= max_index_cst);
7646 : ++index)
7647 : {
7648 57055636 : tree elt_init;
7649 57055636 : constructor_elt *old_cur = d->cur;
7650 57055636 : unsigned int old_raw_idx = d->raw_idx;
7651 57055636 : bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
7652 :
7653 57055636 : if (d->cur->index)
7654 5941818 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7655 57055636 : check_array_designated_initializer (d->cur, index);
7656 57055636 : if (TREE_CODE (d->cur->value) == RAW_DATA_CST
7657 32752 : && (TREE_CODE (elt_type) == INTEGER_TYPE
7658 10233 : || is_byte_access_type (elt_type))
7659 22519 : && TYPE_PRECISION (elt_type) == CHAR_BIT
7660 1858 : && (!sized_array_p || index < max_index_cst)
7661 57057482 : && !vector_p)
7662 : {
7663 526 : elt_init = d->cur->value;
7664 526 : unsigned int off = d->raw_idx;
7665 526 : unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
7666 526 : if (!sized_array_p || len <= max_index_cst - index + 1)
7667 : {
7668 517 : d->cur++;
7669 517 : d->raw_idx = 0;
7670 : }
7671 : else
7672 : {
7673 9 : len = max_index_cst - index + 1;
7674 9 : d->raw_idx += len;
7675 : }
7676 526 : if (!reuse || off || d->cur == old_cur)
7677 : {
7678 27 : elt_init = copy_node (elt_init);
7679 27 : RAW_DATA_LENGTH (elt_init) = len;
7680 27 : RAW_DATA_POINTER (elt_init) += off;
7681 : }
7682 526 : TREE_TYPE (elt_init) = elt_type;
7683 : }
7684 57055110 : else if (d->cur->index)
7685 : {
7686 5941593 : elt_init = reshape_single_init (elt_type, d->cur->value, complain);
7687 5941593 : d->cur++;
7688 : }
7689 : else
7690 51113517 : elt_init = reshape_init_r (elt_type, d,
7691 : /*first_initializer_p=*/NULL_TREE,
7692 : complain);
7693 57055636 : if (elt_init == error_mark_node)
7694 : return error_mark_node;
7695 57055458 : tree idx = size_int (index);
7696 57055458 : if (reuse && old_raw_data_cst && d->cur == old_cur)
7697 : {
7698 : /* We need to stop reusing as some RAW_DATA_CST in the original
7699 : ctor had to be split. */
7700 72 : new_init = build_constructor (init_list_type_node, NULL);
7701 72 : if (index)
7702 : {
7703 72 : vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
7704 72 : memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
7705 72 : (d->cur - first_cur)
7706 : * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
7707 72 : if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
7708 : {
7709 : unsigned int j;
7710 : tree nidx, nval;
7711 4 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
7712 : j, nidx, nval)
7713 4 : if (nidx)
7714 : {
7715 4 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
7716 4 : (void) nval;
7717 4 : break;
7718 : }
7719 : }
7720 : }
7721 : reuse = false;
7722 : }
7723 57055390 : if (reuse)
7724 : {
7725 55544105 : old_cur->index = idx;
7726 55544105 : old_cur->value = elt_init;
7727 : }
7728 : else
7729 1511353 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
7730 : idx, elt_init);
7731 57055458 : if (!TREE_CONSTANT (elt_init))
7732 196707 : TREE_CONSTANT (new_init) = false;
7733 :
7734 : /* This can happen with an invalid initializer (c++/54501). */
7735 57055458 : if (d->cur == old_cur
7736 32082 : && !sized_array_p
7737 14085 : && d->raw_idx == old_raw_idx)
7738 : break;
7739 :
7740 57055455 : if (TREE_CODE (elt_init) == RAW_DATA_CST)
7741 526 : index += RAW_DATA_LENGTH (elt_init) - 1;
7742 : }
7743 :
7744 : return new_init;
7745 : }
7746 :
7747 : /* Subroutine of reshape_init_r, processes the initializers for arrays.
7748 : Parameters are the same of reshape_init_r. */
7749 :
7750 : static tree
7751 421701 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
7752 : tsubst_flags_t complain)
7753 : {
7754 421701 : tree max_index = NULL_TREE;
7755 :
7756 421701 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
7757 :
7758 421701 : if (TYPE_DOMAIN (type))
7759 231052 : max_index = array_type_nelts_minus_one (type);
7760 :
7761 421701 : return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
7762 421701 : first_initializer_p, false, complain);
7763 : }
7764 :
7765 : /* Subroutine of reshape_init_r, processes the initializers for vectors.
7766 : Parameters are the same of reshape_init_r. */
7767 :
7768 : static tree
7769 49897 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
7770 : {
7771 49897 : tree max_index = NULL_TREE;
7772 :
7773 49897 : gcc_assert (VECTOR_TYPE_P (type));
7774 :
7775 49897 : if (COMPOUND_LITERAL_P (d->cur->value))
7776 : {
7777 0 : tree value = d->cur->value;
7778 0 : if (!same_type_p (TREE_TYPE (value), type))
7779 : {
7780 0 : if (complain & tf_error)
7781 0 : error ("invalid type %qT as initializer for a vector of type %qT",
7782 0 : TREE_TYPE (d->cur->value), type);
7783 0 : value = error_mark_node;
7784 : }
7785 0 : ++d->cur;
7786 0 : return value;
7787 : }
7788 :
7789 : /* For a vector, we initialize it as an array of the appropriate size. */
7790 49897 : if (VECTOR_TYPE_P (type))
7791 49897 : max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
7792 :
7793 49897 : return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
7794 49897 : NULL_TREE, true, complain);
7795 : }
7796 :
7797 : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
7798 : INIT, in isolation from any designator or other initializers. */
7799 :
7800 : static tree
7801 6597961 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
7802 : {
7803 : /* We could also implement this by wrapping init in a new CONSTRUCTOR and
7804 : calling reshape_init, but this way can just live on the stack. */
7805 6597961 : constructor_elt elt = { /*index=*/NULL_TREE, init };
7806 6597961 : reshape_iter iter = { &elt, &elt + 1, 0 };
7807 6597961 : return reshape_init_r (type, &iter,
7808 : /*first_initializer_p=*/NULL_TREE,
7809 6597961 : complain);
7810 : }
7811 :
7812 : /* Subroutine of reshape_init_r, processes the initializers for classes
7813 : or union. Parameters are the same of reshape_init_r. */
7814 :
7815 : static tree
7816 3787896 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
7817 : tsubst_flags_t complain)
7818 : {
7819 3787896 : tree field;
7820 3787896 : tree new_init;
7821 :
7822 3787896 : gcc_assert (CLASS_TYPE_P (type));
7823 :
7824 : /* The initializer for a class is always a CONSTRUCTOR. */
7825 3787896 : new_init = build_constructor (init_list_type_node, NULL);
7826 :
7827 3787896 : int binfo_idx = -1;
7828 3787896 : tree binfo = TYPE_BINFO (type);
7829 3787896 : tree base_binfo = NULL_TREE;
7830 3787896 : if (cxx_dialect >= cxx17 && uses_template_parms (type))
7831 : {
7832 : /* We get here from maybe_aggr_guide for C++20 class template argument
7833 : deduction. In this case we need to look through the binfo because a
7834 : template doesn't have base fields. */
7835 2781 : binfo_idx = 0;
7836 2781 : BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
7837 : }
7838 86 : if (base_binfo)
7839 : field = base_binfo;
7840 : else
7841 3787810 : field = next_aggregate_field (TYPE_FIELDS (type));
7842 :
7843 3787810 : if (!field)
7844 : {
7845 : /* [dcl.init.aggr]
7846 :
7847 : An initializer for an aggregate member that is an
7848 : empty class shall have the form of an empty
7849 : initializer-list {}. */
7850 322 : if (!first_initializer_p)
7851 : {
7852 268 : if (complain & tf_error)
7853 13 : error ("initializer for %qT must be brace-enclosed", type);
7854 268 : return error_mark_node;
7855 : }
7856 : return new_init;
7857 : }
7858 :
7859 : /* For C++29 designated initializers we do modify d->cur->index in place
7860 : to cache name lookup results. Make sure to undo it before returning. */
7861 3787574 : struct designator_undo {
7862 : constructor_elt *start, *end;
7863 3787635 : void undo ()
7864 : {
7865 3787786 : while (start != end)
7866 : {
7867 151 : start->index = DECL_NAME (start->index);
7868 151 : ++start;
7869 : }
7870 3787635 : start = end = nullptr;
7871 3787635 : }
7872 3787574 : ~designator_undo () { undo (); }
7873 3787574 : } desig_undo = { nullptr, nullptr };
7874 :
7875 : /* For C++20 CTAD, handle pack expansions in the base list. */
7876 3787574 : tree last_was_pack_expansion = NULL_TREE;
7877 3787574 : bool first_desig = true;
7878 :
7879 : /* Loop through the initializable fields, gathering initializers. */
7880 11328551 : while (d->cur != d->end)
7881 : {
7882 7650016 : tree field_init;
7883 7650016 : constructor_elt *old_cur = d->cur;
7884 7650016 : unsigned old_raw_idx = d->raw_idx;
7885 7650016 : bool direct_desig = false;
7886 :
7887 : /* Handle C++20 designated initializers. */
7888 7650016 : if (d->cur->index)
7889 : {
7890 656702 : if (d->cur->index == error_mark_node)
7891 : return error_mark_node;
7892 :
7893 656695 : if (TREE_CODE (d->cur->index) == FIELD_DECL)
7894 : {
7895 181 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7896 181 : direct_desig = true;
7897 181 : field = d->cur->index;
7898 : }
7899 656514 : else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
7900 : {
7901 656508 : if (first_desig && cxx_dialect >= cxx20)
7902 : {
7903 311585 : if (CONSTRUCTOR_NELTS (new_init))
7904 : {
7905 115 : constructor_elt *last
7906 115 : = &CONSTRUCTOR_ELTS (new_init)->last ();
7907 115 : if (last->index == NULL_TREE
7908 115 : || TREE_CODE (last->index) != FIELD_DECL
7909 230 : || !DECL_FIELD_IS_BASE (last->index))
7910 : {
7911 23 : if (complain & tf_error)
7912 23 : error ("last non-designated initializer clause "
7913 : "does not appertain to a base class "
7914 : "subobject");
7915 23 : return error_mark_node;
7916 : }
7917 : }
7918 : first_desig = false;
7919 : }
7920 656485 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7921 656485 : field = get_class_binding (type, d->cur->index);
7922 656485 : direct_desig = true;
7923 656485 : if (!field && cxx_dialect >= cxx29)
7924 44 : field = lookup_member (type, d->cur->index, /*protect=*/2,
7925 : /*want_type=*/false, complain);
7926 : }
7927 : else
7928 : {
7929 6 : if (complain & tf_error)
7930 6 : error ("%<[%E] =%> used in a GNU-style designated initializer"
7931 : " for class %qT", d->cur->index, type);
7932 6 : return error_mark_node;
7933 : }
7934 :
7935 257 : if (!field && ANON_AGGR_TYPE_P (type))
7936 : /* Apparently the designator isn't for a member of this anonymous
7937 : struct, so head back to the enclosing class. */
7938 : break;
7939 :
7940 656663 : if (!field || TREE_CODE (field) != FIELD_DECL)
7941 : {
7942 43 : if (complain & tf_error)
7943 : {
7944 28 : if (field && TREE_CODE (field) == TREE_LIST)
7945 : {
7946 5 : auto_diagnostic_group g;
7947 5 : error ("request for member %qD is ambiguous",
7948 5 : d->cur->index);
7949 5 : print_candidates (input_location, field);
7950 5 : }
7951 : else
7952 23 : error ("%qT has no non-static data member named %qD", type,
7953 23 : d->cur->index);
7954 : }
7955 43 : return error_mark_node;
7956 : }
7957 :
7958 : /* If the element is an anonymous union object and the initializer
7959 : list is a designated-initializer-list, the anonymous union object
7960 : is initialized by the designated-initializer-list { D }, where D
7961 : is the designated-initializer-clause naming a member of the
7962 : anonymous union object. */
7963 656620 : tree ictx = DECL_CONTEXT (field);
7964 656620 : if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
7965 : {
7966 : /* Find the anon aggr that is a direct member of TYPE. */
7967 266 : while (ANON_AGGR_TYPE_P (ictx))
7968 : {
7969 154 : tree cctx = TYPE_CONTEXT (ictx);
7970 154 : if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
7971 140 : goto found;
7972 : ictx = cctx;
7973 : }
7974 :
7975 : /* In C++29 a designator can name a member of a base; in that
7976 : case, go through the designators and replace ids with _DECLs
7977 : to record the lookup for the most-derived class. */
7978 112 : if (cxx_dialect >= cxx29)
7979 : {
7980 110 : tree ibinfo = lookup_base (type, ictx, ba_unique, NULL,
7981 : complain);
7982 110 : if (!ibinfo)
7983 : /* The designator names a field outside this base class,
7984 : so we're done. */
7985 : break;
7986 61 : else if (ibinfo != error_mark_node)
7987 : {
7988 74 : while (BINFO_INHERITANCE_CHAIN (ibinfo) != binfo)
7989 : ibinfo = BINFO_INHERITANCE_CHAIN (ibinfo);
7990 61 : ictx = TREE_TYPE (ibinfo);
7991 :
7992 61 : desig_undo.undo ();
7993 :
7994 61 : if (d->cur->index != field)
7995 : {
7996 47 : d->cur->index = field;
7997 47 : desig_undo.start = d->cur;
7998 : }
7999 61 : constructor_elt *e = d->cur + 1;
8000 228 : for (; e != d->end; ++e)
8001 : {
8002 173 : if (e->index == NULL_TREE
8003 173 : || e->index == error_mark_node)
8004 : break;
8005 167 : if (desig_undo.start)
8006 : {
8007 104 : gcc_assert (TREE_CODE (e->index)
8008 : == IDENTIFIER_NODE);
8009 104 : field = lookup_member (type, e->index,
8010 : /*protect=*/2,
8011 : /*want_type=*/false,
8012 : tf_none);
8013 104 : if (!field || TREE_CODE (field) != FIELD_DECL)
8014 : break;
8015 : }
8016 : else
8017 : {
8018 63 : gcc_assert (TREE_CODE (e->index) == FIELD_DECL);
8019 : field = e->index;
8020 : }
8021 :
8022 167 : if (desig_undo.start)
8023 104 : e->index = field;
8024 : }
8025 61 : if (desig_undo.start)
8026 47 : desig_undo.end = e;
8027 61 : goto found;
8028 : }
8029 : }
8030 :
8031 : /* Not found, e.g. FIELD is a member of a base class. */
8032 2 : if (complain & tf_error)
8033 2 : error ("%qD is not a direct member of %qT", field, type);
8034 2 : return error_mark_node;
8035 :
8036 201 : found:
8037 : /* Now find the TYPE member with that anon aggr type. */
8038 201 : tree aafield = TYPE_FIELDS (type);
8039 1622 : for (; aafield; aafield = TREE_CHAIN (aafield))
8040 1622 : if (TREE_TYPE (aafield) == ictx)
8041 : break;
8042 0 : gcc_assert (aafield);
8043 : field = aafield;
8044 : direct_desig = false;
8045 : }
8046 : }
8047 :
8048 : /* If we processed all the member of the class, we are done. */
8049 7649682 : if (!field)
8050 : break;
8051 :
8052 15298796 : last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
8053 7649408 : ? field : NULL_TREE);
8054 20 : if (last_was_pack_expansion)
8055 : /* Each non-trailing aggregate element that is a pack expansion is
8056 : assumed to correspond to no elements of the initializer list. */
8057 20 : goto continue_;
8058 :
8059 7649388 : if (direct_desig)
8060 : {
8061 : /* The designated field F is initialized from this one element.
8062 :
8063 : Note that we don't want to do this if we found the designator
8064 : inside an anon aggr above; we use the normal code to implement:
8065 :
8066 : "If the element is an anonymous union member and the initializer
8067 : list is a brace-enclosed designated- initializer-list, the element
8068 : is initialized by the designated-initializer-list { D }, where D
8069 : is the designated- initializer-clause naming a member of the
8070 : anonymous union member." */
8071 656368 : gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
8072 656368 : field_init = reshape_single_init (TREE_TYPE (field),
8073 : d->cur->value, complain);
8074 656368 : d->cur++;
8075 : }
8076 : else
8077 6993020 : field_init = reshape_init_r (TREE_TYPE (field), d,
8078 : /*first_initializer_p=*/NULL_TREE,
8079 : complain);
8080 :
8081 7649388 : if (field_init == error_mark_node)
8082 : return error_mark_node;
8083 :
8084 7649100 : if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
8085 : {
8086 : /* This can happen with an invalid initializer for a flexible
8087 : array member (c++/54441). */
8088 0 : if (complain & tf_error)
8089 0 : error ("invalid initializer for %q#D", field);
8090 0 : return error_mark_node;
8091 : }
8092 :
8093 7649100 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
8094 :
8095 : /* [dcl.init.aggr]
8096 :
8097 : When a union is initialized with a brace-enclosed
8098 : initializer, the braces shall only contain an
8099 : initializer for the first member of the union. */
8100 7649100 : if (TREE_CODE (type) == UNION_TYPE)
8101 : break;
8102 :
8103 7540957 : continue_:
8104 7540977 : if (base_binfo)
8105 : {
8106 101 : if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
8107 : field = base_binfo;
8108 : else
8109 38 : field = next_aggregate_field (TYPE_FIELDS (type));
8110 : }
8111 : else
8112 7540876 : field = next_aggregate_field (DECL_CHAIN (field));
8113 : }
8114 :
8115 : /* A trailing aggregate element that is a pack expansion is assumed to
8116 : correspond to all remaining elements of the initializer list (if any). */
8117 3787205 : if (last_was_pack_expansion)
8118 : {
8119 17 : tree init = d->cur->value;
8120 17 : bool inc_cur;
8121 17 : if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
8122 0 : init = raw_init;
8123 17 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
8124 : last_was_pack_expansion, init);
8125 49 : while (d->cur != d->end)
8126 32 : d->cur++;
8127 : }
8128 :
8129 : return new_init;
8130 3787574 : }
8131 :
8132 : /* Subroutine of reshape_init_r. We're in a context where C99 initializer
8133 : designators are not valid; either complain or return true to indicate
8134 : that reshape_init_r should return error_mark_node. */
8135 :
8136 : static bool
8137 252153 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
8138 : {
8139 252153 : if (d->cur->index)
8140 : {
8141 30 : if (complain & tf_error)
8142 45 : error_at (cp_expr_loc_or_input_loc (d->cur->index),
8143 : "C99 designator %qE outside aggregate initializer",
8144 : d->cur->index);
8145 : else
8146 : return true;
8147 : }
8148 : return false;
8149 : }
8150 :
8151 : /* Subroutine of reshape_init, which processes a single initializer (part of
8152 : a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
8153 : iterator within the CONSTRUCTOR which points to the initializer to process.
8154 : If this is the first initializer of the outermost CONSTRUCTOR node,
8155 : FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE. */
8156 :
8157 : static tree
8158 69205985 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
8159 : tsubst_flags_t complain)
8160 : {
8161 69205985 : tree init = d->cur->value;
8162 :
8163 69205985 : if (error_operand_p (init))
8164 130 : return error_mark_node;
8165 :
8166 4501360 : if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
8167 69457829 : && has_designator_problem (d, complain))
8168 0 : return error_mark_node;
8169 :
8170 69205855 : tree stripped_init = tree_strip_any_location_wrapper (init);
8171 :
8172 69205855 : if (TREE_CODE (type) == COMPLEX_TYPE)
8173 : {
8174 : /* A complex type can be initialized from one or two initializers,
8175 : but braces are not elided. */
8176 672 : init = consume_init (init, d);
8177 672 : if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
8178 : {
8179 9 : if (CONSTRUCTOR_NELTS (stripped_init) > 2)
8180 : {
8181 0 : if (complain & tf_error)
8182 0 : error ("too many initializers for %qT", type);
8183 : else
8184 0 : return error_mark_node;
8185 : }
8186 : }
8187 663 : else if (first_initializer_p && d->cur != d->end)
8188 : {
8189 36 : if (error_operand_p (d->cur->value)
8190 36 : || has_designator_problem (d, complain))
8191 0 : return error_mark_node;
8192 36 : vec<constructor_elt, va_gc> *v = 0;
8193 36 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
8194 36 : init = consume_init (d->cur->value, d);
8195 36 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
8196 36 : init = build_constructor (init_list_type_node, v);
8197 : }
8198 : return init;
8199 : }
8200 :
8201 : /* If we have a designator, d doesn't initialize TYPE directly, it
8202 : initializes an element, with brace elision if !first_initializer_p. But
8203 : if TYPE is non-aggregate (and we didn't already return error_mark_node),
8204 : we should have errored about the designator in has_designator_problem, so
8205 : now ignore it for error recovery. */
8206 69205183 : if (d->cur->index)
8207 : {
8208 : /* Deliberately not CP_AGGREGATE_TYPE_P to get a better diagnostic for
8209 : trying to designate a member of a non-aggregate class. */
8210 368928 : if (AGGREGATE_TYPE_P (type))
8211 368922 : goto skip_single;
8212 : else
8213 6 : gcc_checking_assert (seen_error ());
8214 : }
8215 :
8216 : /* A non-aggregate type is always initialized with a single
8217 : initializer. */
8218 137613827 : if (!CP_AGGREGATE_TYPE_P (type)
8219 : /* As is an array with dependent bound, which we can see
8220 : during C++20 aggregate CTAD. */
8221 74483304 : || (cxx_dialect >= cxx20
8222 5605394 : && TREE_CODE (type) == ARRAY_TYPE
8223 456990 : && uses_template_parms (TYPE_DOMAIN (type))))
8224 : {
8225 : /* It is invalid to initialize a non-aggregate type with a
8226 : brace-enclosed initializer before C++0x.
8227 : We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
8228 : of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
8229 : a CONSTRUCTOR (with a record type). */
8230 63130534 : if (TREE_CODE (stripped_init) == CONSTRUCTOR
8231 : /* Don't complain about a capture-init. */
8232 304885 : && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
8233 63424636 : && BRACE_ENCLOSED_INITIALIZER_P (stripped_init)) /* p7626.C */
8234 : {
8235 294063 : if (SCALAR_TYPE_P (type))
8236 : {
8237 490 : if (cxx_dialect < cxx11)
8238 : {
8239 16 : if (complain & tf_error)
8240 16 : error ("braces around scalar initializer for type %qT",
8241 : type);
8242 16 : init = error_mark_node;
8243 : }
8244 474 : else if (first_initializer_p
8245 474 : || (CONSTRUCTOR_NELTS (stripped_init) > 0
8246 296 : && (BRACE_ENCLOSED_INITIALIZER_P
8247 : (CONSTRUCTOR_ELT (stripped_init,0)->value))))
8248 : {
8249 13 : if (complain & tf_error)
8250 13 : error ("too many braces around scalar initializer "
8251 : "for type %qT", type);
8252 13 : init = error_mark_node;
8253 : }
8254 : }
8255 : else
8256 293573 : maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
8257 : }
8258 63130534 : return consume_init (init, d);
8259 : }
8260 :
8261 : /* "If T is a class type and the initializer list has a single element of
8262 : type cv U, where U is T or a class derived from T, the object is
8263 : initialized from that element." Even if T is an aggregate. */
8264 5681893 : if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
8265 5199399 : && first_initializer_p
8266 3505588 : && d->end - d->cur == 1
8267 609861 : && TREE_CODE (init) != RAW_DATA_CST
8268 6315588 : && reference_related_p (type, TREE_TYPE (init)))
8269 : {
8270 426 : d->cur++;
8271 426 : return init;
8272 : }
8273 :
8274 : /* [dcl.init.aggr]
8275 :
8276 : All implicit type conversions (clause _conv_) are considered when
8277 : initializing the aggregate member with an initializer from an
8278 : initializer-list. If the initializer can initialize a member,
8279 : the member is initialized. Otherwise, if the member is itself a
8280 : non-empty subaggregate, brace elision is assumed and the
8281 : initializer is considered for the initialization of the first
8282 : member of the subaggregate. */
8283 2452564 : if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
8284 : /* But don't try this for the first initializer, since that would be
8285 : looking through the outermost braces; A a2 = { a1 }; is not a
8286 : valid aggregate initialization. */
8287 3252803 : && !first_initializer_p
8288 5722237 : && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
8289 11279 : || can_convert_arg (type, TREE_TYPE (init),
8290 11279 : TREE_CODE (init) == RAW_DATA_CST
8291 5705301 : ? build_int_cst (integer_type_node,
8292 1606 : *(const unsigned char *)
8293 1606 : RAW_DATA_POINTER (init))
8294 : : init,
8295 : LOOKUP_NORMAL, complain)))
8296 5693 : return consume_init (init, d);
8297 :
8298 6068530 : skip_single:
8299 :
8300 : /* [dcl.init.string]
8301 :
8302 : A char array (whether plain char, signed char, or unsigned char)
8303 : can be initialized by a string-literal (optionally enclosed in
8304 : braces); a wchar_t array can be initialized by a wide
8305 : string-literal (optionally enclosed in braces). */
8306 6068530 : if (TREE_CODE (type) == ARRAY_TYPE
8307 6068530 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
8308 : {
8309 112192 : tree str_init = init;
8310 112192 : tree stripped_str_init = stripped_init;
8311 112192 : reshape_iter stripd = {};
8312 :
8313 : /* Strip one level of braces if and only if they enclose a single
8314 : element (as allowed by [dcl.init.string]). */
8315 112192 : if (!first_initializer_p
8316 2780 : && TREE_CODE (stripped_str_init) == CONSTRUCTOR
8317 113818 : && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
8318 : {
8319 399 : stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
8320 399 : str_init = stripd.cur->value;
8321 399 : stripped_str_init = tree_strip_any_location_wrapper (str_init);
8322 : }
8323 :
8324 : /* If it's a string literal, then it's the initializer for the array
8325 : as a whole. Otherwise, continue with normal initialization for
8326 : array types (one value per array element). */
8327 112192 : if (TREE_CODE (stripped_str_init) == STRING_CST)
8328 : {
8329 72 : if ((first_initializer_p && has_designator_problem (d, complain))
8330 1062 : || (stripd.cur && has_designator_problem (&stripd, complain)))
8331 990 : return error_mark_node;
8332 990 : d->cur++;
8333 990 : return str_init;
8334 : }
8335 : }
8336 :
8337 : /* The following cases are about aggregates. If we are not within a full
8338 : initializer already, and there is not a CONSTRUCTOR, it means that there
8339 : is a missing set of braces (that is, we are processing the case for
8340 : which reshape_init exists). */
8341 6067540 : bool braces_elided_p = false;
8342 6067540 : if (!first_initializer_p)
8343 : {
8344 1818652 : if (TREE_CODE (stripped_init) == CONSTRUCTOR && !d->cur->index)
8345 : {
8346 1808063 : tree init_type = TREE_TYPE (init);
8347 1808063 : if (init_type && TYPE_PTRMEMFUNC_P (init_type))
8348 : /* There is no need to call reshape_init for pointer-to-member
8349 : function initializers, as they are always constructed correctly
8350 : by the front end. Here we have e.g. {.__pfn=0B, .__delta=0},
8351 : which is missing outermost braces. We should warn below, and
8352 : one of the routines below will wrap it in additional { }. */;
8353 : /* For a nested compound literal, proceed to specialized routines,
8354 : to handle initialization of arrays and similar. */
8355 1808054 : else if (COMPOUND_LITERAL_P (stripped_init))
8356 8 : gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
8357 : /* A CONSTRUCTOR of the target's type is a previously
8358 : digested initializer. */
8359 1808046 : else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
8360 : {
8361 0 : ++d->cur;
8362 0 : return init;
8363 : }
8364 : else
8365 : {
8366 : /* Something that hasn't been reshaped yet. */
8367 1808046 : ++d->cur;
8368 1808046 : gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
8369 1808046 : return reshape_init (type, init, complain);
8370 : }
8371 : }
8372 :
8373 10606 : if (complain & tf_warning)
8374 9416 : warning (OPT_Wmissing_braces,
8375 : "missing braces around initializer for %qT",
8376 : type);
8377 : braces_elided_p = true;
8378 : }
8379 :
8380 : /* Dispatch to specialized routines. */
8381 4259494 : tree new_init;
8382 4259494 : if (CLASS_TYPE_P (type))
8383 3787896 : new_init = reshape_init_class (type, d, first_initializer_p, complain);
8384 471598 : else if (TREE_CODE (type) == ARRAY_TYPE)
8385 421701 : new_init = reshape_init_array (type, d, first_initializer_p, complain);
8386 49897 : else if (VECTOR_TYPE_P (type))
8387 49897 : new_init = reshape_init_vector (type, d, complain);
8388 : else
8389 0 : gcc_unreachable ();
8390 :
8391 4259494 : if (braces_elided_p
8392 10606 : && TREE_CODE (new_init) == CONSTRUCTOR)
8393 10331 : CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
8394 :
8395 : return new_init;
8396 : }
8397 :
8398 : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
8399 : brace-enclosed aggregate initializer.
8400 :
8401 : INIT is the CONSTRUCTOR containing the list of initializers describing
8402 : a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
8403 : It may not presently match the shape of the TYPE; for example:
8404 :
8405 : struct S { int a; int b; };
8406 : struct S a[] = { 1, 2, 3, 4 };
8407 :
8408 : Here INIT will hold a vector of four elements, rather than a
8409 : vector of two elements, each itself a vector of two elements. This
8410 : routine transforms INIT from the former form into the latter. The
8411 : revised CONSTRUCTOR node is returned. */
8412 :
8413 : tree
8414 12668318 : reshape_init (tree type, tree init, tsubst_flags_t complain)
8415 : {
8416 12668318 : vec<constructor_elt, va_gc> *v;
8417 12668318 : reshape_iter d;
8418 12668318 : tree new_init;
8419 :
8420 12668318 : gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
8421 :
8422 12668318 : v = CONSTRUCTOR_ELTS (init);
8423 :
8424 : /* An empty constructor does not need reshaping, and it is always a valid
8425 : initializer. */
8426 12668318 : if (vec_safe_is_empty (v))
8427 : return init;
8428 :
8429 4502660 : if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
8430 : /* Already reshaped. */
8431 : return init;
8432 :
8433 : /* Brace elision is not performed for a CONSTRUCTOR representing
8434 : parenthesized aggregate initialization. */
8435 4502511 : if (CONSTRUCTOR_IS_PAREN_INIT (init))
8436 : {
8437 849 : tree elt = (*v)[0].value;
8438 : /* If we're initializing a char array from a string-literal that is
8439 : enclosed in braces, unwrap it here. */
8440 849 : if (TREE_CODE (type) == ARRAY_TYPE
8441 277 : && vec_safe_length (v) == 1
8442 149 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
8443 888 : && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
8444 34 : return elt;
8445 : return init;
8446 : }
8447 :
8448 : /* Handle [dcl.init.list] direct-list-initialization from
8449 : single element of enumeration with a fixed underlying type. */
8450 4501662 : if (is_direct_enum_init (type, init))
8451 : {
8452 175 : tree elt = CONSTRUCTOR_ELT (init, 0)->value;
8453 175 : type = cv_unqualified (type);
8454 175 : if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
8455 : {
8456 160 : warning_sentinel w (warn_useless_cast);
8457 160 : warning_sentinel w2 (warn_ignored_qualifiers);
8458 160 : return cp_build_c_cast (input_location, type, elt,
8459 : tf_warning_or_error);
8460 160 : }
8461 : else
8462 15 : return error_mark_node;
8463 : }
8464 :
8465 : /* Recurse on this CONSTRUCTOR. */
8466 4501487 : d.cur = &(*v)[0];
8467 4501487 : d.end = d.cur + v->length ();
8468 4501487 : d.raw_idx = 0;
8469 :
8470 4501487 : new_init = reshape_init_r (type, &d, init, complain);
8471 4501487 : if (new_init == error_mark_node)
8472 : return error_mark_node;
8473 :
8474 : /* Make sure all the element of the constructor were used. Otherwise,
8475 : issue an error about exceeding initializers. */
8476 4500814 : if (d.cur != d.end)
8477 : {
8478 207 : if (complain & tf_error)
8479 64 : error ("too many initializers for %qT", type);
8480 207 : return error_mark_node;
8481 : }
8482 :
8483 4500607 : if (CONSTRUCTOR_IS_DIRECT_INIT (init)
8484 4500607 : && BRACE_ENCLOSED_INITIALIZER_P (new_init))
8485 625317 : CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
8486 4500607 : if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
8487 4500607 : && BRACE_ENCLOSED_INITIALIZER_P (new_init))
8488 75103 : gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
8489 : || seen_error ());
8490 :
8491 : return new_init;
8492 : }
8493 :
8494 : /* Verify array initializer. Returns true if errors have been reported. */
8495 :
8496 : bool
8497 1038243 : check_array_initializer (tree decl, tree type, tree init)
8498 : {
8499 1038243 : tree element_type = TREE_TYPE (type);
8500 :
8501 : /* Structured binding when initialized with an array type needs
8502 : to have complete type. */
8503 1038243 : if (decl
8504 1021200 : && DECL_DECOMPOSITION_P (decl)
8505 10451 : && DECL_DECOMP_IS_BASE (decl)
8506 1048694 : && !COMPLETE_TYPE_P (type))
8507 : {
8508 0 : error_at (DECL_SOURCE_LOCATION (decl),
8509 : "structured binding has incomplete type %qT", type);
8510 0 : TREE_TYPE (decl) = error_mark_node;
8511 0 : return true;
8512 : }
8513 :
8514 : /* The array type itself need not be complete, because the
8515 : initializer may tell us how many elements are in the array.
8516 : But, the elements of the array must be complete. */
8517 1038243 : if (!COMPLETE_TYPE_P (complete_type (element_type)))
8518 : {
8519 15 : if (decl)
8520 9 : error_at (DECL_SOURCE_LOCATION (decl),
8521 : "elements of array %q#D have incomplete type", decl);
8522 : else
8523 6 : error ("elements of array %q#T have incomplete type", type);
8524 : return true;
8525 : }
8526 :
8527 1038228 : location_t loc = (decl ? location_of (decl) : input_location);
8528 1038228 : if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
8529 : return true;
8530 :
8531 : /* A compound literal can't have variable size. */
8532 1038228 : if (init && !decl
8533 1038228 : && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
8534 17034 : || !TREE_CONSTANT (TYPE_SIZE (element_type))))
8535 : {
8536 3 : error ("variable-sized compound literal");
8537 3 : return true;
8538 : }
8539 : return false;
8540 : }
8541 :
8542 : /* Subroutine of check_initializer; args are passed down from that function.
8543 : Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init. */
8544 :
8545 : static tree
8546 3292630 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
8547 : {
8548 3292630 : gcc_assert (stmts_are_full_exprs_p ());
8549 3292630 : if (init)
8550 2680952 : maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
8551 3292630 : return build_aggr_init (decl, init, flags, tf_warning_or_error);
8552 : }
8553 :
8554 : /* Verify INIT (the initializer for DECL), and record the
8555 : initialization in DECL_INITIAL, if appropriate. CLEANUP is as for
8556 : grok_reference_init.
8557 :
8558 : If the return value is non-NULL, it is an expression that must be
8559 : evaluated dynamically to initialize DECL. */
8560 :
8561 : static tree
8562 59379033 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
8563 : {
8564 59379033 : tree type;
8565 59379033 : tree init_code = NULL;
8566 59379033 : tree core_type;
8567 :
8568 : /* Things that are going to be initialized need to have complete
8569 : type. */
8570 59379033 : TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
8571 :
8572 59379033 : if (DECL_HAS_VALUE_EXPR_P (decl))
8573 : {
8574 : /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
8575 : it doesn't have storage to be initialized. */
8576 708 : gcc_assert (init == NULL_TREE);
8577 : return NULL_TREE;
8578 : }
8579 :
8580 59378325 : if (type == error_mark_node)
8581 : /* We will have already complained. */
8582 : return NULL_TREE;
8583 :
8584 59378325 : if (TREE_CODE (type) == ARRAY_TYPE)
8585 : {
8586 1021200 : if (check_array_initializer (decl, type, init))
8587 : return NULL_TREE;
8588 : }
8589 58357125 : else if (!COMPLETE_TYPE_P (type))
8590 : {
8591 37 : error_at (DECL_SOURCE_LOCATION (decl),
8592 : "%q#D has incomplete type", decl);
8593 37 : TREE_TYPE (decl) = error_mark_node;
8594 37 : return NULL_TREE;
8595 : }
8596 : else
8597 : /* There is no way to make a variable-sized class type in GNU C++. */
8598 58357088 : gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
8599 :
8600 59378279 : if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
8601 : {
8602 2976212 : int init_len = CONSTRUCTOR_NELTS (init);
8603 2976212 : if (SCALAR_TYPE_P (type))
8604 : {
8605 76163 : if (init_len == 0)
8606 : {
8607 42667 : maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
8608 42667 : init = build_zero_init (type, NULL_TREE, false);
8609 : }
8610 33496 : else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
8611 : {
8612 12 : error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
8613 : "scalar object %qD requires one element in "
8614 : "initializer", decl);
8615 6 : TREE_TYPE (decl) = error_mark_node;
8616 6 : return NULL_TREE;
8617 : }
8618 : }
8619 : }
8620 :
8621 59378273 : if (TREE_CODE (decl) == CONST_DECL)
8622 : {
8623 0 : gcc_assert (!TYPE_REF_P (type));
8624 :
8625 0 : DECL_INITIAL (decl) = init;
8626 :
8627 0 : gcc_assert (init != NULL_TREE);
8628 : init = NULL_TREE;
8629 : }
8630 59378273 : else if (!init && DECL_REALLY_EXTERN (decl))
8631 : ;
8632 59378273 : else if (flag_openmp
8633 190491 : && VAR_P (decl)
8634 190491 : && DECL_LANG_SPECIFIC (decl)
8635 111301 : && DECL_OMP_DECLARE_MAPPER_P (decl)
8636 59378273 : && TREE_CODE (init) == OMP_DECLARE_MAPPER)
8637 : return NULL_TREE;
8638 4396810 : else if (init || type_build_ctor_call (type)
8639 63163402 : || TYPE_REF_P (type))
8640 : {
8641 55593159 : if (TYPE_REF_P (type))
8642 : {
8643 387825 : init = grok_reference_init (decl, type, init, flags);
8644 387825 : flags |= LOOKUP_ALREADY_DIGESTED;
8645 : }
8646 55205334 : else if (!init)
8647 611681 : check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
8648 : tf_warning_or_error);
8649 : /* Do not reshape constructors of vectors (they don't need to be
8650 : reshaped. */
8651 54593653 : else if (BRACE_ENCLOSED_INITIALIZER_P (init))
8652 : {
8653 2933158 : if (is_std_init_list (type))
8654 : {
8655 410 : init = perform_implicit_conversion (type, init,
8656 : tf_warning_or_error);
8657 410 : flags |= LOOKUP_ALREADY_DIGESTED;
8658 : }
8659 2932748 : else if (TYPE_NON_AGGREGATE_CLASS (type))
8660 : {
8661 : /* Don't reshape if the class has constructors. */
8662 455427 : if (cxx_dialect == cxx98)
8663 6 : error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
8664 : "in C++98 %qD must be initialized by "
8665 : "constructor, not by %<{...}%>",
8666 : decl);
8667 : }
8668 2477321 : else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
8669 : {
8670 0 : error ("opaque vector types cannot be initialized");
8671 0 : init = error_mark_node;
8672 : }
8673 : else
8674 : {
8675 2477321 : init = reshape_init (type, init, tf_warning_or_error);
8676 2477321 : flags |= LOOKUP_NO_NARROWING;
8677 : }
8678 : }
8679 : /* [dcl.init] "Otherwise, if the destination type is an array, the object
8680 : is initialized as follows..." So handle things like
8681 :
8682 : int a[](1, 2, 3);
8683 :
8684 : which is permitted in C++20 by P0960. */
8685 51660495 : else if (TREE_CODE (init) == TREE_LIST
8686 781356 : && TREE_TYPE (init) == NULL_TREE
8687 781356 : && TREE_CODE (type) == ARRAY_TYPE
8688 182 : && !DECL_DECOMPOSITION_P (decl)
8689 51660647 : && (cxx_dialect >= cxx20))
8690 142 : init = do_aggregate_paren_init (init, type);
8691 51660353 : else if (TREE_CODE (init) == TREE_LIST
8692 781214 : && TREE_TYPE (init) != unknown_type_node
8693 52441567 : && !MAYBE_CLASS_TYPE_P (type))
8694 : {
8695 133790 : gcc_assert (TREE_CODE (decl) != RESULT_DECL);
8696 :
8697 : /* We get here with code like `int a (2);' */
8698 133790 : init = build_x_compound_expr_from_list (init, ELK_INIT,
8699 : tf_warning_or_error);
8700 : }
8701 :
8702 : /* If DECL has an array type without a specific bound, deduce the
8703 : array size from the initializer. */
8704 55593159 : maybe_deduce_size_from_array_init (decl, init);
8705 55593159 : type = TREE_TYPE (decl);
8706 55593159 : if (type == error_mark_node)
8707 : return NULL_TREE;
8708 :
8709 107633325 : if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
8710 5507820 : && !(flags & LOOKUP_ALREADY_DIGESTED)
8711 8188014 : && !(init
8712 4895732 : && BRACE_ENCLOSED_INITIALIZER_P (init)
8713 5361208 : && CP_AGGREGATE_TYPE_P (type)))
8714 107904077 : || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
8715 : {
8716 3292630 : init_code = build_aggr_init_full_exprs (decl, init, flags);
8717 :
8718 : /* A constructor call is a non-trivial initializer even if
8719 : it isn't explicitly written. */
8720 3292630 : if (TREE_SIDE_EFFECTS (init_code))
8721 3268931 : DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
8722 :
8723 : /* If this is a constexpr initializer, expand_default_init will
8724 : have returned an INIT_EXPR rather than a CALL_EXPR. In that
8725 : case, pull the initializer back out and pass it down into
8726 : store_init_value. */
8727 8756051 : while (true)
8728 : {
8729 8756051 : if (TREE_CODE (init_code) == EXPR_STMT
8730 5498527 : || TREE_CODE (init_code) == STMT_EXPR
8731 5460539 : || TREE_CODE (init_code) == CONVERT_EXPR)
8732 5425596 : init_code = TREE_OPERAND (init_code, 0);
8733 3330455 : else if (TREE_CODE (init_code) == BIND_EXPR)
8734 37825 : init_code = BIND_EXPR_BODY (init_code);
8735 : else
8736 : break;
8737 : }
8738 3292630 : if (TREE_CODE (init_code) == INIT_EXPR)
8739 : {
8740 : /* In C++20, the call to build_aggr_init could have created
8741 : an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
8742 : A(1, 2). */
8743 2159733 : init = TREE_OPERAND (init_code, 1);
8744 2159733 : init_code = NULL_TREE;
8745 : /* Don't call digest_init; it's unnecessary and will complain
8746 : about aggregate initialization of non-aggregate classes. */
8747 2159733 : flags |= LOOKUP_ALREADY_DIGESTED;
8748 : }
8749 1132897 : else if (DECL_DECLARED_CONSTEXPR_P (decl)
8750 2246560 : || DECL_DECLARED_CONSTINIT_P (decl))
8751 : {
8752 : /* Declared constexpr or constinit, but no suitable initializer;
8753 : massage init appropriately so we can pass it into
8754 : store_init_value for the error. */
8755 19252 : tree new_init = NULL_TREE;
8756 19252 : if (!processing_template_decl
8757 274 : && TREE_CODE (init_code) == CALL_EXPR)
8758 232 : new_init = build_cplus_new (type, init_code, tf_none);
8759 19020 : else if (CLASS_TYPE_P (type)
8760 38040 : && (!init || TREE_CODE (init) == TREE_LIST))
8761 18841 : new_init = build_functional_cast (input_location, type,
8762 : init, tf_none);
8763 19073 : if (new_init)
8764 : {
8765 19073 : init = new_init;
8766 19073 : if (TREE_CODE (init) == TARGET_EXPR
8767 261 : && !(flags & LOOKUP_ONLYCONVERTING))
8768 261 : TARGET_EXPR_DIRECT_INIT_P (init) = true;
8769 : }
8770 : init_code = NULL_TREE;
8771 : }
8772 : else
8773 : init = NULL_TREE;
8774 : }
8775 :
8776 54479510 : if (init && TREE_CODE (init) != TREE_VEC)
8777 : {
8778 54479495 : init_code = store_init_value (decl, init, cleanups, flags);
8779 :
8780 54476798 : if (DECL_INITIAL (decl)
8781 39557939 : && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
8782 57644928 : && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
8783 : {
8784 1399286 : tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
8785 1399286 : if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
8786 1399286 : && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
8787 36 : cp_complete_array_type (&TREE_TYPE (elt), elt, false);
8788 : }
8789 :
8790 2626341 : if (pedantic && TREE_CODE (type) == ARRAY_TYPE
8791 66285 : && DECL_INITIAL (decl)
8792 65542 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8793 54537946 : && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
8794 6 : warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
8795 3 : DECL_SOURCE_LOCATION (decl)),
8796 3 : 0, "array %qD initialized by parenthesized "
8797 : "string literal %qE",
8798 3 : decl, DECL_INITIAL (decl));
8799 : init = NULL_TREE;
8800 : }
8801 : }
8802 3785114 : else if (!init && REFLECTION_TYPE_P (type))
8803 : {
8804 : /* [dcl.init.general]: To default-initialize an object of type
8805 : std::meta::info means that the object is zero-initialized. */
8806 164 : DECL_INITIAL (decl)
8807 164 : = build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
8808 164 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
8809 164 : TREE_CONSTANT (decl) = true;
8810 164 : init = NULL_TREE;
8811 : }
8812 : else
8813 : {
8814 7569900 : if (CLASS_TYPE_P (core_type = strip_array_types (type))
8815 4610539 : && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
8816 825574 : || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
8817 21 : diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
8818 : /*complain=*/true);
8819 :
8820 3784950 : check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
8821 : tf_warning_or_error);
8822 : }
8823 :
8824 167 : if (init && init != error_mark_node)
8825 0 : init_code = cp_build_init_expr (decl, init);
8826 :
8827 16189603 : if (init_code && !TREE_SIDE_EFFECTS (init_code)
8828 59435325 : && init_code != error_mark_node)
8829 : init_code = NULL_TREE;
8830 :
8831 59318104 : if (init_code)
8832 : {
8833 : /* We might have set these in cp_finish_decl. */
8834 16132135 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
8835 16132135 : TREE_CONSTANT (decl) = false;
8836 : }
8837 :
8838 16132135 : if (init_code
8839 16132135 : && DECL_IN_AGGR_P (decl)
8840 6 : && DECL_INITIALIZED_IN_CLASS_P (decl))
8841 : {
8842 0 : static int explained = 0;
8843 :
8844 0 : auto_diagnostic_group d;
8845 0 : if (cxx_dialect < cxx11)
8846 0 : error ("initializer invalid for static member with constructor");
8847 0 : else if (cxx_dialect < cxx17)
8848 0 : error ("non-constant in-class initialization invalid for static "
8849 : "member %qD", decl);
8850 : else
8851 0 : error ("non-constant in-class initialization invalid for non-inline "
8852 : "static member %qD", decl);
8853 0 : if (!explained)
8854 : {
8855 0 : inform (input_location,
8856 : "(an out of class initialization is required)");
8857 0 : explained = 1;
8858 : }
8859 0 : return NULL_TREE;
8860 0 : }
8861 :
8862 : return init_code;
8863 : }
8864 :
8865 : /* If DECL is not a local variable, give it RTL. */
8866 :
8867 : static void
8868 126300568 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
8869 : {
8870 126300568 : int toplev = toplevel_bindings_p ();
8871 126300568 : int defer_p;
8872 :
8873 : /* Set the DECL_ASSEMBLER_NAME for the object. */
8874 126300568 : if (asmspec)
8875 : {
8876 : /* The `register' keyword, when used together with an
8877 : asm-specification, indicates that the variable should be
8878 : placed in a particular register. */
8879 1045741 : if (VAR_P (decl) && DECL_REGISTER (decl))
8880 : {
8881 87 : if (TREE_ADDRESSABLE (decl))
8882 3 : error_at (DECL_SOURCE_LOCATION (decl),
8883 : "address of explicit register variable %qD requested",
8884 : decl);
8885 : else
8886 : {
8887 84 : set_user_assembler_name (decl, asmspec);
8888 84 : DECL_HARD_REGISTER (decl) = 1;
8889 : }
8890 : }
8891 : else
8892 : {
8893 1045654 : if (TREE_CODE (decl) == FUNCTION_DECL
8894 1045654 : && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
8895 83814 : set_builtin_user_assembler_name (decl, asmspec);
8896 1045654 : set_user_assembler_name (decl, asmspec);
8897 1045654 : if (DECL_LOCAL_DECL_P (decl))
8898 6 : if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
8899 : /* We have to propagate the name to the ns-alias.
8900 : This is horrible, as we're affecting a
8901 : possibly-shared decl. Again, a one-true-decl
8902 : model breaks down. */
8903 6 : if (ns_decl != error_mark_node)
8904 6 : set_user_assembler_name (ns_decl, asmspec);
8905 : }
8906 : }
8907 :
8908 : /* Handle non-variables up front. */
8909 126300568 : if (!VAR_P (decl))
8910 : {
8911 60072771 : rest_of_decl_compilation (decl, toplev, at_eof);
8912 60072771 : return;
8913 : }
8914 :
8915 : /* If we see a class member here, it should be a static data
8916 : member. */
8917 66227797 : if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
8918 : {
8919 5735640 : gcc_assert (TREE_STATIC (decl));
8920 : /* An in-class declaration of a static data member should be
8921 : external; it is only a declaration, and not a definition. */
8922 5735640 : if (init == NULL_TREE)
8923 5735615 : gcc_assert (DECL_EXTERNAL (decl)
8924 : || !TREE_PUBLIC (decl));
8925 : }
8926 :
8927 : /* We don't create any RTL for local variables. */
8928 66227797 : if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
8929 : return;
8930 :
8931 : /* Don't output reflection variables. */
8932 40836867 : if (consteval_only_p (decl))
8933 : {
8934 : /* Disable assemble_variable. */
8935 1536 : DECL_EXTERNAL (decl) = true;
8936 : /* Undo make_decl_one_only. */
8937 1536 : if (DECL_COMDAT_GROUP (decl))
8938 : {
8939 258 : symtab_node *node = symtab_node::get (decl);
8940 258 : node->set_comdat_group (NULL);
8941 258 : node->dissolve_same_comdat_group_list ();
8942 : }
8943 : return;
8944 : }
8945 :
8946 : /* We defer emission of local statics until the corresponding
8947 : DECL_EXPR is expanded. But with constexpr its function might never
8948 : be expanded, so go ahead and tell cgraph about the variable now. */
8949 81670662 : defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
8950 143291 : && !var_in_maybe_constexpr_fn (decl))
8951 81532077 : || DECL_VIRTUAL_P (decl));
8952 :
8953 : /* Defer template instantiations. */
8954 40835331 : if (DECL_LANG_SPECIFIC (decl)
8955 40835331 : && DECL_IMPLICIT_INSTANTIATION (decl))
8956 : defer_p = 1;
8957 :
8958 : /* If we're not deferring, go ahead and assemble the variable. */
8959 20893998 : if (!defer_p)
8960 18444716 : rest_of_decl_compilation (decl, toplev, at_eof);
8961 : }
8962 :
8963 : /* walk_tree helper for wrap_temporary_cleanups, below. */
8964 :
8965 : static tree
8966 11600012 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
8967 : {
8968 : /* Stop at types or full-expression boundaries. */
8969 11600012 : if (TYPE_P (*stmt_p)
8970 11599784 : || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
8971 : {
8972 488 : *walk_subtrees = 0;
8973 488 : return NULL_TREE;
8974 : }
8975 :
8976 11599524 : if (TREE_CODE (*stmt_p) == TARGET_EXPR)
8977 : {
8978 251826 : tree guard = (tree)data;
8979 251826 : tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
8980 :
8981 125935 : if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
8982 373755 : && !expr_noexcept_p (tcleanup, tf_none))
8983 : {
8984 145 : tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
8985 : /* Tell honor_protect_cleanup_actions to handle this as a separate
8986 : cleanup. */
8987 145 : TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
8988 145 : TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
8989 : }
8990 : }
8991 :
8992 : return NULL_TREE;
8993 : }
8994 :
8995 : /* We're initializing a local variable which has a cleanup GUARD. If there
8996 : are any temporaries used in the initializer INIT of this variable, we
8997 : need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
8998 : variable will be cleaned up properly if one of them throws.
8999 :
9000 : Unfortunately, there's no way to express this properly in terms of
9001 : nesting, as the regions for the temporaries overlap the region for the
9002 : variable itself; if there are two temporaries, the variable needs to be
9003 : the first thing destroyed if either of the temporary destructors throws.
9004 : However, we only want to run the variable's cleanup if it actually got
9005 : constructed. So we need to guard the temporary cleanups with the
9006 : variable's cleanup if they are run on the normal path, but not if they
9007 : are run on the exceptional path. We implement this by telling
9008 : honor_protect_cleanup_actions to strip the variable cleanup from the
9009 : exceptional path.
9010 :
9011 : Another approach could be to make the variable cleanup region enclose
9012 : initialization, but depend on a flag to indicate that the variable is
9013 : initialized; that's effectively what we do for arrays. But the current
9014 : approach works fine for non-arrays, and has no code overhead in the usual
9015 : case where the temporary destructors are noexcept. */
9016 :
9017 : static void
9018 1046074 : wrap_temporary_cleanups (tree init, tree guard)
9019 : {
9020 1046074 : if (TREE_CODE (guard) == BIND_EXPR)
9021 : {
9022 : /* An array cleanup region already encloses any temporary cleanups,
9023 : don't wrap it around them again. */
9024 422 : gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
9025 : return;
9026 : }
9027 1045652 : cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
9028 : }
9029 :
9030 : /* Generate code to initialize DECL (a local variable). */
9031 :
9032 : static void
9033 25390903 : initialize_local_var (tree decl, tree init, bool decomp)
9034 : {
9035 25390903 : tree type = TREE_TYPE (decl);
9036 25390903 : tree cleanup;
9037 25390903 : int already_used;
9038 :
9039 25390903 : gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
9040 25390903 : gcc_assert (!TREE_STATIC (decl));
9041 :
9042 25390903 : if (DECL_SIZE (decl) == NULL_TREE)
9043 : {
9044 : /* If we used it already as memory, it must stay in memory. */
9045 0 : DECL_INITIAL (decl) = NULL_TREE;
9046 0 : TREE_ADDRESSABLE (decl) = TREE_USED (decl);
9047 0 : return;
9048 : }
9049 :
9050 25390903 : if (type == error_mark_node)
9051 : return;
9052 :
9053 : /* Compute and store the initial value. */
9054 25390903 : already_used = TREE_USED (decl) || TREE_USED (type);
9055 25390903 : if (TREE_USED (type))
9056 32 : DECL_READ_P (decl) = 1;
9057 :
9058 : /* Generate a cleanup, if necessary. */
9059 25390903 : cleanup = (decomp ? NULL_TREE
9060 25355319 : : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
9061 :
9062 : /* Perform the initialization. */
9063 25390903 : if (init)
9064 : {
9065 16117533 : tree rinit = (TREE_CODE (init) == INIT_EXPR
9066 16117533 : ? TREE_OPERAND (init, 1) : NULL_TREE);
9067 14711214 : if (rinit && !TREE_SIDE_EFFECTS (rinit)
9068 22780655 : && TREE_OPERAND (init, 0) == decl)
9069 : {
9070 : /* Stick simple initializers in DECL_INITIAL so that
9071 : -Wno-init-self works (c++/34772). */
9072 8069441 : DECL_INITIAL (decl) = rinit;
9073 :
9074 8069441 : if (warn_init_self && TYPE_REF_P (type))
9075 : {
9076 2469 : STRIP_NOPS (rinit);
9077 2469 : if (rinit == decl)
9078 3 : warning_at (DECL_SOURCE_LOCATION (decl),
9079 3 : OPT_Winit_self,
9080 : "reference %qD is initialized with itself", decl);
9081 : }
9082 : }
9083 : else
9084 : {
9085 8048092 : int saved_stmts_are_full_exprs_p;
9086 :
9087 : /* If we're only initializing a single object, guard the
9088 : destructors of any temporaries used in its initializer with
9089 : its destructor. */
9090 8048092 : if (cleanup)
9091 1042638 : wrap_temporary_cleanups (init, cleanup);
9092 :
9093 8048092 : gcc_assert (building_stmt_list_p ());
9094 8048092 : saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
9095 : /* Avoid CLEANUP_POINT_EXPR for the structured binding
9096 : bases, those will have CLEANUP_POINT_EXPR at the end of
9097 : code emitted by cp_finish_decomp. */
9098 8048092 : if (decomp)
9099 35084 : current_stmt_tree ()->stmts_are_full_exprs_p = 0;
9100 : else
9101 8013008 : current_stmt_tree ()->stmts_are_full_exprs_p = 1;
9102 8048092 : finish_expr_stmt (init);
9103 8048092 : current_stmt_tree ()->stmts_are_full_exprs_p
9104 8048092 : = saved_stmts_are_full_exprs_p;
9105 : }
9106 : }
9107 :
9108 : /* Set this to 0 so we can tell whether an aggregate which was
9109 : initialized was ever used. Don't do this if it has a
9110 : destructor, so we don't complain about the 'resource
9111 : allocation is initialization' idiom. Now set
9112 : attribute((unused)) on types so decls of that type will be
9113 : marked used. (see TREE_USED, above.) */
9114 25390903 : if (TYPE_NEEDS_CONSTRUCTING (type)
9115 2270936 : && ! already_used
9116 25407 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
9117 25413437 : && DECL_NAME (decl))
9118 22486 : TREE_USED (decl) = 0;
9119 25368417 : else if (already_used)
9120 22294965 : TREE_USED (decl) = 1;
9121 :
9122 25390903 : if (cleanup)
9123 1056770 : finish_decl_cleanup (decl, cleanup);
9124 : }
9125 :
9126 : /* DECL is a VAR_DECL for a compiler-generated variable with static
9127 : storage duration (like a virtual table) whose initializer is a
9128 : compile-time constant. Initialize the variable and provide it to the
9129 : back end. */
9130 :
9131 : void
9132 2269228 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
9133 : {
9134 2269228 : tree init;
9135 2269228 : gcc_assert (DECL_ARTIFICIAL (decl));
9136 2269228 : init = build_constructor (TREE_TYPE (decl), v);
9137 2269228 : gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
9138 2269228 : DECL_INITIAL (decl) = init;
9139 2269228 : DECL_INITIALIZED_P (decl) = 1;
9140 : /* Mark the decl as constexpr so that we can access its content
9141 : at compile time. */
9142 2269228 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
9143 2269228 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
9144 2269228 : determine_visibility (decl);
9145 2269228 : layout_var_decl (decl);
9146 2269228 : maybe_commonize_var (decl);
9147 2269228 : make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
9148 2269228 : }
9149 :
9150 : /* INIT is the initializer for a variable, as represented by the
9151 : parser. Returns true iff INIT is value-dependent. */
9152 :
9153 : static bool
9154 10272708 : value_dependent_init_p (tree init)
9155 : {
9156 10272708 : if (TREE_CODE (init) == TREE_LIST)
9157 : /* A parenthesized initializer, e.g.: int i (3, 2); ? */
9158 21709 : return any_value_dependent_elements_p (init);
9159 10250999 : else if (TREE_CODE (init) == CONSTRUCTOR)
9160 : /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
9161 : {
9162 74308 : if (dependent_type_p (TREE_TYPE (init)))
9163 : return true;
9164 :
9165 74302 : vec<constructor_elt, va_gc> *elts;
9166 74302 : size_t nelts;
9167 74302 : size_t i;
9168 :
9169 74302 : elts = CONSTRUCTOR_ELTS (init);
9170 74302 : nelts = vec_safe_length (elts);
9171 654792 : for (i = 0; i < nelts; ++i)
9172 609996 : if (value_dependent_init_p ((*elts)[i].value))
9173 : return true;
9174 : }
9175 : else
9176 : /* It must be a simple expression, e.g., int i = 3; */
9177 10176691 : return value_dependent_expression_p (init);
9178 :
9179 : return false;
9180 : }
9181 :
9182 : /* A helper function to be called via walk_tree. If any label exists
9183 : under *TP, it is (going to be) forced. Set has_forced_label_in_static. */
9184 :
9185 : static tree
9186 337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
9187 : {
9188 337 : if (TYPE_P (*tp))
9189 0 : *walk_subtrees = 0;
9190 337 : if (TREE_CODE (*tp) == LABEL_DECL)
9191 6 : cfun->has_forced_label_in_static = 1;
9192 337 : return NULL_TREE;
9193 : }
9194 :
9195 : /* Return true if DECL has either a trivial destructor, or for C++20
9196 : is constexpr and has a constexpr destructor. */
9197 :
9198 : static bool
9199 64856985 : decl_maybe_constant_destruction (tree decl, tree type)
9200 : {
9201 64856985 : return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
9202 64856985 : || (cxx_dialect >= cxx20
9203 4253834 : && VAR_P (decl)
9204 4253479 : && DECL_DECLARED_CONSTEXPR_P (decl)
9205 488 : && type_has_constexpr_destructor (strip_array_types (type))));
9206 : }
9207 :
9208 : static tree declare_simd_adjust_this (tree *, int *, void *);
9209 :
9210 : /* Helper function of omp_declare_variant_finalize. Finalize one
9211 : "omp declare variant base" attribute. Return true if it should be
9212 : removed. */
9213 :
9214 : static bool
9215 1755 : omp_declare_variant_finalize_one (tree decl, tree attr)
9216 : {
9217 1755 : if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
9218 : {
9219 164 : walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
9220 : DECL_ARGUMENTS (decl), NULL);
9221 164 : walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
9222 : DECL_ARGUMENTS (decl), NULL);
9223 : }
9224 :
9225 1755 : tree ctx = TREE_VALUE (TREE_VALUE (attr));
9226 1755 : tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
9227 : OMP_TRAIT_CONSTRUCT_SIMD);
9228 1755 : if (simd)
9229 : {
9230 51 : TREE_VALUE (simd)
9231 51 : = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
9232 51 : OMP_TS_PROPERTIES (simd));
9233 : /* FIXME, adjusting simd args unimplemented. */
9234 51 : return true;
9235 : }
9236 :
9237 1704 : tree chain = TREE_CHAIN (TREE_VALUE (attr));
9238 1704 : location_t varid_loc
9239 1704 : = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
9240 1704 : location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
9241 1704 : cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
9242 1704 : tree variant = TREE_PURPOSE (TREE_VALUE (attr));
9243 :
9244 1704 : location_t save_loc = input_location;
9245 1704 : input_location = varid_loc;
9246 :
9247 1704 : releasing_vec args;
9248 1704 : tree parm = DECL_ARGUMENTS (decl);
9249 1704 : if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
9250 164 : parm = DECL_CHAIN (parm);
9251 3026 : for (; parm; parm = DECL_CHAIN (parm))
9252 1322 : vec_safe_push (args, forward_parm (parm));
9253 :
9254 1704 : unsigned nappend_args = 0;
9255 1704 : tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
9256 1704 : if (append_args_list)
9257 : {
9258 354 : append_args_list = TREE_VALUE (append_args_list);
9259 354 : append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
9260 591 : ? TREE_VALUE (TREE_CHAIN (append_args_list))
9261 : : NULL_TREE);
9262 741 : for (tree t = append_args_list; t; t = TREE_CHAIN (t))
9263 387 : nappend_args++;
9264 354 : if (nappend_args)
9265 : {
9266 237 : tree type;
9267 237 : if ((type = lookup_qualified_name (global_namespace,
9268 : "omp_interop_t",
9269 : LOOK_want::NORMAL,
9270 : /*complain*/false)) == NULL_TREE
9271 237 : || !c_omp_interop_t_p (TREE_TYPE (type)))
9272 : {
9273 24 : location_t loc = input_location;
9274 24 : variant = tree_strip_any_location_wrapper (variant);
9275 24 : if (!identifier_p (variant))
9276 : {
9277 21 : if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
9278 21 : variant = OVL_FIRST (variant);
9279 21 : loc = EXPR_LOC_OR_LOC (variant,
9280 : DECL_SOURCE_LOCATION (variant));
9281 : }
9282 24 : auto_diagnostic_group d;
9283 24 : error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
9284 24 : args->length () + 1, variant);
9285 24 : inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
9286 : "%<append_args%> specified here");
9287 24 : return true;
9288 24 : }
9289 564 : for (unsigned i = 0; i < nappend_args; i++)
9290 351 : vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
9291 : }
9292 : }
9293 :
9294 1680 : bool koenig_p = false;
9295 1680 : if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
9296 : {
9297 1610 : if (identifier_p (variant)
9298 : /* In C++20, we may need to perform ADL for a template
9299 : name. */
9300 1586 : || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
9301 18 : && identifier_p (TREE_OPERAND (variant, 0))))
9302 : {
9303 24 : if (!args->is_empty ())
9304 : {
9305 24 : koenig_p = true;
9306 24 : if (!any_type_dependent_arguments_p (args))
9307 21 : variant = perform_koenig_lookup (variant, args,
9308 : tf_warning_or_error);
9309 : }
9310 : else
9311 0 : variant = unqualified_fn_lookup_error (variant);
9312 : }
9313 1586 : else if (!args->is_empty () && is_overloaded_fn (variant))
9314 : {
9315 830 : tree fn = get_first_fn (variant);
9316 830 : fn = STRIP_TEMPLATE (fn);
9317 830 : if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
9318 830 : || DECL_FUNCTION_MEMBER_P (fn)
9319 717 : || DECL_LOCAL_DECL_P (fn)))
9320 : {
9321 717 : koenig_p = true;
9322 717 : if (!any_type_dependent_arguments_p (args))
9323 666 : variant = perform_koenig_lookup (variant, args,
9324 : tf_warning_or_error);
9325 : }
9326 : }
9327 : }
9328 :
9329 1680 : if (idk == CP_ID_KIND_QUALIFIED)
9330 6 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
9331 : koenig_p, tf_warning_or_error);
9332 1674 : else if (idk == CP_ID_KIND_NONE
9333 64 : && TREE_CODE (variant) == FUNCTION_DECL
9334 64 : && DECL_IOBJ_MEMBER_FUNCTION_P (variant)
9335 1722 : && CLASS_TYPE_P (DECL_CONTEXT (decl)))
9336 : {
9337 48 : tree saved_ccp = current_class_ptr;
9338 48 : tree saved_ccr = current_class_ref;
9339 48 : current_class_ptr = NULL_TREE;
9340 48 : current_class_ref = NULL_TREE;
9341 48 : inject_this_parameter (DECL_CONTEXT (decl), TYPE_UNQUALIFIED);
9342 48 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
9343 : koenig_p, tf_warning_or_error);
9344 48 : current_class_ptr = saved_ccp;
9345 48 : current_class_ref = saved_ccr;
9346 : }
9347 : else
9348 1626 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
9349 : koenig_p, tf_warning_or_error);
9350 1680 : if (variant == error_mark_node && !processing_template_decl)
9351 : return true;
9352 :
9353 1614 : if (TREE_CODE (variant) == TARGET_EXPR)
9354 9 : variant = TARGET_EXPR_INITIAL (variant);
9355 :
9356 3219 : variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
9357 1614 : input_location = save_loc;
9358 :
9359 1614 : if (variant == decl)
9360 : {
9361 0 : error_at (varid_loc, "variant %qD is the same as base function",
9362 : variant);
9363 0 : return true;
9364 : }
9365 :
9366 1614 : if (variant)
9367 : {
9368 1530 : bool fail;
9369 1530 : const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
9370 1530 : if (!nappend_args)
9371 1371 : fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
9372 : COMPARE_STRICT);
9373 : else
9374 : {
9375 159 : unsigned nbase_args = 0;
9376 159 : for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
9377 756 : t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
9378 240 : nbase_args++;
9379 159 : tree vargs, varg;
9380 159 : vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
9381 399 : for (unsigned i = 0; i < nbase_args && varg;
9382 240 : i++, varg = TREE_CHAIN (varg))
9383 240 : vargs = varg;
9384 417 : for (unsigned i = 0; i < nappend_args && varg; i++)
9385 258 : varg = TREE_CHAIN (varg);
9386 159 : tree saved_vargs;
9387 159 : int saved_no_named_args_stdarg = 0;
9388 159 : if (nbase_args)
9389 : {
9390 111 : saved_vargs = TREE_CHAIN (vargs);
9391 111 : TREE_CHAIN (vargs) = varg;
9392 : }
9393 : else
9394 : {
9395 48 : saved_vargs = vargs;
9396 48 : TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
9397 48 : saved_no_named_args_stdarg
9398 48 : = TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant));
9399 48 : if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl))
9400 48 : && varg == NULL_TREE)
9401 2 : TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1;
9402 : }
9403 : /* Skip assert check that TYPE_CANONICAL is the same. */
9404 159 : fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
9405 : COMPARE_STRUCTURAL);
9406 159 : if (nbase_args)
9407 111 : TREE_CHAIN (vargs) = saved_vargs;
9408 : else
9409 : {
9410 48 : TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
9411 48 : TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant))
9412 96 : = saved_no_named_args_stdarg;
9413 : }
9414 159 : varg = saved_vargs;
9415 159 : if (!fail && !processing_template_decl)
9416 402 : for (unsigned i = 0; i < nappend_args;
9417 246 : i++, varg = TREE_CHAIN (varg))
9418 507 : if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
9419 : {
9420 9 : auto_diagnostic_group d;
9421 9 : error_at (DECL_SOURCE_LOCATION (variant),
9422 : "argument %d of %qD must be of %<omp_interop_t%>",
9423 9 : nbase_args + i + 1, variant);
9424 9 : inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
9425 : "%<append_args%> specified here");
9426 9 : break;
9427 9 : }
9428 : }
9429 1530 : if (fail)
9430 : {
9431 69 : error_at (varid_loc, "variant %qD and base %qD have incompatible "
9432 : "types", variant, decl);
9433 69 : return true;
9434 : }
9435 1461 : if (fndecl_built_in_p (variant)
9436 1461 : && (startswith (varname, "__builtin_")
9437 0 : || startswith (varname, "__sync_")
9438 0 : || startswith (varname, "__atomic_")))
9439 : {
9440 6 : error_at (varid_loc, "variant %qD is a built-in", variant);
9441 6 : return true;
9442 : }
9443 : else
9444 : {
9445 1455 : tree construct
9446 1455 : = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
9447 1455 : omp_mark_declare_variant (match_loc, variant, construct);
9448 1455 : if (!omp_context_selector_matches (ctx, NULL_TREE, false))
9449 : return true;
9450 1039 : TREE_PURPOSE (TREE_VALUE (attr)) = variant;
9451 :
9452 : // Prepend adjust_args list to variant attributes
9453 1039 : tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
9454 1039 : if (adjust_args_list != NULL_TREE)
9455 : {
9456 507 : if (DECL_NONSTATIC_MEMBER_P (variant)
9457 285 : && TREE_VALUE (adjust_args_list))
9458 : {
9459 : /* Shift arg position for the added 'this' pointer. */
9460 : /* Handle need_device_ptr */
9461 21 : for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
9462 51 : t; t = TREE_CHAIN (t))
9463 30 : TREE_VALUE (t)
9464 30 : = build_int_cst (TREE_TYPE (t),
9465 30 : tree_to_uhwi (TREE_VALUE (t)) + 1);
9466 : }
9467 264 : if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
9468 : {
9469 : /* Shift likewise the number of args after which the
9470 : interop object should be added. */
9471 6 : tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
9472 6 : TREE_PURPOSE (nargs)
9473 6 : = build_int_cst (TREE_TYPE (nargs),
9474 6 : tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
9475 : }
9476 528 : for (tree t = append_args_list; t; t = TREE_CHAIN (t))
9477 264 : TREE_VALUE (t)
9478 264 : = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
9479 528 : DECL_ATTRIBUTES (variant) = tree_cons (
9480 : get_identifier ("omp declare variant variant args"),
9481 528 : TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
9482 : }
9483 : }
9484 : }
9485 84 : else if (!processing_template_decl)
9486 : {
9487 0 : error_at (varid_loc, "could not find variant declaration");
9488 0 : return true;
9489 : }
9490 :
9491 : return false;
9492 1704 : }
9493 :
9494 : /* Helper function, finish up "omp declare variant base" attribute
9495 : now that there is a DECL. ATTR is the first "omp declare variant base"
9496 : attribute. */
9497 :
9498 : void
9499 1548 : omp_declare_variant_finalize (tree decl, tree attr)
9500 : {
9501 1548 : size_t attr_len = strlen ("omp declare variant base");
9502 1548 : tree *list = &DECL_ATTRIBUTES (decl);
9503 1548 : bool remove_all = false;
9504 1548 : location_t match_loc = DECL_SOURCE_LOCATION (decl);
9505 1548 : if (TREE_CHAIN (TREE_VALUE (attr))
9506 1548 : && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
9507 3096 : && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
9508 1548 : match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
9509 3096 : if (DECL_CONSTRUCTOR_P (decl))
9510 : {
9511 27 : error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
9512 27 : remove_all = true;
9513 : }
9514 1521 : else if (DECL_DESTRUCTOR_P (decl))
9515 : {
9516 9 : error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
9517 9 : remove_all = true;
9518 : }
9519 1512 : else if (DECL_DEFAULTED_FN (decl))
9520 : {
9521 2 : error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
9522 2 : remove_all = true;
9523 : }
9524 1510 : else if (DECL_DELETED_FN (decl))
9525 : {
9526 2 : error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
9527 2 : remove_all = true;
9528 : }
9529 1508 : else if (DECL_VIRTUAL_P (decl))
9530 : {
9531 0 : error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
9532 0 : remove_all = true;
9533 : }
9534 : /* This loop is like private_lookup_attribute, except that it works
9535 : with tree * rather than tree, as we might want to remove the
9536 : attributes that are diagnosed as erroneous. */
9537 3355 : while (*list)
9538 : {
9539 1807 : tree attr = get_attribute_name (*list);
9540 1807 : size_t ident_len = IDENTIFIER_LENGTH (attr);
9541 4737 : if (cmp_attribs ("omp declare variant base", attr_len,
9542 1807 : IDENTIFIER_POINTER (attr), ident_len))
9543 : {
9544 1795 : if (remove_all || omp_declare_variant_finalize_one (decl, *list))
9545 : {
9546 672 : *list = TREE_CHAIN (*list);
9547 672 : continue;
9548 : }
9549 : }
9550 1135 : list = &TREE_CHAIN (*list);
9551 : }
9552 1548 : }
9553 :
9554 : /* [basic.stc.dynamic.deallocation]/3 - A deallocation function shall not
9555 : have a potentially throwing exception specification. */
9556 :
9557 : void
9558 212012664 : maybe_diagnose_deallocation_noexcept_false (tree decl)
9559 : {
9560 212012664 : if (cxx_dialect >= cxx29
9561 16678788 : && DECL_NAME (decl)
9562 16678788 : && IDENTIFIER_NEWDEL_OP_P (DECL_NAME (decl))
9563 212052751 : && !IDENTIFIER_NEW_OP_P (DECL_NAME (decl)))
9564 : {
9565 22006 : tree spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl));
9566 22006 : if (spec && spec == noexcept_false_spec)
9567 15 : error_at (DECL_SOURCE_LOCATION (decl),
9568 : "deallocation function %qD declared possibly throwing",
9569 : decl);
9570 : }
9571 212012664 : }
9572 :
9573 : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
9574 :
9575 : /* Finish processing of a declaration;
9576 : install its line number and initial value.
9577 : If the length of an array type is not known before,
9578 : it must be determined now, from the initial value, or it is an error.
9579 :
9580 : INIT is the initializer (if any) for DECL. If INIT_CONST_EXPR_P is
9581 : true, then INIT is an integral constant expression.
9582 :
9583 : FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
9584 : if the (init) syntax was used.
9585 :
9586 : DECOMP is first identifier's DECL and identifier count in a structured
9587 : bindings, nullptr if not a structured binding. */
9588 :
9589 : void
9590 341416149 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
9591 : tree asmspec_tree, int flags, cp_decomp *decomp)
9592 : {
9593 341416149 : vec<tree, va_gc> *cleanups = NULL;
9594 341416149 : const char *asmspec = NULL;
9595 341416149 : int was_readonly = 0;
9596 341416149 : bool var_definition_p = false;
9597 341416149 : tree auto_node;
9598 341416149 : auto_vec<tree> extra_cleanups;
9599 341416149 : tree aggregates1 = NULL_TREE;
9600 341416149 : struct decomp_cleanup {
9601 : tree decl;
9602 : cp_decomp *&decomp;
9603 341413452 : ~decomp_cleanup ()
9604 : {
9605 341413452 : if (decomp && DECL_DECOMPOSITION_P (decl))
9606 239470 : cp_finish_decomp (decl, decomp);
9607 341413452 : }
9608 341416149 : } decomp_cl = { decl, decomp };
9609 :
9610 341416149 : if (decl == error_mark_node)
9611 : return;
9612 341416109 : else if (! decl)
9613 : {
9614 0 : if (init)
9615 0 : error ("assignment (not initialization) in declaration");
9616 : return;
9617 : }
9618 :
9619 341416109 : gcc_assert (TREE_CODE (decl) != RESULT_DECL);
9620 : /* Parameters are handled by store_parm_decls, not cp_finish_decl. */
9621 341416109 : gcc_assert (TREE_CODE (decl) != PARM_DECL);
9622 :
9623 341416109 : tree type = TREE_TYPE (decl);
9624 341416109 : if (type == error_mark_node)
9625 : return;
9626 :
9627 341415466 : if (VAR_P (decl) && is_copy_initialization (init))
9628 101779282 : flags |= LOOKUP_ONLYCONVERTING;
9629 :
9630 : /* Warn about register storage specifiers except when in GNU global
9631 : or local register variable extension. */
9632 341415466 : if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
9633 : {
9634 1931 : if (cxx_dialect >= cxx17)
9635 1282 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
9636 : "ISO C++17 does not allow %<register%> storage "
9637 : "class specifier");
9638 : else
9639 649 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
9640 : "%<register%> storage class specifier used");
9641 : }
9642 :
9643 : /* If a name was specified, get the string. */
9644 341415466 : if (at_namespace_scope_p ())
9645 73766740 : asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
9646 341415466 : if (asmspec_tree && asmspec_tree != error_mark_node)
9647 1045750 : asmspec = TREE_STRING_POINTER (asmspec_tree);
9648 :
9649 341415466 : bool in_class_decl
9650 341415466 : = (current_class_type
9651 215645026 : && CP_DECL_CONTEXT (decl) == current_class_type
9652 142945174 : && TYPE_BEING_DEFINED (current_class_type)
9653 482198876 : && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
9654 :
9655 135475591 : if (in_class_decl
9656 135475591 : && (DECL_INITIAL (decl) || init))
9657 99423550 : DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
9658 :
9659 341415466 : if (VAR_P (decl)
9660 341415466 : && (auto_node = type_uses_auto (type)))
9661 : {
9662 14187684 : tree d_init;
9663 14187684 : if (init == NULL_TREE)
9664 : {
9665 4598 : if (DECL_LANG_SPECIFIC (decl)
9666 4513 : && DECL_TEMPLATE_INSTANTIATION (decl)
9667 9108 : && !DECL_TEMPLATE_INSTANTIATED (decl))
9668 : {
9669 : /* init is null because we're deferring instantiating the
9670 : initializer until we need it. Well, we need it now. */
9671 4504 : instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
9672 4504 : return;
9673 : }
9674 :
9675 94 : if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
9676 : /* Class deduction with no initializer is OK. */;
9677 : else
9678 : {
9679 : /* Ordinary auto deduction without an initializer, a situation
9680 : which grokdeclarator already detects and rejects for the most
9681 : part. But we can still get here if we're instantiating a
9682 : variable template before we've fully parsed (and attached) its
9683 : initializer, e.g. template<class> auto x = x<int>; */
9684 3 : error_at (DECL_SOURCE_LOCATION (decl),
9685 : "declaration of %q#D has no initializer", decl);
9686 3 : TREE_TYPE (decl) = error_mark_node;
9687 3 : return;
9688 : }
9689 : }
9690 14183177 : d_init = init;
9691 14183177 : if (d_init)
9692 : {
9693 14183086 : if (TREE_CODE (d_init) == TREE_LIST
9694 14257810 : && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
9695 48004 : d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
9696 : tf_warning_or_error);
9697 14183086 : d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
9698 : /* Force auto deduction now. Use tf_none to avoid redundant warnings
9699 : on deprecated-14.C. */
9700 14183086 : mark_single_function (d_init, tf_none);
9701 : }
9702 14183177 : enum auto_deduction_context adc = adc_variable_type;
9703 14183177 : if (DECL_DECOMPOSITION_P (decl))
9704 : adc = adc_decomp_type;
9705 14183177 : tree outer_targs = NULL_TREE;
9706 14183177 : if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
9707 325 : && DECL_LANG_SPECIFIC (decl)
9708 126 : && DECL_TEMPLATE_INFO (decl)
9709 14183234 : && !DECL_FUNCTION_SCOPE_P (decl))
9710 : /* The outer template arguments might be needed for satisfaction.
9711 : (For function scope variables, do_auto_deduction will obtain the
9712 : outer template arguments from current_function_decl.) */
9713 57 : outer_targs = DECL_TI_ARGS (decl);
9714 14183177 : type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
9715 : tf_warning_or_error, adc,
9716 : outer_targs, flags);
9717 14183177 : if (type == error_mark_node)
9718 : return;
9719 14182013 : if (TREE_CODE (type) == FUNCTION_TYPE)
9720 : {
9721 3 : error ("initializer for %<decltype(auto) %D%> has function type; "
9722 : "did you forget the %<()%>?", decl);
9723 3 : TREE_TYPE (decl) = error_mark_node;
9724 3 : return;
9725 : }
9726 : /* As in start_decl_1, complete so TREE_READONLY is set properly. */
9727 14182010 : if (!processing_template_decl
9728 3189024 : && !type_uses_auto (type)
9729 17371027 : && !COMPLETE_TYPE_P (complete_type (type)))
9730 : {
9731 18 : auto_diagnostic_group d;
9732 18 : error_at (location_of (decl),
9733 : "deduced type %qT for %qD is incomplete", type, decl);
9734 18 : cxx_incomplete_type_inform (type);
9735 18 : TREE_TYPE (decl) = error_mark_node;
9736 18 : return;
9737 18 : }
9738 :
9739 : /* Now that we have a type, try these again. */
9740 14181992 : layout_decl (decl, 0);
9741 14181992 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
9742 :
9743 : /* Update the type of the corresponding TEMPLATE_DECL to match. */
9744 14181992 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
9745 : {
9746 40807 : tree tmpl = template_for_substitution (decl);
9747 40807 : if (DECL_TEMPLATE_RESULT (tmpl) == decl)
9748 34295 : TREE_TYPE (tmpl) = type;
9749 : }
9750 : }
9751 :
9752 341409774 : if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
9753 : {
9754 65 : DECL_DECLARED_CONSTEXPR_P (decl) = 0;
9755 65 : if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
9756 : {
9757 6 : init = NULL_TREE;
9758 6 : DECL_EXTERNAL (decl) = 1;
9759 : }
9760 : }
9761 :
9762 341409774 : if (VAR_P (decl)
9763 128768096 : && DECL_CLASS_SCOPE_P (decl)
9764 20942767 : && verify_type_context (DECL_SOURCE_LOCATION (decl),
9765 : TCTX_STATIC_STORAGE, type)
9766 362352541 : && DECL_INITIALIZED_IN_CLASS_P (decl))
9767 19539205 : check_static_variable_definition (decl, type);
9768 :
9769 341409774 : if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
9770 : {
9771 38570208 : type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
9772 38570208 : ? TCTX_THREAD_STORAGE
9773 : : TCTX_STATIC_STORAGE);
9774 38570208 : verify_type_context (input_location, context, TREE_TYPE (decl));
9775 : }
9776 :
9777 341409774 : if (init && TREE_CODE (decl) == FUNCTION_DECL)
9778 : {
9779 598845 : tree clone;
9780 598845 : if (init == ridpointers[(int)RID_DELETE]
9781 598845 : || (TREE_CODE (init) == STRING_CST
9782 36 : && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
9783 : {
9784 : /* FIXME check this is 1st decl. */
9785 575513 : if (UNLIKELY (DECL_MAIN_P (decl)))
9786 : {
9787 : /* [basic.start.main]/3: A program that defines main as deleted
9788 : is ill-formed. */
9789 6 : error ("%<::main%> cannot be deleted");
9790 6 : DECL_INITIAL (decl) = error_mark_node;
9791 : }
9792 : else
9793 : {
9794 575507 : DECL_DELETED_FN (decl) = 1;
9795 575507 : DECL_DECLARED_INLINE_P (decl) = 1;
9796 575507 : DECL_INITIAL (decl)
9797 575507 : = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
9798 575525 : FOR_EACH_CLONE (clone, decl)
9799 : {
9800 18 : DECL_DELETED_FN (clone) = 1;
9801 18 : DECL_DECLARED_INLINE_P (clone) = 1;
9802 18 : DECL_INITIAL (clone) = DECL_INITIAL (decl);
9803 : }
9804 : }
9805 575513 : init = NULL_TREE;
9806 : }
9807 23332 : else if (init == ridpointers[(int)RID_DEFAULT])
9808 : {
9809 23320 : if (defaultable_fn_check (decl))
9810 23296 : DECL_DEFAULTED_FN (decl) = 1;
9811 : else
9812 24 : DECL_INITIAL (decl) = NULL_TREE;
9813 : }
9814 : }
9815 :
9816 341409774 : if (init && VAR_P (decl))
9817 : {
9818 111959576 : DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
9819 : /* If DECL is a reference, then we want to know whether init is a
9820 : reference constant; init_const_expr_p as passed tells us whether
9821 : it's an rvalue constant. */
9822 111959576 : if (TYPE_REF_P (type))
9823 2416792 : init_const_expr_p = potential_constant_expression (init);
9824 111959576 : if (init_const_expr_p)
9825 : {
9826 : /* Set these flags now for templates. We'll update the flags in
9827 : store_init_value for instantiations. */
9828 98612314 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
9829 98612314 : if (decl_maybe_constant_var_p (decl)
9830 : /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
9831 98612314 : && !TYPE_REF_P (type))
9832 43464138 : TREE_CONSTANT (decl) = true;
9833 : }
9834 : /* This is handled mostly by gimplify.cc, but we have to deal with
9835 : not warning about int x = x; as it is a GCC extension to turn off
9836 : this warning but only if warn_init_self is zero. */
9837 111959576 : if (!DECL_EXTERNAL (decl)
9838 110274607 : && !TREE_STATIC (decl)
9839 74507999 : && decl == tree_strip_any_location_wrapper (init)
9840 222234183 : && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
9841 3760 : suppress_warning (decl, OPT_Winit_self);
9842 : }
9843 229450198 : else if (VAR_P (decl)
9844 16808520 : && COMPLETE_TYPE_P (type)
9845 13235062 : && !TYPE_REF_P (type)
9846 13234354 : && !dependent_type_p (type)
9847 242346648 : && is_really_empty_class (type, /*ignore_vptr*/false))
9848 : /* We have no initializer but there's nothing to initialize anyway.
9849 : Treat DECL as constant due to c++/109876. */
9850 603957 : TREE_CONSTANT (decl) = true;
9851 :
9852 341409774 : if (flag_openmp
9853 855429 : && TREE_CODE (decl) == FUNCTION_DECL
9854 : /* #pragma omp declare variant on methods handled in finish_struct
9855 : instead. */
9856 341780983 : && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
9857 140846 : || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
9858 230826 : if (tree attr = lookup_attribute ("omp declare variant base",
9859 230826 : DECL_ATTRIBUTES (decl)))
9860 970 : omp_declare_variant_finalize (decl, attr);
9861 :
9862 341409774 : if (processing_template_decl)
9863 : {
9864 196404761 : bool type_dependent_p;
9865 :
9866 : /* Add this declaration to the statement-tree. */
9867 196404761 : if (at_function_scope_p ())
9868 70640188 : add_decl_expr (decl);
9869 :
9870 196404761 : type_dependent_p = dependent_type_p (type);
9871 :
9872 196404761 : if (check_for_bare_parameter_packs (init))
9873 : {
9874 3 : init = NULL_TREE;
9875 3 : DECL_INITIAL (decl) = NULL_TREE;
9876 : }
9877 :
9878 : /* Generally, initializers in templates are expanded when the
9879 : template is instantiated. But, if DECL is a variable constant
9880 : then it can be used in future constant expressions, so its value
9881 : must be available. */
9882 :
9883 196404761 : bool dep_init = false;
9884 :
9885 196404761 : if (!VAR_P (decl) || type_dependent_p)
9886 : /* We can't do anything if the decl has dependent type. */;
9887 24558841 : else if (init
9888 22805550 : && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
9889 18602298 : && !TYPE_REF_P (type)
9890 18567860 : && decl_maybe_constant_var_p (decl)
9891 34221553 : && !(dep_init = value_dependent_init_p (init)))
9892 : {
9893 : /* This variable seems to be a non-dependent constant, so process
9894 : its initializer. If check_initializer returns non-null the
9895 : initialization wasn't constant after all. */
9896 2496989 : tree init_code;
9897 2496989 : cleanups = make_tree_vector ();
9898 2496989 : init_code = check_initializer (decl, init, flags, &cleanups);
9899 2496989 : if (init_code == NULL_TREE)
9900 2496989 : init = NULL_TREE;
9901 2496989 : release_tree_vector (cleanups);
9902 : }
9903 : else
9904 : {
9905 22061852 : gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
9906 : /* Try to deduce array size. */
9907 22061852 : maybe_deduce_size_from_array_init (decl, init);
9908 : /* And complain about multiple initializers. */
9909 20308561 : if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
9910 22169287 : && !MAYBE_CLASS_TYPE_P (type))
9911 7 : init = build_x_compound_expr_from_list (init, ELK_INIT,
9912 : tf_warning_or_error);
9913 : }
9914 :
9915 196404761 : if (init)
9916 58807506 : DECL_INITIAL (decl) = init;
9917 :
9918 196404761 : if (dep_init)
9919 : {
9920 7165723 : retrofit_lang_decl (decl);
9921 7165723 : SET_DECL_DEPENDENT_INIT_P (decl, true);
9922 : }
9923 :
9924 196404761 : if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
9925 : {
9926 9 : if (TREE_ADDRESSABLE (decl))
9927 3 : error_at (DECL_SOURCE_LOCATION (decl),
9928 : "address of explicit register variable %qD requested",
9929 : decl);
9930 : else
9931 : {
9932 6 : set_user_assembler_name (decl, asmspec);
9933 6 : DECL_HARD_REGISTER (decl) = 1;
9934 : }
9935 : }
9936 : return;
9937 : }
9938 :
9939 : /* Just store non-static data member initializers for later. */
9940 145005013 : if (init && TREE_CODE (decl) == FIELD_DECL)
9941 617415 : DECL_INITIAL (decl) = init;
9942 :
9943 : /* Take care of TYPE_DECLs up front. */
9944 145005013 : if (TREE_CODE (decl) == TYPE_DECL)
9945 : {
9946 11308177 : if (type != error_mark_node
9947 11308177 : && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
9948 : {
9949 5390338 : if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
9950 0 : warning (0, "shadowing previous type declaration of %q#D", decl);
9951 5390338 : set_identifier_type_value (DECL_NAME (decl), decl);
9952 : }
9953 :
9954 : /* If we have installed this as the canonical typedef for this
9955 : type, and that type has not been defined yet, delay emitting
9956 : the debug information for it, as we will emit it later. */
9957 11308177 : if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
9958 11308177 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
9959 628240 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
9960 :
9961 11308177 : rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
9962 : at_eof);
9963 11308177 : return;
9964 : }
9965 :
9966 : /* A reference will be modified here, as it is initialized. */
9967 133696836 : if (! DECL_EXTERNAL (decl)
9968 65498139 : && TREE_READONLY (decl)
9969 172866375 : && TYPE_REF_P (type))
9970 : {
9971 255365 : was_readonly = 1;
9972 255365 : TREE_READONLY (decl) = 0;
9973 : }
9974 :
9975 : /* This needs to happen before extend_ref_init_temps. */
9976 133696836 : if (VAR_OR_FUNCTION_DECL_P (decl))
9977 : {
9978 124034061 : if (VAR_P (decl))
9979 63961290 : maybe_commonize_var (decl);
9980 124034061 : determine_visibility (decl);
9981 : }
9982 :
9983 133696836 : if (VAR_P (decl))
9984 : {
9985 63961290 : duration_kind dk = decl_storage_duration (decl);
9986 : /* [dcl.constinit]/1 "The constinit specifier shall be applied
9987 : only to a declaration of a variable with static or thread storage
9988 : duration." */
9989 63961290 : if (DECL_DECLARED_CONSTINIT_P (decl)
9990 63961290 : && !(dk == dk_thread || dk == dk_static))
9991 : {
9992 24 : error_at (DECL_SOURCE_LOCATION (decl),
9993 : "%<constinit%> can only be applied to a variable with "
9994 : "static or thread storage duration");
9995 24 : return;
9996 : }
9997 :
9998 63961266 : if (decomp)
9999 : {
10000 68712 : if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
10001 40 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
10002 : "%<constinit%> can be applied to structured binding "
10003 : "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
10004 68712 : cp_maybe_mangle_decomp (decl, decomp);
10005 68712 : if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
10006 : {
10007 628 : if (CP_DECL_THREAD_LOCAL_P (decl))
10008 37 : aggregates1 = tls_aggregates;
10009 : else
10010 591 : aggregates1 = static_aggregates;
10011 : }
10012 : }
10013 :
10014 : /* If this is a local variable that will need a mangled name,
10015 : register it now. We must do this before processing the
10016 : initializer for the variable, since the initialization might
10017 : require a guard variable, and since the mangled name of the
10018 : guard variable will depend on the mangled name of this
10019 : variable. */
10020 63961266 : if (DECL_FUNCTION_SCOPE_P (decl) && TREE_STATIC (decl))
10021 : {
10022 : /* The variable holding an anonymous union will have had its
10023 : discriminator set in finish_anon_union, after which it's
10024 : NAME will have been cleared. */
10025 143533 : if (DECL_NAME (decl))
10026 143216 : determine_local_discriminator (decl);
10027 : /* Normally has_forced_label_in_static is set during GIMPLE
10028 : lowering, but [cd]tors are never actually compiled directly.
10029 : We need to set this early so we can deal with the label
10030 : address extension. */
10031 143533 : if ((DECL_CONSTRUCTOR_P (current_function_decl)
10032 143492 : || DECL_DESTRUCTOR_P (current_function_decl))
10033 143549 : && init)
10034 : {
10035 29 : walk_tree (&init, notice_forced_label_r, NULL, NULL);
10036 29 : add_local_decl (cfun, decl);
10037 : }
10038 : /* And make sure it's in the symbol table for
10039 : c_parse_final_cleanups to find. */
10040 143533 : gcc_checking_assert (!consteval_only_p (decl));
10041 143533 : varpool_node::get_create (decl);
10042 : }
10043 :
10044 63961266 : if (flag_openmp
10045 194843 : && VAR_P (decl)
10046 194843 : && DECL_LANG_SPECIFIC (decl)
10047 115947 : && DECL_OMP_DECLARE_MAPPER_P (decl)
10048 63961279 : && init)
10049 : {
10050 12 : gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
10051 12 : DECL_INITIAL (decl) = init;
10052 : }
10053 : /* Convert the initializer to the type of DECL, if we have not
10054 : already initialized DECL. */
10055 63961254 : else if (!DECL_INITIALIZED_P (decl)
10056 : /* If !DECL_EXTERNAL then DECL is being defined. In the
10057 : case of a static data member initialized inside the
10058 : class-specifier, there can be an initializer even if DECL
10059 : is *not* defined. */
10060 63961254 : && (!DECL_EXTERNAL (decl) || init))
10061 : {
10062 56882044 : cleanups = make_tree_vector ();
10063 56882044 : init = check_initializer (decl, init, flags, &cleanups);
10064 :
10065 : /* Handle:
10066 :
10067 : [dcl.init]
10068 :
10069 : The memory occupied by any object of static storage
10070 : duration is zero-initialized at program startup before
10071 : any other initialization takes place.
10072 :
10073 : We cannot create an appropriate initializer until after
10074 : the type of DECL is finalized. If DECL_INITIAL is set,
10075 : then the DECL is statically initialized, and any
10076 : necessary zero-initialization has already been performed. */
10077 56879347 : if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
10078 527588 : DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
10079 : /*nelts=*/NULL_TREE,
10080 : /*static_storage_p=*/true);
10081 : /* Remember that the initialization for this variable has
10082 : taken place. */
10083 56879347 : DECL_INITIALIZED_P (decl) = 1;
10084 : /* This declaration is the definition of this variable,
10085 : unless we are initializing a static data member within
10086 : the class specifier. */
10087 56879347 : if (!DECL_EXTERNAL (decl))
10088 63958569 : var_definition_p = true;
10089 : }
10090 : /* If the variable has an array type, lay out the type, even if
10091 : there is no initializer. It is valid to index through the
10092 : array, and we must get TYPE_ALIGN set correctly on the array
10093 : type. */
10094 7079210 : else if (TREE_CODE (type) == ARRAY_TYPE)
10095 222389 : layout_type (type);
10096 :
10097 63958569 : if (TREE_STATIC (decl)
10098 37998344 : && !at_function_scope_p ()
10099 101813380 : && current_function_decl == NULL)
10100 : /* So decl is a global variable or a static member of a
10101 : non local class. Record the types it uses
10102 : so that we can decide later to emit debug info for them. */
10103 37854799 : record_types_used_by_current_var_decl (decl);
10104 : }
10105 :
10106 : /* Add this declaration to the statement-tree. This needs to happen
10107 : after the call to check_initializer so that the DECL_EXPR for a
10108 : reference temp is added before the DECL_EXPR for the reference itself. */
10109 133694115 : if (DECL_FUNCTION_SCOPE_P (decl))
10110 : {
10111 : /* If we're building a variable sized type, and we might be
10112 : reachable other than via the top of the current binding
10113 : level, then create a new BIND_EXPR so that we deallocate
10114 : the object at the right time. */
10115 25534463 : if (VAR_P (decl)
10116 25534463 : && DECL_SIZE (decl)
10117 25471865 : && !TREE_CONSTANT (DECL_SIZE (decl))
10118 25535494 : && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
10119 : {
10120 3 : tree bind;
10121 3 : bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
10122 3 : TREE_SIDE_EFFECTS (bind) = 1;
10123 3 : add_stmt (bind);
10124 3 : BIND_EXPR_BODY (bind) = push_stmt_list ();
10125 : }
10126 25534463 : add_decl_expr (decl);
10127 : }
10128 :
10129 133694115 : tree decomp_init = NULL_TREE;
10130 : /* Let the middle end know about variables and functions -- but not
10131 : static data members in uninstantiated class templates. */
10132 133694115 : if (VAR_OR_FUNCTION_DECL_P (decl))
10133 : {
10134 124031340 : if (VAR_P (decl))
10135 : {
10136 63958569 : layout_var_decl (decl);
10137 63958569 : if (!flag_weak)
10138 : /* Check again now that we have an initializer. */
10139 57 : maybe_commonize_var (decl);
10140 : /* A class-scope constexpr variable with an out-of-class declaration.
10141 : C++17 makes them implicitly inline, but still force it out. */
10142 86383481 : if (DECL_INLINE_VAR_P (decl)
10143 30119913 : && !DECL_VAR_DECLARED_INLINE_P (decl)
10144 13617488 : && !DECL_TEMPLATE_INSTANTIATION (decl)
10145 48393810 : && !in_class_decl)
10146 108 : mark_needed (decl);
10147 : }
10148 :
10149 124031340 : if (var_definition_p
10150 : /* With -fmerge-all-constants, gimplify_init_constructor
10151 : might add TREE_STATIC to aggregate variables. */
10152 55666043 : && (TREE_STATIC (decl)
10153 25391058 : || (flag_merge_constants >= 2
10154 38 : && AGGREGATE_TYPE_P (type))))
10155 : {
10156 : /* If a TREE_READONLY variable needs initialization
10157 : at runtime, it is no longer readonly and we need to
10158 : avoid MEM_READONLY_P being set on RTL created for it. */
10159 30274988 : if (init)
10160 : {
10161 14591 : if (TREE_READONLY (decl))
10162 346 : TREE_READONLY (decl) = 0;
10163 : was_readonly = 0;
10164 : }
10165 30260397 : else if (was_readonly)
10166 2674 : TREE_READONLY (decl) = 1;
10167 :
10168 : /* Likewise if it needs destruction. */
10169 30274988 : if (!decl_maybe_constant_destruction (decl, type))
10170 3673 : TREE_READONLY (decl) = 0;
10171 : }
10172 93756352 : else if (VAR_P (decl)
10173 33683581 : && CP_DECL_THREAD_LOCAL_P (decl)
10174 19411 : && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
10175 19411 : && (was_readonly || TREE_READONLY (decl))
10176 93756367 : && var_needs_tls_wrapper (decl))
10177 : {
10178 : /* TLS variables need dynamic initialization by the TLS wrapper
10179 : function, we don't want to hoist accesses to it before the
10180 : wrapper. */
10181 6 : was_readonly = 0;
10182 6 : TREE_READONLY (decl) = 0;
10183 : }
10184 :
10185 124031340 : make_rtl_for_nonlocal_decl (decl, init, asmspec);
10186 :
10187 : /* Check for abstractness of the type. */
10188 124031340 : if (var_definition_p)
10189 55666043 : abstract_virtuals_error (decl, type);
10190 :
10191 124031340 : if (decomp && !cp_finish_decomp (decl, decomp, true))
10192 32876 : decomp = NULL;
10193 :
10194 124031340 : if (TREE_TYPE (decl) == error_mark_node)
10195 : /* No initialization required. */
10196 : ;
10197 124031247 : else if (TREE_CODE (decl) == FUNCTION_DECL)
10198 : {
10199 60072771 : if (init)
10200 : {
10201 602 : if (init == ridpointers[(int)RID_DEFAULT])
10202 : {
10203 : /* An out-of-class default definition is defined at
10204 : the point where it is explicitly defaulted. */
10205 590 : if (DECL_DELETED_FN (decl))
10206 17 : maybe_explain_implicit_delete (decl);
10207 573 : else if (DECL_INITIAL (decl) == error_mark_node)
10208 549 : synthesize_method (decl);
10209 : }
10210 : else
10211 24 : error_at (cp_expr_loc_or_loc (init,
10212 12 : DECL_SOURCE_LOCATION (decl)),
10213 : "function %q#D is initialized like a variable",
10214 : decl);
10215 : }
10216 : /* else no initialization required. */
10217 : }
10218 63958476 : else if (DECL_EXTERNAL (decl)
10219 63958476 : && ! (DECL_LANG_SPECIFIC (decl)
10220 7986348 : && DECL_NOT_REALLY_EXTERN (decl)))
10221 : {
10222 : /* check_initializer will have done any constant initialization. */
10223 : }
10224 : /* A variable definition. */
10225 57633834 : else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
10226 : {
10227 : /* Initialize the local variable. */
10228 25390903 : if (!decomp)
10229 25355319 : initialize_local_var (decl, init, false);
10230 : else
10231 : {
10232 35584 : tree cleanup = NULL_TREE;
10233 35584 : if (DECL_SIZE (decl))
10234 35584 : cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
10235 : /* If cp_finish_decomp needs to emit any code, we need to emit that
10236 : code after code emitted by initialize_local_var in a single
10237 : CLEANUP_POINT_EXPR, so that temporaries are destructed only
10238 : after the cp_finish_decomp emitted code.
10239 : If there are any cleanups, either extend_ref_init_temps
10240 : created ones or e.g. array destruction, push those first
10241 : with the cleanups guarded on a bool temporary, initially
10242 : set to false and set to true after initialize_local_var
10243 : emitted code. */
10244 35584 : tree guard = NULL_TREE;
10245 35584 : if (cleanups || cleanup)
10246 : {
10247 : /* Since the CLEANUP_STMT will refer to the guard, we need it
10248 : to be a variable with the same lifetime. ??? It might be
10249 : better to use wrap_temporary_cleanups. */
10250 35584 : guard = get_temp_regvar (boolean_type_node, boolean_false_node);
10251 : /* And make sure register_local_var_uses sees it. */
10252 35584 : pushdecl (guard);
10253 : }
10254 :
10255 35584 : tree sl = push_stmt_list ();
10256 35584 : initialize_local_var (decl, init, true);
10257 35584 : if (guard)
10258 : {
10259 35584 : add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
10260 : guard, boolean_true_node));
10261 35602 : for (tree &t : *cleanups)
10262 18 : t = build3 (COND_EXPR, void_type_node,
10263 : guard, t, void_node);
10264 35584 : if (cleanup)
10265 32 : cleanup = build3 (COND_EXPR, void_type_node,
10266 : guard, cleanup, void_node);
10267 : }
10268 35584 : unsigned before = stmt_list_stack->length ();
10269 35584 : cp_finish_decomp (decl, decomp);
10270 35584 : decomp = NULL;
10271 35584 : unsigned n_extra_cleanups = stmt_list_stack->length () - before;
10272 35584 : sl = pop_stmt_list (sl);
10273 35584 : if (n_extra_cleanups)
10274 : {
10275 : /* If cp_finish_decomp needs any cleanups, such as for
10276 : extend_ref_init_temps created vars, pop_stmt_list
10277 : popped that all, so push those extra cleanups around
10278 : the whole sequence with a guard variable. */
10279 15 : gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
10280 15 : guard = get_temp_regvar (integer_type_node, integer_zero_node);
10281 15 : pushdecl (guard);
10282 78 : for (unsigned i = 0; i < n_extra_cleanups; ++i)
10283 : {
10284 48 : tree_stmt_iterator tsi = tsi_last (sl);
10285 48 : gcc_assert (!tsi_end_p (tsi));
10286 48 : tree last = tsi_stmt (tsi);
10287 48 : gcc_assert (TREE_CODE (last) == CLEANUP_STMT
10288 : && !CLEANUP_EH_ONLY (last));
10289 48 : tree cst = build_int_cst (integer_type_node, i + 1);
10290 96 : tree cl = build3 (COND_EXPR, void_type_node,
10291 : build2 (GE_EXPR, boolean_type_node,
10292 : guard, cst),
10293 48 : CLEANUP_EXPR (last), void_node);
10294 48 : extra_cleanups.safe_push (cl);
10295 48 : tsi_link_before (&tsi, build2 (MODIFY_EXPR,
10296 : integer_type_node,
10297 : guard, cst),
10298 : TSI_SAME_STMT);
10299 48 : tree sl2 = CLEANUP_BODY (last);
10300 48 : gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
10301 48 : tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
10302 48 : tsi_delink (&tsi);
10303 : }
10304 : }
10305 35584 : decomp_init = maybe_cleanup_point_expr_void (sl);
10306 35584 : if (cleanup)
10307 32 : finish_decl_cleanup (decl, cleanup);
10308 : }
10309 : }
10310 :
10311 : /* If a variable is defined, and then a subsequent
10312 : definition with external linkage is encountered, we will
10313 : get here twice for the same variable. We want to avoid
10314 : calling expand_static_init more than once. For variables
10315 : that are not static data members, we can call
10316 : expand_static_init only when we actually process the
10317 : initializer. It is not legal to redeclare a static data
10318 : member, so this issue does not arise in that case. */
10319 32242931 : else if (var_definition_p && TREE_STATIC (decl))
10320 : {
10321 30273449 : if (decomp && DECL_FUNCTION_SCOPE_P (decl))
10322 : {
10323 106 : tree sl = push_stmt_list ();
10324 106 : auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
10325 106 : current_stmt_tree ()->stmts_are_full_exprs_p = 0;
10326 106 : expand_static_init (decl, init);
10327 106 : current_stmt_tree ()->stmts_are_full_exprs_p
10328 106 : = saved_stmts_are_full_exprs_p;
10329 106 : cp_finish_decomp (decl, decomp);
10330 106 : decomp = NULL;
10331 106 : sl = pop_stmt_list (sl);
10332 106 : sl = maybe_cleanup_point_expr_void (sl);
10333 106 : add_stmt (sl);
10334 : }
10335 : else
10336 30273343 : expand_static_init (decl, init);
10337 : }
10338 : }
10339 :
10340 : /* If a CLEANUP_STMT was created to destroy a temporary bound to a
10341 : reference, insert it in the statement-tree now. */
10342 133694115 : if (cleanups)
10343 : {
10344 56882783 : for (tree t : *cleanups)
10345 : {
10346 3436 : push_cleanup (NULL_TREE, t, false);
10347 : /* As in initialize_local_var. */
10348 3436 : wrap_temporary_cleanups (init, t);
10349 : }
10350 56879347 : release_tree_vector (cleanups);
10351 : }
10352 :
10353 133694193 : for (tree t : &extra_cleanups)
10354 48 : push_cleanup (NULL_TREE, t, false);
10355 :
10356 133694115 : if (decomp_init)
10357 35584 : add_stmt (decomp_init);
10358 :
10359 133694115 : if (decomp
10360 146 : && var_definition_p
10361 146 : && TREE_STATIC (decl)
10362 133694261 : && !DECL_FUNCTION_SCOPE_P (decl))
10363 : {
10364 146 : tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
10365 146 : ? tls_aggregates : static_aggregates);
10366 146 : tree aggregates2 = aggregates3;
10367 146 : if (aggregates2 != aggregates1)
10368 : {
10369 66 : cp_finish_decomp (decl, decomp);
10370 66 : decomp = NULL;
10371 66 : if (aggregates3 != aggregates2)
10372 : {
10373 : /* If there are dynamic initializers for the structured
10374 : binding base or associated extended ref temps and also
10375 : dynamic initializers for the structured binding non-base
10376 : vars, mark them. */
10377 267 : for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
10378 204 : STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
10379 150 : for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
10380 87 : STATIC_INIT_DECOMP_BASE_P (t) = 1;
10381 : }
10382 : }
10383 : }
10384 :
10385 133694115 : if (was_readonly)
10386 254795 : TREE_READONLY (decl) = 1;
10387 :
10388 133694115 : if (flag_openmp
10389 443967 : && VAR_P (decl)
10390 133888958 : && lookup_attribute ("omp declare target implicit",
10391 194843 : DECL_ATTRIBUTES (decl)))
10392 : {
10393 52 : DECL_ATTRIBUTES (decl)
10394 52 : = remove_attribute ("omp declare target implicit",
10395 52 : DECL_ATTRIBUTES (decl));
10396 52 : complete_type (TREE_TYPE (decl));
10397 52 : if (!omp_mappable_type (TREE_TYPE (decl)))
10398 : {
10399 30 : auto_diagnostic_group d;
10400 30 : error ("%q+D in declare target directive does not have mappable"
10401 : " type", decl);
10402 30 : if (TREE_TYPE (decl) != error_mark_node
10403 30 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
10404 30 : cxx_incomplete_type_inform (TREE_TYPE (decl));
10405 30 : }
10406 22 : else if (!lookup_attribute ("omp declare target",
10407 22 : DECL_ATTRIBUTES (decl))
10408 44 : && !lookup_attribute ("omp declare target link",
10409 22 : DECL_ATTRIBUTES (decl)))
10410 : {
10411 22 : DECL_ATTRIBUTES (decl)
10412 22 : = tree_cons (get_identifier ("omp declare target"),
10413 22 : NULL_TREE, DECL_ATTRIBUTES (decl));
10414 22 : symtab_node *node = symtab_node::get (decl);
10415 22 : if (node != NULL)
10416 : {
10417 19 : node->offloadable = 1;
10418 19 : if (ENABLE_OFFLOADING)
10419 : {
10420 : g->have_offload = true;
10421 : if (is_a <varpool_node *> (node))
10422 : vec_safe_push (offload_vars, decl);
10423 : }
10424 : }
10425 : }
10426 : }
10427 :
10428 : /* This is the last point we can lower alignment so give the target the
10429 : chance to do so. */
10430 133694115 : if (VAR_P (decl)
10431 63958569 : && !is_global_var (decl)
10432 159085173 : && !DECL_HARD_REGISTER (decl))
10433 25391005 : targetm.lower_local_decl_alignment (decl);
10434 :
10435 133694115 : invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
10436 341413452 : }
10437 :
10438 : /* For class TYPE return itself or some its bases that contain
10439 : any direct non-static data members. Return error_mark_node if an
10440 : error has been diagnosed. */
10441 :
10442 : static tree
10443 31455 : find_decomp_class_base (location_t loc, tree type, tree ret,
10444 : tsubst_flags_t complain)
10445 : {
10446 62910 : if (LAMBDA_TYPE_P (type))
10447 : {
10448 12 : if (complain & tf_error)
10449 : {
10450 12 : auto_diagnostic_group d;
10451 12 : error_at (loc, "cannot decompose lambda closure type %qT", type);
10452 12 : inform (location_of (type), "lambda declared here");
10453 12 : }
10454 12 : return error_mark_node;
10455 : }
10456 :
10457 31443 : bool member_seen = false;
10458 399219 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
10459 672044 : if (TREE_CODE (field) != FIELD_DECL
10460 63722 : || DECL_ARTIFICIAL (field)
10461 431437 : || DECL_UNNAMED_BIT_FIELD (field))
10462 304229 : continue;
10463 63586 : else if (ret)
10464 : return type;
10465 63560 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
10466 : {
10467 8 : if ((complain & tf_error) == 0)
10468 0 : return error_mark_node;
10469 8 : auto_diagnostic_group d;
10470 8 : if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
10471 4 : error_at (loc, "cannot decompose class type %qT because it has an "
10472 : "anonymous struct member", type);
10473 : else
10474 4 : error_at (loc, "cannot decompose class type %qT because it has an "
10475 : "anonymous union member", type);
10476 8 : inform (DECL_SOURCE_LOCATION (field), "declared here");
10477 8 : return error_mark_node;
10478 8 : }
10479 63552 : else if (!accessible_p (type, field, true))
10480 : {
10481 5 : if ((complain & tf_error) == 0)
10482 0 : return error_mark_node;
10483 5 : auto_diagnostic_group d;
10484 5 : error_at (loc, "cannot decompose inaccessible member %qD of %qT",
10485 : field, type);
10486 5 : inform (DECL_SOURCE_LOCATION (field),
10487 5 : TREE_PRIVATE (field)
10488 : ? G_("declared private here")
10489 : : G_("declared protected here"));
10490 5 : return error_mark_node;
10491 5 : }
10492 : else
10493 : member_seen = true;
10494 :
10495 31404 : tree base_binfo, binfo;
10496 31404 : tree orig_ret = ret;
10497 31404 : int i;
10498 31404 : if (member_seen)
10499 31301 : ret = type;
10500 31468 : for (binfo = TYPE_BINFO (type), i = 0;
10501 31468 : BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
10502 : {
10503 84 : auto_diagnostic_group d;
10504 84 : tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret,
10505 : complain);
10506 84 : if (t == error_mark_node)
10507 : {
10508 3 : if (complain & tf_error)
10509 3 : inform (location_of (type), "in base class of %qT", type);
10510 3 : return error_mark_node;
10511 : }
10512 81 : if (t != NULL_TREE && t != ret)
10513 : {
10514 54 : if (ret == type)
10515 : {
10516 10 : if (complain & tf_error)
10517 10 : error_at (loc, "cannot decompose class type %qT: both it and "
10518 : "its base class %qT have non-static data "
10519 : "members", type, t);
10520 10 : return error_mark_node;
10521 : }
10522 44 : else if (orig_ret != NULL_TREE)
10523 : return t;
10524 44 : else if (ret != NULL_TREE)
10525 : {
10526 7 : if (complain & tf_error)
10527 7 : error_at (loc, "cannot decompose class type %qT: its base "
10528 : "classes %qT and %qT have non-static data "
10529 : "members", type, ret, t);
10530 7 : return error_mark_node;
10531 : }
10532 : else
10533 : ret = t;
10534 : }
10535 84 : }
10536 : return ret;
10537 : }
10538 :
10539 : /* Return std::tuple_size<TYPE>::value. */
10540 :
10541 : static tree
10542 113072 : get_tuple_size (tree type)
10543 : {
10544 113072 : tree args = make_tree_vec (1);
10545 113072 : TREE_VEC_ELT (args, 0) = type;
10546 113072 : tree inst = lookup_template_class (tuple_size_identifier, args,
10547 : /*in_decl*/NULL_TREE,
10548 : /*context*/std_node,
10549 : tf_none);
10550 113072 : inst = complete_type (inst);
10551 113072 : if (inst == error_mark_node
10552 111564 : || !COMPLETE_TYPE_P (inst)
10553 194728 : || !CLASS_TYPE_P (inst))
10554 : return NULL_TREE;
10555 81656 : tree val = lookup_qualified_name (inst, value_identifier,
10556 : LOOK_want::NORMAL, /*complain*/false);
10557 81656 : if (val == error_mark_node)
10558 : return NULL_TREE;
10559 81650 : if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
10560 81650 : val = maybe_constant_value (val, NULL_TREE, mce_true);
10561 81650 : if (TREE_CODE (val) == INTEGER_CST)
10562 : return val;
10563 : else
10564 6 : return error_mark_node;
10565 : }
10566 :
10567 : /* Return std::tuple_element<I,TYPE>::type. */
10568 :
10569 : static tree
10570 92199 : get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i)
10571 : {
10572 92199 : tree args = make_tree_vec (2);
10573 92199 : TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
10574 92199 : TREE_VEC_ELT (args, 1) = type;
10575 92199 : tree inst = lookup_template_class (tuple_element_identifier, args,
10576 : /*in_decl*/NULL_TREE,
10577 : /*context*/std_node,
10578 : tf_warning_or_error);
10579 92199 : return make_typename_type (inst, type_identifier,
10580 92199 : none_type, tf_warning_or_error);
10581 : }
10582 :
10583 : /* Return e.get<i>() or get<i>(e). */
10584 :
10585 : static tree
10586 92208 : get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i)
10587 : {
10588 92208 : tree targs = make_tree_vec (1);
10589 92208 : TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
10590 :
10591 92208 : tree etype = TREE_TYPE (decl);
10592 92208 : tree e = convert_from_reference (decl);
10593 :
10594 : /* [The id-expression] e is an lvalue if the type of the entity e is an
10595 : lvalue reference and an xvalue otherwise. */
10596 92208 : if (!TYPE_REF_P (etype)
10597 92208 : || TYPE_REF_IS_RVALUE (etype))
10598 90836 : e = move (e);
10599 :
10600 92208 : tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
10601 : LOOK_want::NORMAL, /*complain*/false);
10602 92208 : bool use_member_get = false;
10603 :
10604 : /* To use a member get, member lookup must find at least one
10605 : declaration that is a function template
10606 : whose first template parameter is a non-type parameter. */
10607 274138 : for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
10608 : {
10609 92208 : tree fn = *iter;
10610 92208 : if (TREE_CODE (fn) == TEMPLATE_DECL)
10611 : {
10612 2489 : tree tparms = DECL_TEMPLATE_PARMS (fn);
10613 2489 : tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
10614 2489 : if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
10615 : {
10616 : use_member_get = true;
10617 : break;
10618 : }
10619 : }
10620 : }
10621 :
10622 92208 : if (use_member_get)
10623 : {
10624 2486 : fns = lookup_template_function (fns, targs);
10625 2486 : return build_new_method_call (e, fns, /*args*/NULL,
10626 : /*path*/NULL_TREE, LOOKUP_NORMAL,
10627 2486 : /*fn_p*/NULL, tf_warning_or_error);
10628 : }
10629 : else
10630 : {
10631 89722 : releasing_vec args (make_tree_vector_single (e));
10632 89722 : fns = lookup_template_function (get__identifier, targs);
10633 89722 : fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
10634 89722 : return finish_call_expr (fns, &args, /*novirt*/false,
10635 : /*koenig*/true, tf_warning_or_error);
10636 89722 : }
10637 : }
10638 :
10639 : /* It's impossible to recover the decltype of a tuple decomposition variable
10640 : based on the actual type of the variable, so store it in a hash table. */
10641 :
10642 : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
10643 :
10644 : tree
10645 662 : lookup_decomp_type (tree v)
10646 : {
10647 662 : if (decomp_type_table)
10648 535 : if (tree *slot = decomp_type_table->get (v))
10649 471 : return *slot;
10650 : return NULL_TREE;
10651 : }
10652 :
10653 : /* Mangle a decomposition declaration if needed. Arguments like
10654 : in cp_finish_decomp. */
10655 :
10656 : static void
10657 68712 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
10658 : {
10659 68712 : if (!processing_template_decl
10660 68712 : && !error_operand_p (decl)
10661 137424 : && TREE_STATIC (decl))
10662 : {
10663 895 : auto_vec<tree, 16> v;
10664 895 : v.safe_grow (decomp->count, true);
10665 895 : tree d = decomp->decl;
10666 2962 : for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
10667 2067 : v[decomp->count - i - 1] = d;
10668 895 : if (DECL_FUNCTION_SCOPE_P (decl))
10669 : {
10670 : size_t sz = 3;
10671 929 : for (unsigned int i = 0; i < decomp->count; ++i)
10672 662 : sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
10673 267 : char *name = XALLOCAVEC (char, sz);
10674 267 : name[0] = 'D';
10675 267 : name[1] = 'C';
10676 267 : char *p = name + 2;
10677 929 : for (unsigned int i = 0; i < decomp->count; ++i)
10678 : {
10679 662 : size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
10680 662 : *p++ = ' ';
10681 662 : memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
10682 662 : p += len;
10683 : }
10684 267 : *p = '\0';
10685 267 : determine_local_discriminator (decl, get_identifier (name));
10686 : }
10687 895 : SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
10688 895 : maybe_apply_pragma_weak (decl);
10689 895 : }
10690 68712 : }
10691 :
10692 : /* Append #i to DECL_NAME (decl) or for name independent decls
10693 : clear DECL_NAME (decl). */
10694 :
10695 : static void
10696 33807 : set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i)
10697 : {
10698 33807 : if (name_independent_decl_p (decl))
10699 : /* Only "_" names are treated as name independent, "_#0" etc. is not and
10700 : because we pushdecl the individual decl elements of structured binding
10701 : pack, we could get redeclaration errors if there are 2 or more name
10702 : independent structured binding packs in the same scope. */
10703 312 : DECL_NAME (decl) = NULL_TREE;
10704 : else
10705 : {
10706 33495 : tree name = DECL_NAME (decl);
10707 33495 : size_t len = IDENTIFIER_LENGTH (name) + 22;
10708 33495 : char *n = XALLOCAVEC (char, len);
10709 33495 : snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED,
10710 33495 : IDENTIFIER_POINTER (name), i);
10711 33495 : DECL_NAME (decl) = get_identifier (n);
10712 : }
10713 33807 : }
10714 :
10715 : /* Return structured binding size of TYPE or -1 if erroneous. */
10716 :
10717 : HOST_WIDE_INT
10718 954 : cp_decomp_size (location_t loc, tree type, tsubst_flags_t complain)
10719 : {
10720 954 : if (TYPE_REF_P (type))
10721 : {
10722 0 : type = complete_type (TREE_TYPE (type));
10723 0 : if (type == error_mark_node)
10724 : return -1;
10725 0 : if (!COMPLETE_TYPE_P (type))
10726 : {
10727 0 : if (complain & tf_error)
10728 0 : error_at (loc, "structured binding refers to incomplete type %qT",
10729 : type);
10730 : return -1;
10731 : }
10732 : }
10733 :
10734 954 : unsigned HOST_WIDE_INT eltscnt = 0;
10735 954 : if (TREE_CODE (type) == ARRAY_TYPE)
10736 : {
10737 724 : if (TYPE_DOMAIN (type) == NULL_TREE)
10738 : {
10739 9 : if (complain & tf_error)
10740 6 : error_at (loc, "cannot decompose array of unknown bound %qT",
10741 : type);
10742 : return -1;
10743 : }
10744 715 : tree nelts = array_type_nelts_top (type);
10745 715 : if (nelts == error_mark_node)
10746 : return -1;
10747 715 : if (!tree_fits_shwi_p (nelts))
10748 : {
10749 3 : if (complain & tf_error)
10750 3 : error_at (loc, "cannot decompose variable length array %qT", type);
10751 : return -1;
10752 : }
10753 712 : return tree_to_shwi (nelts);
10754 : }
10755 : /* 2 GNU extensions. */
10756 230 : else if (TREE_CODE (type) == COMPLEX_TYPE)
10757 : return 2;
10758 224 : else if (TREE_CODE (type) == VECTOR_TYPE)
10759 : {
10760 12 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
10761 : {
10762 : if (complain & tf_error)
10763 : error_at (loc, "cannot decompose variable length vector %qT", type);
10764 : return -1;
10765 : }
10766 12 : return eltscnt;
10767 : }
10768 212 : else if (tree tsize = get_tuple_size (type))
10769 : {
10770 38 : if (tsize == error_mark_node
10771 32 : || !tree_fits_shwi_p (tsize)
10772 70 : || tree_int_cst_sgn (tsize) < 0)
10773 : {
10774 9 : if (complain & tf_error)
10775 9 : error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
10776 : "constant expression", type);
10777 : return -1;
10778 : }
10779 29 : return tree_to_shwi (tsize);
10780 : }
10781 174 : else if (TREE_CODE (type) == UNION_TYPE)
10782 : {
10783 3 : if (complain & tf_error)
10784 3 : error_at (loc, "cannot decompose union type %qT", type);
10785 : return -1;
10786 : }
10787 171 : else if (!CLASS_TYPE_P (type))
10788 : {
10789 21 : if (complain & tf_error)
10790 18 : error_at (loc, "cannot decompose non-array non-class type %qT", type);
10791 : return -1;
10792 : }
10793 150 : else if (processing_template_decl && complete_type (type) == error_mark_node)
10794 : return -1;
10795 150 : else if (!COMPLETE_TYPE_P (type))
10796 : {
10797 3 : if (complain & tf_error)
10798 3 : error_at (loc, "structured binding refers to incomplete class type "
10799 : "%qT", type);
10800 : return -1;
10801 : }
10802 : else
10803 : {
10804 147 : tree btype = find_decomp_class_base (loc, type, NULL_TREE, complain);
10805 147 : if (btype == error_mark_node)
10806 : return -1;
10807 126 : else if (btype == NULL_TREE)
10808 : return 0;
10809 105 : if (btype != type)
10810 : {
10811 6 : tree binfo = lookup_base (type, btype, ba_check, NULL, complain);
10812 6 : if (binfo == NULL_TREE || binfo == error_mark_node)
10813 : return -1;
10814 : }
10815 1123 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
10816 1703 : if (TREE_CODE (field) != FIELD_DECL
10817 357 : || DECL_ARTIFICIAL (field)
10818 1381 : || DECL_UNNAMED_BIT_FIELD (field))
10819 679 : continue;
10820 : else
10821 345 : eltscnt++;
10822 99 : return eltscnt;
10823 : }
10824 : }
10825 :
10826 : /* Finish a decomposition declaration. DECL is the underlying declaration
10827 : "e", FIRST is the head of a chain of decls for the individual identifiers
10828 : chained through DECL_CHAIN in reverse order and COUNT is the number of
10829 : those decls. If TEST_P is true, return true if any code would need to be
10830 : actually emitted but don't emit it. Return false otherwise. */
10831 :
10832 : bool
10833 344784 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
10834 : {
10835 344784 : tree first = decomp->decl;
10836 344784 : unsigned count = decomp->count;
10837 344784 : if (error_operand_p (decl))
10838 : {
10839 200 : error_out:
10840 625 : while (count--)
10841 : {
10842 425 : TREE_TYPE (first) = error_mark_node;
10843 425 : if (DECL_HAS_VALUE_EXPR_P (first))
10844 : {
10845 9 : SET_DECL_VALUE_EXPR (first, NULL_TREE);
10846 9 : DECL_HAS_VALUE_EXPR_P (first) = 0;
10847 : }
10848 425 : first = DECL_CHAIN (first);
10849 : }
10850 200 : if (DECL_P (decl) && TREE_STATIC (decl))
10851 54 : SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
10852 : return false;
10853 : }
10854 :
10855 344721 : location_t loc = DECL_SOURCE_LOCATION (decl);
10856 344721 : if (type_dependent_expression_p (decl)
10857 : /* This happens for range for when not in templates.
10858 : Still add the DECL_VALUE_EXPRs for later processing. */
10859 344721 : || (!processing_template_decl
10860 104829 : && type_uses_auto (TREE_TYPE (decl))))
10861 : {
10862 660746 : for (unsigned int i = 0; i < count; i++)
10863 : {
10864 440260 : if (!DECL_HAS_VALUE_EXPR_P (first))
10865 : {
10866 440260 : tree v = build_nt (ARRAY_REF, decl,
10867 440260 : size_int (count - i - 1),
10868 : NULL_TREE, NULL_TREE);
10869 440260 : SET_DECL_VALUE_EXPR (first, v);
10870 440260 : DECL_HAS_VALUE_EXPR_P (first) = 1;
10871 : }
10872 440260 : if (processing_template_decl)
10873 439624 : fit_decomposition_lang_decl (first, decl);
10874 440260 : first = DECL_CHAIN (first);
10875 : }
10876 : return false;
10877 : }
10878 :
10879 124235 : auto_vec<tree, 16> v;
10880 124235 : v.safe_grow (count, true);
10881 124235 : tree d = first;
10882 124235 : int pack = -1;
10883 487897 : for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
10884 : {
10885 239427 : v[count - i - 1] = d;
10886 239427 : fit_decomposition_lang_decl (d, decl);
10887 239427 : if (DECL_PACK_P (d))
10888 11111 : pack = count - i - 1;
10889 : }
10890 :
10891 124235 : tree type = TREE_TYPE (decl);
10892 124235 : tree dexp = decl;
10893 :
10894 124235 : if (TYPE_REF_P (type))
10895 : {
10896 2206 : dexp = convert_from_reference (dexp);
10897 2206 : type = complete_type (TREE_TYPE (type));
10898 2206 : if (type == error_mark_node)
10899 137 : goto error_out;
10900 2206 : if (!COMPLETE_TYPE_P (type))
10901 : {
10902 3 : error_at (loc, "structured binding refers to incomplete type %qT",
10903 : type);
10904 3 : goto error_out;
10905 : }
10906 : }
10907 :
10908 124232 : tree eltype = NULL_TREE;
10909 124232 : unsigned HOST_WIDE_INT eltscnt = 0;
10910 : /* Structured binding packs when initializer is non-dependent should
10911 : have their DECL_VALUE_EXPR set to a TREE_VEC. First two elements
10912 : of that TREE_VEC are the base and index, what is normally represented
10913 : as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index
10914 : of the pack first element. The remaining elements of the TREE_VEC
10915 : are VAR_DECLs for the pack elements. */
10916 124232 : tree packv = NULL_TREE;
10917 :
10918 124232 : if (TREE_CODE (type) == ARRAY_TYPE)
10919 : {
10920 11234 : tree nelts;
10921 11234 : nelts = array_type_nelts_top (type);
10922 11234 : if (nelts == error_mark_node)
10923 0 : goto error_out;
10924 11234 : if (DECL_DECOMP_BASE (decl))
10925 : {
10926 9 : error_at (loc, "array initializer for structured binding "
10927 : "declaration in condition");
10928 9 : goto error_out;
10929 : }
10930 11225 : if (!tree_fits_uhwi_p (nelts))
10931 : {
10932 3 : error_at (loc, "cannot decompose variable length array %qT", type);
10933 3 : goto error_out;
10934 : }
10935 11222 : eltscnt = tree_to_uhwi (nelts);
10936 11222 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10937 : {
10938 11 : cnt_mismatch:
10939 38 : auto_diagnostic_group d;
10940 38 : if (count > eltscnt)
10941 27 : error_n (loc, count,
10942 : "%u name provided for structured binding",
10943 : "%u names provided for structured binding", count);
10944 : else
10945 11 : error_n (loc, count,
10946 : "only %u name provided for structured binding",
10947 : "only %u names provided for structured binding", count);
10948 38 : inform_n (loc, eltscnt,
10949 : "while %qT decomposes into %wu element",
10950 : "while %qT decomposes into %wu elements",
10951 : type, eltscnt);
10952 38 : goto error_out;
10953 : }
10954 11211 : eltype = TREE_TYPE (type);
10955 24136 : for (unsigned int i = 0; i < count; i++)
10956 : {
10957 12925 : if ((unsigned) pack == i)
10958 : {
10959 10060 : packv = make_tree_vec (eltscnt - count + 3);
10960 51506 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10961 : {
10962 31386 : tree t;
10963 31386 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10964 31386 : set_sb_pack_name (t, j);
10965 31386 : maybe_push_decl (t);
10966 31386 : TREE_TYPE (t) = eltype;
10967 31386 : layout_decl (t, 0);
10968 31386 : if (!processing_template_decl)
10969 : {
10970 31288 : tree a = unshare_expr (dexp);
10971 31288 : a = build4 (ARRAY_REF, eltype, a, size_int (j + pack),
10972 : NULL_TREE, NULL_TREE);
10973 31288 : SET_DECL_VALUE_EXPR (t, a);
10974 31288 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10975 : }
10976 : }
10977 12925 : continue;
10978 10060 : }
10979 2865 : TREE_TYPE (v[i]) = eltype;
10980 2865 : layout_decl (v[i], 0);
10981 2865 : if (processing_template_decl)
10982 140 : continue;
10983 2725 : tree t = unshare_expr (dexp);
10984 2725 : unsigned HOST_WIDE_INT j = i;
10985 2725 : if (pack != -1 && (unsigned) pack < i)
10986 64 : j = i + eltscnt - count;
10987 2725 : t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
10988 2725 : SET_DECL_VALUE_EXPR (v[i], t);
10989 2725 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10990 : }
10991 : }
10992 : /* 2 GNU extensions. */
10993 112998 : else if (TREE_CODE (type) == COMPLEX_TYPE)
10994 : {
10995 78 : eltscnt = 2;
10996 78 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10997 3 : goto cnt_mismatch;
10998 75 : eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
10999 288 : for (unsigned int i = 0; i < count; i++)
11000 : {
11001 138 : if ((unsigned) pack == i)
11002 : {
11003 60 : packv = make_tree_vec (eltscnt - count + 3);
11004 192 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
11005 : {
11006 72 : tree t;
11007 72 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
11008 72 : set_sb_pack_name (t, j);
11009 72 : maybe_push_decl (t);
11010 72 : TREE_TYPE (t) = eltype;
11011 72 : layout_decl (t, 0);
11012 72 : if (!processing_template_decl)
11013 : {
11014 72 : tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype,
11015 : unshare_expr (dexp));
11016 48 : SET_DECL_VALUE_EXPR (t, a);
11017 48 : DECL_HAS_VALUE_EXPR_P (t) = 1;
11018 : }
11019 : }
11020 60 : continue;
11021 60 : }
11022 78 : TREE_TYPE (v[i]) = eltype;
11023 78 : layout_decl (v[i], 0);
11024 78 : if (processing_template_decl)
11025 16 : continue;
11026 62 : tree t = unshare_expr (dexp);
11027 62 : unsigned HOST_WIDE_INT j = i;
11028 62 : if (pack != -1 && (unsigned) pack < i)
11029 16 : j = i + eltscnt - count;
11030 93 : t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
11031 62 : SET_DECL_VALUE_EXPR (v[i], t);
11032 62 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11033 : }
11034 : }
11035 112920 : else if (TREE_CODE (type) == VECTOR_TYPE)
11036 : {
11037 60 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
11038 : {
11039 : error_at (loc, "cannot decompose variable length vector %qT", type);
11040 : goto error_out;
11041 : }
11042 60 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
11043 3 : goto cnt_mismatch;
11044 57 : eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
11045 306 : for (unsigned int i = 0; i < count; i++)
11046 : {
11047 192 : if ((unsigned) pack == i)
11048 : {
11049 48 : packv = make_tree_vec (eltscnt - count + 3);
11050 756 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
11051 : {
11052 660 : tree t;
11053 660 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
11054 660 : set_sb_pack_name (t, j);
11055 660 : maybe_push_decl (t);
11056 660 : TREE_TYPE (t) = eltype;
11057 660 : layout_decl (t, 0);
11058 660 : if (!processing_template_decl)
11059 : {
11060 440 : tree a = unshare_expr (dexp);
11061 440 : location_t loc = DECL_SOURCE_LOCATION (t);
11062 440 : tree s = size_int (j + pack);
11063 440 : convert_vector_to_array_for_subscript (loc, &a, s);
11064 440 : a = build4 (ARRAY_REF, eltype, a, s,
11065 : NULL_TREE, NULL_TREE);
11066 440 : SET_DECL_VALUE_EXPR (t, a);
11067 440 : DECL_HAS_VALUE_EXPR_P (t) = 1;
11068 : }
11069 : }
11070 84 : continue;
11071 48 : }
11072 144 : TREE_TYPE (v[i]) = eltype;
11073 144 : layout_decl (v[i], 0);
11074 144 : if (processing_template_decl)
11075 36 : continue;
11076 108 : tree t = unshare_expr (dexp);
11077 108 : unsigned HOST_WIDE_INT j = i;
11078 108 : if (pack != -1 && (unsigned) pack < i)
11079 24 : j = i + eltscnt - count;
11080 108 : convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
11081 108 : &t, size_int (j));
11082 108 : t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
11083 108 : SET_DECL_VALUE_EXPR (v[i], t);
11084 108 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11085 : }
11086 : }
11087 112860 : else if (tree tsize = get_tuple_size (type))
11088 : {
11089 81612 : if (tsize == error_mark_node)
11090 : {
11091 0 : error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
11092 : "constant expression", type);
11093 0 : goto error_out;
11094 : }
11095 81612 : if (!tree_fits_uhwi_p (tsize))
11096 : {
11097 12 : auto_diagnostic_group d;
11098 12 : error_n (loc, count,
11099 : "%u name provided for structured binding",
11100 : "%u names provided for structured binding", count);
11101 12 : inform (loc, "while %qT decomposes into %E elements",
11102 : type, tsize);
11103 12 : goto error_out;
11104 12 : }
11105 81600 : eltscnt = tree_to_uhwi (tsize);
11106 81600 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
11107 6 : goto cnt_mismatch;
11108 81594 : if (test_p && eltscnt)
11109 124098 : return true;
11110 45758 : if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt)
11111 : {
11112 : /* For structured bindings used in conditions we need to evaluate
11113 : the conversion of decl (aka e in the standard) to bool or
11114 : integral/enumeral type (the latter for switch conditions)
11115 : before the get methods, as [dcl.struct.bind]/7 requires that:
11116 : "The initialization of e and any conversion of e considered as
11117 : a decision variable is sequenced before the initialization of
11118 : any r_i." */
11119 89 : tree cond = convert_from_reference (decl);
11120 89 : if (integer_onep (DECL_DECOMP_BASE (decl)))
11121 : /* switch condition. */
11122 18 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
11123 : cond, true);
11124 : else
11125 : /* if/while/for condition. */
11126 71 : cond = contextual_conv_bool (cond, tf_warning_or_error);
11127 89 : if (cond && !error_operand_p (cond))
11128 : {
11129 89 : cond = get_temp_regvar (TREE_TYPE (cond), cond);
11130 89 : pushdecl (cond);
11131 : /* Set DECL_DECOMP_BASE to cond VAR_DECL wrapped in
11132 : NON_LVALUE_EXPR, such that it is considered to be
11133 : the condition of a structured binding rather than
11134 : structured binding's base variable. */
11135 89 : DECL_DECOMP_BASE (decl)
11136 178 : = build1 (NON_LVALUE_EXPR, TREE_TYPE (cond), cond);
11137 : }
11138 : }
11139 45758 : int save_read = DECL_READ_P (decl);
11140 137161 : for (unsigned i = 0; i < count; ++i)
11141 : {
11142 91424 : location_t sloc = input_location;
11143 91424 : location_t dloc = DECL_SOURCE_LOCATION (v[i]);
11144 :
11145 91424 : if ((unsigned) pack == i)
11146 : {
11147 401 : packv = make_tree_vec (eltscnt - count + 3);
11148 1987 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
11149 : {
11150 1185 : tree t;
11151 1185 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
11152 1185 : set_sb_pack_name (t, j);
11153 1185 : input_location = dloc;
11154 1185 : tree init = get_tuple_decomp_init (decl, j + pack);
11155 1185 : tree eltype = (init == error_mark_node ? error_mark_node
11156 1185 : : get_tuple_element_type (type, j + pack));
11157 1185 : input_location = sloc;
11158 :
11159 1185 : if (VOID_TYPE_P (eltype))
11160 : {
11161 0 : error ("%<std::tuple_element<%wu, %T>::type%> is "
11162 : "%<void%>", j + pack, type);
11163 0 : eltype = error_mark_node;
11164 : }
11165 1185 : if (init == error_mark_node || eltype == error_mark_node)
11166 : {
11167 0 : inform (dloc, "in initialization of structured binding "
11168 0 : "pack %qD", v[pack]);
11169 0 : goto error_out;
11170 : }
11171 1185 : maybe_push_decl (t);
11172 : /* Save the decltype away before reference collapse. */
11173 1185 : hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
11174 1185 : if (glvalue_p (init))
11175 1083 : eltype = cp_build_reference_type (eltype, !lvalue_p (init));
11176 1185 : TREE_TYPE (t) = eltype;
11177 1185 : layout_decl (t, 0);
11178 1185 : DECL_HAS_VALUE_EXPR_P (t) = 0;
11179 1185 : if (!processing_template_decl)
11180 : {
11181 795 : copy_linkage (t, decl);
11182 795 : tree name = DECL_NAME (t);
11183 795 : if (TREE_STATIC (decl))
11184 52 : DECL_NAME (t) = DECL_NAME (v[pack]);
11185 795 : cp_finish_decl (t, init, /*constexpr*/false,
11186 : /*asm*/NULL_TREE, LOOKUP_NORMAL);
11187 795 : if (TREE_STATIC (decl))
11188 : {
11189 52 : DECL_ASSEMBLER_NAME (t);
11190 52 : DECL_NAME (t) = name;
11191 : }
11192 : }
11193 : }
11194 401 : continue;
11195 401 : }
11196 :
11197 91023 : unsigned HOST_WIDE_INT j = i;
11198 91023 : if (pack != -1 && (unsigned) pack < i)
11199 235 : j = i + eltscnt - count;
11200 91023 : input_location = dloc;
11201 91023 : tree init = get_tuple_decomp_init (decl, j);
11202 91023 : tree eltype = (init == error_mark_node ? error_mark_node
11203 91014 : : get_tuple_element_type (type, j));
11204 91023 : input_location = sloc;
11205 :
11206 91023 : if (VOID_TYPE_P (eltype))
11207 : {
11208 3 : error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>",
11209 : j, type);
11210 3 : eltype = error_mark_node;
11211 : }
11212 91023 : if (init == error_mark_node || eltype == error_mark_node)
11213 : {
11214 21 : inform (dloc, "in initialization of structured binding "
11215 21 : "variable %qD", v[i]);
11216 21 : goto error_out;
11217 : }
11218 : /* Save the decltype away before reference collapse. */
11219 91002 : hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
11220 91002 : if (glvalue_p (init))
11221 90651 : eltype = cp_build_reference_type (eltype, !lvalue_p (init));
11222 91002 : TREE_TYPE (v[i]) = eltype;
11223 91002 : layout_decl (v[i], 0);
11224 91002 : if (DECL_HAS_VALUE_EXPR_P (v[i]))
11225 : {
11226 : /* In this case the names are variables, not just proxies. */
11227 220 : SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
11228 220 : DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
11229 : }
11230 91002 : if (!processing_template_decl)
11231 : {
11232 71252 : copy_linkage (v[i], decl);
11233 71252 : cp_finish_decl (v[i], init, /*constexpr*/false,
11234 : /*asm*/NULL_TREE, LOOKUP_NORMAL);
11235 : }
11236 : }
11237 : /* Ignore reads from the underlying decl performed during initialization
11238 : of the individual variables. If those will be read, we'll mark
11239 : the underlying decl as read at that point. */
11240 45737 : DECL_READ_P (decl) = save_read;
11241 : }
11242 31248 : else if (TREE_CODE (type) == UNION_TYPE)
11243 : {
11244 3 : error_at (loc, "cannot decompose union type %qT", type);
11245 3 : goto error_out;
11246 : }
11247 31245 : else if (!CLASS_TYPE_P (type))
11248 : {
11249 19 : error_at (loc, "cannot decompose non-array non-class type %qT", type);
11250 19 : goto error_out;
11251 : }
11252 31226 : else if (processing_template_decl && complete_type (type) == error_mark_node)
11253 0 : goto error_out;
11254 31226 : else if (processing_template_decl && !COMPLETE_TYPE_P (type))
11255 2 : pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
11256 : type);
11257 : else
11258 : {
11259 31224 : tree btype = find_decomp_class_base (loc, type, NULL_TREE,
11260 : tf_warning_or_error);
11261 31224 : if (btype == error_mark_node)
11262 21 : goto error_out;
11263 31203 : else if (btype == NULL_TREE)
11264 : {
11265 24 : if (pack == 0 && count == 1)
11266 : {
11267 16 : eltscnt = 0;
11268 16 : packv = make_tree_vec (2);
11269 16 : goto done;
11270 : }
11271 8 : error_at (loc, "cannot decompose class type %qT without non-static "
11272 : "data members", type);
11273 8 : goto error_out;
11274 : }
11275 396413 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
11276 667304 : if (TREE_CODE (field) != FIELD_DECL
11277 63180 : || DECL_ARTIFICIAL (field)
11278 428410 : || DECL_UNNAMED_BIT_FIELD (field))
11279 302070 : continue;
11280 : else
11281 63164 : eltscnt++;
11282 31179 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
11283 15 : goto cnt_mismatch;
11284 31164 : tree t = dexp;
11285 31164 : if (type != btype)
11286 : {
11287 18 : t = convert_to_base (t, btype, /*check_access*/true,
11288 : /*nonnull*/false, tf_warning_or_error);
11289 18 : type = btype;
11290 : }
11291 31164 : unsigned HOST_WIDE_INT j = 0;
11292 31164 : unsigned int i = 0;
11293 396202 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
11294 666949 : if (TREE_CODE (field) != FIELD_DECL
11295 63143 : || DECL_ARTIFICIAL (field)
11296 428177 : || DECL_UNNAMED_BIT_FIELD (field))
11297 301911 : continue;
11298 : else
11299 : {
11300 63127 : tree tt = finish_non_static_data_member (field, unshare_expr (t),
11301 : NULL_TREE);
11302 63127 : if (REFERENCE_REF_P (tt))
11303 30 : tt = TREE_OPERAND (tt, 0);
11304 63127 : if (pack != -1 && j >= (unsigned) pack)
11305 : {
11306 685 : if (j == (unsigned) pack)
11307 : {
11308 227 : packv = make_tree_vec (eltscnt - count + 3);
11309 227 : i++;
11310 : }
11311 685 : if (j < (unsigned) pack + eltscnt - (count - 1))
11312 : {
11313 504 : tree t;
11314 504 : TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]);
11315 504 : set_sb_pack_name (t, j + 1 - i);
11316 504 : maybe_push_decl (t);
11317 504 : TREE_TYPE (t) = TREE_TYPE (tt);
11318 504 : layout_decl (t, 0);
11319 504 : if (!processing_template_decl)
11320 : {
11321 383 : SET_DECL_VALUE_EXPR (t, tt);
11322 383 : DECL_HAS_VALUE_EXPR_P (t) = 1;
11323 : }
11324 : else
11325 121 : DECL_HAS_VALUE_EXPR_P (t) = 0;
11326 504 : j++;
11327 504 : continue;
11328 504 : }
11329 : }
11330 62623 : TREE_TYPE (v[i]) = TREE_TYPE (tt);
11331 62623 : layout_decl (v[i], 0);
11332 62623 : if (!processing_template_decl)
11333 : {
11334 43423 : SET_DECL_VALUE_EXPR (v[i], tt);
11335 43423 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11336 : }
11337 62623 : i++;
11338 62623 : j++;
11339 : }
11340 31164 : if (pack != -1 && j == (unsigned) pack)
11341 : {
11342 20 : gcc_checking_assert (eltscnt == count - 1);
11343 20 : packv = make_tree_vec (2);
11344 : }
11345 : }
11346 88262 : done:
11347 88262 : if (packv)
11348 : {
11349 10832 : gcc_checking_assert (pack != -1);
11350 10832 : TREE_VEC_ELT (packv, 0) = decl;
11351 10832 : TREE_VEC_ELT (packv, 1) = size_int (pack);
11352 10832 : SET_DECL_VALUE_EXPR (v[pack], packv);
11353 10832 : DECL_HAS_VALUE_EXPR_P (v[pack]) = 1;
11354 10832 : DECL_IGNORED_P (v[pack]) = 1;
11355 10832 : if (!processing_template_decl)
11356 43481 : for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i)
11357 32954 : pushdecl (TREE_VEC_ELT (packv, 2 + i));
11358 : }
11359 88262 : if (processing_template_decl)
11360 : {
11361 59099 : for (unsigned int i = 0; i < count; i++)
11362 39449 : if (!DECL_HAS_VALUE_EXPR_P (v[i]))
11363 : {
11364 38997 : tree a = build_nt (ARRAY_REF, decl, size_int (i),
11365 : NULL_TREE, NULL_TREE);
11366 38997 : SET_DECL_VALUE_EXPR (v[i], a);
11367 38997 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11368 : }
11369 : }
11370 68612 : else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
11371 : {
11372 480 : tree attr = NULL_TREE, *pa = &attr;
11373 1550 : for (unsigned int i = 0; i < count; i++)
11374 1070 : if ((unsigned) pack != i
11375 1070 : && DECL_HAS_VALUE_EXPR_P (v[i])
11376 1796 : && !DECL_IGNORED_P (v[i]))
11377 : {
11378 726 : (*debug_hooks->early_global_decl) (v[i]);
11379 726 : *pa = build_tree_list (NULL_TREE, v[i]);
11380 726 : pa = &TREE_CHAIN (*pa);
11381 : }
11382 480 : if (attr)
11383 364 : DECL_ATTRIBUTES (decl)
11384 728 : = tree_cons (get_identifier ("structured bindings"),
11385 364 : attr, DECL_ATTRIBUTES (decl));
11386 : }
11387 : return false;
11388 : }
11389 :
11390 : /* Returns a declaration for a VAR_DECL as if:
11391 :
11392 : extern "C" TYPE NAME;
11393 :
11394 : had been seen. Used to create compiler-generated global
11395 : variables. */
11396 :
11397 : static tree
11398 2323 : declare_global_var (tree name, tree type)
11399 : {
11400 2323 : auto cookie = push_abi_namespace (global_namespace);
11401 2323 : tree decl = build_decl (input_location, VAR_DECL, name, type);
11402 2323 : TREE_PUBLIC (decl) = 1;
11403 2323 : DECL_EXTERNAL (decl) = 1;
11404 2323 : DECL_ARTIFICIAL (decl) = 1;
11405 2323 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
11406 : /* If the user has explicitly declared this variable (perhaps
11407 : because the code we are compiling is part of a low-level runtime
11408 : library), then it is possible that our declaration will be merged
11409 : with theirs by pushdecl. */
11410 2323 : decl = pushdecl (decl);
11411 2323 : cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
11412 2323 : pop_abi_namespace (cookie, global_namespace);
11413 :
11414 2323 : return decl;
11415 : }
11416 :
11417 : /* Returns the type for the argument to "atexit" corresponding to the function
11418 : to be called when the program exits. */
11419 :
11420 : static tree
11421 24 : get_atexit_fn_ptr_type ()
11422 : {
11423 24 : if (!atexit_fn_ptr_type_node)
11424 : {
11425 12 : tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
11426 12 : atexit_fn_ptr_type_node = build_pointer_type (fn_type);
11427 : }
11428 :
11429 24 : return atexit_fn_ptr_type_node;
11430 : }
11431 :
11432 : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
11433 : or "__cxa_throw" corresponding to the destructor to be called when the
11434 : program exits. */
11435 :
11436 : tree
11437 19778 : get_cxa_atexit_fn_ptr_type ()
11438 : {
11439 19778 : if (!cleanup_type)
11440 : {
11441 14894 : tree fntype = build_function_type_list (void_type_node,
11442 : ptr_type_node, NULL_TREE);
11443 14894 : fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
11444 14894 : cleanup_type = build_pointer_type (fntype);
11445 : }
11446 :
11447 19778 : return cleanup_type;
11448 : }
11449 :
11450 : /* Returns a pointer to the `atexit' function. Note that if
11451 : FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
11452 : `__cxa_atexit' function specified in the IA64 C++ ABI. */
11453 :
11454 : static tree
11455 3607 : get_atexit_node (void)
11456 : {
11457 3607 : tree atexit_fndecl;
11458 3607 : tree fn_type;
11459 3607 : tree fn_ptr_type;
11460 3607 : const char *name;
11461 3607 : bool use_aeabi_atexit;
11462 3607 : tree ctx = global_namespace;
11463 :
11464 3607 : if (atexit_node)
11465 : return atexit_node;
11466 :
11467 2286 : if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
11468 : {
11469 : /* The declaration for `__cxa_atexit' is:
11470 :
11471 : int __cxa_atexit (void (*)(void *), void *, void *)
11472 :
11473 : We build up the argument types and then the function type
11474 : itself. */
11475 2274 : tree argtype0, argtype1, argtype2;
11476 :
11477 2274 : use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
11478 : /* First, build the pointer-to-function type for the first
11479 : argument. */
11480 2274 : fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
11481 : /* Then, build the rest of the argument types. */
11482 2274 : argtype2 = ptr_type_node;
11483 2274 : if (use_aeabi_atexit)
11484 : {
11485 : argtype1 = fn_ptr_type;
11486 : argtype0 = ptr_type_node;
11487 : }
11488 : else
11489 : {
11490 2274 : argtype1 = ptr_type_node;
11491 2274 : argtype0 = fn_ptr_type;
11492 : }
11493 : /* And the final __cxa_atexit type. */
11494 2274 : fn_type = build_function_type_list (integer_type_node,
11495 : argtype0, argtype1, argtype2,
11496 : NULL_TREE);
11497 : /* ... which needs noexcept. */
11498 2274 : fn_type = build_exception_variant (fn_type, noexcept_true_spec);
11499 2274 : if (use_aeabi_atexit)
11500 : {
11501 0 : name = "__aeabi_atexit";
11502 0 : push_to_top_level ();
11503 0 : int n = push_namespace (get_identifier ("__aeabiv1"), false);
11504 0 : ctx = current_namespace;
11505 0 : while (n--)
11506 0 : pop_namespace ();
11507 0 : pop_from_top_level ();
11508 : }
11509 : else
11510 : {
11511 2274 : name = "__cxa_atexit";
11512 2274 : ctx = abi_node;
11513 : }
11514 : }
11515 : else
11516 : {
11517 : /* The declaration for `atexit' is:
11518 :
11519 : int atexit (void (*)());
11520 :
11521 : We build up the argument types and then the function type
11522 : itself. */
11523 12 : fn_ptr_type = get_atexit_fn_ptr_type ();
11524 : /* Build the final atexit type. */
11525 12 : fn_type = build_function_type_list (integer_type_node,
11526 : fn_ptr_type, NULL_TREE);
11527 : /* ... which needs noexcept. */
11528 12 : fn_type = build_exception_variant (fn_type, noexcept_true_spec);
11529 12 : name = "atexit";
11530 : }
11531 :
11532 : /* Now, build the function declaration. */
11533 2286 : push_lang_context (lang_name_c);
11534 2286 : auto cookie = push_abi_namespace (ctx);
11535 2286 : atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
11536 2286 : DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
11537 : /* Install as hidden builtin so we're (a) more relaxed about
11538 : exception spec matching and (b) will not give a confusing location
11539 : in diagnostic and (c) won't magically appear in user-visible name
11540 : lookups. */
11541 2286 : DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
11542 2286 : atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
11543 2286 : pop_abi_namespace (cookie, ctx);
11544 2286 : mark_used (atexit_fndecl);
11545 2286 : pop_lang_context ();
11546 2286 : atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
11547 :
11548 2286 : return atexit_node;
11549 : }
11550 :
11551 : /* Like get_atexit_node, but for thread-local cleanups. */
11552 :
11553 : static tree
11554 98 : get_thread_atexit_node (void)
11555 : {
11556 98 : if (thread_atexit_node)
11557 : return thread_atexit_node;
11558 :
11559 : /* The declaration for `__cxa_thread_atexit' is:
11560 :
11561 : int __cxa_thread_atexit (void (*)(void *), void *, void *) */
11562 59 : tree fn_type = build_function_type_list (integer_type_node,
11563 : get_cxa_atexit_fn_ptr_type (),
11564 : ptr_type_node, ptr_type_node,
11565 : NULL_TREE);
11566 :
11567 : /* Now, build the function declaration, as with __cxa_atexit. */
11568 59 : unsigned flags = push_abi_namespace ();
11569 59 : tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
11570 : ECF_LEAF | ECF_NOTHROW);
11571 59 : DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
11572 59 : DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
11573 59 : atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
11574 59 : pop_abi_namespace (flags);
11575 59 : mark_used (atexit_fndecl);
11576 59 : thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
11577 :
11578 59 : return thread_atexit_node;
11579 : }
11580 :
11581 : /* Returns the __dso_handle VAR_DECL. */
11582 :
11583 : static tree
11584 3693 : get_dso_handle_node (void)
11585 : {
11586 3693 : if (dso_handle_node)
11587 : return dso_handle_node;
11588 :
11589 : /* Declare the variable. */
11590 2323 : dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
11591 : ptr_type_node);
11592 :
11593 : #ifdef HAVE_GAS_HIDDEN
11594 2323 : if (dso_handle_node != error_mark_node)
11595 : {
11596 2320 : DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
11597 2320 : DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
11598 : }
11599 : #endif
11600 :
11601 2323 : return dso_handle_node;
11602 : }
11603 :
11604 : /* Begin a new function with internal linkage whose job will be simply
11605 : to destroy some particular DECL. OB_PARM is true if object pointer
11606 : is passed to the cleanup function, otherwise no argument is passed. */
11607 :
11608 : static tree
11609 383 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
11610 : {
11611 383 : push_to_top_level ();
11612 :
11613 : /* No need to mangle this. */
11614 383 : push_lang_context (lang_name_c);
11615 :
11616 : /* Build the name of the function. */
11617 383 : gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
11618 383 : const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
11619 383 : dname = targetm.strip_name_encoding (dname);
11620 763 : char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
11621 :
11622 383 : tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
11623 : : get_atexit_fn_ptr_type ());
11624 : /* Build the function declaration. */
11625 383 : tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
11626 383 : DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
11627 : /* It's a function with internal linkage, generated by the
11628 : compiler. */
11629 383 : TREE_PUBLIC (fndecl) = 0;
11630 383 : DECL_ARTIFICIAL (fndecl) = 1;
11631 : /* Make the function `inline' so that it is only emitted if it is
11632 : actually needed. It is unlikely that it will be inlined, since
11633 : it is only called via a function pointer, but we avoid unnecessary
11634 : emissions this way. */
11635 383 : DECL_DECLARED_INLINE_P (fndecl) = 1;
11636 383 : DECL_INTERFACE_KNOWN (fndecl) = 1;
11637 383 : if (ob_parm)
11638 : {
11639 : /* Build the parameter. */
11640 371 : tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
11641 371 : TREE_USED (parmdecl) = 1;
11642 371 : DECL_READ_P (parmdecl) = 1;
11643 371 : DECL_ARGUMENTS (fndecl) = parmdecl;
11644 : }
11645 :
11646 383 : fndecl = pushdecl (fndecl, /*hidden=*/true);
11647 383 : if (omp_target)
11648 : {
11649 3 : DECL_ATTRIBUTES (fndecl)
11650 3 : = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
11651 3 : DECL_ATTRIBUTES (fndecl));
11652 3 : DECL_ATTRIBUTES (fndecl)
11653 6 : = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
11654 3 : DECL_ATTRIBUTES (fndecl));
11655 : }
11656 383 : start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
11657 :
11658 383 : pop_lang_context ();
11659 :
11660 383 : return current_function_decl;
11661 : }
11662 :
11663 : /* Finish the cleanup function begun by start_cleanup_fn. */
11664 :
11665 : static void
11666 383 : end_cleanup_fn (void)
11667 : {
11668 383 : expand_or_defer_fn (finish_function (/*inline_p=*/false));
11669 :
11670 383 : pop_from_top_level ();
11671 383 : }
11672 :
11673 : /* Generate code to handle the destruction of DECL, an object with
11674 : static storage duration. */
11675 :
11676 : tree
11677 15640 : register_dtor_fn (tree decl, bool omp_target)
11678 : {
11679 15640 : tree cleanup;
11680 15640 : tree addr;
11681 15640 : tree compound_stmt;
11682 15640 : tree fcall;
11683 15640 : tree type;
11684 15640 : bool ob_parm, dso_parm, use_dtor;
11685 15640 : tree arg0, arg1, arg2;
11686 15640 : tree atex_node;
11687 :
11688 15640 : type = TREE_TYPE (decl);
11689 15640 : if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
11690 11935 : return void_node;
11691 :
11692 3705 : if (decl_maybe_constant_destruction (decl, type)
11693 3705 : && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
11694 : {
11695 0 : cxx_maybe_build_cleanup (decl, tf_warning_or_error);
11696 0 : return void_node;
11697 : }
11698 :
11699 : /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
11700 : "__aeabi_atexit"), and DECL is a class object, we can just pass the
11701 : destructor to "__cxa_atexit"; we don't have to build a temporary
11702 : function to do the cleanup. */
11703 7410 : dso_parm = (flag_use_cxa_atexit
11704 3705 : && !targetm.cxx.use_atexit_for_cxa_atexit ());
11705 3705 : ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
11706 3693 : use_dtor = ob_parm && CLASS_TYPE_P (type);
11707 3705 : if (use_dtor)
11708 : {
11709 3322 : cleanup = get_class_binding (type, complete_dtor_identifier);
11710 :
11711 : /* Make sure it is accessible. */
11712 3322 : perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
11713 : tf_warning_or_error);
11714 : }
11715 : else
11716 : {
11717 : /* Call build_cleanup before we enter the anonymous function so
11718 : that any access checks will be done relative to the current
11719 : scope, rather than the scope of the anonymous function. */
11720 383 : build_cleanup (decl);
11721 :
11722 : /* Now start the function. */
11723 383 : cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
11724 :
11725 : /* Now, recompute the cleanup. It may contain SAVE_EXPRs that refer
11726 : to the original function, rather than the anonymous one. That
11727 : will make the back end think that nested functions are in use,
11728 : which causes confusion. */
11729 383 : push_deferring_access_checks (dk_no_check);
11730 383 : fcall = build_cleanup (decl);
11731 383 : pop_deferring_access_checks ();
11732 :
11733 : /* Create the body of the anonymous function. */
11734 383 : compound_stmt = begin_compound_stmt (BCS_FN_BODY);
11735 383 : finish_expr_stmt (fcall);
11736 383 : finish_compound_stmt (compound_stmt);
11737 383 : end_cleanup_fn ();
11738 : }
11739 :
11740 : /* Call atexit with the cleanup function. */
11741 3705 : mark_used (cleanup);
11742 3705 : cleanup = build_address (cleanup);
11743 :
11744 3705 : if (CP_DECL_THREAD_LOCAL_P (decl))
11745 98 : atex_node = get_thread_atexit_node ();
11746 : else
11747 3607 : atex_node = get_atexit_node ();
11748 :
11749 3705 : if (use_dtor)
11750 : {
11751 : /* We must convert CLEANUP to the type that "__cxa_atexit"
11752 : expects. */
11753 3322 : cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
11754 : /* "__cxa_atexit" will pass the address of DECL to the
11755 : cleanup function. */
11756 3322 : mark_used (decl);
11757 3322 : addr = build_address (decl);
11758 : /* The declared type of the parameter to "__cxa_atexit" is
11759 : "void *". For plain "T*", we could just let the
11760 : machinery in cp_build_function_call convert it -- but if the
11761 : type is "cv-qualified T *", then we need to convert it
11762 : before passing it in, to avoid spurious errors. */
11763 3322 : addr = build_nop (ptr_type_node, addr);
11764 : }
11765 : else
11766 : /* Since the cleanup functions we build ignore the address
11767 : they're given, there's no reason to pass the actual address
11768 : in, and, in general, it's cheaper to pass NULL than any
11769 : other value. */
11770 383 : addr = null_pointer_node;
11771 :
11772 3705 : if (dso_parm)
11773 3693 : arg2 = cp_build_addr_expr (get_dso_handle_node (),
11774 : tf_warning_or_error);
11775 12 : else if (ob_parm)
11776 : /* Just pass NULL to the dso handle parm if we don't actually
11777 : have a DSO handle on this target. */
11778 0 : arg2 = null_pointer_node;
11779 : else
11780 : arg2 = NULL_TREE;
11781 :
11782 3693 : if (ob_parm)
11783 : {
11784 3693 : if (!CP_DECL_THREAD_LOCAL_P (decl)
11785 3693 : && targetm.cxx.use_aeabi_atexit ())
11786 : {
11787 : arg1 = cleanup;
11788 : arg0 = addr;
11789 : }
11790 : else
11791 : {
11792 : arg1 = addr;
11793 : arg0 = cleanup;
11794 : }
11795 : }
11796 : else
11797 : {
11798 : arg0 = cleanup;
11799 : arg1 = NULL_TREE;
11800 : }
11801 3705 : return cp_build_function_call_nary (atex_node, tf_warning_or_error,
11802 3705 : arg0, arg1, arg2, NULL_TREE);
11803 : }
11804 :
11805 : /* DECL is a VAR_DECL with static storage duration. INIT, if present,
11806 : is its initializer. Generate code to handle the construction
11807 : and destruction of DECL. */
11808 :
11809 : static void
11810 30273449 : expand_static_init (tree decl, tree init)
11811 : {
11812 30273449 : gcc_assert (VAR_P (decl));
11813 30273449 : gcc_assert (TREE_STATIC (decl));
11814 :
11815 : /* Some variables require no dynamic initialization. */
11816 30273449 : if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
11817 : {
11818 : /* Make sure the destructor is callable. */
11819 30269779 : cxx_maybe_build_cleanup (decl, tf_warning_or_error);
11820 30269779 : if (!init)
11821 : return;
11822 : }
11823 :
11824 16504 : if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
11825 15578 : && !DECL_FUNCTION_SCOPE_P (decl))
11826 : {
11827 15 : auto_diagnostic_group d;
11828 15 : location_t dloc = DECL_SOURCE_LOCATION (decl);
11829 15 : if (init)
11830 12 : error_at (dloc, "non-local variable %qD declared %<__thread%> "
11831 : "needs dynamic initialization", decl);
11832 : else
11833 3 : error_at (dloc, "non-local variable %qD declared %<__thread%> "
11834 : "has a non-trivial destructor", decl);
11835 15 : static bool informed;
11836 15 : if (!informed)
11837 : {
11838 6 : inform (dloc, "C++11 %<thread_local%> allows dynamic "
11839 : "initialization and destruction");
11840 6 : informed = true;
11841 : }
11842 15 : return;
11843 15 : }
11844 :
11845 15534 : if (DECL_FUNCTION_SCOPE_P (decl))
11846 : {
11847 : /* Emit code to perform this initialization but once. */
11848 4026 : tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
11849 4026 : tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
11850 4026 : tree guard, guard_addr;
11851 4026 : tree flag, begin;
11852 : /* We don't need thread-safety code for thread-local vars. */
11853 4026 : bool thread_guard = (flag_threadsafe_statics
11854 4026 : && !CP_DECL_THREAD_LOCAL_P (decl));
11855 :
11856 : /* Emit code to perform this initialization but once. This code
11857 : looks like:
11858 :
11859 : static <type> guard;
11860 : if (!__atomic_load (guard.first_byte)) {
11861 : if (__cxa_guard_acquire (&guard)) {
11862 : bool flag = false;
11863 : try {
11864 : // Do initialization.
11865 : flag = true; __cxa_guard_release (&guard);
11866 : // Register variable for destruction at end of program.
11867 : } catch {
11868 : if (!flag) __cxa_guard_abort (&guard);
11869 : }
11870 : }
11871 : }
11872 :
11873 : Note that the `flag' variable is only set to 1 *after* the
11874 : initialization is complete. This ensures that an exception,
11875 : thrown during the construction, will cause the variable to
11876 : reinitialized when we pass through this code again, as per:
11877 :
11878 : [stmt.dcl]
11879 :
11880 : If the initialization exits by throwing an exception, the
11881 : initialization is not complete, so it will be tried again
11882 : the next time control enters the declaration.
11883 :
11884 : This process should be thread-safe, too; multiple threads
11885 : should not be able to initialize the variable more than
11886 : once. */
11887 :
11888 : /* Create the guard variable. */
11889 4026 : guard = get_guard (decl);
11890 :
11891 : /* Begin the conditional initialization. */
11892 4026 : if_stmt = begin_if_stmt ();
11893 :
11894 4026 : finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
11895 4026 : then_clause = begin_compound_stmt (BCS_NO_SCOPE);
11896 :
11897 4026 : if (thread_guard)
11898 : {
11899 3878 : tree vfntype = NULL_TREE;
11900 3878 : tree acquire_name, release_name, abort_name;
11901 3878 : tree acquire_fn, release_fn, abort_fn;
11902 3878 : guard_addr = build_address (guard);
11903 :
11904 3878 : acquire_name = get_identifier ("__cxa_guard_acquire");
11905 3878 : release_name = get_identifier ("__cxa_guard_release");
11906 3878 : abort_name = get_identifier ("__cxa_guard_abort");
11907 3878 : acquire_fn = get_global_binding (acquire_name);
11908 3878 : release_fn = get_global_binding (release_name);
11909 3878 : abort_fn = get_global_binding (abort_name);
11910 3878 : if (!acquire_fn)
11911 2243 : acquire_fn = push_library_fn
11912 2243 : (acquire_name, build_function_type_list (integer_type_node,
11913 2243 : TREE_TYPE (guard_addr),
11914 : NULL_TREE),
11915 : NULL_TREE, ECF_NOTHROW);
11916 3878 : if (!release_fn || !abort_fn)
11917 2246 : vfntype = build_function_type_list (void_type_node,
11918 2246 : TREE_TYPE (guard_addr),
11919 : NULL_TREE);
11920 2246 : if (!release_fn)
11921 2246 : release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
11922 : ECF_NOTHROW);
11923 3878 : if (!abort_fn)
11924 2246 : abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
11925 : ECF_NOTHROW | ECF_LEAF);
11926 :
11927 3878 : inner_if_stmt = begin_if_stmt ();
11928 3878 : finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
11929 : inner_if_stmt);
11930 :
11931 3878 : inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
11932 3878 : begin = get_internal_target_expr (boolean_false_node);
11933 3878 : flag = TARGET_EXPR_SLOT (begin);
11934 :
11935 3878 : TARGET_EXPR_CLEANUP (begin)
11936 3878 : = build3 (COND_EXPR, void_type_node, flag,
11937 : void_node,
11938 : build_call_n (abort_fn, 1, guard_addr));
11939 3878 : CLEANUP_EH_ONLY (begin) = 1;
11940 :
11941 : /* Do the initialization itself. */
11942 3878 : init = add_stmt_to_compound (begin, init);
11943 3878 : init = add_stmt_to_compound (init,
11944 : build2 (MODIFY_EXPR, void_type_node,
11945 : flag, boolean_true_node));
11946 :
11947 : /* Use atexit to register a function for destroying this static
11948 : variable. Do this before calling __cxa_guard_release. */
11949 3878 : init = add_stmt_to_compound (init, register_dtor_fn (decl));
11950 :
11951 3878 : init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
11952 : guard_addr));
11953 : }
11954 : else
11955 : {
11956 148 : init = add_stmt_to_compound (init, set_guard (guard));
11957 :
11958 : /* Use atexit to register a function for destroying this static
11959 : variable. */
11960 148 : init = add_stmt_to_compound (init, register_dtor_fn (decl));
11961 : }
11962 :
11963 4026 : finish_expr_stmt (init);
11964 :
11965 4026 : if (thread_guard)
11966 : {
11967 3878 : finish_compound_stmt (inner_then_clause);
11968 3878 : finish_then_clause (inner_if_stmt);
11969 3878 : finish_if_stmt (inner_if_stmt);
11970 : }
11971 :
11972 4026 : finish_compound_stmt (then_clause);
11973 4026 : finish_then_clause (if_stmt);
11974 4026 : finish_if_stmt (if_stmt);
11975 : }
11976 11508 : else if (CP_DECL_THREAD_LOCAL_P (decl))
11977 795 : tls_aggregates = tree_cons (init, decl, tls_aggregates);
11978 : else
11979 10713 : static_aggregates = tree_cons (init, decl, static_aggregates);
11980 : }
11981 :
11982 :
11983 : /* Make TYPE a complete type based on INITIAL_VALUE.
11984 : Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
11985 : 2 if there was no information (in which case assume 0 if DO_DEFAULT),
11986 : 3 if the initializer list is empty (in pedantic mode). */
11987 :
11988 : int
11989 631560 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
11990 : {
11991 631560 : int failure;
11992 631560 : tree type, elt_type;
11993 :
11994 : /* Don't get confused by a CONSTRUCTOR for some other type. */
11995 631530 : if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
11996 150776 : && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
11997 631892 : && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
11998 : return 1;
11999 :
12000 631557 : if (initial_value)
12001 : {
12002 : /* An array of character type can be initialized from a
12003 : brace-enclosed string constant so call reshape_init to
12004 : remove the optional braces from a braced string literal. */
12005 631527 : if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
12006 631527 : && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
12007 51846 : initial_value = reshape_init (*ptype, initial_value,
12008 : tf_warning_or_error);
12009 :
12010 : /* If any of the elements are parameter packs, we can't actually
12011 : complete this type now because the array size is dependent. */
12012 631527 : if (TREE_CODE (initial_value) == CONSTRUCTOR)
12013 49693863 : for (auto &e: CONSTRUCTOR_ELTS (initial_value))
12014 49241931 : if (PACK_EXPANSION_P (e.value))
12015 : return 0;
12016 : }
12017 :
12018 631557 : failure = complete_array_type (ptype, initial_value, do_default);
12019 :
12020 : /* We can create the array before the element type is complete, which
12021 : means that we didn't have these two bits set in the original type
12022 : either. In completing the type, we are expected to propagate these
12023 : bits. See also complete_type which does the same thing for arrays
12024 : of fixed size. */
12025 631557 : type = *ptype;
12026 1263111 : if (type != error_mark_node && TYPE_DOMAIN (type))
12027 : {
12028 631530 : elt_type = TREE_TYPE (type);
12029 631530 : TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
12030 1263060 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
12031 631530 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
12032 : }
12033 :
12034 : return failure;
12035 : }
12036 :
12037 : /* As above, but either give an error or reject zero-size arrays, depending
12038 : on COMPLAIN. */
12039 :
12040 : int
12041 1253 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
12042 : bool do_default, tsubst_flags_t complain)
12043 : {
12044 1253 : int failure;
12045 1253 : bool sfinae = !(complain & tf_error);
12046 : /* In SFINAE context we can't be lenient about zero-size arrays. */
12047 1253 : if (sfinae)
12048 3 : ++pedantic;
12049 1253 : failure = cp_complete_array_type (ptype, initial_value, do_default);
12050 1253 : if (sfinae)
12051 3 : --pedantic;
12052 1253 : if (failure)
12053 : {
12054 3 : if (sfinae)
12055 : /* Not an error. */;
12056 0 : else if (failure == 1)
12057 0 : error ("initializer fails to determine size of %qT", *ptype);
12058 0 : else if (failure == 2)
12059 : {
12060 0 : if (do_default)
12061 0 : error ("array size missing in %qT", *ptype);
12062 : }
12063 0 : else if (failure == 3)
12064 0 : error ("zero-size array %qT", *ptype);
12065 3 : *ptype = error_mark_node;
12066 : }
12067 1253 : return failure;
12068 : }
12069 :
12070 : /* Return zero if something is declared to be a member of type
12071 : CTYPE when in the context of CUR_TYPE. STRING is the error
12072 : message to print in that case. Otherwise, quietly return 1. */
12073 :
12074 : static int
12075 27692087 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
12076 : {
12077 27692087 : if (ctype && ctype != cur_type)
12078 : {
12079 0 : if (flags == DTOR_FLAG)
12080 0 : error ("destructor for alien class %qT cannot be a member", ctype);
12081 : else
12082 0 : error ("constructor for alien class %qT cannot be a member", ctype);
12083 : return 0;
12084 : }
12085 : return 1;
12086 : }
12087 :
12088 : /* Subroutine of `grokdeclarator'. */
12089 :
12090 : /* Generate errors possibly applicable for a given set of specifiers.
12091 : This is for ARM $7.1.2. */
12092 :
12093 : static void
12094 465108701 : bad_specifiers (tree object,
12095 : enum bad_spec_place type,
12096 : int virtualp,
12097 : int quals,
12098 : int inlinep,
12099 : int friendp,
12100 : int raises,
12101 : const location_t* locations)
12102 : {
12103 465108701 : switch (type)
12104 : {
12105 71949458 : case BSP_VAR:
12106 71949458 : if (virtualp)
12107 0 : error_at (locations[ds_virtual],
12108 : "%qD declared as a %<virtual%> variable", object);
12109 71949458 : if (quals)
12110 3 : error ("%<const%> and %<volatile%> function specifiers on "
12111 : "%qD invalid in variable declaration", object);
12112 : break;
12113 308877850 : case BSP_PARM:
12114 308877850 : if (virtualp)
12115 0 : error_at (locations[ds_virtual],
12116 : "%qD declared as a %<virtual%> parameter", object);
12117 308877850 : if (inlinep)
12118 6 : error_at (locations[ds_inline],
12119 : "%qD declared as an %<inline%> parameter", object);
12120 308877850 : if (quals)
12121 3 : error ("%<const%> and %<volatile%> function specifiers on "
12122 : "%qD invalid in parameter declaration", object);
12123 : break;
12124 49626703 : case BSP_TYPE:
12125 49626703 : if (virtualp)
12126 0 : error_at (locations[ds_virtual],
12127 : "%qD declared as a %<virtual%> type", object);
12128 49626703 : if (inlinep)
12129 6 : error_at (locations[ds_inline],
12130 : "%qD declared as an %<inline%> type", object);
12131 49626703 : if (quals)
12132 0 : error ("%<const%> and %<volatile%> function specifiers on "
12133 : "%qD invalid in type declaration", object);
12134 : break;
12135 34654690 : case BSP_FIELD:
12136 34654690 : if (virtualp)
12137 6 : error_at (locations[ds_virtual],
12138 : "%qD declared as a %<virtual%> field", object);
12139 34654690 : if (inlinep)
12140 6 : error_at (locations[ds_inline],
12141 : "%qD declared as an %<inline%> field", object);
12142 34654690 : if (quals)
12143 0 : error ("%<const%> and %<volatile%> function specifiers on "
12144 : "%qD invalid in field declaration", object);
12145 : break;
12146 0 : default:
12147 0 : gcc_unreachable();
12148 : }
12149 465108701 : if (friendp)
12150 0 : error ("%q+D declared as a friend", object);
12151 465108701 : if (raises
12152 131 : && !flag_noexcept_type
12153 465108726 : && (TREE_CODE (object) == TYPE_DECL
12154 19 : || (!TYPE_PTRFN_P (TREE_TYPE (object))
12155 5 : && !TYPE_REFFN_P (TREE_TYPE (object))
12156 4 : && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
12157 6 : error ("%q+D declared with an exception specification", object);
12158 465108701 : }
12159 :
12160 : /* DECL is a member function or static data member and is presently
12161 : being defined. Check that the definition is taking place in a
12162 : valid namespace. */
12163 :
12164 : static void
12165 102359667 : check_class_member_definition_namespace (tree decl)
12166 : {
12167 : /* These checks only apply to member functions and static data
12168 : members. */
12169 102359667 : gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
12170 : /* We check for problems with specializations in pt.cc in
12171 : check_specialization_namespace, where we can issue better
12172 : diagnostics. */
12173 102359667 : if (processing_specialization)
12174 : return;
12175 : /* We check this in check_explicit_instantiation_namespace. */
12176 102214133 : if (processing_explicit_instantiation)
12177 : return;
12178 : /* [class.mfct]
12179 :
12180 : A member function definition that appears outside of the
12181 : class definition shall appear in a namespace scope enclosing
12182 : the class definition.
12183 :
12184 : [class.static.data]
12185 :
12186 : The definition for a static data member shall appear in a
12187 : namespace scope enclosing the member's class definition. */
12188 102214053 : if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
12189 18 : permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
12190 18 : decl, DECL_CONTEXT (decl));
12191 : }
12192 :
12193 : /* Build a PARM_DECL for the "this" parameter of FN. TYPE is the
12194 : METHOD_TYPE for a non-static member function; QUALS are the
12195 : cv-qualifiers that apply to the function. */
12196 :
12197 : tree
12198 247799151 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
12199 : {
12200 247799151 : tree this_type;
12201 247799151 : tree qual_type;
12202 247799151 : tree parm;
12203 247799151 : cp_cv_quals this_quals;
12204 :
12205 247799151 : if (CLASS_TYPE_P (type))
12206 : {
12207 108180826 : this_type
12208 108180826 : = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
12209 108180826 : this_type = build_pointer_type (this_type);
12210 : }
12211 : else
12212 139618325 : this_type = type_of_this_parm (type);
12213 : /* The `this' parameter is implicitly `const'; it cannot be
12214 : assigned to. */
12215 247799151 : this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
12216 247799151 : qual_type = cp_build_qualified_type (this_type, this_quals);
12217 247799151 : parm = build_artificial_parm (fn, this_identifier, qual_type);
12218 247799151 : cp_apply_type_quals_to_decl (this_quals, parm);
12219 247799151 : return parm;
12220 : }
12221 :
12222 : /* DECL is a static member function. Complain if it was declared
12223 : with function-cv-quals. */
12224 :
12225 : static void
12226 11169204 : check_static_quals (tree decl, cp_cv_quals quals)
12227 : {
12228 0 : if (quals != TYPE_UNQUALIFIED)
12229 6 : error ("static member function %q#D declared with type qualifiers",
12230 : decl);
12231 0 : }
12232 :
12233 : /* Helper function. Replace the temporary this parameter injected
12234 : during cp_finish_omp_declare_simd with the real this parameter. */
12235 :
12236 : static tree
12237 2692 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
12238 : {
12239 2692 : tree this_parm = (tree) data;
12240 2692 : if (TREE_CODE (*tp) == PARM_DECL
12241 450 : && DECL_NAME (*tp) == this_identifier
12242 2965 : && *tp != this_parm)
12243 273 : *tp = this_parm;
12244 2419 : else if (TYPE_P (*tp))
12245 33 : *walk_subtrees = 0;
12246 2692 : return NULL_TREE;
12247 : }
12248 :
12249 : /* CTYPE is class type, or null if non-class.
12250 : TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
12251 : or METHOD_TYPE.
12252 : DECLARATOR is the function's name.
12253 : PARMS is a chain of PARM_DECLs for the function.
12254 : VIRTUALP is truthvalue of whether the function is virtual or not.
12255 : FLAGS are to be passed through to `grokclassfn'.
12256 : QUALS are qualifiers indicating whether the function is `const'
12257 : or `volatile'.
12258 : RAISES is a list of exceptions that this function can raise.
12259 : CHECK is 1 if we must find this method in CTYPE, 0 if we should
12260 : not look, and -1 if we should not call `grokclassfn' at all.
12261 :
12262 : SFK is the kind of special function (if any) for the new function.
12263 :
12264 : Returns `NULL_TREE' if something goes wrong, after issuing
12265 : applicable error messages. */
12266 :
12267 : static tree
12268 197530715 : grokfndecl (tree ctype,
12269 : tree type,
12270 : tree declarator,
12271 : tree parms,
12272 : tree orig_declarator,
12273 : const cp_decl_specifier_seq *declspecs,
12274 : tree decl_reqs,
12275 : int virtualp,
12276 : enum overload_flags flags,
12277 : cp_cv_quals quals,
12278 : cp_ref_qualifier rqual,
12279 : tree raises,
12280 : int check,
12281 : int friendp,
12282 : int publicp,
12283 : int inlinep,
12284 : int initialized,
12285 : bool xobj_func_p,
12286 : special_function_kind sfk,
12287 : bool funcdef_flag,
12288 : bool late_return_type_p,
12289 : int template_count,
12290 : tree in_namespace,
12291 : tree* attrlist,
12292 : tree contract_specifiers,
12293 : location_t location)
12294 : {
12295 197530715 : tree decl;
12296 197530715 : tree t;
12297 :
12298 197530715 : if (location == UNKNOWN_LOCATION)
12299 0 : location = input_location;
12300 :
12301 : /* Was the concept specifier present? */
12302 197530715 : bool concept_p = inlinep & 4;
12303 :
12304 197530715 : if (concept_p)
12305 : {
12306 15 : error_at (location, "function concepts are no longer supported");
12307 15 : return NULL_TREE;
12308 : }
12309 :
12310 : /* [except.spec]/9 - A deallocation function with no explicit noexcept-specifier
12311 : has a non-throwing exception specification. */
12312 197530700 : if (raises == NULL_TREE
12313 118226711 : && cxx_dialect >= cxx11
12314 142736291 : && IDENTIFIER_NEWDEL_OP_P (declarator)
12315 197596697 : && !IDENTIFIER_NEW_OP_P (declarator))
12316 919 : raises = noexcept_true_spec;
12317 :
12318 197530700 : type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
12319 :
12320 197530700 : decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
12321 :
12322 : /* Set the constraints on the declaration. */
12323 197530700 : if (flag_concepts)
12324 : {
12325 193150796 : tree tmpl_reqs = NULL_TREE;
12326 193150796 : tree ctx = friendp ? current_class_type : ctype;
12327 193150796 : bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
12328 193150796 : bool memtmpl = (!block_local
12329 193150796 : && (current_template_depth
12330 193091615 : > template_class_depth (ctx)));
12331 53371963 : if (memtmpl)
12332 : {
12333 53371963 : if (!current_template_parms)
12334 : /* If there are no template parameters, something must have
12335 : gone wrong. */
12336 0 : gcc_assert (seen_error ());
12337 : else
12338 53371963 : tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
12339 : }
12340 193150796 : tree ci = build_constraints (tmpl_reqs, decl_reqs);
12341 : /* C++20 CA378: Remove non-templated constrained functions. */
12342 : /* [temp.friend]/9 A non-template friend declaration with a
12343 : requires-clause shall be a definition. A friend function template with
12344 : a constraint that depends on a template parameter from an enclosing
12345 : template shall be a definition. */
12346 193150796 : if (ci
12347 10390565 : && (block_local
12348 10390562 : || !processing_template_decl
12349 10390501 : || (friendp && !memtmpl && !funcdef_flag)))
12350 : {
12351 73 : if (!friendp || !processing_template_decl)
12352 64 : error_at (location, "constraints on a non-templated function");
12353 : else
12354 9 : error_at (location, "constrained non-template friend declaration"
12355 : " must be a definition");
12356 : ci = NULL_TREE;
12357 : }
12358 193150796 : set_constraints (decl, ci);
12359 1297728 : if (ci && friendp && memtmpl && !funcdef_flag
12360 193188618 : && uses_outer_template_parms_in_constraints (decl, ctx))
12361 6 : error_at (location, "friend function template with constraints that "
12362 : "depend on outer template parameters must be a definition");
12363 : }
12364 :
12365 197530700 : if (TREE_CODE (type) == METHOD_TYPE)
12366 : {
12367 106637072 : tree parm = build_this_parm (decl, type, quals);
12368 106637072 : DECL_CHAIN (parm) = parms;
12369 106637072 : parms = parm;
12370 :
12371 : /* Allocate space to hold the vptr bit if needed. */
12372 106637072 : SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
12373 : }
12374 :
12375 197530700 : DECL_ARGUMENTS (decl) = parms;
12376 596536608 : for (t = parms; t; t = DECL_CHAIN (t))
12377 : {
12378 399005908 : DECL_CONTEXT (t) = decl;
12379 399005908 : if (flag_reflection
12380 7971708 : && initialized == SD_INITIALIZED
12381 400608558 : && DECL_ATTRIBUTES (t))
12382 3634 : for (tree a = DECL_ATTRIBUTES (t);
12383 3638 : (a = lookup_annotation (a));
12384 4 : a = TREE_CHAIN (a))
12385 : {
12386 4 : gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
12387 : /* Mark TREE_PURPOSE of the value that it is an annotation
12388 : on an argument of a function definition (rather than
12389 : annotation from function declaration). For function parameter
12390 : reflection all annotations are listed, while for variable_of
12391 : only those marked here. Annotation is marked as coming from
12392 : function definition's argument if it has TREE_PURPOSE
12393 : void_node or INTEGER_CST with signed type. */
12394 4 : tree val = TREE_VALUE (a);
12395 4 : gcc_assert (TREE_PURPOSE (val) == NULL_TREE);
12396 4 : TREE_PURPOSE (val) = void_node;
12397 : }
12398 : }
12399 :
12400 : /* Propagate volatile out from type to decl. */
12401 197530700 : if (TYPE_VOLATILE (type))
12402 0 : TREE_THIS_VOLATILE (decl) = 1;
12403 :
12404 : /* Setup decl according to sfk. */
12405 197530700 : switch (sfk)
12406 : {
12407 25298100 : case sfk_constructor:
12408 25298100 : case sfk_copy_constructor:
12409 25298100 : case sfk_move_constructor:
12410 25298100 : DECL_CXX_CONSTRUCTOR_P (decl) = 1;
12411 25298100 : DECL_NAME (decl) = ctor_identifier;
12412 25298100 : break;
12413 3387976 : case sfk_destructor:
12414 3387976 : DECL_CXX_DESTRUCTOR_P (decl) = 1;
12415 3387976 : DECL_NAME (decl) = dtor_identifier;
12416 3387976 : break;
12417 1272805 : case sfk_deduction_guide:
12418 : /* Give deduction guides a definition even though they don't really
12419 : have one: the restriction that you can't repeat a deduction guide
12420 : makes them more like a definition anyway. */
12421 1272805 : DECL_INITIAL (decl) = void_node;
12422 : /* But to ensure that external-linkage deduction guides in header units
12423 : don't fall afoul of [module.import] p6, mark them as inline. */
12424 1272805 : DECL_DECLARED_INLINE_P (decl) = true;
12425 1272805 : break;
12426 : default:
12427 : break;
12428 : }
12429 :
12430 197530700 : if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
12431 : {
12432 113260 : if (funcdef_flag)
12433 3 : error_at (location,
12434 : "defining explicit specialization %qD in friend declaration",
12435 : orig_declarator);
12436 : else
12437 : {
12438 113257 : tree fns = TREE_OPERAND (orig_declarator, 0);
12439 113257 : tree args = TREE_OPERAND (orig_declarator, 1);
12440 :
12441 113257 : if (PROCESSING_REAL_TEMPLATE_DECL_P ())
12442 : {
12443 : /* Something like `template <class T> friend void f<T>()'. */
12444 6 : error_at (location,
12445 : "invalid use of template-id %qD in declaration "
12446 : "of primary template",
12447 : orig_declarator);
12448 6 : return NULL_TREE;
12449 : }
12450 :
12451 : /* A friend declaration of the form friend void f<>(). Record
12452 : the information in the TEMPLATE_ID_EXPR. */
12453 113251 : SET_DECL_IMPLICIT_INSTANTIATION (decl);
12454 :
12455 113251 : gcc_assert (identifier_p (fns) || OVL_P (fns));
12456 113251 : DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
12457 :
12458 : /* Remember the befriending class like push_template_decl does for
12459 : template friends. */
12460 113251 : gcc_checking_assert (!DECL_CHAIN (decl));
12461 113251 : DECL_CHAIN (decl) = current_scope ();
12462 :
12463 375523 : for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
12464 262277 : if (TREE_PURPOSE (t)
12465 262277 : && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
12466 : {
12467 5 : error_at (defparse_location (TREE_PURPOSE (t)),
12468 : "default arguments are not allowed in declaration "
12469 : "of friend template specialization %qD",
12470 : decl);
12471 5 : return NULL_TREE;
12472 : }
12473 :
12474 113246 : if (inlinep & 1)
12475 : {
12476 5 : error_at (declspecs->locations[ds_inline],
12477 : "%<inline%> is not allowed in declaration of friend "
12478 : "template specialization %qD",
12479 : decl);
12480 5 : return NULL_TREE;
12481 : }
12482 : }
12483 : }
12484 :
12485 : /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
12486 : expression, that declaration shall be a definition..." */
12487 197530684 : if (friendp && !funcdef_flag)
12488 : {
12489 1922133 : bool has_errored = false;
12490 1922133 : for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
12491 5389617 : t && t != void_list_node; t = TREE_CHAIN (t))
12492 3467484 : if (TREE_PURPOSE (t))
12493 : {
12494 51 : enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
12495 : /* For templates, mark the default argument as erroneous and give a
12496 : hard error. */
12497 51 : if (processing_template_decl)
12498 : {
12499 33 : diag_kind = diagnostics::kind::error;
12500 33 : TREE_PURPOSE (t) = error_mark_node;
12501 : }
12502 51 : if (!has_errored)
12503 : {
12504 48 : has_errored = true;
12505 48 : emit_diagnostic (diag_kind,
12506 48 : DECL_SOURCE_LOCATION (decl),
12507 48 : /*diagnostics::option_id=*/0,
12508 : "friend declaration of %qD specifies default "
12509 : "arguments and isn%'t a definition", decl);
12510 : }
12511 : }
12512 : }
12513 :
12514 : /* If this decl has namespace scope, set that up. */
12515 197530684 : if (in_namespace)
12516 265099 : set_decl_namespace (decl, in_namespace, friendp);
12517 197265585 : else if (ctype)
12518 117716832 : DECL_CONTEXT (decl) = ctype;
12519 : else
12520 79548753 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
12521 :
12522 : /* `main' and builtins have implicit 'C' linkage. */
12523 197530684 : if (ctype == NULL_TREE
12524 79813852 : && DECL_FILE_SCOPE_P (decl)
12525 32873636 : && current_lang_name == lang_name_cplusplus
12526 200592343 : && (MAIN_NAME_P (declarator)
12527 3027448 : || (IDENTIFIER_LENGTH (declarator) > 10
12528 2172964 : && IDENTIFIER_POINTER (declarator)[0] == '_'
12529 1678123 : && IDENTIFIER_POINTER (declarator)[1] == '_'
12530 360774 : && startswith (IDENTIFIER_POINTER (declarator) + 2,
12531 : "builtin_"))
12532 3027430 : || (targetcm.cxx_implicit_extern_c
12533 0 : && (targetcm.cxx_implicit_extern_c
12534 0 : (IDENTIFIER_POINTER (declarator))))))
12535 34229 : SET_DECL_LANGUAGE (decl, lang_c);
12536 :
12537 197530684 : DECL_STATIC_FUNCTION_P (decl)
12538 197530684 : = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
12539 197530684 : DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
12540 :
12541 197530684 : if (initialized == SD_DELETED)
12542 4368372 : DECL_DELETED_FN (decl) = 1;
12543 :
12544 197530684 : if (ctype && funcdef_flag)
12545 101836631 : check_class_member_definition_namespace (decl);
12546 :
12547 197530684 : if (ctype == NULL_TREE && DECL_MAIN_P (decl))
12548 : {
12549 34217 : if (PROCESSING_REAL_TEMPLATE_DECL_P())
12550 9 : error_at (location, "cannot declare %<::main%> to be a template");
12551 34217 : if (inlinep & 1)
12552 3 : error_at (declspecs->locations[ds_inline],
12553 : "cannot declare %<::main%> to be inline");
12554 34217 : if (inlinep & 2)
12555 6 : error_at (declspecs->locations[ds_constexpr],
12556 : "cannot declare %<::main%> to be %qs", "constexpr");
12557 34217 : if (inlinep & 8)
12558 3 : error_at (declspecs->locations[ds_consteval],
12559 : "cannot declare %<::main%> to be %qs", "consteval");
12560 34217 : if (!publicp)
12561 0 : error_at (location, "cannot declare %<::main%> to be static");
12562 34217 : if (current_lang_name != lang_name_cplusplus)
12563 12 : pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
12564 : " linkage specification other than %<extern \"C++\"%>");
12565 34217 : if (module_attach_p ())
12566 : {
12567 3 : auto_diagnostic_group adg;
12568 3 : error_at (location, "cannot attach %<::main%> to a named module");
12569 3 : inform (location, "use %<extern \"C++\"%> to attach it to the "
12570 : "global module instead");
12571 3 : }
12572 : inlinep = 0;
12573 : publicp = 1;
12574 : }
12575 :
12576 : /* Members of anonymous types and local classes have no linkage; make
12577 : them internal. If a typedef is made later, this will be changed. */
12578 197530684 : if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
12579 : publicp = 0;
12580 197516159 : else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
12581 : /* But members of local classes in a module CMI should have their
12582 : definitions exported, in case they are (directly or indirectly)
12583 : used by an importer. We don't just use module_has_cmi_p here
12584 : because for entities in the GMF we don't yet know whether this
12585 : module will have a CMI, so we'll conservatively assume it might. */
12586 2453313 : publicp = module_maybe_has_cmi_p ();
12587 :
12588 197516159 : if (publicp && cxx_dialect == cxx98)
12589 : {
12590 : /* [basic.link]: A name with no linkage (notably, the name of a class
12591 : or enumeration declared in a local scope) shall not be used to
12592 : declare an entity with linkage.
12593 :
12594 : DR 757 relaxes this restriction for C++0x. */
12595 1164978 : no_linkage_error (decl);
12596 : }
12597 :
12598 197530684 : TREE_PUBLIC (decl) = publicp;
12599 197530684 : if (! publicp)
12600 : {
12601 2574557 : DECL_INTERFACE_KNOWN (decl) = 1;
12602 2574557 : DECL_NOT_REALLY_EXTERN (decl) = 1;
12603 : }
12604 :
12605 : /* If the declaration was declared inline, mark it as such. */
12606 197530684 : if (inlinep)
12607 : {
12608 76320788 : DECL_DECLARED_INLINE_P (decl) = 1;
12609 76320788 : if (publicp)
12610 76065792 : DECL_COMDAT (decl) = 1;
12611 : }
12612 76320788 : if (inlinep & 2)
12613 56422387 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
12614 141108297 : else if (inlinep & 8)
12615 : {
12616 1170342 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
12617 1170342 : SET_DECL_IMMEDIATE_FUNCTION_P (decl);
12618 : }
12619 :
12620 197530684 : DECL_EXTERNAL (decl) = 1;
12621 197530684 : if (TREE_CODE (type) == FUNCTION_TYPE)
12622 : {
12623 90893612 : if (quals || rqual)
12624 393 : TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
12625 : TYPE_UNQUALIFIED,
12626 : REF_QUAL_NONE);
12627 90893612 : auto_diagnostic_group d;
12628 90893612 : if (quals)
12629 621 : error (!ctype
12630 : ? G_("non-member function %qD cannot have cv-qualifier")
12631 : : !xobj_func_p
12632 297 : ? G_("static member function %qD cannot have cv-qualifier")
12633 : : G_("explicit object member function "
12634 : "%qD cannot have cv-qualifier"),
12635 : decl);
12636 90893612 : if (rqual)
12637 531 : error (!ctype
12638 : ? G_("non-member function %qD cannot have ref-qualifier")
12639 : : !xobj_func_p
12640 264 : ? G_("static member function %qD cannot have ref-qualifier")
12641 : : G_("explicit object member function "
12642 : "%qD cannot have ref-qualifier"),
12643 : decl);
12644 :
12645 90893612 : if (xobj_func_p && (quals || rqual))
12646 363 : inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
12647 : "explicit object parameter declared here");
12648 90893612 : quals = TYPE_UNQUALIFIED;
12649 90893612 : rqual = REF_QUAL_NONE;
12650 :
12651 90893612 : }
12652 :
12653 197530684 : if (deduction_guide_p (decl))
12654 : {
12655 1272805 : tree type = TREE_TYPE (DECL_NAME (decl));
12656 1272805 : if (in_namespace == NULL_TREE
12657 1272805 : && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
12658 : {
12659 3 : auto_diagnostic_group d;
12660 3 : error_at (location, "deduction guide %qD must be declared in the "
12661 : "same scope as %qT", decl, type);
12662 3 : inform (location_of (type), " declared here");
12663 3 : return NULL_TREE;
12664 3 : }
12665 2545604 : if (DECL_CLASS_SCOPE_P (decl)
12666 1272843 : && current_access_specifier != declared_access (TYPE_NAME (type)))
12667 : {
12668 3 : auto_diagnostic_group d;
12669 3 : error_at (location, "deduction guide %qD must have the same access "
12670 : "as %qT", decl, type);
12671 3 : inform (location_of (type), " declared here");
12672 3 : }
12673 1272802 : if (funcdef_flag)
12674 3 : error_at (location,
12675 : "deduction guide %qD must not have a function body", decl);
12676 : }
12677 365911323 : else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
12678 208614996 : && !grok_op_properties (decl, /*complain=*/true))
12679 : return NULL_TREE;
12680 196257732 : else if (UDLIT_OPER_P (DECL_NAME (decl)))
12681 : {
12682 320012 : bool long_long_unsigned_p;
12683 320012 : bool long_double_p;
12684 320012 : const char *suffix = NULL;
12685 : /* [over.literal]/6: Literal operators shall not have C linkage. */
12686 320012 : if (DECL_LANGUAGE (decl) == lang_c)
12687 : {
12688 6 : auto_diagnostic_group d;
12689 6 : error_at (location, "literal operator with C linkage");
12690 6 : maybe_show_extern_c_location ();
12691 6 : return NULL_TREE;
12692 6 : }
12693 :
12694 320006 : if (DECL_NAMESPACE_SCOPE_P (decl))
12695 : {
12696 320000 : if (!check_literal_operator_args (decl, &long_long_unsigned_p,
12697 : &long_double_p))
12698 : {
12699 42 : error_at (location, "%qD has invalid argument list", decl);
12700 42 : return NULL_TREE;
12701 : }
12702 :
12703 319958 : suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
12704 319958 : if (long_long_unsigned_p)
12705 : {
12706 47314 : if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
12707 68 : warning_at (location, 0, "integer suffix %qs"
12708 : " shadowed by implementation", suffix);
12709 : }
12710 272644 : else if (long_double_p)
12711 : {
12712 86927 : if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
12713 80 : warning_at (location, 0, "floating-point suffix %qs"
12714 : " shadowed by implementation", suffix);
12715 : }
12716 : /* 17.6.3.3.5 */
12717 319958 : if (suffix[0] != '_'
12718 319351 : && !current_function_decl && !(friendp && !funcdef_flag))
12719 319345 : warning_at (location, OPT_Wliteral_suffix,
12720 : "literal operator suffixes not preceded by %<_%>"
12721 : " are reserved for future standardization");
12722 : }
12723 : else
12724 : {
12725 6 : error_at (location, "%qD must be a non-member function", decl);
12726 6 : return NULL_TREE;
12727 : }
12728 : }
12729 :
12730 196257681 : if (funcdef_flag)
12731 : /* Make the init_value nonzero so pushdecl knows this is not
12732 : tentative. error_mark_node is replaced later with the BLOCK. */
12733 139354316 : DECL_INITIAL (decl) = error_mark_node;
12734 :
12735 197530480 : if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
12736 74771056 : TREE_NOTHROW (decl) = 1;
12737 :
12738 197530480 : if (flag_openmp || flag_openmp_simd)
12739 : {
12740 : /* Adjust "omp declare simd" attributes. */
12741 482967 : tree ods = lookup_attribute ("omp declare simd", *attrlist);
12742 482967 : if (ods)
12743 : {
12744 : tree attr;
12745 2033 : for (attr = ods; attr;
12746 1078 : attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
12747 : {
12748 1078 : if (TREE_CODE (type) == METHOD_TYPE)
12749 204 : walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
12750 : DECL_ARGUMENTS (decl), NULL);
12751 1078 : if (TREE_VALUE (attr) != NULL_TREE)
12752 : {
12753 872 : tree cl = TREE_VALUE (TREE_VALUE (attr));
12754 872 : cl = c_omp_declare_simd_clauses_to_numbers
12755 872 : (DECL_ARGUMENTS (decl), cl);
12756 872 : if (cl)
12757 872 : TREE_VALUE (TREE_VALUE (attr)) = cl;
12758 : else
12759 0 : TREE_VALUE (attr) = NULL_TREE;
12760 : }
12761 : }
12762 : }
12763 : }
12764 :
12765 : /* [basic.stc.dynamic.deallocation]/3 - A deallocation function shall not
12766 : have a potentially throwing exception specification. */
12767 197530480 : maybe_diagnose_deallocation_noexcept_false (decl);
12768 :
12769 : /* Caller will do the rest of this. */
12770 197530480 : if (check < 0)
12771 : {
12772 6873004 : if (decl && decl != error_mark_node && contract_specifiers)
12773 24 : set_fn_contract_specifiers (decl, contract_specifiers);
12774 6873004 : return decl;
12775 : }
12776 :
12777 190657476 : if (ctype != NULL_TREE)
12778 117716513 : grokclassfn (ctype, decl, flags);
12779 :
12780 : /* 12.4/3 */
12781 190657476 : if (cxx_dialect >= cxx11
12782 379004480 : && DECL_DESTRUCTOR_P (decl)
12783 3366283 : && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
12784 190829127 : && !processing_template_decl)
12785 87857 : deduce_noexcept_on_destructor (decl);
12786 :
12787 190657476 : set_originating_module (decl);
12788 :
12789 190657476 : decl = check_explicit_specialization (orig_declarator, decl,
12790 : template_count,
12791 190657476 : 2 * funcdef_flag +
12792 190657476 : 4 * (friendp != 0),
12793 : *attrlist);
12794 190657476 : if (decl == error_mark_node)
12795 : return NULL_TREE;
12796 :
12797 190657202 : if (DECL_STATIC_FUNCTION_P (decl))
12798 10986563 : check_static_quals (decl, quals);
12799 :
12800 190657202 : if (attrlist)
12801 : {
12802 190657202 : cplus_decl_attributes (&decl, *attrlist, 0);
12803 190657202 : *attrlist = NULL_TREE;
12804 : }
12805 :
12806 : /* Update now we have a decl and maybe know the return type. */
12807 190657202 : if (contract_specifiers)
12808 : {
12809 912 : tree t = decl;
12810 912 : if (TREE_CODE (decl) == TEMPLATE_DECL)
12811 7 : t = DECL_TEMPLATE_RESULT (decl);
12812 912 : set_fn_contract_specifiers (t, contract_specifiers);
12813 912 : rebuild_postconditions (t);
12814 : }
12815 :
12816 : /* Check main's type after attributes have been applied. */
12817 190657202 : if (ctype == NULL_TREE && DECL_MAIN_P (decl))
12818 : {
12819 34205 : if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
12820 : integer_type_node))
12821 : {
12822 20 : tree dtype = TREE_TYPE (decl);
12823 20 : tree oldtypeargs = TYPE_ARG_TYPES (dtype);
12824 20 : tree newtype;
12825 20 : error_at (declspecs->locations[ds_type_spec],
12826 : "%<::main%> must return %<int%>");
12827 60 : newtype = build_function_type (integer_type_node, oldtypeargs,
12828 20 : TYPE_NO_NAMED_ARGS_STDARG_P (dtype));
12829 20 : TREE_TYPE (decl) = newtype;
12830 : }
12831 34205 : if (warn_main)
12832 34183 : check_main_parameter_types (decl);
12833 : }
12834 :
12835 190657202 : if (ctype != NULL_TREE && check)
12836 : {
12837 9374104 : tree old_decl = check_classfn (ctype, decl,
12838 9374104 : (current_template_depth
12839 9374104 : > template_class_depth (ctype))
12840 2338702 : ? current_template_parms
12841 : : NULL_TREE);
12842 :
12843 9374104 : if (old_decl == error_mark_node)
12844 : return NULL_TREE;
12845 :
12846 9373996 : if (old_decl)
12847 : {
12848 8965572 : tree ok;
12849 8965572 : tree pushed_scope;
12850 :
12851 8965572 : if (TREE_CODE (old_decl) == TEMPLATE_DECL)
12852 : /* Because grokfndecl is always supposed to return a
12853 : FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
12854 : here. We depend on our callers to figure out that its
12855 : really a template that's being returned. */
12856 2338690 : old_decl = DECL_TEMPLATE_RESULT (old_decl);
12857 :
12858 8965572 : if (DECL_STATIC_FUNCTION_P (old_decl)
12859 8965572 : && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
12860 : {
12861 : /* Remove the `this' parm added by grokclassfn. */
12862 182641 : revert_static_member_fn (decl);
12863 182641 : check_static_quals (decl, quals);
12864 : }
12865 8965572 : if (DECL_ARTIFICIAL (old_decl))
12866 : {
12867 9 : error ("definition of implicitly-declared %qD", old_decl);
12868 9 : return NULL_TREE;
12869 : }
12870 8965563 : else if (DECL_DEFAULTED_FN (old_decl))
12871 : {
12872 3 : auto_diagnostic_group d;
12873 3 : error ("definition of explicitly-defaulted %q+D", decl);
12874 3 : inform (DECL_SOURCE_LOCATION (old_decl),
12875 : "%q#D explicitly defaulted here", old_decl);
12876 3 : return NULL_TREE;
12877 3 : }
12878 :
12879 8965560 : if (modules_p () && !module_may_redeclare (old_decl))
12880 : return NULL_TREE;
12881 :
12882 : /* Since we've smashed OLD_DECL to its
12883 : DECL_TEMPLATE_RESULT, we must do the same to DECL. */
12884 8965500 : if (TREE_CODE (decl) == TEMPLATE_DECL)
12885 1203 : decl = DECL_TEMPLATE_RESULT (decl);
12886 :
12887 : /* Attempt to merge the declarations. This can fail, in
12888 : the case of some invalid specialization declarations. */
12889 8965500 : pushed_scope = push_scope (ctype);
12890 8965500 : ok = duplicate_decls (decl, old_decl);
12891 8965500 : if (pushed_scope)
12892 8965500 : pop_scope (pushed_scope);
12893 8965500 : if (!ok)
12894 : {
12895 0 : error ("no %q#D member function declared in class %qT",
12896 : decl, ctype);
12897 0 : return NULL_TREE;
12898 : }
12899 8965500 : if (ok == error_mark_node)
12900 : return NULL_TREE;
12901 8965476 : return old_decl;
12902 : }
12903 : }
12904 :
12905 363383044 : if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
12906 : return NULL_TREE;
12907 :
12908 181691519 : if (ctype == NULL_TREE || check)
12909 73349182 : return decl;
12910 :
12911 108342337 : if (virtualp)
12912 4298248 : DECL_VIRTUAL_P (decl) = 1;
12913 :
12914 108342337 : return decl;
12915 : }
12916 :
12917 : /* decl is a FUNCTION_DECL.
12918 : specifiers are the parsed virt-specifiers.
12919 :
12920 : Set flags to reflect the virt-specifiers.
12921 :
12922 : Returns decl. */
12923 :
12924 : static tree
12925 115215438 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
12926 : {
12927 115215438 : if (decl == NULL_TREE)
12928 : return decl;
12929 115215341 : if (specifiers & VIRT_SPEC_OVERRIDE)
12930 395774 : DECL_OVERRIDE_P (decl) = 1;
12931 115215341 : if (specifiers & VIRT_SPEC_FINAL)
12932 10022 : DECL_FINAL_P (decl) = 1;
12933 : return decl;
12934 : }
12935 :
12936 : /* DECL is a VAR_DECL for a static data member. Set flags to reflect
12937 : the linkage that DECL will receive in the object file. */
12938 :
12939 : static void
12940 14329094 : set_linkage_for_static_data_member (tree decl)
12941 : {
12942 : /* A static data member always has static storage duration and
12943 : external linkage. Note that static data members are forbidden in
12944 : local classes -- the only situation in which a class has
12945 : non-external linkage. */
12946 14329094 : TREE_PUBLIC (decl) = 1;
12947 14329094 : TREE_STATIC (decl) = 1;
12948 : /* For non-template classes, static data members are always put
12949 : out in exactly those files where they are defined, just as
12950 : with ordinary namespace-scope variables. */
12951 14329094 : if (!processing_template_decl)
12952 10947242 : DECL_INTERFACE_KNOWN (decl) = 1;
12953 14329094 : }
12954 :
12955 : /* Create a VAR_DECL named NAME with the indicated TYPE.
12956 :
12957 : If SCOPE is non-NULL, it is the class type or namespace containing
12958 : the variable. If SCOPE is NULL, the variable should is created in
12959 : the innermost enclosing scope. */
12960 :
12961 : static tree
12962 71949550 : grokvardecl (tree type,
12963 : tree name,
12964 : tree orig_declarator,
12965 : const cp_decl_specifier_seq *declspecs,
12966 : int initialized,
12967 : int type_quals,
12968 : int inlinep,
12969 : bool conceptp,
12970 : int template_count,
12971 : tree scope,
12972 : location_t location)
12973 : {
12974 71949550 : tree decl;
12975 71949550 : tree explicit_scope;
12976 :
12977 71949550 : gcc_assert (!name || identifier_p (name));
12978 :
12979 71949550 : bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
12980 71949550 : bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
12981 :
12982 : /* Compute the scope in which to place the variable, but remember
12983 : whether or not that scope was explicitly specified by the user. */
12984 71949550 : explicit_scope = scope;
12985 71949550 : if (!scope)
12986 : {
12987 : /* An explicit "extern" specifier indicates a namespace-scope
12988 : variable. */
12989 71409840 : if (declspecs->storage_class == sc_extern)
12990 567313 : scope = current_decl_namespace ();
12991 70842527 : else if (!at_function_scope_p ())
12992 7540998 : scope = current_scope ();
12993 : }
12994 :
12995 71409840 : if (scope
12996 8648021 : && (/* If the variable is a namespace-scope variable declared in a
12997 : template, we need DECL_LANG_SPECIFIC. */
12998 8648021 : (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
12999 : /* Similarly for namespace-scope variables with language linkage
13000 : other than C++. */
13001 8124985 : || (TREE_CODE (scope) == NAMESPACE_DECL
13002 4654801 : && current_lang_name != lang_name_cplusplus)
13003 : /* Similarly for static data members. */
13004 4934065 : || TYPE_P (scope)
13005 : /* Similarly for explicit specializations. */
13006 4411029 : || (orig_declarator
13007 4410179 : && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
13008 5188361 : decl = build_lang_decl_loc (location, VAR_DECL, name, type);
13009 : else
13010 66761189 : decl = build_decl (location, VAR_DECL, name, type);
13011 :
13012 71949550 : if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
13013 16674 : set_decl_namespace (decl, explicit_scope, 0);
13014 : else
13015 71932876 : DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
13016 :
13017 71949550 : if (declspecs->storage_class == sc_extern)
13018 : {
13019 567313 : DECL_THIS_EXTERN (decl) = 1;
13020 567313 : DECL_EXTERNAL (decl) = !initialized;
13021 : }
13022 :
13023 71949550 : if (DECL_CLASS_SCOPE_P (decl))
13024 : {
13025 523036 : set_linkage_for_static_data_member (decl);
13026 : /* This function is only called with out-of-class definitions. */
13027 523036 : DECL_EXTERNAL (decl) = 0;
13028 523036 : check_class_member_definition_namespace (decl);
13029 : }
13030 : /* At top level, either `static' or no s.c. makes a definition
13031 : (perhaps tentative), and absence of `static' makes it public. */
13032 71426514 : else if (toplevel_bindings_p ())
13033 : {
13034 16247642 : TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
13035 8123821 : && (DECL_THIS_EXTERN (decl)
13036 7518288 : || ! constp
13037 7518288 : || volatilep
13038 7438850 : || inlinep
13039 608936 : || in_template_context
13040 31694 : || processing_specialization
13041 31611 : || module_attach_p ()));
13042 8123821 : TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
13043 : }
13044 : /* Not at top level, only `static' makes a static definition. */
13045 : else
13046 : {
13047 63302693 : TREE_STATIC (decl) = declspecs->storage_class == sc_static;
13048 63302693 : TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
13049 : }
13050 :
13051 71949550 : set_originating_module (decl);
13052 :
13053 71949550 : if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
13054 : {
13055 20203 : if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
13056 : {
13057 20195 : CP_DECL_THREAD_LOCAL_P (decl) = true;
13058 : // NB: Set a tentative TLS model to avoid tls_model attribute
13059 : // warnings due to lack of thread storage duration. It will
13060 : // be updated by cplus_decl_attributes later.
13061 20195 : if (!processing_template_decl)
13062 20070 : set_decl_tls_model (decl, TLS_MODEL_REAL);
13063 : }
13064 20203 : if (declspecs->gnu_thread_keyword_p)
13065 19196 : SET_DECL_GNU_TLS_P (decl);
13066 : }
13067 :
13068 : /* If the type of the decl has no linkage, make sure that we'll
13069 : notice that in mark_used. */
13070 71949550 : if (cxx_dialect > cxx98
13071 71642584 : && decl_linkage (decl) != lk_none
13072 70908451 : && DECL_LANG_SPECIFIC (decl) == NULL
13073 65640702 : && !DECL_EXTERN_C_P (decl)
13074 137590252 : && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
13075 4713 : retrofit_lang_decl (decl);
13076 :
13077 71949550 : if (TREE_PUBLIC (decl))
13078 : {
13079 : /* [basic.link]: A name with no linkage (notably, the name of a class
13080 : or enumeration declared in a local scope) shall not be used to
13081 : declare an entity with linkage.
13082 :
13083 : DR 757 relaxes this restriction for C++0x. */
13084 8577034 : if (cxx_dialect < cxx11)
13085 23915 : no_linkage_error (decl);
13086 : }
13087 : else
13088 63372516 : DECL_INTERFACE_KNOWN (decl) = 1;
13089 :
13090 71949550 : if (DECL_NAME (decl)
13091 71949550 : && MAIN_NAME_P (DECL_NAME (decl)))
13092 : {
13093 12 : if (scope == global_namespace)
13094 6 : error_at (DECL_SOURCE_LOCATION (decl),
13095 : "cannot declare %<::main%> to be a global variable");
13096 6 : else if (DECL_EXTERN_C_P (decl))
13097 3 : error_at (DECL_SOURCE_LOCATION (decl),
13098 : "an entity named %<main%> cannot be declared with "
13099 : "C language linkage");
13100 : }
13101 :
13102 : /* Check if a variable is being declared as a concept. */
13103 71949550 : if (conceptp)
13104 : {
13105 30 : if (!processing_template_decl)
13106 13 : error_at (declspecs->locations[ds_concept],
13107 : "a non-template variable cannot be %<concept%>");
13108 17 : else if (!at_namespace_scope_p ())
13109 2 : error_at (declspecs->locations[ds_concept],
13110 : "concept must be defined at namespace scope");
13111 : else
13112 15 : error_at (declspecs->locations[ds_concept],
13113 : "variable concepts are no longer supported");
13114 : return NULL_TREE;
13115 : }
13116 71949520 : else if (flag_concepts
13117 71949520 : && current_template_depth > template_class_depth (scope))
13118 : {
13119 61949640 : tree ci = current_template_constraints ();
13120 61949640 : set_constraints (decl, ci);
13121 : }
13122 :
13123 : // Handle explicit specializations and instantiations of variable templates.
13124 71949520 : if (orig_declarator)
13125 71206031 : decl = check_explicit_specialization (orig_declarator, decl,
13126 : template_count, 0);
13127 :
13128 71949520 : return decl != error_mark_node ? decl : NULL_TREE;
13129 : }
13130 :
13131 : /* Create and return a canonical pointer to member function type, for
13132 : TYPE, which is a POINTER_TYPE to a METHOD_TYPE. */
13133 :
13134 : tree
13135 3158173 : build_ptrmemfunc_type (tree type)
13136 : {
13137 3158173 : tree field, fields;
13138 3158173 : tree t;
13139 :
13140 3158173 : if (type == error_mark_node)
13141 : return type;
13142 :
13143 : /* Make sure that we always have the unqualified pointer-to-member
13144 : type first. */
13145 3158173 : if (cp_cv_quals quals = cp_type_quals (type))
13146 : {
13147 0 : tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
13148 0 : return cp_build_qualified_type (unqual, quals);
13149 : }
13150 :
13151 : /* If a canonical type already exists for this type, use it. We use
13152 : this method instead of type_hash_canon, because it only does a
13153 : simple equality check on the list of field members. */
13154 :
13155 3158173 : t = TYPE_PTRMEMFUNC_TYPE (type);
13156 3158173 : if (t)
13157 : return t;
13158 :
13159 1057498 : t = make_node (RECORD_TYPE);
13160 :
13161 : /* Let the front end know this is a pointer to member function. */
13162 1057498 : TYPE_PTRMEMFUNC_FLAG (t) = 1;
13163 :
13164 1057498 : field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
13165 1057498 : DECL_NONADDRESSABLE_P (field) = 1;
13166 1057498 : fields = field;
13167 :
13168 1057498 : field = build_decl (input_location, FIELD_DECL, delta_identifier,
13169 : delta_type_node);
13170 1057498 : DECL_NONADDRESSABLE_P (field) = 1;
13171 1057498 : DECL_CHAIN (field) = fields;
13172 1057498 : fields = field;
13173 :
13174 1057498 : finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
13175 :
13176 : /* Zap out the name so that the back end will give us the debugging
13177 : information for this anonymous RECORD_TYPE. */
13178 1057498 : TYPE_NAME (t) = NULL_TREE;
13179 :
13180 : /* Cache this pointer-to-member type so that we can find it again
13181 : later. */
13182 1057498 : TYPE_PTRMEMFUNC_TYPE (type) = t;
13183 :
13184 1057498 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
13185 523564 : SET_TYPE_STRUCTURAL_EQUALITY (t);
13186 533934 : else if (TYPE_CANONICAL (type) != type)
13187 339125 : TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
13188 :
13189 : return t;
13190 : }
13191 :
13192 : /* Create and return a pointer to data member type. */
13193 :
13194 : tree
13195 337243 : build_ptrmem_type (tree class_type, tree member_type)
13196 : {
13197 337243 : if (TREE_CODE (member_type) == METHOD_TYPE)
13198 : {
13199 60859 : cp_cv_quals quals = type_memfn_quals (member_type);
13200 60859 : cp_ref_qualifier rqual = type_memfn_rqual (member_type);
13201 60859 : member_type = build_memfn_type (member_type, class_type, quals, rqual);
13202 60859 : return build_ptrmemfunc_type (build_pointer_type (member_type));
13203 : }
13204 : else
13205 : {
13206 276384 : gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
13207 276384 : return build_offset_type (class_type, member_type);
13208 : }
13209 : }
13210 :
13211 : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
13212 : Check to see that the definition is valid. Issue appropriate error
13213 : messages. */
13214 :
13215 : static void
13216 19539205 : check_static_variable_definition (tree decl, tree type)
13217 : {
13218 : /* Avoid redundant diagnostics on out-of-class definitions. */
13219 19539205 : if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
13220 : ;
13221 : /* Can't check yet if we don't know the type. */
13222 18097103 : else if (dependent_type_p (type))
13223 : ;
13224 : /* If DECL is declared constexpr, we'll do the appropriate checks
13225 : in check_initializer. Similarly for inline static data members. */
13226 17545013 : else if (DECL_P (decl)
13227 17545013 : && (DECL_DECLARED_CONSTEXPR_P (decl)
13228 2798434 : || DECL_VAR_DECLARED_INLINE_P (decl)))
13229 : ;
13230 2797935 : else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
13231 : {
13232 60 : if (!COMPLETE_TYPE_P (type))
13233 11 : error_at (DECL_SOURCE_LOCATION (decl),
13234 : "in-class initialization of static data member %q#D of "
13235 : "incomplete type", decl);
13236 49 : else if (literal_type_p (type))
13237 43 : permerror (DECL_SOURCE_LOCATION (decl),
13238 : "%<constexpr%> needed for in-class initialization of "
13239 : "static data member %q#D of non-integral type", decl);
13240 : else
13241 6 : error_at (DECL_SOURCE_LOCATION (decl),
13242 : "in-class initialization of static data member %q#D of "
13243 : "non-literal type", decl);
13244 : }
13245 : /* Motion 10 at San Diego: If a static const integral data member is
13246 : initialized with an integral constant expression, the initializer
13247 : may appear either in the declaration (within the class), or in
13248 : the definition, but not both. If it appears in the class, the
13249 : member is a member constant. The file-scope definition is always
13250 : required. */
13251 2797875 : else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
13252 11 : error_at (DECL_SOURCE_LOCATION (decl),
13253 : "invalid in-class initialization of static data member "
13254 : "of non-integral type %qT",
13255 : type);
13256 2797864 : else if (!CP_TYPE_CONST_P (type))
13257 5 : error_at (DECL_SOURCE_LOCATION (decl),
13258 : "ISO C++ forbids in-class initialization of non-const "
13259 : "static member %qD",
13260 : decl);
13261 2797859 : else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
13262 5 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
13263 : "ISO C++ forbids initialization of member constant "
13264 : "%qD of non-integral type %qT", decl, type);
13265 19539205 : }
13266 :
13267 : /* *expr_p is part of the TYPE_SIZE of a variably-sized array. If any
13268 : SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
13269 : expressions out into temporary variables so that walk_tree doesn't
13270 : step into them (c++/15764). */
13271 :
13272 : static tree
13273 3380 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
13274 : {
13275 3380 : hash_set<tree> *pset = (hash_set<tree> *)data;
13276 3380 : tree expr = *expr_p;
13277 3380 : if (TREE_CODE (expr) == SAVE_EXPR)
13278 : {
13279 1471 : tree op = TREE_OPERAND (expr, 0);
13280 1471 : cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
13281 1471 : if (TREE_SIDE_EFFECTS (op))
13282 56 : TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
13283 1471 : *walk_subtrees = 0;
13284 : }
13285 1909 : else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
13286 1734 : *walk_subtrees = 0;
13287 3380 : return NULL;
13288 : }
13289 :
13290 : /* Entry point for the above. */
13291 :
13292 : static void
13293 1530 : stabilize_vla_size (tree size)
13294 : {
13295 1530 : hash_set<tree> pset;
13296 : /* Break out any function calls into temporary variables. */
13297 1530 : cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
13298 1530 : }
13299 :
13300 : /* Reduce a SIZEOF_EXPR to its value. */
13301 :
13302 : tree
13303 12620426 : fold_sizeof_expr (tree t)
13304 : {
13305 12620426 : tree r;
13306 12620426 : if (SIZEOF_EXPR_TYPE_P (t))
13307 12000304 : r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
13308 12000304 : TREE_TYPE (TREE_OPERAND (t, 0)),
13309 : SIZEOF_EXPR, false, false);
13310 620122 : else if (TYPE_P (TREE_OPERAND (t, 0)))
13311 0 : r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
13312 0 : TREE_OPERAND (t, 0), SIZEOF_EXPR,
13313 : false, false);
13314 : else
13315 620122 : r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
13316 620122 : TREE_OPERAND (t, 0), SIZEOF_EXPR,
13317 : false, false);
13318 12620426 : if (r == error_mark_node)
13319 94 : r = size_one_node;
13320 12620426 : r = cp_fold_convert (size_type_node, r);
13321 12620426 : return r;
13322 : }
13323 :
13324 : /* Given the SIZE (i.e., number of elements) in an array, compute
13325 : an appropriate index type for the array. If non-NULL, NAME is
13326 : the name of the entity being declared. */
13327 :
13328 : static tree
13329 3568590 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
13330 : tsubst_flags_t complain)
13331 : {
13332 3568590 : if (error_operand_p (size))
13333 32 : return error_mark_node;
13334 :
13335 : /* The type of the index being computed. */
13336 3568558 : tree itype;
13337 :
13338 : /* The original numeric size as seen in the source code before
13339 : conversion to size_t. */
13340 3568558 : tree origsize = size;
13341 :
13342 3568558 : location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
13343 :
13344 3568558 : if (!type_dependent_expression_p (size))
13345 : {
13346 3519579 : origsize = size = mark_rvalue_use (size);
13347 :
13348 38381 : if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
13349 3519739 : && TREE_SIDE_EFFECTS (size))
13350 : /* In C++98, we mark a non-constant array bound with a magic
13351 : NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case. */;
13352 : else
13353 : {
13354 3519578 : size = build_converted_constant_expr (size_type_node, size, complain);
13355 : /* Pedantically a constant expression is required here and so
13356 : __builtin_is_constant_evaluated () should fold to true if it
13357 : is successfully folded into a constant. */
13358 3519578 : size = fold_non_dependent_expr (size, complain,
13359 : /*manifestly_const_eval=*/true);
13360 :
13361 3519578 : if (!TREE_CONSTANT (size))
13362 148758 : size = origsize;
13363 : }
13364 :
13365 3519579 : if (error_operand_p (size))
13366 3 : return error_mark_node;
13367 :
13368 : /* The array bound must be an integer type. */
13369 3519576 : tree type = TREE_TYPE (size);
13370 3519576 : if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
13371 : {
13372 21 : if (!(complain & tf_error))
13373 0 : return error_mark_node;
13374 21 : if (name)
13375 18 : error_at (loc, "size of array %qD has non-integral type %qT",
13376 : name, type);
13377 : else
13378 3 : error_at (loc, "size of array has non-integral type %qT", type);
13379 21 : size = integer_one_node;
13380 : }
13381 : }
13382 :
13383 : /* A type is dependent if it is...an array type constructed from any
13384 : dependent type or whose size is specified by a constant expression
13385 : that is value-dependent. */
13386 : /* We can only call value_dependent_expression_p on integral constant
13387 : expressions. */
13388 3568555 : if (processing_template_decl
13389 1635390 : && potential_constant_expression (size)
13390 5203920 : && value_dependent_expression_p (size))
13391 : {
13392 : /* Just build the index type and mark that it requires
13393 : structural equality checks. */
13394 915168 : in_template:
13395 915168 : itype = build_index_type (build_min (MINUS_EXPR, sizetype,
13396 : size, size_one_node));
13397 915168 : TYPE_DEPENDENT_P (itype) = 1;
13398 915168 : TYPE_DEPENDENT_P_VALID (itype) = 1;
13399 915168 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
13400 915168 : return itype;
13401 : }
13402 :
13403 2670177 : if (TREE_CODE (size) != INTEGER_CST)
13404 : {
13405 18880 : tree folded = cp_fully_fold (size);
13406 18880 : if (TREE_CODE (folded) == INTEGER_CST)
13407 : {
13408 214 : if (name)
13409 140 : pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
13410 : "integral constant-expression", name);
13411 : else
13412 74 : pedwarn (loc, OPT_Wpedantic,
13413 : "size of array is not an integral constant-expression");
13414 : }
13415 18880 : if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
13416 : /* We might have lost the TREE_CONSTANT flag e.g. when we are
13417 : folding a conversion from a pointer to integral type. In that
13418 : case issue an error below and don't treat this as a VLA. */;
13419 : else
13420 : /* Use the folded result for VLAs, too; it will have resolved
13421 : SIZEOF_EXPR. */
13422 : size = folded;
13423 : }
13424 :
13425 : /* Normally, the array-bound will be a constant. */
13426 2670177 : if (TREE_CODE (size) == INTEGER_CST)
13427 : {
13428 : /* The size to use in diagnostics that reflects the constant
13429 : size used in the source, rather than SIZE massaged above. */
13430 2651511 : tree diagsize = size;
13431 :
13432 : /* If the original size before conversion to size_t was signed
13433 : and negative, convert it to ssizetype to restore the sign. */
13434 2651511 : if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
13435 : && TREE_CODE (size) == INTEGER_CST
13436 2651511 : && tree_int_cst_sign_bit (size))
13437 : {
13438 233 : diagsize = fold_convert (ssizetype, size);
13439 :
13440 : /* Clear the overflow bit that may have been set as a result
13441 : of the conversion from the sizetype of the new size to
13442 : ssizetype. */
13443 233 : TREE_OVERFLOW (diagsize) = false;
13444 : }
13445 :
13446 : /* Verify that the array has a positive number of elements
13447 : and issue the appropriate diagnostic if it doesn't. */
13448 2651511 : if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
13449 : {
13450 464 : if (!(complain & tf_error))
13451 15 : return error_mark_node;
13452 449 : size = integer_one_node;
13453 : }
13454 : /* As an extension we allow zero-sized arrays. */
13455 2651047 : else if (integer_zerop (size))
13456 : {
13457 3216 : if (!(complain & tf_error))
13458 : /* We must fail if performing argument deduction (as
13459 : indicated by the state of complain), so that
13460 : another substitution can be found. */
13461 8 : return error_mark_node;
13462 3208 : else if (name)
13463 2914 : pedwarn (loc, OPT_Wpedantic,
13464 : "ISO C++ forbids zero-size array %qD", name);
13465 : else
13466 294 : pedwarn (loc, OPT_Wpedantic,
13467 : "ISO C++ forbids zero-size array");
13468 : }
13469 : }
13470 18666 : else if (TREE_CONSTANT (size)
13471 : /* We don't allow VLAs at non-function scopes, or during
13472 : tentative template substitution. */
13473 18651 : || !at_function_scope_p ()
13474 36992 : || !(complain & tf_error))
13475 : {
13476 346 : if (!(complain & tf_error))
13477 295 : return error_mark_node;
13478 : /* `(int) &fn' is not a valid array bound. */
13479 51 : if (name)
13480 37 : error_at (loc,
13481 : "size of array %qD is not an integral constant-expression",
13482 : name);
13483 : else
13484 14 : error_at (loc, "size of array is not an integral constant-expression");
13485 51 : size = integer_one_node;
13486 : }
13487 18320 : else if (pedantic && warn_vla != 0)
13488 : {
13489 30 : if (name)
13490 15 : pedwarn (name_loc, OPT_Wvla,
13491 : "ISO C++ forbids variable length array %qD", name);
13492 : else
13493 15 : pedwarn (input_location, OPT_Wvla,
13494 : "ISO C++ forbids variable length array");
13495 : }
13496 18290 : else if (warn_vla > 0)
13497 : {
13498 3 : if (name)
13499 3 : warning_at (name_loc, OPT_Wvla,
13500 : "variable length array %qD is used", name);
13501 : else
13502 0 : warning (OPT_Wvla,
13503 : "variable length array is used");
13504 : }
13505 :
13506 2669859 : if (processing_template_decl && !TREE_CONSTANT (size))
13507 16790 : goto in_template;
13508 : else
13509 : {
13510 2653069 : if (!TREE_CONSTANT (size))
13511 : {
13512 : /* A variable sized array. Arrange for the SAVE_EXPR on the inside
13513 : of the MINUS_EXPR, which allows the -1 to get folded with the +1
13514 : that happens when building TYPE_SIZE. */
13515 1530 : size = variable_size (size);
13516 1530 : stabilize_vla_size (size);
13517 : }
13518 :
13519 : /* Compute the index of the largest element in the array. It is
13520 : one less than the number of elements in the array. We save
13521 : and restore PROCESSING_TEMPLATE_DECL so that computations in
13522 : cp_build_binary_op will be appropriately folded. */
13523 2653069 : {
13524 2653069 : processing_template_decl_sentinel s;
13525 2653069 : itype = cp_build_binary_op (input_location,
13526 : MINUS_EXPR,
13527 : cp_convert (ssizetype, size, complain),
13528 : cp_convert (ssizetype, integer_one_node,
13529 : complain),
13530 : complain);
13531 2653069 : itype = maybe_constant_value (itype, NULL_TREE, mce_true);
13532 2653069 : }
13533 :
13534 2653069 : if (!TREE_CONSTANT (itype))
13535 : {
13536 1530 : if (sanitize_flags_p (SANITIZE_VLA)
13537 1530 : && current_function_decl != NULL_TREE)
13538 : {
13539 : /* We have to add 1 -- in the ubsan routine we generate
13540 : LE_EXPR rather than LT_EXPR. */
13541 78 : tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
13542 : build_one_cst (TREE_TYPE (itype)));
13543 78 : t = ubsan_instrument_vla (input_location, t);
13544 78 : finish_expr_stmt (t);
13545 : }
13546 : }
13547 : /* Make sure that there was no overflow when creating to a signed
13548 : index type. (For example, on a 32-bit machine, an array with
13549 : size 2^32 - 1 is too big.) */
13550 2651539 : else if (TREE_CODE (itype) == INTEGER_CST
13551 2651539 : && TREE_OVERFLOW (itype))
13552 : {
13553 0 : if (!(complain & tf_error))
13554 0 : return error_mark_node;
13555 0 : error ("overflow in array dimension");
13556 0 : TREE_OVERFLOW (itype) = 0;
13557 : }
13558 : }
13559 :
13560 : /* Create and return the appropriate index type. */
13561 2653069 : itype = build_index_type (itype);
13562 :
13563 : /* If the index type were dependent, we would have returned early, so
13564 : remember that it isn't. */
13565 2653069 : TYPE_DEPENDENT_P (itype) = 0;
13566 2653069 : TYPE_DEPENDENT_P_VALID (itype) = 1;
13567 2653069 : return itype;
13568 : }
13569 :
13570 : tree
13571 624627 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
13572 : {
13573 624627 : return compute_array_index_type_loc (input_location, name, size, complain);
13574 : }
13575 :
13576 : /* Returns the scope (if any) in which the entity declared by
13577 : DECLARATOR will be located. If the entity was declared with an
13578 : unqualified name, NULL_TREE is returned. */
13579 :
13580 : tree
13581 788448080 : get_scope_of_declarator (const cp_declarator *declarator)
13582 : {
13583 913561117 : while (declarator && declarator->kind != cdk_id)
13584 125113037 : declarator = declarator->declarator;
13585 :
13586 : /* If the declarator-id is a SCOPE_REF, the scope in which the
13587 : declaration occurs is the first operand. */
13588 788448080 : if (declarator
13589 787169843 : && declarator->u.id.qualifying_scope)
13590 : return declarator->u.id.qualifying_scope;
13591 :
13592 : /* Otherwise, the declarator is not a qualified name; the entity will
13593 : be declared in the current scope. */
13594 : return NULL_TREE;
13595 : }
13596 :
13597 : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
13598 : indicated TYPE. If non-NULL, NAME is the NAME of the declaration
13599 : with this type. */
13600 :
13601 : static tree
13602 3783150 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
13603 : {
13604 3783150 : tree itype = NULL_TREE;
13605 :
13606 : /* If things have already gone awry, bail now. */
13607 3783150 : if (type == error_mark_node || size == error_mark_node)
13608 : return error_mark_node;
13609 :
13610 : /* [dcl.type.class.deduct] prohibits forming an array of placeholder
13611 : for a deduced class type. */
13612 3783087 : if (template_placeholder_p (type))
13613 : {
13614 6 : if (name)
13615 0 : error_at (loc, "%qD declared as array of template placeholder "
13616 : "type %qT", name, type);
13617 : else
13618 6 : error ("creating array of template placeholder type %qT", type);
13619 6 : return error_mark_node;
13620 : }
13621 :
13622 : /* If there are some types which cannot be array elements,
13623 : issue an error-message and return. */
13624 3783081 : switch (TREE_CODE (type))
13625 : {
13626 3 : case VOID_TYPE:
13627 3 : if (name)
13628 0 : error_at (loc, "declaration of %qD as array of void", name);
13629 : else
13630 3 : error ("creating array of void");
13631 3 : return error_mark_node;
13632 :
13633 6 : case FUNCTION_TYPE:
13634 6 : if (name)
13635 6 : error_at (loc, "declaration of %qD as array of functions", name);
13636 : else
13637 0 : error ("creating array of functions");
13638 6 : return error_mark_node;
13639 :
13640 21 : case REFERENCE_TYPE:
13641 21 : if (name)
13642 15 : error_at (loc, "declaration of %qD as array of references", name);
13643 : else
13644 6 : error ("creating array of references");
13645 21 : return error_mark_node;
13646 :
13647 0 : case METHOD_TYPE:
13648 0 : if (name)
13649 0 : error_at (loc, "declaration of %qD as array of function members",
13650 : name);
13651 : else
13652 0 : error ("creating array of function members");
13653 0 : return error_mark_node;
13654 :
13655 3783051 : default:
13656 3783051 : break;
13657 : }
13658 :
13659 3783051 : if (!verify_type_context (name ? loc : input_location,
13660 : TCTX_ARRAY_ELEMENT, type))
13661 0 : return error_mark_node;
13662 :
13663 : /* [dcl.array]
13664 :
13665 : The constant expressions that specify the bounds of the arrays
13666 : can be omitted only for the first member of the sequence. */
13667 3783051 : if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
13668 : {
13669 30 : if (name)
13670 24 : error_at (loc, "declaration of %qD as multidimensional array must "
13671 : "have bounds for all dimensions except the first",
13672 : name);
13673 : else
13674 6 : error ("multidimensional array must have bounds for all "
13675 : "dimensions except the first");
13676 :
13677 30 : return error_mark_node;
13678 : }
13679 :
13680 : /* Figure out the index type for the array. */
13681 3783021 : if (size)
13682 : {
13683 2943963 : itype = compute_array_index_type_loc (loc, name, size,
13684 : tf_warning_or_error);
13685 2943963 : if (type_uses_auto (type)
13686 2943963 : && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
13687 : {
13688 9 : sorry_at (loc, "variable-length array of %<auto%>");
13689 9 : return error_mark_node;
13690 : }
13691 : }
13692 :
13693 3783012 : return build_cplus_array_type (type, itype);
13694 : }
13695 :
13696 : /* Returns the smallest location that is not UNKNOWN_LOCATION. */
13697 :
13698 : static location_t
13699 1094121126 : min_location (location_t loca, location_t locb)
13700 : {
13701 1094121126 : if (loca == UNKNOWN_LOCATION
13702 1094121126 : || (locb != UNKNOWN_LOCATION
13703 114442504 : && linemap_location_before_p (line_table, locb, loca)))
13704 980937279 : return locb;
13705 : return loca;
13706 : }
13707 :
13708 : /* Returns the smallest location != UNKNOWN_LOCATION among the
13709 : three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
13710 : and LOCATIONS[ds_restrict]. */
13711 :
13712 : static location_t
13713 1092299210 : smallest_type_quals_location (int type_quals, const location_t* locations)
13714 : {
13715 1092299210 : location_t loc = UNKNOWN_LOCATION;
13716 :
13717 1092299210 : if (type_quals & TYPE_QUAL_CONST)
13718 112880568 : loc = locations[ds_const];
13719 :
13720 1092299210 : if (type_quals & TYPE_QUAL_VOLATILE)
13721 1821825 : loc = min_location (loc, locations[ds_volatile]);
13722 :
13723 1092299210 : if (type_quals & TYPE_QUAL_RESTRICT)
13724 43 : loc = min_location (loc, locations[ds_restrict]);
13725 :
13726 1092299210 : return loc;
13727 : }
13728 :
13729 : /* Returns the smallest among the latter and locations[ds_type_spec]. */
13730 :
13731 : static location_t
13732 1092299189 : smallest_type_location (int type_quals, const location_t* locations)
13733 : {
13734 1092299189 : location_t loc = smallest_type_quals_location (type_quals, locations);
13735 1092299189 : return min_location (loc, locations[ds_type_spec]);
13736 : }
13737 :
13738 : static location_t
13739 26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
13740 : {
13741 26 : int type_quals = get_type_quals (declspecs);
13742 26 : return smallest_type_location (type_quals, declspecs->locations);
13743 : }
13744 :
13745 : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
13746 : strip out the pointer/reference declarator(s). */
13747 :
13748 : static bool
13749 31026330 : maybe_strip_indirect_ref (const cp_declarator** declarator)
13750 : {
13751 31026330 : bool indirect_ref_p = false;
13752 62052807 : while (declarator && *declarator
13753 31026477 : && ((*declarator)->kind == cdk_pointer
13754 31026477 : || (*declarator)->kind == cdk_reference))
13755 : {
13756 147 : indirect_ref_p = true;
13757 147 : *declarator = (*declarator)->declarator;
13758 : }
13759 31026330 : return indirect_ref_p;
13760 : }
13761 :
13762 : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
13763 : and DECLARATOR. SFK indicates the kind of special function (if any) that
13764 : this function is. OPTYPE is the type given in a conversion operator
13765 : declaration, or the class type for a constructor/destructor.
13766 : Returns the actual return type of the function; that may be different
13767 : than TYPE if an error occurs, or for certain special functions. */
13768 :
13769 : static tree
13770 31026330 : check_special_function_return_type (special_function_kind sfk,
13771 : tree type,
13772 : tree optype,
13773 : int type_quals,
13774 : const cp_declarator** declarator,
13775 : const location_t* locations)
13776 : {
13777 31026330 : gcc_assert (declarator);
13778 31026330 : location_t rettype_loc = (type
13779 31026330 : ? smallest_type_location (type_quals, locations)
13780 31026249 : : (*declarator)->id_loc);
13781 31026330 : switch (sfk)
13782 : {
13783 25298142 : case sfk_constructor:
13784 25298142 : if (maybe_strip_indirect_ref (declarator) || type)
13785 81 : error_at (rettype_loc,
13786 : "return type specification for constructor invalid");
13787 25298061 : else if (type_quals != TYPE_UNQUALIFIED)
13788 15 : error_at (smallest_type_quals_location (type_quals, locations),
13789 : "qualifiers are not allowed on constructor declaration");
13790 :
13791 25298142 : if (targetm.cxx.cdtor_returns_this ())
13792 0 : type = build_pointer_type (optype);
13793 : else
13794 25298142 : type = void_type_node;
13795 : break;
13796 :
13797 3388027 : case sfk_destructor:
13798 3388027 : if (maybe_strip_indirect_ref (declarator) || type)
13799 45 : error_at (rettype_loc,
13800 : "return type specification for destructor invalid");
13801 3387982 : else if (type_quals != TYPE_UNQUALIFIED)
13802 3 : error_at (smallest_type_quals_location (type_quals, locations),
13803 : "qualifiers are not allowed on destructor declaration");
13804 :
13805 : /* We can't use the proper return type here because we run into
13806 : problems with ambiguous bases and covariant returns. */
13807 3388027 : if (targetm.cxx.cdtor_returns_this ())
13808 0 : type = build_pointer_type (void_type_node);
13809 : else
13810 3388027 : type = void_type_node;
13811 : break;
13812 :
13813 1067350 : case sfk_conversion:
13814 1067350 : if (maybe_strip_indirect_ref (declarator) || type)
13815 42 : error_at (rettype_loc,
13816 : "return type specified for %<operator %T%>", optype);
13817 1067308 : else if (type_quals != TYPE_UNQUALIFIED)
13818 3 : error_at (smallest_type_quals_location (type_quals, locations),
13819 : "qualifiers are not allowed on declaration of "
13820 : "%<operator %T%>", optype);
13821 :
13822 : type = optype;
13823 : break;
13824 :
13825 1272811 : case sfk_deduction_guide:
13826 1272811 : if (maybe_strip_indirect_ref (declarator) || type)
13827 0 : error_at (rettype_loc,
13828 : "return type specified for deduction guide");
13829 1272811 : else if (type_quals != TYPE_UNQUALIFIED)
13830 0 : error_at (smallest_type_quals_location (type_quals, locations),
13831 : "qualifiers are not allowed on declaration of "
13832 : "deduction guide");
13833 1272811 : if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
13834 : {
13835 3 : error ("template template parameter %qT in declaration of "
13836 : "deduction guide", optype);
13837 3 : type = error_mark_node;
13838 : }
13839 : else
13840 1272808 : type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
13841 34365897 : for (int i = 0; i < ds_last; ++i)
13842 33093086 : if (i != ds_explicit && locations[i])
13843 3 : error_at (locations[i],
13844 : "%<decl-specifier%> in declaration of deduction guide");
13845 : break;
13846 :
13847 0 : default:
13848 0 : gcc_unreachable ();
13849 : }
13850 :
13851 31026330 : return type;
13852 : }
13853 :
13854 : /* A variable or data member (whose unqualified name is IDENTIFIER)
13855 : has been declared with the indicated TYPE. If the TYPE is not
13856 : acceptable, issue an error message and return a type to use for
13857 : error-recovery purposes. */
13858 :
13859 : tree
13860 343077854 : check_var_type (tree identifier, tree type, location_t loc)
13861 : {
13862 343077854 : if (VOID_TYPE_P (type))
13863 : {
13864 92 : if (!identifier)
13865 0 : error_at (loc, "unnamed variable or field declared void");
13866 92 : else if (identifier_p (identifier))
13867 : {
13868 92 : gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
13869 92 : error_at (loc, "variable or field %qE declared void",
13870 : identifier);
13871 : }
13872 : else
13873 0 : error_at (loc, "variable or field declared void");
13874 92 : type = error_mark_node;
13875 : }
13876 :
13877 343077854 : return type;
13878 : }
13879 :
13880 : /* Handle declaring DECL as an inline variable. */
13881 :
13882 : static void
13883 7021818 : mark_inline_variable (tree decl, location_t loc)
13884 : {
13885 7021818 : bool inlinep = true;
13886 7021818 : if (! toplevel_bindings_p ())
13887 : {
13888 24 : error_at (loc, "%<inline%> specifier invalid for variable "
13889 : "%qD declared at block scope", decl);
13890 24 : inlinep = false;
13891 : }
13892 7021794 : else if (cxx_dialect < cxx17)
13893 658 : pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
13894 : "with %<-std=c++17%> or %<-std=gnu++17%>");
13895 682 : if (inlinep)
13896 : {
13897 7021794 : retrofit_lang_decl (decl);
13898 7021794 : SET_DECL_VAR_DECLARED_INLINE_P (decl);
13899 : }
13900 7021818 : }
13901 :
13902 :
13903 : /* Diagnose -Wnon-c-typedef-for-linkage pedwarn. TYPE is the unnamed class
13904 : with a typedef name for linkage purposes with freshly updated TYPE_NAME,
13905 : ORIG is the anonymous TYPE_NAME before that change. */
13906 :
13907 : static bool
13908 42 : diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
13909 : {
13910 42 : gcc_rich_location richloc (DECL_SOURCE_LOCATION (orig));
13911 42 : tree name = DECL_NAME (TYPE_NAME (type));
13912 42 : richloc.add_fixit_insert_before (IDENTIFIER_POINTER (name));
13913 42 : return pedwarn (&richloc, OPT_Wnon_c_typedef_for_linkage,
13914 : "anonymous non-C-compatible type given name for linkage "
13915 42 : "purposes by %<typedef%> declaration");
13916 42 : }
13917 :
13918 : /* Diagnose -Wnon-c-typedef-for-linkage violations on T. TYPE and ORIG
13919 : like for diagnose_non_c_class_typedef_for_linkage, T is initially equal
13920 : to TYPE but during recursion can be set to nested classes. */
13921 :
13922 : static bool
13923 539855 : maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
13924 : {
13925 539855 : if (!COMPLETE_TYPE_P (t))
13926 : return false;
13927 539852 : if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
13928 : {
13929 6 : auto_diagnostic_group d;
13930 6 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13931 9 : inform (type == t ? DECL_SOURCE_LOCATION (orig)
13932 3 : : DECL_SOURCE_LOCATION (TYPE_NAME (t)),
13933 : "type is not C-compatible because it has a base class");
13934 6 : return true;
13935 6 : }
13936 2531101 : for (tree field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
13937 1991316 : switch (TREE_CODE (field))
13938 : {
13939 9 : case VAR_DECL:
13940 : /* static data members have been diagnosed already. */
13941 9 : continue;
13942 1323717 : case FIELD_DECL:
13943 1323717 : if (DECL_INITIAL (field))
13944 : {
13945 4 : auto_diagnostic_group d;
13946 4 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13947 4 : inform (DECL_SOURCE_LOCATION (field),
13948 : "type is not C-compatible because %qD has default "
13949 : "member initializer", field);
13950 4 : return true;
13951 4 : }
13952 1323713 : continue;
13953 9 : case CONST_DECL:
13954 9 : continue;
13955 667500 : case TYPE_DECL:
13956 667500 : if (DECL_SELF_REFERENCE_P (field))
13957 539820 : continue;
13958 127680 : if (DECL_IMPLICIT_TYPEDEF_P (field))
13959 : {
13960 127670 : if (TREE_CODE (TREE_TYPE (field)) == ENUMERAL_TYPE)
13961 3 : continue;
13962 127667 : if (CLASS_TYPE_P (TREE_TYPE (field)))
13963 : {
13964 127667 : tree tf = TREE_TYPE (field);
13965 127667 : if (maybe_diagnose_non_c_class_typedef_for_linkage (type, orig,
13966 : tf))
13967 : return true;
13968 127642 : continue;
13969 127642 : }
13970 : }
13971 : /* FALLTHRU */
13972 32 : case FUNCTION_DECL:
13973 32 : case TEMPLATE_DECL:
13974 32 : {
13975 32 : auto_diagnostic_group d;
13976 32 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13977 32 : inform (DECL_SOURCE_LOCATION (field),
13978 : "type is not C-compatible because it contains %qD "
13979 : "declaration", field);
13980 32 : return true;
13981 32 : }
13982 : default:
13983 : break;
13984 1323731 : }
13985 : return false;
13986 : }
13987 :
13988 : /* Assign a typedef-given name to a class or enumeration type declared
13989 : as anonymous at first. This was split out of grokdeclarator
13990 : because it is also used in libcc1. */
13991 :
13992 : void
13993 413985 : name_unnamed_type (tree type, tree decl)
13994 : {
13995 1241955 : gcc_assert (TYPE_UNNAMED_P (type)
13996 : || enum_with_enumerator_for_linkage_p (type));
13997 :
13998 413985 : tree orig = TYPE_NAME (type);
13999 413985 : if (flag_reflection)
14000 : {
14001 : /* For -freflection for typedef struct { ... } S; ^^S needs to be
14002 : a reflection of a type alias. So, TREE_TYPE (DECL) can't be
14003 : TYPE. Instead of what we do below, override DECL_NAME (orig). */
14004 15934 : DECL_NAME (orig) = DECL_NAME (decl);
14005 15934 : TYPE_DECL_FOR_LINKAGE_PURPOSES_P (orig) = 1;
14006 : }
14007 : else
14008 : /* Replace the anonymous decl with the real decl. Be careful not to
14009 : rename other typedefs (such as the self-reference) of type. */
14010 1192437 : for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
14011 794386 : if (TYPE_NAME (t) == orig)
14012 398051 : TYPE_NAME (t) = decl;
14013 413985 : TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl) = 1;
14014 :
14015 : /* If this is a typedef within a template class, the nested
14016 : type is a (non-primary) template. The name for the
14017 : template needs updating as well. */
14018 413985 : if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
14019 68 : DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
14020 :
14021 : /* Adjust linkage now that we aren't unnamed anymore. */
14022 413985 : reset_type_linkage (type);
14023 :
14024 413985 : if (CLASS_TYPE_P (type) && warn_non_c_typedef_for_linkage)
14025 412188 : maybe_diagnose_non_c_class_typedef_for_linkage (type, orig, type);
14026 :
14027 : /* FIXME remangle member functions; member functions of a
14028 : type with external linkage have external linkage. */
14029 :
14030 : /* Check that our job is done, and that it would fail if we
14031 : attempted to do it again. */
14032 827970 : gcc_assert (!TYPE_UNNAMED_P (type)
14033 : && !enum_with_enumerator_for_linkage_p (type));
14034 413985 : }
14035 :
14036 : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
14037 : is allowed. TYPE might contain a decltype(auto). Returns true if
14038 : there was a problem, false otherwise. */
14039 :
14040 : static bool
14041 664960733 : check_decltype_auto (location_t loc, tree type)
14042 : {
14043 664960733 : if (tree a = type_uses_auto (type))
14044 : {
14045 18641720 : if (AUTO_IS_DECLTYPE (a))
14046 : {
14047 639639 : if (a != type)
14048 : {
14049 33 : error_at (loc, "%qT as type rather than plain "
14050 : "%<decltype(auto)%>", type);
14051 33 : return true;
14052 : }
14053 639606 : else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
14054 : {
14055 37 : error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
14056 37 : return true;
14057 : }
14058 : }
14059 : }
14060 : return false;
14061 : }
14062 :
14063 : /* Issue an error about two mutually incompatible declspecs
14064 : with the given names and locations
14065 : e.g. "error: `signed' and `unsigned' specified together" */
14066 :
14067 : static void
14068 66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
14069 : const char *name_b, location_t loc_b)
14070 : {
14071 66 : gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
14072 66 : richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
14073 : nullptr, highlight_colors::rhs);
14074 66 : pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
14075 66 : pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
14076 66 : error_at (&richloc, "%e and %e specified together",
14077 : &e_name_a, &e_name_b);
14078 66 : }
14079 :
14080 : /* Given declspecs and a declarator (abstract or otherwise), determine
14081 : the name and type of the object declared and construct a DECL node
14082 : for it.
14083 :
14084 : DECLSPECS points to the representation of declaration-specifier
14085 : sequence that precedes declarator.
14086 :
14087 : DECL_CONTEXT says which syntactic context this declaration is in:
14088 : NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
14089 : FUNCDEF for a function definition. Like NORMAL but a few different
14090 : error messages in each case. Return value may be zero meaning
14091 : this definition is too screwy to try to parse.
14092 : MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
14093 : handle member functions (which have FIELD context).
14094 : Return value may be zero meaning this definition is too screwy to
14095 : try to parse.
14096 : PARM for a parameter declaration (either within a function prototype
14097 : or before a function body). Make a PARM_DECL, or return void_type_node.
14098 : TPARM for a template parameter declaration.
14099 : CATCHPARM for a parameter declaration before a catch clause.
14100 : TYPENAME if for a typename (in a cast or sizeof).
14101 : Don't make a DECL node; just return the ..._TYPE node.
14102 : FIELD for a struct or union field; make a FIELD_DECL.
14103 : BITFIELD for a field with specified width.
14104 :
14105 : INITIALIZED is as for start_decl.
14106 :
14107 : ATTRLIST is a pointer to the list of attributes, which may be NULL
14108 : if there are none; *ATTRLIST may be modified if attributes from inside
14109 : the declarator should be applied to the declaration.
14110 :
14111 : When this function is called, scoping variables (such as
14112 : CURRENT_CLASS_TYPE) should reflect the scope in which the
14113 : declaration occurs, not the scope in which the new declaration will
14114 : be placed. For example, on:
14115 :
14116 : void S::f() { ... }
14117 :
14118 : when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
14119 : should not be `S'.
14120 :
14121 : Returns a DECL (if a declarator is present), a TYPE (if there is no
14122 : declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
14123 : error occurs. */
14124 :
14125 : tree
14126 1092299082 : grokdeclarator (const cp_declarator *declarator,
14127 : cp_decl_specifier_seq *declspecs,
14128 : enum decl_context decl_context,
14129 : int initialized,
14130 : tree* attrlist)
14131 : {
14132 1092299082 : tree type = NULL_TREE;
14133 1092299082 : int longlong = 0;
14134 1092299082 : int explicit_intN = 0;
14135 1092299082 : int int_n_alt = 0;
14136 1092299082 : int virtualp, explicitp, friendp, inlinep, staticp;
14137 1092299082 : int explicit_int = 0;
14138 1092299082 : int explicit_char = 0;
14139 1092299082 : int defaulted_int = 0;
14140 :
14141 1092299082 : tree typedef_decl = NULL_TREE;
14142 1092299082 : const char *name = NULL;
14143 1092299082 : tree typedef_type = NULL_TREE;
14144 : /* True if this declarator is a function definition. */
14145 1092299082 : bool funcdef_flag = false;
14146 1092299082 : cp_declarator_kind innermost_code = cdk_error;
14147 1092299082 : int bitfield = 0;
14148 : #if 0
14149 : /* See the code below that used this. */
14150 : tree decl_attr = NULL_TREE;
14151 : #endif
14152 :
14153 : /* Keep track of what sort of function is being processed
14154 : so that we can warn about default return values, or explicit
14155 : return values which do not match prescribed defaults. */
14156 1092299082 : special_function_kind sfk = sfk_none;
14157 :
14158 1092299082 : tree dname = NULL_TREE;
14159 1092299082 : tree ctor_return_type = NULL_TREE;
14160 1092299082 : enum overload_flags flags = NO_SPECIAL;
14161 : /* cv-qualifiers that apply to the declarator, for a declaration of
14162 : a member function. */
14163 1092299082 : cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
14164 : /* virt-specifiers that apply to the declarator, for a declaration of
14165 : a member function. */
14166 1092299082 : cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
14167 : /* ref-qualifier that applies to the declarator, for a declaration of
14168 : a member function. */
14169 1092299082 : cp_ref_qualifier rqual = REF_QUAL_NONE;
14170 : /* cv-qualifiers that apply to the type specified by the DECLSPECS. */
14171 1092299082 : int type_quals = get_type_quals (declspecs);
14172 1092299082 : tree raises = NULL_TREE;
14173 1092299082 : int template_count = 0;
14174 1092299082 : tree returned_attrs = NULL_TREE;
14175 1092299082 : tree contract_specifiers = NULL_TREE;
14176 1092299082 : tree parms = NULL_TREE;
14177 1092299082 : const cp_declarator *id_declarator;
14178 : /* The unqualified name of the declarator; either an
14179 : IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR. */
14180 1092299082 : tree unqualified_id;
14181 : /* The class type, if any, in which this entity is located,
14182 : or NULL_TREE if none. Note that this value may be different from
14183 : the current class type; for example if an attempt is made to declare
14184 : "A::f" inside "B", this value will be "A". */
14185 1092299082 : tree ctype = current_class_type;
14186 : /* The NAMESPACE_DECL for the namespace in which this entity is
14187 : located. If an unqualified name is used to declare the entity,
14188 : this value will be NULL_TREE, even if the entity is located at
14189 : namespace scope. */
14190 1092299082 : tree in_namespace = NULL_TREE;
14191 1092299082 : cp_storage_class storage_class;
14192 1092299082 : bool unsigned_p, signed_p, short_p, long_p, thread_p;
14193 1092299082 : bool type_was_error_mark_node = false;
14194 1092299082 : bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
14195 1092299082 : bool template_type_arg = false;
14196 1092299082 : bool template_parm_flag = false;
14197 1092299082 : bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
14198 1092299082 : bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
14199 1092299082 : bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
14200 1092299082 : bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
14201 1092299082 : bool late_return_type_p = false;
14202 1092299082 : bool array_parameter_p = false;
14203 1092299082 : tree reqs = NULL_TREE;
14204 :
14205 1092299082 : signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
14206 1092299082 : unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
14207 1092299082 : short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
14208 1092299082 : long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
14209 1092299082 : longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
14210 1092299082 : explicit_intN = declspecs->explicit_intN_p;
14211 1092299082 : int_n_alt = declspecs->int_n_alt;
14212 1092299082 : thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
14213 :
14214 : // Was concept_p specified? Note that ds_concept
14215 : // implies ds_constexpr!
14216 1092299082 : bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
14217 1092299082 : if (concept_p)
14218 117 : constexpr_p = true;
14219 :
14220 1092299082 : if (decl_context == FUNCDEF)
14221 : funcdef_flag = true, decl_context = NORMAL;
14222 : else if (decl_context == MEMFUNCDEF)
14223 : funcdef_flag = true, decl_context = FIELD;
14224 : else if (decl_context == BITFIELD)
14225 : bitfield = 1, decl_context = FIELD;
14226 : else if (decl_context == TEMPLATE_TYPE_ARG)
14227 : template_type_arg = true, decl_context = TYPENAME;
14228 : else if (decl_context == TPARM)
14229 11670328 : template_parm_flag = true, decl_context = PARM;
14230 :
14231 1092299082 : if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
14232 11485473 : funcdef_flag = true;
14233 :
14234 1092299082 : location_t typespec_loc = loc_or_input_loc (smallest_type_location
14235 : (type_quals,
14236 1092299082 : declspecs->locations));
14237 1092299082 : location_t id_loc;
14238 1092299082 : location_t init_loc;
14239 1092299082 : if (declarator)
14240 : {
14241 658995783 : id_loc = loc_or_input_loc (declarator->id_loc);
14242 658995783 : init_loc = loc_or_input_loc (declarator->init_loc);
14243 : }
14244 : else
14245 433303299 : init_loc = id_loc = input_location;
14246 :
14247 : /* Look inside a declarator for the name being declared
14248 : and get it as a string, for an error message. */
14249 1092299082 : for (id_declarator = declarator;
14250 1499832511 : id_declarator;
14251 407533429 : id_declarator = id_declarator->declarator)
14252 : {
14253 1022513466 : if (id_declarator->kind != cdk_id)
14254 407533454 : innermost_code = id_declarator->kind;
14255 :
14256 1022513466 : switch (id_declarator->kind)
14257 : {
14258 199997751 : case cdk_function:
14259 199997751 : if (id_declarator->declarator
14260 199604269 : && id_declarator->declarator->kind == cdk_id)
14261 : {
14262 197676507 : sfk = id_declarator->declarator->u.id.sfk;
14263 197676507 : if (sfk == sfk_destructor)
14264 3388030 : flags = DTOR_FLAG;
14265 : }
14266 : break;
14267 :
14268 614980012 : case cdk_id:
14269 614980012 : {
14270 614980012 : tree qualifying_scope = id_declarator->u.id.qualifying_scope;
14271 614980012 : tree decl = id_declarator->u.id.unqualified_name;
14272 614980012 : if (!decl)
14273 : break;
14274 614980012 : if (qualifying_scope)
14275 : {
14276 10179482 : if (check_for_bare_parameter_packs (qualifying_scope,
14277 10179482 : id_declarator->id_loc))
14278 6 : return error_mark_node;
14279 10179476 : if (at_function_scope_p ())
14280 : {
14281 : /* [dcl.meaning]
14282 :
14283 : A declarator-id shall not be qualified except
14284 : for ...
14285 :
14286 : None of the cases are permitted in block
14287 : scope. */
14288 0 : if (qualifying_scope == global_namespace)
14289 0 : error ("invalid use of qualified-name %<::%D%>",
14290 : decl);
14291 0 : else if (TYPE_P (qualifying_scope))
14292 0 : error ("invalid use of qualified-name %<%T::%D%>",
14293 : qualifying_scope, decl);
14294 : else
14295 0 : error ("invalid use of qualified-name %<%D::%D%>",
14296 : qualifying_scope, decl);
14297 0 : return error_mark_node;
14298 : }
14299 10179476 : else if (TYPE_P (qualifying_scope))
14300 : {
14301 9897661 : ctype = qualifying_scope;
14302 9897661 : if (!MAYBE_CLASS_TYPE_P (ctype))
14303 : {
14304 6 : error_at (id_declarator->id_loc,
14305 : "%q#T is not a class or namespace", ctype);
14306 6 : ctype = NULL_TREE;
14307 : }
14308 9897655 : else if (innermost_code != cdk_function
14309 523087 : && current_class_type
14310 9897670 : && !uniquely_derived_from_p (ctype,
14311 : current_class_type))
14312 : {
14313 9 : error_at (id_declarator->id_loc,
14314 : "invalid use of qualified-name %<%T::%D%>",
14315 : qualifying_scope, decl);
14316 9 : return error_mark_node;
14317 : }
14318 : }
14319 281815 : else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
14320 614979997 : in_namespace = qualifying_scope;
14321 : }
14322 614979997 : switch (TREE_CODE (decl))
14323 : {
14324 3388045 : case BIT_NOT_EXPR:
14325 3388045 : {
14326 3388045 : if (innermost_code != cdk_function)
14327 : {
14328 6 : error_at (EXPR_LOCATION (decl),
14329 : "declaration of %qE as non-function", decl);
14330 6 : return error_mark_node;
14331 : }
14332 3388039 : else if (!qualifying_scope
14333 3388039 : && !(current_class_type && at_class_scope_p ()))
14334 : {
14335 9 : error_at (EXPR_LOCATION (decl),
14336 : "declaration of %qE as non-member", decl);
14337 9 : return error_mark_node;
14338 : }
14339 :
14340 3388030 : tree type = TREE_OPERAND (decl, 0);
14341 3388030 : if (TYPE_P (type))
14342 3388027 : type = constructor_name (type);
14343 3388030 : name = identifier_to_locale (IDENTIFIER_POINTER (type));
14344 3388030 : dname = decl;
14345 : }
14346 3388030 : break;
14347 :
14348 3005022 : case TEMPLATE_ID_EXPR:
14349 3005022 : {
14350 3005022 : tree fns = TREE_OPERAND (decl, 0);
14351 :
14352 3005022 : dname = fns;
14353 4007234 : if (!identifier_p (dname))
14354 3004995 : dname = OVL_NAME (dname);
14355 : }
14356 : /* Fall through. */
14357 :
14358 611591952 : case IDENTIFIER_NODE:
14359 611591952 : if (identifier_p (decl))
14360 608586930 : dname = decl;
14361 :
14362 611591952 : if (IDENTIFIER_KEYWORD_P (dname))
14363 : {
14364 0 : error ("declarator-id missing; using reserved word %qD",
14365 : dname);
14366 0 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14367 : }
14368 611591952 : else if (!IDENTIFIER_CONV_OP_P (dname))
14369 610524599 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14370 : else
14371 : {
14372 1067353 : gcc_assert (flags == NO_SPECIAL);
14373 1067353 : flags = TYPENAME_FLAG;
14374 1067353 : sfk = sfk_conversion;
14375 1067353 : tree glob = get_global_binding (dname);
14376 1067353 : if (glob && TREE_CODE (glob) == TYPE_DECL)
14377 0 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14378 : else
14379 : name = "<invalid operator>";
14380 : }
14381 : break;
14382 :
14383 0 : default:
14384 0 : gcc_unreachable ();
14385 : }
14386 : break;
14387 : }
14388 :
14389 : case cdk_array:
14390 : case cdk_pointer:
14391 : case cdk_reference:
14392 : case cdk_ptrmem:
14393 : break;
14394 :
14395 : case cdk_decomp:
14396 1022513411 : name = "structured binding";
14397 : break;
14398 :
14399 25 : case cdk_error:
14400 25 : return error_mark_node;
14401 :
14402 0 : default:
14403 0 : gcc_unreachable ();
14404 : }
14405 1022513411 : if (id_declarator->kind == cdk_id)
14406 : break;
14407 : }
14408 :
14409 : /* [dcl.fct.edf]
14410 :
14411 : The declarator in a function-definition shall have the form
14412 : D1 ( parameter-declaration-clause) ... */
14413 1092299027 : if (funcdef_flag && innermost_code != cdk_function)
14414 : {
14415 3 : error_at (id_loc, "function definition does not declare parameters");
14416 3 : return error_mark_node;
14417 : }
14418 :
14419 1092299024 : if (flags == TYPENAME_FLAG
14420 1092299024 : && innermost_code != cdk_function
14421 3 : && ! (ctype && !declspecs->any_specifiers_p))
14422 : {
14423 3 : error_at (id_loc, "declaration of %qD as non-function", dname);
14424 3 : return error_mark_node;
14425 : }
14426 :
14427 1092299021 : if (dname && identifier_p (dname))
14428 : {
14429 611591946 : if (UDLIT_OPER_P (dname)
14430 611591946 : && innermost_code != cdk_function)
14431 : {
14432 6 : error_at (id_loc, "declaration of %qD as non-function", dname);
14433 6 : return error_mark_node;
14434 : }
14435 :
14436 611591940 : if (IDENTIFIER_ANY_OP_P (dname))
14437 : {
14438 38961612 : if (typedef_p)
14439 : {
14440 3 : error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
14441 3 : return error_mark_node;
14442 : }
14443 38961609 : else if (decl_context == PARM || decl_context == CATCHPARM)
14444 : {
14445 15 : error_at (id_loc, "declaration of %qD as parameter", dname);
14446 15 : return error_mark_node;
14447 : }
14448 : }
14449 : }
14450 :
14451 : /* Anything declared one level down from the top level
14452 : must be one of the parameters of a function
14453 : (because the body is at least two levels down). */
14454 :
14455 : /* This heuristic cannot be applied to C++ nodes! Fixed, however,
14456 : by not allowing C++ class definitions to specify their parameters
14457 : with xdecls (must be spec.d in the parmlist).
14458 :
14459 : Since we now wait to push a class scope until we are sure that
14460 : we are in a legitimate method context, we must set oldcname
14461 : explicitly (since current_class_name is not yet alive).
14462 :
14463 : We also want to avoid calling this a PARM if it is in a namespace. */
14464 :
14465 1092298997 : if (decl_context == NORMAL && !toplevel_bindings_p ())
14466 : {
14467 75690674 : cp_binding_level *b = current_binding_level;
14468 75690674 : current_binding_level = b->level_chain;
14469 75690674 : if (current_binding_level != 0 && toplevel_bindings_p ())
14470 : decl_context = PARM;
14471 75690674 : current_binding_level = b;
14472 : }
14473 :
14474 1092298997 : if (name == NULL)
14475 477071239 : name = decl_context == PARM ? "parameter" : "type name";
14476 :
14477 1092298997 : if (consteval_p && constexpr_p)
14478 : {
14479 6 : error_at (declspecs->locations[ds_consteval],
14480 : "both %qs and %qs specified", "constexpr", "consteval");
14481 6 : return error_mark_node;
14482 : }
14483 :
14484 1092298991 : if (concept_p && typedef_p)
14485 : {
14486 9 : error_at (declspecs->locations[ds_concept],
14487 : "%qs cannot appear in a typedef declaration", "concept");
14488 9 : return error_mark_node;
14489 : }
14490 :
14491 1092298982 : if (constexpr_p && typedef_p)
14492 : {
14493 3 : error_at (declspecs->locations[ds_constexpr],
14494 : "%qs cannot appear in a typedef declaration", "constexpr");
14495 3 : return error_mark_node;
14496 : }
14497 :
14498 1092298979 : if (consteval_p && typedef_p)
14499 : {
14500 3 : error_at (declspecs->locations[ds_consteval],
14501 : "%qs cannot appear in a typedef declaration", "consteval");
14502 3 : return error_mark_node;
14503 : }
14504 :
14505 1092298976 : if (constinit_p && typedef_p)
14506 : {
14507 3 : error_at (declspecs->locations[ds_constinit],
14508 : "%qs cannot appear in a typedef declaration", "constinit");
14509 3 : return error_mark_node;
14510 : }
14511 :
14512 : /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
14513 : keywords shall appear in a decl-specifier-seq." */
14514 1092298973 : if (constinit_p && constexpr_p)
14515 : {
14516 6 : gcc_rich_location richloc (declspecs->locations[ds_constinit]);
14517 6 : richloc.add_range (declspecs->locations[ds_constexpr]);
14518 6 : error_at (&richloc,
14519 : "can use at most one of the %<constinit%> and %<constexpr%> "
14520 : "specifiers");
14521 6 : return error_mark_node;
14522 6 : }
14523 :
14524 : /* If there were multiple types specified in the decl-specifier-seq,
14525 : issue an error message. */
14526 1092298967 : if (declspecs->multiple_types_p)
14527 : {
14528 1501 : error_at (typespec_loc,
14529 : "two or more data types in declaration of %qs", name);
14530 1501 : return error_mark_node;
14531 : }
14532 :
14533 1092297466 : if (declspecs->conflicting_specifiers_p)
14534 31 : return error_mark_node;
14535 :
14536 : /* Extract the basic type from the decl-specifier-seq. */
14537 1092297435 : type = declspecs->type;
14538 1092297435 : if (type == error_mark_node)
14539 : {
14540 1243 : type = NULL_TREE;
14541 1243 : type_was_error_mark_node = true;
14542 : }
14543 :
14544 : /* Ignore erroneous attributes. */
14545 1092297435 : if (attrlist && *attrlist == error_mark_node)
14546 12 : *attrlist = NULL_TREE;
14547 :
14548 : /* An object declared as __attribute__((unavailable)) suppresses
14549 : any reports of being declared with unavailable or deprecated
14550 : items. An object declared as __attribute__((deprecated))
14551 : suppresses warnings of uses of other deprecated items. */
14552 1092297435 : auto ds = make_temp_override (deprecated_state);
14553 1092297435 : if (attrlist && lookup_attribute ("unavailable", *attrlist))
14554 171 : deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
14555 1092297264 : else if (attrlist && lookup_attribute ("deprecated", *attrlist))
14556 977572 : deprecated_state = DEPRECATED_SUPPRESS;
14557 :
14558 1092297435 : cp_handle_deprecated_or_unavailable (type);
14559 1092297435 : if (type && TREE_CODE (type) == TYPE_DECL)
14560 : {
14561 760709272 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
14562 760709272 : typedef_decl = type;
14563 760709272 : type = TREE_TYPE (typedef_decl);
14564 760709272 : if (DECL_ARTIFICIAL (typedef_decl))
14565 552560088 : cp_handle_deprecated_or_unavailable (type);
14566 : }
14567 : /* No type at all: default to `int', and set DEFAULTED_INT
14568 : because it was not a user-defined typedef. */
14569 1092297435 : if (type == NULL_TREE)
14570 : {
14571 40624126 : if (signed_p || unsigned_p || long_p || short_p)
14572 : {
14573 : /* These imply 'int'. */
14574 9596153 : type = integer_type_node;
14575 9596153 : defaulted_int = 1;
14576 : }
14577 : /* If we just have "complex", it is equivalent to "complex double". */
14578 31027973 : else if (!longlong && !explicit_intN
14579 31027973 : && decl_spec_seq_has_spec_p (declspecs, ds_complex))
14580 : {
14581 81 : type = double_type_node;
14582 81 : pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
14583 : "ISO C++ does not support plain %<complex%> meaning "
14584 : "%<double complex%>");
14585 : }
14586 : }
14587 : /* Gather flags. */
14588 1092297435 : explicit_int = declspecs->explicit_int_p;
14589 1092297435 : explicit_char = declspecs->explicit_char_p;
14590 :
14591 : #if 0
14592 : /* See the code below that used this. */
14593 : if (typedef_decl)
14594 : decl_attr = DECL_ATTRIBUTES (typedef_decl);
14595 : #endif
14596 1092297435 : typedef_type = type;
14597 :
14598 1092297435 : if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
14599 2340161 : ctor_return_type = TREE_TYPE (dname);
14600 : else
14601 : ctor_return_type = ctype;
14602 :
14603 1092297435 : if (sfk != sfk_none)
14604 : {
14605 31026330 : type = check_special_function_return_type (sfk, type,
14606 : ctor_return_type,
14607 : type_quals,
14608 : &declarator,
14609 : declspecs->locations);
14610 31026330 : type_quals = TYPE_UNQUALIFIED;
14611 : }
14612 1061271105 : else if (type == NULL_TREE)
14613 : {
14614 1643 : int is_main;
14615 :
14616 1643 : explicit_int = -1;
14617 :
14618 : /* We handle `main' specially here, because 'main () { }' is so
14619 : common. With no options, it is allowed. With -Wreturn-type,
14620 : it is a warning. It is only an error with -pedantic-errors. */
14621 3286 : is_main = (funcdef_flag
14622 3520 : && dname && identifier_p (dname)
14623 234 : && MAIN_NAME_P (dname)
14624 68 : && ctype == NULL_TREE
14625 68 : && in_namespace == NULL_TREE
14626 1711 : && current_namespace == global_namespace);
14627 :
14628 1643 : if (type_was_error_mark_node)
14629 : /* We've already issued an error, don't complain more. */;
14630 400 : else if (in_system_header_at (id_loc) || flag_ms_extensions)
14631 : /* Allow it, sigh. */;
14632 338 : else if (! is_main)
14633 276 : permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
14634 : name);
14635 62 : else if (pedantic)
14636 4 : pedwarn (id_loc, OPT_Wpedantic,
14637 : "ISO C++ forbids declaration of %qs with no type", name);
14638 : else
14639 58 : warning_at (id_loc, OPT_Wreturn_type,
14640 : "ISO C++ forbids declaration of %qs with no type", name);
14641 :
14642 1643 : if (type_was_error_mark_node && template_parm_flag)
14643 : /* FIXME we should be able to propagate the error_mark_node as is
14644 : for other contexts too. */
14645 162 : type = error_mark_node;
14646 : else
14647 1481 : type = integer_type_node;
14648 : }
14649 :
14650 1092297435 : ctype = NULL_TREE;
14651 :
14652 1092297435 : if (explicit_intN)
14653 : {
14654 1156104 : if (! int_n_enabled_p[declspecs->int_n_idx])
14655 : {
14656 0 : error_at (declspecs->locations[ds_type_spec],
14657 : "%<__int%d%> is not supported by this target",
14658 0 : int_n_data[declspecs->int_n_idx].bitsize);
14659 0 : explicit_intN = false;
14660 : }
14661 : /* Don't pedwarn if the alternate "__intN__" form has been used instead
14662 : of "__intN". */
14663 1156104 : else if (!int_n_alt && pedantic)
14664 9951 : pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
14665 : "ISO C++ does not support %<__int%d%> for %qs",
14666 9951 : int_n_data[declspecs->int_n_idx].bitsize, name);
14667 : }
14668 :
14669 : /* Now process the modifiers that were specified
14670 : and check for invalid combinations. */
14671 :
14672 : /* Long double is a special combination. */
14673 1092297435 : if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
14674 : {
14675 9242097 : long_p = false;
14676 9242097 : type = cp_build_qualified_type (long_double_type_node,
14677 : cp_type_quals (type));
14678 : }
14679 :
14680 : /* Check all other uses of type modifiers. */
14681 :
14682 1092297435 : if (unsigned_p || signed_p || long_p || short_p)
14683 : {
14684 22124309 : location_t loc;
14685 22124309 : const char *key;
14686 22124309 : if (unsigned_p)
14687 : {
14688 15050338 : key = "unsigned";
14689 15050338 : loc = declspecs->locations[ds_unsigned];
14690 : }
14691 7073971 : else if (signed_p)
14692 : {
14693 1077825 : key = "signed";
14694 1077825 : loc = declspecs->locations[ds_signed];
14695 : }
14696 5996146 : else if (longlong)
14697 : {
14698 2337740 : key = "long long";
14699 2337740 : loc = declspecs->locations[ds_long_long];
14700 : }
14701 3658406 : else if (long_p)
14702 : {
14703 3074836 : key = "long";
14704 3074836 : loc = declspecs->locations[ds_long];
14705 : }
14706 : else /* if (short_p) */
14707 : {
14708 583570 : key = "short";
14709 583570 : loc = declspecs->locations[ds_short];
14710 : }
14711 :
14712 22124309 : int ok = 0;
14713 :
14714 22124309 : if (signed_p && unsigned_p)
14715 54 : complain_about_incompatible_declspecs
14716 54 : ("signed", declspecs->locations[ds_signed],
14717 : "unsigned", declspecs->locations[ds_unsigned]);
14718 22124255 : else if (long_p && short_p)
14719 12 : complain_about_incompatible_declspecs
14720 12 : ("long", declspecs->locations[ds_long],
14721 : "short", declspecs->locations[ds_short]);
14722 22124243 : else if (TREE_CODE (type) != INTEGER_TYPE
14723 22124230 : || type == char8_type_node
14724 22124206 : || type == char16_type_node
14725 22124182 : || type == char32_type_node
14726 22124158 : || ((long_p || short_p)
14727 11630566 : && (explicit_char || explicit_intN)))
14728 418 : error_at (loc, "%qs specified with %qT", key, type);
14729 22123825 : else if (!explicit_int && !defaulted_int
14730 22123825 : && !explicit_char && !explicit_intN)
14731 : {
14732 30 : if (typedef_decl)
14733 : {
14734 27 : pedwarn (loc, OPT_Wpedantic,
14735 : "%qs specified with typedef-name %qD",
14736 : key, typedef_decl);
14737 27 : ok = !flag_pedantic_errors;
14738 : /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
14739 : and is not built as a typedef. */
14740 27 : if (is_typedef_decl (typedef_decl))
14741 18 : type = DECL_ORIGINAL_TYPE (typedef_decl);
14742 : }
14743 3 : else if (declspecs->decltype_p)
14744 0 : error_at (loc, "%qs specified with %<decltype%>", key);
14745 : else
14746 3 : error_at (loc, "%qs specified with %<typeof%>", key);
14747 : }
14748 : else
14749 : ok = 1;
14750 :
14751 : /* Discard the type modifiers if they are invalid. */
14752 514 : if (! ok)
14753 : {
14754 : unsigned_p = false;
14755 : signed_p = false;
14756 : long_p = false;
14757 : short_p = false;
14758 : longlong = 0;
14759 : }
14760 : }
14761 :
14762 : /* Decide whether an integer type is signed or not.
14763 : Optionally treat bitfields as signed by default. */
14764 1092296945 : if (unsigned_p
14765 : /* [class.bit]
14766 :
14767 : It is implementation-defined whether a plain (neither
14768 : explicitly signed or unsigned) char, short, int, or long
14769 : bit-field is signed or unsigned.
14770 :
14771 : Naturally, we extend this to long long as well. Note that
14772 : this does not include wchar_t. */
14773 1092297435 : || (bitfield && !flag_signed_bitfields
14774 18 : && !signed_p
14775 : /* A typedef for plain `int' without `signed' can be
14776 : controlled just like plain `int', but a typedef for
14777 : `signed int' cannot be so controlled. */
14778 18 : && !(typedef_decl
14779 18 : && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
14780 13 : && TREE_CODE (type) == INTEGER_TYPE
14781 10 : && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
14782 : {
14783 15050123 : if (explicit_intN)
14784 541001 : type = int_n_trees[declspecs->int_n_idx].unsigned_type;
14785 14509122 : else if (longlong)
14786 1489805 : type = long_long_unsigned_type_node;
14787 13019317 : else if (long_p)
14788 2447493 : type = long_unsigned_type_node;
14789 10571824 : else if (short_p)
14790 1479950 : type = short_unsigned_type_node;
14791 9091874 : else if (type == char_type_node)
14792 1981778 : type = unsigned_char_type_node;
14793 7110096 : else if (typedef_decl)
14794 25 : type = c_common_unsigned_type (type);
14795 : else
14796 7110071 : type = unsigned_type_node;
14797 : }
14798 1077247312 : else if (signed_p && type == char_type_node)
14799 710737 : type = signed_char_type_node;
14800 1076536575 : else if (explicit_intN)
14801 615103 : type = int_n_trees[declspecs->int_n_idx].signed_type;
14802 1075921472 : else if (longlong)
14803 2403318 : type = long_long_integer_type_node;
14804 1073518154 : else if (long_p)
14805 3144899 : type = long_integer_type_node;
14806 1070373255 : else if (short_p)
14807 664768 : type = short_integer_type_node;
14808 1069708487 : else if (signed_p && typedef_decl)
14809 9 : type = c_common_signed_type (type);
14810 :
14811 1092297435 : if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
14812 : {
14813 1280890 : if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
14814 3 : error_at (declspecs->locations[ds_complex],
14815 : "complex invalid for %qs", name);
14816 : /* If a modifier is specified, the resulting complex is the complex
14817 : form of TYPE. E.g, "complex short" is "complex short int". */
14818 1280887 : else if (type == integer_type_node)
14819 171 : type = complex_integer_type_node;
14820 1280716 : else if (type == float_type_node)
14821 349961 : type = complex_float_type_node;
14822 930755 : else if (type == double_type_node)
14823 350505 : type = complex_double_type_node;
14824 580250 : else if (type == long_double_type_node)
14825 350002 : type = complex_long_double_type_node;
14826 : else
14827 230248 : type = build_complex_type (type);
14828 : }
14829 :
14830 : /* If we're using the injected-class-name to form a compound type or a
14831 : declaration, replace it with the underlying class so we don't get
14832 : redundant typedefs in the debug output. But if we are returning the
14833 : type unchanged, leave it alone so that it's available to
14834 : maybe_get_template_decl_from_type_decl. */
14835 213758486 : if (CLASS_TYPE_P (type)
14836 213693156 : && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
14837 36801331 : && type == TREE_TYPE (TYPE_NAME (type))
14838 1129098766 : && (declarator || type_quals))
14839 35151009 : type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
14840 :
14841 1092297435 : type_quals |= cp_type_quals (type);
14842 2184594870 : type = cp_build_qualified_type
14843 2184594870 : (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
14844 884148251 : || declspecs->decltype_p)
14845 : ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
14846 : /* We might have ignored or rejected some of the qualifiers. */
14847 1092297435 : type_quals = cp_type_quals (type);
14848 :
14849 1076349154 : if (cxx_dialect >= cxx17 && type && is_auto (type)
14850 23920200 : && innermost_code != cdk_function
14851 : /* Placeholder in parm gets a better error below. */
14852 14865085 : && !(decl_context == PARM || decl_context == CATCHPARM)
14853 1107123896 : && id_declarator && declarator != id_declarator)
14854 1222995 : if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
14855 : {
14856 16 : auto_diagnostic_group g;
14857 16 : gcc_rich_location richloc (typespec_loc);
14858 16 : richloc.add_fixit_insert_after ("<>");
14859 16 : error_at (&richloc, "missing template argument list after %qE; "
14860 : "for deduction, template placeholder must be followed "
14861 : "by a simple declarator-id", tmpl);
14862 16 : inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
14863 16 : type = error_mark_node;
14864 16 : }
14865 :
14866 1092297435 : staticp = 0;
14867 1092297435 : inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
14868 1092297435 : virtualp = decl_spec_seq_has_spec_p (declspecs, ds_virtual);
14869 1092297435 : explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
14870 :
14871 1092297435 : storage_class = declspecs->storage_class;
14872 1092297435 : if (storage_class == sc_static)
14873 25128098 : staticp = 1 + (decl_context == FIELD);
14874 1067169337 : else if (decl_context == FIELD && sfk == sfk_deduction_guide)
14875 : /* Treat class-scope deduction guides as static member functions
14876 : so that they get a FUNCTION_TYPE instead of a METHOD_TYPE. */
14877 24782798 : staticp = 2;
14878 :
14879 1092297435 : if (virtualp)
14880 : {
14881 4298379 : if (staticp == 2)
14882 : {
14883 21 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
14884 21 : richloc.add_range (declspecs->locations[ds_storage_class]);
14885 21 : error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
14886 : "and %<static%>", dname);
14887 21 : storage_class = sc_none;
14888 21 : staticp = 0;
14889 21 : }
14890 4298379 : if (constexpr_p && pedantic && cxx_dialect < cxx20)
14891 : {
14892 6 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
14893 6 : richloc.add_range (declspecs->locations[ds_constexpr]);
14894 6 : pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
14895 : "declared both %<virtual%> and %<constexpr%> only in "
14896 : "%<-std=c++20%> or %<-std=gnu++20%>", dname);
14897 6 : }
14898 : }
14899 1092297435 : friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
14900 :
14901 : /* Issue errors about use of storage classes for parameters. */
14902 1092297435 : if (decl_context == PARM)
14903 : {
14904 308878002 : if (typedef_p)
14905 : {
14906 24 : error_at (declspecs->locations[ds_typedef],
14907 : "typedef declaration invalid in parameter declaration");
14908 24 : return error_mark_node;
14909 : }
14910 308877978 : else if (template_parm_flag && storage_class != sc_none)
14911 : {
14912 16 : error_at (min_location (declspecs->locations[ds_thread],
14913 : declspecs->locations[ds_storage_class]),
14914 : "storage class specified for template parameter %qs",
14915 : name);
14916 16 : return error_mark_node;
14917 : }
14918 308877962 : else if (storage_class == sc_static
14919 308877962 : || storage_class == sc_extern
14920 308877959 : || thread_p)
14921 : {
14922 9 : error_at (min_location (declspecs->locations[ds_thread],
14923 : declspecs->locations[ds_storage_class]),
14924 : "storage class specified for parameter %qs", name);
14925 9 : return error_mark_node;
14926 : }
14927 :
14928 : /* Function parameters cannot be concept. */
14929 308877953 : if (concept_p)
14930 : {
14931 9 : error_at (declspecs->locations[ds_concept],
14932 : "a parameter cannot be declared %qs", "concept");
14933 9 : concept_p = 0;
14934 9 : constexpr_p = 0;
14935 : }
14936 : /* Function parameters cannot be constexpr. If we saw one, moan
14937 : and pretend it wasn't there. */
14938 308877944 : else if (constexpr_p)
14939 : {
14940 9 : error_at (declspecs->locations[ds_constexpr],
14941 : "a parameter cannot be declared %qs", "constexpr");
14942 9 : constexpr_p = 0;
14943 : }
14944 308877953 : if (constinit_p)
14945 : {
14946 6 : error_at (declspecs->locations[ds_constinit],
14947 : "a parameter cannot be declared %qs", "constinit");
14948 6 : constinit_p = 0;
14949 : }
14950 308877953 : if (consteval_p)
14951 : {
14952 3 : error_at (declspecs->locations[ds_consteval],
14953 : "a parameter cannot be declared %qs", "consteval");
14954 3 : consteval_p = 0;
14955 : }
14956 : }
14957 :
14958 : /* Give error if `virtual' is used outside of class declaration. */
14959 1092297386 : if (virtualp
14960 4298379 : && (current_class_name == NULL_TREE || decl_context != FIELD))
14961 : {
14962 68 : error_at (declspecs->locations[ds_virtual],
14963 : "%<virtual%> outside class declaration");
14964 68 : virtualp = 0;
14965 : }
14966 :
14967 1092297386 : if (innermost_code == cdk_decomp)
14968 : {
14969 237482 : location_t loc = (declarator->kind == cdk_reference
14970 247806 : ? declarator->declarator->id_loc : declarator->id_loc);
14971 247806 : if (inlinep)
14972 29 : error_at (declspecs->locations[ds_inline],
14973 : "structured binding declaration cannot be %qs", "inline");
14974 247806 : if (typedef_p)
14975 29 : error_at (declspecs->locations[ds_typedef],
14976 : "structured binding declaration cannot be %qs", "typedef");
14977 247806 : if (constexpr_p && !concept_p && cxx_dialect < cxx26)
14978 101 : pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
14979 : "structured binding declaration can be %qs only with "
14980 : "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
14981 247806 : if (consteval_p)
14982 13 : error_at (declspecs->locations[ds_consteval], "structured "
14983 : "binding declaration cannot be %qs", "consteval");
14984 247806 : if (thread_p && cxx_dialect < cxx20)
14985 75 : pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
14986 : "structured binding declaration can be %qs only in "
14987 : "%<-std=c++20%> or %<-std=gnu++20%>",
14988 75 : declspecs->gnu_thread_keyword_p
14989 : ? "__thread" : "thread_local");
14990 247806 : if (concept_p)
14991 : {
14992 0 : error_at (declspecs->locations[ds_concept],
14993 : "structured binding declaration cannot be %qs", "concept");
14994 0 : constexpr_p = 0;
14995 : }
14996 : /* [dcl.struct.bind] "A cv that includes volatile is deprecated." */
14997 247806 : if (type_quals & TYPE_QUAL_VOLATILE)
14998 26 : warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
14999 : "%<volatile%>-qualified structured binding is deprecated");
15000 247806 : switch (storage_class)
15001 : {
15002 : case sc_none:
15003 : break;
15004 28 : case sc_register:
15005 28 : error_at (loc, "structured binding declaration cannot be %qs",
15006 : "register");
15007 28 : break;
15008 252 : case sc_static:
15009 252 : if (cxx_dialect < cxx20)
15010 185 : pedwarn (loc, OPT_Wc__20_extensions,
15011 : "structured binding declaration can be %qs only in "
15012 : "%<-std=c++20%> or %<-std=gnu++20%>", "static");
15013 : break;
15014 29 : case sc_extern:
15015 29 : error_at (loc, "structured binding declaration cannot be %qs",
15016 : "extern");
15017 29 : break;
15018 28 : case sc_mutable:
15019 28 : error_at (loc, "structured binding declaration cannot be %qs",
15020 : "mutable");
15021 28 : break;
15022 0 : case sc_auto:
15023 0 : error_at (loc, "structured binding declaration cannot be "
15024 : "C++98 %<auto%>");
15025 0 : break;
15026 0 : default:
15027 0 : gcc_unreachable ();
15028 : }
15029 247806 : if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
15030 247806 : || TYPE_IDENTIFIER (type) != auto_identifier)
15031 : {
15032 3 : if (type != error_mark_node)
15033 : {
15034 3 : auto_diagnostic_group d;
15035 3 : error_at (loc, "structured binding declaration cannot have "
15036 : "type %qT", type);
15037 3 : inform (loc,
15038 : "type must be cv-qualified %<auto%> or reference to "
15039 : "cv-qualified %<auto%>");
15040 3 : }
15041 3 : type = build_qualified_type (make_auto (), type_quals);
15042 3 : declspecs->type = type;
15043 : }
15044 247803 : else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
15045 51 : pedwarn (loc, OPT_Wpedantic,
15046 : "structured binding declaration cannot have constrained "
15047 : "%<auto%> type %qT", type);
15048 247806 : inlinep = 0;
15049 247806 : typedef_p = 0;
15050 247806 : consteval_p = 0;
15051 247806 : concept_p = 0;
15052 247806 : if (storage_class != sc_static)
15053 : {
15054 247554 : storage_class = sc_none;
15055 247554 : declspecs->storage_class = sc_none;
15056 : }
15057 : }
15058 :
15059 : /* Static anonymous unions are dealt with here. */
15060 1092297386 : if (staticp && decl_context == TYPENAME
15061 0 : && declspecs->type
15062 1092297386 : && ANON_AGGR_TYPE_P (declspecs->type))
15063 : decl_context = FIELD;
15064 :
15065 : /* Warn about storage classes that are invalid for certain
15066 : kinds of declarations (parameters, typenames, etc.). */
15067 1092297386 : if (thread_p
15068 20649 : && ((storage_class
15069 20649 : && storage_class != sc_extern
15070 528 : && storage_class != sc_static)
15071 20638 : || typedef_p))
15072 : {
15073 17 : location_t loc
15074 17 : = min_location (declspecs->locations[ds_thread],
15075 : declspecs->locations[ds_storage_class]);
15076 17 : error_at (loc, "multiple storage classes in declaration of %qs", name);
15077 17 : thread_p = false;
15078 : }
15079 1092297386 : if (decl_context != NORMAL
15080 915573265 : && ((storage_class != sc_none
15081 915573265 : && storage_class != sc_mutable)
15082 890790481 : || thread_p))
15083 : {
15084 24782787 : if ((decl_context == PARM || decl_context == CATCHPARM)
15085 36 : && (storage_class == sc_register
15086 36 : || storage_class == sc_auto))
15087 : ;
15088 24782751 : else if (typedef_p)
15089 : ;
15090 24782751 : else if (decl_context == FIELD
15091 : /* C++ allows static class elements. */
15092 24782751 : && storage_class == sc_static)
15093 : /* C++ also allows inlines and signed and unsigned elements,
15094 : but in those cases we don't come in here. */
15095 : ;
15096 : else
15097 : {
15098 15 : location_t loc
15099 15 : = min_location (declspecs->locations[ds_thread],
15100 : declspecs->locations[ds_storage_class]);
15101 15 : if (decl_context == FIELD)
15102 15 : error_at (loc, "storage class specified for %qs", name);
15103 0 : else if (decl_context == PARM || decl_context == CATCHPARM)
15104 0 : error_at (loc, "storage class specified for parameter %qs", name);
15105 : else
15106 0 : error_at (loc, "storage class specified for typename");
15107 15 : if (storage_class == sc_register
15108 15 : || storage_class == sc_auto
15109 15 : || storage_class == sc_extern
15110 3 : || thread_p)
15111 15 : storage_class = sc_none;
15112 : }
15113 : }
15114 1067514599 : else if (storage_class == sc_extern && funcdef_flag
15115 1067514599 : && ! toplevel_bindings_p ())
15116 0 : error ("nested function %qs declared %<extern%>", name);
15117 1067514599 : else if (toplevel_bindings_p ())
15118 : {
15119 497845109 : if (storage_class == sc_auto)
15120 2 : error_at (declspecs->locations[ds_storage_class],
15121 : "top-level declaration of %qs specifies %<auto%>", name);
15122 : }
15123 569669490 : else if (thread_p
15124 569669490 : && storage_class != sc_extern
15125 243 : && storage_class != sc_static)
15126 : {
15127 210 : if (declspecs->gnu_thread_keyword_p)
15128 49 : pedwarn (declspecs->locations[ds_thread],
15129 49 : 0, "function-scope %qs implicitly auto and "
15130 : "declared %<__thread%>", name);
15131 :
15132 : /* When thread_local is applied to a variable of block scope the
15133 : storage-class-specifier static is implied if it does not appear
15134 : explicitly. */
15135 210 : storage_class = declspecs->storage_class = sc_static;
15136 210 : staticp = 1;
15137 : }
15138 :
15139 1092297386 : if (storage_class && friendp)
15140 : {
15141 12 : error_at (min_location (declspecs->locations[ds_thread],
15142 : declspecs->locations[ds_storage_class]),
15143 : "storage class specifiers invalid in friend function "
15144 : "declarations");
15145 12 : storage_class = sc_none;
15146 12 : staticp = 0;
15147 : }
15148 :
15149 1092297386 : if (!id_declarator)
15150 : unqualified_id = NULL_TREE;
15151 : else
15152 : {
15153 614978421 : unqualified_id = id_declarator->u.id.unqualified_name;
15154 614978421 : switch (TREE_CODE (unqualified_id))
15155 : {
15156 3388030 : case BIT_NOT_EXPR:
15157 3388030 : unqualified_id = TREE_OPERAND (unqualified_id, 0);
15158 3388030 : if (TYPE_P (unqualified_id))
15159 3388027 : unqualified_id = constructor_name (unqualified_id);
15160 : break;
15161 :
15162 : case IDENTIFIER_NODE:
15163 : case TEMPLATE_ID_EXPR:
15164 : break;
15165 :
15166 0 : default:
15167 0 : gcc_unreachable ();
15168 : }
15169 : }
15170 :
15171 1092297386 : if (declspecs->std_attributes)
15172 : {
15173 795 : location_t attr_loc = declspecs->locations[ds_std_attribute];
15174 795 : auto_diagnostic_group d;
15175 795 : if (any_nonignored_attribute_p (declspecs->std_attributes)
15176 795 : && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
15177 792 : inform (attr_loc, "an attribute that appertains to a type-specifier "
15178 : "is ignored");
15179 795 : }
15180 :
15181 : /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn. */
15182 1092297386 : bool is_xobj_member_function = false;
15183 : /* Determine the type of the entity declared by recurring on the
15184 : declarator. */
15185 1499580995 : for (; declarator; declarator = declarator->declarator)
15186 : {
15187 1022509862 : const cp_declarator *inner_declarator;
15188 1022509862 : tree attrs;
15189 :
15190 1022509862 : if (type == error_mark_node)
15191 607 : return error_mark_node;
15192 :
15193 1022509534 : attrs = declarator->attributes;
15194 1022509534 : if (attrs)
15195 : {
15196 13760 : int attr_flags;
15197 :
15198 13760 : attr_flags = 0;
15199 13760 : if (declarator->kind == cdk_id)
15200 13052 : attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
15201 13760 : if (declarator->kind == cdk_function)
15202 691 : attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
15203 13760 : if (declarator->kind == cdk_array)
15204 2 : attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
15205 13760 : tree late_attrs = NULL_TREE;
15206 13760 : if (decl_context != PARM && decl_context != TYPENAME)
15207 : /* Assume that any attributes that get applied late to
15208 : templates will DTRT when applied to the declaration
15209 : as a whole. */
15210 13748 : late_attrs = splice_template_attributes (&attrs, type);
15211 13760 : returned_attrs = decl_attributes (&type,
15212 : attr_chainon (returned_attrs,
15213 : attrs),
15214 : attr_flags);
15215 13760 : returned_attrs = attr_chainon (late_attrs, returned_attrs);
15216 : }
15217 :
15218 1022509534 : inner_declarator = declarator->declarator;
15219 :
15220 : /* We don't want to warn in parameter context because we don't
15221 : yet know if the parse will succeed, and this might turn out
15222 : to be a constructor call. */
15223 1022509534 : if (decl_context != PARM
15224 1022509534 : && decl_context != TYPENAME
15225 593891987 : && !typedef_p
15226 543112796 : && declarator->parenthesized != UNKNOWN_LOCATION
15227 : /* If the type is class-like and the inner name used a
15228 : global namespace qualifier, we need the parens.
15229 : Unfortunately all we can tell is whether a qualified name
15230 : was used or not. */
15231 1022509715 : && !(inner_declarator
15232 126 : && inner_declarator->kind == cdk_id
15233 108 : && inner_declarator->u.id.qualifying_scope
15234 18 : && (MAYBE_CLASS_TYPE_P (type)
15235 12 : || TREE_CODE (type) == ENUMERAL_TYPE)))
15236 : {
15237 169 : auto_diagnostic_group d;
15238 169 : if (warning_at (declarator->parenthesized, OPT_Wparentheses,
15239 : "unnecessary parentheses in declaration of %qs",
15240 : name))
15241 : {
15242 42 : gcc_rich_location iloc (declarator->parenthesized);
15243 42 : iloc.add_fixit_remove (get_start (declarator->parenthesized));
15244 42 : iloc.add_fixit_remove (get_finish (declarator->parenthesized));
15245 42 : inform (&iloc, "remove parentheses");
15246 42 : }
15247 169 : }
15248 1022509534 : if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
15249 : break;
15250 :
15251 407283888 : switch (declarator->kind)
15252 : {
15253 3783150 : case cdk_array:
15254 7566300 : type = create_array_type_for_decl (dname, type,
15255 3783150 : declarator->u.array.bounds,
15256 3783150 : declarator->id_loc);
15257 3783150 : if (!valid_array_size_p (dname
15258 : ? declarator->id_loc : input_location,
15259 : type, dname))
15260 267 : type = error_mark_node;
15261 :
15262 3783150 : if (declarator->std_attributes)
15263 : /* [dcl.array]/1:
15264 :
15265 : The optional attribute-specifier-seq appertains to the
15266 : array type. */
15267 209 : cplus_decl_attributes (&type, declarator->std_attributes, 0);
15268 : break;
15269 :
15270 199997715 : case cdk_function:
15271 199997715 : {
15272 199997715 : tree arg_types;
15273 199997715 : int funcdecl_p;
15274 :
15275 : /* Declaring a function type. */
15276 :
15277 : /* Pick up type qualifiers which should be applied to `this'. */
15278 199997715 : memfn_quals = declarator->u.function.qualifiers;
15279 : /* Pick up virt-specifiers. */
15280 199997715 : virt_specifiers = declarator->u.function.virt_specifiers;
15281 : /* And ref-qualifier, too */
15282 199997715 : rqual = declarator->u.function.ref_qualifier;
15283 : /* And tx-qualifier. */
15284 199997715 : tree tx_qual = declarator->u.function.tx_qualifier;
15285 : /* Pick up the exception specifications. */
15286 199997715 : raises = declarator->u.function.exception_specification;
15287 : /* If the exception-specification is ill-formed, let's pretend
15288 : there wasn't one. */
15289 199997715 : if (raises == error_mark_node)
15290 9 : raises = NULL_TREE;
15291 :
15292 399995430 : auto find_xobj_parm = [](tree parm_list)
15293 : {
15294 : /* There is no need to iterate over the list,
15295 : only the first parm can be a valid xobj parm. */
15296 399756366 : if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
15297 : return NULL_TREE;
15298 : /* If we make it here, we are looking at an xobj parm.
15299 :
15300 : Non-null 'purpose' usually means the parm has a default
15301 : argument, we don't want to violate this assumption. */
15302 94556 : TREE_PURPOSE (parm_list) = NULL_TREE;
15303 94556 : return TREE_VALUE (parm_list);
15304 : };
15305 :
15306 199997715 : tree xobj_parm
15307 199997715 : = find_xobj_parm (declarator->u.function.parameters);
15308 199997715 : is_xobj_member_function = xobj_parm;
15309 :
15310 199997715 : if (xobj_parm && cxx_dialect < cxx23)
15311 42539 : pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
15312 : "explicit object member function only available "
15313 : "with %<-std=c++23%> or %<-std=gnu++23%>");
15314 :
15315 199997715 : if (xobj_parm && decl_context == TYPENAME)
15316 : {
15317 : /* We inform in every case, just differently depending on what
15318 : case it is. */
15319 9 : auto_diagnostic_group d;
15320 9 : bool ptr_type = true;
15321 : /* If declarator->kind is cdk_function and we are at the end of
15322 : the declarator chain, we are looking at a function type. */
15323 9 : if (!declarator->declarator)
15324 : {
15325 3 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15326 : "a function type cannot "
15327 : "have an explicit object parameter");
15328 3 : ptr_type = false;
15329 : }
15330 6 : else if (declarator->declarator->kind == cdk_pointer)
15331 3 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15332 : "a pointer to function type cannot "
15333 : "have an explicit object parameter");
15334 3 : else if (declarator->declarator->kind == cdk_ptrmem)
15335 3 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15336 : "a pointer to member function type "
15337 : "cannot have an explicit object parameter");
15338 : else
15339 0 : gcc_unreachable ();
15340 :
15341 : /* The locations being used here are probably not correct. */
15342 6 : if (ptr_type)
15343 6 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15344 : "the type of a pointer to explicit object member "
15345 : "function is a regular pointer to function type");
15346 : else
15347 3 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15348 : "the type of an explicit object "
15349 : "member function is a regular function type");
15350 : /* Ideally we should synthesize the correct syntax
15351 : for the user, perhaps this could be added later. */
15352 9 : }
15353 : /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
15354 : the first parm node will never erroneously be detected here. */
15355 199997715 : {
15356 199997715 : auto_diagnostic_group d;
15357 199997715 : bool bad_xobj_parm_encountered = false;
15358 199997715 : for (tree parm = declarator->u.function.parameters;
15359 496204574 : parm && parm != void_list_node;
15360 296206859 : parm = TREE_CHAIN (parm))
15361 : {
15362 296206859 : if (TREE_PURPOSE (parm) != this_identifier)
15363 296206850 : continue;
15364 9 : bad_xobj_parm_encountered = true;
15365 9 : TREE_PURPOSE (parm) = NULL_TREE;
15366 9 : gcc_rich_location bad_xobj_parm
15367 9 : (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
15368 9 : error_at (&bad_xobj_parm,
15369 : "only the first parameter of a member function "
15370 : "can be declared as an explicit object parameter");
15371 9 : }
15372 199997715 : if (bad_xobj_parm_encountered && xobj_parm)
15373 0 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15374 : "valid explicit object parameter declared here");
15375 199997715 : }
15376 :
15377 199997715 : if (reqs)
15378 3 : error_at (location_of (reqs), "requires-clause on return type");
15379 199997715 : reqs = declarator->u.function.requires_clause;
15380 :
15381 : /* Say it's a definition only for the CALL_EXPR
15382 : closest to the identifier. */
15383 199997715 : funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
15384 :
15385 : /* Handle a late-specified return type. */
15386 199997715 : tree late_return_type = declarator->u.function.late_return_type;
15387 199997715 : if (tree auto_node = type_uses_auto (type))
15388 : {
15389 9066999 : if (!late_return_type)
15390 : {
15391 5296396 : if (!funcdecl_p)
15392 : /* auto (*fp)() = f; is OK. */;
15393 5296362 : else if (current_class_type
15394 9741620 : && LAMBDA_TYPE_P (current_class_type))
15395 : /* OK for C++11 lambdas. */;
15396 3409060 : else if (cxx_dialect < cxx14)
15397 : {
15398 7 : auto_diagnostic_group d;
15399 7 : error_at (typespec_loc, "%qs function uses "
15400 : "%<auto%> type specifier without "
15401 : "trailing return type", name);
15402 7 : inform (typespec_loc,
15403 : "deduced return type only available "
15404 : "with %<-std=c++14%> or %<-std=gnu++14%>");
15405 7 : }
15406 3409053 : else if (virtualp)
15407 : {
15408 6 : error_at (typespec_loc, "virtual function "
15409 : "cannot have deduced return type");
15410 6 : virtualp = false;
15411 : }
15412 : }
15413 3770603 : else if (!is_auto (type) && sfk != sfk_conversion)
15414 : {
15415 15 : error_at (typespec_loc, "%qs function with trailing "
15416 : "return type has %qT as its type rather "
15417 : "than plain %<auto%>", name, type);
15418 276 : return error_mark_node;
15419 : }
15420 3770588 : else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
15421 : {
15422 9 : if (funcdecl_p)
15423 3 : error_at (typespec_loc,
15424 : "%qs function with trailing return type "
15425 : "has %<decltype(auto)%> as its type "
15426 : "rather than plain %<auto%>", name);
15427 : else
15428 6 : error_at (typespec_loc,
15429 : "invalid use of %<decltype(auto)%>");
15430 9 : return error_mark_node;
15431 : }
15432 3770579 : else if (is_constrained_auto (type))
15433 : {
15434 6 : if (funcdecl_p)
15435 3 : error_at (typespec_loc,
15436 : "%qs function with trailing return type "
15437 : "has constrained %<auto%> type specifier "
15438 : "rather than plain %<auto%>",
15439 : name);
15440 : else
15441 3 : error_at (typespec_loc,
15442 : "invalid use of constrained %<auto%> type");
15443 6 : return error_mark_node;
15444 : }
15445 9066969 : tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
15446 9066969 : if (!tmpl)
15447 7794154 : if (tree late_auto = type_uses_auto (late_return_type))
15448 40233 : tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
15449 7794154 : if (tmpl)
15450 : {
15451 1272821 : if (!funcdecl_p || !dguide_name_p (unqualified_id))
15452 : {
15453 13 : auto_diagnostic_group g;
15454 13 : error_at (typespec_loc, "deduced class "
15455 : "type %qD in function return type",
15456 13 : DECL_NAME (tmpl));
15457 13 : inform (DECL_SOURCE_LOCATION (tmpl),
15458 : "%qD declared here", tmpl);
15459 13 : return error_mark_node;
15460 13 : }
15461 1272808 : else if (!late_return_type)
15462 : {
15463 3 : auto_diagnostic_group d;
15464 3 : error_at (declarator->id_loc, "deduction guide "
15465 : "for %qT must have trailing return "
15466 3 : "type", TREE_TYPE (tmpl));
15467 3 : inform (DECL_SOURCE_LOCATION (tmpl),
15468 : "%qD declared here", tmpl);
15469 3 : return error_mark_node;
15470 3 : }
15471 1272805 : else if (CLASS_TYPE_P (late_return_type)
15472 1272805 : && CLASSTYPE_TEMPLATE_INFO (late_return_type)
15473 2545610 : && (CLASSTYPE_TI_TEMPLATE (late_return_type)
15474 : == tmpl))
15475 : /* OK */;
15476 : else
15477 0 : error ("trailing return type %qT of deduction guide "
15478 : "is not a specialization of %qT",
15479 0 : late_return_type, TREE_TYPE (tmpl));
15480 : }
15481 : }
15482 190930716 : else if (late_return_type
15483 190930716 : && sfk != sfk_conversion)
15484 : {
15485 37 : if (late_return_type == error_mark_node)
15486 : return error_mark_node;
15487 37 : if (cxx_dialect < cxx11)
15488 : /* Not using maybe_warn_cpp0x because this should
15489 : always be an error. */
15490 1 : error_at (typespec_loc,
15491 : "trailing return type only available "
15492 : "with %<-std=c++11%> or %<-std=gnu++11%>");
15493 : else
15494 36 : error_at (typespec_loc, "%qs function with trailing "
15495 : "return type not declared with %<auto%> "
15496 : "type specifier", name);
15497 37 : return error_mark_node;
15498 : }
15499 199997632 : if (late_return_type && sfk == sfk_conversion)
15500 : {
15501 14 : error ("a conversion function cannot have a trailing return type");
15502 14 : return error_mark_node;
15503 : }
15504 199997618 : type = splice_late_return_type (type, late_return_type);
15505 199997618 : if (type == error_mark_node)
15506 : return error_mark_node;
15507 :
15508 199997540 : if (late_return_type)
15509 : {
15510 3770481 : late_return_type_p = true;
15511 3770481 : type_quals = cp_type_quals (type);
15512 : }
15513 :
15514 199997540 : if (type_quals != TYPE_UNQUALIFIED)
15515 : {
15516 : /* It's wrong, for instance, to issue a -Wignored-qualifiers
15517 : warning for
15518 : static_assert(!is_same_v<void(*)(), const void(*)()>);
15519 : because there the qualifier matters. */
15520 12432 : if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
15521 232 : warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
15522 : "qualifiers ignored on function return type");
15523 : /* [dcl.fct] "A volatile-qualified return type is
15524 : deprecated." */
15525 12432 : if (type_quals & TYPE_QUAL_VOLATILE)
15526 643 : warning_at (typespec_loc, OPT_Wvolatile,
15527 : "%<volatile%>-qualified return type is "
15528 : "deprecated");
15529 :
15530 : /* We now know that the TYPE_QUALS don't apply to the
15531 : decl, but to its return type. */
15532 : type_quals = TYPE_UNQUALIFIED;
15533 : }
15534 :
15535 : /* Error about some types functions can't return. */
15536 :
15537 199997540 : if (TREE_CODE (type) == FUNCTION_TYPE)
15538 : {
15539 30 : error_at (typespec_loc, "%qs declared as function returning "
15540 : "a function", name);
15541 30 : return error_mark_node;
15542 : }
15543 199997510 : if (TREE_CODE (type) == ARRAY_TYPE)
15544 : {
15545 6 : error_at (typespec_loc, "%qs declared as function returning "
15546 : "an array", name);
15547 6 : return error_mark_node;
15548 : }
15549 199997504 : if (constinit_p && funcdecl_p)
15550 : {
15551 15 : error_at (declspecs->locations[ds_constinit],
15552 : "%<constinit%> on function return type is not "
15553 : "allowed");
15554 15 : return error_mark_node;
15555 : }
15556 :
15557 199997489 : if (check_decltype_auto (typespec_loc, type))
15558 50 : return error_mark_node;
15559 :
15560 199997439 : if (ctype == NULL_TREE
15561 199997439 : && decl_context == FIELD
15562 : && funcdecl_p
15563 115545295 : && friendp == 0)
15564 108342631 : ctype = current_class_type;
15565 :
15566 199997439 : if (ctype && (sfk == sfk_constructor
15567 108342631 : || sfk == sfk_destructor))
15568 : {
15569 : /* We are within a class's scope. If our declarator name
15570 : is the same as the class name, and we are defining
15571 : a function, then it is a constructor/destructor, and
15572 : therefore returns a void type. */
15573 :
15574 : /* ISO C++ 12.4/2. A destructor may not be declared
15575 : const or volatile. A destructor may not be static.
15576 : A destructor may not be declared with ref-qualifier.
15577 :
15578 : ISO C++ 12.1. A constructor may not be declared
15579 : const or volatile. A constructor may not be
15580 : virtual. A constructor may not be static.
15581 : A constructor may not be declared with ref-qualifier. */
15582 27692087 : if (staticp == 2)
15583 9 : error_at (declspecs->locations[ds_storage_class],
15584 : (flags == DTOR_FLAG)
15585 : ? G_("destructor cannot be static member "
15586 : "function")
15587 : : G_("constructor cannot be static member "
15588 : "function"));
15589 27692087 : if (memfn_quals)
15590 : {
15591 9 : error ((flags == DTOR_FLAG)
15592 : ? G_("destructors may not be cv-qualified")
15593 : : G_("constructors may not be cv-qualified"));
15594 9 : memfn_quals = TYPE_UNQUALIFIED;
15595 : }
15596 :
15597 27692087 : if (rqual)
15598 : {
15599 6 : maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
15600 6 : error ((flags == DTOR_FLAG)
15601 : ? G_("destructors may not be ref-qualified")
15602 : : G_("constructors may not be ref-qualified"));
15603 6 : rqual = REF_QUAL_NONE;
15604 : }
15605 :
15606 27692087 : if (decl_context == FIELD
15607 27692087 : && !member_function_or_else (ctype,
15608 : current_class_type,
15609 : flags))
15610 0 : return error_mark_node;
15611 :
15612 27692087 : if (flags != DTOR_FLAG)
15613 : {
15614 : /* It's a constructor. */
15615 24477237 : if (explicitp == 1)
15616 5730513 : explicitp = 2;
15617 24477237 : if (virtualp)
15618 : {
15619 3 : permerror (declspecs->locations[ds_virtual],
15620 : "constructors cannot be declared %<virtual%>");
15621 3 : virtualp = 0;
15622 : }
15623 24477237 : if (decl_context == FIELD
15624 24477237 : && sfk != sfk_constructor)
15625 0 : return error_mark_node;
15626 : }
15627 27692087 : if (decl_context == FIELD)
15628 27692087 : staticp = 0;
15629 : }
15630 172305352 : else if (friendp)
15631 : {
15632 6873095 : if (virtualp)
15633 : {
15634 : /* Cannot be both friend and virtual. */
15635 12 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
15636 12 : richloc.add_range (declspecs->locations[ds_friend]);
15637 12 : error_at (&richloc, "virtual functions cannot be friends");
15638 12 : friendp = 0;
15639 12 : }
15640 6873095 : if (decl_context == NORMAL)
15641 0 : error_at (declarator->id_loc,
15642 : "friend declaration not in class definition");
15643 6873095 : if (current_function_decl && funcdef_flag)
15644 : {
15645 9 : error_at (declarator->id_loc,
15646 : "cannot define friend function %qs in a local "
15647 : "class definition", name);
15648 9 : friendp = 0;
15649 : }
15650 : /* [class.friend]/6: A function can be defined in a friend
15651 : declaration if the function name is unqualified. */
15652 6873095 : if (funcdef_flag && in_namespace)
15653 : {
15654 6 : if (in_namespace == global_namespace)
15655 3 : error_at (declarator->id_loc,
15656 : "friend function definition %qs cannot have "
15657 : "a name qualified with %<::%>", name);
15658 : else
15659 3 : error_at (declarator->id_loc,
15660 : "friend function definition %qs cannot have "
15661 : "a name qualified with %<%D::%>", name,
15662 : in_namespace);
15663 : }
15664 : }
15665 165432257 : else if (ctype && sfk == sfk_conversion)
15666 : {
15667 1066879 : if (explicitp == 1)
15668 : {
15669 499173 : maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
15670 499173 : explicitp = 2;
15671 : }
15672 : }
15673 164365378 : else if (sfk == sfk_deduction_guide)
15674 : {
15675 1272805 : if (explicitp == 1)
15676 199997439 : explicitp = 2;
15677 : }
15678 :
15679 199997439 : if (xobj_parm)
15680 : {
15681 94556 : if (!ctype
15682 110 : && (decl_context == NORMAL || friendp)
15683 101 : && (in_namespace
15684 101 : || !declarator->declarator->u.id.qualifying_scope))
15685 : {
15686 24 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15687 : "a non-member function cannot have "
15688 : "an explicit object parameter");
15689 24 : is_xobj_member_function = false;
15690 : }
15691 : else
15692 : {
15693 94532 : if (virtualp)
15694 : {
15695 24 : auto_diagnostic_group d;
15696 24 : error_at (declspecs->locations[ds_virtual],
15697 : "an explicit object member function cannot "
15698 : "be %<virtual%>");
15699 24 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15700 : "explicit object parameter declared here");
15701 24 : virtualp = false;
15702 24 : }
15703 94532 : if (staticp >= 2)
15704 : {
15705 3 : auto_diagnostic_group d;
15706 3 : error_at (declspecs->locations[ds_storage_class],
15707 : "an explicit object member function cannot "
15708 : "be %<static%>");
15709 3 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15710 : "explicit object parameter declared here");
15711 3 : }
15712 94532 : if (unqualified_id
15713 200091962 : && identifier_p (unqualified_id)
15714 189055 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
15715 12 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15716 : "%qD cannot be an explicit object member "
15717 : "function", unqualified_id);
15718 : }
15719 : }
15720 199997439 : tree pushed_scope = NULL_TREE;
15721 199997439 : if (funcdecl_p
15722 199997439 : && decl_context != FIELD
15723 82460516 : && inner_declarator->u.id.qualifying_scope
15724 209373076 : && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
15725 9374209 : pushed_scope
15726 9374209 : = push_scope (inner_declarator->u.id.qualifying_scope);
15727 :
15728 199997439 : arg_types = grokparms (declarator->u.function.parameters, &parms);
15729 :
15730 199997439 : if (pushed_scope)
15731 9374209 : pop_scope (pushed_scope);
15732 :
15733 199997439 : if (inner_declarator
15734 199603974 : && inner_declarator->kind == cdk_id
15735 197676242 : && inner_declarator->u.id.sfk == sfk_destructor
15736 3388021 : && arg_types != void_list_node)
15737 : {
15738 21 : error_at (declarator->id_loc,
15739 : "destructors may not have parameters");
15740 21 : arg_types = void_list_node;
15741 21 : parms = NULL_TREE;
15742 21 : is_xobj_member_function = false;
15743 : }
15744 :
15745 199997439 : type = cp_build_function_type (type, arg_types);
15746 :
15747 199997439 : tree attrs = declarator->std_attributes;
15748 199997439 : if (tx_qual)
15749 : {
15750 242 : tree att = build_tree_list (tx_qual, NULL_TREE);
15751 : /* transaction_safe applies to the type, but
15752 : transaction_safe_dynamic applies to the function. */
15753 242 : if (is_attribute_p ("transaction_safe", tx_qual))
15754 213 : attrs = attr_chainon (attrs, att);
15755 : else
15756 29 : returned_attrs = attr_chainon (returned_attrs, att);
15757 : }
15758 :
15759 : /* Actually apply the contract specifiers to the declaration. */
15760 199997439 : if (flag_contracts)
15761 22903512 : contract_specifiers
15762 : = contract_specifiers_concat
15763 22903512 : (contract_specifiers,
15764 22903512 : declarator->u.function.contract_specifiers);
15765 :
15766 199997439 : if (attrs)
15767 : /* [dcl.fct]/2:
15768 :
15769 : The optional attribute-specifier-seq appertains to
15770 : the function type. */
15771 513 : cplus_decl_attributes (&type, attrs, 0);
15772 :
15773 199997439 : if (raises)
15774 79644198 : type = build_exception_variant (type, raises);
15775 : }
15776 199997439 : break;
15777 :
15778 203503023 : case cdk_pointer:
15779 203503023 : case cdk_reference:
15780 203503023 : case cdk_ptrmem:
15781 : /* Filter out pointers-to-references and references-to-references.
15782 : We can get these if a TYPE_DECL is used. */
15783 :
15784 203503023 : if (TYPE_REF_P (type))
15785 : {
15786 240 : if (declarator->kind != cdk_reference)
15787 : {
15788 3 : error ("cannot declare pointer to %q#T", type);
15789 3 : type = TREE_TYPE (type);
15790 : }
15791 :
15792 : /* In C++0x, we allow reference to reference declarations
15793 : that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
15794 : and template type arguments [14.3.1/4 temp.arg.type]. The
15795 : check for direct reference to reference declarations, which
15796 : are still forbidden, occurs below. Reasoning behind the change
15797 : can be found in DR106, DR540, and the rvalue reference
15798 : proposals. */
15799 237 : else if (cxx_dialect == cxx98)
15800 : {
15801 0 : error ("cannot declare reference to %q#T", type);
15802 0 : type = TREE_TYPE (type);
15803 : }
15804 : }
15805 203502783 : else if (VOID_TYPE_P (type))
15806 : {
15807 5433363 : if (declarator->kind == cdk_reference)
15808 4 : error ("cannot declare reference to %q#T", type);
15809 5433359 : else if (declarator->kind == cdk_ptrmem)
15810 3 : error ("cannot declare pointer to %q#T member", type);
15811 : }
15812 :
15813 : /* We now know that the TYPE_QUALS don't apply to the decl,
15814 : but to the target of the pointer. */
15815 203503023 : type_quals = TYPE_UNQUALIFIED;
15816 :
15817 : /* This code used to handle METHOD_TYPE, but I don't think it's
15818 : possible to get it here anymore. */
15819 203503023 : gcc_assert (TREE_CODE (type) != METHOD_TYPE);
15820 203503023 : if (declarator->kind == cdk_ptrmem
15821 1161637 : && TREE_CODE (type) == FUNCTION_TYPE)
15822 : {
15823 939704 : memfn_quals |= type_memfn_quals (type);
15824 939704 : if (rqual == REF_QUAL_NONE)
15825 599098 : rqual = type_memfn_rqual (type);
15826 1879408 : type = build_memfn_type (type,
15827 939704 : declarator->u.pointer.class_type,
15828 : memfn_quals,
15829 : rqual);
15830 939704 : if (type == error_mark_node)
15831 : return error_mark_node;
15832 :
15833 : rqual = REF_QUAL_NONE;
15834 : memfn_quals = TYPE_UNQUALIFIED;
15835 : }
15836 :
15837 203503020 : if (TREE_CODE (type) == FUNCTION_TYPE
15838 203503020 : && (type_memfn_quals (type) != TYPE_UNQUALIFIED
15839 1064679 : || type_memfn_rqual (type) != REF_QUAL_NONE))
15840 15 : error (declarator->kind == cdk_reference
15841 : ? G_("cannot declare reference to qualified function type %qT")
15842 : : G_("cannot declare pointer to qualified function type %qT"),
15843 : type);
15844 :
15845 : /* When the pointed-to type involves components of variable size,
15846 : care must be taken to ensure that the size evaluation code is
15847 : emitted early enough to dominate all the possible later uses
15848 : and late enough for the variables on which it depends to have
15849 : been assigned.
15850 :
15851 : This is expected to happen automatically when the pointed-to
15852 : type has a name/declaration of it's own, but special attention
15853 : is required if the type is anonymous.
15854 :
15855 : We handle the NORMAL and FIELD contexts here by inserting a
15856 : dummy statement that just evaluates the size at a safe point
15857 : and ensures it is not deferred until e.g. within a deeper
15858 : conditional context (c++/43555).
15859 :
15860 : We expect nothing to be needed here for PARM or TYPENAME.
15861 : Evaluating the size at this point for TYPENAME would
15862 : actually be incorrect, as we might be in the middle of an
15863 : expression with side effects on the pointed-to type size
15864 : "arguments" prior to the pointer declaration point and the
15865 : size evaluation could end up prior to the side effects. */
15866 :
15867 203503020 : if (!TYPE_NAME (type)
15868 5747903 : && (decl_context == NORMAL || decl_context == FIELD)
15869 643862 : && at_function_scope_p ()
15870 203544829 : && variably_modified_type_p (type, NULL_TREE))
15871 : {
15872 119 : TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
15873 : NULL_TREE, type);
15874 119 : add_decl_expr (TYPE_NAME (type));
15875 : }
15876 :
15877 203503020 : if (declarator->kind == cdk_reference)
15878 : {
15879 : /* In C++0x, the type we are creating a reference to might be
15880 : a typedef which is itself a reference type. In that case,
15881 : we follow the reference collapsing rules in
15882 : [7.1.3/8 dcl.typedef] to create the final reference type:
15883 :
15884 : "If a typedef TD names a type that is a reference to a type
15885 : T, an attempt to create the type 'lvalue reference to cv TD'
15886 : creates the type 'lvalue reference to T,' while an attempt
15887 : to create the type "rvalue reference to cv TD' creates the
15888 : type TD."
15889 : */
15890 136205117 : if (VOID_TYPE_P (type))
15891 : /* We already gave an error. */;
15892 136205113 : else if (TYPE_REF_P (type))
15893 : {
15894 237 : if (declarator->u.reference.rvalue_ref)
15895 : /* Leave type alone. */;
15896 : else
15897 116 : type = cp_build_reference_type (TREE_TYPE (type), false);
15898 : }
15899 : else
15900 136204876 : type = cp_build_reference_type
15901 136204876 : (type, declarator->u.reference.rvalue_ref);
15902 :
15903 : /* In C++0x, we need this check for direct reference to
15904 : reference declarations, which are forbidden by
15905 : [8.3.2/5 dcl.ref]. Reference to reference declarations
15906 : are only allowed indirectly through typedefs and template
15907 : type arguments. Example:
15908 :
15909 : void foo(int & &); // invalid ref-to-ref decl
15910 :
15911 : typedef int & int_ref;
15912 : void foo(int_ref &); // valid ref-to-ref decl
15913 : */
15914 136205117 : if (inner_declarator && inner_declarator->kind == cdk_reference)
15915 2 : error ("cannot declare reference to %q#T, which is not "
15916 : "a typedef or a template type argument", type);
15917 : }
15918 67297903 : else if (TREE_CODE (type) == METHOD_TYPE)
15919 939701 : type = build_ptrmemfunc_type (build_pointer_type (type));
15920 66358202 : else if (declarator->kind == cdk_ptrmem)
15921 : {
15922 221933 : gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
15923 : != NAMESPACE_DECL);
15924 221933 : if (declarator->u.pointer.class_type == error_mark_node)
15925 : /* We will already have complained. */
15926 3 : type = error_mark_node;
15927 : else
15928 221930 : type = build_ptrmem_type (declarator->u.pointer.class_type,
15929 : type);
15930 : }
15931 : else
15932 66136269 : type = build_pointer_type (type);
15933 :
15934 : /* Process a list of type modifier keywords (such as
15935 : const or volatile) that were given inside the `*' or `&'. */
15936 :
15937 203503020 : if (declarator->u.pointer.qualifiers)
15938 : {
15939 8945592 : type
15940 8945592 : = cp_build_qualified_type (type,
15941 : declarator->u.pointer.qualifiers);
15942 8945592 : type_quals = cp_type_quals (type);
15943 : }
15944 :
15945 : /* Apply C++11 attributes to the pointer, and not to the
15946 : type pointed to. This is unlike what is done for GNU
15947 : attributes above. It is to comply with [dcl.ptr]/1:
15948 :
15949 : [the optional attribute-specifier-seq (7.6.1) appertains
15950 : to the pointer and not to the object pointed to]. */
15951 203503020 : if (declarator->std_attributes)
15952 189 : cplus_decl_attributes (&type, declarator->std_attributes, 0);
15953 :
15954 : ctype = NULL_TREE;
15955 : break;
15956 :
15957 : case cdk_error:
15958 : break;
15959 :
15960 0 : default:
15961 0 : gcc_unreachable ();
15962 : }
15963 : }
15964 :
15965 1092296779 : id_loc = declarator ? declarator->id_loc : input_location;
15966 :
15967 1092296779 : if (innermost_code != cdk_function
15968 : /* Don't check this if it can be the artificial decltype(auto)
15969 : we created when building a constraint in a compound-requirement:
15970 : that the type-constraint is plain is going to be checked in
15971 : cp_parser_compound_requirement. */
15972 1092296779 : && decl_context != TYPENAME
15973 1092296779 : && check_decltype_auto (id_loc, type))
15974 20 : return error_mark_node;
15975 :
15976 : /* A `constexpr' specifier used in an object declaration declares
15977 : the object as `const'. */
15978 1092296759 : if (constexpr_p && innermost_code != cdk_function)
15979 : {
15980 : /* DR1688 says that a `constexpr' specifier in combination with
15981 : `volatile' is valid. */
15982 :
15983 20893419 : if (!TYPE_REF_P (type))
15984 : {
15985 20881528 : type_quals |= TYPE_QUAL_CONST;
15986 20881528 : type = cp_build_qualified_type (type, type_quals);
15987 : }
15988 : }
15989 :
15990 614977823 : if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
15991 3005020 : && !FUNC_OR_METHOD_TYPE_P (type)
15992 1094299540 : && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
15993 : {
15994 0 : error ("template-id %qD used as a declarator",
15995 : unqualified_id);
15996 0 : unqualified_id = dname;
15997 : }
15998 :
15999 : /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
16000 : qualified with a class-name, turn it into a METHOD_TYPE, unless
16001 : we know that the function is static. We take advantage of this
16002 : opportunity to do other processing that pertains to entities
16003 : explicitly declared to be class members. Note that if DECLARATOR
16004 : is non-NULL, we know it is a cdk_id declarator; otherwise, we
16005 : would not have exited the loop above. */
16006 1092296759 : if (declarator
16007 615225629 : && declarator->kind == cdk_id
16008 614977823 : && declarator->u.id.qualifying_scope
16009 1102476226 : && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
16010 : {
16011 9897646 : ctype = declarator->u.id.qualifying_scope;
16012 9897646 : ctype = TYPE_MAIN_VARIANT (ctype);
16013 9897646 : template_count = num_template_headers_for_class (ctype);
16014 :
16015 9897646 : if (ctype == current_class_type)
16016 : {
16017 54 : if (friendp)
16018 : {
16019 15 : permerror (declspecs->locations[ds_friend],
16020 : "member functions are implicitly "
16021 : "friends of their class");
16022 15 : friendp = 0;
16023 : }
16024 : else
16025 39 : permerror (id_loc, "extra qualification %<%T::%> on member %qs",
16026 : ctype, name);
16027 : }
16028 9897592 : else if (/* If the qualifying type is already complete, then we
16029 : can skip the following checks. */
16030 9897592 : !COMPLETE_TYPE_P (ctype)
16031 154 : && (/* If the function is being defined, then
16032 : qualifying type must certainly be complete. */
16033 : funcdef_flag
16034 : /* A friend declaration of "T::f" is OK, even if
16035 : "T" is a template parameter. But, if this
16036 : function is not a friend, the qualifying type
16037 : must be a class. */
16038 117 : || (!friendp && !CLASS_TYPE_P (ctype))
16039 : /* For a declaration, the type need not be
16040 : complete, if either it is dependent (since there
16041 : is no meaningful definition of complete in that
16042 : case) or the qualifying class is currently being
16043 : defined. */
16044 129 : || !(dependent_type_p (ctype)
16045 24 : || currently_open_class (ctype)))
16046 : /* Check that the qualifying type is complete. */
16047 9897656 : && !complete_type_or_else (ctype, NULL_TREE))
16048 64 : return error_mark_node;
16049 9897528 : else if (TREE_CODE (type) == FUNCTION_TYPE)
16050 : {
16051 9374471 : if (current_class_type
16052 289 : && (!friendp || funcdef_flag || initialized))
16053 : {
16054 57 : error_at (id_loc, funcdef_flag || initialized
16055 : ? G_("cannot define member function %<%T::%s%> "
16056 : "within %qT")
16057 : : G_("cannot declare member function %<%T::%s%> "
16058 : "within %qT"),
16059 : ctype, name, current_class_type);
16060 48 : return error_mark_node;
16061 : }
16062 : }
16063 523057 : else if (typedef_p && current_class_type)
16064 : {
16065 0 : error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
16066 : ctype, name, current_class_type);
16067 0 : return error_mark_node;
16068 : }
16069 : }
16070 :
16071 1092296647 : if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
16072 61312473 : ctype = current_class_type;
16073 :
16074 : /* Now TYPE has the actual type. */
16075 :
16076 1092296647 : if (returned_attrs)
16077 : {
16078 2940 : if (attrlist)
16079 2940 : *attrlist = attr_chainon (returned_attrs, *attrlist);
16080 : else
16081 : attrlist = &returned_attrs;
16082 : }
16083 :
16084 1092296647 : if (declarator
16085 615225517 : && declarator->kind == cdk_id
16086 614977711 : && declarator->std_attributes
16087 602443 : && attrlist != NULL)
16088 : {
16089 : /* [dcl.meaning]/1: The optional attribute-specifier-seq following
16090 : a declarator-id appertains to the entity that is declared. */
16091 602440 : if (declarator->std_attributes != error_mark_node)
16092 : {
16093 602422 : if (flag_reflection
16094 : && declarator->std_attributes != error_mark_node
16095 28830 : && lookup_annotation (declarator->std_attributes)
16096 40 : && *attrlist != error_mark_node
16097 602462 : && lookup_annotation (*attrlist))
16098 : /* If there are annotations in both lists, ensure
16099 : declarator->std_attributes go after *attrlist. See
16100 : PR124399. */
16101 14 : *attrlist = chainon (copy_list (*attrlist),
16102 14 : declarator->std_attributes);
16103 : else
16104 602408 : *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
16105 : }
16106 : else
16107 : /* We should have already diagnosed the issue (c++/78344). */
16108 18 : gcc_assert (seen_error ());
16109 : }
16110 :
16111 : /* Handle parameter packs. */
16112 1092296647 : if (parameter_pack_p)
16113 : {
16114 3229286 : if (decl_context == PARM)
16115 : /* Turn the type into a pack expansion.*/
16116 3229286 : type = make_pack_expansion (type);
16117 : else
16118 0 : error ("non-parameter %qs cannot be a parameter pack", name);
16119 : }
16120 :
16121 1092296647 : if ((decl_context == FIELD || decl_context == PARM)
16122 485406007 : && !processing_template_decl
16123 1247098106 : && variably_modified_type_p (type, NULL_TREE))
16124 : {
16125 12 : if (decl_context == FIELD)
16126 6 : error_at (id_loc,
16127 : "data member may not have variably modified type %qT", type);
16128 : else
16129 6 : error_at (id_loc,
16130 : "parameter may not have variably modified type %qT", type);
16131 12 : type = error_mark_node;
16132 : }
16133 :
16134 1092296647 : if (explicitp == 1 || (explicitp && friendp))
16135 : {
16136 : /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
16137 : in the declaration of a constructor or conversion function within
16138 : a class definition. */
16139 74 : if (!current_class_type)
16140 59 : error_at (declspecs->locations[ds_explicit],
16141 : "%<explicit%> outside class declaration");
16142 15 : else if (friendp)
16143 12 : error_at (declspecs->locations[ds_explicit],
16144 : "%<explicit%> in friend declaration");
16145 : else
16146 3 : error_at (declspecs->locations[ds_explicit],
16147 : "only declarations of constructors and conversion operators "
16148 : "can be %<explicit%>");
16149 : explicitp = 0;
16150 : }
16151 :
16152 1092296647 : if (storage_class == sc_mutable)
16153 : {
16154 142695 : location_t sloc = declspecs->locations[ds_storage_class];
16155 142695 : if (decl_context != FIELD || friendp)
16156 : {
16157 30 : error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
16158 : name);
16159 30 : storage_class = sc_none;
16160 : }
16161 142665 : else if (decl_context == TYPENAME || typedef_p)
16162 : {
16163 0 : error_at (sloc,
16164 : "non-object member %qs cannot be declared %<mutable%>",
16165 : name);
16166 0 : storage_class = sc_none;
16167 : }
16168 142665 : else if (FUNC_OR_METHOD_TYPE_P (type))
16169 : {
16170 3 : error_at (sloc, "function %qs cannot be declared %<mutable%>",
16171 : name);
16172 3 : storage_class = sc_none;
16173 : }
16174 142662 : else if (staticp)
16175 : {
16176 0 : error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
16177 : name);
16178 0 : storage_class = sc_none;
16179 : }
16180 142662 : else if (type_quals & TYPE_QUAL_CONST)
16181 : {
16182 9 : error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
16183 : name);
16184 9 : storage_class = sc_none;
16185 : }
16186 142653 : else if (TYPE_REF_P (type))
16187 : {
16188 6 : permerror (sloc, "reference %qs cannot be declared %<mutable%>",
16189 : name);
16190 6 : storage_class = sc_none;
16191 : }
16192 : }
16193 :
16194 : /* If this is declaring a typedef name, return a TYPE_DECL. */
16195 1092296647 : if (typedef_p && decl_context != TYPENAME)
16196 : {
16197 49626709 : bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
16198 49626709 : tree decl;
16199 :
16200 49626709 : if (funcdef_flag)
16201 : {
16202 6 : if (decl_context == NORMAL)
16203 3 : error_at (id_loc,
16204 : "typedef may not be a function definition");
16205 : else
16206 3 : error_at (id_loc,
16207 : "typedef may not be a member function definition");
16208 6 : return error_mark_node;
16209 : }
16210 :
16211 : /* This declaration:
16212 :
16213 : typedef void f(int) const;
16214 :
16215 : declares a function type which is not a member of any
16216 : particular class, but which is cv-qualified; for
16217 : example "f S::*" declares a pointer to a const-qualified
16218 : member function of S. We record the cv-qualification in the
16219 : function type. */
16220 49626703 : if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
16221 : {
16222 62 : type = apply_memfn_quals (type, memfn_quals, rqual);
16223 :
16224 : /* We have now dealt with these qualifiers. */
16225 62 : memfn_quals = TYPE_UNQUALIFIED;
16226 62 : rqual = REF_QUAL_NONE;
16227 : }
16228 :
16229 49626703 : if (type_uses_auto (type))
16230 : {
16231 62 : if (alias_p)
16232 20 : error_at (declspecs->locations[ds_type_spec],
16233 : "%<auto%> not allowed in alias declaration");
16234 : else
16235 42 : error_at (declspecs->locations[ds_type_spec],
16236 : "typedef declared %<auto%>");
16237 62 : type = error_mark_node;
16238 : }
16239 :
16240 49626703 : if (reqs)
16241 3 : error_at (location_of (reqs), "requires-clause on typedef");
16242 :
16243 49626703 : if (id_declarator && declarator->u.id.qualifying_scope)
16244 : {
16245 21 : error_at (id_loc, "typedef name may not be a nested-name-specifier");
16246 21 : type = error_mark_node;
16247 : }
16248 :
16249 49626703 : if (decl_context == FIELD)
16250 26657933 : decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
16251 : else
16252 22968770 : decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
16253 :
16254 49626703 : if (decl_context != FIELD)
16255 : {
16256 22968770 : if (!current_function_decl)
16257 10133465 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
16258 12835305 : else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
16259 : /* The TYPE_DECL is "abstract" because there will be
16260 : clones of this constructor/destructor, and there will
16261 : be copies of this TYPE_DECL generated in those
16262 : clones. The decloning optimization (for space) may
16263 : revert this subsequently if it determines that
16264 : the clones should share a common implementation. */
16265 163771 : DECL_ABSTRACT_P (decl) = true;
16266 :
16267 22968770 : set_originating_module (decl);
16268 : }
16269 26657933 : else if (current_class_type
16270 26657933 : && constructor_name_p (unqualified_id, current_class_type))
16271 3 : permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
16272 : "as enclosing class",
16273 : unqualified_id);
16274 :
16275 : /* If the user declares "typedef struct {...} foo" then the
16276 : struct will have an anonymous name. Fill that name in now.
16277 : Nothing can refer to it, so nothing needs know about the name
16278 : change. */
16279 49626703 : if (type != error_mark_node
16280 49626620 : && unqualified_id
16281 49626617 : && TYPE_NAME (type)
16282 46127318 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16283 92116149 : && (TYPE_UNNAMED_P (type)
16284 : /* An enum may have previously used an enumerator for linkage
16285 : purposes, but we want the typedef name to take priority. */
16286 45713651 : || enum_with_enumerator_for_linkage_p (type))
16287 414089 : && declspecs->type_definition_p
16288 414006 : && attributes_naming_typedef_ok (*attrlist)
16289 50040706 : && cp_type_quals (type) == TYPE_UNQUALIFIED)
16290 413985 : name_unnamed_type (type, decl);
16291 :
16292 49626703 : if (signed_p
16293 49626703 : || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
16294 394783 : C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
16295 :
16296 49626703 : bad_specifiers (decl, BSP_TYPE, virtualp,
16297 : memfn_quals != TYPE_UNQUALIFIED,
16298 : inlinep, friendp, raises != NULL_TREE,
16299 : declspecs->locations);
16300 :
16301 49626703 : if (alias_p)
16302 : /* Acknowledge that this was written:
16303 : `using analias = atype;'. */
16304 22535007 : TYPE_DECL_ALIAS_P (decl) = 1;
16305 :
16306 : /* We use a flag so that dependent_opaque_alias_p doesn't have to
16307 : recompute the answer every single time. */
16308 49626703 : TYPE_DECL_OPAQUE_ALIAS_P (decl) = any_lambdas_p (type);
16309 :
16310 49626703 : return decl;
16311 : }
16312 :
16313 : /* Detect the case of an array type of unspecified size
16314 : which came, as such, direct from a typedef name.
16315 : We must copy the type, so that the array's domain can be
16316 : individually set by the object's initializer. */
16317 :
16318 1042669938 : if (type && typedef_type
16319 1011642246 : && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
16320 1043288740 : && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
16321 83 : type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
16322 :
16323 : /* Detect where we're using a typedef of function type to declare a
16324 : function. PARMS will not be set, so we must create it now. */
16325 :
16326 1042669938 : if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
16327 : {
16328 16536 : tree decls = NULL_TREE;
16329 16536 : tree args;
16330 :
16331 16536 : for (args = TYPE_ARG_TYPES (type);
16332 35537 : args && args != void_list_node;
16333 19001 : args = TREE_CHAIN (args))
16334 : {
16335 19001 : tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
16336 19001 : TREE_VALUE (args));
16337 :
16338 19001 : DECL_CHAIN (decl) = decls;
16339 19001 : decls = decl;
16340 : }
16341 :
16342 16536 : parms = nreverse (decls);
16343 :
16344 16536 : if (decl_context != TYPENAME)
16345 : {
16346 : /* The qualifiers on the function type become the qualifiers on
16347 : the non-static member function. */
16348 15752 : memfn_quals |= type_memfn_quals (type);
16349 15752 : rqual = type_memfn_rqual (type);
16350 15752 : type_quals = TYPE_UNQUALIFIED;
16351 15752 : raises = TYPE_RAISES_EXCEPTIONS (type);
16352 : }
16353 : }
16354 :
16355 : /* If this is a type name (such as, in a cast or sizeof),
16356 : compute the type and return it now. */
16357 :
16358 1042669154 : if (decl_context == TYPENAME)
16359 : {
16360 : /* Note that here we don't care about type_quals. */
16361 :
16362 : /* Special case: "friend class foo" looks like a TYPENAME context. */
16363 429656951 : if (friendp)
16364 : {
16365 0 : if (inlinep)
16366 : {
16367 0 : error ("%<inline%> specified for friend class declaration");
16368 0 : inlinep = 0;
16369 : }
16370 :
16371 0 : if (!current_aggr)
16372 : {
16373 : /* Don't allow friend declaration without a class-key. */
16374 0 : if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
16375 0 : permerror (input_location, "template parameters cannot be friends");
16376 0 : else if (TREE_CODE (type) == TYPENAME_TYPE)
16377 0 : permerror (input_location, "friend declaration requires class-key, "
16378 : "i.e. %<friend class %T::%D%>",
16379 0 : TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
16380 : else
16381 0 : permerror (input_location, "friend declaration requires class-key, "
16382 : "i.e. %<friend %#T%>",
16383 : type);
16384 : }
16385 :
16386 : /* Only try to do this stuff if we didn't already give up. */
16387 0 : if (type != integer_type_node)
16388 : {
16389 : /* A friendly class? */
16390 0 : if (current_class_type)
16391 0 : make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
16392 : /*complain=*/true);
16393 : else
16394 0 : error ("trying to make class %qT a friend of global scope",
16395 : type);
16396 :
16397 0 : type = void_type_node;
16398 : }
16399 : }
16400 429656951 : else if (memfn_quals || rqual)
16401 : {
16402 13964 : if (ctype == NULL_TREE
16403 13964 : && TREE_CODE (type) == METHOD_TYPE)
16404 0 : ctype = TYPE_METHOD_BASETYPE (type);
16405 :
16406 13964 : if (ctype)
16407 0 : type = build_memfn_type (type, ctype, memfn_quals, rqual);
16408 : /* Core issue #547: need to allow this in template type args.
16409 : Allow it in general in C++11 for alias-declarations. */
16410 13964 : else if ((template_type_arg || cxx_dialect >= cxx11)
16411 13962 : && TREE_CODE (type) == FUNCTION_TYPE)
16412 13960 : type = apply_memfn_quals (type, memfn_quals, rqual);
16413 : else
16414 4 : error ("invalid qualifiers on non-member function type");
16415 : }
16416 :
16417 429656951 : if (reqs)
16418 3 : error_at (location_of (reqs), "requires-clause on type-id");
16419 :
16420 429656951 : return type;
16421 : }
16422 613012987 : else if (unqualified_id == NULL_TREE && decl_context != PARM
16423 882773 : && decl_context != CATCHPARM
16424 387473 : && TREE_CODE (type) != UNION_TYPE
16425 387090 : && ! bitfield
16426 387090 : && innermost_code != cdk_decomp)
16427 : {
16428 9 : error ("abstract declarator %qT used as declaration", type);
16429 9 : return error_mark_node;
16430 : }
16431 :
16432 613012978 : if (!FUNC_OR_METHOD_TYPE_P (type))
16433 : {
16434 : /* Only functions may be declared using an operator-function-id. */
16435 415378312 : if (dname && IDENTIFIER_ANY_OP_P (dname))
16436 : {
16437 8 : error_at (id_loc, "declaration of %qD as non-function", dname);
16438 8 : return error_mark_node;
16439 : }
16440 :
16441 415378304 : if (reqs)
16442 15 : error_at (location_of (reqs),
16443 : "requires-clause on declaration of non-function type %qT",
16444 : type);
16445 : }
16446 :
16447 : /* We don't check parameter types here because we can emit a better
16448 : error message later. */
16449 613012970 : if (decl_context != PARM)
16450 : {
16451 304135120 : type = check_var_type (unqualified_id, type, id_loc);
16452 304135120 : if (type == error_mark_node)
16453 : return error_mark_node;
16454 : }
16455 :
16456 : /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
16457 : or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
16458 :
16459 613012886 : if (decl_context == PARM || decl_context == CATCHPARM)
16460 : {
16461 309387858 : if (ctype || in_namespace)
16462 0 : error ("cannot use %<::%> in parameter declaration");
16463 :
16464 309387858 : tree auto_node = type_uses_auto (type);
16465 309387858 : if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
16466 : {
16467 126 : bool err_p = true;
16468 126 : if (cxx_dialect >= cxx14)
16469 : {
16470 224 : if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
16471 3 : error_at (typespec_loc,
16472 : "cannot declare a parameter with %<decltype(auto)%>");
16473 115 : else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
16474 : {
16475 7 : auto_diagnostic_group g;
16476 7 : gcc_rich_location richloc (typespec_loc);
16477 7 : richloc.add_fixit_insert_after ("<>");
16478 7 : error_at (&richloc,
16479 : "missing template argument list after %qE; template "
16480 : "placeholder not permitted in parameter", c);
16481 7 : if (decl_context == PARM && cxx_dialect >= cxx20)
16482 6 : inform (typespec_loc, "or use %<auto%> for an "
16483 : "abbreviated function template");
16484 7 : inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
16485 7 : }
16486 108 : else if (decl_context == CATCHPARM || template_parm_flag)
16487 14 : error_at (typespec_loc,
16488 : "%<auto%> parameter not permitted in this context");
16489 : else
16490 : /* Do not issue an error while tentatively parsing a function
16491 : parameter: for T t(auto(a), 42);, when we just saw the 1st
16492 : parameter, we don't know yet that this construct won't be
16493 : a function declaration. Defer the checking to
16494 : cp_parser_parameter_declaration_clause. */
16495 : err_p = false;
16496 : }
16497 : else
16498 8 : error_at (typespec_loc, "parameter declared %<auto%>");
16499 32 : if (err_p)
16500 32 : type = error_mark_node;
16501 : }
16502 :
16503 : /* A parameter declared as an array of T is really a pointer to T.
16504 : One declared as a function is really a pointer to a function.
16505 : One declared as a member is really a pointer to member. */
16506 :
16507 309387858 : if (TREE_CODE (type) == ARRAY_TYPE)
16508 : {
16509 : /* Transfer const-ness of array into that of type pointed to. */
16510 803962 : type = build_pointer_type (TREE_TYPE (type));
16511 803962 : type_quals = TYPE_UNQUALIFIED;
16512 803962 : array_parameter_p = true;
16513 : }
16514 308583896 : else if (TREE_CODE (type) == FUNCTION_TYPE)
16515 103891 : type = build_pointer_type (type);
16516 : }
16517 :
16518 152894609 : if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
16519 : /* Don't convert xobj member functions to METHOD_TYPE. */
16520 117716877 : && !is_xobj_member_function
16521 719658551 : && !(unqualified_id
16522 213282382 : && identifier_p (unqualified_id)
16523 106645265 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
16524 : {
16525 106637117 : cp_cv_quals real_quals = memfn_quals;
16526 106637117 : if (cxx_dialect < cxx14 && constexpr_p
16527 724402 : && sfk != sfk_constructor && sfk != sfk_destructor)
16528 3719 : real_quals |= TYPE_QUAL_CONST;
16529 106637117 : type = build_memfn_type (type, ctype, real_quals, rqual);
16530 : }
16531 :
16532 613012886 : {
16533 613012886 : tree decl = NULL_TREE;
16534 :
16535 613012886 : if (decl_context == PARM)
16536 : {
16537 308877850 : decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
16538 308877850 : DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
16539 :
16540 308877850 : bad_specifiers (decl, BSP_PARM, virtualp,
16541 : memfn_quals != TYPE_UNQUALIFIED,
16542 : inlinep, friendp, raises != NULL_TREE,
16543 : declspecs->locations);
16544 : }
16545 304135036 : else if (decl_context == FIELD)
16546 : {
16547 149870209 : if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
16548 20848638 : if (tree auto_node = type_uses_auto (type))
16549 : {
16550 24 : location_t tloc = declspecs->locations[ds_type_spec];
16551 24 : if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
16552 6 : error_at (tloc, "invalid use of template-name %qE without an "
16553 : "argument list",
16554 6 : CLASS_PLACEHOLDER_TEMPLATE (auto_node));
16555 : else
16556 18 : error_at (tloc, "non-static data member declared with "
16557 : "placeholder %qT", auto_node);
16558 24 : type = error_mark_node;
16559 : }
16560 :
16561 : /* The C99 flexible array extension. */
16562 125087456 : if (!staticp && TREE_CODE (type) == ARRAY_TYPE
16563 151027014 : && TYPE_DOMAIN (type) == NULL_TREE)
16564 : {
16565 1401 : if (ctype
16566 1401 : && (TREE_CODE (ctype) == UNION_TYPE
16567 1401 : || TREE_CODE (ctype) == QUAL_UNION_TYPE))
16568 84 : pedwarn (id_loc, OPT_Wpedantic,
16569 : "flexible array member in union is a GCC extension");
16570 :
16571 : else
16572 : {
16573 : /* Array is a flexible member. */
16574 1317 : if (name)
16575 1317 : pedwarn (id_loc, OPT_Wpedantic,
16576 : "ISO C++ forbids flexible array member %qs", name);
16577 : else
16578 : pedwarn (input_location, OPT_Wpedantic,
16579 : "ISO C++ forbids flexible array members");
16580 :
16581 : /* Flexible array member has a null domain. */
16582 1317 : type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
16583 : }
16584 : }
16585 :
16586 149870209 : if (type == error_mark_node)
16587 : {
16588 : /* Happens when declaring arrays of sizes which
16589 : are error_mark_node, for example. */
16590 24 : decl = NULL_TREE;
16591 : }
16592 149870185 : else if (in_namespace && !friendp)
16593 : {
16594 : /* Something like struct S { int N::j; }; */
16595 6 : error_at (id_loc, "invalid use of %<::%>");
16596 6 : return error_mark_node;
16597 : }
16598 149870179 : else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
16599 : {
16600 115215492 : int publicp = 0;
16601 115215492 : tree function_context;
16602 :
16603 115215492 : if (friendp == 0)
16604 : {
16605 : /* This should never happen in pure C++ (the check
16606 : could be an assert). It could happen in
16607 : Objective-C++ if someone writes invalid code that
16608 : uses a function declaration for an instance
16609 : variable or property (instance variables and
16610 : properties are parsed as FIELD_DECLs, but they are
16611 : part of an Objective-C class, not a C++ class).
16612 : That code is invalid and is caught by this
16613 : check. */
16614 108342454 : if (!ctype)
16615 : {
16616 0 : error ("declaration of function %qD in invalid context",
16617 : unqualified_id);
16618 0 : return error_mark_node;
16619 : }
16620 :
16621 : /* ``A union may [ ... ] not [ have ] virtual functions.''
16622 : ARM 9.5 */
16623 108342454 : if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
16624 : {
16625 3 : error_at (declspecs->locations[ds_virtual],
16626 : "function %qD declared %<virtual%> inside a union",
16627 : unqualified_id);
16628 3 : return error_mark_node;
16629 : }
16630 :
16631 4298257 : if (virtualp
16632 119513746 : && identifier_p (unqualified_id)
16633 4298257 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16634 : {
16635 9 : error_at (declspecs->locations[ds_virtual],
16636 : "%qD cannot be declared %<virtual%>, since it "
16637 : "is always static", unqualified_id);
16638 9 : virtualp = 0;
16639 : }
16640 : }
16641 :
16642 : /* Check that the name used for a destructor makes sense. */
16643 115215489 : if (sfk == sfk_destructor)
16644 : {
16645 3214886 : tree uqname = id_declarator->u.id.unqualified_name;
16646 :
16647 3214886 : if (!ctype)
16648 : {
16649 12 : gcc_assert (friendp);
16650 12 : error_at (id_loc, "expected qualified name in friend "
16651 : "declaration for destructor %qD", uqname);
16652 12 : return error_mark_node;
16653 : }
16654 :
16655 3214874 : if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
16656 : {
16657 9 : error_at (id_loc, "declaration of %qD as member of %qT",
16658 : uqname, ctype);
16659 9 : return error_mark_node;
16660 : }
16661 3214865 : if (concept_p)
16662 : {
16663 9 : error_at (declspecs->locations[ds_concept],
16664 : "a destructor cannot be %qs", "concept");
16665 9 : return error_mark_node;
16666 : }
16667 3214856 : if (constexpr_p && cxx_dialect < cxx20)
16668 : {
16669 6 : error_at (declspecs->locations[ds_constexpr],
16670 : "%<constexpr%> destructors only available"
16671 : " with %<-std=c++20%> or %<-std=gnu++20%>");
16672 6 : return error_mark_node;
16673 : }
16674 3214850 : if (consteval_p)
16675 : {
16676 3 : error_at (declspecs->locations[ds_consteval],
16677 : "a destructor cannot be %qs", "consteval");
16678 3 : return error_mark_node;
16679 : }
16680 : }
16681 112000603 : else if (sfk == sfk_constructor && friendp && !ctype)
16682 : {
16683 0 : error ("expected qualified name in friend declaration "
16684 : "for constructor %qD",
16685 0 : id_declarator->u.id.unqualified_name);
16686 0 : return error_mark_node;
16687 : }
16688 115215450 : if (sfk == sfk_constructor)
16689 24477261 : if (concept_p)
16690 : {
16691 9 : error_at (declspecs->locations[ds_concept],
16692 : "a constructor cannot be %<concept%>");
16693 9 : return error_mark_node;
16694 : }
16695 90738189 : if (concept_p)
16696 : {
16697 9 : error_at (declspecs->locations[ds_concept],
16698 : "a concept cannot be a member function");
16699 9 : concept_p = false;
16700 : }
16701 115215432 : else if (consteval_p
16702 116021612 : && identifier_p (unqualified_id)
16703 116021603 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16704 : {
16705 9 : error_at (declspecs->locations[ds_consteval],
16706 : "%qD cannot be %qs", unqualified_id, "consteval");
16707 9 : consteval_p = false;
16708 : }
16709 :
16710 115215441 : if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16711 : {
16712 113281 : tree tmpl = TREE_OPERAND (unqualified_id, 0);
16713 113281 : if (variable_template_p (tmpl))
16714 : {
16715 3 : auto_diagnostic_group d;
16716 3 : error_at (id_loc, "specialization of variable template "
16717 : "%qD declared as function", tmpl);
16718 3 : inform (DECL_SOURCE_LOCATION (tmpl),
16719 : "variable template declared here");
16720 3 : return error_mark_node;
16721 3 : }
16722 : }
16723 :
16724 : /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
16725 115215438 : function_context
16726 : = (ctype != NULL_TREE
16727 115215438 : ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
16728 230430876 : publicp = ((! friendp || ! staticp)
16729 115215438 : && function_context == NULL_TREE);
16730 :
16731 115215438 : decl = grokfndecl (ctype, type,
16732 115215438 : TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
16733 : ? unqualified_id : dname,
16734 : parms,
16735 : unqualified_id,
16736 : declspecs,
16737 : reqs,
16738 : virtualp, flags, memfn_quals, rqual, raises,
16739 : friendp ? -1 : 0, friendp, publicp,
16740 115215438 : inlinep | (2 * constexpr_p) | (4 * concept_p)
16741 115215438 : | (8 * consteval_p),
16742 : initialized,
16743 : is_xobj_member_function, sfk,
16744 : funcdef_flag, late_return_type_p,
16745 : template_count, in_namespace,
16746 : attrlist, contract_specifiers, id_loc);
16747 115215438 : decl = set_virt_specifiers (decl, virt_specifiers);
16748 115215438 : if (decl == NULL_TREE)
16749 97 : return error_mark_node;
16750 : #if 0
16751 : /* This clobbers the attrs stored in `decl' from `attrlist'. */
16752 : /* The decl and setting of decl_attr is also turned off. */
16753 : decl = build_decl_attribute_variant (decl, decl_attr);
16754 : #endif
16755 :
16756 : /* [class.conv.ctor]
16757 :
16758 : A constructor declared without the function-specifier
16759 : explicit that can be called with a single parameter
16760 : specifies a conversion from the type of its first
16761 : parameter to the type of its class. Such a constructor
16762 : is called a converting constructor. */
16763 115215341 : if (explicitp == 2)
16764 6229686 : DECL_NONCONVERTING_P (decl) = 1;
16765 :
16766 115215341 : if (declspecs->explicit_specifier)
16767 455059 : store_explicit_specifier (decl, declspecs->explicit_specifier);
16768 : }
16769 34654687 : else if (!staticp
16770 34654687 : && ((current_class_type
16771 20848629 : && same_type_p (TYPE_MAIN_VARIANT (type),
16772 : current_class_type))
16773 20848533 : || (!dependent_type_p (type)
16774 12578346 : && !COMPLETE_TYPE_P (complete_type (type))
16775 1449 : && (!complete_or_array_type_p (type)
16776 1374 : || initialized == SD_UNINITIALIZED))))
16777 : {
16778 1512 : if (TREE_CODE (type) != ARRAY_TYPE
16779 1512 : || !COMPLETE_TYPE_P (TREE_TYPE (type)))
16780 : {
16781 171 : if (unqualified_id)
16782 : {
16783 126 : auto_diagnostic_group d;
16784 126 : error_at (id_loc, "field %qD has incomplete type %qT",
16785 : unqualified_id, type);
16786 126 : cxx_incomplete_type_inform (strip_array_types (type));
16787 126 : }
16788 : else
16789 45 : error ("name %qT has incomplete type", type);
16790 :
16791 171 : type = error_mark_node;
16792 171 : decl = NULL_TREE;
16793 : }
16794 : }
16795 55500280 : else if (!verify_type_context (input_location,
16796 : staticp
16797 : ? TCTX_STATIC_STORAGE
16798 : : TCTX_FIELD, type))
16799 : {
16800 0 : type = error_mark_node;
16801 0 : decl = NULL_TREE;
16802 : }
16803 : else
16804 : {
16805 34653169 : if (friendp)
16806 : {
16807 12 : if (unqualified_id)
16808 9 : error_at (id_loc,
16809 : "%qE is neither function nor member function; "
16810 : "cannot be declared friend", unqualified_id);
16811 : else
16812 3 : error ("unnamed field is neither function nor member "
16813 : "function; cannot be declared friend");
16814 12 : return error_mark_node;
16815 : }
16816 34653157 : decl = NULL_TREE;
16817 : }
16818 :
16819 149870034 : if (friendp)
16820 : {
16821 6873007 : if (flag_reflection && !funcdef_flag && decl)
16822 : {
16823 16908 : if (attrlist && lookup_annotation (*attrlist))
16824 : {
16825 : /* Remove the annotations to avoid spurious warning
16826 : below. */
16827 8 : *attrlist = remove_attribute ("internal ", "annotation ",
16828 : *attrlist);
16829 8 : error_at (id_loc, "annotation applied to non-defining "
16830 : "friend declaration %qD", decl);
16831 : }
16832 16908 : for (tree arg = DECL_ARGUMENTS (decl);
16833 39450 : arg; arg = DECL_CHAIN (arg))
16834 22542 : if (lookup_annotation (DECL_ATTRIBUTES (arg)))
16835 8 : error_at (DECL_SOURCE_LOCATION (arg),
16836 : "annotation applied to parameter %qD of "
16837 : "non-defining friend declaration", arg);
16838 : }
16839 : /* Packages tend to use GNU attributes on friends, so we only
16840 : warn for standard attributes. */
16841 6873007 : if (attrlist
16842 6873007 : && !funcdef_flag
16843 6873007 : && cxx11_attribute_p (*attrlist))
16844 : {
16845 27 : *attrlist = NULL_TREE;
16846 27 : auto_diagnostic_group d;
16847 27 : if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
16848 27 : inform (id_loc, "an attribute that appertains to a friend "
16849 : "declaration that is not a definition is ignored");
16850 27 : }
16851 : /* Friends are treated specially. */
16852 6873007 : if (ctype == current_class_type)
16853 : ; /* We already issued a permerror. */
16854 6873007 : else if (decl && DECL_NAME (decl))
16855 : {
16856 6873004 : set_originating_module (decl, true);
16857 :
16858 6873004 : if (initialized)
16859 : /* Kludge: We need funcdef_flag to be true in do_friend for
16860 : in-class defaulted functions, but that breaks grokfndecl.
16861 : So set it here. */
16862 221497 : funcdef_flag = true;
16863 :
16864 6873004 : cplus_decl_attributes (&decl, *attrlist, 0);
16865 6873004 : *attrlist = NULL_TREE;
16866 :
16867 6873004 : tree scope = ctype ? ctype : in_namespace;
16868 6873004 : decl = do_friend (scope, unqualified_id, decl,
16869 : flags, funcdef_flag);
16870 6873004 : return decl;
16871 : }
16872 : else
16873 3 : return error_mark_node;
16874 : }
16875 :
16876 : /* Structure field. It may not be a function, except for C++. */
16877 :
16878 142997027 : if (decl == NULL_TREE)
16879 : {
16880 34654690 : if (staticp)
16881 : {
16882 : /* C++ allows static class members. All other work
16883 : for this is done by grokfield. */
16884 13806058 : decl = build_lang_decl_loc (id_loc, VAR_DECL,
16885 : dname, type);
16886 13806058 : if (unqualified_id
16887 13806055 : && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16888 : {
16889 44768 : decl = check_explicit_specialization (unqualified_id, decl,
16890 : template_count,
16891 : concept_p * 8);
16892 44768 : if (decl == error_mark_node)
16893 : return error_mark_node;
16894 : }
16895 13806058 : set_linkage_for_static_data_member (decl);
16896 13806058 : if (concept_p)
16897 15 : error_at (declspecs->locations[ds_concept],
16898 : "static data member %qE declared %qs",
16899 : unqualified_id, "concept");
16900 13806043 : else if (constexpr_p && !initialized)
16901 : {
16902 9 : error_at (DECL_SOURCE_LOCATION (decl),
16903 : "%<constexpr%> static data member %qD must "
16904 : "have an initializer", decl);
16905 9 : constexpr_p = false;
16906 : }
16907 13806058 : if (consteval_p)
16908 3 : error_at (declspecs->locations[ds_consteval],
16909 : "static data member %qE declared %qs",
16910 : unqualified_id, "consteval");
16911 :
16912 13806058 : if (inlinep)
16913 24372 : mark_inline_variable (decl, declspecs->locations[ds_inline]);
16914 :
16915 13806058 : if (!DECL_VAR_DECLARED_INLINE_P (decl)
16916 13806058 : && !(cxx_dialect >= cxx17 && constexpr_p))
16917 : /* Even if there is an in-class initialization, DECL
16918 : is considered undefined until an out-of-class
16919 : definition is provided, unless this is an inline
16920 : variable. */
16921 1921345 : DECL_EXTERNAL (decl) = 1;
16922 :
16923 13806058 : if (thread_p)
16924 : {
16925 422 : CP_DECL_THREAD_LOCAL_P (decl) = true;
16926 422 : if (!processing_template_decl)
16927 376 : set_decl_tls_model (decl, decl_default_tls_model (decl));
16928 422 : if (declspecs->gnu_thread_keyword_p)
16929 34 : SET_DECL_GNU_TLS_P (decl);
16930 : }
16931 :
16932 : /* Set the constraints on the declaration. */
16933 13806058 : bool memtmpl = (current_template_depth
16934 13806058 : > template_class_depth (current_class_type));
16935 13806058 : if (memtmpl)
16936 : {
16937 401338 : tree ci = current_template_constraints ();
16938 401338 : set_constraints (decl, ci);
16939 : }
16940 : }
16941 : else
16942 : {
16943 20848632 : if (concept_p)
16944 : {
16945 12 : error_at (declspecs->locations[ds_concept],
16946 : "non-static data member %qE declared %qs",
16947 : unqualified_id, "concept");
16948 12 : concept_p = false;
16949 12 : constexpr_p = false;
16950 : }
16951 20848620 : else if (constexpr_p)
16952 : {
16953 9 : error_at (declspecs->locations[ds_constexpr],
16954 : "non-static data member %qE declared %qs",
16955 : unqualified_id, "constexpr");
16956 9 : constexpr_p = false;
16957 : }
16958 20848632 : if (constinit_p)
16959 : {
16960 6 : error_at (declspecs->locations[ds_constinit],
16961 : "non-static data member %qE declared %qs",
16962 : unqualified_id, "constinit");
16963 6 : constinit_p = false;
16964 : }
16965 20848632 : if (consteval_p)
16966 : {
16967 3 : error_at (declspecs->locations[ds_consteval],
16968 : "non-static data member %qE declared %qs",
16969 : unqualified_id, "consteval");
16970 3 : consteval_p = false;
16971 : }
16972 20848632 : decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
16973 20848632 : DECL_NONADDRESSABLE_P (decl) = bitfield;
16974 20848632 : if (bitfield && !unqualified_id)
16975 139266 : DECL_PADDING_P (decl) = 1;
16976 :
16977 20848632 : if (storage_class == sc_mutable)
16978 : {
16979 142647 : DECL_MUTABLE_P (decl) = 1;
16980 142647 : storage_class = sc_none;
16981 : }
16982 :
16983 20848632 : if (initialized)
16984 : {
16985 : /* An attempt is being made to initialize a non-static
16986 : member. This is new in C++11. */
16987 2424207 : maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
16988 :
16989 : /* If this has been parsed with static storage class, but
16990 : errors forced staticp to be cleared, ensure NSDMI is
16991 : not present. */
16992 2424207 : if (declspecs->storage_class == sc_static)
16993 3 : DECL_INITIAL (decl) = error_mark_node;
16994 : }
16995 : }
16996 :
16997 55503322 : bad_specifiers (decl, BSP_FIELD, virtualp,
16998 : memfn_quals != TYPE_UNQUALIFIED,
16999 : staticp ? false : inlinep, friendp,
17000 : raises != NULL_TREE,
17001 : declspecs->locations);
17002 : }
17003 : }
17004 154264827 : else if (FUNC_OR_METHOD_TYPE_P (type))
17005 : {
17006 82315277 : tree original_name;
17007 82315277 : int publicp = 0;
17008 :
17009 82315277 : if (!unqualified_id)
17010 0 : return error_mark_node;
17011 :
17012 82315277 : if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
17013 : original_name = dname;
17014 : else
17015 81426325 : original_name = unqualified_id;
17016 : // FIXME:gcc_assert (original_name == dname);
17017 :
17018 82315277 : if (storage_class == sc_auto)
17019 1 : error_at (declspecs->locations[ds_storage_class],
17020 : "storage class %<auto%> invalid for function %qs", name);
17021 82315276 : else if (storage_class == sc_register)
17022 7 : error_at (declspecs->locations[ds_storage_class],
17023 : "storage class %<register%> invalid for function %qs",
17024 : name);
17025 82315269 : else if (thread_p)
17026 : {
17027 12 : if (declspecs->gnu_thread_keyword_p)
17028 12 : error_at (declspecs->locations[ds_thread],
17029 : "storage class %<__thread%> invalid for function %qs",
17030 : name);
17031 : else
17032 0 : error_at (declspecs->locations[ds_thread],
17033 : "storage class %<thread_local%> invalid for "
17034 : "function %qs", name);
17035 : }
17036 82315257 : else if (constinit_p)
17037 3 : error_at (declspecs->locations[ds_constinit],
17038 : "%<constinit%> specifier invalid for function %qs", name);
17039 :
17040 82315277 : if (virt_specifiers)
17041 6 : error ("virt-specifiers in %qs not allowed outside a class "
17042 : "definition", name);
17043 : /* Function declaration not at top level.
17044 : Storage classes other than `extern' are not allowed
17045 : and `extern' makes no difference. */
17046 82315277 : if (! toplevel_bindings_p ()
17047 62604 : && (storage_class == sc_static
17048 62595 : || decl_spec_seq_has_spec_p (declspecs, ds_inline))
17049 82315289 : && pedantic)
17050 : {
17051 9 : if (storage_class == sc_static)
17052 6 : pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
17053 : "%<static%> specifier invalid for function %qs "
17054 : "declared out of global scope", name);
17055 : else
17056 3 : pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
17057 : "%<inline%> specifier invalid for function %qs "
17058 : "declared out of global scope", name);
17059 : }
17060 :
17061 82315277 : if (ctype == NULL_TREE)
17062 : {
17063 72941101 : if (virtualp)
17064 : {
17065 0 : error ("virtual non-class function %qs", name);
17066 0 : virtualp = 0;
17067 : }
17068 72941101 : else if (sfk == sfk_constructor
17069 72941101 : || sfk == sfk_destructor)
17070 : {
17071 3 : error (funcdef_flag
17072 : ? G_("%qs defined in a non-class scope")
17073 : : G_("%qs declared in a non-class scope"), name);
17074 3 : sfk = sfk_none;
17075 : }
17076 : }
17077 82315277 : if (consteval_p
17078 82678053 : && identifier_p (unqualified_id)
17079 82678053 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
17080 : {
17081 9 : error_at (declspecs->locations[ds_consteval],
17082 : "%qD cannot be %qs", unqualified_id, "consteval");
17083 9 : consteval_p = false;
17084 : }
17085 :
17086 : /* Record whether the function is public. */
17087 82315277 : publicp = (ctype != NULL_TREE
17088 82315277 : || storage_class != sc_static);
17089 :
17090 164630554 : decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
17091 : declspecs, reqs, virtualp, flags, memfn_quals, rqual, raises,
17092 : 1, friendp,
17093 : publicp,
17094 82315277 : inlinep | (2 * constexpr_p) | (4 * concept_p)
17095 82315277 : | (8 * consteval_p),
17096 : initialized,
17097 : is_xobj_member_function, sfk,
17098 : funcdef_flag,
17099 : late_return_type_p,
17100 : template_count, in_namespace, attrlist,
17101 : contract_specifiers, id_loc);
17102 82315277 : if (decl == NULL_TREE)
17103 619 : return error_mark_node;
17104 :
17105 82314658 : if (explicitp == 2)
17106 11415 : DECL_NONCONVERTING_P (decl) = 1;
17107 82314658 : if (staticp == 1)
17108 : {
17109 118517 : int invalid_static = 0;
17110 :
17111 : /* Don't allow a static member function in a class, and forbid
17112 : declaring main to be static. */
17113 118517 : if (TREE_CODE (type) == METHOD_TYPE)
17114 : {
17115 0 : permerror (input_location, "cannot declare member function %qD to have "
17116 : "static linkage", decl);
17117 0 : invalid_static = 1;
17118 : }
17119 118517 : else if (current_function_decl)
17120 : {
17121 : /* 7.1.1: There can be no static function declarations within a
17122 : block. */
17123 9 : error_at (declspecs->locations[ds_storage_class],
17124 : "cannot declare static function inside another function");
17125 9 : invalid_static = 1;
17126 : }
17127 :
17128 9 : if (invalid_static)
17129 : {
17130 82314658 : staticp = 0;
17131 : storage_class = sc_none;
17132 : }
17133 : }
17134 82314658 : if (declspecs->explicit_specifier)
17135 3 : store_explicit_specifier (decl, declspecs->explicit_specifier);
17136 : }
17137 : else
17138 : {
17139 : /* It's a variable. */
17140 :
17141 : /* An uninitialized decl with `extern' is a reference. */
17142 143376064 : decl = grokvardecl (type, dname, unqualified_id,
17143 : declspecs,
17144 : initialized,
17145 : type_quals,
17146 : inlinep,
17147 : concept_p,
17148 : template_count,
17149 : ctype ? ctype : in_namespace,
17150 : id_loc);
17151 71949550 : if (decl == NULL_TREE)
17152 92 : return error_mark_node;
17153 :
17154 71949458 : bad_specifiers (decl, BSP_VAR, virtualp,
17155 : memfn_quals != TYPE_UNQUALIFIED,
17156 : inlinep, friendp, raises != NULL_TREE,
17157 : declspecs->locations);
17158 :
17159 71949458 : if (ctype)
17160 : {
17161 523030 : DECL_CONTEXT (decl) = ctype;
17162 523030 : if (staticp == 1)
17163 : {
17164 6 : permerror (declspecs->locations[ds_storage_class],
17165 : "%<static%> may not be used when defining "
17166 : "(as opposed to declaring) a static data member");
17167 6 : staticp = 0;
17168 6 : storage_class = sc_none;
17169 : }
17170 523030 : if (storage_class == sc_register && TREE_STATIC (decl))
17171 : {
17172 0 : error ("static member %qD declared %<register%>", decl);
17173 0 : storage_class = sc_none;
17174 : }
17175 523030 : if (storage_class == sc_extern && pedantic)
17176 : {
17177 0 : pedwarn (input_location, OPT_Wpedantic,
17178 : "cannot explicitly declare member %q#D to have "
17179 : "extern linkage", decl);
17180 0 : storage_class = sc_none;
17181 : }
17182 : }
17183 71426428 : else if (constexpr_p && DECL_EXTERNAL (decl))
17184 : {
17185 14 : error_at (DECL_SOURCE_LOCATION (decl),
17186 : "declaration of %<constexpr%> variable %qD "
17187 : "is not a definition", decl);
17188 14 : constexpr_p = false;
17189 : }
17190 71949458 : if (consteval_p)
17191 : {
17192 13 : error_at (DECL_SOURCE_LOCATION (decl),
17193 : "a variable cannot be declared %<consteval%>");
17194 13 : consteval_p = false;
17195 : }
17196 :
17197 71949458 : if (inlinep)
17198 6997446 : mark_inline_variable (decl, declspecs->locations[ds_inline]);
17199 71949458 : if (innermost_code == cdk_decomp)
17200 : {
17201 247806 : gcc_assert (declarator && declarator->kind == cdk_decomp);
17202 247806 : DECL_SOURCE_LOCATION (decl) = id_loc;
17203 247806 : DECL_ARTIFICIAL (decl) = 1;
17204 247806 : fit_decomposition_lang_decl (decl, NULL_TREE);
17205 : }
17206 : }
17207 :
17208 606138993 : if (VAR_P (decl) && !initialized)
17209 7727127 : if (tree auto_node = type_uses_auto (type))
17210 104 : if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
17211 : {
17212 21 : location_t loc = declspecs->locations[ds_type_spec];
17213 21 : error_at (loc, "declaration of %q#D has no initializer", decl);
17214 21 : TREE_TYPE (decl) = error_mark_node;
17215 : }
17216 :
17217 606138993 : if (storage_class == sc_extern && initialized && !funcdef_flag)
17218 : {
17219 277 : if (toplevel_bindings_p ())
17220 : {
17221 : /* It's common practice (and completely valid) to have a const
17222 : be initialized and declared extern. */
17223 253 : if (!(type_quals & TYPE_QUAL_CONST))
17224 20 : warning_at (DECL_SOURCE_LOCATION (decl), 0,
17225 : "%qs initialized and declared %<extern%>", name);
17226 : }
17227 : else
17228 : {
17229 24 : error_at (DECL_SOURCE_LOCATION (decl),
17230 : "%qs has both %<extern%> and initializer", name);
17231 24 : return error_mark_node;
17232 : }
17233 : }
17234 :
17235 : /* Record `register' declaration for warnings on &
17236 : and in case doing stupid register allocation. */
17237 :
17238 606138969 : if (storage_class == sc_register)
17239 : {
17240 2069 : DECL_REGISTER (decl) = 1;
17241 : /* Warn about register storage specifiers on PARM_DECLs. */
17242 2069 : if (TREE_CODE (decl) == PARM_DECL)
17243 : {
17244 35 : if (cxx_dialect >= cxx17)
17245 24 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
17246 : "ISO C++17 does not allow %<register%> storage "
17247 : "class specifier");
17248 : else
17249 11 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
17250 : "%<register%> storage class specifier used");
17251 : }
17252 : }
17253 606136900 : else if (storage_class == sc_extern)
17254 32287153 : DECL_THIS_EXTERN (decl) = 1;
17255 573849747 : else if (storage_class == sc_static)
17256 25128209 : DECL_THIS_STATIC (decl) = 1;
17257 :
17258 606138969 : if (VAR_P (decl))
17259 : {
17260 : /* Set constexpr flag on vars (functions got it in grokfndecl). */
17261 85755492 : if (constexpr_p)
17262 20893345 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
17263 : /* And the constinit flag (which only applies to variables). */
17264 64862147 : else if (constinit_p)
17265 453 : DECL_DECLARED_CONSTINIT_P (decl) = true;
17266 : }
17267 520383477 : else if (TREE_CODE (decl) == FUNCTION_DECL)
17268 : {
17269 : /* If we saw a return type, record its location. */
17270 190656995 : location_t loc = declspecs->locations[ds_type_spec];
17271 190656995 : if (loc == UNKNOWN_LOCATION)
17272 : /* Build DECL_RESULT in start_preparsed_function. */;
17273 155978759 : else if (!DECL_RESULT (decl))
17274 : {
17275 155938805 : tree restype = TREE_TYPE (TREE_TYPE (decl));
17276 155938805 : tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
17277 155938805 : DECL_ARTIFICIAL (resdecl) = 1;
17278 155938805 : DECL_IGNORED_P (resdecl) = 1;
17279 155938805 : DECL_RESULT (decl) = resdecl;
17280 : }
17281 39954 : else if (funcdef_flag)
17282 3 : DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
17283 : }
17284 :
17285 : /* Record constancy and volatility on the DECL itself . There's
17286 : no need to do this when processing a template; we'll do this
17287 : for the instantiated declaration based on the type of DECL. */
17288 606138969 : if (!processing_template_decl
17289 : /* Don't do it for instantiated variable templates either,
17290 : cp_apply_type_quals_to_decl should have been called on it
17291 : already and might have been overridden in cp_finish_decl
17292 : if initializer needs runtime initialization. */
17293 606138969 : && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
17294 202458105 : cp_apply_type_quals_to_decl (type_quals, decl);
17295 :
17296 606138969 : return decl;
17297 : }
17298 1092297429 : }
17299 :
17300 : /* Subroutine of start_function. Ensure that each of the parameter
17301 : types (as listed in PARMS) is complete, as is required for a
17302 : function definition. */
17303 :
17304 : static void
17305 169405640 : require_complete_types_for_parms (tree parms)
17306 : {
17307 501509190 : for (; parms; parms = DECL_CHAIN (parms))
17308 : {
17309 332103550 : if (dependent_type_p (TREE_TYPE (parms)))
17310 186390250 : continue;
17311 145713300 : if (!VOID_TYPE_P (TREE_TYPE (parms))
17312 145713300 : && complete_type_or_else (TREE_TYPE (parms), parms))
17313 : {
17314 145713219 : relayout_decl (parms);
17315 145713219 : DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
17316 :
17317 145713219 : abstract_virtuals_error (parms, TREE_TYPE (parms));
17318 145713219 : maybe_warn_parm_abi (TREE_TYPE (parms),
17319 145713219 : DECL_SOURCE_LOCATION (parms));
17320 : }
17321 : else
17322 : /* grokparms or complete_type_or_else will have already issued
17323 : an error. */
17324 81 : TREE_TYPE (parms) = error_mark_node;
17325 : }
17326 169405640 : }
17327 :
17328 : /* Returns nonzero if T is a local variable. */
17329 :
17330 : int
17331 181658646 : local_variable_p (const_tree t)
17332 : {
17333 181658646 : if ((VAR_P (t)
17334 70214594 : && (DECL_LOCAL_DECL_P (t)
17335 70214594 : || !DECL_CONTEXT (t)
17336 70170946 : || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
17337 187566397 : || (TREE_CODE (t) == PARM_DECL))
17338 161608845 : return 1;
17339 :
17340 : return 0;
17341 : }
17342 :
17343 : /* Like local_variable_p, but suitable for use as a tree-walking
17344 : function. */
17345 :
17346 : static tree
17347 5763595 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
17348 : void * /*data*/)
17349 : {
17350 5763595 : if (unevaluated_p (TREE_CODE (*tp)))
17351 : {
17352 : /* DR 2082 permits local variables in unevaluated contexts
17353 : within a default argument. */
17354 70 : *walk_subtrees = 0;
17355 70 : return NULL_TREE;
17356 : }
17357 :
17358 5763525 : if (local_variable_p (*tp)
17359 5763525 : && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
17360 : return *tp;
17361 5763525 : else if (TYPE_P (*tp))
17362 30 : *walk_subtrees = 0;
17363 :
17364 : return NULL_TREE;
17365 : }
17366 :
17367 : /* Check that ARG, which is a default-argument expression for a
17368 : parameter DECL, is valid. Returns ARG, or ERROR_MARK_NODE, if
17369 : something goes wrong. DECL may also be a _TYPE node, rather than a
17370 : DECL, if there is no DECL available. */
17371 :
17372 : tree
17373 2846986 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
17374 : {
17375 2846986 : tree var;
17376 2846986 : tree decl_type;
17377 :
17378 2846986 : if (TREE_CODE (arg) == DEFERRED_PARSE)
17379 : /* We get a DEFERRED_PARSE when looking at an in-class declaration
17380 : with a default argument. Ignore the argument for now; we'll
17381 : deal with it after the class is complete. */
17382 : return arg;
17383 :
17384 2017304 : if (TYPE_P (decl))
17385 : {
17386 : decl_type = decl;
17387 : decl = NULL_TREE;
17388 : }
17389 : else
17390 614317 : decl_type = TREE_TYPE (decl);
17391 :
17392 2017304 : if (arg == error_mark_node
17393 2017163 : || decl == error_mark_node
17394 2017154 : || TREE_TYPE (arg) == error_mark_node
17395 4034458 : || decl_type == error_mark_node)
17396 : /* Something already went wrong. There's no need to check
17397 : further. */
17398 : return error_mark_node;
17399 :
17400 : /* [dcl.fct.default]
17401 :
17402 : A default argument expression is implicitly converted to the
17403 : parameter type. */
17404 2017154 : ++cp_unevaluated_operand;
17405 : /* Avoid digest_init clobbering the initializer. */
17406 2017154 : tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
17407 2017154 : perform_implicit_conversion_flags (decl_type, carg, complain,
17408 : LOOKUP_IMPLICIT);
17409 2017154 : --cp_unevaluated_operand;
17410 :
17411 : /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
17412 : the call sites. */
17413 1604164 : if (TYPE_PTR_OR_PTRMEM_P (decl_type)
17414 413005 : && null_ptr_cst_p (arg)
17415 : /* Don't lose side-effects as in PR90473. */
17416 2395253 : && !TREE_SIDE_EFFECTS (arg))
17417 378096 : return nullptr_node;
17418 :
17419 : /* [dcl.fct.default]
17420 :
17421 : Local variables shall not be used in default argument
17422 : expressions.
17423 :
17424 : The keyword `this' shall not be used in a default argument of a
17425 : member function. */
17426 1639058 : var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
17427 1639058 : if (var)
17428 : {
17429 0 : if (complain & tf_warning_or_error)
17430 : {
17431 0 : if (DECL_NAME (var) == this_identifier)
17432 0 : permerror (input_location, "default argument %qE uses %qD",
17433 : arg, var);
17434 : else
17435 0 : error ("default argument %qE uses local variable %qD", arg, var);
17436 : }
17437 0 : return error_mark_node;
17438 : }
17439 :
17440 : /* All is well. */
17441 1639058 : return arg;
17442 : }
17443 :
17444 : /* Returns a deprecated type used within TYPE, or NULL_TREE if none. */
17445 :
17446 : static tree
17447 295294256 : type_is_deprecated (tree type)
17448 : {
17449 435175922 : enum tree_code code;
17450 435175922 : if (TREE_DEPRECATED (type))
17451 : return type;
17452 435134245 : if (TYPE_NAME (type))
17453 : {
17454 290831968 : if (TREE_DEPRECATED (TYPE_NAME (type)))
17455 : return type;
17456 : else
17457 : {
17458 290831962 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
17459 290831962 : return NULL_TREE;
17460 : }
17461 : }
17462 :
17463 : /* Do warn about using typedefs to a deprecated class. */
17464 144302277 : if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
17465 0 : return type_is_deprecated (TYPE_MAIN_VARIANT (type));
17466 :
17467 144302277 : code = TREE_CODE (type);
17468 :
17469 144302277 : if (code == POINTER_TYPE || code == REFERENCE_TYPE
17470 144302277 : || code == OFFSET_TYPE || code == FUNCTION_TYPE
17471 : || code == METHOD_TYPE || code == ARRAY_TYPE)
17472 139758246 : return type_is_deprecated (TREE_TYPE (type));
17473 :
17474 123420 : if (TYPE_PTRMEMFUNC_P (type))
17475 123420 : return type_is_deprecated
17476 123420 : (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
17477 :
17478 : return NULL_TREE;
17479 : }
17480 :
17481 : /* Returns an unavailable type used within TYPE, or NULL_TREE if none. */
17482 :
17483 : static tree
17484 296553623 : type_is_unavailable (tree type)
17485 : {
17486 437188564 : enum tree_code code;
17487 437188564 : if (TREE_UNAVAILABLE (type))
17488 : return type;
17489 437188558 : if (TYPE_NAME (type))
17490 : {
17491 292132949 : if (TREE_UNAVAILABLE (TYPE_NAME (type)))
17492 : return type;
17493 : else
17494 : {
17495 292132943 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
17496 292132943 : return NULL_TREE;
17497 : }
17498 : }
17499 :
17500 : /* Do warn about using typedefs to a deprecated class. */
17501 145055609 : if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
17502 0 : return type_is_deprecated (TYPE_MAIN_VARIANT (type));
17503 :
17504 145055609 : code = TREE_CODE (type);
17505 :
17506 145055609 : if (code == POINTER_TYPE || code == REFERENCE_TYPE
17507 145055609 : || code == OFFSET_TYPE || code == FUNCTION_TYPE
17508 : || code == METHOD_TYPE || code == ARRAY_TYPE)
17509 140395369 : return type_is_unavailable (TREE_TYPE (type));
17510 :
17511 239572 : if (TYPE_PTRMEMFUNC_P (type))
17512 239572 : return type_is_unavailable
17513 239572 : (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
17514 :
17515 : return NULL_TREE;
17516 : }
17517 :
17518 : /* Decode the list of parameter types for a function type.
17519 : Given the list of things declared inside the parens,
17520 : return a list of types.
17521 :
17522 : If this parameter does not end with an ellipsis, we append
17523 : void_list_node.
17524 :
17525 : *PARMS is set to the chain of PARM_DECLs created. */
17526 :
17527 : tree
17528 203102359 : grokparms (tree parmlist, tree *parms)
17529 : {
17530 203102359 : tree result = NULL_TREE;
17531 203102359 : tree decls = NULL_TREE;
17532 203102359 : tree parm;
17533 203102359 : int any_error = 0;
17534 :
17535 500308702 : for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
17536 : {
17537 497714433 : tree type = NULL_TREE;
17538 497714433 : tree init = TREE_PURPOSE (parm);
17539 497714433 : tree decl = TREE_VALUE (parm);
17540 :
17541 497714433 : if (parm == void_list_node || parm == explicit_void_list_node)
17542 : break;
17543 :
17544 297206359 : if (! decl || TREE_TYPE (decl) == error_mark_node)
17545 : {
17546 198 : any_error = 1;
17547 198 : continue;
17548 : }
17549 :
17550 297206161 : type = TREE_TYPE (decl);
17551 297206161 : if (VOID_TYPE_P (type))
17552 : {
17553 82 : if (same_type_p (type, void_type_node)
17554 73 : && !init
17555 61 : && !DECL_NAME (decl) && !result
17556 110 : && TREE_CHAIN (parm) == void_list_node)
17557 : /* DR 577: A parameter list consisting of a single
17558 : unnamed parameter of non-dependent type 'void'. */
17559 : break;
17560 66 : else if (cv_qualified_p (type))
17561 9 : error_at (DECL_SOURCE_LOCATION (decl),
17562 : "invalid use of cv-qualified type %qT in "
17563 : "parameter declaration", type);
17564 : else
17565 57 : error_at (DECL_SOURCE_LOCATION (decl),
17566 : "invalid use of type %<void%> in parameter "
17567 : "declaration");
17568 : /* It's not a good idea to actually create parameters of
17569 : type `void'; other parts of the compiler assume that a
17570 : void type terminates the parameter list. */
17571 66 : type = error_mark_node;
17572 66 : TREE_TYPE (decl) = error_mark_node;
17573 : }
17574 :
17575 297206145 : if (type != error_mark_node)
17576 : {
17577 297206079 : if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
17578 : {
17579 296553623 : tree unavailtype = type_is_unavailable (type);
17580 296553623 : if (unavailtype)
17581 12 : cp_handle_deprecated_or_unavailable (unavailtype);
17582 : }
17583 297206079 : if (deprecated_state != DEPRECATED_SUPPRESS
17584 297206079 : && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
17585 : {
17586 295294256 : tree deptype = type_is_deprecated (type);
17587 295294256 : if (deptype)
17588 41683 : cp_handle_deprecated_or_unavailable (deptype);
17589 : }
17590 :
17591 : /* [dcl.fct] "A parameter with volatile-qualified type is
17592 : deprecated." */
17593 297206079 : if (CP_TYPE_VOLATILE_P (type))
17594 564 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
17595 : "%<volatile%>-qualified parameter is "
17596 : "deprecated");
17597 :
17598 : /* Top-level qualifiers on the parameters are
17599 : ignored for function types. */
17600 297206079 : type = cp_build_qualified_type (type, 0);
17601 297206079 : if (TREE_CODE (type) == METHOD_TYPE)
17602 : {
17603 0 : error ("parameter %qD invalidly declared method type", decl);
17604 0 : type = build_pointer_type (type);
17605 0 : TREE_TYPE (decl) = type;
17606 : }
17607 297206079 : else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
17608 : {
17609 : /* Before C++17 DR 393:
17610 : [dcl.fct]/6, parameter types cannot contain pointers
17611 : (references) to arrays of unknown bound. */
17612 1768337 : tree t = TREE_TYPE (type);
17613 1768337 : int ptr = TYPE_PTR_P (type);
17614 :
17615 1937421 : while (1)
17616 : {
17617 1852879 : if (TYPE_PTR_P (t))
17618 : ptr = 1;
17619 1771621 : else if (TREE_CODE (t) != ARRAY_TYPE)
17620 : break;
17621 3294 : else if (!TYPE_DOMAIN (t))
17622 : break;
17623 84542 : t = TREE_TYPE (t);
17624 : }
17625 1768337 : if (TREE_CODE (t) == ARRAY_TYPE)
17626 16 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
17627 : ptr
17628 : ? G_("parameter %qD includes pointer to array of "
17629 : "unknown bound %qT")
17630 : : G_("parameter %qD includes reference to array of "
17631 : "unknown bound %qT"),
17632 : decl, t);
17633 : }
17634 :
17635 297206079 : if (init && !processing_template_decl)
17636 1443990 : init = check_default_argument (decl, init, tf_warning_or_error);
17637 : }
17638 :
17639 297206145 : DECL_CHAIN (decl) = decls;
17640 297206145 : decls = decl;
17641 297206145 : result = tree_cons (init, type, result);
17642 : }
17643 203102359 : decls = nreverse (decls);
17644 203102359 : result = nreverse (result);
17645 203102359 : if (parm)
17646 200508090 : result = chainon (result, void_list_node);
17647 203102359 : *parms = decls;
17648 203102359 : if (any_error)
17649 183 : result = NULL_TREE;
17650 :
17651 183 : if (any_error)
17652 : /* We had parm errors, recover by giving the function (...) type. */
17653 183 : result = NULL_TREE;
17654 :
17655 203102359 : return result;
17656 : }
17657 :
17658 :
17659 : /* D is a constructor or overloaded `operator='.
17660 :
17661 : Let T be the class in which D is declared. Then, this function
17662 : returns:
17663 :
17664 : -1 if D's is an ill-formed constructor or copy assignment operator
17665 : whose first parameter is of type `T'.
17666 : 0 if D is not a copy constructor or copy assignment
17667 : operator.
17668 : 1 if D is a copy constructor or copy assignment operator whose
17669 : first parameter is a reference to non-const qualified T.
17670 : 2 if D is a copy constructor or copy assignment operator whose
17671 : first parameter is a reference to const qualified T.
17672 :
17673 : This function can be used as a predicate. Positive values indicate
17674 : a copy constructor and nonzero values indicate a copy assignment
17675 : operator. */
17676 :
17677 : int
17678 357485740 : copy_fn_p (const_tree d)
17679 : {
17680 357485740 : tree args;
17681 357485740 : tree arg_type;
17682 357485740 : int result = 1;
17683 :
17684 357485740 : gcc_assert (DECL_FUNCTION_MEMBER_P (d));
17685 :
17686 357485740 : if (TREE_CODE (d) == TEMPLATE_DECL
17687 357485740 : || (DECL_TEMPLATE_INFO (d)
17688 158415615 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
17689 : /* Instantiations of template member functions are never copy
17690 : functions. Note that member functions of templated classes are
17691 : represented as template functions internally, and we must
17692 : accept those as copy functions. */
17693 : return 0;
17694 :
17695 301756011 : if (!DECL_CONSTRUCTOR_P (d)
17696 301756011 : && DECL_NAME (d) != assign_op_identifier)
17697 : return 0;
17698 :
17699 300922573 : if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
17700 : {
17701 282 : tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
17702 282 : if (!TYPE_REF_P (object_param)
17703 255 : || TYPE_REF_IS_RVALUE (object_param)
17704 : /* Reject unrelated object parameters. */
17705 237 : || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
17706 519 : || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
17707 : return 0;
17708 228 : args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
17709 : }
17710 : else
17711 300922291 : args = FUNCTION_FIRST_USER_PARMTYPE (d);
17712 300922519 : if (!args)
17713 : return 0;
17714 :
17715 300914670 : arg_type = TREE_VALUE (args);
17716 300914670 : if (arg_type == error_mark_node)
17717 : return 0;
17718 :
17719 300914635 : if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
17720 : {
17721 : /* Pass by value copy assignment operator. */
17722 : result = -1;
17723 : }
17724 300913091 : else if (TYPE_REF_P (arg_type)
17725 190646576 : && !TYPE_REF_IS_RVALUE (arg_type)
17726 421652379 : && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
17727 : {
17728 97313392 : if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
17729 97141540 : result = 2;
17730 : }
17731 : else
17732 : return 0;
17733 :
17734 97314936 : args = TREE_CHAIN (args);
17735 :
17736 100273568 : if (args && args != void_list_node && !TREE_PURPOSE (args))
17737 : /* There are more non-optional args. */
17738 2958118 : return 0;
17739 :
17740 : return result;
17741 : }
17742 :
17743 : /* D is a constructor or overloaded `operator='.
17744 :
17745 : Let T be the class in which D is declared. Then, this function
17746 : returns true when D is a move constructor or move assignment
17747 : operator, false otherwise. */
17748 :
17749 : bool
17750 165984379 : move_fn_p (const_tree d)
17751 : {
17752 165984379 : if (cxx_dialect == cxx98)
17753 : /* There are no move constructors if we are in C++98 mode. */
17754 : return false;
17755 :
17756 165907764 : if (TREE_CODE (d) == TEMPLATE_DECL
17757 165907764 : || (DECL_TEMPLATE_INFO (d)
17758 67059047 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
17759 : /* Instantiations of template member functions are never move
17760 : functions. Note that member functions of templated classes are
17761 : represented as template functions internally, and we must
17762 : accept those as move functions. */
17763 : return 0;
17764 :
17765 134669240 : return move_signature_fn_p (d);
17766 : }
17767 :
17768 : /* D is a constructor or overloaded `operator='.
17769 :
17770 : Then, this function returns true when D has the same signature as a move
17771 : constructor or move assignment operator (because either it is such a
17772 : ctor/op= or it is a template specialization with the same signature),
17773 : false otherwise. */
17774 :
17775 : bool
17776 134669240 : move_signature_fn_p (const_tree d)
17777 : {
17778 134669240 : tree args;
17779 134669240 : tree arg_type;
17780 134669240 : bool result = false;
17781 :
17782 134669240 : if (!DECL_CONSTRUCTOR_P (d)
17783 134669240 : && DECL_NAME (d) != assign_op_identifier)
17784 : return 0;
17785 :
17786 134669014 : if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
17787 : {
17788 126 : tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
17789 126 : if (!TYPE_REF_P (object_param)
17790 102 : || TYPE_REF_IS_RVALUE (object_param)
17791 : /* Reject unrelated object parameters. */
17792 90 : || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
17793 216 : || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
17794 : return 0;
17795 84 : args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
17796 : }
17797 : else
17798 134668888 : args = FUNCTION_FIRST_USER_PARMTYPE (d);
17799 134668972 : if (!args)
17800 : return 0;
17801 :
17802 134665988 : arg_type = TREE_VALUE (args);
17803 134665988 : if (arg_type == error_mark_node)
17804 : return 0;
17805 :
17806 134665980 : if (TYPE_REF_P (arg_type)
17807 68505430 : && TYPE_REF_IS_RVALUE (arg_type)
17808 188359059 : && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
17809 : DECL_CONTEXT (d)))
17810 : result = true;
17811 :
17812 134665980 : args = TREE_CHAIN (args);
17813 :
17814 150444765 : if (args && args != void_list_node && !TREE_PURPOSE (args))
17815 : /* There are more non-optional args. */
17816 12531452 : return false;
17817 :
17818 : return result;
17819 : }
17820 :
17821 : /* Remember any special properties of member function DECL. */
17822 :
17823 : void
17824 367677782 : grok_special_member_properties (tree decl)
17825 : {
17826 367677782 : tree class_type;
17827 :
17828 367677782 : if (TREE_CODE (decl) == USING_DECL
17829 367677782 : || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
17830 : return;
17831 :
17832 344621008 : class_type = DECL_CONTEXT (decl);
17833 344621008 : if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
17834 : {
17835 155566411 : int ctor = copy_fn_p (decl);
17836 :
17837 155566411 : if (!DECL_ARTIFICIAL (decl))
17838 107946964 : TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
17839 :
17840 155566411 : if (ctor > 0)
17841 : {
17842 : /* [class.copy]
17843 :
17844 : A non-template constructor for class X is a copy
17845 : constructor if its first parameter is of type X&, const
17846 : X&, volatile X& or const volatile X&, and either there
17847 : are no other parameters or else all other parameters have
17848 : default arguments. */
17849 31715259 : TYPE_HAS_COPY_CTOR (class_type) = 1;
17850 31715259 : if (ctor > 1)
17851 31635566 : TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
17852 : }
17853 :
17854 155566411 : if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
17855 33202224 : TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
17856 :
17857 155566411 : if (is_list_ctor (decl))
17858 1582823 : TYPE_HAS_LIST_CTOR (class_type) = 1;
17859 :
17860 155566411 : if (maybe_constexpr_fn (decl)
17861 155566411 : && !ctor && !move_fn_p (decl))
17862 56772382 : TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
17863 : }
17864 189054597 : else if (DECL_NAME (decl) == assign_op_identifier)
17865 : {
17866 : /* [class.copy]
17867 :
17868 : A non-template assignment operator for class X is a copy
17869 : assignment operator if its parameter is of type X, X&, const
17870 : X&, volatile X& or const volatile X&. */
17871 :
17872 15710401 : int assop = copy_fn_p (decl);
17873 :
17874 15710401 : if (assop)
17875 : {
17876 7991481 : TYPE_HAS_COPY_ASSIGN (class_type) = 1;
17877 7991481 : if (assop != 1)
17878 7962511 : TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
17879 : }
17880 : }
17881 173344196 : else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
17882 2863843 : TYPE_HAS_CONVERSION (class_type) = true;
17883 :
17884 : /* Destructors are handled in check_methods. */
17885 : }
17886 :
17887 : /* Check a constructor DECL has the correct form. Complains
17888 : if the class has a constructor of the form X(X). */
17889 :
17890 : bool
17891 49983172 : grok_ctor_properties (const_tree ctype, const_tree decl)
17892 : {
17893 49983172 : int ctor_parm = copy_fn_p (decl);
17894 :
17895 49983172 : if (ctor_parm < 0)
17896 : {
17897 : /* [class.copy]
17898 :
17899 : A declaration of a constructor for a class X is ill-formed if
17900 : its first parameter is of type (optionally cv-qualified) X
17901 : and either there are no other parameters or else all other
17902 : parameters have default arguments.
17903 :
17904 : We *don't* complain about member template instantiations that
17905 : have this form, though; they can occur as we try to decide
17906 : what constructor to use during overload resolution. Since
17907 : overload resolution will never prefer such a constructor to
17908 : the non-template copy constructor (which is either explicitly
17909 : or implicitly defined), there's no need to worry about their
17910 : existence. Theoretically, they should never even be
17911 : instantiated, but that's hard to forestall. */
17912 9 : error_at (DECL_SOURCE_LOCATION (decl),
17913 : "invalid constructor; you probably meant %<%T (const %T&)%>",
17914 : ctype, ctype);
17915 9 : return false;
17916 : }
17917 :
17918 : return true;
17919 : }
17920 :
17921 : /* DECL is a declaration for an overloaded or conversion operator. If
17922 : COMPLAIN is true, errors are issued for invalid declarations. */
17923 :
17924 : bool
17925 62335042 : grok_op_properties (tree decl, bool complain)
17926 : {
17927 62335042 : tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
17928 62335042 : bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
17929 62335042 : tree name = DECL_NAME (decl);
17930 62335042 : location_t loc = DECL_SOURCE_LOCATION (decl);
17931 :
17932 62335042 : tree class_type = DECL_CONTEXT (decl);
17933 62335042 : if (class_type && !CLASS_TYPE_P (class_type))
17934 : class_type = NULL_TREE;
17935 :
17936 62335042 : tree_code operator_code;
17937 62335042 : unsigned op_flags;
17938 62335042 : if (IDENTIFIER_CONV_OP_P (name))
17939 : {
17940 : /* Conversion operators are TYPE_EXPR for the purposes of this
17941 : function. */
17942 : operator_code = TYPE_EXPR;
17943 : op_flags = OVL_OP_FLAG_UNARY;
17944 : }
17945 : else
17946 : {
17947 59868424 : const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
17948 :
17949 59868424 : operator_code = ovl_op->tree_code;
17950 59868424 : op_flags = ovl_op->flags;
17951 59868424 : gcc_checking_assert (operator_code != ERROR_MARK);
17952 59868424 : DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
17953 : }
17954 :
17955 59868424 : if (op_flags & OVL_OP_FLAG_ALLOC)
17956 : {
17957 : /* operator new and operator delete are quite special. */
17958 362842 : if (class_type)
17959 9802 : switch (op_flags)
17960 : {
17961 6707 : case OVL_OP_FLAG_ALLOC:
17962 6707 : TYPE_HAS_NEW_OPERATOR (class_type) = 1;
17963 6707 : break;
17964 :
17965 2779 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
17966 2779 : TYPE_GETS_DELETE (class_type) |= 1;
17967 2779 : break;
17968 :
17969 135 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
17970 135 : TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
17971 135 : break;
17972 :
17973 181 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
17974 181 : TYPE_GETS_DELETE (class_type) |= 2;
17975 181 : break;
17976 :
17977 0 : default:
17978 0 : gcc_unreachable ();
17979 : }
17980 :
17981 : /* [basic.std.dynamic.allocation]/1:
17982 :
17983 : A program is ill-formed if an allocation function is declared
17984 : in a namespace scope other than global scope or declared
17985 : static in global scope.
17986 :
17987 : The same also holds true for deallocation functions. */
17988 362842 : if (DECL_NAMESPACE_SCOPE_P (decl))
17989 : {
17990 353040 : if (CP_DECL_CONTEXT (decl) != global_namespace)
17991 : {
17992 6 : error_at (loc, "%qD may not be declared within a namespace",
17993 : decl);
17994 6 : return false;
17995 : }
17996 :
17997 353034 : if (!TREE_PUBLIC (decl))
17998 : {
17999 6 : error_at (loc, "%qD may not be declared as static", decl);
18000 6 : return false;
18001 : }
18002 : }
18003 :
18004 : /* Check for replaceable global new/delete operators with
18005 : const std::nothrow_t & last argument, other replaceable global
18006 : new/delete operators are marked in cxx_init_decl_processing. */
18007 362830 : if (CP_DECL_CONTEXT (decl) == global_namespace)
18008 : {
18009 353028 : tree args = argtypes;
18010 353028 : if (args
18011 353016 : && args != void_list_node
18012 1059042 : && same_type_p (TREE_VALUE (args),
18013 : (op_flags & OVL_OP_FLAG_DELETE)
18014 : ? ptr_type_node : size_type_node))
18015 : {
18016 352986 : args = TREE_CHAIN (args);
18017 352986 : if (aligned_allocation_fn_p (decl))
18018 113820 : args = TREE_CHAIN (args);
18019 352986 : if (args
18020 352980 : && args != void_list_node
18021 588637 : && TREE_CHAIN (args) == void_list_node)
18022 : {
18023 207041 : tree t = TREE_VALUE (args);
18024 207041 : if (TYPE_REF_P (t)
18025 117477 : && !TYPE_REF_IS_RVALUE (t)
18026 117477 : && (t = TREE_TYPE (t))
18027 117477 : && TYPE_QUALS (t) == TYPE_QUAL_CONST
18028 324020 : && is_std_class (t, "nothrow_t"))
18029 116979 : DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
18030 : }
18031 : }
18032 : }
18033 :
18034 362830 : if (op_flags & OVL_OP_FLAG_DELETE)
18035 : {
18036 207378 : DECL_SET_IS_OPERATOR_DELETE (decl, true);
18037 207378 : coerce_delete_type (decl, loc);
18038 : }
18039 : else
18040 : {
18041 155452 : DECL_SET_IS_OPERATOR_NEW (decl, true);
18042 155452 : TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
18043 : }
18044 :
18045 : return true;
18046 : }
18047 :
18048 : /* An operator function must either be a non-static member function
18049 : or have at least one parameter of a class, a reference to a class,
18050 : an enumeration, or a reference to an enumeration. 13.4.0.6 */
18051 61972200 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
18052 : {
18053 15914484 : if (operator_code == TYPE_EXPR
18054 15914484 : || operator_code == COMPONENT_REF
18055 15914463 : || operator_code == NOP_EXPR)
18056 : {
18057 33 : error_at (loc, "%qD must be a non-static member function", decl);
18058 33 : return false;
18059 : }
18060 :
18061 15914451 : if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
18062 : {
18063 141845 : if (! DECL_STATIC_FUNCTION_P (decl))
18064 : {
18065 12 : error_at (loc, "%qD must be a member function", decl);
18066 12 : return false;
18067 : }
18068 141833 : if (cxx_dialect < cxx23
18069 : /* For lambdas we diagnose static lambda specifier elsewhere. */
18070 217660 : && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
18071 : /* For instantiations, we have diagnosed this already. */
18072 250649 : && ! DECL_USE_TEMPLATE (decl))
18073 108810 : pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
18074 : "function only with %<-std=c++23%> or %<-std=gnu++23%>",
18075 : decl);
18076 141833 : if (operator_code == ARRAY_REF)
18077 : /* static operator[] should have exactly one argument
18078 : for C++20 and earlier, so that it isn't multidimensional. */
18079 : op_flags = OVL_OP_FLAG_UNARY;
18080 : }
18081 15772606 : else if (DECL_STATIC_FUNCTION_P (decl))
18082 : {
18083 9 : error_at (loc, "%qD must be either a non-static member "
18084 : "function or a non-member function", decl);
18085 9 : return false;
18086 : }
18087 : else
18088 424434 : for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
18089 : {
18090 16197031 : if (!arg || arg == void_list_node)
18091 : {
18092 18 : if (complain)
18093 15 : error_at (loc, "%qD must have an argument of class or "
18094 : "enumerated type", decl);
18095 : return false;
18096 : }
18097 :
18098 16197013 : tree type = non_reference (TREE_VALUE (arg));
18099 16197013 : if (type == error_mark_node)
18100 : return false;
18101 :
18102 : /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
18103 : because these checks are performed even on template
18104 : functions. */
18105 16197010 : if (MAYBE_CLASS_TYPE_P (type)
18106 1456202 : || TREE_CODE (type) == ENUMERAL_TYPE)
18107 : break;
18108 424434 : }
18109 : }
18110 :
18111 61968817 : if (operator_code == CALL_EXPR)
18112 : /* There are no further restrictions on the arguments to an overloaded
18113 : "operator ()". */
18114 : return true;
18115 :
18116 : /* C++23 allows an arbitrary number of parameters and default arguments for
18117 : operator[], and none of the other checks below apply. */
18118 51571233 : if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
18119 : return true;
18120 :
18121 51253471 : if (operator_code == COND_EXPR)
18122 : {
18123 : /* 13.4.0.3 */
18124 6 : error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
18125 6 : return false;
18126 : }
18127 :
18128 : /* Count the number of arguments and check for ellipsis. */
18129 : int arity = 0;
18130 145639058 : for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
18131 : {
18132 94385608 : if (!arg)
18133 : {
18134 15 : error_at (loc, "%qD must not have variable number of arguments",
18135 : decl);
18136 15 : return false;
18137 : }
18138 94385593 : ++arity;
18139 : }
18140 : /* FIXME: We need tests for these errors with xobj member functions. */
18141 : /* Verify correct number of arguments. */
18142 51253450 : switch (op_flags)
18143 : {
18144 10638127 : case OVL_OP_FLAG_AMBIARY:
18145 10638127 : if (arity == 1)
18146 : {
18147 : /* We have a unary instance of an ambi-ary op. Remap to the
18148 : unary one. */
18149 4581389 : unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
18150 4581389 : const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
18151 4581389 : gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
18152 4581389 : operator_code = ovl_op->tree_code;
18153 4581389 : DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
18154 : }
18155 6056738 : else if (arity != 2)
18156 : {
18157 : /* This was an ambiguous operator but is invalid. */
18158 3 : error_at (loc,
18159 : methodp
18160 : ? G_("%qD must have either zero or one argument")
18161 : : G_("%qD must have either one or two arguments"), decl);
18162 3 : return false;
18163 : }
18164 6056735 : else if ((operator_code == POSTINCREMENT_EXPR
18165 6056735 : || operator_code == POSTDECREMENT_EXPR)
18166 2809379 : && ! processing_template_decl
18167 : /* x++ and x--'s second argument must be an int. */
18168 7878112 : && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
18169 : integer_type_node))
18170 : {
18171 15 : error_at (loc,
18172 : methodp
18173 : ? G_("postfix %qD must have %<int%> as its argument")
18174 : : G_("postfix %qD must have %<int%> as its second argument"),
18175 : decl);
18176 15 : return false;
18177 : }
18178 : break;
18179 :
18180 3539948 : case OVL_OP_FLAG_UNARY:
18181 3539948 : if (arity != 1)
18182 : {
18183 9 : error_at (loc,
18184 : methodp
18185 : ? G_("%qD must have no arguments")
18186 : : G_("%qD must have exactly one argument"), decl);
18187 9 : return false;
18188 : }
18189 : break;
18190 :
18191 37075375 : case OVL_OP_FLAG_BINARY:
18192 37075375 : if (arity != 2)
18193 : {
18194 3 : error_at (loc,
18195 : methodp
18196 : ? G_("%qD must have exactly one argument")
18197 : : G_("%qD must have exactly two arguments"), decl);
18198 3 : return false;
18199 : }
18200 : break;
18201 :
18202 0 : default:
18203 0 : gcc_unreachable ();
18204 : }
18205 :
18206 : /* There can be no default arguments. */
18207 145638917 : for (tree arg = argtypes; arg && arg != void_list_node;
18208 94385497 : arg = TREE_CHAIN (arg))
18209 94385512 : if (TREE_PURPOSE (arg))
18210 : {
18211 15 : TREE_PURPOSE (arg) = NULL_TREE;
18212 15 : error_at (loc, "%qD cannot have default arguments", decl);
18213 15 : return false;
18214 : }
18215 :
18216 : /* At this point the declaration is well-formed. It may not be
18217 : sensible though. */
18218 :
18219 : /* Check member function warnings only on the in-class declaration.
18220 : There's no point warning on an out-of-class definition. */
18221 51253405 : if (class_type && class_type != current_class_type)
18222 : return true;
18223 :
18224 : /* Warn about conversion operators that will never be used. */
18225 49336272 : if (IDENTIFIER_CONV_OP_P (name)
18226 2466152 : && ! DECL_TEMPLATE_INFO (decl)
18227 50403142 : && warn_class_conversion)
18228 : {
18229 1066837 : tree t = TREE_TYPE (name);
18230 1066837 : int ref = TYPE_REF_P (t);
18231 :
18232 1066837 : if (ref)
18233 21935 : t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
18234 :
18235 1066837 : if (VOID_TYPE_P (t))
18236 9 : warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
18237 : "will never use a type conversion operator", class_type);
18238 1066828 : else if (class_type)
18239 : {
18240 1066828 : if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
18241 24 : warning_at (loc, OPT_Wclass_conversion,
18242 : ref
18243 : ? G_("converting %qT to a reference to the same type "
18244 : "will never use a type conversion operator")
18245 : : G_("converting %qT to the same type "
18246 : "will never use a type conversion operator"),
18247 : class_type);
18248 : /* Don't force t to be complete here. */
18249 1066813 : else if (MAYBE_CLASS_TYPE_P (t)
18250 608567 : && COMPLETE_TYPE_P (t)
18251 162316 : && DERIVED_FROM_P (t, class_type))
18252 30 : warning_at (loc, OPT_Wclass_conversion,
18253 : ref
18254 : ? G_("converting %qT to a reference to a base class "
18255 : "%qT will never use a type conversion operator")
18256 : : G_("converting %qT to a base class %qT "
18257 : "will never use a type conversion operator"),
18258 : class_type, t);
18259 : }
18260 : }
18261 :
18262 49336272 : if (!warn_ecpp)
18263 : return true;
18264 :
18265 : /* Effective C++ rules below. */
18266 :
18267 : /* More Effective C++ rule 7. */
18268 54 : if (operator_code == TRUTH_ANDIF_EXPR
18269 54 : || operator_code == TRUTH_ORIF_EXPR
18270 54 : || operator_code == COMPOUND_EXPR)
18271 0 : warning_at (loc, OPT_Weffc__,
18272 : "user-defined %qD always evaluates both arguments", decl);
18273 :
18274 : /* More Effective C++ rule 6. */
18275 54 : if (operator_code == POSTINCREMENT_EXPR
18276 : || operator_code == POSTDECREMENT_EXPR
18277 : || operator_code == PREINCREMENT_EXPR
18278 54 : || operator_code == PREDECREMENT_EXPR)
18279 : {
18280 0 : tree arg = TREE_VALUE (argtypes);
18281 0 : tree ret = TREE_TYPE (TREE_TYPE (decl));
18282 0 : if (methodp || TYPE_REF_P (arg))
18283 0 : arg = TREE_TYPE (arg);
18284 0 : arg = TYPE_MAIN_VARIANT (arg);
18285 :
18286 0 : if (operator_code == PREINCREMENT_EXPR
18287 : || operator_code == PREDECREMENT_EXPR)
18288 : {
18289 0 : if (!TYPE_REF_P (ret)
18290 0 : || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
18291 0 : warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
18292 : build_reference_type (arg));
18293 : }
18294 : else
18295 : {
18296 0 : if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
18297 0 : warning_at (loc, OPT_Weffc__,
18298 : "postfix %qD should return %qT", decl, arg);
18299 : }
18300 : }
18301 :
18302 : /* Effective C++ rule 23. */
18303 54 : if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
18304 : && (operator_code == PLUS_EXPR
18305 9 : || operator_code == MINUS_EXPR
18306 9 : || operator_code == TRUNC_DIV_EXPR
18307 : || operator_code == MULT_EXPR
18308 : || operator_code == TRUNC_MOD_EXPR)
18309 60 : && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
18310 3 : warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
18311 :
18312 : return true;
18313 : }
18314 :
18315 : /* Return a string giving the keyword associate with CODE. */
18316 :
18317 : const char *
18318 3578 : tag_name (enum tag_types code)
18319 : {
18320 3578 : switch (code)
18321 : {
18322 : case record_type:
18323 : return "struct";
18324 114 : case class_type:
18325 114 : return "class";
18326 3 : case union_type:
18327 3 : return "union";
18328 9 : case enum_type:
18329 9 : return "enum";
18330 3363 : case typename_type:
18331 3363 : case none_type:
18332 3363 : return "typename";
18333 29 : case scope_type:
18334 29 : return nullptr;
18335 : }
18336 0 : gcc_unreachable ();
18337 : }
18338 :
18339 : /* Name lookup in an elaborated-type-specifier (after the keyword
18340 : indicated by TAG_CODE) has found the TYPE_DECL DECL. If the
18341 : elaborated-type-specifier is invalid, issue a diagnostic and return
18342 : error_mark_node; otherwise, return the *_TYPE to which it referred.
18343 : If ALLOW_TEMPLATE_P is true, TYPE may be a class template. */
18344 :
18345 : tree
18346 12660726 : check_elaborated_type_specifier (enum tag_types tag_code,
18347 : tree decl,
18348 : bool allow_template_p)
18349 : {
18350 12660726 : tree type;
18351 :
18352 : /* In the case of:
18353 :
18354 : struct S { struct S *p; };
18355 :
18356 : name lookup will find the TYPE_DECL for the implicit "S::S"
18357 : typedef. Adjust for that here. */
18358 12660726 : if (DECL_SELF_REFERENCE_P (decl))
18359 438235 : decl = TYPE_NAME (TREE_TYPE (decl));
18360 :
18361 12660726 : type = TREE_TYPE (decl);
18362 :
18363 : /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
18364 : is false for this case as well. */
18365 12660726 : if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
18366 : {
18367 9 : error ("using template type parameter %qT after %qs",
18368 : type, tag_name (tag_code));
18369 9 : return error_mark_node;
18370 : }
18371 : /* Accept template template parameters. */
18372 12660717 : else if (allow_template_p
18373 7158988 : && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
18374 7158976 : || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
18375 : ;
18376 : /* [dcl.type.elab]
18377 :
18378 : If the identifier resolves to a typedef-name or the
18379 : simple-template-id resolves to an alias template
18380 : specialization, the elaborated-type-specifier is ill-formed.
18381 :
18382 : In other words, the only legitimate declaration to use in the
18383 : elaborated type specifier is the implicit typedef created when
18384 : the type is declared. */
18385 12660702 : else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
18386 438364 : && !DECL_SELF_REFERENCE_P (decl)
18387 12660831 : && tag_code != typename_type)
18388 : {
18389 78 : auto_diagnostic_group d;
18390 78 : if (alias_template_specialization_p (type, nt_opaque))
18391 21 : error ("using alias template specialization %qT after %qs",
18392 : type, tag_name (tag_code));
18393 : else
18394 57 : error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
18395 78 : inform (DECL_SOURCE_LOCATION (decl),
18396 : "%qD has a previous declaration here", decl);
18397 78 : return error_mark_node;
18398 78 : }
18399 12660624 : else if (TREE_CODE (type) != RECORD_TYPE
18400 12660624 : && TREE_CODE (type) != UNION_TYPE
18401 : && tag_code != enum_type
18402 73324 : && tag_code != typename_type)
18403 : {
18404 6 : auto_diagnostic_group d;
18405 6 : error ("%qT referred to as %qs", type, tag_name (tag_code));
18406 6 : inform (location_of (type), "%qT has a previous declaration here", type);
18407 6 : return error_mark_node;
18408 6 : }
18409 12660618 : else if (TREE_CODE (type) != ENUMERAL_TYPE
18410 12587339 : && tag_code == enum_type)
18411 : {
18412 3 : auto_diagnostic_group d;
18413 3 : error ("%qT referred to as enum", type);
18414 3 : inform (location_of (type), "%qT has a previous declaration here", type);
18415 3 : return error_mark_node;
18416 3 : }
18417 12660615 : else if (!allow_template_p
18418 5501669 : && TREE_CODE (type) == RECORD_TYPE
18419 18035011 : && CLASSTYPE_IS_TEMPLATE (type))
18420 : {
18421 : /* If a class template appears as elaborated type specifier
18422 : without a template header such as:
18423 :
18424 : template <class T> class C {};
18425 : void f(class C); // No template header here
18426 :
18427 : then the required template argument is missing. */
18428 18 : error ("template argument required for %<%s %T%>",
18429 : tag_name (tag_code),
18430 18 : DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
18431 18 : return error_mark_node;
18432 : }
18433 :
18434 : return type;
18435 : }
18436 :
18437 : /* Lookup NAME of an elaborated type specifier according to SCOPE and
18438 : issue diagnostics if necessary. Return *_TYPE node upon success,
18439 : NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
18440 : error. */
18441 :
18442 : static tree
18443 27590476 : lookup_and_check_tag (enum tag_types tag_code, tree name,
18444 : TAG_how how, bool template_header_p)
18445 : {
18446 27590476 : tree decl;
18447 27590476 : if (how == TAG_how::GLOBAL)
18448 : {
18449 : /* First try ordinary name lookup, ignoring hidden class name
18450 : injected via friend declaration. */
18451 2213039 : decl = lookup_name (name, LOOK_want::TYPE);
18452 : /* If that fails, the name will be placed in the smallest
18453 : non-class, non-function-prototype scope according to 3.3.1/5.
18454 : We may already have a hidden name declared as friend in this
18455 : scope. So lookup again but not ignoring hidden names.
18456 : If we find one, that name will be made visible rather than
18457 : creating a new tag. */
18458 2213039 : if (!decl)
18459 19329 : decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
18460 : }
18461 : else
18462 25377437 : decl = lookup_elaborated_type (name, how);
18463 :
18464 25396766 : if (!decl)
18465 : /* We found nothing. */
18466 : return NULL_TREE;
18467 :
18468 6239497 : if (TREE_CODE (decl) == TREE_LIST)
18469 : {
18470 3 : auto_diagnostic_group d;
18471 3 : error ("reference to %qD is ambiguous", name);
18472 3 : print_candidates (input_location, decl);
18473 3 : return error_mark_node;
18474 3 : }
18475 :
18476 2551987 : if (DECL_CLASS_TEMPLATE_P (decl)
18477 2551981 : && !template_header_p
18478 8791475 : && how == TAG_how::CURRENT_ONLY)
18479 : {
18480 12 : auto_diagnostic_group d;
18481 12 : error ("class template %qD redeclared as non-template", name);
18482 12 : inform (location_of (decl), "previous declaration here");
18483 12 : CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
18484 12 : return error_mark_node;
18485 12 : }
18486 :
18487 2551975 : if (DECL_CLASS_TEMPLATE_P (decl)
18488 : /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
18489 : so ignore a template template parameter. */
18490 6239488 : || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
18491 2551972 : decl = DECL_TEMPLATE_RESULT (decl);
18492 :
18493 6239482 : if (TREE_CODE (decl) != TYPE_DECL)
18494 : /* Found not-a-type. */
18495 : return NULL_TREE;
18496 :
18497 : /* Look for invalid nested type:
18498 : class C {
18499 : class C {};
18500 : }; */
18501 6239461 : if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
18502 : {
18503 6 : error ("%qD has the same name as the class in which it is "
18504 : "declared", decl);
18505 6 : return error_mark_node;
18506 : }
18507 :
18508 : /* Two cases we need to consider when deciding if a class
18509 : template is allowed as an elaborated type specifier:
18510 : 1. It is a self reference to its own class.
18511 : 2. It comes with a template header.
18512 :
18513 : For example:
18514 :
18515 : template <class T> class C {
18516 : class C *c1; // DECL_SELF_REFERENCE_P is true
18517 : class D;
18518 : };
18519 : template <class U> class C; // template_header_p is true
18520 : template <class T> class C<T>::D {
18521 : class C *c2; // DECL_SELF_REFERENCE_P is true
18522 : }; */
18523 :
18524 18718365 : tree t = check_elaborated_type_specifier (tag_code, decl,
18525 : template_header_p
18526 12040690 : | DECL_SELF_REFERENCE_P (decl));
18527 2738392 : if (template_header_p && t && CLASS_TYPE_P (t)
18528 8977835 : && (!CLASSTYPE_TEMPLATE_INFO (t)
18529 2738362 : || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
18530 : {
18531 21 : auto_diagnostic_group d;
18532 21 : error ("%qT is not a template", t);
18533 21 : inform (location_of (t), "previous declaration here");
18534 42 : if (TYPE_CLASS_SCOPE_P (t)
18535 24 : && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
18536 3 : inform (input_location,
18537 : "perhaps you want to explicitly add %<%T::%>",
18538 3 : TYPE_CONTEXT (t));
18539 21 : return error_mark_node;
18540 21 : }
18541 :
18542 : return t;
18543 : }
18544 :
18545 : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
18546 : Define the tag as a forward-reference if it is not defined.
18547 :
18548 : If a declaration is given, process it here, and report an error if
18549 : multiple declarations are not identical.
18550 :
18551 : SCOPE is TS_CURRENT when this is also a definition. Only look in
18552 : the current frame for the name (since C++ allows new names in any
18553 : scope.) It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
18554 : declaration. Only look beginning from the current scope outward up
18555 : till the nearest non-class scope. Otherwise it is TS_GLOBAL.
18556 :
18557 : TEMPLATE_HEADER_P is true when this declaration is preceded by
18558 : a set of template parameters. */
18559 :
18560 : tree
18561 27574349 : xref_tag (enum tag_types tag_code, tree name,
18562 : TAG_how how, bool template_header_p)
18563 : {
18564 27574349 : enum tree_code code;
18565 27574349 : tree context = NULL_TREE;
18566 :
18567 27574349 : auto_cond_timevar tv (TV_NAME_LOOKUP);
18568 :
18569 27574349 : gcc_assert (identifier_p (name));
18570 :
18571 27574349 : switch (tag_code)
18572 : {
18573 : case record_type:
18574 : case class_type:
18575 : code = RECORD_TYPE;
18576 : break;
18577 : case union_type:
18578 : code = UNION_TYPE;
18579 : break;
18580 : case enum_type:
18581 : code = ENUMERAL_TYPE;
18582 : break;
18583 0 : default:
18584 0 : gcc_unreachable ();
18585 : }
18586 :
18587 : /* In case of anonymous name, xref_tag is only called to
18588 : make type node and push name. Name lookup is not required. */
18589 27574349 : tree t = NULL_TREE;
18590 27574349 : if (!IDENTIFIER_ANON_P (name))
18591 25128253 : t = lookup_and_check_tag (tag_code, name, how, template_header_p);
18592 :
18593 27574349 : if (t == error_mark_node)
18594 : return error_mark_node;
18595 :
18596 2955483 : if (how != TAG_how::CURRENT_ONLY && t && current_class_type
18597 1406937 : && template_class_depth (current_class_type)
18598 28195909 : && template_header_p)
18599 : {
18600 362492 : if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
18601 : return t;
18602 :
18603 : /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
18604 : a definition of this tag. Since, in addition, we are
18605 : currently processing a (member) template declaration of a
18606 : template class, we must be very careful; consider:
18607 :
18608 : template <class X> struct S1
18609 :
18610 : template <class U> struct S2
18611 : {
18612 : template <class V> friend struct S1;
18613 : };
18614 :
18615 : Here, the S2::S1 declaration should not be confused with the
18616 : outer declaration. In particular, the inner version should
18617 : have a template parameter of level 2, not level 1.
18618 :
18619 : On the other hand, when presented with:
18620 :
18621 : template <class T> struct S1
18622 : {
18623 : template <class U> struct S2 {};
18624 : template <class U> friend struct S2;
18625 : };
18626 :
18627 : the friend must find S1::S2 eventually. We accomplish this
18628 : by making sure that the new type we create to represent this
18629 : declaration has the right TYPE_CONTEXT. */
18630 362489 : context = TYPE_CONTEXT (t);
18631 362489 : t = NULL_TREE;
18632 : }
18633 :
18634 27574235 : if (! t)
18635 : {
18636 : /* If no such tag is yet defined, create a forward-reference node
18637 : and record it as the "definition".
18638 : When a real declaration of this type is found,
18639 : the forward-reference will be altered into a real type. */
18640 21734381 : if (code == ENUMERAL_TYPE)
18641 : {
18642 13 : error ("use of enum %q#D without previous declaration", name);
18643 13 : return error_mark_node;
18644 : }
18645 :
18646 21734368 : t = make_class_type (code);
18647 21734368 : TYPE_CONTEXT (t) = context;
18648 21734368 : if (IDENTIFIER_LAMBDA_P (name))
18649 : /* Mark it as a lambda type right now. Our caller will
18650 : correct the value. */
18651 1680414 : SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
18652 21734368 : t = pushtag (name, t, how);
18653 : }
18654 : else
18655 : {
18656 5839854 : if (template_header_p && MAYBE_CLASS_TYPE_P (t))
18657 : {
18658 : /* Check that we aren't trying to overload a class with different
18659 : constraints. */
18660 2375870 : if (!redeclare_class_template (t, current_template_parms,
18661 : current_template_constraints ()))
18662 60 : return error_mark_node;
18663 : }
18664 3463984 : else if (!processing_template_decl
18665 3117303 : && CLASS_TYPE_P (t)
18666 6554863 : && CLASSTYPE_IS_TEMPLATE (t))
18667 : {
18668 0 : auto_diagnostic_group d;
18669 0 : error ("redeclaration of %qT as a non-template", t);
18670 0 : inform (location_of (t), "previous declaration %qD", t);
18671 0 : return error_mark_node;
18672 0 : }
18673 :
18674 5839794 : if (modules_p ()
18675 5839794 : && how == TAG_how::CURRENT_ONLY)
18676 : {
18677 12604 : tree decl = TYPE_NAME (t);
18678 12604 : if (!module_may_redeclare (decl))
18679 15 : return error_mark_node;
18680 :
18681 12589 : tree not_tmpl = STRIP_TEMPLATE (decl);
18682 12589 : if (DECL_LANG_SPECIFIC (not_tmpl)
18683 4604 : && DECL_MODULE_ATTACH_P (not_tmpl)
18684 54 : && !DECL_MODULE_EXPORT_P (not_tmpl)
18685 12631 : && module_exporting_p ())
18686 : {
18687 6 : auto_diagnostic_group d;
18688 6 : error ("conflicting exporting for declaration %qD", decl);
18689 6 : inform (DECL_SOURCE_LOCATION (decl),
18690 : "previously declared here without exporting");
18691 6 : }
18692 :
18693 12589 : tree maybe_tmpl = decl;
18694 12589 : if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
18695 9385 : maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
18696 :
18697 : /* FIXME: we should do a more precise check for redefinitions
18698 : of a conflicting using-declaration here, as these diagnostics
18699 : are not ideal. */
18700 12589 : if (DECL_LANG_SPECIFIC (decl)
18701 4604 : && DECL_MODULE_IMPORT_P (decl)
18702 12646 : && CP_DECL_CONTEXT (decl) == current_namespace)
18703 : {
18704 : /* Push it into this TU's symbol slot. */
18705 54 : if (maybe_tmpl != decl)
18706 : /* We're in the template parm binding level.
18707 : Pushtag has logic to slide under that, but we're
18708 : not pushing a *new* type. */
18709 20 : push_nested_namespace (CP_DECL_CONTEXT (decl));
18710 :
18711 54 : pushdecl (maybe_tmpl);
18712 54 : if (maybe_tmpl != decl)
18713 20 : pop_nested_namespace (CP_DECL_CONTEXT (decl));
18714 : }
18715 :
18716 12589 : set_instantiating_module (maybe_tmpl);
18717 : }
18718 : }
18719 :
18720 : return t;
18721 27574349 : }
18722 :
18723 : /* Create the binfo hierarchy for REF with (possibly NULL) base list
18724 : BASE_LIST. For each element on BASE_LIST the TREE_PURPOSE is an
18725 : access_* node, and the TREE_VALUE is the type of the base-class.
18726 : Non-NULL TREE_TYPE indicates virtual inheritance. */
18727 :
18728 : void
18729 74069474 : xref_basetypes (tree ref, tree base_list)
18730 : {
18731 74069474 : tree *basep;
18732 74069474 : tree binfo, base_binfo;
18733 74069474 : unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases. */
18734 74069474 : unsigned max_bases = 0; /* Maximum direct bases. */
18735 74069474 : unsigned max_dvbases = 0; /* Maximum direct virtual bases. */
18736 : /* Highest direct base index with annotations. */
18737 74069474 : unsigned max_annotated_base = 0;
18738 74069474 : int i;
18739 74069474 : tree default_access;
18740 74069474 : tree igo_prev; /* Track Inheritance Graph Order. */
18741 :
18742 74069474 : if (ref == error_mark_node)
18743 12 : return;
18744 :
18745 : /* The base of a derived class is private by default, all others are
18746 : public. */
18747 74069474 : default_access = (TREE_CODE (ref) == RECORD_TYPE
18748 73423601 : && CLASSTYPE_DECLARED_CLASS (ref)
18749 74069474 : ? access_private_node : access_public_node);
18750 :
18751 : /* First, make sure that any templates in base-classes are
18752 : instantiated. This ensures that if we call ourselves recursively
18753 : we do not get confused about which classes are marked and which
18754 : are not. */
18755 74069474 : basep = &base_list;
18756 108488440 : while (*basep)
18757 : {
18758 34418966 : tree basetype = TREE_VALUE (*basep);
18759 :
18760 : /* The dependent_type_p call below should really be dependent_scope_p
18761 : so that we give a hard error about using an incomplete type as a
18762 : base, but we allow it with a pedwarn for backward
18763 : compatibility. */
18764 34418966 : if (processing_template_decl
18765 34418966 : && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
18766 3 : cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
18767 : diagnostics::kind::pedwarn);
18768 34418966 : if (!dependent_type_p (basetype)
18769 34418966 : && !complete_type_or_else (basetype, NULL))
18770 : /* An incomplete type. Remove it from the list. */
18771 15 : *basep = TREE_CHAIN (*basep);
18772 : else
18773 : {
18774 34418951 : max_bases++;
18775 34418951 : if (TREE_CODE (TREE_PURPOSE (*basep)) == TREE_LIST)
18776 28 : max_annotated_base = max_bases;
18777 34418951 : if (TREE_TYPE (*basep))
18778 70757 : max_dvbases++;
18779 34418951 : if (CLASS_TYPE_P (basetype))
18780 33590419 : max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
18781 34418951 : basep = &TREE_CHAIN (*basep);
18782 : }
18783 : }
18784 74069474 : max_vbases += max_dvbases;
18785 :
18786 74069474 : TYPE_MARKED_P (ref) = 1;
18787 :
18788 : /* The binfo slot should be empty, unless this is an (ill-formed)
18789 : redefinition. */
18790 74069474 : gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
18791 :
18792 74069474 : gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
18793 :
18794 74069474 : binfo = make_tree_binfo (max_bases);
18795 :
18796 74069474 : TYPE_BINFO (ref) = binfo;
18797 74069474 : BINFO_OFFSET (binfo) = size_zero_node;
18798 74069474 : BINFO_TYPE (binfo) = ref;
18799 :
18800 : /* Apply base-class info set up to the variants of this type. */
18801 74069474 : fixup_type_variants (ref);
18802 :
18803 74069474 : if (max_bases)
18804 : {
18805 33480008 : vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases + max_annotated_base);
18806 33480008 : BINFO_BASE_ACCESSES (binfo)->quick_grow (max_bases + max_annotated_base);
18807 : /* A C++98 POD cannot have base classes. */
18808 33480008 : CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
18809 :
18810 33480008 : if (TREE_CODE (ref) == UNION_TYPE)
18811 : {
18812 12 : error ("derived union %qT invalid", ref);
18813 12 : return;
18814 : }
18815 : }
18816 :
18817 33479996 : if (max_bases > 1)
18818 741659 : warning (OPT_Wmultiple_inheritance,
18819 : "%qT defined with multiple direct bases", ref);
18820 :
18821 74069462 : if (max_vbases)
18822 : {
18823 : /* An aggregate can't have virtual base classes. */
18824 210224 : CLASSTYPE_NON_AGGREGATE (ref) = true;
18825 :
18826 210224 : vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
18827 :
18828 210224 : if (max_dvbases)
18829 69343 : warning (OPT_Wvirtual_inheritance,
18830 : "%qT defined with direct virtual base", ref);
18831 : }
18832 :
18833 108488401 : for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
18834 : {
18835 34418939 : tree access = TREE_PURPOSE (base_list);
18836 34418939 : tree annotations = NULL_TREE;
18837 34418939 : if (TREE_CODE (access) == TREE_LIST)
18838 : {
18839 28 : annotations = TREE_VALUE (access);
18840 28 : access = TREE_PURPOSE (access);
18841 78 : for (tree *d = &annotations; *d; )
18842 : {
18843 50 : if (annotation_p (*d))
18844 : {
18845 50 : tree name = get_attribute_name (*d);
18846 50 : tree args = TREE_VALUE (*d);
18847 50 : const attribute_spec *as
18848 50 : = lookup_attribute_spec (TREE_PURPOSE (*d));
18849 50 : bool no_add_attrs = false;
18850 50 : as->handler (&binfo, name, args, 0, &no_add_attrs);
18851 50 : if (no_add_attrs)
18852 : {
18853 2 : *d = TREE_CHAIN (*d);
18854 2 : continue;
18855 : }
18856 : }
18857 48 : d = &TREE_CHAIN (*d);
18858 : }
18859 : }
18860 34418939 : int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
18861 34418939 : tree basetype = TREE_VALUE (base_list);
18862 :
18863 34418939 : if (access == access_default_node)
18864 4668773 : access = default_access;
18865 :
18866 : /* Before C++17, an aggregate cannot have base classes. In C++17, an
18867 : aggregate can't have virtual, private, or protected base classes. */
18868 34418939 : if (cxx_dialect < cxx17
18869 34194894 : || access != access_public_node
18870 33219350 : || via_virtual)
18871 1266786 : CLASSTYPE_NON_AGGREGATE (ref) = true;
18872 :
18873 34418939 : if (PACK_EXPANSION_P (basetype))
18874 30004 : basetype = PACK_EXPANSION_PATTERN (basetype);
18875 34418939 : if (TREE_CODE (basetype) == TYPE_DECL)
18876 0 : basetype = TREE_TYPE (basetype);
18877 34418939 : if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
18878 : {
18879 24 : error ("base type %qT fails to be a struct or class type",
18880 : basetype);
18881 24 : goto dropped_base;
18882 : }
18883 34418915 : else if (ANON_AGGR_TYPE_P (basetype))
18884 : {
18885 2 : error ("base type %qT is anonymous struct type", basetype);
18886 2 : goto dropped_base;
18887 : }
18888 :
18889 34418913 : base_binfo = NULL_TREE;
18890 34418913 : if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
18891 : {
18892 27167052 : base_binfo = TYPE_BINFO (basetype);
18893 : /* The original basetype could have been a typedef'd type. */
18894 27167052 : basetype = BINFO_TYPE (base_binfo);
18895 :
18896 : /* Inherit flags from the base. */
18897 81501156 : TYPE_HAS_NEW_OPERATOR (ref)
18898 27167052 : |= TYPE_HAS_NEW_OPERATOR (basetype);
18899 81501156 : TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
18900 27167052 : |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
18901 27167052 : TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
18902 27167052 : TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
18903 81501156 : CLASSTYPE_DIAMOND_SHAPED_P (ref)
18904 27167052 : |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
18905 81501156 : CLASSTYPE_REPEATED_BASE_P (ref)
18906 27167052 : |= CLASSTYPE_REPEATED_BASE_P (basetype);
18907 : }
18908 :
18909 : /* We must do this test after we've seen through a typedef
18910 : type. */
18911 34418913 : if (TYPE_MARKED_P (basetype))
18912 : {
18913 18 : if (basetype == ref)
18914 0 : error ("recursive type %qT undefined", basetype);
18915 : else
18916 18 : error ("duplicate base type %qT invalid", basetype);
18917 18 : goto dropped_base;
18918 : }
18919 :
18920 34418895 : if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
18921 : /* Regenerate the pack expansion for the bases. */
18922 30004 : basetype = make_pack_expansion (basetype);
18923 :
18924 34418895 : TYPE_MARKED_P (basetype) = 1;
18925 :
18926 34418895 : base_binfo = copy_binfo (base_binfo, basetype, ref,
18927 : &igo_prev, via_virtual);
18928 34418895 : if (!BINFO_INHERITANCE_CHAIN (base_binfo))
18929 34348153 : BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
18930 :
18931 34418895 : unsigned len;
18932 34418895 : len = BINFO_N_BASE_BINFOS (binfo);
18933 34418895 : BINFO_BASE_APPEND (binfo, base_binfo);
18934 34418895 : BINFO_BASE_ACCESS (binfo, len) = access;
18935 34418895 : if (len < max_annotated_base)
18936 34 : BINFO_BASE_ACCESS (binfo, max_bases + len) = annotations;
18937 34418895 : continue;
18938 :
18939 44 : dropped_base:
18940 : /* Update max_vbases to reflect the reality that we are dropping
18941 : this base: if it reaches zero we want to undo the vec_alloc
18942 : above to avoid inconsistencies during error-recovery: eg, in
18943 : build_special_member_call, CLASSTYPE_VBASECLASSES non null
18944 : and vtt null (c++/27952). */
18945 44 : if (via_virtual)
18946 12 : max_vbases--;
18947 44 : if (CLASS_TYPE_P (basetype))
18948 32 : max_vbases
18949 35 : -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
18950 34418895 : }
18951 :
18952 74069462 : unsigned len = BINFO_N_BASE_BINFOS (binfo);
18953 74069462 : if (len < max_bases)
18954 : {
18955 44 : if (len && max_annotated_base)
18956 0 : memmove (&BINFO_BASE_ACCESS (binfo, len),
18957 0 : &BINFO_BASE_ACCESS (binfo, max_bases),
18958 0 : MIN (max_annotated_base, len) * sizeof (tree));
18959 44 : BINFO_BASE_ACCESSES (binfo)->truncate (len + MIN (max_annotated_base,
18960 : len));
18961 : }
18962 :
18963 74069462 : if (CLASSTYPE_VBASECLASSES (ref)
18964 74069462 : && max_vbases == 0)
18965 24 : vec_free (CLASSTYPE_VBASECLASSES (ref));
18966 :
18967 74279674 : if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
18968 : /* If we didn't get max_vbases vbases, we must have shared at
18969 : least one of them, and are therefore diamond shaped. */
18970 22926 : CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
18971 :
18972 : /* Unmark all the types. */
18973 108488357 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
18974 34418895 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
18975 74069462 : TYPE_MARKED_P (ref) = 0;
18976 :
18977 : /* Now see if we have a repeated base type. */
18978 74069462 : if (!CLASSTYPE_REPEATED_BASE_P (ref))
18979 : {
18980 186847127 : for (base_binfo = binfo; base_binfo;
18981 112778101 : base_binfo = TREE_CHAIN (base_binfo))
18982 : {
18983 112778850 : if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
18984 : {
18985 749 : CLASSTYPE_REPEATED_BASE_P (ref) = 1;
18986 749 : break;
18987 : }
18988 112778101 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
18989 : }
18990 186847127 : for (base_binfo = binfo; base_binfo;
18991 112778101 : base_binfo = TREE_CHAIN (base_binfo))
18992 112778850 : if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
18993 112778101 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
18994 : else
18995 : break;
18996 : }
18997 : }
18998 :
18999 :
19000 : /* Copies the enum-related properties from type SRC to type DST.
19001 : Used with the underlying type of an enum and the enum itself. */
19002 : static void
19003 2086141 : copy_type_enum (tree dst, tree src)
19004 : {
19005 2086141 : tree t;
19006 4172306 : for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
19007 : {
19008 2086165 : TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
19009 2086165 : TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
19010 2086165 : TYPE_SIZE (t) = TYPE_SIZE (src);
19011 2086165 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
19012 2086165 : SET_TYPE_MODE (dst, TYPE_MODE (src));
19013 2086165 : TYPE_PRECISION (t) = TYPE_PRECISION (src);
19014 2086165 : unsigned valign = TYPE_ALIGN (src);
19015 2086165 : if (TYPE_USER_ALIGN (t))
19016 12 : valign = MAX (valign, TYPE_ALIGN (t));
19017 : else
19018 2086153 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
19019 2086165 : SET_TYPE_ALIGN (t, valign);
19020 2086165 : TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
19021 : }
19022 2086141 : }
19023 :
19024 : /* Begin compiling the definition of an enumeration type.
19025 : NAME is its name,
19026 :
19027 : if ENUMTYPE is not NULL_TREE then the type has already been found.
19028 :
19029 : UNDERLYING_TYPE is the type that will be used as the storage for
19030 : the enumeration type. This should be NULL_TREE if no storage type
19031 : was specified.
19032 :
19033 : ATTRIBUTES are any attributes specified after the enum-key.
19034 :
19035 : SCOPED_ENUM_P is true if this is a scoped enumeration type.
19036 :
19037 : if IS_NEW is not NULL, gets TRUE iff a new type is created.
19038 :
19039 : Returns the type object, as yet incomplete.
19040 : Also records info about it so that build_enumerator
19041 : may be used to declare the individual values as they are read. */
19042 :
19043 : tree
19044 2462359 : start_enum (tree name, tree enumtype, tree underlying_type,
19045 : tree attributes, bool scoped_enum_p, bool *is_new)
19046 : {
19047 2462359 : tree prevtype = NULL_TREE;
19048 2462359 : gcc_assert (identifier_p (name));
19049 :
19050 2462359 : if (is_new)
19051 1987010 : *is_new = false;
19052 : /* [C++0x dcl.enum]p5:
19053 :
19054 : If not explicitly specified, the underlying type of a scoped
19055 : enumeration type is int. */
19056 2462359 : if (!underlying_type && scoped_enum_p)
19057 181804 : underlying_type = integer_type_node;
19058 :
19059 2462359 : if (underlying_type)
19060 614717 : underlying_type = cv_unqualified (underlying_type);
19061 :
19062 : /* If this is the real definition for a previous forward reference,
19063 : fill in the contents in the same object that used to be the
19064 : forward reference. */
19065 2462359 : if (!enumtype)
19066 2462223 : enumtype = lookup_and_check_tag (enum_type, name,
19067 : /*tag_scope=*/TAG_how::CURRENT_ONLY,
19068 : /*template_header_p=*/false);
19069 :
19070 : /* In case of a template_decl, the only check that should be deferred
19071 : to instantiation time is the comparison of underlying types. */
19072 2462359 : if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
19073 : {
19074 : /* Attempt to set the declaring module. */
19075 37152 : if (modules_p ())
19076 : {
19077 216 : tree decl = TYPE_NAME (enumtype);
19078 216 : if (!module_may_redeclare (decl))
19079 3 : enumtype = error_mark_node;
19080 : else
19081 213 : set_instantiating_module (decl);
19082 : }
19083 :
19084 37152 : if (enumtype == error_mark_node)
19085 : ;
19086 37368 : else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
19087 : {
19088 6 : auto_diagnostic_group d;
19089 6 : error_at (input_location, "scoped/unscoped mismatch "
19090 : "in enum %q#T", enumtype);
19091 6 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
19092 : "previous definition here");
19093 6 : enumtype = error_mark_node;
19094 6 : }
19095 37143 : else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
19096 : {
19097 0 : auto_diagnostic_group d;
19098 0 : error_at (input_location, "underlying type mismatch "
19099 : "in enum %q#T", enumtype);
19100 0 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
19101 : "previous definition here");
19102 0 : enumtype = error_mark_node;
19103 0 : }
19104 37128 : else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
19105 74271 : && !same_type_p (underlying_type,
19106 : ENUM_UNDERLYING_TYPE (enumtype)))
19107 : {
19108 29 : auto_diagnostic_group d;
19109 29 : error_at (input_location, "different underlying type "
19110 : "in enum %q#T", enumtype);
19111 29 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
19112 : "previous definition here");
19113 29 : underlying_type = NULL_TREE;
19114 29 : }
19115 : }
19116 :
19117 2462359 : if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
19118 37143 : || processing_template_decl)
19119 : {
19120 : /* In case of error, make a dummy enum to allow parsing to
19121 : continue. */
19122 2425317 : if (enumtype == error_mark_node)
19123 : {
19124 9 : name = make_anon_name ();
19125 9 : enumtype = NULL_TREE;
19126 : }
19127 :
19128 : /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
19129 : of an opaque enum, or an opaque enum of an already defined
19130 : enumeration (C++11).
19131 : In any other case, it'll be NULL_TREE. */
19132 2425317 : if (!enumtype)
19133 : {
19134 2425213 : if (is_new)
19135 1949867 : *is_new = true;
19136 : }
19137 2425317 : prevtype = enumtype;
19138 :
19139 : /* Do not push the decl more than once. */
19140 2425317 : if (!enumtype
19141 104 : || TREE_CODE (enumtype) != ENUMERAL_TYPE)
19142 : {
19143 2425216 : enumtype = cxx_make_type (ENUMERAL_TYPE);
19144 2425216 : enumtype = pushtag (name, enumtype);
19145 :
19146 2425216 : if (enumtype != error_mark_node)
19147 : {
19148 : /* The enum is considered opaque until the opening '{' of the
19149 : enumerator list. */
19150 2425198 : SET_OPAQUE_ENUM_P (enumtype, true);
19151 2425198 : ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
19152 :
19153 : /* std::byte aliases anything. */
19154 2425198 : if (TYPE_CONTEXT (enumtype) == std_node
19155 2794216 : && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
19156 13918 : TYPE_ALIAS_SET (enumtype) = 0;
19157 : }
19158 : }
19159 : else
19160 101 : enumtype = xref_tag (enum_type, name);
19161 :
19162 2425317 : if (enumtype == error_mark_node)
19163 : return error_mark_node;
19164 : }
19165 :
19166 2462341 : SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
19167 :
19168 2462341 : cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
19169 :
19170 2462341 : if (underlying_type)
19171 : {
19172 614685 : if (ENUM_UNDERLYING_TYPE (enumtype))
19173 : /* We already checked that it matches, don't change it to a different
19174 : typedef variant. */;
19175 577586 : else if (CP_INTEGRAL_TYPE_P (underlying_type))
19176 : {
19177 577512 : copy_type_enum (enumtype, underlying_type);
19178 577512 : ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
19179 : }
19180 74 : else if (dependent_type_p (underlying_type))
19181 61 : ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
19182 : else
19183 : {
19184 13 : error ("underlying type %qT of %qT must be an integral type",
19185 : underlying_type, enumtype);
19186 13 : copy_type_enum (enumtype, integer_type_node);
19187 13 : ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
19188 : }
19189 : }
19190 :
19191 : /* If into a template class, the returned enum is always the first
19192 : declaration (opaque or not) seen. This way all the references to
19193 : this type will be to the same declaration. The following ones are used
19194 : only to check for definition errors. */
19195 2462341 : if (prevtype && processing_template_decl)
19196 : return prevtype;
19197 : else
19198 2462240 : return enumtype;
19199 : }
19200 :
19201 : /* Returns true if TYPE is an enum that uses an enumerator name for
19202 : linkage purposes at namespace scope. The term is defined in [dcl.enum]/12
19203 : for all enums, not just those at namespace scope, but for backward ABI
19204 : compatibility we want to treat those not at namespace scope the old way
19205 : and e.g. mangle the class scope ones based on their position within the
19206 : class rather than the first enumerator. */
19207 :
19208 : bool
19209 422512786 : enum_with_enumerator_for_linkage_p (tree type)
19210 : {
19211 422512786 : return (cxx_dialect >= cxx20
19212 417826844 : && UNSCOPED_ENUM_P (type)
19213 20448822 : && TYPE_ANON_P (type)
19214 3165610 : && TYPE_VALUES (type)
19215 424457338 : && TYPE_NAMESPACE_SCOPE_P (type));
19216 : }
19217 :
19218 : /* After processing and defining all the values of an enumeration type,
19219 : install their decls in the enumeration type.
19220 : ENUMTYPE is the type object. */
19221 :
19222 : void
19223 2356912 : finish_enum_value_list (tree enumtype)
19224 : {
19225 2356912 : tree values;
19226 2356912 : tree underlying_type;
19227 2356912 : tree decl;
19228 2356912 : tree value;
19229 2356912 : tree minnode, maxnode;
19230 2356912 : tree t;
19231 :
19232 2356912 : ENUM_BEING_DEFINED_P (enumtype) = 0;
19233 :
19234 2356912 : bool fixed_underlying_type_p
19235 2356912 : = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
19236 :
19237 : /* We built up the VALUES in reverse order. */
19238 2356912 : TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
19239 :
19240 : /* For an enum defined in a template, just set the type of the values;
19241 : all further processing is postponed until the template is
19242 : instantiated. We need to set the type so that tsubst of a CONST_DECL
19243 : works. */
19244 2356912 : if (processing_template_decl)
19245 : {
19246 446661 : for (values = TYPE_VALUES (enumtype);
19247 805232 : values;
19248 446661 : values = TREE_CHAIN (values))
19249 446661 : TREE_TYPE (TREE_VALUE (values)) = enumtype;
19250 : return;
19251 : }
19252 :
19253 : /* Determine the minimum and maximum values of the enumerators. */
19254 1998341 : if (TYPE_VALUES (enumtype))
19255 : {
19256 : minnode = maxnode = NULL_TREE;
19257 :
19258 11960259 : for (values = TYPE_VALUES (enumtype);
19259 13920804 : values;
19260 11960259 : values = TREE_CHAIN (values))
19261 : {
19262 11960259 : decl = TREE_VALUE (values);
19263 :
19264 : /* [dcl.enum]: Following the closing brace of an enum-specifier,
19265 : each enumerator has the type of its enumeration. Prior to the
19266 : closing brace, the type of each enumerator is the type of its
19267 : initializing value. */
19268 11960259 : TREE_TYPE (decl) = enumtype;
19269 :
19270 : /* Update the minimum and maximum values, if appropriate. */
19271 11960259 : value = DECL_INITIAL (decl);
19272 11960259 : if (!value || TREE_CODE (value) != INTEGER_CST)
19273 7 : value = integer_zero_node;
19274 : /* Figure out what the minimum and maximum values of the
19275 : enumerators are. */
19276 11960259 : if (!minnode)
19277 : minnode = maxnode = value;
19278 9999714 : else if (tree_int_cst_lt (maxnode, value))
19279 : maxnode = value;
19280 1547706 : else if (tree_int_cst_lt (value, minnode))
19281 175758 : minnode = value;
19282 : }
19283 : }
19284 : else
19285 : /* [dcl.enum]
19286 :
19287 : If the enumerator-list is empty, the underlying type is as if
19288 : the enumeration had a single enumerator with value 0. */
19289 37796 : minnode = maxnode = integer_zero_node;
19290 :
19291 1998341 : if (!fixed_underlying_type_p)
19292 : {
19293 : /* Compute the number of bits require to represent all values of the
19294 : enumeration. We must do this before the type of MINNODE and
19295 : MAXNODE are transformed, since tree_int_cst_min_precision relies
19296 : on the TREE_TYPE of the value it is passed. */
19297 1508616 : signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
19298 1508616 : int lowprec = tree_int_cst_min_precision (minnode, sgn);
19299 1508616 : int highprec = tree_int_cst_min_precision (maxnode, sgn);
19300 1508616 : int precision = MAX (lowprec, highprec);
19301 1508616 : unsigned int itk;
19302 1508616 : bool use_short_enum;
19303 :
19304 : /* Determine the underlying type of the enumeration.
19305 :
19306 : [dcl.enum]
19307 :
19308 : The underlying type of an enumeration is an integral type that
19309 : can represent all the enumerator values defined in the
19310 : enumeration. It is implementation-defined which integral type is
19311 : used as the underlying type for an enumeration except that the
19312 : underlying type shall not be larger than int unless the value of
19313 : an enumerator cannot fit in an int or unsigned int.
19314 :
19315 : We use "int" or an "unsigned int" as the underlying type, even if
19316 : a smaller integral type would work, unless the user has
19317 : explicitly requested that we use the smallest possible type. The
19318 : user can request that for all enumerations with a command line
19319 : flag, or for just one enumeration with an attribute. */
19320 :
19321 3017232 : use_short_enum = flag_short_enums
19322 1508616 : || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
19323 :
19324 : /* If the precision of the type was specified with an attribute and it
19325 : was too small, give an error. Otherwise, use it. */
19326 1508616 : if (TYPE_PRECISION (enumtype))
19327 : {
19328 11 : if (precision > TYPE_PRECISION (enumtype))
19329 0 : error ("specified mode too small for enumerated values");
19330 : else
19331 : {
19332 11 : use_short_enum = true;
19333 11 : precision = TYPE_PRECISION (enumtype);
19334 : }
19335 : }
19336 :
19337 2933522 : for (itk = (use_short_enum ? itk_char : itk_int);
19338 2933522 : itk != itk_none;
19339 : itk++)
19340 : {
19341 2933519 : underlying_type = integer_types[itk];
19342 2933519 : if (underlying_type != NULL_TREE
19343 2933501 : && TYPE_PRECISION (underlying_type) >= precision
19344 5864915 : && TYPE_SIGN (underlying_type) == sgn)
19345 : break;
19346 : }
19347 1508616 : if (itk == itk_none)
19348 : {
19349 : /* DR 377
19350 :
19351 : IF no integral type can represent all the enumerator values, the
19352 : enumeration is ill-formed. */
19353 3 : error ("no integral type can represent all of the enumerator values "
19354 : "for %qT", enumtype);
19355 3 : precision = TYPE_PRECISION (long_long_integer_type_node);
19356 3 : underlying_type = integer_types[itk_unsigned_long_long];
19357 : }
19358 :
19359 : /* [dcl.enum]
19360 :
19361 : The value of sizeof() applied to an enumeration type, an object
19362 : of an enumeration type, or an enumerator, is the value of sizeof()
19363 : applied to the underlying type. */
19364 1508616 : copy_type_enum (enumtype, underlying_type);
19365 :
19366 : /* Compute the minimum and maximum values for the type.
19367 :
19368 : [dcl.enum]
19369 :
19370 : For an enumeration where emin is the smallest enumerator and emax
19371 : is the largest, the values of the enumeration are the values of the
19372 : underlying type in the range bmin to bmax, where bmin and bmax are,
19373 : respectively, the smallest and largest values of the smallest bit-
19374 : field that can store emin and emax. */
19375 :
19376 : /* The middle-end currently assumes that types with TYPE_PRECISION
19377 : narrower than their underlying type are suitably zero or sign
19378 : extended to fill their mode. Similarly, it assumes that the front
19379 : end assures that a value of a particular type must be within
19380 : TYPE_MIN_VALUE and TYPE_MAX_VALUE.
19381 :
19382 : We used to set these fields based on bmin and bmax, but that led
19383 : to invalid assumptions like optimizing away bounds checking. So
19384 : now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
19385 : TYPE_MAX_VALUE to the values for the mode above and only restrict
19386 : the ENUM_UNDERLYING_TYPE for the benefit of diagnostics. */
19387 1508616 : ENUM_UNDERLYING_TYPE (enumtype)
19388 1508616 : = build_distinct_type_copy (underlying_type);
19389 1508616 : TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
19390 1508616 : set_min_and_max_values_for_integral_type
19391 1508616 : (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
19392 :
19393 : /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE. */
19394 1508616 : if (flag_strict_enums)
19395 38 : set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
19396 :
19397 1508616 : if (use_short_enum)
19398 : {
19399 126 : TYPE_PACKED (enumtype) = use_short_enum;
19400 126 : fixup_attribute_variants (enumtype);
19401 : }
19402 : }
19403 : else
19404 489725 : underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
19405 :
19406 : /* If the enum is exported, mark the consts too. */
19407 1998341 : bool export_p = (UNSCOPED_ENUM_P (enumtype)
19408 1586091 : && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
19409 1998929 : && at_namespace_scope_p ());
19410 :
19411 : /* Convert each of the enumerators to the type of the underlying
19412 : type of the enumeration. */
19413 13958600 : for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
19414 : {
19415 11960259 : decl = TREE_VALUE (values);
19416 11960259 : iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
19417 11960259 : if (fixed_underlying_type_p)
19418 : /* If the enumeration type has a fixed underlying type, we
19419 : already checked all of the enumerator values. */
19420 4194367 : value = DECL_INITIAL (decl);
19421 : else
19422 7765892 : value = perform_implicit_conversion (underlying_type,
19423 7765892 : DECL_INITIAL (decl),
19424 : tf_warning_or_error);
19425 11960259 : if (!value)
19426 3 : value = integer_zero_node;
19427 : /* Do not clobber shared ints. But do share identical enumerators. */
19428 11960259 : value = fold_convert (enumtype, value);
19429 :
19430 11960259 : DECL_INITIAL (decl) = value;
19431 11960259 : if (export_p)
19432 3594 : DECL_MODULE_EXPORT_P (decl) = true;
19433 11960259 : }
19434 :
19435 : /* Fix up all variant types of this enum type. */
19436 3996728 : for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
19437 1998387 : TYPE_VALUES (t) = TYPE_VALUES (enumtype);
19438 :
19439 1998341 : if (at_class_scope_p ()
19440 1069035 : && COMPLETE_TYPE_P (current_class_type)
19441 1998405 : && UNSCOPED_ENUM_P (enumtype))
19442 : {
19443 45 : insert_late_enum_def_bindings (current_class_type, enumtype);
19444 : /* TYPE_FIELDS needs fixup. */
19445 45 : fixup_type_variants (current_class_type);
19446 : }
19447 :
19448 : /* P2115: An unnamed enum uses the name of its first enumerator for
19449 : linkage purposes; reset the type linkage if that is the case. */
19450 1998341 : if (enum_with_enumerator_for_linkage_p (enumtype))
19451 355891 : reset_type_linkage (enumtype);
19452 :
19453 : /* Finish debugging output for this type. */
19454 1998341 : rest_of_type_compilation (enumtype, namespace_bindings_p ());
19455 :
19456 : /* Each enumerator now has the type of its enumeration. Clear the cache
19457 : so that this change in types doesn't confuse us later on. */
19458 1998341 : clear_cv_and_fold_caches ();
19459 : }
19460 :
19461 : /* Finishes the enum type. This is called only the first time an
19462 : enumeration is seen, be it opaque or odinary.
19463 : ENUMTYPE is the type object. */
19464 :
19465 : void
19466 2345056 : finish_enum (tree enumtype)
19467 : {
19468 2345056 : if (processing_template_decl)
19469 : {
19470 358599 : if (at_function_scope_p ())
19471 9660 : add_stmt (build_min (TAG_DEFN, enumtype));
19472 : return;
19473 : }
19474 :
19475 : /* If this is a forward declaration, there should not be any variants,
19476 : though we can get a variant in the middle of an enum-specifier with
19477 : wacky code like 'enum E { e = sizeof(const E*) };' */
19478 3972914 : gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
19479 : && (TYPE_VALUES (enumtype)
19480 : || !TYPE_NEXT_VARIANT (enumtype)));
19481 : }
19482 :
19483 : /* Build and install a CONST_DECL for an enumeration constant of the
19484 : enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
19485 : Apply ATTRIBUTES if available. LOC is the location of NAME.
19486 : Assignment of sequential values by default is handled here. */
19487 :
19488 : tree
19489 12406894 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
19490 : location_t loc)
19491 : {
19492 12406894 : tree decl;
19493 12406894 : tree context;
19494 12406894 : tree type;
19495 :
19496 : /* scalar_constant_value will pull out this expression, so make sure
19497 : it's folded as appropriate.
19498 :
19499 : Creating a TARGET_EXPR in a template breaks when substituting, and
19500 : here we would create it for instance when using a class prvalue with
19501 : a user-defined conversion function. So don't use such a tree. We
19502 : instantiate VALUE here to get errors about bad enumerators even in
19503 : a template that does not get instantiated. */
19504 12406894 : if (processing_template_decl)
19505 446661 : value = maybe_fold_non_dependent_expr (value);
19506 :
19507 : /* If the VALUE was erroneous, pretend it wasn't there; that will
19508 : result in the enum being assigned the next value in sequence. */
19509 12406894 : if (value == error_mark_node)
19510 : value = NULL_TREE;
19511 :
19512 : /* Remove no-op casts from the value. */
19513 12406856 : if (value)
19514 9512640 : STRIP_TYPE_NOPS (value);
19515 :
19516 12406894 : if (! processing_template_decl)
19517 : {
19518 : /* Validate and default VALUE. */
19519 11960233 : if (value != NULL_TREE)
19520 : {
19521 5439869 : if (!ENUM_UNDERLYING_TYPE (enumtype))
19522 : {
19523 2763824 : tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
19524 : value, true);
19525 2763824 : if (tmp_value)
19526 5439869 : value = tmp_value;
19527 : }
19528 2676045 : else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
19529 : (TREE_TYPE (value)))
19530 39 : value = perform_implicit_conversion_flags
19531 39 : (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
19532 : LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
19533 :
19534 5439869 : if (value == error_mark_node)
19535 : value = NULL_TREE;
19536 :
19537 5439848 : if (value != NULL_TREE)
19538 : {
19539 5439848 : if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
19540 : (TREE_TYPE (value)))
19541 : {
19542 17 : error_at (cp_expr_loc_or_input_loc (value),
19543 : "enumerator value for %qD must have integral or "
19544 : "unscoped enumeration type", name);
19545 17 : value = NULL_TREE;
19546 : }
19547 : else
19548 : {
19549 5439831 : value = cxx_constant_value (value);
19550 :
19551 5439831 : if (TREE_CODE (value) != INTEGER_CST)
19552 : {
19553 48 : error ("enumerator value for %qD is not an integer "
19554 : "constant", name);
19555 48 : value = NULL_TREE;
19556 : }
19557 : }
19558 : }
19559 : }
19560 :
19561 : /* Default based on previous value. */
19562 65 : if (value == NULL_TREE)
19563 : {
19564 6520450 : if (TYPE_VALUES (enumtype))
19565 : {
19566 5969667 : tree prev_value;
19567 :
19568 : /* C++03 7.2/4: If no initializer is specified for the first
19569 : enumerator, the type is an unspecified integral
19570 : type. Otherwise the type is the same as the type of the
19571 : initializing value of the preceding enumerator unless the
19572 : incremented value is not representable in that type, in
19573 : which case the type is an unspecified integral type
19574 : sufficient to contain the incremented value. */
19575 5969667 : prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
19576 5969667 : if (TREE_CODE (prev_value) != INTEGER_CST)
19577 2 : value = error_mark_node;
19578 : else
19579 : {
19580 5969665 : wi::overflow_type overflowed;
19581 5969665 : tree type = TREE_TYPE (prev_value);
19582 5969665 : signop sgn = TYPE_SIGN (type);
19583 5969665 : widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
19584 5969665 : &overflowed);
19585 5969665 : if (!overflowed)
19586 : {
19587 5969665 : bool pos = !wi::neg_p (wi, sgn);
19588 5969665 : if (!wi::fits_to_tree_p (wi, type))
19589 : {
19590 : unsigned int itk;
19591 53 : for (itk = itk_int; itk != itk_none; itk++)
19592 : {
19593 53 : type = integer_types[itk];
19594 53 : if (type != NULL_TREE
19595 53 : && (pos || !TYPE_UNSIGNED (type))
19596 106 : && wi::fits_to_tree_p (wi, type))
19597 : break;
19598 : }
19599 17 : if (type && cxx_dialect < cxx11
19600 6 : && itk > itk_unsigned_long)
19601 3 : pedwarn (input_location, OPT_Wlong_long,
19602 : pos ? G_("\
19603 : incremented enumerator value is too large for %<unsigned long%>") : G_("\
19604 : incremented enumerator value is too large for %<long%>"));
19605 : }
19606 5969665 : if (type == NULL_TREE)
19607 0 : overflowed = wi::OVF_UNKNOWN;
19608 : else
19609 5969665 : value = wide_int_to_tree (type, wi);
19610 : }
19611 :
19612 5969665 : if (overflowed)
19613 : {
19614 0 : error ("overflow in enumeration values at %qD", name);
19615 0 : value = error_mark_node;
19616 : }
19617 5969665 : }
19618 : }
19619 : else
19620 550783 : value = integer_zero_node;
19621 : }
19622 :
19623 : /* Remove no-op casts from the value. */
19624 11960233 : STRIP_TYPE_NOPS (value);
19625 :
19626 : /* If the underlying type of the enum is fixed, check whether
19627 : the enumerator values fits in the underlying type. If it
19628 : does not fit, the program is ill-formed [C++0x dcl.enum]. */
19629 11960233 : if (ENUM_UNDERLYING_TYPE (enumtype)
19630 : && value
19631 11960233 : && TREE_CODE (value) == INTEGER_CST)
19632 : {
19633 4194339 : if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
19634 9 : error ("enumerator value %qE is outside the range of underlying "
19635 9 : "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
19636 :
19637 : /* Convert the value to the appropriate type. */
19638 4194339 : value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
19639 : }
19640 : }
19641 :
19642 : /* C++ associates enums with global, function, or class declarations. */
19643 12406894 : context = current_scope ();
19644 :
19645 : /* Build the actual enumeration constant. Note that the enumeration
19646 : constants have the underlying type of the enum (if it is fixed)
19647 : or the type of their initializer (if the underlying type of the
19648 : enum is not fixed):
19649 :
19650 : [ C++0x dcl.enum ]
19651 :
19652 : If the underlying type is fixed, the type of each enumerator
19653 : prior to the closing brace is the underlying type; if the
19654 : initializing value of an enumerator cannot be represented by
19655 : the underlying type, the program is ill-formed. If the
19656 : underlying type is not fixed, the type of each enumerator is
19657 : the type of its initializing value.
19658 :
19659 : If the underlying type is not fixed, it will be computed by
19660 : finish_enum and we will reset the type of this enumerator. Of
19661 : course, if we're processing a template, there may be no value. */
19662 12406894 : type = value ? TREE_TYPE (value) : NULL_TREE;
19663 :
19664 12406894 : decl = build_decl (loc, CONST_DECL, name, type);
19665 :
19666 12406894 : DECL_CONTEXT (decl) = enumtype;
19667 12406894 : TREE_CONSTANT (decl) = 1;
19668 12406894 : TREE_READONLY (decl) = 1;
19669 12406894 : DECL_INITIAL (decl) = value;
19670 :
19671 12406894 : if (attributes)
19672 146228 : cplus_decl_attributes (&decl, attributes, 0);
19673 :
19674 12406894 : if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
19675 : {
19676 : /* In something like `struct S { enum E { i = 7 }; };' we put `i'
19677 : on the TYPE_FIELDS list for `S'. (That's so that you can say
19678 : things like `S::i' later.) */
19679 :
19680 : /* The enumerator may be getting declared outside of its enclosing
19681 : class, like so:
19682 :
19683 : class S { public: enum E : int; }; enum S::E : int { i = 7; };
19684 :
19685 : For which case we need to make sure that the access of `S::i'
19686 : matches the access of `S::E'. */
19687 2156076 : auto cas = make_temp_override (current_access_specifier);
19688 2156076 : set_current_access_from_decl (TYPE_NAME (enumtype));
19689 2156076 : finish_member_declaration (decl);
19690 2156076 : }
19691 : else
19692 10250818 : pushdecl (decl);
19693 :
19694 : /* Add this enumeration constant to the list for this type. */
19695 12406894 : TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
19696 :
19697 12406894 : return decl;
19698 : }
19699 :
19700 : /* Look for an enumerator with the given NAME within the enumeration
19701 : type ENUMTYPE. This routine is used primarily for qualified name
19702 : lookup into an enumerator in C++0x, e.g.,
19703 :
19704 : enum class Color { Red, Green, Blue };
19705 :
19706 : Color color = Color::Red;
19707 :
19708 : Returns the value corresponding to the enumerator, or
19709 : NULL_TREE if no such enumerator was found. */
19710 : tree
19711 29745679 : lookup_enumerator (tree enumtype, tree name)
19712 : {
19713 29745679 : tree e;
19714 29745679 : gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
19715 :
19716 29745679 : e = purpose_member (name, TYPE_VALUES (enumtype));
19717 59491260 : return e? TREE_VALUE (e) : NULL_TREE;
19718 : }
19719 :
19720 : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL. */
19721 :
19722 : tree
19723 0 : cxx_simulate_enum_decl (location_t loc, const char *name,
19724 : vec<string_int_pair> *values)
19725 : {
19726 0 : location_t saved_loc = input_location;
19727 0 : input_location = loc;
19728 :
19729 0 : tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
19730 : NULL_TREE, false, NULL);
19731 0 : if (!OPAQUE_ENUM_P (enumtype))
19732 : {
19733 0 : auto_diagnostic_group d;
19734 0 : error_at (loc, "multiple definition of %q#T", enumtype);
19735 0 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
19736 : "previous definition here");
19737 0 : return enumtype;
19738 0 : }
19739 0 : SET_OPAQUE_ENUM_P (enumtype, false);
19740 0 : DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
19741 :
19742 0 : for (const string_int_pair &value : values)
19743 0 : build_enumerator (get_identifier (value.first),
19744 0 : build_int_cst (integer_type_node, value.second),
19745 : enumtype, NULL_TREE, loc);
19746 :
19747 0 : finish_enum_value_list (enumtype);
19748 0 : finish_enum (enumtype);
19749 :
19750 0 : input_location = saved_loc;
19751 0 : return enumtype;
19752 : }
19753 :
19754 : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL. */
19755 :
19756 : tree
19757 0 : cxx_simulate_record_decl (location_t loc, const char *name,
19758 : array_slice<const tree> fields)
19759 : {
19760 0 : iloc_sentinel ils (loc);
19761 :
19762 0 : tree ident = get_identifier (name);
19763 0 : tree type = xref_tag (/*tag_code=*/record_type, ident);
19764 0 : if (type != error_mark_node
19765 0 : && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
19766 : {
19767 0 : error ("redefinition of %q#T", type);
19768 0 : type = error_mark_node;
19769 : }
19770 0 : if (type == error_mark_node)
19771 0 : return lhd_simulate_record_decl (loc, name, fields);
19772 :
19773 0 : xref_basetypes (type, NULL_TREE);
19774 0 : type = begin_class_definition (type);
19775 0 : if (type == error_mark_node)
19776 0 : return lhd_simulate_record_decl (loc, name, fields);
19777 :
19778 0 : for (tree field : fields)
19779 0 : finish_member_declaration (field);
19780 :
19781 0 : type = finish_struct (type, NULL_TREE);
19782 :
19783 0 : tree decl = build_decl (loc, TYPE_DECL, ident, type);
19784 0 : set_underlying_type (decl);
19785 0 : lang_hooks.decls.pushdecl (decl);
19786 :
19787 0 : return type;
19788 0 : }
19789 :
19790 : /* We're defining DECL. Make sure that its type is OK. */
19791 :
19792 : static void
19793 169405640 : check_function_type (tree decl, tree current_function_parms)
19794 : {
19795 169405640 : tree fntype = TREE_TYPE (decl);
19796 169405640 : tree return_type = complete_type (TREE_TYPE (fntype));
19797 :
19798 : /* In a function definition, arg types must be complete. */
19799 169405640 : require_complete_types_for_parms (current_function_parms);
19800 :
19801 169405640 : if (dependent_type_p (return_type)
19802 169405640 : || type_uses_auto (return_type))
19803 : return;
19804 115714572 : if (!COMPLETE_OR_VOID_TYPE_P (return_type))
19805 : {
19806 12 : tree args = TYPE_ARG_TYPES (fntype);
19807 :
19808 12 : error ("return type %q#T is incomplete", return_type);
19809 :
19810 : /* Make it return void instead. */
19811 12 : if (TREE_CODE (fntype) == METHOD_TYPE)
19812 3 : fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
19813 : void_type_node,
19814 3 : TREE_CHAIN (args));
19815 : else
19816 18 : fntype = build_function_type (void_type_node, args,
19817 9 : TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
19818 12 : fntype = (cp_build_type_attribute_variant
19819 12 : (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
19820 12 : fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
19821 12 : TREE_TYPE (decl) = fntype;
19822 : }
19823 : else
19824 : {
19825 115714560 : abstract_virtuals_error (decl, TREE_TYPE (fntype));
19826 115714560 : maybe_warn_parm_abi (TREE_TYPE (fntype),
19827 115714560 : DECL_SOURCE_LOCATION (decl));
19828 : }
19829 : }
19830 :
19831 : /* True iff FN is an implicitly-defined default constructor. */
19832 :
19833 : static bool
19834 17651263 : implicit_default_ctor_p (tree fn)
19835 : {
19836 17651263 : return (DECL_CONSTRUCTOR_P (fn)
19837 17651263 : && !user_provided_p (fn)
19838 19639026 : && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
19839 : }
19840 :
19841 : /* Clobber the contents of *this to let the back end know that the object
19842 : storage is dead when we enter the constructor or leave the destructor. */
19843 :
19844 : static tree
19845 1542905 : build_clobber_this (clobber_kind kind)
19846 : {
19847 : /* Clobbering an empty base is pointless, and harmful if its one byte
19848 : TYPE_SIZE overlays real data. */
19849 1542905 : if (is_empty_class (current_class_type))
19850 0 : return void_node;
19851 :
19852 : /* If we have virtual bases, clobber the whole object, but only if we're in
19853 : charge. If we don't have virtual bases, clobber the as-base type so we
19854 : don't mess with tail padding. */
19855 1542905 : bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
19856 :
19857 1542905 : tree ctype = current_class_type;
19858 1542905 : if (!vbases)
19859 1535042 : ctype = CLASSTYPE_AS_BASE (ctype);
19860 :
19861 1542905 : tree clobber = build_clobber (ctype, kind);
19862 :
19863 1542905 : tree thisref = current_class_ref;
19864 1542905 : if (ctype != current_class_type)
19865 : {
19866 176697 : thisref = build_nop (build_reference_type (ctype), current_class_ptr);
19867 176697 : thisref = convert_from_reference (thisref);
19868 : }
19869 :
19870 1542905 : tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
19871 1542905 : if (kind == CLOBBER_OBJECT_BEGIN)
19872 0 : TREE_SET_CODE (exprstmt, INIT_EXPR);
19873 1542905 : if (vbases)
19874 7863 : exprstmt = build_if_in_charge (exprstmt);
19875 :
19876 : return exprstmt;
19877 : }
19878 :
19879 : /* Create the FUNCTION_DECL for a function definition.
19880 : DECLSPECS and DECLARATOR are the parts of the declaration;
19881 : they describe the function's name and the type it returns,
19882 : but twisted together in a fashion that parallels the syntax of C.
19883 :
19884 : FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
19885 : DECLARATOR is really the DECL for the function we are about to
19886 : process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
19887 : indicating that the function is an inline defined in-class.
19888 :
19889 : This function creates a binding context for the function body
19890 : as well as setting up the FUNCTION_DECL in current_function_decl.
19891 :
19892 : For C++, we must first check whether that datum makes any sense.
19893 : For example, "class A local_a(1,2);" means that variable local_a
19894 : is an aggregate of type A, which should have a constructor
19895 : applied to it with the argument list [1, 2].
19896 :
19897 : On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
19898 : or may be a BLOCK if the function has been defined previously
19899 : in this translation unit. On exit, DECL_INITIAL (decl1) will be
19900 : error_mark_node if the function has never been defined, or
19901 : a BLOCK if the function has been defined somewhere. */
19902 :
19903 : bool
19904 169405676 : start_preparsed_function (tree decl1, tree attrs, int flags)
19905 : {
19906 169405676 : tree ctype = NULL_TREE;
19907 169405676 : bool doing_friend = false;
19908 :
19909 : /* Sanity check. */
19910 169405676 : gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
19911 169405676 : gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
19912 :
19913 169405676 : tree fntype = TREE_TYPE (decl1);
19914 169405676 : if (DECL_CLASS_SCOPE_P (decl1))
19915 124999284 : ctype = DECL_CONTEXT (decl1);
19916 : else
19917 : {
19918 88812784 : ctype = DECL_FRIEND_CONTEXT (decl1);
19919 :
19920 44406391 : if (ctype)
19921 169405676 : doing_friend = true;
19922 : }
19923 :
19924 : /* Adjust for #pragma target/optimize if this is an artificial function that
19925 : (probably) didn't go through grokfndecl. We particularly don't want this
19926 : for deferred instantiations, which should match their template. */
19927 169405676 : if (DECL_ARTIFICIAL (decl1))
19928 3981450 : decl_attributes (&decl1, NULL_TREE, 0);
19929 :
19930 169405676 : if (DECL_DECLARED_INLINE_P (decl1)
19931 169405676 : && lookup_attribute ("noinline", attrs))
19932 : {
19933 0 : auto_urlify_attributes sentinel;
19934 0 : warning_at (DECL_SOURCE_LOCATION (decl1), 0,
19935 : "inline function %qD given attribute %qs", decl1, "noinline");
19936 0 : }
19937 :
19938 : /* Handle gnu_inline attribute. */
19939 169405676 : if (GNU_INLINE_P (decl1))
19940 : {
19941 2015223 : DECL_EXTERNAL (decl1) = 1;
19942 2015223 : DECL_NOT_REALLY_EXTERN (decl1) = 0;
19943 2015223 : DECL_INTERFACE_KNOWN (decl1) = 1;
19944 2015223 : DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
19945 : }
19946 :
19947 169405676 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
19948 : /* This is a constructor, we must ensure that any default args
19949 : introduced by this definition are propagated to the clones
19950 : now. The clones are used directly in overload resolution. */
19951 21104676 : adjust_clone_args (decl1);
19952 :
19953 : /* Sometimes we don't notice that a function is a static member, and
19954 : build a METHOD_TYPE for it. Fix that up now. */
19955 169405676 : gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
19956 : && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
19957 :
19958 : /* Set up current_class_type, and enter the scope of the class, if
19959 : appropriate. */
19960 169405676 : if (ctype)
19961 129835568 : push_nested_class (ctype);
19962 :
19963 : /* Now that we have entered the scope of the class, we must restore
19964 : the bindings for any template parameters surrounding DECL1, if it
19965 : is an inline member template. (Order is important; consider the
19966 : case where a template parameter has the same name as a field of
19967 : the class.) It is not until after this point that
19968 : PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly. */
19969 169405676 : if (flags & SF_INCLASS_INLINE)
19970 87077483 : maybe_begin_member_template_processing (decl1);
19971 :
19972 : /* Effective C++ rule 15. */
19973 169405676 : if (warn_ecpp
19974 123 : && DECL_ASSIGNMENT_OPERATOR_P (decl1)
19975 30 : && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
19976 169405706 : && VOID_TYPE_P (TREE_TYPE (fntype)))
19977 0 : warning (OPT_Weffc__,
19978 : "%<operator=%> should return a reference to %<*this%>");
19979 :
19980 : /* Make the init_value nonzero so pushdecl knows this is not tentative.
19981 : error_mark_node is replaced below (in poplevel) with the BLOCK. */
19982 169405676 : if (!DECL_INITIAL (decl1))
19983 36766978 : DECL_INITIAL (decl1) = error_mark_node;
19984 :
19985 : /* This function exists in static storage.
19986 : (This does not mean `static' in the C sense!) */
19987 169405676 : TREE_STATIC (decl1) = 1;
19988 :
19989 : /* We must call push_template_decl after current_class_type is set
19990 : up. (If we are processing inline definitions after exiting a
19991 : class scope, current_class_type will be NULL_TREE until set above
19992 : by push_nested_class.) */
19993 169405676 : if (processing_template_decl)
19994 : {
19995 99480491 : tree newdecl1 = push_template_decl (decl1, doing_friend);
19996 99480491 : if (newdecl1 == error_mark_node)
19997 : {
19998 36 : if (ctype)
19999 9 : pop_nested_class ();
20000 : return false;
20001 : }
20002 99480455 : decl1 = newdecl1;
20003 : }
20004 :
20005 : /* Make sure the parameter and return types are reasonable. When
20006 : you declare a function, these types can be incomplete, but they
20007 : must be complete when you define the function. */
20008 169405640 : check_function_type (decl1, DECL_ARGUMENTS (decl1));
20009 :
20010 : /* Build the return declaration for the function. */
20011 169405640 : tree restype = TREE_TYPE (fntype);
20012 :
20013 169405640 : if (DECL_RESULT (decl1) == NULL_TREE)
20014 : {
20015 : /* In a template instantiation, copy the return type location. When
20016 : parsing, the location will be set in grokdeclarator. */
20017 69902304 : location_t loc = input_location;
20018 69902304 : if (DECL_TEMPLATE_INSTANTIATION (decl1))
20019 : {
20020 33107305 : tree tmpl = template_for_substitution (decl1);
20021 33107305 : if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
20022 32145648 : loc = DECL_SOURCE_LOCATION (res);
20023 : }
20024 :
20025 69902304 : tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
20026 69902304 : DECL_ARTIFICIAL (resdecl) = 1;
20027 69902304 : DECL_IGNORED_P (resdecl) = 1;
20028 69902304 : DECL_RESULT (decl1) = resdecl;
20029 :
20030 69902304 : cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
20031 : }
20032 :
20033 : /* Record the decl so that the function name is defined.
20034 : If we already have a decl for this name, and it is a FUNCTION_DECL,
20035 : use the old decl. */
20036 169405640 : if (!processing_template_decl && !(flags & SF_PRE_PARSED))
20037 : {
20038 : /* A specialization is not used to guide overload resolution. */
20039 20909992 : if (!DECL_FUNCTION_MEMBER_P (decl1)
20040 20889991 : && !(DECL_USE_TEMPLATE (decl1) &&
20041 13716 : PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
20042 : {
20043 10013085 : tree olddecl = pushdecl (decl1);
20044 :
20045 10013085 : if (olddecl == error_mark_node)
20046 : /* If something went wrong when registering the declaration,
20047 : use DECL1; we have to have a FUNCTION_DECL to use when
20048 : parsing the body of the function. */
20049 : ;
20050 : else
20051 : {
20052 : /* Otherwise, OLDDECL is either a previous declaration
20053 : of the same function or DECL1 itself. */
20054 :
20055 10012872 : if (warn_missing_declarations
20056 21 : && olddecl == decl1
20057 15 : && !DECL_MAIN_P (decl1)
20058 15 : && TREE_PUBLIC (decl1)
20059 10012884 : && !DECL_DECLARED_INLINE_P (decl1))
20060 : {
20061 9 : tree context;
20062 :
20063 : /* Check whether DECL1 is in an anonymous
20064 : namespace. */
20065 9 : for (context = DECL_CONTEXT (decl1);
20066 18 : context;
20067 9 : context = DECL_CONTEXT (context))
20068 : {
20069 12 : if (TREE_CODE (context) == NAMESPACE_DECL
20070 12 : && DECL_NAME (context) == NULL_TREE)
20071 : break;
20072 : }
20073 :
20074 9 : if (context == NULL)
20075 6 : warning_at (DECL_SOURCE_LOCATION (decl1),
20076 6 : OPT_Wmissing_declarations,
20077 : "no previous declaration for %qD", decl1);
20078 : }
20079 :
20080 10012872 : decl1 = olddecl;
20081 : }
20082 : }
20083 : else
20084 : {
20085 : /* We need to set the DECL_CONTEXT. */
20086 850105 : if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
20087 0 : DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
20088 : }
20089 10863190 : fntype = TREE_TYPE (decl1);
20090 10863190 : restype = TREE_TYPE (fntype);
20091 :
20092 : /* If #pragma weak applies, mark the decl appropriately now.
20093 : The pragma only applies to global functions. Because
20094 : determining whether or not the #pragma applies involves
20095 : computing the mangled name for the declaration, we cannot
20096 : apply the pragma until after we have merged this declaration
20097 : with any previous declarations; if the original declaration
20098 : has a linkage specification, that specification applies to
20099 : the definition as well, and may affect the mangled name. */
20100 10863190 : if (DECL_FILE_SCOPE_P (decl1))
20101 2580990 : maybe_apply_pragma_weak (decl1);
20102 : }
20103 :
20104 : /* We are now in the scope of the function being defined. */
20105 169405640 : current_function_decl = decl1;
20106 :
20107 : /* Save the parm names or decls from this function's declarator
20108 : where store_parm_decls will find them. */
20109 169405640 : tree current_function_parms = DECL_ARGUMENTS (decl1);
20110 :
20111 : /* Let the user know we're compiling this function. */
20112 169405640 : announce_function (decl1);
20113 :
20114 169405640 : gcc_assert (DECL_INITIAL (decl1));
20115 :
20116 : /* This function may already have been parsed, in which case just
20117 : return; our caller will skip over the body without parsing. */
20118 169405640 : if (DECL_INITIAL (decl1) != error_mark_node)
20119 : return true;
20120 :
20121 : /* Initialize RTL machinery. We cannot do this until
20122 : CURRENT_FUNCTION_DECL and DECL_RESULT are set up. We do this
20123 : even when processing a template; this is how we get
20124 : CFUN set up, and our per-function variables initialized.
20125 : FIXME factor out the non-RTL stuff. */
20126 169405640 : cp_binding_level *bl = current_binding_level;
20127 169405640 : allocate_struct_function (decl1, processing_template_decl);
20128 :
20129 : /* Initialize the language data structures. Whenever we start
20130 : a new function, we destroy temporaries in the usual way. */
20131 169405640 : cfun->language = ggc_cleared_alloc<language_function> ();
20132 169405640 : current_stmt_tree ()->stmts_are_full_exprs_p = 1;
20133 169405640 : current_binding_level = bl;
20134 :
20135 : /* If we are (erroneously) defining a function that we have already
20136 : defined before, wipe out what we knew before. */
20137 169405640 : gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
20138 169405640 : FNDECL_USED_AUTO (decl1) = false;
20139 169405640 : DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
20140 :
20141 169405640 : if (!processing_template_decl && type_uses_auto (restype))
20142 : {
20143 1065402 : FNDECL_USED_AUTO (decl1) = true;
20144 1065402 : DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
20145 : }
20146 :
20147 : /* Start the statement-tree, start the tree now. */
20148 169405640 : DECL_SAVED_TREE (decl1) = push_stmt_list ();
20149 :
20150 169405640 : if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
20151 : {
20152 : /* We know that this was set up by `grokclassfn'. We do not
20153 : wait until `store_parm_decls', since evil parse errors may
20154 : never get us to that point. Here we keep the consistency
20155 : between `current_class_type' and `current_class_ptr'. */
20156 109961958 : tree t = DECL_ARGUMENTS (decl1);
20157 :
20158 109961958 : gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
20159 109961958 : gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
20160 :
20161 109961958 : cp_function_chain->x_current_class_ref
20162 109961958 : = cp_build_fold_indirect_ref (t);
20163 : /* Set this second to avoid shortcut in cp_build_indirect_ref. */
20164 109961958 : cp_function_chain->x_current_class_ptr = t;
20165 :
20166 : /* Constructors and destructors need to know whether they're "in
20167 : charge" of initializing virtual base classes. */
20168 109961958 : t = DECL_CHAIN (t);
20169 109961958 : if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
20170 : {
20171 18477 : current_in_charge_parm = t;
20172 18477 : t = DECL_CHAIN (t);
20173 : }
20174 109961958 : if (DECL_HAS_VTT_PARM_P (decl1))
20175 : {
20176 37013 : gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
20177 37013 : current_vtt_parm = t;
20178 : }
20179 : }
20180 :
20181 305685531 : bool honor_interface = (!DECL_TEMPLOID_INSTANTIATION (decl1)
20182 : /* Implicitly-defined methods (like the
20183 : destructor for a class in which no destructor
20184 : is explicitly declared) must not be defined
20185 : until their definition is needed. So, we
20186 : ignore interface specifications for
20187 : compiler-generated functions. */
20188 206137166 : && !DECL_ARTIFICIAL (decl1));
20189 169405640 : struct c_fileinfo *finfo
20190 169405640 : = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
20191 :
20192 169405640 : if (processing_template_decl)
20193 : /* Don't mess with interface flags. */;
20194 69925185 : else if (DECL_INTERFACE_KNOWN (decl1))
20195 : {
20196 20431712 : tree ctx = decl_function_context (decl1);
20197 :
20198 20431712 : if (DECL_NOT_REALLY_EXTERN (decl1))
20199 16276600 : DECL_EXTERNAL (decl1) = 0;
20200 :
20201 20431712 : if (ctx != NULL_TREE && vague_linkage_p (ctx))
20202 : /* This is a function in a local class in an extern inline
20203 : or template function. */
20204 3212564 : comdat_linkage (decl1);
20205 : }
20206 : /* If this function belongs to an interface, it is public.
20207 : If it belongs to someone else's interface, it is also external.
20208 : This only affects inlines and template instantiations. */
20209 49493473 : else if (!finfo->interface_unknown && honor_interface)
20210 : {
20211 106 : if (DECL_DECLARED_INLINE_P (decl1)
20212 106 : || DECL_TEMPLOID_INSTANTIATION (decl1))
20213 : {
20214 82 : DECL_EXTERNAL (decl1)
20215 164 : = (finfo->interface_only
20216 82 : || (DECL_DECLARED_INLINE_P (decl1)
20217 36 : && ! flag_implement_inlines
20218 0 : && !DECL_VINDEX (decl1)));
20219 :
20220 : /* For WIN32 we also want to put these in linkonce sections. */
20221 82 : maybe_make_one_only (decl1);
20222 : }
20223 : else
20224 24 : DECL_EXTERNAL (decl1) = 0;
20225 106 : DECL_INTERFACE_KNOWN (decl1) = 1;
20226 : /* If this function is in an interface implemented in this file,
20227 : make sure that the back end knows to emit this function
20228 : here. */
20229 106 : if (!DECL_EXTERNAL (decl1))
20230 60 : mark_needed (decl1);
20231 : }
20232 49493367 : else if (finfo->interface_unknown && finfo->interface_only
20233 0 : && honor_interface)
20234 : {
20235 : /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
20236 : interface, we will have both finfo->interface_unknown and
20237 : finfo->interface_only set. In that case, we don't want to
20238 : use the normal heuristics because someone will supply a
20239 : #pragma implementation elsewhere, and deducing it here would
20240 : produce a conflict. */
20241 0 : comdat_linkage (decl1);
20242 0 : DECL_EXTERNAL (decl1) = 0;
20243 0 : DECL_INTERFACE_KNOWN (decl1) = 1;
20244 0 : DECL_DEFER_OUTPUT (decl1) = 1;
20245 : }
20246 : else
20247 : {
20248 : /* This is a definition, not a reference.
20249 : So clear DECL_EXTERNAL, unless this is a GNU extern inline. */
20250 49493367 : if (!GNU_INLINE_P (decl1))
20251 49493364 : DECL_EXTERNAL (decl1) = 0;
20252 :
20253 49493367 : if ((DECL_DECLARED_INLINE_P (decl1)
20254 1929252 : || DECL_TEMPLOID_INSTANTIATION (decl1))
20255 51179059 : && ! DECL_INTERFACE_KNOWN (decl1))
20256 49249807 : DECL_DEFER_OUTPUT (decl1) = 1;
20257 : else
20258 243560 : DECL_INTERFACE_KNOWN (decl1) = 1;
20259 : }
20260 :
20261 : /* Determine the ELF visibility attribute for the function. We must not
20262 : do this before calling "pushdecl", as we must allow "duplicate_decls"
20263 : to merge any attributes appropriately. We also need to wait until
20264 : linkage is set. */
20265 169405640 : if (!DECL_CLONED_FUNCTION_P (decl1))
20266 152618897 : determine_visibility (decl1);
20267 :
20268 169405640 : if (!processing_template_decl)
20269 69925185 : maybe_instantiate_noexcept (decl1);
20270 :
20271 169405640 : begin_scope (sk_function_parms, decl1);
20272 :
20273 169405640 : ++function_depth;
20274 :
20275 169405640 : start_fname_decls ();
20276 :
20277 169405640 : store_parm_decls (current_function_parms);
20278 :
20279 169405640 : start_function_contracts (decl1);
20280 :
20281 169405640 : if (!processing_template_decl
20282 69925185 : && flag_lifetime_dse > 1
20283 139840988 : && DECL_CONSTRUCTOR_P (decl1)
20284 : /* Clobbering an empty base is harmful if it overlays real data. */
20285 19606327 : && !is_empty_class (current_class_type)
20286 : /* We can't clobber safely for an implicitly-defined default constructor
20287 : because part of the initialization might happen before we enter the
20288 : constructor, via AGGR_INIT_ZERO_FIRST (c++/68006). */
20289 17650618 : && !implicit_default_ctor_p (decl1)
20290 185834292 : && !lookup_attribute ("clobber *this",
20291 16428652 : DECL_ATTRIBUTES (current_class_ptr)))
20292 16419120 : DECL_ATTRIBUTES (current_class_ptr)
20293 32838240 : = tree_cons (get_identifier ("clobber *this"), NULL_TREE,
20294 16419120 : DECL_ATTRIBUTES (current_class_ptr));
20295 :
20296 169405640 : if (!processing_template_decl
20297 139850370 : && DECL_CONSTRUCTOR_P (decl1)
20298 19607575 : && sanitize_flags_p (SANITIZE_VPTR)
20299 1935 : && !DECL_CLONED_FUNCTION_P (decl1)
20300 169406285 : && !implicit_default_ctor_p (decl1))
20301 485 : cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
20302 :
20303 169405640 : if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
20304 169405067 : start_lambda_scope (decl1);
20305 :
20306 : return true;
20307 : }
20308 :
20309 :
20310 : /* Like start_preparsed_function, except that instead of a
20311 : FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
20312 :
20313 : Returns true on success. If the DECLARATOR is not suitable
20314 : for a function, we return false, which tells the parser to
20315 : skip the entire function. */
20316 :
20317 : bool
20318 40565493 : start_function (cp_decl_specifier_seq *declspecs,
20319 : const cp_declarator *declarator,
20320 : tree attrs)
20321 : {
20322 40565493 : tree decl1;
20323 :
20324 40565493 : decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
20325 40565493 : invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
20326 40565493 : if (decl1 == error_mark_node)
20327 : return false;
20328 :
20329 40565127 : if (DECL_MAIN_P (decl1))
20330 : /* main must return int. grokfndecl should have corrected it
20331 : (and issued a diagnostic) if the user got it wrong. */
20332 34157 : gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
20333 : integer_type_node));
20334 :
20335 40565127 : return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
20336 : }
20337 :
20338 : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
20339 : FN. */
20340 :
20341 : bool
20342 324441835 : use_eh_spec_block (tree fn)
20343 : {
20344 322462699 : return (flag_exceptions && flag_enforce_eh_specs
20345 322462699 : && !processing_template_decl
20346 : /* We insert the EH_SPEC_BLOCK only in the original
20347 : function; then, it is copied automatically to the
20348 : clones. */
20349 122142950 : && !DECL_CLONED_FUNCTION_P (fn)
20350 : /* Implicitly-generated constructors and destructors have
20351 : exception specifications. However, those specifications
20352 : are the union of the possible exceptions specified by the
20353 : constructors/destructors for bases and members, so no
20354 : unallowed exception will ever reach this function. By
20355 : not creating the EH_SPEC_BLOCK we save a little memory,
20356 : and we avoid spurious warnings about unreachable
20357 : code. */
20358 105397986 : && !DECL_DEFAULTED_FN (fn)
20359 427246863 : && !type_throw_all_p (TREE_TYPE (fn)));
20360 : }
20361 :
20362 : /* Helper function to push ARGS into the current lexical scope. DECL
20363 : is the function declaration. NONPARMS is used to handle enum
20364 : constants. */
20365 :
20366 : void
20367 164396646 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
20368 : {
20369 : /* If we're doing semantic analysis, then we'll call pushdecl
20370 : for each of these. We must do them in reverse order so that
20371 : they end in the correct forward order. */
20372 164396646 : args = nreverse (args);
20373 :
20374 164396646 : tree next;
20375 668649607 : for (tree parm = args; parm; parm = next)
20376 : {
20377 339856315 : next = DECL_CHAIN (parm);
20378 339856315 : if (TREE_CODE (parm) == PARM_DECL)
20379 339856315 : pushdecl (parm);
20380 0 : else if (nonparms)
20381 : {
20382 : /* If we find an enum constant or a type tag, put it aside for
20383 : the moment. */
20384 0 : TREE_CHAIN (parm) = NULL_TREE;
20385 0 : *nonparms = chainon (*nonparms, parm);
20386 : }
20387 : }
20388 :
20389 : /* Get the decls in their original chain order and record in the
20390 : function. This is all and only the PARM_DECLs that were
20391 : pushed into scope by the loop above. */
20392 164396646 : DECL_ARGUMENTS (decl) = get_local_decls ();
20393 164396646 : }
20394 :
20395 : /* Store the parameter declarations into the current function declaration.
20396 : This is called after parsing the parameter declarations, before
20397 : digesting the body of the function.
20398 :
20399 : Also install to binding contour return value identifier, if any. */
20400 :
20401 : static void
20402 169405640 : store_parm_decls (tree current_function_parms)
20403 : {
20404 169405640 : tree fndecl = current_function_decl;
20405 :
20406 : /* This is a chain of any other decls that came in among the parm
20407 : declarations. If a parm is declared with enum {foo, bar} x;
20408 : then CONST_DECLs for foo and bar are put here. */
20409 169405640 : tree nonparms = NULL_TREE;
20410 :
20411 169405640 : if (current_function_parms)
20412 : {
20413 : /* This case is when the function was defined with an ANSI prototype.
20414 : The parms already have decls, so we need not do anything here
20415 : except record them as in effect
20416 : and complain if any redundant old-style parm decls were written. */
20417 :
20418 160730943 : tree specparms = current_function_parms;
20419 :
20420 : /* Must clear this because it might contain TYPE_DECLs declared
20421 : at class level. */
20422 160730943 : current_binding_level->names = NULL;
20423 :
20424 160730943 : do_push_parm_decls (fndecl, specparms, &nonparms);
20425 : }
20426 : else
20427 8674697 : DECL_ARGUMENTS (fndecl) = NULL_TREE;
20428 :
20429 : /* Now store the final chain of decls for the arguments
20430 : as the decl-chain of the current lexical scope.
20431 : Put the enumerators in as well, at the front so that
20432 : DECL_ARGUMENTS is not modified. */
20433 169405640 : current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
20434 :
20435 : /* Register cleanups for parameters with trivial_abi attribute, the cleanup
20436 : of which is the callee's responsibility. */
20437 169405640 : if (!processing_template_decl && !DECL_CLONED_FUNCTION_P (fndecl))
20438 137342012 : for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
20439 : {
20440 84203570 : if (TREE_CODE (parm) == PARM_DECL)
20441 : {
20442 84203570 : tree parm_type = TREE_TYPE (parm);
20443 84203570 : if (has_trivial_abi_attribute (parm_type))
20444 : {
20445 18 : tree cleanup
20446 18 : = cxx_maybe_build_cleanup (parm, tf_warning_or_error);
20447 18 : if (cleanup && cleanup != error_mark_node)
20448 18 : finish_decl_cleanup (parm, cleanup);
20449 : }
20450 : }
20451 : }
20452 :
20453 169405640 : if (use_eh_spec_block (current_function_decl))
20454 25809481 : current_eh_spec_block = begin_eh_spec_block ();
20455 169405640 : }
20456 :
20457 :
20458 : /* Mark CDTOR's implicit THIS argument for returning, if required by
20459 : the ABI.. Return the decl for THIS, if it is to be returned, and
20460 : NULL otherwise. */
20461 :
20462 : tree
20463 145119617 : maybe_prepare_return_this (tree cdtor)
20464 : {
20465 145119617 : if (targetm.cxx.cdtor_returns_this ())
20466 0 : if (tree val = DECL_ARGUMENTS (cdtor))
20467 : {
20468 0 : suppress_warning (val, OPT_Wuse_after_free_);
20469 0 : return val;
20470 : }
20471 :
20472 : return NULL_TREE;
20473 : }
20474 :
20475 : /* Set the return value of the [cd]tor if the ABI wants that. */
20476 :
20477 : void
20478 8547206 : maybe_return_this ()
20479 : {
20480 8547206 : if (tree val = maybe_prepare_return_this (current_function_decl))
20481 : {
20482 : /* Return the address of the object. */
20483 0 : val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
20484 0 : val = build2 (MODIFY_EXPR, TREE_TYPE (val),
20485 0 : DECL_RESULT (current_function_decl), val);
20486 0 : tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
20487 0 : add_stmt (exprstmt);
20488 : }
20489 8547206 : }
20490 :
20491 : /* Do all the processing for the beginning of a destructor; set up the
20492 : vtable pointers and cleanups for bases and members. */
20493 :
20494 : static void
20495 1690070 : begin_destructor_body (void)
20496 : {
20497 1690070 : tree compound_stmt;
20498 :
20499 : /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
20500 : issued an error message. We still want to try to process the
20501 : body of the function, but initialize_vtbl_ptrs will crash if
20502 : TYPE_BINFO is NULL. */
20503 1690070 : if (COMPLETE_TYPE_P (current_class_type))
20504 : {
20505 1690070 : compound_stmt = begin_compound_stmt (0);
20506 : /* Make all virtual function table pointers in non-virtual base
20507 : classes point to CURRENT_CLASS_TYPE's virtual function
20508 : tables. */
20509 1690070 : initialize_vtbl_ptrs (current_class_ptr);
20510 1690070 : finish_compound_stmt (compound_stmt);
20511 :
20512 1690070 : if (flag_lifetime_dse
20513 : /* Clobbering an empty base is harmful if it overlays real data. */
20514 1690070 : && !is_empty_class (current_class_type))
20515 : {
20516 1542968 : if (sanitize_flags_p (SANITIZE_VPTR)
20517 239 : && (flag_sanitize_recover & SANITIZE_VPTR) == 0
20518 1543031 : && TYPE_CONTAINS_VPTR_P (current_class_type))
20519 : {
20520 63 : tree binfo = TYPE_BINFO (current_class_type);
20521 63 : tree ref
20522 63 : = cp_build_fold_indirect_ref (current_class_ptr);
20523 :
20524 63 : tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
20525 63 : tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
20526 63 : tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
20527 : NOP_EXPR, vtbl,
20528 : tf_warning_or_error);
20529 : /* If the vptr is shared with some virtual nearly empty base,
20530 : don't clear it if not in charge, the dtor of the virtual
20531 : nearly empty base will do that later. */
20532 63 : if (CLASSTYPE_VBASECLASSES (current_class_type))
20533 : {
20534 : tree c = current_class_type;
20535 66 : while (CLASSTYPE_PRIMARY_BINFO (c))
20536 : {
20537 63 : if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
20538 : {
20539 36 : stmt = convert_to_void (stmt, ICV_STATEMENT,
20540 : tf_warning_or_error);
20541 36 : stmt = build_if_in_charge (stmt);
20542 36 : break;
20543 : }
20544 27 : c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
20545 : }
20546 : }
20547 63 : finish_decl_cleanup (NULL_TREE, stmt);
20548 : }
20549 : else
20550 1542905 : finish_decl_cleanup (NULL_TREE,
20551 : build_clobber_this (CLOBBER_OBJECT_END));
20552 : }
20553 :
20554 : /* And insert cleanups for our bases and members so that they
20555 : will be properly destroyed if we throw. */
20556 1690070 : push_base_cleanups ();
20557 : }
20558 1690070 : }
20559 :
20560 : /* Do the necessary processing for the beginning of a function body, which
20561 : in this case includes member-initializers, but not the catch clauses of
20562 : a function-try-block. Currently, this means opening a binding level
20563 : for the member-initializers (in a ctor), member cleanups (in a dtor),
20564 : and capture proxies (in a lambda operator()). */
20565 :
20566 : tree
20567 133283164 : begin_function_body (void)
20568 : {
20569 274409176 : if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
20570 : return NULL_TREE;
20571 :
20572 26037870 : if (processing_template_decl)
20573 : /* Do nothing now. */;
20574 : else
20575 : /* Always keep the BLOCK node associated with the outermost pair of
20576 : curly braces of a function. These are needed for correct
20577 : operation of dwarfout.c. */
20578 8718864 : keep_next_level (true);
20579 :
20580 26037870 : tree stmt = begin_compound_stmt (BCS_FN_BODY);
20581 26037870 : current_binding_level->artificial = 1;
20582 :
20583 26037870 : if (processing_template_decl)
20584 : /* Do nothing now. */;
20585 17437728 : else if (DECL_DESTRUCTOR_P (current_function_decl))
20586 1690070 : begin_destructor_body ();
20587 :
20588 : return stmt;
20589 : }
20590 :
20591 : /* Do the processing for the end of a function body. Currently, this means
20592 : closing out the cleanups for fully-constructed bases and members, and in
20593 : the case of the destructor, deleting the object if desired. Again, this
20594 : is only meaningful for [cd]tors, since they are the only functions where
20595 : there is a significant distinction between the main body and any
20596 : function catch clauses. Handling, say, main() return semantics here
20597 : would be wrong, as flowing off the end of a function catch clause for
20598 : main() would also need to return 0. */
20599 :
20600 : void
20601 133283140 : finish_function_body (tree compstmt)
20602 : {
20603 133283140 : if (compstmt == NULL_TREE)
20604 : return;
20605 :
20606 : /* Close the block. */
20607 26037870 : finish_compound_stmt (compstmt);
20608 :
20609 26037870 : if (processing_template_decl)
20610 : /* Do nothing now. */;
20611 8718864 : else if (DECL_CONSTRUCTOR_P (current_function_decl)
20612 8718864 : || DECL_DESTRUCTOR_P (current_function_decl))
20613 8221337 : maybe_return_this ();
20614 : }
20615 :
20616 : /* Given a function, returns the BLOCK corresponding to the outermost level
20617 : of curly braces, skipping the artificial block created for constructor
20618 : initializers. */
20619 :
20620 : tree
20621 365617 : outer_curly_brace_block (tree fndecl)
20622 : {
20623 365617 : tree block = DECL_INITIAL (fndecl);
20624 365617 : if (BLOCK_OUTER_CURLY_BRACE_P (block))
20625 : return block;
20626 1213 : block = BLOCK_SUBBLOCKS (block);
20627 1213 : if (BLOCK_OUTER_CURLY_BRACE_P (block))
20628 : return block;
20629 0 : block = BLOCK_SUBBLOCKS (block);
20630 0 : gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
20631 : return block;
20632 : }
20633 :
20634 : /* If FNDECL is a class's key method, add the class to the list of
20635 : keyed classes that should be emitted. */
20636 :
20637 : static void
20638 169409588 : record_key_method_defined (tree fndecl)
20639 : {
20640 228857194 : if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
20641 110057613 : && DECL_VIRTUAL_P (fndecl)
20642 172294632 : && !processing_template_decl)
20643 : {
20644 1499728 : tree fnclass = DECL_CONTEXT (fndecl);
20645 1499728 : if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
20646 : {
20647 30801 : tree classdecl = TYPE_NAME (fnclass);
20648 : /* Classes attached to a named module are already handled. */
20649 30801 : if (!DECL_LANG_SPECIFIC (classdecl)
20650 31124 : || !DECL_MODULE_ATTACH_P (classdecl))
20651 30756 : vec_safe_push (keyed_classes, fnclass);
20652 : }
20653 : }
20654 169409588 : }
20655 :
20656 : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
20657 : of "return *this;" immediately before its location, using FNDECL's
20658 : first statement (if any) to give the indentation, if appropriate. */
20659 :
20660 : static void
20661 18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
20662 : {
20663 18 : location_t indent = UNKNOWN_LOCATION;
20664 18 : tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
20665 18 : if (stmts)
20666 9 : indent = EXPR_LOCATION (stmts);
20667 18 : richloc->add_fixit_insert_formatted ("return *this;",
20668 : richloc->get_loc (),
20669 : indent);
20670 18 : }
20671 :
20672 : /* Finish up a function declaration and compile that function
20673 : all the way to assembler language output. The free the storage
20674 : for the function definition. INLINE_P is TRUE if we just
20675 : finished processing the body of an in-class inline function
20676 : definition. (This processing will have taken place after the
20677 : class definition is complete.) */
20678 :
20679 : tree
20680 169405604 : finish_function (bool inline_p)
20681 : {
20682 169405604 : tree fndecl = current_function_decl;
20683 169405604 : tree fntype, ctype = NULL_TREE;
20684 169405604 : tree resumer = NULL_TREE, destroyer = NULL_TREE;
20685 :
20686 : /* When we get some parse errors, we can end up without a
20687 : current_function_decl, so cope. */
20688 169405604 : if (fndecl == NULL_TREE || fndecl == error_mark_node)
20689 0 : return error_mark_node;
20690 :
20691 169405604 : if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20692 169405031 : finish_lambda_scope ();
20693 :
20694 169405604 : if (c_dialect_objc ())
20695 0 : objc_finish_function ();
20696 :
20697 169405604 : record_key_method_defined (fndecl);
20698 :
20699 169405604 : fntype = TREE_TYPE (fndecl);
20700 :
20701 : /* TREE_READONLY (fndecl) = 1;
20702 : This caused &foo to be of type ptr-to-const-function
20703 : which then got a warning when stored in a ptr-to-function variable. */
20704 :
20705 169405604 : gcc_assert (building_stmt_list_p ());
20706 : /* The current function is being defined, so its DECL_INITIAL should
20707 : be set, and unless there's a multiple definition, it should be
20708 : error_mark_node. */
20709 169405604 : gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
20710 :
20711 169405604 : cp_coroutine_transform *coroutine = nullptr;
20712 169405604 : if (flag_coroutines
20713 166554560 : && !processing_template_decl
20714 68104897 : && DECL_COROUTINE_P (fndecl)
20715 169410566 : && !DECL_RAMP_FN (fndecl))
20716 : {
20717 1710 : gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
20718 : && !DECL_DEFAULTED_FN (fndecl));
20719 1710 : coroutine = new cp_coroutine_transform (fndecl, inline_p);
20720 1710 : if (coroutine && coroutine->cp_valid_coroutine ())
20721 1710 : coroutine->apply_transforms ();
20722 :
20723 : /* We should handle coroutine IFNs in middle end lowering. */
20724 1710 : cfun->coroutine_component = true;
20725 :
20726 : /* Do not try to process the ramp's EH unless outlining succeeded. */
20727 1710 : if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
20728 360 : finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
20729 : (TREE_TYPE (fndecl)),
20730 360 : current_eh_spec_block);
20731 :
20732 : /* If outlining succeeded, then add contracts handling if needed. */
20733 1710 : if (coroutine->cp_valid_coroutine ())
20734 1626 : maybe_apply_function_contracts (fndecl);
20735 : }
20736 : else
20737 : /* For a cloned function, we've already got all the code we need;
20738 : there's no need to add any extra bits. */
20739 169403894 : if (!DECL_CLONED_FUNCTION_P (fndecl))
20740 : {
20741 : /* Make it so that `main' always returns 0 by default. */
20742 152617151 : if (DECL_MAIN_FREESTANDING_P (current_function_decl)
20743 152651293 : && !TREE_THIS_VOLATILE (current_function_decl))
20744 34142 : finish_return_stmt (integer_zero_node);
20745 :
20746 152617151 : if (use_eh_spec_block (current_function_decl))
20747 25809118 : finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
20748 : (TREE_TYPE (current_function_decl)),
20749 25809118 : current_eh_spec_block);
20750 :
20751 152617151 : maybe_apply_function_contracts (current_function_decl);
20752 :
20753 : }
20754 :
20755 : /* If we're saving up tree structure, tie off the function now. */
20756 169405604 : DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
20757 :
20758 169405604 : finish_fname_decls ();
20759 :
20760 : /* This must come after expand_function_end because cleanups might
20761 : have declarations (from inline functions) that need to go into
20762 : this function's blocks. */
20763 :
20764 : /* If the current binding level isn't the outermost binding level
20765 : for this function, either there is a bug, or we have experienced
20766 : syntax errors and the statement tree is malformed. */
20767 169405604 : if (current_binding_level->kind != sk_function_parms)
20768 : {
20769 : /* Make sure we have already experienced errors. */
20770 12 : gcc_assert (errorcount);
20771 :
20772 : /* Throw away the broken statement tree and extra binding
20773 : levels. */
20774 12 : DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
20775 :
20776 27 : while (current_binding_level->kind != sk_function_parms)
20777 : {
20778 15 : if (current_binding_level->kind == sk_class)
20779 0 : pop_nested_class ();
20780 : else
20781 15 : poplevel (0, 0, 0);
20782 : }
20783 : }
20784 169405604 : poplevel (1, 0, 1);
20785 :
20786 : /* Statements should always be full-expressions at the outermost set
20787 : of curly braces for a function. */
20788 169405604 : gcc_assert (stmts_are_full_exprs_p ());
20789 :
20790 : /* If there are no return statements in a function with auto return type,
20791 : the return type is void. But if the declared type is something like
20792 : auto*, this is an error. */
20793 69925149 : if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
20794 170471006 : && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20795 : {
20796 148032 : if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20797 148017 : && !current_function_returns_value
20798 295812 : && !current_function_returns_null)
20799 : {
20800 : /* We haven't applied return type deduction because we haven't
20801 : seen any return statements. Do that now. */
20802 147780 : tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
20803 147780 : do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
20804 : void_node, node, tf_warning_or_error,
20805 : adc_return_type);
20806 :
20807 147780 : apply_deduced_return_type (fndecl, void_type_node);
20808 147780 : fntype = TREE_TYPE (fndecl);
20809 : }
20810 252 : else if (!current_function_returns_value
20811 6 : && !current_function_returns_null)
20812 : {
20813 6 : auto_diagnostic_group d;
20814 12 : error ("no return statements in function returning %qT",
20815 6 : DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
20816 6 : inform (input_location, "only plain %<auto%> return type can be "
20817 : "deduced to %<void%>");
20818 6 : }
20819 : }
20820 :
20821 169405604 : if (FNDECL_USED_AUTO (fndecl)
20822 169405604 : && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20823 1065150 : if (location_t fcloc = failed_completion_location (fndecl))
20824 : {
20825 6 : auto_diagnostic_group adg;
20826 6 : if (warning (OPT_Wsfinae_incomplete_,
20827 : "defining %qD, which previously failed to be deduced "
20828 : "in a SFINAE context", fndecl)
20829 6 : && warn_sfinae_incomplete == 1)
20830 6 : inform (fcloc, "here. Use %qs for a diagnostic at that point",
20831 : "-Wsfinae-incomplete=2");
20832 6 : }
20833 :
20834 : /* Remember that we were in class scope. */
20835 169405604 : if (current_class_name)
20836 129835556 : ctype = current_class_type;
20837 :
20838 169405604 : if (DECL_DELETED_FN (fndecl))
20839 : {
20840 93 : DECL_INITIAL (fndecl) = error_mark_node;
20841 93 : DECL_SAVED_TREE (fndecl) = NULL_TREE;
20842 93 : goto cleanup;
20843 : }
20844 :
20845 169405511 : if (flag_openmp)
20846 326882 : if (tree attr = lookup_attribute ("omp declare variant base",
20847 326882 : DECL_ATTRIBUTES (fndecl)))
20848 267 : omp_declare_variant_finalize (fndecl, attr);
20849 :
20850 : /* Complain if there's just no return statement. */
20851 169405511 : if ((warn_return_type
20852 47369 : || (cxx_dialect >= cxx14
20853 39336 : && DECL_DECLARED_CONSTEXPR_P (fndecl)))
20854 169376139 : && !VOID_TYPE_P (TREE_TYPE (fntype))
20855 106590569 : && !dependent_type_p (TREE_TYPE (fntype))
20856 53969865 : && !current_function_returns_value && !current_function_returns_null
20857 : /* Don't complain if we abort or throw. */
20858 37826 : && !current_function_returns_abnormally
20859 : /* Don't complain if there's an infinite loop. */
20860 953 : && !current_function_infinite_loop
20861 : /* Don't complain if we are declared noreturn. */
20862 885 : && !TREE_THIS_VOLATILE (fndecl)
20863 879 : && !DECL_NAME (DECL_RESULT (fndecl))
20864 879 : && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
20865 : /* Structor return values (if any) are set by the compiler. */
20866 1270 : && !DECL_CONSTRUCTOR_P (fndecl)
20867 635 : && !DECL_DESTRUCTOR_P (fndecl)
20868 169406146 : && targetm.warn_func_return (fndecl))
20869 : {
20870 629 : gcc_rich_location richloc (input_location);
20871 : /* Potentially add a "return *this;" fix-it hint for
20872 : assignment operators. */
20873 629 : if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
20874 : {
20875 39 : tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
20876 39 : if (TREE_CODE (valtype) == REFERENCE_TYPE
20877 32 : && current_class_ref
20878 26 : && same_type_ignoring_top_level_qualifiers_p
20879 26 : (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
20880 71 : && global_dc->option_enabled_p (OPT_Wreturn_type))
20881 18 : add_return_star_this_fixit (&richloc, fndecl);
20882 : }
20883 629 : if (cxx_dialect >= cxx14
20884 629 : && DECL_DECLARED_CONSTEXPR_P (fndecl))
20885 2 : error_at (&richloc, "no return statement in %<constexpr%> function "
20886 : "returning non-void");
20887 627 : else if (warning_at (&richloc, OPT_Wreturn_type,
20888 : "no return statement in function returning "
20889 : "non-void"))
20890 169 : suppress_warning (fndecl, OPT_Wreturn_type);
20891 629 : }
20892 :
20893 : /* Lambda closure members are implicitly constexpr if possible. */
20894 169405511 : if (cxx_dialect >= cxx17
20895 293114247 : && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
20896 2038834 : DECL_DECLARED_CONSTEXPR_P (fndecl)
20897 2038834 : = ((processing_template_decl
20898 659135 : || is_valid_constexpr_fn (fndecl, /*complain*/false))
20899 4076788 : && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
20900 :
20901 : /* Invoke the pre-genericize plugin before we start munging things. */
20902 169405511 : if (!processing_template_decl)
20903 69925056 : invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
20904 :
20905 : /* Fold away non-ODR usages of constants so that we don't need to
20906 : try and stream them in modules if they're internal. */
20907 169405511 : if (!processing_template_decl)
20908 69925056 : cp_fold_function_non_odr_use (fndecl);
20909 :
20910 : /* Save constexpr function body before it gets munged by
20911 : the NRV transformation. */
20912 169405511 : maybe_save_constexpr_fundef (fndecl);
20913 :
20914 : /* Perform delayed folding before NRV transformation. */
20915 169405511 : if (!processing_template_decl
20916 139850112 : && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
20917 238278585 : && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20918 68872631 : cp_fold_function (fndecl);
20919 :
20920 : /* Set up the named return value optimization, if we can. Candidate
20921 : variables are selected in check_return_expr. */
20922 169405511 : if (tree r = current_function_return_value)
20923 : {
20924 44593309 : if (r != error_mark_node)
20925 234376 : finalize_nrv (fndecl, r);
20926 44593309 : current_function_return_value = NULL_TREE;
20927 : }
20928 :
20929 : /* Must mark the RESULT_DECL as being in this function. */
20930 169405511 : DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
20931 :
20932 : /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
20933 : to the FUNCTION_DECL node itself. */
20934 169405511 : BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
20935 :
20936 : /* Store the end of the function, so that we get good line number
20937 : info for the epilogue. */
20938 169405511 : cfun->function_end_locus = input_location;
20939 :
20940 : /* Complain about parameters that are only set, but never otherwise used. */
20941 169405511 : if (warn_unused_but_set_parameter
20942 1000929 : && !processing_template_decl
20943 511138 : && errorcount == unused_but_set_errorcount
20944 169916646 : && !DECL_CLONED_FUNCTION_P (fndecl))
20945 : {
20946 399296 : tree decl;
20947 :
20948 399296 : for (decl = DECL_ARGUMENTS (fndecl);
20949 1064378 : decl;
20950 665082 : decl = DECL_CHAIN (decl))
20951 665082 : if (TREE_USED (decl)
20952 552039 : && TREE_CODE (decl) == PARM_DECL
20953 552039 : && !DECL_READ_P (decl)
20954 225 : && DECL_NAME (decl)
20955 225 : && !DECL_ARTIFICIAL (decl)
20956 225 : && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
20957 225 : && !DECL_IN_SYSTEM_HEADER (decl)
20958 225 : && TREE_TYPE (decl) != error_mark_node
20959 225 : && !TYPE_REF_P (TREE_TYPE (decl))
20960 665307 : && (!CLASS_TYPE_P (TREE_TYPE (decl))
20961 0 : || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
20962 225 : warning_at (DECL_SOURCE_LOCATION (decl),
20963 225 : OPT_Wunused_but_set_parameter_,
20964 : "parameter %qD set but not used", decl);
20965 399296 : unused_but_set_errorcount = errorcount;
20966 : }
20967 :
20968 : /* Complain about locally defined typedefs that are not used in this
20969 : function. */
20970 169405511 : maybe_warn_unused_local_typedefs ();
20971 :
20972 : /* Possibly warn about unused parameters. */
20973 169405511 : if (warn_unused_parameter
20974 731543 : && !processing_template_decl
20975 169759249 : && !DECL_CLONED_FUNCTION_P (fndecl))
20976 271749 : do_warn_unused_parameter (fndecl);
20977 :
20978 : /* Genericize before inlining. */
20979 169405511 : if (!processing_template_decl
20980 139850112 : && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
20981 238278098 : && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20982 68872144 : cp_genericize (fndecl);
20983 :
20984 : /* If this function can't throw any exceptions, remember that. */
20985 169405511 : if (!processing_template_decl
20986 69925056 : && !cp_function_chain->can_throw
20987 53315599 : && !flag_non_call_exceptions
20988 53306816 : && !decl_replaceable_p (fndecl,
20989 53306816 : opt_for_fn (fndecl, flag_semantic_interposition))
20990 222462475 : && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
20991 53054129 : TREE_NOTHROW (fndecl) = 1;
20992 :
20993 169405604 : cleanup:
20994 :
20995 : /* We're leaving the context of this function, so zap cfun. It's still in
20996 : DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation. */
20997 169405604 : set_cfun (NULL);
20998 169405604 : current_function_decl = NULL;
20999 :
21000 : /* If this is an in-class inline definition, we may have to pop the
21001 : bindings for the template parameters that we added in
21002 : maybe_begin_member_template_processing when start_function was
21003 : called. */
21004 169405604 : if (inline_p)
21005 87077921 : maybe_end_member_template_processing ();
21006 :
21007 : /* Leave the scope of the class. */
21008 169405604 : if (ctype)
21009 129835556 : pop_nested_class ();
21010 :
21011 169405604 : --function_depth;
21012 :
21013 : /* Clean up. */
21014 169405604 : invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
21015 :
21016 : /* Build outlined functions for coroutines and contracts. */
21017 :
21018 169405604 : if (coroutine)
21019 : {
21020 : /* Emit the resumer and destroyer functions now, providing that we have
21021 : not encountered some fatal error. */
21022 1710 : if (coroutine->cp_valid_coroutine ())
21023 : {
21024 1626 : coroutine->finish_transforms ();
21025 1626 : resumer = coroutine->get_resumer ();
21026 1626 : destroyer = coroutine->get_destroyer ();
21027 1626 : expand_or_defer_fn (resumer);
21028 1626 : expand_or_defer_fn (destroyer);
21029 : }
21030 1710 : delete coroutine;
21031 : }
21032 :
21033 : /* If we have used outlined contracts checking functions, build and emit
21034 : them here. */
21035 169405604 : finish_function_outlined_contracts (fndecl);
21036 :
21037 169405604 : return fndecl;
21038 : }
21039 :
21040 : /* Create the FUNCTION_DECL for a function definition.
21041 : DECLSPECS and DECLARATOR are the parts of the declaration;
21042 : they describe the return type and the name of the function,
21043 : but twisted together in a fashion that parallels the syntax of C.
21044 :
21045 : This function creates a binding context for the function body
21046 : as well as setting up the FUNCTION_DECL in current_function_decl.
21047 :
21048 : Returns a FUNCTION_DECL on success.
21049 :
21050 : If the DECLARATOR is not suitable for a function (it defines a datum
21051 : instead), we return 0, which tells yyparse to report a parse error.
21052 :
21053 : May return void_type_node indicating that this method is actually
21054 : a friend. See grokfield for more details.
21055 :
21056 : Came here with a `.pushlevel' .
21057 :
21058 : DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
21059 : CHANGES TO CODE IN `grokfield'. */
21060 :
21061 : tree
21062 87303617 : grokmethod (cp_decl_specifier_seq *declspecs,
21063 : const cp_declarator *declarator, tree attrlist)
21064 : {
21065 87303617 : tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
21066 87303617 : &attrlist);
21067 :
21068 87303617 : if (fndecl == error_mark_node)
21069 : return error_mark_node;
21070 :
21071 87303512 : if (attrlist)
21072 0 : cplus_decl_attributes (&fndecl, attrlist, 0);
21073 :
21074 : /* Pass friends other than inline friend functions back. */
21075 87303512 : if (fndecl == void_type_node)
21076 : return fndecl;
21077 :
21078 87303512 : if (DECL_IN_AGGR_P (fndecl))
21079 : {
21080 0 : if (DECL_CLASS_SCOPE_P (fndecl))
21081 0 : error ("%qD is already defined in class %qT", fndecl,
21082 0 : DECL_CONTEXT (fndecl));
21083 0 : return error_mark_node;
21084 : }
21085 :
21086 87303512 : check_template_shadow (fndecl);
21087 :
21088 : /* p1779 ABI-Isolation makes inline not a default for in-class
21089 : definitions attached to a named module. If the user explicitly
21090 : made it inline, grokdeclarator will already have done the right
21091 : things. */
21092 87303512 : if ((!named_module_attach_p ()
21093 1169 : || flag_module_implicit_inline
21094 : /* Lambda's operator function remains inline. */
21095 2302 : || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
21096 : /* If the user explicitly asked for this to be inline, we don't
21097 : need to do more, but more importantly we want to warn if we
21098 : can't inline it. */
21099 87303049 : && !DECL_DECLARED_INLINE_P (fndecl))
21100 : {
21101 49064857 : if (TREE_PUBLIC (fndecl))
21102 46800330 : DECL_COMDAT (fndecl) = 1;
21103 49064857 : DECL_DECLARED_INLINE_P (fndecl) = 1;
21104 : /* It's ok if we can't inline this. */
21105 49064857 : DECL_NO_INLINE_WARNING_P (fndecl) = 1;
21106 : }
21107 :
21108 : /* We process method specializations in finish_struct_1. */
21109 87303512 : if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
21110 : {
21111 : /* Avoid calling decl_spec_seq... until we have to. */
21112 70111132 : bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
21113 70111132 : fndecl = push_template_decl (fndecl, friendp);
21114 70111132 : if (fndecl == error_mark_node)
21115 : return fndecl;
21116 : }
21117 :
21118 87303504 : if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
21119 : {
21120 0 : fndecl = copy_node (fndecl);
21121 0 : TREE_CHAIN (fndecl) = NULL_TREE;
21122 : }
21123 :
21124 87303504 : cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
21125 :
21126 87303504 : DECL_IN_AGGR_P (fndecl) = 1;
21127 87303504 : return fndecl;
21128 : }
21129 :
21130 :
21131 : /* VAR is a VAR_DECL. If its type is incomplete, remember VAR so that
21132 : we can lay it out later, when and if its type becomes complete.
21133 :
21134 : Also handle constexpr variables where the initializer involves
21135 : an unlowered PTRMEM_CST because the class isn't complete yet. */
21136 :
21137 : void
21138 108309654 : maybe_register_incomplete_var (tree var)
21139 : {
21140 108309654 : gcc_assert (VAR_P (var));
21141 :
21142 : /* Keep track of variables with incomplete types. */
21143 47517604 : if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
21144 155825465 : && DECL_EXTERNAL (var))
21145 : {
21146 6816422 : tree inner_type = TREE_TYPE (var);
21147 :
21148 6976588 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
21149 160166 : inner_type = TREE_TYPE (inner_type);
21150 6816422 : inner_type = TYPE_MAIN_VARIANT (inner_type);
21151 :
21152 6974209 : if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
21153 : /* RTTI TD entries are created while defining the type_info. */
21154 6816422 : || (TYPE_LANG_SPECIFIC (inner_type)
21155 2418298 : && TYPE_BEING_DEFINED (inner_type)))
21156 : {
21157 157787 : incomplete_var iv = {var, inner_type};
21158 157787 : vec_safe_push (incomplete_vars, iv);
21159 : }
21160 13013052 : else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
21161 3620695 : && DECL_CLASS_SCOPE_P (var)
21162 1129548 : && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
21163 1129548 : && decl_constant_var_p (var)
21164 7382545 : && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
21165 : {
21166 : /* When the outermost open class is complete we can resolve any
21167 : pointers-to-members. */
21168 27 : tree context = outermost_open_class ();
21169 27 : incomplete_var iv = {var, context};
21170 27 : vec_safe_push (incomplete_vars, iv);
21171 : }
21172 : }
21173 108309654 : }
21174 :
21175 : /* Called when a class type (given by TYPE) is defined. If there are
21176 : any existing VAR_DECLs whose type has been completed by this
21177 : declaration, update them now. */
21178 :
21179 : void
21180 73928042 : complete_vars (tree type)
21181 : {
21182 73928042 : unsigned ix;
21183 73928042 : incomplete_var *iv;
21184 :
21185 74602661 : for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
21186 : {
21187 674619 : if (same_type_p (type, iv->incomplete_type))
21188 : {
21189 156583 : tree var = iv->decl;
21190 156583 : tree type = TREE_TYPE (var);
21191 :
21192 156583 : if (type != error_mark_node
21193 156583 : && (TYPE_MAIN_VARIANT (strip_array_types (type))
21194 156580 : == iv->incomplete_type))
21195 : {
21196 : /* Complete the type of the variable. */
21197 156553 : complete_type (type);
21198 156553 : cp_apply_type_quals_to_decl (cp_type_quals (type), var);
21199 156553 : if (COMPLETE_TYPE_P (type))
21200 156538 : layout_var_decl (var);
21201 : }
21202 :
21203 : /* Remove this entry from the list. */
21204 156583 : incomplete_vars->unordered_remove (ix);
21205 : }
21206 : else
21207 518036 : ix++;
21208 : }
21209 73928042 : }
21210 :
21211 : /* If DECL is of a type which needs a cleanup, build and return an
21212 : expression to perform that cleanup here. Return NULL_TREE if no
21213 : cleanup need be done. DECL can also be a _REF when called from
21214 : split_nonconstant_init_1. */
21215 :
21216 : tree
21217 92917490 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
21218 : {
21219 92917490 : tree type;
21220 92917490 : tree attr;
21221 92917490 : tree cleanup;
21222 :
21223 : /* Assume no cleanup is required. */
21224 92917490 : cleanup = NULL_TREE;
21225 :
21226 92917490 : if (!decl || error_operand_p (decl))
21227 : return cleanup;
21228 :
21229 : /* Handle "__attribute__((cleanup))". We run the cleanup function
21230 : before the destructor since the destructor is what actually
21231 : terminates the lifetime of the object. */
21232 92917490 : if (DECL_P (decl))
21233 92558102 : attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
21234 : else
21235 : attr = NULL_TREE;
21236 92558102 : if (attr)
21237 : {
21238 159 : tree id;
21239 159 : tree fn;
21240 159 : tree arg;
21241 :
21242 : /* Get the name specified by the user for the cleanup function. */
21243 159 : id = TREE_VALUE (TREE_VALUE (attr));
21244 : /* Look up the name to find the cleanup function to call. It is
21245 : important to use lookup_name here because that is what is
21246 : used in c-common.cc:handle_cleanup_attribute when performing
21247 : initial checks on the attribute. Note that those checks
21248 : include ensuring that the function found is not an overloaded
21249 : function, or an object with an overloaded call operator,
21250 : etc.; we can rely on the fact that the function found is an
21251 : ordinary FUNCTION_DECL. */
21252 159 : fn = lookup_name (id);
21253 159 : arg = build_address (decl);
21254 159 : if (!mark_used (decl, complain) && !(complain & tf_error))
21255 0 : return error_mark_node;
21256 159 : cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
21257 159 : if (cleanup == error_mark_node)
21258 : return error_mark_node;
21259 : }
21260 : /* Handle ordinary C++ destructors. */
21261 92917478 : type = TREE_TYPE (decl);
21262 92917478 : if (type_build_dtor_call (type))
21263 : {
21264 7018016 : int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
21265 7018016 : tree addr;
21266 7018016 : tree call;
21267 :
21268 7018016 : if (TREE_CODE (type) == ARRAY_TYPE)
21269 : addr = decl;
21270 : else
21271 7012768 : addr = build_address (decl);
21272 :
21273 7018016 : call = build_delete (input_location, TREE_TYPE (addr), addr,
21274 : sfk_complete_destructor, flags, 0, complain);
21275 7018016 : if (call == error_mark_node)
21276 : cleanup = error_mark_node;
21277 7017953 : else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
21278 : /* Discard the call. */;
21279 4304843 : else if (decl_maybe_constant_destruction (decl, type)
21280 4305045 : && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
21281 202 : cxx_constant_dtor (call, decl);
21282 4304641 : else if (cleanup)
21283 3 : cleanup = cp_build_compound_expr (cleanup, call, complain);
21284 : else
21285 : cleanup = call;
21286 : }
21287 :
21288 : /* build_delete sets the location of the destructor call to the
21289 : current location, even though the destructor is going to be
21290 : called later, at the end of the current scope. This can lead to
21291 : a "jumpy" behavior for users of debuggers when they step around
21292 : the end of the block. So let's unset the location of the
21293 : destructor call instead. */
21294 92917478 : protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
21295 92917478 : if (cleanup && CONVERT_EXPR_P (cleanup))
21296 0 : protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
21297 :
21298 0 : if (cleanup
21299 4304848 : && DECL_P (decl)
21300 4304382 : && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
21301 : /* Treat objects with destructors as used; the destructor may do
21302 : something substantive. */
21303 4304376 : && !mark_used (decl, complain) && !(complain & tf_error))
21304 0 : return error_mark_node;
21305 :
21306 4304848 : if (cleanup && cfun && !processing_template_decl
21307 96779723 : && !expr_noexcept_p (cleanup, tf_none))
21308 5868 : cp_function_chain->throwing_cleanup = true;
21309 :
21310 : return cleanup;
21311 : }
21312 :
21313 :
21314 : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
21315 : FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
21316 : METHOD_TYPE or FUNCTION_TYPE, or pointer to member function. */
21317 :
21318 : tree
21319 810785 : static_fn_type (tree memfntype)
21320 : {
21321 810785 : tree fntype;
21322 810785 : tree args;
21323 :
21324 810785 : if (TYPE_PTRMEMFUNC_P (memfntype))
21325 20955 : memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
21326 810785 : if (INDIRECT_TYPE_P (memfntype)
21327 687405 : || TREE_CODE (memfntype) == FUNCTION_DECL)
21328 637609 : memfntype = TREE_TYPE (memfntype);
21329 810785 : if (TREE_CODE (memfntype) == FUNCTION_TYPE)
21330 : return memfntype;
21331 627487 : gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
21332 627487 : args = TYPE_ARG_TYPES (memfntype);
21333 627487 : fntype = cp_build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
21334 627487 : fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
21335 627487 : fntype = (cp_build_type_attribute_variant
21336 627487 : (fntype, TYPE_ATTRIBUTES (memfntype)));
21337 627487 : fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
21338 627487 : return fntype;
21339 : }
21340 :
21341 : /* DECL was originally constructed as a non-static member function,
21342 : but turned out to be static. Update it accordingly. */
21343 :
21344 : void
21345 183922 : revert_static_member_fn (tree decl)
21346 : {
21347 183922 : tree stype = static_fn_type (decl);
21348 183922 : cp_cv_quals quals = type_memfn_quals (stype);
21349 183922 : cp_ref_qualifier rqual = type_memfn_rqual (stype);
21350 :
21351 183922 : if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
21352 9 : stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
21353 :
21354 183922 : TREE_TYPE (decl) = stype;
21355 :
21356 183922 : if (DECL_ARGUMENTS (decl))
21357 183922 : DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
21358 183922 : DECL_STATIC_FUNCTION_P (decl) = 1;
21359 183922 : }
21360 :
21361 : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
21362 : one of the language-independent trees. */
21363 :
21364 : enum cp_tree_node_structure_enum
21365 39600973693 : cp_tree_node_structure (union lang_tree_node * t)
21366 : {
21367 39600973693 : switch (TREE_CODE (&t->generic))
21368 : {
21369 : case ARGUMENT_PACK_SELECT: return TS_CP_ARGUMENT_PACK_SELECT;
21370 162424937 : case BASELINK: return TS_CP_BASELINK;
21371 84551188 : case CONSTRAINT_INFO: return TS_CP_CONSTRAINT_INFO;
21372 11808221 : case DEFERRED_NOEXCEPT: return TS_CP_DEFERRED_NOEXCEPT;
21373 6276124 : case DEFERRED_PARSE: return TS_CP_DEFERRED_PARSE;
21374 2137587453 : case IDENTIFIER_NODE: return TS_CP_IDENTIFIER;
21375 3551554 : case LAMBDA_EXPR: return TS_CP_LAMBDA_EXPR;
21376 277092 : case BINDING_VECTOR: return TS_CP_BINDING_VECTOR;
21377 735563810 : case OVERLOAD: return TS_CP_OVERLOAD;
21378 719 : case PTRMEM_CST: return TS_CP_PTRMEM;
21379 16408412 : case STATIC_ASSERT: return TS_CP_STATIC_ASSERT;
21380 698661954 : case TEMPLATE_DECL: return TS_CP_TEMPLATE_DECL;
21381 1623671309 : case TEMPLATE_INFO: return TS_CP_TEMPLATE_INFO;
21382 706943916 : case TEMPLATE_PARM_INDEX: return TS_CP_TPI;
21383 15952529 : case TRAIT_EXPR: return TS_CP_TRAIT_EXPR;
21384 6 : case TU_LOCAL_ENTITY: return TS_CP_TU_LOCAL_ENTITY;
21385 3670776 : case USERDEF_LITERAL: return TS_CP_USERDEF_LITERAL;
21386 14934729 : case REQUIRES_EXPR: return TS_CP_REQUIRES_EXPR;
21387 33378688964 : default: return TS_CP_GENERIC;
21388 : }
21389 : }
21390 :
21391 : bool
21392 9176 : cp_missing_noreturn_ok_p (tree decl)
21393 : {
21394 : /* A missing noreturn is ok for the `main' function. */
21395 9176 : return DECL_MAIN_P (decl);
21396 : }
21397 :
21398 : /* Return the decl used to identify the COMDAT group into which DECL should
21399 : be placed. */
21400 :
21401 : tree
21402 130548814 : cxx_comdat_group (tree decl)
21403 : {
21404 : /* Virtual tables, construction virtual tables, and virtual table
21405 : tables all go in a single COMDAT group, named after the primary
21406 : virtual table. */
21407 130548814 : if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
21408 541400 : decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
21409 : /* For all other DECLs, the COMDAT group is the mangled name of the
21410 : declaration itself. */
21411 : else
21412 : {
21413 130007414 : while (DECL_THUNK_P (decl))
21414 : {
21415 : /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
21416 : into the same section as the target function. In that case
21417 : we must return target's name. */
21418 0 : tree target = THUNK_TARGET (decl);
21419 0 : if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
21420 0 : && DECL_SECTION_NAME (target) != NULL
21421 0 : && DECL_ONE_ONLY (target))
21422 : decl = target;
21423 : else
21424 : break;
21425 : }
21426 : /* If a ctor/dtor has already set the comdat group by
21427 : maybe_clone_body, don't override it. */
21428 130007414 : if (SUPPORTS_ONE_ONLY
21429 130007414 : && TREE_CODE (decl) == FUNCTION_DECL
21430 130007414 : && DECL_CLONED_FUNCTION_P (decl))
21431 18896392 : if (tree comdat = DECL_COMDAT_GROUP (decl))
21432 2769534 : return comdat;
21433 : }
21434 :
21435 : return decl;
21436 : }
21437 :
21438 : /* Returns the return type for FN as written by the user, which may include
21439 : a placeholder for a deduced return type. */
21440 :
21441 : tree
21442 569136974 : fndecl_declared_return_type (tree fn)
21443 : {
21444 569136974 : fn = STRIP_TEMPLATE (fn);
21445 569136974 : if (FNDECL_USED_AUTO (fn))
21446 403115 : return DECL_SAVED_AUTO_RETURN_TYPE (fn);
21447 :
21448 568733859 : return TREE_TYPE (TREE_TYPE (fn));
21449 : }
21450 :
21451 : /* Returns true iff DECL is a variable or function declared with an auto type
21452 : that has not yet been deduced to a real type. */
21453 :
21454 : bool
21455 1022654381 : undeduced_auto_decl (tree decl)
21456 : {
21457 1022654381 : if (cxx_dialect < cxx11)
21458 : return false;
21459 1020038506 : STRIP_ANY_LOCATION_WRAPPER (decl);
21460 464436493 : return ((VAR_OR_FUNCTION_DECL_P (decl)
21461 98008744 : || TREE_CODE (decl) == TEMPLATE_DECL)
21462 1386739832 : && type_uses_auto (TREE_TYPE (decl)));
21463 : }
21464 :
21465 : /* Complain if DECL has an undeduced return type. */
21466 :
21467 : bool
21468 338742796 : require_deduced_type (tree decl, tsubst_flags_t complain)
21469 : {
21470 338742796 : if (undeduced_auto_decl (decl))
21471 : {
21472 14412 : if (TREE_CODE (decl) == FUNCTION_DECL
21473 14412 : && fndecl_built_in_p (decl, CP_BUILT_IN_SOURCE_LOCATION,
21474 : BUILT_IN_FRONTEND))
21475 : {
21476 : /* Set the return type of __builtin_source_location. */
21477 10334 : tree type = get_source_location_impl_type ();
21478 10334 : if (type == error_mark_node)
21479 : {
21480 33 : inform (input_location, "using %qs", "__builtin_source_location");
21481 33 : return false;
21482 : }
21483 10301 : type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
21484 10301 : type = build_pointer_type (type);
21485 10301 : apply_deduced_return_type (decl, type);
21486 10301 : return true;
21487 : }
21488 :
21489 4078 : if (TREE_CODE (decl) == FUNCTION_DECL
21490 4078 : && fndecl_built_in_p (decl, CP_BUILT_IN_CURRENT_EXCEPTION,
21491 : BUILT_IN_FRONTEND))
21492 : {
21493 : /* Set the return type of __builtin_current_exception. */
21494 2080 : tree name = get_identifier ("exception_ptr");
21495 2080 : tree eptr = lookup_qualified_name (std_node, name);
21496 2080 : tree fld;
21497 2080 : if (TREE_CODE (eptr) != TYPE_DECL
21498 2080 : || !CLASS_TYPE_P (TREE_TYPE (eptr))
21499 2080 : || !COMPLETE_TYPE_P (TREE_TYPE (eptr))
21500 2080 : || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (eptr))))
21501 2080 : || DECL_ARTIFICIAL (fld)
21502 2080 : || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE
21503 2080 : || next_aggregate_field (DECL_CHAIN (fld))
21504 4160 : || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (eptr)),
21505 2080 : TYPE_SIZE (TREE_TYPE (fld))))
21506 : {
21507 0 : error ("%qs used without %qs declaration",
21508 : "__builtin_current_exception", "std::exception_ptr");
21509 0 : return false;
21510 : }
21511 :
21512 2080 : apply_deduced_return_type (decl, TREE_TYPE (eptr));
21513 2080 : return true;
21514 : }
21515 :
21516 1998 : if (warning_suppressed_p (decl) && seen_error ())
21517 : /* We probably already complained about deduction failure. */;
21518 1815 : else if (complain & tf_error)
21519 74 : error ("use of %qD before deduction of %<auto%>", decl);
21520 1998 : note_failed_type_completion (decl, complain);
21521 1998 : return false;
21522 : }
21523 : return true;
21524 : }
21525 :
21526 : /* Create a representation of the explicit-specifier with
21527 : constant-expression of EXPR. COMPLAIN is as for tsubst. */
21528 :
21529 : tree
21530 8597387 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
21531 : {
21532 8597387 : if (check_for_bare_parameter_packs (expr))
21533 3 : return error_mark_node;
21534 :
21535 8597384 : if (instantiation_dependent_expression_p (expr))
21536 : /* Wait for instantiation, tsubst_function_decl will handle it. */
21537 : return expr;
21538 :
21539 6908790 : expr = build_converted_constant_bool_expr (expr, complain);
21540 6908790 : expr = instantiate_non_dependent_expr (expr, complain);
21541 6908790 : expr = cxx_constant_value (expr, complain);
21542 6908790 : return expr;
21543 : }
21544 :
21545 : #include "gt-cp-decl.h"
|