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 256262796 : current_tmpl_spec_kind (int n_class_scopes)
312 : {
313 256262796 : int n_template_parm_scopes = 0;
314 256262796 : int seen_specialization_p = 0;
315 256262796 : int innermost_specialization_p = 0;
316 256262796 : cp_binding_level *b;
317 :
318 : /* Scan through the template parameter scopes. */
319 256262796 : for (b = current_binding_level;
320 319635047 : b->kind == sk_template_parms;
321 63372251 : 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 63372251 : if (b->explicit_spec_p)
333 : {
334 1490597 : if (n_template_parm_scopes == 0)
335 : innermost_specialization_p = 1;
336 : else
337 1175 : seen_specialization_p = 1;
338 : }
339 61881654 : else if (seen_specialization_p == 1)
340 : return tsk_invalid_member_spec;
341 :
342 63372251 : ++n_template_parm_scopes;
343 : }
344 :
345 : /* Handle explicit instantiations. */
346 256262796 : if (processing_explicit_instantiation)
347 : {
348 2014295 : 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 2014295 : return tsk_expl_inst;
358 : }
359 :
360 254248501 : 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 254248501 : 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 55114085 : 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 109219551 : return innermost_specialization_p ? tsk_expl_spec : tsk_template;
394 : }
395 :
396 : /* Exit the current scope. */
397 :
398 : void
399 100524093 : finish_scope (void)
400 : {
401 100524093 : poplevel (0, 0, 0);
402 100524093 : }
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 20919 : check_label_used (tree label)
409 : {
410 20919 : if (!processing_template_decl)
411 : {
412 20610 : 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 20601 : warn_for_unused_label (label);
424 : }
425 20919 : }
426 :
427 : /* Helper function to sort named label entries in a vector by DECL_UID. */
428 :
429 : static int
430 235630 : sort_labels (const void *a, const void *b)
431 : {
432 235630 : tree label1 = *(tree const *) a;
433 235630 : tree label2 = *(tree const *) b;
434 :
435 : /* DECL_UIDs can never be equal. */
436 235630 : 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 165896868 : pop_labels (tree block)
508 : {
509 165896868 : if (!named_labels)
510 165892178 : 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 4690 : auto_vec<tree, 32> labels (named_labels->elements ());
518 4690 : hash_table<named_label_hash>::iterator end (named_labels->end ());
519 :
520 4690 : if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
521 711 : && !processing_template_decl)
522 : {
523 6410 : for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
524 : {
525 2528 : named_label_entry *ent = *iter;
526 2528 : 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 46462 : for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
537 : {
538 20886 : named_label_entry *ent = *iter;
539 :
540 20886 : gcc_checking_assert (!ent->outer);
541 20886 : if (ent->label_decl)
542 20700 : labels.quick_push (ent->label_decl);
543 20886 : ggc_free (ent);
544 : }
545 4690 : named_labels = NULL;
546 4690 : labels.qsort (sort_labels);
547 :
548 25390 : while (labels.length ())
549 : {
550 20700 : tree label = labels.pop ();
551 :
552 20700 : DECL_CHAIN (label) = BLOCK_VARS (block);
553 20700 : BLOCK_VARS (block) = label;
554 :
555 20700 : check_label_used (label);
556 : }
557 4690 : }
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 1726104 : level_for_constexpr_if (cp_binding_level *b)
618 : {
619 1722027 : return (b->kind == sk_cond && b->this_entity
620 296 : && TREE_CODE (b->this_entity) == IF_STMT
621 1726400 : && 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 1726080 : level_for_consteval_if (cp_binding_level *b)
628 : {
629 1722003 : return (b->kind == sk_cond && b->this_entity
630 272 : && TREE_CODE (b->this_entity) == IF_STMT
631 1726352 : && 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 156757 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
652 : {
653 156757 : named_label_entry *ent = *slot;
654 156757 : cp_binding_level *obl = bl->level_chain;
655 :
656 156757 : if (ent->binding_level == bl)
657 : {
658 10268 : tree decl;
659 :
660 : /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
661 : TREE_LISTs representing OVERLOADs, so be careful. */
662 15213 : for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
663 5018 : ? DECL_CHAIN (decl)
664 73 : : TREE_CHAIN (decl)))
665 4945 : if (decl_jump_unsafe (decl))
666 : {
667 1900 : vec_safe_push (ent->bad_decls, decl);
668 1900 : ent->has_bad_decls = true;
669 : }
670 3045 : else if (decl_instrument_init_bypass_p (decl))
671 440 : vec_safe_push (ent->bad_decls, decl);
672 :
673 10268 : ent->binding_level = obl;
674 10268 : ent->names_in_scope = obl->names;
675 10268 : 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 4122 : case sk_block:
693 4122 : if (level_for_constexpr_if (obl))
694 15 : ent->in_constexpr_if = true;
695 4107 : else if (level_for_consteval_if (obl))
696 30 : ent->in_consteval_if = true;
697 : break;
698 : default:
699 : break;
700 : }
701 : }
702 146489 : else if (ent->uses)
703 : {
704 : struct named_label_use_entry *use;
705 :
706 22857 : for (use = ent->uses; use ; use = use->next)
707 15533 : if (use->binding_level == bl)
708 : {
709 5985 : 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 5985 : use->binding_level = obl;
719 5985 : use->names_in_scope = obl->names;
720 5985 : if (bl->kind == sk_omp)
721 12 : use->in_omp_scope = true;
722 : }
723 : }
724 :
725 156757 : 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 696576077 : poplevel (int keep, int reverse, int functionbody)
749 : {
750 696576077 : tree link;
751 : /* The chain of decls was accumulated in reverse order.
752 : Put it into forward order, just for cleanliness. */
753 696576077 : tree decls;
754 696576077 : tree subblocks;
755 696576077 : tree block;
756 696576077 : tree decl;
757 696576077 : scope_kind kind;
758 :
759 696576077 : auto_cond_timevar tv (TV_NAME_LOOKUP);
760 696576407 : restart:
761 :
762 696576407 : block = NULL_TREE;
763 :
764 696576407 : gcc_assert (current_binding_level->kind != sk_class
765 : && current_binding_level->kind != sk_namespace);
766 :
767 696576407 : if (current_binding_level->kind == sk_cleanup)
768 : functionbody = 0;
769 696576407 : subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
770 :
771 696576407 : 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 696576407 : gcc_assert (keep == 0 || keep == 1);
777 :
778 696576407 : if (current_binding_level->keep)
779 8594358 : keep = 1;
780 :
781 : /* Any uses of undefined labels, and any defined labels, now operate
782 : under constraints of next binding contour. */
783 696576407 : if (cfun && !functionbody && named_labels)
784 43873 : named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
785 200630 : (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 696576407 : decls = current_binding_level->names;
792 696576407 : if (reverse)
793 : {
794 382188662 : decls = nreverse (decls);
795 382188662 : 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 696576407 : block = NULL_TREE;
802 : /* Avoid function body block if possible. */
803 738950513 : if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
804 : keep = 0;
805 654202565 : else if (keep == 1 || functionbody)
806 209234910 : block = make_node (BLOCK);
807 209234910 : if (block != NULL_TREE)
808 : {
809 209234910 : BLOCK_VARS (block) = decls;
810 209234910 : BLOCK_SUBBLOCKS (block) = subblocks;
811 : }
812 :
813 : /* In each subblock, record that this is its superior. */
814 696576407 : if (keep >= 0)
815 782287556 : for (link = subblocks; link; link = BLOCK_CHAIN (link))
816 85711149 : BLOCK_SUPERCONTEXT (link) = block;
817 :
818 : /* Before we remove the declarations first check for unused variables. */
819 696576407 : if ((warn_unused_variable || warn_unused_but_set_variable)
820 6730054 : && current_binding_level->kind != sk_template_parms
821 5671513 : && !processing_template_decl)
822 6488548 : 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 3288098 : tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
828 3288098 : decl = strip_using_decl (udecl);
829 :
830 3288098 : tree type = TREE_TYPE (decl);
831 3288098 : if (VAR_P (decl)
832 386756 : && (!TREE_USED (decl) || !DECL_READ_P (decl))
833 3611 : && !DECL_IN_SYSTEM_HEADER (udecl)
834 : /* For structured bindings, consider only real variables, not
835 : subobjects. */
836 3599 : && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
837 3376 : : (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 3292406 : && (!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 1408295422 : for (link = decls; link; link = TREE_CHAIN (link))
881 : {
882 711719015 : tree name;
883 711719015 : if (TREE_CODE (link) == TREE_LIST)
884 : {
885 13777907 : decl = TREE_VALUE (link);
886 13777907 : name = TREE_PURPOSE (link);
887 13777907 : gcc_checking_assert (name);
888 : }
889 : else
890 : {
891 697941108 : decl = link;
892 697941108 : name = DECL_NAME (decl);
893 : }
894 :
895 : /* Remove the binding. */
896 711719015 : if (TREE_CODE (decl) == LABEL_DECL)
897 219 : pop_local_label (name, decl);
898 : else
899 711718796 : pop_local_binding (name, decl);
900 : }
901 :
902 : /* Restore the IDENTIFIER_TYPE_VALUEs. */
903 696576407 : for (link = current_binding_level->type_shadowed;
904 949526018 : link; link = TREE_CHAIN (link))
905 252949611 : 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 696576407 : if (block)
915 : {
916 209234910 : tree* d;
917 :
918 551044926 : for (d = &BLOCK_VARS (block); *d; )
919 : {
920 341810016 : if (TREE_CODE (*d) == TREE_LIST
921 341810016 : || (!processing_template_decl
922 108207704 : && undeduced_auto_decl (*d)))
923 13777959 : *d = TREE_CHAIN (*d);
924 : else
925 328032057 : 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 696576407 : if (functionbody)
932 : {
933 165896868 : 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 123523026 : BLOCK_VARS (block) = 0;
939 123523026 : pop_labels (block);
940 : }
941 : else
942 42373842 : pop_labels (subblocks);
943 : }
944 :
945 696576407 : kind = current_binding_level->kind;
946 696576407 : if (kind == sk_cleanup)
947 : {
948 330 : 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 330 : stmt = pop_stmt_list (current_binding_level->statement_list);
954 330 : stmt = c_build_bind_expr (input_location, block, stmt);
955 330 : add_stmt (stmt);
956 : }
957 :
958 696576407 : leave_scope ();
959 696576407 : if (functionbody)
960 : {
961 : /* The current function is being defined, so its DECL_INITIAL
962 : should be error_mark_node. */
963 165896868 : gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
964 208270710 : DECL_INITIAL (current_function_decl) = block ? block : subblocks;
965 165896868 : if (subblocks)
966 : {
967 80601519 : if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
968 52624921 : && BLOCK_SUBBLOCKS (subblocks))
969 1377948 : BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
970 : else
971 40996158 : BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
972 : }
973 : }
974 530679539 : else if (block)
975 85711884 : current_binding_level->blocks
976 171423768 : = 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 444967655 : 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 696576407 : if (block)
991 209234910 : TREE_USED (block) = 1;
992 :
993 : /* All temporary bindings created for cleanups are popped silently. */
994 696576407 : if (kind == sk_cleanup)
995 330 : goto restart;
996 :
997 1393152154 : return block;
998 696576077 : }
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 147309 : wrapup_namespace_globals ()
1006 : {
1007 147309 : if (vec<tree, va_gc> *statics = static_decls)
1008 : {
1009 18160756 : for (tree decl : *statics)
1010 : {
1011 18039855 : if (warn_unused_function
1012 998714 : && TREE_CODE (decl) == FUNCTION_DECL
1013 749479 : && DECL_INITIAL (decl) == 0
1014 7591 : && DECL_EXTERNAL (decl)
1015 7579 : && !TREE_PUBLIC (decl)
1016 34 : && !DECL_ARTIFICIAL (decl)
1017 34 : && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
1018 9 : && !warning_suppressed_p (decl, OPT_Wunused)
1019 19038569 : && warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_function,
1020 : "%qF declared %<static%> but never defined",
1021 : decl))
1022 6 : suppress_warning (decl, OPT_Wunused);
1023 :
1024 18039855 : if (VAR_P (decl)
1025 5959764 : && DECL_EXTERNAL (decl)
1026 : /* We mark consteval-only variables DECL_EXTERNAL, but
1027 : extern constexpr inline std::meta::info i{};
1028 : is a definition (the extern is redundant). */
1029 2046575 : && !DECL_INITIAL (decl)
1030 2045184 : && DECL_INLINE_VAR_P (decl)
1031 18039884 : && DECL_ODR_USED (decl))
1032 3 : error_at (DECL_SOURCE_LOCATION (decl),
1033 : "odr-used inline variable %qD is not defined", decl);
1034 : }
1035 :
1036 : /* Clear out the list, so we don't rescan next time. */
1037 120901 : static_decls = NULL;
1038 :
1039 : /* Write out any globals that need to be output. */
1040 120901 : return wrapup_global_declarations (statics->address (),
1041 120901 : statics->length ());
1042 : }
1043 : return 0;
1044 : }
1045 :
1046 : /* In C++, you don't have to write `struct S' to refer to `S'; you
1047 : can just use `S'. We accomplish this by creating a TYPE_DECL as
1048 : if the user had written `typedef struct S S'. Create and return
1049 : the TYPE_DECL for TYPE. */
1050 :
1051 : tree
1052 187181726 : create_implicit_typedef (tree name, tree type)
1053 : {
1054 187181726 : tree decl;
1055 :
1056 187181726 : decl = build_decl (input_location, TYPE_DECL, name, type);
1057 187181726 : DECL_ARTIFICIAL (decl) = 1;
1058 : /* There are other implicit type declarations, like the one *within*
1059 : a class that allows you to write `S::S'. We must distinguish
1060 : amongst these. */
1061 187181726 : SET_DECL_IMPLICIT_TYPEDEF_P (decl);
1062 187181726 : TYPE_NAME (type) = decl;
1063 187181726 : TYPE_STUB_DECL (type) = decl;
1064 :
1065 187181726 : return decl;
1066 : }
1067 :
1068 : /* Function-scope local entities that need discriminators. Each entry
1069 : is a {decl,name} pair. VAR_DECLs for anon unions get their name
1070 : smashed, so we cannot rely on DECL_NAME. */
1071 :
1072 : static GTY((deletable)) vec<tree, va_gc> *local_entities;
1073 :
1074 : /* Determine the mangling discriminator of local DECL. There are
1075 : generally very few of these in any particular function. */
1076 :
1077 : void
1078 754900 : determine_local_discriminator (tree decl, tree name)
1079 : {
1080 754900 : auto_cond_timevar tv (TV_NAME_LOOKUP);
1081 754900 : retrofit_lang_decl (decl);
1082 754900 : tree ctx = DECL_CONTEXT (decl);
1083 754900 : size_t nelts = vec_safe_length (local_entities);
1084 754900 : if (name == NULL_TREE)
1085 754633 : name = (TREE_CODE (decl) == TYPE_DECL
1086 1230554 : && TYPE_UNNAMED_P (TREE_TYPE (decl))
1087 1365881 : ? NULL_TREE : DECL_NAME (decl));
1088 22140835 : for (size_t i = 0; i < nelts; i += 2)
1089 : {
1090 21386609 : tree *pair = &(*local_entities)[i];
1091 21386609 : tree d = pair[0];
1092 21386609 : tree n = pair[1];
1093 21386609 : gcc_checking_assert (d != decl);
1094 21386609 : if (name == n
1095 3792298 : && TREE_CODE (decl) == TREE_CODE (d)
1096 25178898 : && ctx == DECL_CONTEXT (d))
1097 : {
1098 674 : tree disc = integer_one_node;
1099 674 : if (DECL_DISCRIMINATOR (d))
1100 372 : disc = build_int_cst (TREE_TYPE (disc),
1101 372 : TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
1102 674 : DECL_DISCRIMINATOR (decl) = disc;
1103 : /* Replace the saved decl. */
1104 674 : pair[0] = decl;
1105 674 : decl = NULL_TREE;
1106 674 : break;
1107 : }
1108 : }
1109 :
1110 754900 : if (decl)
1111 : {
1112 754226 : vec_safe_reserve (local_entities, 2);
1113 754226 : local_entities->quick_push (decl);
1114 754226 : local_entities->quick_push (name);
1115 : }
1116 754900 : }
1117 :
1118 :
1119 : /* True if DECL is a constrained hidden friend as per [temp.friend]/9:
1120 :
1121 : A non-template friend declaration with a requires-clause shall be a
1122 : definition. A friend function template with a constraint that depends on a
1123 : template parameter from an enclosing template shall be a definition. Such a
1124 : constrained friend function or function template declaration does not
1125 : declare the same function or function template as a declaration in any other
1126 : scope.
1127 :
1128 : The ABI calls this a "member-like constrained friend" and mangles it like a
1129 : member function to avoid collisions. */
1130 :
1131 : bool
1132 2565399225 : member_like_constrained_friend_p (tree decl)
1133 : {
1134 2565399225 : return (TREE_CODE (decl) == FUNCTION_DECL
1135 878529676 : && DECL_UNIQUE_FRIEND_P (decl)
1136 292647554 : && DECL_FRIEND_CONTEXT (decl)
1137 128689566 : && get_constraints (decl)
1138 18716854 : && CLASSTYPE_IMPLICIT_INSTANTIATION (DECL_FRIEND_CONTEXT (decl))
1139 2574735806 : && (!DECL_TEMPLATE_INFO (decl)
1140 9336581 : || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
1141 8549 : || (uses_outer_template_parms_in_constraints
1142 8549 : (most_general_template (decl)))));
1143 : }
1144 :
1145 : /* Returns true if functions FN1 and FN2 have equivalent trailing
1146 : requires clauses. */
1147 :
1148 : static bool
1149 69370650 : function_requirements_equivalent_p (tree newfn, tree oldfn)
1150 : {
1151 : /* [temp.friend]/9 "Such a constrained friend function does not declare the
1152 : same function as a declaration in any other scope." So no need to
1153 : actually compare the requirements. */
1154 69370650 : if (member_like_constrained_friend_p (newfn)
1155 69370650 : || member_like_constrained_friend_p (oldfn))
1156 121 : return false;
1157 :
1158 : /* Compare only trailing requirements. */
1159 69370529 : tree reqs1 = get_trailing_function_requirements (newfn);
1160 69370529 : tree reqs2 = get_trailing_function_requirements (oldfn);
1161 69370529 : if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
1162 : return false;
1163 :
1164 : /* Substitution is needed when friends are involved. */
1165 69235783 : reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
1166 69235783 : reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
1167 :
1168 69235783 : return cp_tree_equal (reqs1, reqs2);
1169 : }
1170 :
1171 : /* Two functions of the same name correspond [basic.scope.scope] if
1172 :
1173 : + both declare functions with the same non-object-parameter-type-list,
1174 : equivalent ([temp.over.link]) trailing requires-clauses (if any, except as
1175 : specified in [temp.friend]), and, if both are non-static members, they have
1176 : corresponding object parameters, or
1177 :
1178 : + both declare function templates with equivalent
1179 : non-object-parameter-type-lists, return types (if any), template-heads, and
1180 : trailing requires-clauses (if any), and, if both are non-static members,
1181 : they have corresponding object parameters.
1182 :
1183 : This is a subset of decls_match: it identifies declarations that cannot be
1184 : overloaded with one another. This function does not consider DECL_NAME. */
1185 :
1186 : bool
1187 1476768010 : fns_correspond (tree newdecl, tree olddecl)
1188 : {
1189 1476768010 : if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
1190 : return false;
1191 :
1192 1372200119 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1193 : {
1194 1370843024 : if (!template_heads_equivalent_p (newdecl, olddecl))
1195 : return 0;
1196 325419083 : newdecl = DECL_TEMPLATE_RESULT (newdecl);
1197 325419083 : olddecl = DECL_TEMPLATE_RESULT (olddecl);
1198 : }
1199 :
1200 326776178 : tree f1 = TREE_TYPE (newdecl);
1201 326776178 : tree f2 = TREE_TYPE (olddecl);
1202 :
1203 326776178 : int rq1 = type_memfn_rqual (f1);
1204 326776178 : int rq2 = type_memfn_rqual (f2);
1205 :
1206 : /* If only one is a non-static member function, ignore ref-quals. */
1207 326776178 : if (TREE_CODE (f1) != TREE_CODE (f2))
1208 : rq1 = rq2;
1209 : /* Two non-static member functions have corresponding object parameters if:
1210 : + exactly one is an implicit object member function with no ref-qualifier
1211 : and the types of their object parameters ([dcl.fct]), after removing
1212 : top-level references, are the same, or
1213 : + their object parameters have the same type. */
1214 : /* ??? We treat member functions of different classes as corresponding even
1215 : though that means the object parameters have different types. */
1216 326776178 : else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
1217 0 : rq1 = rq2;
1218 :
1219 326776178 : bool types_match = rq1 == rq2;
1220 :
1221 326776178 : if (types_match)
1222 : {
1223 326776178 : tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1224 326776178 : tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
1225 326776178 : types_match = compparms (p1, p2);
1226 : }
1227 :
1228 : /* Two function declarations match if either has a requires-clause
1229 : then both have a requires-clause and their constraints-expressions
1230 : are equivalent. */
1231 326776178 : if (types_match && flag_concepts)
1232 40365968 : types_match = function_requirements_equivalent_p (newdecl, olddecl);
1233 :
1234 : return types_match;
1235 : }
1236 :
1237 : /* Subroutine of duplicate_decls: return truthvalue of whether
1238 : or not types of these decls match.
1239 :
1240 : For C++, we must compare the parameter list so that `int' can match
1241 : `int&' in a parameter position, but `int&' is not confused with
1242 : `const int&'. */
1243 :
1244 : int
1245 865949781 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
1246 : {
1247 865949781 : int types_match;
1248 :
1249 865949781 : if (newdecl == olddecl)
1250 : return 1;
1251 :
1252 865832683 : if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
1253 : /* If the two DECLs are not even the same kind of thing, we're not
1254 : interested in their types. */
1255 : return 0;
1256 :
1257 456698752 : gcc_assert (DECL_P (newdecl));
1258 :
1259 456698752 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
1260 : {
1261 : /* Specializations of different templates are different functions
1262 : even if they have the same type. */
1263 301746742 : tree t1 = (DECL_USE_TEMPLATE (newdecl)
1264 301746742 : ? DECL_TI_TEMPLATE (newdecl)
1265 650811 : : NULL_TREE);
1266 301746742 : tree t2 = (DECL_USE_TEMPLATE (olddecl)
1267 301746742 : ? DECL_TI_TEMPLATE (olddecl)
1268 4144402 : : NULL_TREE);
1269 301746742 : if (t1 != t2)
1270 : return 0;
1271 :
1272 298253068 : if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1273 301248166 : && ! (DECL_EXTERN_C_P (newdecl)
1274 2995098 : && DECL_EXTERN_C_P (olddecl)))
1275 : return 0;
1276 :
1277 : /* A new declaration doesn't match a built-in one unless it
1278 : is also extern "C". */
1279 276465536 : if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
1280 276465536 : && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
1281 : return 0;
1282 :
1283 275805514 : tree f1 = TREE_TYPE (newdecl);
1284 275805514 : tree f2 = TREE_TYPE (olddecl);
1285 275805514 : if (TREE_CODE (f1) != TREE_CODE (f2))
1286 : return 0;
1287 :
1288 : /* A declaration with deduced return type should use its pre-deduction
1289 : type for declaration matching. */
1290 275627650 : tree r2 = fndecl_declared_return_type (olddecl);
1291 275627650 : tree r1 = fndecl_declared_return_type (newdecl);
1292 :
1293 : /* For memchr et al, allow const void* return type (as specified by C++)
1294 : when we expect void* (as in C). */
1295 275627650 : if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
1296 6641137 : && DECL_EXTERN_C_P (olddecl)
1297 4082376 : && !same_type_p (r1, r2)
1298 70 : && TREE_CODE (r1) == POINTER_TYPE
1299 15 : && TREE_CODE (r2) == POINTER_TYPE
1300 275627662 : && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
1301 : r2 = r1;
1302 :
1303 275627650 : tree p1 = TYPE_ARG_TYPES (f1);
1304 275627650 : tree p2 = TYPE_ARG_TYPES (f2);
1305 :
1306 275627650 : if (same_type_p (r1, r2))
1307 : {
1308 176488641 : if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
1309 176488613 : && fndecl_built_in_p (olddecl))
1310 : {
1311 50 : types_match = self_promoting_args_p (p1);
1312 50 : if (p1 == void_list_node)
1313 3 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl);
1314 : }
1315 : else
1316 176488507 : types_match =
1317 176488507 : compparms (p1, p2)
1318 29492132 : && type_memfn_rqual (f1) == type_memfn_rqual (f2)
1319 205980243 : && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
1320 1255297 : || comp_type_attributes (TREE_TYPE (newdecl),
1321 1255297 : TREE_TYPE (olddecl)) != 0);
1322 : }
1323 : else
1324 : types_match = 0;
1325 :
1326 : /* Two function declarations match if either has a requires-clause
1327 : then both have a requires-clause and their constraints-expressions
1328 : are equivalent. */
1329 29491765 : if (types_match && flag_concepts)
1330 29004650 : types_match = function_requirements_equivalent_p (newdecl, olddecl);
1331 :
1332 : /* The decls dont match if they correspond to two different versions
1333 : of the same function. Disallow extern "C" functions to be
1334 : versions for now. */
1335 29491765 : if (types_match
1336 29290214 : && !DECL_EXTERN_C_P (newdecl)
1337 21392573 : && !DECL_EXTERN_C_P (olddecl)
1338 50880504 : && disjoint_version_decls (newdecl, olddecl))
1339 : {
1340 8880 : if (record_versions)
1341 8793 : maybe_version_functions (newdecl, olddecl);
1342 8880 : return 0;
1343 : }
1344 : }
1345 154952010 : else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1346 : {
1347 153168580 : if (!template_heads_equivalent_p (newdecl, olddecl))
1348 : return 0;
1349 :
1350 50079299 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1351 50079299 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
1352 :
1353 50079299 : if (TREE_CODE (newres) != TREE_CODE (oldres))
1354 : return 0;
1355 :
1356 : /* Two template types match if they are the same. Otherwise, compare
1357 : the underlying declarations. */
1358 50079293 : if (TREE_CODE (newres) == TYPE_DECL)
1359 30 : types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
1360 : else
1361 50079263 : types_match = decls_match (newres, oldres);
1362 : }
1363 : else
1364 : {
1365 : /* Need to check scope for variable declaration (VAR_DECL).
1366 : For typedef (TYPE_DECL), scope is ignored. */
1367 1783430 : if (VAR_P (newdecl)
1368 1216679 : && CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1369 : /* [dcl.link]
1370 : Two declarations for an object with C language linkage
1371 : with the same name (ignoring the namespace that qualify
1372 : it) that appear in different namespace scopes refer to
1373 : the same object. */
1374 1974895 : && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
1375 : return 0;
1376 :
1377 1592013 : if (TREE_TYPE (newdecl) == error_mark_node)
1378 0 : types_match = TREE_TYPE (olddecl) == error_mark_node;
1379 1592013 : else if (TREE_TYPE (olddecl) == NULL_TREE)
1380 0 : types_match = TREE_TYPE (newdecl) == NULL_TREE;
1381 1592013 : else if (TREE_TYPE (newdecl) == NULL_TREE)
1382 : types_match = 0;
1383 : else
1384 1592013 : types_match = comptypes (TREE_TYPE (newdecl),
1385 1592013 : TREE_TYPE (olddecl),
1386 : COMPARE_REDECLARATION);
1387 : }
1388 :
1389 : return types_match;
1390 : }
1391 :
1392 : /* Mark DECL as versioned if it isn't already. */
1393 :
1394 : void
1395 17676 : maybe_mark_function_versioned (tree decl)
1396 : {
1397 17676 : if (!DECL_FUNCTION_VERSIONED (decl))
1398 : {
1399 : /* We need to insert function version now to make sure the correct
1400 : pre-mangled assembler name is recorded. */
1401 1068 : cgraph_node *node = cgraph_node::get_create (decl);
1402 :
1403 1068 : if (!node->function_version ())
1404 1068 : node->insert_new_function_version ();
1405 :
1406 1068 : DECL_FUNCTION_VERSIONED (decl) = 1;
1407 : /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
1408 : to include the version marker. */
1409 1068 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
1410 1062 : mangle_decl (decl);
1411 : }
1412 17676 : }
1413 :
1414 : /* NEWDECL and OLDDECL have identical signatures. If they are
1415 : different versions adjust them, record function versions, and return
1416 : true. */
1417 :
1418 : bool
1419 206840 : maybe_version_functions (tree newdecl, tree olddecl)
1420 : {
1421 206840 : if (!disjoint_version_decls (newdecl, olddecl))
1422 : return false;
1423 :
1424 8820 : maybe_mark_function_versioned (olddecl);
1425 8820 : if (DECL_LOCAL_DECL_P (olddecl))
1426 : {
1427 18 : olddecl = DECL_LOCAL_DECL_ALIAS (olddecl);
1428 18 : maybe_mark_function_versioned (olddecl);
1429 : }
1430 :
1431 8820 : maybe_mark_function_versioned (newdecl);
1432 8820 : if (DECL_LOCAL_DECL_P (newdecl))
1433 : {
1434 : /* Unfortunately, we can get here before pushdecl naturally calls
1435 : push_local_extern_decl_alias, so we need to call it directly. */
1436 18 : if (!DECL_LOCAL_DECL_ALIAS (newdecl))
1437 6 : push_local_extern_decl_alias (newdecl);
1438 18 : newdecl = DECL_LOCAL_DECL_ALIAS (newdecl);
1439 18 : maybe_mark_function_versioned (newdecl);
1440 : }
1441 :
1442 : /* Add the new version to the function version structure. */
1443 8820 : cgraph_node *fn_node = cgraph_node::get_create (olddecl);
1444 8820 : cgraph_function_version_info *fn_v = fn_node->function_version ();
1445 8820 : if (!fn_v)
1446 15 : fn_v = fn_node->insert_new_function_version ();
1447 :
1448 8820 : cgraph_node::add_function_version (fn_v, newdecl);
1449 :
1450 8820 : return true;
1451 : }
1452 :
1453 : /* If NEWDECL is `static' and an `extern' was seen previously,
1454 : warn about it. OLDDECL is the previous declaration.
1455 :
1456 : Note that this does not apply to the C++ case of declaring
1457 : a variable `extern const' and then later `const'.
1458 :
1459 : Don't complain about built-in functions, since they are beyond
1460 : the user's control. */
1461 :
1462 : void
1463 20070391 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
1464 : {
1465 20070391 : if (TREE_CODE (newdecl) == TYPE_DECL
1466 20020746 : || TREE_CODE (newdecl) == TEMPLATE_DECL
1467 15919188 : || TREE_CODE (newdecl) == CONST_DECL
1468 15919188 : || TREE_CODE (newdecl) == NAMESPACE_DECL)
1469 20070379 : return;
1470 :
1471 : /* Don't get confused by static member functions; that's a different
1472 : use of `static'. */
1473 15919188 : if (TREE_CODE (newdecl) == FUNCTION_DECL
1474 15919188 : && DECL_STATIC_FUNCTION_P (newdecl))
1475 : return;
1476 :
1477 : /* If the old declaration was `static', or the new one isn't, then
1478 : everything is OK. */
1479 15740995 : if (DECL_THIS_STATIC (olddecl) || !DECL_THIS_STATIC (newdecl))
1480 : return;
1481 :
1482 : /* It's OK to declare a builtin function as `static'. */
1483 12 : if (TREE_CODE (olddecl) == FUNCTION_DECL
1484 12 : && DECL_ARTIFICIAL (olddecl))
1485 : return;
1486 :
1487 12 : auto_diagnostic_group d;
1488 12 : if (permerror (DECL_SOURCE_LOCATION (newdecl),
1489 : "%qD was declared %<extern%> and later %<static%>", newdecl))
1490 12 : inform (DECL_SOURCE_LOCATION (olddecl),
1491 : "previous declaration of %qD", olddecl);
1492 12 : }
1493 :
1494 : /* NEW_DECL is a redeclaration of OLD_DECL; both are functions or
1495 : function templates. If their exception specifications do not
1496 : match, issue a diagnostic. */
1497 :
1498 : static void
1499 19508745 : check_redeclaration_exception_specification (tree new_decl,
1500 : tree old_decl)
1501 : {
1502 19508745 : tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
1503 19508745 : tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
1504 :
1505 : /* Two default specs are equivalent, don't force evaluation. */
1506 7450262 : if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
1507 19655073 : && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
1508 : return;
1509 :
1510 19498827 : if (!type_dependent_expression_p (old_decl))
1511 : {
1512 11916209 : maybe_instantiate_noexcept (new_decl);
1513 11916209 : maybe_instantiate_noexcept (old_decl);
1514 : }
1515 19498827 : new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
1516 19498827 : old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
1517 :
1518 : /* [except.spec]
1519 :
1520 : If any declaration of a function has an exception-specification,
1521 : all declarations, including the definition and an explicit
1522 : specialization, of that function shall have an
1523 : exception-specification with the same set of type-ids. */
1524 19498827 : if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
1525 15540075 : && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
1526 35038797 : && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
1527 : {
1528 329 : const char *const msg
1529 : = G_("declaration of %qF has a different exception specifier");
1530 329 : bool complained = true;
1531 329 : location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
1532 329 : auto_diagnostic_group d;
1533 :
1534 : /* Be permissive about C++98 vs C++11 operator new declarations. */
1535 658 : bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
1536 1 : && CP_DECL_CONTEXT (new_decl) == global_namespace
1537 331 : && (nothrow_spec_p (new_exceptions)
1538 1 : == nothrow_spec_p (old_exceptions)));
1539 :
1540 329 : if (DECL_IN_SYSTEM_HEADER (old_decl)
1541 329 : && (global_new || DECL_EXTERN_C_P (old_decl)))
1542 : /* Don't fuss about the C library; the C library functions are not
1543 : specified to have exception specifications (just behave as if they
1544 : have them), but some implementations include them. */
1545 233 : complained = pedwarn (new_loc, OPT_Wsystem_headers, msg, new_decl);
1546 96 : else if (!flag_exceptions)
1547 : /* We used to silently permit mismatched eh specs with
1548 : -fno-exceptions, so only complain if -pedantic. */
1549 3 : complained = pedwarn (new_loc, OPT_Wpedantic, msg, new_decl);
1550 93 : else if (!new_exceptions || global_new)
1551 : /* Reduce to pedwarn for omitted exception specification. No warning
1552 : flag for this; silence the warning by correcting the code. */
1553 18 : complained = pedwarn (new_loc, 0, msg, new_decl);
1554 : else
1555 75 : error_at (new_loc, msg, new_decl);
1556 :
1557 329 : if (complained)
1558 99 : inform (DECL_SOURCE_LOCATION (old_decl),
1559 : "from previous declaration %qF", old_decl);
1560 :
1561 : /* Copy the old exception specification if new_decl has none. Unless the
1562 : old decl is extern "C", as obscure code might depend on the type of
1563 : the new declaration (e.g. noexcept-type19.C). */
1564 329 : if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
1565 17 : TREE_TYPE (new_decl)
1566 34 : = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
1567 329 : }
1568 : }
1569 :
1570 : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
1571 : Otherwise issue diagnostics. */
1572 :
1573 : bool
1574 20070917 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
1575 : {
1576 20070917 : old_decl = STRIP_TEMPLATE (old_decl);
1577 20070917 : new_decl = STRIP_TEMPLATE (new_decl);
1578 20070917 : if (!VAR_OR_FUNCTION_DECL_P (old_decl)
1579 20021248 : || !VAR_OR_FUNCTION_DECL_P (new_decl))
1580 : return true;
1581 20021248 : if (DECL_DECLARED_CONSTEXPR_P (old_decl)
1582 20021248 : == DECL_DECLARED_CONSTEXPR_P (new_decl))
1583 : {
1584 19869631 : if (TREE_CODE (old_decl) != FUNCTION_DECL)
1585 : return true;
1586 39018320 : if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1587 19509160 : == DECL_IMMEDIATE_FUNCTION_P (new_decl))
1588 : return true;
1589 : }
1590 151623 : if (TREE_CODE (old_decl) == FUNCTION_DECL)
1591 : {
1592 : /* With -fimplicit-constexpr, ignore changes in the constexpr
1593 : keyword. */
1594 71 : if (flag_implicit_constexpr
1595 71 : && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
1596 0 : == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
1597 : return true;
1598 71 : if (fndecl_built_in_p (old_decl))
1599 : {
1600 : /* Hide a built-in declaration. */
1601 0 : DECL_DECLARED_CONSTEXPR_P (old_decl)
1602 0 : = DECL_DECLARED_CONSTEXPR_P (new_decl);
1603 0 : if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
1604 0 : SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
1605 0 : return true;
1606 : }
1607 : /* 7.1.5 [dcl.constexpr]
1608 : Note: An explicit specialization can differ from the template
1609 : declaration with respect to the constexpr specifier. */
1610 71 : if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
1611 71 : && DECL_TEMPLATE_SPECIALIZATION (new_decl))
1612 : return true;
1613 :
1614 42 : const char *kind = "constexpr";
1615 42 : if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1616 72 : || DECL_IMMEDIATE_FUNCTION_P (new_decl))
1617 : kind = "consteval";
1618 42 : auto_diagnostic_group d;
1619 42 : error_at (DECL_SOURCE_LOCATION (new_decl),
1620 : "redeclaration %qD differs in %qs "
1621 : "from previous declaration", new_decl,
1622 : kind);
1623 42 : inform (DECL_SOURCE_LOCATION (old_decl),
1624 : "previous declaration %qD", old_decl);
1625 42 : return false;
1626 42 : }
1627 : return true;
1628 : }
1629 :
1630 : /* DECL is a redeclaration of a function or function template. If
1631 : it does have default arguments issue a diagnostic. Note: this
1632 : function is used to enforce the requirements in C++11 8.3.6 about
1633 : no default arguments in redeclarations. */
1634 :
1635 : static void
1636 11759504 : check_redeclaration_no_default_args (tree decl)
1637 : {
1638 11759504 : gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
1639 :
1640 11759504 : for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
1641 34611827 : t && t != void_list_node; t = TREE_CHAIN (t))
1642 22852380 : if (TREE_PURPOSE (t))
1643 : {
1644 57 : permerror (DECL_SOURCE_LOCATION (decl),
1645 : "redeclaration of %q#D may not have default "
1646 : "arguments", decl);
1647 57 : return;
1648 : }
1649 : }
1650 :
1651 : /* NEWDECL is a redeclaration of a function or function template OLDDECL,
1652 : in any case represented as FUNCTION_DECLs (the DECL_TEMPLATE_RESULTs of
1653 : the TEMPLATE_DECLs in case of function templates). This function is used
1654 : to enforce the final part of C++17 11.3.6/4, about a single declaration:
1655 : "If a friend declaration specifies a default argument expression, that
1656 : declaration shall be a definition and shall be the only declaration of
1657 : the function or function template in the translation unit." */
1658 :
1659 : static void
1660 7195941 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
1661 : {
1662 13674171 : if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
1663 : return;
1664 :
1665 3697782 : for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
1666 1848891 : t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1667 4889375 : t1 && t1 != void_list_node;
1668 3040484 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1669 4323031 : if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
1670 8676009 : || (DECL_UNIQUE_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
1671 : {
1672 36 : auto_diagnostic_group d;
1673 36 : if (permerror (DECL_SOURCE_LOCATION (newdecl),
1674 : "friend declaration of %q#D specifies default "
1675 : "arguments and isn%'t the only declaration", newdecl))
1676 36 : inform (DECL_SOURCE_LOCATION (olddecl),
1677 : "previous declaration of %q#D", olddecl);
1678 36 : return;
1679 36 : }
1680 : }
1681 :
1682 : /* Merge tree bits that correspond to attributes noreturn, nothrow,
1683 : const, malloc, and pure from NEWDECL with those of OLDDECL. */
1684 :
1685 : static void
1686 18940939 : merge_attribute_bits (tree newdecl, tree olddecl)
1687 : {
1688 18940939 : TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1689 18940939 : TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
1690 18940939 : TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
1691 18940939 : TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
1692 18940939 : TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1693 18940939 : TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
1694 18940939 : DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1695 18940939 : DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
1696 18940939 : DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1697 18940939 : DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
1698 18940939 : DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
1699 18940939 : DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
1700 18940939 : TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
1701 18940939 : TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
1702 18940939 : TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
1703 18940939 : TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
1704 18940939 : }
1705 :
1706 : #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn) \
1707 : && lookup_attribute ("gnu_inline", \
1708 : DECL_ATTRIBUTES (fn)))
1709 :
1710 : /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
1711 : ambiguates olddecl. Returns true if an error occurs. */
1712 :
1713 : static bool
1714 149066866 : duplicate_function_template_decls (tree newdecl, tree olddecl)
1715 : {
1716 149066866 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
1717 149066866 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1718 : /* Function template declarations can be differentiated by parameter
1719 : and return type. */
1720 149066866 : if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
1721 149066866 : TYPE_ARG_TYPES (TREE_TYPE (newres)))
1722 149066866 : && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
1723 : TREE_TYPE (TREE_TYPE (olddecl))))
1724 : {
1725 : /* ... and also by their template-heads and requires-clauses. */
1726 7311 : if (template_heads_equivalent_p (newdecl, olddecl)
1727 7311 : && function_requirements_equivalent_p (newres, oldres))
1728 : {
1729 0 : auto_diagnostic_group d;
1730 0 : error ("ambiguating new declaration %q+#D", newdecl);
1731 0 : inform (DECL_SOURCE_LOCATION (olddecl),
1732 : "old declaration %q#D", olddecl);
1733 0 : return true;
1734 0 : }
1735 :
1736 : /* FIXME: The types are the same but the are differences
1737 : in either the template heads or function requirements.
1738 : We should be able to diagnose a set of common errors
1739 : stemming from these declarations. For example:
1740 :
1741 : template<typename T> requires C void f(...);
1742 : template<typename T> void f(...) requires C;
1743 :
1744 : These are functionally equivalent but not equivalent. */
1745 : }
1746 :
1747 : return false;
1748 : }
1749 :
1750 : /* OLD_PARMS is the innermost set of template parameters for some template
1751 : declaration, and NEW_PARMS is the corresponding set of template parameters
1752 : for a redeclaration of that template. Merge the default arguments within
1753 : these two sets of parameters. CLASS_P is true iff the template in
1754 : question is a class template. */
1755 :
1756 : bool
1757 9101479 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
1758 : {
1759 9101479 : gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
1760 : == TREE_VEC_LENGTH (old_parms));
1761 25748620 : for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
1762 : {
1763 16647171 : tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
1764 16647171 : tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
1765 16647171 : tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
1766 16647171 : tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
1767 16647171 : if (error_operand_p (new_parm) || error_operand_p (old_parm))
1768 : return false;
1769 16647168 : if (new_default != NULL_TREE && old_default != NULL_TREE)
1770 : {
1771 27 : auto_diagnostic_group d;
1772 27 : error ("redefinition of default argument for %q+#D", new_parm);
1773 27 : inform (DECL_SOURCE_LOCATION (old_parm),
1774 : "original definition appeared here");
1775 27 : return false;
1776 27 : }
1777 16647141 : else if (new_default != NULL_TREE)
1778 : /* Update the previous template parameters (which are the ones
1779 : that will really count) with the new default value. */
1780 236773 : old_default = new_default;
1781 16410368 : else if (class_p && old_default != NULL_TREE)
1782 : /* Update the new parameters, too; they'll be used as the
1783 : parameters for any members. */
1784 1021195 : new_default = old_default;
1785 : }
1786 : return true;
1787 : }
1788 :
1789 : /* Helper function for duplicate_decls and push_local_extern_decl_alias.
1790 : Merge parameter attributes and names between NEWDECL and OLDDECL.
1791 : NEW_DEFINES_FUNCTION and TYPES_MATCH argument like variables in
1792 : duplicate_decls, EXTERN_ALIAS false for duplicate_decls and true for
1793 : push_local_extern_decl_alias. */
1794 :
1795 : void
1796 15407631 : merge_decl_arguments (tree newdecl, tree olddecl, bool new_defines_function,
1797 : bool types_match, bool extern_alias)
1798 : {
1799 15407631 : tree oldarg, newarg, type = NULL_TREE;
1800 15407631 : tree first_user_parm = NULL_TREE;
1801 15407631 : if (extern_alias)
1802 189 : first_user_parm = FUNCTION_FIRST_USER_PARM (newdecl);
1803 15407631 : for (oldarg = DECL_ARGUMENTS (olddecl), newarg = DECL_ARGUMENTS (newdecl);
1804 43152451 : oldarg && newarg;
1805 27744820 : oldarg = DECL_CHAIN (oldarg), newarg = DECL_CHAIN (newarg))
1806 : {
1807 27744820 : DECL_ATTRIBUTES (newarg)
1808 27744820 : = (*targetm.merge_decl_attributes) (oldarg, newarg);
1809 27744820 : if (lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (newarg))
1810 27744889 : && !lookup_attribute (NULL, "indeterminate",
1811 69 : DECL_ATTRIBUTES (oldarg)))
1812 : {
1813 18 : auto_diagnostic_group d;
1814 18 : error_at (DECL_SOURCE_LOCATION (newarg),
1815 : "%<indeterminate%> attribute not specified for parameter "
1816 : "%qD on the first declaration of its function", newarg);
1817 18 : inform (DECL_SOURCE_LOCATION (oldarg), "earlier declaration");
1818 18 : }
1819 : /* ??? Should attributes propagate out from a block extern? If so,
1820 : we should do that for the function itself, not just parameters. */
1821 27744820 : if (!extern_alias || flag_reflection)
1822 27744653 : DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1823 27744820 : if (!flag_reflection)
1824 27351054 : continue;
1825 : /* For extern_alias set DECL_HAS_DEFAULT_ARGUMENT_P on oldarg
1826 : if the local extern has a default argument for that parameter. */
1827 393766 : if (extern_alias)
1828 : {
1829 36 : if (newarg == first_user_parm)
1830 12 : type = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1831 24 : else if (type)
1832 24 : type = TREE_CHAIN (type);
1833 72 : if (type && TREE_PURPOSE (type))
1834 4 : DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
1835 : }
1836 : else
1837 : {
1838 : /* Otherwise propagate the flag. */
1839 393730 : if (DECL_HAS_DEFAULT_ARGUMENT_P (oldarg))
1840 0 : DECL_HAS_DEFAULT_ARGUMENT_P (newarg) = 1;
1841 393730 : if (DECL_HAS_DEFAULT_ARGUMENT_P (newarg))
1842 0 : DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
1843 : }
1844 : /* Merge names for std::meta::has_identifier and
1845 : std::meta::{,u8}identifier_of purposes. If they are different and
1846 : both oldarg and newarg are named, add flag to force that
1847 : std::meta::has_identifier returns false. If one is named and one is
1848 : unnamed, if neither is a olddecl nor newdecl is definition, propagate
1849 : DECL_NAME to both. Otherwise stash the old name into "old parm name"
1850 : artificial attribute. */
1851 393766 : if (DECL_NAME (oldarg) != DECL_NAME (newarg))
1852 : {
1853 43568 : if (DECL_NAME (oldarg) && DECL_NAME (newarg))
1854 : {
1855 : /* Different names. */
1856 9872 : MULTIPLE_NAMES_PARM_P (oldarg) = 1;
1857 9872 : MULTIPLE_NAMES_PARM_P (newarg) = 1;
1858 : }
1859 33696 : else if (!new_defines_function
1860 33696 : && types_match
1861 33696 : && DECL_INITIAL (olddecl) == NULL_TREE)
1862 : {
1863 : /* For 2 non-definitions with matching types, one is named and
1864 : one unnamed, propagate name to both. */
1865 6422 : if (DECL_NAME (oldarg))
1866 5418 : DECL_NAME (newarg) = DECL_NAME (oldarg);
1867 : else
1868 1004 : DECL_NAME (oldarg) = DECL_NAME (newarg);
1869 : }
1870 : /* Depending on which PARM_DECL we'll keep, look at the other
1871 : PARM_DECL's name. */
1872 27274 : else if (tree name = ((new_defines_function || !types_match)
1873 27274 : ? DECL_NAME (oldarg) : DECL_NAME (newarg)))
1874 : {
1875 216 : tree opn = lookup_attribute ("old parm name",
1876 216 : DECL_ATTRIBUTES (oldarg));
1877 216 : if (opn)
1878 : {
1879 4 : if (TREE_VALUE (TREE_VALUE (opn)) == name)
1880 : /* Name already in "old parm name" attribute. */;
1881 : else
1882 : {
1883 : /* Different names. */
1884 0 : MULTIPLE_NAMES_PARM_P (oldarg) = 1;
1885 0 : MULTIPLE_NAMES_PARM_P (newarg) = 1;
1886 : }
1887 : }
1888 : else
1889 : {
1890 : /* Save name into attribute. */
1891 212 : DECL_ATTRIBUTES (newarg)
1892 212 : = tree_cons (get_identifier ("old parm name"),
1893 : tree_cons (NULL_TREE, name, NULL_TREE),
1894 212 : DECL_ATTRIBUTES (newarg));
1895 212 : DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1896 : }
1897 : }
1898 27058 : else if (extern_alias)
1899 2 : DECL_NAME (newarg) = DECL_NAME (oldarg);
1900 : }
1901 : }
1902 15407631 : }
1903 :
1904 : /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
1905 : If the redeclaration is invalid, a diagnostic is issued, and the
1906 : error_mark_node is returned. Otherwise, OLDDECL is returned.
1907 :
1908 : If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
1909 : returned.
1910 :
1911 : HIDING is true if the new decl is being hidden. WAS_HIDDEN is true
1912 : if the old decl was hidden.
1913 :
1914 : Hidden decls can be anticipated builtins, injected friends, or
1915 : (coming soon) injected from a local-extern decl. */
1916 :
1917 : tree
1918 333976859 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
1919 : {
1920 333976859 : unsigned olddecl_uid = DECL_UID (olddecl);
1921 333976859 : int types_match = 0;
1922 333976859 : int new_defines_function = 0;
1923 333976859 : tree new_template_info;
1924 333976859 : location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
1925 333976859 : location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
1926 :
1927 333976859 : if (newdecl == olddecl)
1928 : return olddecl;
1929 :
1930 333132984 : types_match = decls_match (newdecl, olddecl);
1931 :
1932 : /* If either the type of the new decl or the type of the old decl is an
1933 : error_mark_node, then that implies that we have already issued an
1934 : error (earlier) for some bogus type specification, and in that case,
1935 : it is rather pointless to harass the user with yet more error message
1936 : about the same declaration, so just pretend the types match here. */
1937 333132984 : if (TREE_TYPE (newdecl) == error_mark_node
1938 333132984 : || TREE_TYPE (olddecl) == error_mark_node)
1939 : return error_mark_node;
1940 :
1941 : /* Check for redeclaration and other discrepancies. */
1942 333132958 : if (TREE_CODE (olddecl) == FUNCTION_DECL
1943 333132958 : && DECL_IS_UNDECLARED_BUILTIN (olddecl))
1944 : {
1945 6403516 : if (TREE_CODE (newdecl) != FUNCTION_DECL)
1946 : {
1947 : /* Avoid warnings redeclaring built-ins which have not been
1948 : explicitly declared. */
1949 197101 : if (was_hidden)
1950 : {
1951 197059 : if (TREE_PUBLIC (newdecl)
1952 197059 : && CP_DECL_CONTEXT (newdecl) == global_namespace)
1953 12 : warning_at (newdecl_loc,
1954 12 : OPT_Wbuiltin_declaration_mismatch,
1955 : "built-in function %qD declared as non-function",
1956 : newdecl);
1957 197059 : return NULL_TREE;
1958 : }
1959 :
1960 : /* If you declare a built-in or predefined function name as static,
1961 : the old definition is overridden, but optionally warn this was a
1962 : bad choice of name. */
1963 42 : if (! TREE_PUBLIC (newdecl))
1964 : {
1965 42 : warning_at (newdecl_loc,
1966 42 : OPT_Wshadow,
1967 42 : fndecl_built_in_p (olddecl)
1968 : ? G_("shadowing built-in function %q#D")
1969 : : G_("shadowing library function %q#D"), olddecl);
1970 : /* Discard the old built-in function. */
1971 42 : return NULL_TREE;
1972 : }
1973 : /* If the built-in is not ansi, then programs can override
1974 : it even globally without an error. */
1975 0 : else if (! fndecl_built_in_p (olddecl))
1976 0 : warning_at (newdecl_loc, 0,
1977 : "library function %q#D redeclared as non-function %q#D",
1978 : olddecl, newdecl);
1979 : else
1980 0 : error_at (newdecl_loc,
1981 : "declaration of %q#D conflicts with built-in "
1982 : "declaration %q#D", newdecl, olddecl);
1983 0 : return NULL_TREE;
1984 : }
1985 6206415 : else if (!types_match)
1986 : {
1987 : /* Avoid warnings redeclaring built-ins which have not been
1988 : explicitly declared. */
1989 2247663 : if (was_hidden)
1990 : {
1991 806237 : tree t1, t2;
1992 :
1993 : /* A new declaration doesn't match a built-in one unless it
1994 : is also extern "C". */
1995 806237 : gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
1996 806237 : gcc_assert (DECL_EXTERN_C_P (olddecl));
1997 806237 : if (!DECL_EXTERN_C_P (newdecl))
1998 : return NULL_TREE;
1999 :
2000 146215 : for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2001 146215 : t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2002 251840 : t1 || t2;
2003 105625 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
2004 : {
2005 251822 : if (!t1 || !t2)
2006 : break;
2007 : /* FILE, tm types are not known at the time
2008 : we create the builtins. */
2009 775667 : for (unsigned i = 0;
2010 1027327 : i < sizeof (builtin_structptr_types)
2011 : / sizeof (builtin_structptr_type);
2012 : ++i)
2013 921696 : if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
2014 : {
2015 146029 : tree t = TREE_VALUE (t1);
2016 :
2017 146029 : if (TYPE_PTR_P (t)
2018 292058 : && TYPE_IDENTIFIER (TREE_TYPE (t))
2019 146029 : == get_identifier (builtin_structptr_types[i].str)
2020 292043 : && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
2021 : {
2022 146014 : tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2023 :
2024 146014 : TYPE_ARG_TYPES (TREE_TYPE (olddecl))
2025 146014 : = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
2026 146014 : types_match = decls_match (newdecl, olddecl);
2027 146014 : if (types_match)
2028 146014 : return duplicate_decls (newdecl, olddecl,
2029 146014 : hiding, was_hidden);
2030 0 : TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
2031 : }
2032 15 : goto next_arg;
2033 : }
2034 :
2035 105631 : if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
2036 : break;
2037 105625 : next_arg:;
2038 : }
2039 :
2040 201 : warning_at (newdecl_loc,
2041 201 : OPT_Wbuiltin_declaration_mismatch,
2042 : "declaration of %q#D conflicts with built-in "
2043 : "declaration %q#D", newdecl, olddecl);
2044 : }
2045 1441426 : else if ((DECL_EXTERN_C_P (newdecl)
2046 15 : && DECL_EXTERN_C_P (olddecl))
2047 2882837 : || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2048 1441411 : TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
2049 : {
2050 : /* Don't really override olddecl for __* prefixed builtins
2051 : except for __[^b]*_chk, the compiler might be using those
2052 : explicitly. */
2053 15 : if (fndecl_built_in_p (olddecl))
2054 : {
2055 15 : tree id = DECL_NAME (olddecl);
2056 15 : const char *name = IDENTIFIER_POINTER (id);
2057 15 : size_t len;
2058 :
2059 15 : if (name[0] == '_'
2060 15 : && name[1] == '_'
2061 30 : && (startswith (name + 2, "builtin_")
2062 6 : || (len = strlen (name)) <= strlen ("___chk")
2063 6 : || memcmp (name + len - strlen ("_chk"),
2064 : "_chk", strlen ("_chk") + 1) != 0))
2065 : {
2066 15 : if (DECL_INITIAL (newdecl))
2067 : {
2068 6 : error_at (newdecl_loc,
2069 : "definition of %q#D ambiguates built-in "
2070 : "declaration %q#D", newdecl, olddecl);
2071 6 : return error_mark_node;
2072 : }
2073 9 : auto_diagnostic_group d;
2074 9 : if (permerror (newdecl_loc,
2075 : "new declaration %q#D ambiguates built-in"
2076 : " declaration %q#D", newdecl, olddecl)
2077 9 : && flag_permissive)
2078 3 : inform (newdecl_loc,
2079 : "ignoring the %q#D declaration", newdecl);
2080 9 : return flag_permissive ? olddecl : error_mark_node;
2081 9 : }
2082 : }
2083 :
2084 : /* A near match; override the builtin. */
2085 :
2086 0 : if (TREE_PUBLIC (newdecl))
2087 0 : warning_at (newdecl_loc,
2088 0 : OPT_Wbuiltin_declaration_mismatch,
2089 : "new declaration %q#D ambiguates built-in "
2090 : "declaration %q#D", newdecl, olddecl);
2091 : else
2092 0 : warning (OPT_Wshadow,
2093 : fndecl_built_in_p (olddecl)
2094 : ? G_("shadowing built-in function %q#D")
2095 : : G_("shadowing library function %q#D"), olddecl);
2096 : }
2097 : else
2098 : /* Discard the old built-in function. */
2099 : return NULL_TREE;
2100 :
2101 : /* Replace the old RTL to avoid problems with inlining. */
2102 201 : COPY_DECL_RTL (newdecl, olddecl);
2103 : }
2104 : else
2105 : {
2106 : /* Even if the types match, prefer the new declarations type
2107 : for built-ins which have not been explicitly declared,
2108 : for exception lists, etc... */
2109 3958752 : tree type = TREE_TYPE (newdecl);
2110 3958752 : tree attribs = (*targetm.merge_type_attributes)
2111 3958752 : (TREE_TYPE (olddecl), type);
2112 :
2113 3958752 : type = cp_build_type_attribute_variant (type, attribs);
2114 3958752 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type;
2115 : }
2116 :
2117 : /* If a function is explicitly declared "throw ()", propagate that to
2118 : the corresponding builtin. */
2119 3958953 : if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
2120 3790068 : && was_hidden
2121 3790025 : && TREE_NOTHROW (newdecl)
2122 7481880 : && !TREE_NOTHROW (olddecl))
2123 : {
2124 27826 : enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
2125 27826 : tree tmpdecl = builtin_decl_explicit (fncode);
2126 27826 : if (tmpdecl && tmpdecl != olddecl && types_match)
2127 27826 : TREE_NOTHROW (tmpdecl) = 1;
2128 : }
2129 :
2130 : /* Whether or not the builtin can throw exceptions has no
2131 : bearing on this declarator. */
2132 3958953 : TREE_NOTHROW (olddecl) = 0;
2133 :
2134 3958953 : if (DECL_THIS_STATIC (newdecl) && !DECL_THIS_STATIC (olddecl))
2135 : {
2136 : /* If a builtin function is redeclared as `static', merge
2137 : the declarations, but make the original one static. */
2138 3 : DECL_THIS_STATIC (olddecl) = 1;
2139 3 : TREE_PUBLIC (olddecl) = 0;
2140 :
2141 : /* Make the old declaration consistent with the new one so
2142 : that all remnants of the builtin-ness of this function
2143 : will be banished. */
2144 3 : SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
2145 3 : COPY_DECL_RTL (newdecl, olddecl);
2146 : }
2147 : }
2148 326729442 : else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
2149 : {
2150 : /* C++ Standard, 3.3, clause 4:
2151 : "[Note: a namespace name or a class template name must be unique
2152 : in its declarative region (7.3.2, clause 14). ]" */
2153 72885526 : if (TREE_CODE (olddecl) == NAMESPACE_DECL
2154 72885499 : || TREE_CODE (newdecl) == NAMESPACE_DECL)
2155 : /* Namespace conflicts with not namespace. */;
2156 35650505 : else if (DECL_TYPE_TEMPLATE_P (olddecl)
2157 108535992 : || DECL_TYPE_TEMPLATE_P (newdecl))
2158 : /* Class template conflicts. */;
2159 72885481 : else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
2160 35650505 : && DECL_TEMPLATE_RESULT (olddecl)
2161 35650505 : && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
2162 108535980 : || (TREE_CODE (newdecl) == TEMPLATE_DECL
2163 37186300 : && DECL_TEMPLATE_RESULT (newdecl)
2164 37186300 : && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
2165 : /* Variable template conflicts. */;
2166 72885472 : else if (concept_definition_p (olddecl)
2167 145770938 : || concept_definition_p (newdecl))
2168 : /* Concept conflicts. */;
2169 72885460 : else if ((TREE_CODE (newdecl) == FUNCTION_DECL
2170 35689478 : && DECL_FUNCTION_TEMPLATE_P (olddecl))
2171 72924445 : || (TREE_CODE (olddecl) == FUNCTION_DECL
2172 37186313 : && DECL_FUNCTION_TEMPLATE_P (newdecl)))
2173 : {
2174 : /* One is a function and the other is a template
2175 : function. */
2176 72836769 : if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
2177 : return NULL_TREE;
2178 :
2179 : /* There can only be one! */
2180 57499 : auto_diagnostic_group d;
2181 57499 : if (TREE_CODE (newdecl) == TEMPLATE_DECL
2182 57499 : && check_raw_literal_operator (olddecl))
2183 3 : error_at (newdecl_loc,
2184 : "literal operator %q#D conflicts with"
2185 : " raw literal operator", newdecl);
2186 57496 : else if (check_raw_literal_operator (newdecl))
2187 3 : error_at (newdecl_loc,
2188 : "raw literal operator %q#D conflicts with"
2189 : " literal operator template", newdecl);
2190 : else
2191 : return NULL_TREE;
2192 :
2193 6 : inform (olddecl_loc, "previous declaration %q#D", olddecl);
2194 6 : return error_mark_node;
2195 57499 : }
2196 48691 : else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
2197 : /* A structured binding must be unique in its declarative region. */;
2198 39135 : else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
2199 48688 : || DECL_IMPLICIT_TYPEDEF_P (newdecl))
2200 : /* One is an implicit typedef, that's ok. */
2201 : return NULL_TREE;
2202 :
2203 153 : auto_diagnostic_group d;
2204 153 : error ("%q#D redeclared as different kind of entity", newdecl);
2205 153 : inform (olddecl_loc, "previous declaration %q#D", olddecl);
2206 :
2207 153 : return error_mark_node;
2208 153 : }
2209 253843916 : else if (!types_match)
2210 : {
2211 237698602 : if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl))
2212 : /* These are certainly not duplicate declarations; they're
2213 : from different scopes. */
2214 : return NULL_TREE;
2215 :
2216 237698542 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2217 : {
2218 149066884 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
2219 149066884 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
2220 :
2221 : /* The name of a class template may not be declared to refer to
2222 : any other template, class, function, object, namespace, value,
2223 : or type in the same scope. */
2224 149066884 : if (TREE_CODE (oldres) == TYPE_DECL
2225 149066878 : || TREE_CODE (newres) == TYPE_DECL)
2226 : {
2227 9 : auto_diagnostic_group d;
2228 9 : error_at (newdecl_loc,
2229 : "conflicting declaration of template %q#D", newdecl);
2230 9 : inform (olddecl_loc,
2231 : "previous declaration %q#D", olddecl);
2232 9 : return error_mark_node;
2233 9 : }
2234 :
2235 149066875 : else if (TREE_CODE (oldres) == FUNCTION_DECL
2236 149066866 : && TREE_CODE (newres) == FUNCTION_DECL)
2237 : {
2238 149066866 : if (duplicate_function_template_decls (newdecl, olddecl))
2239 0 : return error_mark_node;
2240 : return NULL_TREE;
2241 : }
2242 : return NULL_TREE;
2243 : }
2244 88631658 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2245 : {
2246 88631501 : if (DECL_EXTERN_C_P (newdecl) && DECL_EXTERN_C_P (olddecl))
2247 : {
2248 57 : auto_diagnostic_group d;
2249 57 : error_at (newdecl_loc,
2250 : "conflicting declaration of C function %q#D",
2251 : newdecl);
2252 57 : inform (olddecl_loc,
2253 : "previous declaration %q#D", olddecl);
2254 57 : return error_mark_node;
2255 57 : }
2256 : /* For function versions, params and types match, but they
2257 : are not ambiguous. */
2258 88631444 : else if (((!DECL_FUNCTION_VERSIONED (newdecl)
2259 88623110 : && !DECL_FUNCTION_VERSIONED (olddecl))
2260 8379 : || !same_type_p (fndecl_declared_return_type (newdecl),
2261 : fndecl_declared_return_type (olddecl)))
2262 : /* Let constrained hidden friends coexist for now, we'll
2263 : check satisfaction later. */
2264 88623065 : && !member_like_constrained_friend_p (newdecl)
2265 81091039 : && !member_like_constrained_friend_p (olddecl)
2266 : // The functions have the same parameter types.
2267 79350063 : && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2268 79350063 : TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
2269 : // And the same constraints.
2270 88631513 : && equivalently_constrained (newdecl, olddecl))
2271 : {
2272 69 : auto_diagnostic_group d;
2273 69 : error_at (newdecl_loc,
2274 : "ambiguating new declaration of %q#D", newdecl);
2275 69 : inform (olddecl_loc,
2276 : "old declaration %q#D", olddecl);
2277 69 : return error_mark_node;
2278 69 : }
2279 : else
2280 88631375 : return NULL_TREE;
2281 : }
2282 : else
2283 : {
2284 157 : auto_diagnostic_group d;
2285 157 : error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
2286 157 : inform (olddecl_loc,
2287 : "previous declaration as %q#D", olddecl);
2288 157 : return error_mark_node;
2289 157 : }
2290 : }
2291 16145314 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2292 16145314 : && DECL_OMP_DECLARE_REDUCTION_P (newdecl))
2293 : {
2294 : /* OMP UDRs are never duplicates. */
2295 33 : gcc_assert (DECL_OMP_DECLARE_REDUCTION_P (olddecl));
2296 33 : auto_diagnostic_group d;
2297 33 : error_at (newdecl_loc,
2298 : "redeclaration of %<pragma omp declare reduction%>");
2299 33 : inform (olddecl_loc,
2300 : "previous %<pragma omp declare reduction%> declaration");
2301 33 : return error_mark_node;
2302 33 : }
2303 16145281 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2304 16145281 : && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
2305 224 : && (!DECL_TEMPLATE_INFO (newdecl)
2306 224 : || (DECL_TI_TEMPLATE (newdecl)
2307 224 : != DECL_TI_TEMPLATE (olddecl))))
2308 11448774 : || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
2309 568072 : && (!DECL_TEMPLATE_INFO (olddecl)
2310 568072 : || (DECL_TI_TEMPLATE (olddecl)
2311 568072 : != DECL_TI_TEMPLATE (newdecl))))))
2312 : /* It's OK to have a template specialization and a non-template
2313 : with the same type, or to have specializations of two
2314 : different templates with the same type. Note that if one is a
2315 : specialization, and the other is an instantiation of the same
2316 : template, that we do not exit at this point. That situation
2317 : can occur if we instantiate a template class, and then
2318 : specialize one of its methods. This situation is valid, but
2319 : the declarations must be merged in the usual way. */
2320 : return NULL_TREE;
2321 16145281 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2322 16145281 : && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
2323 650504 : && !DECL_USE_TEMPLATE (newdecl))
2324 11448774 : || (DECL_TEMPLATE_INSTANTIATION (newdecl)
2325 82656 : && !DECL_USE_TEMPLATE (olddecl))))
2326 : /* One of the declarations is a template instantiation, and the
2327 : other is not a template at all. That's OK. */
2328 : return NULL_TREE;
2329 16145281 : else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
2330 : {
2331 : /* In [namespace.alias] we have:
2332 :
2333 : In a declarative region, a namespace-alias-definition can be
2334 : used to redefine a namespace-alias declared in that declarative
2335 : region to refer only to the namespace to which it already
2336 : refers.
2337 :
2338 : Therefore, if we encounter a second alias directive for the same
2339 : alias, we can just ignore the second directive. */
2340 29 : if (DECL_NAMESPACE_ALIAS (newdecl)
2341 29 : && (DECL_NAMESPACE_ALIAS (newdecl)
2342 26 : == DECL_NAMESPACE_ALIAS (olddecl)))
2343 : return olddecl;
2344 :
2345 : /* Leave it to update_binding to merge or report error. */
2346 : return NULL_TREE;
2347 : }
2348 : /* Check if the two decls are non-mergeable versioned decls. */
2349 16145252 : else if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
2350 : && diagnose_versioned_decls (olddecl, newdecl))
2351 : return error_mark_node;
2352 : else
2353 : {
2354 16145252 : const char *errmsg = redeclaration_error_message (newdecl, olddecl);
2355 16145252 : if (errmsg)
2356 : {
2357 621 : auto_diagnostic_group d;
2358 621 : error_at (newdecl_loc, errmsg, newdecl);
2359 621 : if (DECL_NAME (olddecl) != NULL_TREE)
2360 621 : inform (olddecl_loc,
2361 621 : (DECL_INITIAL (olddecl) && namespace_bindings_p ())
2362 : ? G_("%q#D previously defined here")
2363 : : G_("%q#D previously declared here"), olddecl);
2364 621 : if (cxx_dialect >= cxx26
2365 147 : && DECL_NAME (newdecl)
2366 147 : && id_equal (DECL_NAME (newdecl), "_")
2367 634 : && !name_independent_decl_p (newdecl))
2368 : {
2369 13 : if (TREE_CODE (newdecl) == PARM_DECL)
2370 2 : inform (newdecl_loc,
2371 : "parameter declaration is not name-independent");
2372 11 : else if (DECL_DECOMPOSITION_P (newdecl))
2373 : {
2374 3 : if (at_namespace_scope_p ())
2375 2 : inform (newdecl_loc,
2376 : "structured binding at namespace scope is not "
2377 : "name-independent");
2378 1 : else if (TREE_STATIC (newdecl))
2379 1 : inform (newdecl_loc,
2380 : "static structured binding is not "
2381 : "name-independent");
2382 0 : else if (DECL_EXTERNAL (newdecl))
2383 0 : inform (newdecl_loc,
2384 : "extern structured binding is not "
2385 : "name-independent");
2386 : }
2387 8 : else if (at_class_scope_p ()
2388 0 : && VAR_P (newdecl)
2389 8 : && TREE_STATIC (newdecl))
2390 0 : inform (newdecl_loc,
2391 : "static data member is not name-independent");
2392 8 : else if (VAR_P (newdecl) && at_namespace_scope_p ())
2393 3 : inform (newdecl_loc,
2394 : "variable at namespace scope is not name-independent");
2395 5 : else if (VAR_P (newdecl) && TREE_STATIC (newdecl))
2396 3 : inform (newdecl_loc,
2397 : "static variable is not name-independent");
2398 2 : else if (VAR_P (newdecl) && DECL_EXTERNAL (newdecl))
2399 0 : inform (newdecl_loc,
2400 : "extern variable is not name-independent");
2401 : }
2402 621 : return error_mark_node;
2403 621 : }
2404 16144631 : else if (TREE_CODE (olddecl) == FUNCTION_DECL
2405 11448534 : && DECL_INITIAL (olddecl) != NULL_TREE
2406 17397 : && !prototype_p (TREE_TYPE (olddecl))
2407 16144631 : && prototype_p (TREE_TYPE (newdecl)))
2408 : {
2409 : /* Prototype decl follows defn w/o prototype. */
2410 0 : auto_diagnostic_group d;
2411 0 : if (warning_at (newdecl_loc, 0,
2412 : "prototype specified for %q#D", newdecl))
2413 0 : inform (olddecl_loc,
2414 : "previous non-prototype definition here");
2415 0 : }
2416 15632885 : else if (VAR_OR_FUNCTION_DECL_P (olddecl)
2417 27593165 : && DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl))
2418 : {
2419 : /* [dcl.link]
2420 : If two declarations of the same function or object
2421 : specify different linkage-specifications ..., the program
2422 : is ill-formed.... Except for functions with C++ linkage,
2423 : a function declaration without a linkage specification
2424 : shall not precede the first linkage specification for
2425 : that function. A function can be declared without a
2426 : linkage specification after an explicit linkage
2427 : specification has been seen; the linkage explicitly
2428 : specified in the earlier declaration is not affected by
2429 : such a function declaration.
2430 :
2431 : DR 563 raises the question why the restrictions on
2432 : functions should not also apply to objects. Older
2433 : versions of G++ silently ignore the linkage-specification
2434 : for this example:
2435 :
2436 : namespace N {
2437 : extern int i;
2438 : extern "C" int i;
2439 : }
2440 :
2441 : which is clearly wrong. Therefore, we now treat objects
2442 : like functions. */
2443 1806 : if (current_lang_depth () == 0)
2444 : {
2445 : /* There is no explicit linkage-specification, so we use
2446 : the linkage from the previous declaration. */
2447 1794 : retrofit_lang_decl (newdecl);
2448 1794 : SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
2449 : }
2450 : else
2451 : {
2452 12 : auto_diagnostic_group d;
2453 12 : error_at (newdecl_loc,
2454 : "conflicting declaration of %q#D with %qL linkage",
2455 12 : newdecl, DECL_LANGUAGE (newdecl));
2456 12 : inform (olddecl_loc,
2457 : "previous declaration with %qL linkage",
2458 12 : DECL_LANGUAGE (olddecl));
2459 12 : }
2460 : }
2461 :
2462 16144631 : if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
2463 : ;
2464 15473243 : else if (TREE_CODE (olddecl) == FUNCTION_DECL)
2465 : {
2466 : /* Note: free functions, as TEMPLATE_DECLs, are handled below. */
2467 13471273 : if (DECL_FUNCTION_MEMBER_P (olddecl)
2468 10797815 : && (/* grokfndecl passes member function templates too
2469 : as FUNCTION_DECLs. */
2470 8302442 : DECL_TEMPLATE_INFO (olddecl)
2471 : /* C++11 8.3.6/6.
2472 : Default arguments for a member function of a class
2473 : template shall be specified on the initial declaration
2474 : of the member function within the class template. */
2475 701167 : || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
2476 : {
2477 7680689 : check_redeclaration_no_default_args (newdecl);
2478 :
2479 7680689 : if (DECL_TEMPLATE_INFO (olddecl)
2480 7680689 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
2481 : {
2482 2238917 : tree new_parms = DECL_TEMPLATE_INFO (newdecl)
2483 2238917 : ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
2484 2238917 : : INNERMOST_TEMPLATE_PARMS (current_template_parms);
2485 2238917 : tree old_parms
2486 2238917 : = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
2487 2238917 : merge_default_template_args (new_parms, old_parms,
2488 : /*class_p=*/false);
2489 : }
2490 : }
2491 : else
2492 : {
2493 3117126 : tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
2494 3117126 : tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
2495 3117126 : int i = 1;
2496 :
2497 8057892 : for (; t1 && t1 != void_list_node;
2498 4940766 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
2499 4942611 : if (TREE_PURPOSE (t1) && TREE_PURPOSE (t2))
2500 : {
2501 57 : if (simple_cst_equal (TREE_PURPOSE (t1),
2502 57 : TREE_PURPOSE (t2)) == 1)
2503 : {
2504 24 : auto_diagnostic_group d;
2505 24 : if (permerror (newdecl_loc,
2506 : "default argument given for parameter "
2507 : "%d of %q#D", i, newdecl))
2508 24 : inform (olddecl_loc,
2509 : "previous specification in %q#D here",
2510 : olddecl);
2511 24 : }
2512 : else
2513 : {
2514 33 : auto_diagnostic_group d;
2515 33 : error_at (newdecl_loc,
2516 : "default argument given for parameter %d "
2517 : "of %q#D", i, newdecl);
2518 33 : inform (olddecl_loc,
2519 : "previous specification in %q#D here",
2520 : olddecl);
2521 33 : }
2522 : }
2523 :
2524 : /* C++17 11.3.6/4: "If a friend declaration specifies a default
2525 : argument expression, that declaration... shall be the only
2526 : declaration of the function or function template in the
2527 : translation unit." */
2528 3117126 : check_no_redeclaration_friend_default_args (olddecl, newdecl);
2529 : }
2530 : }
2531 : }
2532 :
2533 : /* Do not merge an implicit typedef with an explicit one. In:
2534 :
2535 : class A;
2536 : ...
2537 : typedef class A A __attribute__ ((foo));
2538 :
2539 : the attribute should apply only to the typedef. */
2540 20103584 : if (TREE_CODE (olddecl) == TYPE_DECL
2541 20103584 : && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
2542 49648 : || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
2543 : return NULL_TREE;
2544 :
2545 20070457 : if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
2546 : return NULL_TREE;
2547 :
2548 20070445 : if (!validate_constexpr_redeclaration (olddecl, newdecl))
2549 30 : return error_mark_node;
2550 :
2551 20070415 : if (modules_p ()
2552 61324 : && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
2553 20106331 : && TREE_CODE (olddecl) != NAMESPACE_DECL)
2554 : {
2555 35916 : if (!module_may_redeclare (olddecl, newdecl))
2556 24 : return error_mark_node;
2557 :
2558 35892 : if (!hiding)
2559 : {
2560 : /* The old declaration should match the exportingness of the new
2561 : declaration. But hidden friend declarations just keep the
2562 : exportingness of the old declaration; see CWG2588. */
2563 31564 : tree not_tmpl = STRIP_TEMPLATE (olddecl);
2564 31564 : if (DECL_LANG_SPECIFIC (not_tmpl)
2565 31467 : && DECL_MODULE_ATTACH_P (not_tmpl)
2566 : /* Typedefs are not entities and so are OK to be redeclared
2567 : as exported: see [module.interface]/p6. */
2568 31755 : && TREE_CODE (olddecl) != TYPE_DECL)
2569 : {
2570 179 : if (DECL_MODULE_EXPORT_P (newdecl)
2571 179 : && !DECL_MODULE_EXPORT_P (not_tmpl))
2572 : {
2573 15 : auto_diagnostic_group d;
2574 15 : error ("conflicting exporting for declaration %qD", newdecl);
2575 15 : inform (olddecl_loc,
2576 : "previously declared here without exporting");
2577 15 : }
2578 : }
2579 31385 : else if (DECL_MODULE_EXPORT_P (newdecl))
2580 10322 : DECL_MODULE_EXPORT_P (not_tmpl) = true;
2581 : }
2582 : }
2583 :
2584 : /* We have committed to returning OLDDECL at this point. */
2585 :
2586 : /* If new decl is `static' and an `extern' was seen previously,
2587 : warn about it. */
2588 20070391 : warn_extern_redeclared_static (newdecl, olddecl);
2589 :
2590 : /* True to merge attributes between the declarations, false to
2591 : set OLDDECL's attributes to those of NEWDECL (for template
2592 : explicit specializations that specify their own attributes
2593 : independent of those specified for the primary template). */
2594 20070391 : const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
2595 15407442 : || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
2596 20638448 : || DECL_TEMPLATE_SPECIALIZATION (olddecl));
2597 :
2598 20070391 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2599 : {
2600 15407442 : if (merge_attr)
2601 : {
2602 14839594 : {
2603 14839594 : auto_diagnostic_group d;
2604 14839594 : if (diagnose_mismatched_attributes (olddecl, newdecl))
2605 36 : inform (olddecl_loc, DECL_INITIAL (olddecl)
2606 : ? G_("previous definition of %qD here")
2607 : : G_("previous declaration of %qD here"), olddecl);
2608 14839594 : }
2609 :
2610 : /* [dcl.attr.noreturn]: The first declaration of a function shall
2611 : specify the noreturn attribute if any declaration of that function
2612 : specifies the noreturn attribute. */
2613 14839594 : tree a;
2614 14839594 : if (TREE_THIS_VOLATILE (newdecl)
2615 97692 : && !TREE_THIS_VOLATILE (olddecl)
2616 : /* This applies to [[noreturn]] only, not its GNU variants. */
2617 76 : && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
2618 54 : && cxx11_attribute_p (a)
2619 14839615 : && get_attribute_namespace (a) == NULL_TREE)
2620 : {
2621 9 : auto_diagnostic_group d;
2622 9 : error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
2623 : "but its first declaration was not", newdecl);
2624 9 : inform (olddecl_loc, "previous declaration of %qD", olddecl);
2625 9 : }
2626 : }
2627 :
2628 : /* Now that functions must hold information normally held
2629 : by field decls, there is extra work to do so that
2630 : declaration information does not get destroyed during
2631 : definition. */
2632 15407442 : if (DECL_VINDEX (olddecl))
2633 159395 : DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2634 15407442 : if (DECL_CONTEXT (olddecl))
2635 15407442 : DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2636 15407442 : DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
2637 15407442 : DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2638 15407442 : DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
2639 15407442 : DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
2640 15407442 : DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
2641 15407442 : DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
2642 15407442 : DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
2643 15407442 : DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
2644 15407442 : DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
2645 15407442 : |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
2646 15407442 : if (DECL_OVERLOADED_OPERATOR_P (olddecl))
2647 2768573 : DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
2648 5537146 : = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
2649 15407442 : new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
2650 :
2651 15407442 : check_redecl_contract (newdecl, olddecl);
2652 :
2653 : /* Optionally warn about more than one declaration for the same
2654 : name, but don't warn about a function declaration followed by a
2655 : definition. */
2656 27 : if (warn_redundant_decls && ! DECL_ARTIFICIAL (olddecl)
2657 27 : && !(new_defines_function && DECL_INITIAL (olddecl) == NULL_TREE)
2658 : /* Don't warn about extern decl followed by definition. */
2659 27 : && !(DECL_EXTERNAL (olddecl) && ! DECL_EXTERNAL (newdecl))
2660 : /* Don't warn if at least one is/was hidden. */
2661 27 : && !(hiding || was_hidden)
2662 : /* Don't warn about declaration followed by specialization. */
2663 15407454 : && (! DECL_TEMPLATE_SPECIALIZATION (newdecl)
2664 9 : || DECL_TEMPLATE_SPECIALIZATION (olddecl)))
2665 : {
2666 6 : auto_diagnostic_group d;
2667 6 : if (warning_at (newdecl_loc,
2668 6 : OPT_Wredundant_decls,
2669 : "redundant redeclaration of %qD in same scope",
2670 : newdecl))
2671 6 : inform (olddecl_loc,
2672 : "previous declaration of %qD", olddecl);
2673 6 : }
2674 :
2675 : /* [dcl.fct.def.delete] A deleted definition of a function shall be the
2676 : first declaration of the function or, for an explicit specialization
2677 : of a function template, the first declaration of that
2678 : specialization. */
2679 15407442 : if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
2680 650504 : && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
2681 : {
2682 14839594 : if (DECL_DELETED_FN (newdecl))
2683 : {
2684 21 : auto_diagnostic_group d;
2685 21 : if (pedwarn (newdecl_loc, 0, "deleted definition of %qD "
2686 : "is not first declaration", newdecl))
2687 21 : inform (olddecl_loc,
2688 : "previous declaration of %qD", olddecl);
2689 21 : }
2690 14839594 : DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
2691 14839594 : if (DECL_DELETED_FN (olddecl)
2692 6 : && DECL_INITIAL (olddecl)
2693 14839600 : && TREE_CODE (DECL_INITIAL (olddecl)) == STRING_CST)
2694 3 : DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2695 : }
2696 : }
2697 :
2698 : /* Deal with C++: must preserve virtual function table size. */
2699 20070391 : if (TREE_CODE (olddecl) == TYPE_DECL)
2700 : {
2701 49645 : tree newtype = TREE_TYPE (newdecl);
2702 49645 : tree oldtype = TREE_TYPE (olddecl);
2703 :
2704 49645 : if (newtype != error_mark_node && oldtype != error_mark_node
2705 99290 : && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2706 136899 : CLASSTYPE_FRIEND_CLASSES (newtype)
2707 45633 : = CLASSTYPE_FRIEND_CLASSES (oldtype);
2708 :
2709 49645 : DECL_ORIGINAL_TYPE (newdecl) = DECL_ORIGINAL_TYPE (olddecl);
2710 : }
2711 :
2712 : /* Copy all the DECL_... slots specified in the new decl except for
2713 : any that we copy here from the old type. */
2714 20070391 : if (merge_attr)
2715 19502543 : DECL_ATTRIBUTES (newdecl)
2716 39005086 : = (*targetm.merge_decl_attributes) (olddecl, newdecl);
2717 : else
2718 567848 : DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2719 :
2720 : /* Transfer purviewness and importingness to the old decl. */
2721 20070391 : transfer_defining_module (olddecl, newdecl);
2722 :
2723 20070391 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2724 : {
2725 4101558 : tree old_result = DECL_TEMPLATE_RESULT (olddecl);
2726 4101558 : tree new_result = DECL_TEMPLATE_RESULT (newdecl);
2727 4101558 : TREE_TYPE (olddecl) = TREE_TYPE (old_result);
2728 :
2729 : /* The new decl should not already have gathered any
2730 : specializations. */
2731 4101558 : gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
2732 :
2733 : /* Make sure the contracts are equivalent. */
2734 4101558 : check_redecl_contract (newdecl, olddecl);
2735 :
2736 4101558 : DECL_ATTRIBUTES (old_result)
2737 4101558 : = (*targetm.merge_decl_attributes) (old_result, new_result);
2738 :
2739 4101558 : if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2740 : {
2741 4101528 : if (DECL_SOURCE_LOCATION (newdecl)
2742 4101528 : != DECL_SOURCE_LOCATION (olddecl))
2743 : {
2744 : /* Per C++11 8.3.6/4, default arguments cannot be added in
2745 : later declarations of a function template. */
2746 4078815 : check_redeclaration_no_default_args (newdecl);
2747 : /* C++17 11.3.6/4: "If a friend declaration specifies a default
2748 : argument expression, that declaration... shall be the only
2749 : declaration of the function or function template in the
2750 : translation unit." */
2751 4078815 : check_no_redeclaration_friend_default_args
2752 4078815 : (old_result, new_result);
2753 :
2754 4078815 : tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
2755 4078815 : tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
2756 4078815 : merge_default_template_args (new_parms, old_parms,
2757 : /*class_p=*/false);
2758 : }
2759 4101528 : if (!DECL_UNIQUE_FRIEND_P (new_result))
2760 2997073 : DECL_UNIQUE_FRIEND_P (old_result) = false;
2761 :
2762 4101528 : check_default_args (newdecl);
2763 :
2764 8203044 : if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
2765 4101528 : && DECL_INITIAL (new_result))
2766 : {
2767 24 : if (DECL_INITIAL (old_result))
2768 12 : DECL_UNINLINABLE (old_result) = 1;
2769 : else
2770 12 : DECL_UNINLINABLE (old_result) = DECL_UNINLINABLE (new_result);
2771 24 : DECL_EXTERNAL (old_result) = DECL_EXTERNAL (new_result);
2772 72 : DECL_NOT_REALLY_EXTERN (old_result)
2773 24 : = DECL_NOT_REALLY_EXTERN (new_result);
2774 48 : DECL_INTERFACE_KNOWN (old_result)
2775 24 : = DECL_INTERFACE_KNOWN (new_result);
2776 24 : DECL_DECLARED_INLINE_P (old_result)
2777 24 : = DECL_DECLARED_INLINE_P (new_result);
2778 24 : DECL_DISREGARD_INLINE_LIMITS (old_result)
2779 24 : |= DECL_DISREGARD_INLINE_LIMITS (new_result);
2780 : }
2781 : else
2782 : {
2783 4101504 : DECL_DECLARED_INLINE_P (old_result)
2784 4101504 : |= DECL_DECLARED_INLINE_P (new_result);
2785 4101504 : DECL_DISREGARD_INLINE_LIMITS (old_result)
2786 4101504 : |= DECL_DISREGARD_INLINE_LIMITS (new_result);
2787 4101504 : check_redeclaration_exception_specification (newdecl, olddecl);
2788 :
2789 4101504 : merge_attribute_bits (new_result, old_result);
2790 : }
2791 : }
2792 :
2793 : /* If the new declaration is a definition, update the file and
2794 : line information on the declaration, and also make
2795 : the old declaration the same definition. */
2796 4101558 : if (DECL_INITIAL (new_result) != NULL_TREE)
2797 : {
2798 5577386 : DECL_SOURCE_LOCATION (olddecl)
2799 5577386 : = DECL_SOURCE_LOCATION (old_result)
2800 2788693 : = DECL_SOURCE_LOCATION (newdecl);
2801 2788693 : DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
2802 2788693 : if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2803 : {
2804 2788693 : update_contract_arguments (new_result, old_result);
2805 :
2806 2788693 : DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
2807 10054238 : for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
2808 7265545 : DECL_CONTEXT (p) = old_result;
2809 :
2810 5577386 : if (tree fc = DECL_FRIEND_CONTEXT (new_result))
2811 18 : SET_DECL_FRIEND_CONTEXT (old_result, fc);
2812 : }
2813 : }
2814 :
2815 4101558 : return olddecl;
2816 : }
2817 :
2818 15968833 : if (types_match)
2819 : {
2820 15968632 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2821 15407241 : check_redeclaration_exception_specification (newdecl, olddecl);
2822 :
2823 : /* Automatically handles default parameters. */
2824 15968632 : tree oldtype = TREE_TYPE (olddecl);
2825 15968632 : tree newtype;
2826 :
2827 : /* For typedefs use the old type, as the new type's DECL_NAME points
2828 : at newdecl, which will be ggc_freed. */
2829 15968632 : if (TREE_CODE (newdecl) == TYPE_DECL)
2830 : {
2831 : /* But NEWTYPE might have an attribute, honor that. */
2832 49645 : tree tem = TREE_TYPE (newdecl);
2833 49645 : newtype = oldtype;
2834 :
2835 49645 : if (TYPE_USER_ALIGN (tem))
2836 : {
2837 21 : if (TYPE_ALIGN (tem) > TYPE_ALIGN (newtype))
2838 6 : SET_TYPE_ALIGN (newtype, TYPE_ALIGN (tem));
2839 21 : TYPE_USER_ALIGN (newtype) = true;
2840 : }
2841 :
2842 : /* And remove the new type from the variants list. */
2843 49645 : if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
2844 : {
2845 24 : tree remove = TREE_TYPE (newdecl);
2846 24 : if (TYPE_MAIN_VARIANT (remove) == remove)
2847 : {
2848 9 : gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
2849 : /* If remove is the main variant, no need to remove that
2850 : from the list. One of the DECL_ORIGINAL_TYPE
2851 : variants, e.g. created for aligned attribute, might still
2852 : refer to the newdecl TYPE_DECL though, so remove that one
2853 : in that case. */
2854 9 : if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
2855 6 : if (orig != remove)
2856 6 : for (tree t = TYPE_MAIN_VARIANT (orig); t;
2857 0 : t = TYPE_MAIN_VARIANT (t))
2858 6 : if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
2859 : {
2860 12 : TYPE_NEXT_VARIANT (t)
2861 6 : = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
2862 6 : break;
2863 : }
2864 : }
2865 : else
2866 15 : for (tree t = TYPE_MAIN_VARIANT (remove); ;
2867 0 : t = TYPE_NEXT_VARIANT (t))
2868 15 : if (TYPE_NEXT_VARIANT (t) == remove)
2869 : {
2870 15 : TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
2871 15 : break;
2872 : }
2873 : }
2874 : }
2875 15918987 : else if (merge_attr)
2876 15351139 : newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2877 : else
2878 567848 : newtype = TREE_TYPE (newdecl);
2879 :
2880 15968632 : if (VAR_P (newdecl))
2881 : {
2882 511746 : DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
2883 : /* For already initialized vars, TREE_READONLY could have been
2884 : cleared in cp_finish_decl, because the var needs runtime
2885 : initialization or destruction. Make sure not to set
2886 : TREE_READONLY on it again. */
2887 511746 : if (DECL_INITIALIZED_P (olddecl)
2888 1217 : && !DECL_EXTERNAL (olddecl)
2889 511833 : && !TREE_READONLY (olddecl))
2890 32 : TREE_READONLY (newdecl) = 0;
2891 511746 : DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
2892 1023492 : DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
2893 511746 : |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
2894 511746 : if (DECL_DEPENDENT_INIT_P (olddecl))
2895 108169 : SET_DECL_DEPENDENT_INIT_P (newdecl, true);
2896 1023492 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
2897 511746 : |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
2898 511746 : DECL_DECLARED_CONSTEXPR_P (newdecl)
2899 511746 : |= DECL_DECLARED_CONSTEXPR_P (olddecl);
2900 1023492 : DECL_DECLARED_CONSTINIT_P (newdecl)
2901 511746 : |= DECL_DECLARED_CONSTINIT_P (olddecl);
2902 :
2903 : /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
2904 511746 : if (DECL_LANG_SPECIFIC (olddecl)
2905 1019894 : && CP_DECL_THREADPRIVATE_P (olddecl))
2906 : {
2907 : /* Allocate a LANG_SPECIFIC structure for NEWDECL, if needed. */
2908 41 : retrofit_lang_decl (newdecl);
2909 41 : CP_DECL_THREADPRIVATE_P (newdecl) = 1;
2910 : }
2911 : }
2912 :
2913 : /* An explicit specialization of a function template or of a member
2914 : function of a class template can be declared transaction_safe
2915 : independently of whether the corresponding template entity is declared
2916 : transaction_safe. */
2917 1207 : if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
2918 1072 : && DECL_TEMPLATE_INSTANTIATION (olddecl)
2919 78 : && DECL_TEMPLATE_SPECIALIZATION (newdecl)
2920 54 : && tx_safe_fn_type_p (newtype)
2921 15968632 : && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
2922 0 : newtype = tx_unsafe_fn_variant (newtype);
2923 :
2924 15968632 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2925 :
2926 15968632 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2927 15407241 : check_default_args (newdecl);
2928 :
2929 : /* Lay the type out, unless already done. */
2930 15968632 : if (! same_type_p (newtype, oldtype)
2931 370 : && TREE_TYPE (newdecl) != error_mark_node
2932 15969002 : && !(processing_template_decl && uses_template_parms (newdecl)))
2933 287 : layout_type (TREE_TYPE (newdecl));
2934 :
2935 15968632 : if ((VAR_P (newdecl)
2936 15456886 : || TREE_CODE (newdecl) == PARM_DECL
2937 15456886 : || TREE_CODE (newdecl) == RESULT_DECL
2938 15456886 : || TREE_CODE (newdecl) == FIELD_DECL
2939 15456886 : || TREE_CODE (newdecl) == TYPE_DECL)
2940 16018277 : && !(processing_template_decl && uses_template_parms (newdecl)))
2941 395077 : layout_decl (newdecl, 0);
2942 :
2943 : /* Merge deprecatedness. */
2944 15968632 : if (TREE_DEPRECATED (newdecl))
2945 11715 : TREE_DEPRECATED (olddecl) = 1;
2946 :
2947 : /* Merge unavailability. */
2948 15968632 : if (TREE_UNAVAILABLE (newdecl))
2949 3 : TREE_UNAVAILABLE (olddecl) = 1;
2950 :
2951 : /* Preserve function specific target and optimization options */
2952 15968632 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2953 : {
2954 15407241 : if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
2955 15407241 : && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
2956 0 : DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
2957 0 : = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
2958 :
2959 15407241 : if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
2960 15407241 : && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
2961 55 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
2962 55 : = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
2963 :
2964 15407241 : if (!DECL_UNIQUE_FRIEND_P (olddecl))
2965 14877457 : DECL_UNIQUE_FRIEND_P (newdecl) = false;
2966 : }
2967 : else
2968 : {
2969 : /* Merge the const type qualifier. */
2970 561391 : if (TREE_READONLY (newdecl))
2971 152888 : TREE_READONLY (olddecl) = 1;
2972 : /* Merge the volatile type qualifier. */
2973 561391 : if (TREE_THIS_VOLATILE (newdecl))
2974 5 : TREE_THIS_VOLATILE (olddecl) = 1;
2975 : }
2976 :
2977 : /* Merge the initialization information. */
2978 15968632 : if (DECL_INITIAL (newdecl) == NULL_TREE
2979 15968632 : && DECL_INITIAL (olddecl) != NULL_TREE)
2980 : {
2981 186823 : DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2982 186823 : DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
2983 186823 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2984 : {
2985 17313 : DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
2986 17313 : DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
2987 : }
2988 : }
2989 :
2990 15968632 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2991 : {
2992 15407241 : DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
2993 15407241 : |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
2994 15407241 : DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
2995 15407241 : if (DECL_IS_OPERATOR_NEW_P (olddecl))
2996 57046 : DECL_SET_IS_OPERATOR_NEW (newdecl, true);
2997 15407241 : DECL_LOOPING_CONST_OR_PURE_P (newdecl)
2998 15407241 : |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
2999 15407241 : DECL_IS_REPLACEABLE_OPERATOR (newdecl)
3000 15407241 : |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
3001 :
3002 15407241 : if (merge_attr)
3003 14839393 : merge_attribute_bits (newdecl, olddecl);
3004 : else
3005 : {
3006 : /* Merge the noreturn bit. */
3007 567848 : TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
3008 567848 : TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
3009 567848 : TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
3010 567848 : DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
3011 567848 : DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
3012 : }
3013 : /* Keep the old RTL. */
3014 15407241 : COPY_DECL_RTL (olddecl, newdecl);
3015 : }
3016 561391 : else if (VAR_P (newdecl)
3017 561391 : && (DECL_SIZE (olddecl) || !DECL_SIZE (newdecl)))
3018 : {
3019 : /* Keep the old RTL. We cannot keep the old RTL if the old
3020 : declaration was for an incomplete object and the new
3021 : declaration is not since many attributes of the RTL will
3022 : change. */
3023 511672 : COPY_DECL_RTL (olddecl, newdecl);
3024 : }
3025 : }
3026 : /* If cannot merge, then use the new type and qualifiers,
3027 : and don't preserve the old rtl. */
3028 : else
3029 : {
3030 : /* Clean out any memory we had of the old declaration. */
3031 201 : tree oldstatic = value_member (olddecl, static_aggregates);
3032 201 : if (oldstatic)
3033 0 : TREE_VALUE (oldstatic) = error_mark_node;
3034 :
3035 201 : TREE_TYPE (olddecl) = TREE_TYPE (newdecl);
3036 201 : TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
3037 201 : TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
3038 201 : TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
3039 201 : TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
3040 : }
3041 :
3042 : /* Merge the storage class information. */
3043 15968833 : merge_weak (newdecl, olddecl);
3044 :
3045 15968833 : DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
3046 15968833 : TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
3047 15968833 : TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
3048 15968833 : if (! DECL_EXTERNAL (olddecl))
3049 54303 : DECL_EXTERNAL (newdecl) = 0;
3050 15968833 : if (! DECL_COMDAT (olddecl))
3051 6797713 : DECL_COMDAT (newdecl) = 0;
3052 :
3053 15968833 : if (VAR_OR_FUNCTION_DECL_P (newdecl) && DECL_LOCAL_DECL_P (newdecl))
3054 : {
3055 78 : if (!DECL_LOCAL_DECL_P (olddecl))
3056 : /* This can happen if olddecl was brought in from the
3057 : enclosing namespace via a using-decl. The new decl is
3058 : then not a block-scope extern at all. */
3059 3 : DECL_LOCAL_DECL_P (newdecl) = false;
3060 : else
3061 : {
3062 75 : retrofit_lang_decl (newdecl);
3063 75 : tree alias = DECL_LOCAL_DECL_ALIAS (newdecl)
3064 75 : = DECL_LOCAL_DECL_ALIAS (olddecl);
3065 75 : if (alias != error_mark_node)
3066 : {
3067 72 : DECL_ATTRIBUTES (alias)
3068 72 : = (*targetm.merge_decl_attributes) (alias, newdecl);
3069 72 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3070 42 : merge_attribute_bits (newdecl, alias);
3071 : }
3072 : }
3073 : }
3074 :
3075 15968833 : new_template_info = NULL_TREE;
3076 15968833 : if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
3077 : {
3078 15915608 : bool new_redefines_gnu_inline = false;
3079 :
3080 15915608 : if (new_defines_function
3081 15915608 : && ((DECL_INTERFACE_KNOWN (olddecl)
3082 1290 : && TREE_CODE (olddecl) == FUNCTION_DECL)
3083 9362615 : || (TREE_CODE (olddecl) == TEMPLATE_DECL
3084 0 : && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
3085 : == FUNCTION_DECL))))
3086 2580 : new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
3087 :
3088 : if (!new_redefines_gnu_inline)
3089 : {
3090 15915530 : DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
3091 15915530 : DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
3092 15915530 : DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
3093 : }
3094 :
3095 15915608 : if (TREE_CODE (newdecl) != TYPE_DECL)
3096 : {
3097 15915544 : DECL_TEMPLATE_INSTANTIATED (newdecl)
3098 15915544 : |= DECL_TEMPLATE_INSTANTIATED (olddecl);
3099 15915544 : DECL_ODR_USED (newdecl) |= DECL_ODR_USED (olddecl);
3100 :
3101 : /* If the OLDDECL is an instantiation and/or specialization,
3102 : then the NEWDECL must be too. But, it may not yet be marked
3103 : as such if the caller has created NEWDECL, but has not yet
3104 : figured out that it is a redeclaration. */
3105 15915544 : if (!DECL_USE_TEMPLATE (newdecl))
3106 15264822 : DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
3107 :
3108 15915544 : if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
3109 15347468 : DECL_INITIALIZED_IN_CLASS_P (newdecl)
3110 30694936 : |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
3111 : }
3112 :
3113 : /* Don't really know how much of the language-specific
3114 : values we should copy from old to new. */
3115 15915608 : DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
3116 :
3117 15915608 : if (LANG_DECL_HAS_MIN (newdecl))
3118 : {
3119 15915608 : DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
3120 15915608 : if (DECL_TEMPLATE_INFO (newdecl))
3121 : {
3122 650755 : new_template_info = DECL_TEMPLATE_INFO (newdecl);
3123 650755 : if (DECL_TEMPLATE_INSTANTIATION (olddecl)
3124 650755 : && DECL_TEMPLATE_SPECIALIZATION (newdecl))
3125 : /* Remember the presence of explicit specialization args. */
3126 1135702 : TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
3127 1135702 : = TINFO_USED_TEMPLATE_ID (new_template_info);
3128 : }
3129 :
3130 : /* We don't want to copy template info from a non-templated friend
3131 : (PR105761), but these shouldn't have DECL_TEMPLATE_INFO now. */
3132 15915608 : gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
3133 : || !non_templated_friend_p (olddecl));
3134 15915608 : DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
3135 : }
3136 :
3137 15915608 : if (DECL_DECLARES_FUNCTION_P (newdecl))
3138 : {
3139 : /* Only functions have these fields. */
3140 15407442 : DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
3141 15407442 : DECL_BEFRIENDING_CLASSES (newdecl)
3142 15407442 : = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
3143 15407442 : DECL_BEFRIENDING_CLASSES (olddecl));
3144 : /* DECL_THUNKS is only valid for virtual functions,
3145 : otherwise it is a DECL_FRIEND_CONTEXT. */
3146 15407442 : if (DECL_VIRTUAL_P (newdecl))
3147 634550 : SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
3148 29545784 : else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
3149 381125 : SET_DECL_FRIEND_CONTEXT (olddecl, fc);
3150 : }
3151 508166 : else if (VAR_P (newdecl))
3152 : {
3153 : /* Only variables have this field. */
3154 508102 : if (VAR_HAD_UNKNOWN_BOUND (olddecl))
3155 198 : SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
3156 : }
3157 : }
3158 :
3159 15968833 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3160 : {
3161 15407442 : merge_decl_arguments (newdecl, olddecl, new_defines_function,
3162 : types_match, false);
3163 :
3164 15407442 : if (DECL_TEMPLATE_INSTANTIATION (olddecl)
3165 15407442 : && !DECL_TEMPLATE_INSTANTIATION (newdecl))
3166 : {
3167 : /* If newdecl is not a specialization, then it is not a
3168 : template-related function at all. And that means that we
3169 : should have exited above, returning 0. */
3170 567848 : gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
3171 :
3172 567848 : if (DECL_ODR_USED (olddecl))
3173 : /* From [temp.expl.spec]:
3174 :
3175 : If a template, a member template or the member of a class
3176 : template is explicitly specialized then that
3177 : specialization shall be declared before the first use of
3178 : that specialization that would cause an implicit
3179 : instantiation to take place, in every translation unit in
3180 : which such a use occurs. */
3181 0 : error ("explicit specialization of %qD after first use",
3182 : olddecl);
3183 :
3184 567848 : SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
3185 567848 : DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
3186 1135543 : && DECL_NONGNU_INLINE_P (newdecl));
3187 :
3188 : /* Don't propagate visibility from the template to the
3189 : specialization here. We'll do that in determine_visibility if
3190 : appropriate. */
3191 567848 : DECL_VISIBILITY_SPECIFIED (olddecl) = 0;
3192 :
3193 : /* [temp.expl.spec/14] We don't inline explicit specialization
3194 : just because the primary template says so. */
3195 567848 : gcc_assert (!merge_attr);
3196 :
3197 567848 : DECL_DECLARED_INLINE_P (olddecl)
3198 567848 : = DECL_DECLARED_INLINE_P (newdecl);
3199 :
3200 567848 : DECL_DISREGARD_INLINE_LIMITS (olddecl)
3201 567848 : = DECL_DISREGARD_INLINE_LIMITS (newdecl);
3202 :
3203 567848 : DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
3204 : }
3205 14839594 : else if (new_defines_function && DECL_INITIAL (olddecl))
3206 : {
3207 : /* Never inline re-defined extern inline functions.
3208 : FIXME: this could be better handled by keeping both
3209 : function as separate declarations. */
3210 78 : DECL_UNINLINABLE (newdecl) = 1;
3211 : }
3212 : else
3213 : {
3214 14839516 : if (DECL_PENDING_INLINE_P (olddecl))
3215 : {
3216 6 : DECL_PENDING_INLINE_P (newdecl) = 1;
3217 6 : DECL_PENDING_INLINE_INFO (newdecl)
3218 12 : = DECL_PENDING_INLINE_INFO (olddecl);
3219 : }
3220 14839510 : else if (DECL_PENDING_INLINE_P (newdecl))
3221 : ;
3222 14839510 : else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
3223 14839510 : DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
3224 29679020 : = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
3225 :
3226 14839516 : DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
3227 :
3228 44518548 : DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
3229 29679032 : = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
3230 :
3231 29679032 : DECL_DISREGARD_INLINE_LIMITS (newdecl)
3232 14839516 : = DECL_DISREGARD_INLINE_LIMITS (olddecl)
3233 14839516 : = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
3234 29266172 : || DECL_DISREGARD_INLINE_LIMITS (olddecl));
3235 : }
3236 :
3237 : /* Preserve abstractness on cloned [cd]tors. */
3238 15407442 : DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
3239 :
3240 : /* Update newdecl's parms to point at olddecl. */
3241 49020211 : for (tree parm = DECL_ARGUMENTS (newdecl); parm;
3242 33612769 : parm = DECL_CHAIN (parm))
3243 33612769 : DECL_CONTEXT (parm) = olddecl;
3244 :
3245 15407442 : if (! types_match)
3246 : {
3247 201 : SET_DECL_LANGUAGE (olddecl, DECL_LANGUAGE (newdecl));
3248 201 : COPY_DECL_ASSEMBLER_NAME (newdecl, olddecl);
3249 201 : COPY_DECL_RTL (newdecl, olddecl);
3250 : }
3251 15407442 : if (! types_match || new_defines_function)
3252 : {
3253 : /* Update the contracts to reflect the new parameter names. */
3254 9364106 : update_contract_arguments (newdecl, olddecl);
3255 :
3256 : /* Mark the old PARM_DECLs in case std::meta::parameters_of has
3257 : been called on the old declaration and reflections of those
3258 : arguments are held across this point and used later.
3259 : Such PARM_DECLs are no longer present in
3260 : DECL_ARGUMENTS (DECL_CONTEXT (oldarg)) chain. */
3261 9364106 : for (tree oldarg = DECL_ARGUMENTS (olddecl);
3262 32841029 : oldarg; oldarg = DECL_CHAIN (oldarg))
3263 23476923 : OLD_PARM_DECL_P (oldarg) = 1;
3264 :
3265 : /* These need to be copied so that the names are available.
3266 : Note that if the types do match, we'll preserve inline
3267 : info and other bits, but if not, we won't. */
3268 9364106 : DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
3269 9364106 : DECL_RESULT (olddecl) = DECL_RESULT (newdecl);
3270 : }
3271 : /* If redeclaring a builtin function, it stays built in
3272 : if newdecl is a gnu_inline definition, or if newdecl is just
3273 : a declaration. */
3274 15407442 : if (fndecl_built_in_p (olddecl)
3275 15464519 : && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
3276 : {
3277 4044250 : copy_decl_built_in_function (newdecl, olddecl);
3278 : /* If we're keeping the built-in definition, keep the rtl,
3279 : regardless of declaration matches. */
3280 4044250 : COPY_DECL_RTL (olddecl, newdecl);
3281 4044250 : if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
3282 : {
3283 4044244 : enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
3284 4044244 : if (builtin_decl_explicit_p (fncode))
3285 : {
3286 : /* A compatible prototype of these builtin functions
3287 : is seen, assume the runtime implements it with
3288 : the expected semantics. */
3289 4044244 : switch (fncode)
3290 : {
3291 10104 : case BUILT_IN_STPCPY:
3292 10104 : set_builtin_decl_implicit_p (fncode, true);
3293 10104 : break;
3294 4034140 : default:
3295 4034140 : set_builtin_decl_declared_p (fncode, true);
3296 4034140 : break;
3297 : }
3298 : }
3299 :
3300 4044244 : copy_attributes_to_builtin (newdecl);
3301 : }
3302 : }
3303 15407442 : if (new_defines_function)
3304 : /* If defining a function declared with other language
3305 : linkage, use the previously declared language linkage. */
3306 9363905 : SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
3307 6043537 : else if (types_match)
3308 : {
3309 6043336 : DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
3310 : /* Don't clear out the arguments if we're just redeclaring a
3311 : function. */
3312 6043336 : if (DECL_ARGUMENTS (olddecl))
3313 1962390 : DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
3314 : }
3315 : }
3316 561391 : else if (TREE_CODE (newdecl) == NAMESPACE_DECL)
3317 0 : NAMESPACE_LEVEL (newdecl) = NAMESPACE_LEVEL (olddecl);
3318 :
3319 : /* Now preserve various other info from the definition. */
3320 15968833 : TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
3321 15968833 : TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
3322 15968833 : DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
3323 15968833 : COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
3324 :
3325 : /* Warn about conflicting visibility specifications. */
3326 15968833 : if (DECL_VISIBILITY_SPECIFIED (olddecl)
3327 5628173 : && DECL_VISIBILITY_SPECIFIED (newdecl)
3328 15980701 : && DECL_VISIBILITY (newdecl) != DECL_VISIBILITY (olddecl))
3329 : {
3330 12 : auto_diagnostic_group d;
3331 12 : if (warning_at (newdecl_loc, OPT_Wattributes,
3332 : "%qD: visibility attribute ignored because it "
3333 : "conflicts with previous declaration", newdecl))
3334 12 : inform (olddecl_loc,
3335 : "previous declaration of %qD", olddecl);
3336 12 : }
3337 : /* Choose the declaration which specified visibility. */
3338 15968833 : if (DECL_VISIBILITY_SPECIFIED (olddecl))
3339 : {
3340 5628173 : DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
3341 5628173 : DECL_VISIBILITY_SPECIFIED (newdecl) = 1;
3342 : }
3343 : /* Init priority used to be merged from newdecl to olddecl by the memcpy,
3344 : so keep this behavior. */
3345 15968833 : if (VAR_P (newdecl) && DECL_HAS_INIT_PRIORITY_P (newdecl))
3346 : {
3347 10 : SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl));
3348 10 : DECL_HAS_INIT_PRIORITY_P (olddecl) = 1;
3349 : }
3350 : /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED. */
3351 15968833 : if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl))
3352 : {
3353 54 : SET_DECL_ALIGN (newdecl, DECL_ALIGN (olddecl));
3354 54 : DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl);
3355 : }
3356 15968779 : else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
3357 15968779 : && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
3358 3 : DECL_USER_ALIGN (newdecl) = 1;
3359 :
3360 15968833 : DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
3361 31937666 : if (DECL_WARN_IF_NOT_ALIGN (olddecl)
3362 15968833 : > DECL_WARN_IF_NOT_ALIGN (newdecl))
3363 0 : SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
3364 : DECL_WARN_IF_NOT_ALIGN (olddecl));
3365 15968833 : if (TREE_CODE (newdecl) == FIELD_DECL)
3366 0 : DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
3367 :
3368 : /* Merge module entity mapping information. */
3369 15968833 : if (DECL_LANG_SPECIFIC (olddecl)
3370 31884487 : && (DECL_MODULE_ENTITY_P (olddecl)
3371 15915318 : || DECL_MODULE_KEYED_DECLS_P (olddecl)))
3372 : {
3373 336 : retrofit_lang_decl (newdecl);
3374 336 : DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
3375 336 : DECL_MODULE_KEYED_DECLS_P (newdecl) = DECL_MODULE_KEYED_DECLS_P (olddecl);
3376 : }
3377 :
3378 : /* The DECL_LANG_SPECIFIC information in OLDDECL will be replaced
3379 : with that from NEWDECL below. */
3380 15968833 : if (DECL_LANG_SPECIFIC (olddecl))
3381 : {
3382 15915654 : gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
3383 : != DECL_LANG_SPECIFIC (newdecl));
3384 15915654 : ggc_free (DECL_LANG_SPECIFIC (olddecl));
3385 : }
3386 :
3387 : /* Merge the USED information. */
3388 15968833 : if (TREE_USED (olddecl))
3389 504927 : TREE_USED (newdecl) = 1;
3390 15463906 : else if (TREE_USED (newdecl))
3391 62 : TREE_USED (olddecl) = 1;
3392 :
3393 15968833 : if (VAR_P (newdecl))
3394 : {
3395 511746 : if (DECL_READ_P (olddecl))
3396 43781 : DECL_READ_P (newdecl) = 1;
3397 467965 : else if (DECL_READ_P (newdecl))
3398 3 : DECL_READ_P (olddecl) = 1;
3399 : }
3400 :
3401 15968833 : if (DECL_PRESERVE_P (olddecl))
3402 48 : DECL_PRESERVE_P (newdecl) = 1;
3403 15968785 : else if (DECL_PRESERVE_P (newdecl))
3404 75 : DECL_PRESERVE_P (olddecl) = 1;
3405 :
3406 : /* Merge the DECL_FUNCTION_VERSIONED information. newdecl will be copied
3407 : to olddecl and deleted. */
3408 15968833 : if (TREE_CODE (newdecl) == FUNCTION_DECL
3409 31376275 : && DECL_FUNCTION_VERSIONED (olddecl))
3410 : {
3411 : /* Set the flag for newdecl so that it gets copied to olddecl. */
3412 258 : DECL_FUNCTION_VERSIONED (newdecl) = 1;
3413 : /* newdecl will be purged after copying to olddecl and is no longer
3414 : a version. */
3415 258 : cgraph_node::delete_function_version_by_decl (newdecl);
3416 : }
3417 :
3418 15968833 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3419 : {
3420 15407442 : int function_size;
3421 15407442 : struct symtab_node *snode = symtab_node::get (olddecl);
3422 :
3423 15407442 : function_size = sizeof (struct tree_decl_common);
3424 :
3425 15407442 : memcpy ((char *) olddecl + sizeof (struct tree_common),
3426 : (char *) newdecl + sizeof (struct tree_common),
3427 : function_size - sizeof (struct tree_common));
3428 :
3429 15407442 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3430 : (char *) newdecl + sizeof (struct tree_decl_common),
3431 : sizeof (struct tree_function_decl) - sizeof (struct tree_decl_common));
3432 :
3433 : /* Preserve symtab node mapping. */
3434 15407442 : olddecl->decl_with_vis.symtab_node = snode;
3435 :
3436 15407442 : if (new_template_info)
3437 : /* If newdecl is a template instantiation, it is possible that
3438 : the following sequence of events has occurred:
3439 :
3440 : o A friend function was declared in a class template. The
3441 : class template was instantiated.
3442 :
3443 : o The instantiation of the friend declaration was
3444 : recorded on the instantiation list, and is newdecl.
3445 :
3446 : o Later, however, instantiate_class_template called pushdecl
3447 : on the newdecl to perform name injection. But, pushdecl in
3448 : turn called duplicate_decls when it discovered that another
3449 : declaration of a global function with the same name already
3450 : existed.
3451 :
3452 : o Here, in duplicate_decls, we decided to clobber newdecl.
3453 :
3454 : If we're going to do that, we'd better make sure that
3455 : olddecl, and not newdecl, is on the list of
3456 : instantiations so that if we try to do the instantiation
3457 : again we won't get the clobbered declaration. */
3458 650746 : reregister_specialization (newdecl,
3459 : new_template_info,
3460 : olddecl);
3461 : }
3462 : else
3463 : {
3464 561391 : size_t size = tree_code_size (TREE_CODE (newdecl));
3465 :
3466 561391 : memcpy ((char *) olddecl + sizeof (struct tree_common),
3467 : (char *) newdecl + sizeof (struct tree_common),
3468 : sizeof (struct tree_decl_common) - sizeof (struct tree_common));
3469 :
3470 561391 : switch (TREE_CODE (newdecl))
3471 : {
3472 561391 : case LABEL_DECL:
3473 561391 : case VAR_DECL:
3474 561391 : case RESULT_DECL:
3475 561391 : case PARM_DECL:
3476 561391 : case FIELD_DECL:
3477 561391 : case TYPE_DECL:
3478 561391 : case CONST_DECL:
3479 561391 : {
3480 561391 : struct symtab_node *snode = NULL;
3481 :
3482 561391 : if (VAR_P (newdecl)
3483 561391 : && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
3484 3 : || DECL_EXTERNAL (olddecl)))
3485 511746 : snode = symtab_node::get (olddecl);
3486 561391 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3487 : (char *) newdecl + sizeof (struct tree_decl_common),
3488 : size - sizeof (struct tree_decl_common)
3489 561391 : + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
3490 561391 : if (VAR_P (newdecl))
3491 511746 : olddecl->decl_with_vis.symtab_node = snode;
3492 : }
3493 : break;
3494 0 : default:
3495 0 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3496 : (char *) newdecl + sizeof (struct tree_decl_common),
3497 : sizeof (struct tree_decl_non_common) - sizeof (struct tree_decl_common)
3498 0 : + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
3499 0 : break;
3500 : }
3501 : }
3502 :
3503 15968833 : if (VAR_OR_FUNCTION_DECL_P (newdecl))
3504 : {
3505 15919188 : if (DECL_EXTERNAL (olddecl)
3506 513123 : || TREE_PUBLIC (olddecl)
3507 15919257 : || TREE_STATIC (olddecl))
3508 : {
3509 : /* Merge the section attribute.
3510 : We want to issue an error if the sections conflict but that must be
3511 : done later in decl_attributes since we are called before attributes
3512 : are assigned. */
3513 15919188 : if (DECL_SECTION_NAME (newdecl) != NULL)
3514 7 : set_decl_section_name (olddecl, newdecl);
3515 :
3516 15919188 : if (DECL_ONE_ONLY (newdecl))
3517 : {
3518 0 : struct symtab_node *oldsym, *newsym;
3519 0 : if (TREE_CODE (olddecl) == FUNCTION_DECL)
3520 0 : oldsym = cgraph_node::get_create (olddecl);
3521 : else
3522 0 : oldsym = varpool_node::get_create (olddecl);
3523 0 : newsym = symtab_node::get (newdecl);
3524 0 : oldsym->set_comdat_group (newsym->get_comdat_group ());
3525 : }
3526 : }
3527 :
3528 15919188 : if (VAR_P (newdecl)
3529 15919188 : && CP_DECL_THREAD_LOCAL_P (newdecl))
3530 : {
3531 404 : CP_DECL_THREAD_LOCAL_P (olddecl) = true;
3532 404 : if (!processing_template_decl)
3533 371 : set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl));
3534 : }
3535 : }
3536 :
3537 15968833 : DECL_UID (olddecl) = olddecl_uid;
3538 :
3539 : /* NEWDECL contains the merged attribute lists.
3540 : Update OLDDECL to be the same. */
3541 15968833 : DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
3542 :
3543 : /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
3544 : so that encode_section_info has a chance to look at the new decl
3545 : flags and attributes. */
3546 15968833 : if (DECL_RTL_SET_P (olddecl)
3547 15968848 : && (TREE_CODE (olddecl) == FUNCTION_DECL
3548 15 : || (VAR_P (olddecl)
3549 15 : && TREE_STATIC (olddecl))))
3550 15 : make_decl_rtl (olddecl);
3551 :
3552 : /* The NEWDECL will no longer be needed. Because every out-of-class
3553 : declaration of a member results in a call to duplicate_decls,
3554 : freeing these nodes represents in a significant savings.
3555 :
3556 : Before releasing the node, be sore to remove function from symbol
3557 : table that might have been inserted there to record comdat group.
3558 : Be sure to however do not free DECL_STRUCT_FUNCTION because this
3559 : structure is shared in between newdecl and oldecl. */
3560 15968833 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3561 15407442 : DECL_STRUCT_FUNCTION (newdecl) = NULL;
3562 15968833 : if (VAR_OR_FUNCTION_DECL_P (newdecl))
3563 : {
3564 15919188 : struct symtab_node *snode = symtab_node::get (newdecl);
3565 15919188 : if (snode)
3566 399 : snode->remove ();
3567 : }
3568 :
3569 15968833 : if (TREE_CODE (olddecl) == FUNCTION_DECL)
3570 : {
3571 15407442 : tree clone;
3572 15949913 : FOR_EACH_CLONE (clone, olddecl)
3573 : {
3574 542471 : DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
3575 542471 : DECL_PRESERVE_P (clone) |= DECL_PRESERVE_P (olddecl);
3576 : }
3577 : }
3578 :
3579 : /* Remove the associated constraints for newdecl, if any, before
3580 : reclaiming memory. */
3581 15968833 : if (flag_concepts)
3582 15701747 : remove_constraints (newdecl);
3583 :
3584 15968833 : if (flag_contracts)
3585 : /* Remove the specifiers, and then remove the decl from the lookup. */
3586 1502930 : remove_decl_with_fn_contracts_specifiers (newdecl);
3587 :
3588 : /* And similarly for any module tracking data. */
3589 15968833 : if (modules_p ())
3590 43835 : remove_defining_module (newdecl);
3591 :
3592 15968833 : ggc_free (newdecl);
3593 :
3594 15968833 : return olddecl;
3595 : }
3596 :
3597 : /* Return zero if the declaration NEWDECL is valid
3598 : when the declaration OLDDECL (assumed to be for the same name)
3599 : has already been seen.
3600 : Otherwise return an error message format string with a %s
3601 : where the identifier should go. */
3602 :
3603 : static const char *
3604 16145252 : redeclaration_error_message (tree newdecl, tree olddecl)
3605 : {
3606 16145288 : if (TREE_CODE (newdecl) == TYPE_DECL)
3607 : {
3608 : /* Because C++ can put things into name space for free,
3609 : constructs like "typedef struct foo { ... } foo"
3610 : would look like an erroneous redeclaration. */
3611 82808 : if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
3612 : return NULL;
3613 : else
3614 : return G_("redefinition of %q#D");
3615 : }
3616 16062480 : else if (TREE_CODE (newdecl) == FUNCTION_DECL)
3617 : {
3618 : /* If this is a pure function, its olddecl will actually be
3619 : the original initialization to `0' (which we force to call
3620 : abort()). Don't complain about redefinition in this case. */
3621 22897548 : if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
3622 11448792 : && DECL_INITIAL (olddecl) == NULL_TREE)
3623 : return NULL;
3624 :
3625 : /* If both functions come from different namespaces, this is not
3626 : a redeclaration - this is a conflict with a used function. */
3627 22897518 : if (DECL_NAMESPACE_SCOPE_P (olddecl)
3628 2685910 : && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
3629 11448762 : && ! decls_match (olddecl, newdecl))
3630 : return G_("%qD conflicts with used function");
3631 :
3632 : /* We'll complain about linkage mismatches in
3633 : warn_extern_redeclared_static. */
3634 :
3635 : /* Defining the same name twice is no good. */
3636 11448759 : if (decl_defined_p (olddecl)
3637 11448759 : && decl_defined_p (newdecl))
3638 : {
3639 306 : if (DECL_NAME (olddecl) == NULL_TREE)
3640 : return G_("%q#D not declared in class");
3641 447 : else if (!GNU_INLINE_P (olddecl)
3642 393 : || GNU_INLINE_P (newdecl))
3643 222 : return G_("redefinition of %q#D");
3644 : }
3645 :
3646 13275357 : if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
3647 : {
3648 1775378 : bool olda = GNU_INLINE_P (olddecl);
3649 1775378 : bool newa = GNU_INLINE_P (newdecl);
3650 :
3651 1775378 : if (olda != newa)
3652 : {
3653 15 : if (newa)
3654 : return G_("%q+D redeclared inline with "
3655 : "%<gnu_inline%> attribute");
3656 : else
3657 : return G_("%q+D redeclared inline without "
3658 : "%<gnu_inline%> attribute");
3659 : }
3660 : }
3661 :
3662 : /* [class.compare.default]: A definition of a comparison operator as
3663 : defaulted that appears in a class shall be the first declaration of
3664 : that function. */
3665 11448522 : special_function_kind sfk = special_function_p (olddecl);
3666 11448522 : if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
3667 : return G_("comparison operator %q+D defaulted after "
3668 : "its first declaration");
3669 :
3670 11448519 : check_abi_tag_redeclaration
3671 11448519 : (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
3672 11448519 : lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
3673 :
3674 11448519 : return NULL;
3675 : }
3676 4613706 : else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3677 : {
3678 4101597 : tree nt, ot;
3679 :
3680 4101597 : if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
3681 : return G_("redefinition of %q#D");
3682 :
3683 4101591 : if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
3684 36 : return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
3685 36 : DECL_TEMPLATE_RESULT (olddecl));
3686 :
3687 4101555 : if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
3688 : return NULL;
3689 :
3690 4101543 : nt = DECL_TEMPLATE_RESULT (newdecl);
3691 4101543 : if (DECL_TEMPLATE_INFO (nt))
3692 990044 : nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
3693 4101543 : ot = DECL_TEMPLATE_RESULT (olddecl);
3694 4101543 : if (DECL_TEMPLATE_INFO (ot))
3695 4101543 : ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
3696 6890290 : if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
3697 4101582 : && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
3698 15 : return G_("redefinition of %q#D");
3699 :
3700 6637431 : if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
3701 : {
3702 1836748 : bool olda = GNU_INLINE_P (ot);
3703 1836748 : bool newa = GNU_INLINE_P (nt);
3704 :
3705 1836748 : if (olda != newa)
3706 : {
3707 0 : if (newa)
3708 : return G_("%q+D redeclared inline with "
3709 : "%<gnu_inline%> attribute");
3710 : else
3711 : return G_("%q+D redeclared inline without "
3712 : "%<gnu_inline%> attribute");
3713 : }
3714 : }
3715 :
3716 : /* Core issue #226 (C++11):
3717 :
3718 : If a friend function template declaration specifies a
3719 : default template-argument, that declaration shall be a
3720 : definition and shall be the only declaration of the
3721 : function template in the translation unit. */
3722 4101528 : if ((cxx_dialect != cxx98)
3723 4084947 : && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
3724 4310386 : && !check_default_tmpl_args (nt, DECL_TEMPLATE_PARMS (newdecl),
3725 : /*is_primary=*/true,
3726 : /*is_partial=*/false,
3727 : /*is_friend_decl=*/2))
3728 : return G_("redeclaration of friend %q#D "
3729 : "may not have default template arguments");
3730 :
3731 4101525 : return NULL;
3732 : }
3733 512109 : else if (VAR_P (newdecl)
3734 512025 : && (CP_DECL_THREAD_LOCAL_P (newdecl)
3735 512025 : != CP_DECL_THREAD_LOCAL_P (olddecl))
3736 512156 : && (! DECL_LANG_SPECIFIC (olddecl)
3737 44 : || ! CP_DECL_THREADPRIVATE_P (olddecl)
3738 41 : || CP_DECL_THREAD_LOCAL_P (newdecl)))
3739 : {
3740 : /* Only variables can be thread-local, and all declarations must
3741 : agree on this property. */
3742 6 : if (CP_DECL_THREAD_LOCAL_P (newdecl))
3743 : return G_("thread-local declaration of %q#D follows "
3744 : "non-thread-local declaration");
3745 : else
3746 3 : return G_("non-thread-local declaration of %q#D follows "
3747 : "thread-local declaration");
3748 : }
3749 512103 : else if (toplevel_bindings_p () || DECL_NAMESPACE_SCOPE_P (newdecl))
3750 : {
3751 : /* The objects have been declared at namespace scope. If either
3752 : is a member of an anonymous union, then this is an invalid
3753 : redeclaration. For example:
3754 :
3755 : int i;
3756 : union { int i; };
3757 :
3758 : is invalid. */
3759 511869 : if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
3760 1023807 : || (VAR_P (olddecl) && DECL_ANON_UNION_VAR_P (olddecl)))
3761 : return G_("redeclaration of %q#D");
3762 : /* If at least one declaration is a reference, there is no
3763 : conflict. For example:
3764 :
3765 : int i = 3;
3766 : extern int i;
3767 :
3768 : is valid. */
3769 511935 : if (DECL_EXTERNAL (newdecl) || DECL_EXTERNAL (olddecl))
3770 : return NULL;
3771 :
3772 : /* Static data member declared outside a class definition
3773 : if the variable is defined within the class with constexpr
3774 : specifier is declaration rather than definition (and
3775 : deprecated). */
3776 2820 : if (cxx_dialect >= cxx17
3777 2747 : && VAR_P (olddecl)
3778 2691 : && DECL_CLASS_SCOPE_P (olddecl)
3779 2649 : && DECL_DECLARED_CONSTEXPR_P (olddecl)
3780 5457 : && !DECL_INITIAL (newdecl))
3781 : {
3782 2637 : DECL_EXTERNAL (newdecl) = 1;
3783 : /* For now, only warn with explicit -Wdeprecated. */
3784 2637 : if (OPTION_SET_P (warn_deprecated))
3785 : {
3786 40 : auto_diagnostic_group d;
3787 40 : if (warning_at (DECL_SOURCE_LOCATION (newdecl), OPT_Wdeprecated,
3788 : "redundant redeclaration of %<constexpr%> "
3789 : "static data member %qD", newdecl))
3790 4 : inform (DECL_SOURCE_LOCATION (olddecl),
3791 : "previous declaration of %qD", olddecl);
3792 40 : }
3793 2637 : return NULL;
3794 : }
3795 :
3796 : /* Reject two definitions. */
3797 : return G_("redefinition of %q#D");
3798 : }
3799 : else
3800 : {
3801 : /* Objects declared with block scope: */
3802 : /* Reject two definitions, and reject a definition
3803 : together with an external reference. */
3804 153 : if (!(DECL_EXTERNAL (newdecl) && DECL_EXTERNAL (olddecl)))
3805 : return G_("redeclaration of %q#D");
3806 : return NULL;
3807 : }
3808 : }
3809 :
3810 :
3811 : /* Hash and equality functions for the named_label table. */
3812 :
3813 : hashval_t
3814 79451 : named_label_hash::hash (const value_type entry)
3815 : {
3816 79451 : return IDENTIFIER_HASH_VALUE (entry->name);
3817 : }
3818 :
3819 : bool
3820 76328 : named_label_hash::equal (const value_type entry, compare_type name)
3821 : {
3822 76328 : return name == entry->name;
3823 : }
3824 :
3825 : /* Look for a label named ID in the current function. If one cannot
3826 : be found, create one. Return the named_label_entry, or NULL on
3827 : failure. */
3828 :
3829 : static named_label_entry *
3830 24374 : lookup_label_1 (tree id, bool making_local_p)
3831 : {
3832 24374 : auto_cond_timevar tv (TV_NAME_LOOKUP);
3833 :
3834 : /* You can't use labels at global scope. */
3835 24374 : if (current_function_decl == NULL_TREE)
3836 : {
3837 3 : error ("label %qE referenced outside of any function", id);
3838 3 : return NULL;
3839 : }
3840 :
3841 24371 : if (!named_labels)
3842 4699 : named_labels = hash_table<named_label_hash>::create_ggc (13);
3843 :
3844 24371 : hashval_t hash = IDENTIFIER_HASH_VALUE (id);
3845 24371 : named_label_entry **slot
3846 24371 : = named_labels->find_slot_with_hash (id, hash, INSERT);
3847 24371 : named_label_entry *old = *slot;
3848 :
3849 24371 : if (old && old->label_decl)
3850 : {
3851 3464 : if (!making_local_p)
3852 : return old;
3853 :
3854 21 : if (old->binding_level == current_binding_level)
3855 : {
3856 0 : auto_diagnostic_group d;
3857 0 : error ("local label %qE conflicts with existing label", id);
3858 0 : inform (DECL_SOURCE_LOCATION (old->label_decl), "previous label");
3859 0 : return NULL;
3860 0 : }
3861 : }
3862 :
3863 : /* We are making a new decl, create or reuse the named_label_entry */
3864 20949 : named_label_entry *ent = NULL;
3865 33 : if (old && !old->label_decl)
3866 : ent = old;
3867 : else
3868 : {
3869 20916 : ent = ggc_cleared_alloc<named_label_entry> ();
3870 20916 : ent->name = id;
3871 20916 : ent->outer = old;
3872 20916 : *slot = ent;
3873 : }
3874 :
3875 : /* Now create the LABEL_DECL. */
3876 20928 : tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
3877 :
3878 20928 : DECL_CONTEXT (decl) = current_function_decl;
3879 20928 : SET_DECL_MODE (decl, VOIDmode);
3880 20928 : if (making_local_p)
3881 : {
3882 219 : C_DECLARED_LABEL_FLAG (decl) = true;
3883 219 : DECL_CHAIN (decl) = current_binding_level->names;
3884 219 : current_binding_level->names = decl;
3885 : }
3886 :
3887 20928 : ent->label_decl = decl;
3888 :
3889 20928 : return ent;
3890 24374 : }
3891 :
3892 : /* Wrapper for lookup_label_1. */
3893 :
3894 : tree
3895 2958 : lookup_label (tree id)
3896 : {
3897 2958 : named_label_entry *ent = lookup_label_1 (id, false);
3898 2958 : return ent ? ent->label_decl : NULL_TREE;
3899 : }
3900 :
3901 : /* Remember that we've seen &&ID. */
3902 :
3903 : void
3904 253 : mark_label_addressed (tree id)
3905 : {
3906 253 : named_label_entry *ent = lookup_label_1 (id, false);
3907 253 : ent->addressed = true;
3908 253 : }
3909 :
3910 : tree
3911 219 : declare_local_label (tree id)
3912 : {
3913 219 : named_label_entry *ent = lookup_label_1 (id, true);
3914 219 : return ent ? ent->label_decl : NULL_TREE;
3915 : }
3916 :
3917 : /* Returns true if it is ill-formed to jump past the declaration of DECL. */
3918 :
3919 : static bool
3920 2937608 : decl_jump_unsafe (tree decl)
3921 : {
3922 : /* [stmt.dcl]/3: A program that jumps from a point where a local variable
3923 : with automatic storage duration is not in scope to a point where it is
3924 : in scope is ill-formed unless the variable has scalar type, class type
3925 : with a trivial default constructor and a trivial destructor, a
3926 : cv-qualified version of one of these types, or an array of one of the
3927 : preceding types and is declared without an initializer (8.5). */
3928 2937608 : tree type = TREE_TYPE (decl);
3929 :
3930 2937608 : return (type != error_mark_node
3931 2937590 : && VAR_P (decl)
3932 15070 : && !TREE_STATIC (decl)
3933 2952542 : && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
3934 12992 : || variably_modified_type_p (type, NULL_TREE)));
3935 : }
3936 :
3937 : /* Returns true if decl is an automatic variable with vacuous initialization
3938 : except when it is [[indeterminate]] or [[gnu::uninitialized]].
3939 : Jumps across such initialization need to be instrumented for
3940 : !!flag_auto_var_init. */
3941 :
3942 : static bool
3943 2935657 : decl_instrument_init_bypass_p (tree decl)
3944 : {
3945 2935657 : tree type = TREE_TYPE (decl);
3946 :
3947 2935657 : return (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
3948 2183121 : && !processing_template_decl
3949 2182875 : && type != error_mark_node
3950 2182869 : && VAR_P (decl)
3951 1070 : && !TREE_STATIC (decl)
3952 1049 : && !DECL_EXTERNAL (decl)
3953 2070 : && !(DECL_NONTRIVIALLY_INITIALIZED_P (decl)
3954 1035 : || variably_modified_type_p (type, NULL_TREE))
3955 1035 : && !lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (decl))
3956 1035 : && !lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
3957 2936692 : && !DECL_HAS_VALUE_EXPR_P (decl));
3958 : }
3959 :
3960 : /* Build .DEFERRED_INIT call for DECL. */
3961 :
3962 : static tree
3963 140 : build_deferred_init_call (tree decl)
3964 : {
3965 140 : tree decl_size_arg = TYPE_SIZE_UNIT (TREE_TYPE (decl));
3966 280 : tree init_type_arg = build_int_cst (integer_type_node,
3967 140 : (int) flag_auto_var_init);
3968 140 : location_t loc = DECL_SOURCE_LOCATION (decl);
3969 140 : tree decl_name;
3970 :
3971 140 : if (DECL_NAME (decl))
3972 140 : decl_name = build_string_literal (DECL_NAME (decl));
3973 : else
3974 : {
3975 0 : char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3];
3976 0 : sprintf (decl_name_anonymous, "D.%u", DECL_UID (decl));
3977 0 : decl_name = build_string_literal (decl_name_anonymous);
3978 : }
3979 :
3980 140 : tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
3981 140 : TREE_TYPE (decl), 3,
3982 : decl_size_arg, init_type_arg,
3983 : decl_name);
3984 140 : tree ret = build2_loc (loc, MODIFY_EXPR, void_type_node, decl, call);
3985 140 : return build_stmt (loc, EXPR_STMT, ret);
3986 : }
3987 :
3988 : /* Emit before ITER (and any labels/case labels before it) code like
3989 : if (0)
3990 : {
3991 : l1:
3992 : v4 = .DEFERRED_INIT (sizeof (v4), ?, "v4");
3993 : v3 = .DEFERRED_INIT (sizeof (v3), ?, "v3");
3994 : v2 = .DEFERRED_INIT (sizeof (v2), ?, "v2");
3995 : v1 = .DEFERRED_INIT (sizeof (v1), ?, "v1");
3996 : }
3997 : and return l1 label, or if it already exists, assert it has the
3998 : .DEFERRED_INIT calls for the right decls in the right order and
3999 : amend it, either by adding extra labels in between or further
4000 : ,DEFERRED_INIT calls before the first label and extra label before
4001 : that. If CASE_LABEL is non-NULL, emit that CASE_LABEL_EXPR instead
4002 : of adding a label. DECLS points to an array of NDECLS VAR_DECLs
4003 : which should be initialized. */
4004 :
4005 : static tree
4006 127 : maybe_add_deferred_init_calls (tree_stmt_iterator iter, tree case_label,
4007 : tree *decls, unsigned ndecls)
4008 : {
4009 127 : tree lab = NULL_TREE;
4010 191 : for (; !tsi_end_p (iter); tsi_prev (&iter))
4011 : {
4012 185 : switch (TREE_CODE (tsi_stmt (iter)))
4013 : {
4014 64 : case LABEL_EXPR:
4015 64 : case CASE_LABEL_EXPR:
4016 64 : case DEBUG_BEGIN_STMT:
4017 64 : continue;
4018 : default:
4019 : break;
4020 : }
4021 : break;
4022 : }
4023 127 : if (!tsi_end_p (iter)
4024 121 : && TREE_CODE (tsi_stmt (iter)) == IF_STMT
4025 204 : && IF_STMT_VACUOUS_INIT_P (tsi_stmt (iter)))
4026 : {
4027 : /* Found IF_STMT added for this or some adjacent
4028 : LABEL_EXPR/CASE_LABEL_EXPR by an earlier call to this function.
4029 : The decls are ordered so that we can always reuse it. Sometimes
4030 : by no modifications at all and just returning the right label
4031 : which was added already before, sometimes by adding a label in
4032 : between two previously added .DEFERRED_INIT calls and sometimes
4033 : by adding extra statements (.DEFERRED_INIT calls and LABEL_EXPR
4034 : before that) before the statements in IF_STMT body. */
4035 71 : tree then_clause = THEN_CLAUSE (tsi_stmt (iter));
4036 71 : iter = tsi_last (then_clause);
4037 71 : bool add = false;
4038 381 : for (unsigned int i = 0; i < ndecls; ++i)
4039 : {
4040 310 : tree decl = decls[i];
4041 310 : if (!add)
4042 : {
4043 : /* Skip over labels/case labels after .DEFERRED_INIT for the
4044 : DECL we are looking for. */
4045 399 : while (!tsi_end_p (iter)
4046 399 : && (TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR
4047 286 : || (TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR
4048 26 : && !case_label)))
4049 119 : tsi_prev (&iter);
4050 280 : if (tsi_end_p (iter))
4051 : {
4052 : /* Reached the start, we'll need to prepend further
4053 : statements. */
4054 20 : add = true;
4055 20 : iter = tsi_start (then_clause);
4056 : }
4057 : else
4058 : {
4059 : /* Found something, assert it is .DEFERRED_INIT for
4060 : DECL. */
4061 260 : tree t = tsi_stmt (iter);
4062 260 : gcc_checking_assert (TREE_CODE (t) == EXPR_STMT);
4063 260 : t = EXPR_STMT_EXPR (t);
4064 260 : gcc_checking_assert (TREE_CODE (t) == MODIFY_EXPR
4065 : && TREE_OPERAND (t, 0) == decl
4066 : && (TREE_CODE (TREE_OPERAND (t, 1))
4067 : == CALL_EXPR));
4068 260 : t = TREE_OPERAND (t, 1);
4069 260 : gcc_checking_assert (CALL_EXPR_FN (t) == NULL_TREE
4070 : && (CALL_EXPR_IFN (t)
4071 : == IFN_DEFERRED_INIT));
4072 260 : tsi_prev (&iter);
4073 : }
4074 : }
4075 280 : if (add)
4076 : {
4077 : /* If reached the start in this or some earlier iteration,
4078 : prepend .DEFERRED_INIT call for DECL. */
4079 50 : tree t = build_deferred_init_call (decl);
4080 50 : STMT_IS_FULL_EXPR_P (t) = 1;
4081 50 : tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
4082 : }
4083 : }
4084 71 : if (!add)
4085 : {
4086 : /* If .DEFERRED_INIT calls for all the decls were already there,
4087 : skip over case labels and if we find a LABEL_EXPR, return
4088 : its label. */
4089 63 : while (!tsi_end_p (iter)
4090 63 : && !case_label
4091 117 : && TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR)
4092 12 : tsi_prev (&iter);
4093 51 : if (tsi_end_p (iter))
4094 : {
4095 : /* Only case labels were found and we are looking for normal
4096 : label, we'll need to add it. */
4097 0 : add = true;
4098 0 : iter = tsi_start (then_clause);
4099 : }
4100 51 : else if (!case_label
4101 51 : && TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR)
4102 : /* Return existing label. */
4103 21 : lab = LABEL_EXPR_LABEL (tsi_stmt (iter));
4104 : else
4105 : {
4106 : /* We'll need to add a LABEL_EXPR or move CASE_LABEL_EXPR. */
4107 30 : gcc_checking_assert (case_label
4108 : || (TREE_CODE (tsi_stmt (iter))
4109 : == EXPR_STMT));
4110 30 : add = true;
4111 30 : tsi_next (&iter);
4112 30 : gcc_checking_assert (!tsi_end_p (iter));
4113 : }
4114 : }
4115 21 : if (add)
4116 : {
4117 50 : tree t;
4118 50 : if (case_label)
4119 : t = case_label;
4120 : else
4121 : {
4122 41 : lab = create_artificial_label (UNKNOWN_LOCATION);
4123 41 : t = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
4124 : }
4125 50 : tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
4126 : }
4127 : }
4128 : else
4129 : {
4130 : /* No IF_STMT created by this function found. Create it all
4131 : from scratch, so a LABEL_EXPR (or moved CASE_LABEL_EXPR)
4132 : followed by .DEFERRED_INIT calls inside of a new if (0). */
4133 56 : tree new_then = push_stmt_list ();
4134 56 : if (!case_label)
4135 : {
4136 23 : lab = create_artificial_label (UNKNOWN_LOCATION);
4137 23 : add_stmt (build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab));
4138 : }
4139 : else
4140 33 : add_stmt (case_label);
4141 146 : for (unsigned int i = ndecls; i; --i)
4142 90 : add_stmt (build_deferred_init_call (decls[i - 1]));
4143 56 : new_then = pop_stmt_list (new_then);
4144 56 : tree stmt = build4 (IF_STMT, void_type_node, boolean_false_node,
4145 : new_then, void_node, NULL_TREE);
4146 56 : IF_STMT_VACUOUS_INIT_P (stmt) = 1;
4147 56 : if (tsi_end_p (iter))
4148 : {
4149 6 : iter = tsi_start (iter.container);
4150 6 : tsi_link_before (&iter, stmt, TSI_SAME_STMT);
4151 : }
4152 : else
4153 50 : tsi_link_after (&iter, stmt, TSI_CONTINUE_LINKING);
4154 : }
4155 127 : return lab;
4156 : }
4157 :
4158 : /* Adjust backward gotos to named label ENT if they jump over vacuous
4159 : initializers if !!flag_auto_var_init. ITER is the location of
4160 : LABEL_EXPR for that named label. */
4161 :
4162 : static void
4163 19 : adjust_backward_goto (named_label_entry *ent, tree_stmt_iterator iter)
4164 : {
4165 19 : auto_vec<tree, 4> decls;
4166 19 : unsigned int i, max_cnt = ent->direct_goto->last ().n_bad_decls;
4167 19 : tree decl;
4168 88 : FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, i, decl)
4169 88 : if (!decl_jump_unsafe (decl))
4170 : {
4171 88 : gcc_checking_assert (decl_instrument_init_bypass_p (decl));
4172 88 : decls.safe_push (decl);
4173 176 : if (decls.length () == max_cnt)
4174 : break;
4175 : }
4176 19 : named_label_bck_direct_goto *dgoto;
4177 19 : unsigned last = 0;
4178 19 : tree lab = NULL_TREE;
4179 103 : FOR_EACH_VEC_SAFE_ELT_REVERSE (ent->direct_goto, i, dgoto)
4180 : {
4181 46 : if (dgoto->n_bad_decls != last)
4182 : {
4183 40 : last = dgoto->n_bad_decls;
4184 80 : lab = maybe_add_deferred_init_calls (iter, NULL_TREE,
4185 : decls.address (), last);
4186 : }
4187 46 : *dgoto->direct_goto = lab;
4188 : }
4189 19 : }
4190 :
4191 : /* A subroutine of check_previous_goto_1 and check_goto to identify a branch
4192 : to the user. */
4193 :
4194 : static bool
4195 286 : identify_goto (tree decl, location_t loc, const location_t *locus,
4196 : enum diagnostics::kind diag_kind, bool computed)
4197 : {
4198 286 : if (computed)
4199 43 : diag_kind = diagnostics::kind::warning;
4200 286 : auto_diagnostic_group d;
4201 286 : bool complained
4202 373 : = emit_diagnostic (diag_kind, loc, 0,
4203 : decl ? G_("jump to label %qD")
4204 : : G_("jump to case label"), decl);
4205 286 : if (complained && locus)
4206 : {
4207 199 : if (computed)
4208 43 : inform (*locus, " as a possible target of computed goto");
4209 : else
4210 156 : inform (*locus, " from here");
4211 : }
4212 572 : return complained;
4213 286 : }
4214 :
4215 : /* Check that a single previously seen jump to a newly defined label
4216 : is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
4217 : the jump context; NAMES are the names in scope in LEVEL at the jump
4218 : context; LOCUS is the source position of the jump or 0. COMPUTED
4219 : is a vec of decls if the jump is a computed goto. DIRECT_GOTO is a
4220 : vec of pointers to LABEL_DECLs that might need adjusting if vacuous
4221 : initializations are crossed for !!flag_auto_var_init. CASE_LABEL is
4222 : CASE_LABEL_EXPR to be moved if needed for the check_switch_goto case.
4223 : Returns non-zero if all is well, 2 if any vacuous initializers were
4224 : crossed. */
4225 :
4226 : static int
4227 1751667 : check_previous_goto_1 (tree decl, cp_binding_level *level, tree names,
4228 : bool exited_omp, const location_t *locus,
4229 : vec<tree, va_gc> *computed,
4230 : vec<named_label_fwd_direct_goto, va_gc> *direct_goto,
4231 : tree case_label)
4232 : {
4233 1751667 : auto_diagnostic_group d;
4234 1751667 : cp_binding_level *b;
4235 1751667 : bool complained = false;
4236 1751667 : int identified = 0;
4237 1751667 : bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
4238 1751667 : bool saw_ceif = false, saw_se = false;
4239 1751667 : auto_vec<tree> vacuous_decls;
4240 1751667 : bool vacuous_inits = false;
4241 :
4242 1751667 : if (exited_omp)
4243 : {
4244 12 : complained = identify_goto (decl, input_location, locus,
4245 : diagnostics::kind::error,
4246 : computed);
4247 12 : if (complained)
4248 12 : inform (input_location, " exits OpenMP structured block");
4249 : saw_omp = true;
4250 : identified = 2;
4251 : }
4252 :
4253 5225591 : for (b = current_binding_level; b ; b = b->level_chain)
4254 : {
4255 3473924 : tree new_decls, old_decls = (b == level ? names : NULL_TREE);
4256 :
4257 6406309 : for (new_decls = b->names; new_decls != old_decls;
4258 5854082 : new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
4259 2921697 : : TREE_CHAIN (new_decls)))
4260 : {
4261 2932385 : bool problem = decl_jump_unsafe (new_decls);
4262 2932385 : if (! problem)
4263 : {
4264 2932340 : if (decl_instrument_init_bypass_p (new_decls))
4265 : {
4266 323 : if (direct_goto || case_label)
4267 254 : vacuous_decls.safe_push (new_decls);
4268 : vacuous_inits = true;
4269 : }
4270 2932340 : continue;
4271 : }
4272 :
4273 45 : if (!identified)
4274 : {
4275 45 : complained = identify_goto (decl, input_location, locus,
4276 : diagnostics::kind::error,
4277 : computed);
4278 45 : identified = 2;
4279 : }
4280 45 : if (complained)
4281 45 : inform (DECL_SOURCE_LOCATION (new_decls),
4282 : " crosses initialization of %q#D", new_decls);
4283 : }
4284 :
4285 3473924 : if (b == level)
4286 : break;
4287 :
4288 1722257 : const char *inf = NULL;
4289 1722257 : location_t loc = input_location;
4290 1722257 : switch (b->kind)
4291 : {
4292 3 : case sk_try:
4293 3 : if (!saw_eh)
4294 : inf = G_(" enters %<try%> block");
4295 : saw_eh = true;
4296 : break;
4297 :
4298 9 : case sk_catch:
4299 9 : if (!saw_eh)
4300 : inf = G_(" enters %<catch%> block");
4301 : saw_eh = true;
4302 : break;
4303 :
4304 102 : case sk_omp:
4305 102 : if (!saw_omp)
4306 : inf = G_(" enters OpenMP structured block");
4307 : saw_omp = true;
4308 : break;
4309 :
4310 3 : case sk_transaction:
4311 3 : if (!saw_tm)
4312 : inf = G_(" enters synchronized or atomic statement");
4313 : saw_tm = true;
4314 : break;
4315 :
4316 18 : case sk_stmt_expr:
4317 18 : if (!saw_se)
4318 : inf = G_(" enters statement expression");
4319 : saw_se = true;
4320 : break;
4321 :
4322 1721985 : case sk_block:
4323 1721985 : if (!saw_cxif && level_for_constexpr_if (b->level_chain))
4324 : {
4325 9 : inf = G_(" enters %<constexpr if%> statement");
4326 9 : loc = EXPR_LOCATION (b->level_chain->this_entity);
4327 : saw_cxif = true;
4328 : }
4329 1721976 : else if (!saw_ceif && level_for_consteval_if (b->level_chain))
4330 : {
4331 18 : inf = G_(" enters %<consteval if%> statement");
4332 18 : loc = EXPR_LOCATION (b->level_chain->this_entity);
4333 : saw_ceif = true;
4334 : }
4335 : break;
4336 :
4337 : default:
4338 : break;
4339 : }
4340 :
4341 : if (inf)
4342 : {
4343 141 : if (identified < 2)
4344 141 : complained = identify_goto (decl, input_location, locus,
4345 : diagnostics::kind::error,
4346 : computed);
4347 141 : identified = 2;
4348 141 : if (complained)
4349 141 : inform (loc, inf);
4350 : }
4351 : }
4352 :
4353 1751667 : if (!vec_safe_is_empty (computed))
4354 : {
4355 9 : if (!identified)
4356 6 : complained = identify_goto (decl, input_location, locus,
4357 : diagnostics::kind::error,
4358 : computed);
4359 9 : identified = 2;
4360 9 : if (complained)
4361 18 : for (tree d : computed)
4362 : {
4363 9 : if (DECL_P (d))
4364 6 : inform (DECL_SOURCE_LOCATION (d), " does not destroy %qD", d);
4365 3 : else if (d == get_identifier ("catch"))
4366 3 : inform (*locus, " does not clean up handled exception");
4367 : }
4368 : }
4369 :
4370 1751756 : if (!vacuous_decls.is_empty () && !seen_error ())
4371 : {
4372 87 : tree_stmt_iterator iter = tsi_last (cur_stmt_list);
4373 87 : if (case_label)
4374 : {
4375 42 : gcc_checking_assert (tsi_stmt (iter) == case_label);
4376 42 : tsi_delink (&iter);
4377 42 : iter = tsi_last (cur_stmt_list);
4378 : }
4379 87 : tree lab = maybe_add_deferred_init_calls (iter, case_label,
4380 : vacuous_decls.address (),
4381 : vacuous_decls.length ());
4382 87 : if (lab)
4383 : {
4384 : unsigned int i;
4385 : named_label_fwd_direct_goto *dgoto;
4386 177 : FOR_EACH_VEC_SAFE_ELT (direct_goto, i, dgoto)
4387 45 : *dgoto->direct_goto = lab;
4388 : }
4389 : }
4390 :
4391 1751667 : if (identified)
4392 : return 0;
4393 1751463 : return vacuous_inits ? 2 : 1;
4394 1751667 : }
4395 :
4396 : static void
4397 2112 : check_previous_goto (tree decl, struct named_label_use_entry *use)
4398 : {
4399 2112 : check_previous_goto_1 (decl, use->binding_level,
4400 2112 : use->names_in_scope, use->in_omp_scope,
4401 2112 : &use->o_goto_locus, use->computed_goto,
4402 : use->direct_goto, NULL_TREE);
4403 2112 : vec_free (use->direct_goto);
4404 2112 : }
4405 :
4406 : static int
4407 1749555 : check_switch_goto (cp_binding_level *level, tree case_label)
4408 : {
4409 1749555 : return check_previous_goto_1 (NULL_TREE, level, level->names,
4410 1749555 : false, NULL, nullptr, nullptr, case_label);
4411 : }
4412 :
4413 : /* Check that a new jump to a label ENT is OK. DECLP is a pointer
4414 : to a LABEL_DECL for direct gotos and NULL for computed gotos. */
4415 :
4416 : void
4417 2836 : check_goto_1 (named_label_entry *ent, tree *declp)
4418 : {
4419 2836 : auto_diagnostic_group d;
4420 2836 : tree decl = ent->label_decl;
4421 2836 : bool computed = declp == NULL;
4422 :
4423 : /* If the label hasn't been defined yet, defer checking. */
4424 2836 : if (! DECL_INITIAL (decl))
4425 : {
4426 : /* Don't bother creating another use if the last goto had the
4427 : same data, and will therefore create the same set of errors. */
4428 2181 : if (ent->uses
4429 658 : && ent->uses->binding_level == current_binding_level
4430 60 : && ent->uses->names_in_scope == current_binding_level->names)
4431 : {
4432 60 : if (declp
4433 54 : && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
4434 11 : && !processing_template_decl)
4435 9 : vec_safe_push (ent->uses->direct_goto,
4436 9 : named_label_fwd_direct_goto { declp });
4437 60 : return;
4438 : }
4439 :
4440 2121 : named_label_use_entry *new_use
4441 2121 : = ggc_alloc<named_label_use_entry> ();
4442 2121 : new_use->binding_level = current_binding_level;
4443 2121 : new_use->names_in_scope = current_binding_level->names;
4444 2121 : new_use->o_goto_locus = input_location;
4445 2121 : new_use->in_omp_scope = false;
4446 2121 : new_use->computed_goto = computed ? make_tree_vector () : nullptr;
4447 2121 : new_use->direct_goto = nullptr;
4448 2121 : if (declp
4449 2030 : && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
4450 358 : && !processing_template_decl)
4451 301 : vec_safe_push (new_use->direct_goto,
4452 301 : named_label_fwd_direct_goto { declp });
4453 :
4454 2121 : new_use->next = ent->uses;
4455 2121 : ent->uses = new_use;
4456 2121 : return;
4457 : }
4458 :
4459 655 : bool saw_catch = false, complained = false;
4460 655 : int identified = 0;
4461 655 : tree bad;
4462 655 : unsigned ix;
4463 655 : unsigned n_bad_decls = 0;
4464 :
4465 655 : if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
4466 640 : || ent->in_constexpr_if || ent->in_consteval_if
4467 634 : || ent->in_omp_scope || ent->in_stmt_expr
4468 616 : || ent->has_bad_decls)
4469 : {
4470 45 : enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
4471 45 : if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
4472 30 : || ent->in_consteval_if || ent->in_transaction_scope
4473 24 : || ent->in_omp_scope || ent->in_stmt_expr)
4474 39 : diag_kind = diagnostics::kind::error;
4475 45 : complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4476 : &input_location, diag_kind, computed);
4477 45 : identified = 1 + (diag_kind == diagnostics::kind::error);
4478 : }
4479 :
4480 845 : FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
4481 : {
4482 190 : bool problem = decl_jump_unsafe (bad);
4483 190 : if (!problem)
4484 : {
4485 184 : gcc_checking_assert (decl_instrument_init_bypass_p (bad));
4486 184 : n_bad_decls++;
4487 184 : continue;
4488 : }
4489 :
4490 6 : if (DECL_ARTIFICIAL (bad))
4491 : {
4492 : /* Can't skip init of __exception_info. */
4493 0 : if (identified == 1)
4494 : {
4495 0 : complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4496 : &input_location,
4497 : diagnostics::kind::error,
4498 : computed);
4499 0 : identified = 2;
4500 : }
4501 0 : if (complained)
4502 0 : inform (DECL_SOURCE_LOCATION (bad), " enters %<catch%> block");
4503 : saw_catch = true;
4504 : }
4505 6 : else if (complained)
4506 6 : inform (DECL_SOURCE_LOCATION (bad),
4507 : " skips initialization of %q#D", bad);
4508 : }
4509 :
4510 655 : if (complained)
4511 : {
4512 45 : if (ent->in_try_scope)
4513 9 : inform (input_location, " enters %<try%> block");
4514 36 : else if (ent->in_catch_scope && !saw_catch)
4515 3 : inform (input_location, " enters %<catch%> block");
4516 33 : else if (ent->in_transaction_scope)
4517 3 : inform (input_location, " enters synchronized or atomic statement");
4518 30 : else if (ent->in_constexpr_if)
4519 3 : inform (input_location, " enters %<constexpr if%> statement");
4520 27 : else if (ent->in_consteval_if)
4521 3 : inform (input_location, " enters %<consteval if%> statement");
4522 24 : else if (ent->in_stmt_expr)
4523 15 : inform (input_location, " enters statement expression");
4524 : }
4525 :
4526 655 : if (ent->in_omp_scope)
4527 : {
4528 3 : if (complained)
4529 3 : inform (input_location, " enters OpenMP structured block");
4530 : }
4531 652 : else if (flag_openmp)
4532 69 : for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
4533 : {
4534 42 : if (b == ent->binding_level)
4535 : break;
4536 36 : if (b->kind == sk_omp)
4537 : {
4538 21 : if (identified < 2)
4539 : {
4540 42 : complained = identify_goto (decl,
4541 21 : DECL_SOURCE_LOCATION (decl),
4542 : &input_location,
4543 : diagnostics::kind::error,
4544 : computed);
4545 21 : identified = 2;
4546 : }
4547 21 : if (complained)
4548 21 : inform (input_location, " exits OpenMP structured block");
4549 : break;
4550 : }
4551 : }
4552 :
4553 : /* Warn if a computed goto might involve a local variable going out of scope
4554 : without being cleaned up. */
4555 655 : if (computed)
4556 : {
4557 71 : auto level = ent->binding_level;
4558 71 : auto names = ent->names_in_scope;
4559 71 : for (auto b = current_binding_level; ; b = b->level_chain)
4560 : {
4561 111 : if (b->kind == sk_catch)
4562 : {
4563 6 : if (!identified)
4564 : {
4565 6 : complained
4566 6 : = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4567 : &input_location, diagnostics::kind::error,
4568 : computed);
4569 6 : identified = 2;
4570 : }
4571 6 : if (complained)
4572 6 : inform (input_location,
4573 : " does not clean up handled exception");
4574 : }
4575 111 : tree end = b == level ? names : NULL_TREE;
4576 127 : for (tree d = b->names; d != end; d = DECL_CHAIN (d))
4577 : {
4578 16 : if (automatic_var_with_nontrivial_dtor_p (d))
4579 : {
4580 10 : if (!identified)
4581 : {
4582 10 : complained
4583 10 : = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4584 : &input_location, diagnostics::kind::error,
4585 : computed);
4586 10 : identified = 2;
4587 : }
4588 10 : if (complained)
4589 10 : inform (DECL_SOURCE_LOCATION (d),
4590 : " does not destroy %qD", d);
4591 : }
4592 : }
4593 111 : if (b == level)
4594 : break;
4595 40 : }
4596 : }
4597 :
4598 655 : if (n_bad_decls && declp)
4599 46 : vec_safe_push (ent->direct_goto,
4600 46 : named_label_bck_direct_goto { declp, n_bad_decls });
4601 2836 : }
4602 :
4603 : /* Check that a new jump to a label *DECLP is OK. Called by
4604 : finish_goto_stmt. */
4605 :
4606 : void
4607 2796 : check_goto (tree *declp)
4608 : {
4609 2796 : if (!named_labels)
4610 : return;
4611 2781 : tree decl = *declp;
4612 2781 : if (TREE_CODE (decl) != LABEL_DECL)
4613 : {
4614 : /* We don't know where a computed goto is jumping,
4615 : so check all addressable labels. */
4616 312 : for (auto iter = named_labels->begin ();
4617 425 : iter != named_labels->end ();
4618 199 : ++iter)
4619 : {
4620 199 : auto ent = *iter;
4621 199 : if (ent->addressed)
4622 168 : check_goto_1 (ent, NULL);
4623 : }
4624 : }
4625 : else
4626 : {
4627 2668 : hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
4628 2668 : named_label_entry **slot
4629 2668 : = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
4630 2668 : named_label_entry *ent = *slot;
4631 2668 : check_goto_1 (ent, declp);
4632 : }
4633 : }
4634 :
4635 : /* Check that a return is ok wrt OpenMP structured blocks.
4636 : Called by finish_return_stmt. Returns true if all is well. */
4637 :
4638 : bool
4639 279999 : check_omp_return (void)
4640 : {
4641 1110743 : for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
4642 830744 : if (b->kind == sk_omp)
4643 : {
4644 15 : error ("invalid exit from OpenMP structured block");
4645 15 : return false;
4646 : }
4647 830729 : else if (b->kind == sk_function_parms)
4648 : break;
4649 : return true;
4650 : }
4651 :
4652 : /* Define a label, specifying the location in the source file.
4653 : Return the LABEL_DECL node for the label. */
4654 :
4655 : tree
4656 20925 : define_label (location_t location, tree name)
4657 : {
4658 20925 : auto_cond_timevar tv (TV_NAME_LOOKUP);
4659 :
4660 : /* After labels, make any new cleanups in the function go into their
4661 : own new (temporary) binding contour. */
4662 20925 : for (cp_binding_level *p = current_binding_level;
4663 31655 : p->kind != sk_function_parms;
4664 10730 : p = p->level_chain)
4665 10730 : p->more_cleanups_ok = 0;
4666 :
4667 20925 : named_label_entry *ent = lookup_label_1 (name, false);
4668 20925 : tree decl = ent->label_decl;
4669 :
4670 20925 : if (DECL_INITIAL (decl) != NULL_TREE)
4671 : {
4672 6 : error ("duplicate label %qD", decl);
4673 6 : return error_mark_node;
4674 : }
4675 : else
4676 : {
4677 : /* Mark label as having been defined. */
4678 20919 : DECL_INITIAL (decl) = error_mark_node;
4679 : /* Say where in the source. */
4680 20919 : DECL_SOURCE_LOCATION (decl) = location;
4681 :
4682 20919 : ent->binding_level = current_binding_level;
4683 20919 : ent->names_in_scope = current_binding_level->names;
4684 :
4685 23031 : for (named_label_use_entry *use = ent->uses; use; use = use->next)
4686 2112 : check_previous_goto (decl, use);
4687 20919 : ent->uses = NULL;
4688 : }
4689 :
4690 20919 : return decl;
4691 20925 : }
4692 :
4693 : struct cp_switch
4694 : {
4695 : cp_binding_level *level;
4696 : struct cp_switch *next;
4697 : /* The SWITCH_STMT being built. */
4698 : tree switch_stmt;
4699 : /* A splay-tree mapping the low element of a case range to the high
4700 : element, or NULL_TREE if there is no high element. Used to
4701 : determine whether or not a new case label duplicates an old case
4702 : label. We need a tree, rather than simply a hash table, because
4703 : of the GNU case range extension. */
4704 : splay_tree cases;
4705 : /* Remember whether a default: case label has been seen. */
4706 : bool has_default_p;
4707 : /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT. */
4708 : bool break_stmt_seen_p;
4709 : /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
4710 : where BREAK_STMT doesn't belong to the SWITCH_STMT. */
4711 : bool in_loop_body_p;
4712 : };
4713 :
4714 : /* A stack of the currently active switch statements. The innermost
4715 : switch statement is on the top of the stack. There is no need to
4716 : mark the stack for garbage collection because it is only active
4717 : during the processing of the body of a function, and we never
4718 : collect at that point. */
4719 :
4720 : static struct cp_switch *switch_stack;
4721 :
4722 : /* Called right after a switch-statement condition is parsed.
4723 : SWITCH_STMT is the switch statement being parsed. */
4724 :
4725 : void
4726 717155 : push_switch (tree switch_stmt)
4727 : {
4728 717155 : struct cp_switch *p = XNEW (struct cp_switch);
4729 717155 : p->level = current_binding_level;
4730 717155 : p->next = switch_stack;
4731 717155 : p->switch_stmt = switch_stmt;
4732 717155 : p->cases = splay_tree_new (case_compare, NULL, NULL);
4733 717155 : p->has_default_p = false;
4734 717155 : p->break_stmt_seen_p = false;
4735 717155 : p->in_loop_body_p = false;
4736 717155 : switch_stack = p;
4737 717155 : }
4738 :
4739 : void
4740 717155 : pop_switch (void)
4741 : {
4742 717155 : struct cp_switch *cs = switch_stack;
4743 :
4744 : /* Emit warnings as needed. */
4745 717155 : location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
4746 717155 : tree cond = SWITCH_STMT_COND (cs->switch_stmt);
4747 717155 : const bool bool_cond_p
4748 717155 : = (SWITCH_STMT_TYPE (cs->switch_stmt)
4749 717155 : && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
4750 717155 : if (!processing_template_decl)
4751 294244 : c_do_switch_warnings (cs->cases, switch_location,
4752 294244 : SWITCH_STMT_TYPE (cs->switch_stmt), cond,
4753 : bool_cond_p);
4754 :
4755 : /* For the benefit of block_may_fallthru remember if the switch body
4756 : case labels cover all possible values and if there are break; stmts. */
4757 717155 : if (cs->has_default_p
4758 717155 : || (!processing_template_decl
4759 42204 : && c_switch_covers_all_cases_p (cs->cases,
4760 42204 : SWITCH_STMT_TYPE (cs->switch_stmt))))
4761 529461 : SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
4762 717155 : if (!cs->break_stmt_seen_p)
4763 370798 : SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
4764 : /* Now that we're done with the switch warnings, set the switch type
4765 : to the type of the condition if the index type was of scoped enum type.
4766 : (Such types don't participate in the integer promotions.) We do this
4767 : because of bit-fields whose declared type is a scoped enum type:
4768 : gimplification will use the lowered index type, but convert the
4769 : case values to SWITCH_STMT_TYPE, which would have been the declared type
4770 : and verify_gimple_switch doesn't accept that. */
4771 717155 : if (is_bitfield_expr_with_lowered_type (cond))
4772 27890 : SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
4773 717155 : gcc_assert (!cs->in_loop_body_p);
4774 717155 : splay_tree_delete (cs->cases);
4775 717155 : switch_stack = switch_stack->next;
4776 717155 : free (cs);
4777 717155 : }
4778 :
4779 : /* Note that a BREAK_STMT is about to be added. If it is inside of
4780 : a SWITCH_STMT and not inside of a loop body inside of it, note
4781 : in switch_stack we've seen a BREAK_STMT. */
4782 :
4783 : void
4784 4819451 : note_break_stmt (void)
4785 : {
4786 4819451 : if (switch_stack && !switch_stack->in_loop_body_p)
4787 2715765 : switch_stack->break_stmt_seen_p = true;
4788 4819451 : }
4789 :
4790 : /* Note the start of processing of an iteration statement's body.
4791 : The note_break_stmt function will do nothing while processing it.
4792 : Return a flag that should be passed to note_iteration_stmt_body_end. */
4793 :
4794 : bool
4795 18280180 : note_iteration_stmt_body_start (void)
4796 : {
4797 18280180 : if (!switch_stack)
4798 : return false;
4799 193833 : bool ret = switch_stack->in_loop_body_p;
4800 193833 : switch_stack->in_loop_body_p = true;
4801 193833 : return ret;
4802 : }
4803 :
4804 : /* Note the end of processing of an iteration statement's body. */
4805 :
4806 : void
4807 18280180 : note_iteration_stmt_body_end (bool prev)
4808 : {
4809 18280180 : if (switch_stack)
4810 193833 : switch_stack->in_loop_body_p = prev;
4811 18280180 : }
4812 :
4813 : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
4814 : condition. Note that if TYPE and VALUE are already integral we don't
4815 : really do the conversion because the language-independent
4816 : warning/optimization code will work better that way. */
4817 :
4818 : static tree
4819 3498778 : case_conversion (tree type, tree value)
4820 : {
4821 3498778 : if (value == NULL_TREE)
4822 : return value;
4823 :
4824 1497522 : value = mark_rvalue_use (value);
4825 :
4826 1497522 : if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
4827 1110792 : type = type_promotes_to (type);
4828 :
4829 1497522 : tree ovalue = value;
4830 : /* The constant-expression VALUE shall be a converted constant expression
4831 : of the adjusted type of the switch condition, which doesn't allow
4832 : narrowing conversions. */
4833 1497522 : value = build_converted_constant_expr (type, value, tf_warning_or_error);
4834 :
4835 1497522 : if (cxx_dialect >= cxx11
4836 1497522 : && (SCOPED_ENUM_P (type)
4837 1107711 : || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
4838 : /* Use the converted value. */;
4839 : else
4840 : /* The already integral case. */
4841 : value = ovalue;
4842 :
4843 1497522 : return cxx_constant_value (value);
4844 : }
4845 :
4846 : /* Note that we've seen a definition of a case label, and complain if this
4847 : is a bad place for one. */
4848 :
4849 : tree
4850 5771644 : finish_case_label (location_t loc, tree low_value, tree high_value)
4851 : {
4852 5771644 : tree cond, r;
4853 5771644 : cp_binding_level *p;
4854 5771644 : tree type;
4855 :
4856 5771644 : if (low_value == NULL_TREE && high_value == NULL_TREE)
4857 529425 : switch_stack->has_default_p = true;
4858 :
4859 5771644 : if (processing_template_decl)
4860 : {
4861 4022132 : tree label;
4862 :
4863 : /* For templates, just add the case label; we'll do semantic
4864 : analysis at instantiation-time. But diagnose case labels
4865 : in expansion statements with switch outside of it here. */
4866 4022132 : if (in_expansion_stmt)
4867 39 : for (cp_binding_level *b = current_binding_level;
4868 78 : b != switch_stack->level; b = b->level_chain)
4869 63 : if (b->kind == sk_template_for && b->this_entity)
4870 : {
4871 24 : auto_diagnostic_group d;
4872 24 : error ("jump to case label");
4873 24 : inform (EXPR_LOCATION (b->this_entity),
4874 : " enters %<template for%> statement");
4875 24 : return error_mark_node;
4876 24 : }
4877 4022108 : label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
4878 4022108 : return add_stmt (build_case_label (low_value, high_value, label));
4879 : }
4880 :
4881 : /* Find the condition on which this switch statement depends. */
4882 1749512 : cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
4883 1749512 : if (cond && TREE_CODE (cond) == TREE_LIST)
4884 0 : cond = TREE_VALUE (cond);
4885 :
4886 1749512 : int chk_switch_goto = check_switch_goto (switch_stack->level, NULL_TREE);
4887 1749512 : if (!chk_switch_goto)
4888 87 : return error_mark_node;
4889 :
4890 1749425 : type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
4891 1749425 : if (type == error_mark_node)
4892 : return error_mark_node;
4893 :
4894 1749389 : low_value = case_conversion (type, low_value);
4895 1749389 : high_value = case_conversion (type, high_value);
4896 :
4897 1749389 : r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
4898 :
4899 1749389 : if (r != error_mark_node && chk_switch_goto == 2)
4900 43 : check_switch_goto (switch_stack->level, r);
4901 :
4902 : /* After labels, make any new cleanups in the function go into their
4903 : own new (temporary) binding contour. */
4904 1749389 : for (p = current_binding_level;
4905 7356230 : p->kind != sk_function_parms;
4906 5606841 : p = p->level_chain)
4907 5606841 : p->more_cleanups_ok = 0;
4908 :
4909 : return r;
4910 : }
4911 :
4912 : struct typename_info {
4913 : tree scope;
4914 : tree name;
4915 : tree template_id;
4916 : tag_types tag_type;
4917 : };
4918 :
4919 : struct typename_hasher : ggc_ptr_hash<tree_node>
4920 : {
4921 : typedef typename_info *compare_type;
4922 :
4923 : /* Hash a TYPENAME_TYPE. */
4924 :
4925 : static hashval_t
4926 457067025 : hash (tree context, tree fullname)
4927 : {
4928 457067025 : hashval_t hash = 0;
4929 457067025 : hash = iterative_hash_object (context, hash);
4930 457067025 : hash = iterative_hash_object (fullname, hash);
4931 457067025 : return hash;
4932 : }
4933 :
4934 : static hashval_t
4935 64548711 : hash (const typename_info *ti)
4936 : {
4937 64548711 : return typename_hasher::hash (ti->scope, ti->template_id);
4938 : }
4939 :
4940 : static hashval_t
4941 392518314 : hash (tree t)
4942 : {
4943 392518314 : return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
4944 : }
4945 :
4946 : /* Compare two TYPENAME_TYPEs. */
4947 :
4948 : static bool
4949 462309148 : equal (tree t1, const typename_info *t2)
4950 : {
4951 462309148 : return (TYPE_IDENTIFIER (t1) == t2->name
4952 150176711 : && TYPE_CONTEXT (t1) == t2->scope
4953 33153026 : && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
4954 495449408 : && get_typename_tag (t1) == t2->tag_type);
4955 : }
4956 : };
4957 :
4958 : /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
4959 : the type of `T', NAME is the IDENTIFIER_NODE for `t'.
4960 :
4961 : Returns the new TYPENAME_TYPE. */
4962 :
4963 : static GTY (()) hash_table<typename_hasher> *typename_htab;
4964 :
4965 : tree
4966 64548711 : build_typename_type (tree context, tree name, tree fullname,
4967 : enum tag_types tag_type)
4968 : {
4969 64548711 : typename_info ti;
4970 :
4971 64548711 : if (typename_htab == NULL)
4972 20039 : typename_htab = hash_table<typename_hasher>::create_ggc (61);
4973 :
4974 64548711 : ti.scope = FROB_CONTEXT (context);
4975 64548711 : ti.name = name;
4976 64548711 : ti.template_id = fullname;
4977 64548711 : ti.tag_type = tag_type;
4978 64548711 : hashval_t hash = typename_hasher::hash (&ti);
4979 :
4980 : /* See if we already have this type. */
4981 64548711 : tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
4982 64548711 : tree t = *e;
4983 64548711 : if (*e)
4984 : t = *e;
4985 : else
4986 : {
4987 : /* Build the TYPENAME_TYPE. */
4988 32504199 : t = cxx_make_type (TYPENAME_TYPE);
4989 32504199 : TYPE_CONTEXT (t) = ti.scope;
4990 32504199 : TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
4991 32504199 : set_typename_tag (t, ti.tag_type);
4992 :
4993 : /* Build the corresponding TYPE_DECL. */
4994 32504199 : tree d = build_decl (input_location, TYPE_DECL, name, t);
4995 32504199 : TYPE_NAME (t) = d;
4996 32504199 : TYPE_STUB_DECL (t) = d;
4997 32504199 : DECL_CONTEXT (d) = ti.scope;
4998 32504199 : DECL_ARTIFICIAL (d) = 1;
4999 :
5000 : /* Store it in the hash table. */
5001 32504199 : *e = t;
5002 :
5003 : /* TYPENAME_TYPEs must always be compared structurally, because
5004 : they may or may not resolve down to another type depending on
5005 : the currently open classes. */
5006 32504199 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5007 : }
5008 :
5009 64548711 : return t;
5010 : }
5011 :
5012 : /* Resolve `typename CONTEXT::NAME'. TAG_TYPE indicates the tag
5013 : provided to name the type. Returns an appropriate type, unless an
5014 : error occurs, in which case error_mark_node is returned. If we
5015 : locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
5016 : return that, rather than the _TYPE it corresponds to, in other
5017 : cases we look through the type decl. If TF_ERROR is set, complain
5018 : about errors, otherwise be quiet. */
5019 :
5020 : tree
5021 272744475 : make_typename_type (tree context, tree name, enum tag_types tag_type,
5022 : tsubst_flags_t complain)
5023 : {
5024 272744475 : tree fullname;
5025 272744475 : tree t;
5026 272744475 : bool want_template;
5027 :
5028 272744475 : if (name == error_mark_node
5029 272744469 : || context == NULL_TREE
5030 272744469 : || context == error_mark_node)
5031 : return error_mark_node;
5032 :
5033 272744453 : if (TYPE_P (name))
5034 : {
5035 0 : if (!(TYPE_LANG_SPECIFIC (name)
5036 0 : && (CLASSTYPE_IS_TEMPLATE (name)
5037 0 : || CLASSTYPE_USE_TEMPLATE (name))))
5038 0 : name = TYPE_IDENTIFIER (name);
5039 : else
5040 : /* Create a TEMPLATE_ID_EXPR for the type. */
5041 0 : name = build_nt (TEMPLATE_ID_EXPR,
5042 0 : CLASSTYPE_TI_TEMPLATE (name),
5043 0 : CLASSTYPE_TI_ARGS (name));
5044 : }
5045 272744453 : else if (TREE_CODE (name) == TYPE_DECL)
5046 0 : name = DECL_NAME (name);
5047 :
5048 272744453 : fullname = name;
5049 :
5050 272744453 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
5051 : {
5052 5362883 : name = TREE_OPERAND (name, 0);
5053 5362883 : if (DECL_TYPE_TEMPLATE_P (name))
5054 0 : name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
5055 5362883 : if (TREE_CODE (name) != IDENTIFIER_NODE)
5056 : {
5057 0 : if (complain & tf_error)
5058 0 : error ("%qD is not a type", name);
5059 0 : return error_mark_node;
5060 : }
5061 : }
5062 272744453 : if (TREE_CODE (name) == TEMPLATE_DECL)
5063 : {
5064 0 : if (complain & tf_error)
5065 0 : error ("%qD used without template arguments", name);
5066 0 : return error_mark_node;
5067 : }
5068 272744453 : else if (is_overloaded_fn (name))
5069 : {
5070 3 : if (complain & tf_error)
5071 3 : error ("%qD is a function, not a type", name);
5072 3 : return error_mark_node;
5073 : }
5074 272744450 : gcc_assert (identifier_p (name));
5075 272744450 : gcc_assert (TYPE_P (context));
5076 :
5077 272744450 : if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
5078 : /* This can happen for C++17 variadic using (c++/88986). */;
5079 259455730 : else if (!MAYBE_CLASS_TYPE_P (context))
5080 : {
5081 6 : if (complain & tf_error)
5082 6 : error ("%q#T is not a class", context);
5083 6 : return error_mark_node;
5084 : }
5085 :
5086 : /* When the CONTEXT is a dependent type, NAME could refer to a
5087 : dependent base class of CONTEXT. But look inside it anyway
5088 : if CONTEXT is a currently open scope, in case it refers to a
5089 : member of the current instantiation or a non-dependent base;
5090 : lookup will stop when we hit a dependent base. */
5091 272744444 : if (!dependent_scope_p (context))
5092 : {
5093 : /* We generally don't ignore non-types during TYPENAME_TYPE lookup
5094 : (as per [temp.res.general]/3), unless
5095 : - the tag corresponds to a class-key or 'enum' so
5096 : [basic.lookup.elab] applies, or
5097 : - the tag corresponds to scope_type or tf_qualifying_scope is
5098 : set so [basic.lookup.qual]/1 applies, or
5099 : - we're inside a base-specifier so [class.derived.general]/2 applies;
5100 : the tag will already be class_type in that case.
5101 : TODO: If we'd set/track the scope_type tag thoroughly on all
5102 : TYPENAME_TYPEs that are followed by :: then we wouldn't need the
5103 : tf_qualifying_scope flag. */
5104 426094830 : bool want_type = (tag_type != none_type && tag_type != typename_type)
5105 213047415 : || (complain & tf_qualifying_scope);
5106 213047415 : t = lookup_member (context, name, /*protect=*/2, want_type, complain);
5107 : }
5108 : else
5109 : t = NULL_TREE;
5110 :
5111 291496686 : if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
5112 59697954 : return build_typename_type (context, name, fullname, tag_type);
5113 :
5114 213046490 : want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
5115 :
5116 213046490 : if (!t)
5117 : {
5118 18751317 : if (complain & tf_error)
5119 : {
5120 234 : if (!COMPLETE_TYPE_P (context))
5121 18 : cxx_incomplete_type_error (NULL_TREE, context);
5122 : else
5123 431 : error (want_template ? G_("no class template named %q#T in %q#T")
5124 : : G_("no type named %q#T in %q#T"), name, context);
5125 : }
5126 18751317 : return error_mark_node;
5127 : }
5128 :
5129 : /* Pull out the template from an injected-class-name (or multiple). */
5130 194295173 : if (want_template)
5131 3415073 : t = maybe_get_template_decl_from_type_decl (t);
5132 :
5133 194295173 : if (TREE_CODE (t) == TREE_LIST)
5134 : {
5135 3 : if (complain & tf_error)
5136 : {
5137 3 : auto_diagnostic_group d;
5138 3 : error ("lookup of %qT in %qT is ambiguous", name, context);
5139 3 : print_candidates (input_location, t);
5140 3 : }
5141 3 : return error_mark_node;
5142 : }
5143 :
5144 194295170 : if (want_template && !DECL_TYPE_TEMPLATE_P (t))
5145 : {
5146 6 : if (complain & tf_error)
5147 6 : error ("%<typename %T::%D%> names %q#T, which is not a class template",
5148 : context, name, t);
5149 6 : return error_mark_node;
5150 : }
5151 194295164 : if (!want_template && TREE_CODE (t) != TYPE_DECL)
5152 : {
5153 2187 : if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
5154 4377 : && DECL_TYPE_TEMPLATE_P (t))
5155 : /* The caller permits this typename-specifier to name a template
5156 : (because it appears in a CTAD-enabled context). */;
5157 : else
5158 : {
5159 23 : if (complain & tf_error)
5160 17 : error ("%<typename %T::%D%> names %q#D, which is not a type",
5161 : context, name, t);
5162 23 : return error_mark_node;
5163 : }
5164 : }
5165 :
5166 194295141 : if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
5167 : context, complain))
5168 42 : return error_mark_node;
5169 :
5170 194295099 : if (!want_template && DECL_TYPE_TEMPLATE_P (t))
5171 2176 : return make_template_placeholder (t);
5172 :
5173 194292923 : if (want_template)
5174 : {
5175 3415067 : t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
5176 : NULL_TREE, context,
5177 : complain | tf_user);
5178 3415067 : if (t == error_mark_node)
5179 : return error_mark_node;
5180 3415062 : t = TYPE_NAME (t);
5181 : }
5182 :
5183 194292918 : if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
5184 2343853 : t = TREE_TYPE (t);
5185 :
5186 194292918 : maybe_record_typedef_use (t);
5187 :
5188 194292918 : return t;
5189 : }
5190 :
5191 : /* Resolve `CONTEXT::template NAME'. Returns a TEMPLATE_DECL if the name
5192 : can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
5193 : in which case error_mark_node is returned.
5194 :
5195 : If PARM_LIST is non-NULL, also make sure that the template parameter
5196 : list of TEMPLATE_DECL matches.
5197 :
5198 : If COMPLAIN zero, don't complain about any errors that occur. */
5199 :
5200 : tree
5201 185657 : make_unbound_class_template (tree context, tree name, tree parm_list,
5202 : tsubst_flags_t complain)
5203 : {
5204 185657 : if (TYPE_P (name))
5205 0 : name = TYPE_IDENTIFIER (name);
5206 185657 : else if (DECL_P (name))
5207 0 : name = DECL_NAME (name);
5208 185657 : gcc_assert (identifier_p (name));
5209 :
5210 185657 : if (!dependent_type_p (context)
5211 185657 : || currently_open_class (context))
5212 : {
5213 91780 : tree tmpl = NULL_TREE;
5214 :
5215 91780 : if (MAYBE_CLASS_TYPE_P (context))
5216 91774 : tmpl = lookup_field (context, name, 0, false);
5217 :
5218 91774 : if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
5219 3 : tmpl = maybe_get_template_decl_from_type_decl (tmpl);
5220 :
5221 91768 : if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
5222 : {
5223 12 : if (complain & tf_error)
5224 9 : error ("no class template named %q#T in %q#T", name, context);
5225 12 : return error_mark_node;
5226 : }
5227 :
5228 91768 : if (parm_list
5229 91768 : && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
5230 : {
5231 0 : if (complain & tf_error)
5232 : {
5233 0 : auto_diagnostic_group d;
5234 0 : error ("template parameters do not match template %qD", tmpl);
5235 0 : inform (DECL_SOURCE_LOCATION (tmpl),
5236 : "%qD declared here", tmpl);
5237 0 : }
5238 0 : return error_mark_node;
5239 : }
5240 :
5241 91768 : if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
5242 : complain))
5243 0 : return error_mark_node;
5244 :
5245 : return tmpl;
5246 : }
5247 :
5248 93877 : return make_unbound_class_template_raw (context, name, parm_list);
5249 : }
5250 :
5251 : /* Build an UNBOUND_CLASS_TEMPLATE. */
5252 :
5253 : tree
5254 93929 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
5255 : {
5256 : /* Build the UNBOUND_CLASS_TEMPLATE. */
5257 93929 : tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
5258 93929 : TYPE_CONTEXT (t) = FROB_CONTEXT (context);
5259 93929 : TREE_TYPE (t) = NULL_TREE;
5260 93929 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5261 :
5262 : /* Build the corresponding TEMPLATE_DECL. */
5263 93929 : tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
5264 93929 : TYPE_NAME (t) = d;
5265 93929 : TYPE_STUB_DECL (t) = d;
5266 93929 : DECL_CONTEXT (d) = TYPE_CONTEXT (t);
5267 93929 : DECL_ARTIFICIAL (d) = 1;
5268 93929 : DECL_TEMPLATE_PARMS (d) = parm_list;
5269 :
5270 93929 : return t;
5271 : }
5272 :
5273 :
5274 :
5275 : /* Push the declarations of builtin types into the global namespace.
5276 : RID_INDEX is the index of the builtin type in the array
5277 : RID_POINTERS. NAME is the name used when looking up the builtin
5278 : type. TYPE is the _TYPE node for the builtin type.
5279 :
5280 : The calls to set_global_binding below should be
5281 : eliminated. Built-in types should not be looked up name; their
5282 : names are keywords that the parser can recognize. However, there
5283 : is code in c-common.cc that uses identifier_global_value to look up
5284 : built-in types by name. */
5285 :
5286 : void
5287 4237335 : record_builtin_type (enum rid rid_index,
5288 : const char* name,
5289 : tree type)
5290 : {
5291 4237335 : tree decl = NULL_TREE;
5292 :
5293 4237335 : if (name)
5294 : {
5295 2500921 : tree tname = get_identifier (name);
5296 2500921 : tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
5297 2500921 : DECL_ARTIFICIAL (tdecl) = 1;
5298 2500921 : set_global_binding (tdecl);
5299 2500921 : decl = tdecl;
5300 : }
5301 :
5302 4237335 : if ((int) rid_index < (int) RID_MAX)
5303 2601792 : if (tree rname = ridpointers[(int) rid_index])
5304 1988940 : if (!decl || DECL_NAME (decl) != rname)
5305 : {
5306 1429988 : tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
5307 1429988 : DECL_ARTIFICIAL (rdecl) = 1;
5308 1429988 : set_global_binding (rdecl);
5309 1429988 : if (!decl)
5310 : decl = rdecl;
5311 : }
5312 :
5313 3930909 : if (decl)
5314 : {
5315 3624483 : if (!TYPE_NAME (type))
5316 3011631 : TYPE_NAME (type) = decl;
5317 3624483 : debug_hooks->type_decl (decl, 0);
5318 : }
5319 4237335 : }
5320 :
5321 : /* Push a type into the namespace so that the back ends ignore it. */
5322 :
5323 : static void
5324 306426 : record_unknown_type (tree type, const char* name)
5325 : {
5326 306426 : tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
5327 : TYPE_DECL, get_identifier (name), type));
5328 : /* Make sure the "unknown type" typedecl gets ignored for debug info. */
5329 306426 : DECL_IGNORED_P (decl) = 1;
5330 306426 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
5331 306426 : TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
5332 306426 : SET_TYPE_ALIGN (type, 1);
5333 306426 : TYPE_USER_ALIGN (type) = 0;
5334 306426 : SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
5335 306426 : }
5336 :
5337 : /* Create all the predefined identifiers. */
5338 :
5339 : static void
5340 102142 : initialize_predefined_identifiers (void)
5341 : {
5342 102142 : struct predefined_identifier
5343 : {
5344 : const char *name; /* Name. */
5345 : tree *node; /* Node to store it in. */
5346 : cp_identifier_kind kind; /* Kind of identifier. */
5347 : };
5348 :
5349 : /* A table of identifiers to create at startup. */
5350 102142 : static const predefined_identifier predefined_identifiers[] = {
5351 : {"C++", &lang_name_cplusplus, cik_normal},
5352 : {"C", &lang_name_c, cik_normal},
5353 : /* Some of these names have a trailing space so that it is
5354 : impossible for them to conflict with names written by users. */
5355 : {"__ct ", &ctor_identifier, cik_ctor},
5356 : {"__ct_base ", &base_ctor_identifier, cik_ctor},
5357 : {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
5358 : {"__dt ", &dtor_identifier, cik_dtor},
5359 : {"__dt_base ", &base_dtor_identifier, cik_dtor},
5360 : {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
5361 : {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
5362 : {"__conv_op ", &conv_op_identifier, cik_conv_op},
5363 : {"__in_chrg", &in_charge_identifier, cik_normal},
5364 : {"__as_base ", &as_base_identifier, cik_normal},
5365 : {"this", &this_identifier, cik_normal},
5366 : {"__delta", &delta_identifier, cik_normal},
5367 : {"__pfn", &pfn_identifier, cik_normal},
5368 : {"_vptr", &vptr_identifier, cik_normal},
5369 : {"__vtt_parm", &vtt_parm_identifier, cik_normal},
5370 : {"::", &global_identifier, cik_normal},
5371 : /* The demangler expects anonymous namespaces to be called
5372 : something starting with '_GLOBAL__N_'. It no longer needs
5373 : to be unique to the TU. */
5374 : {"_GLOBAL__N_1", &anon_identifier, cik_normal},
5375 : {"auto", &auto_identifier, cik_normal},
5376 : {"decltype(auto)", &decltype_auto_identifier, cik_normal},
5377 : {"initializer_list", &init_list_identifier, cik_normal},
5378 : {"__for_range ", &for_range__identifier, cik_normal},
5379 : {"__for_begin ", &for_begin__identifier, cik_normal},
5380 : {"__for_end ", &for_end__identifier, cik_normal},
5381 : {"__for_range", &for_range_identifier, cik_normal},
5382 : {"__for_begin", &for_begin_identifier, cik_normal},
5383 : {"__for_end", &for_end_identifier, cik_normal},
5384 : {"abi_tag", &abi_tag_identifier, cik_normal},
5385 : {"aligned", &aligned_identifier, cik_normal},
5386 : {"begin", &begin_identifier, cik_normal},
5387 : {"end", &end_identifier, cik_normal},
5388 : {"get", &get__identifier, cik_normal},
5389 : {"gnu", &gnu_identifier, cik_normal},
5390 : {"tuple_element", &tuple_element_identifier, cik_normal},
5391 : {"tuple_size", &tuple_size_identifier, cik_normal},
5392 : {"type", &type_identifier, cik_normal},
5393 : {"value", &value_identifier, cik_normal},
5394 : {"_FUN", &fun_identifier, cik_normal},
5395 : {"__closure", &closure_identifier, cik_normal},
5396 : {"heap uninit", &heap_uninit_identifier, cik_normal},
5397 : {"heap ", &heap_identifier, cik_normal},
5398 : {"heap deleted", &heap_deleted_identifier, cik_normal},
5399 : {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
5400 : {"heap []", &heap_vec_identifier, cik_normal},
5401 : {"omp", &omp_identifier, cik_normal},
5402 : {"internal ", &internal_identifier, cik_normal},
5403 : {"annotation ", &annotation_identifier, cik_normal},
5404 : {NULL, NULL, cik_normal}
5405 : };
5406 :
5407 5004958 : for (const predefined_identifier *pid = predefined_identifiers;
5408 5004958 : pid->name; ++pid)
5409 : {
5410 4902816 : *pid->node = get_identifier (pid->name);
5411 : /* Some of these identifiers already have a special kind. */
5412 4902816 : if (pid->kind != cik_normal)
5413 817136 : set_identifier_kind (*pid->node, pid->kind);
5414 : }
5415 102142 : }
5416 :
5417 : /* Build a specific variant of operator new. */
5418 :
5419 : static void
5420 183005 : cxx_build_operator_new (tree newtype)
5421 : {
5422 183005 : tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
5423 183005 : DECL_IS_MALLOC (opnew) = 1;
5424 183005 : DECL_SET_IS_OPERATOR_NEW (opnew, true);
5425 183005 : DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
5426 183005 : opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
5427 183005 : DECL_IS_MALLOC (opnew) = 1;
5428 183005 : DECL_SET_IS_OPERATOR_NEW (opnew, true);
5429 183005 : DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
5430 183005 : }
5431 :
5432 : /* Build a specific variant of operator delete. */
5433 :
5434 : static void
5435 346039 : cxx_build_operator_delete (tree deltype)
5436 : {
5437 346039 : tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
5438 346039 : DECL_SET_IS_OPERATOR_DELETE (opdel, true);
5439 346039 : DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
5440 346039 : opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
5441 346039 : DECL_SET_IS_OPERATOR_DELETE (opdel, true);
5442 346039 : DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
5443 346039 : }
5444 :
5445 : /* Declare all variants of operator new and delete. */
5446 :
5447 : static void
5448 102142 : cxx_init_operator_new_delete_decls (void)
5449 : {
5450 102142 : tree newattrs, extvisattr;
5451 102142 : tree newtype, deltype;
5452 102142 : tree ptr_ftype_sizetype;
5453 102142 : tree new_eh_spec;
5454 102142 : tree void_ftype_ptr = build_function_type_list (void_type_node,
5455 : ptr_type_node, NULL_TREE);
5456 102142 : void_ftype_ptr
5457 102142 : = build_exception_variant (void_ftype_ptr, empty_except_spec);
5458 :
5459 102142 : ptr_ftype_sizetype
5460 102142 : = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
5461 102142 : if (cxx_dialect == cxx98)
5462 : {
5463 14220 : tree bad_alloc_id;
5464 14220 : tree bad_alloc_type_node;
5465 14220 : tree bad_alloc_decl;
5466 :
5467 14220 : push_nested_namespace (std_node);
5468 14220 : bad_alloc_id = get_identifier ("bad_alloc");
5469 14220 : bad_alloc_type_node = make_class_type (RECORD_TYPE);
5470 14220 : TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
5471 14220 : bad_alloc_decl
5472 14220 : = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
5473 14220 : DECL_CONTEXT (bad_alloc_decl) = current_namespace;
5474 14220 : pop_nested_namespace (std_node);
5475 :
5476 14220 : new_eh_spec
5477 14220 : = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
5478 : }
5479 : else
5480 87922 : new_eh_spec = noexcept_false_spec;
5481 :
5482 102142 : extvisattr = build_tree_list (get_identifier ("externally_visible"),
5483 : NULL_TREE);
5484 102142 : newattrs = tree_cons (get_identifier ("alloc_size"),
5485 : build_tree_list (NULL_TREE, integer_one_node),
5486 : extvisattr);
5487 102142 : newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
5488 102142 : newtype = build_exception_variant (newtype, new_eh_spec);
5489 102142 : deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
5490 102142 : deltype = build_exception_variant (deltype, empty_except_spec);
5491 102142 : cxx_build_operator_new (newtype);
5492 102142 : cxx_build_operator_delete (deltype);
5493 102142 : if (flag_sized_deallocation)
5494 : {
5495 : /* Also push the sized deallocation variants:
5496 : void operator delete(void*, std::size_t) throw();
5497 : void operator delete[](void*, std::size_t) throw(); */
5498 82176 : tree void_ftype_ptr_size
5499 82176 : = build_function_type_list (void_type_node, ptr_type_node,
5500 : size_type_node, NULL_TREE);
5501 82176 : deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
5502 : extvisattr);
5503 82176 : deltype = build_exception_variant (deltype, empty_except_spec);
5504 82176 : cxx_build_operator_delete (deltype);
5505 : }
5506 :
5507 102142 : if (aligned_new_threshold)
5508 : {
5509 80863 : push_nested_namespace (std_node);
5510 80863 : tree align_id = get_identifier ("align_val_t");
5511 80863 : align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
5512 : NULL_TREE, /*scoped*/true, NULL);
5513 80863 : pop_nested_namespace (std_node);
5514 :
5515 : /* operator new (size_t, align_val_t); */
5516 80863 : newtype = build_function_type_list (ptr_type_node, size_type_node,
5517 : align_type_node, NULL_TREE);
5518 80863 : newtype = cp_build_type_attribute_variant (newtype, newattrs);
5519 80863 : newtype = build_exception_variant (newtype, new_eh_spec);
5520 80863 : cxx_build_operator_new (newtype);
5521 :
5522 : /* operator delete (void *, align_val_t); */
5523 80863 : deltype = build_function_type_list (void_type_node, ptr_type_node,
5524 : align_type_node, NULL_TREE);
5525 80863 : deltype = cp_build_type_attribute_variant (deltype, extvisattr);
5526 80863 : deltype = build_exception_variant (deltype, empty_except_spec);
5527 80863 : cxx_build_operator_delete (deltype);
5528 :
5529 80863 : if (flag_sized_deallocation)
5530 : {
5531 : /* operator delete (void *, size_t, align_val_t); */
5532 80858 : deltype = build_function_type_list (void_type_node, ptr_type_node,
5533 : size_type_node, align_type_node,
5534 : NULL_TREE);
5535 80858 : deltype = cp_build_type_attribute_variant (deltype, extvisattr);
5536 80858 : deltype = build_exception_variant (deltype, empty_except_spec);
5537 80858 : cxx_build_operator_delete (deltype);
5538 : }
5539 : }
5540 102142 : }
5541 :
5542 : /* Create the predefined scalar types of C,
5543 : and some nodes representing standard constants (0, 1, (void *)0).
5544 : Initialize the global binding level.
5545 : Make definitions for built-in primitive functions. */
5546 :
5547 : void
5548 102142 : cxx_init_decl_processing (void)
5549 : {
5550 102142 : tree void_ftype;
5551 :
5552 : /* Create all the identifiers we need. */
5553 102142 : initialize_predefined_identifiers ();
5554 :
5555 : /* Create the global variables. */
5556 102142 : push_to_top_level ();
5557 :
5558 102142 : current_function_decl = NULL_TREE;
5559 102142 : current_binding_level = NULL;
5560 : /* Enter the global namespace. */
5561 102142 : gcc_assert (global_namespace == NULL_TREE);
5562 102142 : global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
5563 : void_type_node);
5564 102142 : TREE_PUBLIC (global_namespace) = true;
5565 102142 : DECL_MODULE_EXPORT_P (global_namespace) = true;
5566 102142 : DECL_CONTEXT (global_namespace)
5567 102142 : = build_translation_unit_decl (get_identifier (main_input_filename));
5568 : /* Remember whether we want the empty class passing ABI change warning
5569 : in this TU. */
5570 102142 : TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
5571 127722 : = warn_abi && abi_version_crosses (12);
5572 102142 : debug_hooks->register_main_translation_unit
5573 102142 : (DECL_CONTEXT (global_namespace));
5574 102142 : begin_scope (sk_namespace, global_namespace);
5575 102142 : current_namespace = global_namespace;
5576 :
5577 102142 : if (flag_visibility_ms_compat)
5578 6 : default_visibility = VISIBILITY_HIDDEN;
5579 :
5580 : /* Initially, C. */
5581 102142 : current_lang_name = lang_name_c;
5582 :
5583 : /* Create the `std' namespace. */
5584 102142 : push_namespace (get_identifier ("std"));
5585 102142 : std_node = current_namespace;
5586 102142 : pop_namespace ();
5587 :
5588 102142 : flag_noexcept_type = (cxx_dialect >= cxx17);
5589 :
5590 102142 : c_common_nodes_and_builtins ();
5591 :
5592 : /* Call the target stack_protect_guard hook if the stack protection
5593 : guard is declared as a global symbol. */
5594 102142 : if (targetm.stack_protect_guard_symbol_p ())
5595 24 : pushdecl (targetm.stack_protect_guard ());
5596 :
5597 102142 : tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
5598 102142 : tree decl
5599 102142 : = add_builtin_function ("__builtin_is_constant_evaluated",
5600 : bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
5601 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5602 102142 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5603 :
5604 : /* The concrete return type of __builtin_source_location is
5605 : const std::source_location::__impl*, but we can't form the type
5606 : at this point. So we initially declare it with an auto return
5607 : type which we then "deduce" from require_deduced_type upon first use. */
5608 102142 : tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
5609 102142 : decl = add_builtin_function ("__builtin_source_location",
5610 : auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
5611 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5612 102142 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5613 :
5614 102142 : tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
5615 : NULL_TREE);
5616 102142 : decl
5617 102142 : = add_builtin_function ("__builtin_is_corresponding_member",
5618 : bool_vaftype,
5619 : CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
5620 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5621 102142 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5622 :
5623 102142 : decl
5624 102142 : = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
5625 : bool_vaftype,
5626 : CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
5627 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5628 102142 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5629 :
5630 102142 : if (cxx_dialect >= cxx26)
5631 : {
5632 25231 : tree void_ptrintftype
5633 25231 : = build_function_type_list (void_type_node, ptr_type_node,
5634 : integer_type_node, NULL_TREE);
5635 25231 : decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
5636 : void_ptrintftype,
5637 : CP_BUILT_IN_EH_PTR_ADJUST_REF,
5638 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5639 25231 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5640 :
5641 : /* Similar case to __builtin_source_location above. The concrete
5642 : return type is std::exception_ptr, but we can't form the type
5643 : at this point, so it is deduced later. */
5644 25231 : decl = add_builtin_function ("__builtin_current_exception",
5645 : auto_ftype, CP_BUILT_IN_CURRENT_EXCEPTION,
5646 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5647 25231 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5648 :
5649 25231 : tree int_ftype = build_function_type_list (integer_type_node, NULL_TREE);
5650 25231 : decl = add_builtin_function ("__builtin_uncaught_exceptions",
5651 : int_ftype, CP_BUILT_IN_UNCAUGHT_EXCEPTIONS,
5652 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5653 25231 : set_call_expr_flags (decl, ECF_PURE | ECF_NOTHROW | ECF_LEAF);
5654 : }
5655 :
5656 102142 : decl
5657 102142 : = add_builtin_function ("__builtin_is_string_literal",
5658 : bool_vaftype,
5659 : CP_BUILT_IN_IS_STRING_LITERAL,
5660 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5661 102142 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5662 :
5663 102142 : tree void_vaintftype = build_varargs_function_type_list (void_type_node,
5664 : integer_type_node,
5665 : NULL_TREE);
5666 102142 : decl = add_builtin_function ("__builtin_constexpr_diag",
5667 : void_vaintftype,
5668 : CP_BUILT_IN_CONSTEXPR_DIAG,
5669 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5670 102142 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5671 :
5672 102142 : integer_two_node = build_int_cst (NULL_TREE, 2);
5673 :
5674 : /* Guess at the initial static decls size. */
5675 102142 : vec_alloc (static_decls, 500);
5676 :
5677 : /* ... and keyed classes. */
5678 102142 : vec_alloc (keyed_classes, 100);
5679 :
5680 102142 : record_builtin_type (RID_BOOL, "bool", boolean_type_node);
5681 102142 : truthvalue_type_node = boolean_type_node;
5682 102142 : truthvalue_false_node = boolean_false_node;
5683 102142 : truthvalue_true_node = boolean_true_node;
5684 :
5685 102142 : empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
5686 102142 : noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
5687 102142 : noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
5688 102142 : noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
5689 : NULL_TREE);
5690 :
5691 : #if 0
5692 : record_builtin_type (RID_MAX, NULL, string_type_node);
5693 : #endif
5694 :
5695 102142 : delta_type_node = ptrdiff_type_node;
5696 102142 : vtable_index_type = ptrdiff_type_node;
5697 :
5698 102142 : vtt_parm_type = build_pointer_type (const_ptr_type_node);
5699 102142 : void_ftype = build_function_type_list (void_type_node, NULL_TREE);
5700 :
5701 : /* Create the conversion operator marker. This operator's DECL_NAME
5702 : is in the identifier table, so we can use identifier equality to
5703 : find it. */
5704 102142 : conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
5705 : void_ftype);
5706 :
5707 : /* C++ extensions */
5708 :
5709 102142 : unknown_type_node = make_node (LANG_TYPE);
5710 102142 : record_unknown_type (unknown_type_node, "unknown type");
5711 :
5712 : /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
5713 102142 : TREE_TYPE (unknown_type_node) = unknown_type_node;
5714 :
5715 : /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
5716 : result. */
5717 102142 : TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
5718 102142 : TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
5719 :
5720 102142 : init_list_type_node = make_node (LANG_TYPE);
5721 102142 : record_unknown_type (init_list_type_node, "init list");
5722 :
5723 : /* Used when parsing to distinguish parameter-lists () and (void). */
5724 102142 : explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
5725 :
5726 102142 : {
5727 : /* Make sure we get a unique function type, so we can give
5728 : its pointer type a name. (This wins for gdb.) */
5729 102142 : tree vfunc_type = make_node (FUNCTION_TYPE);
5730 102142 : TREE_TYPE (vfunc_type) = integer_type_node;
5731 102142 : TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
5732 102142 : layout_type (vfunc_type);
5733 :
5734 102142 : vtable_entry_type = build_pointer_type (vfunc_type);
5735 : }
5736 102142 : record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
5737 :
5738 102142 : vtbl_type_node
5739 102142 : = build_cplus_array_type (vtable_entry_type, NULL_TREE);
5740 102142 : layout_type (vtbl_type_node);
5741 102142 : vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
5742 102142 : record_builtin_type (RID_MAX, NULL, vtbl_type_node);
5743 102142 : vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
5744 102142 : layout_type (vtbl_ptr_type_node);
5745 102142 : record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
5746 :
5747 102142 : push_namespace (get_identifier ("__cxxabiv1"));
5748 102142 : abi_node = current_namespace;
5749 102142 : pop_namespace ();
5750 :
5751 102142 : any_targ_node = make_node (LANG_TYPE);
5752 102142 : record_unknown_type (any_targ_node, "any type");
5753 :
5754 : /* Now, C++. */
5755 102142 : current_lang_name = lang_name_cplusplus;
5756 :
5757 102142 : if (aligned_new_threshold > 1
5758 102142 : && !pow2p_hwi (aligned_new_threshold))
5759 : {
5760 0 : error ("%<-faligned-new=%d%> is not a power of two",
5761 : aligned_new_threshold);
5762 0 : aligned_new_threshold = 1;
5763 : }
5764 102142 : if (aligned_new_threshold == -1)
5765 123407 : aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
5766 102142 : if (aligned_new_threshold == 1)
5767 80860 : aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
5768 :
5769 : /* Ensure attribs.cc is initialized. */
5770 102142 : init_attributes ();
5771 102142 : cxx_init_operator_new_delete_decls ();
5772 :
5773 : /* C++-specific nullptr initialization. */
5774 102142 : if (abi_version_at_least (9))
5775 101971 : SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
5776 102142 : record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
5777 :
5778 102142 : if (! supports_one_only ())
5779 0 : flag_weak = 0;
5780 :
5781 102142 : abort_fndecl
5782 102142 : = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
5783 : ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
5784 102142 : if (flag_weak)
5785 : /* If no definition is available, resolve references to NULL. */
5786 102112 : declare_weak (abort_fndecl);
5787 :
5788 : /* Perform other language dependent initializations. */
5789 102142 : init_class_processing ();
5790 102142 : init_rtti_processing ();
5791 102142 : init_template_processing ();
5792 :
5793 102142 : if (flag_exceptions)
5794 100885 : init_exception_processing ();
5795 :
5796 102142 : if (flag_contracts)
5797 25277 : init_contracts ();
5798 :
5799 102142 : if (modules_p ())
5800 4950 : init_modules (parse_in);
5801 :
5802 102142 : if (flag_reflection)
5803 1271 : init_reflection ();
5804 :
5805 102142 : make_fname_decl = cp_make_fname_decl;
5806 102142 : start_fname_decls ();
5807 :
5808 : /* Show we use EH for cleanups. */
5809 102142 : if (flag_exceptions)
5810 100885 : using_eh_for_cleanups ();
5811 :
5812 : /* Check that the hardware interference sizes are at least
5813 : alignof(max_align_t), as required by the standard. */
5814 102142 : const int max_align = max_align_t_align () / BITS_PER_UNIT;
5815 102142 : if (OPTION_SET_P (param_destruct_interfere_size))
5816 : {
5817 0 : if (param_destruct_interfere_size < max_align)
5818 0 : error ("%<--param destructive-interference-size=%d%> is less than "
5819 : "%d", param_destruct_interfere_size, max_align);
5820 0 : else if (param_destruct_interfere_size < param_l1_cache_line_size)
5821 0 : warning (OPT_Winterference_size,
5822 : "%<--param destructive-interference-size=%d%> "
5823 : "is less than %<--param l1-cache-line-size=%d%>",
5824 : param_destruct_interfere_size, param_l1_cache_line_size);
5825 : }
5826 102142 : else if (param_destruct_interfere_size)
5827 : /* Assume the internal value is OK. */;
5828 0 : else if (param_l1_cache_line_size >= max_align)
5829 0 : param_destruct_interfere_size = param_l1_cache_line_size;
5830 : /* else leave it unset. */
5831 :
5832 102142 : if (OPTION_SET_P (param_construct_interfere_size))
5833 : {
5834 0 : if (param_construct_interfere_size < max_align)
5835 0 : error ("%<--param constructive-interference-size=%d%> is less than "
5836 : "%d", param_construct_interfere_size, max_align);
5837 0 : else if (param_construct_interfere_size > param_l1_cache_line_size
5838 0 : && param_l1_cache_line_size >= max_align)
5839 0 : warning (OPT_Winterference_size,
5840 : "%<--param constructive-interference-size=%d%> "
5841 : "is greater than %<--param l1-cache-line-size=%d%>",
5842 : param_construct_interfere_size, param_l1_cache_line_size);
5843 : }
5844 102142 : else if (param_construct_interfere_size)
5845 : /* Assume the internal value is OK. */;
5846 0 : else if (param_l1_cache_line_size >= max_align)
5847 0 : param_construct_interfere_size = param_l1_cache_line_size;
5848 102142 : }
5849 :
5850 : /* Enter an abi node in global-module context. returns a cookie to
5851 : give to pop_abi_namespace. */
5852 :
5853 : unsigned
5854 58839 : push_abi_namespace (tree node)
5855 : {
5856 58839 : push_nested_namespace (node);
5857 58839 : push_visibility ("default", 2);
5858 58839 : unsigned flags = module_kind;
5859 58839 : module_kind = 0;
5860 58839 : return flags;
5861 : }
5862 :
5863 : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
5864 : you. */
5865 :
5866 : void
5867 58839 : pop_abi_namespace (unsigned flags, tree node)
5868 : {
5869 58839 : module_kind = flags;
5870 58839 : pop_visibility (2);
5871 58839 : pop_nested_namespace (node);
5872 58839 : }
5873 :
5874 : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
5875 : the decl, LOC is the location to give the decl, NAME is the
5876 : initialization string and TYPE_DEP indicates whether NAME depended
5877 : on the type of the function. We make use of that to detect
5878 : __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
5879 : at the point of first use, so we mustn't push the decl now. */
5880 :
5881 : static tree
5882 233391 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
5883 : {
5884 233391 : tree domain = NULL_TREE;
5885 233391 : tree init = NULL_TREE;
5886 :
5887 233391 : if (!(type_dep && current_function_decl && in_template_context))
5888 : {
5889 58829 : const char *name = NULL;
5890 58829 : bool release_name = false;
5891 :
5892 58829 : if (current_function_decl == NULL_TREE)
5893 : name = "top level";
5894 58815 : else if (type_dep == 0)
5895 : {
5896 : /* __FUNCTION__ */
5897 594 : name = fname_as_string (type_dep);
5898 594 : release_name = true;
5899 : }
5900 : else
5901 : {
5902 : /* __PRETTY_FUNCTION__ */
5903 58221 : gcc_checking_assert (type_dep == 1);
5904 58221 : name = cxx_printable_name (current_function_decl, 2);
5905 : }
5906 :
5907 58815 : if (!release_name)
5908 : {
5909 58235 : cpp_string cstr = { 0, 0 }, strname;
5910 58235 : strname.text
5911 58235 : = const_cast <unsigned char *> ((const unsigned char *) name);
5912 58235 : strname.len = strlen (name) + 1;
5913 58235 : if (cpp_translate_string (parse_in, &strname, &cstr, CPP_STRING,
5914 : false))
5915 : {
5916 58235 : name = (const char *) cstr.text;
5917 58235 : release_name = true;
5918 : }
5919 : }
5920 :
5921 58829 : size_t length = strlen (name);
5922 58829 : domain = build_index_type (size_int (length));
5923 58829 : init = build_string (length + 1, name);
5924 58829 : if (release_name)
5925 58829 : free (const_cast<char *> (name));
5926 : }
5927 :
5928 233391 : tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
5929 233391 : type = build_cplus_array_type (type, domain);
5930 :
5931 233391 : if (init)
5932 58829 : TREE_TYPE (init) = type;
5933 : else
5934 174562 : init = error_mark_node;
5935 :
5936 233391 : tree decl = build_decl (loc, VAR_DECL, id, type);
5937 :
5938 233391 : TREE_READONLY (decl) = 1;
5939 233391 : DECL_ARTIFICIAL (decl) = 1;
5940 233391 : DECL_DECLARED_CONSTEXPR_P (decl) = 1;
5941 233391 : TREE_STATIC (decl) = 1;
5942 :
5943 233391 : TREE_USED (decl) = 1;
5944 :
5945 233391 : SET_DECL_VALUE_EXPR (decl, init);
5946 233391 : DECL_HAS_VALUE_EXPR_P (decl) = 1;
5947 : /* For decl_constant_var_p. */
5948 233391 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
5949 :
5950 233391 : if (current_function_decl)
5951 : {
5952 233377 : DECL_CONTEXT (decl) = current_function_decl;
5953 233377 : decl = pushdecl_outermost_localscope (decl);
5954 233377 : if (decl != error_mark_node)
5955 233374 : add_decl_expr (decl);
5956 : else
5957 3 : gcc_assert (seen_error ());
5958 : }
5959 : else
5960 : {
5961 14 : DECL_THIS_STATIC (decl) = true;
5962 14 : decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
5963 : }
5964 :
5965 233391 : return decl;
5966 : }
5967 :
5968 : /* Install DECL as a builtin function at current global scope. Return
5969 : the new decl (if we found an existing version). Also installs it
5970 : into ::std, if it's not '_*'. */
5971 :
5972 : tree
5973 237687523 : cxx_builtin_function (tree decl)
5974 : {
5975 237687523 : retrofit_lang_decl (decl);
5976 :
5977 237687523 : DECL_ARTIFICIAL (decl) = 1;
5978 237687523 : SET_DECL_LANGUAGE (decl, lang_c);
5979 : /* Runtime library routines are, by definition, available in an
5980 : external shared object. */
5981 237687523 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
5982 237687523 : DECL_VISIBILITY_SPECIFIED (decl) = 1;
5983 :
5984 237687523 : tree id = DECL_NAME (decl);
5985 237687523 : const char *name = IDENTIFIER_POINTER (id);
5986 237687523 : bool hiding = false;
5987 237687523 : if (name[0] != '_' || name[1] != '_')
5988 : /* In the user's namespace, it must be declared before use. */
5989 : hiding = true;
5990 199357585 : else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
5991 199357585 : && !startswith (name + 2, "builtin_")
5992 223168390 : && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
5993 : "_chk", strlen ("_chk") + 1))
5994 : /* Treat __*_chk fortification functions as anticipated as well,
5995 : unless they are __builtin_*_chk. */
5996 : hiding = true;
5997 :
5998 : /* All builtins that don't begin with an '_' should additionally
5999 : go in the 'std' namespace. */
6000 237687523 : if (name[0] != '_')
6001 : {
6002 38189689 : tree std_decl = copy_decl (decl);
6003 :
6004 38189689 : push_nested_namespace (std_node);
6005 38189689 : DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
6006 38189689 : pushdecl (std_decl, hiding);
6007 38189689 : pop_nested_namespace (std_node);
6008 : }
6009 :
6010 237687523 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
6011 237687523 : decl = pushdecl (decl, hiding);
6012 :
6013 237687523 : return decl;
6014 : }
6015 :
6016 : /* Like cxx_builtin_function, but guarantee the function is added to the global
6017 : scope. This is to allow function specific options to add new machine
6018 : dependent builtins when the target ISA changes via attribute((target(...)))
6019 : which saves space on program startup if the program does not use non-generic
6020 : ISAs. */
6021 :
6022 : tree
6023 817556 : cxx_builtin_function_ext_scope (tree decl)
6024 : {
6025 817556 : push_nested_namespace (global_namespace);
6026 817556 : decl = cxx_builtin_function (decl);
6027 817556 : pop_nested_namespace (global_namespace);
6028 :
6029 817556 : return decl;
6030 : }
6031 :
6032 : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL. */
6033 :
6034 : tree
6035 0 : cxx_simulate_builtin_function_decl (tree decl)
6036 : {
6037 0 : retrofit_lang_decl (decl);
6038 :
6039 0 : DECL_ARTIFICIAL (decl) = 1;
6040 0 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
6041 0 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
6042 0 : return pushdecl (decl);
6043 : }
6044 :
6045 : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
6046 : function. Not called directly. */
6047 :
6048 : static tree
6049 1649967 : build_library_fn (tree name, enum tree_code operator_code, tree type,
6050 : int ecf_flags)
6051 : {
6052 1649967 : tree fn = build_lang_decl (FUNCTION_DECL, name, type);
6053 1649967 : DECL_EXTERNAL (fn) = 1;
6054 1649967 : TREE_PUBLIC (fn) = 1;
6055 1649967 : DECL_ARTIFICIAL (fn) = 1;
6056 1649967 : DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
6057 1649967 : = OVL_OP_INFO (false, operator_code)->ovl_op_code;
6058 1649967 : SET_DECL_LANGUAGE (fn, lang_c);
6059 : /* Runtime library routines are, by definition, available in an
6060 : external shared object. */
6061 1649967 : DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
6062 1649967 : DECL_VISIBILITY_SPECIFIED (fn) = 1;
6063 1649967 : set_call_expr_flags (fn, ecf_flags);
6064 1649967 : return fn;
6065 : }
6066 :
6067 : /* Returns the _DECL for a library function with C++ linkage. */
6068 :
6069 : static tree
6070 1159213 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
6071 : int ecf_flags)
6072 : {
6073 1159213 : tree fn = build_library_fn (name, operator_code, type, ecf_flags);
6074 1159213 : DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
6075 1159213 : SET_DECL_LANGUAGE (fn, lang_cplusplus);
6076 1159213 : return fn;
6077 : }
6078 :
6079 : /* Like build_library_fn, but takes a C string instead of an
6080 : IDENTIFIER_NODE. */
6081 :
6082 : tree
6083 107143 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
6084 : {
6085 107143 : return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
6086 : }
6087 :
6088 : /* Like build_cp_library_fn, but takes a C string instead of an
6089 : IDENTIFIER_NODE. */
6090 :
6091 : tree
6092 101125 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
6093 : {
6094 101125 : return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
6095 101125 : ecf_flags);
6096 : }
6097 :
6098 : /* Like build_library_fn, but also pushes the function so that we will
6099 : be able to find it via get_global_binding. Also, the function
6100 : may throw exceptions listed in RAISES. */
6101 :
6102 : tree
6103 383611 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
6104 : {
6105 383611 : if (raises)
6106 42827 : type = build_exception_variant (type, raises);
6107 :
6108 383611 : tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
6109 383611 : return pushdecl_top_level (fn);
6110 : }
6111 :
6112 : /* Like build_cp_library_fn, but also pushes the function so that it
6113 : will be found by normal lookup. */
6114 :
6115 : static tree
6116 1058088 : push_cp_library_fn (enum tree_code operator_code, tree type,
6117 : int ecf_flags)
6118 : {
6119 1058088 : tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
6120 : operator_code, type, ecf_flags);
6121 1058088 : pushdecl (fn);
6122 1058088 : if (flag_tm)
6123 3556 : apply_tm_attr (fn, get_identifier ("transaction_safe"));
6124 1058088 : return fn;
6125 : }
6126 :
6127 : /* Like push_library_fn, but also note that this function throws
6128 : and does not return. Used for __throw_foo and the like. */
6129 :
6130 : tree
6131 111847 : push_throw_library_fn (tree name, tree type)
6132 : {
6133 111847 : tree fn = push_library_fn (name, type, NULL_TREE,
6134 : ECF_NORETURN | ECF_XTHROW | ECF_COLD);
6135 111847 : return fn;
6136 : }
6137 :
6138 : /* When we call finish_struct for an anonymous union, we create
6139 : default copy constructors and such. But, an anonymous union
6140 : shouldn't have such things; this function undoes the damage to the
6141 : anonymous union type T.
6142 :
6143 : (The reason that we create the synthesized methods is that we don't
6144 : distinguish `union { int i; }' from `typedef union { int i; } U'.
6145 : The first is an anonymous union; the second is just an ordinary
6146 : union type.) */
6147 :
6148 : void
6149 178110 : fixup_anonymous_aggr (tree t)
6150 : {
6151 : /* Wipe out memory of synthesized methods. */
6152 178110 : TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
6153 178110 : TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
6154 178110 : TYPE_HAS_COPY_CTOR (t) = 0;
6155 178110 : TYPE_HAS_CONST_COPY_CTOR (t) = 0;
6156 178110 : TYPE_HAS_COPY_ASSIGN (t) = 0;
6157 178110 : TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
6158 :
6159 : /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
6160 : invalid members. */
6161 1041511 : for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
6162 : {
6163 863401 : if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
6164 0 : *prev_p = DECL_CHAIN (probe);
6165 : else
6166 863401 : prev_p = &DECL_CHAIN (probe);
6167 :
6168 863401 : if (DECL_ARTIFICIAL (probe)
6169 863401 : && (!DECL_IMPLICIT_TYPEDEF_P (probe)
6170 77680 : || TYPE_ANON_P (TREE_TYPE (probe))))
6171 292919 : continue;
6172 :
6173 570482 : if (TREE_CODE (probe) != FIELD_DECL
6174 570428 : || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
6175 : {
6176 : /* We already complained about static data members in
6177 : finish_static_data_member_decl. */
6178 66 : if (!VAR_P (probe))
6179 : {
6180 51 : auto_diagnostic_group d;
6181 51 : if (permerror (DECL_SOURCE_LOCATION (probe),
6182 51 : TREE_CODE (t) == UNION_TYPE
6183 : ? "%q#D invalid; an anonymous union may "
6184 : "only have public non-static data members"
6185 : : "%q#D invalid; an anonymous struct may "
6186 : "only have public non-static data members", probe))
6187 : {
6188 51 : static bool hint;
6189 51 : if (flag_permissive && !hint)
6190 : {
6191 6 : hint = true;
6192 6 : inform (DECL_SOURCE_LOCATION (probe),
6193 : "this flexibility is deprecated and will be "
6194 : "removed");
6195 : }
6196 : }
6197 51 : }
6198 : }
6199 : }
6200 :
6201 : /* Splice all functions out of CLASSTYPE_MEMBER_VEC. */
6202 178110 : vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
6203 178110 : unsigned store = 0;
6204 528737 : for (tree elt : vec)
6205 350627 : if (!is_overloaded_fn (elt))
6206 350606 : (*vec)[store++] = elt;
6207 178110 : vec_safe_truncate (vec, store);
6208 :
6209 : /* Wipe RTTI info. */
6210 178110 : SET_CLASSTYPE_TYPEINFO_VAR (t, NULL_TREE);
6211 :
6212 : /* Anonymous aggregates cannot have fields with ctors, dtors or complex
6213 : assignment operators (because they cannot have these methods themselves).
6214 : For anonymous unions this is already checked because they are not allowed
6215 : in any union, otherwise we have to check it. */
6216 178110 : if (TREE_CODE (t) != UNION_TYPE)
6217 : {
6218 37892 : tree field, type;
6219 :
6220 37892 : if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
6221 : {
6222 9 : error_at (location_of (t), "anonymous struct with base classes");
6223 : /* Avoid ICE after error on anon-struct9.C. */
6224 9 : TYPE_NEEDS_CONSTRUCTING (t) = false;
6225 : }
6226 :
6227 152411 : for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
6228 114519 : if (TREE_CODE (field) == FIELD_DECL)
6229 : {
6230 76526 : type = TREE_TYPE (field);
6231 76526 : if (CLASS_TYPE_P (type))
6232 : {
6233 61 : if (TYPE_NEEDS_CONSTRUCTING (type))
6234 6 : error ("member %q+#D with constructor not allowed "
6235 : "in anonymous aggregate", field);
6236 61 : if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
6237 0 : error ("member %q+#D with destructor not allowed "
6238 : "in anonymous aggregate", field);
6239 61 : if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
6240 0 : error ("member %q+#D with copy assignment operator "
6241 : "not allowed in anonymous aggregate", field);
6242 : }
6243 : }
6244 : }
6245 178110 : }
6246 :
6247 : /* Warn for an attribute located at LOCATION that appertains to the
6248 : class type CLASS_TYPE that has not been properly placed after its
6249 : class-key, in it class-specifier. */
6250 :
6251 : void
6252 117 : warn_misplaced_attr_for_class_type (location_t location,
6253 : tree class_type)
6254 : {
6255 117 : gcc_assert (OVERLOAD_TYPE_P (class_type));
6256 :
6257 117 : auto_diagnostic_group d;
6258 117 : if (warning_at (location, OPT_Wattributes,
6259 : "attribute ignored in declaration "
6260 : "of %q#T", class_type))
6261 117 : inform (location,
6262 : "attribute for %q#T must follow the %qs keyword",
6263 : class_type, class_key_or_enum_as_string (class_type));
6264 117 : }
6265 :
6266 : /* Returns the cv-qualifiers that apply to the type specified
6267 : by the DECLSPECS. */
6268 :
6269 : static int
6270 1068617977 : get_type_quals (const cp_decl_specifier_seq *declspecs)
6271 : {
6272 1068617977 : int type_quals = TYPE_UNQUALIFIED;
6273 :
6274 1068617977 : if (decl_spec_seq_has_spec_p (declspecs, ds_const))
6275 110501985 : type_quals |= TYPE_QUAL_CONST;
6276 1068617977 : if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
6277 1782284 : type_quals |= TYPE_QUAL_VOLATILE;
6278 1068617977 : if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
6279 34 : type_quals |= TYPE_QUAL_RESTRICT;
6280 :
6281 1068617977 : return type_quals;
6282 : }
6283 :
6284 : /* Make sure that a declaration with no declarator is well-formed, i.e.
6285 : just declares a tagged type or anonymous union.
6286 :
6287 : Returns the type declared; or NULL_TREE if none. */
6288 :
6289 : tree
6290 38445420 : check_tag_decl (cp_decl_specifier_seq *declspecs,
6291 : bool explicit_type_instantiation_p)
6292 : {
6293 38445420 : int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
6294 38445420 : int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
6295 : /* If a class, struct, or enum type is declared by the DECLSPECS
6296 : (i.e, if a class-specifier, enum-specifier, or non-typename
6297 : elaborated-type-specifier appears in the DECLSPECS),
6298 : DECLARED_TYPE is set to the corresponding type. */
6299 38445420 : tree declared_type = NULL_TREE;
6300 38445420 : bool error_p = false;
6301 :
6302 38445420 : if (declspecs->multiple_types_p)
6303 26 : error_at (smallest_type_location (declspecs),
6304 : "multiple types in one declaration");
6305 38445394 : else if (declspecs->redefined_builtin_type)
6306 : {
6307 21 : location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
6308 21 : if (!in_system_header_at (loc))
6309 9 : permerror (loc, "redeclaration of C++ built-in type %qT",
6310 : declspecs->redefined_builtin_type);
6311 21 : return NULL_TREE;
6312 : }
6313 :
6314 38445399 : if (declspecs->type
6315 38445384 : && TYPE_P (declspecs->type)
6316 76520543 : && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
6317 38074111 : && MAYBE_CLASS_TYPE_P (declspecs->type))
6318 1925152 : || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
6319 : declared_type = declspecs->type;
6320 371333 : else if (declspecs->type == error_mark_node)
6321 1502 : error_p = true;
6322 :
6323 38445399 : if (type_uses_auto (declared_type))
6324 : {
6325 8 : error_at (declspecs->locations[ds_type_spec],
6326 : "%<auto%> can only be specified for variables "
6327 : "or function declarations");
6328 8 : return error_mark_node;
6329 : }
6330 :
6331 38445391 : if (declared_type && !OVERLOAD_TYPE_P (declared_type))
6332 : declared_type = NULL_TREE;
6333 :
6334 38445391 : if (!declared_type && !saw_friend && !error_p)
6335 91 : permerror (input_location, "declaration does not declare anything");
6336 : /* Check for an anonymous union. */
6337 38074031 : else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
6338 110923330 : && TYPE_UNNAMED_P (declared_type))
6339 : {
6340 : /* 7/3 In a simple-declaration, the optional init-declarator-list
6341 : can be omitted only when declaring a class (clause 9) or
6342 : enumeration (7.2), that is, when the decl-specifier-seq contains
6343 : either a class-specifier, an elaborated-type-specifier with
6344 : a class-key (9.1), or an enum-specifier. In these cases and
6345 : whenever a class-specifier or enum-specifier is present in the
6346 : decl-specifier-seq, the identifiers in these specifiers are among
6347 : the names being declared by the declaration (as class-name,
6348 : enum-names, or enumerators, depending on the syntax). In such
6349 : cases, and except for the declaration of an unnamed bit-field (9.6),
6350 : the decl-specifier-seq shall introduce one or more names into the
6351 : program, or shall redeclare a name introduced by a previous
6352 : declaration. [Example:
6353 : enum { }; // ill-formed
6354 : typedef class { }; // ill-formed
6355 : --end example] */
6356 178116 : if (saw_typedef)
6357 : {
6358 6 : error_at (declspecs->locations[ds_typedef],
6359 : "missing type-name in typedef-declaration");
6360 6 : return NULL_TREE;
6361 : }
6362 178110 : /* Anonymous unions are objects, so they can have specifiers. */;
6363 178110 : SET_ANON_AGGR_TYPE_P (declared_type);
6364 :
6365 178110 : if (TREE_CODE (declared_type) != UNION_TYPE)
6366 37892 : pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
6367 37892 : OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
6368 : }
6369 :
6370 : else
6371 : {
6372 38267184 : if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
6373 9 : error_at (declspecs->locations[ds_inline],
6374 : "%<inline%> can only be specified for functions");
6375 38267175 : else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
6376 3 : error_at (declspecs->locations[ds_virtual],
6377 : "%<virtual%> can only be specified for functions");
6378 38267172 : else if (saw_friend
6379 38267172 : && (!current_class_type
6380 2133500 : || current_scope () != current_class_type))
6381 0 : error_at (declspecs->locations[ds_friend],
6382 : "%<friend%> can only be specified inside a class");
6383 38267172 : else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
6384 3 : error_at (declspecs->locations[ds_explicit],
6385 : "%<explicit%> can only be specified for constructors");
6386 38267169 : else if (declspecs->storage_class)
6387 3 : error_at (declspecs->locations[ds_storage_class],
6388 : "a storage class can only be specified for objects "
6389 : "and functions");
6390 38267166 : else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
6391 9 : error_at (declspecs->locations[ds_const],
6392 : "%<const%> can only be specified for objects and "
6393 : "functions");
6394 38267157 : else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
6395 3 : error_at (declspecs->locations[ds_volatile],
6396 : "%<volatile%> can only be specified for objects and "
6397 : "functions");
6398 38267154 : else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
6399 3 : error_at (declspecs->locations[ds_restrict],
6400 : "%<__restrict%> can only be specified for objects and "
6401 : "functions");
6402 38267151 : else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
6403 3 : error_at (declspecs->locations[ds_thread],
6404 : "%<__thread%> can only be specified for objects "
6405 : "and functions");
6406 38267148 : else if (saw_typedef)
6407 24 : warning_at (declspecs->locations[ds_typedef], 0,
6408 : "%<typedef%> was ignored in this declaration");
6409 38267124 : else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
6410 9 : error_at (declspecs->locations[ds_constexpr],
6411 : "%qs cannot be used for type declarations", "constexpr");
6412 38267115 : else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
6413 3 : error_at (declspecs->locations[ds_constinit],
6414 : "%qs cannot be used for type declarations", "constinit");
6415 38267112 : else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
6416 3 : error_at (declspecs->locations[ds_consteval],
6417 : "%qs cannot be used for type declarations", "consteval");
6418 : }
6419 :
6420 38445385 : if (declspecs->attributes && warn_attributes && declared_type)
6421 : {
6422 30 : location_t loc;
6423 24 : if (!CLASS_TYPE_P (declared_type)
6424 54 : || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
6425 : /* For a non-template class, use the name location. */
6426 21 : loc = location_of (declared_type);
6427 : else
6428 : /* For a template class (an explicit instantiation), use the
6429 : current location. */
6430 9 : loc = input_location;
6431 :
6432 30 : if (explicit_type_instantiation_p)
6433 : /* [dcl.attr.grammar]/4:
6434 :
6435 : No attribute-specifier-seq shall appertain to an explicit
6436 : instantiation. */
6437 : {
6438 6 : auto_diagnostic_group d;
6439 6 : if (warning_at (loc, OPT_Wattributes,
6440 : "attribute ignored in explicit instantiation %q#T",
6441 : declared_type))
6442 6 : inform (loc,
6443 : "no attribute can be applied to "
6444 : "an explicit instantiation");
6445 6 : }
6446 : else
6447 24 : warn_misplaced_attr_for_class_type (loc, declared_type);
6448 : }
6449 :
6450 38445385 : if (declspecs->std_attributes
6451 93 : && declared_type
6452 38445475 : && any_nonignored_attribute_p (declspecs->std_attributes))
6453 : {
6454 90 : auto_diagnostic_group d;
6455 90 : if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
6456 : "attribute ignored"))
6457 90 : inform (declspecs->locations[ds_std_attribute],
6458 : "an attribute that appertains to a type-specifier is ignored");
6459 90 : }
6460 :
6461 : return declared_type;
6462 : }
6463 :
6464 : /* Called when a declaration is seen that contains no names to declare.
6465 : If its type is a reference to a structure, union or enum inherited
6466 : from a containing scope, shadow that tag name for the current scope
6467 : with a forward reference.
6468 : If its type defines a new named structure or union
6469 : or defines an enum, it is valid but we need not do anything here.
6470 : Otherwise, it is an error.
6471 :
6472 : C++: may have to grok the declspecs to learn about static,
6473 : complain for anonymous unions.
6474 :
6475 : Returns the TYPE declared -- or NULL_TREE if none. */
6476 :
6477 : tree
6478 33699289 : shadow_tag (cp_decl_specifier_seq *declspecs)
6479 : {
6480 33699289 : tree t = check_tag_decl (declspecs,
6481 : /*explicit_type_instantiation_p=*/false);
6482 :
6483 33699289 : if (!t)
6484 : return NULL_TREE;
6485 :
6486 33697774 : t = maybe_process_partial_specialization (t);
6487 33697774 : if (t == error_mark_node)
6488 : return NULL_TREE;
6489 :
6490 : /* This is where the variables in an anonymous union are
6491 : declared. An anonymous union declaration looks like:
6492 : union { ... } ;
6493 : because there is no declarator after the union, the parser
6494 : sends that declaration here. */
6495 33695869 : if (ANON_AGGR_TYPE_P (t))
6496 : {
6497 386 : fixup_anonymous_aggr (t);
6498 :
6499 386 : if (TYPE_FIELDS (t))
6500 : {
6501 386 : tree decl = grokdeclarator (/*declarator=*/NULL,
6502 : declspecs, NORMAL, 0, NULL);
6503 386 : finish_anon_union (decl);
6504 : }
6505 : }
6506 :
6507 : return t;
6508 : }
6509 :
6510 : /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
6511 :
6512 : tree
6513 417884323 : groktypename (cp_decl_specifier_seq *type_specifiers,
6514 : const cp_declarator *declarator,
6515 : bool is_template_arg)
6516 : {
6517 417884323 : tree attrs;
6518 417884323 : tree type;
6519 69003430 : enum decl_context context
6520 417884323 : = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
6521 417884323 : attrs = type_specifiers->attributes;
6522 417884323 : type_specifiers->attributes = NULL_TREE;
6523 417884323 : type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
6524 417884323 : if (attrs && type != error_mark_node)
6525 : {
6526 673 : if (CLASS_TYPE_P (type))
6527 6 : warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
6528 : "outside of definition", type);
6529 667 : else if (MAYBE_CLASS_TYPE_P (type))
6530 : /* A template type parameter or other dependent type. */
6531 9 : warning (OPT_Wattributes, "ignoring attributes applied to dependent "
6532 : "type %qT without an associated declaration", type);
6533 : else
6534 658 : cplus_decl_attributes (&type, attrs, 0);
6535 : }
6536 417884323 : return type;
6537 : }
6538 :
6539 : /* Process a DECLARATOR for a function-scope or namespace-scope
6540 : variable or function declaration.
6541 : (Function definitions go through start_function; class member
6542 : declarations appearing in the body of the class go through
6543 : grokfield.) The DECL corresponding to the DECLARATOR is returned.
6544 : If an error occurs, the error_mark_node is returned instead.
6545 :
6546 : DECLSPECS are the decl-specifiers for the declaration. INITIALIZED is
6547 : SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
6548 : for an explicitly defaulted function, or SD_DELETED for an explicitly
6549 : deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
6550 : implicitly initialized via a default constructor. It can also be
6551 : SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
6552 : mark the new decl as DECL_DECOMPOSITION_P.
6553 :
6554 : ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
6555 : declaration.
6556 :
6557 : The scope represented by the context of the returned DECL is pushed
6558 : (if it is not the global namespace) and is assigned to
6559 : *PUSHED_SCOPE_P. The caller is then responsible for calling
6560 : pop_scope on *PUSHED_SCOPE_P if it is set. */
6561 :
6562 : tree
6563 131006344 : start_decl (const cp_declarator *declarator,
6564 : cp_decl_specifier_seq *declspecs,
6565 : int initialized,
6566 : tree attributes,
6567 : tree prefix_attributes,
6568 : tree *pushed_scope_p)
6569 : {
6570 131006344 : tree decl;
6571 131006344 : tree context;
6572 131006344 : bool was_public;
6573 131006344 : int flags;
6574 131006344 : bool alias;
6575 131006344 : tree initial;
6576 :
6577 131006344 : *pushed_scope_p = NULL_TREE;
6578 :
6579 131006344 : if (prefix_attributes != error_mark_node)
6580 131006342 : attributes = attr_chainon (attributes, prefix_attributes);
6581 :
6582 131006344 : decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
6583 : &attributes);
6584 :
6585 131006344 : if (decl == NULL_TREE || VOID_TYPE_P (decl)
6586 131006344 : || decl == error_mark_node
6587 131004189 : || prefix_attributes == error_mark_node)
6588 2157 : return error_mark_node;
6589 :
6590 131004187 : context = CP_DECL_CONTEXT (decl);
6591 131004187 : if (context != global_namespace)
6592 22988395 : *pushed_scope_p = push_scope (context);
6593 :
6594 131004187 : if (initialized && TREE_CODE (decl) == TYPE_DECL)
6595 : {
6596 27 : error_at (DECL_SOURCE_LOCATION (decl),
6597 : "typedef %qD is initialized (use %qs instead)",
6598 : decl, "decltype");
6599 27 : return error_mark_node;
6600 : }
6601 :
6602 131004160 : if (flag_contracts
6603 14310324 : && TREE_CODE (decl) == FUNCTION_DECL
6604 4030168 : && !processing_template_decl
6605 3262259 : && DECL_RESULT (decl)
6606 134260064 : && is_auto (TREE_TYPE (DECL_RESULT (decl))))
6607 42 : for (tree ca = get_fn_contract_specifiers (decl); ca; ca = TREE_CHAIN (ca))
6608 9 : if (POSTCONDITION_P (CONTRACT_STATEMENT (ca))
6609 9 : && POSTCONDITION_IDENTIFIER (CONTRACT_STATEMENT (ca)))
6610 : {
6611 3 : error_at (DECL_SOURCE_LOCATION (decl),
6612 : "postconditions with deduced result name types must only"
6613 : " appear on function definitions");
6614 3 : return error_mark_node;
6615 : }
6616 : /* Save the DECL_INITIAL value in case it gets clobbered to assist
6617 : with attribute validation. */
6618 131004157 : initial = DECL_INITIAL (decl);
6619 :
6620 131004157 : if (initialized)
6621 : {
6622 63435198 : if (! toplevel_bindings_p ()
6623 63435198 : && DECL_EXTERNAL (decl))
6624 3 : warning (0, "declaration of %q#D has %<extern%> and is initialized",
6625 : decl);
6626 63435198 : DECL_EXTERNAL (decl) = 0;
6627 63435198 : if (toplevel_bindings_p ())
6628 7616115 : TREE_STATIC (decl) = 1;
6629 : /* Tell 'cplus_decl_attributes' this is an initialized decl,
6630 : even though we might not yet have the initializer expression. */
6631 63435198 : if (!DECL_INITIAL (decl))
6632 62850203 : DECL_INITIAL (decl) = error_mark_node;
6633 : }
6634 131004157 : alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
6635 :
6636 131004157 : if (alias && TREE_CODE (decl) == FUNCTION_DECL)
6637 3988 : record_key_method_defined (decl);
6638 :
6639 : /* If this is a typedef that names the class for linkage purposes
6640 : (7.1.3p8), apply any attributes directly to the type. */
6641 131004157 : if (TREE_CODE (decl) == TYPE_DECL
6642 131004157 : && TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl))
6643 : flags = ATTR_FLAG_TYPE_IN_PLACE;
6644 : else
6645 : flags = 0;
6646 :
6647 : /* Set attributes here so if duplicate decl, will have proper attributes. */
6648 131004157 : cplus_decl_attributes (&decl, attributes, flags);
6649 :
6650 : /* Restore the original DECL_INITIAL that we may have clobbered earlier to
6651 : assist with attribute validation. */
6652 131004157 : DECL_INITIAL (decl) = initial;
6653 :
6654 : /* Dllimported symbols cannot be defined. Static data members (which
6655 : can be initialized in-class and dllimported) go through grokfield,
6656 : not here, so we don't need to exclude those decls when checking for
6657 : a definition. */
6658 131004157 : if (initialized && DECL_DLLIMPORT_P (decl))
6659 : {
6660 0 : error_at (DECL_SOURCE_LOCATION (decl),
6661 : "definition of %q#D is marked %<dllimport%>", decl);
6662 0 : DECL_DLLIMPORT_P (decl) = 0;
6663 : }
6664 :
6665 : /* If #pragma weak was used, mark the decl weak now. */
6666 131004157 : if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
6667 47866580 : maybe_apply_pragma_weak (decl);
6668 :
6669 131004157 : if (TREE_CODE (decl) == FUNCTION_DECL
6670 38807382 : && DECL_DECLARED_INLINE_P (decl)
6671 3456242 : && DECL_UNINLINABLE (decl)
6672 131004157 : && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
6673 : {
6674 0 : auto_urlify_attributes sentinel;
6675 0 : warning_at (DECL_SOURCE_LOCATION (decl), 0,
6676 : "inline function %qD given attribute %qs", decl, "noinline");
6677 0 : }
6678 :
6679 131004157 : if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
6680 : {
6681 868993 : bool this_tmpl = (current_template_depth
6682 868993 : > template_class_depth (context));
6683 868993 : if (VAR_P (decl))
6684 : {
6685 508119 : tree field = lookup_field (context, DECL_NAME (decl), 0, false);
6686 508119 : if (field == NULL_TREE
6687 508119 : || !(VAR_P (field) || variable_template_p (field)))
6688 6 : error ("%q+#D is not a static data member of %q#T", decl, context);
6689 508113 : else if (variable_template_p (field)
6690 508113 : && (DECL_LANG_SPECIFIC (decl)
6691 147 : && DECL_TEMPLATE_SPECIALIZATION (decl)))
6692 : /* OK, specialization was already checked. */;
6693 508044 : else if (variable_template_p (field) && !this_tmpl)
6694 : {
6695 3 : auto_diagnostic_group d;
6696 3 : error_at (DECL_SOURCE_LOCATION (decl),
6697 : "non-member-template declaration of %qD", decl);
6698 3 : inform (DECL_SOURCE_LOCATION (field), "does not match "
6699 : "member template declaration here");
6700 3 : return error_mark_node;
6701 3 : }
6702 : else
6703 : {
6704 508041 : if (variable_template_p (field))
6705 75 : field = DECL_TEMPLATE_RESULT (field);
6706 :
6707 508041 : if (DECL_CONTEXT (field) != context)
6708 : {
6709 3 : if (!same_type_p (DECL_CONTEXT (field), context))
6710 3 : permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
6711 : "to be defined as %<%T::%D%>",
6712 3 : DECL_CONTEXT (field), DECL_NAME (decl),
6713 3 : context, DECL_NAME (decl));
6714 3 : DECL_CONTEXT (decl) = DECL_CONTEXT (field);
6715 : }
6716 :
6717 508041 : if (modules_p () && !module_may_redeclare (field))
6718 30 : return error_mark_node;
6719 :
6720 : /* Static data member are tricky; an in-class initialization
6721 : still doesn't provide a definition, so the in-class
6722 : declaration will have DECL_EXTERNAL set, but will have an
6723 : initialization. Thus, duplicate_decls won't warn
6724 : about this situation, and so we check here. */
6725 508011 : if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
6726 9 : error ("duplicate initialization of %qD", decl);
6727 508011 : field = duplicate_decls (decl, field);
6728 508011 : if (field == error_mark_node)
6729 : return error_mark_node;
6730 507955 : else if (field)
6731 507955 : decl = field;
6732 : }
6733 : }
6734 : else
6735 : {
6736 360886 : tree field = check_classfn (context, decl,
6737 : this_tmpl
6738 12 : ? current_template_parms
6739 : : NULL_TREE);
6740 360799 : if (field && field != error_mark_node
6741 721673 : && duplicate_decls (decl, field))
6742 360799 : decl = field;
6743 : }
6744 :
6745 : /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
6746 868904 : DECL_IN_AGGR_P (decl) = 0;
6747 : /* Do not mark DECL as an explicit specialization if it was not
6748 : already marked as an instantiation; a declaration should
6749 : never be marked as a specialization unless we know what
6750 : template is being specialized. */
6751 868904 : if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
6752 : {
6753 358868 : SET_DECL_TEMPLATE_SPECIALIZATION (decl);
6754 358868 : if (TREE_CODE (decl) == FUNCTION_DECL)
6755 338151 : DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
6756 338151 : && DECL_NONGNU_INLINE_P (decl));
6757 : else
6758 20717 : DECL_COMDAT (decl) = false;
6759 :
6760 : /* [temp.expl.spec] An explicit specialization of a static data
6761 : member of a template is a definition if the declaration
6762 : includes an initializer; otherwise, it is a declaration.
6763 :
6764 : We check for processing_specialization so this only applies
6765 : to the new specialization syntax. */
6766 358868 : if (!initialized && processing_specialization)
6767 358666 : DECL_EXTERNAL (decl) = 1;
6768 : }
6769 :
6770 1227618 : if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
6771 : /* Aliases are definitions. */
6772 868940 : && !alias)
6773 : {
6774 9 : permerror (declarator->id_loc,
6775 : "declaration of %q#D outside of class is not definition",
6776 : decl);
6777 : }
6778 : }
6779 :
6780 : /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works. */
6781 131004068 : if (initialized == SD_DECOMPOSITION)
6782 487935 : fit_decomposition_lang_decl (decl, NULL_TREE);
6783 :
6784 131004068 : was_public = TREE_PUBLIC (decl);
6785 :
6786 223207776 : if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
6787 131589090 : && current_function_decl)
6788 : {
6789 : /* A function-scope decl of some namespace-scope decl. */
6790 62545 : DECL_LOCAL_DECL_P (decl) = true;
6791 62545 : if (named_module_attach_p ())
6792 3 : error_at (declarator->id_loc,
6793 : "block-scope extern declaration %q#D must not be"
6794 : " attached to a named module", decl);
6795 : }
6796 :
6797 : /* Enter this declaration into the symbol table. Don't push the plain
6798 : VAR_DECL for a variable template. */
6799 131004068 : if (!template_parm_scope_p ()
6800 131004068 : || !VAR_P (decl))
6801 126714283 : decl = maybe_push_decl (decl);
6802 :
6803 131004068 : if (processing_template_decl)
6804 83129551 : decl = push_template_decl (decl);
6805 :
6806 131004068 : if (decl == error_mark_node)
6807 : return error_mark_node;
6808 :
6809 131003628 : if (VAR_P (decl)
6810 69731075 : && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
6811 70019 : && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
6812 : /* But not templated variables. */
6813 131034410 : && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
6814 : {
6815 : /* This is a const variable with implicit 'static'. Set
6816 : DECL_THIS_STATIC so we can tell it from variables that are
6817 : !TREE_PUBLIC because of the anonymous namespace. */
6818 30782 : gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
6819 30782 : DECL_THIS_STATIC (decl) = 1;
6820 : }
6821 :
6822 73925756 : if (current_function_decl && VAR_P (decl)
6823 61297294 : && maybe_constexpr_fn (current_function_decl)
6824 147037181 : && cxx_dialect < cxx23)
6825 : {
6826 12725645 : bool ok = false;
6827 12725645 : if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
6828 : {
6829 9 : if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
6830 18 : error_at (DECL_SOURCE_LOCATION (decl),
6831 : "%qD defined %<thread_local%> in %qs function only "
6832 : "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
6833 9 : DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
6834 : ? "consteval" : "constexpr");
6835 : }
6836 12725636 : else if (TREE_STATIC (decl))
6837 : {
6838 50 : if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
6839 72 : error_at (DECL_SOURCE_LOCATION (decl),
6840 : "%qD defined %<static%> in %qs function only available "
6841 : "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
6842 36 : DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
6843 : ? "consteval" : "constexpr");
6844 : }
6845 : else
6846 : ok = true;
6847 45 : if (!ok)
6848 59 : cp_function_chain->invalid_constexpr = true;
6849 : }
6850 :
6851 131003628 : if (!processing_template_decl && VAR_P (decl))
6852 8739461 : start_decl_1 (decl, initialized);
6853 :
6854 131003625 : return decl;
6855 : }
6856 :
6857 : /* Process the declaration of a variable DECL. INITIALIZED is true
6858 : iff DECL is explicitly initialized. (INITIALIZED is false if the
6859 : variable is initialized via an implicitly-called constructor.)
6860 : This function must be called for ordinary variables (including, for
6861 : example, implicit instantiations of templates), but must not be
6862 : called for template declarations. */
6863 :
6864 : void
6865 8748893 : start_decl_1 (tree decl, bool initialized)
6866 : {
6867 8748893 : gcc_checking_assert (!processing_template_decl);
6868 :
6869 8748893 : if (error_operand_p (decl))
6870 : return;
6871 :
6872 8748878 : gcc_checking_assert (VAR_P (decl));
6873 :
6874 8748878 : tree type = TREE_TYPE (decl);
6875 8748878 : bool complete_p = COMPLETE_TYPE_P (type);
6876 8748878 : bool aggregate_definition_p
6877 8748878 : = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
6878 :
6879 : /* If an explicit initializer is present, or if this is a definition
6880 : of an aggregate, then we need a complete type at this point.
6881 : (Scalars are always complete types, so there is nothing to
6882 : check.) This code just sets COMPLETE_P; errors (if necessary)
6883 : are issued below. */
6884 4533348 : if ((initialized || aggregate_definition_p)
6885 7708901 : && !complete_p
6886 6176496 : && COMPLETE_TYPE_P (complete_type (type)))
6887 : {
6888 338932 : complete_p = true;
6889 : /* We will not yet have set TREE_READONLY on DECL if the type
6890 : was "const", but incomplete, before this point. But, now, we
6891 : have a complete type, so we can try again. */
6892 338932 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
6893 : }
6894 :
6895 8748875 : if (initialized)
6896 : /* Is it valid for this decl to have an initializer at all? */
6897 : {
6898 : /* Don't allow initializations for incomplete types except for
6899 : arrays which might be completed by the initialization. */
6900 6941595 : if (complete_p)
6901 : ; /* A complete type is ok. */
6902 1303975 : else if (type_uses_auto (type))
6903 : ; /* An auto type is ok. */
6904 122690 : else if (TREE_CODE (type) != ARRAY_TYPE)
6905 : {
6906 27 : auto_diagnostic_group d;
6907 27 : error ("variable %q#D has initializer but incomplete type", decl);
6908 48 : maybe_suggest_missing_header (input_location,
6909 27 : TYPE_IDENTIFIER (type),
6910 27 : CP_TYPE_CONTEXT (type));
6911 27 : type = TREE_TYPE (decl) = error_mark_node;
6912 27 : }
6913 122663 : else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
6914 : {
6915 0 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
6916 0 : error ("elements of array %q#D have incomplete type", decl);
6917 : /* else we already gave an error in start_decl. */
6918 : }
6919 : }
6920 1807280 : else if (aggregate_definition_p && !complete_p)
6921 : {
6922 238 : if (type_uses_auto (type))
6923 71 : gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
6924 : else
6925 : {
6926 167 : auto_diagnostic_group d;
6927 167 : error ("aggregate %q#D has incomplete type and cannot be defined",
6928 : decl);
6929 289 : maybe_suggest_missing_header (input_location,
6930 167 : TYPE_IDENTIFIER (type),
6931 167 : CP_TYPE_CONTEXT (type));
6932 : /* Change the type so that assemble_variable will give
6933 : DECL an rtl we can live with: (mem (const_int 0)). */
6934 167 : type = TREE_TYPE (decl) = error_mark_node;
6935 167 : }
6936 : }
6937 :
6938 : /* Create a new scope to hold this declaration if necessary.
6939 : Whether or not a new scope is necessary cannot be determined
6940 : until after the type has been completed; if the type is a
6941 : specialization of a class template it is not until after
6942 : instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
6943 : will be set correctly. */
6944 8748875 : maybe_push_cleanup_level (type);
6945 : }
6946 :
6947 : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
6948 : C++20 P0960. TYPE is the type of the object we're initializing. */
6949 :
6950 : tree
6951 309 : do_aggregate_paren_init (tree init, tree type)
6952 : {
6953 309 : tree val = TREE_VALUE (init);
6954 :
6955 309 : if (TREE_CHAIN (init) == NULL_TREE)
6956 : {
6957 : /* If the list has a single element and it's a string literal,
6958 : then it's the initializer for the array as a whole. */
6959 193 : if (TREE_CODE (type) == ARRAY_TYPE
6960 193 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
6961 239 : && TREE_CODE (tree_strip_any_location_wrapper (val))
6962 : == STRING_CST)
6963 : return val;
6964 : /* Handle non-standard extensions like compound literals. This also
6965 : prevents triggering aggregate parenthesized-initialization in
6966 : compiler-generated code for =default. */
6967 154 : else if (same_type_ignoring_top_level_qualifiers_p (type,
6968 154 : TREE_TYPE (val)))
6969 : return val;
6970 : }
6971 :
6972 208 : init = build_constructor_from_list (init_list_type_node, init);
6973 208 : CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
6974 208 : CONSTRUCTOR_IS_PAREN_INIT (init) = true;
6975 208 : return init;
6976 : }
6977 :
6978 : /* Handle initialization of references. DECL, TYPE, and INIT have the
6979 : same meaning as in cp_finish_decl. *CLEANUP must be NULL on entry,
6980 : but will be set to a new CLEANUP_STMT if a temporary is created
6981 : that must be destroyed subsequently.
6982 :
6983 : Returns an initializer expression to use to initialize DECL, or
6984 : NULL if the initialization can be performed statically.
6985 :
6986 : Quotes on semantics can be found in ARM 8.4.3. */
6987 :
6988 : static tree
6989 380966 : grok_reference_init (tree decl, tree type, tree init, int flags)
6990 : {
6991 380966 : if (init == NULL_TREE)
6992 : {
6993 15 : if ((DECL_LANG_SPECIFIC (decl) == 0
6994 3 : || DECL_IN_AGGR_P (decl) == 0)
6995 18 : && ! DECL_THIS_EXTERN (decl))
6996 15 : error_at (DECL_SOURCE_LOCATION (decl),
6997 : "%qD declared as reference but not initialized", decl);
6998 15 : return NULL_TREE;
6999 : }
7000 :
7001 380951 : tree ttype = TREE_TYPE (type);
7002 380951 : if (TREE_CODE (init) == TREE_LIST)
7003 : {
7004 : /* This handles (C++20 only) code like
7005 :
7006 : const A& r(1, 2, 3);
7007 :
7008 : where we treat the parenthesized list as a CONSTRUCTOR. */
7009 1246 : if (TREE_TYPE (init) == NULL_TREE
7010 1246 : && CP_AGGREGATE_TYPE_P (ttype)
7011 86 : && !DECL_DECOMPOSITION_P (decl)
7012 1329 : && (cxx_dialect >= cxx20))
7013 : {
7014 : /* We don't know yet if we should treat const A& r(1) as
7015 : const A& r{1}. */
7016 77 : if (list_length (init) == 1)
7017 : {
7018 56 : flags |= LOOKUP_AGGREGATE_PAREN_INIT;
7019 56 : init = build_x_compound_expr_from_list (init, ELK_INIT,
7020 : tf_warning_or_error);
7021 : }
7022 : /* If the list had more than one element, the code is ill-formed
7023 : pre-C++20, so we can build a constructor right away. */
7024 : else
7025 21 : init = do_aggregate_paren_init (init, ttype);
7026 : }
7027 : else
7028 1169 : init = build_x_compound_expr_from_list (init, ELK_INIT,
7029 : tf_warning_or_error);
7030 : }
7031 :
7032 380951 : if (TREE_CODE (ttype) != ARRAY_TYPE
7033 380951 : && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
7034 : /* Note: default conversion is only called in very special cases. */
7035 12 : init = decay_conversion (init, tf_warning_or_error);
7036 :
7037 : /* check_initializer handles this for non-reference variables, but for
7038 : references we need to do it here or the initializer will get the
7039 : incomplete array type and confuse later calls to
7040 : cp_complete_array_type. */
7041 380951 : if (TREE_CODE (ttype) == ARRAY_TYPE
7042 24217 : && TYPE_DOMAIN (ttype) == NULL_TREE
7043 381034 : && (BRACE_ENCLOSED_INITIALIZER_P (init)
7044 50 : || TREE_CODE (init) == STRING_CST))
7045 : {
7046 33 : cp_complete_array_type (&ttype, init, false);
7047 33 : if (ttype != TREE_TYPE (type))
7048 33 : type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
7049 : }
7050 :
7051 : /* Convert INIT to the reference type TYPE. This may involve the
7052 : creation of a temporary, whose lifetime must be the same as that
7053 : of the reference. If so, a DECL_EXPR for the temporary will be
7054 : added just after the DECL_EXPR for DECL. That's why we don't set
7055 : DECL_INITIAL for local references (instead assigning to them
7056 : explicitly); we need to allow the temporary to be initialized
7057 : first. */
7058 380951 : return initialize_reference (type, init, flags,
7059 380951 : tf_warning_or_error);
7060 : }
7061 :
7062 : /* Designated initializers in arrays are not supported in GNU C++.
7063 : The parser cannot detect this error since it does not know whether
7064 : a given brace-enclosed initializer is for a class type or for an
7065 : array. This function checks that CE does not use a designated
7066 : initializer. If it does, an error is issued. Returns true if CE
7067 : is valid, i.e., does not have a designated initializer. */
7068 :
7069 : bool
7070 154777456 : check_array_designated_initializer (constructor_elt *ce,
7071 : unsigned HOST_WIDE_INT index)
7072 : {
7073 : /* Designated initializers for array elements are not supported. */
7074 154777456 : if (ce->index)
7075 : {
7076 : /* The parser only allows identifiers as designated
7077 : initializers. */
7078 104462518 : if (ce->index == error_mark_node)
7079 : {
7080 0 : error ("name used in a GNU-style designated "
7081 : "initializer for an array");
7082 0 : return false;
7083 : }
7084 104462518 : else if (identifier_p (ce->index))
7085 : {
7086 19 : error ("name %qD used in a GNU-style designated "
7087 : "initializer for an array", ce->index);
7088 19 : ce->index = error_mark_node;
7089 19 : return false;
7090 : }
7091 :
7092 104462499 : tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
7093 : ce->index, true);
7094 104462499 : if (ce_index
7095 104462496 : && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
7096 208924992 : && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
7097 : == INTEGER_CST))
7098 : {
7099 : /* A C99 designator is OK if it matches the current index. */
7100 104462493 : if (wi::to_wide (ce_index) == index)
7101 : {
7102 104462487 : ce->index = ce_index;
7103 104462487 : return true;
7104 : }
7105 : else
7106 6 : sorry ("non-trivial designated initializers not supported");
7107 : }
7108 : else
7109 6 : error_at (cp_expr_loc_or_input_loc (ce->index),
7110 : "C99 designator %qE is not an integral constant-expression",
7111 : ce->index);
7112 :
7113 12 : return false;
7114 : }
7115 :
7116 : return true;
7117 : }
7118 :
7119 : /* When parsing `int a[] = {1, 2};' we don't know the size of the
7120 : array until we finish parsing the initializer. If that's the
7121 : situation we're in, update DECL accordingly. */
7122 :
7123 : static void
7124 75781460 : maybe_deduce_size_from_array_init (tree decl, tree init)
7125 : {
7126 75781460 : tree type = TREE_TYPE (decl);
7127 :
7128 75781460 : if (TREE_CODE (type) == ARRAY_TYPE
7129 978647 : && TYPE_DOMAIN (type) == NULL_TREE
7130 76402745 : && TREE_CODE (decl) != TYPE_DECL)
7131 : {
7132 : /* do_default is really a C-ism to deal with tentative definitions.
7133 : But let's leave it here to ease the eventual merge. */
7134 621285 : int do_default = !DECL_EXTERNAL (decl);
7135 621285 : tree initializer = init ? init : DECL_INITIAL (decl);
7136 621285 : int failure = 0;
7137 :
7138 : /* Check that there are no designated initializers in INIT, as
7139 : those are not supported in GNU C++, and as the middle-end
7140 : will crash if presented with a non-numeric designated
7141 : initializer. */
7142 621285 : if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
7143 : {
7144 148089 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
7145 148089 : constructor_elt *ce;
7146 148089 : HOST_WIDE_INT i, j = 0;
7147 48564847 : FOR_EACH_VEC_SAFE_ELT (v, i, ce)
7148 : {
7149 48417780 : if (instantiation_dependent_expression_p (ce->index))
7150 75781460 : return;
7151 48417774 : if (!check_array_designated_initializer (ce, j))
7152 1 : failure = 1;
7153 : /* If an un-designated initializer is type-dependent, we can't
7154 : check brace elision yet. */
7155 48417774 : if (ce->index == NULL_TREE
7156 48417774 : && type_dependent_expression_p (ce->value))
7157 : return;
7158 48416758 : if (TREE_CODE (ce->value) == RAW_DATA_CST)
7159 210 : j += RAW_DATA_LENGTH (ce->value);
7160 : else
7161 48416548 : ++j;
7162 : }
7163 : }
7164 :
7165 147067 : if (failure)
7166 1 : TREE_TYPE (decl) = error_mark_node;
7167 : else
7168 : {
7169 620262 : failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
7170 : do_default);
7171 620262 : if (failure == 1)
7172 : {
7173 33 : error_at (cp_expr_loc_or_loc (initializer,
7174 30 : DECL_SOURCE_LOCATION (decl)),
7175 : "initializer fails to determine size of %qD", decl);
7176 : }
7177 620232 : else if (failure == 2)
7178 : {
7179 30 : if (do_default)
7180 : {
7181 6 : error_at (DECL_SOURCE_LOCATION (decl),
7182 : "array size missing in %qD", decl);
7183 : }
7184 : /* If a `static' var's size isn't known, make it extern as
7185 : well as static, so it does not get allocated. If it's not
7186 : `static', then don't mark it extern; finish_incomplete_decl
7187 : will give it a default size and it will get allocated. */
7188 24 : else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
7189 0 : DECL_EXTERNAL (decl) = 1;
7190 : }
7191 620202 : else if (failure == 3)
7192 : {
7193 6 : error_at (DECL_SOURCE_LOCATION (decl),
7194 : "zero-size array %qD", decl);
7195 : }
7196 : }
7197 :
7198 620263 : cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
7199 :
7200 620263 : relayout_decl (decl);
7201 :
7202 : /* Update the type of the corresponding TEMPLATE_DECL to match. */
7203 620263 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
7204 : {
7205 212 : tree tmpl = template_for_substitution (decl);
7206 212 : if (DECL_TEMPLATE_RESULT (tmpl) == decl)
7207 50 : TREE_TYPE (tmpl) = TREE_TYPE (decl);
7208 : }
7209 : }
7210 : }
7211 :
7212 : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
7213 : any appropriate error messages regarding the layout. */
7214 :
7215 : static void
7216 65005828 : layout_var_decl (tree decl)
7217 : {
7218 65005828 : tree type;
7219 :
7220 65005828 : type = TREE_TYPE (decl);
7221 65005828 : if (type == error_mark_node)
7222 : return;
7223 :
7224 : /* If we haven't already laid out this declaration, do so now.
7225 : Note that we must not call complete type for an external object
7226 : because it's type might involve templates that we are not
7227 : supposed to instantiate yet. (And it's perfectly valid to say
7228 : `extern X x' for some incomplete type `X'.) */
7229 65005781 : if (!DECL_EXTERNAL (decl))
7230 54501490 : complete_type (type);
7231 65005781 : if (!DECL_SIZE (decl)
7232 625811 : && TREE_TYPE (decl) != error_mark_node
7233 65631592 : && complete_or_array_type_p (type))
7234 472233 : layout_decl (decl, 0);
7235 :
7236 65005781 : if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
7237 : {
7238 : /* An automatic variable with an incomplete type: that is an error.
7239 : Don't talk about array types here, since we took care of that
7240 : message in grokdeclarator. */
7241 17 : error_at (DECL_SOURCE_LOCATION (decl),
7242 : "storage size of %qD isn%'t known", decl);
7243 17 : TREE_TYPE (decl) = error_mark_node;
7244 : }
7245 : #if 0
7246 : /* Keep this code around in case we later want to control debug info
7247 : based on whether a type is "used". (jason 1999-11-11) */
7248 :
7249 : else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
7250 : /* Let debugger know it should output info for this type. */
7251 : note_debug_info_needed (ttype);
7252 :
7253 : if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
7254 : note_debug_info_needed (DECL_CONTEXT (decl));
7255 : #endif
7256 :
7257 119507271 : if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
7258 40059980 : && DECL_SIZE (decl) != NULL_TREE
7259 104779336 : && ! TREE_CONSTANT (DECL_SIZE (decl)))
7260 : {
7261 6 : if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
7262 6 : && !DECL_LOCAL_DECL_P (decl))
7263 0 : constant_expression_warning (DECL_SIZE (decl));
7264 : else
7265 : {
7266 6 : error_at (DECL_SOURCE_LOCATION (decl),
7267 : "storage size of %qD isn%'t constant", decl);
7268 6 : TREE_TYPE (decl) = error_mark_node;
7269 6 : type = error_mark_node;
7270 : }
7271 : }
7272 :
7273 : /* If the final element initializes a flexible array field, adjust
7274 : the size of the DECL with the initializer based on whether the
7275 : DECL is a union or a structure. */
7276 65005781 : if (type != error_mark_node
7277 65005775 : && DECL_INITIAL (decl)
7278 38506203 : && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
7279 5276592 : && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
7280 3551336 : && DECL_SIZE (decl) != NULL_TREE
7281 3551336 : && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
7282 3551336 : && COMPLETE_TYPE_P (type)
7283 3551336 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
7284 68557117 : && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
7285 : {
7286 3551336 : constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
7287 3551336 : if (elt.index)
7288 : {
7289 1329545 : tree itype = TREE_TYPE (elt.index);
7290 1329545 : tree vtype = TREE_TYPE (elt.value);
7291 1329545 : if (TREE_CODE (itype) == ARRAY_TYPE
7292 85006 : && TYPE_DOMAIN (itype) == NULL
7293 275 : && TREE_CODE (vtype) == ARRAY_TYPE
7294 1329820 : && COMPLETE_TYPE_P (vtype))
7295 : {
7296 : /* For a structure, add the size of the initializer to the DECL's
7297 : size. */
7298 275 : if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
7299 : {
7300 260 : DECL_SIZE (decl)
7301 260 : = size_binop (PLUS_EXPR, DECL_SIZE (decl),
7302 : TYPE_SIZE (vtype));
7303 260 : DECL_SIZE_UNIT (decl)
7304 520 : = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
7305 : TYPE_SIZE_UNIT (vtype));
7306 : }
7307 : /* For a union, the DECL's size is the maximum of the current size
7308 : and the size of the initializer. */
7309 : else
7310 : {
7311 15 : DECL_SIZE (decl)
7312 15 : = size_binop (MAX_EXPR, DECL_SIZE (decl),
7313 : TYPE_SIZE (vtype));
7314 15 : DECL_SIZE_UNIT (decl)
7315 30 : = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
7316 : TYPE_SIZE_UNIT (vtype));
7317 : }
7318 : }
7319 : }
7320 : }
7321 : }
7322 :
7323 : /* If a local static variable is declared in an inline function, or if
7324 : we have a weak definition, we must endeavor to create only one
7325 : instance of the variable at link-time. */
7326 :
7327 : void
7328 80050158 : maybe_commonize_var (tree decl)
7329 : {
7330 : /* Don't mess with __FUNCTION__ and similar. But do handle structured
7331 : bindings. */
7332 80050158 : if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
7333 : return;
7334 :
7335 : /* Static data in a function with comdat linkage also has comdat
7336 : linkage. */
7337 74724770 : if ((TREE_STATIC (decl)
7338 49506691 : && DECL_FUNCTION_SCOPE_P (decl)
7339 140508 : && vague_linkage_p (DECL_CONTEXT (decl)))
7340 173916307 : || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
7341 : {
7342 43386831 : if (flag_weak)
7343 : {
7344 : /* With weak symbols, we simply make the variable COMDAT;
7345 : that will cause copies in multiple translations units to
7346 : be merged. */
7347 43386804 : comdat_linkage (decl);
7348 : }
7349 : else
7350 : {
7351 27 : if (DECL_INITIAL (decl) == NULL_TREE
7352 27 : || DECL_INITIAL (decl) == error_mark_node)
7353 : {
7354 : /* Without weak symbols, we can use COMMON to merge
7355 : uninitialized variables. */
7356 24 : TREE_PUBLIC (decl) = 1;
7357 24 : DECL_COMMON (decl) = 1;
7358 : }
7359 : else
7360 : {
7361 : /* While for initialized variables, we must use internal
7362 : linkage -- which means that multiple copies will not
7363 : be merged. */
7364 3 : TREE_PUBLIC (decl) = 0;
7365 3 : DECL_COMMON (decl) = 0;
7366 3 : DECL_INTERFACE_KNOWN (decl) = 1;
7367 3 : const char *msg;
7368 3 : if (DECL_INLINE_VAR_P (decl))
7369 : msg = G_("sorry: semantics of inline variable "
7370 : "%q#D are wrong (you%'ll wind up with "
7371 : "multiple copies)");
7372 : else
7373 : msg = G_("sorry: semantics of inline function "
7374 : "static data %q#D are wrong (you%'ll wind "
7375 : "up with multiple copies)");
7376 3 : auto_diagnostic_group d;
7377 3 : if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
7378 : msg, decl))
7379 3 : inform (DECL_SOURCE_LOCATION (decl),
7380 : "you can work around this by removing the initializer");
7381 3 : }
7382 : }
7383 : }
7384 : }
7385 :
7386 : /* Issue an error message if DECL is an uninitialized const variable.
7387 : CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
7388 : context from potential_constant_expression. Returns true if all is well,
7389 : false otherwise. */
7390 :
7391 : bool
7392 9217677 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
7393 : tsubst_flags_t complain)
7394 : {
7395 9217677 : tree type = strip_array_types (TREE_TYPE (decl));
7396 :
7397 : /* ``Unless explicitly declared extern, a const object does not have
7398 : external linkage and must be initialized. ($8.4; $12.1)'' ARM
7399 : 7.1.6 */
7400 9217677 : if (VAR_P (decl)
7401 9217677 : && !TYPE_REF_P (type)
7402 9169432 : && (CP_TYPE_CONST_P (type)
7403 : /* C++20 permits trivial default initialization in constexpr
7404 : context (P1331R2). */
7405 7132586 : || (cxx_dialect < cxx20
7406 137290 : && (constexpr_context_p
7407 123882 : || var_in_constexpr_fn (decl))))
7408 11270041 : && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
7409 : {
7410 658607 : tree field = default_init_uninitialized_part (type);
7411 658607 : if (!field)
7412 : return true;
7413 :
7414 3914 : auto_diagnostic_group d;
7415 3914 : bool show_notes = true;
7416 :
7417 3914 : if (!constexpr_context_p || cxx_dialect >= cxx20)
7418 : {
7419 188 : if (CP_TYPE_CONST_P (type))
7420 : {
7421 90 : if (complain & tf_error)
7422 84 : show_notes = permerror (DECL_SOURCE_LOCATION (decl),
7423 : "uninitialized %<const %D%>", decl);
7424 : }
7425 : else
7426 : {
7427 98 : if (!is_instantiation_of_constexpr (current_function_decl)
7428 98 : && (complain & tf_error))
7429 21 : error_at (DECL_SOURCE_LOCATION (decl),
7430 : "uninitialized variable %qD in %<constexpr%> "
7431 : "function", decl);
7432 : else
7433 : show_notes = false;
7434 98 : cp_function_chain->invalid_constexpr = true;
7435 : }
7436 : }
7437 3726 : else if (complain & tf_error)
7438 2 : error_at (DECL_SOURCE_LOCATION (decl),
7439 : "uninitialized variable %qD in %<constexpr%> context",
7440 : decl);
7441 :
7442 3914 : if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
7443 : {
7444 62 : tree defaulted_ctor;
7445 :
7446 62 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
7447 : "%q#T has no user-provided default constructor", type);
7448 62 : defaulted_ctor = in_class_defaulted_default_constructor (type);
7449 62 : if (defaulted_ctor)
7450 33 : inform (DECL_SOURCE_LOCATION (defaulted_ctor),
7451 : "constructor is not user-provided because it is "
7452 : "explicitly defaulted in the class body");
7453 62 : inform (DECL_SOURCE_LOCATION (field),
7454 : "and the implicitly-defined constructor does not "
7455 : "initialize %q#D", field);
7456 : }
7457 :
7458 3914 : return false;
7459 3914 : }
7460 :
7461 : return true;
7462 : }
7463 :
7464 : /* Structure holding the current initializer being processed by reshape_init.
7465 : CUR is a pointer to the current element being processed, END is a pointer
7466 : after the last element present in the initializer and RAW_IDX is index into
7467 : RAW_DATA_CST if that is CUR elt. */
7468 : struct reshape_iter
7469 : {
7470 : constructor_elt *cur;
7471 : constructor_elt *end;
7472 : unsigned raw_idx;
7473 : };
7474 :
7475 : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
7476 :
7477 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
7478 : returned is the next FIELD_DECL (possibly FIELD itself) that can be
7479 : initialized as if for an aggregate class. If there are no more such fields,
7480 : the return value will be NULL. */
7481 :
7482 : tree
7483 15399093 : next_aggregate_field (tree field)
7484 : {
7485 15399093 : while (field
7486 64033226 : && (TREE_CODE (field) != FIELD_DECL
7487 9634065 : || DECL_UNNAMED_BIT_FIELD (field)
7488 9633904 : || (DECL_ARTIFICIAL (field)
7489 : /* In C++17, aggregates can have bases. */
7490 215407 : && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
7491 48634133 : field = DECL_CHAIN (field);
7492 :
7493 15399093 : return field;
7494 : }
7495 :
7496 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
7497 : returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
7498 : to a subobject. If there are no more such fields, the return value will be
7499 : NULL. */
7500 :
7501 : tree
7502 67468563 : next_subobject_field (tree field)
7503 : {
7504 67468563 : while (field
7505 874989718 : && (TREE_CODE (field) != FIELD_DECL
7506 30003656 : || DECL_UNNAMED_BIT_FIELD (field)
7507 30003517 : || (DECL_ARTIFICIAL (field)
7508 8367485 : && !DECL_FIELD_IS_BASE (field)
7509 1800034 : && !DECL_VIRTUAL_P (field))))
7510 807521155 : field = DECL_CHAIN (field);
7511 :
7512 67468563 : return field;
7513 : }
7514 :
7515 : /* Return true for [dcl.init.list] direct-list-initialization from
7516 : single element of enumeration with a fixed underlying type. */
7517 :
7518 : bool
7519 187170327 : is_direct_enum_init (tree type, tree init)
7520 : {
7521 187170327 : if (cxx_dialect >= cxx17
7522 185131222 : && TREE_CODE (type) == ENUMERAL_TYPE
7523 7582334 : && ENUM_FIXED_UNDERLYING_TYPE_P (type)
7524 5180972 : && TREE_CODE (init) == CONSTRUCTOR
7525 439847 : && CONSTRUCTOR_IS_DIRECT_INIT (init)
7526 218983 : && CONSTRUCTOR_NELTS (init) == 1
7527 217 : && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
7528 : /* DR 2374: The single element needs to be implicitly
7529 : convertible to the underlying type of the enum. */
7530 217 : && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
7531 187170542 : && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
7532 215 : TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
7533 215 : CONSTRUCTOR_ELT (init, 0)->value,
7534 : LOOKUP_IMPLICIT, tf_none))
7535 : return true;
7536 : return false;
7537 : }
7538 :
7539 : /* Helper function for reshape_init*. Split first element of
7540 : RAW_DATA_CST or return NULL for other elements. Set *INC_CUR
7541 : to true if the whole d->cur has been consumed. */
7542 :
7543 : static tree
7544 62025250 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
7545 : {
7546 62025250 : *inc_cur = true;
7547 62025250 : if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
7548 : return NULL_TREE;
7549 30720 : tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
7550 30720 : if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
7551 30588 : *inc_cur = false;
7552 : else
7553 132 : d->raw_idx = 0;
7554 : return ret;
7555 : }
7556 :
7557 : /* Wrapper around that which for RAW_DATA_CST in INIT
7558 : (as well as in D->cur->value) peels off the first element
7559 : of the raw data and returns it, otherwise increments
7560 : D->cur and returns INIT. */
7561 :
7562 : static tree
7563 62025233 : consume_init (tree init, reshape_iter *d)
7564 : {
7565 62025233 : bool inc_cur;
7566 62025233 : if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
7567 30720 : init = raw_init;
7568 62025233 : if (inc_cur)
7569 61994645 : d->cur++;
7570 62025233 : return init;
7571 : }
7572 :
7573 : /* Subroutine of reshape_init_array and reshape_init_vector, which does
7574 : the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
7575 : INTEGER_CST representing the size of the array minus one (the maximum index),
7576 : or NULL_TREE if the array was declared without specifying the size. D is
7577 : the iterator within the constructor. */
7578 :
7579 : static tree
7580 467513 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
7581 : tree first_initializer_p, bool vector_p,
7582 : tsubst_flags_t complain)
7583 : {
7584 467513 : tree new_init;
7585 467513 : bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
7586 467513 : unsigned HOST_WIDE_INT max_index_cst = 0;
7587 467513 : unsigned HOST_WIDE_INT index;
7588 :
7589 : /* The initializer for an array is always a CONSTRUCTOR. If this is the
7590 : outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
7591 : to build a new one. But don't reuse if not complaining; if this is
7592 : tentative, we might also reshape to another type (95319). */
7593 467513 : bool reuse = (first_initializer_p
7594 408584 : && (complain & tf_error)
7595 407299 : && !CP_AGGREGATE_TYPE_P (elt_type)
7596 810598 : && !TREE_SIDE_EFFECTS (first_initializer_p));
7597 129890 : if (reuse)
7598 : new_init = first_initializer_p;
7599 : else
7600 129890 : new_init = build_constructor (init_list_type_node, NULL);
7601 :
7602 467513 : if (sized_array_p)
7603 : {
7604 277467 : poly_uint64 midx;
7605 : /* Minus 1 is used for zero sized arrays. */
7606 277467 : if (integer_all_onesp (max_index))
7607 24 : return new_init;
7608 :
7609 277443 : if (tree_fits_poly_uint64_p (max_index))
7610 277443 : midx = tree_to_poly_uint64 (max_index);
7611 : /* sizetype is sign extended, not zero extended. */
7612 : else
7613 0 : midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
7614 :
7615 : /* For VLA vectors, we restrict the number of elements in the constructor
7616 : to lower bound of the VLA elements. */
7617 277443 : max_index_cst = constant_lower_bound (midx);
7618 : }
7619 :
7620 467489 : constructor_elt *first_cur = d->cur;
7621 : /* Loop until there are no more initializers. */
7622 56544384 : for (index = 0;
7623 56544384 : d->cur != d->end && (!sized_array_p || index <= max_index_cst);
7624 : ++index)
7625 : {
7626 56077075 : tree elt_init;
7627 56077075 : constructor_elt *old_cur = d->cur;
7628 56077075 : unsigned int old_raw_idx = d->raw_idx;
7629 56077075 : bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
7630 :
7631 56077075 : if (d->cur->index)
7632 5784229 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7633 56077075 : check_array_designated_initializer (d->cur, index);
7634 56077075 : if (TREE_CODE (d->cur->value) == RAW_DATA_CST
7635 32752 : && (TREE_CODE (elt_type) == INTEGER_TYPE
7636 10233 : || is_byte_access_type (elt_type))
7637 22519 : && TYPE_PRECISION (elt_type) == CHAR_BIT
7638 1858 : && (!sized_array_p || index < max_index_cst)
7639 56078921 : && !vector_p)
7640 : {
7641 526 : elt_init = d->cur->value;
7642 526 : unsigned int off = d->raw_idx;
7643 526 : unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
7644 526 : if (!sized_array_p || len <= max_index_cst - index + 1)
7645 : {
7646 517 : d->cur++;
7647 517 : d->raw_idx = 0;
7648 : }
7649 : else
7650 : {
7651 9 : len = max_index_cst - index + 1;
7652 9 : d->raw_idx += len;
7653 : }
7654 526 : if (!reuse || off || d->cur == old_cur)
7655 : {
7656 27 : elt_init = copy_node (elt_init);
7657 27 : RAW_DATA_LENGTH (elt_init) = len;
7658 27 : RAW_DATA_POINTER (elt_init) += off;
7659 : }
7660 526 : TREE_TYPE (elt_init) = elt_type;
7661 : }
7662 : else
7663 56076549 : elt_init = reshape_init_r (elt_type, d,
7664 : /*first_initializer_p=*/NULL_TREE,
7665 : complain);
7666 56077075 : if (elt_init == error_mark_node)
7667 : return error_mark_node;
7668 56076898 : tree idx = size_int (index);
7669 56076898 : if (reuse && old_raw_data_cst && d->cur == old_cur)
7670 : {
7671 : /* We need to stop reusing as some RAW_DATA_CST in the original
7672 : ctor had to be split. */
7673 72 : new_init = build_constructor (init_list_type_node, NULL);
7674 72 : if (index)
7675 : {
7676 72 : vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
7677 72 : memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
7678 72 : (d->cur - first_cur)
7679 : * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
7680 72 : if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
7681 : {
7682 : unsigned int j;
7683 : tree nidx, nval;
7684 4 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
7685 : j, nidx, nval)
7686 4 : if (nidx)
7687 : {
7688 4 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
7689 4 : (void) nval;
7690 4 : break;
7691 : }
7692 : }
7693 : }
7694 : reuse = false;
7695 : }
7696 56076826 : if (reuse)
7697 : {
7698 54576292 : old_cur->index = idx;
7699 54576292 : old_cur->value = elt_init;
7700 : }
7701 : else
7702 1500606 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
7703 : idx, elt_init);
7704 56076898 : if (!TREE_CONSTANT (elt_init))
7705 203569 : TREE_CONSTANT (new_init) = false;
7706 :
7707 : /* This can happen with an invalid initializer (c++/54501). */
7708 56076898 : if (d->cur == old_cur
7709 32082 : && !sized_array_p
7710 14085 : && d->raw_idx == old_raw_idx)
7711 : break;
7712 :
7713 56076895 : if (TREE_CODE (elt_init) == RAW_DATA_CST)
7714 526 : index += RAW_DATA_LENGTH (elt_init) - 1;
7715 : }
7716 :
7717 : return new_init;
7718 : }
7719 :
7720 : /* Subroutine of reshape_init_r, processes the initializers for arrays.
7721 : Parameters are the same of reshape_init_r. */
7722 :
7723 : static tree
7724 417616 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
7725 : tsubst_flags_t complain)
7726 : {
7727 417616 : tree max_index = NULL_TREE;
7728 :
7729 417616 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
7730 :
7731 417616 : if (TYPE_DOMAIN (type))
7732 227616 : max_index = array_type_nelts_minus_one (type);
7733 :
7734 417616 : return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
7735 417616 : first_initializer_p, false, complain);
7736 : }
7737 :
7738 : /* Subroutine of reshape_init_r, processes the initializers for vectors.
7739 : Parameters are the same of reshape_init_r. */
7740 :
7741 : static tree
7742 49897 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
7743 : {
7744 49897 : tree max_index = NULL_TREE;
7745 :
7746 49897 : gcc_assert (VECTOR_TYPE_P (type));
7747 :
7748 49897 : if (COMPOUND_LITERAL_P (d->cur->value))
7749 : {
7750 0 : tree value = d->cur->value;
7751 0 : if (!same_type_p (TREE_TYPE (value), type))
7752 : {
7753 0 : if (complain & tf_error)
7754 0 : error ("invalid type %qT as initializer for a vector of type %qT",
7755 0 : TREE_TYPE (d->cur->value), type);
7756 0 : value = error_mark_node;
7757 : }
7758 0 : ++d->cur;
7759 0 : return value;
7760 : }
7761 :
7762 : /* For a vector, we initialize it as an array of the appropriate size. */
7763 49897 : if (VECTOR_TYPE_P (type))
7764 49897 : max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
7765 :
7766 49897 : return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
7767 49897 : NULL_TREE, true, complain);
7768 : }
7769 :
7770 : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
7771 : INIT, in isolation from any designator or other initializers. */
7772 :
7773 : static tree
7774 613416 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
7775 : {
7776 : /* We could also implement this by wrapping init in a new CONSTRUCTOR and
7777 : calling reshape_init, but this way can just live on the stack. */
7778 613416 : constructor_elt elt = { /*index=*/NULL_TREE, init };
7779 613416 : reshape_iter iter = { &elt, &elt + 1, 0 };
7780 613416 : return reshape_init_r (type, &iter,
7781 : /*first_initializer_p=*/NULL_TREE,
7782 613416 : complain);
7783 : }
7784 :
7785 : /* Subroutine of reshape_init_r, processes the initializers for classes
7786 : or union. Parameters are the same of reshape_init_r. */
7787 :
7788 : static tree
7789 3715379 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
7790 : tsubst_flags_t complain)
7791 : {
7792 3715379 : tree field;
7793 3715379 : tree new_init;
7794 :
7795 3715379 : gcc_assert (CLASS_TYPE_P (type));
7796 :
7797 : /* The initializer for a class is always a CONSTRUCTOR. */
7798 3715379 : new_init = build_constructor (init_list_type_node, NULL);
7799 :
7800 3715379 : int binfo_idx = -1;
7801 3715379 : tree binfo = TYPE_BINFO (type);
7802 3715379 : tree base_binfo = NULL_TREE;
7803 3715379 : if (cxx_dialect >= cxx17 && uses_template_parms (type))
7804 : {
7805 : /* We get here from maybe_aggr_guide for C++20 class template argument
7806 : deduction. In this case we need to look through the binfo because a
7807 : template doesn't have base fields. */
7808 2775 : binfo_idx = 0;
7809 2775 : BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
7810 : }
7811 86 : if (base_binfo)
7812 : field = base_binfo;
7813 : else
7814 3715293 : field = next_aggregate_field (TYPE_FIELDS (type));
7815 :
7816 3715379 : if (!field)
7817 : {
7818 : /* [dcl.init.aggr]
7819 :
7820 : An initializer for an aggregate member that is an
7821 : empty class shall have the form of an empty
7822 : initializer-list {}. */
7823 322 : if (!first_initializer_p)
7824 : {
7825 268 : if (complain & tf_error)
7826 13 : error ("initializer for %qT must be brace-enclosed", type);
7827 268 : return error_mark_node;
7828 : }
7829 : return new_init;
7830 : }
7831 :
7832 : /* For C++20 CTAD, handle pack expansions in the base list. */
7833 : tree last_was_pack_expansion = NULL_TREE;
7834 :
7835 : /* Loop through the initializable fields, gathering initializers. */
7836 11098096 : while (d->cur != d->end)
7837 : {
7838 7490485 : tree field_init;
7839 7490485 : constructor_elt *old_cur = d->cur;
7840 7490485 : unsigned old_raw_idx = d->raw_idx;
7841 7490485 : bool direct_desig = false;
7842 :
7843 : /* Handle C++20 designated initializers. */
7844 7490485 : if (d->cur->index)
7845 : {
7846 613586 : if (d->cur->index == error_mark_node)
7847 : return error_mark_node;
7848 :
7849 613580 : if (TREE_CODE (d->cur->index) == FIELD_DECL)
7850 : {
7851 : /* We already reshaped this; we should have returned early from
7852 : reshape_init. */
7853 0 : gcc_checking_assert (false);
7854 : if (field != d->cur->index)
7855 : {
7856 : if (tree id = DECL_NAME (d->cur->index))
7857 : gcc_checking_assert (d->cur->index
7858 : == get_class_binding (type, id));
7859 : field = d->cur->index;
7860 : }
7861 : }
7862 613580 : else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
7863 : {
7864 613574 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7865 613574 : field = get_class_binding (type, d->cur->index);
7866 613574 : direct_desig = true;
7867 : }
7868 : else
7869 : {
7870 6 : if (complain & tf_error)
7871 6 : error ("%<[%E] =%> used in a GNU-style designated initializer"
7872 : " for class %qT", d->cur->index, type);
7873 6 : return error_mark_node;
7874 : }
7875 :
7876 613574 : if (!field && ANON_AGGR_TYPE_P (type))
7877 : /* Apparently the designator isn't for a member of this anonymous
7878 : struct, so head back to the enclosing class. */
7879 : break;
7880 :
7881 613571 : if (!field || TREE_CODE (field) != FIELD_DECL)
7882 : {
7883 18 : if (complain & tf_error)
7884 : {
7885 6 : if (field && TREE_CODE (field) == TREE_LIST)
7886 : {
7887 3 : auto_diagnostic_group g;
7888 3 : error ("request for member %qD is ambiguous",
7889 3 : d->cur->index);
7890 3 : print_candidates (input_location, field);
7891 3 : }
7892 : else
7893 3 : error ("%qT has no non-static data member named %qD", type,
7894 3 : d->cur->index);
7895 : }
7896 18 : return error_mark_node;
7897 : }
7898 :
7899 : /* If the element is an anonymous union object and the initializer
7900 : list is a designated-initializer-list, the anonymous union object
7901 : is initialized by the designated-initializer-list { D }, where D
7902 : is the designated-initializer-clause naming a member of the
7903 : anonymous union object. */
7904 613553 : tree ictx = DECL_CONTEXT (field);
7905 613553 : if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
7906 : {
7907 : /* Find the anon aggr that is a direct member of TYPE. */
7908 151 : while (ANON_AGGR_TYPE_P (ictx))
7909 : {
7910 148 : tree cctx = TYPE_CONTEXT (ictx);
7911 148 : if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
7912 134 : goto found;
7913 : ictx = cctx;
7914 : }
7915 :
7916 : /* Not found, e.g. FIELD is a member of a base class. */
7917 3 : if (complain & tf_error)
7918 3 : error ("%qD is not a direct member of %qT", field, type);
7919 3 : return error_mark_node;
7920 :
7921 134 : found:
7922 : /* Now find the TYPE member with that anon aggr type. */
7923 134 : tree aafield = TYPE_FIELDS (type);
7924 1139 : for (; aafield; aafield = TREE_CHAIN (aafield))
7925 1139 : if (TREE_TYPE (aafield) == ictx)
7926 : break;
7927 0 : gcc_assert (aafield);
7928 : field = aafield;
7929 : direct_desig = false;
7930 : }
7931 : }
7932 :
7933 : /* If we processed all the member of the class, we are done. */
7934 7490315 : if (!field)
7935 : break;
7936 :
7937 14979938 : last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
7938 7489979 : ? field : NULL_TREE);
7939 7489979 : if (last_was_pack_expansion)
7940 : /* Each non-trailing aggregate element that is a pack expansion is
7941 : assumed to correspond to no elements of the initializer list. */
7942 20 : goto continue_;
7943 :
7944 7489959 : if (direct_desig)
7945 : {
7946 : /* The designated field F is initialized from this one element.
7947 :
7948 : Note that we don't want to do this if we found the designator
7949 : inside an anon aggr above; we use the normal code to implement:
7950 :
7951 : "If the element is an anonymous union member and the initializer
7952 : list is a brace-enclosed designated- initializer-list, the element
7953 : is initialized by the designated-initializer-list { D }, where D
7954 : is the designated- initializer-clause naming a member of the
7955 : anonymous union member." */
7956 613416 : gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
7957 613416 : field_init = reshape_single_init (TREE_TYPE (field),
7958 : d->cur->value, complain);
7959 613416 : d->cur++;
7960 : }
7961 : else
7962 6876543 : field_init = reshape_init_r (TREE_TYPE (field), d,
7963 : /*first_initializer_p=*/NULL_TREE,
7964 : complain);
7965 :
7966 7489959 : if (field_init == error_mark_node)
7967 : return error_mark_node;
7968 :
7969 7489672 : if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
7970 : {
7971 : /* This can happen with an invalid initializer for a flexible
7972 : array member (c++/54441). */
7973 0 : if (complain & tf_error)
7974 0 : error ("invalid initializer for %q#D", field);
7975 0 : return error_mark_node;
7976 : }
7977 :
7978 7489672 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
7979 :
7980 : /* [dcl.init.aggr]
7981 :
7982 : When a union is initialized with a brace-enclosed
7983 : initializer, the braces shall only contain an
7984 : initializer for the first member of the union. */
7985 7489672 : if (TREE_CODE (type) == UNION_TYPE)
7986 : break;
7987 :
7988 7383019 : continue_:
7989 7383039 : if (base_binfo)
7990 : {
7991 101 : if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
7992 : field = base_binfo;
7993 : else
7994 38 : field = next_aggregate_field (TYPE_FIELDS (type));
7995 : }
7996 : else
7997 7382938 : field = next_aggregate_field (DECL_CHAIN (field));
7998 : }
7999 :
8000 : /* A trailing aggregate element that is a pack expansion is assumed to
8001 : correspond to all remaining elements of the initializer list (if any). */
8002 3714737 : if (last_was_pack_expansion)
8003 : {
8004 17 : tree init = d->cur->value;
8005 17 : bool inc_cur;
8006 17 : if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
8007 0 : init = raw_init;
8008 17 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
8009 : last_was_pack_expansion, init);
8010 49 : while (d->cur != d->end)
8011 32 : d->cur++;
8012 : }
8013 :
8014 : return new_init;
8015 : }
8016 :
8017 : /* Subroutine of reshape_init_r. We're in a context where C99 initializer
8018 : designators are not valid; either complain or return true to indicate
8019 : that reshape_init_r should return error_mark_node. */
8020 :
8021 : static bool
8022 248919 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
8023 : {
8024 248919 : if (d->cur->index)
8025 : {
8026 30 : if (complain & tf_error)
8027 45 : error_at (cp_expr_loc_or_input_loc (d->cur->index),
8028 : "C99 designator %qE outside aggregate initializer",
8029 : d->cur->index);
8030 : else
8031 : return true;
8032 : }
8033 : return false;
8034 : }
8035 :
8036 : /* Subroutine of reshape_init, which processes a single initializer (part of
8037 : a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
8038 : iterator within the CONSTRUCTOR which points to the initializer to process.
8039 : If this is the first initializer of the outermost CONSTRUCTOR node,
8040 : FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE. */
8041 :
8042 : static tree
8043 67988281 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
8044 : tsubst_flags_t complain)
8045 : {
8046 67988281 : tree init = d->cur->value;
8047 :
8048 67988281 : if (error_operand_p (init))
8049 131 : return error_mark_node;
8050 :
8051 4421645 : if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
8052 68236890 : && has_designator_problem (d, complain))
8053 0 : return error_mark_node;
8054 :
8055 67988150 : tree stripped_init = tree_strip_any_location_wrapper (init);
8056 :
8057 67988150 : if (TREE_CODE (type) == COMPLEX_TYPE)
8058 : {
8059 : /* A complex type can be initialized from one or two initializers,
8060 : but braces are not elided. */
8061 672 : init = consume_init (init, d);
8062 672 : if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
8063 : {
8064 9 : if (CONSTRUCTOR_NELTS (stripped_init) > 2)
8065 : {
8066 0 : if (complain & tf_error)
8067 0 : error ("too many initializers for %qT", type);
8068 : else
8069 0 : return error_mark_node;
8070 : }
8071 : }
8072 663 : else if (first_initializer_p && d->cur != d->end)
8073 : {
8074 36 : if (error_operand_p (d->cur->value)
8075 36 : || has_designator_problem (d, complain))
8076 0 : return error_mark_node;
8077 36 : vec<constructor_elt, va_gc> *v = 0;
8078 36 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
8079 36 : init = consume_init (d->cur->value, d);
8080 36 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
8081 36 : init = build_constructor (init_list_type_node, v);
8082 : }
8083 672 : return init;
8084 : }
8085 :
8086 : /* A non-aggregate type is always initialized with a single
8087 : initializer. */
8088 135916261 : if (!CP_AGGREGATE_TYPE_P (type)
8089 : /* As is an array with dependent bound, which we can see
8090 : during C++20 aggregate CTAD. */
8091 73897433 : || (cxx_dialect >= cxx20
8092 5863144 : && TREE_CODE (type) == ARRAY_TYPE
8093 502731 : && uses_template_parms (TYPE_DOMAIN (type))))
8094 : {
8095 : /* It is invalid to initialize a non-aggregate type with a
8096 : brace-enclosed initializer before C++0x.
8097 : We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
8098 : of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
8099 : a CONSTRUCTOR (with a record type). */
8100 62018839 : if (TREE_CODE (stripped_init) == CONSTRUCTOR
8101 : /* Don't complain about a capture-init. */
8102 301509 : && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
8103 62309702 : && BRACE_ENCLOSED_INITIALIZER_P (stripped_init)) /* p7626.C */
8104 : {
8105 290824 : if (SCALAR_TYPE_P (type))
8106 : {
8107 478 : if (cxx_dialect < cxx11)
8108 : {
8109 16 : if (complain & tf_error)
8110 16 : error ("braces around scalar initializer for type %qT",
8111 : type);
8112 16 : init = error_mark_node;
8113 : }
8114 462 : else if (first_initializer_p
8115 462 : || (CONSTRUCTOR_NELTS (stripped_init) > 0
8116 296 : && (BRACE_ENCLOSED_INITIALIZER_P
8117 : (CONSTRUCTOR_ELT (stripped_init,0)->value))))
8118 : {
8119 13 : if (complain & tf_error)
8120 13 : error ("too many braces around scalar initializer "
8121 : "for type %qT", type);
8122 13 : init = error_mark_node;
8123 : }
8124 : }
8125 : else
8126 290346 : maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
8127 : }
8128 62018839 : return consume_init (init, d);
8129 : }
8130 :
8131 : /* "If T is a class type and the initializer list has a single element of
8132 : type cv U, where U is T or a class derived from T, the object is
8133 : initialized from that element." Even if T is an aggregate. */
8134 5944862 : if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
8135 5416559 : && first_initializer_p
8136 : /* But not if it's a designated init. */
8137 3749920 : && !d->cur->index
8138 3447884 : && d->end - d->cur == 1
8139 601722 : && TREE_CODE (init) != RAW_DATA_CST
8140 6570361 : && reference_related_p (type, TREE_TYPE (init)))
8141 : {
8142 426 : d->cur++;
8143 426 : return init;
8144 : }
8145 :
8146 : /* [dcl.init.aggr]
8147 :
8148 : All implicit type conversions (clause _conv_) are considered when
8149 : initializing the aggregate member with an initializer from an
8150 : initializer-list. If the initializer can initialize a member,
8151 : the member is initialized. Otherwise, if the member is itself a
8152 : non-empty subaggregate, brace elision is assumed and the
8153 : initializer is considered for the initialization of the first
8154 : member of the subaggregate. */
8155 2412762 : if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
8156 : /* But don't try this for the first initializer, since that would be
8157 : looking through the outermost braces; A a2 = { a1 }; is not a
8158 : valid aggregate initialization. */
8159 3555517 : && !first_initializer_p
8160 5985207 : && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
8161 11344 : || can_convert_arg (type, TREE_TYPE (init),
8162 11344 : TREE_CODE (init) == RAW_DATA_CST
8163 5969819 : ? build_int_cst (integer_type_node,
8164 1606 : *(const unsigned char *)
8165 1606 : RAW_DATA_POINTER (init))
8166 : : init,
8167 : LOOKUP_NORMAL, complain)))
8168 5686 : return consume_init (init, d);
8169 :
8170 : /* [dcl.init.string]
8171 :
8172 : A char array (whether plain char, signed char, or unsigned char)
8173 : can be initialized by a string-literal (optionally enclosed in
8174 : braces); a wchar_t array can be initialized by a wide
8175 : string-literal (optionally enclosed in braces). */
8176 5962527 : if (TREE_CODE (type) == ARRAY_TYPE
8177 5962527 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
8178 : {
8179 110822 : tree str_init = init;
8180 110822 : tree stripped_str_init = stripped_init;
8181 110822 : reshape_iter stripd = {};
8182 :
8183 : /* Strip one level of braces if and only if they enclose a single
8184 : element (as allowed by [dcl.init.string]). */
8185 110822 : if (!first_initializer_p
8186 2742 : && TREE_CODE (stripped_str_init) == CONSTRUCTOR
8187 112410 : && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
8188 : {
8189 392 : stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
8190 392 : str_init = stripd.cur->value;
8191 392 : stripped_str_init = tree_strip_any_location_wrapper (str_init);
8192 : }
8193 :
8194 : /* If it's a string literal, then it's the initializer for the array
8195 : as a whole. Otherwise, continue with normal initialization for
8196 : array types (one value per array element). */
8197 110822 : if (TREE_CODE (stripped_str_init) == STRING_CST)
8198 : {
8199 72 : if ((first_initializer_p && has_designator_problem (d, complain))
8200 1062 : || (stripd.cur && has_designator_problem (&stripd, complain)))
8201 990 : return error_mark_node;
8202 990 : d->cur++;
8203 990 : return str_init;
8204 : }
8205 : }
8206 :
8207 : /* The following cases are about aggregates. If we are not within a full
8208 : initializer already, and there is not a CONSTRUCTOR, it means that there
8209 : is a missing set of braces (that is, we are processing the case for
8210 : which reshape_init exists). */
8211 5961537 : bool braces_elided_p = false;
8212 5961537 : if (!first_initializer_p)
8213 : {
8214 1789130 : if (TREE_CODE (stripped_init) == CONSTRUCTOR)
8215 : {
8216 1778677 : tree init_type = TREE_TYPE (init);
8217 1778677 : if (init_type && TYPE_PTRMEMFUNC_P (init_type))
8218 : /* There is no need to call reshape_init for pointer-to-member
8219 : function initializers, as they are always constructed correctly
8220 : by the front end. Here we have e.g. {.__pfn=0B, .__delta=0},
8221 : which is missing outermost braces. We should warn below, and
8222 : one of the routines below will wrap it in additional { }. */;
8223 : /* For a nested compound literal, proceed to specialized routines,
8224 : to handle initialization of arrays and similar. */
8225 1778668 : else if (COMPOUND_LITERAL_P (stripped_init))
8226 8 : gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
8227 : /* If we have an unresolved designator, we need to find the member it
8228 : designates within TYPE, so proceed to the routines below. For
8229 : FIELD_DECL or INTEGER_CST designators, we're already initializing
8230 : the designated element. */
8231 1778660 : else if (d->cur->index
8232 30 : && TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
8233 : /* Brace elision with designators is only permitted for anonymous
8234 : aggregates. */
8235 15 : gcc_checking_assert (ANON_AGGR_TYPE_P (type));
8236 : /* A CONSTRUCTOR of the target's type is a previously
8237 : digested initializer. */
8238 1778645 : else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
8239 : {
8240 0 : ++d->cur;
8241 0 : return init;
8242 : }
8243 : else
8244 : {
8245 : /* Something that hasn't been reshaped yet. */
8246 1778645 : ++d->cur;
8247 1778645 : gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
8248 1778645 : return reshape_init (type, init, complain);
8249 : }
8250 : }
8251 :
8252 10485 : if (complain & tf_warning)
8253 9295 : warning (OPT_Wmissing_braces,
8254 : "missing braces around initializer for %qT",
8255 : type);
8256 : braces_elided_p = true;
8257 : }
8258 :
8259 : /* Dispatch to specialized routines. */
8260 4182892 : tree new_init;
8261 4182892 : if (CLASS_TYPE_P (type))
8262 3715379 : new_init = reshape_init_class (type, d, first_initializer_p, complain);
8263 467513 : else if (TREE_CODE (type) == ARRAY_TYPE)
8264 417616 : new_init = reshape_init_array (type, d, first_initializer_p, complain);
8265 49897 : else if (VECTOR_TYPE_P (type))
8266 49897 : new_init = reshape_init_vector (type, d, complain);
8267 : else
8268 0 : gcc_unreachable ();
8269 :
8270 4182892 : if (braces_elided_p
8271 10485 : && TREE_CODE (new_init) == CONSTRUCTOR)
8272 10211 : CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
8273 :
8274 : return new_init;
8275 : }
8276 :
8277 : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
8278 : brace-enclosed aggregate initializer.
8279 :
8280 : INIT is the CONSTRUCTOR containing the list of initializers describing
8281 : a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
8282 : It may not presently match the shape of the TYPE; for example:
8283 :
8284 : struct S { int a; int b; };
8285 : struct S a[] = { 1, 2, 3, 4 };
8286 :
8287 : Here INIT will hold a vector of four elements, rather than a
8288 : vector of two elements, each itself a vector of two elements. This
8289 : routine transforms INIT from the former form into the latter. The
8290 : revised CONSTRUCTOR node is returned. */
8291 :
8292 : tree
8293 12413185 : reshape_init (tree type, tree init, tsubst_flags_t complain)
8294 : {
8295 12413185 : vec<constructor_elt, va_gc> *v;
8296 12413185 : reshape_iter d;
8297 12413185 : tree new_init;
8298 :
8299 12413185 : gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
8300 :
8301 12413185 : v = CONSTRUCTOR_ELTS (init);
8302 :
8303 : /* An empty constructor does not need reshaping, and it is always a valid
8304 : initializer. */
8305 12414146 : if (vec_safe_is_empty (v))
8306 : return init;
8307 :
8308 4422943 : if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
8309 : /* Already reshaped. */
8310 : return init;
8311 :
8312 : /* Brace elision is not performed for a CONSTRUCTOR representing
8313 : parenthesized aggregate initialization. */
8314 4422797 : if (CONSTRUCTOR_IS_PAREN_INIT (init))
8315 : {
8316 849 : tree elt = (*v)[0].value;
8317 : /* If we're initializing a char array from a string-literal that is
8318 : enclosed in braces, unwrap it here. */
8319 849 : if (TREE_CODE (type) == ARRAY_TYPE
8320 277 : && vec_safe_length (v) == 1
8321 149 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
8322 888 : && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
8323 : return elt;
8324 815 : return init;
8325 : }
8326 :
8327 : /* Handle [dcl.init.list] direct-list-initialization from
8328 : single element of enumeration with a fixed underlying type. */
8329 4421948 : if (is_direct_enum_init (type, init))
8330 : {
8331 175 : tree elt = CONSTRUCTOR_ELT (init, 0)->value;
8332 175 : type = cv_unqualified (type);
8333 175 : if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
8334 : {
8335 160 : warning_sentinel w (warn_useless_cast);
8336 160 : warning_sentinel w2 (warn_ignored_qualifiers);
8337 160 : return cp_build_c_cast (input_location, type, elt,
8338 : tf_warning_or_error);
8339 160 : }
8340 : else
8341 15 : return error_mark_node;
8342 : }
8343 :
8344 : /* Recurse on this CONSTRUCTOR. */
8345 4421773 : d.cur = &(*v)[0];
8346 4421773 : d.end = d.cur + v->length ();
8347 4421773 : d.raw_idx = 0;
8348 :
8349 4421773 : new_init = reshape_init_r (type, &d, init, complain);
8350 4421773 : if (new_init == error_mark_node)
8351 : return error_mark_node;
8352 :
8353 : /* Make sure all the element of the constructor were used. Otherwise,
8354 : issue an error about exceeding initializers. */
8355 4421148 : if (d.cur != d.end)
8356 : {
8357 207 : if (complain & tf_error)
8358 64 : error ("too many initializers for %qT", type);
8359 207 : return error_mark_node;
8360 : }
8361 :
8362 4420941 : if (CONSTRUCTOR_IS_DIRECT_INIT (init)
8363 4420941 : && BRACE_ENCLOSED_INITIALIZER_P (new_init))
8364 601025 : CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
8365 4420941 : if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
8366 4420941 : && BRACE_ENCLOSED_INITIALIZER_P (new_init))
8367 73932 : gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
8368 : || seen_error ());
8369 :
8370 : return new_init;
8371 : }
8372 :
8373 : /* Verify array initializer. Returns true if errors have been reported. */
8374 :
8375 : bool
8376 1019471 : check_array_initializer (tree decl, tree type, tree init)
8377 : {
8378 1019471 : tree element_type = TREE_TYPE (type);
8379 :
8380 : /* Structured binding when initialized with an array type needs
8381 : to have complete type. */
8382 1019471 : if (decl
8383 1001145 : && DECL_DECOMPOSITION_P (decl)
8384 10451 : && DECL_DECOMP_IS_BASE (decl)
8385 1029922 : && !COMPLETE_TYPE_P (type))
8386 : {
8387 0 : error_at (DECL_SOURCE_LOCATION (decl),
8388 : "structured binding has incomplete type %qT", type);
8389 0 : TREE_TYPE (decl) = error_mark_node;
8390 0 : return true;
8391 : }
8392 :
8393 : /* The array type itself need not be complete, because the
8394 : initializer may tell us how many elements are in the array.
8395 : But, the elements of the array must be complete. */
8396 1019471 : if (!COMPLETE_TYPE_P (complete_type (element_type)))
8397 : {
8398 15 : if (decl)
8399 9 : error_at (DECL_SOURCE_LOCATION (decl),
8400 : "elements of array %q#D have incomplete type", decl);
8401 : else
8402 6 : error ("elements of array %q#T have incomplete type", type);
8403 15 : return true;
8404 : }
8405 :
8406 1019456 : location_t loc = (decl ? location_of (decl) : input_location);
8407 1019456 : if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
8408 : return true;
8409 :
8410 : /* A compound literal can't have variable size. */
8411 1019456 : if (init && !decl
8412 1019456 : && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
8413 18317 : || !TREE_CONSTANT (TYPE_SIZE (element_type))))
8414 : {
8415 3 : error ("variable-sized compound literal");
8416 3 : return true;
8417 : }
8418 : return false;
8419 : }
8420 :
8421 : /* Subroutine of check_initializer; args are passed down from that function.
8422 : Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init. */
8423 :
8424 : static tree
8425 3185258 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
8426 : {
8427 3185258 : gcc_assert (stmts_are_full_exprs_p ());
8428 3185258 : if (init)
8429 2601268 : maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
8430 3185258 : return build_aggr_init (decl, init, flags, tf_warning_or_error);
8431 : }
8432 :
8433 : /* Verify INIT (the initializer for DECL), and record the
8434 : initialization in DECL_INITIAL, if appropriate. CLEANUP is as for
8435 : grok_reference_init.
8436 :
8437 : If the return value is non-NULL, it is an expression that must be
8438 : evaluated dynamically to initialize DECL. */
8439 :
8440 : static tree
8441 58133283 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
8442 : {
8443 58133283 : tree type;
8444 58133283 : tree init_code = NULL;
8445 58133283 : tree core_type;
8446 :
8447 : /* Things that are going to be initialized need to have complete
8448 : type. */
8449 58133283 : TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
8450 :
8451 58133283 : if (DECL_HAS_VALUE_EXPR_P (decl))
8452 : {
8453 : /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
8454 : it doesn't have storage to be initialized. */
8455 108 : gcc_assert (init == NULL_TREE);
8456 : return NULL_TREE;
8457 : }
8458 :
8459 58133175 : if (type == error_mark_node)
8460 : /* We will have already complained. */
8461 : return NULL_TREE;
8462 :
8463 58133175 : if (TREE_CODE (type) == ARRAY_TYPE)
8464 : {
8465 1001145 : if (check_array_initializer (decl, type, init))
8466 : return NULL_TREE;
8467 : }
8468 57132030 : else if (!COMPLETE_TYPE_P (type))
8469 : {
8470 37 : error_at (DECL_SOURCE_LOCATION (decl),
8471 : "%q#D has incomplete type", decl);
8472 37 : TREE_TYPE (decl) = error_mark_node;
8473 37 : return NULL_TREE;
8474 : }
8475 : else
8476 : /* There is no way to make a variable-sized class type in GNU C++. */
8477 57131993 : gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
8478 :
8479 58133129 : if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
8480 : {
8481 2905686 : int init_len = CONSTRUCTOR_NELTS (init);
8482 2905686 : if (SCALAR_TYPE_P (type))
8483 : {
8484 70340 : if (init_len == 0)
8485 : {
8486 37525 : maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
8487 37525 : init = build_zero_init (type, NULL_TREE, false);
8488 : }
8489 32815 : else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
8490 : {
8491 12 : error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
8492 : "scalar object %qD requires one element in "
8493 : "initializer", decl);
8494 6 : TREE_TYPE (decl) = error_mark_node;
8495 6 : return NULL_TREE;
8496 : }
8497 : }
8498 : }
8499 :
8500 58133123 : if (TREE_CODE (decl) == CONST_DECL)
8501 : {
8502 0 : gcc_assert (!TYPE_REF_P (type));
8503 :
8504 0 : DECL_INITIAL (decl) = init;
8505 :
8506 0 : gcc_assert (init != NULL_TREE);
8507 : init = NULL_TREE;
8508 : }
8509 58133123 : else if (!init && DECL_REALLY_EXTERN (decl))
8510 : ;
8511 58133123 : else if (flag_openmp
8512 189889 : && VAR_P (decl)
8513 189889 : && DECL_LANG_SPECIFIC (decl)
8514 110971 : && DECL_OMP_DECLARE_MAPPER_P (decl)
8515 58133123 : && TREE_CODE (init) == OMP_DECLARE_MAPPER)
8516 : return NULL_TREE;
8517 4303049 : else if (init || type_build_ctor_call (type)
8518 61852179 : || TYPE_REF_P (type))
8519 : {
8520 54414082 : if (TYPE_REF_P (type))
8521 : {
8522 380966 : init = grok_reference_init (decl, type, init, flags);
8523 380966 : flags |= LOOKUP_ALREADY_DIGESTED;
8524 : }
8525 54033116 : else if (!init)
8526 583993 : check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
8527 : tf_warning_or_error);
8528 : /* Do not reshape constructors of vectors (they don't need to be
8529 : reshaped. */
8530 53449123 : else if (BRACE_ENCLOSED_INITIALIZER_P (init))
8531 : {
8532 2867774 : if (is_std_init_list (type))
8533 : {
8534 401 : init = perform_implicit_conversion (type, init,
8535 : tf_warning_or_error);
8536 401 : flags |= LOOKUP_ALREADY_DIGESTED;
8537 : }
8538 2867373 : else if (TYPE_NON_AGGREGATE_CLASS (type))
8539 : {
8540 : /* Don't reshape if the class has constructors. */
8541 449248 : if (cxx_dialect == cxx98)
8542 6 : error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
8543 : "in C++98 %qD must be initialized by "
8544 : "constructor, not by %<{...}%>",
8545 : decl);
8546 : }
8547 2418125 : else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
8548 : {
8549 0 : error ("opaque vector types cannot be initialized");
8550 0 : init = error_mark_node;
8551 : }
8552 : else
8553 : {
8554 2418125 : init = reshape_init (type, init, tf_warning_or_error);
8555 2418125 : flags |= LOOKUP_NO_NARROWING;
8556 : }
8557 : }
8558 : /* [dcl.init] "Otherwise, if the destination type is an array, the object
8559 : is initialized as follows..." So handle things like
8560 :
8561 : int a[](1, 2, 3);
8562 :
8563 : which is permitted in C++20 by P0960. */
8564 50581349 : else if (TREE_CODE (init) == TREE_LIST
8565 758938 : && TREE_TYPE (init) == NULL_TREE
8566 758938 : && TREE_CODE (type) == ARRAY_TYPE
8567 182 : && !DECL_DECOMPOSITION_P (decl)
8568 50581501 : && (cxx_dialect >= cxx20))
8569 142 : init = do_aggregate_paren_init (init, type);
8570 50581207 : else if (TREE_CODE (init) == TREE_LIST
8571 758796 : && TREE_TYPE (init) != unknown_type_node
8572 51340003 : && !MAYBE_CLASS_TYPE_P (type))
8573 : {
8574 131140 : gcc_assert (TREE_CODE (decl) != RESULT_DECL);
8575 :
8576 : /* We get here with code like `int a (2);' */
8577 131140 : init = build_x_compound_expr_from_list (init, ELK_INIT,
8578 : tf_warning_or_error);
8579 : }
8580 :
8581 : /* If DECL has an array type without a specific bound, deduce the
8582 : array size from the initializer. */
8583 54414082 : maybe_deduce_size_from_array_init (decl, init);
8584 54414082 : type = TREE_TYPE (decl);
8585 54414082 : if (type == error_mark_node)
8586 : return NULL_TREE;
8587 :
8588 105391708 : if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
8589 5344748 : && !(flags & LOOKUP_ALREADY_DIGESTED)
8590 7963081 : && !(init
8591 4760357 : && BRACE_ENCLOSED_INITIALIZER_P (init)
8592 5237468 : && CP_AGGREGATE_TYPE_P (type)))
8593 105653295 : || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
8594 : {
8595 3185258 : init_code = build_aggr_init_full_exprs (decl, init, flags);
8596 :
8597 : /* A constructor call is a non-trivial initializer even if
8598 : it isn't explicitly written. */
8599 3185258 : if (TREE_SIDE_EFFECTS (init_code))
8600 3161806 : DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
8601 :
8602 : /* If this is a constexpr initializer, expand_default_init will
8603 : have returned an INIT_EXPR rather than a CALL_EXPR. In that
8604 : case, pull the initializer back out and pass it down into
8605 : store_init_value. */
8606 8471237 : while (true)
8607 : {
8608 8471237 : if (TREE_CODE (init_code) == EXPR_STMT
8609 5320837 : || TREE_CODE (init_code) == STMT_EXPR
8610 5283298 : || TREE_CODE (init_code) == CONVERT_EXPR)
8611 5248603 : init_code = TREE_OPERAND (init_code, 0);
8612 3222634 : else if (TREE_CODE (init_code) == BIND_EXPR)
8613 37376 : init_code = BIND_EXPR_BODY (init_code);
8614 : else
8615 : break;
8616 : }
8617 3185258 : if (TREE_CODE (init_code) == INIT_EXPR)
8618 : {
8619 : /* In C++20, the call to build_aggr_init could have created
8620 : an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
8621 : A(1, 2). */
8622 2090086 : init = TREE_OPERAND (init_code, 1);
8623 2090086 : init_code = NULL_TREE;
8624 : /* Don't call digest_init; it's unnecessary and will complain
8625 : about aggregate initialization of non-aggregate classes. */
8626 2090086 : flags |= LOOKUP_ALREADY_DIGESTED;
8627 : }
8628 1095172 : else if (DECL_DECLARED_CONSTEXPR_P (decl)
8629 2171335 : || DECL_DECLARED_CONSTINIT_P (decl))
8630 : {
8631 : /* Declared constexpr or constinit, but no suitable initializer;
8632 : massage init appropriately so we can pass it into
8633 : store_init_value for the error. */
8634 19027 : tree new_init = NULL_TREE;
8635 19027 : if (!processing_template_decl
8636 271 : && TREE_CODE (init_code) == CALL_EXPR)
8637 232 : new_init = build_cplus_new (type, init_code, tf_none);
8638 18795 : else if (CLASS_TYPE_P (type)
8639 37590 : && (!init || TREE_CODE (init) == TREE_LIST))
8640 18619 : new_init = build_functional_cast (input_location, type,
8641 : init, tf_none);
8642 18851 : if (new_init)
8643 : {
8644 18851 : init = new_init;
8645 18851 : if (TREE_CODE (init) == TARGET_EXPR
8646 261 : && !(flags & LOOKUP_ONLYCONVERTING))
8647 261 : TARGET_EXPR_DIRECT_INIT_P (init) = true;
8648 : }
8649 : init_code = NULL_TREE;
8650 : }
8651 : else
8652 : init = NULL_TREE;
8653 : }
8654 :
8655 53337933 : if (init && TREE_CODE (init) != TREE_VEC)
8656 : {
8657 53337918 : init_code = store_init_value (decl, init, cleanups, flags);
8658 :
8659 53335221 : if (DECL_INITIAL (decl)
8660 38725138 : && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
8661 56427673 : && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
8662 : {
8663 1366943 : tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
8664 1366943 : if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
8665 1366943 : && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
8666 36 : cp_complete_array_type (&TREE_TYPE (elt), elt, false);
8667 : }
8668 :
8669 2563547 : if (pedantic && TREE_CODE (type) == ARRAY_TYPE
8670 65774 : && DECL_INITIAL (decl)
8671 65031 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8672 53395955 : && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
8673 6 : warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
8674 3 : DECL_SOURCE_LOCATION (decl)),
8675 3 : 0, "array %qD initialized by parenthesized "
8676 : "string literal %qE",
8677 3 : decl, DECL_INITIAL (decl));
8678 : init = NULL_TREE;
8679 : }
8680 : }
8681 3719041 : else if (!init && REFLECTION_TYPE_P (type))
8682 : {
8683 : /* [dcl.init.general]: To default-initialize an object of type
8684 : std::meta::info means that the object is zero-initialized. */
8685 154 : DECL_INITIAL (decl)
8686 154 : = build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
8687 154 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
8688 154 : TREE_CONSTANT (decl) = true;
8689 154 : init = NULL_TREE;
8690 : }
8691 : else
8692 : {
8693 7437774 : if (CLASS_TYPE_P (core_type = strip_array_types (type))
8694 4533571 : && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
8695 814669 : || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
8696 21 : diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
8697 : /*complain=*/true);
8698 :
8699 3718887 : check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
8700 : tf_warning_or_error);
8701 : }
8702 :
8703 154 : if (init && init != error_mark_node)
8704 0 : init_code = cp_build_init_expr (decl, init);
8705 :
8706 15835529 : if (init_code && !TREE_SIDE_EFFECTS (init_code)
8707 58189492 : && init_code != error_mark_node)
8708 : init_code = NULL_TREE;
8709 :
8710 58073634 : if (init_code)
8711 : {
8712 : /* We might have set these in cp_finish_decl. */
8713 15778741 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
8714 15778741 : TREE_CONSTANT (decl) = false;
8715 : }
8716 :
8717 15778741 : if (init_code
8718 15778741 : && DECL_IN_AGGR_P (decl)
8719 6 : && DECL_INITIALIZED_IN_CLASS_P (decl))
8720 : {
8721 0 : static int explained = 0;
8722 :
8723 0 : auto_diagnostic_group d;
8724 0 : if (cxx_dialect < cxx11)
8725 0 : error ("initializer invalid for static member with constructor");
8726 0 : else if (cxx_dialect < cxx17)
8727 0 : error ("non-constant in-class initialization invalid for static "
8728 : "member %qD", decl);
8729 : else
8730 0 : error ("non-constant in-class initialization invalid for non-inline "
8731 : "static member %qD", decl);
8732 0 : if (!explained)
8733 : {
8734 0 : inform (input_location,
8735 : "(an out of class initialization is required)");
8736 0 : explained = 1;
8737 : }
8738 0 : return NULL_TREE;
8739 0 : }
8740 :
8741 : return init_code;
8742 : }
8743 :
8744 : /* If DECL is not a local variable, give it RTL. */
8745 :
8746 : static void
8747 123679602 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
8748 : {
8749 123679602 : int toplev = toplevel_bindings_p ();
8750 123679602 : int defer_p;
8751 :
8752 : /* Set the DECL_ASSEMBLER_NAME for the object. */
8753 123679602 : if (asmspec)
8754 : {
8755 : /* The `register' keyword, when used together with an
8756 : asm-specification, indicates that the variable should be
8757 : placed in a particular register. */
8758 1022265 : if (VAR_P (decl) && DECL_REGISTER (decl))
8759 : {
8760 87 : if (TREE_ADDRESSABLE (decl))
8761 3 : error_at (DECL_SOURCE_LOCATION (decl),
8762 : "address of explicit register variable %qD requested",
8763 : decl);
8764 : else
8765 : {
8766 84 : set_user_assembler_name (decl, asmspec);
8767 84 : DECL_HARD_REGISTER (decl) = 1;
8768 : }
8769 : }
8770 : else
8771 : {
8772 1022178 : if (TREE_CODE (decl) == FUNCTION_DECL
8773 1022178 : && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
8774 81822 : set_builtin_user_assembler_name (decl, asmspec);
8775 1022178 : set_user_assembler_name (decl, asmspec);
8776 1022178 : if (DECL_LOCAL_DECL_P (decl))
8777 6 : if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
8778 : /* We have to propagate the name to the ns-alias.
8779 : This is horrible, as we're affecting a
8780 : possibly-shared decl. Again, a one-true-decl
8781 : model breaks down. */
8782 6 : if (ns_decl != error_mark_node)
8783 6 : set_user_assembler_name (ns_decl, asmspec);
8784 : }
8785 : }
8786 :
8787 : /* Handle non-variables up front. */
8788 123679602 : if (!VAR_P (decl))
8789 : {
8790 58825725 : rest_of_decl_compilation (decl, toplev, at_eof);
8791 58825725 : return;
8792 : }
8793 :
8794 : /* If we see a class member here, it should be a static data
8795 : member. */
8796 64853877 : if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
8797 : {
8798 5626469 : gcc_assert (TREE_STATIC (decl));
8799 : /* An in-class declaration of a static data member should be
8800 : external; it is only a declaration, and not a definition. */
8801 5626469 : if (init == NULL_TREE)
8802 5626444 : gcc_assert (DECL_EXTERNAL (decl)
8803 : || !TREE_PUBLIC (decl));
8804 : }
8805 :
8806 : /* We don't create any RTL for local variables. */
8807 64853877 : if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
8808 : return;
8809 :
8810 : /* Don't output reflection variables. */
8811 39908189 : if (consteval_only_p (decl))
8812 : {
8813 : /* Disable assemble_variable. */
8814 1800 : DECL_EXTERNAL (decl) = true;
8815 : /* Undo make_decl_one_only. */
8816 1800 : if (DECL_COMDAT_GROUP (decl))
8817 : {
8818 310 : symtab_node *node = symtab_node::get (decl);
8819 310 : node->set_comdat_group (NULL);
8820 310 : node->dissolve_same_comdat_group_list ();
8821 : }
8822 1800 : return;
8823 : }
8824 :
8825 : /* We defer emission of local statics until the corresponding
8826 : DECL_EXPR is expanded. But with constexpr its function might never
8827 : be expanded, so go ahead and tell cgraph about the variable now. */
8828 79812778 : defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
8829 140737 : && !var_in_maybe_constexpr_fn (decl))
8830 79676657 : || DECL_VIRTUAL_P (decl));
8831 :
8832 : /* Defer template instantiations. */
8833 39906389 : if (DECL_LANG_SPECIFIC (decl)
8834 39906389 : && DECL_IMPLICIT_INSTANTIATION (decl))
8835 : defer_p = 1;
8836 :
8837 : /* If we're not deferring, go ahead and assemble the variable. */
8838 20371735 : if (!defer_p)
8839 17973043 : rest_of_decl_compilation (decl, toplev, at_eof);
8840 : }
8841 :
8842 : /* walk_tree helper for wrap_temporary_cleanups, below. */
8843 :
8844 : static tree
8845 11095233 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
8846 : {
8847 : /* Stop at types or full-expression boundaries. */
8848 11095233 : if (TYPE_P (*stmt_p)
8849 11095005 : || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
8850 : {
8851 488 : *walk_subtrees = 0;
8852 488 : return NULL_TREE;
8853 : }
8854 :
8855 11094745 : if (TREE_CODE (*stmt_p) == TARGET_EXPR)
8856 : {
8857 236840 : tree guard = (tree)data;
8858 236840 : tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
8859 :
8860 118024 : if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
8861 350891 : && !expr_noexcept_p (tcleanup, tf_none))
8862 : {
8863 145 : tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
8864 : /* Tell honor_protect_cleanup_actions to handle this as a separate
8865 : cleanup. */
8866 145 : TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
8867 145 : TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
8868 : }
8869 : }
8870 :
8871 : return NULL_TREE;
8872 : }
8873 :
8874 : /* We're initializing a local variable which has a cleanup GUARD. If there
8875 : are any temporaries used in the initializer INIT of this variable, we
8876 : need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
8877 : variable will be cleaned up properly if one of them throws.
8878 :
8879 : Unfortunately, there's no way to express this properly in terms of
8880 : nesting, as the regions for the temporaries overlap the region for the
8881 : variable itself; if there are two temporaries, the variable needs to be
8882 : the first thing destroyed if either of the temporary destructors throws.
8883 : However, we only want to run the variable's cleanup if it actually got
8884 : constructed. So we need to guard the temporary cleanups with the
8885 : variable's cleanup if they are run on the normal path, but not if they
8886 : are run on the exceptional path. We implement this by telling
8887 : honor_protect_cleanup_actions to strip the variable cleanup from the
8888 : exceptional path.
8889 :
8890 : Another approach could be to make the variable cleanup region enclose
8891 : initialization, but depend on a flag to indicate that the variable is
8892 : initialized; that's effectively what we do for arrays. But the current
8893 : approach works fine for non-arrays, and has no code overhead in the usual
8894 : case where the temporary destructors are noexcept. */
8895 :
8896 : static void
8897 1003060 : wrap_temporary_cleanups (tree init, tree guard)
8898 : {
8899 1003060 : if (TREE_CODE (guard) == BIND_EXPR)
8900 : {
8901 : /* An array cleanup region already encloses any temporary cleanups,
8902 : don't wrap it around them again. */
8903 422 : gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
8904 : return;
8905 : }
8906 1002638 : cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
8907 : }
8908 :
8909 : /* Generate code to initialize DECL (a local variable). */
8910 :
8911 : static void
8912 24945661 : initialize_local_var (tree decl, tree init, bool decomp)
8913 : {
8914 24945661 : tree type = TREE_TYPE (decl);
8915 24945661 : tree cleanup;
8916 24945661 : int already_used;
8917 :
8918 24945661 : gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
8919 24945661 : gcc_assert (!TREE_STATIC (decl));
8920 :
8921 24945661 : if (DECL_SIZE (decl) == NULL_TREE)
8922 : {
8923 : /* If we used it already as memory, it must stay in memory. */
8924 0 : DECL_INITIAL (decl) = NULL_TREE;
8925 0 : TREE_ADDRESSABLE (decl) = TREE_USED (decl);
8926 0 : return;
8927 : }
8928 :
8929 24945661 : if (type == error_mark_node)
8930 : return;
8931 :
8932 : /* Compute and store the initial value. */
8933 24945661 : already_used = TREE_USED (decl) || TREE_USED (type);
8934 24945661 : if (TREE_USED (type))
8935 32 : DECL_READ_P (decl) = 1;
8936 :
8937 : /* Generate a cleanup, if necessary. */
8938 24945661 : cleanup = (decomp ? NULL_TREE
8939 24910478 : : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
8940 :
8941 : /* Perform the initialization. */
8942 24945661 : if (init)
8943 : {
8944 15764541 : tree rinit = (TREE_CODE (init) == INIT_EXPR
8945 15764541 : ? TREE_OPERAND (init, 1) : NULL_TREE);
8946 14414266 : if (rinit && !TREE_SIDE_EFFECTS (rinit)
8947 22328301 : && TREE_OPERAND (init, 0) == decl)
8948 : {
8949 : /* Stick simple initializers in DECL_INITIAL so that
8950 : -Wno-init-self works (c++/34772). */
8951 7914035 : DECL_INITIAL (decl) = rinit;
8952 :
8953 7914035 : if (warn_init_self && TYPE_REF_P (type))
8954 : {
8955 2469 : STRIP_NOPS (rinit);
8956 2469 : if (rinit == decl)
8957 3 : warning_at (DECL_SOURCE_LOCATION (decl),
8958 3 : OPT_Winit_self,
8959 : "reference %qD is initialized with itself", decl);
8960 : }
8961 : }
8962 : else
8963 : {
8964 7850506 : int saved_stmts_are_full_exprs_p;
8965 :
8966 : /* If we're only initializing a single object, guard the
8967 : destructors of any temporaries used in its initializer with
8968 : its destructor. */
8969 7850506 : if (cleanup)
8970 999657 : wrap_temporary_cleanups (init, cleanup);
8971 :
8972 7850506 : gcc_assert (building_stmt_list_p ());
8973 7850506 : saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
8974 : /* Avoid CLEANUP_POINT_EXPR for the structured binding
8975 : bases, those will have CLEANUP_POINT_EXPR at the end of
8976 : code emitted by cp_finish_decomp. */
8977 7850506 : if (decomp)
8978 34686 : current_stmt_tree ()->stmts_are_full_exprs_p = 0;
8979 : else
8980 7815820 : current_stmt_tree ()->stmts_are_full_exprs_p = 1;
8981 7850506 : finish_expr_stmt (init);
8982 7850506 : current_stmt_tree ()->stmts_are_full_exprs_p
8983 7850506 : = saved_stmts_are_full_exprs_p;
8984 : }
8985 : }
8986 :
8987 : /* Set this to 0 so we can tell whether an aggregate which was
8988 : initialized was ever used. Don't do this if it has a
8989 : destructor, so we don't complain about the 'resource
8990 : allocation is initialization' idiom. Now set
8991 : attribute((unused)) on types so decls of that type will be
8992 : marked used. (see TREE_USED, above.) */
8993 24945661 : if (TYPE_NEEDS_CONSTRUCTING (type)
8994 2191218 : && ! already_used
8995 25106 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
8996 24967942 : && DECL_NAME (decl))
8997 22233 : TREE_USED (decl) = 0;
8998 24923428 : else if (already_used)
8999 21906602 : TREE_USED (decl) = 1;
9000 :
9001 24945661 : if (cleanup)
9002 1013232 : finish_decl_cleanup (decl, cleanup);
9003 : }
9004 :
9005 : /* DECL is a VAR_DECL for a compiler-generated variable with static
9006 : storage duration (like a virtual table) whose initializer is a
9007 : compile-time constant. Initialize the variable and provide it to the
9008 : back end. */
9009 :
9010 : void
9011 2221791 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
9012 : {
9013 2221791 : tree init;
9014 2221791 : gcc_assert (DECL_ARTIFICIAL (decl));
9015 2221791 : init = build_constructor (TREE_TYPE (decl), v);
9016 2221791 : gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
9017 2221791 : DECL_INITIAL (decl) = init;
9018 2221791 : DECL_INITIALIZED_P (decl) = 1;
9019 : /* Mark the decl as constexpr so that we can access its content
9020 : at compile time. */
9021 2221791 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
9022 2221791 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
9023 2221791 : determine_visibility (decl);
9024 2221791 : layout_var_decl (decl);
9025 2221791 : maybe_commonize_var (decl);
9026 2221791 : make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
9027 2221791 : }
9028 :
9029 : /* INIT is the initializer for a variable, as represented by the
9030 : parser. Returns true iff INIT is value-dependent. */
9031 :
9032 : static bool
9033 9980561 : value_dependent_init_p (tree init)
9034 : {
9035 9980561 : if (TREE_CODE (init) == TREE_LIST)
9036 : /* A parenthesized initializer, e.g.: int i (3, 2); ? */
9037 21444 : return any_value_dependent_elements_p (init);
9038 9959117 : else if (TREE_CODE (init) == CONSTRUCTOR)
9039 : /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
9040 : {
9041 73163 : if (dependent_type_p (TREE_TYPE (init)))
9042 : return true;
9043 :
9044 73157 : vec<constructor_elt, va_gc> *elts;
9045 73157 : size_t nelts;
9046 73157 : size_t i;
9047 :
9048 73157 : elts = CONSTRUCTOR_ELTS (init);
9049 73157 : nelts = vec_safe_length (elts);
9050 646233 : for (i = 0; i < nelts; ++i)
9051 602209 : if (value_dependent_init_p ((*elts)[i].value))
9052 : return true;
9053 : }
9054 : else
9055 : /* It must be a simple expression, e.g., int i = 3; */
9056 9885954 : return value_dependent_expression_p (init);
9057 :
9058 : return false;
9059 : }
9060 :
9061 : /* A helper function to be called via walk_tree. If any label exists
9062 : under *TP, it is (going to be) forced. Set has_forced_label_in_static. */
9063 :
9064 : static tree
9065 337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
9066 : {
9067 337 : if (TYPE_P (*tp))
9068 0 : *walk_subtrees = 0;
9069 337 : if (TREE_CODE (*tp) == LABEL_DECL)
9070 6 : cfun->has_forced_label_in_static = 1;
9071 337 : return NULL_TREE;
9072 : }
9073 :
9074 : /* Return true if DECL has either a trivial destructor, or for C++20
9075 : is constexpr and has a constexpr destructor. */
9076 :
9077 : static bool
9078 63284445 : decl_maybe_constant_destruction (tree decl, tree type)
9079 : {
9080 63284445 : return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
9081 63284445 : || (cxx_dialect >= cxx20
9082 4123139 : && VAR_P (decl)
9083 4122794 : && DECL_DECLARED_CONSTEXPR_P (decl)
9084 484 : && type_has_constexpr_destructor (strip_array_types (type))));
9085 : }
9086 :
9087 : static tree declare_simd_adjust_this (tree *, int *, void *);
9088 :
9089 : /* Helper function of omp_declare_variant_finalize. Finalize one
9090 : "omp declare variant base" attribute. Return true if it should be
9091 : removed. */
9092 :
9093 : static bool
9094 1755 : omp_declare_variant_finalize_one (tree decl, tree attr)
9095 : {
9096 1755 : if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
9097 : {
9098 164 : walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
9099 : DECL_ARGUMENTS (decl), NULL);
9100 164 : walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
9101 : DECL_ARGUMENTS (decl), NULL);
9102 : }
9103 :
9104 1755 : tree ctx = TREE_VALUE (TREE_VALUE (attr));
9105 1755 : tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
9106 : OMP_TRAIT_CONSTRUCT_SIMD);
9107 1755 : if (simd)
9108 : {
9109 51 : TREE_VALUE (simd)
9110 51 : = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
9111 51 : OMP_TS_PROPERTIES (simd));
9112 : /* FIXME, adjusting simd args unimplemented. */
9113 51 : return true;
9114 : }
9115 :
9116 1704 : tree chain = TREE_CHAIN (TREE_VALUE (attr));
9117 1704 : location_t varid_loc
9118 1704 : = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
9119 1704 : location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
9120 1704 : cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
9121 1704 : tree variant = TREE_PURPOSE (TREE_VALUE (attr));
9122 :
9123 1704 : location_t save_loc = input_location;
9124 1704 : input_location = varid_loc;
9125 :
9126 1704 : releasing_vec args;
9127 1704 : tree parm = DECL_ARGUMENTS (decl);
9128 1704 : if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
9129 164 : parm = DECL_CHAIN (parm);
9130 3026 : for (; parm; parm = DECL_CHAIN (parm))
9131 1322 : vec_safe_push (args, forward_parm (parm));
9132 :
9133 1704 : unsigned nappend_args = 0;
9134 1704 : tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
9135 1704 : if (append_args_list)
9136 : {
9137 354 : append_args_list = TREE_VALUE (append_args_list);
9138 354 : append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
9139 591 : ? TREE_VALUE (TREE_CHAIN (append_args_list))
9140 : : NULL_TREE);
9141 741 : for (tree t = append_args_list; t; t = TREE_CHAIN (t))
9142 387 : nappend_args++;
9143 354 : if (nappend_args)
9144 : {
9145 237 : tree type;
9146 237 : if ((type = lookup_qualified_name (global_namespace,
9147 : "omp_interop_t",
9148 : LOOK_want::NORMAL,
9149 : /*complain*/false)) == NULL_TREE
9150 237 : || !c_omp_interop_t_p (TREE_TYPE (type)))
9151 : {
9152 24 : location_t loc = input_location;
9153 24 : variant = tree_strip_any_location_wrapper (variant);
9154 24 : if (!identifier_p (variant))
9155 : {
9156 21 : if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
9157 21 : variant = OVL_FIRST (variant);
9158 21 : loc = EXPR_LOC_OR_LOC (variant,
9159 : DECL_SOURCE_LOCATION (variant));
9160 : }
9161 24 : auto_diagnostic_group d;
9162 24 : error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
9163 24 : args->length () + 1, variant);
9164 24 : inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
9165 : "%<append_args%> specified here");
9166 24 : return true;
9167 24 : }
9168 564 : for (unsigned i = 0; i < nappend_args; i++)
9169 351 : vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
9170 : }
9171 : }
9172 :
9173 1680 : bool koenig_p = false;
9174 1680 : if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
9175 : {
9176 1610 : if (identifier_p (variant)
9177 : /* In C++20, we may need to perform ADL for a template
9178 : name. */
9179 1586 : || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
9180 18 : && identifier_p (TREE_OPERAND (variant, 0))))
9181 : {
9182 24 : if (!args->is_empty ())
9183 : {
9184 24 : koenig_p = true;
9185 24 : if (!any_type_dependent_arguments_p (args))
9186 21 : variant = perform_koenig_lookup (variant, args,
9187 : tf_warning_or_error);
9188 : }
9189 : else
9190 0 : variant = unqualified_fn_lookup_error (variant);
9191 : }
9192 1586 : else if (!args->is_empty () && is_overloaded_fn (variant))
9193 : {
9194 830 : tree fn = get_first_fn (variant);
9195 830 : fn = STRIP_TEMPLATE (fn);
9196 830 : if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
9197 830 : || DECL_FUNCTION_MEMBER_P (fn)
9198 717 : || DECL_LOCAL_DECL_P (fn)))
9199 : {
9200 717 : koenig_p = true;
9201 717 : if (!any_type_dependent_arguments_p (args))
9202 666 : variant = perform_koenig_lookup (variant, args,
9203 : tf_warning_or_error);
9204 : }
9205 : }
9206 : }
9207 :
9208 1680 : if (idk == CP_ID_KIND_QUALIFIED)
9209 6 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
9210 : koenig_p, tf_warning_or_error);
9211 1674 : else if (idk == CP_ID_KIND_NONE
9212 64 : && TREE_CODE (variant) == FUNCTION_DECL
9213 64 : && DECL_IOBJ_MEMBER_FUNCTION_P (variant)
9214 1722 : && CLASS_TYPE_P (DECL_CONTEXT (decl)))
9215 : {
9216 48 : tree saved_ccp = current_class_ptr;
9217 48 : tree saved_ccr = current_class_ref;
9218 48 : current_class_ptr = NULL_TREE;
9219 48 : current_class_ref = NULL_TREE;
9220 48 : inject_this_parameter (DECL_CONTEXT (decl), TYPE_UNQUALIFIED);
9221 48 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
9222 : koenig_p, tf_warning_or_error);
9223 48 : current_class_ptr = saved_ccp;
9224 48 : current_class_ref = saved_ccr;
9225 : }
9226 : else
9227 1626 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
9228 : koenig_p, tf_warning_or_error);
9229 1680 : if (variant == error_mark_node && !processing_template_decl)
9230 : return true;
9231 :
9232 1614 : if (TREE_CODE (variant) == TARGET_EXPR)
9233 9 : variant = TARGET_EXPR_INITIAL (variant);
9234 :
9235 3219 : variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
9236 1614 : input_location = save_loc;
9237 :
9238 1614 : if (variant == decl)
9239 : {
9240 0 : error_at (varid_loc, "variant %qD is the same as base function",
9241 : variant);
9242 0 : return true;
9243 : }
9244 :
9245 1614 : if (variant)
9246 : {
9247 1530 : bool fail;
9248 1530 : const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
9249 1530 : if (!nappend_args)
9250 1371 : fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
9251 : COMPARE_STRICT);
9252 : else
9253 : {
9254 159 : unsigned nbase_args = 0;
9255 159 : for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
9256 756 : t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
9257 240 : nbase_args++;
9258 159 : tree vargs, varg;
9259 159 : vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
9260 399 : for (unsigned i = 0; i < nbase_args && varg;
9261 240 : i++, varg = TREE_CHAIN (varg))
9262 240 : vargs = varg;
9263 417 : for (unsigned i = 0; i < nappend_args && varg; i++)
9264 258 : varg = TREE_CHAIN (varg);
9265 159 : tree saved_vargs;
9266 159 : int saved_no_named_args_stdarg = 0;
9267 159 : if (nbase_args)
9268 : {
9269 111 : saved_vargs = TREE_CHAIN (vargs);
9270 111 : TREE_CHAIN (vargs) = varg;
9271 : }
9272 : else
9273 : {
9274 48 : saved_vargs = vargs;
9275 48 : TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
9276 48 : saved_no_named_args_stdarg
9277 48 : = TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant));
9278 48 : if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl))
9279 48 : && varg == NULL_TREE)
9280 2 : TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1;
9281 : }
9282 : /* Skip assert check that TYPE_CANONICAL is the same. */
9283 159 : fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
9284 : COMPARE_STRUCTURAL);
9285 159 : if (nbase_args)
9286 111 : TREE_CHAIN (vargs) = saved_vargs;
9287 : else
9288 : {
9289 48 : TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
9290 48 : TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant))
9291 96 : = saved_no_named_args_stdarg;
9292 : }
9293 159 : varg = saved_vargs;
9294 159 : if (!fail && !processing_template_decl)
9295 402 : for (unsigned i = 0; i < nappend_args;
9296 246 : i++, varg = TREE_CHAIN (varg))
9297 507 : if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
9298 : {
9299 9 : auto_diagnostic_group d;
9300 9 : error_at (DECL_SOURCE_LOCATION (variant),
9301 : "argument %d of %qD must be of %<omp_interop_t%>",
9302 9 : nbase_args + i + 1, variant);
9303 9 : inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
9304 : "%<append_args%> specified here");
9305 9 : break;
9306 9 : }
9307 : }
9308 1530 : if (fail)
9309 : {
9310 69 : error_at (varid_loc, "variant %qD and base %qD have incompatible "
9311 : "types", variant, decl);
9312 69 : return true;
9313 : }
9314 1461 : if (fndecl_built_in_p (variant)
9315 1461 : && (startswith (varname, "__builtin_")
9316 0 : || startswith (varname, "__sync_")
9317 0 : || startswith (varname, "__atomic_")))
9318 : {
9319 6 : error_at (varid_loc, "variant %qD is a built-in", variant);
9320 6 : return true;
9321 : }
9322 : else
9323 : {
9324 1455 : tree construct
9325 1455 : = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
9326 1455 : omp_mark_declare_variant (match_loc, variant, construct);
9327 1455 : if (!omp_context_selector_matches (ctx, NULL_TREE, false))
9328 : return true;
9329 1039 : TREE_PURPOSE (TREE_VALUE (attr)) = variant;
9330 :
9331 : // Prepend adjust_args list to variant attributes
9332 1039 : tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
9333 1039 : if (adjust_args_list != NULL_TREE)
9334 : {
9335 507 : if (DECL_NONSTATIC_MEMBER_P (variant)
9336 285 : && TREE_VALUE (adjust_args_list))
9337 : {
9338 : /* Shift arg position for the added 'this' pointer. */
9339 : /* Handle need_device_ptr */
9340 21 : for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
9341 51 : t; t = TREE_CHAIN (t))
9342 30 : TREE_VALUE (t)
9343 30 : = build_int_cst (TREE_TYPE (t),
9344 30 : tree_to_uhwi (TREE_VALUE (t)) + 1);
9345 : }
9346 264 : if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
9347 : {
9348 : /* Shift likewise the number of args after which the
9349 : interop object should be added. */
9350 6 : tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
9351 6 : TREE_PURPOSE (nargs)
9352 6 : = build_int_cst (TREE_TYPE (nargs),
9353 6 : tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
9354 : }
9355 528 : for (tree t = append_args_list; t; t = TREE_CHAIN (t))
9356 264 : TREE_VALUE (t)
9357 264 : = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
9358 528 : DECL_ATTRIBUTES (variant) = tree_cons (
9359 : get_identifier ("omp declare variant variant args"),
9360 528 : TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
9361 : }
9362 : }
9363 : }
9364 84 : else if (!processing_template_decl)
9365 : {
9366 0 : error_at (varid_loc, "could not find variant declaration");
9367 0 : return true;
9368 : }
9369 :
9370 : return false;
9371 1704 : }
9372 :
9373 : /* Helper function, finish up "omp declare variant base" attribute
9374 : now that there is a DECL. ATTR is the first "omp declare variant base"
9375 : attribute. */
9376 :
9377 : void
9378 1548 : omp_declare_variant_finalize (tree decl, tree attr)
9379 : {
9380 1548 : size_t attr_len = strlen ("omp declare variant base");
9381 1548 : tree *list = &DECL_ATTRIBUTES (decl);
9382 1548 : bool remove_all = false;
9383 1548 : location_t match_loc = DECL_SOURCE_LOCATION (decl);
9384 1548 : if (TREE_CHAIN (TREE_VALUE (attr))
9385 1548 : && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
9386 3096 : && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
9387 1548 : match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
9388 3096 : if (DECL_CONSTRUCTOR_P (decl))
9389 : {
9390 27 : error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
9391 27 : remove_all = true;
9392 : }
9393 1521 : else if (DECL_DESTRUCTOR_P (decl))
9394 : {
9395 9 : error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
9396 9 : remove_all = true;
9397 : }
9398 1512 : else if (DECL_DEFAULTED_FN (decl))
9399 : {
9400 2 : error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
9401 2 : remove_all = true;
9402 : }
9403 1510 : else if (DECL_DELETED_FN (decl))
9404 : {
9405 2 : error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
9406 2 : remove_all = true;
9407 : }
9408 1508 : else if (DECL_VIRTUAL_P (decl))
9409 : {
9410 0 : error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
9411 0 : remove_all = true;
9412 : }
9413 : /* This loop is like private_lookup_attribute, except that it works
9414 : with tree * rather than tree, as we might want to remove the
9415 : attributes that are diagnosed as erroneous. */
9416 3355 : while (*list)
9417 : {
9418 1807 : tree attr = get_attribute_name (*list);
9419 1807 : size_t ident_len = IDENTIFIER_LENGTH (attr);
9420 4737 : if (cmp_attribs ("omp declare variant base", attr_len,
9421 1807 : IDENTIFIER_POINTER (attr), ident_len))
9422 : {
9423 1795 : if (remove_all || omp_declare_variant_finalize_one (decl, *list))
9424 : {
9425 672 : *list = TREE_CHAIN (*list);
9426 672 : continue;
9427 : }
9428 : }
9429 1135 : list = &TREE_CHAIN (*list);
9430 : }
9431 1548 : }
9432 :
9433 : /* [basic.stc.dynamic.deallocation]/3 - A deallocation function shall not
9434 : have a potentially throwing exception specification. */
9435 :
9436 : void
9437 207562313 : maybe_diagnose_deallocation_noexcept_false (tree decl)
9438 : {
9439 207562313 : if (cxx_dialect >= cxx29
9440 16321784 : && DECL_NAME (decl)
9441 16321784 : && IDENTIFIER_NEWDEL_OP_P (DECL_NAME (decl))
9442 207601754 : && !IDENTIFIER_NEW_OP_P (DECL_NAME (decl)))
9443 : {
9444 21657 : tree spec = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl));
9445 21657 : if (spec && spec == noexcept_false_spec)
9446 15 : error_at (DECL_SOURCE_LOCATION (decl),
9447 : "deallocation function %qD declared possibly throwing",
9448 : decl);
9449 : }
9450 207562313 : }
9451 :
9452 : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
9453 :
9454 : /* Finish processing of a declaration;
9455 : install its line number and initial value.
9456 : If the length of an array type is not known before,
9457 : it must be determined now, from the initial value, or it is an error.
9458 :
9459 : INIT is the initializer (if any) for DECL. If INIT_CONST_EXPR_P is
9460 : true, then INIT is an integral constant expression.
9461 :
9462 : FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
9463 : if the (init) syntax was used.
9464 :
9465 : DECOMP is first identifier's DECL and identifier count in a structured
9466 : bindings, nullptr if not a structured binding. */
9467 :
9468 : void
9469 333961361 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
9470 : tree asmspec_tree, int flags, cp_decomp *decomp)
9471 : {
9472 333961361 : vec<tree, va_gc> *cleanups = NULL;
9473 333961361 : const char *asmspec = NULL;
9474 333961361 : int was_readonly = 0;
9475 333961361 : bool var_definition_p = false;
9476 333961361 : tree auto_node;
9477 333961361 : auto_vec<tree> extra_cleanups;
9478 333961361 : tree aggregates1 = NULL_TREE;
9479 333961361 : struct decomp_cleanup {
9480 : tree decl;
9481 : cp_decomp *&decomp;
9482 333958664 : ~decomp_cleanup ()
9483 : {
9484 333958664 : if (decomp && DECL_DECOMPOSITION_P (decl))
9485 235726 : cp_finish_decomp (decl, decomp);
9486 333958664 : }
9487 333961361 : } decomp_cl = { decl, decomp };
9488 :
9489 333961361 : if (decl == error_mark_node)
9490 : return;
9491 333961321 : else if (! decl)
9492 : {
9493 0 : if (init)
9494 0 : error ("assignment (not initialization) in declaration");
9495 0 : return;
9496 : }
9497 :
9498 333961321 : gcc_assert (TREE_CODE (decl) != RESULT_DECL);
9499 : /* Parameters are handled by store_parm_decls, not cp_finish_decl. */
9500 333961321 : gcc_assert (TREE_CODE (decl) != PARM_DECL);
9501 :
9502 333961321 : tree type = TREE_TYPE (decl);
9503 333961321 : if (type == error_mark_node)
9504 : return;
9505 :
9506 333960630 : if (VAR_P (decl) && is_copy_initialization (init))
9507 99500674 : flags |= LOOKUP_ONLYCONVERTING;
9508 :
9509 : /* Warn about register storage specifiers except when in GNU global
9510 : or local register variable extension. */
9511 333960630 : if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
9512 : {
9513 1931 : if (cxx_dialect >= cxx17)
9514 1282 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
9515 : "ISO C++17 does not allow %<register%> storage "
9516 : "class specifier");
9517 : else
9518 649 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
9519 : "%<register%> storage class specifier used");
9520 : }
9521 :
9522 : /* If a name was specified, get the string. */
9523 333960630 : if (at_namespace_scope_p ())
9524 72109528 : asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
9525 333960630 : if (asmspec_tree && asmspec_tree != error_mark_node)
9526 1022274 : asmspec = TREE_STRING_POINTER (asmspec_tree);
9527 :
9528 333960630 : bool in_class_decl
9529 333960630 : = (current_class_type
9530 210732033 : && CP_DECL_CONTEXT (decl) == current_class_type
9531 139877759 : && TYPE_BEING_DEFINED (current_class_type)
9532 471724544 : && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
9533 :
9534 132542539 : if (in_class_decl
9535 132542539 : && (DECL_INITIAL (decl) || init))
9536 97269285 : DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
9537 :
9538 333960630 : if (VAR_P (decl)
9539 333960630 : && (auto_node = type_uses_auto (type)))
9540 : {
9541 13980344 : tree d_init;
9542 13980344 : if (init == NULL_TREE)
9543 : {
9544 4598 : if (DECL_LANG_SPECIFIC (decl)
9545 4513 : && DECL_TEMPLATE_INSTANTIATION (decl)
9546 9108 : && !DECL_TEMPLATE_INSTANTIATED (decl))
9547 : {
9548 : /* init is null because we're deferring instantiating the
9549 : initializer until we need it. Well, we need it now. */
9550 4504 : instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
9551 4504 : return;
9552 : }
9553 :
9554 94 : if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
9555 : /* Class deduction with no initializer is OK. */;
9556 : else
9557 : {
9558 : /* Ordinary auto deduction without an initializer, a situation
9559 : which grokdeclarator already detects and rejects for the most
9560 : part. But we can still get here if we're instantiating a
9561 : variable template before we've fully parsed (and attached) its
9562 : initializer, e.g. template<class> auto x = x<int>; */
9563 3 : error_at (DECL_SOURCE_LOCATION (decl),
9564 : "declaration of %q#D has no initializer", decl);
9565 3 : TREE_TYPE (decl) = error_mark_node;
9566 3 : return;
9567 : }
9568 : }
9569 13975837 : d_init = init;
9570 13975837 : if (d_init)
9571 : {
9572 13975746 : if (TREE_CODE (d_init) == TREE_LIST
9573 14049549 : && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
9574 47437 : d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
9575 : tf_warning_or_error);
9576 13975746 : d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
9577 : /* Force auto deduction now. Use tf_none to avoid redundant warnings
9578 : on deprecated-14.C. */
9579 13975746 : mark_single_function (d_init, tf_none);
9580 : }
9581 13975837 : enum auto_deduction_context adc = adc_variable_type;
9582 13975837 : if (DECL_DECOMPOSITION_P (decl))
9583 : adc = adc_decomp_type;
9584 13975837 : tree outer_targs = NULL_TREE;
9585 13975837 : if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
9586 325 : && DECL_LANG_SPECIFIC (decl)
9587 126 : && DECL_TEMPLATE_INFO (decl)
9588 13975894 : && !DECL_FUNCTION_SCOPE_P (decl))
9589 : /* The outer template arguments might be needed for satisfaction.
9590 : (For function scope variables, do_auto_deduction will obtain the
9591 : outer template arguments from current_function_decl.) */
9592 57 : outer_targs = DECL_TI_ARGS (decl);
9593 13975837 : type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
9594 : tf_warning_or_error, adc,
9595 : outer_targs, flags);
9596 13975837 : if (type == error_mark_node)
9597 : return;
9598 13974707 : if (TREE_CODE (type) == FUNCTION_TYPE)
9599 : {
9600 3 : error ("initializer for %<decltype(auto) %D%> has function type; "
9601 : "did you forget the %<()%>?", decl);
9602 3 : TREE_TYPE (decl) = error_mark_node;
9603 3 : return;
9604 : }
9605 : /* As in start_decl_1, complete so TREE_READONLY is set properly. */
9606 13974704 : if (!processing_template_decl
9607 3206155 : && !type_uses_auto (type)
9608 17180852 : && !COMPLETE_TYPE_P (complete_type (type)))
9609 : {
9610 18 : auto_diagnostic_group d;
9611 18 : error_at (location_of (decl),
9612 : "deduced type %qT for %qD is incomplete", type, decl);
9613 18 : cxx_incomplete_type_inform (type);
9614 18 : TREE_TYPE (decl) = error_mark_node;
9615 18 : return;
9616 18 : }
9617 :
9618 : /* Now that we have a type, try these again. */
9619 13974686 : layout_decl (decl, 0);
9620 13974686 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
9621 :
9622 : /* Update the type of the corresponding TEMPLATE_DECL to match. */
9623 13974686 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
9624 : {
9625 40135 : tree tmpl = template_for_substitution (decl);
9626 40135 : if (DECL_TEMPLATE_RESULT (tmpl) == decl)
9627 33626 : TREE_TYPE (tmpl) = type;
9628 : }
9629 : }
9630 :
9631 333954972 : if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
9632 : {
9633 65 : DECL_DECLARED_CONSTEXPR_P (decl) = 0;
9634 65 : if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
9635 : {
9636 6 : init = NULL_TREE;
9637 6 : DECL_EXTERNAL (decl) = 1;
9638 : }
9639 : }
9640 :
9641 333954972 : if (VAR_P (decl)
9642 125881583 : && DECL_CLASS_SCOPE_P (decl)
9643 20462844 : && verify_type_context (DECL_SOURCE_LOCATION (decl),
9644 : TCTX_STATIC_STORAGE, type)
9645 354417816 : && DECL_INITIALIZED_IN_CLASS_P (decl))
9646 19096139 : check_static_variable_definition (decl, type);
9647 :
9648 333954972 : if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
9649 : {
9650 37688967 : type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
9651 37688967 : ? TCTX_THREAD_STORAGE
9652 : : TCTX_STATIC_STORAGE);
9653 37688967 : verify_type_context (input_location, context, TREE_TYPE (decl));
9654 : }
9655 :
9656 333954972 : if (init && TREE_CODE (decl) == FUNCTION_DECL)
9657 : {
9658 585004 : tree clone;
9659 585004 : if (init == ridpointers[(int)RID_DELETE]
9660 585004 : || (TREE_CODE (init) == STRING_CST
9661 36 : && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
9662 : {
9663 : /* FIXME check this is 1st decl. */
9664 562278 : if (UNLIKELY (DECL_MAIN_P (decl)))
9665 : {
9666 : /* [basic.start.main]/3: A program that defines main as deleted
9667 : is ill-formed. */
9668 6 : error ("%<::main%> cannot be deleted");
9669 6 : DECL_INITIAL (decl) = error_mark_node;
9670 : }
9671 : else
9672 : {
9673 562272 : DECL_DELETED_FN (decl) = 1;
9674 562272 : DECL_DECLARED_INLINE_P (decl) = 1;
9675 562272 : DECL_INITIAL (decl)
9676 562272 : = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
9677 562290 : FOR_EACH_CLONE (clone, decl)
9678 : {
9679 18 : DECL_DELETED_FN (clone) = 1;
9680 18 : DECL_DECLARED_INLINE_P (clone) = 1;
9681 18 : DECL_INITIAL (clone) = DECL_INITIAL (decl);
9682 : }
9683 : }
9684 562278 : init = NULL_TREE;
9685 : }
9686 22726 : else if (init == ridpointers[(int)RID_DEFAULT])
9687 : {
9688 22714 : if (defaultable_fn_check (decl))
9689 22690 : DECL_DEFAULTED_FN (decl) = 1;
9690 : else
9691 24 : DECL_INITIAL (decl) = NULL_TREE;
9692 : }
9693 : }
9694 :
9695 333954972 : if (init && VAR_P (decl))
9696 : {
9697 109398040 : DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
9698 : /* If DECL is a reference, then we want to know whether init is a
9699 : reference constant; init_const_expr_p as passed tells us whether
9700 : it's an rvalue constant. */
9701 109398040 : if (TYPE_REF_P (type))
9702 2355867 : init_const_expr_p = potential_constant_expression (init);
9703 109398040 : if (init_const_expr_p)
9704 : {
9705 : /* Set these flags now for templates. We'll update the flags in
9706 : store_init_value for instantiations. */
9707 96374506 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
9708 96374506 : if (decl_maybe_constant_var_p (decl)
9709 : /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
9710 96374506 : && !TYPE_REF_P (type))
9711 42479129 : TREE_CONSTANT (decl) = true;
9712 : }
9713 : /* This is handled mostly by gimplify.cc, but we have to deal with
9714 : not warning about int x = x; as it is a GCC extension to turn off
9715 : this warning but only if warn_init_self is zero. */
9716 109398040 : if (!DECL_EXTERNAL (decl)
9717 107749509 : && !TREE_STATIC (decl)
9718 72834210 : && decl == tree_strip_any_location_wrapper (init)
9719 109401824 : && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
9720 3760 : suppress_warning (decl, OPT_Winit_self);
9721 : }
9722 224556932 : else if (VAR_P (decl)
9723 16483543 : && COMPLETE_TYPE_P (type)
9724 12964782 : && !TYPE_REF_P (type)
9725 12964074 : && !dependent_type_p (type)
9726 237190099 : && is_really_empty_class (type, /*ignore_vptr*/false))
9727 : /* We have no initializer but there's nothing to initialize anyway.
9728 : Treat DECL as constant due to c++/109876. */
9729 595758 : TREE_CONSTANT (decl) = true;
9730 :
9731 333954972 : if (flag_openmp
9732 852246 : && TREE_CODE (decl) == FUNCTION_DECL
9733 : /* #pragma omp declare variant on methods handled in finish_struct
9734 : instead. */
9735 334324214 : && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
9736 140053 : || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
9737 229652 : if (tree attr = lookup_attribute ("omp declare variant base",
9738 229652 : DECL_ATTRIBUTES (decl)))
9739 970 : omp_declare_variant_finalize (decl, attr);
9740 :
9741 333954972 : if (processing_template_decl)
9742 : {
9743 191922621 : bool type_dependent_p;
9744 :
9745 : /* Add this declaration to the statement-tree. */
9746 191922621 : if (at_function_scope_p ())
9747 68964988 : add_decl_expr (decl);
9748 :
9749 191922621 : type_dependent_p = dependent_type_p (type);
9750 :
9751 191922621 : if (check_for_bare_parameter_packs (init))
9752 : {
9753 3 : init = NULL_TREE;
9754 3 : DECL_INITIAL (decl) = NULL_TREE;
9755 : }
9756 :
9757 : /* Generally, initializers in templates are expanded when the
9758 : template is instantiated. But, if DECL is a variable constant
9759 : then it can be used in future constant expressions, so its value
9760 : must be available. */
9761 :
9762 191922621 : bool dep_init = false;
9763 :
9764 191922621 : if (!VAR_P (decl) || type_dependent_p)
9765 : /* We can't do anything if the decl has dependent type. */;
9766 23809688 : else if (init
9767 22098382 : && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
9768 18038216 : && !TYPE_REF_P (type)
9769 18004490 : && decl_maybe_constant_var_p (decl)
9770 33188040 : && !(dep_init = value_dependent_init_p (init)))
9771 : {
9772 : /* This variable seems to be a non-dependent constant, so process
9773 : its initializer. If check_initializer returns non-null the
9774 : initialization wasn't constant after all. */
9775 2442310 : tree init_code;
9776 2442310 : cleanups = make_tree_vector ();
9777 2442310 : init_code = check_initializer (decl, init, flags, &cleanups);
9778 2442310 : if (init_code == NULL_TREE)
9779 2442310 : init = NULL_TREE;
9780 2442310 : release_tree_vector (cleanups);
9781 : }
9782 : else
9783 : {
9784 21367378 : gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
9785 : /* Try to deduce array size. */
9786 21367378 : maybe_deduce_size_from_array_init (decl, init);
9787 : /* And complain about multiple initializers. */
9788 19656072 : if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
9789 21473145 : && !MAYBE_CLASS_TYPE_P (type))
9790 7 : init = build_x_compound_expr_from_list (init, ELK_INIT,
9791 : tf_warning_or_error);
9792 : }
9793 :
9794 191922621 : if (init)
9795 57319442 : DECL_INITIAL (decl) = init;
9796 :
9797 191922621 : if (dep_init)
9798 : {
9799 6936042 : retrofit_lang_decl (decl);
9800 6936042 : SET_DECL_DEPENDENT_INIT_P (decl, true);
9801 : }
9802 :
9803 191922621 : if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
9804 : {
9805 9 : if (TREE_ADDRESSABLE (decl))
9806 3 : error_at (DECL_SOURCE_LOCATION (decl),
9807 : "address of explicit register variable %qD requested",
9808 : decl);
9809 : else
9810 : {
9811 6 : set_user_assembler_name (decl, asmspec);
9812 6 : DECL_HARD_REGISTER (decl) = 1;
9813 : }
9814 : }
9815 191922621 : return;
9816 : }
9817 :
9818 : /* Just store non-static data member initializers for later. */
9819 142032351 : if (init && TREE_CODE (decl) == FIELD_DECL)
9820 608697 : DECL_INITIAL (decl) = init;
9821 :
9822 : /* Take care of TYPE_DECLs up front. */
9823 142032351 : if (TREE_CODE (decl) == TYPE_DECL)
9824 : {
9825 11085259 : if (type != error_mark_node
9826 11085259 : && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
9827 : {
9828 5295459 : if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
9829 0 : warning (0, "shadowing previous type declaration of %q#D", decl);
9830 5295459 : set_identifier_type_value (DECL_NAME (decl), decl);
9831 : }
9832 :
9833 : /* If we have installed this as the canonical typedef for this
9834 : type, and that type has not been defined yet, delay emitting
9835 : the debug information for it, as we will emit it later. */
9836 11085259 : if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
9837 11085259 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
9838 606555 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
9839 :
9840 11085259 : rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
9841 : at_eof);
9842 11085259 : return;
9843 : }
9844 :
9845 : /* A reference will be modified here, as it is initialized. */
9846 130947092 : if (! DECL_EXTERNAL (decl)
9847 64151662 : && TREE_READONLY (decl)
9848 169342755 : && TYPE_REF_P (type))
9849 : {
9850 250056 : was_readonly = 1;
9851 250056 : TREE_READONLY (decl) = 0;
9852 : }
9853 :
9854 : /* This needs to happen before extend_ref_init_temps. */
9855 130947092 : if (VAR_OR_FUNCTION_DECL_P (decl))
9856 : {
9857 121460532 : if (VAR_P (decl))
9858 62634807 : maybe_commonize_var (decl);
9859 121460532 : determine_visibility (decl);
9860 : }
9861 :
9862 130947092 : if (VAR_P (decl))
9863 : {
9864 62634807 : duration_kind dk = decl_storage_duration (decl);
9865 : /* [dcl.constinit]/1 "The constinit specifier shall be applied
9866 : only to a declaration of a variable with static or thread storage
9867 : duration." */
9868 62634807 : if (DECL_DECLARED_CONSTINIT_P (decl)
9869 62634807 : && !(dk == dk_thread || dk == dk_static))
9870 : {
9871 24 : error_at (DECL_SOURCE_LOCATION (decl),
9872 : "%<constinit%> can only be applied to a variable with "
9873 : "static or thread storage duration");
9874 24 : return;
9875 : }
9876 :
9877 62634783 : if (decomp)
9878 : {
9879 67920 : if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
9880 40 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
9881 : "%<constinit%> can be applied to structured binding "
9882 : "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
9883 67920 : cp_maybe_mangle_decomp (decl, decomp);
9884 67920 : if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
9885 : {
9886 622 : if (CP_DECL_THREAD_LOCAL_P (decl))
9887 37 : aggregates1 = tls_aggregates;
9888 : else
9889 585 : aggregates1 = static_aggregates;
9890 : }
9891 : }
9892 :
9893 : /* Detect stuff like 'info r = ^^int;' outside a manifestly
9894 : constant-evaluated context. */
9895 62634783 : check_out_of_consteval_use (decl);
9896 :
9897 : /* If this is a local variable that will need a mangled name,
9898 : register it now. We must do this before processing the
9899 : initializer for the variable, since the initialization might
9900 : require a guard variable, and since the mangled name of the
9901 : guard variable will depend on the mangled name of this
9902 : variable. */
9903 62634783 : if (DECL_FUNCTION_SCOPE_P (decl) && TREE_STATIC (decl))
9904 : {
9905 : /* The variable holding an anonymous union will have had its
9906 : discriminator set in finish_anon_union, after which it's
9907 : NAME will have been cleared. */
9908 140969 : if (DECL_NAME (decl))
9909 140652 : determine_local_discriminator (decl);
9910 : /* Normally has_forced_label_in_static is set during GIMPLE
9911 : lowering, but [cd]tors are never actually compiled directly.
9912 : We need to set this early so we can deal with the label
9913 : address extension. */
9914 140969 : if ((DECL_CONSTRUCTOR_P (current_function_decl)
9915 140928 : || DECL_DESTRUCTOR_P (current_function_decl))
9916 140985 : && init)
9917 : {
9918 29 : walk_tree (&init, notice_forced_label_r, NULL, NULL);
9919 29 : add_local_decl (cfun, decl);
9920 : }
9921 140969 : if (!consteval_only_p (decl))
9922 : /* And make sure it's in the symbol table for
9923 : c_parse_final_cleanups to find. */
9924 140737 : varpool_node::get_create (decl);
9925 : }
9926 :
9927 62634783 : if (flag_openmp
9928 194231 : && VAR_P (decl)
9929 194231 : && DECL_LANG_SPECIFIC (decl)
9930 115615 : && DECL_OMP_DECLARE_MAPPER_P (decl)
9931 62634796 : && init)
9932 : {
9933 12 : gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
9934 12 : DECL_INITIAL (decl) = init;
9935 : }
9936 : /* Convert the initializer to the type of DECL, if we have not
9937 : already initialized DECL. */
9938 62634771 : else if (!DECL_INITIALIZED_P (decl)
9939 : /* If !DECL_EXTERNAL then DECL is being defined. In the
9940 : case of a static data member initialized inside the
9941 : class-specifier, there can be an initializer even if DECL
9942 : is *not* defined. */
9943 62634771 : && (!DECL_EXTERNAL (decl) || init))
9944 : {
9945 55690973 : cleanups = make_tree_vector ();
9946 55690973 : init = check_initializer (decl, init, flags, &cleanups);
9947 :
9948 : /* Handle:
9949 :
9950 : [dcl.init]
9951 :
9952 : The memory occupied by any object of static storage
9953 : duration is zero-initialized at program startup before
9954 : any other initialization takes place.
9955 :
9956 : We cannot create an appropriate initializer until after
9957 : the type of DECL is finalized. If DECL_INITIAL is set,
9958 : then the DECL is statically initialized, and any
9959 : necessary zero-initialization has already been performed. */
9960 55688276 : if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
9961 520965 : DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
9962 : /*nelts=*/NULL_TREE,
9963 : /*static_storage_p=*/true);
9964 : /* Remember that the initialization for this variable has
9965 : taken place. */
9966 55688276 : DECL_INITIALIZED_P (decl) = 1;
9967 : /* This declaration is the definition of this variable,
9968 : unless we are initializing a static data member within
9969 : the class specifier. */
9970 55688276 : if (!DECL_EXTERNAL (decl))
9971 62632086 : var_definition_p = true;
9972 : }
9973 : /* If the variable has an array type, lay out the type, even if
9974 : there is no initializer. It is valid to index through the
9975 : array, and we must get TYPE_ALIGN set correctly on the array
9976 : type. */
9977 6943798 : else if (TREE_CODE (type) == ARRAY_TYPE)
9978 216981 : layout_type (type);
9979 :
9980 62632086 : if (TREE_STATIC (decl)
9981 37126788 : && !at_function_scope_p ()
9982 99617905 : && current_function_decl == NULL)
9983 : /* So decl is a global variable or a static member of a
9984 : non local class. Record the types it uses
9985 : so that we can decide later to emit debug info for them. */
9986 36985807 : record_types_used_by_current_var_decl (decl);
9987 : }
9988 :
9989 : /* Add this declaration to the statement-tree. This needs to happen
9990 : after the call to check_initializer so that the DECL_EXPR for a
9991 : reference temp is added before the DECL_EXPR for the reference itself. */
9992 130944371 : if (DECL_FUNCTION_SCOPE_P (decl))
9993 : {
9994 : /* If we're building a variable sized type, and we might be
9995 : reachable other than via the top of the current binding
9996 : level, then create a new BIND_EXPR so that we deallocate
9997 : the object at the right time. */
9998 25086657 : if (VAR_P (decl)
9999 25086657 : && DECL_SIZE (decl)
10000 25024984 : && !TREE_CONSTANT (DECL_SIZE (decl))
10001 25087685 : && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
10002 : {
10003 3 : tree bind;
10004 3 : bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
10005 3 : TREE_SIDE_EFFECTS (bind) = 1;
10006 3 : add_stmt (bind);
10007 3 : BIND_EXPR_BODY (bind) = push_stmt_list ();
10008 : }
10009 25086657 : add_decl_expr (decl);
10010 : }
10011 :
10012 130944371 : tree decomp_init = NULL_TREE;
10013 : /* Let the middle end know about variables and functions -- but not
10014 : static data members in uninstantiated class templates. */
10015 130944371 : if (VAR_OR_FUNCTION_DECL_P (decl))
10016 : {
10017 121457811 : if (VAR_P (decl))
10018 : {
10019 62632086 : layout_var_decl (decl);
10020 62632086 : if (!flag_weak)
10021 : /* Check again now that we have an initializer. */
10022 57 : maybe_commonize_var (decl);
10023 : /* A class-scope constexpr variable with an out-of-class declaration.
10024 : C++17 makes them implicitly inline, but still force it out. */
10025 84552129 : if (DECL_INLINE_VAR_P (decl)
10026 29413996 : && !DECL_VAR_DECLARED_INLINE_P (decl)
10027 13299283 : && !DECL_TEMPLATE_INSTANTIATION (decl)
10028 47242281 : && !in_class_decl)
10029 108 : mark_needed (decl);
10030 : }
10031 :
10032 121457811 : if (var_definition_p
10033 : /* With -fmerge-all-constants, gimplify_init_constructor
10034 : might add TREE_STATIC to aggregate variables. */
10035 54500232 : && (TREE_STATIC (decl)
10036 24945816 : || (flag_merge_constants >= 2
10037 38 : && AGGREGATE_TYPE_P (type))))
10038 : {
10039 : /* If a TREE_READONLY variable needs initialization
10040 : at runtime, it is no longer readonly and we need to
10041 : avoid MEM_READONLY_P being set on RTL created for it. */
10042 29554419 : if (init)
10043 : {
10044 14189 : if (TREE_READONLY (decl))
10045 348 : TREE_READONLY (decl) = 0;
10046 : was_readonly = 0;
10047 : }
10048 29540230 : else if (was_readonly)
10049 2482 : TREE_READONLY (decl) = 1;
10050 :
10051 : /* Likewise if it needs destruction. */
10052 29554419 : if (!decl_maybe_constant_destruction (decl, type))
10053 3486 : TREE_READONLY (decl) = 0;
10054 : }
10055 91903392 : else if (VAR_P (decl)
10056 33077667 : && CP_DECL_THREAD_LOCAL_P (decl)
10057 19189 : && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
10058 19189 : && (was_readonly || TREE_READONLY (decl))
10059 91903407 : && var_needs_tls_wrapper (decl))
10060 : {
10061 : /* TLS variables need dynamic initialization by the TLS wrapper
10062 : function, we don't want to hoist accesses to it before the
10063 : wrapper. */
10064 6 : was_readonly = 0;
10065 6 : TREE_READONLY (decl) = 0;
10066 : }
10067 :
10068 121457811 : make_rtl_for_nonlocal_decl (decl, init, asmspec);
10069 :
10070 : /* Check for abstractness of the type. */
10071 121457811 : if (var_definition_p)
10072 54500232 : abstract_virtuals_error (decl, type);
10073 :
10074 121457811 : if (decomp && !cp_finish_decomp (decl, decomp, true))
10075 32485 : decomp = NULL;
10076 :
10077 121457811 : if (TREE_TYPE (decl) == error_mark_node)
10078 : /* No initialization required. */
10079 : ;
10080 121457718 : else if (TREE_CODE (decl) == FUNCTION_DECL)
10081 : {
10082 58825725 : if (init)
10083 : {
10084 600 : if (init == ridpointers[(int)RID_DEFAULT])
10085 : {
10086 : /* An out-of-class default definition is defined at
10087 : the point where it is explicitly defaulted. */
10088 588 : if (DECL_DELETED_FN (decl))
10089 17 : maybe_explain_implicit_delete (decl);
10090 571 : else if (DECL_INITIAL (decl) == error_mark_node)
10091 547 : synthesize_method (decl);
10092 : }
10093 : else
10094 24 : error_at (cp_expr_loc_or_loc (init,
10095 12 : DECL_SOURCE_LOCATION (decl)),
10096 : "function %q#D is initialized like a variable",
10097 : decl);
10098 : }
10099 : /* else no initialization required. */
10100 : }
10101 62631993 : else if (DECL_EXTERNAL (decl)
10102 62631993 : && ! (DECL_LANG_SPECIFIC (decl)
10103 7828408 : && DECL_NOT_REALLY_EXTERN (decl)))
10104 : {
10105 : /* check_initializer will have done any constant initialization. */
10106 : }
10107 : /* A variable definition. */
10108 56426417 : else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
10109 : {
10110 : /* Initialize the local variable. */
10111 24945661 : if (!decomp)
10112 24910478 : initialize_local_var (decl, init, false);
10113 : else
10114 : {
10115 35183 : tree cleanup = NULL_TREE;
10116 35183 : if (DECL_SIZE (decl))
10117 35183 : cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
10118 : /* If cp_finish_decomp needs to emit any code, we need to emit that
10119 : code after code emitted by initialize_local_var in a single
10120 : CLEANUP_POINT_EXPR, so that temporaries are destructed only
10121 : after the cp_finish_decomp emitted code.
10122 : If there are any cleanups, either extend_ref_init_temps
10123 : created ones or e.g. array destruction, push those first
10124 : with the cleanups guarded on a bool temporary, initially
10125 : set to false and set to true after initialize_local_var
10126 : emitted code. */
10127 35183 : tree guard = NULL_TREE;
10128 35183 : if (cleanups || cleanup)
10129 : {
10130 : /* Since the CLEANUP_STMT will refer to the guard, we need it
10131 : to be a variable with the same lifetime. ??? It might be
10132 : better to use wrap_temporary_cleanups. */
10133 35183 : guard = get_temp_regvar (boolean_type_node, boolean_false_node);
10134 : /* And make sure register_local_var_uses sees it. */
10135 35183 : pushdecl (guard);
10136 : }
10137 :
10138 35183 : tree sl = push_stmt_list ();
10139 35183 : initialize_local_var (decl, init, true);
10140 35183 : if (guard)
10141 : {
10142 35183 : add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
10143 : guard, boolean_true_node));
10144 35201 : for (tree &t : *cleanups)
10145 18 : t = build3 (COND_EXPR, void_type_node,
10146 : guard, t, void_node);
10147 35183 : if (cleanup)
10148 32 : cleanup = build3 (COND_EXPR, void_type_node,
10149 : guard, cleanup, void_node);
10150 : }
10151 35183 : unsigned before = stmt_list_stack->length ();
10152 35183 : cp_finish_decomp (decl, decomp);
10153 35183 : decomp = NULL;
10154 35183 : unsigned n_extra_cleanups = stmt_list_stack->length () - before;
10155 35183 : sl = pop_stmt_list (sl);
10156 35183 : if (n_extra_cleanups)
10157 : {
10158 : /* If cp_finish_decomp needs any cleanups, such as for
10159 : extend_ref_init_temps created vars, pop_stmt_list
10160 : popped that all, so push those extra cleanups around
10161 : the whole sequence with a guard variable. */
10162 15 : gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
10163 15 : guard = get_temp_regvar (integer_type_node, integer_zero_node);
10164 15 : pushdecl (guard);
10165 63 : for (unsigned i = 0; i < n_extra_cleanups; ++i)
10166 : {
10167 48 : tree_stmt_iterator tsi = tsi_last (sl);
10168 48 : gcc_assert (!tsi_end_p (tsi));
10169 48 : tree last = tsi_stmt (tsi);
10170 48 : gcc_assert (TREE_CODE (last) == CLEANUP_STMT
10171 : && !CLEANUP_EH_ONLY (last));
10172 48 : tree cst = build_int_cst (integer_type_node, i + 1);
10173 96 : tree cl = build3 (COND_EXPR, void_type_node,
10174 : build2 (GE_EXPR, boolean_type_node,
10175 : guard, cst),
10176 48 : CLEANUP_EXPR (last), void_node);
10177 48 : extra_cleanups.safe_push (cl);
10178 48 : tsi_link_before (&tsi, build2 (MODIFY_EXPR,
10179 : integer_type_node,
10180 : guard, cst),
10181 : TSI_SAME_STMT);
10182 48 : tree sl2 = CLEANUP_BODY (last);
10183 48 : gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
10184 48 : tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
10185 48 : tsi_delink (&tsi);
10186 : }
10187 : }
10188 35183 : decomp_init = maybe_cleanup_point_expr_void (sl);
10189 35183 : if (cleanup)
10190 32 : finish_decl_cleanup (decl, cleanup);
10191 : }
10192 : }
10193 :
10194 : /* If a variable is defined, and then a subsequent
10195 : definition with external linkage is encountered, we will
10196 : get here twice for the same variable. We want to avoid
10197 : calling expand_static_init more than once. For variables
10198 : that are not static data members, we can call
10199 : expand_static_init only when we actually process the
10200 : initializer. It is not legal to redeclare a static data
10201 : member, so this issue does not arise in that case. */
10202 31480756 : else if (var_definition_p && TREE_STATIC (decl))
10203 : {
10204 29552658 : if (decomp && DECL_FUNCTION_SCOPE_P (decl))
10205 : {
10206 106 : tree sl = push_stmt_list ();
10207 106 : auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
10208 106 : current_stmt_tree ()->stmts_are_full_exprs_p = 0;
10209 106 : expand_static_init (decl, init);
10210 106 : current_stmt_tree ()->stmts_are_full_exprs_p
10211 106 : = saved_stmts_are_full_exprs_p;
10212 106 : cp_finish_decomp (decl, decomp);
10213 106 : decomp = NULL;
10214 106 : sl = pop_stmt_list (sl);
10215 106 : sl = maybe_cleanup_point_expr_void (sl);
10216 106 : add_stmt (sl);
10217 : }
10218 : else
10219 29552552 : expand_static_init (decl, init);
10220 : }
10221 : }
10222 :
10223 : /* If a CLEANUP_STMT was created to destroy a temporary bound to a
10224 : reference, insert it in the statement-tree now. */
10225 130944371 : if (cleanups)
10226 : {
10227 55691679 : for (tree t : *cleanups)
10228 : {
10229 3403 : push_cleanup (NULL_TREE, t, false);
10230 : /* As in initialize_local_var. */
10231 3403 : wrap_temporary_cleanups (init, t);
10232 : }
10233 55688276 : release_tree_vector (cleanups);
10234 : }
10235 :
10236 130944449 : for (tree t : &extra_cleanups)
10237 48 : push_cleanup (NULL_TREE, t, false);
10238 :
10239 130944371 : if (decomp_init)
10240 35183 : add_stmt (decomp_init);
10241 :
10242 130944371 : if (decomp
10243 146 : && var_definition_p
10244 146 : && TREE_STATIC (decl)
10245 130944517 : && !DECL_FUNCTION_SCOPE_P (decl))
10246 : {
10247 146 : tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
10248 146 : ? tls_aggregates : static_aggregates);
10249 146 : tree aggregates2 = aggregates3;
10250 146 : if (aggregates2 != aggregates1)
10251 : {
10252 66 : cp_finish_decomp (decl, decomp);
10253 66 : decomp = NULL;
10254 66 : if (aggregates3 != aggregates2)
10255 : {
10256 : /* If there are dynamic initializers for the structured
10257 : binding base or associated extended ref temps and also
10258 : dynamic initializers for the structured binding non-base
10259 : vars, mark them. */
10260 267 : for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
10261 204 : STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
10262 150 : for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
10263 87 : STATIC_INIT_DECOMP_BASE_P (t) = 1;
10264 : }
10265 : }
10266 : }
10267 :
10268 130944371 : if (was_readonly)
10269 249486 : TREE_READONLY (decl) = 1;
10270 :
10271 130944371 : if (flag_openmp
10272 442724 : && VAR_P (decl)
10273 131138602 : && lookup_attribute ("omp declare target implicit",
10274 194231 : DECL_ATTRIBUTES (decl)))
10275 : {
10276 52 : DECL_ATTRIBUTES (decl)
10277 52 : = remove_attribute ("omp declare target implicit",
10278 52 : DECL_ATTRIBUTES (decl));
10279 52 : complete_type (TREE_TYPE (decl));
10280 52 : if (!omp_mappable_type (TREE_TYPE (decl)))
10281 : {
10282 30 : auto_diagnostic_group d;
10283 30 : error ("%q+D in declare target directive does not have mappable"
10284 : " type", decl);
10285 30 : if (TREE_TYPE (decl) != error_mark_node
10286 30 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
10287 30 : cxx_incomplete_type_inform (TREE_TYPE (decl));
10288 30 : }
10289 22 : else if (!lookup_attribute ("omp declare target",
10290 22 : DECL_ATTRIBUTES (decl))
10291 44 : && !lookup_attribute ("omp declare target link",
10292 22 : DECL_ATTRIBUTES (decl)))
10293 : {
10294 22 : DECL_ATTRIBUTES (decl)
10295 22 : = tree_cons (get_identifier ("omp declare target"),
10296 22 : NULL_TREE, DECL_ATTRIBUTES (decl));
10297 22 : symtab_node *node = symtab_node::get (decl);
10298 22 : if (node != NULL)
10299 : {
10300 19 : node->offloadable = 1;
10301 19 : if (ENABLE_OFFLOADING)
10302 : {
10303 : g->have_offload = true;
10304 : if (is_a <varpool_node *> (node))
10305 : vec_safe_push (offload_vars, decl);
10306 : }
10307 : }
10308 : }
10309 : }
10310 :
10311 : /* This is the last point we can lower alignment so give the target the
10312 : chance to do so. */
10313 130944371 : if (VAR_P (decl)
10314 62632086 : && !is_global_var (decl)
10315 155890187 : && !DECL_HARD_REGISTER (decl))
10316 24945763 : targetm.lower_local_decl_alignment (decl);
10317 :
10318 130944371 : invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
10319 333958664 : }
10320 :
10321 : /* For class TYPE return itself or some its bases that contain
10322 : any direct non-static data members. Return error_mark_node if an
10323 : error has been diagnosed. */
10324 :
10325 : static tree
10326 30953 : find_decomp_class_base (location_t loc, tree type, tree ret,
10327 : tsubst_flags_t complain)
10328 : {
10329 61906 : if (LAMBDA_TYPE_P (type))
10330 : {
10331 12 : if (complain & tf_error)
10332 : {
10333 12 : auto_diagnostic_group d;
10334 12 : error_at (loc, "cannot decompose lambda closure type %qT", type);
10335 12 : inform (location_of (type), "lambda declared here");
10336 12 : }
10337 12 : return error_mark_node;
10338 : }
10339 :
10340 30941 : bool member_seen = false;
10341 392232 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
10342 660078 : if (TREE_CODE (field) != FIELD_DECL
10343 62718 : || DECL_ARTIFICIAL (field)
10344 423948 : || DECL_UNNAMED_BIT_FIELD (field))
10345 298748 : continue;
10346 62582 : else if (ret)
10347 : return type;
10348 62556 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
10349 : {
10350 8 : if ((complain & tf_error) == 0)
10351 0 : return error_mark_node;
10352 8 : auto_diagnostic_group d;
10353 8 : if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
10354 4 : error_at (loc, "cannot decompose class type %qT because it has an "
10355 : "anonymous struct member", type);
10356 : else
10357 4 : error_at (loc, "cannot decompose class type %qT because it has an "
10358 : "anonymous union member", type);
10359 8 : inform (DECL_SOURCE_LOCATION (field), "declared here");
10360 8 : return error_mark_node;
10361 8 : }
10362 62548 : else if (!accessible_p (type, field, true))
10363 : {
10364 5 : if ((complain & tf_error) == 0)
10365 0 : return error_mark_node;
10366 5 : auto_diagnostic_group d;
10367 5 : error_at (loc, "cannot decompose inaccessible member %qD of %qT",
10368 : field, type);
10369 5 : inform (DECL_SOURCE_LOCATION (field),
10370 5 : TREE_PRIVATE (field)
10371 : ? G_("declared private here")
10372 : : G_("declared protected here"));
10373 5 : return error_mark_node;
10374 5 : }
10375 : else
10376 : member_seen = true;
10377 :
10378 30902 : tree base_binfo, binfo;
10379 30902 : tree orig_ret = ret;
10380 30902 : int i;
10381 30902 : if (member_seen)
10382 30799 : ret = type;
10383 30966 : for (binfo = TYPE_BINFO (type), i = 0;
10384 30966 : BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
10385 : {
10386 84 : auto_diagnostic_group d;
10387 84 : tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret,
10388 : complain);
10389 84 : if (t == error_mark_node)
10390 : {
10391 3 : if (complain & tf_error)
10392 3 : inform (location_of (type), "in base class of %qT", type);
10393 3 : return error_mark_node;
10394 : }
10395 81 : if (t != NULL_TREE && t != ret)
10396 : {
10397 54 : if (ret == type)
10398 : {
10399 10 : if (complain & tf_error)
10400 10 : error_at (loc, "cannot decompose class type %qT: both it and "
10401 : "its base class %qT have non-static data "
10402 : "members", type, t);
10403 10 : return error_mark_node;
10404 : }
10405 44 : else if (orig_ret != NULL_TREE)
10406 : return t;
10407 44 : else if (ret != NULL_TREE)
10408 : {
10409 7 : if (complain & tf_error)
10410 7 : error_at (loc, "cannot decompose class type %qT: its base "
10411 : "classes %qT and %qT have non-static data "
10412 : "members", type, ret, t);
10413 7 : return error_mark_node;
10414 : }
10415 : else
10416 : ret = t;
10417 : }
10418 84 : }
10419 : return ret;
10420 : }
10421 :
10422 : /* Return std::tuple_size<TYPE>::value. */
10423 :
10424 : static tree
10425 111657 : get_tuple_size (tree type)
10426 : {
10427 111657 : tree args = make_tree_vec (1);
10428 111657 : TREE_VEC_ELT (args, 0) = type;
10429 111657 : tree inst = lookup_template_class (tuple_size_identifier, args,
10430 : /*in_decl*/NULL_TREE,
10431 : /*context*/std_node,
10432 : tf_none);
10433 111657 : inst = complete_type (inst);
10434 111657 : if (inst == error_mark_node
10435 110167 : || !COMPLETE_TYPE_P (inst)
10436 192400 : || !CLASS_TYPE_P (inst))
10437 : return NULL_TREE;
10438 80743 : tree val = lookup_qualified_name (inst, value_identifier,
10439 : LOOK_want::NORMAL, /*complain*/false);
10440 80743 : if (val == error_mark_node)
10441 : return NULL_TREE;
10442 80737 : if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
10443 80737 : val = maybe_constant_value (val, NULL_TREE, mce_true);
10444 80737 : if (TREE_CODE (val) == INTEGER_CST)
10445 : return val;
10446 : else
10447 6 : return error_mark_node;
10448 : }
10449 :
10450 : /* Return std::tuple_element<I,TYPE>::type. */
10451 :
10452 : static tree
10453 91178 : get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i)
10454 : {
10455 91178 : tree args = make_tree_vec (2);
10456 91178 : TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
10457 91178 : TREE_VEC_ELT (args, 1) = type;
10458 91178 : tree inst = lookup_template_class (tuple_element_identifier, args,
10459 : /*in_decl*/NULL_TREE,
10460 : /*context*/std_node,
10461 : tf_warning_or_error);
10462 91178 : return make_typename_type (inst, type_identifier,
10463 91178 : none_type, tf_warning_or_error);
10464 : }
10465 :
10466 : /* Return e.get<i>() or get<i>(e). */
10467 :
10468 : static tree
10469 91187 : get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i)
10470 : {
10471 91187 : tree targs = make_tree_vec (1);
10472 91187 : TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
10473 :
10474 91187 : tree etype = TREE_TYPE (decl);
10475 91187 : tree e = convert_from_reference (decl);
10476 :
10477 : /* [The id-expression] e is an lvalue if the type of the entity e is an
10478 : lvalue reference and an xvalue otherwise. */
10479 91187 : if (!TYPE_REF_P (etype)
10480 91187 : || TYPE_REF_IS_RVALUE (etype))
10481 89815 : e = move (e);
10482 :
10483 91187 : tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
10484 : LOOK_want::NORMAL, /*complain*/false);
10485 91187 : bool use_member_get = false;
10486 :
10487 : /* To use a member get, member lookup must find at least one
10488 : declaration that is a function template
10489 : whose first template parameter is a non-type parameter. */
10490 271081 : for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
10491 : {
10492 91187 : tree fn = *iter;
10493 91187 : if (TREE_CODE (fn) == TEMPLATE_DECL)
10494 : {
10495 2483 : tree tparms = DECL_TEMPLATE_PARMS (fn);
10496 2483 : tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
10497 2483 : if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
10498 : {
10499 : use_member_get = true;
10500 : break;
10501 : }
10502 : }
10503 : }
10504 :
10505 91187 : if (use_member_get)
10506 : {
10507 2480 : fns = lookup_template_function (fns, targs);
10508 2480 : return build_new_method_call (e, fns, /*args*/NULL,
10509 : /*path*/NULL_TREE, LOOKUP_NORMAL,
10510 2480 : /*fn_p*/NULL, tf_warning_or_error);
10511 : }
10512 : else
10513 : {
10514 88707 : releasing_vec args (make_tree_vector_single (e));
10515 88707 : fns = lookup_template_function (get__identifier, targs);
10516 88707 : fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
10517 88707 : return finish_call_expr (fns, &args, /*novirt*/false,
10518 : /*koenig*/true, tf_warning_or_error);
10519 88707 : }
10520 : }
10521 :
10522 : /* It's impossible to recover the decltype of a tuple decomposition variable
10523 : based on the actual type of the variable, so store it in a hash table. */
10524 :
10525 : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
10526 :
10527 : tree
10528 662 : lookup_decomp_type (tree v)
10529 : {
10530 662 : if (decomp_type_table)
10531 535 : if (tree *slot = decomp_type_table->get (v))
10532 471 : return *slot;
10533 : return NULL_TREE;
10534 : }
10535 :
10536 : /* Mangle a decomposition declaration if needed. Arguments like
10537 : in cp_finish_decomp. */
10538 :
10539 : static void
10540 67920 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
10541 : {
10542 67920 : if (!processing_template_decl
10543 67920 : && !error_operand_p (decl)
10544 135840 : && TREE_STATIC (decl))
10545 : {
10546 889 : auto_vec<tree, 16> v;
10547 889 : v.safe_grow (decomp->count, true);
10548 889 : tree d = decomp->decl;
10549 2944 : for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
10550 2055 : v[decomp->count - i - 1] = d;
10551 889 : if (DECL_FUNCTION_SCOPE_P (decl))
10552 : {
10553 : size_t sz = 3;
10554 929 : for (unsigned int i = 0; i < decomp->count; ++i)
10555 662 : sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
10556 267 : char *name = XALLOCAVEC (char, sz);
10557 267 : name[0] = 'D';
10558 267 : name[1] = 'C';
10559 267 : char *p = name + 2;
10560 929 : for (unsigned int i = 0; i < decomp->count; ++i)
10561 : {
10562 662 : size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
10563 662 : *p++ = ' ';
10564 662 : memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
10565 662 : p += len;
10566 : }
10567 267 : *p = '\0';
10568 267 : determine_local_discriminator (decl, get_identifier (name));
10569 : }
10570 889 : SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
10571 889 : maybe_apply_pragma_weak (decl);
10572 889 : }
10573 67920 : }
10574 :
10575 : /* Append #i to DECL_NAME (decl) or for name independent decls
10576 : clear DECL_NAME (decl). */
10577 :
10578 : static void
10579 33807 : set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i)
10580 : {
10581 33807 : if (name_independent_decl_p (decl))
10582 : /* Only "_" names are treated as name independent, "_#0" etc. is not and
10583 : because we pushdecl the individual decl elements of structured binding
10584 : pack, we could get redeclaration errors if there are 2 or more name
10585 : independent structured binding packs in the same scope. */
10586 312 : DECL_NAME (decl) = NULL_TREE;
10587 : else
10588 : {
10589 33495 : tree name = DECL_NAME (decl);
10590 33495 : size_t len = IDENTIFIER_LENGTH (name) + 22;
10591 33495 : char *n = XALLOCAVEC (char, len);
10592 33495 : snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED,
10593 33495 : IDENTIFIER_POINTER (name), i);
10594 33495 : DECL_NAME (decl) = get_identifier (n);
10595 : }
10596 33807 : }
10597 :
10598 : /* Return structured binding size of TYPE or -1 if erroneous. */
10599 :
10600 : HOST_WIDE_INT
10601 954 : cp_decomp_size (location_t loc, tree type, tsubst_flags_t complain)
10602 : {
10603 954 : if (TYPE_REF_P (type))
10604 : {
10605 0 : type = complete_type (TREE_TYPE (type));
10606 0 : if (type == error_mark_node)
10607 : return -1;
10608 0 : if (!COMPLETE_TYPE_P (type))
10609 : {
10610 0 : if (complain & tf_error)
10611 0 : error_at (loc, "structured binding refers to incomplete type %qT",
10612 : type);
10613 0 : return -1;
10614 : }
10615 : }
10616 :
10617 954 : unsigned HOST_WIDE_INT eltscnt = 0;
10618 954 : if (TREE_CODE (type) == ARRAY_TYPE)
10619 : {
10620 724 : if (TYPE_DOMAIN (type) == NULL_TREE)
10621 : {
10622 9 : if (complain & tf_error)
10623 6 : error_at (loc, "cannot decompose array of unknown bound %qT",
10624 : type);
10625 9 : return -1;
10626 : }
10627 715 : tree nelts = array_type_nelts_top (type);
10628 715 : if (nelts == error_mark_node)
10629 : return -1;
10630 715 : if (!tree_fits_shwi_p (nelts))
10631 : {
10632 3 : if (complain & tf_error)
10633 3 : error_at (loc, "cannot decompose variable length array %qT", type);
10634 3 : return -1;
10635 : }
10636 712 : return tree_to_shwi (nelts);
10637 : }
10638 : /* 2 GNU extensions. */
10639 230 : else if (TREE_CODE (type) == COMPLEX_TYPE)
10640 : return 2;
10641 224 : else if (TREE_CODE (type) == VECTOR_TYPE)
10642 : {
10643 12 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
10644 : {
10645 : if (complain & tf_error)
10646 : error_at (loc, "cannot decompose variable length vector %qT", type);
10647 : return -1;
10648 : }
10649 12 : return eltscnt;
10650 : }
10651 212 : else if (tree tsize = get_tuple_size (type))
10652 : {
10653 38 : if (tsize == error_mark_node
10654 32 : || !tree_fits_shwi_p (tsize)
10655 70 : || tree_int_cst_sgn (tsize) < 0)
10656 : {
10657 9 : if (complain & tf_error)
10658 9 : error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
10659 : "constant expression", type);
10660 9 : return -1;
10661 : }
10662 29 : return tree_to_shwi (tsize);
10663 : }
10664 174 : else if (TREE_CODE (type) == UNION_TYPE)
10665 : {
10666 3 : if (complain & tf_error)
10667 3 : error_at (loc, "cannot decompose union type %qT", type);
10668 3 : return -1;
10669 : }
10670 171 : else if (!CLASS_TYPE_P (type))
10671 : {
10672 21 : if (complain & tf_error)
10673 18 : error_at (loc, "cannot decompose non-array non-class type %qT", type);
10674 21 : return -1;
10675 : }
10676 150 : else if (processing_template_decl && complete_type (type) == error_mark_node)
10677 : return -1;
10678 150 : else if (!COMPLETE_TYPE_P (type))
10679 : {
10680 3 : if (complain & tf_error)
10681 3 : error_at (loc, "structured binding refers to incomplete class type "
10682 : "%qT", type);
10683 3 : return -1;
10684 : }
10685 : else
10686 : {
10687 147 : tree btype = find_decomp_class_base (loc, type, NULL_TREE, complain);
10688 147 : if (btype == error_mark_node)
10689 : return -1;
10690 126 : else if (btype == NULL_TREE)
10691 : return 0;
10692 105 : if (btype != type)
10693 : {
10694 6 : tree binfo = lookup_base (type, btype, ba_check, NULL, complain);
10695 6 : if (binfo == NULL_TREE || binfo == error_mark_node)
10696 : return -1;
10697 : }
10698 1123 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
10699 1703 : if (TREE_CODE (field) != FIELD_DECL
10700 357 : || DECL_ARTIFICIAL (field)
10701 1381 : || DECL_UNNAMED_BIT_FIELD (field))
10702 679 : continue;
10703 : else
10704 345 : eltscnt++;
10705 99 : return eltscnt;
10706 : }
10707 : }
10708 :
10709 : /* Finish a decomposition declaration. DECL is the underlying declaration
10710 : "e", FIRST is the head of a chain of decls for the individual identifiers
10711 : chained through DECL_CHAIN in reverse order and COUNT is the number of
10712 : those decls. If TEST_P is true, return true if any code would need to be
10713 : actually emitted but don't emit it. Return false otherwise. */
10714 :
10715 : bool
10716 339847 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
10717 : {
10718 339847 : tree first = decomp->decl;
10719 339847 : unsigned count = decomp->count;
10720 339847 : if (error_operand_p (decl))
10721 : {
10722 63 : error_out:
10723 625 : while (count--)
10724 : {
10725 425 : TREE_TYPE (first) = error_mark_node;
10726 425 : if (DECL_HAS_VALUE_EXPR_P (first))
10727 : {
10728 9 : SET_DECL_VALUE_EXPR (first, NULL_TREE);
10729 9 : DECL_HAS_VALUE_EXPR_P (first) = 0;
10730 : }
10731 425 : first = DECL_CHAIN (first);
10732 : }
10733 200 : if (DECL_P (decl) && TREE_STATIC (decl))
10734 54 : SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
10735 200 : return false;
10736 : }
10737 :
10738 339784 : location_t loc = DECL_SOURCE_LOCATION (decl);
10739 339784 : if (type_dependent_expression_p (decl)
10740 : /* This happens for range for when not in templates.
10741 : Still add the DECL_VALUE_EXPRs for later processing. */
10742 339784 : || (!processing_template_decl
10743 103636 : && type_uses_auto (TREE_TYPE (decl))))
10744 : {
10745 650183 : for (unsigned int i = 0; i < count; i++)
10746 : {
10747 433219 : if (!DECL_HAS_VALUE_EXPR_P (first))
10748 : {
10749 433219 : tree v = build_nt (ARRAY_REF, decl,
10750 433219 : size_int (count - i - 1),
10751 : NULL_TREE, NULL_TREE);
10752 433219 : SET_DECL_VALUE_EXPR (first, v);
10753 433219 : DECL_HAS_VALUE_EXPR_P (first) = 1;
10754 : }
10755 433219 : if (processing_template_decl)
10756 432583 : fit_decomposition_lang_decl (first, decl);
10757 433219 : first = DECL_CHAIN (first);
10758 : }
10759 : return false;
10760 : }
10761 :
10762 122820 : auto_vec<tree, 16> v;
10763 122820 : v.safe_grow (count, true);
10764 122820 : tree d = first;
10765 122820 : int pack = -1;
10766 359423 : for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
10767 : {
10768 236603 : v[count - i - 1] = d;
10769 236603 : fit_decomposition_lang_decl (d, decl);
10770 236603 : if (DECL_PACK_P (d))
10771 11111 : pack = count - i - 1;
10772 : }
10773 :
10774 122820 : tree type = TREE_TYPE (decl);
10775 122820 : tree dexp = decl;
10776 :
10777 122820 : if (TYPE_REF_P (type))
10778 : {
10779 2206 : dexp = convert_from_reference (dexp);
10780 2206 : type = complete_type (TREE_TYPE (type));
10781 2206 : if (type == error_mark_node)
10782 137 : goto error_out;
10783 2206 : if (!COMPLETE_TYPE_P (type))
10784 : {
10785 3 : error_at (loc, "structured binding refers to incomplete type %qT",
10786 : type);
10787 3 : goto error_out;
10788 : }
10789 : }
10790 :
10791 122817 : tree eltype = NULL_TREE;
10792 122817 : unsigned HOST_WIDE_INT eltscnt = 0;
10793 : /* Structured binding packs when initializer is non-dependent should
10794 : have their DECL_VALUE_EXPR set to a TREE_VEC. First two elements
10795 : of that TREE_VEC are the base and index, what is normally represented
10796 : as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index
10797 : of the pack first element. The remaining elements of the TREE_VEC
10798 : are VAR_DECLs for the pack elements. */
10799 122817 : tree packv = NULL_TREE;
10800 :
10801 122817 : if (TREE_CODE (type) == ARRAY_TYPE)
10802 : {
10803 11234 : tree nelts;
10804 11234 : nelts = array_type_nelts_top (type);
10805 11234 : if (nelts == error_mark_node)
10806 0 : goto error_out;
10807 11234 : if (DECL_DECOMP_BASE (decl))
10808 : {
10809 9 : error_at (loc, "array initializer for structured binding "
10810 : "declaration in condition");
10811 9 : goto error_out;
10812 : }
10813 11225 : if (!tree_fits_uhwi_p (nelts))
10814 : {
10815 3 : error_at (loc, "cannot decompose variable length array %qT", type);
10816 3 : goto error_out;
10817 : }
10818 11222 : eltscnt = tree_to_uhwi (nelts);
10819 11222 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10820 : {
10821 11 : cnt_mismatch:
10822 38 : auto_diagnostic_group d;
10823 38 : if (count > eltscnt)
10824 27 : error_n (loc, count,
10825 : "%u name provided for structured binding",
10826 : "%u names provided for structured binding", count);
10827 : else
10828 11 : error_n (loc, count,
10829 : "only %u name provided for structured binding",
10830 : "only %u names provided for structured binding", count);
10831 38 : inform_n (loc, eltscnt,
10832 : "while %qT decomposes into %wu element",
10833 : "while %qT decomposes into %wu elements",
10834 : type, eltscnt);
10835 38 : goto error_out;
10836 : }
10837 11211 : eltype = TREE_TYPE (type);
10838 24136 : for (unsigned int i = 0; i < count; i++)
10839 : {
10840 12925 : if ((unsigned) pack == i)
10841 : {
10842 10060 : packv = make_tree_vec (eltscnt - count + 3);
10843 41446 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10844 : {
10845 31386 : tree t;
10846 31386 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10847 31386 : set_sb_pack_name (t, j);
10848 31386 : maybe_push_decl (t);
10849 31386 : TREE_TYPE (t) = eltype;
10850 31386 : layout_decl (t, 0);
10851 31386 : if (!processing_template_decl)
10852 : {
10853 31288 : tree a = unshare_expr (dexp);
10854 31288 : a = build4 (ARRAY_REF, eltype, a, size_int (j + pack),
10855 : NULL_TREE, NULL_TREE);
10856 31288 : SET_DECL_VALUE_EXPR (t, a);
10857 31288 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10858 : }
10859 : }
10860 12925 : continue;
10861 10060 : }
10862 2865 : TREE_TYPE (v[i]) = eltype;
10863 2865 : layout_decl (v[i], 0);
10864 2865 : if (processing_template_decl)
10865 140 : continue;
10866 2725 : tree t = unshare_expr (dexp);
10867 2725 : unsigned HOST_WIDE_INT j = i;
10868 2725 : if (pack != -1 && (unsigned) pack < i)
10869 64 : j = i + eltscnt - count;
10870 2725 : t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
10871 2725 : SET_DECL_VALUE_EXPR (v[i], t);
10872 2725 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10873 : }
10874 : }
10875 : /* 2 GNU extensions. */
10876 111583 : else if (TREE_CODE (type) == COMPLEX_TYPE)
10877 : {
10878 78 : eltscnt = 2;
10879 78 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10880 3 : goto cnt_mismatch;
10881 75 : eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
10882 213 : for (unsigned int i = 0; i < count; i++)
10883 : {
10884 138 : if ((unsigned) pack == i)
10885 : {
10886 60 : packv = make_tree_vec (eltscnt - count + 3);
10887 132 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10888 : {
10889 72 : tree t;
10890 72 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10891 72 : set_sb_pack_name (t, j);
10892 72 : maybe_push_decl (t);
10893 72 : TREE_TYPE (t) = eltype;
10894 72 : layout_decl (t, 0);
10895 72 : if (!processing_template_decl)
10896 : {
10897 72 : tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype,
10898 : unshare_expr (dexp));
10899 48 : SET_DECL_VALUE_EXPR (t, a);
10900 48 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10901 : }
10902 : }
10903 60 : continue;
10904 60 : }
10905 78 : TREE_TYPE (v[i]) = eltype;
10906 78 : layout_decl (v[i], 0);
10907 78 : if (processing_template_decl)
10908 16 : continue;
10909 62 : tree t = unshare_expr (dexp);
10910 62 : unsigned HOST_WIDE_INT j = i;
10911 62 : if (pack != -1 && (unsigned) pack < i)
10912 16 : j = i + eltscnt - count;
10913 93 : t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
10914 62 : SET_DECL_VALUE_EXPR (v[i], t);
10915 62 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10916 : }
10917 : }
10918 111505 : else if (TREE_CODE (type) == VECTOR_TYPE)
10919 : {
10920 60 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
10921 : {
10922 : error_at (loc, "cannot decompose variable length vector %qT", type);
10923 : goto error_out;
10924 : }
10925 60 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10926 3 : goto cnt_mismatch;
10927 57 : eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
10928 249 : for (unsigned int i = 0; i < count; i++)
10929 : {
10930 192 : if ((unsigned) pack == i)
10931 : {
10932 48 : packv = make_tree_vec (eltscnt - count + 3);
10933 708 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10934 : {
10935 660 : tree t;
10936 660 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10937 660 : set_sb_pack_name (t, j);
10938 660 : maybe_push_decl (t);
10939 660 : TREE_TYPE (t) = eltype;
10940 660 : layout_decl (t, 0);
10941 660 : if (!processing_template_decl)
10942 : {
10943 440 : tree a = unshare_expr (dexp);
10944 440 : location_t loc = DECL_SOURCE_LOCATION (t);
10945 440 : tree s = size_int (j + pack);
10946 440 : convert_vector_to_array_for_subscript (loc, &a, s);
10947 440 : a = build4 (ARRAY_REF, eltype, a, s,
10948 : NULL_TREE, NULL_TREE);
10949 440 : SET_DECL_VALUE_EXPR (t, a);
10950 440 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10951 : }
10952 : }
10953 84 : continue;
10954 48 : }
10955 144 : TREE_TYPE (v[i]) = eltype;
10956 144 : layout_decl (v[i], 0);
10957 144 : if (processing_template_decl)
10958 36 : continue;
10959 108 : tree t = unshare_expr (dexp);
10960 108 : unsigned HOST_WIDE_INT j = i;
10961 108 : if (pack != -1 && (unsigned) pack < i)
10962 24 : j = i + eltscnt - count;
10963 108 : convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
10964 108 : &t, size_int (j));
10965 108 : t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
10966 108 : SET_DECL_VALUE_EXPR (v[i], t);
10967 108 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10968 : }
10969 : }
10970 111445 : else if (tree tsize = get_tuple_size (type))
10971 : {
10972 80699 : if (tsize == error_mark_node)
10973 : {
10974 0 : error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
10975 : "constant expression", type);
10976 0 : goto error_out;
10977 : }
10978 80699 : if (!tree_fits_uhwi_p (tsize))
10979 : {
10980 12 : auto_diagnostic_group d;
10981 12 : error_n (loc, count,
10982 : "%u name provided for structured binding",
10983 : "%u names provided for structured binding", count);
10984 12 : inform (loc, "while %qT decomposes into %E elements",
10985 : type, tsize);
10986 12 : goto error_out;
10987 12 : }
10988 80687 : eltscnt = tree_to_uhwi (tsize);
10989 80687 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10990 6 : goto cnt_mismatch;
10991 80681 : if (test_p && eltscnt)
10992 122683 : return true;
10993 45246 : if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt)
10994 : {
10995 : /* For structured bindings used in conditions we need to evaluate
10996 : the conversion of decl (aka e in the standard) to bool or
10997 : integral/enumeral type (the latter for switch conditions)
10998 : before the get methods. */
10999 86 : tree cond = convert_from_reference (decl);
11000 86 : if (integer_onep (DECL_DECOMP_BASE (decl)))
11001 : /* switch condition. */
11002 18 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
11003 : cond, true);
11004 : else
11005 : /* if/while/for condition. */
11006 68 : cond = contextual_conv_bool (cond, tf_warning_or_error);
11007 86 : if (cond && !error_operand_p (cond))
11008 : {
11009 : /* Wrap that value into a TARGET_EXPR, emit it right
11010 : away and save for later uses in the cp_parse_condition
11011 : or its instantiation. */
11012 86 : cond = get_internal_target_expr (cond);
11013 86 : add_stmt (cond);
11014 86 : DECL_DECOMP_BASE (decl) = cond;
11015 : }
11016 : }
11017 45246 : int save_read = DECL_READ_P (decl);
11018 135628 : for (unsigned i = 0; i < count; ++i)
11019 : {
11020 90403 : location_t sloc = input_location;
11021 90403 : location_t dloc = DECL_SOURCE_LOCATION (v[i]);
11022 :
11023 90403 : if ((unsigned) pack == i)
11024 : {
11025 401 : packv = make_tree_vec (eltscnt - count + 3);
11026 1586 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
11027 : {
11028 1185 : tree t;
11029 1185 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
11030 1185 : set_sb_pack_name (t, j);
11031 1185 : input_location = dloc;
11032 1185 : tree init = get_tuple_decomp_init (decl, j + pack);
11033 1185 : tree eltype = (init == error_mark_node ? error_mark_node
11034 1185 : : get_tuple_element_type (type, j + pack));
11035 1185 : input_location = sloc;
11036 :
11037 1185 : if (VOID_TYPE_P (eltype))
11038 : {
11039 0 : error ("%<std::tuple_element<%wu, %T>::type%> is "
11040 : "%<void%>", j + pack, type);
11041 0 : eltype = error_mark_node;
11042 : }
11043 1185 : if (init == error_mark_node || eltype == error_mark_node)
11044 : {
11045 0 : inform (dloc, "in initialization of structured binding "
11046 0 : "pack %qD", v[pack]);
11047 0 : goto error_out;
11048 : }
11049 1185 : maybe_push_decl (t);
11050 : /* Save the decltype away before reference collapse. */
11051 1185 : hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
11052 1185 : if (glvalue_p (init))
11053 1083 : eltype = cp_build_reference_type (eltype, !lvalue_p (init));
11054 1185 : TREE_TYPE (t) = eltype;
11055 1185 : layout_decl (t, 0);
11056 1185 : DECL_HAS_VALUE_EXPR_P (t) = 0;
11057 1185 : if (!processing_template_decl)
11058 : {
11059 795 : copy_linkage (t, decl);
11060 795 : tree name = DECL_NAME (t);
11061 795 : if (TREE_STATIC (decl))
11062 52 : DECL_NAME (t) = DECL_NAME (v[pack]);
11063 795 : cp_finish_decl (t, init, /*constexpr*/false,
11064 : /*asm*/NULL_TREE, LOOKUP_NORMAL);
11065 795 : if (TREE_STATIC (decl))
11066 : {
11067 52 : DECL_ASSEMBLER_NAME (t);
11068 52 : DECL_NAME (t) = name;
11069 : }
11070 : }
11071 : }
11072 401 : continue;
11073 401 : }
11074 :
11075 90002 : unsigned HOST_WIDE_INT j = i;
11076 90002 : if (pack != -1 && (unsigned) pack < i)
11077 235 : j = i + eltscnt - count;
11078 90002 : input_location = dloc;
11079 90002 : tree init = get_tuple_decomp_init (decl, j);
11080 90002 : tree eltype = (init == error_mark_node ? error_mark_node
11081 89993 : : get_tuple_element_type (type, j));
11082 90002 : input_location = sloc;
11083 :
11084 90002 : if (VOID_TYPE_P (eltype))
11085 : {
11086 3 : error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>",
11087 : j, type);
11088 3 : eltype = error_mark_node;
11089 : }
11090 90002 : if (init == error_mark_node || eltype == error_mark_node)
11091 : {
11092 21 : inform (dloc, "in initialization of structured binding "
11093 21 : "variable %qD", v[i]);
11094 21 : goto error_out;
11095 : }
11096 : /* Save the decltype away before reference collapse. */
11097 89981 : hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
11098 89981 : if (glvalue_p (init))
11099 89633 : eltype = cp_build_reference_type (eltype, !lvalue_p (init));
11100 89981 : TREE_TYPE (v[i]) = eltype;
11101 89981 : layout_decl (v[i], 0);
11102 89981 : if (DECL_HAS_VALUE_EXPR_P (v[i]))
11103 : {
11104 : /* In this case the names are variables, not just proxies. */
11105 220 : SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
11106 220 : DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
11107 : }
11108 89981 : if (!processing_template_decl)
11109 : {
11110 70453 : copy_linkage (v[i], decl);
11111 70453 : cp_finish_decl (v[i], init, /*constexpr*/false,
11112 : /*asm*/NULL_TREE, LOOKUP_NORMAL);
11113 : }
11114 : }
11115 : /* Ignore reads from the underlying decl performed during initialization
11116 : of the individual variables. If those will be read, we'll mark
11117 : the underlying decl as read at that point. */
11118 45225 : DECL_READ_P (decl) = save_read;
11119 : }
11120 30746 : else if (TREE_CODE (type) == UNION_TYPE)
11121 : {
11122 3 : error_at (loc, "cannot decompose union type %qT", type);
11123 3 : goto error_out;
11124 : }
11125 30743 : else if (!CLASS_TYPE_P (type))
11126 : {
11127 19 : error_at (loc, "cannot decompose non-array non-class type %qT", type);
11128 19 : goto error_out;
11129 : }
11130 30724 : else if (processing_template_decl && complete_type (type) == error_mark_node)
11131 0 : goto error_out;
11132 30724 : else if (processing_template_decl && !COMPLETE_TYPE_P (type))
11133 2 : pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
11134 : type);
11135 : else
11136 : {
11137 30722 : tree btype = find_decomp_class_base (loc, type, NULL_TREE,
11138 : tf_warning_or_error);
11139 30722 : if (btype == error_mark_node)
11140 21 : goto error_out;
11141 30701 : else if (btype == NULL_TREE)
11142 : {
11143 24 : if (pack == 0 && count == 1)
11144 : {
11145 16 : eltscnt = 0;
11146 16 : packv = make_tree_vec (2);
11147 16 : goto done;
11148 : }
11149 8 : error_at (loc, "cannot decompose class type %qT without non-static "
11150 : "data members", type);
11151 8 : goto error_out;
11152 : }
11153 389426 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
11154 655338 : if (TREE_CODE (field) != FIELD_DECL
11155 62176 : || DECL_ARTIFICIAL (field)
11156 420921 : || DECL_UNNAMED_BIT_FIELD (field))
11157 296589 : continue;
11158 : else
11159 62160 : eltscnt++;
11160 30677 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
11161 15 : goto cnt_mismatch;
11162 30662 : tree t = dexp;
11163 30662 : if (type != btype)
11164 : {
11165 18 : t = convert_to_base (t, btype, /*check_access*/true,
11166 : /*nonnull*/false, tf_warning_or_error);
11167 18 : type = btype;
11168 : }
11169 30662 : unsigned HOST_WIDE_INT j = 0;
11170 30662 : unsigned int i = 0;
11171 389215 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
11172 654983 : if (TREE_CODE (field) != FIELD_DECL
11173 62139 : || DECL_ARTIFICIAL (field)
11174 420688 : || DECL_UNNAMED_BIT_FIELD (field))
11175 296430 : continue;
11176 : else
11177 : {
11178 62123 : tree tt = finish_non_static_data_member (field, unshare_expr (t),
11179 : NULL_TREE);
11180 62123 : if (REFERENCE_REF_P (tt))
11181 30 : tt = TREE_OPERAND (tt, 0);
11182 62123 : if (pack != -1 && j >= (unsigned) pack)
11183 : {
11184 685 : if (j == (unsigned) pack)
11185 : {
11186 227 : packv = make_tree_vec (eltscnt - count + 3);
11187 227 : i++;
11188 : }
11189 685 : if (j < (unsigned) pack + eltscnt - (count - 1))
11190 : {
11191 504 : tree t;
11192 504 : TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]);
11193 504 : set_sb_pack_name (t, j + 1 - i);
11194 504 : maybe_push_decl (t);
11195 504 : TREE_TYPE (t) = TREE_TYPE (tt);
11196 504 : layout_decl (t, 0);
11197 504 : if (!processing_template_decl)
11198 : {
11199 383 : SET_DECL_VALUE_EXPR (t, tt);
11200 383 : DECL_HAS_VALUE_EXPR_P (t) = 1;
11201 : }
11202 : else
11203 121 : DECL_HAS_VALUE_EXPR_P (t) = 0;
11204 504 : j++;
11205 504 : continue;
11206 504 : }
11207 : }
11208 61619 : TREE_TYPE (v[i]) = TREE_TYPE (tt);
11209 61619 : layout_decl (v[i], 0);
11210 61619 : if (!processing_template_decl)
11211 : {
11212 42641 : SET_DECL_VALUE_EXPR (v[i], tt);
11213 42641 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11214 : }
11215 61619 : i++;
11216 61619 : j++;
11217 : }
11218 30662 : if (pack != -1 && j == (unsigned) pack)
11219 : {
11220 20 : gcc_checking_assert (eltscnt == count - 1);
11221 20 : packv = make_tree_vec (2);
11222 : }
11223 : }
11224 87248 : done:
11225 87248 : if (packv)
11226 : {
11227 10832 : gcc_checking_assert (pack != -1);
11228 10832 : TREE_VEC_ELT (packv, 0) = decl;
11229 10832 : TREE_VEC_ELT (packv, 1) = size_int (pack);
11230 10832 : SET_DECL_VALUE_EXPR (v[pack], packv);
11231 10832 : DECL_HAS_VALUE_EXPR_P (v[pack]) = 1;
11232 10832 : DECL_IGNORED_P (v[pack]) = 1;
11233 10832 : if (!processing_template_decl)
11234 43481 : for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i)
11235 32954 : pushdecl (TREE_VEC_ELT (packv, 2 + i));
11236 : }
11237 87248 : if (processing_template_decl)
11238 : {
11239 58433 : for (unsigned int i = 0; i < count; i++)
11240 39005 : if (!DECL_HAS_VALUE_EXPR_P (v[i]))
11241 : {
11242 38553 : tree a = build_nt (ARRAY_REF, decl, size_int (i),
11243 : NULL_TREE, NULL_TREE);
11244 38553 : SET_DECL_VALUE_EXPR (v[i], a);
11245 38553 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11246 : }
11247 : }
11248 67820 : else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
11249 : {
11250 480 : tree attr = NULL_TREE, *pa = &attr;
11251 1550 : for (unsigned int i = 0; i < count; i++)
11252 1070 : if ((unsigned) pack != i
11253 1070 : && DECL_HAS_VALUE_EXPR_P (v[i])
11254 1796 : && !DECL_IGNORED_P (v[i]))
11255 : {
11256 726 : (*debug_hooks->early_global_decl) (v[i]);
11257 726 : *pa = build_tree_list (NULL_TREE, v[i]);
11258 726 : pa = &TREE_CHAIN (*pa);
11259 : }
11260 480 : if (attr)
11261 364 : DECL_ATTRIBUTES (decl)
11262 728 : = tree_cons (get_identifier ("structured bindings"),
11263 364 : attr, DECL_ATTRIBUTES (decl));
11264 : }
11265 : return false;
11266 : }
11267 :
11268 : /* Returns a declaration for a VAR_DECL as if:
11269 :
11270 : extern "C" TYPE NAME;
11271 :
11272 : had been seen. Used to create compiler-generated global
11273 : variables. */
11274 :
11275 : static tree
11276 2222 : declare_global_var (tree name, tree type)
11277 : {
11278 2222 : auto cookie = push_abi_namespace (global_namespace);
11279 2222 : tree decl = build_decl (input_location, VAR_DECL, name, type);
11280 2222 : TREE_PUBLIC (decl) = 1;
11281 2222 : DECL_EXTERNAL (decl) = 1;
11282 2222 : DECL_ARTIFICIAL (decl) = 1;
11283 2222 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
11284 : /* If the user has explicitly declared this variable (perhaps
11285 : because the code we are compiling is part of a low-level runtime
11286 : library), then it is possible that our declaration will be merged
11287 : with theirs by pushdecl. */
11288 2222 : decl = pushdecl (decl);
11289 2222 : cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
11290 2222 : pop_abi_namespace (cookie, global_namespace);
11291 :
11292 2222 : return decl;
11293 : }
11294 :
11295 : /* Returns the type for the argument to "atexit" corresponding to the function
11296 : to be called when the program exits. */
11297 :
11298 : static tree
11299 24 : get_atexit_fn_ptr_type ()
11300 : {
11301 24 : if (!atexit_fn_ptr_type_node)
11302 : {
11303 12 : tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
11304 12 : atexit_fn_ptr_type_node = build_pointer_type (fn_type);
11305 : }
11306 :
11307 24 : return atexit_fn_ptr_type_node;
11308 : }
11309 :
11310 : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
11311 : or "__cxa_throw" corresponding to the destructor to be called when the
11312 : program exits. */
11313 :
11314 : tree
11315 19388 : get_cxa_atexit_fn_ptr_type ()
11316 : {
11317 19388 : if (!cleanup_type)
11318 : {
11319 14713 : tree fntype = build_function_type_list (void_type_node,
11320 : ptr_type_node, NULL_TREE);
11321 14713 : fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
11322 14713 : cleanup_type = build_pointer_type (fntype);
11323 : }
11324 :
11325 19388 : return cleanup_type;
11326 : }
11327 :
11328 : /* Returns a pointer to the `atexit' function. Note that if
11329 : FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
11330 : `__cxa_atexit' function specified in the IA64 C++ ABI. */
11331 :
11332 : static tree
11333 3417 : get_atexit_node (void)
11334 : {
11335 3417 : tree atexit_fndecl;
11336 3417 : tree fn_type;
11337 3417 : tree fn_ptr_type;
11338 3417 : const char *name;
11339 3417 : bool use_aeabi_atexit;
11340 3417 : tree ctx = global_namespace;
11341 :
11342 3417 : if (atexit_node)
11343 : return atexit_node;
11344 :
11345 2185 : if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
11346 : {
11347 : /* The declaration for `__cxa_atexit' is:
11348 :
11349 : int __cxa_atexit (void (*)(void *), void *, void *)
11350 :
11351 : We build up the argument types and then the function type
11352 : itself. */
11353 2173 : tree argtype0, argtype1, argtype2;
11354 :
11355 2173 : use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
11356 : /* First, build the pointer-to-function type for the first
11357 : argument. */
11358 2173 : fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
11359 : /* Then, build the rest of the argument types. */
11360 2173 : argtype2 = ptr_type_node;
11361 2173 : if (use_aeabi_atexit)
11362 : {
11363 : argtype1 = fn_ptr_type;
11364 : argtype0 = ptr_type_node;
11365 : }
11366 : else
11367 : {
11368 2173 : argtype1 = ptr_type_node;
11369 2173 : argtype0 = fn_ptr_type;
11370 : }
11371 : /* And the final __cxa_atexit type. */
11372 2173 : fn_type = build_function_type_list (integer_type_node,
11373 : argtype0, argtype1, argtype2,
11374 : NULL_TREE);
11375 : /* ... which needs noexcept. */
11376 2173 : fn_type = build_exception_variant (fn_type, noexcept_true_spec);
11377 2173 : if (use_aeabi_atexit)
11378 : {
11379 0 : name = "__aeabi_atexit";
11380 0 : push_to_top_level ();
11381 0 : int n = push_namespace (get_identifier ("__aeabiv1"), false);
11382 0 : ctx = current_namespace;
11383 0 : while (n--)
11384 0 : pop_namespace ();
11385 0 : pop_from_top_level ();
11386 : }
11387 : else
11388 : {
11389 2173 : name = "__cxa_atexit";
11390 2173 : ctx = abi_node;
11391 : }
11392 : }
11393 : else
11394 : {
11395 : /* The declaration for `atexit' is:
11396 :
11397 : int atexit (void (*)());
11398 :
11399 : We build up the argument types and then the function type
11400 : itself. */
11401 12 : fn_ptr_type = get_atexit_fn_ptr_type ();
11402 : /* Build the final atexit type. */
11403 12 : fn_type = build_function_type_list (integer_type_node,
11404 : fn_ptr_type, NULL_TREE);
11405 : /* ... which needs noexcept. */
11406 12 : fn_type = build_exception_variant (fn_type, noexcept_true_spec);
11407 12 : name = "atexit";
11408 : }
11409 :
11410 : /* Now, build the function declaration. */
11411 2185 : push_lang_context (lang_name_c);
11412 2185 : auto cookie = push_abi_namespace (ctx);
11413 2185 : atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
11414 2185 : DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
11415 : /* Install as hidden builtin so we're (a) more relaxed about
11416 : exception spec matching and (b) will not give a confusing location
11417 : in diagnostic and (c) won't magically appear in user-visible name
11418 : lookups. */
11419 2185 : DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
11420 2185 : atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
11421 2185 : pop_abi_namespace (cookie, ctx);
11422 2185 : mark_used (atexit_fndecl);
11423 2185 : pop_lang_context ();
11424 2185 : atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
11425 :
11426 2185 : return atexit_node;
11427 : }
11428 :
11429 : /* Like get_atexit_node, but for thread-local cleanups. */
11430 :
11431 : static tree
11432 98 : get_thread_atexit_node (void)
11433 : {
11434 98 : if (thread_atexit_node)
11435 : return thread_atexit_node;
11436 :
11437 : /* The declaration for `__cxa_thread_atexit' is:
11438 :
11439 : int __cxa_thread_atexit (void (*)(void *), void *, void *) */
11440 59 : tree fn_type = build_function_type_list (integer_type_node,
11441 : get_cxa_atexit_fn_ptr_type (),
11442 : ptr_type_node, ptr_type_node,
11443 : NULL_TREE);
11444 :
11445 : /* Now, build the function declaration, as with __cxa_atexit. */
11446 59 : unsigned flags = push_abi_namespace ();
11447 59 : tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
11448 : ECF_LEAF | ECF_NOTHROW);
11449 59 : DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
11450 59 : DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
11451 59 : atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
11452 59 : pop_abi_namespace (flags);
11453 59 : mark_used (atexit_fndecl);
11454 59 : thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
11455 :
11456 59 : return thread_atexit_node;
11457 : }
11458 :
11459 : /* Returns the __dso_handle VAR_DECL. */
11460 :
11461 : static tree
11462 3503 : get_dso_handle_node (void)
11463 : {
11464 3503 : if (dso_handle_node)
11465 : return dso_handle_node;
11466 :
11467 : /* Declare the variable. */
11468 2222 : dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
11469 : ptr_type_node);
11470 :
11471 : #ifdef HAVE_GAS_HIDDEN
11472 2222 : if (dso_handle_node != error_mark_node)
11473 : {
11474 2219 : DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
11475 2219 : DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
11476 : }
11477 : #endif
11478 :
11479 2222 : return dso_handle_node;
11480 : }
11481 :
11482 : /* Begin a new function with internal linkage whose job will be simply
11483 : to destroy some particular DECL. OB_PARM is true if object pointer
11484 : is passed to the cleanup function, otherwise no argument is passed. */
11485 :
11486 : static tree
11487 380 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
11488 : {
11489 380 : push_to_top_level ();
11490 :
11491 : /* No need to mangle this. */
11492 380 : push_lang_context (lang_name_c);
11493 :
11494 : /* Build the name of the function. */
11495 380 : gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
11496 380 : const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
11497 380 : dname = targetm.strip_name_encoding (dname);
11498 757 : char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
11499 :
11500 380 : tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
11501 : : get_atexit_fn_ptr_type ());
11502 : /* Build the function declaration. */
11503 380 : tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
11504 380 : DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
11505 : /* It's a function with internal linkage, generated by the
11506 : compiler. */
11507 380 : TREE_PUBLIC (fndecl) = 0;
11508 380 : DECL_ARTIFICIAL (fndecl) = 1;
11509 : /* Make the function `inline' so that it is only emitted if it is
11510 : actually needed. It is unlikely that it will be inlined, since
11511 : it is only called via a function pointer, but we avoid unnecessary
11512 : emissions this way. */
11513 380 : DECL_DECLARED_INLINE_P (fndecl) = 1;
11514 380 : DECL_INTERFACE_KNOWN (fndecl) = 1;
11515 380 : if (ob_parm)
11516 : {
11517 : /* Build the parameter. */
11518 368 : tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
11519 368 : TREE_USED (parmdecl) = 1;
11520 368 : DECL_READ_P (parmdecl) = 1;
11521 368 : DECL_ARGUMENTS (fndecl) = parmdecl;
11522 : }
11523 :
11524 380 : fndecl = pushdecl (fndecl, /*hidden=*/true);
11525 380 : if (omp_target)
11526 : {
11527 3 : DECL_ATTRIBUTES (fndecl)
11528 3 : = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
11529 3 : DECL_ATTRIBUTES (fndecl));
11530 3 : DECL_ATTRIBUTES (fndecl)
11531 6 : = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
11532 3 : DECL_ATTRIBUTES (fndecl));
11533 : }
11534 380 : start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
11535 :
11536 380 : pop_lang_context ();
11537 :
11538 380 : return current_function_decl;
11539 : }
11540 :
11541 : /* Finish the cleanup function begun by start_cleanup_fn. */
11542 :
11543 : static void
11544 380 : end_cleanup_fn (void)
11545 : {
11546 380 : expand_or_defer_fn (finish_function (/*inline_p=*/false));
11547 :
11548 380 : pop_from_top_level ();
11549 380 : }
11550 :
11551 : /* Generate code to handle the destruction of DECL, an object with
11552 : static storage duration. */
11553 :
11554 : tree
11555 15191 : register_dtor_fn (tree decl, bool omp_target)
11556 : {
11557 15191 : tree cleanup;
11558 15191 : tree addr;
11559 15191 : tree compound_stmt;
11560 15191 : tree fcall;
11561 15191 : tree type;
11562 15191 : bool ob_parm, dso_parm, use_dtor;
11563 15191 : tree arg0, arg1, arg2;
11564 15191 : tree atex_node;
11565 :
11566 15191 : type = TREE_TYPE (decl);
11567 15191 : if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
11568 11676 : return void_node;
11569 :
11570 3515 : if (decl_maybe_constant_destruction (decl, type)
11571 3515 : && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
11572 : {
11573 0 : cxx_maybe_build_cleanup (decl, tf_warning_or_error);
11574 0 : return void_node;
11575 : }
11576 :
11577 : /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
11578 : "__aeabi_atexit"), and DECL is a class object, we can just pass the
11579 : destructor to "__cxa_atexit"; we don't have to build a temporary
11580 : function to do the cleanup. */
11581 7030 : dso_parm = (flag_use_cxa_atexit
11582 3515 : && !targetm.cxx.use_atexit_for_cxa_atexit ());
11583 3515 : ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
11584 3503 : use_dtor = ob_parm && CLASS_TYPE_P (type);
11585 3515 : if (use_dtor)
11586 : {
11587 3135 : cleanup = get_class_binding (type, complete_dtor_identifier);
11588 :
11589 : /* Make sure it is accessible. */
11590 3135 : perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
11591 : tf_warning_or_error);
11592 : }
11593 : else
11594 : {
11595 : /* Call build_cleanup before we enter the anonymous function so
11596 : that any access checks will be done relative to the current
11597 : scope, rather than the scope of the anonymous function. */
11598 380 : build_cleanup (decl);
11599 :
11600 : /* Now start the function. */
11601 380 : cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
11602 :
11603 : /* Now, recompute the cleanup. It may contain SAVE_EXPRs that refer
11604 : to the original function, rather than the anonymous one. That
11605 : will make the back end think that nested functions are in use,
11606 : which causes confusion. */
11607 380 : push_deferring_access_checks (dk_no_check);
11608 380 : fcall = build_cleanup (decl);
11609 380 : pop_deferring_access_checks ();
11610 :
11611 : /* Create the body of the anonymous function. */
11612 380 : compound_stmt = begin_compound_stmt (BCS_FN_BODY);
11613 380 : finish_expr_stmt (fcall);
11614 380 : finish_compound_stmt (compound_stmt);
11615 380 : end_cleanup_fn ();
11616 : }
11617 :
11618 : /* Call atexit with the cleanup function. */
11619 3515 : mark_used (cleanup);
11620 3515 : cleanup = build_address (cleanup);
11621 :
11622 3515 : if (CP_DECL_THREAD_LOCAL_P (decl))
11623 98 : atex_node = get_thread_atexit_node ();
11624 : else
11625 3417 : atex_node = get_atexit_node ();
11626 :
11627 3515 : if (use_dtor)
11628 : {
11629 : /* We must convert CLEANUP to the type that "__cxa_atexit"
11630 : expects. */
11631 3135 : cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
11632 : /* "__cxa_atexit" will pass the address of DECL to the
11633 : cleanup function. */
11634 3135 : mark_used (decl);
11635 3135 : addr = build_address (decl);
11636 : /* The declared type of the parameter to "__cxa_atexit" is
11637 : "void *". For plain "T*", we could just let the
11638 : machinery in cp_build_function_call convert it -- but if the
11639 : type is "cv-qualified T *", then we need to convert it
11640 : before passing it in, to avoid spurious errors. */
11641 3135 : addr = build_nop (ptr_type_node, addr);
11642 : }
11643 : else
11644 : /* Since the cleanup functions we build ignore the address
11645 : they're given, there's no reason to pass the actual address
11646 : in, and, in general, it's cheaper to pass NULL than any
11647 : other value. */
11648 380 : addr = null_pointer_node;
11649 :
11650 3515 : if (dso_parm)
11651 3503 : arg2 = cp_build_addr_expr (get_dso_handle_node (),
11652 : tf_warning_or_error);
11653 12 : else if (ob_parm)
11654 : /* Just pass NULL to the dso handle parm if we don't actually
11655 : have a DSO handle on this target. */
11656 0 : arg2 = null_pointer_node;
11657 : else
11658 : arg2 = NULL_TREE;
11659 :
11660 3503 : if (ob_parm)
11661 : {
11662 3503 : if (!CP_DECL_THREAD_LOCAL_P (decl)
11663 3503 : && targetm.cxx.use_aeabi_atexit ())
11664 : {
11665 : arg1 = cleanup;
11666 : arg0 = addr;
11667 : }
11668 : else
11669 : {
11670 : arg1 = addr;
11671 : arg0 = cleanup;
11672 : }
11673 : }
11674 : else
11675 : {
11676 : arg0 = cleanup;
11677 : arg1 = NULL_TREE;
11678 : }
11679 3515 : return cp_build_function_call_nary (atex_node, tf_warning_or_error,
11680 3515 : arg0, arg1, arg2, NULL_TREE);
11681 : }
11682 :
11683 : /* DECL is a VAR_DECL with static storage duration. INIT, if present,
11684 : is its initializer. Generate code to handle the construction
11685 : and destruction of DECL. */
11686 :
11687 : static void
11688 29552658 : expand_static_init (tree decl, tree init)
11689 : {
11690 29552658 : gcc_assert (VAR_P (decl));
11691 29552658 : gcc_assert (TREE_STATIC (decl));
11692 :
11693 : /* Some variables require no dynamic initialization. */
11694 29552658 : if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
11695 : {
11696 : /* Make sure the destructor is callable. */
11697 29549175 : cxx_maybe_build_cleanup (decl, tf_warning_or_error);
11698 29549175 : if (!init)
11699 : return;
11700 : }
11701 :
11702 16058 : if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
11703 15132 : && !DECL_FUNCTION_SCOPE_P (decl))
11704 : {
11705 15 : auto_diagnostic_group d;
11706 15 : location_t dloc = DECL_SOURCE_LOCATION (decl);
11707 15 : if (init)
11708 12 : error_at (dloc, "non-local variable %qD declared %<__thread%> "
11709 : "needs dynamic initialization", decl);
11710 : else
11711 3 : error_at (dloc, "non-local variable %qD declared %<__thread%> "
11712 : "has a non-trivial destructor", decl);
11713 15 : static bool informed;
11714 15 : if (!informed)
11715 : {
11716 6 : inform (dloc, "C++11 %<thread_local%> allows dynamic "
11717 : "initialization and destruction");
11718 6 : informed = true;
11719 : }
11720 15 : return;
11721 15 : }
11722 :
11723 15088 : if (DECL_FUNCTION_SCOPE_P (decl))
11724 : {
11725 : /* Emit code to perform this initialization but once. */
11726 3856 : tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
11727 3856 : tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
11728 3856 : tree guard, guard_addr;
11729 3856 : tree flag, begin;
11730 : /* We don't need thread-safety code for thread-local vars. */
11731 3856 : bool thread_guard = (flag_threadsafe_statics
11732 3856 : && !CP_DECL_THREAD_LOCAL_P (decl));
11733 :
11734 : /* Emit code to perform this initialization but once. This code
11735 : looks like:
11736 :
11737 : static <type> guard;
11738 : if (!__atomic_load (guard.first_byte)) {
11739 : if (__cxa_guard_acquire (&guard)) {
11740 : bool flag = false;
11741 : try {
11742 : // Do initialization.
11743 : flag = true; __cxa_guard_release (&guard);
11744 : // Register variable for destruction at end of program.
11745 : } catch {
11746 : if (!flag) __cxa_guard_abort (&guard);
11747 : }
11748 : }
11749 : }
11750 :
11751 : Note that the `flag' variable is only set to 1 *after* the
11752 : initialization is complete. This ensures that an exception,
11753 : thrown during the construction, will cause the variable to
11754 : reinitialized when we pass through this code again, as per:
11755 :
11756 : [stmt.dcl]
11757 :
11758 : If the initialization exits by throwing an exception, the
11759 : initialization is not complete, so it will be tried again
11760 : the next time control enters the declaration.
11761 :
11762 : This process should be thread-safe, too; multiple threads
11763 : should not be able to initialize the variable more than
11764 : once. */
11765 :
11766 : /* Create the guard variable. */
11767 3856 : guard = get_guard (decl);
11768 :
11769 : /* Begin the conditional initialization. */
11770 3856 : if_stmt = begin_if_stmt ();
11771 :
11772 3856 : finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
11773 3856 : then_clause = begin_compound_stmt (BCS_NO_SCOPE);
11774 :
11775 3856 : if (thread_guard)
11776 : {
11777 3708 : tree vfntype = NULL_TREE;
11778 3708 : tree acquire_name, release_name, abort_name;
11779 3708 : tree acquire_fn, release_fn, abort_fn;
11780 3708 : guard_addr = build_address (guard);
11781 :
11782 3708 : acquire_name = get_identifier ("__cxa_guard_acquire");
11783 3708 : release_name = get_identifier ("__cxa_guard_release");
11784 3708 : abort_name = get_identifier ("__cxa_guard_abort");
11785 3708 : acquire_fn = get_global_binding (acquire_name);
11786 3708 : release_fn = get_global_binding (release_name);
11787 3708 : abort_fn = get_global_binding (abort_name);
11788 3708 : if (!acquire_fn)
11789 2104 : acquire_fn = push_library_fn
11790 2104 : (acquire_name, build_function_type_list (integer_type_node,
11791 2104 : TREE_TYPE (guard_addr),
11792 : NULL_TREE),
11793 : NULL_TREE, ECF_NOTHROW);
11794 3708 : if (!release_fn || !abort_fn)
11795 2107 : vfntype = build_function_type_list (void_type_node,
11796 2107 : TREE_TYPE (guard_addr),
11797 : NULL_TREE);
11798 2107 : if (!release_fn)
11799 2107 : release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
11800 : ECF_NOTHROW);
11801 3708 : if (!abort_fn)
11802 2107 : abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
11803 : ECF_NOTHROW | ECF_LEAF);
11804 :
11805 3708 : inner_if_stmt = begin_if_stmt ();
11806 3708 : finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
11807 : inner_if_stmt);
11808 :
11809 3708 : inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
11810 3708 : begin = get_internal_target_expr (boolean_false_node);
11811 3708 : flag = TARGET_EXPR_SLOT (begin);
11812 :
11813 3708 : TARGET_EXPR_CLEANUP (begin)
11814 3708 : = build3 (COND_EXPR, void_type_node, flag,
11815 : void_node,
11816 : build_call_n (abort_fn, 1, guard_addr));
11817 3708 : CLEANUP_EH_ONLY (begin) = 1;
11818 :
11819 : /* Do the initialization itself. */
11820 3708 : init = add_stmt_to_compound (begin, init);
11821 3708 : init = add_stmt_to_compound (init,
11822 : build2 (MODIFY_EXPR, void_type_node,
11823 : flag, boolean_true_node));
11824 :
11825 : /* Use atexit to register a function for destroying this static
11826 : variable. Do this before calling __cxa_guard_release. */
11827 3708 : init = add_stmt_to_compound (init, register_dtor_fn (decl));
11828 :
11829 3708 : init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
11830 : guard_addr));
11831 : }
11832 : else
11833 : {
11834 148 : init = add_stmt_to_compound (init, set_guard (guard));
11835 :
11836 : /* Use atexit to register a function for destroying this static
11837 : variable. */
11838 148 : init = add_stmt_to_compound (init, register_dtor_fn (decl));
11839 : }
11840 :
11841 3856 : finish_expr_stmt (init);
11842 :
11843 3856 : if (thread_guard)
11844 : {
11845 3708 : finish_compound_stmt (inner_then_clause);
11846 3708 : finish_then_clause (inner_if_stmt);
11847 3708 : finish_if_stmt (inner_if_stmt);
11848 : }
11849 :
11850 3856 : finish_compound_stmt (then_clause);
11851 3856 : finish_then_clause (if_stmt);
11852 3856 : finish_if_stmt (if_stmt);
11853 : }
11854 11232 : else if (CP_DECL_THREAD_LOCAL_P (decl))
11855 795 : tls_aggregates = tree_cons (init, decl, tls_aggregates);
11856 : else
11857 10437 : static_aggregates = tree_cons (init, decl, static_aggregates);
11858 : }
11859 :
11860 :
11861 : /* Make TYPE a complete type based on INITIAL_VALUE.
11862 : Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
11863 : 2 if there was no information (in which case assume 0 if DO_DEFAULT),
11864 : 3 if the initializer list is empty (in pedantic mode). */
11865 :
11866 : int
11867 622055 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
11868 : {
11869 622055 : int failure;
11870 622055 : tree type, elt_type;
11871 :
11872 : /* Don't get confused by a CONSTRUCTOR for some other type. */
11873 622025 : if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
11874 148802 : && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
11875 622387 : && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
11876 : return 1;
11877 :
11878 622052 : if (initial_value)
11879 : {
11880 : /* An array of character type can be initialized from a
11881 : brace-enclosed string constant so call reshape_init to
11882 : remove the optional braces from a braced string literal. */
11883 622022 : if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
11884 622022 : && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
11885 51224 : initial_value = reshape_init (*ptype, initial_value,
11886 : tf_warning_or_error);
11887 :
11888 : /* If any of the elements are parameter packs, we can't actually
11889 : complete this type now because the array size is dependent. */
11890 622022 : if (TREE_CODE (initial_value) == CONSTRUCTOR)
11891 48869088 : for (auto &e: CONSTRUCTOR_ELTS (initial_value))
11892 48423078 : if (PACK_EXPANSION_P (e.value))
11893 : return 0;
11894 : }
11895 :
11896 622052 : failure = complete_array_type (ptype, initial_value, do_default);
11897 :
11898 : /* We can create the array before the element type is complete, which
11899 : means that we didn't have these two bits set in the original type
11900 : either. In completing the type, we are expected to propagate these
11901 : bits. See also complete_type which does the same thing for arrays
11902 : of fixed size. */
11903 622052 : type = *ptype;
11904 1244101 : if (type != error_mark_node && TYPE_DOMAIN (type))
11905 : {
11906 622025 : elt_type = TREE_TYPE (type);
11907 622025 : TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
11908 1244050 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
11909 622025 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
11910 : }
11911 :
11912 : return failure;
11913 : }
11914 :
11915 : /* As above, but either give an error or reject zero-size arrays, depending
11916 : on COMPLAIN. */
11917 :
11918 : int
11919 1253 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
11920 : bool do_default, tsubst_flags_t complain)
11921 : {
11922 1253 : int failure;
11923 1253 : bool sfinae = !(complain & tf_error);
11924 : /* In SFINAE context we can't be lenient about zero-size arrays. */
11925 1253 : if (sfinae)
11926 3 : ++pedantic;
11927 1253 : failure = cp_complete_array_type (ptype, initial_value, do_default);
11928 1253 : if (sfinae)
11929 3 : --pedantic;
11930 1253 : if (failure)
11931 : {
11932 3 : if (sfinae)
11933 : /* Not an error. */;
11934 0 : else if (failure == 1)
11935 0 : error ("initializer fails to determine size of %qT", *ptype);
11936 0 : else if (failure == 2)
11937 : {
11938 0 : if (do_default)
11939 0 : error ("array size missing in %qT", *ptype);
11940 : }
11941 0 : else if (failure == 3)
11942 0 : error ("zero-size array %qT", *ptype);
11943 3 : *ptype = error_mark_node;
11944 : }
11945 1253 : return failure;
11946 : }
11947 :
11948 : /* Return zero if something is declared to be a member of type
11949 : CTYPE when in the context of CUR_TYPE. STRING is the error
11950 : message to print in that case. Otherwise, quietly return 1. */
11951 :
11952 : static int
11953 27161839 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
11954 : {
11955 27161839 : if (ctype && ctype != cur_type)
11956 : {
11957 0 : if (flags == DTOR_FLAG)
11958 0 : error ("destructor for alien class %qT cannot be a member", ctype);
11959 : else
11960 0 : error ("constructor for alien class %qT cannot be a member", ctype);
11961 0 : return 0;
11962 : }
11963 : return 1;
11964 : }
11965 :
11966 : /* Subroutine of `grokdeclarator'. */
11967 :
11968 : /* Generate errors possibly applicable for a given set of specifiers.
11969 : This is for ARM $7.1.2. */
11970 :
11971 : static void
11972 454756012 : bad_specifiers (tree object,
11973 : enum bad_spec_place type,
11974 : int virtualp,
11975 : int quals,
11976 : int inlinep,
11977 : int friendp,
11978 : int raises,
11979 : const location_t* locations)
11980 : {
11981 454756012 : switch (type)
11982 : {
11983 70220751 : case BSP_VAR:
11984 70220751 : if (virtualp)
11985 0 : error_at (locations[ds_virtual],
11986 : "%qD declared as a %<virtual%> variable", object);
11987 70220751 : if (quals)
11988 3 : error ("%<const%> and %<volatile%> function specifiers on "
11989 : "%qD invalid in variable declaration", object);
11990 : break;
11991 302161788 : case BSP_PARM:
11992 302161788 : if (virtualp)
11993 0 : error_at (locations[ds_virtual],
11994 : "%qD declared as a %<virtual%> parameter", object);
11995 302161788 : if (inlinep)
11996 6 : error_at (locations[ds_inline],
11997 : "%qD declared as an %<inline%> parameter", object);
11998 302161788 : if (quals)
11999 3 : error ("%<const%> and %<volatile%> function specifiers on "
12000 : "%qD invalid in parameter declaration", object);
12001 : break;
12002 48497558 : case BSP_TYPE:
12003 48497558 : if (virtualp)
12004 0 : error_at (locations[ds_virtual],
12005 : "%qD declared as a %<virtual%> type", object);
12006 48497558 : if (inlinep)
12007 6 : error_at (locations[ds_inline],
12008 : "%qD declared as an %<inline%> type", object);
12009 48497558 : if (quals)
12010 0 : error ("%<const%> and %<volatile%> function specifiers on "
12011 : "%qD invalid in type declaration", object);
12012 : break;
12013 33875915 : case BSP_FIELD:
12014 33875915 : if (virtualp)
12015 6 : error_at (locations[ds_virtual],
12016 : "%qD declared as a %<virtual%> field", object);
12017 33875915 : if (inlinep)
12018 6 : error_at (locations[ds_inline],
12019 : "%qD declared as an %<inline%> field", object);
12020 33875915 : if (quals)
12021 0 : error ("%<const%> and %<volatile%> function specifiers on "
12022 : "%qD invalid in field declaration", object);
12023 : break;
12024 0 : default:
12025 0 : gcc_unreachable();
12026 : }
12027 454756012 : if (friendp)
12028 0 : error ("%q+D declared as a friend", object);
12029 454756012 : if (raises
12030 131 : && !flag_noexcept_type
12031 454756037 : && (TREE_CODE (object) == TYPE_DECL
12032 19 : || (!TYPE_PTRFN_P (TREE_TYPE (object))
12033 5 : && !TYPE_REFFN_P (TREE_TYPE (object))
12034 4 : && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
12035 6 : error ("%q+D declared with an exception specification", object);
12036 454756012 : }
12037 :
12038 : /* DECL is a member function or static data member and is presently
12039 : being defined. Check that the definition is taking place in a
12040 : valid namespace. */
12041 :
12042 : static void
12043 100232684 : check_class_member_definition_namespace (tree decl)
12044 : {
12045 : /* These checks only apply to member functions and static data
12046 : members. */
12047 100232684 : gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
12048 : /* We check for problems with specializations in pt.cc in
12049 : check_specialization_namespace, where we can issue better
12050 : diagnostics. */
12051 100232684 : if (processing_specialization)
12052 : return;
12053 : /* We check this in check_explicit_instantiation_namespace. */
12054 100089729 : if (processing_explicit_instantiation)
12055 : return;
12056 : /* [class.mfct]
12057 :
12058 : A member function definition that appears outside of the
12059 : class definition shall appear in a namespace scope enclosing
12060 : the class definition.
12061 :
12062 : [class.static.data]
12063 :
12064 : The definition for a static data member shall appear in a
12065 : namespace scope enclosing the member's class definition. */
12066 100089649 : if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
12067 18 : permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
12068 18 : decl, DECL_CONTEXT (decl));
12069 : }
12070 :
12071 : /* Build a PARM_DECL for the "this" parameter of FN. TYPE is the
12072 : METHOD_TYPE for a non-static member function; QUALS are the
12073 : cv-qualifiers that apply to the function. */
12074 :
12075 : tree
12076 242807240 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
12077 : {
12078 242807240 : tree this_type;
12079 242807240 : tree qual_type;
12080 242807240 : tree parm;
12081 242807240 : cp_cv_quals this_quals;
12082 :
12083 242807240 : if (CLASS_TYPE_P (type))
12084 : {
12085 105950543 : this_type
12086 105950543 : = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
12087 105950543 : this_type = build_pointer_type (this_type);
12088 : }
12089 : else
12090 136856697 : this_type = type_of_this_parm (type);
12091 : /* The `this' parameter is implicitly `const'; it cannot be
12092 : assigned to. */
12093 242807240 : this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
12094 242807240 : qual_type = cp_build_qualified_type (this_type, this_quals);
12095 242807240 : parm = build_artificial_parm (fn, this_identifier, qual_type);
12096 242807240 : cp_apply_type_quals_to_decl (this_quals, parm);
12097 242807240 : return parm;
12098 : }
12099 :
12100 : /* DECL is a static member function. Complain if it was declared
12101 : with function-cv-quals. */
12102 :
12103 : static void
12104 10898978 : check_static_quals (tree decl, cp_cv_quals quals)
12105 : {
12106 0 : if (quals != TYPE_UNQUALIFIED)
12107 6 : error ("static member function %q#D declared with type qualifiers",
12108 : decl);
12109 0 : }
12110 :
12111 : /* Helper function. Replace the temporary this parameter injected
12112 : during cp_finish_omp_declare_simd with the real this parameter. */
12113 :
12114 : static tree
12115 2692 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
12116 : {
12117 2692 : tree this_parm = (tree) data;
12118 2692 : if (TREE_CODE (*tp) == PARM_DECL
12119 450 : && DECL_NAME (*tp) == this_identifier
12120 2965 : && *tp != this_parm)
12121 273 : *tp = this_parm;
12122 2419 : else if (TYPE_P (*tp))
12123 33 : *walk_subtrees = 0;
12124 2692 : return NULL_TREE;
12125 : }
12126 :
12127 : /* CTYPE is class type, or null if non-class.
12128 : TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
12129 : or METHOD_TYPE.
12130 : DECLARATOR is the function's name.
12131 : PARMS is a chain of PARM_DECLs for the function.
12132 : VIRTUALP is truthvalue of whether the function is virtual or not.
12133 : FLAGS are to be passed through to `grokclassfn'.
12134 : QUALS are qualifiers indicating whether the function is `const'
12135 : or `volatile'.
12136 : RAISES is a list of exceptions that this function can raise.
12137 : CHECK is 1 if we must find this method in CTYPE, 0 if we should
12138 : not look, and -1 if we should not call `grokclassfn' at all.
12139 :
12140 : SFK is the kind of special function (if any) for the new function.
12141 :
12142 : Returns `NULL_TREE' if something goes wrong, after issuing
12143 : applicable error messages. */
12144 :
12145 : static tree
12146 193386004 : grokfndecl (tree ctype,
12147 : tree type,
12148 : tree declarator,
12149 : tree parms,
12150 : tree orig_declarator,
12151 : const cp_decl_specifier_seq *declspecs,
12152 : tree decl_reqs,
12153 : int virtualp,
12154 : enum overload_flags flags,
12155 : cp_cv_quals quals,
12156 : cp_ref_qualifier rqual,
12157 : tree raises,
12158 : int check,
12159 : int friendp,
12160 : int publicp,
12161 : int inlinep,
12162 : int initialized,
12163 : bool xobj_func_p,
12164 : special_function_kind sfk,
12165 : bool funcdef_flag,
12166 : bool late_return_type_p,
12167 : int template_count,
12168 : tree in_namespace,
12169 : tree* attrlist,
12170 : tree contract_specifiers,
12171 : location_t location)
12172 : {
12173 193386004 : tree decl;
12174 193386004 : tree t;
12175 :
12176 193386004 : if (location == UNKNOWN_LOCATION)
12177 0 : location = input_location;
12178 :
12179 : /* Was the concept specifier present? */
12180 193386004 : bool concept_p = inlinep & 4;
12181 :
12182 193386004 : if (concept_p)
12183 : {
12184 15 : error_at (location, "function concepts are no longer supported");
12185 15 : return NULL_TREE;
12186 : }
12187 :
12188 : /* [except.spec]/9 - A deallocation function with no explicit noexcept-specifier
12189 : has a non-throwing exception specification. */
12190 193385989 : if (raises == NULL_TREE
12191 115712034 : && cxx_dialect >= cxx11
12192 139736812 : && IDENTIFIER_NEWDEL_OP_P (declarator)
12193 193450120 : && !IDENTIFIER_NEW_OP_P (declarator))
12194 852 : raises = noexcept_true_spec;
12195 :
12196 193385989 : type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
12197 :
12198 193385989 : decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
12199 :
12200 : /* Set the constraints on the declaration. */
12201 193385989 : if (flag_concepts)
12202 : {
12203 189139944 : tree tmpl_reqs = NULL_TREE;
12204 189139944 : tree ctx = friendp ? current_class_type : ctype;
12205 189139944 : bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
12206 189139944 : bool memtmpl = (!block_local
12207 189139944 : && (current_template_depth
12208 189081915 : > template_class_depth (ctx)));
12209 52216237 : if (memtmpl)
12210 : {
12211 52216237 : if (!current_template_parms)
12212 : /* If there are no template parameters, something must have
12213 : gone wrong. */
12214 0 : gcc_assert (seen_error ());
12215 : else
12216 52216237 : tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
12217 : }
12218 189139944 : tree ci = build_constraints (tmpl_reqs, decl_reqs);
12219 : /* C++20 CA378: Remove non-templated constrained functions. */
12220 : /* [temp.friend]/9 A non-template friend declaration with a
12221 : requires-clause shall be a definition. A friend function template with
12222 : a constraint that depends on a template parameter from an enclosing
12223 : template shall be a definition. */
12224 189139944 : if (ci
12225 10183890 : && (block_local
12226 10183887 : || !processing_template_decl
12227 10183826 : || (friendp && !memtmpl && !funcdef_flag)))
12228 : {
12229 73 : if (!friendp || !processing_template_decl)
12230 64 : error_at (location, "constraints on a non-templated function");
12231 : else
12232 9 : error_at (location, "constrained non-template friend declaration"
12233 : " must be a definition");
12234 : ci = NULL_TREE;
12235 : }
12236 189139944 : set_constraints (decl, ci);
12237 1272515 : if (ci && friendp && memtmpl && !funcdef_flag
12238 189177318 : && uses_outer_template_parms_in_constraints (decl, ctx))
12239 6 : error_at (location, "friend function template with constraints that "
12240 : "depend on outer template parameters must be a definition");
12241 : }
12242 :
12243 193385989 : if (TREE_CODE (type) == METHOD_TYPE)
12244 : {
12245 104488468 : tree parm = build_this_parm (decl, type, quals);
12246 104488468 : DECL_CHAIN (parm) = parms;
12247 104488468 : parms = parm;
12248 :
12249 : /* Allocate space to hold the vptr bit if needed. */
12250 104488468 : SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
12251 : }
12252 :
12253 193385989 : DECL_ARGUMENTS (decl) = parms;
12254 583988194 : for (t = parms; t; t = DECL_CHAIN (t))
12255 : {
12256 390602205 : DECL_CONTEXT (t) = decl;
12257 390602205 : if (flag_reflection
12258 7690790 : && initialized == SD_INITIALIZED
12259 392146517 : && DECL_ATTRIBUTES (t))
12260 3546 : for (tree a = DECL_ATTRIBUTES (t);
12261 3550 : (a = lookup_annotation (a));
12262 4 : a = TREE_CHAIN (a))
12263 : {
12264 4 : gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
12265 : /* Mark TREE_PURPOSE of the value that it is an annotation
12266 : on an argument of a function definition (rather than
12267 : annotation from function declaration). For function parameter
12268 : reflection all annotations are listed, while for variable_of
12269 : only those marked here. Annotation is marked as coming from
12270 : function definition's argument if it has TREE_PURPOSE
12271 : void_node or INTEGER_CST with signed type. */
12272 4 : tree val = TREE_VALUE (a);
12273 4 : gcc_assert (TREE_PURPOSE (val) == NULL_TREE);
12274 4 : TREE_PURPOSE (val) = void_node;
12275 : }
12276 : }
12277 :
12278 : /* Propagate volatile out from type to decl. */
12279 193385989 : if (TYPE_VOLATILE (type))
12280 0 : TREE_THIS_VOLATILE (decl) = 1;
12281 :
12282 : /* Setup decl according to sfk. */
12283 193385989 : switch (sfk)
12284 : {
12285 24807644 : case sfk_constructor:
12286 24807644 : case sfk_copy_constructor:
12287 24807644 : case sfk_move_constructor:
12288 24807644 : DECL_CXX_CONSTRUCTOR_P (decl) = 1;
12289 24807644 : DECL_NAME (decl) = ctor_identifier;
12290 24807644 : break;
12291 3330209 : case sfk_destructor:
12292 3330209 : DECL_CXX_DESTRUCTOR_P (decl) = 1;
12293 3330209 : DECL_NAME (decl) = dtor_identifier;
12294 3330209 : break;
12295 1252881 : case sfk_deduction_guide:
12296 : /* Give deduction guides a definition even though they don't really
12297 : have one: the restriction that you can't repeat a deduction guide
12298 : makes them more like a definition anyway. */
12299 1252881 : DECL_INITIAL (decl) = void_node;
12300 : /* But to ensure that external-linkage deduction guides in header units
12301 : don't fall afoul of [module.import] p6, mark them as inline. */
12302 1252881 : DECL_DECLARED_INLINE_P (decl) = true;
12303 1252881 : break;
12304 : default:
12305 : break;
12306 : }
12307 :
12308 193385989 : if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
12309 : {
12310 97396 : if (funcdef_flag)
12311 3 : error_at (location,
12312 : "defining explicit specialization %qD in friend declaration",
12313 : orig_declarator);
12314 : else
12315 : {
12316 97393 : tree fns = TREE_OPERAND (orig_declarator, 0);
12317 97393 : tree args = TREE_OPERAND (orig_declarator, 1);
12318 :
12319 97393 : if (PROCESSING_REAL_TEMPLATE_DECL_P ())
12320 : {
12321 : /* Something like `template <class T> friend void f<T>()'. */
12322 6 : error_at (location,
12323 : "invalid use of template-id %qD in declaration "
12324 : "of primary template",
12325 : orig_declarator);
12326 6 : return NULL_TREE;
12327 : }
12328 :
12329 : /* A friend declaration of the form friend void f<>(). Record
12330 : the information in the TEMPLATE_ID_EXPR. */
12331 97387 : SET_DECL_IMPLICIT_INSTANTIATION (decl);
12332 :
12333 97387 : gcc_assert (identifier_p (fns) || OVL_P (fns));
12334 97387 : DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
12335 :
12336 : /* Remember the befriending class like push_template_decl does for
12337 : template friends. */
12338 97387 : gcc_checking_assert (!DECL_CHAIN (decl));
12339 97387 : DECL_CHAIN (decl) = current_scope ();
12340 :
12341 314295 : for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
12342 216913 : if (TREE_PURPOSE (t)
12343 216913 : && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
12344 : {
12345 5 : error_at (defparse_location (TREE_PURPOSE (t)),
12346 : "default arguments are not allowed in declaration "
12347 : "of friend template specialization %qD",
12348 : decl);
12349 5 : return NULL_TREE;
12350 : }
12351 :
12352 97382 : if (inlinep & 1)
12353 : {
12354 5 : error_at (declspecs->locations[ds_inline],
12355 : "%<inline%> is not allowed in declaration of friend "
12356 : "template specialization %qD",
12357 : decl);
12358 5 : return NULL_TREE;
12359 : }
12360 : }
12361 : }
12362 :
12363 : /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
12364 : expression, that declaration shall be a definition..." */
12365 193385973 : if (friendp && !funcdef_flag)
12366 : {
12367 1878988 : bool has_errored = false;
12368 1878988 : for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
12369 5266755 : t && t != void_list_node; t = TREE_CHAIN (t))
12370 3387767 : if (TREE_PURPOSE (t))
12371 : {
12372 51 : enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
12373 : /* For templates, mark the default argument as erroneous and give a
12374 : hard error. */
12375 51 : if (processing_template_decl)
12376 : {
12377 33 : diag_kind = diagnostics::kind::error;
12378 33 : TREE_PURPOSE (t) = error_mark_node;
12379 : }
12380 51 : if (!has_errored)
12381 : {
12382 48 : has_errored = true;
12383 48 : emit_diagnostic (diag_kind,
12384 48 : DECL_SOURCE_LOCATION (decl),
12385 48 : /*diagnostics::option_id=*/0,
12386 : "friend declaration of %qD specifies default "
12387 : "arguments and isn%'t a definition", decl);
12388 : }
12389 : }
12390 : }
12391 :
12392 : /* If this decl has namespace scope, set that up. */
12393 193385973 : if (in_namespace)
12394 259689 : set_decl_namespace (decl, in_namespace, friendp);
12395 193126284 : else if (ctype)
12396 115301578 : DECL_CONTEXT (decl) = ctype;
12397 : else
12398 77824706 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
12399 :
12400 : /* `main' and builtins have implicit 'C' linkage. */
12401 193385973 : if (ctype == NULL_TREE
12402 78084395 : && DECL_FILE_SCOPE_P (decl)
12403 32143667 : && current_lang_name == lang_name_cplusplus
12404 196383441 : && (MAIN_NAME_P (declarator)
12405 2962443 : || (IDENTIFIER_LENGTH (declarator) > 10
12406 2117579 : && IDENTIFIER_POINTER (declarator)[0] == '_'
12407 1635122 : && IDENTIFIER_POINTER (declarator)[1] == '_'
12408 350646 : && startswith (IDENTIFIER_POINTER (declarator) + 2,
12409 : "builtin_"))
12410 2962425 : || (targetcm.cxx_implicit_extern_c
12411 0 : && (targetcm.cxx_implicit_extern_c
12412 0 : (IDENTIFIER_POINTER (declarator))))))
12413 35043 : SET_DECL_LANGUAGE (decl, lang_c);
12414 :
12415 193385973 : DECL_STATIC_FUNCTION_P (decl)
12416 193385973 : = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
12417 193385973 : DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
12418 :
12419 193385973 : if (initialized == SD_DELETED)
12420 4294503 : DECL_DELETED_FN (decl) = 1;
12421 :
12422 193385973 : if (ctype && funcdef_flag)
12423 99724476 : check_class_member_definition_namespace (decl);
12424 :
12425 193385973 : if (ctype == NULL_TREE && DECL_MAIN_P (decl))
12426 : {
12427 35031 : if (PROCESSING_REAL_TEMPLATE_DECL_P())
12428 9 : error_at (location, "cannot declare %<::main%> to be a template");
12429 35031 : if (inlinep & 1)
12430 3 : error_at (declspecs->locations[ds_inline],
12431 : "cannot declare %<::main%> to be inline");
12432 35031 : if (inlinep & 2)
12433 6 : error_at (declspecs->locations[ds_constexpr],
12434 : "cannot declare %<::main%> to be %qs", "constexpr");
12435 35031 : if (inlinep & 8)
12436 3 : error_at (declspecs->locations[ds_consteval],
12437 : "cannot declare %<::main%> to be %qs", "consteval");
12438 35031 : if (!publicp)
12439 0 : error_at (location, "cannot declare %<::main%> to be static");
12440 35031 : if (current_lang_name != lang_name_cplusplus)
12441 12 : pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
12442 : " linkage specification other than %<extern \"C++\"%>");
12443 35031 : if (module_attach_p ())
12444 : {
12445 3 : auto_diagnostic_group adg;
12446 3 : error_at (location, "cannot attach %<::main%> to a named module");
12447 3 : inform (location, "use %<extern \"C++\"%> to attach it to the "
12448 : "global module instead");
12449 3 : }
12450 : inlinep = 0;
12451 : publicp = 1;
12452 : }
12453 :
12454 : /* Members of anonymous types and local classes have no linkage; make
12455 : them internal. If a typedef is made later, this will be changed. */
12456 193385973 : if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
12457 : publicp = 0;
12458 193371614 : else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
12459 : /* But members of local classes in a module CMI should have their
12460 : definitions exported, in case they are (directly or indirectly)
12461 : used by an importer. We don't just use module_has_cmi_p here
12462 : because for entities in the GMF we don't yet know whether this
12463 : module will have a CMI, so we'll conservatively assume it might. */
12464 2394169 : publicp = module_maybe_has_cmi_p ();
12465 :
12466 193371614 : if (publicp && cxx_dialect == cxx98)
12467 : {
12468 : /* [basic.link]: A name with no linkage (notably, the name of a class
12469 : or enumeration declared in a local scope) shall not be used to
12470 : declare an entity with linkage.
12471 :
12472 : DR 757 relaxes this restriction for C++0x. */
12473 1055118 : no_linkage_error (decl);
12474 : }
12475 :
12476 193385973 : TREE_PUBLIC (decl) = publicp;
12477 193385973 : if (! publicp)
12478 : {
12479 2513212 : DECL_INTERFACE_KNOWN (decl) = 1;
12480 2513212 : DECL_NOT_REALLY_EXTERN (decl) = 1;
12481 : }
12482 :
12483 : /* If the declaration was declared inline, mark it as such. */
12484 193385973 : if (inlinep)
12485 : {
12486 74295249 : DECL_DECLARED_INLINE_P (decl) = 1;
12487 74295249 : if (publicp)
12488 74038054 : DECL_COMDAT (decl) = 1;
12489 : }
12490 74295249 : if (inlinep & 2)
12491 54796151 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
12492 138589822 : else if (inlinep & 8)
12493 : {
12494 1139031 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
12495 1139031 : SET_DECL_IMMEDIATE_FUNCTION_P (decl);
12496 : }
12497 :
12498 193385973 : DECL_EXTERNAL (decl) = 1;
12499 193385973 : if (TREE_CODE (type) == FUNCTION_TYPE)
12500 : {
12501 88897505 : if (quals || rqual)
12502 393 : TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
12503 : TYPE_UNQUALIFIED,
12504 : REF_QUAL_NONE);
12505 88897505 : auto_diagnostic_group d;
12506 88897505 : if (quals)
12507 621 : error (!ctype
12508 : ? G_("non-member function %qD cannot have cv-qualifier")
12509 : : !xobj_func_p
12510 297 : ? G_("static member function %qD cannot have cv-qualifier")
12511 : : G_("explicit object member function "
12512 : "%qD cannot have cv-qualifier"),
12513 : decl);
12514 88897505 : if (rqual)
12515 531 : error (!ctype
12516 : ? G_("non-member function %qD cannot have ref-qualifier")
12517 : : !xobj_func_p
12518 264 : ? G_("static member function %qD cannot have ref-qualifier")
12519 : : G_("explicit object member function "
12520 : "%qD cannot have ref-qualifier"),
12521 : decl);
12522 :
12523 88897505 : if (xobj_func_p && (quals || rqual))
12524 363 : inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
12525 : "explicit object parameter declared here");
12526 88897505 : quals = TYPE_UNQUALIFIED;
12527 88897505 : rqual = REF_QUAL_NONE;
12528 :
12529 88897505 : }
12530 :
12531 193385973 : if (deduction_guide_p (decl))
12532 : {
12533 1252881 : tree type = TREE_TYPE (DECL_NAME (decl));
12534 1252881 : if (in_namespace == NULL_TREE
12535 1252881 : && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
12536 : {
12537 3 : auto_diagnostic_group d;
12538 3 : error_at (location, "deduction guide %qD must be declared in the "
12539 : "same scope as %qT", decl, type);
12540 3 : inform (location_of (type), " declared here");
12541 3 : return NULL_TREE;
12542 3 : }
12543 2505756 : if (DECL_CLASS_SCOPE_P (decl)
12544 1252919 : && current_access_specifier != declared_access (TYPE_NAME (type)))
12545 : {
12546 3 : auto_diagnostic_group d;
12547 3 : error_at (location, "deduction guide %qD must have the same access "
12548 : "as %qT", decl, type);
12549 3 : inform (location_of (type), " declared here");
12550 3 : }
12551 1252878 : if (funcdef_flag)
12552 3 : error_at (location,
12553 : "deduction guide %qD must not have a function body", decl);
12554 : }
12555 358305994 : else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
12556 204278029 : && !grok_op_properties (decl, /*complain=*/true))
12557 : return NULL_TREE;
12558 192132945 : else if (UDLIT_OPER_P (DECL_NAME (decl)))
12559 : {
12560 313677 : bool long_long_unsigned_p;
12561 313677 : bool long_double_p;
12562 313677 : const char *suffix = NULL;
12563 : /* [over.literal]/6: Literal operators shall not have C linkage. */
12564 313677 : if (DECL_LANGUAGE (decl) == lang_c)
12565 : {
12566 6 : auto_diagnostic_group d;
12567 6 : error_at (location, "literal operator with C linkage");
12568 6 : maybe_show_extern_c_location ();
12569 6 : return NULL_TREE;
12570 6 : }
12571 :
12572 313671 : if (DECL_NAMESPACE_SCOPE_P (decl))
12573 : {
12574 313665 : if (!check_literal_operator_args (decl, &long_long_unsigned_p,
12575 : &long_double_p))
12576 : {
12577 42 : error_at (location, "%qD has invalid argument list", decl);
12578 42 : return NULL_TREE;
12579 : }
12580 :
12581 313623 : suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
12582 313623 : if (long_long_unsigned_p)
12583 : {
12584 46759 : if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
12585 68 : warning_at (location, 0, "integer suffix %qs"
12586 : " shadowed by implementation", suffix);
12587 : }
12588 266864 : else if (long_double_p)
12589 : {
12590 85688 : if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
12591 80 : warning_at (location, 0, "floating-point suffix %qs"
12592 : " shadowed by implementation", suffix);
12593 : }
12594 : /* 17.6.3.3.5 */
12595 313623 : if (suffix[0] != '_'
12596 313016 : && !current_function_decl && !(friendp && !funcdef_flag))
12597 313010 : warning_at (location, OPT_Wliteral_suffix,
12598 : "literal operator suffixes not preceded by %<_%>"
12599 : " are reserved for future standardization");
12600 : }
12601 : else
12602 : {
12603 6 : error_at (location, "%qD must be a non-member function", decl);
12604 6 : return NULL_TREE;
12605 : }
12606 : }
12607 :
12608 192132894 : if (funcdef_flag)
12609 : /* Make the init_value nonzero so pushdecl knows this is not
12610 : tentative. error_mark_node is replaced later with the BLOCK. */
12611 136451453 : DECL_INITIAL (decl) = error_mark_node;
12612 :
12613 193385769 : if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
12614 73239050 : TREE_NOTHROW (decl) = 1;
12615 :
12616 193385769 : if (flag_openmp || flag_openmp_simd)
12617 : {
12618 : /* Adjust "omp declare simd" attributes. */
12619 480675 : tree ods = lookup_attribute ("omp declare simd", *attrlist);
12620 480675 : if (ods)
12621 : {
12622 : tree attr;
12623 2033 : for (attr = ods; attr;
12624 1078 : attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
12625 : {
12626 1078 : if (TREE_CODE (type) == METHOD_TYPE)
12627 204 : walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
12628 : DECL_ARGUMENTS (decl), NULL);
12629 1078 : if (TREE_VALUE (attr) != NULL_TREE)
12630 : {
12631 872 : tree cl = TREE_VALUE (TREE_VALUE (attr));
12632 872 : cl = c_omp_declare_simd_clauses_to_numbers
12633 872 : (DECL_ARGUMENTS (decl), cl);
12634 872 : if (cl)
12635 872 : TREE_VALUE (TREE_VALUE (attr)) = cl;
12636 : else
12637 0 : TREE_VALUE (attr) = NULL_TREE;
12638 : }
12639 : }
12640 : }
12641 : }
12642 :
12643 : /* [basic.stc.dynamic.deallocation]/3 - A deallocation function shall not
12644 : have a potentially throwing exception specification. */
12645 193385769 : maybe_diagnose_deallocation_noexcept_false (decl);
12646 :
12647 : /* Caller will do the rest of this. */
12648 193385769 : if (check < 0)
12649 : {
12650 6669382 : if (decl && decl != error_mark_node && contract_specifiers)
12651 24 : set_fn_contract_specifiers (decl, contract_specifiers);
12652 6669382 : return decl;
12653 : }
12654 :
12655 186716387 : if (ctype != NULL_TREE)
12656 115301271 : grokclassfn (ctype, decl, flags);
12657 :
12658 : /* 12.4/3 */
12659 186716387 : if (cxx_dialect >= cxx11
12660 371338856 : && DECL_DESTRUCTOR_P (decl)
12661 3310988 : && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
12662 186884137 : && !processing_template_decl)
12663 85792 : deduce_noexcept_on_destructor (decl);
12664 :
12665 186716387 : set_originating_module (decl);
12666 :
12667 186716387 : decl = check_explicit_specialization (orig_declarator, decl,
12668 : template_count,
12669 186716387 : 2 * funcdef_flag +
12670 186716387 : 4 * (friendp != 0),
12671 : *attrlist);
12672 186716387 : if (decl == error_mark_node)
12673 : return NULL_TREE;
12674 :
12675 186716113 : if (DECL_STATIC_FUNCTION_P (decl))
12676 10721008 : check_static_quals (decl, quals);
12677 :
12678 186716113 : if (attrlist)
12679 : {
12680 186716113 : cplus_decl_attributes (&decl, *attrlist, 0);
12681 186716113 : *attrlist = NULL_TREE;
12682 : }
12683 :
12684 : /* Update now we have a decl and maybe know the return type. */
12685 186716113 : if (contract_specifiers)
12686 : {
12687 854 : tree t = decl;
12688 854 : if (TREE_CODE (decl) == TEMPLATE_DECL)
12689 3 : t = DECL_TEMPLATE_RESULT (decl);
12690 854 : set_fn_contract_specifiers (t, contract_specifiers);
12691 854 : rebuild_postconditions (t);
12692 : }
12693 :
12694 : /* Check main's type after attributes have been applied. */
12695 186716113 : if (ctype == NULL_TREE && DECL_MAIN_P (decl))
12696 : {
12697 35019 : if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
12698 : integer_type_node))
12699 : {
12700 20 : tree dtype = TREE_TYPE (decl);
12701 20 : tree oldtypeargs = TYPE_ARG_TYPES (dtype);
12702 20 : tree newtype;
12703 20 : error_at (declspecs->locations[ds_type_spec],
12704 : "%<::main%> must return %<int%>");
12705 60 : newtype = build_function_type (integer_type_node, oldtypeargs,
12706 20 : TYPE_NO_NAMED_ARGS_STDARG_P (dtype));
12707 20 : TREE_TYPE (decl) = newtype;
12708 : }
12709 35019 : if (warn_main)
12710 34997 : check_main_parameter_types (decl);
12711 : }
12712 :
12713 186716113 : if (ctype != NULL_TREE && check)
12714 : {
12715 9183745 : tree old_decl = check_classfn (ctype, decl,
12716 9183745 : (current_template_depth
12717 9183745 : > template_class_depth (ctype))
12718 2239990 : ? current_template_parms
12719 : : NULL_TREE);
12720 :
12721 9183745 : if (old_decl == error_mark_node)
12722 : return NULL_TREE;
12723 :
12724 9183637 : if (old_decl)
12725 : {
12726 8785549 : tree ok;
12727 8785549 : tree pushed_scope;
12728 :
12729 8785549 : if (TREE_CODE (old_decl) == TEMPLATE_DECL)
12730 : /* Because grokfndecl is always supposed to return a
12731 : FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
12732 : here. We depend on our callers to figure out that its
12733 : really a template that's being returned. */
12734 2239978 : old_decl = DECL_TEMPLATE_RESULT (old_decl);
12735 :
12736 8785549 : if (DECL_STATIC_FUNCTION_P (old_decl)
12737 8785549 : && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
12738 : {
12739 : /* Remove the `this' parm added by grokclassfn. */
12740 177970 : revert_static_member_fn (decl);
12741 177970 : check_static_quals (decl, quals);
12742 : }
12743 8785549 : if (DECL_ARTIFICIAL (old_decl))
12744 : {
12745 9 : error ("definition of implicitly-declared %qD", old_decl);
12746 9 : return NULL_TREE;
12747 : }
12748 8785540 : else if (DECL_DEFAULTED_FN (old_decl))
12749 : {
12750 3 : auto_diagnostic_group d;
12751 3 : error ("definition of explicitly-defaulted %q+D", decl);
12752 3 : inform (DECL_SOURCE_LOCATION (old_decl),
12753 : "%q#D explicitly defaulted here", old_decl);
12754 3 : return NULL_TREE;
12755 3 : }
12756 :
12757 8785537 : if (modules_p () && !module_may_redeclare (old_decl))
12758 : return NULL_TREE;
12759 :
12760 : /* Since we've smashed OLD_DECL to its
12761 : DECL_TEMPLATE_RESULT, we must do the same to DECL. */
12762 8785477 : if (TREE_CODE (decl) == TEMPLATE_DECL)
12763 1037 : decl = DECL_TEMPLATE_RESULT (decl);
12764 :
12765 : /* Attempt to merge the declarations. This can fail, in
12766 : the case of some invalid specialization declarations. */
12767 8785477 : pushed_scope = push_scope (ctype);
12768 8785477 : ok = duplicate_decls (decl, old_decl);
12769 8785477 : if (pushed_scope)
12770 8785477 : pop_scope (pushed_scope);
12771 8785477 : if (!ok)
12772 : {
12773 0 : error ("no %q#D member function declared in class %qT",
12774 : decl, ctype);
12775 0 : return NULL_TREE;
12776 : }
12777 8785477 : if (ok == error_mark_node)
12778 : return NULL_TREE;
12779 : return old_decl;
12780 : }
12781 : }
12782 :
12783 355860912 : if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
12784 : return NULL_TREE;
12785 :
12786 : /* Don't call check_consteval_only_fn for defaulted functions. Those are
12787 : immediate-escalating functions but at this point DECL_DEFAULTED_P has
12788 : not been set. */
12789 177930453 : if (initialized != SD_DEFAULTED)
12790 171158077 : check_consteval_only_fn (decl);
12791 :
12792 177930453 : if (ctype == NULL_TREE || check)
12793 71812999 : return decl;
12794 :
12795 106117454 : if (virtualp)
12796 4202367 : DECL_VIRTUAL_P (decl) = 1;
12797 :
12798 106117454 : return decl;
12799 : }
12800 :
12801 : /* decl is a FUNCTION_DECL.
12802 : specifiers are the parsed virt-specifiers.
12803 :
12804 : Set flags to reflect the virt-specifiers.
12805 :
12806 : Returns decl. */
12807 :
12808 : static tree
12809 112786933 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
12810 : {
12811 112786933 : if (decl == NULL_TREE)
12812 : return decl;
12813 112786836 : if (specifiers & VIRT_SPEC_OVERRIDE)
12814 333525 : DECL_OVERRIDE_P (decl) = 1;
12815 112786836 : if (specifiers & VIRT_SPEC_FINAL)
12816 9911 : DECL_FINAL_P (decl) = 1;
12817 : return decl;
12818 : }
12819 :
12820 : /* DECL is a VAR_DECL for a static data member. Set flags to reflect
12821 : the linkage that DECL will receive in the object file. */
12822 :
12823 : static void
12824 13960486 : set_linkage_for_static_data_member (tree decl)
12825 : {
12826 : /* A static data member always has static storage duration and
12827 : external linkage. Note that static data members are forbidden in
12828 : local classes -- the only situation in which a class has
12829 : non-external linkage. */
12830 13960486 : TREE_PUBLIC (decl) = 1;
12831 13960486 : TREE_STATIC (decl) = 1;
12832 : /* For non-template classes, static data members are always put
12833 : out in exactly those files where they are defined, just as
12834 : with ordinary namespace-scope variables. */
12835 13960486 : if (!processing_template_decl)
12836 10648787 : DECL_INTERFACE_KNOWN (decl) = 1;
12837 13960486 : }
12838 :
12839 : /* Create a VAR_DECL named NAME with the indicated TYPE.
12840 :
12841 : If SCOPE is non-NULL, it is the class type or namespace containing
12842 : the variable. If SCOPE is NULL, the variable should is created in
12843 : the innermost enclosing scope. */
12844 :
12845 : static tree
12846 70220843 : grokvardecl (tree type,
12847 : tree name,
12848 : tree orig_declarator,
12849 : const cp_decl_specifier_seq *declspecs,
12850 : int initialized,
12851 : int type_quals,
12852 : int inlinep,
12853 : bool conceptp,
12854 : int template_count,
12855 : tree scope,
12856 : location_t location)
12857 : {
12858 70220843 : tree decl;
12859 70220843 : tree explicit_scope;
12860 :
12861 70220843 : gcc_assert (!name || identifier_p (name));
12862 :
12863 70220843 : bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
12864 70220843 : bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
12865 :
12866 : /* Compute the scope in which to place the variable, but remember
12867 : whether or not that scope was explicitly specified by the user. */
12868 70220843 : explicit_scope = scope;
12869 70220843 : if (!scope)
12870 : {
12871 : /* An explicit "extern" specifier indicates a namespace-scope
12872 : variable. */
12873 69696391 : if (declspecs->storage_class == sc_extern)
12874 557729 : scope = current_decl_namespace ();
12875 69138662 : else if (!at_function_scope_p ())
12876 7353517 : scope = current_scope ();
12877 : }
12878 :
12879 69696391 : if (scope
12880 8435698 : && (/* If the variable is a namespace-scope variable declared in a
12881 : template, we need DECL_LANG_SPECIFIC. */
12882 8435698 : (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
12883 : /* Similarly for namespace-scope variables with language linkage
12884 : other than C++. */
12885 7927490 : || (TREE_CODE (scope) == NAMESPACE_DECL
12886 4538203 : && current_lang_name != lang_name_cplusplus)
12887 : /* Similarly for static data members. */
12888 4809380 : || TYPE_P (scope)
12889 : /* Similarly for explicit specializations. */
12890 4301172 : || (orig_declarator
12891 4300328 : && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
12892 5035357 : decl = build_lang_decl_loc (location, VAR_DECL, name, type);
12893 : else
12894 65185486 : decl = build_decl (location, VAR_DECL, name, type);
12895 :
12896 70220843 : if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
12897 16244 : set_decl_namespace (decl, explicit_scope, 0);
12898 : else
12899 70204599 : DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
12900 :
12901 70220843 : if (declspecs->storage_class == sc_extern)
12902 : {
12903 557729 : DECL_THIS_EXTERN (decl) = 1;
12904 557729 : DECL_EXTERNAL (decl) = !initialized;
12905 : }
12906 :
12907 70220843 : if (DECL_CLASS_SCOPE_P (decl))
12908 : {
12909 508208 : set_linkage_for_static_data_member (decl);
12910 : /* This function is only called with out-of-class definitions. */
12911 508208 : DECL_EXTERNAL (decl) = 0;
12912 508208 : check_class_member_definition_namespace (decl);
12913 : }
12914 : /* At top level, either `static' or no s.c. makes a definition
12915 : (perhaps tentative), and absence of `static' makes it public. */
12916 69712635 : else if (toplevel_bindings_p ())
12917 : {
12918 15852652 : TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
12919 7926326 : && (DECL_THIS_EXTERN (decl)
12920 7330357 : || ! constp
12921 7330357 : || volatilep
12922 7251352 : || inlinep
12923 596024 : || in_template_context
12924 31061 : || processing_specialization
12925 30978 : || module_attach_p ()));
12926 7926326 : TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
12927 : }
12928 : /* Not at top level, only `static' makes a static definition. */
12929 : else
12930 : {
12931 61786309 : TREE_STATIC (decl) = declspecs->storage_class == sc_static;
12932 61786309 : TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
12933 : }
12934 :
12935 70220843 : set_originating_module (decl);
12936 :
12937 70220843 : if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
12938 : {
12939 20025 : if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
12940 : {
12941 20017 : CP_DECL_THREAD_LOCAL_P (decl) = true;
12942 : // NB: Set a tentative TLS model to avoid tls_model attribute
12943 : // warnings due to lack of thread storage duration. It will
12944 : // be updated by cplus_decl_attributes later.
12945 20017 : if (!processing_template_decl)
12946 19892 : set_decl_tls_model (decl, TLS_MODEL_REAL);
12947 : }
12948 20025 : if (declspecs->gnu_thread_keyword_p)
12949 19018 : SET_DECL_GNU_TLS_P (decl);
12950 : }
12951 :
12952 : /* If the type of the decl has no linkage, make sure that we'll
12953 : notice that in mark_used. */
12954 70220843 : if (cxx_dialect > cxx98
12955 69943725 : && decl_linkage (decl) != lk_none
12956 69233172 : && DECL_LANG_SPECIFIC (decl) == NULL
12957 64117873 : && !DECL_EXTERN_C_P (decl)
12958 134338716 : && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
12959 4594 : retrofit_lang_decl (decl);
12960 :
12961 70220843 : if (TREE_PUBLIC (decl))
12962 : {
12963 : /* [basic.link]: A name with no linkage (notably, the name of a class
12964 : or enumeration declared in a local scope) shall not be used to
12965 : declare an entity with linkage.
12966 :
12967 : DR 757 relaxes this restriction for C++0x. */
12968 8365324 : if (cxx_dialect < cxx11)
12969 22373 : no_linkage_error (decl);
12970 : }
12971 : else
12972 61855519 : DECL_INTERFACE_KNOWN (decl) = 1;
12973 :
12974 70220843 : if (DECL_NAME (decl)
12975 70220843 : && MAIN_NAME_P (DECL_NAME (decl)))
12976 : {
12977 12 : if (scope == global_namespace)
12978 6 : error_at (DECL_SOURCE_LOCATION (decl),
12979 : "cannot declare %<::main%> to be a global variable");
12980 6 : else if (DECL_EXTERN_C_P (decl))
12981 3 : error_at (DECL_SOURCE_LOCATION (decl),
12982 : "an entity named %<main%> cannot be declared with "
12983 : "C language linkage");
12984 : }
12985 :
12986 : /* Check if a variable is being declared as a concept. */
12987 70220843 : if (conceptp)
12988 : {
12989 30 : if (!processing_template_decl)
12990 13 : error_at (declspecs->locations[ds_concept],
12991 : "a non-template variable cannot be %<concept%>");
12992 17 : else if (!at_namespace_scope_p ())
12993 2 : error_at (declspecs->locations[ds_concept],
12994 : "concept must be defined at namespace scope");
12995 : else
12996 15 : error_at (declspecs->locations[ds_concept],
12997 : "variable concepts are no longer supported");
12998 30 : return NULL_TREE;
12999 : }
13000 70220813 : else if (flag_concepts
13001 70220813 : && current_template_depth > template_class_depth (scope))
13002 : {
13003 60454894 : tree ci = current_template_constraints ();
13004 60454894 : set_constraints (decl, ci);
13005 : }
13006 :
13007 : // Handle explicit specializations and instantiations of variable templates.
13008 70220813 : if (orig_declarator)
13009 69502329 : decl = check_explicit_specialization (orig_declarator, decl,
13010 : template_count, 0);
13011 :
13012 70220813 : return decl != error_mark_node ? decl : NULL_TREE;
13013 : }
13014 :
13015 : /* Create and return a canonical pointer to member function type, for
13016 : TYPE, which is a POINTER_TYPE to a METHOD_TYPE. */
13017 :
13018 : tree
13019 3110331 : build_ptrmemfunc_type (tree type)
13020 : {
13021 3110331 : tree field, fields;
13022 3110331 : tree t;
13023 :
13024 3110331 : if (type == error_mark_node)
13025 : return type;
13026 :
13027 : /* Make sure that we always have the unqualified pointer-to-member
13028 : type first. */
13029 3110331 : if (cp_cv_quals quals = cp_type_quals (type))
13030 : {
13031 0 : tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
13032 0 : return cp_build_qualified_type (unqual, quals);
13033 : }
13034 :
13035 : /* If a canonical type already exists for this type, use it. We use
13036 : this method instead of type_hash_canon, because it only does a
13037 : simple equality check on the list of field members. */
13038 :
13039 3110331 : t = TYPE_PTRMEMFUNC_TYPE (type);
13040 3110331 : if (t)
13041 : return t;
13042 :
13043 1039575 : t = make_node (RECORD_TYPE);
13044 :
13045 : /* Let the front end know this is a pointer to member function. */
13046 1039575 : TYPE_PTRMEMFUNC_FLAG (t) = 1;
13047 :
13048 1039575 : field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
13049 1039575 : DECL_NONADDRESSABLE_P (field) = 1;
13050 1039575 : fields = field;
13051 :
13052 1039575 : field = build_decl (input_location, FIELD_DECL, delta_identifier,
13053 : delta_type_node);
13054 1039575 : DECL_NONADDRESSABLE_P (field) = 1;
13055 1039575 : DECL_CHAIN (field) = fields;
13056 1039575 : fields = field;
13057 :
13058 1039575 : finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
13059 :
13060 : /* Zap out the name so that the back end will give us the debugging
13061 : information for this anonymous RECORD_TYPE. */
13062 1039575 : TYPE_NAME (t) = NULL_TREE;
13063 :
13064 : /* Cache this pointer-to-member type so that we can find it again
13065 : later. */
13066 1039575 : TYPE_PTRMEMFUNC_TYPE (type) = t;
13067 :
13068 1039575 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
13069 517320 : SET_TYPE_STRUCTURAL_EQUALITY (t);
13070 522255 : else if (TYPE_CANONICAL (type) != type)
13071 330956 : TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
13072 :
13073 : return t;
13074 : }
13075 :
13076 : /* Create and return a pointer to data member type. */
13077 :
13078 : tree
13079 331448 : build_ptrmem_type (tree class_type, tree member_type)
13080 : {
13081 331448 : if (TREE_CODE (member_type) == METHOD_TYPE)
13082 : {
13083 60135 : cp_cv_quals quals = type_memfn_quals (member_type);
13084 60135 : cp_ref_qualifier rqual = type_memfn_rqual (member_type);
13085 60135 : member_type = build_memfn_type (member_type, class_type, quals, rqual);
13086 60135 : return build_ptrmemfunc_type (build_pointer_type (member_type));
13087 : }
13088 : else
13089 : {
13090 271313 : gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
13091 271313 : return build_offset_type (class_type, member_type);
13092 : }
13093 : }
13094 :
13095 : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
13096 : Check to see that the definition is valid. Issue appropriate error
13097 : messages. */
13098 :
13099 : static void
13100 19096139 : check_static_variable_definition (tree decl, tree type)
13101 : {
13102 : /* Avoid redundant diagnostics on out-of-class definitions. */
13103 19096139 : if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
13104 : ;
13105 : /* Can't check yet if we don't know the type. */
13106 17683045 : else if (dependent_type_p (type))
13107 : ;
13108 : /* If DECL is declared constexpr, we'll do the appropriate checks
13109 : in check_initializer. Similarly for inline static data members. */
13110 17138540 : else if (DECL_P (decl)
13111 17138540 : && (DECL_DECLARED_CONSTEXPR_P (decl)
13112 2736701 : || DECL_VAR_DECLARED_INLINE_P (decl)))
13113 : ;
13114 2736202 : else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
13115 : {
13116 60 : if (!COMPLETE_TYPE_P (type))
13117 11 : error_at (DECL_SOURCE_LOCATION (decl),
13118 : "in-class initialization of static data member %q#D of "
13119 : "incomplete type", decl);
13120 49 : else if (literal_type_p (type))
13121 43 : permerror (DECL_SOURCE_LOCATION (decl),
13122 : "%<constexpr%> needed for in-class initialization of "
13123 : "static data member %q#D of non-integral type", decl);
13124 : else
13125 6 : error_at (DECL_SOURCE_LOCATION (decl),
13126 : "in-class initialization of static data member %q#D of "
13127 : "non-literal type", decl);
13128 : }
13129 : /* Motion 10 at San Diego: If a static const integral data member is
13130 : initialized with an integral constant expression, the initializer
13131 : may appear either in the declaration (within the class), or in
13132 : the definition, but not both. If it appears in the class, the
13133 : member is a member constant. The file-scope definition is always
13134 : required. */
13135 2736142 : else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
13136 11 : error_at (DECL_SOURCE_LOCATION (decl),
13137 : "invalid in-class initialization of static data member "
13138 : "of non-integral type %qT",
13139 : type);
13140 2736131 : else if (!CP_TYPE_CONST_P (type))
13141 5 : error_at (DECL_SOURCE_LOCATION (decl),
13142 : "ISO C++ forbids in-class initialization of non-const "
13143 : "static member %qD",
13144 : decl);
13145 2736126 : else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
13146 5 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
13147 : "ISO C++ forbids initialization of member constant "
13148 : "%qD of non-integral type %qT", decl, type);
13149 19096139 : }
13150 :
13151 : /* *expr_p is part of the TYPE_SIZE of a variably-sized array. If any
13152 : SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
13153 : expressions out into temporary variables so that walk_tree doesn't
13154 : step into them (c++/15764). */
13155 :
13156 : static tree
13157 3574 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
13158 : {
13159 3574 : hash_set<tree> *pset = (hash_set<tree> *)data;
13160 3574 : tree expr = *expr_p;
13161 3574 : if (TREE_CODE (expr) == SAVE_EXPR)
13162 : {
13163 1568 : tree op = TREE_OPERAND (expr, 0);
13164 1568 : cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
13165 1568 : if (TREE_SIDE_EFFECTS (op))
13166 56 : TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
13167 1568 : *walk_subtrees = 0;
13168 : }
13169 2006 : else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
13170 1831 : *walk_subtrees = 0;
13171 3574 : return NULL;
13172 : }
13173 :
13174 : /* Entry point for the above. */
13175 :
13176 : static void
13177 1627 : stabilize_vla_size (tree size)
13178 : {
13179 1627 : hash_set<tree> pset;
13180 : /* Break out any function calls into temporary variables. */
13181 1627 : cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
13182 1627 : }
13183 :
13184 : /* Reduce a SIZEOF_EXPR to its value. */
13185 :
13186 : tree
13187 12235779 : fold_sizeof_expr (tree t)
13188 : {
13189 12235779 : tree r;
13190 12235779 : if (SIZEOF_EXPR_TYPE_P (t))
13191 11649901 : r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
13192 11649901 : TREE_TYPE (TREE_OPERAND (t, 0)),
13193 : SIZEOF_EXPR, false, false);
13194 585878 : else if (TYPE_P (TREE_OPERAND (t, 0)))
13195 0 : r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
13196 0 : TREE_OPERAND (t, 0), SIZEOF_EXPR,
13197 : false, false);
13198 : else
13199 585878 : r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
13200 585878 : TREE_OPERAND (t, 0), SIZEOF_EXPR,
13201 : false, false);
13202 12235779 : if (r == error_mark_node)
13203 67 : r = size_one_node;
13204 12235779 : r = cp_fold_convert (size_type_node, r);
13205 12235779 : return r;
13206 : }
13207 :
13208 : /* Given the SIZE (i.e., number of elements) in an array, compute
13209 : an appropriate index type for the array. If non-NULL, NAME is
13210 : the name of the entity being declared. */
13211 :
13212 : static tree
13213 3488210 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
13214 : tsubst_flags_t complain)
13215 : {
13216 3488210 : if (error_operand_p (size))
13217 32 : return error_mark_node;
13218 :
13219 : /* The type of the index being computed. */
13220 3488178 : tree itype;
13221 :
13222 : /* The original numeric size as seen in the source code before
13223 : conversion to size_t. */
13224 3488178 : tree origsize = size;
13225 :
13226 3488178 : location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
13227 :
13228 3488178 : if (!type_dependent_expression_p (size))
13229 : {
13230 3440312 : origsize = size = mark_rvalue_use (size);
13231 :
13232 35918 : if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
13233 3440472 : && TREE_SIDE_EFFECTS (size))
13234 : /* In C++98, we mark a non-constant array bound with a magic
13235 : NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case. */;
13236 : else
13237 : {
13238 3440311 : size = build_converted_constant_expr (size_type_node, size, complain);
13239 : /* Pedantically a constant expression is required here and so
13240 : __builtin_is_constant_evaluated () should fold to true if it
13241 : is successfully folded into a constant. */
13242 3440311 : size = fold_non_dependent_expr (size, complain,
13243 : /*manifestly_const_eval=*/true);
13244 :
13245 3440311 : if (!TREE_CONSTANT (size))
13246 137448 : size = origsize;
13247 : }
13248 :
13249 3440312 : if (error_operand_p (size))
13250 3 : return error_mark_node;
13251 :
13252 : /* The array bound must be an integer type. */
13253 3440309 : tree type = TREE_TYPE (size);
13254 3440309 : if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
13255 : {
13256 21 : if (!(complain & tf_error))
13257 0 : return error_mark_node;
13258 21 : if (name)
13259 18 : error_at (loc, "size of array %qD has non-integral type %qT",
13260 : name, type);
13261 : else
13262 3 : error_at (loc, "size of array has non-integral type %qT", type);
13263 21 : size = integer_one_node;
13264 : }
13265 : }
13266 :
13267 : /* A type is dependent if it is...an array type constructed from any
13268 : dependent type or whose size is specified by a constant expression
13269 : that is value-dependent. */
13270 : /* We can only call value_dependent_expression_p on integral constant
13271 : expressions. */
13272 3488175 : if (processing_template_decl
13273 1594711 : && potential_constant_expression (size)
13274 5082861 : && value_dependent_expression_p (size))
13275 : {
13276 : /* Just build the index type and mark that it requires
13277 : structural equality checks. */
13278 886462 : in_template:
13279 886462 : itype = build_index_type (build_min (MINUS_EXPR, sizetype,
13280 : size, size_one_node));
13281 886462 : TYPE_DEPENDENT_P (itype) = 1;
13282 886462 : TYPE_DEPENDENT_P_VALID (itype) = 1;
13283 886462 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
13284 886462 : return itype;
13285 : }
13286 :
13287 2618188 : if (TREE_CODE (size) != INTEGER_CST)
13288 : {
13289 18716 : tree folded = cp_fully_fold (size);
13290 18716 : if (TREE_CODE (folded) == INTEGER_CST)
13291 : {
13292 264 : if (name)
13293 190 : pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
13294 : "integral constant-expression", name);
13295 : else
13296 74 : pedwarn (loc, OPT_Wpedantic,
13297 : "size of array is not an integral constant-expression");
13298 : }
13299 18716 : if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
13300 : /* We might have lost the TREE_CONSTANT flag e.g. when we are
13301 : folding a conversion from a pointer to integral type. In that
13302 : case issue an error below and don't treat this as a VLA. */;
13303 : else
13304 : /* Use the folded result for VLAs, too; it will have resolved
13305 : SIZEOF_EXPR. */
13306 : size = folded;
13307 : }
13308 :
13309 : /* Normally, the array-bound will be a constant. */
13310 2618188 : if (TREE_CODE (size) == INTEGER_CST)
13311 : {
13312 : /* The size to use in diagnostics that reflects the constant
13313 : size used in the source, rather than SIZE massaged above. */
13314 2599736 : tree diagsize = size;
13315 :
13316 : /* If the original size before conversion to size_t was signed
13317 : and negative, convert it to ssizetype to restore the sign. */
13318 2599736 : if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
13319 : && TREE_CODE (size) == INTEGER_CST
13320 2599736 : && tree_int_cst_sign_bit (size))
13321 : {
13322 283 : diagsize = fold_convert (ssizetype, size);
13323 :
13324 : /* Clear the overflow bit that may have been set as a result
13325 : of the conversion from the sizetype of the new size to
13326 : ssizetype. */
13327 283 : TREE_OVERFLOW (diagsize) = false;
13328 : }
13329 :
13330 : /* Verify that the array has a positive number of elements
13331 : and issue the appropriate diagnostic if it doesn't. */
13332 2599736 : if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
13333 : {
13334 514 : if (!(complain & tf_error))
13335 15 : return error_mark_node;
13336 499 : size = integer_one_node;
13337 : }
13338 : /* As an extension we allow zero-sized arrays. */
13339 2599222 : else if (integer_zerop (size))
13340 : {
13341 3196 : if (!(complain & tf_error))
13342 : /* We must fail if performing argument deduction (as
13343 : indicated by the state of complain), so that
13344 : another substitution can be found. */
13345 8 : return error_mark_node;
13346 3188 : else if (name)
13347 2894 : pedwarn (loc, OPT_Wpedantic,
13348 : "ISO C++ forbids zero-size array %qD", name);
13349 : else
13350 294 : pedwarn (loc, OPT_Wpedantic,
13351 : "ISO C++ forbids zero-size array");
13352 : }
13353 : }
13354 18452 : else if (TREE_CONSTANT (size)
13355 : /* We don't allow VLAs at non-function scopes, or during
13356 : tentative template substitution. */
13357 18437 : || !at_function_scope_p ()
13358 36560 : || !(complain & tf_error))
13359 : {
13360 350 : if (!(complain & tf_error))
13361 299 : return error_mark_node;
13362 : /* `(int) &fn' is not a valid array bound. */
13363 51 : if (name)
13364 37 : error_at (loc,
13365 : "size of array %qD is not an integral constant-expression",
13366 : name);
13367 : else
13368 14 : error_at (loc, "size of array is not an integral constant-expression");
13369 51 : size = integer_one_node;
13370 : }
13371 18102 : else if (pedantic && warn_vla != 0)
13372 : {
13373 30 : if (name)
13374 15 : pedwarn (name_loc, OPT_Wvla,
13375 : "ISO C++ forbids variable length array %qD", name);
13376 : else
13377 15 : pedwarn (input_location, OPT_Wvla,
13378 : "ISO C++ forbids variable length array");
13379 : }
13380 18072 : else if (warn_vla > 0)
13381 : {
13382 3 : if (name)
13383 3 : warning_at (name_loc, OPT_Wvla,
13384 : "variable length array %qD is used", name);
13385 : else
13386 0 : warning (OPT_Wvla,
13387 : "variable length array is used");
13388 : }
13389 :
13390 2617866 : if (processing_template_decl && !TREE_CONSTANT (size))
13391 16475 : goto in_template;
13392 : else
13393 : {
13394 2601391 : if (!TREE_CONSTANT (size))
13395 : {
13396 : /* A variable sized array. Arrange for the SAVE_EXPR on the inside
13397 : of the MINUS_EXPR, which allows the -1 to get folded with the +1
13398 : that happens when building TYPE_SIZE. */
13399 1627 : size = variable_size (size);
13400 1627 : stabilize_vla_size (size);
13401 : }
13402 :
13403 : /* Compute the index of the largest element in the array. It is
13404 : one less than the number of elements in the array. We save
13405 : and restore PROCESSING_TEMPLATE_DECL so that computations in
13406 : cp_build_binary_op will be appropriately folded. */
13407 2601391 : {
13408 2601391 : processing_template_decl_sentinel s;
13409 2601391 : itype = cp_build_binary_op (input_location,
13410 : MINUS_EXPR,
13411 : cp_convert (ssizetype, size, complain),
13412 : cp_convert (ssizetype, integer_one_node,
13413 : complain),
13414 : complain);
13415 2601391 : itype = maybe_constant_value (itype, NULL_TREE, mce_true);
13416 2601391 : }
13417 :
13418 2601391 : if (!TREE_CONSTANT (itype))
13419 : {
13420 1627 : if (sanitize_flags_p (SANITIZE_VLA)
13421 1627 : && current_function_decl != NULL_TREE)
13422 : {
13423 : /* We have to add 1 -- in the ubsan routine we generate
13424 : LE_EXPR rather than LT_EXPR. */
13425 78 : tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
13426 : build_one_cst (TREE_TYPE (itype)));
13427 78 : t = ubsan_instrument_vla (input_location, t);
13428 78 : finish_expr_stmt (t);
13429 : }
13430 : }
13431 : /* Make sure that there was no overflow when creating to a signed
13432 : index type. (For example, on a 32-bit machine, an array with
13433 : size 2^32 - 1 is too big.) */
13434 2599764 : else if (TREE_CODE (itype) == INTEGER_CST
13435 2599764 : && TREE_OVERFLOW (itype))
13436 : {
13437 0 : if (!(complain & tf_error))
13438 0 : return error_mark_node;
13439 0 : error ("overflow in array dimension");
13440 0 : TREE_OVERFLOW (itype) = 0;
13441 : }
13442 : }
13443 :
13444 : /* Create and return the appropriate index type. */
13445 2601391 : itype = build_index_type (itype);
13446 :
13447 : /* If the index type were dependent, we would have returned early, so
13448 : remember that it isn't. */
13449 2601391 : TYPE_DEPENDENT_P (itype) = 0;
13450 2601391 : TYPE_DEPENDENT_P_VALID (itype) = 1;
13451 2601391 : return itype;
13452 : }
13453 :
13454 : tree
13455 611389 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
13456 : {
13457 611389 : return compute_array_index_type_loc (input_location, name, size, complain);
13458 : }
13459 :
13460 : /* Returns the scope (if any) in which the entity declared by
13461 : DECLARATOR will be located. If the entity was declared with an
13462 : unqualified name, NULL_TREE is returned. */
13463 :
13464 : tree
13465 771382165 : get_scope_of_declarator (const cp_declarator *declarator)
13466 : {
13467 893923114 : while (declarator && declarator->kind != cdk_id)
13468 122540949 : declarator = declarator->declarator;
13469 :
13470 : /* If the declarator-id is a SCOPE_REF, the scope in which the
13471 : declaration occurs is the first operand. */
13472 771382165 : if (declarator
13473 770122092 : && declarator->u.id.qualifying_scope)
13474 : return declarator->u.id.qualifying_scope;
13475 :
13476 : /* Otherwise, the declarator is not a qualified name; the entity will
13477 : be declared in the current scope. */
13478 : return NULL_TREE;
13479 : }
13480 :
13481 : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
13482 : indicated TYPE. If non-NULL, NAME is the NAME of the declaration
13483 : with this type. */
13484 :
13485 : static tree
13486 3698279 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
13487 : {
13488 3698279 : tree itype = NULL_TREE;
13489 :
13490 : /* If things have already gone awry, bail now. */
13491 3698279 : if (type == error_mark_node || size == error_mark_node)
13492 : return error_mark_node;
13493 :
13494 : /* [dcl.type.class.deduct] prohibits forming an array of placeholder
13495 : for a deduced class type. */
13496 3698216 : if (template_placeholder_p (type))
13497 : {
13498 6 : if (name)
13499 0 : error_at (loc, "%qD declared as array of template placeholder "
13500 : "type %qT", name, type);
13501 : else
13502 6 : error ("creating array of template placeholder type %qT", type);
13503 6 : return error_mark_node;
13504 : }
13505 :
13506 : /* If there are some types which cannot be array elements,
13507 : issue an error-message and return. */
13508 3698210 : switch (TREE_CODE (type))
13509 : {
13510 3 : case VOID_TYPE:
13511 3 : if (name)
13512 0 : error_at (loc, "declaration of %qD as array of void", name);
13513 : else
13514 3 : error ("creating array of void");
13515 3 : return error_mark_node;
13516 :
13517 6 : case FUNCTION_TYPE:
13518 6 : if (name)
13519 6 : error_at (loc, "declaration of %qD as array of functions", name);
13520 : else
13521 0 : error ("creating array of functions");
13522 6 : return error_mark_node;
13523 :
13524 21 : case REFERENCE_TYPE:
13525 21 : if (name)
13526 15 : error_at (loc, "declaration of %qD as array of references", name);
13527 : else
13528 6 : error ("creating array of references");
13529 21 : return error_mark_node;
13530 :
13531 0 : case METHOD_TYPE:
13532 0 : if (name)
13533 0 : error_at (loc, "declaration of %qD as array of function members",
13534 : name);
13535 : else
13536 0 : error ("creating array of function members");
13537 0 : return error_mark_node;
13538 :
13539 3698180 : default:
13540 3698180 : break;
13541 : }
13542 :
13543 3698180 : if (!verify_type_context (name ? loc : input_location,
13544 : TCTX_ARRAY_ELEMENT, type))
13545 0 : return error_mark_node;
13546 :
13547 : /* [dcl.array]
13548 :
13549 : The constant expressions that specify the bounds of the arrays
13550 : can be omitted only for the first member of the sequence. */
13551 3698180 : if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
13552 : {
13553 30 : if (name)
13554 24 : error_at (loc, "declaration of %qD as multidimensional array must "
13555 : "have bounds for all dimensions except the first",
13556 : name);
13557 : else
13558 6 : error ("multidimensional array must have bounds for all "
13559 : "dimensions except the first");
13560 :
13561 30 : return error_mark_node;
13562 : }
13563 :
13564 : /* Figure out the index type for the array. */
13565 3698150 : if (size)
13566 : {
13567 2876821 : itype = compute_array_index_type_loc (loc, name, size,
13568 : tf_warning_or_error);
13569 2876821 : if (type_uses_auto (type)
13570 2876821 : && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
13571 : {
13572 9 : sorry_at (loc, "variable-length array of %<auto%>");
13573 9 : return error_mark_node;
13574 : }
13575 : }
13576 :
13577 3698141 : return build_cplus_array_type (type, itype);
13578 : }
13579 :
13580 : /* Returns the smallest location that is not UNKNOWN_LOCATION. */
13581 :
13582 : static location_t
13583 1070400484 : min_location (location_t loca, location_t locb)
13584 : {
13585 1070400484 : if (loca == UNKNOWN_LOCATION
13586 1070400484 : || (locb != UNKNOWN_LOCATION
13587 112028956 : && linemap_location_before_p (line_table, locb, loca)))
13588 959608128 : return locb;
13589 : return loca;
13590 : }
13591 :
13592 : /* Returns the smallest location != UNKNOWN_LOCATION among the
13593 : three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
13594 : and LOCATIONS[ds_restrict]. */
13595 :
13596 : static location_t
13597 1068618079 : smallest_type_quals_location (int type_quals, const location_t* locations)
13598 : {
13599 1068618079 : location_t loc = UNKNOWN_LOCATION;
13600 :
13601 1068618079 : if (type_quals & TYPE_QUAL_CONST)
13602 110502018 : loc = locations[ds_const];
13603 :
13604 1068618079 : if (type_quals & TYPE_QUAL_VOLATILE)
13605 1782314 : loc = min_location (loc, locations[ds_volatile]);
13606 :
13607 1068618079 : if (type_quals & TYPE_QUAL_RESTRICT)
13608 43 : loc = min_location (loc, locations[ds_restrict]);
13609 :
13610 1068618079 : return loc;
13611 : }
13612 :
13613 : /* Returns the smallest among the latter and locations[ds_type_spec]. */
13614 :
13615 : static location_t
13616 1068618058 : smallest_type_location (int type_quals, const location_t* locations)
13617 : {
13618 1068618058 : location_t loc = smallest_type_quals_location (type_quals, locations);
13619 1068618058 : return min_location (loc, locations[ds_type_spec]);
13620 : }
13621 :
13622 : static location_t
13623 26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
13624 : {
13625 26 : int type_quals = get_type_quals (declspecs);
13626 26 : return smallest_type_location (type_quals, declspecs->locations);
13627 : }
13628 :
13629 : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
13630 : strip out the pointer/reference declarator(s). */
13631 :
13632 : static bool
13633 30439265 : maybe_strip_indirect_ref (const cp_declarator** declarator)
13634 : {
13635 30439265 : bool indirect_ref_p = false;
13636 60878677 : while (declarator && *declarator
13637 30439412 : && ((*declarator)->kind == cdk_pointer
13638 30439412 : || (*declarator)->kind == cdk_reference))
13639 : {
13640 147 : indirect_ref_p = true;
13641 147 : *declarator = (*declarator)->declarator;
13642 : }
13643 30439265 : return indirect_ref_p;
13644 : }
13645 :
13646 : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
13647 : and DECLARATOR. SFK indicates the kind of special function (if any) that
13648 : this function is. OPTYPE is the type given in a conversion operator
13649 : declaration, or the class type for a constructor/destructor.
13650 : Returns the actual return type of the function; that may be different
13651 : than TYPE if an error occurs, or for certain special functions. */
13652 :
13653 : static tree
13654 30439265 : check_special_function_return_type (special_function_kind sfk,
13655 : tree type,
13656 : tree optype,
13657 : int type_quals,
13658 : const cp_declarator** declarator,
13659 : const location_t* locations)
13660 : {
13661 30439265 : gcc_assert (declarator);
13662 30439265 : location_t rettype_loc = (type
13663 30439265 : ? smallest_type_location (type_quals, locations)
13664 30439184 : : (*declarator)->id_loc);
13665 30439265 : switch (sfk)
13666 : {
13667 24807686 : case sfk_constructor:
13668 24807686 : if (maybe_strip_indirect_ref (declarator) || type)
13669 81 : error_at (rettype_loc,
13670 : "return type specification for constructor invalid");
13671 24807605 : else if (type_quals != TYPE_UNQUALIFIED)
13672 15 : error_at (smallest_type_quals_location (type_quals, locations),
13673 : "qualifiers are not allowed on constructor declaration");
13674 :
13675 24807686 : if (targetm.cxx.cdtor_returns_this ())
13676 0 : type = build_pointer_type (optype);
13677 : else
13678 24807686 : type = void_type_node;
13679 : break;
13680 :
13681 3330260 : case sfk_destructor:
13682 3330260 : if (maybe_strip_indirect_ref (declarator) || type)
13683 45 : error_at (rettype_loc,
13684 : "return type specification for destructor invalid");
13685 3330215 : else if (type_quals != TYPE_UNQUALIFIED)
13686 3 : error_at (smallest_type_quals_location (type_quals, locations),
13687 : "qualifiers are not allowed on destructor declaration");
13688 :
13689 : /* We can't use the proper return type here because we run into
13690 : problems with ambiguous bases and covariant returns. */
13691 3330260 : if (targetm.cxx.cdtor_returns_this ())
13692 0 : type = build_pointer_type (void_type_node);
13693 : else
13694 3330260 : type = void_type_node;
13695 : break;
13696 :
13697 1048432 : case sfk_conversion:
13698 1048432 : if (maybe_strip_indirect_ref (declarator) || type)
13699 42 : error_at (rettype_loc,
13700 : "return type specified for %<operator %T%>", optype);
13701 1048390 : else if (type_quals != TYPE_UNQUALIFIED)
13702 3 : error_at (smallest_type_quals_location (type_quals, locations),
13703 : "qualifiers are not allowed on declaration of "
13704 : "%<operator %T%>", optype);
13705 :
13706 : type = optype;
13707 : break;
13708 :
13709 1252887 : case sfk_deduction_guide:
13710 1252887 : if (maybe_strip_indirect_ref (declarator) || type)
13711 0 : error_at (rettype_loc,
13712 : "return type specified for deduction guide");
13713 1252887 : else if (type_quals != TYPE_UNQUALIFIED)
13714 0 : error_at (smallest_type_quals_location (type_quals, locations),
13715 : "qualifiers are not allowed on declaration of "
13716 : "deduction guide");
13717 1252887 : if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
13718 : {
13719 3 : error ("template template parameter %qT in declaration of "
13720 : "deduction guide", optype);
13721 3 : type = error_mark_node;
13722 : }
13723 : else
13724 1252884 : type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
13725 33827949 : for (int i = 0; i < ds_last; ++i)
13726 32575062 : if (i != ds_explicit && locations[i])
13727 3 : error_at (locations[i],
13728 : "%<decl-specifier%> in declaration of deduction guide");
13729 : break;
13730 :
13731 0 : default:
13732 0 : gcc_unreachable ();
13733 : }
13734 :
13735 30439265 : return type;
13736 : }
13737 :
13738 : /* A variable or data member (whose unqualified name is IDENTIFIER)
13739 : has been declared with the indicated TYPE. If the TYPE is not
13740 : acceptable, issue an error message and return a type to use for
13741 : error-recovery purposes. */
13742 :
13743 : tree
13744 335683199 : check_var_type (tree identifier, tree type, location_t loc)
13745 : {
13746 335683199 : if (VOID_TYPE_P (type))
13747 : {
13748 92 : if (!identifier)
13749 0 : error_at (loc, "unnamed variable or field declared void");
13750 92 : else if (identifier_p (identifier))
13751 : {
13752 92 : gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
13753 92 : error_at (loc, "variable or field %qE declared void",
13754 : identifier);
13755 : }
13756 : else
13757 0 : error_at (loc, "variable or field declared void");
13758 92 : type = error_mark_node;
13759 : }
13760 :
13761 335683199 : return type;
13762 : }
13763 :
13764 : /* Handle declaring DECL as an inline variable. */
13765 :
13766 : static void
13767 6842227 : mark_inline_variable (tree decl, location_t loc)
13768 : {
13769 6842227 : bool inlinep = true;
13770 6842227 : if (! toplevel_bindings_p ())
13771 : {
13772 24 : error_at (loc, "%<inline%> specifier invalid for variable "
13773 : "%qD declared at block scope", decl);
13774 24 : inlinep = false;
13775 : }
13776 6842203 : else if (cxx_dialect < cxx17)
13777 658 : pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
13778 : "with %<-std=c++17%> or %<-std=gnu++17%>");
13779 682 : if (inlinep)
13780 : {
13781 6842203 : retrofit_lang_decl (decl);
13782 6842203 : SET_DECL_VAR_DECLARED_INLINE_P (decl);
13783 : }
13784 6842227 : }
13785 :
13786 :
13787 : /* Diagnose -Wnon-c-typedef-for-linkage pedwarn. TYPE is the unnamed class
13788 : with a typedef name for linkage purposes with freshly updated TYPE_NAME,
13789 : ORIG is the anonymous TYPE_NAME before that change. */
13790 :
13791 : static bool
13792 42 : diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
13793 : {
13794 42 : gcc_rich_location richloc (DECL_SOURCE_LOCATION (orig));
13795 42 : tree name = DECL_NAME (TYPE_NAME (type));
13796 42 : richloc.add_fixit_insert_before (IDENTIFIER_POINTER (name));
13797 42 : return pedwarn (&richloc, OPT_Wnon_c_typedef_for_linkage,
13798 : "anonymous non-C-compatible type given name for linkage "
13799 42 : "purposes by %<typedef%> declaration");
13800 42 : }
13801 :
13802 : /* Diagnose -Wnon-c-typedef-for-linkage violations on T. TYPE and ORIG
13803 : like for diagnose_non_c_class_typedef_for_linkage, T is initially equal
13804 : to TYPE but during recursion can be set to nested classes. */
13805 :
13806 : static bool
13807 527072 : maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
13808 : {
13809 527072 : if (!COMPLETE_TYPE_P (t))
13810 : return false;
13811 527069 : if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
13812 : {
13813 6 : auto_diagnostic_group d;
13814 6 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13815 9 : inform (type == t ? DECL_SOURCE_LOCATION (orig)
13816 3 : : DECL_SOURCE_LOCATION (TYPE_NAME (t)),
13817 : "type is not C-compatible because it has a base class");
13818 6 : return true;
13819 6 : }
13820 2476043 : for (tree field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
13821 1949041 : switch (TREE_CODE (field))
13822 : {
13823 9 : case VAR_DECL:
13824 : /* static data members have been diagnosed already. */
13825 9 : continue;
13826 1296274 : case FIELD_DECL:
13827 1296274 : if (DECL_INITIAL (field))
13828 : {
13829 4 : auto_diagnostic_group d;
13830 4 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13831 4 : inform (DECL_SOURCE_LOCATION (field),
13832 : "type is not C-compatible because %qD has default "
13833 : "member initializer", field);
13834 4 : return true;
13835 4 : }
13836 1296270 : continue;
13837 9 : case CONST_DECL:
13838 9 : continue;
13839 652668 : case TYPE_DECL:
13840 652668 : if (DECL_SELF_REFERENCE_P (field))
13841 527037 : continue;
13842 125631 : if (DECL_IMPLICIT_TYPEDEF_P (field))
13843 : {
13844 125621 : if (TREE_CODE (TREE_TYPE (field)) == ENUMERAL_TYPE)
13845 3 : continue;
13846 125618 : if (CLASS_TYPE_P (TREE_TYPE (field)))
13847 : {
13848 125618 : tree tf = TREE_TYPE (field);
13849 125618 : if (maybe_diagnose_non_c_class_typedef_for_linkage (type, orig,
13850 : tf))
13851 : return true;
13852 125593 : continue;
13853 125593 : }
13854 : }
13855 : /* FALLTHRU */
13856 32 : case FUNCTION_DECL:
13857 32 : case TEMPLATE_DECL:
13858 32 : {
13859 32 : auto_diagnostic_group d;
13860 32 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13861 32 : inform (DECL_SOURCE_LOCATION (field),
13862 : "type is not C-compatible because it contains %qD "
13863 : "declaration", field);
13864 32 : return true;
13865 32 : }
13866 : default:
13867 : break;
13868 1296288 : }
13869 : return false;
13870 : }
13871 :
13872 : /* Assign a typedef-given name to a class or enumeration type declared
13873 : as anonymous at first. This was split out of grokdeclarator
13874 : because it is also used in libcc1. */
13875 :
13876 : void
13877 403251 : name_unnamed_type (tree type, tree decl)
13878 : {
13879 1209753 : gcc_assert (TYPE_UNNAMED_P (type)
13880 : || enum_with_enumerator_for_linkage_p (type));
13881 :
13882 403251 : tree orig = TYPE_NAME (type);
13883 403251 : if (flag_reflection)
13884 : {
13885 : /* For -freflection for typedef struct { ... } S; ^^S needs to be
13886 : a reflection of a type alias. So, TREE_TYPE (DECL) can't be
13887 : TYPE. Instead of what we do below, override DECL_NAME (orig). */
13888 15546 : DECL_NAME (orig) = DECL_NAME (decl);
13889 15546 : TYPE_DECL_FOR_LINKAGE_PURPOSES_P (orig) = 1;
13890 : }
13891 : else
13892 : /* Replace the anonymous decl with the real decl. Be careful not to
13893 : rename other typedefs (such as the self-reference) of type. */
13894 1161399 : for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
13895 773694 : if (TYPE_NAME (t) == orig)
13896 387705 : TYPE_NAME (t) = decl;
13897 403251 : TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl) = 1;
13898 :
13899 : /* If this is a typedef within a template class, the nested
13900 : type is a (non-primary) template. The name for the
13901 : template needs updating as well. */
13902 403251 : if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
13903 68 : DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
13904 :
13905 : /* Adjust linkage now that we aren't unnamed anymore. */
13906 403251 : reset_type_linkage (type);
13907 :
13908 403251 : if (CLASS_TYPE_P (type) && warn_non_c_typedef_for_linkage)
13909 401454 : maybe_diagnose_non_c_class_typedef_for_linkage (type, orig, type);
13910 :
13911 : /* FIXME remangle member functions; member functions of a
13912 : type with external linkage have external linkage. */
13913 :
13914 : /* Check that our job is done, and that it would fail if we
13915 : attempted to do it again. */
13916 806502 : gcc_assert (!TYPE_UNNAMED_P (type)
13917 : && !enum_with_enumerator_for_linkage_p (type));
13918 403251 : }
13919 :
13920 : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
13921 : is allowed. TYPE might contain a decltype(auto). Returns true if
13922 : there was a problem, false otherwise. */
13923 :
13924 : static bool
13925 650419285 : check_decltype_auto (location_t loc, tree type)
13926 : {
13927 650419285 : if (tree a = type_uses_auto (type))
13928 : {
13929 18227014 : if (AUTO_IS_DECLTYPE (a))
13930 : {
13931 628530 : if (a != type)
13932 : {
13933 33 : error_at (loc, "%qT as type rather than plain "
13934 : "%<decltype(auto)%>", type);
13935 33 : return true;
13936 : }
13937 628497 : else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
13938 : {
13939 37 : error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
13940 37 : return true;
13941 : }
13942 : }
13943 : }
13944 : return false;
13945 : }
13946 :
13947 : /* Issue an error about two mutually incompatible declspecs
13948 : with the given names and locations
13949 : e.g. "error: `signed' and `unsigned' specified together" */
13950 :
13951 : static void
13952 66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
13953 : const char *name_b, location_t loc_b)
13954 : {
13955 66 : gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
13956 66 : richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
13957 : nullptr, highlight_colors::rhs);
13958 66 : pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
13959 66 : pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
13960 66 : error_at (&richloc, "%e and %e specified together",
13961 : &e_name_a, &e_name_b);
13962 66 : }
13963 :
13964 : /* Given declspecs and a declarator (abstract or otherwise), determine
13965 : the name and type of the object declared and construct a DECL node
13966 : for it.
13967 :
13968 : DECLSPECS points to the representation of declaration-specifier
13969 : sequence that precedes declarator.
13970 :
13971 : DECL_CONTEXT says which syntactic context this declaration is in:
13972 : NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
13973 : FUNCDEF for a function definition. Like NORMAL but a few different
13974 : error messages in each case. Return value may be zero meaning
13975 : this definition is too screwy to try to parse.
13976 : MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
13977 : handle member functions (which have FIELD context).
13978 : Return value may be zero meaning this definition is too screwy to
13979 : try to parse.
13980 : PARM for a parameter declaration (either within a function prototype
13981 : or before a function body). Make a PARM_DECL, or return void_type_node.
13982 : TPARM for a template parameter declaration.
13983 : CATCHPARM for a parameter declaration before a catch clause.
13984 : TYPENAME if for a typename (in a cast or sizeof).
13985 : Don't make a DECL node; just return the ..._TYPE node.
13986 : FIELD for a struct or union field; make a FIELD_DECL.
13987 : BITFIELD for a field with specified width.
13988 :
13989 : INITIALIZED is as for start_decl.
13990 :
13991 : ATTRLIST is a pointer to the list of attributes, which may be NULL
13992 : if there are none; *ATTRLIST may be modified if attributes from inside
13993 : the declarator should be applied to the declaration.
13994 :
13995 : When this function is called, scoping variables (such as
13996 : CURRENT_CLASS_TYPE) should reflect the scope in which the
13997 : declaration occurs, not the scope in which the new declaration will
13998 : be placed. For example, on:
13999 :
14000 : void S::f() { ... }
14001 :
14002 : when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
14003 : should not be `S'.
14004 :
14005 : Returns a DECL (if a declarator is present), a TYPE (if there is no
14006 : declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
14007 : error occurs. */
14008 :
14009 : tree
14010 1068617951 : grokdeclarator (const cp_declarator *declarator,
14011 : cp_decl_specifier_seq *declspecs,
14012 : enum decl_context decl_context,
14013 : int initialized,
14014 : tree* attrlist)
14015 : {
14016 1068617951 : tree type = NULL_TREE;
14017 1068617951 : int longlong = 0;
14018 1068617951 : int explicit_intN = 0;
14019 1068617951 : int int_n_alt = 0;
14020 1068617951 : int virtualp, explicitp, friendp, inlinep, staticp;
14021 1068617951 : int explicit_int = 0;
14022 1068617951 : int explicit_char = 0;
14023 1068617951 : int defaulted_int = 0;
14024 :
14025 1068617951 : tree typedef_decl = NULL_TREE;
14026 1068617951 : const char *name = NULL;
14027 1068617951 : tree typedef_type = NULL_TREE;
14028 : /* True if this declarator is a function definition. */
14029 1068617951 : bool funcdef_flag = false;
14030 1068617951 : cp_declarator_kind innermost_code = cdk_error;
14031 1068617951 : int bitfield = 0;
14032 : #if 0
14033 : /* See the code below that used this. */
14034 : tree decl_attr = NULL_TREE;
14035 : #endif
14036 :
14037 : /* Keep track of what sort of function is being processed
14038 : so that we can warn about default return values, or explicit
14039 : return values which do not match prescribed defaults. */
14040 1068617951 : special_function_kind sfk = sfk_none;
14041 :
14042 1068617951 : tree dname = NULL_TREE;
14043 1068617951 : tree ctor_return_type = NULL_TREE;
14044 1068617951 : enum overload_flags flags = NO_SPECIAL;
14045 : /* cv-qualifiers that apply to the declarator, for a declaration of
14046 : a member function. */
14047 1068617951 : cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
14048 : /* virt-specifiers that apply to the declarator, for a declaration of
14049 : a member function. */
14050 1068617951 : cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
14051 : /* ref-qualifier that applies to the declarator, for a declaration of
14052 : a member function. */
14053 1068617951 : cp_ref_qualifier rqual = REF_QUAL_NONE;
14054 : /* cv-qualifiers that apply to the type specified by the DECLSPECS. */
14055 1068617951 : int type_quals = get_type_quals (declspecs);
14056 1068617951 : tree raises = NULL_TREE;
14057 1068617951 : int template_count = 0;
14058 1068617951 : tree returned_attrs = NULL_TREE;
14059 1068617951 : tree contract_specifiers = NULL_TREE;
14060 1068617951 : tree parms = NULL_TREE;
14061 1068617951 : const cp_declarator *id_declarator;
14062 : /* The unqualified name of the declarator; either an
14063 : IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR. */
14064 1068617951 : tree unqualified_id;
14065 : /* The class type, if any, in which this entity is located,
14066 : or NULL_TREE if none. Note that this value may be different from
14067 : the current class type; for example if an attempt is made to declare
14068 : "A::f" inside "B", this value will be "A". */
14069 1068617951 : tree ctype = current_class_type;
14070 : /* The NAMESPACE_DECL for the namespace in which this entity is
14071 : located. If an unqualified name is used to declare the entity,
14072 : this value will be NULL_TREE, even if the entity is located at
14073 : namespace scope. */
14074 1068617951 : tree in_namespace = NULL_TREE;
14075 1068617951 : cp_storage_class storage_class;
14076 1068617951 : bool unsigned_p, signed_p, short_p, long_p, thread_p;
14077 1068617951 : bool type_was_error_mark_node = false;
14078 1068617951 : bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
14079 1068617951 : bool template_type_arg = false;
14080 1068617951 : bool template_parm_flag = false;
14081 1068617951 : bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
14082 1068617951 : bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
14083 1068617951 : bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
14084 1068617951 : bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
14085 1068617951 : bool late_return_type_p = false;
14086 1068617951 : bool array_parameter_p = false;
14087 1068617951 : tree reqs = NULL_TREE;
14088 :
14089 1068617951 : signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
14090 1068617951 : unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
14091 1068617951 : short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
14092 1068617951 : long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
14093 1068617951 : longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
14094 1068617951 : explicit_intN = declspecs->explicit_intN_p;
14095 1068617951 : int_n_alt = declspecs->int_n_alt;
14096 1068617951 : thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
14097 :
14098 : // Was concept_p specified? Note that ds_concept
14099 : // implies ds_constexpr!
14100 1068617951 : bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
14101 1068617951 : if (concept_p)
14102 117 : constexpr_p = true;
14103 :
14104 1068617951 : if (decl_context == FUNCDEF)
14105 : funcdef_flag = true, decl_context = NORMAL;
14106 : else if (decl_context == MEMFUNCDEF)
14107 : funcdef_flag = true, decl_context = FIELD;
14108 : else if (decl_context == BITFIELD)
14109 : bitfield = 1, decl_context = FIELD;
14110 : else if (decl_context == TEMPLATE_TYPE_ARG)
14111 : template_type_arg = true, decl_context = TYPENAME;
14112 : else if (decl_context == TPARM)
14113 11314160 : template_parm_flag = true, decl_context = PARM;
14114 :
14115 1068617951 : if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
14116 11286599 : funcdef_flag = true;
14117 :
14118 1068617951 : location_t typespec_loc = loc_or_input_loc (smallest_type_location
14119 : (type_quals,
14120 1068617951 : declspecs->locations));
14121 1068617951 : location_t id_loc;
14122 1068617951 : location_t init_loc;
14123 1068617951 : if (declarator)
14124 : {
14125 644541603 : id_loc = loc_or_input_loc (declarator->id_loc);
14126 644541603 : init_loc = loc_or_input_loc (declarator->init_loc);
14127 : }
14128 : else
14129 424076348 : init_loc = id_loc = input_location;
14130 :
14131 : /* Look inside a declarator for the name being declared
14132 : and get it as a string, for an error message. */
14133 1068617951 : for (id_declarator = declarator;
14134 1467587308 : id_declarator;
14135 398969357 : id_declarator = id_declarator->declarator)
14136 : {
14137 1000518040 : if (id_declarator->kind != cdk_id)
14138 398969382 : innermost_code = id_declarator->kind;
14139 :
14140 1000518040 : switch (id_declarator->kind)
14141 : {
14142 195806837 : case cdk_function:
14143 195806837 : if (id_declarator->declarator
14144 195419278 : && id_declarator->declarator->kind == cdk_id)
14145 : {
14146 193529641 : sfk = id_declarator->declarator->u.id.sfk;
14147 193529641 : if (sfk == sfk_destructor)
14148 3330263 : flags = DTOR_FLAG;
14149 : }
14150 : break;
14151 :
14152 601548658 : case cdk_id:
14153 601548658 : {
14154 601548658 : tree qualifying_scope = id_declarator->u.id.qualifying_scope;
14155 601548658 : tree decl = id_declarator->u.id.unqualified_name;
14156 601548658 : if (!decl)
14157 : break;
14158 601548658 : if (qualifying_scope)
14159 : {
14160 9968443 : if (check_for_bare_parameter_packs (qualifying_scope,
14161 9968443 : id_declarator->id_loc))
14162 6 : return error_mark_node;
14163 9968437 : if (at_function_scope_p ())
14164 : {
14165 : /* [dcl.meaning]
14166 :
14167 : A declarator-id shall not be qualified except
14168 : for ...
14169 :
14170 : None of the cases are permitted in block
14171 : scope. */
14172 0 : if (qualifying_scope == global_namespace)
14173 0 : error ("invalid use of qualified-name %<::%D%>",
14174 : decl);
14175 0 : else if (TYPE_P (qualifying_scope))
14176 0 : error ("invalid use of qualified-name %<%T::%D%>",
14177 : qualifying_scope, decl);
14178 : else
14179 0 : error ("invalid use of qualified-name %<%D::%D%>",
14180 : qualifying_scope, decl);
14181 0 : return error_mark_node;
14182 : }
14183 9968437 : else if (TYPE_P (qualifying_scope))
14184 : {
14185 9692462 : ctype = qualifying_scope;
14186 9692462 : if (!MAYBE_CLASS_TYPE_P (ctype))
14187 : {
14188 6 : error_at (id_declarator->id_loc,
14189 : "%q#T is not a class or namespace", ctype);
14190 6 : ctype = NULL_TREE;
14191 : }
14192 9692456 : else if (innermost_code != cdk_function
14193 508259 : && current_class_type
14194 9692471 : && !uniquely_derived_from_p (ctype,
14195 : current_class_type))
14196 : {
14197 9 : error_at (id_declarator->id_loc,
14198 : "invalid use of qualified-name %<%T::%D%>",
14199 : qualifying_scope, decl);
14200 9 : return error_mark_node;
14201 : }
14202 : }
14203 275975 : else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
14204 601548643 : in_namespace = qualifying_scope;
14205 : }
14206 601548643 : switch (TREE_CODE (decl))
14207 : {
14208 3330278 : case BIT_NOT_EXPR:
14209 3330278 : {
14210 3330278 : if (innermost_code != cdk_function)
14211 : {
14212 6 : error_at (EXPR_LOCATION (decl),
14213 : "declaration of %qE as non-function", decl);
14214 6 : return error_mark_node;
14215 : }
14216 3330272 : else if (!qualifying_scope
14217 3330272 : && !(current_class_type && at_class_scope_p ()))
14218 : {
14219 9 : error_at (EXPR_LOCATION (decl),
14220 : "declaration of %qE as non-member", decl);
14221 9 : return error_mark_node;
14222 : }
14223 :
14224 3330263 : tree type = TREE_OPERAND (decl, 0);
14225 3330263 : if (TYPE_P (type))
14226 3330260 : type = constructor_name (type);
14227 3330263 : name = identifier_to_locale (IDENTIFIER_POINTER (type));
14228 3330263 : dname = decl;
14229 : }
14230 3330263 : break;
14231 :
14232 2895911 : case TEMPLATE_ID_EXPR:
14233 2895911 : {
14234 2895911 : tree fns = TREE_OPERAND (decl, 0);
14235 :
14236 2895911 : dname = fns;
14237 3861085 : if (!identifier_p (dname))
14238 2895887 : dname = OVL_NAME (dname);
14239 : }
14240 : /* Fall through. */
14241 :
14242 598218365 : case IDENTIFIER_NODE:
14243 598218365 : if (identifier_p (decl))
14244 595322454 : dname = decl;
14245 :
14246 598218365 : if (IDENTIFIER_KEYWORD_P (dname))
14247 : {
14248 0 : error ("declarator-id missing; using reserved word %qD",
14249 : dname);
14250 0 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14251 : }
14252 598218365 : else if (!IDENTIFIER_CONV_OP_P (dname))
14253 597169930 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14254 : else
14255 : {
14256 1048435 : gcc_assert (flags == NO_SPECIAL);
14257 1048435 : flags = TYPENAME_FLAG;
14258 1048435 : sfk = sfk_conversion;
14259 1048435 : tree glob = get_global_binding (dname);
14260 1048435 : if (glob && TREE_CODE (glob) == TYPE_DECL)
14261 0 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14262 : else
14263 : name = "<invalid operator>";
14264 : }
14265 : break;
14266 :
14267 0 : default:
14268 0 : gcc_unreachable ();
14269 : }
14270 : break;
14271 : }
14272 :
14273 : case cdk_array:
14274 : case cdk_pointer:
14275 : case cdk_reference:
14276 : case cdk_ptrmem:
14277 : break;
14278 :
14279 : case cdk_decomp:
14280 1000517985 : name = "structured binding";
14281 : break;
14282 :
14283 25 : case cdk_error:
14284 25 : return error_mark_node;
14285 :
14286 0 : default:
14287 0 : gcc_unreachable ();
14288 : }
14289 1000517985 : if (id_declarator->kind == cdk_id)
14290 : break;
14291 : }
14292 :
14293 : /* [dcl.fct.edf]
14294 :
14295 : The declarator in a function-definition shall have the form
14296 : D1 ( parameter-declaration-clause) ... */
14297 1068617896 : if (funcdef_flag && innermost_code != cdk_function)
14298 : {
14299 3 : error_at (id_loc, "function definition does not declare parameters");
14300 3 : return error_mark_node;
14301 : }
14302 :
14303 1068617893 : if (flags == TYPENAME_FLAG
14304 1068617893 : && innermost_code != cdk_function
14305 3 : && ! (ctype && !declspecs->any_specifiers_p))
14306 : {
14307 3 : error_at (id_loc, "declaration of %qD as non-function", dname);
14308 3 : return error_mark_node;
14309 : }
14310 :
14311 1068617890 : if (dname && identifier_p (dname))
14312 : {
14313 598218359 : if (UDLIT_OPER_P (dname)
14314 598218359 : && innermost_code != cdk_function)
14315 : {
14316 6 : error_at (id_loc, "declaration of %qD as non-function", dname);
14317 6 : return error_mark_node;
14318 : }
14319 :
14320 598218353 : if (IDENTIFIER_ANY_OP_P (dname))
14321 : {
14322 38105187 : if (typedef_p)
14323 : {
14324 3 : error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
14325 3 : return error_mark_node;
14326 : }
14327 38105184 : else if (decl_context == PARM || decl_context == CATCHPARM)
14328 : {
14329 15 : error_at (id_loc, "declaration of %qD as parameter", dname);
14330 15 : return error_mark_node;
14331 : }
14332 : }
14333 : }
14334 :
14335 : /* Anything declared one level down from the top level
14336 : must be one of the parameters of a function
14337 : (because the body is at least two levels down). */
14338 :
14339 : /* This heuristic cannot be applied to C++ nodes! Fixed, however,
14340 : by not allowing C++ class definitions to specify their parameters
14341 : with xdecls (must be spec.d in the parmlist).
14342 :
14343 : Since we now wait to push a class scope until we are sure that
14344 : we are in a legitimate method context, we must set oldcname
14345 : explicitly (since current_class_name is not yet alive).
14346 :
14347 : We also want to avoid calling this a PARM if it is in a namespace. */
14348 :
14349 1068617866 : if (decl_context == NORMAL && !toplevel_bindings_p ())
14350 : {
14351 73926249 : cp_binding_level *b = current_binding_level;
14352 73926249 : current_binding_level = b->level_chain;
14353 73926249 : if (current_binding_level != 0 && toplevel_bindings_p ())
14354 : decl_context = PARM;
14355 73926249 : current_binding_level = b;
14356 : }
14357 :
14358 1068617866 : if (name == NULL)
14359 466825332 : name = decl_context == PARM ? "parameter" : "type name";
14360 :
14361 1068617866 : if (consteval_p && constexpr_p)
14362 : {
14363 6 : error_at (declspecs->locations[ds_consteval],
14364 : "both %qs and %qs specified", "constexpr", "consteval");
14365 6 : return error_mark_node;
14366 : }
14367 :
14368 1068617860 : if (concept_p && typedef_p)
14369 : {
14370 9 : error_at (declspecs->locations[ds_concept],
14371 : "%qs cannot appear in a typedef declaration", "concept");
14372 9 : return error_mark_node;
14373 : }
14374 :
14375 1068617851 : if (constexpr_p && typedef_p)
14376 : {
14377 3 : error_at (declspecs->locations[ds_constexpr],
14378 : "%qs cannot appear in a typedef declaration", "constexpr");
14379 3 : return error_mark_node;
14380 : }
14381 :
14382 1068617848 : if (consteval_p && typedef_p)
14383 : {
14384 3 : error_at (declspecs->locations[ds_consteval],
14385 : "%qs cannot appear in a typedef declaration", "consteval");
14386 3 : return error_mark_node;
14387 : }
14388 :
14389 1068617845 : if (constinit_p && typedef_p)
14390 : {
14391 3 : error_at (declspecs->locations[ds_constinit],
14392 : "%qs cannot appear in a typedef declaration", "constinit");
14393 3 : return error_mark_node;
14394 : }
14395 :
14396 : /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
14397 : keywords shall appear in a decl-specifier-seq." */
14398 1068617842 : if (constinit_p && constexpr_p)
14399 : {
14400 6 : gcc_rich_location richloc (declspecs->locations[ds_constinit]);
14401 6 : richloc.add_range (declspecs->locations[ds_constexpr]);
14402 6 : error_at (&richloc,
14403 : "can use at most one of the %<constinit%> and %<constexpr%> "
14404 : "specifiers");
14405 6 : return error_mark_node;
14406 6 : }
14407 :
14408 : /* If there were multiple types specified in the decl-specifier-seq,
14409 : issue an error message. */
14410 1068617836 : if (declspecs->multiple_types_p)
14411 : {
14412 1501 : error_at (typespec_loc,
14413 : "two or more data types in declaration of %qs", name);
14414 1501 : return error_mark_node;
14415 : }
14416 :
14417 1068616335 : if (declspecs->conflicting_specifiers_p)
14418 31 : return error_mark_node;
14419 :
14420 : /* Extract the basic type from the decl-specifier-seq. */
14421 1068616304 : type = declspecs->type;
14422 1068616304 : if (type == error_mark_node)
14423 : {
14424 1231 : type = NULL_TREE;
14425 1231 : type_was_error_mark_node = true;
14426 : }
14427 :
14428 : /* Ignore erroneous attributes. */
14429 1068616304 : if (attrlist && *attrlist == error_mark_node)
14430 12 : *attrlist = NULL_TREE;
14431 :
14432 : /* An object declared as __attribute__((unavailable)) suppresses
14433 : any reports of being declared with unavailable or deprecated
14434 : items. An object declared as __attribute__((deprecated))
14435 : suppresses warnings of uses of other deprecated items. */
14436 1068616304 : auto ds = make_temp_override (deprecated_state);
14437 1068616304 : if (attrlist && lookup_attribute ("unavailable", *attrlist))
14438 171 : deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
14439 1068616133 : else if (attrlist && lookup_attribute ("deprecated", *attrlist))
14440 958016 : deprecated_state = DEPRECATED_SUPPRESS;
14441 :
14442 1068616304 : cp_handle_deprecated_or_unavailable (type);
14443 1068616304 : if (type && TREE_CODE (type) == TYPE_DECL)
14444 : {
14445 744010524 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
14446 744010524 : typedef_decl = type;
14447 744010524 : type = TREE_TYPE (typedef_decl);
14448 744010524 : if (DECL_ARTIFICIAL (typedef_decl))
14449 540992363 : cp_handle_deprecated_or_unavailable (type);
14450 : }
14451 : /* No type at all: default to `int', and set DEFAULTED_INT
14452 : because it was not a user-defined typedef. */
14453 1068616304 : if (type == NULL_TREE)
14454 : {
14455 39784068 : if (signed_p || unsigned_p || long_p || short_p)
14456 : {
14457 : /* These imply 'int'. */
14458 9343172 : type = integer_type_node;
14459 9343172 : defaulted_int = 1;
14460 : }
14461 : /* If we just have "complex", it is equivalent to "complex double". */
14462 30440896 : else if (!longlong && !explicit_intN
14463 30440896 : && decl_spec_seq_has_spec_p (declspecs, ds_complex))
14464 : {
14465 81 : type = double_type_node;
14466 81 : pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
14467 : "ISO C++ does not support plain %<complex%> meaning "
14468 : "%<double complex%>");
14469 : }
14470 : }
14471 : /* Gather flags. */
14472 1068616304 : explicit_int = declspecs->explicit_int_p;
14473 1068616304 : explicit_char = declspecs->explicit_char_p;
14474 :
14475 : #if 0
14476 : /* See the code below that used this. */
14477 : if (typedef_decl)
14478 : decl_attr = DECL_ATTRIBUTES (typedef_decl);
14479 : #endif
14480 1068616304 : typedef_type = type;
14481 :
14482 1068616304 : if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
14483 2301319 : ctor_return_type = TREE_TYPE (dname);
14484 : else
14485 : ctor_return_type = ctype;
14486 :
14487 1068616304 : if (sfk != sfk_none)
14488 : {
14489 30439265 : type = check_special_function_return_type (sfk, type,
14490 : ctor_return_type,
14491 : type_quals,
14492 : &declarator,
14493 : declspecs->locations);
14494 30439265 : type_quals = TYPE_UNQUALIFIED;
14495 : }
14496 1038177039 : else if (type == NULL_TREE)
14497 : {
14498 1631 : int is_main;
14499 :
14500 1631 : explicit_int = -1;
14501 :
14502 : /* We handle `main' specially here, because 'main () { }' is so
14503 : common. With no options, it is allowed. With -Wreturn-type,
14504 : it is a warning. It is only an error with -pedantic-errors. */
14505 3262 : is_main = (funcdef_flag
14506 3496 : && dname && identifier_p (dname)
14507 234 : && MAIN_NAME_P (dname)
14508 68 : && ctype == NULL_TREE
14509 68 : && in_namespace == NULL_TREE
14510 1699 : && current_namespace == global_namespace);
14511 :
14512 1631 : if (type_was_error_mark_node)
14513 : /* We've already issued an error, don't complain more. */;
14514 400 : else if (in_system_header_at (id_loc) || flag_ms_extensions)
14515 : /* Allow it, sigh. */;
14516 338 : else if (! is_main)
14517 276 : permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
14518 : name);
14519 62 : else if (pedantic)
14520 4 : pedwarn (id_loc, OPT_Wpedantic,
14521 : "ISO C++ forbids declaration of %qs with no type", name);
14522 : else
14523 58 : warning_at (id_loc, OPT_Wreturn_type,
14524 : "ISO C++ forbids declaration of %qs with no type", name);
14525 :
14526 1631 : if (type_was_error_mark_node && template_parm_flag)
14527 : /* FIXME we should be able to propagate the error_mark_node as is
14528 : for other contexts too. */
14529 150 : type = error_mark_node;
14530 : else
14531 1481 : type = integer_type_node;
14532 : }
14533 :
14534 1068616304 : ctype = NULL_TREE;
14535 :
14536 1068616304 : if (explicit_intN)
14537 : {
14538 1136846 : if (! int_n_enabled_p[declspecs->int_n_idx])
14539 : {
14540 0 : error_at (declspecs->locations[ds_type_spec],
14541 : "%<__int%d%> is not supported by this target",
14542 0 : int_n_data[declspecs->int_n_idx].bitsize);
14543 0 : explicit_intN = false;
14544 : }
14545 : /* Don't pedwarn if the alternate "__intN__" form has been used instead
14546 : of "__intN". */
14547 1136846 : else if (!int_n_alt && pedantic)
14548 9827 : pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
14549 : "ISO C++ does not support %<__int%d%> for %qs",
14550 9827 : int_n_data[declspecs->int_n_idx].bitsize, name);
14551 : }
14552 :
14553 : /* Now process the modifiers that were specified
14554 : and check for invalid combinations. */
14555 :
14556 : /* Long double is a special combination. */
14557 1068616304 : if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
14558 : {
14559 9065492 : long_p = false;
14560 9065492 : type = cp_build_qualified_type (long_double_type_node,
14561 : cp_type_quals (type));
14562 : }
14563 :
14564 : /* Check all other uses of type modifiers. */
14565 :
14566 1068616304 : if (unsigned_p || signed_p || long_p || short_p)
14567 : {
14568 21638681 : location_t loc;
14569 21638681 : const char *key;
14570 21638681 : if (unsigned_p)
14571 : {
14572 14720920 : key = "unsigned";
14573 14720920 : loc = declspecs->locations[ds_unsigned];
14574 : }
14575 6917761 : else if (signed_p)
14576 : {
14577 1053988 : key = "signed";
14578 1053988 : loc = declspecs->locations[ds_signed];
14579 : }
14580 5863773 : else if (longlong)
14581 : {
14582 2286594 : key = "long long";
14583 2286594 : loc = declspecs->locations[ds_long_long];
14584 : }
14585 3577179 : else if (long_p)
14586 : {
14587 3007481 : key = "long";
14588 3007481 : loc = declspecs->locations[ds_long];
14589 : }
14590 : else /* if (short_p) */
14591 : {
14592 569698 : key = "short";
14593 569698 : loc = declspecs->locations[ds_short];
14594 : }
14595 :
14596 21638681 : int ok = 0;
14597 :
14598 21638681 : if (signed_p && unsigned_p)
14599 54 : complain_about_incompatible_declspecs
14600 54 : ("signed", declspecs->locations[ds_signed],
14601 : "unsigned", declspecs->locations[ds_unsigned]);
14602 21638627 : else if (long_p && short_p)
14603 12 : complain_about_incompatible_declspecs
14604 12 : ("long", declspecs->locations[ds_long],
14605 : "short", declspecs->locations[ds_short]);
14606 21638615 : else if (TREE_CODE (type) != INTEGER_TYPE
14607 21638602 : || type == char8_type_node
14608 21638578 : || type == char16_type_node
14609 21638554 : || type == char32_type_node
14610 21638530 : || ((long_p || short_p)
14611 11374861 : && (explicit_char || explicit_intN)))
14612 418 : error_at (loc, "%qs specified with %qT", key, type);
14613 21638197 : else if (!explicit_int && !defaulted_int
14614 21638197 : && !explicit_char && !explicit_intN)
14615 : {
14616 30 : if (typedef_decl)
14617 : {
14618 27 : pedwarn (loc, OPT_Wpedantic,
14619 : "%qs specified with typedef-name %qD",
14620 : key, typedef_decl);
14621 27 : ok = !flag_pedantic_errors;
14622 : /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
14623 : and is not built as a typedef. */
14624 27 : if (is_typedef_decl (typedef_decl))
14625 18 : type = DECL_ORIGINAL_TYPE (typedef_decl);
14626 : }
14627 3 : else if (declspecs->decltype_p)
14628 0 : error_at (loc, "%qs specified with %<decltype%>", key);
14629 : else
14630 3 : error_at (loc, "%qs specified with %<typeof%>", key);
14631 : }
14632 : else
14633 : ok = 1;
14634 :
14635 : /* Discard the type modifiers if they are invalid. */
14636 514 : if (! ok)
14637 : {
14638 : unsigned_p = false;
14639 : signed_p = false;
14640 : long_p = false;
14641 : short_p = false;
14642 : longlong = 0;
14643 : }
14644 : }
14645 :
14646 : /* Decide whether an integer type is signed or not.
14647 : Optionally treat bitfields as signed by default. */
14648 1068615814 : if (unsigned_p
14649 : /* [class.bit]
14650 :
14651 : It is implementation-defined whether a plain (neither
14652 : explicitly signed or unsigned) char, short, int, or long
14653 : bit-field is signed or unsigned.
14654 :
14655 : Naturally, we extend this to long long as well. Note that
14656 : this does not include wchar_t. */
14657 1068616304 : || (bitfield && !flag_signed_bitfields
14658 18 : && !signed_p
14659 : /* A typedef for plain `int' without `signed' can be
14660 : controlled just like plain `int', but a typedef for
14661 : `signed int' cannot be so controlled. */
14662 18 : && !(typedef_decl
14663 18 : && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
14664 13 : && TREE_CODE (type) == INTEGER_TYPE
14665 10 : && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
14666 : {
14667 14720705 : if (explicit_intN)
14668 537175 : type = int_n_trees[declspecs->int_n_idx].unsigned_type;
14669 14183530 : else if (longlong)
14670 1457797 : type = long_long_unsigned_type_node;
14671 12725733 : else if (long_p)
14672 2391380 : type = long_unsigned_type_node;
14673 10334353 : else if (short_p)
14674 1448596 : type = short_unsigned_type_node;
14675 8885757 : else if (type == char_type_node)
14676 1940301 : type = unsigned_char_type_node;
14677 6945456 : else if (typedef_decl)
14678 25 : type = c_common_unsigned_type (type);
14679 : else
14680 6945431 : type = unsigned_type_node;
14681 : }
14682 1053895599 : else if (signed_p && type == char_type_node)
14683 693135 : type = signed_char_type_node;
14684 1053202464 : else if (explicit_intN)
14685 599671 : type = int_n_trees[declspecs->int_n_idx].signed_type;
14686 1052602793 : else if (longlong)
14687 2351153 : type = long_long_integer_type_node;
14688 1050251640 : else if (long_p)
14689 3076286 : type = long_integer_type_node;
14690 1047175354 : else if (short_p)
14691 649316 : type = short_integer_type_node;
14692 1046526038 : else if (signed_p && typedef_decl)
14693 9 : type = c_common_signed_type (type);
14694 :
14695 1068616304 : if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
14696 : {
14697 1265760 : if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
14698 3 : error_at (declspecs->locations[ds_complex],
14699 : "complex invalid for %qs", name);
14700 : /* If a modifier is specified, the resulting complex is the complex
14701 : form of TYPE. E.g, "complex short" is "complex short int". */
14702 1265757 : else if (type == integer_type_node)
14703 171 : type = complex_integer_type_node;
14704 1265586 : else if (type == float_type_node)
14705 345965 : type = complex_float_type_node;
14706 919621 : else if (type == double_type_node)
14707 346503 : type = complex_double_type_node;
14708 573118 : else if (type == long_double_type_node)
14709 346006 : type = complex_long_double_type_node;
14710 : else
14711 227112 : type = build_complex_type (type);
14712 : }
14713 :
14714 : /* If we're using the injected-class-name to form a compound type or a
14715 : declaration, replace it with the underlying class so we don't get
14716 : redundant typedefs in the debug output. But if we are returning the
14717 : type unchanged, leave it alone so that it's available to
14718 : maybe_get_template_decl_from_type_decl. */
14719 209553861 : if (CLASS_TYPE_P (type)
14720 209489957 : && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
14721 35930373 : && type == TREE_TYPE (TYPE_NAME (type))
14722 1104546677 : && (declarator || type_quals))
14723 34308022 : type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
14724 :
14725 1068616304 : type_quals |= cp_type_quals (type);
14726 2137232608 : type = cp_build_qualified_type
14727 2137232608 : (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
14728 865598143 : || declspecs->decltype_p)
14729 : ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
14730 : /* We might have ignored or rejected some of the qualifiers. */
14731 1068616304 : type_quals = cp_type_quals (type);
14732 :
14733 1053365887 : if (cxx_dialect >= cxx17 && type && is_auto (type)
14734 23398439 : && innermost_code != cdk_function
14735 : /* Placeholder in parm gets a better error below. */
14736 14550546 : && !(decl_context == PARM || decl_context == CATCHPARM)
14737 1083128810 : && id_declarator && declarator != id_declarator)
14738 1187270 : if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
14739 : {
14740 16 : auto_diagnostic_group g;
14741 16 : gcc_rich_location richloc (typespec_loc);
14742 16 : richloc.add_fixit_insert_after ("<>");
14743 16 : error_at (&richloc, "missing template argument list after %qE; "
14744 : "for deduction, template placeholder must be followed "
14745 : "by a simple declarator-id", tmpl);
14746 16 : inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
14747 16 : type = error_mark_node;
14748 16 : }
14749 :
14750 1068616304 : staticp = 0;
14751 1068616304 : inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
14752 1068616304 : virtualp = decl_spec_seq_has_spec_p (declspecs, ds_virtual);
14753 1068616304 : explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
14754 :
14755 1068616304 : storage_class = declspecs->storage_class;
14756 1068616304 : if (storage_class == sc_static)
14757 24494093 : staticp = 1 + (decl_context == FIELD);
14758 1044122211 : else if (decl_context == FIELD && sfk == sfk_deduction_guide)
14759 : /* Treat class-scope deduction guides as static member functions
14760 : so that they get a FUNCTION_TYPE instead of a METHOD_TYPE. */
14761 24163758 : staticp = 2;
14762 :
14763 1068616304 : if (virtualp)
14764 : {
14765 4202498 : if (staticp == 2)
14766 : {
14767 21 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
14768 21 : richloc.add_range (declspecs->locations[ds_storage_class]);
14769 21 : error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
14770 : "and %<static%>", dname);
14771 21 : storage_class = sc_none;
14772 21 : staticp = 0;
14773 21 : }
14774 4202498 : if (constexpr_p && pedantic && cxx_dialect < cxx20)
14775 : {
14776 6 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
14777 6 : richloc.add_range (declspecs->locations[ds_constexpr]);
14778 6 : pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
14779 : "declared both %<virtual%> and %<constexpr%> only in "
14780 : "%<-std=c++20%> or %<-std=gnu++20%>", dname);
14781 6 : }
14782 : }
14783 1068616304 : friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
14784 :
14785 : /* Issue errors about use of storage classes for parameters. */
14786 1068616304 : if (decl_context == PARM)
14787 : {
14788 302161940 : if (typedef_p)
14789 : {
14790 24 : error_at (declspecs->locations[ds_typedef],
14791 : "typedef declaration invalid in parameter declaration");
14792 24 : return error_mark_node;
14793 : }
14794 302161916 : else if (template_parm_flag && storage_class != sc_none)
14795 : {
14796 16 : error_at (min_location (declspecs->locations[ds_thread],
14797 : declspecs->locations[ds_storage_class]),
14798 : "storage class specified for template parameter %qs",
14799 : name);
14800 16 : return error_mark_node;
14801 : }
14802 302161900 : else if (storage_class == sc_static
14803 302161900 : || storage_class == sc_extern
14804 302161897 : || thread_p)
14805 : {
14806 9 : error_at (min_location (declspecs->locations[ds_thread],
14807 : declspecs->locations[ds_storage_class]),
14808 : "storage class specified for parameter %qs", name);
14809 9 : return error_mark_node;
14810 : }
14811 :
14812 : /* Function parameters cannot be concept. */
14813 302161891 : if (concept_p)
14814 : {
14815 9 : error_at (declspecs->locations[ds_concept],
14816 : "a parameter cannot be declared %qs", "concept");
14817 9 : concept_p = 0;
14818 9 : constexpr_p = 0;
14819 : }
14820 : /* Function parameters cannot be constexpr. If we saw one, moan
14821 : and pretend it wasn't there. */
14822 302161882 : else if (constexpr_p)
14823 : {
14824 9 : error_at (declspecs->locations[ds_constexpr],
14825 : "a parameter cannot be declared %qs", "constexpr");
14826 9 : constexpr_p = 0;
14827 : }
14828 302161891 : if (constinit_p)
14829 : {
14830 6 : error_at (declspecs->locations[ds_constinit],
14831 : "a parameter cannot be declared %qs", "constinit");
14832 6 : constinit_p = 0;
14833 : }
14834 302161891 : if (consteval_p)
14835 : {
14836 3 : error_at (declspecs->locations[ds_consteval],
14837 : "a parameter cannot be declared %qs", "consteval");
14838 3 : consteval_p = 0;
14839 : }
14840 : }
14841 :
14842 : /* Give error if `virtual' is used outside of class declaration. */
14843 1068616255 : if (virtualp
14844 4202498 : && (current_class_name == NULL_TREE || decl_context != FIELD))
14845 : {
14846 68 : error_at (declspecs->locations[ds_virtual],
14847 : "%<virtual%> outside class declaration");
14848 68 : virtualp = 0;
14849 : }
14850 :
14851 1068616255 : if (innermost_code == cdk_decomp)
14852 : {
14853 233726 : location_t loc = (declarator->kind == cdk_reference
14854 243936 : ? declarator->declarator->id_loc : declarator->id_loc);
14855 243936 : if (inlinep)
14856 29 : error_at (declspecs->locations[ds_inline],
14857 : "structured binding declaration cannot be %qs", "inline");
14858 243936 : if (typedef_p)
14859 29 : error_at (declspecs->locations[ds_typedef],
14860 : "structured binding declaration cannot be %qs", "typedef");
14861 243936 : if (constexpr_p && !concept_p && cxx_dialect < cxx26)
14862 99 : pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
14863 : "structured binding declaration can be %qs only with "
14864 : "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
14865 243936 : if (consteval_p)
14866 13 : error_at (declspecs->locations[ds_consteval], "structured "
14867 : "binding declaration cannot be %qs", "consteval");
14868 243936 : if (thread_p && cxx_dialect < cxx20)
14869 75 : pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
14870 : "structured binding declaration can be %qs only in "
14871 : "%<-std=c++20%> or %<-std=gnu++20%>",
14872 75 : declspecs->gnu_thread_keyword_p
14873 : ? "__thread" : "thread_local");
14874 243936 : if (concept_p)
14875 : {
14876 0 : error_at (declspecs->locations[ds_concept],
14877 : "structured binding declaration cannot be %qs", "concept");
14878 0 : constexpr_p = 0;
14879 : }
14880 : /* [dcl.struct.bind] "A cv that includes volatile is deprecated." */
14881 243936 : if (type_quals & TYPE_QUAL_VOLATILE)
14882 26 : warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
14883 : "%<volatile%>-qualified structured binding is deprecated");
14884 243936 : switch (storage_class)
14885 : {
14886 : case sc_none:
14887 : break;
14888 28 : case sc_register:
14889 28 : error_at (loc, "structured binding declaration cannot be %qs",
14890 : "register");
14891 28 : break;
14892 252 : case sc_static:
14893 252 : if (cxx_dialect < cxx20)
14894 185 : pedwarn (loc, OPT_Wc__20_extensions,
14895 : "structured binding declaration can be %qs only in "
14896 : "%<-std=c++20%> or %<-std=gnu++20%>", "static");
14897 : break;
14898 29 : case sc_extern:
14899 29 : error_at (loc, "structured binding declaration cannot be %qs",
14900 : "extern");
14901 29 : break;
14902 28 : case sc_mutable:
14903 28 : error_at (loc, "structured binding declaration cannot be %qs",
14904 : "mutable");
14905 28 : break;
14906 0 : case sc_auto:
14907 0 : error_at (loc, "structured binding declaration cannot be "
14908 : "C++98 %<auto%>");
14909 0 : break;
14910 0 : default:
14911 0 : gcc_unreachable ();
14912 : }
14913 243936 : if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
14914 243936 : || TYPE_IDENTIFIER (type) != auto_identifier)
14915 : {
14916 3 : if (type != error_mark_node)
14917 : {
14918 3 : auto_diagnostic_group d;
14919 3 : error_at (loc, "structured binding declaration cannot have "
14920 : "type %qT", type);
14921 3 : inform (loc,
14922 : "type must be cv-qualified %<auto%> or reference to "
14923 : "cv-qualified %<auto%>");
14924 3 : }
14925 3 : type = build_qualified_type (make_auto (), type_quals);
14926 3 : declspecs->type = type;
14927 : }
14928 243933 : else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
14929 51 : pedwarn (loc, OPT_Wpedantic,
14930 : "structured binding declaration cannot have constrained "
14931 : "%<auto%> type %qT", type);
14932 243936 : inlinep = 0;
14933 243936 : typedef_p = 0;
14934 243936 : consteval_p = 0;
14935 243936 : concept_p = 0;
14936 243936 : if (storage_class != sc_static)
14937 : {
14938 243684 : storage_class = sc_none;
14939 243684 : declspecs->storage_class = sc_none;
14940 : }
14941 : }
14942 :
14943 : /* Static anonymous unions are dealt with here. */
14944 1068616255 : if (staticp && decl_context == TYPENAME
14945 0 : && declspecs->type
14946 1068616255 : && ANON_AGGR_TYPE_P (declspecs->type))
14947 : decl_context = FIELD;
14948 :
14949 : /* Warn about storage classes that are invalid for certain
14950 : kinds of declarations (parameters, typenames, etc.). */
14951 1068616255 : if (thread_p
14952 20471 : && ((storage_class
14953 20471 : && storage_class != sc_extern
14954 528 : && storage_class != sc_static)
14955 20460 : || typedef_p))
14956 : {
14957 17 : location_t loc
14958 17 : = min_location (declspecs->locations[ds_thread],
14959 : declspecs->locations[ds_storage_class]);
14960 17 : error_at (loc, "multiple storage classes in declaration of %qs", name);
14961 17 : thread_p = false;
14962 : }
14963 1068616255 : if (decl_context != NORMAL
14964 895819087 : && ((storage_class != sc_none
14965 895819087 : && storage_class != sc_mutable)
14966 871655343 : || thread_p))
14967 : {
14968 24163747 : if ((decl_context == PARM || decl_context == CATCHPARM)
14969 36 : && (storage_class == sc_register
14970 36 : || storage_class == sc_auto))
14971 : ;
14972 24163711 : else if (typedef_p)
14973 : ;
14974 24163711 : else if (decl_context == FIELD
14975 : /* C++ allows static class elements. */
14976 24163711 : && storage_class == sc_static)
14977 : /* C++ also allows inlines and signed and unsigned elements,
14978 : but in those cases we don't come in here. */
14979 : ;
14980 : else
14981 : {
14982 15 : location_t loc
14983 15 : = min_location (declspecs->locations[ds_thread],
14984 : declspecs->locations[ds_storage_class]);
14985 15 : if (decl_context == FIELD)
14986 15 : error_at (loc, "storage class specified for %qs", name);
14987 0 : else if (decl_context == PARM || decl_context == CATCHPARM)
14988 0 : error_at (loc, "storage class specified for parameter %qs", name);
14989 : else
14990 0 : error_at (loc, "storage class specified for typename");
14991 15 : if (storage_class == sc_register
14992 15 : || storage_class == sc_auto
14993 15 : || storage_class == sc_extern
14994 3 : || thread_p)
14995 15 : storage_class = sc_none;
14996 : }
14997 : }
14998 1044452508 : else if (storage_class == sc_extern && funcdef_flag
14999 1044452508 : && ! toplevel_bindings_p ())
15000 0 : error ("nested function %qs declared %<extern%>", name);
15001 1044452508 : else if (toplevel_bindings_p ())
15002 : {
15003 486796463 : if (storage_class == sc_auto)
15004 2 : error_at (declspecs->locations[ds_storage_class],
15005 : "top-level declaration of %qs specifies %<auto%>", name);
15006 : }
15007 557656045 : else if (thread_p
15008 557656045 : && storage_class != sc_extern
15009 243 : && storage_class != sc_static)
15010 : {
15011 210 : if (declspecs->gnu_thread_keyword_p)
15012 49 : pedwarn (declspecs->locations[ds_thread],
15013 49 : 0, "function-scope %qs implicitly auto and "
15014 : "declared %<__thread%>", name);
15015 :
15016 : /* When thread_local is applied to a variable of block scope the
15017 : storage-class-specifier static is implied if it does not appear
15018 : explicitly. */
15019 210 : storage_class = declspecs->storage_class = sc_static;
15020 210 : staticp = 1;
15021 : }
15022 :
15023 1068616255 : if (storage_class && friendp)
15024 : {
15025 12 : error_at (min_location (declspecs->locations[ds_thread],
15026 : declspecs->locations[ds_storage_class]),
15027 : "storage class specifiers invalid in friend function "
15028 : "declarations");
15029 12 : storage_class = sc_none;
15030 12 : staticp = 0;
15031 : }
15032 :
15033 1068616255 : if (!id_declarator)
15034 : unqualified_id = NULL_TREE;
15035 : else
15036 : {
15037 601547067 : unqualified_id = id_declarator->u.id.unqualified_name;
15038 601547067 : switch (TREE_CODE (unqualified_id))
15039 : {
15040 3330263 : case BIT_NOT_EXPR:
15041 3330263 : unqualified_id = TREE_OPERAND (unqualified_id, 0);
15042 3330263 : if (TYPE_P (unqualified_id))
15043 3330260 : unqualified_id = constructor_name (unqualified_id);
15044 : break;
15045 :
15046 : case IDENTIFIER_NODE:
15047 : case TEMPLATE_ID_EXPR:
15048 : break;
15049 :
15050 0 : default:
15051 0 : gcc_unreachable ();
15052 : }
15053 : }
15054 :
15055 1068616255 : if (declspecs->std_attributes)
15056 : {
15057 795 : location_t attr_loc = declspecs->locations[ds_std_attribute];
15058 795 : auto_diagnostic_group d;
15059 795 : if (any_nonignored_attribute_p (declspecs->std_attributes)
15060 795 : && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
15061 792 : inform (attr_loc, "an attribute that appertains to a type-specifier "
15062 : "is ignored");
15063 795 : }
15064 :
15065 : /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn. */
15066 : bool is_xobj_member_function = false;
15067 : /* Determine the type of the entity declared by recurring on the
15068 : declarator. */
15069 1467339662 : for (; declarator; declarator = declarator->declarator)
15070 : {
15071 1000514436 : const cp_declarator *inner_declarator;
15072 1000514436 : tree attrs;
15073 :
15074 1000514436 : if (type == error_mark_node)
15075 607 : return error_mark_node;
15076 :
15077 1000514108 : attrs = declarator->attributes;
15078 1000514108 : if (attrs)
15079 : {
15080 13433 : int attr_flags;
15081 :
15082 13433 : attr_flags = 0;
15083 13433 : if (declarator->kind == cdk_id)
15084 12726 : attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
15085 13433 : if (declarator->kind == cdk_function)
15086 690 : attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
15087 13433 : if (declarator->kind == cdk_array)
15088 2 : attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
15089 13433 : tree late_attrs = NULL_TREE;
15090 13433 : if (decl_context != PARM && decl_context != TYPENAME)
15091 : /* Assume that any attributes that get applied late to
15092 : templates will DTRT when applied to the declaration
15093 : as a whole. */
15094 13421 : late_attrs = splice_template_attributes (&attrs, type);
15095 13433 : returned_attrs = decl_attributes (&type,
15096 : attr_chainon (returned_attrs,
15097 : attrs),
15098 : attr_flags);
15099 13433 : returned_attrs = attr_chainon (late_attrs, returned_attrs);
15100 : }
15101 :
15102 1000514108 : inner_declarator = declarator->declarator;
15103 :
15104 : /* We don't want to warn in parameter context because we don't
15105 : yet know if the parse will succeed, and this might turn out
15106 : to be a constructor call. */
15107 1000514108 : if (decl_context != PARM
15108 1000514108 : && decl_context != TYPENAME
15109 581038797 : && !typedef_p
15110 531411935 : && declarator->parenthesized != UNKNOWN_LOCATION
15111 : /* If the type is class-like and the inner name used a
15112 : global namespace qualifier, we need the parens.
15113 : Unfortunately all we can tell is whether a qualified name
15114 : was used or not. */
15115 1000514289 : && !(inner_declarator
15116 126 : && inner_declarator->kind == cdk_id
15117 108 : && inner_declarator->u.id.qualifying_scope
15118 18 : && (MAYBE_CLASS_TYPE_P (type)
15119 12 : || TREE_CODE (type) == ENUMERAL_TYPE)))
15120 : {
15121 169 : auto_diagnostic_group d;
15122 169 : if (warning_at (declarator->parenthesized, OPT_Wparentheses,
15123 : "unnecessary parentheses in declaration of %qs",
15124 : name))
15125 : {
15126 42 : gcc_rich_location iloc (declarator->parenthesized);
15127 42 : iloc.add_fixit_remove (get_start (declarator->parenthesized));
15128 42 : iloc.add_fixit_remove (get_finish (declarator->parenthesized));
15129 42 : inform (&iloc, "remove parentheses");
15130 42 : }
15131 169 : }
15132 1000514108 : if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
15133 : break;
15134 :
15135 398723686 : switch (declarator->kind)
15136 : {
15137 3698279 : case cdk_array:
15138 7396558 : type = create_array_type_for_decl (dname, type,
15139 3698279 : declarator->u.array.bounds,
15140 3698279 : declarator->id_loc);
15141 3698279 : if (!valid_array_size_p (dname
15142 : ? declarator->id_loc : input_location,
15143 : type, dname))
15144 267 : type = error_mark_node;
15145 :
15146 3698279 : if (declarator->std_attributes)
15147 : /* [dcl.array]/1:
15148 :
15149 : The optional attribute-specifier-seq appertains to the
15150 : array type. */
15151 209 : cplus_decl_attributes (&type, declarator->std_attributes, 0);
15152 : break;
15153 :
15154 195806801 : case cdk_function:
15155 195806801 : {
15156 195806801 : tree arg_types;
15157 195806801 : int funcdecl_p;
15158 :
15159 : /* Declaring a function type. */
15160 :
15161 : /* Pick up type qualifiers which should be applied to `this'. */
15162 195806801 : memfn_quals = declarator->u.function.qualifiers;
15163 : /* Pick up virt-specifiers. */
15164 195806801 : virt_specifiers = declarator->u.function.virt_specifiers;
15165 : /* And ref-qualifier, too */
15166 195806801 : rqual = declarator->u.function.ref_qualifier;
15167 : /* And tx-qualifier. */
15168 195806801 : tree tx_qual = declarator->u.function.tx_qualifier;
15169 : /* Pick up the exception specifications. */
15170 195806801 : raises = declarator->u.function.exception_specification;
15171 : /* If the exception-specification is ill-formed, let's pretend
15172 : there wasn't one. */
15173 195806801 : if (raises == error_mark_node)
15174 9 : raises = NULL_TREE;
15175 :
15176 391613602 : auto find_xobj_parm = [](tree parm_list)
15177 : {
15178 : /* There is no need to iterate over the list,
15179 : only the first parm can be a valid xobj parm. */
15180 391380722 : if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
15181 : return NULL_TREE;
15182 : /* If we make it here, we are looking at an xobj parm.
15183 :
15184 : Non-null 'purpose' usually means the parm has a default
15185 : argument, we don't want to violate this assumption. */
15186 93283 : TREE_PURPOSE (parm_list) = NULL_TREE;
15187 93283 : return TREE_VALUE (parm_list);
15188 : };
15189 :
15190 195806801 : tree xobj_parm
15191 195806801 : = find_xobj_parm (declarator->u.function.parameters);
15192 195806801 : is_xobj_member_function = xobj_parm;
15193 :
15194 195806801 : if (xobj_parm && cxx_dialect < cxx23)
15195 42051 : pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
15196 : "explicit object member function only available "
15197 : "with %<-std=c++23%> or %<-std=gnu++23%>");
15198 :
15199 195806801 : if (xobj_parm && decl_context == TYPENAME)
15200 : {
15201 : /* We inform in every case, just differently depending on what
15202 : case it is. */
15203 9 : auto_diagnostic_group d;
15204 9 : bool ptr_type = true;
15205 : /* If declarator->kind is cdk_function and we are at the end of
15206 : the declarator chain, we are looking at a function type. */
15207 9 : if (!declarator->declarator)
15208 : {
15209 3 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15210 : "a function type cannot "
15211 : "have an explicit object parameter");
15212 3 : ptr_type = false;
15213 : }
15214 6 : else if (declarator->declarator->kind == cdk_pointer)
15215 3 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15216 : "a pointer to function type cannot "
15217 : "have an explicit object parameter");
15218 3 : else if (declarator->declarator->kind == cdk_ptrmem)
15219 3 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15220 : "a pointer to member function type "
15221 : "cannot have an explicit object parameter");
15222 : else
15223 0 : gcc_unreachable ();
15224 :
15225 : /* The locations being used here are probably not correct. */
15226 6 : if (ptr_type)
15227 6 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15228 : "the type of a pointer to explicit object member "
15229 : "function is a regular pointer to function type");
15230 : else
15231 3 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15232 : "the type of an explicit object "
15233 : "member function is a regular function type");
15234 : /* Ideally we should synthesize the correct syntax
15235 : for the user, perhaps this could be added later. */
15236 9 : }
15237 : /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
15238 : the first parm node will never erroneously be detected here. */
15239 195806801 : {
15240 195806801 : auto_diagnostic_group d;
15241 195806801 : bool bad_xobj_parm_encountered = false;
15242 195806801 : for (tree parm = declarator->u.function.parameters;
15243 485682468 : parm && parm != void_list_node;
15244 289875667 : parm = TREE_CHAIN (parm))
15245 : {
15246 289875667 : if (TREE_PURPOSE (parm) != this_identifier)
15247 289875658 : continue;
15248 9 : bad_xobj_parm_encountered = true;
15249 9 : TREE_PURPOSE (parm) = NULL_TREE;
15250 9 : gcc_rich_location bad_xobj_parm
15251 9 : (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
15252 9 : error_at (&bad_xobj_parm,
15253 : "only the first parameter of a member function "
15254 : "can be declared as an explicit object parameter");
15255 9 : }
15256 195806801 : if (bad_xobj_parm_encountered && xobj_parm)
15257 0 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15258 : "valid explicit object parameter declared here");
15259 195806801 : }
15260 :
15261 195806801 : if (reqs)
15262 3 : error_at (location_of (reqs), "requires-clause on return type");
15263 195806801 : reqs = declarator->u.function.requires_clause;
15264 :
15265 : /* Say it's a definition only for the CALL_EXPR
15266 : closest to the identifier. */
15267 195806801 : funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
15268 :
15269 : /* Handle a late-specified return type. */
15270 195806801 : tree late_return_type = declarator->u.function.late_return_type;
15271 195806801 : if (tree auto_node = type_uses_auto (type))
15272 : {
15273 8859728 : if (!late_return_type)
15274 : {
15275 5155283 : if (!funcdecl_p)
15276 : /* auto (*fp)() = f; is OK. */;
15277 5155249 : else if (current_class_type
15278 9479126 : && LAMBDA_TYPE_P (current_class_type))
15279 : /* OK for C++11 lambdas. */;
15280 3324647 : else if (cxx_dialect < cxx14)
15281 : {
15282 7 : auto_diagnostic_group d;
15283 7 : error_at (typespec_loc, "%qs function uses "
15284 : "%<auto%> type specifier without "
15285 : "trailing return type", name);
15286 7 : inform (typespec_loc,
15287 : "deduced return type only available "
15288 : "with %<-std=c++14%> or %<-std=gnu++14%>");
15289 7 : }
15290 3324640 : else if (virtualp)
15291 : {
15292 6 : error_at (typespec_loc, "virtual function "
15293 : "cannot have deduced return type");
15294 6 : virtualp = false;
15295 : }
15296 : }
15297 3704445 : else if (!is_auto (type) && sfk != sfk_conversion)
15298 : {
15299 15 : error_at (typespec_loc, "%qs function with trailing "
15300 : "return type has %qT as its type rather "
15301 : "than plain %<auto%>", name, type);
15302 276 : return error_mark_node;
15303 : }
15304 3704430 : else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
15305 : {
15306 9 : if (funcdecl_p)
15307 3 : error_at (typespec_loc,
15308 : "%qs function with trailing return type "
15309 : "has %<decltype(auto)%> as its type "
15310 : "rather than plain %<auto%>", name);
15311 : else
15312 6 : error_at (typespec_loc,
15313 : "invalid use of %<decltype(auto)%>");
15314 9 : return error_mark_node;
15315 : }
15316 3704421 : else if (is_constrained_auto (type))
15317 : {
15318 6 : if (funcdecl_p)
15319 3 : error_at (typespec_loc,
15320 : "%qs function with trailing return type "
15321 : "has constrained %<auto%> type specifier "
15322 : "rather than plain %<auto%>",
15323 : name);
15324 : else
15325 3 : error_at (typespec_loc,
15326 : "invalid use of constrained %<auto%> type");
15327 6 : return error_mark_node;
15328 : }
15329 8859698 : tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
15330 8859698 : if (!tmpl)
15331 7606807 : if (tree late_auto = type_uses_auto (late_return_type))
15332 39726 : tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
15333 7606807 : if (tmpl)
15334 : {
15335 1252897 : if (!funcdecl_p || !dguide_name_p (unqualified_id))
15336 : {
15337 13 : auto_diagnostic_group g;
15338 13 : error_at (typespec_loc, "deduced class "
15339 : "type %qD in function return type",
15340 13 : DECL_NAME (tmpl));
15341 13 : inform (DECL_SOURCE_LOCATION (tmpl),
15342 : "%qD declared here", tmpl);
15343 13 : return error_mark_node;
15344 13 : }
15345 1252884 : else if (!late_return_type)
15346 : {
15347 3 : auto_diagnostic_group d;
15348 3 : error_at (declarator->id_loc, "deduction guide "
15349 : "for %qT must have trailing return "
15350 3 : "type", TREE_TYPE (tmpl));
15351 3 : inform (DECL_SOURCE_LOCATION (tmpl),
15352 : "%qD declared here", tmpl);
15353 3 : return error_mark_node;
15354 3 : }
15355 1252881 : else if (CLASS_TYPE_P (late_return_type)
15356 1252881 : && CLASSTYPE_TEMPLATE_INFO (late_return_type)
15357 2505762 : && (CLASSTYPE_TI_TEMPLATE (late_return_type)
15358 : == tmpl))
15359 : /* OK */;
15360 : else
15361 0 : error ("trailing return type %qT of deduction guide "
15362 : "is not a specialization of %qT",
15363 0 : late_return_type, TREE_TYPE (tmpl));
15364 : }
15365 : }
15366 186947073 : else if (late_return_type
15367 186947073 : && sfk != sfk_conversion)
15368 : {
15369 37 : if (late_return_type == error_mark_node)
15370 : return error_mark_node;
15371 37 : if (cxx_dialect < cxx11)
15372 : /* Not using maybe_warn_cpp0x because this should
15373 : always be an error. */
15374 1 : error_at (typespec_loc,
15375 : "trailing return type only available "
15376 : "with %<-std=c++11%> or %<-std=gnu++11%>");
15377 : else
15378 36 : error_at (typespec_loc, "%qs function with trailing "
15379 : "return type not declared with %<auto%> "
15380 : "type specifier", name);
15381 37 : return error_mark_node;
15382 : }
15383 195806718 : if (late_return_type && sfk == sfk_conversion)
15384 : {
15385 14 : error ("a conversion function cannot have a trailing return type");
15386 14 : return error_mark_node;
15387 : }
15388 195806704 : type = splice_late_return_type (type, late_return_type);
15389 195806704 : if (type == error_mark_node)
15390 : return error_mark_node;
15391 :
15392 195806626 : if (late_return_type)
15393 : {
15394 3704323 : late_return_type_p = true;
15395 3704323 : type_quals = cp_type_quals (type);
15396 : }
15397 :
15398 195806626 : if (type_quals != TYPE_UNQUALIFIED)
15399 : {
15400 : /* It's wrong, for instance, to issue a -Wignored-qualifiers
15401 : warning for
15402 : static_assert(!is_same_v<void(*)(), const void(*)()>);
15403 : because there the qualifier matters. */
15404 12063 : if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
15405 232 : warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
15406 : "qualifiers ignored on function return type");
15407 : /* [dcl.fct] "A volatile-qualified return type is
15408 : deprecated." */
15409 12063 : if (type_quals & TYPE_QUAL_VOLATILE)
15410 599 : warning_at (typespec_loc, OPT_Wvolatile,
15411 : "%<volatile%>-qualified return type is "
15412 : "deprecated");
15413 :
15414 : /* We now know that the TYPE_QUALS don't apply to the
15415 : decl, but to its return type. */
15416 : type_quals = TYPE_UNQUALIFIED;
15417 : }
15418 :
15419 : /* Error about some types functions can't return. */
15420 :
15421 195806626 : if (TREE_CODE (type) == FUNCTION_TYPE)
15422 : {
15423 30 : error_at (typespec_loc, "%qs declared as function returning "
15424 : "a function", name);
15425 30 : return error_mark_node;
15426 : }
15427 195806596 : if (TREE_CODE (type) == ARRAY_TYPE)
15428 : {
15429 6 : error_at (typespec_loc, "%qs declared as function returning "
15430 : "an array", name);
15431 6 : return error_mark_node;
15432 : }
15433 195806590 : if (constinit_p && funcdecl_p)
15434 : {
15435 15 : error_at (declspecs->locations[ds_constinit],
15436 : "%<constinit%> on function return type is not "
15437 : "allowed");
15438 15 : return error_mark_node;
15439 : }
15440 :
15441 195806575 : if (check_decltype_auto (typespec_loc, type))
15442 50 : return error_mark_node;
15443 :
15444 195806525 : if (ctype == NULL_TREE
15445 195806525 : && decl_context == FIELD
15446 : && funcdecl_p
15447 113109676 : && friendp == 0)
15448 106117737 : ctype = current_class_type;
15449 :
15450 195806525 : if (ctype && (sfk == sfk_constructor
15451 106117737 : || sfk == sfk_destructor))
15452 : {
15453 : /* We are within a class's scope. If our declarator name
15454 : is the same as the class name, and we are defining
15455 : a function, then it is a constructor/destructor, and
15456 : therefore returns a void type. */
15457 :
15458 : /* ISO C++ 12.4/2. A destructor may not be declared
15459 : const or volatile. A destructor may not be static.
15460 : A destructor may not be declared with ref-qualifier.
15461 :
15462 : ISO C++ 12.1. A constructor may not be declared
15463 : const or volatile. A constructor may not be
15464 : virtual. A constructor may not be static.
15465 : A constructor may not be declared with ref-qualifier. */
15466 27161839 : if (staticp == 2)
15467 9 : error_at (declspecs->locations[ds_storage_class],
15468 : (flags == DTOR_FLAG)
15469 : ? G_("destructor cannot be static member "
15470 : "function")
15471 : : G_("constructor cannot be static member "
15472 : "function"));
15473 27161839 : if (memfn_quals)
15474 : {
15475 9 : error ((flags == DTOR_FLAG)
15476 : ? G_("destructors may not be cv-qualified")
15477 : : G_("constructors may not be cv-qualified"));
15478 9 : memfn_quals = TYPE_UNQUALIFIED;
15479 : }
15480 :
15481 27161839 : if (rqual)
15482 : {
15483 6 : maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
15484 6 : error ((flags == DTOR_FLAG)
15485 : ? G_("destructors may not be ref-qualified")
15486 : : G_("constructors may not be ref-qualified"));
15487 6 : rqual = REF_QUAL_NONE;
15488 : }
15489 :
15490 27161839 : if (decl_context == FIELD
15491 27161839 : && !member_function_or_else (ctype,
15492 : current_class_type,
15493 : flags))
15494 0 : return error_mark_node;
15495 :
15496 27161839 : if (flags != DTOR_FLAG)
15497 : {
15498 : /* It's a constructor. */
15499 24000735 : if (explicitp == 1)
15500 5589864 : explicitp = 2;
15501 24000735 : if (virtualp)
15502 : {
15503 3 : permerror (declspecs->locations[ds_virtual],
15504 : "constructors cannot be declared %<virtual%>");
15505 3 : virtualp = 0;
15506 : }
15507 24000735 : if (decl_context == FIELD
15508 24000735 : && sfk != sfk_constructor)
15509 0 : return error_mark_node;
15510 : }
15511 27161839 : if (decl_context == FIELD)
15512 27161839 : staticp = 0;
15513 : }
15514 168644686 : else if (friendp)
15515 : {
15516 6669473 : if (virtualp)
15517 : {
15518 : /* Cannot be both friend and virtual. */
15519 12 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
15520 12 : richloc.add_range (declspecs->locations[ds_friend]);
15521 12 : error_at (&richloc, "virtual functions cannot be friends");
15522 12 : friendp = 0;
15523 12 : }
15524 6669473 : if (decl_context == NORMAL)
15525 0 : error_at (declarator->id_loc,
15526 : "friend declaration not in class definition");
15527 6669473 : if (current_function_decl && funcdef_flag)
15528 : {
15529 9 : error_at (declarator->id_loc,
15530 : "cannot define friend function %qs in a local "
15531 : "class definition", name);
15532 9 : friendp = 0;
15533 : }
15534 : /* [class.friend]/6: A function can be defined in a friend
15535 : declaration if the function name is unqualified. */
15536 6669473 : if (funcdef_flag && in_namespace)
15537 : {
15538 6 : if (in_namespace == global_namespace)
15539 3 : error_at (declarator->id_loc,
15540 : "friend function definition %qs cannot have "
15541 : "a name qualified with %<::%>", name);
15542 : else
15543 3 : error_at (declarator->id_loc,
15544 : "friend function definition %qs cannot have "
15545 : "a name qualified with %<%D::%>", name,
15546 : in_namespace);
15547 : }
15548 : }
15549 161975213 : else if (ctype && sfk == sfk_conversion)
15550 : {
15551 1048001 : if (explicitp == 1)
15552 : {
15553 490539 : maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
15554 490539 : explicitp = 2;
15555 : }
15556 : }
15557 160927212 : else if (sfk == sfk_deduction_guide)
15558 : {
15559 1252881 : if (explicitp == 1)
15560 195806525 : explicitp = 2;
15561 : }
15562 :
15563 195806525 : if (xobj_parm)
15564 : {
15565 93283 : if (!ctype
15566 93283 : && decl_context == NORMAL
15567 71 : && (in_namespace
15568 71 : || !declarator->declarator->u.id.qualifying_scope))
15569 6 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15570 : "a non-member function cannot have "
15571 : "an explicit object parameter");
15572 : else
15573 : {
15574 93277 : if (virtualp)
15575 : {
15576 24 : auto_diagnostic_group d;
15577 24 : error_at (declspecs->locations[ds_virtual],
15578 : "an explicit object member function cannot "
15579 : "be %<virtual%>");
15580 24 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15581 : "explicit object parameter declared here");
15582 24 : virtualp = false;
15583 24 : }
15584 93277 : if (staticp >= 2)
15585 : {
15586 3 : auto_diagnostic_group d;
15587 3 : error_at (declspecs->locations[ds_storage_class],
15588 : "an explicit object member function cannot "
15589 : "be %<static%>");
15590 3 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15591 : "explicit object parameter declared here");
15592 3 : }
15593 93277 : if (unqualified_id
15594 195899793 : && identifier_p (unqualified_id)
15595 186545 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
15596 12 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15597 : "%qD cannot be an explicit object member "
15598 : "function", unqualified_id);
15599 : }
15600 : }
15601 195806525 : tree pushed_scope = NULL_TREE;
15602 195806525 : if (funcdecl_p
15603 195806525 : && decl_context != FIELD
15604 80742166 : && inner_declarator->u.id.qualifying_scope
15605 204991803 : && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
15606 9183850 : pushed_scope
15607 9183850 : = push_scope (inner_declarator->u.id.qualifying_scope);
15608 :
15609 195806525 : arg_types = grokparms (declarator->u.function.parameters, &parms);
15610 :
15611 195806525 : if (pushed_scope)
15612 9183850 : pop_scope (pushed_scope);
15613 :
15614 195806525 : if (inner_declarator
15615 195418983 : && inner_declarator->kind == cdk_id
15616 193529376 : && inner_declarator->u.id.sfk == sfk_destructor
15617 3330254 : && arg_types != void_list_node)
15618 : {
15619 21 : error_at (declarator->id_loc,
15620 : "destructors may not have parameters");
15621 21 : arg_types = void_list_node;
15622 21 : parms = NULL_TREE;
15623 21 : is_xobj_member_function = false;
15624 : }
15625 :
15626 195806525 : type = cp_build_function_type (type, arg_types);
15627 :
15628 195806525 : tree attrs = declarator->std_attributes;
15629 195806525 : if (tx_qual)
15630 : {
15631 242 : tree att = build_tree_list (tx_qual, NULL_TREE);
15632 : /* transaction_safe applies to the type, but
15633 : transaction_safe_dynamic applies to the function. */
15634 242 : if (is_attribute_p ("transaction_safe", tx_qual))
15635 213 : attrs = attr_chainon (attrs, att);
15636 : else
15637 29 : returned_attrs = attr_chainon (returned_attrs, att);
15638 : }
15639 :
15640 : /* Actually apply the contract attributes to the declaration. */
15641 195806525 : if (flag_contracts)
15642 22450719 : contract_specifiers
15643 22450719 : = attr_chainon (contract_specifiers,
15644 22450719 : declarator->u.function.contract_specifiers);
15645 :
15646 195806525 : if (attrs)
15647 : /* [dcl.fct]/2:
15648 :
15649 : The optional attribute-specifier-seq appertains to
15650 : the function type. */
15651 513 : cplus_decl_attributes (&type, attrs, 0);
15652 :
15653 195806525 : if (raises)
15654 78010318 : type = build_exception_variant (type, raises);
15655 : }
15656 195806525 : break;
15657 :
15658 199218606 : case cdk_pointer:
15659 199218606 : case cdk_reference:
15660 199218606 : case cdk_ptrmem:
15661 : /* Filter out pointers-to-references and references-to-references.
15662 : We can get these if a TYPE_DECL is used. */
15663 :
15664 199218606 : if (TYPE_REF_P (type))
15665 : {
15666 240 : if (declarator->kind != cdk_reference)
15667 : {
15668 3 : error ("cannot declare pointer to %q#T", type);
15669 3 : type = TREE_TYPE (type);
15670 : }
15671 :
15672 : /* In C++0x, we allow reference to reference declarations
15673 : that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
15674 : and template type arguments [14.3.1/4 temp.arg.type]. The
15675 : check for direct reference to reference declarations, which
15676 : are still forbidden, occurs below. Reasoning behind the change
15677 : can be found in DR106, DR540, and the rvalue reference
15678 : proposals. */
15679 237 : else if (cxx_dialect == cxx98)
15680 : {
15681 0 : error ("cannot declare reference to %q#T", type);
15682 0 : type = TREE_TYPE (type);
15683 : }
15684 : }
15685 199218366 : else if (VOID_TYPE_P (type))
15686 : {
15687 5317072 : if (declarator->kind == cdk_reference)
15688 4 : error ("cannot declare reference to %q#T", type);
15689 5317068 : else if (declarator->kind == cdk_ptrmem)
15690 3 : error ("cannot declare pointer to %q#T member", type);
15691 : }
15692 :
15693 : /* We now know that the TYPE_QUALS don't apply to the decl,
15694 : but to the target of the pointer. */
15695 199218606 : type_quals = TYPE_UNQUALIFIED;
15696 :
15697 : /* This code used to handle METHOD_TYPE, but I don't think it's
15698 : possible to get it here anymore. */
15699 199218606 : gcc_assert (TREE_CODE (type) != METHOD_TYPE);
15700 199218606 : if (declarator->kind == cdk_ptrmem
15701 1139858 : && TREE_CODE (type) == FUNCTION_TYPE)
15702 : {
15703 922458 : memfn_quals |= type_memfn_quals (type);
15704 1844916 : type = build_memfn_type (type,
15705 922458 : declarator->u.pointer.class_type,
15706 : memfn_quals,
15707 : rqual);
15708 922458 : if (type == error_mark_node)
15709 : return error_mark_node;
15710 :
15711 : rqual = REF_QUAL_NONE;
15712 : memfn_quals = TYPE_UNQUALIFIED;
15713 : }
15714 :
15715 199218603 : if (TREE_CODE (type) == FUNCTION_TYPE
15716 199218603 : && (type_memfn_quals (type) != TYPE_UNQUALIFIED
15717 1042242 : || type_memfn_rqual (type) != REF_QUAL_NONE))
15718 15 : error (declarator->kind == cdk_reference
15719 : ? G_("cannot declare reference to qualified function type %qT")
15720 : : G_("cannot declare pointer to qualified function type %qT"),
15721 : type);
15722 :
15723 : /* When the pointed-to type involves components of variable size,
15724 : care must be taken to ensure that the size evaluation code is
15725 : emitted early enough to dominate all the possible later uses
15726 : and late enough for the variables on which it depends to have
15727 : been assigned.
15728 :
15729 : This is expected to happen automatically when the pointed-to
15730 : type has a name/declaration of it's own, but special attention
15731 : is required if the type is anonymous.
15732 :
15733 : We handle the NORMAL and FIELD contexts here by inserting a
15734 : dummy statement that just evaluates the size at a safe point
15735 : and ensures it is not deferred until e.g. within a deeper
15736 : conditional context (c++/43555).
15737 :
15738 : We expect nothing to be needed here for PARM or TYPENAME.
15739 : Evaluating the size at this point for TYPENAME would
15740 : actually be incorrect, as we might be in the middle of an
15741 : expression with side effects on the pointed-to type size
15742 : "arguments" prior to the pointer declaration point and the
15743 : size evaluation could end up prior to the side effects. */
15744 :
15745 199218603 : if (!TYPE_NAME (type)
15746 5624384 : && (decl_context == NORMAL || decl_context == FIELD)
15747 628735 : && at_function_scope_p ()
15748 199259410 : && variably_modified_type_p (type, NULL_TREE))
15749 : {
15750 119 : TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
15751 : NULL_TREE, type);
15752 119 : add_decl_expr (TYPE_NAME (type));
15753 : }
15754 :
15755 199218603 : if (declarator->kind == cdk_reference)
15756 : {
15757 : /* In C++0x, the type we are creating a reference to might be
15758 : a typedef which is itself a reference type. In that case,
15759 : we follow the reference collapsing rules in
15760 : [7.1.3/8 dcl.typedef] to create the final reference type:
15761 :
15762 : "If a typedef TD names a type that is a reference to a type
15763 : T, an attempt to create the type 'lvalue reference to cv TD'
15764 : creates the type 'lvalue reference to T,' while an attempt
15765 : to create the type "rvalue reference to cv TD' creates the
15766 : type TD."
15767 : */
15768 133410642 : if (VOID_TYPE_P (type))
15769 : /* We already gave an error. */;
15770 133410638 : else if (TYPE_REF_P (type))
15771 : {
15772 237 : if (declarator->u.reference.rvalue_ref)
15773 : /* Leave type alone. */;
15774 : else
15775 116 : type = cp_build_reference_type (TREE_TYPE (type), false);
15776 : }
15777 : else
15778 133410401 : type = cp_build_reference_type
15779 133410401 : (type, declarator->u.reference.rvalue_ref);
15780 :
15781 : /* In C++0x, we need this check for direct reference to
15782 : reference declarations, which are forbidden by
15783 : [8.3.2/5 dcl.ref]. Reference to reference declarations
15784 : are only allowed indirectly through typedefs and template
15785 : type arguments. Example:
15786 :
15787 : void foo(int & &); // invalid ref-to-ref decl
15788 :
15789 : typedef int & int_ref;
15790 : void foo(int_ref &); // valid ref-to-ref decl
15791 : */
15792 133410642 : if (inner_declarator && inner_declarator->kind == cdk_reference)
15793 2 : error ("cannot declare reference to %q#T, which is not "
15794 : "a typedef or a template type argument", type);
15795 : }
15796 65807961 : else if (TREE_CODE (type) == METHOD_TYPE)
15797 922455 : type = build_ptrmemfunc_type (build_pointer_type (type));
15798 64885506 : else if (declarator->kind == cdk_ptrmem)
15799 : {
15800 217400 : gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
15801 : != NAMESPACE_DECL);
15802 217400 : if (declarator->u.pointer.class_type == error_mark_node)
15803 : /* We will already have complained. */
15804 3 : type = error_mark_node;
15805 : else
15806 217397 : type = build_ptrmem_type (declarator->u.pointer.class_type,
15807 : type);
15808 : }
15809 : else
15810 64668106 : type = build_pointer_type (type);
15811 :
15812 : /* Process a list of type modifier keywords (such as
15813 : const or volatile) that were given inside the `*' or `&'. */
15814 :
15815 199218603 : if (declarator->u.pointer.qualifiers)
15816 : {
15817 8735711 : type
15818 8735711 : = cp_build_qualified_type (type,
15819 : declarator->u.pointer.qualifiers);
15820 8735711 : type_quals = cp_type_quals (type);
15821 : }
15822 :
15823 : /* Apply C++11 attributes to the pointer, and not to the
15824 : type pointed to. This is unlike what is done for GNU
15825 : attributes above. It is to comply with [dcl.ptr]/1:
15826 :
15827 : [the optional attribute-specifier-seq (7.6.1) appertains
15828 : to the pointer and not to the object pointed to]. */
15829 199218603 : if (declarator->std_attributes)
15830 189 : cplus_decl_attributes (&type, declarator->std_attributes, 0);
15831 :
15832 : ctype = NULL_TREE;
15833 : break;
15834 :
15835 : case cdk_error:
15836 : break;
15837 :
15838 0 : default:
15839 0 : gcc_unreachable ();
15840 : }
15841 : }
15842 :
15843 1068615648 : id_loc = declarator ? declarator->id_loc : input_location;
15844 :
15845 1068615648 : if (innermost_code != cdk_function
15846 : /* Don't check this if it can be the artificial decltype(auto)
15847 : we created when building a constraint in a compound-requirement:
15848 : that the type-constraint is plain is going to be checked in
15849 : cp_parser_compound_requirement. */
15850 1068615648 : && decl_context != TYPENAME
15851 1068615648 : && check_decltype_auto (id_loc, type))
15852 20 : return error_mark_node;
15853 :
15854 : /* A `constexpr' specifier used in an object declaration declares
15855 : the object as `const'. */
15856 1068615628 : if (constexpr_p && innermost_code != cdk_function)
15857 : {
15858 : /* DR1688 says that a `constexpr' specifier in combination with
15859 : `volatile' is valid. */
15860 :
15861 20308902 : if (!TYPE_REF_P (type))
15862 : {
15863 20297302 : type_quals |= TYPE_QUAL_CONST;
15864 20297302 : type = cp_build_qualified_type (type, type_quals);
15865 : }
15866 : }
15867 :
15868 601546469 : if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
15869 2895909 : && !FUNC_OR_METHOD_TYPE_P (type)
15870 1070546339 : && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
15871 : {
15872 0 : error ("template-id %qD used as a declarator",
15873 : unqualified_id);
15874 0 : unqualified_id = dname;
15875 : }
15876 :
15877 : /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
15878 : qualified with a class-name, turn it into a METHOD_TYPE, unless
15879 : we know that the function is static. We take advantage of this
15880 : opportunity to do other processing that pertains to entities
15881 : explicitly declared to be class members. Note that if DECLARATOR
15882 : is non-NULL, we know it is a cdk_id declarator; otherwise, we
15883 : would not have exited the loop above. */
15884 1068615628 : if (declarator
15885 601790405 : && declarator->kind == cdk_id
15886 601546469 : && declarator->u.id.qualifying_scope
15887 1078584056 : && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
15888 : {
15889 9692447 : ctype = declarator->u.id.qualifying_scope;
15890 9692447 : ctype = TYPE_MAIN_VARIANT (ctype);
15891 9692447 : template_count = num_template_headers_for_class (ctype);
15892 :
15893 9692447 : if (ctype == current_class_type)
15894 : {
15895 54 : if (friendp)
15896 : {
15897 15 : permerror (declspecs->locations[ds_friend],
15898 : "member functions are implicitly "
15899 : "friends of their class");
15900 15 : friendp = 0;
15901 : }
15902 : else
15903 39 : permerror (id_loc, "extra qualification %<%T::%> on member %qs",
15904 : ctype, name);
15905 : }
15906 9692393 : else if (/* If the qualifying type is already complete, then we
15907 : can skip the following checks. */
15908 9692393 : !COMPLETE_TYPE_P (ctype)
15909 154 : && (/* If the function is being defined, then
15910 : qualifying type must certainly be complete. */
15911 : funcdef_flag
15912 : /* A friend declaration of "T::f" is OK, even if
15913 : "T" is a template parameter. But, if this
15914 : function is not a friend, the qualifying type
15915 : must be a class. */
15916 117 : || (!friendp && !CLASS_TYPE_P (ctype))
15917 : /* For a declaration, the type need not be
15918 : complete, if either it is dependent (since there
15919 : is no meaningful definition of complete in that
15920 : case) or the qualifying class is currently being
15921 : defined. */
15922 129 : || !(dependent_type_p (ctype)
15923 24 : || currently_open_class (ctype)))
15924 : /* Check that the qualifying type is complete. */
15925 9692457 : && !complete_type_or_else (ctype, NULL_TREE))
15926 64 : return error_mark_node;
15927 9692329 : else if (TREE_CODE (type) == FUNCTION_TYPE)
15928 : {
15929 9184100 : if (current_class_type
15930 277 : && (!friendp || funcdef_flag || initialized))
15931 : {
15932 57 : error_at (id_loc, funcdef_flag || initialized
15933 : ? G_("cannot define member function %<%T::%s%> "
15934 : "within %qT")
15935 : : G_("cannot declare member function %<%T::%s%> "
15936 : "within %qT"),
15937 : ctype, name, current_class_type);
15938 48 : return error_mark_node;
15939 : }
15940 : }
15941 508229 : else if (typedef_p && current_class_type)
15942 : {
15943 0 : error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
15944 : ctype, name, current_class_type);
15945 0 : return error_mark_node;
15946 : }
15947 : }
15948 :
15949 1068615516 : if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
15950 59907947 : ctype = current_class_type;
15951 :
15952 : /* Now TYPE has the actual type. */
15953 :
15954 1068615516 : if (returned_attrs)
15955 : {
15956 2939 : if (attrlist)
15957 2939 : *attrlist = attr_chainon (returned_attrs, *attrlist);
15958 : else
15959 : attrlist = &returned_attrs;
15960 : }
15961 :
15962 1068615516 : if (declarator
15963 601790293 : && declarator->kind == cdk_id
15964 601546357 : && declarator->std_attributes
15965 591861 : && attrlist != NULL)
15966 : {
15967 : /* [dcl.meaning]/1: The optional attribute-specifier-seq following
15968 : a declarator-id appertains to the entity that is declared. */
15969 591858 : if (declarator->std_attributes != error_mark_node)
15970 : {
15971 591840 : if (flag_reflection
15972 : && declarator->std_attributes != error_mark_node
15973 28078 : && lookup_annotation (declarator->std_attributes)
15974 40 : && *attrlist != error_mark_node
15975 591880 : && lookup_annotation (*attrlist))
15976 : /* If there are annotations in both lists, ensure
15977 : declarator->std_attributes go after *attrlist. See
15978 : PR124399. */
15979 14 : *attrlist = chainon (copy_list (*attrlist),
15980 14 : declarator->std_attributes);
15981 : else
15982 591826 : *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
15983 : }
15984 : else
15985 : /* We should have already diagnosed the issue (c++/78344). */
15986 18 : gcc_assert (seen_error ());
15987 : }
15988 :
15989 : /* Handle parameter packs. */
15990 1068615516 : if (parameter_pack_p)
15991 : {
15992 3177346 : if (decl_context == PARM)
15993 : /* Turn the type into a pack expansion.*/
15994 3177346 : type = make_pack_expansion (type);
15995 : else
15996 0 : error ("non-parameter %qs cannot be a parameter pack", name);
15997 : }
15998 :
15999 1068615516 : if ((decl_context == FIELD || decl_context == PARM)
16000 474856903 : && !processing_template_decl
16001 1220104065 : && variably_modified_type_p (type, NULL_TREE))
16002 : {
16003 12 : if (decl_context == FIELD)
16004 6 : error_at (id_loc,
16005 : "data member may not have variably modified type %qT", type);
16006 : else
16007 6 : error_at (id_loc,
16008 : "parameter may not have variably modified type %qT", type);
16009 12 : type = error_mark_node;
16010 : }
16011 :
16012 1068615516 : if (explicitp == 1 || (explicitp && friendp))
16013 : {
16014 : /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
16015 : in the declaration of a constructor or conversion function within
16016 : a class definition. */
16017 74 : if (!current_class_type)
16018 59 : error_at (declspecs->locations[ds_explicit],
16019 : "%<explicit%> outside class declaration");
16020 15 : else if (friendp)
16021 12 : error_at (declspecs->locations[ds_explicit],
16022 : "%<explicit%> in friend declaration");
16023 : else
16024 3 : error_at (declspecs->locations[ds_explicit],
16025 : "only declarations of constructors and conversion operators "
16026 : "can be %<explicit%>");
16027 : explicitp = 0;
16028 : }
16029 :
16030 1068615516 : if (storage_class == sc_mutable)
16031 : {
16032 139361 : location_t sloc = declspecs->locations[ds_storage_class];
16033 139361 : if (decl_context != FIELD || friendp)
16034 : {
16035 30 : error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
16036 : name);
16037 30 : storage_class = sc_none;
16038 : }
16039 139331 : else if (decl_context == TYPENAME || typedef_p)
16040 : {
16041 0 : error_at (sloc,
16042 : "non-object member %qs cannot be declared %<mutable%>",
16043 : name);
16044 0 : storage_class = sc_none;
16045 : }
16046 139331 : else if (FUNC_OR_METHOD_TYPE_P (type))
16047 : {
16048 3 : error_at (sloc, "function %qs cannot be declared %<mutable%>",
16049 : name);
16050 3 : storage_class = sc_none;
16051 : }
16052 139328 : else if (staticp)
16053 : {
16054 0 : error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
16055 : name);
16056 0 : storage_class = sc_none;
16057 : }
16058 139328 : else if (type_quals & TYPE_QUAL_CONST)
16059 : {
16060 9 : error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
16061 : name);
16062 9 : storage_class = sc_none;
16063 : }
16064 139319 : else if (TYPE_REF_P (type))
16065 : {
16066 6 : permerror (sloc, "reference %qs cannot be declared %<mutable%>",
16067 : name);
16068 6 : storage_class = sc_none;
16069 : }
16070 : }
16071 :
16072 : /* If this is declaring a typedef name, return a TYPE_DECL. */
16073 1068615516 : if (typedef_p && decl_context != TYPENAME)
16074 : {
16075 48497564 : bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
16076 48497564 : tree decl;
16077 :
16078 48497564 : if (funcdef_flag)
16079 : {
16080 6 : if (decl_context == NORMAL)
16081 3 : error_at (id_loc,
16082 : "typedef may not be a function definition");
16083 : else
16084 3 : error_at (id_loc,
16085 : "typedef may not be a member function definition");
16086 6 : return error_mark_node;
16087 : }
16088 :
16089 : /* This declaration:
16090 :
16091 : typedef void f(int) const;
16092 :
16093 : declares a function type which is not a member of any
16094 : particular class, but which is cv-qualified; for
16095 : example "f S::*" declares a pointer to a const-qualified
16096 : member function of S. We record the cv-qualification in the
16097 : function type. */
16098 48497558 : if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
16099 : {
16100 62 : type = apply_memfn_quals (type, memfn_quals, rqual);
16101 :
16102 : /* We have now dealt with these qualifiers. */
16103 62 : memfn_quals = TYPE_UNQUALIFIED;
16104 62 : rqual = REF_QUAL_NONE;
16105 : }
16106 :
16107 48497558 : if (type_uses_auto (type))
16108 : {
16109 62 : if (alias_p)
16110 20 : error_at (declspecs->locations[ds_type_spec],
16111 : "%<auto%> not allowed in alias declaration");
16112 : else
16113 42 : error_at (declspecs->locations[ds_type_spec],
16114 : "typedef declared %<auto%>");
16115 62 : type = error_mark_node;
16116 : }
16117 :
16118 48497558 : if (reqs)
16119 3 : error_at (location_of (reqs), "requires-clause on typedef");
16120 :
16121 48497558 : if (id_declarator && declarator->u.id.qualifying_scope)
16122 : {
16123 21 : error_at (id_loc, "typedef name may not be a nested-name-specifier");
16124 21 : type = error_mark_node;
16125 : }
16126 :
16127 48497558 : if (decl_context == FIELD)
16128 26032171 : decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
16129 : else
16130 22465387 : decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
16131 :
16132 48497558 : if (decl_context != FIELD)
16133 : {
16134 22465387 : if (!current_function_decl)
16135 9898267 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
16136 12567120 : else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
16137 : /* The TYPE_DECL is "abstract" because there will be
16138 : clones of this constructor/destructor, and there will
16139 : be copies of this TYPE_DECL generated in those
16140 : clones. The decloning optimization (for space) may
16141 : revert this subsequently if it determines that
16142 : the clones should share a common implementation. */
16143 161623 : DECL_ABSTRACT_P (decl) = true;
16144 :
16145 22465387 : set_originating_module (decl);
16146 : }
16147 26032171 : else if (current_class_type
16148 26032171 : && constructor_name_p (unqualified_id, current_class_type))
16149 3 : permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
16150 : "as enclosing class",
16151 : unqualified_id);
16152 :
16153 : /* If the user declares "typedef struct {...} foo" then the
16154 : struct will have an anonymous name. Fill that name in now.
16155 : Nothing can refer to it, so nothing needs know about the name
16156 : change. */
16157 48497558 : if (type != error_mark_node
16158 48497475 : && unqualified_id
16159 48497472 : && TYPE_NAME (type)
16160 45076883 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16161 90016818 : && (TYPE_UNNAMED_P (type)
16162 : /* An enum may have previously used an enumerator for linkage
16163 : purposes, but we want the typedef name to take priority. */
16164 44673950 : || enum_with_enumerator_for_linkage_p (type))
16165 403355 : && declspecs->type_definition_p
16166 403272 : && attributes_naming_typedef_ok (*attrlist)
16167 48900827 : && cp_type_quals (type) == TYPE_UNQUALIFIED)
16168 403251 : name_unnamed_type (type, decl);
16169 :
16170 48497558 : if (signed_p
16171 48497558 : || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
16172 384591 : C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
16173 :
16174 48497558 : bad_specifiers (decl, BSP_TYPE, virtualp,
16175 : memfn_quals != TYPE_UNQUALIFIED,
16176 : inlinep, friendp, raises != NULL_TREE,
16177 : declspecs->locations);
16178 :
16179 48497558 : if (alias_p)
16180 : /* Acknowledge that this was written:
16181 : `using analias = atype;'. */
16182 21937029 : TYPE_DECL_ALIAS_P (decl) = 1;
16183 :
16184 : /* We use a flag so that dependent_opaque_alias_p doesn't have to
16185 : recompute the answer every single time. */
16186 48497558 : TYPE_DECL_OPAQUE_ALIAS_P (decl) = any_lambdas_p (type);
16187 :
16188 48497558 : return decl;
16189 : }
16190 :
16191 : /* Detect the case of an array type of unspecified size
16192 : which came, as such, direct from a typedef name.
16193 : We must copy the type, so that the array's domain can be
16194 : individually set by the object's initializer. */
16195 :
16196 1020117952 : if (type && typedef_type
16197 989677337 : && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
16198 1020722547 : && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
16199 83 : type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
16200 :
16201 : /* Detect where we're using a typedef of function type to declare a
16202 : function. PARMS will not be set, so we must create it now. */
16203 :
16204 1020117952 : if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
16205 : {
16206 16124 : tree decls = NULL_TREE;
16207 16124 : tree args;
16208 :
16209 16124 : for (args = TYPE_ARG_TYPES (type);
16210 34713 : args && args != void_list_node;
16211 18589 : args = TREE_CHAIN (args))
16212 : {
16213 18589 : tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
16214 18589 : TREE_VALUE (args));
16215 :
16216 18589 : DECL_CHAIN (decl) = decls;
16217 18589 : decls = decl;
16218 : }
16219 :
16220 16124 : parms = nreverse (decls);
16221 :
16222 16124 : if (decl_context != TYPENAME)
16223 : {
16224 : /* The qualifiers on the function type become the qualifiers on
16225 : the non-static member function. */
16226 15351 : memfn_quals |= type_memfn_quals (type);
16227 15351 : rqual = type_memfn_rqual (type);
16228 15351 : type_quals = TYPE_UNQUALIFIED;
16229 15351 : raises = TYPE_RAISES_EXCEPTIONS (type);
16230 : }
16231 : }
16232 :
16233 : /* If this is a type name (such as, in a cast or sizeof),
16234 : compute the type and return it now. */
16235 :
16236 1020117179 : if (decl_context == TYPENAME)
16237 : {
16238 : /* Note that here we don't care about type_quals. */
16239 :
16240 : /* Special case: "friend class foo" looks like a TYPENAME context. */
16241 420473220 : if (friendp)
16242 : {
16243 0 : if (inlinep)
16244 : {
16245 0 : error ("%<inline%> specified for friend class declaration");
16246 0 : inlinep = 0;
16247 : }
16248 :
16249 0 : if (!current_aggr)
16250 : {
16251 : /* Don't allow friend declaration without a class-key. */
16252 0 : if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
16253 0 : permerror (input_location, "template parameters cannot be friends");
16254 0 : else if (TREE_CODE (type) == TYPENAME_TYPE)
16255 0 : permerror (input_location, "friend declaration requires class-key, "
16256 : "i.e. %<friend class %T::%D%>",
16257 0 : TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
16258 : else
16259 0 : permerror (input_location, "friend declaration requires class-key, "
16260 : "i.e. %<friend %#T%>",
16261 : type);
16262 : }
16263 :
16264 : /* Only try to do this stuff if we didn't already give up. */
16265 0 : if (type != integer_type_node)
16266 : {
16267 : /* A friendly class? */
16268 0 : if (current_class_type)
16269 0 : make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
16270 : /*complain=*/true);
16271 : else
16272 0 : error ("trying to make class %qT a friend of global scope",
16273 : type);
16274 :
16275 0 : type = void_type_node;
16276 : }
16277 : }
16278 420473220 : else if (memfn_quals || rqual)
16279 : {
16280 13750 : if (ctype == NULL_TREE
16281 13750 : && TREE_CODE (type) == METHOD_TYPE)
16282 0 : ctype = TYPE_METHOD_BASETYPE (type);
16283 :
16284 13750 : if (ctype)
16285 0 : type = build_memfn_type (type, ctype, memfn_quals, rqual);
16286 : /* Core issue #547: need to allow this in template type args.
16287 : Allow it in general in C++11 for alias-declarations. */
16288 13750 : else if ((template_type_arg || cxx_dialect >= cxx11)
16289 13748 : && TREE_CODE (type) == FUNCTION_TYPE)
16290 13746 : type = apply_memfn_quals (type, memfn_quals, rqual);
16291 : else
16292 4 : error ("invalid qualifiers on non-member function type");
16293 : }
16294 :
16295 420473220 : if (reqs)
16296 3 : error_at (location_of (reqs), "requires-clause on type-id");
16297 :
16298 420473220 : return type;
16299 : }
16300 599644732 : else if (unqualified_id == NULL_TREE && decl_context != PARM
16301 853573 : && decl_context != CATCHPARM
16302 379402 : && TREE_CODE (type) != UNION_TYPE
16303 379025 : && ! bitfield
16304 379025 : && innermost_code != cdk_decomp)
16305 : {
16306 9 : error ("abstract declarator %qT used as declaration", type);
16307 9 : return error_mark_node;
16308 : }
16309 :
16310 599644723 : if (!FUNC_OR_METHOD_TYPE_P (type))
16311 : {
16312 : /* Only functions may be declared using an operator-function-id. */
16313 406155989 : if (dname && IDENTIFIER_ANY_OP_P (dname))
16314 : {
16315 8 : error_at (id_loc, "declaration of %qD as non-function", dname);
16316 8 : return error_mark_node;
16317 : }
16318 :
16319 406155981 : if (reqs)
16320 15 : error_at (location_of (reqs),
16321 : "requires-clause on declaration of non-function type %qT",
16322 : type);
16323 : }
16324 :
16325 : /* We don't check parameter types here because we can emit a better
16326 : error message later. */
16327 599644715 : if (decl_context != PARM)
16328 : {
16329 297482927 : type = check_var_type (unqualified_id, type, id_loc);
16330 297482927 : if (type == error_mark_node)
16331 : return error_mark_node;
16332 : }
16333 :
16334 : /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
16335 : or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
16336 :
16337 599644631 : if (decl_context == PARM || decl_context == CATCHPARM)
16338 : {
16339 302650453 : if (ctype || in_namespace)
16340 0 : error ("cannot use %<::%> in parameter declaration");
16341 :
16342 302650453 : tree auto_node = type_uses_auto (type);
16343 302650453 : if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
16344 : {
16345 126 : bool err_p = true;
16346 126 : if (cxx_dialect >= cxx14)
16347 : {
16348 224 : if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
16349 3 : error_at (typespec_loc,
16350 : "cannot declare a parameter with %<decltype(auto)%>");
16351 115 : else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
16352 : {
16353 7 : auto_diagnostic_group g;
16354 7 : gcc_rich_location richloc (typespec_loc);
16355 7 : richloc.add_fixit_insert_after ("<>");
16356 7 : error_at (&richloc,
16357 : "missing template argument list after %qE; template "
16358 : "placeholder not permitted in parameter", c);
16359 7 : if (decl_context == PARM && cxx_dialect >= cxx20)
16360 6 : inform (typespec_loc, "or use %<auto%> for an "
16361 : "abbreviated function template");
16362 7 : inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
16363 7 : }
16364 108 : else if (decl_context == CATCHPARM || template_parm_flag)
16365 14 : error_at (typespec_loc,
16366 : "%<auto%> parameter not permitted in this context");
16367 : else
16368 : /* Do not issue an error while tentatively parsing a function
16369 : parameter: for T t(auto(a), 42);, when we just saw the 1st
16370 : parameter, we don't know yet that this construct won't be
16371 : a function declaration. Defer the checking to
16372 : cp_parser_parameter_declaration_clause. */
16373 : err_p = false;
16374 : }
16375 : else
16376 8 : error_at (typespec_loc, "parameter declared %<auto%>");
16377 32 : if (err_p)
16378 32 : type = error_mark_node;
16379 : }
16380 :
16381 : /* A parameter declared as an array of T is really a pointer to T.
16382 : One declared as a function is really a pointer to a function.
16383 : One declared as a member is really a pointer to member. */
16384 :
16385 302650453 : if (TREE_CODE (type) == ARRAY_TYPE)
16386 : {
16387 : /* Transfer const-ness of array into that of type pointed to. */
16388 784305 : type = build_pointer_type (TREE_TYPE (type));
16389 784305 : type_quals = TYPE_UNQUALIFIED;
16390 784305 : array_parameter_p = true;
16391 : }
16392 301866148 : else if (TREE_CODE (type) == FUNCTION_TYPE)
16393 102670 : type = build_pointer_type (type);
16394 : }
16395 :
16396 149685752 : if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
16397 : /* Don't convert xobj member functions to METHOD_TYPE. */
16398 115301623 : && !is_xobj_member_function
16399 704141557 : && !(unqualified_id
16400 208985039 : && identifier_p (unqualified_id)
16401 104496526 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
16402 : {
16403 104488513 : cp_cv_quals real_quals = memfn_quals;
16404 104488513 : if (cxx_dialect < cxx14 && constexpr_p
16405 669202 : && sfk != sfk_constructor && sfk != sfk_destructor)
16406 3715 : real_quals |= TYPE_QUAL_CONST;
16407 104488513 : type = build_memfn_type (type, ctype, real_quals, rqual);
16408 : }
16409 :
16410 599644631 : {
16411 599644631 : tree decl = NULL_TREE;
16412 :
16413 599644631 : if (decl_context == PARM)
16414 : {
16415 302161788 : decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
16416 302161788 : DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
16417 :
16418 302161788 : bad_specifiers (decl, BSP_PARM, virtualp,
16419 : memfn_quals != TYPE_UNQUALIFIED,
16420 : inlinep, friendp, raises != NULL_TREE,
16421 : declspecs->locations);
16422 : }
16423 297482843 : else if (decl_context == FIELD)
16424 : {
16425 146662929 : if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
16426 20423643 : if (tree auto_node = type_uses_auto (type))
16427 : {
16428 24 : location_t tloc = declspecs->locations[ds_type_spec];
16429 24 : if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
16430 6 : error_at (tloc, "invalid use of template-name %qE without an "
16431 : "argument list",
16432 6 : CLASS_PLACEHOLDER_TEMPLATE (auto_node));
16433 : else
16434 18 : error_at (tloc, "non-static data member declared with "
16435 : "placeholder %qT", auto_node);
16436 24 : type = error_mark_node;
16437 : }
16438 :
16439 : /* The C99 flexible array extension. */
16440 122499216 : if (!staticp && TREE_CODE (type) == ARRAY_TYPE
16441 147786003 : && TYPE_DOMAIN (type) == NULL_TREE)
16442 : {
16443 1400 : if (ctype
16444 1400 : && (TREE_CODE (ctype) == UNION_TYPE
16445 1400 : || TREE_CODE (ctype) == QUAL_UNION_TYPE))
16446 84 : pedwarn (id_loc, OPT_Wpedantic,
16447 : "flexible array member in union is a GCC extension");
16448 :
16449 : else
16450 : {
16451 : /* Array is a flexible member. */
16452 1316 : if (name)
16453 1316 : pedwarn (id_loc, OPT_Wpedantic,
16454 : "ISO C++ forbids flexible array member %qs", name);
16455 : else
16456 : pedwarn (input_location, OPT_Wpedantic,
16457 : "ISO C++ forbids flexible array members");
16458 :
16459 : /* Flexible array member has a null domain. */
16460 1316 : type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
16461 : }
16462 : }
16463 :
16464 146662929 : if (type == error_mark_node)
16465 : {
16466 : /* Happens when declaring arrays of sizes which
16467 : are error_mark_node, for example. */
16468 24 : decl = NULL_TREE;
16469 : }
16470 146662905 : else if (in_namespace && !friendp)
16471 : {
16472 : /* Something like struct S { int N::j; }; */
16473 6 : error_at (id_loc, "invalid use of %<::%>");
16474 6 : return error_mark_node;
16475 : }
16476 146662899 : else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
16477 : {
16478 112786987 : int publicp = 0;
16479 112786987 : tree function_context;
16480 :
16481 112786987 : if (friendp == 0)
16482 : {
16483 : /* This should never happen in pure C++ (the check
16484 : could be an assert). It could happen in
16485 : Objective-C++ if someone writes invalid code that
16486 : uses a function declaration for an instance
16487 : variable or property (instance variables and
16488 : properties are parsed as FIELD_DECLs, but they are
16489 : part of an Objective-C class, not a C++ class).
16490 : That code is invalid and is caught by this
16491 : check. */
16492 106117571 : if (!ctype)
16493 : {
16494 0 : error ("declaration of function %qD in invalid context",
16495 : unqualified_id);
16496 0 : return error_mark_node;
16497 : }
16498 :
16499 : /* ``A union may [ ... ] not [ have ] virtual functions.''
16500 : ARM 9.5 */
16501 106117571 : if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
16502 : {
16503 3 : error_at (declspecs->locations[ds_virtual],
16504 : "function %qD declared %<virtual%> inside a union",
16505 : unqualified_id);
16506 3 : return error_mark_node;
16507 : }
16508 :
16509 4202376 : if (virtualp
16510 116989360 : && identifier_p (unqualified_id)
16511 4202376 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16512 : {
16513 9 : error_at (declspecs->locations[ds_virtual],
16514 : "%qD cannot be declared %<virtual%>, since it "
16515 : "is always static", unqualified_id);
16516 9 : virtualp = 0;
16517 : }
16518 : }
16519 :
16520 : /* Check that the name used for a destructor makes sense. */
16521 112786984 : if (sfk == sfk_destructor)
16522 : {
16523 3161140 : tree uqname = id_declarator->u.id.unqualified_name;
16524 :
16525 3161140 : if (!ctype)
16526 : {
16527 12 : gcc_assert (friendp);
16528 12 : error_at (id_loc, "expected qualified name in friend "
16529 : "declaration for destructor %qD", uqname);
16530 12 : return error_mark_node;
16531 : }
16532 :
16533 3161128 : if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
16534 : {
16535 9 : error_at (id_loc, "declaration of %qD as member of %qT",
16536 : uqname, ctype);
16537 9 : return error_mark_node;
16538 : }
16539 3161119 : if (concept_p)
16540 : {
16541 9 : error_at (declspecs->locations[ds_concept],
16542 : "a destructor cannot be %qs", "concept");
16543 9 : return error_mark_node;
16544 : }
16545 3161110 : if (constexpr_p && cxx_dialect < cxx20)
16546 : {
16547 6 : error_at (declspecs->locations[ds_constexpr],
16548 : "%<constexpr%> destructors only available"
16549 : " with %<-std=c++20%> or %<-std=gnu++20%>");
16550 6 : return error_mark_node;
16551 : }
16552 3161104 : if (consteval_p)
16553 : {
16554 3 : error_at (declspecs->locations[ds_consteval],
16555 : "a destructor cannot be %qs", "consteval");
16556 3 : return error_mark_node;
16557 : }
16558 : }
16559 109625844 : else if (sfk == sfk_constructor && friendp && !ctype)
16560 : {
16561 0 : error ("expected qualified name in friend declaration "
16562 : "for constructor %qD",
16563 0 : id_declarator->u.id.unqualified_name);
16564 0 : return error_mark_node;
16565 : }
16566 112786945 : if (sfk == sfk_constructor)
16567 24000759 : if (concept_p)
16568 : {
16569 9 : error_at (declspecs->locations[ds_concept],
16570 : "a constructor cannot be %<concept%>");
16571 9 : return error_mark_node;
16572 : }
16573 88786186 : if (concept_p)
16574 : {
16575 9 : error_at (declspecs->locations[ds_concept],
16576 : "a concept cannot be a member function");
16577 9 : concept_p = false;
16578 : }
16579 112786927 : else if (consteval_p
16580 113579497 : && identifier_p (unqualified_id)
16581 113579488 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16582 : {
16583 9 : error_at (declspecs->locations[ds_consteval],
16584 : "%qD cannot be %qs", unqualified_id, "consteval");
16585 9 : consteval_p = false;
16586 : }
16587 :
16588 112786936 : if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16589 : {
16590 97417 : tree tmpl = TREE_OPERAND (unqualified_id, 0);
16591 97417 : if (variable_template_p (tmpl))
16592 : {
16593 3 : auto_diagnostic_group d;
16594 3 : error_at (id_loc, "specialization of variable template "
16595 : "%qD declared as function", tmpl);
16596 3 : inform (DECL_SOURCE_LOCATION (tmpl),
16597 : "variable template declared here");
16598 3 : return error_mark_node;
16599 3 : }
16600 : }
16601 :
16602 : /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
16603 112786933 : function_context
16604 : = (ctype != NULL_TREE
16605 112786933 : ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
16606 225573866 : publicp = ((! friendp || ! staticp)
16607 112786933 : && function_context == NULL_TREE);
16608 :
16609 112786933 : decl = grokfndecl (ctype, type,
16610 112786933 : TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
16611 : ? unqualified_id : dname,
16612 : parms,
16613 : unqualified_id,
16614 : declspecs,
16615 : reqs,
16616 : virtualp, flags, memfn_quals, rqual, raises,
16617 : friendp ? -1 : 0, friendp, publicp,
16618 112786933 : inlinep | (2 * constexpr_p) | (4 * concept_p)
16619 112786933 : | (8 * consteval_p),
16620 : initialized,
16621 : is_xobj_member_function, sfk,
16622 : funcdef_flag, late_return_type_p,
16623 : template_count, in_namespace,
16624 : attrlist, contract_specifiers, id_loc);
16625 112786933 : decl = set_virt_specifiers (decl, virt_specifiers);
16626 112786933 : if (decl == NULL_TREE)
16627 97 : return error_mark_node;
16628 : #if 0
16629 : /* This clobbers the attrs stored in `decl' from `attrlist'. */
16630 : /* The decl and setting of decl_attr is also turned off. */
16631 : decl = build_decl_attribute_variant (decl, decl_attr);
16632 : #endif
16633 :
16634 : /* [class.conv.ctor]
16635 :
16636 : A constructor declared without the function-specifier
16637 : explicit that can be called with a single parameter
16638 : specifies a conversion from the type of its first
16639 : parameter to the type of its class. Such a constructor
16640 : is called a converting constructor. */
16641 112786836 : if (explicitp == 2)
16642 6080403 : DECL_NONCONVERTING_P (decl) = 1;
16643 :
16644 112786836 : if (declspecs->explicit_specifier)
16645 444390 : store_explicit_specifier (decl, declspecs->explicit_specifier);
16646 : }
16647 33875912 : else if (!staticp
16648 33875912 : && ((current_class_type
16649 20423634 : && same_type_p (TYPE_MAIN_VARIANT (type),
16650 : current_class_type))
16651 20423538 : || (!dependent_type_p (type)
16652 12319863 : && !COMPLETE_TYPE_P (complete_type (type))
16653 1448 : && (!complete_or_array_type_p (type)
16654 1373 : || initialized == SD_UNINITIALIZED))))
16655 : {
16656 1511 : if (TREE_CODE (type) != ARRAY_TYPE
16657 1511 : || !COMPLETE_TYPE_P (TREE_TYPE (type)))
16658 : {
16659 171 : if (unqualified_id)
16660 : {
16661 126 : auto_diagnostic_group d;
16662 126 : error_at (id_loc, "field %qD has incomplete type %qT",
16663 : unqualified_id, type);
16664 126 : cxx_incomplete_type_inform (strip_array_types (type));
16665 126 : }
16666 : else
16667 45 : error ("name %qT has incomplete type", type);
16668 :
16669 171 : type = error_mark_node;
16670 171 : decl = NULL_TREE;
16671 : }
16672 : }
16673 54296512 : else if (!verify_type_context (input_location,
16674 : staticp
16675 : ? TCTX_STATIC_STORAGE
16676 : : TCTX_FIELD, type))
16677 : {
16678 0 : type = error_mark_node;
16679 0 : decl = NULL_TREE;
16680 : }
16681 : else
16682 : {
16683 33874395 : if (friendp)
16684 : {
16685 12 : if (unqualified_id)
16686 9 : error_at (id_loc,
16687 : "%qE is neither function nor member function; "
16688 : "cannot be declared friend", unqualified_id);
16689 : else
16690 3 : error ("unnamed field is neither function nor member "
16691 : "function; cannot be declared friend");
16692 12 : return error_mark_node;
16693 : }
16694 33874383 : decl = NULL_TREE;
16695 : }
16696 :
16697 146662754 : if (friendp)
16698 : {
16699 6669385 : if (flag_reflection && !funcdef_flag && decl)
16700 : {
16701 15318 : if (attrlist && lookup_annotation (*attrlist))
16702 : {
16703 : /* Remove the annotations to avoid spurious warning
16704 : below. */
16705 8 : *attrlist = remove_attribute ("internal ", "annotation ",
16706 : *attrlist);
16707 8 : error_at (id_loc, "annotation applied to non-defining "
16708 : "friend declaration %qD", decl);
16709 : }
16710 15318 : for (tree arg = DECL_ARGUMENTS (decl);
16711 35068 : arg; arg = DECL_CHAIN (arg))
16712 19750 : if (lookup_annotation (DECL_ATTRIBUTES (arg)))
16713 8 : error_at (DECL_SOURCE_LOCATION (arg),
16714 : "annotation applied to parameter %qD of "
16715 : "non-defining friend declaration", arg);
16716 : }
16717 : /* Packages tend to use GNU attributes on friends, so we only
16718 : warn for standard attributes. */
16719 6669385 : if (attrlist
16720 6669385 : && !funcdef_flag
16721 6669385 : && cxx11_attribute_p (*attrlist))
16722 : {
16723 27 : *attrlist = NULL_TREE;
16724 27 : auto_diagnostic_group d;
16725 27 : if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
16726 27 : inform (id_loc, "an attribute that appertains to a friend "
16727 : "declaration that is not a definition is ignored");
16728 27 : }
16729 : /* Friends are treated specially. */
16730 6669385 : if (ctype == current_class_type)
16731 : ; /* We already issued a permerror. */
16732 6669385 : else if (decl && DECL_NAME (decl))
16733 : {
16734 6669382 : set_originating_module (decl, true);
16735 :
16736 6669382 : if (initialized)
16737 : /* Kludge: We need funcdef_flag to be true in do_friend for
16738 : in-class defaulted functions, but that breaks grokfndecl.
16739 : So set it here. */
16740 217734 : funcdef_flag = true;
16741 :
16742 6669382 : cplus_decl_attributes (&decl, *attrlist, 0);
16743 6669382 : *attrlist = NULL_TREE;
16744 :
16745 6669382 : tree scope = ctype ? ctype : in_namespace;
16746 6669382 : decl = do_friend (scope, unqualified_id, decl,
16747 : flags, funcdef_flag);
16748 6669382 : return decl;
16749 : }
16750 : else
16751 3 : return error_mark_node;
16752 : }
16753 :
16754 : /* Structure field. It may not be a function, except for C++. */
16755 :
16756 139993369 : if (decl == NULL_TREE)
16757 : {
16758 33875915 : if (staticp)
16759 : {
16760 : /* C++ allows static class members. All other work
16761 : for this is done by grokfield. */
16762 13452278 : decl = build_lang_decl_loc (id_loc, VAR_DECL,
16763 : dname, type);
16764 13452278 : if (unqualified_id
16765 13452275 : && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16766 : {
16767 44080 : decl = check_explicit_specialization (unqualified_id, decl,
16768 : template_count,
16769 : concept_p * 8);
16770 44080 : if (decl == error_mark_node)
16771 : return error_mark_node;
16772 : }
16773 13452278 : set_linkage_for_static_data_member (decl);
16774 13452278 : if (concept_p)
16775 15 : error_at (declspecs->locations[ds_concept],
16776 : "static data member %qE declared %qs",
16777 : unqualified_id, "concept");
16778 13452263 : else if (constexpr_p && !initialized)
16779 : {
16780 9 : error_at (DECL_SOURCE_LOCATION (decl),
16781 : "%<constexpr%> static data member %qD must "
16782 : "have an initializer", decl);
16783 9 : constexpr_p = false;
16784 : }
16785 13452278 : if (consteval_p)
16786 3 : error_at (declspecs->locations[ds_consteval],
16787 : "static data member %qE declared %qs",
16788 : unqualified_id, "consteval");
16789 :
16790 13452278 : if (inlinep)
16791 24065 : mark_inline_variable (decl, declspecs->locations[ds_inline]);
16792 :
16793 13452278 : if (!DECL_VAR_DECLARED_INLINE_P (decl)
16794 13452278 : && !(cxx_dialect >= cxx17 && constexpr_p))
16795 : /* Even if there is an in-class initialization, DECL
16796 : is considered undefined until an out-of-class
16797 : definition is provided, unless this is an inline
16798 : variable. */
16799 1872094 : DECL_EXTERNAL (decl) = 1;
16800 :
16801 13452278 : if (thread_p)
16802 : {
16803 422 : CP_DECL_THREAD_LOCAL_P (decl) = true;
16804 422 : if (!processing_template_decl)
16805 376 : set_decl_tls_model (decl, decl_default_tls_model (decl));
16806 422 : if (declspecs->gnu_thread_keyword_p)
16807 34 : SET_DECL_GNU_TLS_P (decl);
16808 : }
16809 :
16810 : /* Set the constraints on the declaration. */
16811 13452278 : bool memtmpl = (current_template_depth
16812 13452278 : > template_class_depth (current_class_type));
16813 13452278 : if (memtmpl)
16814 : {
16815 393423 : tree ci = current_template_constraints ();
16816 393423 : set_constraints (decl, ci);
16817 : }
16818 : }
16819 : else
16820 : {
16821 20423637 : if (concept_p)
16822 : {
16823 12 : error_at (declspecs->locations[ds_concept],
16824 : "non-static data member %qE declared %qs",
16825 : unqualified_id, "concept");
16826 12 : concept_p = false;
16827 12 : constexpr_p = false;
16828 : }
16829 20423625 : else if (constexpr_p)
16830 : {
16831 9 : error_at (declspecs->locations[ds_constexpr],
16832 : "non-static data member %qE declared %qs",
16833 : unqualified_id, "constexpr");
16834 9 : constexpr_p = false;
16835 : }
16836 20423637 : if (constinit_p)
16837 : {
16838 6 : error_at (declspecs->locations[ds_constinit],
16839 : "non-static data member %qE declared %qs",
16840 : unqualified_id, "constinit");
16841 6 : constinit_p = false;
16842 : }
16843 20423637 : if (consteval_p)
16844 : {
16845 3 : error_at (declspecs->locations[ds_consteval],
16846 : "non-static data member %qE declared %qs",
16847 : unqualified_id, "consteval");
16848 3 : consteval_p = false;
16849 : }
16850 20423637 : decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
16851 20423637 : DECL_NONADDRESSABLE_P (decl) = bitfield;
16852 20423637 : if (bitfield && !unqualified_id)
16853 135071 : DECL_PADDING_P (decl) = 1;
16854 :
16855 20423637 : if (storage_class == sc_mutable)
16856 : {
16857 139313 : DECL_MUTABLE_P (decl) = 1;
16858 139313 : storage_class = sc_none;
16859 : }
16860 :
16861 20423637 : if (initialized)
16862 : {
16863 : /* An attempt is being made to initialize a non-static
16864 : member. This is new in C++11. */
16865 2338176 : maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
16866 :
16867 : /* If this has been parsed with static storage class, but
16868 : errors forced staticp to be cleared, ensure NSDMI is
16869 : not present. */
16870 2338176 : if (declspecs->storage_class == sc_static)
16871 3 : DECL_INITIAL (decl) = error_mark_node;
16872 : }
16873 : }
16874 :
16875 54299552 : bad_specifiers (decl, BSP_FIELD, virtualp,
16876 : memfn_quals != TYPE_UNQUALIFIED,
16877 : staticp ? false : inlinep, friendp,
16878 : raises != NULL_TREE,
16879 : declspecs->locations);
16880 : }
16881 : }
16882 150819914 : else if (FUNC_OR_METHOD_TYPE_P (type))
16883 : {
16884 80599071 : tree original_name;
16885 80599071 : int publicp = 0;
16886 :
16887 80599071 : if (!unqualified_id)
16888 0 : return error_mark_node;
16889 :
16890 80599071 : if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16891 : original_name = dname;
16892 : else
16893 79731296 : original_name = unqualified_id;
16894 : // FIXME:gcc_assert (original_name == dname);
16895 :
16896 80599071 : if (storage_class == sc_auto)
16897 1 : error_at (declspecs->locations[ds_storage_class],
16898 : "storage class %<auto%> invalid for function %qs", name);
16899 80599070 : else if (storage_class == sc_register)
16900 7 : error_at (declspecs->locations[ds_storage_class],
16901 : "storage class %<register%> invalid for function %qs",
16902 : name);
16903 80599063 : else if (thread_p)
16904 : {
16905 12 : if (declspecs->gnu_thread_keyword_p)
16906 12 : error_at (declspecs->locations[ds_thread],
16907 : "storage class %<__thread%> invalid for function %qs",
16908 : name);
16909 : else
16910 0 : error_at (declspecs->locations[ds_thread],
16911 : "storage class %<thread_local%> invalid for "
16912 : "function %qs", name);
16913 : }
16914 80599051 : else if (constinit_p)
16915 3 : error_at (declspecs->locations[ds_constinit],
16916 : "%<constinit%> specifier invalid for function %qs", name);
16917 :
16918 80599071 : if (virt_specifiers)
16919 6 : error ("virt-specifiers in %qs not allowed outside a class "
16920 : "definition", name);
16921 : /* Function declaration not at top level.
16922 : Storage classes other than `extern' are not allowed
16923 : and `extern' makes no difference. */
16924 80599071 : if (! toplevel_bindings_p ()
16925 61405 : && (storage_class == sc_static
16926 61396 : || decl_spec_seq_has_spec_p (declspecs, ds_inline))
16927 80599083 : && pedantic)
16928 : {
16929 9 : if (storage_class == sc_static)
16930 6 : pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
16931 : "%<static%> specifier invalid for function %qs "
16932 : "declared out of global scope", name);
16933 : else
16934 3 : pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
16935 : "%<inline%> specifier invalid for function %qs "
16936 : "declared out of global scope", name);
16937 : }
16938 :
16939 80599071 : if (ctype == NULL_TREE)
16940 : {
16941 71415254 : if (virtualp)
16942 : {
16943 0 : error ("virtual non-class function %qs", name);
16944 0 : virtualp = 0;
16945 : }
16946 71415254 : else if (sfk == sfk_constructor
16947 71415254 : || sfk == sfk_destructor)
16948 : {
16949 3 : error (funcdef_flag
16950 : ? G_("%qs defined in a non-class scope")
16951 : : G_("%qs declared in a non-class scope"), name);
16952 3 : sfk = sfk_none;
16953 : }
16954 : }
16955 80599071 : if (consteval_p
16956 80944170 : && identifier_p (unqualified_id)
16957 80944170 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16958 : {
16959 9 : error_at (declspecs->locations[ds_consteval],
16960 : "%qD cannot be %qs", unqualified_id, "consteval");
16961 9 : consteval_p = false;
16962 : }
16963 :
16964 : /* Record whether the function is public. */
16965 80599071 : publicp = (ctype != NULL_TREE
16966 80599071 : || storage_class != sc_static);
16967 :
16968 161198142 : decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
16969 : declspecs, reqs, virtualp, flags, memfn_quals, rqual, raises,
16970 : 1, friendp,
16971 : publicp,
16972 80599071 : inlinep | (2 * constexpr_p) | (4 * concept_p)
16973 80599071 : | (8 * consteval_p),
16974 : initialized,
16975 : is_xobj_member_function, sfk,
16976 : funcdef_flag,
16977 : late_return_type_p,
16978 : template_count, in_namespace, attrlist,
16979 : contract_specifiers, id_loc);
16980 80599071 : if (decl == NULL_TREE)
16981 619 : return error_mark_node;
16982 :
16983 80598452 : if (explicitp == 2)
16984 11274 : DECL_NONCONVERTING_P (decl) = 1;
16985 80598452 : if (staticp == 1)
16986 : {
16987 115578 : int invalid_static = 0;
16988 :
16989 : /* Don't allow a static member function in a class, and forbid
16990 : declaring main to be static. */
16991 115578 : if (TREE_CODE (type) == METHOD_TYPE)
16992 : {
16993 0 : permerror (input_location, "cannot declare member function %qD to have "
16994 : "static linkage", decl);
16995 0 : invalid_static = 1;
16996 : }
16997 115578 : else if (current_function_decl)
16998 : {
16999 : /* 7.1.1: There can be no static function declarations within a
17000 : block. */
17001 9 : error_at (declspecs->locations[ds_storage_class],
17002 : "cannot declare static function inside another function");
17003 9 : invalid_static = 1;
17004 : }
17005 :
17006 9 : if (invalid_static)
17007 : {
17008 80598452 : staticp = 0;
17009 : storage_class = sc_none;
17010 : }
17011 : }
17012 80598452 : if (declspecs->explicit_specifier)
17013 3 : store_explicit_specifier (decl, declspecs->explicit_specifier);
17014 : }
17015 : else
17016 : {
17017 : /* It's a variable. */
17018 :
17019 : /* An uninitialized decl with `extern' is a reference. */
17020 139933478 : decl = grokvardecl (type, dname, unqualified_id,
17021 : declspecs,
17022 : initialized,
17023 : type_quals,
17024 : inlinep,
17025 : concept_p,
17026 : template_count,
17027 : ctype ? ctype : in_namespace,
17028 : id_loc);
17029 70220843 : if (decl == NULL_TREE)
17030 92 : return error_mark_node;
17031 :
17032 70220751 : bad_specifiers (decl, BSP_VAR, virtualp,
17033 : memfn_quals != TYPE_UNQUALIFIED,
17034 : inlinep, friendp, raises != NULL_TREE,
17035 : declspecs->locations);
17036 :
17037 70220751 : if (ctype)
17038 : {
17039 508202 : DECL_CONTEXT (decl) = ctype;
17040 508202 : if (staticp == 1)
17041 : {
17042 6 : permerror (declspecs->locations[ds_storage_class],
17043 : "%<static%> may not be used when defining "
17044 : "(as opposed to declaring) a static data member");
17045 6 : staticp = 0;
17046 6 : storage_class = sc_none;
17047 : }
17048 508202 : if (storage_class == sc_register && TREE_STATIC (decl))
17049 : {
17050 0 : error ("static member %qD declared %<register%>", decl);
17051 0 : storage_class = sc_none;
17052 : }
17053 508202 : if (storage_class == sc_extern && pedantic)
17054 : {
17055 0 : pedwarn (input_location, OPT_Wpedantic,
17056 : "cannot explicitly declare member %q#D to have "
17057 : "extern linkage", decl);
17058 0 : storage_class = sc_none;
17059 : }
17060 : }
17061 69712549 : else if (constexpr_p && DECL_EXTERNAL (decl))
17062 : {
17063 14 : error_at (DECL_SOURCE_LOCATION (decl),
17064 : "declaration of %<constexpr%> variable %qD "
17065 : "is not a definition", decl);
17066 14 : constexpr_p = false;
17067 : }
17068 70220751 : if (consteval_p)
17069 : {
17070 13 : error_at (DECL_SOURCE_LOCATION (decl),
17071 : "a variable cannot be declared %<consteval%>");
17072 13 : consteval_p = false;
17073 : }
17074 :
17075 70220751 : if (inlinep)
17076 6818162 : mark_inline_variable (decl, declspecs->locations[ds_inline]);
17077 70220751 : if (innermost_code == cdk_decomp)
17078 : {
17079 243936 : gcc_assert (declarator && declarator->kind == cdk_decomp);
17080 243936 : DECL_SOURCE_LOCATION (decl) = id_loc;
17081 243936 : DECL_ARTIFICIAL (decl) = 1;
17082 243936 : fit_decomposition_lang_decl (decl, NULL_TREE);
17083 : }
17084 : }
17085 :
17086 592974360 : if (VAR_P (decl) && !initialized)
17087 7591185 : if (tree auto_node = type_uses_auto (type))
17088 104 : if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
17089 : {
17090 21 : location_t loc = declspecs->locations[ds_type_spec];
17091 21 : error_at (loc, "declaration of %q#D has no initializer", decl);
17092 21 : TREE_TYPE (decl) = error_mark_node;
17093 : }
17094 :
17095 592974360 : if (storage_class == sc_extern && initialized && !funcdef_flag)
17096 : {
17097 277 : if (toplevel_bindings_p ())
17098 : {
17099 : /* It's common practice (and completely valid) to have a const
17100 : be initialized and declared extern. */
17101 253 : if (!(type_quals & TYPE_QUAL_CONST))
17102 20 : warning_at (DECL_SOURCE_LOCATION (decl), 0,
17103 : "%qs initialized and declared %<extern%>", name);
17104 : }
17105 : else
17106 : {
17107 24 : error_at (DECL_SOURCE_LOCATION (decl),
17108 : "%qs has both %<extern%> and initializer", name);
17109 24 : return error_mark_node;
17110 : }
17111 : }
17112 :
17113 : /* Record `register' declaration for warnings on &
17114 : and in case doing stupid register allocation. */
17115 :
17116 592974336 : if (storage_class == sc_register)
17117 : {
17118 2069 : DECL_REGISTER (decl) = 1;
17119 : /* Warn about register storage specifiers on PARM_DECLs. */
17120 2069 : if (TREE_CODE (decl) == PARM_DECL)
17121 : {
17122 35 : if (cxx_dialect >= cxx17)
17123 24 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
17124 : "ISO C++17 does not allow %<register%> storage "
17125 : "class specifier");
17126 : else
17127 11 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
17128 : "%<register%> storage class specifier used");
17129 : }
17130 : }
17131 592972267 : else if (storage_class == sc_extern)
17132 31571809 : DECL_THIS_EXTERN (decl) = 1;
17133 561400458 : else if (storage_class == sc_static)
17134 24494204 : DECL_THIS_STATIC (decl) = 1;
17135 :
17136 592974336 : if (VAR_P (decl))
17137 : {
17138 : /* Set constexpr flag on vars (functions got it in grokfndecl). */
17139 83673005 : if (constexpr_p)
17140 20308828 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
17141 : /* And the constinit flag (which only applies to variables). */
17142 63364177 : else if (constinit_p)
17143 453 : DECL_DECLARED_CONSTINIT_P (decl) = true;
17144 : }
17145 509301331 : else if (TREE_CODE (decl) == FUNCTION_DECL)
17146 : {
17147 : /* If we saw a return type, record its location. */
17148 186715906 : location_t loc = declspecs->locations[ds_type_spec];
17149 186715906 : if (loc == UNKNOWN_LOCATION)
17150 : /* Build DECL_RESULT in start_preparsed_function. */;
17151 152719478 : else if (!DECL_RESULT (decl))
17152 : {
17153 152680727 : tree restype = TREE_TYPE (TREE_TYPE (decl));
17154 152680727 : tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
17155 152680727 : DECL_ARTIFICIAL (resdecl) = 1;
17156 152680727 : DECL_IGNORED_P (resdecl) = 1;
17157 152680727 : DECL_RESULT (decl) = resdecl;
17158 : }
17159 38751 : else if (funcdef_flag)
17160 3 : DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
17161 : }
17162 :
17163 : /* Record constancy and volatility on the DECL itself . There's
17164 : no need to do this when processing a template; we'll do this
17165 : for the instantiated declaration based on the type of DECL. */
17166 592974336 : if (!processing_template_decl
17167 : /* Don't do it for instantiated variable templates either,
17168 : cp_apply_type_quals_to_decl should have been called on it
17169 : already and might have been overridden in cp_finish_decl
17170 : if initializer needs runtime initialization. */
17171 592974336 : && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
17172 198128932 : cp_apply_type_quals_to_decl (type_quals, decl);
17173 :
17174 592974336 : return decl;
17175 : }
17176 1068616298 : }
17177 :
17178 : /* Subroutine of start_function. Ensure that each of the parameter
17179 : types (as listed in PARMS) is complete, as is required for a
17180 : function definition. */
17181 :
17182 : static void
17183 165896904 : require_complete_types_for_parms (tree parms)
17184 : {
17185 491112818 : for (; parms; parms = DECL_CHAIN (parms))
17186 : {
17187 325215914 : if (dependent_type_p (TREE_TYPE (parms)))
17188 182398043 : continue;
17189 142817871 : if (!VOID_TYPE_P (TREE_TYPE (parms))
17190 142817871 : && complete_type_or_else (TREE_TYPE (parms), parms))
17191 : {
17192 142817790 : relayout_decl (parms);
17193 142817790 : DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
17194 :
17195 142817790 : abstract_virtuals_error (parms, TREE_TYPE (parms));
17196 142817790 : maybe_warn_parm_abi (TREE_TYPE (parms),
17197 142817790 : DECL_SOURCE_LOCATION (parms));
17198 : }
17199 : else
17200 : /* grokparms or complete_type_or_else will have already issued
17201 : an error. */
17202 81 : TREE_TYPE (parms) = error_mark_node;
17203 : }
17204 165896904 : }
17205 :
17206 : /* Returns nonzero if T is a local variable. */
17207 :
17208 : int
17209 177200295 : local_variable_p (const_tree t)
17210 : {
17211 177200295 : if ((VAR_P (t)
17212 68259393 : && (DECL_LOCAL_DECL_P (t)
17213 68259393 : || !DECL_CONTEXT (t)
17214 68216434 : || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
17215 182960014 : || (TREE_CODE (t) == PARM_DECL))
17216 157648166 : return 1;
17217 :
17218 : return 0;
17219 : }
17220 :
17221 : /* Like local_variable_p, but suitable for use as a tree-walking
17222 : function. */
17223 :
17224 : static tree
17225 5646224 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
17226 : void * /*data*/)
17227 : {
17228 5646224 : if (unevaluated_p (TREE_CODE (*tp)))
17229 : {
17230 : /* DR 2082 permits local variables in unevaluated contexts
17231 : within a default argument. */
17232 64 : *walk_subtrees = 0;
17233 64 : return NULL_TREE;
17234 : }
17235 :
17236 5646160 : if (local_variable_p (*tp)
17237 5646160 : && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
17238 : return *tp;
17239 5646160 : else if (TYPE_P (*tp))
17240 30 : *walk_subtrees = 0;
17241 :
17242 : return NULL_TREE;
17243 : }
17244 :
17245 : /* Check that ARG, which is a default-argument expression for a
17246 : parameter DECL, is valid. Returns ARG, or ERROR_MARK_NODE, if
17247 : something goes wrong. DECL may also be a _TYPE node, rather than a
17248 : DECL, if there is no DECL available. */
17249 :
17250 : tree
17251 2789318 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
17252 : {
17253 2789318 : tree var;
17254 2789318 : tree decl_type;
17255 :
17256 2789318 : if (TREE_CODE (arg) == DEFERRED_PARSE)
17257 : /* We get a DEFERRED_PARSE when looking at an in-class declaration
17258 : with a default argument. Ignore the argument for now; we'll
17259 : deal with it after the class is complete. */
17260 : return arg;
17261 :
17262 1975800 : if (TYPE_P (decl))
17263 : {
17264 : decl_type = decl;
17265 : decl = NULL_TREE;
17266 : }
17267 : else
17268 601546 : decl_type = TREE_TYPE (decl);
17269 :
17270 1975800 : if (arg == error_mark_node
17271 1975659 : || decl == error_mark_node
17272 1975650 : || TREE_TYPE (arg) == error_mark_node
17273 3951450 : || decl_type == error_mark_node)
17274 : /* Something already went wrong. There's no need to check
17275 : further. */
17276 : return error_mark_node;
17277 :
17278 : /* [dcl.fct.default]
17279 :
17280 : A default argument expression is implicitly converted to the
17281 : parameter type. */
17282 1975650 : ++cp_unevaluated_operand;
17283 : /* Avoid digest_init clobbering the initializer. */
17284 1975650 : tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
17285 1975650 : perform_implicit_conversion_flags (decl_type, carg, complain,
17286 : LOOKUP_IMPLICIT);
17287 1975650 : --cp_unevaluated_operand;
17288 :
17289 : /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
17290 : the call sites. */
17291 1573805 : if (TYPE_PTR_OR_PTRMEM_P (decl_type)
17292 401860 : && null_ptr_cst_p (arg)
17293 : /* Don't lose side-effects as in PR90473. */
17294 2343073 : && !TREE_SIDE_EFFECTS (arg))
17295 367420 : return nullptr_node;
17296 :
17297 : /* [dcl.fct.default]
17298 :
17299 : Local variables shall not be used in default argument
17300 : expressions.
17301 :
17302 : The keyword `this' shall not be used in a default argument of a
17303 : member function. */
17304 1608230 : var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
17305 1608230 : if (var)
17306 : {
17307 0 : if (complain & tf_warning_or_error)
17308 : {
17309 0 : if (DECL_NAME (var) == this_identifier)
17310 0 : permerror (input_location, "default argument %qE uses %qD",
17311 : arg, var);
17312 : else
17313 0 : error ("default argument %qE uses local variable %qD", arg, var);
17314 : }
17315 0 : return error_mark_node;
17316 : }
17317 :
17318 : /* All is well. */
17319 1608230 : return arg;
17320 : }
17321 :
17322 : /* Returns a deprecated type used within TYPE, or NULL_TREE if none. */
17323 :
17324 : static tree
17325 288972129 : type_is_deprecated (tree type)
17326 : {
17327 426016012 : enum tree_code code;
17328 426016012 : if (TREE_DEPRECATED (type))
17329 : return type;
17330 425975199 : if (TYPE_NAME (type))
17331 : {
17332 284578196 : if (TREE_DEPRECATED (TYPE_NAME (type)))
17333 : return type;
17334 : else
17335 : {
17336 284578190 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
17337 284578190 : return NULL_TREE;
17338 : }
17339 : }
17340 :
17341 : /* Do warn about using typedefs to a deprecated class. */
17342 141397003 : if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
17343 0 : return type_is_deprecated (TYPE_MAIN_VARIANT (type));
17344 :
17345 141397003 : code = TREE_CODE (type);
17346 :
17347 141397003 : if (code == POINTER_TYPE || code == REFERENCE_TYPE
17348 141397003 : || code == OFFSET_TYPE || code == FUNCTION_TYPE
17349 : || code == METHOD_TYPE || code == ARRAY_TYPE)
17350 136924119 : return type_is_deprecated (TREE_TYPE (type));
17351 :
17352 119764 : if (TYPE_PTRMEMFUNC_P (type))
17353 119764 : return type_is_deprecated
17354 119764 : (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
17355 :
17356 : return NULL_TREE;
17357 : }
17358 :
17359 : /* Returns an unavailable type used within TYPE, or NULL_TREE if none. */
17360 :
17361 : static tree
17362 290210074 : type_is_unavailable (tree type)
17363 : {
17364 427992438 : enum tree_code code;
17365 427992438 : if (TREE_UNAVAILABLE (type))
17366 : return type;
17367 427992432 : if (TYPE_NAME (type))
17368 : {
17369 285856891 : if (TREE_UNAVAILABLE (TYPE_NAME (type)))
17370 : return type;
17371 : else
17372 : {
17373 285856885 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
17374 285856885 : return NULL_TREE;
17375 : }
17376 : }
17377 :
17378 : /* Do warn about using typedefs to a deprecated class. */
17379 142135541 : if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
17380 0 : return type_is_deprecated (TYPE_MAIN_VARIANT (type));
17381 :
17382 142135541 : code = TREE_CODE (type);
17383 :
17384 142135541 : if (code == POINTER_TYPE || code == REFERENCE_TYPE
17385 142135541 : || code == OFFSET_TYPE || code == FUNCTION_TYPE
17386 : || code == METHOD_TYPE || code == ARRAY_TYPE)
17387 137549448 : return type_is_unavailable (TREE_TYPE (type));
17388 :
17389 232916 : if (TYPE_PTRMEMFUNC_P (type))
17390 232916 : return type_is_unavailable
17391 232916 : (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
17392 :
17393 : return NULL_TREE;
17394 : }
17395 :
17396 : /* Decode the list of parameter types for a function type.
17397 : Given the list of things declared inside the parens,
17398 : return a list of types.
17399 :
17400 : If this parameter does not end with an ellipsis, we append
17401 : void_list_node.
17402 :
17403 : *PARMS is set to the chain of PARM_DECLs created. */
17404 :
17405 : tree
17406 198834057 : grokparms (tree parmlist, tree *parms)
17407 : {
17408 198834057 : tree result = NULL_TREE;
17409 198834057 : tree decls = NULL_TREE;
17410 198834057 : tree parm;
17411 198834057 : int any_error = 0;
17412 :
17413 489680532 : for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
17414 : {
17415 487147412 : tree type = NULL_TREE;
17416 487147412 : tree init = TREE_PURPOSE (parm);
17417 487147412 : tree decl = TREE_VALUE (parm);
17418 :
17419 487147412 : if (parm == void_list_node || parm == explicit_void_list_node)
17420 : break;
17421 :
17422 290846491 : if (! decl || TREE_TYPE (decl) == error_mark_node)
17423 : {
17424 198 : any_error = 1;
17425 198 : continue;
17426 : }
17427 :
17428 290846293 : type = TREE_TYPE (decl);
17429 290846293 : if (VOID_TYPE_P (type))
17430 : {
17431 82 : if (same_type_p (type, void_type_node)
17432 73 : && !init
17433 61 : && !DECL_NAME (decl) && !result
17434 110 : && TREE_CHAIN (parm) == void_list_node)
17435 : /* DR 577: A parameter list consisting of a single
17436 : unnamed parameter of non-dependent type 'void'. */
17437 : break;
17438 66 : else if (cv_qualified_p (type))
17439 9 : error_at (DECL_SOURCE_LOCATION (decl),
17440 : "invalid use of cv-qualified type %qT in "
17441 : "parameter declaration", type);
17442 : else
17443 57 : error_at (DECL_SOURCE_LOCATION (decl),
17444 : "invalid use of type %<void%> in parameter "
17445 : "declaration");
17446 : /* It's not a good idea to actually create parameters of
17447 : type `void'; other parts of the compiler assume that a
17448 : void type terminates the parameter list. */
17449 66 : type = error_mark_node;
17450 66 : TREE_TYPE (decl) = error_mark_node;
17451 : }
17452 :
17453 290846277 : if (type != error_mark_node)
17454 : {
17455 290846211 : if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
17456 : {
17457 290210074 : tree unavailtype = type_is_unavailable (type);
17458 290210074 : if (unavailtype)
17459 12 : cp_handle_deprecated_or_unavailable (unavailtype);
17460 : }
17461 290846211 : if (deprecated_state != DEPRECATED_SUPPRESS
17462 290846211 : && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
17463 : {
17464 288972129 : tree deptype = type_is_deprecated (type);
17465 288972129 : if (deptype)
17466 40819 : cp_handle_deprecated_or_unavailable (deptype);
17467 : }
17468 :
17469 : /* [dcl.fct] "A parameter with volatile-qualified type is
17470 : deprecated." */
17471 290846211 : if (CP_TYPE_VOLATILE_P (type))
17472 520 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
17473 : "%<volatile%>-qualified parameter is "
17474 : "deprecated");
17475 :
17476 : /* Top-level qualifiers on the parameters are
17477 : ignored for function types. */
17478 290846211 : type = cp_build_qualified_type (type, 0);
17479 290846211 : if (TREE_CODE (type) == METHOD_TYPE)
17480 : {
17481 0 : error ("parameter %qD invalidly declared method type", decl);
17482 0 : type = build_pointer_type (type);
17483 0 : TREE_TYPE (decl) = type;
17484 : }
17485 290846211 : else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
17486 : {
17487 : /* Before C++17 DR 393:
17488 : [dcl.fct]/6, parameter types cannot contain pointers
17489 : (references) to arrays of unknown bound. */
17490 1663091 : tree t = TREE_TYPE (type);
17491 1663091 : int ptr = TYPE_PTR_P (type);
17492 :
17493 1823115 : while (1)
17494 : {
17495 1743103 : if (TYPE_PTR_P (t))
17496 : ptr = 1;
17497 1666271 : else if (TREE_CODE (t) != ARRAY_TYPE)
17498 : break;
17499 3190 : else if (!TYPE_DOMAIN (t))
17500 : break;
17501 80012 : t = TREE_TYPE (t);
17502 : }
17503 1663091 : if (TREE_CODE (t) == ARRAY_TYPE)
17504 16 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
17505 : ptr
17506 : ? G_("parameter %qD includes pointer to array of "
17507 : "unknown bound %qT")
17508 : : G_("parameter %qD includes reference to array of "
17509 : "unknown bound %qT"),
17510 : decl, t);
17511 : }
17512 :
17513 290846211 : if (init && !processing_template_decl)
17514 1415055 : init = check_default_argument (decl, init, tf_warning_or_error);
17515 : }
17516 :
17517 290846277 : DECL_CHAIN (decl) = decls;
17518 290846277 : decls = decl;
17519 290846277 : result = tree_cons (init, type, result);
17520 : }
17521 198834057 : decls = nreverse (decls);
17522 198834057 : result = nreverse (result);
17523 198834057 : if (parm)
17524 196300937 : result = chainon (result, void_list_node);
17525 198834057 : *parms = decls;
17526 198834057 : if (any_error)
17527 183 : result = NULL_TREE;
17528 :
17529 183 : if (any_error)
17530 : /* We had parm errors, recover by giving the function (...) type. */
17531 183 : result = NULL_TREE;
17532 :
17533 198834057 : return result;
17534 : }
17535 :
17536 :
17537 : /* D is a constructor or overloaded `operator='.
17538 :
17539 : Let T be the class in which D is declared. Then, this function
17540 : returns:
17541 :
17542 : -1 if D's is an ill-formed constructor or copy assignment operator
17543 : whose first parameter is of type `T'.
17544 : 0 if D is not a copy constructor or copy assignment
17545 : operator.
17546 : 1 if D is a copy constructor or copy assignment operator whose
17547 : first parameter is a reference to non-const qualified T.
17548 : 2 if D is a copy constructor or copy assignment operator whose
17549 : first parameter is a reference to const qualified T.
17550 :
17551 : This function can be used as a predicate. Positive values indicate
17552 : a copy constructor and nonzero values indicate a copy assignment
17553 : operator. */
17554 :
17555 : int
17556 349933689 : copy_fn_p (const_tree d)
17557 : {
17558 349933689 : tree args;
17559 349933689 : tree arg_type;
17560 349933689 : int result = 1;
17561 :
17562 349933689 : gcc_assert (DECL_FUNCTION_MEMBER_P (d));
17563 :
17564 349933689 : if (TREE_CODE (d) == TEMPLATE_DECL
17565 349933689 : || (DECL_TEMPLATE_INFO (d)
17566 155277033 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
17567 : /* Instantiations of template member functions are never copy
17568 : functions. Note that member functions of templated classes are
17569 : represented as template functions internally, and we must
17570 : accept those as copy functions. */
17571 : return 0;
17572 :
17573 295689511 : if (!DECL_CONSTRUCTOR_P (d)
17574 295689511 : && DECL_NAME (d) != assign_op_identifier)
17575 : return 0;
17576 :
17577 294866751 : if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
17578 : {
17579 282 : tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
17580 282 : if (!TYPE_REF_P (object_param)
17581 255 : || TYPE_REF_IS_RVALUE (object_param)
17582 : /* Reject unrelated object parameters. */
17583 237 : || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
17584 519 : || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
17585 54 : return 0;
17586 228 : args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
17587 : }
17588 : else
17589 294866469 : args = FUNCTION_FIRST_USER_PARMTYPE (d);
17590 294866697 : if (!args)
17591 : return 0;
17592 :
17593 294858851 : arg_type = TREE_VALUE (args);
17594 294858851 : if (arg_type == error_mark_node)
17595 : return 0;
17596 :
17597 294858816 : if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
17598 : {
17599 : /* Pass by value copy assignment operator. */
17600 : result = -1;
17601 : }
17602 294857286 : else if (TYPE_REF_P (arg_type)
17603 186812260 : && !TYPE_REF_IS_RVALUE (arg_type)
17604 413037820 : && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
17605 : {
17606 95158462 : if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
17607 94988456 : result = 2;
17608 : }
17609 : else
17610 : return 0;
17611 :
17612 95159992 : args = TREE_CHAIN (args);
17613 :
17614 98048945 : if (args && args != void_list_node && !TREE_PURPOSE (args))
17615 : /* There are more non-optional args. */
17616 : return 0;
17617 :
17618 : return result;
17619 : }
17620 :
17621 : /* D is a constructor or overloaded `operator='.
17622 :
17623 : Let T be the class in which D is declared. Then, this function
17624 : returns true when D is a move constructor or move assignment
17625 : operator, false otherwise. */
17626 :
17627 : bool
17628 162084554 : move_fn_p (const_tree d)
17629 : {
17630 162084554 : if (cxx_dialect == cxx98)
17631 : /* There are no move constructors if we are in C++98 mode. */
17632 : return false;
17633 :
17634 162017582 : if (TREE_CODE (d) == TEMPLATE_DECL
17635 162017582 : || (DECL_TEMPLATE_INFO (d)
17636 65688632 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
17637 : /* Instantiations of template member functions are never move
17638 : functions. Note that member functions of templated classes are
17639 : represented as template functions internally, and we must
17640 : accept those as move functions. */
17641 : return 0;
17642 :
17643 131951879 : return move_signature_fn_p (d);
17644 : }
17645 :
17646 : /* D is a constructor or overloaded `operator='.
17647 :
17648 : Then, this function returns true when D has the same signature as a move
17649 : constructor or move assignment operator (because either it is such a
17650 : ctor/op= or it is a template specialization with the same signature),
17651 : false otherwise. */
17652 :
17653 : bool
17654 131951879 : move_signature_fn_p (const_tree d)
17655 : {
17656 131951879 : tree args;
17657 131951879 : tree arg_type;
17658 131951879 : bool result = false;
17659 :
17660 131951879 : if (!DECL_CONSTRUCTOR_P (d)
17661 131951879 : && DECL_NAME (d) != assign_op_identifier)
17662 : return 0;
17663 :
17664 131951653 : if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
17665 : {
17666 126 : tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
17667 126 : if (!TYPE_REF_P (object_param)
17668 102 : || TYPE_REF_IS_RVALUE (object_param)
17669 : /* Reject unrelated object parameters. */
17670 90 : || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
17671 216 : || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
17672 42 : return 0;
17673 84 : args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
17674 : }
17675 : else
17676 131951527 : args = FUNCTION_FIRST_USER_PARMTYPE (d);
17677 131951611 : if (!args)
17678 : return 0;
17679 :
17680 131948627 : arg_type = TREE_VALUE (args);
17681 131948627 : if (arg_type == error_mark_node)
17682 : return 0;
17683 :
17684 131948619 : if (TYPE_REF_P (arg_type)
17685 67160732 : && TYPE_REF_IS_RVALUE (arg_type)
17686 184576568 : && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
17687 : DECL_CONTEXT (d)))
17688 : result = true;
17689 :
17690 131948619 : args = TREE_CHAIN (args);
17691 :
17692 147352572 : if (args && args != void_list_node && !TREE_PURPOSE (args))
17693 : /* There are more non-optional args. */
17694 : return false;
17695 :
17696 : return result;
17697 : }
17698 :
17699 : /* Remember any special properties of member function DECL. */
17700 :
17701 : void
17702 360601238 : grok_special_member_properties (tree decl)
17703 : {
17704 360601238 : tree class_type;
17705 :
17706 360601238 : if (TREE_CODE (decl) == USING_DECL
17707 360601238 : || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
17708 : return;
17709 :
17710 338048452 : class_type = DECL_CONTEXT (decl);
17711 338048452 : if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
17712 : {
17713 152716823 : int ctor = copy_fn_p (decl);
17714 :
17715 152716823 : if (!DECL_ARTIFICIAL (decl))
17716 106046369 : TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
17717 :
17718 152716823 : if (ctor > 0)
17719 : {
17720 : /* [class.copy]
17721 :
17722 : A non-template constructor for class X is a copy
17723 : constructor if its first parameter is of type X&, const
17724 : X&, volatile X& or const volatile X&, and either there
17725 : are no other parameters or else all other parameters have
17726 : default arguments. */
17727 31083931 : TYPE_HAS_COPY_CTOR (class_type) = 1;
17728 31083931 : if (ctor > 1)
17729 31005004 : TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
17730 : }
17731 :
17732 152716823 : if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
17733 32578134 : TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
17734 :
17735 152716823 : if (is_list_ctor (decl))
17736 1550971 : TYPE_HAS_LIST_CTOR (class_type) = 1;
17737 :
17738 152716823 : if (maybe_constexpr_fn (decl)
17739 152716823 : && !ctor && !move_fn_p (decl))
17740 55625388 : TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
17741 : }
17742 185331629 : else if (DECL_NAME (decl) == assign_op_identifier)
17743 : {
17744 : /* [class.copy]
17745 :
17746 : A non-template assignment operator for class X is a copy
17747 : assignment operator if its parameter is of type X, X&, const
17748 : X&, volatile X& or const volatile X&. */
17749 :
17750 15469453 : int assop = copy_fn_p (decl);
17751 :
17752 15469453 : if (assop)
17753 : {
17754 7862170 : TYPE_HAS_COPY_ASSIGN (class_type) = 1;
17755 7862170 : if (assop != 1)
17756 7833541 : TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
17757 : }
17758 : }
17759 169862176 : else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
17760 2819879 : TYPE_HAS_CONVERSION (class_type) = true;
17761 :
17762 : /* Destructors are handled in check_methods. */
17763 : }
17764 :
17765 : /* Check a constructor DECL has the correct form. Complains
17766 : if the class has a constructor of the form X(X). */
17767 :
17768 : bool
17769 49081360 : grok_ctor_properties (const_tree ctype, const_tree decl)
17770 : {
17771 49081360 : int ctor_parm = copy_fn_p (decl);
17772 :
17773 49081360 : if (ctor_parm < 0)
17774 : {
17775 : /* [class.copy]
17776 :
17777 : A declaration of a constructor for a class X is ill-formed if
17778 : its first parameter is of type (optionally cv-qualified) X
17779 : and either there are no other parameters or else all other
17780 : parameters have default arguments.
17781 :
17782 : We *don't* complain about member template instantiations that
17783 : have this form, though; they can occur as we try to decide
17784 : what constructor to use during overload resolution. Since
17785 : overload resolution will never prefer such a constructor to
17786 : the non-template copy constructor (which is either explicitly
17787 : or implicitly defined), there's no need to worry about their
17788 : existence. Theoretically, they should never even be
17789 : instantiated, but that's hard to forestall. */
17790 9 : error_at (DECL_SOURCE_LOCATION (decl),
17791 : "invalid constructor; you probably meant %<%T (const %T&)%>",
17792 : ctype, ctype);
17793 9 : return false;
17794 : }
17795 :
17796 : return true;
17797 : }
17798 :
17799 : /* DECL is a declaration for an overloaded or conversion operator. If
17800 : COMPLAIN is true, errors are issued for invalid declarations. */
17801 :
17802 : bool
17803 61072512 : grok_op_properties (tree decl, bool complain)
17804 : {
17805 61072512 : tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
17806 61072512 : bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
17807 61072512 : tree name = DECL_NAME (decl);
17808 61072512 : location_t loc = DECL_SOURCE_LOCATION (decl);
17809 :
17810 61072512 : tree class_type = DECL_CONTEXT (decl);
17811 61072512 : if (class_type && !CLASS_TYPE_P (class_type))
17812 : class_type = NULL_TREE;
17813 :
17814 61072512 : tree_code operator_code;
17815 61072512 : unsigned op_flags;
17816 61072512 : if (IDENTIFIER_CONV_OP_P (name))
17817 : {
17818 : /* Conversion operators are TYPE_EXPR for the purposes of this
17819 : function. */
17820 : operator_code = TYPE_EXPR;
17821 : op_flags = OVL_OP_FLAG_UNARY;
17822 : }
17823 : else
17824 : {
17825 58645413 : const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
17826 :
17827 58645413 : operator_code = ovl_op->tree_code;
17828 58645413 : op_flags = ovl_op->flags;
17829 58645413 : gcc_checking_assert (operator_code != ERROR_MARK);
17830 58645413 : DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
17831 : }
17832 :
17833 58645413 : if (op_flags & OVL_OP_FLAG_ALLOC)
17834 : {
17835 : /* operator new and operator delete are quite special. */
17836 351993 : if (class_type)
17837 9661 : switch (op_flags)
17838 : {
17839 6614 : case OVL_OP_FLAG_ALLOC:
17840 6614 : TYPE_HAS_NEW_OPERATOR (class_type) = 1;
17841 6614 : break;
17842 :
17843 2731 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
17844 2731 : TYPE_GETS_DELETE (class_type) |= 1;
17845 2731 : break;
17846 :
17847 135 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
17848 135 : TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
17849 135 : break;
17850 :
17851 181 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
17852 181 : TYPE_GETS_DELETE (class_type) |= 2;
17853 181 : break;
17854 :
17855 0 : default:
17856 0 : gcc_unreachable ();
17857 : }
17858 :
17859 : /* [basic.std.dynamic.allocation]/1:
17860 :
17861 : A program is ill-formed if an allocation function is declared
17862 : in a namespace scope other than global scope or declared
17863 : static in global scope.
17864 :
17865 : The same also holds true for deallocation functions. */
17866 351993 : if (DECL_NAMESPACE_SCOPE_P (decl))
17867 : {
17868 342332 : if (CP_DECL_CONTEXT (decl) != global_namespace)
17869 : {
17870 6 : error_at (loc, "%qD may not be declared within a namespace",
17871 : decl);
17872 6 : return false;
17873 : }
17874 :
17875 342326 : if (!TREE_PUBLIC (decl))
17876 : {
17877 6 : error_at (loc, "%qD may not be declared as static", decl);
17878 6 : return false;
17879 : }
17880 : }
17881 :
17882 : /* Check for replaceable global new/delete operators with
17883 : const std::nothrow_t & last argument, other replaceable global
17884 : new/delete operators are marked in cxx_init_decl_processing. */
17885 351981 : if (CP_DECL_CONTEXT (decl) == global_namespace)
17886 : {
17887 342320 : tree args = argtypes;
17888 342320 : if (args
17889 342308 : && args != void_list_node
17890 1026918 : && same_type_p (TREE_VALUE (args),
17891 : (op_flags & OVL_OP_FLAG_DELETE)
17892 : ? ptr_type_node : size_type_node))
17893 : {
17894 342278 : args = TREE_CHAIN (args);
17895 342278 : if (aligned_allocation_fn_p (decl))
17896 110476 : args = TREE_CHAIN (args);
17897 342278 : if (args
17898 342272 : && args != void_list_node
17899 570733 : && TREE_CHAIN (args) == void_list_node)
17900 : {
17901 200786 : tree t = TREE_VALUE (args);
17902 200786 : if (TYPE_REF_P (t)
17903 113927 : && !TYPE_REF_IS_RVALUE (t)
17904 113927 : && (t = TREE_TYPE (t))
17905 113927 : && TYPE_QUALS (t) == TYPE_QUAL_CONST
17906 314253 : && is_std_class (t, "nothrow_t"))
17907 113467 : DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
17908 : }
17909 : }
17910 : }
17911 :
17912 351981 : if (op_flags & OVL_OP_FLAG_DELETE)
17913 : {
17914 201113 : DECL_SET_IS_OPERATOR_DELETE (decl, true);
17915 201113 : coerce_delete_type (decl, loc);
17916 : }
17917 : else
17918 : {
17919 150868 : DECL_SET_IS_OPERATOR_NEW (decl, true);
17920 150868 : TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
17921 : }
17922 :
17923 351981 : return true;
17924 : }
17925 :
17926 : /* An operator function must either be a non-static member function
17927 : or have at least one parameter of a class, a reference to a class,
17928 : an enumeration, or a reference to an enumeration. 13.4.0.6 */
17929 60720519 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
17930 : {
17931 15566616 : if (operator_code == TYPE_EXPR
17932 15566616 : || operator_code == COMPONENT_REF
17933 15566595 : || operator_code == NOP_EXPR)
17934 : {
17935 33 : error_at (loc, "%qD must be a non-static member function", decl);
17936 33 : return false;
17937 : }
17938 :
17939 15566583 : if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
17940 : {
17941 137980 : if (! DECL_STATIC_FUNCTION_P (decl))
17942 : {
17943 12 : error_at (loc, "%qD must be a member function", decl);
17944 12 : return false;
17945 : }
17946 137968 : if (cxx_dialect < cxx23
17947 : /* For lambdas we diagnose static lambda specifier elsewhere. */
17948 210948 : && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
17949 : /* For instantiations, we have diagnosed this already. */
17950 243428 : && ! DECL_USE_TEMPLATE (decl))
17951 105454 : pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
17952 : "function only with %<-std=c++23%> or %<-std=gnu++23%>",
17953 : decl);
17954 137968 : if (operator_code == ARRAY_REF)
17955 : /* static operator[] should have exactly one argument
17956 : for C++20 and earlier, so that it isn't multidimensional. */
17957 : op_flags = OVL_OP_FLAG_UNARY;
17958 : }
17959 15428603 : else if (DECL_STATIC_FUNCTION_P (decl))
17960 : {
17961 9 : error_at (loc, "%qD must be either a non-static member "
17962 : "function or a non-member function", decl);
17963 9 : return false;
17964 : }
17965 : else
17966 416117 : for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
17967 : {
17968 15844711 : if (!arg || arg == void_list_node)
17969 : {
17970 18 : if (complain)
17971 15 : error_at (loc, "%qD must have an argument of class or "
17972 : "enumerated type", decl);
17973 18 : return false;
17974 : }
17975 :
17976 15844693 : tree type = non_reference (TREE_VALUE (arg));
17977 15844693 : if (type == error_mark_node)
17978 : return false;
17979 :
17980 : /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
17981 : because these checks are performed even on template
17982 : functions. */
17983 15844690 : if (MAYBE_CLASS_TYPE_P (type)
17984 1429041 : || TREE_CODE (type) == ENUMERAL_TYPE)
17985 : break;
17986 416117 : }
17987 : }
17988 :
17989 60717171 : if (operator_code == CALL_EXPR)
17990 : /* There are no further restrictions on the arguments to an overloaded
17991 : "operator ()". */
17992 : return true;
17993 :
17994 : /* C++23 allows an arbitrary number of parameters and default arguments for
17995 : operator[], and none of the other checks below apply. */
17996 50550236 : if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
17997 : return true;
17998 :
17999 50241421 : if (operator_code == COND_EXPR)
18000 : {
18001 : /* 13.4.0.3 */
18002 6 : error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
18003 6 : return false;
18004 : }
18005 :
18006 : /* Count the number of arguments and check for ellipsis. */
18007 : int arity = 0;
18008 142775148 : for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
18009 : {
18010 92533748 : if (!arg)
18011 : {
18012 15 : error_at (loc, "%qD must not have variable number of arguments",
18013 : decl);
18014 15 : return false;
18015 : }
18016 92533733 : ++arity;
18017 : }
18018 : /* FIXME: We need tests for these errors with xobj member functions. */
18019 : /* Verify correct number of arguments. */
18020 50241400 : switch (op_flags)
18021 : {
18022 10344934 : case OVL_OP_FLAG_AMBIARY:
18023 10344934 : if (arity == 1)
18024 : {
18025 : /* We have a unary instance of an ambi-ary op. Remap to the
18026 : unary one. */
18027 4468570 : unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
18028 4468570 : const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
18029 4468570 : gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
18030 4468570 : operator_code = ovl_op->tree_code;
18031 4468570 : DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
18032 : }
18033 5876364 : else if (arity != 2)
18034 : {
18035 : /* This was an ambiguous operator but is invalid. */
18036 3 : error_at (loc,
18037 : methodp
18038 : ? G_("%qD must have either zero or one argument")
18039 : : G_("%qD must have either one or two arguments"), decl);
18040 3 : return false;
18041 : }
18042 5876361 : else if ((operator_code == POSTINCREMENT_EXPR
18043 5876361 : || operator_code == POSTDECREMENT_EXPR)
18044 2739527 : && ! processing_template_decl
18045 : /* x++ and x--'s second argument must be an int. */
18046 7668288 : && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
18047 : integer_type_node))
18048 : {
18049 15 : error_at (loc,
18050 : methodp
18051 : ? G_("postfix %qD must have %<int%> as its argument")
18052 : : G_("postfix %qD must have %<int%> as its second argument"),
18053 : decl);
18054 15 : return false;
18055 : }
18056 : break;
18057 :
18058 3480527 : case OVL_OP_FLAG_UNARY:
18059 3480527 : if (arity != 1)
18060 : {
18061 9 : error_at (loc,
18062 : methodp
18063 : ? G_("%qD must have no arguments")
18064 : : G_("%qD must have exactly one argument"), decl);
18065 9 : return false;
18066 : }
18067 : break;
18068 :
18069 36415939 : case OVL_OP_FLAG_BINARY:
18070 36415939 : if (arity != 2)
18071 : {
18072 3 : error_at (loc,
18073 : methodp
18074 : ? G_("%qD must have exactly one argument")
18075 : : G_("%qD must have exactly two arguments"), decl);
18076 3 : return false;
18077 : }
18078 : break;
18079 :
18080 0 : default:
18081 0 : gcc_unreachable ();
18082 : }
18083 :
18084 : /* There can be no default arguments. */
18085 142775007 : for (tree arg = argtypes; arg && arg != void_list_node;
18086 92533637 : arg = TREE_CHAIN (arg))
18087 92533652 : if (TREE_PURPOSE (arg))
18088 : {
18089 15 : TREE_PURPOSE (arg) = NULL_TREE;
18090 15 : error_at (loc, "%qD cannot have default arguments", decl);
18091 15 : return false;
18092 : }
18093 :
18094 : /* At this point the declaration is well-formed. It may not be
18095 : sensible though. */
18096 :
18097 : /* Check member function warnings only on the in-class declaration.
18098 : There's no point warning on an out-of-class definition. */
18099 50241355 : if (class_type && class_type != current_class_type)
18100 : return true;
18101 :
18102 : /* Warn about conversion operators that will never be used. */
18103 48348750 : if (IDENTIFIER_CONV_OP_P (name)
18104 2426673 : && ! DECL_TEMPLATE_INFO (decl)
18105 49396742 : && warn_class_conversion)
18106 : {
18107 1047959 : tree t = TREE_TYPE (name);
18108 1047959 : int ref = TYPE_REF_P (t);
18109 :
18110 1047959 : if (ref)
18111 21672 : t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
18112 :
18113 1047959 : if (VOID_TYPE_P (t))
18114 9 : warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
18115 : "will never use a type conversion operator", class_type);
18116 1047950 : else if (class_type)
18117 : {
18118 1047950 : if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
18119 24 : warning_at (loc, OPT_Wclass_conversion,
18120 : ref
18121 : ? G_("converting %qT to a reference to the same type "
18122 : "will never use a type conversion operator")
18123 : : G_("converting %qT to the same type "
18124 : "will never use a type conversion operator"),
18125 : class_type);
18126 : /* Don't force t to be complete here. */
18127 1047935 : else if (MAYBE_CLASS_TYPE_P (t)
18128 597776 : && COMPLETE_TYPE_P (t)
18129 159569 : && DERIVED_FROM_P (t, class_type))
18130 30 : warning_at (loc, OPT_Wclass_conversion,
18131 : ref
18132 : ? G_("converting %qT to a reference to a base class "
18133 : "%qT will never use a type conversion operator")
18134 : : G_("converting %qT to a base class %qT "
18135 : "will never use a type conversion operator"),
18136 : class_type, t);
18137 : }
18138 : }
18139 :
18140 48348750 : if (!warn_ecpp)
18141 : return true;
18142 :
18143 : /* Effective C++ rules below. */
18144 :
18145 : /* More Effective C++ rule 7. */
18146 54 : if (operator_code == TRUTH_ANDIF_EXPR
18147 54 : || operator_code == TRUTH_ORIF_EXPR
18148 54 : || operator_code == COMPOUND_EXPR)
18149 0 : warning_at (loc, OPT_Weffc__,
18150 : "user-defined %qD always evaluates both arguments", decl);
18151 :
18152 : /* More Effective C++ rule 6. */
18153 54 : if (operator_code == POSTINCREMENT_EXPR
18154 : || operator_code == POSTDECREMENT_EXPR
18155 : || operator_code == PREINCREMENT_EXPR
18156 54 : || operator_code == PREDECREMENT_EXPR)
18157 : {
18158 0 : tree arg = TREE_VALUE (argtypes);
18159 0 : tree ret = TREE_TYPE (TREE_TYPE (decl));
18160 0 : if (methodp || TYPE_REF_P (arg))
18161 0 : arg = TREE_TYPE (arg);
18162 0 : arg = TYPE_MAIN_VARIANT (arg);
18163 :
18164 0 : if (operator_code == PREINCREMENT_EXPR
18165 : || operator_code == PREDECREMENT_EXPR)
18166 : {
18167 0 : if (!TYPE_REF_P (ret)
18168 0 : || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
18169 0 : warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
18170 : build_reference_type (arg));
18171 : }
18172 : else
18173 : {
18174 0 : if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
18175 0 : warning_at (loc, OPT_Weffc__,
18176 : "postfix %qD should return %qT", decl, arg);
18177 : }
18178 : }
18179 :
18180 : /* Effective C++ rule 23. */
18181 54 : if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
18182 : && (operator_code == PLUS_EXPR
18183 9 : || operator_code == MINUS_EXPR
18184 9 : || operator_code == TRUNC_DIV_EXPR
18185 : || operator_code == MULT_EXPR
18186 : || operator_code == TRUNC_MOD_EXPR)
18187 60 : && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
18188 3 : warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
18189 :
18190 : return true;
18191 : }
18192 :
18193 : /* Return a string giving the keyword associate with CODE. */
18194 :
18195 : const char *
18196 3520 : tag_name (enum tag_types code)
18197 : {
18198 3520 : switch (code)
18199 : {
18200 : case record_type:
18201 : return "struct";
18202 112 : case class_type:
18203 112 : return "class";
18204 3 : case union_type:
18205 3 : return "union";
18206 9 : case enum_type:
18207 9 : return "enum";
18208 3307 : case typename_type:
18209 3307 : case none_type:
18210 3307 : return "typename";
18211 29 : case scope_type:
18212 29 : return nullptr;
18213 : }
18214 0 : gcc_unreachable ();
18215 : }
18216 :
18217 : /* Name lookup in an elaborated-type-specifier (after the keyword
18218 : indicated by TAG_CODE) has found the TYPE_DECL DECL. If the
18219 : elaborated-type-specifier is invalid, issue a diagnostic and return
18220 : error_mark_node; otherwise, return the *_TYPE to which it referred.
18221 : If ALLOW_TEMPLATE_P is true, TYPE may be a class template. */
18222 :
18223 : tree
18224 12375842 : check_elaborated_type_specifier (enum tag_types tag_code,
18225 : tree decl,
18226 : bool allow_template_p)
18227 : {
18228 12375842 : tree type;
18229 :
18230 : /* In the case of:
18231 :
18232 : struct S { struct S *p; };
18233 :
18234 : name lookup will find the TYPE_DECL for the implicit "S::S"
18235 : typedef. Adjust for that here. */
18236 12375842 : if (DECL_SELF_REFERENCE_P (decl))
18237 428730 : decl = TYPE_NAME (TREE_TYPE (decl));
18238 :
18239 12375842 : type = TREE_TYPE (decl);
18240 :
18241 : /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
18242 : is false for this case as well. */
18243 12375842 : if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
18244 : {
18245 9 : error ("using template type parameter %qT after %qs",
18246 : type, tag_name (tag_code));
18247 9 : return error_mark_node;
18248 : }
18249 : /* Accept template template parameters. */
18250 12375833 : else if (allow_template_p
18251 6968798 : && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
18252 6968786 : || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
18253 : ;
18254 : /* [dcl.type.elab]
18255 :
18256 : If the identifier resolves to a typedef-name or the
18257 : simple-template-id resolves to an alias template
18258 : specialization, the elaborated-type-specifier is ill-formed.
18259 :
18260 : In other words, the only legitimate declaration to use in the
18261 : elaborated type specifier is the implicit typedef created when
18262 : the type is declared. */
18263 12375818 : else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
18264 428859 : && !DECL_SELF_REFERENCE_P (decl)
18265 12375947 : && tag_code != typename_type)
18266 : {
18267 78 : auto_diagnostic_group d;
18268 78 : if (alias_template_specialization_p (type, nt_opaque))
18269 21 : error ("using alias template specialization %qT after %qs",
18270 : type, tag_name (tag_code));
18271 : else
18272 57 : error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
18273 78 : inform (DECL_SOURCE_LOCATION (decl),
18274 : "%qD has a previous declaration here", decl);
18275 78 : return error_mark_node;
18276 78 : }
18277 12375740 : else if (TREE_CODE (type) != RECORD_TYPE
18278 12375740 : && TREE_CODE (type) != UNION_TYPE
18279 : && tag_code != enum_type
18280 72259 : && tag_code != typename_type)
18281 : {
18282 6 : auto_diagnostic_group d;
18283 6 : error ("%qT referred to as %qs", type, tag_name (tag_code));
18284 6 : inform (location_of (type), "%qT has a previous declaration here", type);
18285 6 : return error_mark_node;
18286 6 : }
18287 12375734 : else if (TREE_CODE (type) != ENUMERAL_TYPE
18288 12303520 : && tag_code == enum_type)
18289 : {
18290 3 : auto_diagnostic_group d;
18291 3 : error ("%qT referred to as enum", type);
18292 3 : inform (location_of (type), "%qT has a previous declaration here", type);
18293 3 : return error_mark_node;
18294 3 : }
18295 12375731 : else if (!allow_template_p
18296 5406975 : && TREE_CODE (type) == RECORD_TYPE
18297 17657180 : && CLASSTYPE_IS_TEMPLATE (type))
18298 : {
18299 : /* If a class template appears as elaborated type specifier
18300 : without a template header such as:
18301 :
18302 : template <class T> class C {};
18303 : void f(class C); // No template header here
18304 :
18305 : then the required template argument is missing. */
18306 18 : error ("template argument required for %<%s %T%>",
18307 : tag_name (tag_code),
18308 18 : DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
18309 18 : return error_mark_node;
18310 : }
18311 :
18312 : return type;
18313 : }
18314 :
18315 : /* Lookup NAME of an elaborated type specifier according to SCOPE and
18316 : issue diagnostics if necessary. Return *_TYPE node upon success,
18317 : NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
18318 : error. */
18319 :
18320 : static tree
18321 26947688 : lookup_and_check_tag (enum tag_types tag_code, tree name,
18322 : TAG_how how, bool template_header_p)
18323 : {
18324 26947688 : tree decl;
18325 26947688 : if (how == TAG_how::GLOBAL)
18326 : {
18327 : /* First try ordinary name lookup, ignoring hidden class name
18328 : injected via friend declaration. */
18329 2165693 : decl = lookup_name (name, LOOK_want::TYPE);
18330 : /* If that fails, the name will be placed in the smallest
18331 : non-class, non-function-prototype scope according to 3.3.1/5.
18332 : We may already have a hidden name declared as friend in this
18333 : scope. So lookup again but not ignoring hidden names.
18334 : If we find one, that name will be made visible rather than
18335 : creating a new tag. */
18336 2165693 : if (!decl)
18337 18892 : decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
18338 : }
18339 : else
18340 24781995 : decl = lookup_elaborated_type (name, how);
18341 :
18342 24800887 : if (!decl)
18343 : /* We found nothing. */
18344 : return NULL_TREE;
18345 :
18346 6083046 : if (TREE_CODE (decl) == TREE_LIST)
18347 : {
18348 3 : auto_diagnostic_group d;
18349 3 : error ("reference to %qD is ambiguous", name);
18350 3 : print_candidates (input_location, decl);
18351 3 : return error_mark_node;
18352 3 : }
18353 :
18354 2472039 : if (DECL_CLASS_TEMPLATE_P (decl)
18355 2472033 : && !template_header_p
18356 8555076 : && how == TAG_how::CURRENT_ONLY)
18357 : {
18358 12 : auto_diagnostic_group d;
18359 12 : error ("class template %qD redeclared as non-template", name);
18360 12 : inform (location_of (decl), "previous declaration here");
18361 12 : CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
18362 12 : return error_mark_node;
18363 12 : }
18364 :
18365 2472027 : if (DECL_CLASS_TEMPLATE_P (decl)
18366 : /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
18367 : so ignore a template template parameter. */
18368 6083037 : || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
18369 2472024 : decl = DECL_TEMPLATE_RESULT (decl);
18370 :
18371 6083031 : if (TREE_CODE (decl) != TYPE_DECL)
18372 : /* Found not-a-type. */
18373 : return NULL_TREE;
18374 :
18375 : /* Look for invalid nested type:
18376 : class C {
18377 : class C {};
18378 : }; */
18379 6083010 : if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
18380 : {
18381 6 : error ("%qD has the same name as the class in which it is "
18382 : "declared", decl);
18383 6 : return error_mark_node;
18384 : }
18385 :
18386 : /* Two cases we need to consider when deciding if a class
18387 : template is allowed as an elaborated type specifier:
18388 : 1. It is a self reference to its own class.
18389 : 2. It comes with a template header.
18390 :
18391 : For example:
18392 :
18393 : template <class T> class C {
18394 : class C *c1; // DECL_SELF_REFERENCE_P is true
18395 : class D;
18396 : };
18397 : template <class U> class C; // template_header_p is true
18398 : template <class T> class C<T>::D {
18399 : class C *c2; // DECL_SELF_REFERENCE_P is true
18400 : }; */
18401 :
18402 18249012 : tree t = check_elaborated_type_specifier (tag_code, decl,
18403 : template_header_p
18404 11737293 : | DECL_SELF_REFERENCE_P (decl));
18405 2654846 : if (template_header_p && t && CLASS_TYPE_P (t)
18406 8737838 : && (!CLASSTYPE_TEMPLATE_INFO (t)
18407 2654816 : || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
18408 : {
18409 21 : auto_diagnostic_group d;
18410 21 : error ("%qT is not a template", t);
18411 21 : inform (location_of (t), "previous declaration here");
18412 42 : if (TYPE_CLASS_SCOPE_P (t)
18413 24 : && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
18414 3 : inform (input_location,
18415 : "perhaps you want to explicitly add %<%T::%>",
18416 3 : TYPE_CONTEXT (t));
18417 21 : return error_mark_node;
18418 21 : }
18419 :
18420 : return t;
18421 : }
18422 :
18423 : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
18424 : Define the tag as a forward-reference if it is not defined.
18425 :
18426 : If a declaration is given, process it here, and report an error if
18427 : multiple declarations are not identical.
18428 :
18429 : SCOPE is TS_CURRENT when this is also a definition. Only look in
18430 : the current frame for the name (since C++ allows new names in any
18431 : scope.) It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
18432 : declaration. Only look beginning from the current scope outward up
18433 : till the nearest non-class scope. Otherwise it is TS_GLOBAL.
18434 :
18435 : TEMPLATE_HEADER_P is true when this declaration is preceded by
18436 : a set of template parameters. */
18437 :
18438 : tree
18439 26917433 : xref_tag (enum tag_types tag_code, tree name,
18440 : TAG_how how, bool template_header_p)
18441 : {
18442 26917433 : enum tree_code code;
18443 26917433 : tree context = NULL_TREE;
18444 :
18445 26917433 : auto_cond_timevar tv (TV_NAME_LOOKUP);
18446 :
18447 26917433 : gcc_assert (identifier_p (name));
18448 :
18449 26917433 : switch (tag_code)
18450 : {
18451 : case record_type:
18452 : case class_type:
18453 : code = RECORD_TYPE;
18454 : break;
18455 : case union_type:
18456 : code = UNION_TYPE;
18457 : break;
18458 : case enum_type:
18459 : code = ENUMERAL_TYPE;
18460 : break;
18461 0 : default:
18462 0 : gcc_unreachable ();
18463 : }
18464 :
18465 : /* In case of anonymous name, xref_tag is only called to
18466 : make type node and push name. Name lookup is not required. */
18467 26917433 : tree t = NULL_TREE;
18468 26917433 : if (!IDENTIFIER_ANON_P (name))
18469 24540966 : t = lookup_and_check_tag (tag_code, name, how, template_header_p);
18470 :
18471 26917433 : if (t == error_mark_node)
18472 : return error_mark_node;
18473 :
18474 2894957 : if (how != TAG_how::CURRENT_ONLY && t && current_class_type
18475 1381170 : && template_class_depth (current_class_type)
18476 27528961 : && template_header_p)
18477 : {
18478 356526 : if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
18479 : return t;
18480 :
18481 : /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
18482 : a definition of this tag. Since, in addition, we are
18483 : currently processing a (member) template declaration of a
18484 : template class, we must be very careful; consider:
18485 :
18486 : template <class X> struct S1
18487 :
18488 : template <class U> struct S2
18489 : {
18490 : template <class V> friend struct S1;
18491 : };
18492 :
18493 : Here, the S2::S1 declaration should not be confused with the
18494 : outer declaration. In particular, the inner version should
18495 : have a template parameter of level 2, not level 1.
18496 :
18497 : On the other hand, when presented with:
18498 :
18499 : template <class T> struct S1
18500 : {
18501 : template <class U> struct S2 {};
18502 : template <class U> friend struct S2;
18503 : };
18504 :
18505 : the friend must find S1::S2 eventually. We accomplish this
18506 : by making sure that the new type we create to represent this
18507 : declaration has the right TYPE_CONTEXT. */
18508 356523 : context = TYPE_CONTEXT (t);
18509 356523 : t = NULL_TREE;
18510 : }
18511 :
18512 26917319 : if (! t)
18513 : {
18514 : /* If no such tag is yet defined, create a forward-reference node
18515 : and record it as the "definition".
18516 : When a real declaration of this type is found,
18517 : the forward-reference will be altered into a real type. */
18518 21227052 : if (code == ENUMERAL_TYPE)
18519 : {
18520 13 : error ("use of enum %q#D without previous declaration", name);
18521 13 : return error_mark_node;
18522 : }
18523 :
18524 21227039 : t = make_class_type (code);
18525 21227039 : TYPE_CONTEXT (t) = context;
18526 21227039 : if (IDENTIFIER_LAMBDA_P (name))
18527 : /* Mark it as a lambda type right now. Our caller will
18528 : correct the value. */
18529 1627461 : SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
18530 21227039 : t = pushtag (name, t, how);
18531 : }
18532 : else
18533 : {
18534 5690267 : if (template_header_p && MAYBE_CLASS_TYPE_P (t))
18535 : {
18536 : /* Check that we aren't trying to overload a class with different
18537 : constraints. */
18538 2298290 : if (!redeclare_class_template (t, current_template_parms,
18539 : current_template_constraints ()))
18540 60 : return error_mark_node;
18541 : }
18542 3391977 : else if (!processing_template_decl
18543 3050641 : && CLASS_TYPE_P (t)
18544 6416250 : && CLASSTYPE_IS_TEMPLATE (t))
18545 : {
18546 0 : auto_diagnostic_group d;
18547 0 : error ("redeclaration of %qT as a non-template", t);
18548 0 : inform (location_of (t), "previous declaration %qD", t);
18549 0 : return error_mark_node;
18550 0 : }
18551 :
18552 5690207 : if (modules_p ()
18553 5690207 : && how == TAG_how::CURRENT_ONLY)
18554 : {
18555 12139 : tree decl = TYPE_NAME (t);
18556 12139 : if (!module_may_redeclare (decl))
18557 15 : return error_mark_node;
18558 :
18559 12124 : tree not_tmpl = STRIP_TEMPLATE (decl);
18560 12124 : if (DECL_LANG_SPECIFIC (not_tmpl)
18561 4548 : && DECL_MODULE_ATTACH_P (not_tmpl)
18562 54 : && !DECL_MODULE_EXPORT_P (not_tmpl)
18563 12166 : && module_exporting_p ())
18564 : {
18565 6 : auto_diagnostic_group d;
18566 6 : error ("conflicting exporting for declaration %qD", decl);
18567 6 : inform (DECL_SOURCE_LOCATION (decl),
18568 : "previously declared here without exporting");
18569 6 : }
18570 :
18571 12124 : tree maybe_tmpl = decl;
18572 12124 : if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
18573 9011 : maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
18574 :
18575 : /* FIXME: we should do a more precise check for redefinitions
18576 : of a conflicting using-declaration here, as these diagnostics
18577 : are not ideal. */
18578 12124 : if (DECL_LANG_SPECIFIC (decl)
18579 4548 : && DECL_MODULE_IMPORT_P (decl)
18580 12178 : && CP_DECL_CONTEXT (decl) == current_namespace)
18581 : {
18582 : /* Push it into this TU's symbol slot. */
18583 51 : if (maybe_tmpl != decl)
18584 : /* We're in the template parm binding level.
18585 : Pushtag has logic to slide under that, but we're
18586 : not pushing a *new* type. */
18587 20 : push_nested_namespace (CP_DECL_CONTEXT (decl));
18588 :
18589 51 : pushdecl (maybe_tmpl);
18590 51 : if (maybe_tmpl != decl)
18591 20 : pop_nested_namespace (CP_DECL_CONTEXT (decl));
18592 : }
18593 :
18594 12124 : set_instantiating_module (maybe_tmpl);
18595 : }
18596 : }
18597 :
18598 : return t;
18599 26917433 : }
18600 :
18601 : /* Create the binfo hierarchy for REF with (possibly NULL) base list
18602 : BASE_LIST. For each element on BASE_LIST the TREE_PURPOSE is an
18603 : access_* node, and the TREE_VALUE is the type of the base-class.
18604 : Non-NULL TREE_TYPE indicates virtual inheritance. */
18605 :
18606 : void
18607 72397896 : xref_basetypes (tree ref, tree base_list)
18608 : {
18609 72397896 : tree *basep;
18610 72397896 : tree binfo, base_binfo;
18611 72397896 : unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases. */
18612 72397896 : unsigned max_bases = 0; /* Maximum direct bases. */
18613 72397896 : unsigned max_dvbases = 0; /* Maximum direct virtual bases. */
18614 : /* Highest direct base index with annotations. */
18615 72397896 : unsigned max_annotated_base = 0;
18616 72397896 : int i;
18617 72397896 : tree default_access;
18618 72397896 : tree igo_prev; /* Track Inheritance Graph Order. */
18619 :
18620 72397896 : if (ref == error_mark_node)
18621 12 : return;
18622 :
18623 : /* The base of a derived class is private by default, all others are
18624 : public. */
18625 72397896 : default_access = (TREE_CODE (ref) == RECORD_TYPE
18626 71766024 : && CLASSTYPE_DECLARED_CLASS (ref)
18627 72397896 : ? access_private_node : access_public_node);
18628 :
18629 : /* First, make sure that any templates in base-classes are
18630 : instantiated. This ensures that if we call ourselves recursively
18631 : we do not get confused about which classes are marked and which
18632 : are not. */
18633 72397896 : basep = &base_list;
18634 106066164 : while (*basep)
18635 : {
18636 33668268 : tree basetype = TREE_VALUE (*basep);
18637 :
18638 : /* The dependent_type_p call below should really be dependent_scope_p
18639 : so that we give a hard error about using an incomplete type as a
18640 : base, but we allow it with a pedwarn for backward
18641 : compatibility. */
18642 33668268 : if (processing_template_decl
18643 33668268 : && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
18644 3 : cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
18645 : diagnostics::kind::pedwarn);
18646 33668268 : if (!dependent_type_p (basetype)
18647 33668268 : && !complete_type_or_else (basetype, NULL))
18648 : /* An incomplete type. Remove it from the list. */
18649 15 : *basep = TREE_CHAIN (*basep);
18650 : else
18651 : {
18652 33668253 : max_bases++;
18653 33668253 : if (TREE_CODE (TREE_PURPOSE (*basep)) == TREE_LIST)
18654 28 : max_annotated_base = max_bases;
18655 33668253 : if (TREE_TYPE (*basep))
18656 69095 : max_dvbases++;
18657 33668253 : if (CLASS_TYPE_P (basetype))
18658 32857956 : max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
18659 33668253 : basep = &TREE_CHAIN (*basep);
18660 : }
18661 : }
18662 72397896 : max_vbases += max_dvbases;
18663 :
18664 72397896 : TYPE_MARKED_P (ref) = 1;
18665 :
18666 : /* The binfo slot should be empty, unless this is an (ill-formed)
18667 : redefinition. */
18668 72397896 : gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
18669 :
18670 72397896 : gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
18671 :
18672 72397896 : binfo = make_tree_binfo (max_bases);
18673 :
18674 72397896 : TYPE_BINFO (ref) = binfo;
18675 72397896 : BINFO_OFFSET (binfo) = size_zero_node;
18676 72397896 : BINFO_TYPE (binfo) = ref;
18677 :
18678 : /* Apply base-class info set up to the variants of this type. */
18679 72397896 : fixup_type_variants (ref);
18680 :
18681 72397896 : if (max_bases)
18682 : {
18683 32747525 : vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases + max_annotated_base);
18684 32747525 : BINFO_BASE_ACCESSES (binfo)->quick_grow (max_bases + max_annotated_base);
18685 : /* A C++98 POD cannot have base classes. */
18686 32747525 : CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
18687 :
18688 32747525 : if (TREE_CODE (ref) == UNION_TYPE)
18689 : {
18690 12 : error ("derived union %qT invalid", ref);
18691 12 : return;
18692 : }
18693 : }
18694 :
18695 32747513 : if (max_bases > 1)
18696 727546 : warning (OPT_Wmultiple_inheritance,
18697 : "%qT defined with multiple direct bases", ref);
18698 :
18699 72397884 : if (max_vbases)
18700 : {
18701 : /* An aggregate can't have virtual base classes. */
18702 205935 : CLASSTYPE_NON_AGGREGATE (ref) = true;
18703 :
18704 205935 : vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
18705 :
18706 205935 : if (max_dvbases)
18707 67681 : warning (OPT_Wvirtual_inheritance,
18708 : "%qT defined with direct virtual base", ref);
18709 : }
18710 :
18711 106066125 : for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
18712 : {
18713 33668241 : tree access = TREE_PURPOSE (base_list);
18714 33668241 : tree annotations = NULL_TREE;
18715 33668241 : if (TREE_CODE (access) == TREE_LIST)
18716 : {
18717 28 : annotations = TREE_VALUE (access);
18718 28 : access = TREE_PURPOSE (access);
18719 78 : for (tree *d = &annotations; *d; )
18720 : {
18721 50 : if (annotation_p (*d))
18722 : {
18723 50 : tree name = get_attribute_name (*d);
18724 50 : tree args = TREE_VALUE (*d);
18725 50 : const attribute_spec *as
18726 50 : = lookup_attribute_spec (TREE_PURPOSE (*d));
18727 50 : bool no_add_attrs = false;
18728 50 : as->handler (&binfo, name, args, 0, &no_add_attrs);
18729 50 : if (no_add_attrs)
18730 : {
18731 2 : *d = TREE_CHAIN (*d);
18732 2 : continue;
18733 : }
18734 : }
18735 48 : d = &TREE_CHAIN (*d);
18736 : }
18737 : }
18738 33668241 : int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
18739 33668241 : tree basetype = TREE_VALUE (base_list);
18740 :
18741 33668241 : if (access == access_default_node)
18742 4572916 : access = default_access;
18743 :
18744 : /* Before C++17, an aggregate cannot have base classes. In C++17, an
18745 : aggregate can't have virtual, private, or protected base classes. */
18746 33668241 : if (cxx_dialect < cxx17
18747 33452083 : || access != access_public_node
18748 32493030 : || via_virtual)
18749 1240996 : CLASSTYPE_NON_AGGREGATE (ref) = true;
18750 :
18751 33668241 : if (PACK_EXPANSION_P (basetype))
18752 29650 : basetype = PACK_EXPANSION_PATTERN (basetype);
18753 33668241 : if (TREE_CODE (basetype) == TYPE_DECL)
18754 0 : basetype = TREE_TYPE (basetype);
18755 33668241 : if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
18756 : {
18757 24 : error ("base type %qT fails to be a struct or class type",
18758 : basetype);
18759 24 : goto dropped_base;
18760 : }
18761 33668217 : else if (ANON_AGGR_TYPE_P (basetype))
18762 : {
18763 2 : error ("base type %qT is anonymous struct type", basetype);
18764 2 : goto dropped_base;
18765 : }
18766 :
18767 33668215 : base_binfo = NULL_TREE;
18768 33668215 : if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
18769 : {
18770 26589382 : base_binfo = TYPE_BINFO (basetype);
18771 : /* The original basetype could have been a typedef'd type. */
18772 26589382 : basetype = BINFO_TYPE (base_binfo);
18773 :
18774 : /* Inherit flags from the base. */
18775 79768146 : TYPE_HAS_NEW_OPERATOR (ref)
18776 26589382 : |= TYPE_HAS_NEW_OPERATOR (basetype);
18777 79768146 : TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
18778 26589382 : |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
18779 26589382 : TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
18780 26589382 : TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
18781 79768146 : CLASSTYPE_DIAMOND_SHAPED_P (ref)
18782 26589382 : |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
18783 79768146 : CLASSTYPE_REPEATED_BASE_P (ref)
18784 26589382 : |= CLASSTYPE_REPEATED_BASE_P (basetype);
18785 : }
18786 :
18787 : /* We must do this test after we've seen through a typedef
18788 : type. */
18789 33668215 : if (TYPE_MARKED_P (basetype))
18790 : {
18791 18 : if (basetype == ref)
18792 0 : error ("recursive type %qT undefined", basetype);
18793 : else
18794 18 : error ("duplicate base type %qT invalid", basetype);
18795 18 : goto dropped_base;
18796 : }
18797 :
18798 33668197 : if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
18799 : /* Regenerate the pack expansion for the bases. */
18800 29650 : basetype = make_pack_expansion (basetype);
18801 :
18802 33668197 : TYPE_MARKED_P (basetype) = 1;
18803 :
18804 33668197 : base_binfo = copy_binfo (base_binfo, basetype, ref,
18805 : &igo_prev, via_virtual);
18806 33668197 : if (!BINFO_INHERITANCE_CHAIN (base_binfo))
18807 33599117 : BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
18808 :
18809 33668197 : unsigned len;
18810 33668197 : len = BINFO_N_BASE_BINFOS (binfo);
18811 33668197 : BINFO_BASE_APPEND (binfo, base_binfo);
18812 33668197 : BINFO_BASE_ACCESS (binfo, len) = access;
18813 33668197 : if (len < max_annotated_base)
18814 34 : BINFO_BASE_ACCESS (binfo, max_bases + len) = annotations;
18815 33668197 : continue;
18816 :
18817 44 : dropped_base:
18818 : /* Update max_vbases to reflect the reality that we are dropping
18819 : this base: if it reaches zero we want to undo the vec_alloc
18820 : above to avoid inconsistencies during error-recovery: eg, in
18821 : build_special_member_call, CLASSTYPE_VBASECLASSES non null
18822 : and vtt null (c++/27952). */
18823 44 : if (via_virtual)
18824 12 : max_vbases--;
18825 44 : if (CLASS_TYPE_P (basetype))
18826 32 : max_vbases
18827 35 : -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
18828 33668197 : }
18829 :
18830 72397884 : unsigned len = BINFO_N_BASE_BINFOS (binfo);
18831 72397884 : if (len < max_bases)
18832 : {
18833 44 : if (len && max_annotated_base)
18834 0 : memmove (&BINFO_BASE_ACCESS (binfo, len),
18835 0 : &BINFO_BASE_ACCESS (binfo, max_bases),
18836 0 : MIN (max_annotated_base, len) * sizeof (tree));
18837 44 : BINFO_BASE_ACCESSES (binfo)->truncate (len + MIN (max_annotated_base,
18838 : len));
18839 : }
18840 :
18841 72397884 : if (CLASSTYPE_VBASECLASSES (ref)
18842 72397884 : && max_vbases == 0)
18843 24 : vec_free (CLASSTYPE_VBASECLASSES (ref));
18844 :
18845 72603807 : if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
18846 : /* If we didn't get max_vbases vbases, we must have shared at
18847 : least one of them, and are therefore diamond shaped. */
18848 22370 : CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
18849 :
18850 : /* Unmark all the types. */
18851 106066081 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
18852 33668197 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
18853 72397884 : TYPE_MARKED_P (ref) = 0;
18854 :
18855 : /* Now see if we have a repeated base type. */
18856 72397884 : if (!CLASSTYPE_REPEATED_BASE_P (ref))
18857 : {
18858 182682257 : for (base_binfo = binfo; base_binfo;
18859 110284809 : base_binfo = TREE_CHAIN (base_binfo))
18860 : {
18861 110285534 : if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
18862 : {
18863 725 : CLASSTYPE_REPEATED_BASE_P (ref) = 1;
18864 725 : break;
18865 : }
18866 110284809 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
18867 : }
18868 182682257 : for (base_binfo = binfo; base_binfo;
18869 110284809 : base_binfo = TREE_CHAIN (base_binfo))
18870 110285534 : if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
18871 110284809 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
18872 : else
18873 : break;
18874 : }
18875 : }
18876 :
18877 :
18878 : /* Copies the enum-related properties from type SRC to type DST.
18879 : Used with the underlying type of an enum and the enum itself. */
18880 : static void
18881 2041156 : copy_type_enum (tree dst, tree src)
18882 : {
18883 2041156 : tree t;
18884 4082336 : for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
18885 : {
18886 2041180 : TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
18887 2041180 : TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
18888 2041180 : TYPE_SIZE (t) = TYPE_SIZE (src);
18889 2041180 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
18890 2041180 : SET_TYPE_MODE (dst, TYPE_MODE (src));
18891 2041180 : TYPE_PRECISION (t) = TYPE_PRECISION (src);
18892 2041180 : unsigned valign = TYPE_ALIGN (src);
18893 2041180 : if (TYPE_USER_ALIGN (t))
18894 12 : valign = MAX (valign, TYPE_ALIGN (t));
18895 : else
18896 2041168 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
18897 2041180 : SET_TYPE_ALIGN (t, valign);
18898 2041180 : TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
18899 : }
18900 2041156 : }
18901 :
18902 : /* Begin compiling the definition of an enumeration type.
18903 : NAME is its name,
18904 :
18905 : if ENUMTYPE is not NULL_TREE then the type has already been found.
18906 :
18907 : UNDERLYING_TYPE is the type that will be used as the storage for
18908 : the enumeration type. This should be NULL_TREE if no storage type
18909 : was specified.
18910 :
18911 : ATTRIBUTES are any attributes specified after the enum-key.
18912 :
18913 : SCOPED_ENUM_P is true if this is a scoped enumeration type.
18914 :
18915 : if IS_NEW is not NULL, gets TRUE iff a new type is created.
18916 :
18917 : Returns the type object, as yet incomplete.
18918 : Also records info about it so that build_enumerator
18919 : may be used to declare the individual values as they are read. */
18920 :
18921 : tree
18922 2406858 : start_enum (tree name, tree enumtype, tree underlying_type,
18923 : tree attributes, bool scoped_enum_p, bool *is_new)
18924 : {
18925 2406858 : tree prevtype = NULL_TREE;
18926 2406858 : gcc_assert (identifier_p (name));
18927 :
18928 2406858 : if (is_new)
18929 1941761 : *is_new = false;
18930 : /* [C++0x dcl.enum]p5:
18931 :
18932 : If not explicitly specified, the underlying type of a scoped
18933 : enumeration type is int. */
18934 2406858 : if (!underlying_type && scoped_enum_p)
18935 178582 : underlying_type = integer_type_node;
18936 :
18937 2406858 : if (underlying_type)
18938 607063 : underlying_type = cv_unqualified (underlying_type);
18939 :
18940 : /* If this is the real definition for a previous forward reference,
18941 : fill in the contents in the same object that used to be the
18942 : forward reference. */
18943 2406858 : if (!enumtype)
18944 2406722 : enumtype = lookup_and_check_tag (enum_type, name,
18945 : /*tag_scope=*/TAG_how::CURRENT_ONLY,
18946 : /*template_header_p=*/false);
18947 :
18948 : /* In case of a template_decl, the only check that should be deferred
18949 : to instantiation time is the comparison of underlying types. */
18950 2406858 : if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
18951 : {
18952 : /* Attempt to set the declaring module. */
18953 36254 : if (modules_p ())
18954 : {
18955 213 : tree decl = TYPE_NAME (enumtype);
18956 213 : if (!module_may_redeclare (decl))
18957 3 : enumtype = error_mark_node;
18958 : else
18959 210 : set_instantiating_module (decl);
18960 : }
18961 :
18962 36254 : if (enumtype == error_mark_node)
18963 : ;
18964 36470 : else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
18965 : {
18966 6 : auto_diagnostic_group d;
18967 6 : error_at (input_location, "scoped/unscoped mismatch "
18968 : "in enum %q#T", enumtype);
18969 6 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18970 : "previous definition here");
18971 6 : enumtype = error_mark_node;
18972 6 : }
18973 36245 : else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
18974 : {
18975 0 : auto_diagnostic_group d;
18976 0 : error_at (input_location, "underlying type mismatch "
18977 : "in enum %q#T", enumtype);
18978 0 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18979 : "previous definition here");
18980 0 : enumtype = error_mark_node;
18981 0 : }
18982 36230 : else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
18983 72475 : && !same_type_p (underlying_type,
18984 : ENUM_UNDERLYING_TYPE (enumtype)))
18985 : {
18986 29 : auto_diagnostic_group d;
18987 29 : error_at (input_location, "different underlying type "
18988 : "in enum %q#T", enumtype);
18989 29 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18990 : "previous definition here");
18991 29 : underlying_type = NULL_TREE;
18992 29 : }
18993 : }
18994 :
18995 2406858 : if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
18996 36245 : || processing_template_decl)
18997 : {
18998 : /* In case of error, make a dummy enum to allow parsing to
18999 : continue. */
19000 2370714 : if (enumtype == error_mark_node)
19001 : {
19002 9 : name = make_anon_name ();
19003 9 : enumtype = NULL_TREE;
19004 : }
19005 :
19006 : /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
19007 : of an opaque enum, or an opaque enum of an already defined
19008 : enumeration (C++11).
19009 : In any other case, it'll be NULL_TREE. */
19010 2370714 : if (!enumtype)
19011 : {
19012 2370610 : if (is_new)
19013 1905516 : *is_new = true;
19014 : }
19015 2370714 : prevtype = enumtype;
19016 :
19017 : /* Do not push the decl more than once. */
19018 2370714 : if (!enumtype
19019 104 : || TREE_CODE (enumtype) != ENUMERAL_TYPE)
19020 : {
19021 2370613 : enumtype = cxx_make_type (ENUMERAL_TYPE);
19022 2370613 : enumtype = pushtag (name, enumtype);
19023 :
19024 2370613 : if (enumtype != error_mark_node)
19025 : {
19026 : /* The enum is considered opaque until the opening '{' of the
19027 : enumerator list. */
19028 2370595 : SET_OPAQUE_ENUM_P (enumtype, true);
19029 2370595 : ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
19030 :
19031 : /* std::byte aliases anything. */
19032 2370595 : if (TYPE_CONTEXT (enumtype) == std_node
19033 2734396 : && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
19034 13542 : TYPE_ALIAS_SET (enumtype) = 0;
19035 : }
19036 : }
19037 : else
19038 101 : enumtype = xref_tag (enum_type, name);
19039 :
19040 2370714 : if (enumtype == error_mark_node)
19041 : return error_mark_node;
19042 : }
19043 :
19044 2406840 : SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
19045 :
19046 2406840 : cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
19047 :
19048 2406840 : if (underlying_type)
19049 : {
19050 607031 : if (ENUM_UNDERLYING_TYPE (enumtype))
19051 : /* We already checked that it matches, don't change it to a different
19052 : typedef variant. */;
19053 570830 : else if (CP_INTEGRAL_TYPE_P (underlying_type))
19054 : {
19055 570756 : copy_type_enum (enumtype, underlying_type);
19056 570756 : ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
19057 : }
19058 74 : else if (dependent_type_p (underlying_type))
19059 61 : ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
19060 : else
19061 : {
19062 13 : error ("underlying type %qT of %qT must be an integral type",
19063 : underlying_type, enumtype);
19064 13 : copy_type_enum (enumtype, integer_type_node);
19065 13 : ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
19066 : }
19067 : }
19068 :
19069 : /* If into a template class, the returned enum is always the first
19070 : declaration (opaque or not) seen. This way all the references to
19071 : this type will be to the same declaration. The following ones are used
19072 : only to check for definition errors. */
19073 2406840 : if (prevtype && processing_template_decl)
19074 : return prevtype;
19075 : else
19076 2406739 : return enumtype;
19077 : }
19078 :
19079 : /* Returns true if TYPE is an enum that uses an enumerator name for
19080 : linkage purposes at namespace scope. The term is defined in [dcl.enum]/12
19081 : for all enums, not just those at namespace scope, but for backward ABI
19082 : compatibility we want to treat those not at namespace scope the old way
19083 : and e.g. mangle the class scope ones based on their position within the
19084 : class rather than the first enumerator. */
19085 :
19086 : bool
19087 413712223 : enum_with_enumerator_for_linkage_p (tree type)
19088 : {
19089 413712223 : return (cxx_dialect >= cxx20
19090 409211399 : && UNSCOPED_ENUM_P (type)
19091 20103446 : && TYPE_ANON_P (type)
19092 3086721 : && TYPE_VALUES (type)
19093 415608840 : && TYPE_NAMESPACE_SCOPE_P (type));
19094 : }
19095 :
19096 : /* After processing and defining all the values of an enumeration type,
19097 : install their decls in the enumeration type.
19098 : ENUMTYPE is the type object. */
19099 :
19100 : void
19101 2301136 : finish_enum_value_list (tree enumtype)
19102 : {
19103 2301136 : tree values;
19104 2301136 : tree underlying_type;
19105 2301136 : tree decl;
19106 2301136 : tree value;
19107 2301136 : tree minnode, maxnode;
19108 2301136 : tree t;
19109 :
19110 2301136 : ENUM_BEING_DEFINED_P (enumtype) = 0;
19111 :
19112 2301136 : bool fixed_underlying_type_p
19113 2301136 : = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
19114 :
19115 : /* We built up the VALUES in reverse order. */
19116 2301136 : TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
19117 :
19118 : /* For an enum defined in a template, just set the type of the values;
19119 : all further processing is postponed until the template is
19120 : instantiated. We need to set the type so that tsubst of a CONST_DECL
19121 : works. */
19122 2301136 : if (processing_template_decl)
19123 : {
19124 454003 : for (values = TYPE_VALUES (enumtype);
19125 811991 : values;
19126 454003 : values = TREE_CHAIN (values))
19127 454003 : TREE_TYPE (TREE_VALUE (values)) = enumtype;
19128 : return;
19129 : }
19130 :
19131 : /* Determine the minimum and maximum values of the enumerators. */
19132 1943148 : if (TYPE_VALUES (enumtype))
19133 : {
19134 : minnode = maxnode = NULL_TREE;
19135 :
19136 11681574 : for (values = TYPE_VALUES (enumtype);
19137 13587823 : values;
19138 11681574 : values = TREE_CHAIN (values))
19139 : {
19140 11681574 : decl = TREE_VALUE (values);
19141 :
19142 : /* [dcl.enum]: Following the closing brace of an enum-specifier,
19143 : each enumerator has the type of its enumeration. Prior to the
19144 : closing brace, the type of each enumerator is the type of its
19145 : initializing value. */
19146 11681574 : TREE_TYPE (decl) = enumtype;
19147 :
19148 : /* Update the minimum and maximum values, if appropriate. */
19149 11681574 : value = DECL_INITIAL (decl);
19150 11681574 : if (!value || TREE_CODE (value) != INTEGER_CST)
19151 7 : value = integer_zero_node;
19152 : /* Figure out what the minimum and maximum values of the
19153 : enumerators are. */
19154 11681574 : if (!minnode)
19155 : minnode = maxnode = value;
19156 9775325 : else if (tree_int_cst_lt (maxnode, value))
19157 : maxnode = value;
19158 1509681 : else if (tree_int_cst_lt (value, minnode))
19159 171370 : minnode = value;
19160 : }
19161 : }
19162 : else
19163 : /* [dcl.enum]
19164 :
19165 : If the enumerator-list is empty, the underlying type is as if
19166 : the enumeration had a single enumerator with value 0. */
19167 36899 : minnode = maxnode = integer_zero_node;
19168 :
19169 1943148 : if (!fixed_underlying_type_p)
19170 : {
19171 : /* Compute the number of bits require to represent all values of the
19172 : enumeration. We must do this before the type of MINNODE and
19173 : MAXNODE are transformed, since tree_int_cst_min_precision relies
19174 : on the TREE_TYPE of the value it is passed. */
19175 1470387 : signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
19176 1470387 : int lowprec = tree_int_cst_min_precision (minnode, sgn);
19177 1470387 : int highprec = tree_int_cst_min_precision (maxnode, sgn);
19178 1470387 : int precision = MAX (lowprec, highprec);
19179 1470387 : unsigned int itk;
19180 1470387 : bool use_short_enum;
19181 :
19182 : /* Determine the underlying type of the enumeration.
19183 :
19184 : [dcl.enum]
19185 :
19186 : The underlying type of an enumeration is an integral type that
19187 : can represent all the enumerator values defined in the
19188 : enumeration. It is implementation-defined which integral type is
19189 : used as the underlying type for an enumeration except that the
19190 : underlying type shall not be larger than int unless the value of
19191 : an enumerator cannot fit in an int or unsigned int.
19192 :
19193 : We use "int" or an "unsigned int" as the underlying type, even if
19194 : a smaller integral type would work, unless the user has
19195 : explicitly requested that we use the smallest possible type. The
19196 : user can request that for all enumerations with a command line
19197 : flag, or for just one enumeration with an attribute. */
19198 :
19199 2940774 : use_short_enum = flag_short_enums
19200 1470387 : || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
19201 :
19202 : /* If the precision of the type was specified with an attribute and it
19203 : was too small, give an error. Otherwise, use it. */
19204 1470387 : if (TYPE_PRECISION (enumtype))
19205 : {
19206 11 : if (precision > TYPE_PRECISION (enumtype))
19207 0 : error ("specified mode too small for enumerated values");
19208 : else
19209 : {
19210 11 : use_short_enum = true;
19211 11 : precision = TYPE_PRECISION (enumtype);
19212 : }
19213 : }
19214 :
19215 2859326 : for (itk = (use_short_enum ? itk_char : itk_int);
19216 2859326 : itk != itk_none;
19217 : itk++)
19218 : {
19219 2859323 : underlying_type = integer_types[itk];
19220 2859323 : if (underlying_type != NULL_TREE
19221 2859305 : && TYPE_PRECISION (underlying_type) >= precision
19222 5716527 : && TYPE_SIGN (underlying_type) == sgn)
19223 : break;
19224 : }
19225 1470387 : if (itk == itk_none)
19226 : {
19227 : /* DR 377
19228 :
19229 : IF no integral type can represent all the enumerator values, the
19230 : enumeration is ill-formed. */
19231 3 : error ("no integral type can represent all of the enumerator values "
19232 : "for %qT", enumtype);
19233 3 : precision = TYPE_PRECISION (long_long_integer_type_node);
19234 3 : underlying_type = integer_types[itk_unsigned_long_long];
19235 : }
19236 :
19237 : /* [dcl.enum]
19238 :
19239 : The value of sizeof() applied to an enumeration type, an object
19240 : of an enumeration type, or an enumerator, is the value of sizeof()
19241 : applied to the underlying type. */
19242 1470387 : copy_type_enum (enumtype, underlying_type);
19243 :
19244 : /* Compute the minimum and maximum values for the type.
19245 :
19246 : [dcl.enum]
19247 :
19248 : For an enumeration where emin is the smallest enumerator and emax
19249 : is the largest, the values of the enumeration are the values of the
19250 : underlying type in the range bmin to bmax, where bmin and bmax are,
19251 : respectively, the smallest and largest values of the smallest bit-
19252 : field that can store emin and emax. */
19253 :
19254 : /* The middle-end currently assumes that types with TYPE_PRECISION
19255 : narrower than their underlying type are suitably zero or sign
19256 : extended to fill their mode. Similarly, it assumes that the front
19257 : end assures that a value of a particular type must be within
19258 : TYPE_MIN_VALUE and TYPE_MAX_VALUE.
19259 :
19260 : We used to set these fields based on bmin and bmax, but that led
19261 : to invalid assumptions like optimizing away bounds checking. So
19262 : now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
19263 : TYPE_MAX_VALUE to the values for the mode above and only restrict
19264 : the ENUM_UNDERLYING_TYPE for the benefit of diagnostics. */
19265 1470387 : ENUM_UNDERLYING_TYPE (enumtype)
19266 1470387 : = build_distinct_type_copy (underlying_type);
19267 1470387 : TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
19268 1470387 : set_min_and_max_values_for_integral_type
19269 1470387 : (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
19270 :
19271 : /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE. */
19272 1470387 : if (flag_strict_enums)
19273 38 : set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
19274 :
19275 1470387 : if (use_short_enum)
19276 : {
19277 122 : TYPE_PACKED (enumtype) = use_short_enum;
19278 122 : fixup_attribute_variants (enumtype);
19279 : }
19280 : }
19281 : else
19282 472761 : underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
19283 :
19284 : /* If the enum is exported, mark the consts too. */
19285 1943148 : bool export_p = (UNSCOPED_ENUM_P (enumtype)
19286 1546963 : && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
19287 1943736 : && at_namespace_scope_p ());
19288 :
19289 : /* Convert each of the enumerators to the type of the underlying
19290 : type of the enumeration. */
19291 13624722 : for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
19292 : {
19293 11681574 : decl = TREE_VALUE (values);
19294 11681574 : iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
19295 11681574 : if (fixed_underlying_type_p)
19296 : /* If the enumeration type has a fixed underlying type, we
19297 : already checked all of the enumerator values. */
19298 4106519 : value = DECL_INITIAL (decl);
19299 : else
19300 7575055 : value = perform_implicit_conversion (underlying_type,
19301 7575055 : DECL_INITIAL (decl),
19302 : tf_warning_or_error);
19303 11681574 : if (!value)
19304 3 : value = integer_zero_node;
19305 : /* Do not clobber shared ints. But do share identical enumerators. */
19306 11681574 : value = fold_convert (enumtype, value);
19307 :
19308 11681574 : DECL_INITIAL (decl) = value;
19309 11681574 : if (export_p)
19310 3594 : DECL_MODULE_EXPORT_P (decl) = true;
19311 11681574 : }
19312 :
19313 : /* Fix up all variant types of this enum type. */
19314 3886342 : for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
19315 1943194 : TYPE_VALUES (t) = TYPE_VALUES (enumtype);
19316 :
19317 1943148 : if (at_class_scope_p ()
19318 1040448 : && COMPLETE_TYPE_P (current_class_type)
19319 1943212 : && UNSCOPED_ENUM_P (enumtype))
19320 : {
19321 45 : insert_late_enum_def_bindings (current_class_type, enumtype);
19322 : /* TYPE_FIELDS needs fixup. */
19323 45 : fixup_type_variants (current_class_type);
19324 : }
19325 :
19326 : /* P2115: An unnamed enum uses the name of its first enumerator for
19327 : linkage purposes; reset the type linkage if that is the case. */
19328 1943148 : if (enum_with_enumerator_for_linkage_p (enumtype))
19329 348854 : reset_type_linkage (enumtype);
19330 :
19331 : /* Finish debugging output for this type. */
19332 1943148 : rest_of_type_compilation (enumtype, namespace_bindings_p ());
19333 :
19334 : /* Each enumerator now has the type of its enumeration. Clear the cache
19335 : so that this change in types doesn't confuse us later on. */
19336 1943148 : clear_cv_and_fold_caches ();
19337 : }
19338 :
19339 : /* Finishes the enum type. This is called only the first time an
19340 : enumeration is seen, be it opaque or odinary.
19341 : ENUMTYPE is the type object. */
19342 :
19343 : void
19344 2289690 : finish_enum (tree enumtype)
19345 : {
19346 2289690 : if (processing_template_decl)
19347 : {
19348 358016 : if (at_function_scope_p ())
19349 9458 : add_stmt (build_min (TAG_DEFN, enumtype));
19350 358016 : return;
19351 : }
19352 :
19353 : /* If this is a forward declaration, there should not be any variants,
19354 : though we can get a variant in the middle of an enum-specifier with
19355 : wacky code like 'enum E { e = sizeof(const E*) };' */
19356 3863348 : gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
19357 : && (TYPE_VALUES (enumtype)
19358 : || !TYPE_NEXT_VARIANT (enumtype)));
19359 : }
19360 :
19361 : /* Build and install a CONST_DECL for an enumeration constant of the
19362 : enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
19363 : Apply ATTRIBUTES if available. LOC is the location of NAME.
19364 : Assignment of sequential values by default is handled here. */
19365 :
19366 : tree
19367 12135551 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
19368 : location_t loc)
19369 : {
19370 12135551 : tree decl;
19371 12135551 : tree context;
19372 12135551 : tree type;
19373 :
19374 : /* scalar_constant_value will pull out this expression, so make sure
19375 : it's folded as appropriate.
19376 :
19377 : Creating a TARGET_EXPR in a template breaks when substituting, and
19378 : here we would create it for instance when using a class prvalue with
19379 : a user-defined conversion function. So don't use such a tree. We
19380 : instantiate VALUE here to get errors about bad enumerators even in
19381 : a template that does not get instantiated. */
19382 12135551 : if (processing_template_decl)
19383 454003 : value = maybe_fold_non_dependent_expr (value);
19384 :
19385 : /* If the VALUE was erroneous, pretend it wasn't there; that will
19386 : result in the enum being assigned the next value in sequence. */
19387 12135551 : if (value == error_mark_node)
19388 : value = NULL_TREE;
19389 :
19390 : /* Remove no-op casts from the value. */
19391 12135513 : if (value)
19392 9285089 : STRIP_TYPE_NOPS (value);
19393 :
19394 12135551 : if (! processing_template_decl)
19395 : {
19396 : /* Validate and default VALUE. */
19397 11681548 : if (value != NULL_TREE)
19398 : {
19399 5301056 : if (!ENUM_UNDERLYING_TYPE (enumtype))
19400 : {
19401 2691465 : tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
19402 : value, true);
19403 2691465 : if (tmp_value)
19404 5301056 : value = tmp_value;
19405 : }
19406 2609591 : else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
19407 : (TREE_TYPE (value)))
19408 39 : value = perform_implicit_conversion_flags
19409 39 : (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
19410 : LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
19411 :
19412 5301056 : if (value == error_mark_node)
19413 : value = NULL_TREE;
19414 :
19415 5301035 : if (value != NULL_TREE)
19416 : {
19417 5301035 : if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
19418 : (TREE_TYPE (value)))
19419 : {
19420 17 : error_at (cp_expr_loc_or_input_loc (value),
19421 : "enumerator value for %qD must have integral or "
19422 : "unscoped enumeration type", name);
19423 17 : value = NULL_TREE;
19424 : }
19425 : else
19426 : {
19427 5301018 : value = cxx_constant_value (value);
19428 :
19429 5301018 : if (TREE_CODE (value) != INTEGER_CST)
19430 : {
19431 48 : error ("enumerator value for %qD is not an integer "
19432 : "constant", name);
19433 48 : value = NULL_TREE;
19434 : }
19435 : }
19436 : }
19437 : }
19438 :
19439 : /* Default based on previous value. */
19440 65 : if (value == NULL_TREE)
19441 : {
19442 6380578 : if (TYPE_VALUES (enumtype))
19443 : {
19444 5840571 : tree prev_value;
19445 :
19446 : /* C++03 7.2/4: If no initializer is specified for the first
19447 : enumerator, the type is an unspecified integral
19448 : type. Otherwise the type is the same as the type of the
19449 : initializing value of the preceding enumerator unless the
19450 : incremented value is not representable in that type, in
19451 : which case the type is an unspecified integral type
19452 : sufficient to contain the incremented value. */
19453 5840571 : prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
19454 5840571 : if (TREE_CODE (prev_value) != INTEGER_CST)
19455 2 : value = error_mark_node;
19456 : else
19457 : {
19458 5840569 : wi::overflow_type overflowed;
19459 5840569 : tree type = TREE_TYPE (prev_value);
19460 5840569 : signop sgn = TYPE_SIGN (type);
19461 5840569 : widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
19462 5840569 : &overflowed);
19463 5840569 : if (!overflowed)
19464 : {
19465 5840569 : bool pos = !wi::neg_p (wi, sgn);
19466 5840569 : if (!wi::fits_to_tree_p (wi, type))
19467 : {
19468 : unsigned int itk;
19469 53 : for (itk = itk_int; itk != itk_none; itk++)
19470 : {
19471 53 : type = integer_types[itk];
19472 53 : if (type != NULL_TREE
19473 53 : && (pos || !TYPE_UNSIGNED (type))
19474 106 : && wi::fits_to_tree_p (wi, type))
19475 : break;
19476 : }
19477 17 : if (type && cxx_dialect < cxx11
19478 6 : && itk > itk_unsigned_long)
19479 3 : pedwarn (input_location, OPT_Wlong_long,
19480 : pos ? G_("\
19481 : incremented enumerator value is too large for %<unsigned long%>") : G_("\
19482 : incremented enumerator value is too large for %<long%>"));
19483 : }
19484 5840569 : if (type == NULL_TREE)
19485 0 : overflowed = wi::OVF_UNKNOWN;
19486 : else
19487 5840569 : value = wide_int_to_tree (type, wi);
19488 : }
19489 :
19490 5840569 : if (overflowed)
19491 : {
19492 0 : error ("overflow in enumeration values at %qD", name);
19493 0 : value = error_mark_node;
19494 : }
19495 5840569 : }
19496 : }
19497 : else
19498 540007 : value = integer_zero_node;
19499 : }
19500 :
19501 : /* Remove no-op casts from the value. */
19502 11681548 : STRIP_TYPE_NOPS (value);
19503 :
19504 : /* If the underlying type of the enum is fixed, check whether
19505 : the enumerator values fits in the underlying type. If it
19506 : does not fit, the program is ill-formed [C++0x dcl.enum]. */
19507 11681548 : if (ENUM_UNDERLYING_TYPE (enumtype)
19508 : && value
19509 11681548 : && TREE_CODE (value) == INTEGER_CST)
19510 : {
19511 4106491 : if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
19512 9 : error ("enumerator value %qE is outside the range of underlying "
19513 9 : "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
19514 :
19515 : /* Convert the value to the appropriate type. */
19516 4106491 : value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
19517 : }
19518 : }
19519 :
19520 : /* C++ associates enums with global, function, or class declarations. */
19521 12135551 : context = current_scope ();
19522 :
19523 : /* Build the actual enumeration constant. Note that the enumeration
19524 : constants have the underlying type of the enum (if it is fixed)
19525 : or the type of their initializer (if the underlying type of the
19526 : enum is not fixed):
19527 :
19528 : [ C++0x dcl.enum ]
19529 :
19530 : If the underlying type is fixed, the type of each enumerator
19531 : prior to the closing brace is the underlying type; if the
19532 : initializing value of an enumerator cannot be represented by
19533 : the underlying type, the program is ill-formed. If the
19534 : underlying type is not fixed, the type of each enumerator is
19535 : the type of its initializing value.
19536 :
19537 : If the underlying type is not fixed, it will be computed by
19538 : finish_enum and we will reset the type of this enumerator. Of
19539 : course, if we're processing a template, there may be no value. */
19540 12135551 : type = value ? TREE_TYPE (value) : NULL_TREE;
19541 :
19542 12135551 : decl = build_decl (loc, CONST_DECL, name, type);
19543 :
19544 12135551 : DECL_CONTEXT (decl) = enumtype;
19545 12135551 : TREE_CONSTANT (decl) = 1;
19546 12135551 : TREE_READONLY (decl) = 1;
19547 12135551 : DECL_INITIAL (decl) = value;
19548 :
19549 12135551 : if (attributes)
19550 133197 : cplus_decl_attributes (&decl, attributes, 0);
19551 :
19552 12135551 : if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
19553 : {
19554 : /* In something like `struct S { enum E { i = 7 }; };' we put `i'
19555 : on the TYPE_FIELDS list for `S'. (That's so that you can say
19556 : things like `S::i' later.) */
19557 :
19558 : /* The enumerator may be getting declared outside of its enclosing
19559 : class, like so:
19560 :
19561 : class S { public: enum E : int; }; enum S::E : int { i = 7; };
19562 :
19563 : For which case we need to make sure that the access of `S::i'
19564 : matches the access of `S::E'. */
19565 2101427 : auto cas = make_temp_override (current_access_specifier);
19566 2101427 : set_current_access_from_decl (TYPE_NAME (enumtype));
19567 2101427 : finish_member_declaration (decl);
19568 2101427 : }
19569 : else
19570 10034124 : pushdecl (decl);
19571 :
19572 : /* Add this enumeration constant to the list for this type. */
19573 12135551 : TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
19574 :
19575 12135551 : return decl;
19576 : }
19577 :
19578 : /* Look for an enumerator with the given NAME within the enumeration
19579 : type ENUMTYPE. This routine is used primarily for qualified name
19580 : lookup into an enumerator in C++0x, e.g.,
19581 :
19582 : enum class Color { Red, Green, Blue };
19583 :
19584 : Color color = Color::Red;
19585 :
19586 : Returns the value corresponding to the enumerator, or
19587 : NULL_TREE if no such enumerator was found. */
19588 : tree
19589 28478693 : lookup_enumerator (tree enumtype, tree name)
19590 : {
19591 28478693 : tree e;
19592 28478693 : gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
19593 :
19594 28478693 : e = purpose_member (name, TYPE_VALUES (enumtype));
19595 56957288 : return e? TREE_VALUE (e) : NULL_TREE;
19596 : }
19597 :
19598 : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL. */
19599 :
19600 : tree
19601 0 : cxx_simulate_enum_decl (location_t loc, const char *name,
19602 : vec<string_int_pair> *values)
19603 : {
19604 0 : location_t saved_loc = input_location;
19605 0 : input_location = loc;
19606 :
19607 0 : tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
19608 : NULL_TREE, false, NULL);
19609 0 : if (!OPAQUE_ENUM_P (enumtype))
19610 : {
19611 0 : auto_diagnostic_group d;
19612 0 : error_at (loc, "multiple definition of %q#T", enumtype);
19613 0 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
19614 : "previous definition here");
19615 0 : return enumtype;
19616 0 : }
19617 0 : SET_OPAQUE_ENUM_P (enumtype, false);
19618 0 : DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
19619 :
19620 0 : for (const string_int_pair &value : values)
19621 0 : build_enumerator (get_identifier (value.first),
19622 0 : build_int_cst (integer_type_node, value.second),
19623 : enumtype, NULL_TREE, loc);
19624 :
19625 0 : finish_enum_value_list (enumtype);
19626 0 : finish_enum (enumtype);
19627 :
19628 0 : input_location = saved_loc;
19629 0 : return enumtype;
19630 : }
19631 :
19632 : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL. */
19633 :
19634 : tree
19635 0 : cxx_simulate_record_decl (location_t loc, const char *name,
19636 : array_slice<const tree> fields)
19637 : {
19638 0 : iloc_sentinel ils (loc);
19639 :
19640 0 : tree ident = get_identifier (name);
19641 0 : tree type = xref_tag (/*tag_code=*/record_type, ident);
19642 0 : if (type != error_mark_node
19643 0 : && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
19644 : {
19645 0 : error ("redefinition of %q#T", type);
19646 0 : type = error_mark_node;
19647 : }
19648 0 : if (type == error_mark_node)
19649 0 : return lhd_simulate_record_decl (loc, name, fields);
19650 :
19651 0 : xref_basetypes (type, NULL_TREE);
19652 0 : type = begin_class_definition (type);
19653 0 : if (type == error_mark_node)
19654 0 : return lhd_simulate_record_decl (loc, name, fields);
19655 :
19656 0 : for (tree field : fields)
19657 0 : finish_member_declaration (field);
19658 :
19659 0 : type = finish_struct (type, NULL_TREE);
19660 :
19661 0 : tree decl = build_decl (loc, TYPE_DECL, ident, type);
19662 0 : set_underlying_type (decl);
19663 0 : lang_hooks.decls.pushdecl (decl);
19664 :
19665 0 : return type;
19666 0 : }
19667 :
19668 : /* We're defining DECL. Make sure that its type is OK. */
19669 :
19670 : static void
19671 165896904 : check_function_type (tree decl, tree current_function_parms)
19672 : {
19673 165896904 : tree fntype = TREE_TYPE (decl);
19674 165896904 : tree return_type = complete_type (TREE_TYPE (fntype));
19675 :
19676 : /* In a function definition, arg types must be complete. */
19677 165896904 : require_complete_types_for_parms (current_function_parms);
19678 :
19679 165896904 : if (dependent_type_p (return_type)
19680 165896904 : || type_uses_auto (return_type))
19681 52498538 : return;
19682 113398366 : if (!COMPLETE_OR_VOID_TYPE_P (return_type))
19683 : {
19684 12 : tree args = TYPE_ARG_TYPES (fntype);
19685 :
19686 12 : error ("return type %q#T is incomplete", return_type);
19687 :
19688 : /* Make it return void instead. */
19689 12 : if (TREE_CODE (fntype) == METHOD_TYPE)
19690 3 : fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
19691 : void_type_node,
19692 3 : TREE_CHAIN (args));
19693 : else
19694 18 : fntype = build_function_type (void_type_node, args,
19695 9 : TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
19696 12 : fntype = (cp_build_type_attribute_variant
19697 12 : (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
19698 12 : fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
19699 12 : TREE_TYPE (decl) = fntype;
19700 : }
19701 : else
19702 : {
19703 113398354 : abstract_virtuals_error (decl, TREE_TYPE (fntype));
19704 113398354 : maybe_warn_parm_abi (TREE_TYPE (fntype),
19705 113398354 : DECL_SOURCE_LOCATION (decl));
19706 : }
19707 : }
19708 :
19709 : /* True iff FN is an implicitly-defined default constructor. */
19710 :
19711 : static bool
19712 17349223 : implicit_default_ctor_p (tree fn)
19713 : {
19714 17349223 : return (DECL_CONSTRUCTOR_P (fn)
19715 17349223 : && !user_provided_p (fn)
19716 19309911 : && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
19717 : }
19718 :
19719 : /* Clobber the contents of *this to let the back end know that the object
19720 : storage is dead when we enter the constructor or leave the destructor. */
19721 :
19722 : static tree
19723 1507197 : build_clobber_this (clobber_kind kind)
19724 : {
19725 : /* Clobbering an empty base is pointless, and harmful if its one byte
19726 : TYPE_SIZE overlays real data. */
19727 1507197 : if (is_empty_class (current_class_type))
19728 0 : return void_node;
19729 :
19730 : /* If we have virtual bases, clobber the whole object, but only if we're in
19731 : charge. If we don't have virtual bases, clobber the as-base type so we
19732 : don't mess with tail padding. */
19733 1507197 : bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
19734 :
19735 1507197 : tree ctype = current_class_type;
19736 1507197 : if (!vbases)
19737 1499725 : ctype = CLASSTYPE_AS_BASE (ctype);
19738 :
19739 1507197 : tree clobber = build_clobber (ctype, kind);
19740 :
19741 1507197 : tree thisref = current_class_ref;
19742 1507197 : if (ctype != current_class_type)
19743 : {
19744 173174 : thisref = build_nop (build_reference_type (ctype), current_class_ptr);
19745 173174 : thisref = convert_from_reference (thisref);
19746 : }
19747 :
19748 1507197 : tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
19749 1507197 : if (kind == CLOBBER_OBJECT_BEGIN)
19750 0 : TREE_SET_CODE (exprstmt, INIT_EXPR);
19751 1507197 : if (vbases)
19752 7472 : exprstmt = build_if_in_charge (exprstmt);
19753 :
19754 : return exprstmt;
19755 : }
19756 :
19757 : /* Create the FUNCTION_DECL for a function definition.
19758 : DECLSPECS and DECLARATOR are the parts of the declaration;
19759 : they describe the function's name and the type it returns,
19760 : but twisted together in a fashion that parallels the syntax of C.
19761 :
19762 : FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
19763 : DECLARATOR is really the DECL for the function we are about to
19764 : process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
19765 : indicating that the function is an inline defined in-class.
19766 :
19767 : This function creates a binding context for the function body
19768 : as well as setting up the FUNCTION_DECL in current_function_decl.
19769 :
19770 : For C++, we must first check whether that datum makes any sense.
19771 : For example, "class A local_a(1,2);" means that variable local_a
19772 : is an aggregate of type A, which should have a constructor
19773 : applied to it with the argument list [1, 2].
19774 :
19775 : On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
19776 : or may be a BLOCK if the function has been defined previously
19777 : in this translation unit. On exit, DECL_INITIAL (decl1) will be
19778 : error_mark_node if the function has never been defined, or
19779 : a BLOCK if the function has been defined somewhere. */
19780 :
19781 : bool
19782 165896940 : start_preparsed_function (tree decl1, tree attrs, int flags)
19783 : {
19784 165896940 : tree ctype = NULL_TREE;
19785 165896940 : bool doing_friend = false;
19786 :
19787 : /* Sanity check. */
19788 165896940 : gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
19789 165896940 : gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
19790 :
19791 165896940 : tree fntype = TREE_TYPE (decl1);
19792 165896940 : if (DECL_CLASS_SCOPE_P (decl1))
19793 122387476 : ctype = DECL_CONTEXT (decl1);
19794 : else
19795 : {
19796 87018928 : ctype = DECL_FRIEND_CONTEXT (decl1);
19797 :
19798 43509463 : if (ctype)
19799 165896940 : doing_friend = true;
19800 : }
19801 :
19802 : /* Adjust for #pragma target/optimize if this is an artificial function that
19803 : (probably) didn't go through grokfndecl. We particularly don't want this
19804 : for deferred instantiations, which should match their template. */
19805 165896940 : if (DECL_ARTIFICIAL (decl1))
19806 3890011 : decl_attributes (&decl1, NULL_TREE, 0);
19807 :
19808 165896940 : if (DECL_DECLARED_INLINE_P (decl1)
19809 165896940 : && lookup_attribute ("noinline", attrs))
19810 : {
19811 0 : auto_urlify_attributes sentinel;
19812 0 : warning_at (DECL_SOURCE_LOCATION (decl1), 0,
19813 : "inline function %qD given attribute %qs", decl1, "noinline");
19814 0 : }
19815 :
19816 : /* Handle gnu_inline attribute. */
19817 165896940 : if (GNU_INLINE_P (decl1))
19818 : {
19819 1969301 : DECL_EXTERNAL (decl1) = 1;
19820 1969301 : DECL_NOT_REALLY_EXTERN (decl1) = 0;
19821 1969301 : DECL_INTERFACE_KNOWN (decl1) = 1;
19822 1969301 : DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
19823 : }
19824 :
19825 165896940 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
19826 : /* This is a constructor, we must ensure that any default args
19827 : introduced by this definition are propagated to the clones
19828 : now. The clones are used directly in overload resolution. */
19829 20693372 : adjust_clone_args (decl1);
19830 :
19831 : /* Sometimes we don't notice that a function is a static member, and
19832 : build a METHOD_TYPE for it. Fix that up now. */
19833 165896940 : gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
19834 : && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
19835 :
19836 : /* Set up current_class_type, and enter the scope of the class, if
19837 : appropriate. */
19838 165896940 : if (ctype)
19839 127063233 : push_nested_class (ctype);
19840 :
19841 : /* Now that we have entered the scope of the class, we must restore
19842 : the bindings for any template parameters surrounding DECL1, if it
19843 : is an inline member template. (Order is important; consider the
19844 : case where a template parameter has the same name as a field of
19845 : the class.) It is not until after this point that
19846 : PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly. */
19847 165896940 : if (flags & SF_INCLASS_INLINE)
19848 85166323 : maybe_begin_member_template_processing (decl1);
19849 :
19850 : /* Effective C++ rule 15. */
19851 165896940 : if (warn_ecpp
19852 123 : && DECL_ASSIGNMENT_OPERATOR_P (decl1)
19853 30 : && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
19854 165896970 : && VOID_TYPE_P (TREE_TYPE (fntype)))
19855 0 : warning (OPT_Weffc__,
19856 : "%<operator=%> should return a reference to %<*this%>");
19857 :
19858 : /* Make the init_value nonzero so pushdecl knows this is not tentative.
19859 : error_mark_node is replaced below (in poplevel) with the BLOCK. */
19860 165896940 : if (!DECL_INITIAL (decl1))
19861 36052769 : DECL_INITIAL (decl1) = error_mark_node;
19862 :
19863 : /* This function exists in static storage.
19864 : (This does not mean `static' in the C sense!) */
19865 165896940 : TREE_STATIC (decl1) = 1;
19866 :
19867 : /* We must call push_template_decl after current_class_type is set
19868 : up. (If we are processing inline definitions after exiting a
19869 : class scope, current_class_type will be NULL_TREE until set above
19870 : by push_nested_class.) */
19871 165896940 : if (processing_template_decl)
19872 : {
19873 97337070 : tree newdecl1 = push_template_decl (decl1, doing_friend);
19874 97337070 : if (newdecl1 == error_mark_node)
19875 : {
19876 36 : if (ctype)
19877 9 : pop_nested_class ();
19878 36 : return false;
19879 : }
19880 97337034 : decl1 = newdecl1;
19881 : }
19882 :
19883 : /* Make sure the parameter and return types are reasonable. When
19884 : you declare a function, these types can be incomplete, but they
19885 : must be complete when you define the function. */
19886 165896904 : check_function_type (decl1, DECL_ARGUMENTS (decl1));
19887 :
19888 : /* Build the return declaration for the function. */
19889 165896904 : tree restype = TREE_TYPE (fntype);
19890 :
19891 165896904 : if (DECL_RESULT (decl1) == NULL_TREE)
19892 : {
19893 : /* In a template instantiation, copy the return type location. When
19894 : parsing, the location will be set in grokdeclarator. */
19895 68457075 : location_t loc = input_location;
19896 68457075 : if (DECL_TEMPLATE_INSTANTIATION (decl1))
19897 : {
19898 32462448 : tree tmpl = template_for_substitution (decl1);
19899 32462448 : if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
19900 31514603 : loc = DECL_SOURCE_LOCATION (res);
19901 : }
19902 :
19903 68457075 : tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
19904 68457075 : DECL_ARTIFICIAL (resdecl) = 1;
19905 68457075 : DECL_IGNORED_P (resdecl) = 1;
19906 68457075 : DECL_RESULT (decl1) = resdecl;
19907 :
19908 68457075 : cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
19909 : }
19910 :
19911 : /* Record the decl so that the function name is defined.
19912 : If we already have a decl for this name, and it is a FUNCTION_DECL,
19913 : use the old decl. */
19914 165896904 : if (!processing_template_decl && !(flags & SF_PRE_PARSED))
19915 : {
19916 : /* A specialization is not used to guide overload resolution. */
19917 20534744 : if (!DECL_FUNCTION_MEMBER_P (decl1)
19918 20514962 : && !(DECL_USE_TEMPLATE (decl1) &&
19919 13351 : PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
19920 : {
19921 9832720 : tree olddecl = pushdecl (decl1);
19922 :
19923 9832720 : if (olddecl == error_mark_node)
19924 : /* If something went wrong when registering the declaration,
19925 : use DECL1; we have to have a FUNCTION_DECL to use when
19926 : parsing the body of the function. */
19927 : ;
19928 : else
19929 : {
19930 : /* Otherwise, OLDDECL is either a previous declaration
19931 : of the same function or DECL1 itself. */
19932 :
19933 9832507 : if (warn_missing_declarations
19934 21 : && olddecl == decl1
19935 15 : && !DECL_MAIN_P (decl1)
19936 15 : && TREE_PUBLIC (decl1)
19937 9832519 : && !DECL_DECLARED_INLINE_P (decl1))
19938 : {
19939 9 : tree context;
19940 :
19941 : /* Check whether DECL1 is in an anonymous
19942 : namespace. */
19943 9 : for (context = DECL_CONTEXT (decl1);
19944 18 : context;
19945 9 : context = DECL_CONTEXT (context))
19946 : {
19947 12 : if (TREE_CODE (context) == NAMESPACE_DECL
19948 12 : && DECL_NAME (context) == NULL_TREE)
19949 : break;
19950 : }
19951 :
19952 9 : if (context == NULL)
19953 6 : warning_at (DECL_SOURCE_LOCATION (decl1),
19954 6 : OPT_Wmissing_declarations,
19955 : "no previous declaration for %qD", decl1);
19956 : }
19957 :
19958 9832507 : decl1 = olddecl;
19959 : }
19960 : }
19961 : else
19962 : {
19963 : /* We need to set the DECL_CONTEXT. */
19964 836171 : if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
19965 0 : DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
19966 : }
19967 10668891 : fntype = TREE_TYPE (decl1);
19968 10668891 : restype = TREE_TYPE (fntype);
19969 :
19970 : /* If #pragma weak applies, mark the decl appropriately now.
19971 : The pragma only applies to global functions. Because
19972 : determining whether or not the #pragma applies involves
19973 : computing the mangled name for the declaration, we cannot
19974 : apply the pragma until after we have merged this declaration
19975 : with any previous declarations; if the original declaration
19976 : has a linkage specification, that specification applies to
19977 : the definition as well, and may affect the mangled name. */
19978 10668891 : if (DECL_FILE_SCOPE_P (decl1))
19979 2523507 : maybe_apply_pragma_weak (decl1);
19980 : }
19981 :
19982 : /* We are now in the scope of the function being defined. */
19983 165896904 : current_function_decl = decl1;
19984 :
19985 : /* Save the parm names or decls from this function's declarator
19986 : where store_parm_decls will find them. */
19987 165896904 : tree current_function_parms = DECL_ARGUMENTS (decl1);
19988 :
19989 : /* Let the user know we're compiling this function. */
19990 165896904 : announce_function (decl1);
19991 :
19992 165896904 : gcc_assert (DECL_INITIAL (decl1));
19993 :
19994 : /* This function may already have been parsed, in which case just
19995 : return; our caller will skip over the body without parsing. */
19996 165896904 : if (DECL_INITIAL (decl1) != error_mark_node)
19997 : return true;
19998 :
19999 : /* Initialize RTL machinery. We cannot do this until
20000 : CURRENT_FUNCTION_DECL and DECL_RESULT are set up. We do this
20001 : even when processing a template; this is how we get
20002 : CFUN set up, and our per-function variables initialized.
20003 : FIXME factor out the non-RTL stuff. */
20004 165896904 : cp_binding_level *bl = current_binding_level;
20005 165896904 : allocate_struct_function (decl1, processing_template_decl);
20006 :
20007 : /* Initialize the language data structures. Whenever we start
20008 : a new function, we destroy temporaries in the usual way. */
20009 165896904 : cfun->language = ggc_cleared_alloc<language_function> ();
20010 165896904 : current_stmt_tree ()->stmts_are_full_exprs_p = 1;
20011 165896904 : current_binding_level = bl;
20012 :
20013 : /* If we are (erroneously) defining a function that we have already
20014 : defined before, wipe out what we knew before. */
20015 165896904 : gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
20016 165896904 : FNDECL_USED_AUTO (decl1) = false;
20017 165896904 : DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
20018 :
20019 165896904 : if (!processing_template_decl && type_uses_auto (restype))
20020 : {
20021 1048333 : FNDECL_USED_AUTO (decl1) = true;
20022 1048333 : DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
20023 : }
20024 :
20025 : /* Start the statement-tree, start the tree now. */
20026 165896904 : DECL_SAVED_TREE (decl1) = push_stmt_list ();
20027 :
20028 165896904 : if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
20029 : {
20030 : /* We know that this was set up by `grokclassfn'. We do not
20031 : wait until `store_parm_decls', since evil parse errors may
20032 : never get us to that point. Here we keep the consistency
20033 : between `current_class_type' and `current_class_ptr'. */
20034 107679438 : tree t = DECL_ARGUMENTS (decl1);
20035 :
20036 107679438 : gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
20037 107679438 : gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
20038 :
20039 107679438 : cp_function_chain->x_current_class_ref
20040 107679438 : = cp_build_fold_indirect_ref (t);
20041 : /* Set this second to avoid shortcut in cp_build_indirect_ref. */
20042 107679438 : cp_function_chain->x_current_class_ptr = t;
20043 :
20044 : /* Constructors and destructors need to know whether they're "in
20045 : charge" of initializing virtual base classes. */
20046 107679438 : t = DECL_CHAIN (t);
20047 107679438 : if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
20048 : {
20049 17685 : current_in_charge_parm = t;
20050 17685 : t = DECL_CHAIN (t);
20051 : }
20052 107679438 : if (DECL_HAS_VTT_PARM_P (decl1))
20053 : {
20054 35429 : gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
20055 35429 : current_vtt_parm = t;
20056 : }
20057 : }
20058 :
20059 299313915 : bool honor_interface = (!DECL_TEMPLOID_INSTANTIATION (decl1)
20060 : /* Implicitly-defined methods (like the
20061 : destructor for a class in which no destructor
20062 : is explicitly declared) must not be defined
20063 : until their definition is needed. So, we
20064 : ignore interface specifications for
20065 : compiler-generated functions. */
20066 201911882 : && !DECL_ARTIFICIAL (decl1));
20067 165896904 : struct c_fileinfo *finfo
20068 165896904 : = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
20069 :
20070 165896904 : if (processing_template_decl)
20071 : /* Don't mess with interface flags. */;
20072 68559870 : else if (DECL_INTERFACE_KNOWN (decl1))
20073 : {
20074 19990806 : tree ctx = decl_function_context (decl1);
20075 :
20076 19990806 : if (DECL_NOT_REALLY_EXTERN (decl1))
20077 15933544 : DECL_EXTERNAL (decl1) = 0;
20078 :
20079 19990806 : if (ctx != NULL_TREE && vague_linkage_p (ctx))
20080 : /* This is a function in a local class in an extern inline
20081 : or template function. */
20082 3110424 : comdat_linkage (decl1);
20083 : }
20084 : /* If this function belongs to an interface, it is public.
20085 : If it belongs to someone else's interface, it is also external.
20086 : This only affects inlines and template instantiations. */
20087 48569064 : else if (!finfo->interface_unknown && honor_interface)
20088 : {
20089 106 : if (DECL_DECLARED_INLINE_P (decl1)
20090 106 : || DECL_TEMPLOID_INSTANTIATION (decl1))
20091 : {
20092 82 : DECL_EXTERNAL (decl1)
20093 164 : = (finfo->interface_only
20094 82 : || (DECL_DECLARED_INLINE_P (decl1)
20095 36 : && ! flag_implement_inlines
20096 0 : && !DECL_VINDEX (decl1)));
20097 :
20098 : /* For WIN32 we also want to put these in linkonce sections. */
20099 82 : maybe_make_one_only (decl1);
20100 : }
20101 : else
20102 24 : DECL_EXTERNAL (decl1) = 0;
20103 106 : DECL_INTERFACE_KNOWN (decl1) = 1;
20104 : /* If this function is in an interface implemented in this file,
20105 : make sure that the back end knows to emit this function
20106 : here. */
20107 106 : if (!DECL_EXTERNAL (decl1))
20108 60 : mark_needed (decl1);
20109 : }
20110 48568958 : else if (finfo->interface_unknown && finfo->interface_only
20111 0 : && honor_interface)
20112 : {
20113 : /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
20114 : interface, we will have both finfo->interface_unknown and
20115 : finfo->interface_only set. In that case, we don't want to
20116 : use the normal heuristics because someone will supply a
20117 : #pragma implementation elsewhere, and deducing it here would
20118 : produce a conflict. */
20119 0 : comdat_linkage (decl1);
20120 0 : DECL_EXTERNAL (decl1) = 0;
20121 0 : DECL_INTERFACE_KNOWN (decl1) = 1;
20122 0 : DECL_DEFER_OUTPUT (decl1) = 1;
20123 : }
20124 : else
20125 : {
20126 : /* This is a definition, not a reference.
20127 : So clear DECL_EXTERNAL, unless this is a GNU extern inline. */
20128 48568958 : if (!GNU_INLINE_P (decl1))
20129 48568955 : DECL_EXTERNAL (decl1) = 0;
20130 :
20131 48568958 : if ((DECL_DECLARED_INLINE_P (decl1)
20132 1900548 : || DECL_TEMPLOID_INSTANTIATION (decl1))
20133 50227880 : && ! DECL_INTERFACE_KNOWN (decl1))
20134 48327332 : DECL_DEFER_OUTPUT (decl1) = 1;
20135 : else
20136 241626 : DECL_INTERFACE_KNOWN (decl1) = 1;
20137 : }
20138 :
20139 : /* Determine the ELF visibility attribute for the function. We must not
20140 : do this before calling "pushdecl", as we must allow "duplicate_decls"
20141 : to merge any attributes appropriately. We also need to wait until
20142 : linkage is set. */
20143 165896904 : if (!DECL_CLONED_FUNCTION_P (decl1))
20144 149446288 : determine_visibility (decl1);
20145 :
20146 165896904 : if (!processing_template_decl)
20147 68559870 : maybe_instantiate_noexcept (decl1);
20148 :
20149 165896904 : begin_scope (sk_function_parms, decl1);
20150 :
20151 165896904 : ++function_depth;
20152 :
20153 165896904 : start_fname_decls ();
20154 :
20155 165896904 : store_parm_decls (current_function_parms);
20156 :
20157 165896904 : start_function_contracts (decl1);
20158 :
20159 165896904 : if (!processing_template_decl
20160 68559870 : && flag_lifetime_dse > 1
20161 137110370 : && DECL_CONSTRUCTOR_P (decl1)
20162 : /* Clobbering an empty base is harmful if it overlays real data. */
20163 19229717 : && !is_empty_class (current_class_type)
20164 : /* We can't clobber safely for an implicitly-defined default constructor
20165 : because part of the initialization might happen before we enter the
20166 : constructor, via AGGR_INIT_ZERO_FIRST (c++/68006). */
20167 17348580 : && !implicit_default_ctor_p (decl1)
20168 182040723 : && !lookup_attribute ("clobber *this",
20169 16143819 : DECL_ATTRIBUTES (current_class_ptr)))
20170 16134337 : DECL_ATTRIBUTES (current_class_ptr)
20171 32268674 : = tree_cons (get_identifier ("clobber *this"), NULL_TREE,
20172 16134337 : DECL_ATTRIBUTES (current_class_ptr));
20173 :
20174 165896904 : if (!processing_template_decl
20175 137119740 : && DECL_CONSTRUCTOR_P (decl1)
20176 19230959 : && sanitize_flags_p (SANITIZE_VPTR)
20177 1929 : && !DECL_CLONED_FUNCTION_P (decl1)
20178 165897547 : && !implicit_default_ctor_p (decl1))
20179 483 : cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
20180 :
20181 165896904 : if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
20182 165896331 : start_lambda_scope (decl1);
20183 :
20184 : return true;
20185 : }
20186 :
20187 :
20188 : /* Like start_preparsed_function, except that instead of a
20189 : FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
20190 :
20191 : Returns true on success. If the DECLARATOR is not suitable
20192 : for a function, we return false, which tells the parser to
20193 : skip the entire function. */
20194 :
20195 : bool
20196 39777629 : start_function (cp_decl_specifier_seq *declspecs,
20197 : const cp_declarator *declarator,
20198 : tree attrs)
20199 : {
20200 39777629 : tree decl1;
20201 :
20202 39777629 : decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
20203 39777629 : invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
20204 39777629 : if (decl1 == error_mark_node)
20205 : return false;
20206 :
20207 39777263 : if (DECL_MAIN_P (decl1))
20208 : /* main must return int. grokfndecl should have corrected it
20209 : (and issued a diagnostic) if the user got it wrong. */
20210 34971 : gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
20211 : integer_type_node));
20212 :
20213 39777263 : return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
20214 : }
20215 :
20216 : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
20217 : FN. */
20218 :
20219 : bool
20220 317664172 : use_eh_spec_block (tree fn)
20221 : {
20222 315715909 : return (flag_exceptions && flag_enforce_eh_specs
20223 315715909 : && !processing_template_decl
20224 : /* We insert the EH_SPEC_BLOCK only in the original
20225 : function; then, it is copied automatically to the
20226 : clones. */
20227 119735754 : && !DECL_CLONED_FUNCTION_P (fn)
20228 : /* Implicitly-generated constructors and destructors have
20229 : exception specifications. However, those specifications
20230 : are the union of the possible exceptions specified by the
20231 : constructors/destructors for bases and members, so no
20232 : unallowed exception will ever reach this function. By
20233 : not creating the EH_SPEC_BLOCK we save a little memory,
20234 : and we avoid spurious warnings about unreachable
20235 : code. */
20236 103326915 : && !DECL_DEFAULTED_FN (fn)
20237 418440045 : && !type_throw_all_p (TREE_TYPE (fn)));
20238 : }
20239 :
20240 : /* Helper function to push ARGS into the current lexical scope. DECL
20241 : is the function declaration. NONPARMS is used to handle enum
20242 : constants. */
20243 :
20244 : void
20245 160976536 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
20246 : {
20247 : /* If we're doing semantic analysis, then we'll call pushdecl
20248 : for each of these. We must do them in reverse order so that
20249 : they end in the correct forward order. */
20250 160976536 : args = nreverse (args);
20251 :
20252 160976536 : tree next;
20253 493776003 : for (tree parm = args; parm; parm = next)
20254 : {
20255 332799467 : next = DECL_CHAIN (parm);
20256 332799467 : if (TREE_CODE (parm) == PARM_DECL)
20257 332799467 : pushdecl (parm);
20258 0 : else if (nonparms)
20259 : {
20260 : /* If we find an enum constant or a type tag, put it aside for
20261 : the moment. */
20262 0 : TREE_CHAIN (parm) = NULL_TREE;
20263 0 : *nonparms = chainon (*nonparms, parm);
20264 : }
20265 : }
20266 :
20267 : /* Get the decls in their original chain order and record in the
20268 : function. This is all and only the PARM_DECLs that were
20269 : pushed into scope by the loop above. */
20270 160976536 : DECL_ARGUMENTS (decl) = get_local_decls ();
20271 160976536 : }
20272 :
20273 : /* Store the parameter declarations into the current function declaration.
20274 : This is called after parsing the parameter declarations, before
20275 : digesting the body of the function.
20276 :
20277 : Also install to binding contour return value identifier, if any. */
20278 :
20279 : static void
20280 165896904 : store_parm_decls (tree current_function_parms)
20281 : {
20282 165896904 : tree fndecl = current_function_decl;
20283 :
20284 : /* This is a chain of any other decls that came in among the parm
20285 : declarations. If a parm is declared with enum {foo, bar} x;
20286 : then CONST_DECLs for foo and bar are put here. */
20287 165896904 : tree nonparms = NULL_TREE;
20288 :
20289 165896904 : if (current_function_parms)
20290 : {
20291 : /* This case is when the function was defined with an ANSI prototype.
20292 : The parms already have decls, so we need not do anything here
20293 : except record them as in effect
20294 : and complain if any redundant old-style parm decls were written. */
20295 :
20296 157390353 : tree specparms = current_function_parms;
20297 :
20298 : /* Must clear this because it might contain TYPE_DECLs declared
20299 : at class level. */
20300 157390353 : current_binding_level->names = NULL;
20301 :
20302 157390353 : do_push_parm_decls (fndecl, specparms, &nonparms);
20303 : }
20304 : else
20305 8506551 : DECL_ARGUMENTS (fndecl) = NULL_TREE;
20306 :
20307 : /* Now store the final chain of decls for the arguments
20308 : as the decl-chain of the current lexical scope.
20309 : Put the enumerators in as well, at the front so that
20310 : DECL_ARGUMENTS is not modified. */
20311 165896904 : current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
20312 :
20313 : /* Register cleanups for parameters with trivial_abi attribute, the cleanup
20314 : of which is the callee's responsibility. */
20315 165896904 : if (!processing_template_decl && !DECL_CLONED_FUNCTION_P (fndecl))
20316 134646777 : for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
20317 : {
20318 82537523 : if (TREE_CODE (parm) == PARM_DECL)
20319 : {
20320 82537523 : tree parm_type = TREE_TYPE (parm);
20321 82537523 : if (has_trivial_abi_attribute (parm_type))
20322 : {
20323 18 : tree cleanup
20324 18 : = cxx_maybe_build_cleanup (parm, tf_warning_or_error);
20325 18 : if (cleanup && cleanup != error_mark_node)
20326 18 : finish_decl_cleanup (parm, cleanup);
20327 : }
20328 : }
20329 : }
20330 :
20331 165896904 : if (use_eh_spec_block (current_function_decl))
20332 25312684 : current_eh_spec_block = begin_eh_spec_block ();
20333 165896904 : }
20334 :
20335 :
20336 : /* Mark CDTOR's implicit THIS argument for returning, if required by
20337 : the ABI.. Return the decl for THIS, if it is to be returned, and
20338 : NULL otherwise. */
20339 :
20340 : tree
20341 142500064 : maybe_prepare_return_this (tree cdtor)
20342 : {
20343 142500064 : if (targetm.cxx.cdtor_returns_this ())
20344 0 : if (tree val = DECL_ARGUMENTS (cdtor))
20345 : {
20346 0 : suppress_warning (val, OPT_Wuse_after_free_);
20347 0 : return val;
20348 : }
20349 :
20350 : return NULL_TREE;
20351 : }
20352 :
20353 : /* Set the return value of the [cd]tor if the ABI wants that. */
20354 :
20355 : void
20356 8376010 : maybe_return_this ()
20357 : {
20358 8376010 : if (tree val = maybe_prepare_return_this (current_function_decl))
20359 : {
20360 : /* Return the address of the object. */
20361 0 : val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
20362 0 : val = build2 (MODIFY_EXPR, TREE_TYPE (val),
20363 0 : DECL_RESULT (current_function_decl), val);
20364 0 : tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
20365 0 : add_stmt (exprstmt);
20366 : }
20367 8376010 : }
20368 :
20369 : /* Do all the processing for the beginning of a destructor; set up the
20370 : vtable pointers and cleanups for bases and members. */
20371 :
20372 : static void
20373 1650731 : begin_destructor_body (void)
20374 : {
20375 1650731 : tree compound_stmt;
20376 :
20377 : /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
20378 : issued an error message. We still want to try to process the
20379 : body of the function, but initialize_vtbl_ptrs will crash if
20380 : TYPE_BINFO is NULL. */
20381 1650731 : if (COMPLETE_TYPE_P (current_class_type))
20382 : {
20383 1650731 : compound_stmt = begin_compound_stmt (0);
20384 : /* Make all virtual function table pointers in non-virtual base
20385 : classes point to CURRENT_CLASS_TYPE's virtual function
20386 : tables. */
20387 1650731 : initialize_vtbl_ptrs (current_class_ptr);
20388 1650731 : finish_compound_stmt (compound_stmt);
20389 :
20390 1650731 : if (flag_lifetime_dse
20391 : /* Clobbering an empty base is harmful if it overlays real data. */
20392 1650731 : && !is_empty_class (current_class_type))
20393 : {
20394 1507260 : if (sanitize_flags_p (SANITIZE_VPTR)
20395 235 : && (flag_sanitize_recover & SANITIZE_VPTR) == 0
20396 1507323 : && TYPE_CONTAINS_VPTR_P (current_class_type))
20397 : {
20398 63 : tree binfo = TYPE_BINFO (current_class_type);
20399 63 : tree ref
20400 63 : = cp_build_fold_indirect_ref (current_class_ptr);
20401 :
20402 63 : tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
20403 63 : tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
20404 63 : tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
20405 : NOP_EXPR, vtbl,
20406 : tf_warning_or_error);
20407 : /* If the vptr is shared with some virtual nearly empty base,
20408 : don't clear it if not in charge, the dtor of the virtual
20409 : nearly empty base will do that later. */
20410 63 : if (CLASSTYPE_VBASECLASSES (current_class_type))
20411 : {
20412 : tree c = current_class_type;
20413 66 : while (CLASSTYPE_PRIMARY_BINFO (c))
20414 : {
20415 63 : if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
20416 : {
20417 36 : stmt = convert_to_void (stmt, ICV_STATEMENT,
20418 : tf_warning_or_error);
20419 36 : stmt = build_if_in_charge (stmt);
20420 36 : break;
20421 : }
20422 27 : c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
20423 : }
20424 : }
20425 63 : finish_decl_cleanup (NULL_TREE, stmt);
20426 : }
20427 : else
20428 1507197 : finish_decl_cleanup (NULL_TREE,
20429 : build_clobber_this (CLOBBER_OBJECT_END));
20430 : }
20431 :
20432 : /* And insert cleanups for our bases and members so that they
20433 : will be properly destroyed if we throw. */
20434 1650731 : push_base_cleanups ();
20435 : }
20436 1650731 : }
20437 :
20438 : /* Do the necessary processing for the beginning of a function body, which
20439 : in this case includes member-initializers, but not the catch clauses of
20440 : a function-try-block. Currently, this means opening a binding level
20441 : for the member-initializers (in a ctor), member cleanups (in a dtor),
20442 : and capture proxies (in a lambda operator()). */
20443 :
20444 : tree
20445 130472474 : begin_function_body (void)
20446 : {
20447 268608967 : if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
20448 : return NULL_TREE;
20449 :
20450 25506370 : if (processing_template_decl)
20451 : /* Do nothing now. */;
20452 : else
20453 : /* Always keep the BLOCK node associated with the outermost pair of
20454 : curly braces of a function. These are needed for correct
20455 : operation of dwarfout.c. */
20456 8537937 : keep_next_level (true);
20457 :
20458 25506370 : tree stmt = begin_compound_stmt (BCS_FN_BODY);
20459 25506370 : current_binding_level->artificial = 1;
20460 :
20461 25506370 : if (processing_template_decl)
20462 : /* Do nothing now. */;
20463 17075874 : else if (DECL_DESTRUCTOR_P (current_function_decl))
20464 1650731 : begin_destructor_body ();
20465 :
20466 : return stmt;
20467 : }
20468 :
20469 : /* Do the processing for the end of a function body. Currently, this means
20470 : closing out the cleanups for fully-constructed bases and members, and in
20471 : the case of the destructor, deleting the object if desired. Again, this
20472 : is only meaningful for [cd]tors, since they are the only functions where
20473 : there is a significant distinction between the main body and any
20474 : function catch clauses. Handling, say, main() return semantics here
20475 : would be wrong, as flowing off the end of a function catch clause for
20476 : main() would also need to return 0. */
20477 :
20478 : void
20479 130472450 : finish_function_body (tree compstmt)
20480 : {
20481 130472450 : if (compstmt == NULL_TREE)
20482 : return;
20483 :
20484 : /* Close the block. */
20485 25506370 : finish_compound_stmt (compstmt);
20486 :
20487 25506370 : if (processing_template_decl)
20488 : /* Do nothing now. */;
20489 8537937 : else if (DECL_CONSTRUCTOR_P (current_function_decl)
20490 8537937 : || DECL_DESTRUCTOR_P (current_function_decl))
20491 8056486 : maybe_return_this ();
20492 : }
20493 :
20494 : /* Given a function, returns the BLOCK corresponding to the outermost level
20495 : of curly braces, skipping the artificial block created for constructor
20496 : initializers. */
20497 :
20498 : tree
20499 357490 : outer_curly_brace_block (tree fndecl)
20500 : {
20501 357490 : tree block = DECL_INITIAL (fndecl);
20502 357490 : if (BLOCK_OUTER_CURLY_BRACE_P (block))
20503 : return block;
20504 1213 : block = BLOCK_SUBBLOCKS (block);
20505 1213 : if (BLOCK_OUTER_CURLY_BRACE_P (block))
20506 : return block;
20507 0 : block = BLOCK_SUBBLOCKS (block);
20508 0 : gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
20509 : return block;
20510 : }
20511 :
20512 : /* If FNDECL is a class's key method, add the class to the list of
20513 : keyed classes that should be emitted. */
20514 :
20515 : static void
20516 165900856 : record_key_method_defined (tree fndecl)
20517 : {
20518 224122250 : if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
20519 107773845 : && DECL_VIRTUAL_P (fndecl)
20520 168726797 : && !processing_template_decl)
20521 : {
20522 1471650 : tree fnclass = DECL_CONTEXT (fndecl);
20523 1471650 : if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
20524 : {
20525 30304 : tree classdecl = TYPE_NAME (fnclass);
20526 : /* Classes attached to a named module are already handled. */
20527 30304 : if (!DECL_LANG_SPECIFIC (classdecl)
20528 30627 : || !DECL_MODULE_ATTACH_P (classdecl))
20529 30259 : vec_safe_push (keyed_classes, fnclass);
20530 : }
20531 : }
20532 165900856 : }
20533 :
20534 : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
20535 : of "return *this;" immediately before its location, using FNDECL's
20536 : first statement (if any) to give the indentation, if appropriate. */
20537 :
20538 : static void
20539 18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
20540 : {
20541 18 : location_t indent = UNKNOWN_LOCATION;
20542 18 : tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
20543 18 : if (stmts)
20544 9 : indent = EXPR_LOCATION (stmts);
20545 18 : richloc->add_fixit_insert_formatted ("return *this;",
20546 : richloc->get_loc (),
20547 : indent);
20548 18 : }
20549 :
20550 : /* Finish up a function declaration and compile that function
20551 : all the way to assembler language output. The free the storage
20552 : for the function definition. INLINE_P is TRUE if we just
20553 : finished processing the body of an in-class inline function
20554 : definition. (This processing will have taken place after the
20555 : class definition is complete.) */
20556 :
20557 : tree
20558 165896868 : finish_function (bool inline_p)
20559 : {
20560 165896868 : tree fndecl = current_function_decl;
20561 165896868 : tree fntype, ctype = NULL_TREE;
20562 165896868 : tree resumer = NULL_TREE, destroyer = NULL_TREE;
20563 :
20564 : /* When we get some parse errors, we can end up without a
20565 : current_function_decl, so cope. */
20566 165896868 : if (fndecl == NULL_TREE || fndecl == error_mark_node)
20567 0 : return error_mark_node;
20568 :
20569 165896868 : if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20570 165896295 : finish_lambda_scope ();
20571 :
20572 165896868 : if (c_dialect_objc ())
20573 0 : objc_finish_function ();
20574 :
20575 165896868 : record_key_method_defined (fndecl);
20576 :
20577 165896868 : fntype = TREE_TYPE (fndecl);
20578 :
20579 : /* TREE_READONLY (fndecl) = 1;
20580 : This caused &foo to be of type ptr-to-const-function
20581 : which then got a warning when stored in a ptr-to-function variable. */
20582 :
20583 165896868 : gcc_assert (building_stmt_list_p ());
20584 : /* The current function is being defined, so its DECL_INITIAL should
20585 : be set, and unless there's a multiple definition, it should be
20586 : error_mark_node. */
20587 165896868 : gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
20588 :
20589 165896868 : cp_coroutine_transform *coroutine = nullptr;
20590 165896868 : if (flag_coroutines
20591 163146091 : && !processing_template_decl
20592 66788977 : && DECL_COROUTINE_P (fndecl)
20593 165901830 : && !DECL_RAMP_FN (fndecl))
20594 : {
20595 1710 : gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
20596 : && !DECL_DEFAULTED_FN (fndecl));
20597 1710 : coroutine = new cp_coroutine_transform (fndecl, inline_p);
20598 1710 : if (coroutine && coroutine->cp_valid_coroutine ())
20599 1710 : coroutine->apply_transforms ();
20600 :
20601 : /* We should handle coroutine IFNs in middle end lowering. */
20602 1710 : cfun->coroutine_component = true;
20603 :
20604 : /* Do not try to process the ramp's EH unless outlining succeeded. */
20605 1710 : if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
20606 360 : finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
20607 : (TREE_TYPE (fndecl)),
20608 360 : current_eh_spec_block);
20609 :
20610 : /* If outlining succeeded, then add contracts handling if needed. */
20611 1710 : if (coroutine->cp_valid_coroutine ())
20612 1626 : maybe_apply_function_contracts (fndecl);
20613 : }
20614 : else
20615 : /* For a cloned function, we've already got all the code we need;
20616 : there's no need to add any extra bits. */
20617 165895158 : if (!DECL_CLONED_FUNCTION_P (fndecl))
20618 : {
20619 : /* Make it so that `main' always returns 0 by default. */
20620 149444542 : if (DECL_MAIN_FREESTANDING_P (current_function_decl)
20621 149479498 : && !TREE_THIS_VOLATILE (current_function_decl))
20622 34956 : finish_return_stmt (integer_zero_node);
20623 :
20624 149444542 : if (use_eh_spec_block (current_function_decl))
20625 25312321 : finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
20626 : (TREE_TYPE (current_function_decl)),
20627 25312321 : current_eh_spec_block);
20628 :
20629 149444542 : maybe_apply_function_contracts (current_function_decl);
20630 :
20631 : }
20632 :
20633 : /* If we're saving up tree structure, tie off the function now. */
20634 165896868 : DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
20635 :
20636 165896868 : finish_fname_decls ();
20637 :
20638 : /* This must come after expand_function_end because cleanups might
20639 : have declarations (from inline functions) that need to go into
20640 : this function's blocks. */
20641 :
20642 : /* If the current binding level isn't the outermost binding level
20643 : for this function, either there is a bug, or we have experienced
20644 : syntax errors and the statement tree is malformed. */
20645 165896868 : if (current_binding_level->kind != sk_function_parms)
20646 : {
20647 : /* Make sure we have already experienced errors. */
20648 12 : gcc_assert (errorcount);
20649 :
20650 : /* Throw away the broken statement tree and extra binding
20651 : levels. */
20652 12 : DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
20653 :
20654 27 : while (current_binding_level->kind != sk_function_parms)
20655 : {
20656 15 : if (current_binding_level->kind == sk_class)
20657 0 : pop_nested_class ();
20658 : else
20659 15 : poplevel (0, 0, 0);
20660 : }
20661 : }
20662 165896868 : poplevel (1, 0, 1);
20663 :
20664 : /* Statements should always be full-expressions at the outermost set
20665 : of curly braces for a function. */
20666 165896868 : gcc_assert (stmts_are_full_exprs_p ());
20667 :
20668 : /* If there are no return statements in a function with auto return type,
20669 : the return type is void. But if the declared type is something like
20670 : auto*, this is an error. */
20671 68559834 : if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
20672 166945201 : && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20673 : {
20674 146410 : if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20675 146395 : && !current_function_returns_value
20676 292572 : && !current_function_returns_null)
20677 : {
20678 : /* We haven't applied return type deduction because we haven't
20679 : seen any return statements. Do that now. */
20680 146162 : tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
20681 146162 : do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
20682 : void_node, node, tf_warning_or_error,
20683 : adc_return_type);
20684 :
20685 146162 : apply_deduced_return_type (fndecl, void_type_node);
20686 146162 : fntype = TREE_TYPE (fndecl);
20687 : }
20688 248 : else if (!current_function_returns_value
20689 6 : && !current_function_returns_null)
20690 : {
20691 6 : auto_diagnostic_group d;
20692 12 : error ("no return statements in function returning %qT",
20693 6 : DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
20694 6 : inform (input_location, "only plain %<auto%> return type can be "
20695 : "deduced to %<void%>");
20696 6 : }
20697 : }
20698 :
20699 165896868 : if (FNDECL_USED_AUTO (fndecl)
20700 165896868 : && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20701 1048085 : if (location_t fcloc = failed_completion_location (fndecl))
20702 : {
20703 6 : auto_diagnostic_group adg;
20704 6 : if (warning (OPT_Wsfinae_incomplete_,
20705 : "defining %qD, which previously failed to be deduced "
20706 : "in a SFINAE context", fndecl)
20707 6 : && warn_sfinae_incomplete == 1)
20708 6 : inform (fcloc, "here. Use %qs for a diagnostic at that point",
20709 : "-Wsfinae-incomplete=2");
20710 6 : }
20711 :
20712 : /* Remember that we were in class scope. */
20713 165896868 : if (current_class_name)
20714 127063221 : ctype = current_class_type;
20715 :
20716 165896868 : if (DECL_DELETED_FN (fndecl))
20717 : {
20718 93 : DECL_INITIAL (fndecl) = error_mark_node;
20719 93 : DECL_SAVED_TREE (fndecl) = NULL_TREE;
20720 93 : goto cleanup;
20721 : }
20722 :
20723 165896775 : if (flag_openmp)
20724 325326 : if (tree attr = lookup_attribute ("omp declare variant base",
20725 325326 : DECL_ATTRIBUTES (fndecl)))
20726 267 : omp_declare_variant_finalize (fndecl, attr);
20727 :
20728 : /* Complain if there's just no return statement. */
20729 165896775 : if ((warn_return_type
20730 47205 : || (cxx_dialect >= cxx14
20731 39169 : && DECL_DECLARED_CONSTEXPR_P (fndecl)))
20732 165867423 : && !VOID_TYPE_P (TREE_TYPE (fntype))
20733 104201024 : && !dependent_type_p (TREE_TYPE (fntype))
20734 52755775 : && !current_function_returns_value && !current_function_returns_null
20735 : /* Don't complain if we abort or throw. */
20736 37421 : && !current_function_returns_abnormally
20737 : /* Don't complain if there's an infinite loop. */
20738 953 : && !current_function_infinite_loop
20739 : /* Don't complain if we are declared noreturn. */
20740 885 : && !TREE_THIS_VOLATILE (fndecl)
20741 879 : && !DECL_NAME (DECL_RESULT (fndecl))
20742 879 : && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
20743 : /* Structor return values (if any) are set by the compiler. */
20744 1270 : && !DECL_CONSTRUCTOR_P (fndecl)
20745 635 : && !DECL_DESTRUCTOR_P (fndecl)
20746 165897410 : && targetm.warn_func_return (fndecl))
20747 : {
20748 629 : gcc_rich_location richloc (input_location);
20749 : /* Potentially add a "return *this;" fix-it hint for
20750 : assignment operators. */
20751 629 : if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
20752 : {
20753 39 : tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
20754 39 : if (TREE_CODE (valtype) == REFERENCE_TYPE
20755 32 : && current_class_ref
20756 26 : && same_type_ignoring_top_level_qualifiers_p
20757 26 : (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
20758 71 : && global_dc->option_enabled_p (OPT_Wreturn_type))
20759 18 : add_return_star_this_fixit (&richloc, fndecl);
20760 : }
20761 629 : if (cxx_dialect >= cxx14
20762 629 : && DECL_DECLARED_CONSTEXPR_P (fndecl))
20763 2 : error_at (&richloc, "no return statement in %<constexpr%> function "
20764 : "returning non-void");
20765 627 : else if (warning_at (&richloc, OPT_Wreturn_type,
20766 : "no return statement in function returning "
20767 : "non-void"))
20768 169 : suppress_warning (fndecl, OPT_Wreturn_type);
20769 629 : }
20770 :
20771 : /* Lambda closure members are implicitly constexpr if possible. */
20772 165896775 : if (cxx_dialect >= cxx17
20773 287058228 : && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
20774 1982417 : DECL_DECLARED_CONSTEXPR_P (fndecl)
20775 1982417 : = ((processing_template_decl
20776 641320 : || is_valid_constexpr_fn (fndecl, /*complain*/false))
20777 3963929 : && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
20778 :
20779 : /* Invoke the pre-genericize plugin before we start munging things. */
20780 165896775 : if (!processing_template_decl)
20781 68559741 : invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
20782 :
20783 : /* Fold away non-ODR usages of constants so that we don't need to
20784 : try and stream them in modules if they're internal. */
20785 165896775 : if (!processing_template_decl)
20786 68559741 : cp_fold_function_non_odr_use (fndecl);
20787 :
20788 : /* Save constexpr function body before it gets munged by
20789 : the NRV transformation. */
20790 165896775 : maybe_save_constexpr_fundef (fndecl);
20791 :
20792 : /* Perform delayed folding before NRV transformation. */
20793 165896775 : if (!processing_template_decl
20794 137119482 : && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
20795 233338852 : && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20796 67441634 : cp_fold_function (fndecl);
20797 :
20798 : /* Set up the named return value optimization, if we can. Candidate
20799 : variables are selected in check_return_expr. */
20800 165896775 : if (tree r = current_function_return_value)
20801 : {
20802 43593143 : if (r != error_mark_node)
20803 229304 : finalize_nrv (fndecl, r);
20804 43593143 : current_function_return_value = NULL_TREE;
20805 : }
20806 :
20807 : /* Must mark the RESULT_DECL as being in this function. */
20808 165896775 : DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
20809 :
20810 : /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
20811 : to the FUNCTION_DECL node itself. */
20812 165896775 : BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
20813 :
20814 : /* Store the end of the function, so that we get good line number
20815 : info for the epilogue. */
20816 165896775 : cfun->function_end_locus = input_location;
20817 :
20818 : /* Complain about parameters that are only set, but never otherwise used. */
20819 165896775 : if (warn_unused_but_set_parameter
20820 996960 : && !processing_template_decl
20821 509099 : && errorcount == unused_but_set_errorcount
20822 166405871 : && !DECL_CLONED_FUNCTION_P (fndecl))
20823 : {
20824 397680 : tree decl;
20825 :
20826 397680 : for (decl = DECL_ARGUMENTS (fndecl);
20827 1059709 : decl;
20828 662029 : decl = DECL_CHAIN (decl))
20829 662029 : if (TREE_USED (decl)
20830 549420 : && TREE_CODE (decl) == PARM_DECL
20831 549420 : && !DECL_READ_P (decl)
20832 225 : && DECL_NAME (decl)
20833 225 : && !DECL_ARTIFICIAL (decl)
20834 225 : && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
20835 225 : && !DECL_IN_SYSTEM_HEADER (decl)
20836 225 : && TREE_TYPE (decl) != error_mark_node
20837 225 : && !TYPE_REF_P (TREE_TYPE (decl))
20838 662254 : && (!CLASS_TYPE_P (TREE_TYPE (decl))
20839 0 : || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
20840 225 : warning_at (DECL_SOURCE_LOCATION (decl),
20841 225 : OPT_Wunused_but_set_parameter_,
20842 : "parameter %qD set but not used", decl);
20843 397680 : unused_but_set_errorcount = errorcount;
20844 : }
20845 :
20846 : /* Complain about locally defined typedefs that are not used in this
20847 : function. */
20848 165896775 : maybe_warn_unused_local_typedefs ();
20849 :
20850 : /* Possibly warn about unused parameters. */
20851 165896775 : if (warn_unused_parameter
20852 727574 : && !processing_template_decl
20853 166248474 : && !DECL_CLONED_FUNCTION_P (fndecl))
20854 270133 : do_warn_unused_parameter (fndecl);
20855 :
20856 : /* Genericize before inlining. */
20857 165896775 : if (!processing_template_decl
20858 137119482 : && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
20859 233334410 : && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20860 67437192 : cp_genericize (fndecl);
20861 :
20862 : /* If this function can't throw any exceptions, remember that. */
20863 165896775 : if (!processing_template_decl
20864 68559741 : && !cp_function_chain->can_throw
20865 52285935 : && !flag_non_call_exceptions
20866 52277176 : && !decl_replaceable_p (fndecl,
20867 52277176 : opt_for_fn (fndecl, flag_semantic_interposition))
20868 217928527 : && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
20869 52028972 : TREE_NOTHROW (fndecl) = 1;
20870 :
20871 165896868 : cleanup:
20872 :
20873 : /* We're leaving the context of this function, so zap cfun. It's still in
20874 : DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation. */
20875 165896868 : set_cfun (NULL);
20876 165896868 : current_function_decl = NULL;
20877 :
20878 : /* If this is an in-class inline definition, we may have to pop the
20879 : bindings for the template parameters that we added in
20880 : maybe_begin_member_template_processing when start_function was
20881 : called. */
20882 165896868 : if (inline_p)
20883 85166761 : maybe_end_member_template_processing ();
20884 :
20885 : /* Leave the scope of the class. */
20886 165896868 : if (ctype)
20887 127063221 : pop_nested_class ();
20888 :
20889 165896868 : --function_depth;
20890 :
20891 : /* Clean up. */
20892 165896868 : invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
20893 :
20894 : /* Build outlined functions for coroutines and contracts. */
20895 :
20896 165896868 : if (coroutine)
20897 : {
20898 : /* Emit the resumer and destroyer functions now, providing that we have
20899 : not encountered some fatal error. */
20900 1710 : if (coroutine->cp_valid_coroutine ())
20901 : {
20902 1626 : coroutine->finish_transforms ();
20903 1626 : resumer = coroutine->get_resumer ();
20904 1626 : destroyer = coroutine->get_destroyer ();
20905 1626 : expand_or_defer_fn (resumer);
20906 1626 : expand_or_defer_fn (destroyer);
20907 : }
20908 1710 : delete coroutine;
20909 : }
20910 :
20911 : /* If we have used outlined contracts checking functions, build and emit
20912 : them here. */
20913 165896868 : finish_function_outlined_contracts (fndecl);
20914 :
20915 165896868 : return fndecl;
20916 : }
20917 :
20918 : /* Create the FUNCTION_DECL for a function definition.
20919 : DECLSPECS and DECLARATOR are the parts of the declaration;
20920 : they describe the return type and the name of the function,
20921 : but twisted together in a fashion that parallels the syntax of C.
20922 :
20923 : This function creates a binding context for the function body
20924 : as well as setting up the FUNCTION_DECL in current_function_decl.
20925 :
20926 : Returns a FUNCTION_DECL on success.
20927 :
20928 : If the DECLARATOR is not suitable for a function (it defines a datum
20929 : instead), we return 0, which tells yyparse to report a parse error.
20930 :
20931 : May return void_type_node indicating that this method is actually
20932 : a friend. See grokfield for more details.
20933 :
20934 : Came here with a `.pushlevel' .
20935 :
20936 : DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
20937 : CHANGES TO CODE IN `grokfield'. */
20938 :
20939 : tree
20940 85387492 : grokmethod (cp_decl_specifier_seq *declspecs,
20941 : const cp_declarator *declarator, tree attrlist)
20942 : {
20943 85387492 : tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
20944 85387492 : &attrlist);
20945 :
20946 85387492 : if (fndecl == error_mark_node)
20947 : return error_mark_node;
20948 :
20949 85387387 : if (attrlist)
20950 0 : cplus_decl_attributes (&fndecl, attrlist, 0);
20951 :
20952 : /* Pass friends other than inline friend functions back. */
20953 85387387 : if (fndecl == void_type_node)
20954 : return fndecl;
20955 :
20956 85387387 : if (DECL_IN_AGGR_P (fndecl))
20957 : {
20958 0 : if (DECL_CLASS_SCOPE_P (fndecl))
20959 0 : error ("%qD is already defined in class %qT", fndecl,
20960 0 : DECL_CONTEXT (fndecl));
20961 0 : return error_mark_node;
20962 : }
20963 :
20964 85387387 : check_template_shadow (fndecl);
20965 :
20966 : /* p1779 ABI-Isolation makes inline not a default for in-class
20967 : definitions attached to a named module. If the user explicitly
20968 : made it inline, grokdeclarator will already have done the right
20969 : things. */
20970 85387387 : if ((!named_module_attach_p ()
20971 1034 : || flag_module_implicit_inline
20972 : /* Lambda's operator function remains inline. */
20973 2032 : || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
20974 : /* If the user explicitly asked for this to be inline, we don't
20975 : need to do more, but more importantly we want to warn if we
20976 : can't inline it. */
20977 85386924 : && !DECL_DECLARED_INLINE_P (fndecl))
20978 : {
20979 48203246 : if (TREE_PUBLIC (fndecl))
20980 46001551 : DECL_COMDAT (fndecl) = 1;
20981 48203246 : DECL_DECLARED_INLINE_P (fndecl) = 1;
20982 : /* It's ok if we can't inline this. */
20983 48203246 : DECL_NO_INLINE_WARNING_P (fndecl) = 1;
20984 : }
20985 :
20986 : /* We process method specializations in finish_struct_1. */
20987 85387387 : if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
20988 : {
20989 : /* Avoid calling decl_spec_seq... until we have to. */
20990 68556083 : bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
20991 68556083 : fndecl = push_template_decl (fndecl, friendp);
20992 68556083 : if (fndecl == error_mark_node)
20993 : return fndecl;
20994 : }
20995 :
20996 85387379 : if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
20997 : {
20998 0 : fndecl = copy_node (fndecl);
20999 0 : TREE_CHAIN (fndecl) = NULL_TREE;
21000 : }
21001 :
21002 85387379 : cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
21003 :
21004 85387379 : DECL_IN_AGGR_P (fndecl) = 1;
21005 85387379 : return fndecl;
21006 : }
21007 :
21008 :
21009 : /* VAR is a VAR_DECL. If its type is incomplete, remember VAR so that
21010 : we can lay it out later, when and if its type becomes complete.
21011 :
21012 : Also handle constexpr variables where the initializer involves
21013 : an unlowered PTRMEM_CST because the class isn't complete yet. */
21014 :
21015 : void
21016 105820534 : maybe_register_incomplete_var (tree var)
21017 : {
21018 105820534 : gcc_assert (VAR_P (var));
21019 :
21020 : /* Keep track of variables with incomplete types. */
21021 46512918 : if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
21022 152331638 : && DECL_EXTERNAL (var))
21023 : {
21024 6675419 : tree inner_type = TREE_TYPE (var);
21025 :
21026 6831292 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
21027 155873 : inner_type = TREE_TYPE (inner_type);
21028 6675419 : inner_type = TYPE_MAIN_VARIANT (inner_type);
21029 :
21030 6828617 : if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
21031 : /* RTTI TD entries are created while defining the type_info. */
21032 6675419 : || (TYPE_LANG_SPECIFIC (inner_type)
21033 2365959 : && TYPE_BEING_DEFINED (inner_type)))
21034 : {
21035 153198 : incomplete_var iv = {var, inner_type};
21036 153198 : vec_safe_push (incomplete_vars, iv);
21037 : }
21038 12742944 : else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
21039 3541143 : && DECL_CLASS_SCOPE_P (var)
21040 1100374 : && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
21041 1100374 : && decl_constant_var_p (var)
21042 7227361 : && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
21043 : {
21044 : /* When the outermost open class is complete we can resolve any
21045 : pointers-to-members. */
21046 29 : tree context = outermost_open_class ();
21047 29 : incomplete_var iv = {var, context};
21048 29 : vec_safe_push (incomplete_vars, iv);
21049 : }
21050 : }
21051 105820534 : }
21052 :
21053 : /* Called when a class type (given by TYPE) is defined. If there are
21054 : any existing VAR_DECLs whose type has been completed by this
21055 : declaration, update them now. */
21056 :
21057 : void
21058 72259178 : complete_vars (tree type)
21059 : {
21060 72259178 : unsigned ix;
21061 72259178 : incomplete_var *iv;
21062 :
21063 72928458 : for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
21064 : {
21065 669280 : if (same_type_p (type, iv->incomplete_type))
21066 : {
21067 151998 : tree var = iv->decl;
21068 151998 : tree type = TREE_TYPE (var);
21069 :
21070 151998 : if (type != error_mark_node
21071 151998 : && (TYPE_MAIN_VARIANT (strip_array_types (type))
21072 151995 : == iv->incomplete_type))
21073 : {
21074 : /* Complete the type of the variable. */
21075 151966 : complete_type (type);
21076 151966 : cp_apply_type_quals_to_decl (cp_type_quals (type), var);
21077 151966 : if (COMPLETE_TYPE_P (type))
21078 151951 : layout_var_decl (var);
21079 : }
21080 :
21081 : /* Remove this entry from the list. */
21082 151998 : incomplete_vars->unordered_remove (ix);
21083 : }
21084 : else
21085 517282 : ix++;
21086 : }
21087 72259178 : }
21088 :
21089 : /* If DECL is of a type which needs a cleanup, build and return an
21090 : expression to perform that cleanup here. Return NULL_TREE if no
21091 : cleanup need be done. DECL can also be a _REF when called from
21092 : split_nonconstant_init_1. */
21093 :
21094 : tree
21095 90846392 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
21096 : {
21097 90846392 : tree type;
21098 90846392 : tree attr;
21099 90846392 : tree cleanup;
21100 :
21101 : /* Assume no cleanup is required. */
21102 90846392 : cleanup = NULL_TREE;
21103 :
21104 90846392 : if (!decl || error_operand_p (decl))
21105 : return cleanup;
21106 :
21107 : /* Handle "__attribute__((cleanup))". We run the cleanup function
21108 : before the destructor since the destructor is what actually
21109 : terminates the lifetime of the object. */
21110 90846392 : if (DECL_P (decl))
21111 90520183 : attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
21112 : else
21113 : attr = NULL_TREE;
21114 90520183 : if (attr)
21115 : {
21116 159 : tree id;
21117 159 : tree fn;
21118 159 : tree arg;
21119 :
21120 : /* Get the name specified by the user for the cleanup function. */
21121 159 : id = TREE_VALUE (TREE_VALUE (attr));
21122 : /* Look up the name to find the cleanup function to call. It is
21123 : important to use lookup_name here because that is what is
21124 : used in c-common.cc:handle_cleanup_attribute when performing
21125 : initial checks on the attribute. Note that those checks
21126 : include ensuring that the function found is not an overloaded
21127 : function, or an object with an overloaded call operator,
21128 : etc.; we can rely on the fact that the function found is an
21129 : ordinary FUNCTION_DECL. */
21130 159 : fn = lookup_name (id);
21131 159 : arg = build_address (decl);
21132 159 : if (!mark_used (decl, complain) && !(complain & tf_error))
21133 0 : return error_mark_node;
21134 159 : cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
21135 159 : if (cleanup == error_mark_node)
21136 : return error_mark_node;
21137 : }
21138 : /* Handle ordinary C++ destructors. */
21139 90846380 : type = TREE_TYPE (decl);
21140 90846380 : if (type_build_dtor_call (type))
21141 : {
21142 6854070 : int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
21143 6854070 : tree addr;
21144 6854070 : tree call;
21145 :
21146 6854070 : if (TREE_CODE (type) == ARRAY_TYPE)
21147 : addr = decl;
21148 : else
21149 6849042 : addr = build_address (decl);
21150 :
21151 6854070 : call = build_delete (input_location, TREE_TYPE (addr), addr,
21152 : sfk_complete_destructor, flags, 0, complain);
21153 6854070 : if (call == error_mark_node)
21154 : cleanup = error_mark_node;
21155 6854007 : else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
21156 : /* Discard the call. */;
21157 4173853 : else if (decl_maybe_constant_destruction (decl, type)
21158 4174053 : && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
21159 200 : cxx_constant_dtor (call, decl);
21160 4173653 : else if (cleanup)
21161 3 : cleanup = cp_build_compound_expr (cleanup, call, complain);
21162 : else
21163 : cleanup = call;
21164 : }
21165 :
21166 : /* build_delete sets the location of the destructor call to the
21167 : current location, even though the destructor is going to be
21168 : called later, at the end of the current scope. This can lead to
21169 : a "jumpy" behavior for users of debuggers when they step around
21170 : the end of the block. So let's unset the location of the
21171 : destructor call instead. */
21172 90846380 : protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
21173 90846380 : if (cleanup && CONVERT_EXPR_P (cleanup))
21174 0 : protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
21175 :
21176 0 : if (cleanup
21177 4173860 : && DECL_P (decl)
21178 4173398 : && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
21179 : /* Treat objects with destructors as used; the destructor may do
21180 : something substantive. */
21181 4173392 : && !mark_used (decl, complain) && !(complain & tf_error))
21182 0 : return error_mark_node;
21183 :
21184 4173860 : if (cleanup && cfun && !processing_template_decl
21185 94586456 : && !expr_noexcept_p (cleanup, tf_none))
21186 5502 : cp_function_chain->throwing_cleanup = true;
21187 :
21188 : return cleanup;
21189 : }
21190 :
21191 :
21192 : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
21193 : FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
21194 : METHOD_TYPE or FUNCTION_TYPE, or pointer to member function. */
21195 :
21196 : tree
21197 6014996 : static_fn_type (tree memfntype)
21198 : {
21199 6014996 : tree fntype;
21200 6014996 : tree args;
21201 :
21202 6014996 : if (TYPE_PTRMEMFUNC_P (memfntype))
21203 20721 : memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
21204 6014996 : if (INDIRECT_TYPE_P (memfntype)
21205 5278944 : || TREE_CODE (memfntype) == FUNCTION_DECL)
21206 5843902 : memfntype = TREE_TYPE (memfntype);
21207 6014996 : if (TREE_CODE (memfntype) == FUNCTION_TYPE)
21208 : return memfntype;
21209 608635 : gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
21210 608635 : args = TYPE_ARG_TYPES (memfntype);
21211 608635 : fntype = cp_build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
21212 608635 : fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
21213 608635 : fntype = (cp_build_type_attribute_variant
21214 608635 : (fntype, TYPE_ATTRIBUTES (memfntype)));
21215 608635 : fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
21216 608635 : return fntype;
21217 : }
21218 :
21219 : /* DECL was originally constructed as a non-static member function,
21220 : but turned out to be static. Update it accordingly. */
21221 :
21222 : void
21223 179091 : revert_static_member_fn (tree decl)
21224 : {
21225 179091 : tree stype = static_fn_type (decl);
21226 179091 : cp_cv_quals quals = type_memfn_quals (stype);
21227 179091 : cp_ref_qualifier rqual = type_memfn_rqual (stype);
21228 :
21229 179091 : if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
21230 9 : stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
21231 :
21232 179091 : TREE_TYPE (decl) = stype;
21233 :
21234 179091 : if (DECL_ARGUMENTS (decl))
21235 179091 : DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
21236 179091 : DECL_STATIC_FUNCTION_P (decl) = 1;
21237 179091 : }
21238 :
21239 : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
21240 : one of the language-independent trees. */
21241 :
21242 : enum cp_tree_node_structure_enum
21243 38634311674 : cp_tree_node_structure (union lang_tree_node * t)
21244 : {
21245 38634311674 : switch (TREE_CODE (&t->generic))
21246 : {
21247 : case ARGUMENT_PACK_SELECT: return TS_CP_ARGUMENT_PACK_SELECT;
21248 158648879 : case BASELINK: return TS_CP_BASELINK;
21249 82527438 : case CONSTRAINT_INFO: return TS_CP_CONSTRAINT_INFO;
21250 11618114 : case DEFERRED_NOEXCEPT: return TS_CP_DEFERRED_NOEXCEPT;
21251 6124553 : case DEFERRED_PARSE: return TS_CP_DEFERRED_PARSE;
21252 2074453400 : case IDENTIFIER_NODE: return TS_CP_IDENTIFIER;
21253 3351416 : case LAMBDA_EXPR: return TS_CP_LAMBDA_EXPR;
21254 276179 : case BINDING_VECTOR: return TS_CP_BINDING_VECTOR;
21255 720864638 : case OVERLOAD: return TS_CP_OVERLOAD;
21256 705 : case PTRMEM_CST: return TS_CP_PTRMEM;
21257 16081008 : case STATIC_ASSERT: return TS_CP_STATIC_ASSERT;
21258 679937689 : case TEMPLATE_DECL: return TS_CP_TEMPLATE_DECL;
21259 1582904706 : case TEMPLATE_INFO: return TS_CP_TEMPLATE_INFO;
21260 689281524 : case TEMPLATE_PARM_INDEX: return TS_CP_TPI;
21261 15410867 : case TRAIT_EXPR: return TS_CP_TRAIT_EXPR;
21262 6 : case TU_LOCAL_ENTITY: return TS_CP_TU_LOCAL_ENTITY;
21263 3608589 : case USERDEF_LITERAL: return TS_CP_USERDEF_LITERAL;
21264 14526200 : case REQUIRES_EXPR: return TS_CP_REQUIRES_EXPR;
21265 32574695763 : default: return TS_CP_GENERIC;
21266 : }
21267 : }
21268 :
21269 : bool
21270 9053 : cp_missing_noreturn_ok_p (tree decl)
21271 : {
21272 : /* A missing noreturn is ok for the `main' function. */
21273 9053 : return DECL_MAIN_P (decl);
21274 : }
21275 :
21276 : /* Return the decl used to identify the COMDAT group into which DECL should
21277 : be placed. */
21278 :
21279 : tree
21280 127808156 : cxx_comdat_group (tree decl)
21281 : {
21282 : /* Virtual tables, construction virtual tables, and virtual table
21283 : tables all go in a single COMDAT group, named after the primary
21284 : virtual table. */
21285 127808156 : if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
21286 532775 : decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
21287 : /* For all other DECLs, the COMDAT group is the mangled name of the
21288 : declaration itself. */
21289 : else
21290 : {
21291 127275381 : while (DECL_THUNK_P (decl))
21292 : {
21293 : /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
21294 : into the same section as the target function. In that case
21295 : we must return target's name. */
21296 0 : tree target = THUNK_TARGET (decl);
21297 0 : if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
21298 0 : && DECL_SECTION_NAME (target) != NULL
21299 0 : && DECL_ONE_ONLY (target))
21300 : decl = target;
21301 : else
21302 : break;
21303 : }
21304 : /* If a ctor/dtor has already set the comdat group by
21305 : maybe_clone_body, don't override it. */
21306 127275381 : if (SUPPORTS_ONE_ONLY
21307 127275381 : && TREE_CODE (decl) == FUNCTION_DECL
21308 127275381 : && DECL_CLONED_FUNCTION_P (decl))
21309 18488297 : if (tree comdat = DECL_COMDAT_GROUP (decl))
21310 : return comdat;
21311 : }
21312 :
21313 : return decl;
21314 : }
21315 :
21316 : /* Returns the return type for FN as written by the user, which may include
21317 : a placeholder for a deduced return type. */
21318 :
21319 : tree
21320 559822838 : fndecl_declared_return_type (tree fn)
21321 : {
21322 559822838 : fn = STRIP_TEMPLATE (fn);
21323 559822838 : if (FNDECL_USED_AUTO (fn))
21324 403085 : return DECL_SAVED_AUTO_RETURN_TYPE (fn);
21325 :
21326 559419753 : return TREE_TYPE (TREE_TYPE (fn));
21327 : }
21328 :
21329 : /* Returns true iff DECL is a variable or function declared with an auto type
21330 : that has not yet been deduced to a real type. */
21331 :
21332 : bool
21333 1006624427 : undeduced_auto_decl (tree decl)
21334 : {
21335 1006624427 : if (cxx_dialect < cxx11)
21336 : return false;
21337 1004247400 : STRIP_ANY_LOCATION_WRAPPER (decl);
21338 460576918 : return ((VAR_OR_FUNCTION_DECL_P (decl)
21339 95938239 : || TREE_CODE (decl) == TEMPLATE_DECL)
21340 1369107182 : && type_uses_auto (TREE_TYPE (decl)));
21341 : }
21342 :
21343 : /* Complain if DECL has an undeduced return type. */
21344 :
21345 : bool
21346 332277852 : require_deduced_type (tree decl, tsubst_flags_t complain)
21347 : {
21348 332277852 : if (undeduced_auto_decl (decl))
21349 : {
21350 14996 : if (TREE_CODE (decl) == FUNCTION_DECL
21351 14996 : && fndecl_built_in_p (decl, CP_BUILT_IN_SOURCE_LOCATION,
21352 : BUILT_IN_FRONTEND))
21353 : {
21354 : /* Set the return type of __builtin_source_location. */
21355 10207 : tree type = get_source_location_impl_type ();
21356 10207 : if (type == error_mark_node)
21357 : {
21358 33 : inform (input_location, "using %qs", "__builtin_source_location");
21359 33 : return false;
21360 : }
21361 10174 : type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
21362 10174 : type = build_pointer_type (type);
21363 10174 : apply_deduced_return_type (decl, type);
21364 10174 : return true;
21365 : }
21366 :
21367 4789 : if (TREE_CODE (decl) == FUNCTION_DECL
21368 4789 : && fndecl_built_in_p (decl, CP_BUILT_IN_CURRENT_EXCEPTION,
21369 : BUILT_IN_FRONTEND))
21370 : {
21371 : /* Set the return type of __builtin_current_exception. */
21372 2045 : tree name = get_identifier ("exception_ptr");
21373 2045 : tree eptr = lookup_qualified_name (std_node, name);
21374 2045 : tree fld;
21375 2045 : if (TREE_CODE (eptr) != TYPE_DECL
21376 2045 : || !CLASS_TYPE_P (TREE_TYPE (eptr))
21377 2045 : || !COMPLETE_TYPE_P (TREE_TYPE (eptr))
21378 2045 : || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (eptr))))
21379 2045 : || DECL_ARTIFICIAL (fld)
21380 2045 : || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE
21381 2045 : || next_aggregate_field (DECL_CHAIN (fld))
21382 4090 : || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (eptr)),
21383 2045 : TYPE_SIZE (TREE_TYPE (fld))))
21384 : {
21385 0 : error ("%qs used without %qs declaration",
21386 : "__builtin_current_exception", "std::exception_ptr");
21387 0 : return false;
21388 : }
21389 :
21390 2045 : apply_deduced_return_type (decl, TREE_TYPE (eptr));
21391 2045 : return true;
21392 : }
21393 :
21394 2744 : if (warning_suppressed_p (decl) && seen_error ())
21395 : /* We probably already complained about deduction failure. */;
21396 2565 : else if (complain & tf_error)
21397 74 : error ("use of %qD before deduction of %<auto%>", decl);
21398 2744 : note_failed_type_completion (decl, complain);
21399 2744 : return false;
21400 : }
21401 : return true;
21402 : }
21403 :
21404 : /* Create a representation of the explicit-specifier with
21405 : constant-expression of EXPR. COMPLAIN is as for tsubst. */
21406 :
21407 : tree
21408 8408350 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
21409 : {
21410 8408350 : if (check_for_bare_parameter_packs (expr))
21411 3 : return error_mark_node;
21412 :
21413 8408347 : if (instantiation_dependent_expression_p (expr))
21414 : /* Wait for instantiation, tsubst_function_decl will handle it. */
21415 : return expr;
21416 :
21417 6747633 : expr = build_converted_constant_bool_expr (expr, complain);
21418 6747633 : expr = instantiate_non_dependent_expr (expr, complain);
21419 6747633 : expr = cxx_constant_value (expr, complain);
21420 6747633 : return expr;
21421 : }
21422 :
21423 : #include "gt-cp-decl.h"
|