Line data Source code
1 : /* Process declarations and variables for -*- C++ -*- compiler.
2 : Copyright (C) 1988-2026 Free Software Foundation, Inc.
3 : Contributed by Michael Tiemann (tiemann@cygnus.com)
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3, or (at your option)
10 : any later version.
11 :
12 : GCC is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 :
22 : /* Process declarations and symbol lookup for C++ front end.
23 : Also constructs types; the standard scalar types at initialization,
24 : and structure, union, array and enum types when they are declared. */
25 :
26 : /* ??? not all decl nodes are given the most useful possible
27 : line numbers. For example, the CONST_DECLs for enum values. */
28 :
29 : #include "config.h"
30 : #include "system.h"
31 : #include "coretypes.h"
32 : #include "target.h"
33 : #include "c-family/c-target.h"
34 : #include "cp-tree.h"
35 : #include "timevar.h"
36 : #include "stringpool.h"
37 : #include "cgraph.h"
38 : #include "stor-layout.h"
39 : #include "varasm.h"
40 : #include "attribs.h"
41 : #include "flags.h"
42 : #include "tree-iterator.h"
43 : #include "decl.h"
44 : #include "intl.h"
45 : #include "toplev.h"
46 : #include "c-family/c-objc.h"
47 : #include "c-family/c-pragma.h"
48 : #include "c-family/c-ubsan.h"
49 : #include "cp/cp-name-hint.h"
50 : #include "debug.h"
51 : #include "plugin.h"
52 : #include "builtins.h"
53 : #include "gimplify.h"
54 : #include "asan.h"
55 : #include "gcc-rich-location.h"
56 : #include "langhooks.h"
57 : #include "context.h" /* For 'g'. */
58 : #include "omp-general.h"
59 : #include "omp-offload.h" /* For offload_vars. */
60 : #include "opts.h"
61 : #include "langhooks-def.h" /* For lhd_simulate_record_decl */
62 : #include "coroutines.h"
63 : #include "contracts.h"
64 : #include "gcc-urlifier.h"
65 : #include "diagnostic-highlight-colors.h"
66 : #include "pretty-print-markup.h"
67 :
68 : /* Possible cases of bad specifiers type used by bad_specifiers. */
69 : enum bad_spec_place {
70 : BSP_VAR, /* variable */
71 : BSP_PARM, /* parameter */
72 : BSP_TYPE, /* type */
73 : BSP_FIELD /* field */
74 : };
75 :
76 : static const char *redeclaration_error_message (tree, tree);
77 :
78 : static bool decl_jump_unsafe (tree);
79 : static bool decl_instrument_init_bypass_p (tree);
80 : static void require_complete_types_for_parms (tree);
81 : static tree grok_reference_init (tree, tree, tree, int);
82 : static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
83 : int, int, int, bool, int, tree, location_t);
84 : static void check_static_variable_definition (tree, tree);
85 : static void record_unknown_type (tree, const char *);
86 : static int member_function_or_else (tree, tree, enum overload_flags);
87 : static tree local_variable_p_walkfn (tree *, int *, void *);
88 : static tree lookup_and_check_tag (enum tag_types, tree, TAG_how, bool);
89 : static void maybe_deduce_size_from_array_init (tree, tree);
90 : static void layout_var_decl (tree);
91 : static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
92 : static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
93 : static void copy_type_enum (tree , tree);
94 : static void check_function_type (tree, tree);
95 : static void begin_destructor_body (void);
96 : static void record_key_method_defined (tree);
97 : static tree create_array_type_for_decl (tree, tree, tree, location_t);
98 : static tree get_atexit_node (void);
99 : static tree get_dso_handle_node (void);
100 : static tree start_cleanup_fn (tree, bool, bool);
101 : static void end_cleanup_fn (void);
102 : static tree cp_make_fname_decl (location_t, tree, int);
103 : static void initialize_predefined_identifiers (void);
104 : static tree check_special_function_return_type
105 : (special_function_kind, tree, tree, int, const cp_declarator**,
106 : const location_t*);
107 : static tree push_cp_library_fn (enum tree_code, tree, int);
108 : static tree build_cp_library_fn (tree, enum tree_code, tree, int);
109 : static void store_parm_decls (tree);
110 : static void initialize_local_var (tree, tree, bool);
111 : static void expand_static_init (tree, tree);
112 : static location_t smallest_type_location (const cp_decl_specifier_seq*);
113 : static bool identify_goto (tree, location_t, const location_t *,
114 : enum diagnostics::kind, bool);
115 :
116 : /* The following symbols are subsumed in the cp_global_trees array, and
117 : listed here individually for documentation purposes.
118 :
119 : C++ extensions
120 : tree wchar_decl_node;
121 :
122 : tree vtable_entry_type;
123 : tree delta_type_node;
124 : tree __t_desc_type_node;
125 :
126 : tree class_type_node;
127 : tree unknown_type_node;
128 :
129 : Array type `vtable_entry_type[]'
130 :
131 : tree vtbl_type_node;
132 : tree vtbl_ptr_type_node;
133 :
134 : Namespaces,
135 :
136 : tree std_node;
137 : tree std_meta_node;
138 : tree abi_node;
139 :
140 : A FUNCTION_DECL which can call `abort'. Not necessarily the
141 : one that the user will declare, but sufficient to be called
142 : by routines that want to abort the program.
143 :
144 : tree abort_fndecl;
145 :
146 : Used by RTTI
147 : tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
148 : tree tinfo_var_id; */
149 :
150 : tree cp_global_trees[CPTI_MAX];
151 :
152 : /* A list of objects which have constructors or destructors
153 : which reside in namespace scope. The decl is stored in
154 : the TREE_VALUE slot and the initializer is stored
155 : in the TREE_PURPOSE slot. */
156 : tree static_aggregates;
157 :
158 : /* Like static_aggregates, but for thread_local variables. */
159 : tree tls_aggregates;
160 :
161 : /* A hash-map mapping from variable decls to the dynamic initializer for
162 : the decl. This is currently only used by OpenMP. */
163 : decl_tree_map *dynamic_initializers;
164 :
165 : /* -- end of C++ */
166 :
167 : /* A node for the integer constant 2. */
168 :
169 : tree integer_two_node;
170 :
171 : /* vector of static decls. */
172 : vec<tree, va_gc> *static_decls;
173 :
174 : /* vector of keyed classes. */
175 : vec<tree, va_gc> *keyed_classes;
176 :
177 : /* Used in the direct_goto vector of named_label_use_entry for
178 : addresses of the LABEL_DECLs within GOTO_EXPR or asm goto
179 : for forward jumps. */
180 :
181 : struct GTY(()) named_label_fwd_direct_goto {
182 : tree *GTY((skip)) direct_goto;
183 : };
184 :
185 : /* Used in the direct_goto vector of named_label_use_entry for
186 : addresses of the LABEL_DECLs within GOTO_EXPR or asm goto
187 : for backward jumps. */
188 :
189 : struct GTY(()) named_label_bck_direct_goto {
190 : tree *GTY((skip)) direct_goto;
191 : /* Number of the decl_instrument_init_bypass_p decls in bad_decls vector
192 : at the time this backward goto has been seen. */
193 : unsigned n_bad_decls;
194 : };
195 :
196 : /* Used only for jumps to as-yet undefined labels, since jumps to
197 : defined labels can have their validity checked immediately. */
198 :
199 : struct GTY((chain_next ("%h.next"))) named_label_use_entry {
200 : struct named_label_use_entry *next;
201 : /* The binding level to which this entry is *currently* attached.
202 : This is initially the binding level in which the goto appeared,
203 : but is modified as scopes are closed. */
204 : cp_binding_level *binding_level;
205 : /* The head of the names list that was current when the goto appeared,
206 : or the inner scope popped. These are the decls that will *not* be
207 : skipped when jumping to the label. */
208 : tree names_in_scope;
209 : /* If the use is a possible destination of a computed goto, a vec of decls
210 : that aren't destroyed, filled in by poplevel_named_label_1. */
211 : vec<tree, va_gc> *computed_goto;
212 : /* If the use is a destination of normal goto, a vec of addresses of
213 : LABEL_DECLs that might need changing for !!flag_auto_var_init
214 : forward jumps across vacuous initializers. */
215 : vec<named_label_fwd_direct_goto, va_gc> *direct_goto;
216 : /* The location of the goto, for error reporting. */
217 : location_t o_goto_locus;
218 : /* True if an OpenMP structured block scope has been closed since
219 : the goto appeared. This means that the branch from the label will
220 : illegally exit an OpenMP scope. */
221 : bool in_omp_scope;
222 : };
223 :
224 : /* A list of all LABEL_DECLs in the function that have names. Here so
225 : we can clear out their names' definitions at the end of the
226 : function, and so we can check the validity of jumps to these labels. */
227 :
228 : struct GTY((for_user)) named_label_entry {
229 :
230 : tree name; /* Name of decl. */
231 :
232 : tree label_decl; /* LABEL_DECL, unless deleted local label. */
233 :
234 : named_label_entry *outer; /* Outer shadowed chain. */
235 :
236 : /* The binding level to which the label is *currently* attached.
237 : This is initially set to the binding level in which the label
238 : is defined, but is modified as scopes are closed. */
239 : cp_binding_level *binding_level;
240 :
241 : /* The head of the names list that was current when the label was
242 : defined, or the inner scope popped. These are the decls that will
243 : be skipped when jumping to the label. */
244 : tree names_in_scope;
245 :
246 : /* A vector of all decls from all binding levels that would be
247 : crossed by a backward branch to the label. */
248 : vec<tree, va_gc> *bad_decls;
249 :
250 : /* A list of uses of the label, before the label is defined. */
251 : named_label_use_entry *uses;
252 :
253 : /* If the use is a destination of normal goto, a vec of addresses of
254 : LABEL_DECLs that might need changing for !!flag_auto_var_init
255 : backward jumps across vacuous initializers. */
256 : vec<named_label_bck_direct_goto, va_gc> *direct_goto;
257 :
258 : /* True if we've seen &&label. Apparently we can't use TREE_ADDRESSABLE for
259 : this, it has a more specific meaning for LABEL_DECL. */
260 : bool addressed : 1;
261 :
262 : /* The following bits are set after the label is defined, and are
263 : updated as scopes are popped. They indicate that a jump to the
264 : label will illegally enter a scope of the given flavor. */
265 : bool in_try_scope : 1;
266 : bool in_catch_scope : 1;
267 : bool in_omp_scope : 1;
268 : bool in_transaction_scope : 1;
269 : bool in_constexpr_if : 1;
270 : bool in_consteval_if : 1;
271 : bool in_stmt_expr : 1;
272 :
273 : /* True if bad_decls chain contains any decl_jump_unsafe decls
274 : (rather than just decl_instrument_init_bypass_p). */
275 : bool has_bad_decls : 1;
276 : };
277 :
278 : #define named_labels cp_function_chain->x_named_labels
279 :
280 : /* The number of function bodies which we are currently processing.
281 : (Zero if we are at namespace scope, one inside the body of a
282 : function, two inside the body of a function in a local class, etc.) */
283 : int function_depth;
284 :
285 : /* Whether the exception-specifier is part of a function type (i.e. C++17). */
286 : bool flag_noexcept_type;
287 :
288 : /* States indicating how grokdeclarator() should handle declspecs marked
289 : with __attribute__((deprecated)). An object declared as
290 : __attribute__((deprecated)) suppresses warnings of uses of other
291 : deprecated items. */
292 : enum deprecated_states deprecated_state = DEPRECATED_NORMAL;
293 :
294 :
295 : /* A list of VAR_DECLs whose type was incomplete at the time the
296 : variable was declared. */
297 :
298 : struct GTY(()) incomplete_var {
299 : tree decl;
300 : tree incomplete_type;
301 : };
302 :
303 :
304 : static GTY(()) vec<incomplete_var, va_gc> *incomplete_vars;
305 :
306 : /* Returns the kind of template specialization we are currently
307 : processing, given that it's declaration contained N_CLASS_SCOPES
308 : explicit scope qualifications. */
309 :
310 : tmpl_spec_kind
311 244965214 : current_tmpl_spec_kind (int n_class_scopes)
312 : {
313 244965214 : int n_template_parm_scopes = 0;
314 244965214 : int seen_specialization_p = 0;
315 244965214 : int innermost_specialization_p = 0;
316 244965214 : cp_binding_level *b;
317 :
318 : /* Scan through the template parameter scopes. */
319 244965214 : for (b = current_binding_level;
320 305340617 : b->kind == sk_template_parms;
321 60375403 : 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 60375403 : if (b->explicit_spec_p)
333 : {
334 1397176 : if (n_template_parm_scopes == 0)
335 : innermost_specialization_p = 1;
336 : else
337 1238 : seen_specialization_p = 1;
338 : }
339 58978227 : else if (seen_specialization_p == 1)
340 : return tsk_invalid_member_spec;
341 :
342 60375403 : ++n_template_parm_scopes;
343 : }
344 :
345 : /* Handle explicit instantiations. */
346 244965214 : if (processing_explicit_instantiation)
347 : {
348 1940224 : 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 1940224 : return tsk_expl_inst;
358 : }
359 :
360 243024990 : 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 243024990 : 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 52446297 : 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 103965000 : return innermost_specialization_p ? tsk_expl_spec : tsk_template;
394 : }
395 :
396 : /* Exit the current scope. */
397 :
398 : void
399 95600479 : finish_scope (void)
400 : {
401 95600479 : poplevel (0, 0, 0);
402 95600479 : }
403 :
404 : /* When a label goes out of scope, check to see if that label was used
405 : in a valid manner, and issue any appropriate warnings or errors. */
406 :
407 : static void
408 20670 : check_label_used (tree label)
409 : {
410 20670 : if (!processing_template_decl)
411 : {
412 20361 : if (DECL_INITIAL (label) == NULL_TREE)
413 : {
414 9 : location_t location;
415 :
416 9 : error ("label %q+D used but not defined", label);
417 9 : location = input_location;
418 : /* FIXME want (LOCATION_FILE (input_location), (line)0) */
419 : /* Avoid crashing later. */
420 9 : define_label (location, DECL_NAME (label));
421 : }
422 : else
423 20352 : warn_for_unused_label (label);
424 : }
425 20670 : }
426 :
427 : /* Helper function to sort named label entries in a vector by DECL_UID. */
428 :
429 : static int
430 232680 : sort_labels (const void *a, const void *b)
431 : {
432 232680 : tree label1 = *(tree const *) a;
433 232680 : tree label2 = *(tree const *) b;
434 :
435 : /* DECL_UIDs can never be equal. */
436 232680 : return DECL_UID (label1) > DECL_UID (label2) ? -1 : +1;
437 : }
438 :
439 : static void adjust_backward_goto (named_label_entry *, tree_stmt_iterator);
440 : static named_label_entry *lookup_label_1 (tree, bool);
441 :
442 : /* Helper of pop_labels, called through cp_walk_tree. Adjust
443 : LABEL_EXPRs of named labels, if they are targets of backwards
444 : gotos jumping across vacuous initialization for
445 : !!flag_auto_var_init. */
446 :
447 : static tree
448 2909 : adjust_backward_gotos (tree *tp, int *walk_subtrees, void *data)
449 : {
450 2909 : tree t = *tp;
451 2909 : switch (TREE_CODE (t))
452 : {
453 3 : case LABEL_EXPR:
454 : /* In rare cases LABEL_EXPR can appear as the only substatement
455 : of some other statement, e.g. if body etc. In that case, we know
456 : there can't be an older if (0) wrapper with artificial initializers
457 : before it. Replace the LABEL_EXPR statement with a STATEMENT_LIST
458 : and insert the LABEL_EXPR into it, later on if (0) will be added
459 : before that. */
460 3 : if (DECL_NAME (LABEL_EXPR_LABEL (t)))
461 : {
462 3 : named_label_entry *ent
463 3 : = lookup_label_1 (DECL_NAME (LABEL_EXPR_LABEL (t)), false);
464 3 : if (ent->direct_goto)
465 : {
466 3 : *tp = alloc_stmt_list ();
467 3 : append_to_statement_list_force (t, tp);
468 3 : adjust_backward_goto (ent, tsi_last (*tp));
469 : }
470 : }
471 3 : *walk_subtrees = 0;
472 3 : break;
473 141 : case STATEMENT_LIST:
474 141 : {
475 141 : tree_stmt_iterator i;
476 141 : *walk_subtrees = 0;
477 : /* In the common case, LABEL_EXPRs appear inside of a STATEMENT_LIST.
478 : In that case pass the stmt iterator to adjust_backward_goto, so
479 : that it can insert if (0) wrapper artificial initializers before
480 : it or reuse the existing ones. */
481 915 : for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
482 774 : if (TREE_CODE (tsi_stmt (i)) != LABEL_EXPR)
483 737 : cp_walk_tree (tsi_stmt_ptr (i), adjust_backward_gotos,
484 : data, (hash_set<tree> *) data);
485 37 : else if (DECL_NAME (LABEL_EXPR_LABEL (tsi_stmt (i))))
486 : {
487 16 : named_label_entry *ent
488 16 : = lookup_label_1 (DECL_NAME (LABEL_EXPR_LABEL (tsi_stmt (i))),
489 : false);
490 16 : if (ent->direct_goto)
491 16 : adjust_backward_goto (ent, i);
492 : }
493 141 : break;
494 : }
495 2765 : default:
496 2765 : if (TYPE_P (t))
497 4 : *walk_subtrees = 0;
498 : }
499 2909 : return NULL_TREE;
500 : }
501 :
502 : /* At the end of a function, all labels declared within the function
503 : go out of scope. BLOCK is the top-level block for the
504 : function. */
505 :
506 : static void
507 157955125 : pop_labels (tree block)
508 : {
509 157955125 : if (!named_labels)
510 157950486 : return;
511 :
512 : /* We need to add the labels to the block chain, so debug
513 : information is emitted. But, we want the order to be stable so
514 : need to sort them first. Otherwise the debug output could be
515 : randomly ordered. I guess it's mostly stable, unless the hash
516 : table implementation changes. */
517 4639 : auto_vec<tree, 32> labels (named_labels->elements ());
518 4639 : hash_table<named_label_hash>::iterator end (named_labels->end ());
519 :
520 4639 : if (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
521 687 : && !processing_template_decl)
522 : {
523 6158 : for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
524 : {
525 2426 : named_label_entry *ent = *iter;
526 2426 : if (ent->direct_goto)
527 : {
528 4 : hash_set<tree> pset;
529 4 : cp_walk_tree (&DECL_SAVED_TREE (current_function_decl),
530 : adjust_backward_gotos, &pset, &pset);
531 4 : break;
532 4 : }
533 : }
534 : }
535 :
536 45913 : for (decltype (end) iter (named_labels->begin ()); iter != end; ++iter)
537 : {
538 20637 : named_label_entry *ent = *iter;
539 :
540 20637 : gcc_checking_assert (!ent->outer);
541 20637 : if (ent->label_decl)
542 20451 : labels.quick_push (ent->label_decl);
543 20637 : ggc_free (ent);
544 : }
545 4639 : named_labels = NULL;
546 4639 : labels.qsort (sort_labels);
547 :
548 25090 : while (labels.length ())
549 : {
550 20451 : tree label = labels.pop ();
551 :
552 20451 : DECL_CHAIN (label) = BLOCK_VARS (block);
553 20451 : BLOCK_VARS (block) = label;
554 :
555 20451 : check_label_used (label);
556 : }
557 4639 : }
558 :
559 : /* At the end of a block with local labels, restore the outer definition. */
560 :
561 : static void
562 219 : pop_local_label (tree id, tree label)
563 : {
564 219 : check_label_used (label);
565 219 : named_label_entry **slot = named_labels->find_slot_with_hash
566 219 : (id, IDENTIFIER_HASH_VALUE (id), NO_INSERT);
567 219 : named_label_entry *ent = *slot;
568 :
569 219 : if (ent->outer)
570 : ent = ent->outer;
571 : else
572 : {
573 198 : ent = ggc_cleared_alloc<named_label_entry> ();
574 198 : ent->name = id;
575 : }
576 219 : *slot = ent;
577 219 : }
578 :
579 : /* The following two routines are used to interface to Objective-C++.
580 : The binding level is purposely treated as an opaque type. */
581 :
582 : void *
583 0 : objc_get_current_scope (void)
584 : {
585 0 : return current_binding_level;
586 : }
587 :
588 : /* The following routine is used by the NeXT-style SJLJ exceptions;
589 : variables get marked 'volatile' so as to not be clobbered by
590 : _setjmp()/_longjmp() calls. All variables in the current scope,
591 : as well as parent scopes up to (but not including) ENCLOSING_BLK
592 : shall be thusly marked. */
593 :
594 : void
595 0 : objc_mark_locals_volatile (void *enclosing_blk)
596 : {
597 0 : cp_binding_level *scope;
598 :
599 0 : for (scope = current_binding_level;
600 0 : scope && scope != enclosing_blk;
601 0 : scope = scope->level_chain)
602 : {
603 0 : tree decl;
604 :
605 0 : for (decl = scope->names; decl; decl = TREE_CHAIN (decl))
606 0 : objc_volatilize_decl (decl);
607 :
608 : /* Do not climb up past the current function. */
609 0 : if (scope->kind == sk_function_parms)
610 : break;
611 : }
612 0 : }
613 :
614 : /* True if B is the level for the condition of a constexpr if. */
615 :
616 : static bool
617 1426053 : level_for_constexpr_if (cp_binding_level *b)
618 : {
619 1421991 : return (b->kind == sk_cond && b->this_entity
620 292 : && TREE_CODE (b->this_entity) == IF_STMT
621 1426345 : && 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 1426029 : level_for_consteval_if (cp_binding_level *b)
628 : {
629 1421967 : return (b->kind == sk_cond && b->this_entity
630 268 : && TREE_CODE (b->this_entity) == IF_STMT
631 1426297 : && IF_STMT_CONSTEVAL_P (b->this_entity));
632 : }
633 :
634 : /* True if T is a non-static VAR_DECL that has a non-trivial destructor.
635 : See [stmt.dcl]/2. */
636 :
637 : static bool
638 25 : automatic_var_with_nontrivial_dtor_p (const_tree t)
639 : {
640 25 : if (error_operand_p (t))
641 : return false;
642 :
643 19 : return (VAR_P (t)
644 19 : && decl_storage_duration (const_cast<tree> (t)) == dk_auto
645 38 : && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (t)));
646 : }
647 :
648 : /* Update data for defined and undefined labels when leaving a scope. */
649 :
650 : int
651 155078 : poplevel_named_label_1 (named_label_entry **slot, cp_binding_level *bl)
652 : {
653 155078 : named_label_entry *ent = *slot;
654 155078 : cp_binding_level *obl = bl->level_chain;
655 :
656 155078 : if (ent->binding_level == bl)
657 : {
658 10178 : tree decl;
659 :
660 : /* ENT->NAMES_IN_SCOPE may contain a mixture of DECLs and
661 : TREE_LISTs representing OVERLOADs, so be careful. */
662 15074 : for (decl = ent->names_in_scope; decl; decl = (DECL_P (decl)
663 4969 : ? DECL_CHAIN (decl)
664 73 : : TREE_CHAIN (decl)))
665 4896 : if (decl_jump_unsafe (decl))
666 : {
667 1872 : vec_safe_push (ent->bad_decls, decl);
668 1872 : ent->has_bad_decls = true;
669 : }
670 3024 : else if (decl_instrument_init_bypass_p (decl))
671 435 : vec_safe_push (ent->bad_decls, decl);
672 :
673 10178 : ent->binding_level = obl;
674 10178 : ent->names_in_scope = obl->names;
675 10178 : switch (bl->kind)
676 : {
677 42 : case sk_try:
678 42 : ent->in_try_scope = true;
679 42 : break;
680 27 : case sk_catch:
681 27 : ent->in_catch_scope = true;
682 27 : break;
683 324 : case sk_omp:
684 324 : ent->in_omp_scope = true;
685 324 : break;
686 3 : case sk_transaction:
687 3 : ent->in_transaction_scope = true;
688 3 : break;
689 45 : case sk_stmt_expr:
690 45 : ent->in_stmt_expr = true;
691 45 : break;
692 4100 : case sk_block:
693 4100 : if (level_for_constexpr_if (obl))
694 15 : ent->in_constexpr_if = true;
695 4085 : else if (level_for_consteval_if (obl))
696 30 : ent->in_consteval_if = true;
697 : break;
698 : default:
699 : break;
700 : }
701 : }
702 144900 : else if (ent->uses)
703 : {
704 : struct named_label_use_entry *use;
705 :
706 22845 : for (use = ent->uses; use ; use = use->next)
707 15527 : if (use->binding_level == bl)
708 : {
709 5981 : if (auto &cg = use->computed_goto)
710 : {
711 57 : if (bl->kind == sk_catch)
712 3 : vec_safe_push (cg, get_identifier ("catch"));
713 66 : for (tree d = use->names_in_scope; d; d = DECL_CHAIN (d))
714 9 : if (automatic_var_with_nontrivial_dtor_p (d))
715 6 : vec_safe_push (cg, d);
716 : }
717 :
718 5981 : use->binding_level = obl;
719 5981 : use->names_in_scope = obl->names;
720 5981 : if (bl->kind == sk_omp)
721 12 : use->in_omp_scope = true;
722 : }
723 : }
724 :
725 155078 : return 1;
726 : }
727 :
728 : /* Saved errorcount to avoid -Wunused-but-set-{parameter,variable} warnings
729 : when errors were reported, except for -Werror-unused-but-set-*. */
730 : static int unused_but_set_errorcount;
731 :
732 : /* Exit a binding level.
733 : Pop the level off, and restore the state of the identifier-decl mappings
734 : that were in effect when this level was entered.
735 :
736 : If KEEP == 1, this level had explicit declarations, so
737 : and create a "block" (a BLOCK node) for the level
738 : to record its declarations and subblocks for symbol table output.
739 :
740 : If FUNCTIONBODY is nonzero, this level is the body of a function,
741 : so create a block as if KEEP were set and also clear out all
742 : label names.
743 :
744 : If REVERSE is nonzero, reverse the order of decls before putting
745 : them into the BLOCK. */
746 :
747 : tree
748 661892426 : poplevel (int keep, int reverse, int functionbody)
749 : {
750 661892426 : tree link;
751 : /* The chain of decls was accumulated in reverse order.
752 : Put it into forward order, just for cleanliness. */
753 661892426 : tree decls;
754 661892426 : tree subblocks;
755 661892426 : tree block;
756 661892426 : tree decl;
757 661892426 : scope_kind kind;
758 :
759 661892426 : auto_cond_timevar tv (TV_NAME_LOOKUP);
760 661892804 : restart:
761 :
762 661892804 : block = NULL_TREE;
763 :
764 661892804 : gcc_assert (current_binding_level->kind != sk_class
765 : && current_binding_level->kind != sk_namespace);
766 :
767 661892804 : if (current_binding_level->kind == sk_cleanup)
768 : functionbody = 0;
769 661892804 : subblocks = functionbody >= 0 ? current_binding_level->blocks : 0;
770 :
771 661892804 : 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 661892804 : gcc_assert (keep == 0 || keep == 1);
777 :
778 661892804 : if (current_binding_level->keep)
779 8135513 : keep = 1;
780 :
781 : /* Any uses of undefined labels, and any defined labels, now operate
782 : under constraints of next binding contour. */
783 661892804 : if (cfun && !functionbody && named_labels)
784 43502 : named_labels->traverse<cp_binding_level *, poplevel_named_label_1>
785 198580 : (current_binding_level);
786 :
787 : /* Get the decls in the order they were written.
788 : Usually current_binding_level->names is in reverse order.
789 : But parameter decls were previously put in forward order. */
790 :
791 661892804 : decls = current_binding_level->names;
792 661892804 : if (reverse)
793 : {
794 362897690 : decls = nreverse (decls);
795 362897690 : 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 661892804 : block = NULL_TREE;
802 : /* Avoid function body block if possible. */
803 702186671 : if (functionbody && subblocks && BLOCK_CHAIN (subblocks) == NULL_TREE)
804 : keep = 0;
805 621599198 : else if (keep == 1 || functionbody)
806 198925350 : block = make_node (BLOCK);
807 198925350 : if (block != NULL_TREE)
808 : {
809 198925350 : BLOCK_VARS (block) = decls;
810 198925350 : BLOCK_SUBBLOCKS (block) = subblocks;
811 : }
812 :
813 : /* In each subblock, record that this is its superior. */
814 661892804 : if (keep >= 0)
815 743155911 : for (link = subblocks; link; link = BLOCK_CHAIN (link))
816 81263107 : BLOCK_SUPERCONTEXT (link) = block;
817 :
818 : /* Before we remove the declarations first check for unused variables. */
819 661892804 : if ((warn_unused_variable || warn_unused_but_set_variable)
820 6713406 : && current_binding_level->kind != sk_template_parms
821 5653524 : && !processing_template_decl)
822 6466844 : 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 3278681 : tree udecl = TREE_CODE (d) == TREE_LIST ? TREE_VALUE (d) : d;
828 3278681 : decl = strip_using_decl (udecl);
829 :
830 3278681 : tree type = TREE_TYPE (decl);
831 3278681 : if (VAR_P (decl)
832 383996 : && (!TREE_USED (decl) || !DECL_READ_P (decl))
833 3451 : && !DECL_IN_SYSTEM_HEADER (udecl)
834 : /* For structured bindings, consider only real variables, not
835 : subobjects. */
836 3439 : && (DECL_DECOMPOSITION_P (decl) ? DECL_DECOMP_IS_BASE (decl)
837 3216 : : (DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)))
838 : /* Don't warn about name-independent declarations. */
839 896 : && !name_independent_decl_p (decl)
840 740 : && type != error_mark_node
841 3282826 : && (!CLASS_TYPE_P (type)
842 51 : || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
843 3 : || lookup_attribute ("warn_unused",
844 3 : TYPE_ATTRIBUTES (TREE_TYPE (decl)))))
845 : {
846 706 : if (!TREE_USED (decl))
847 : {
848 308 : if (TREE_CODE (udecl) == USING_DECL)
849 3 : warning_at (DECL_SOURCE_LOCATION (udecl),
850 3 : OPT_Wunused_variable,
851 : "unused using-declaration %qD", udecl);
852 305 : else if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
853 3 : warning_at (DECL_SOURCE_LOCATION (decl),
854 3 : OPT_Wunused_variable,
855 : "unused structured binding declaration");
856 : else
857 302 : warning_at (DECL_SOURCE_LOCATION (decl),
858 302 : OPT_Wunused_variable, "unused variable %qD", decl);
859 308 : suppress_warning (decl, OPT_Wunused_variable);
860 : }
861 398 : else if (DECL_CONTEXT (decl) == current_function_decl
862 : // For -Wunused-but-set-variable leave references alone.
863 374 : && !TYPE_REF_P (TREE_TYPE (decl))
864 772 : && errorcount == unused_but_set_errorcount)
865 : {
866 365 : if (!DECL_NAME (decl) && DECL_DECOMPOSITION_P (decl))
867 12 : warning_at (DECL_SOURCE_LOCATION (decl),
868 12 : OPT_Wunused_but_set_variable_, "structured "
869 : "binding declaration set but not used");
870 : else
871 353 : warning_at (DECL_SOURCE_LOCATION (decl),
872 353 : OPT_Wunused_but_set_variable_,
873 : "variable %qD set but not used", decl);
874 365 : unused_but_set_errorcount = errorcount;
875 : }
876 : }
877 : }
878 :
879 : /* Remove declarations for all the DECLs in this level. */
880 1339964436 : for (link = decls; link; link = TREE_CHAIN (link))
881 : {
882 678071632 : tree name;
883 678071632 : if (TREE_CODE (link) == TREE_LIST)
884 : {
885 12999100 : decl = TREE_VALUE (link);
886 12999100 : name = TREE_PURPOSE (link);
887 12999100 : gcc_checking_assert (name);
888 : }
889 : else
890 : {
891 665072532 : decl = link;
892 665072532 : name = DECL_NAME (decl);
893 : }
894 :
895 : /* Remove the binding. */
896 678071632 : if (TREE_CODE (decl) == LABEL_DECL)
897 219 : pop_local_label (name, decl);
898 : else
899 678071413 : pop_local_binding (name, decl);
900 : }
901 :
902 : /* Restore the IDENTIFIER_TYPE_VALUEs. */
903 661892804 : for (link = current_binding_level->type_shadowed;
904 903113370 : link; link = TREE_CHAIN (link))
905 241220566 : 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 661892804 : if (block)
915 : {
916 198925350 : tree* d;
917 :
918 524790982 : for (d = &BLOCK_VARS (block); *d; )
919 : {
920 325865632 : if (TREE_CODE (*d) == TREE_LIST
921 325865632 : || (!processing_template_decl
922 103109269 : && undeduced_auto_decl (*d)))
923 12999152 : *d = TREE_CHAIN (*d);
924 : else
925 312866480 : 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 661892804 : if (functionbody)
932 : {
933 157955125 : 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 117661519 : BLOCK_VARS (block) = 0;
939 117661519 : pop_labels (block);
940 : }
941 : else
942 40293606 : pop_labels (subblocks);
943 : }
944 :
945 661892804 : kind = current_binding_level->kind;
946 661892804 : if (kind == sk_cleanup)
947 : {
948 378 : 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 378 : stmt = pop_stmt_list (current_binding_level->statement_list);
954 378 : stmt = c_build_bind_expr (input_location, block, stmt);
955 378 : add_stmt (stmt);
956 : }
957 :
958 661892804 : leave_scope ();
959 661892804 : if (functionbody)
960 : {
961 : /* The current function is being defined, so its DECL_INITIAL
962 : should be error_mark_node. */
963 157955125 : gcc_assert (DECL_INITIAL (current_function_decl) == error_mark_node);
964 198248731 : DECL_INITIAL (current_function_decl) = block ? block : subblocks;
965 157955125 : if (subblocks)
966 : {
967 76537272 : if (FUNCTION_NEEDS_BODY_BLOCK (current_function_decl)
968 49917465 : && BLOCK_SUBBLOCKS (subblocks))
969 1255308 : BLOCK_OUTER_CURLY_BRACE_P (BLOCK_SUBBLOCKS (subblocks)) = 1;
970 : else
971 39038559 : BLOCK_OUTER_CURLY_BRACE_P (subblocks) = 1;
972 : }
973 : }
974 503937679 : else if (block)
975 81263831 : current_binding_level->blocks
976 162527662 : = 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 422673848 : 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 661892804 : if (block)
991 198925350 : TREE_USED (block) = 1;
992 :
993 : /* All temporary bindings created for cleanups are popped silently. */
994 661892804 : if (kind == sk_cleanup)
995 378 : goto restart;
996 :
997 1323784852 : return block;
998 661892426 : }
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 141973 : wrapup_namespace_globals ()
1006 : {
1007 141973 : if (vec<tree, va_gc> *statics = static_decls)
1008 : {
1009 17267835 : for (tree decl : *statics)
1010 : {
1011 17151230 : if (warn_unused_function
1012 998137 : && TREE_CODE (decl) == FUNCTION_DECL
1013 748888 : && DECL_INITIAL (decl) == 0
1014 7583 : && DECL_EXTERNAL (decl)
1015 7571 : && !TREE_PUBLIC (decl)
1016 32 : && !DECL_ARTIFICIAL (decl)
1017 32 : && !DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl)
1018 9 : && !warning_suppressed_p (decl, OPT_Wunused)
1019 18149367 : && 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 17151230 : if (VAR_P (decl)
1025 5744073 : && 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 1987635 : && !DECL_INITIAL (decl)
1030 1986998 : && DECL_INLINE_VAR_P (decl)
1031 17151258 : && 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 116605 : static_decls = NULL;
1038 :
1039 : /* Write out any globals that need to be output. */
1040 116605 : return wrapup_global_declarations (statics->address (),
1041 116605 : 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 179106253 : create_implicit_typedef (tree name, tree type)
1053 : {
1054 179106253 : tree decl;
1055 :
1056 179106253 : decl = build_decl (input_location, TYPE_DECL, name, type);
1057 179106253 : 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 179106253 : SET_DECL_IMPLICIT_TYPEDEF_P (decl);
1062 179106253 : TYPE_NAME (type) = decl;
1063 179106253 : TYPE_STUB_DECL (type) = decl;
1064 :
1065 179106253 : 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 710570 : determine_local_discriminator (tree decl, tree name)
1079 : {
1080 710570 : auto_cond_timevar tv (TV_NAME_LOOKUP);
1081 710570 : retrofit_lang_decl (decl);
1082 710570 : tree ctx = DECL_CONTEXT (decl);
1083 710570 : size_t nelts = vec_safe_length (local_entities);
1084 710570 : if (name == NULL_TREE)
1085 710307 : name = (TREE_CODE (decl) == TYPE_DECL
1086 1153028 : && TYPE_UNNAMED_P (TREE_TYPE (decl))
1087 1282786 : ? NULL_TREE : DECL_NAME (decl));
1088 20844411 : for (size_t i = 0; i < nelts; i += 2)
1089 : {
1090 20134318 : tree *pair = &(*local_entities)[i];
1091 20134318 : tree d = pair[0];
1092 20134318 : tree n = pair[1];
1093 20134318 : gcc_checking_assert (d != decl);
1094 20134318 : if (name == n
1095 3532663 : && TREE_CODE (decl) == TREE_CODE (d)
1096 23666972 : && ctx == DECL_CONTEXT (d))
1097 : {
1098 477 : tree disc = integer_one_node;
1099 477 : if (DECL_DISCRIMINATOR (d))
1100 250 : disc = build_int_cst (TREE_TYPE (disc),
1101 250 : TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
1102 477 : DECL_DISCRIMINATOR (decl) = disc;
1103 : /* Replace the saved decl. */
1104 477 : pair[0] = decl;
1105 477 : decl = NULL_TREE;
1106 477 : break;
1107 : }
1108 : }
1109 :
1110 710570 : if (decl)
1111 : {
1112 710093 : vec_safe_reserve (local_entities, 2);
1113 710093 : local_entities->quick_push (decl);
1114 710093 : local_entities->quick_push (name);
1115 : }
1116 710570 : }
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 2416319576 : member_like_constrained_friend_p (tree decl)
1133 : {
1134 2416319576 : return (TREE_CODE (decl) == FUNCTION_DECL
1135 798755207 : && DECL_UNIQUE_FRIEND_P (decl)
1136 191472802 : && DECL_FRIEND_CONTEXT (decl)
1137 78701919 : && get_constraints (decl)
1138 6151350 : && CLASSTYPE_IMPLICIT_INSTANTIATION (DECL_FRIEND_CONTEXT (decl))
1139 2419388016 : && (!DECL_TEMPLATE_INFO (decl)
1140 3068440 : || !PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl))
1141 6415 : || (uses_outer_template_parms_in_constraints
1142 6415 : (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 69010826 : 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 69010826 : if (member_like_constrained_friend_p (newfn)
1155 69010826 : || member_like_constrained_friend_p (oldfn))
1156 97 : return false;
1157 :
1158 : /* Compare only trailing requirements. */
1159 69010729 : tree reqs1 = get_trailing_function_requirements (newfn);
1160 69010729 : tree reqs2 = get_trailing_function_requirements (oldfn);
1161 69010729 : if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
1162 : return false;
1163 :
1164 : /* Substitution is needed when friends are involved. */
1165 68887456 : reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
1166 68887456 : reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
1167 :
1168 68887456 : 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 1520324982 : fns_correspond (tree newdecl, tree olddecl)
1188 : {
1189 1520324982 : if (TREE_CODE (newdecl) != TREE_CODE (olddecl))
1190 : return false;
1191 :
1192 1410857738 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1193 : {
1194 1409502207 : if (!template_heads_equivalent_p (newdecl, olddecl))
1195 : return 0;
1196 336091248 : newdecl = DECL_TEMPLATE_RESULT (newdecl);
1197 336091248 : olddecl = DECL_TEMPLATE_RESULT (olddecl);
1198 : }
1199 :
1200 337446779 : tree f1 = TREE_TYPE (newdecl);
1201 337446779 : tree f2 = TREE_TYPE (olddecl);
1202 :
1203 337446779 : int rq1 = type_memfn_rqual (f1);
1204 337446779 : int rq2 = type_memfn_rqual (f2);
1205 :
1206 : /* If only one is a non-static member function, ignore ref-quals. */
1207 337446779 : 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 337446779 : else if ((rq1 == REF_QUAL_NONE) != (rq2 == REF_QUAL_NONE))
1217 0 : rq1 = rq2;
1218 :
1219 337446779 : bool types_match = rq1 == rq2;
1220 :
1221 337446779 : if (types_match)
1222 : {
1223 337446779 : tree p1 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1224 337446779 : tree p2 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
1225 337446779 : 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 337446779 : if (types_match && flag_concepts)
1232 41229869 : 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 800880641 : decls_match (tree newdecl, tree olddecl, bool record_versions /* = true */)
1246 : {
1247 800880641 : int types_match;
1248 :
1249 800880641 : if (newdecl == olddecl)
1250 : return 1;
1251 :
1252 800788802 : 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 411287094 : gcc_assert (DECL_P (newdecl));
1258 :
1259 411287094 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
1260 : {
1261 : /* Specializations of different templates are different functions
1262 : even if they have the same type. */
1263 262617243 : tree t1 = (DECL_USE_TEMPLATE (newdecl)
1264 262617243 : ? DECL_TI_TEMPLATE (newdecl)
1265 629546 : : NULL_TREE);
1266 262617243 : tree t2 = (DECL_USE_TEMPLATE (olddecl)
1267 262617243 : ? DECL_TI_TEMPLATE (olddecl)
1268 3940912 : : NULL_TREE);
1269 262617243 : if (t1 != t2)
1270 : return 0;
1271 :
1272 259305807 : if (CP_DECL_CONTEXT (newdecl) != CP_DECL_CONTEXT (olddecl)
1273 262204583 : && ! (DECL_EXTERN_C_P (newdecl)
1274 2898776 : && 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 238465687 : if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
1280 238465687 : && DECL_EXTERN_C_P (olddecl) && !DECL_EXTERN_C_P (newdecl))
1281 : return 0;
1282 :
1283 237825919 : tree f1 = TREE_TYPE (newdecl);
1284 237825919 : tree f2 = TREE_TYPE (olddecl);
1285 237825919 : 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 237657494 : tree r2 = fndecl_declared_return_type (olddecl);
1291 237657494 : 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 237657494 : if (DECL_IS_UNDECLARED_BUILTIN (olddecl)
1296 6353088 : && DECL_EXTERN_C_P (olddecl)
1297 3931945 : && !same_type_p (r1, r2)
1298 70 : && TREE_CODE (r1) == POINTER_TYPE
1299 15 : && TREE_CODE (r2) == POINTER_TYPE
1300 237657506 : && comp_ptr_ttypes (TREE_TYPE (r1), TREE_TYPE (r2)))
1301 : r2 = r1;
1302 :
1303 237657494 : tree p1 = TYPE_ARG_TYPES (f1);
1304 237657494 : tree p2 = TYPE_ARG_TYPES (f2);
1305 :
1306 237657494 : if (same_type_p (r1, r2))
1307 : {
1308 163393592 : if (!prototype_p (f2) && DECL_EXTERN_C_P (olddecl)
1309 163393564 : && 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 163393458 : types_match =
1317 163393458 : compparms (p1, p2)
1318 28273645 : && type_memfn_rqual (f1) == type_memfn_rqual (f2)
1319 191666805 : && (TYPE_ATTRIBUTES (TREE_TYPE (newdecl)) == NULL_TREE
1320 1199042 : || comp_type_attributes (TREE_TYPE (newdecl),
1321 1199042 : 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 28273376 : if (types_match && flag_concepts)
1330 27780928 : 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 28273376 : if (types_match
1336 28087129 : && !DECL_EXTERN_C_P (newdecl)
1337 20481290 : && !DECL_EXTERN_C_P (olddecl)
1338 48750770 : && disjoint_version_decls (newdecl, olddecl))
1339 : {
1340 8868 : if (record_versions)
1341 8781 : maybe_version_functions (newdecl, olddecl);
1342 8868 : return 0;
1343 : }
1344 : }
1345 148669851 : else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1346 : {
1347 146963057 : if (!template_heads_equivalent_p (newdecl, olddecl))
1348 : return 0;
1349 :
1350 48416199 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1351 48416199 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
1352 :
1353 48416199 : 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 48416193 : if (TREE_CODE (newres) == TYPE_DECL)
1359 30 : types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
1360 : else
1361 48416163 : 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 1706794 : if (VAR_P (newdecl)
1368 1167139 : && 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 1892362 : && !(DECL_EXTERN_C_P (olddecl) && DECL_EXTERN_C_P (newdecl)))
1375 : return 0;
1376 :
1377 1521274 : if (TREE_TYPE (newdecl) == error_mark_node)
1378 0 : types_match = TREE_TYPE (olddecl) == error_mark_node;
1379 1521274 : else if (TREE_TYPE (olddecl) == NULL_TREE)
1380 0 : types_match = TREE_TYPE (newdecl) == NULL_TREE;
1381 1521274 : else if (TREE_TYPE (newdecl) == NULL_TREE)
1382 : types_match = 0;
1383 : else
1384 1521274 : types_match = comptypes (TREE_TYPE (newdecl),
1385 1521274 : 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 17652 : maybe_mark_function_versioned (tree decl)
1396 : {
1397 17652 : 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 1065 : cgraph_node *node = cgraph_node::get_create (decl);
1402 :
1403 1065 : if (!node->function_version ())
1404 1065 : node->insert_new_function_version ();
1405 :
1406 1065 : DECL_FUNCTION_VERSIONED (decl) = 1;
1407 : /* If DECL_ASSEMBLER_NAME has already been set, re-mangle
1408 : to include the version marker. */
1409 1065 : if (DECL_ASSEMBLER_NAME_SET_P (decl))
1410 1059 : mangle_decl (decl);
1411 : }
1412 17652 : }
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 197577 : maybe_version_functions (tree newdecl, tree olddecl)
1420 : {
1421 197577 : if (!disjoint_version_decls (newdecl, olddecl))
1422 : return false;
1423 :
1424 8808 : maybe_mark_function_versioned (olddecl);
1425 8808 : 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 8808 : maybe_mark_function_versioned (newdecl);
1432 8808 : 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 8808 : cgraph_node *fn_node = cgraph_node::get_create (olddecl);
1444 8808 : cgraph_function_version_info *fn_v = fn_node->function_version ();
1445 8808 : if (!fn_v)
1446 15 : fn_v = fn_node->insert_new_function_version ();
1447 :
1448 8808 : cgraph_node::add_function_version (fn_v, newdecl);
1449 :
1450 8808 : 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 19244733 : warn_extern_redeclared_static (tree newdecl, tree olddecl)
1464 : {
1465 19244733 : if (TREE_CODE (newdecl) == TYPE_DECL
1466 19198293 : || TREE_CODE (newdecl) == TEMPLATE_DECL
1467 15294842 : || TREE_CODE (newdecl) == CONST_DECL
1468 15294842 : || TREE_CODE (newdecl) == NAMESPACE_DECL)
1469 19244721 : return;
1470 :
1471 : /* Don't get confused by static member functions; that's a different
1472 : use of `static'. */
1473 15294842 : if (TREE_CODE (newdecl) == FUNCTION_DECL
1474 15294842 : && 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 15124778 : 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 18708065 : check_redeclaration_exception_specification (tree new_decl,
1500 : tree old_decl)
1501 : {
1502 18708065 : tree new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
1503 18708065 : tree old_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (old_decl));
1504 :
1505 : /* Two default specs are equivalent, don't force evaluation. */
1506 7128721 : if (UNEVALUATED_NOEXCEPT_SPEC_P (new_exceptions)
1507 18850623 : && UNEVALUATED_NOEXCEPT_SPEC_P (old_exceptions))
1508 : return;
1509 :
1510 18698408 : if (!type_dependent_expression_p (old_decl))
1511 : {
1512 11424110 : maybe_instantiate_noexcept (new_decl);
1513 11424110 : maybe_instantiate_noexcept (old_decl);
1514 : }
1515 18698408 : new_exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (new_decl));
1516 18698408 : 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 18698408 : if (!DECL_IS_UNDECLARED_BUILTIN (old_decl)
1525 14886695 : && !DECL_IS_UNDECLARED_BUILTIN (new_decl)
1526 33584982 : && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
1527 : {
1528 326 : const char *const msg
1529 : = G_("declaration of %qF has a different exception specifier");
1530 326 : bool complained = true;
1531 326 : location_t new_loc = DECL_SOURCE_LOCATION (new_decl);
1532 326 : auto_diagnostic_group d;
1533 :
1534 : /* Be permissive about C++98 vs C++11 operator new declarations. */
1535 652 : bool global_new = (IDENTIFIER_NEW_OP_P (DECL_NAME (new_decl))
1536 1 : && CP_DECL_CONTEXT (new_decl) == global_namespace
1537 328 : && (nothrow_spec_p (new_exceptions)
1538 1 : == nothrow_spec_p (old_exceptions)));
1539 :
1540 326 : if (DECL_IN_SYSTEM_HEADER (old_decl)
1541 326 : && (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 93 : 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 90 : 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 21 : complained = pedwarn (new_loc, 0, msg, new_decl);
1554 : else
1555 69 : error_at (new_loc, msg, new_decl);
1556 :
1557 326 : if (complained)
1558 96 : 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 326 : if (!new_exceptions && !DECL_EXTERN_C_P (old_decl))
1565 20 : TREE_TYPE (new_decl)
1566 40 : = build_exception_variant (TREE_TYPE (new_decl), old_exceptions);
1567 326 : }
1568 : }
1569 :
1570 : /* Return true if OLD_DECL and NEW_DECL agree on constexprness.
1571 : Otherwise issue diagnostics. */
1572 :
1573 : bool
1574 19245245 : validate_constexpr_redeclaration (tree old_decl, tree new_decl)
1575 : {
1576 19245245 : old_decl = STRIP_TEMPLATE (old_decl);
1577 19245245 : new_decl = STRIP_TEMPLATE (new_decl);
1578 19245245 : if (!VAR_OR_FUNCTION_DECL_P (old_decl)
1579 19198781 : || !VAR_OR_FUNCTION_DECL_P (new_decl))
1580 : return true;
1581 19198781 : if (DECL_DECLARED_CONSTEXPR_P (old_decl)
1582 19198781 : == DECL_DECLARED_CONSTEXPR_P (new_decl))
1583 : {
1584 19056499 : if (TREE_CODE (old_decl) != FUNCTION_DECL)
1585 : return true;
1586 37416944 : if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1587 18708472 : == DECL_IMMEDIATE_FUNCTION_P (new_decl))
1588 : return true;
1589 : }
1590 142288 : if (TREE_CODE (old_decl) == FUNCTION_DECL)
1591 : {
1592 : /* With -fimplicit-constexpr, ignore changes in the constexpr
1593 : keyword. */
1594 69 : if (flag_implicit_constexpr
1595 69 : && (DECL_IMMEDIATE_FUNCTION_P (new_decl)
1596 0 : == DECL_IMMEDIATE_FUNCTION_P (old_decl)))
1597 : return true;
1598 69 : 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 69 : if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
1611 69 : && 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 11251811 : check_redeclaration_no_default_args (tree decl)
1637 : {
1638 11251811 : gcc_assert (DECL_DECLARES_FUNCTION_P (decl));
1639 :
1640 11251811 : for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
1641 33159436 : t && t != void_list_node; t = TREE_CHAIN (t))
1642 21907682 : 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 6874298 : check_no_redeclaration_friend_default_args (tree olddecl, tree newdecl)
1661 : {
1662 13052344 : if (!DECL_UNIQUE_FRIEND_P (olddecl) && !DECL_UNIQUE_FRIEND_P (newdecl))
1663 : return;
1664 :
1665 3440828 : for (tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl),
1666 1720414 : t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1667 4566733 : t1 && t1 != void_list_node;
1668 2846319 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
1669 4090462 : if ((DECL_UNIQUE_FRIEND_P (olddecl) && TREE_PURPOSE (t1))
1670 8107347 : || (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 18156421 : merge_attribute_bits (tree newdecl, tree olddecl)
1687 : {
1688 18156421 : TREE_THIS_VOLATILE (newdecl) |= TREE_THIS_VOLATILE (olddecl);
1689 18156421 : TREE_THIS_VOLATILE (olddecl) |= TREE_THIS_VOLATILE (newdecl);
1690 18156421 : TREE_NOTHROW (newdecl) |= TREE_NOTHROW (olddecl);
1691 18156421 : TREE_NOTHROW (olddecl) |= TREE_NOTHROW (newdecl);
1692 18156421 : TREE_READONLY (newdecl) |= TREE_READONLY (olddecl);
1693 18156421 : TREE_READONLY (olddecl) |= TREE_READONLY (newdecl);
1694 18156421 : DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
1695 18156421 : DECL_IS_MALLOC (olddecl) |= DECL_IS_MALLOC (newdecl);
1696 18156421 : DECL_PURE_P (newdecl) |= DECL_PURE_P (olddecl);
1697 18156421 : DECL_PURE_P (olddecl) |= DECL_PURE_P (newdecl);
1698 18156421 : DECL_UNINLINABLE (newdecl) |= DECL_UNINLINABLE (olddecl);
1699 18156421 : DECL_UNINLINABLE (olddecl) |= DECL_UNINLINABLE (newdecl);
1700 18156421 : TREE_DEPRECATED (newdecl) |= TREE_DEPRECATED (olddecl);
1701 18156421 : TREE_DEPRECATED (olddecl) |= TREE_DEPRECATED (newdecl);
1702 18156421 : TREE_UNAVAILABLE (newdecl) |= TREE_UNAVAILABLE (olddecl);
1703 18156421 : TREE_UNAVAILABLE (olddecl) |= TREE_UNAVAILABLE (newdecl);
1704 18156421 : }
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 143059450 : duplicate_function_template_decls (tree newdecl, tree olddecl)
1715 : {
1716 143059450 : tree newres = DECL_TEMPLATE_RESULT (newdecl);
1717 143059450 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1718 : /* Function template declarations can be differentiated by parameter
1719 : and return type. */
1720 143059450 : if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
1721 143059450 : TYPE_ARG_TYPES (TREE_TYPE (newres)))
1722 143059450 : && 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 6629 : if (template_heads_equivalent_p (newdecl, olddecl)
1727 6629 : && 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 8649020 : merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
1758 : {
1759 8649020 : gcc_checking_assert (TREE_VEC_LENGTH (new_parms)
1760 : == TREE_VEC_LENGTH (old_parms));
1761 24477994 : for (int i = 0; i < TREE_VEC_LENGTH (new_parms); i++)
1762 : {
1763 15829004 : tree new_parm = TREE_VALUE (TREE_VEC_ELT (new_parms, i));
1764 15829004 : tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
1765 15829004 : tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
1766 15829004 : tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
1767 15829004 : if (error_operand_p (new_parm) || error_operand_p (old_parm))
1768 : return false;
1769 15829001 : 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 15828974 : 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 206799 : old_default = new_default;
1781 15622175 : 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 1085970 : 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 14805048 : merge_decl_arguments (tree newdecl, tree olddecl, bool new_defines_function,
1797 : bool types_match, bool extern_alias)
1798 : {
1799 14805048 : tree oldarg, newarg, type = NULL_TREE;
1800 14805048 : tree first_user_parm = NULL_TREE;
1801 14805048 : if (extern_alias)
1802 179 : first_user_parm = FUNCTION_FIRST_USER_PARM (newdecl);
1803 14805048 : for (oldarg = DECL_ARGUMENTS (olddecl), newarg = DECL_ARGUMENTS (newdecl);
1804 41427216 : oldarg && newarg;
1805 26622168 : oldarg = DECL_CHAIN (oldarg), newarg = DECL_CHAIN (newarg))
1806 : {
1807 26622168 : DECL_ATTRIBUTES (newarg)
1808 26622168 : = (*targetm.merge_decl_attributes) (oldarg, newarg);
1809 26622168 : if (lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (newarg))
1810 26622237 : && !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 26622168 : if (!extern_alias || flag_reflection)
1822 26622005 : DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1823 26622168 : if (!flag_reflection)
1824 26440358 : 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 181810 : if (extern_alias)
1828 : {
1829 18 : if (newarg == first_user_parm)
1830 6 : type = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
1831 12 : else if (type)
1832 12 : type = TREE_CHAIN (type);
1833 36 : if (type && TREE_PURPOSE (type))
1834 2 : DECL_HAS_DEFAULT_ARGUMENT_P (oldarg) = 1;
1835 : }
1836 : else
1837 : {
1838 : /* Otherwise propagate the flag. */
1839 181792 : if (DECL_HAS_DEFAULT_ARGUMENT_P (oldarg))
1840 0 : DECL_HAS_DEFAULT_ARGUMENT_P (newarg) = 1;
1841 181792 : 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 181810 : if (DECL_NAME (oldarg) != DECL_NAME (newarg))
1852 : {
1853 20745 : if (DECL_NAME (oldarg) && DECL_NAME (newarg))
1854 : {
1855 : /* Different names. */
1856 4362 : MULTIPLE_NAMES_PARM_P (oldarg) = 1;
1857 4362 : MULTIPLE_NAMES_PARM_P (newarg) = 1;
1858 : }
1859 16383 : else if (!new_defines_function
1860 16383 : && types_match
1861 16383 : && 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 3087 : if (DECL_NAME (oldarg))
1866 2565 : DECL_NAME (newarg) = DECL_NAME (oldarg);
1867 : else
1868 522 : 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 13296 : else if (tree name = ((new_defines_function || !types_match)
1873 13296 : ? DECL_NAME (oldarg) : DECL_NAME (newarg)))
1874 : {
1875 115 : tree opn = lookup_attribute ("old parm name",
1876 115 : DECL_ATTRIBUTES (oldarg));
1877 115 : if (opn)
1878 : {
1879 2 : 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 113 : DECL_ATTRIBUTES (newarg)
1892 113 : = tree_cons (get_identifier ("old parm name"),
1893 : tree_cons (NULL_TREE, name, NULL_TREE),
1894 113 : DECL_ATTRIBUTES (newarg));
1895 113 : DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
1896 : }
1897 : }
1898 13181 : else if (extern_alias)
1899 1 : DECL_NAME (newarg) = DECL_NAME (oldarg);
1900 : }
1901 : }
1902 14805048 : }
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 294189005 : duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden)
1919 : {
1920 294189005 : unsigned olddecl_uid = DECL_UID (olddecl);
1921 294189005 : int types_match = 0;
1922 294189005 : int new_defines_function = 0;
1923 294189005 : tree new_template_info;
1924 294189005 : location_t olddecl_loc = DECL_SOURCE_LOCATION (olddecl);
1925 294189005 : location_t newdecl_loc = DECL_SOURCE_LOCATION (newdecl);
1926 :
1927 294189005 : if (newdecl == olddecl)
1928 : return olddecl;
1929 :
1930 293385959 : 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 293385959 : if (TREE_TYPE (newdecl) == error_mark_node
1938 293385959 : || TREE_TYPE (olddecl) == error_mark_node)
1939 : return error_mark_node;
1940 :
1941 : /* Check for redeclaration and other discrepancies. */
1942 293385934 : if (TREE_CODE (olddecl) == FUNCTION_DECL
1943 293385934 : && DECL_IS_UNDECLARED_BUILTIN (olddecl))
1944 : {
1945 6149485 : if (TREE_CODE (newdecl) != FUNCTION_DECL)
1946 : {
1947 : /* Avoid warnings redeclaring built-ins which have not been
1948 : explicitly declared. */
1949 186681 : if (was_hidden)
1950 : {
1951 186639 : if (TREE_PUBLIC (newdecl)
1952 186639 : && 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 186639 : 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 5962804 : else if (!types_match)
1986 : {
1987 : /* Avoid warnings redeclaring built-ins which have not been
1988 : explicitly declared. */
1989 2151091 : if (was_hidden)
1990 : {
1991 779211 : tree t1, t2;
1992 :
1993 : /* A new declaration doesn't match a built-in one unless it
1994 : is also extern "C". */
1995 779211 : gcc_assert (DECL_IS_UNDECLARED_BUILTIN (olddecl));
1996 779211 : gcc_assert (DECL_EXTERN_C_P (olddecl));
1997 779211 : if (!DECL_EXTERN_C_P (newdecl))
1998 : return NULL_TREE;
1999 :
2000 139443 : for (t1 = TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2001 139443 : t2 = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2002 240340 : t1 || t2;
2003 100897 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2))
2004 : {
2005 240322 : if (!t1 || !t2)
2006 : break;
2007 : /* FILE, tm types are not known at the time
2008 : we create the builtins. */
2009 743153 : for (unsigned i = 0;
2010 983313 : i < sizeof (builtin_structptr_types)
2011 : / sizeof (builtin_structptr_type);
2012 : ++i)
2013 882410 : if (TREE_VALUE (t2) == builtin_structptr_types[i].node)
2014 : {
2015 139257 : tree t = TREE_VALUE (t1);
2016 :
2017 139257 : if (TYPE_PTR_P (t)
2018 278514 : && TYPE_IDENTIFIER (TREE_TYPE (t))
2019 139257 : == get_identifier (builtin_structptr_types[i].str)
2020 278499 : && compparms (TREE_CHAIN (t1), TREE_CHAIN (t2)))
2021 : {
2022 139242 : tree oldargs = TYPE_ARG_TYPES (TREE_TYPE (olddecl));
2023 :
2024 139242 : TYPE_ARG_TYPES (TREE_TYPE (olddecl))
2025 139242 : = TYPE_ARG_TYPES (TREE_TYPE (newdecl));
2026 139242 : types_match = decls_match (newdecl, olddecl);
2027 139242 : if (types_match)
2028 139242 : return duplicate_decls (newdecl, olddecl,
2029 139242 : hiding, was_hidden);
2030 0 : TYPE_ARG_TYPES (TREE_TYPE (olddecl)) = oldargs;
2031 : }
2032 15 : goto next_arg;
2033 : }
2034 :
2035 100903 : if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
2036 : break;
2037 100897 : 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 1371880 : else if ((DECL_EXTERN_C_P (newdecl)
2046 15 : && DECL_EXTERN_C_P (olddecl))
2047 2743745 : || compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2048 1371865 : 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 3811713 : tree type = TREE_TYPE (newdecl);
2110 3811713 : tree attribs = (*targetm.merge_type_attributes)
2111 3811713 : (TREE_TYPE (olddecl), type);
2112 :
2113 3811713 : type = cp_build_type_attribute_variant (type, attribs);
2114 3811713 : 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 3811914 : if (DECL_BUILT_IN_CLASS (olddecl) == BUILT_IN_NORMAL
2120 3653181 : && was_hidden
2121 3653138 : && TREE_NOTHROW (newdecl)
2122 7210617 : && !TREE_NOTHROW (olddecl))
2123 : {
2124 27001 : enum built_in_function fncode = DECL_FUNCTION_CODE (olddecl);
2125 27001 : tree tmpdecl = builtin_decl_explicit (fncode);
2126 27001 : if (tmpdecl && tmpdecl != olddecl && types_match)
2127 27001 : TREE_NOTHROW (tmpdecl) = 1;
2128 : }
2129 :
2130 : /* Whether or not the builtin can throw exceptions has no
2131 : bearing on this declarator. */
2132 3811914 : TREE_NOTHROW (olddecl) = 0;
2133 :
2134 3811914 : 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 287236449 : 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 69189100 : if (TREE_CODE (olddecl) == NAMESPACE_DECL
2154 69189073 : || TREE_CODE (newdecl) == NAMESPACE_DECL)
2155 : /* Namespace conflicts with not namespace. */;
2156 33888528 : else if (DECL_TYPE_TEMPLATE_P (olddecl)
2157 103077589 : || DECL_TYPE_TEMPLATE_P (newdecl))
2158 : /* Class template conflicts. */;
2159 69189055 : else if ((TREE_CODE (olddecl) == TEMPLATE_DECL
2160 33888528 : && DECL_TEMPLATE_RESULT (olddecl)
2161 33888528 : && TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == VAR_DECL)
2162 103077577 : || (TREE_CODE (newdecl) == TEMPLATE_DECL
2163 35253218 : && DECL_TEMPLATE_RESULT (newdecl)
2164 35253218 : && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == VAR_DECL))
2165 : /* Variable template conflicts. */;
2166 69189046 : else if (concept_definition_p (olddecl)
2167 138378086 : || concept_definition_p (newdecl))
2168 : /* Concept conflicts. */;
2169 69189034 : else if ((TREE_CODE (newdecl) == FUNCTION_DECL
2170 33926399 : && DECL_FUNCTION_TEMPLATE_P (olddecl))
2171 69226917 : || (TREE_CODE (olddecl) == FUNCTION_DECL
2172 35253228 : && DECL_FUNCTION_TEMPLATE_P (newdecl)))
2173 : {
2174 : /* One is a function and the other is a template
2175 : function. */
2176 69141710 : if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
2177 : return NULL_TREE;
2178 :
2179 : /* There can only be one! */
2180 55939 : auto_diagnostic_group d;
2181 55939 : if (TREE_CODE (newdecl) == TEMPLATE_DECL
2182 55939 : && check_raw_literal_operator (olddecl))
2183 3 : error_at (newdecl_loc,
2184 : "literal operator %q#D conflicts with"
2185 : " raw literal operator", newdecl);
2186 55936 : 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 55939 : }
2196 47324 : else if (DECL_DECOMPOSITION_P (olddecl) || DECL_DECOMPOSITION_P (newdecl))
2197 : /* A structured binding must be unique in its declarative region. */;
2198 38031 : else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
2199 47321 : || 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 218047349 : else if (!types_match)
2210 : {
2211 202582494 : 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 202582434 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2217 : {
2218 143059468 : tree oldres = DECL_TEMPLATE_RESULT (olddecl);
2219 143059468 : 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 143059468 : if (TREE_CODE (oldres) == TYPE_DECL
2225 143059462 : || 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 143059459 : else if (TREE_CODE (oldres) == FUNCTION_DECL
2236 143059450 : && TREE_CODE (newres) == FUNCTION_DECL)
2237 : {
2238 143059450 : if (duplicate_function_template_decls (newdecl, olddecl))
2239 0 : return error_mark_node;
2240 : return NULL_TREE;
2241 : }
2242 : return NULL_TREE;
2243 : }
2244 59522966 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2245 : {
2246 59522811 : 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 59522754 : else if (((!DECL_FUNCTION_VERSIONED (newdecl)
2259 59514432 : && !DECL_FUNCTION_VERSIONED (olddecl))
2260 8367 : || !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 59514387 : && !member_like_constrained_friend_p (newdecl)
2265 56972918 : && !member_like_constrained_friend_p (olddecl)
2266 : // The functions have the same parameter types.
2267 56523190 : && compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
2268 56523190 : TYPE_ARG_TYPES (TREE_TYPE (olddecl)))
2269 : // And the same constraints.
2270 59522823 : && 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 59522685 : return NULL_TREE;
2281 : }
2282 : else
2283 : {
2284 155 : auto_diagnostic_group d;
2285 155 : error_at (newdecl_loc, "conflicting declaration %q#D", newdecl);
2286 155 : inform (olddecl_loc,
2287 : "previous declaration as %q#D", olddecl);
2288 155 : return error_mark_node;
2289 155 : }
2290 : }
2291 15464855 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2292 15464855 : && 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 15464822 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2304 15464822 : && ((DECL_TEMPLATE_SPECIALIZATION (olddecl)
2305 222 : && (!DECL_TEMPLATE_INFO (newdecl)
2306 222 : || (DECL_TI_TEMPLATE (newdecl)
2307 222 : != DECL_TI_TEMPLATE (olddecl))))
2308 10993240 : || (DECL_TEMPLATE_SPECIALIZATION (newdecl)
2309 551908 : && (!DECL_TEMPLATE_INFO (olddecl)
2310 551908 : || (DECL_TI_TEMPLATE (olddecl)
2311 551908 : != 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 15464822 : else if (TREE_CODE (newdecl) == FUNCTION_DECL
2322 15464822 : && ((DECL_TEMPLATE_INSTANTIATION (olddecl)
2323 629254 : && !DECL_USE_TEMPLATE (newdecl))
2324 10993240 : || (DECL_TEMPLATE_INSTANTIATION (newdecl)
2325 77568 : && !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 15464822 : 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 28 : if (DECL_NAMESPACE_ALIAS (newdecl)
2341 28 : && (DECL_NAMESPACE_ALIAS (newdecl)
2342 25 : == 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 15464794 : else if (!TARGET_HAS_FMV_TARGET_ATTRIBUTE
2350 : && diagnose_versioned_decls (olddecl, newdecl))
2351 : return error_mark_node;
2352 : else
2353 : {
2354 15464794 : const char *errmsg = redeclaration_error_message (newdecl, olddecl);
2355 15464794 : if (errmsg)
2356 : {
2357 624 : auto_diagnostic_group d;
2358 624 : error_at (newdecl_loc, errmsg, newdecl);
2359 624 : if (DECL_NAME (olddecl) != NULL_TREE)
2360 624 : inform (olddecl_loc,
2361 624 : (DECL_INITIAL (olddecl) && namespace_bindings_p ())
2362 : ? G_("%q#D previously defined here")
2363 : : G_("%q#D previously declared here"), olddecl);
2364 624 : if (cxx_dialect >= cxx26
2365 150 : && DECL_NAME (newdecl)
2366 150 : && id_equal (DECL_NAME (newdecl), "_")
2367 637 : && !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 624 : return error_mark_node;
2403 624 : }
2404 15464170 : else if (TREE_CODE (olddecl) == FUNCTION_DECL
2405 10993000 : && DECL_INITIAL (olddecl) != NULL_TREE
2406 15467 : && !prototype_p (TREE_TYPE (olddecl))
2407 15464170 : && 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 14974197 : else if (VAR_OR_FUNCTION_DECL_P (olddecl)
2417 26457170 : && 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 1837 : if (current_lang_depth () == 0)
2444 : {
2445 : /* There is no explicit linkage-specification, so we use
2446 : the linkage from the previous declaration. */
2447 1825 : retrofit_lang_decl (newdecl);
2448 1825 : 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 15464170 : if (DECL_LANG_SPECIFIC (olddecl) && DECL_USE_TEMPLATE (olddecl))
2463 : ;
2464 14814600 : else if (TREE_CODE (olddecl) == FUNCTION_DECL)
2465 : {
2466 : /* Note: free functions, as TEMPLATE_DECLs, are handled below. */
2467 12928643 : if (DECL_FUNCTION_MEMBER_P (olddecl)
2468 10363533 : && (/* grokfndecl passes member function templates too
2469 : as FUNCTION_DECLs. */
2470 7968359 : 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 675955 : || CLASSTYPE_TEMPLATE_INFO (CP_DECL_CONTEXT (olddecl))))
2476 : {
2477 7370523 : check_redeclaration_no_default_args (newdecl);
2478 :
2479 7370523 : if (DECL_TEMPLATE_INFO (olddecl)
2480 7370523 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (olddecl)))
2481 : {
2482 2137824 : tree new_parms = DECL_TEMPLATE_INFO (newdecl)
2483 2137824 : ? DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (newdecl))
2484 2137824 : : INNERMOST_TEMPLATE_PARMS (current_template_parms);
2485 2137824 : tree old_parms
2486 2137824 : = DECL_INNERMOST_TEMPLATE_PARMS (DECL_TI_TEMPLATE (olddecl));
2487 2137824 : merge_default_template_args (new_parms, old_parms,
2488 : /*class_p=*/false);
2489 : }
2490 : }
2491 : else
2492 : {
2493 2993010 : tree t1 = FUNCTION_FIRST_USER_PARMTYPE (olddecl);
2494 2993010 : tree t2 = FUNCTION_FIRST_USER_PARMTYPE (newdecl);
2495 2993010 : int i = 1;
2496 :
2497 7727361 : for (; t1 && t1 != void_list_node;
2498 4734351 : t1 = TREE_CHAIN (t1), t2 = TREE_CHAIN (t2), i++)
2499 4736252 : 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 2993010 : 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 19276084 : if (TREE_CODE (olddecl) == TYPE_DECL
2541 19276084 : && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
2542 46443 : || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
2543 : return NULL_TREE;
2544 :
2545 19244799 : if (DECL_TEMPLATE_PARM_P (olddecl) != DECL_TEMPLATE_PARM_P (newdecl))
2546 : return NULL_TREE;
2547 :
2548 19244787 : if (!validate_constexpr_redeclaration (olddecl, newdecl))
2549 30 : return error_mark_node;
2550 :
2551 19244757 : if (modules_p ()
2552 56357 : && TREE_CODE (CP_DECL_CONTEXT (olddecl)) == NAMESPACE_DECL
2553 19278131 : && TREE_CODE (olddecl) != NAMESPACE_DECL)
2554 : {
2555 33374 : if (!module_may_redeclare (olddecl, newdecl))
2556 24 : return error_mark_node;
2557 :
2558 33350 : 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 29340 : tree not_tmpl = STRIP_TEMPLATE (olddecl);
2564 29340 : if (DECL_LANG_SPECIFIC (not_tmpl)
2565 29243 : && 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 29531 : && 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 29161 : else if (DECL_MODULE_EXPORT_P (newdecl))
2580 10202 : 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 19244733 : 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 19244733 : const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
2595 14804869 : || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
2596 19796626 : || DECL_TEMPLATE_SPECIALIZATION (olddecl));
2597 :
2598 19244733 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2599 : {
2600 14804869 : if (merge_attr)
2601 : {
2602 14253183 : {
2603 14253183 : auto_diagnostic_group d;
2604 14253183 : 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 14253183 : }
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 14253183 : tree a;
2614 14253183 : if (TREE_THIS_VOLATILE (newdecl)
2615 88234 : && !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 14253204 : && 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 14804869 : if (DECL_VINDEX (olddecl))
2633 155468 : DECL_VINDEX (newdecl) = DECL_VINDEX (olddecl);
2634 14804869 : if (DECL_CONTEXT (olddecl))
2635 14804869 : DECL_CONTEXT (newdecl) = DECL_CONTEXT (olddecl);
2636 14804869 : DECL_STATIC_CONSTRUCTOR (newdecl) |= DECL_STATIC_CONSTRUCTOR (olddecl);
2637 14804869 : DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
2638 14804869 : DECL_PURE_VIRTUAL_P (newdecl) |= DECL_PURE_VIRTUAL_P (olddecl);
2639 14804869 : DECL_VIRTUAL_P (newdecl) |= DECL_VIRTUAL_P (olddecl);
2640 14804869 : DECL_INVALID_OVERRIDER_P (newdecl) |= DECL_INVALID_OVERRIDER_P (olddecl);
2641 14804869 : DECL_FINAL_P (newdecl) |= DECL_FINAL_P (olddecl);
2642 14804869 : DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
2643 14804869 : DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
2644 14804869 : DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (newdecl)
2645 14804869 : |= DECL_HAS_DEPENDENT_EXPLICIT_SPEC_P (olddecl);
2646 14804869 : if (DECL_OVERLOADED_OPERATOR_P (olddecl))
2647 2680647 : DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
2648 5361294 : = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
2649 14804869 : new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
2650 :
2651 14804869 : 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 14804881 : && (! 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 14804869 : if (!(DECL_TEMPLATE_INSTANTIATION (olddecl)
2680 629254 : && DECL_TEMPLATE_SPECIALIZATION (newdecl)))
2681 : {
2682 14253183 : 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 14253183 : DECL_DELETED_FN (newdecl) |= DECL_DELETED_FN (olddecl);
2691 14253183 : if (DECL_DELETED_FN (olddecl)
2692 6 : && DECL_INITIAL (olddecl)
2693 14253189 : && 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 19244733 : if (TREE_CODE (olddecl) == TYPE_DECL)
2700 : {
2701 46440 : tree newtype = TREE_TYPE (newdecl);
2702 46440 : tree oldtype = TREE_TYPE (olddecl);
2703 :
2704 46440 : if (newtype != error_mark_node && oldtype != error_mark_node
2705 92880 : && TYPE_LANG_SPECIFIC (newtype) && TYPE_LANG_SPECIFIC (oldtype))
2706 127233 : CLASSTYPE_FRIEND_CLASSES (newtype)
2707 42411 : = CLASSTYPE_FRIEND_CLASSES (oldtype);
2708 :
2709 46440 : 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 19244733 : if (merge_attr)
2715 18693047 : DECL_ATTRIBUTES (newdecl)
2716 37386094 : = (*targetm.merge_decl_attributes) (olddecl, newdecl);
2717 : else
2718 551686 : DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2719 :
2720 : /* Transfer purviewness and importingness to the old decl. */
2721 19244733 : transfer_defining_module (olddecl, newdecl);
2722 :
2723 19244733 : if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2724 : {
2725 3903451 : tree old_result = DECL_TEMPLATE_RESULT (olddecl);
2726 3903451 : tree new_result = DECL_TEMPLATE_RESULT (newdecl);
2727 3903451 : TREE_TYPE (olddecl) = TREE_TYPE (old_result);
2728 :
2729 : /* The new decl should not already have gathered any
2730 : specializations. */
2731 3903451 : gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
2732 :
2733 : /* Make sure the contracts are equivalent. */
2734 3903451 : check_redecl_contract (newdecl, olddecl);
2735 :
2736 3903451 : DECL_ATTRIBUTES (old_result)
2737 3903451 : = (*targetm.merge_decl_attributes) (old_result, new_result);
2738 :
2739 3903451 : if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2740 : {
2741 3903421 : if (DECL_SOURCE_LOCATION (newdecl)
2742 3903421 : != 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 3881288 : 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 3881288 : check_no_redeclaration_friend_default_args
2752 3881288 : (old_result, new_result);
2753 :
2754 3881288 : tree new_parms = DECL_INNERMOST_TEMPLATE_PARMS (newdecl);
2755 3881288 : tree old_parms = DECL_INNERMOST_TEMPLATE_PARMS (olddecl);
2756 3881288 : merge_default_template_args (new_parms, old_parms,
2757 : /*class_p=*/false);
2758 : }
2759 3903421 : if (!DECL_UNIQUE_FRIEND_P (new_result))
2760 2895260 : DECL_UNIQUE_FRIEND_P (old_result) = false;
2761 :
2762 3903421 : check_default_args (newdecl);
2763 :
2764 7806830 : if (GNU_INLINE_P (old_result) != GNU_INLINE_P (new_result)
2765 3903421 : && 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 3903397 : DECL_DECLARED_INLINE_P (old_result)
2784 3903397 : |= DECL_DECLARED_INLINE_P (new_result);
2785 3903397 : DECL_DISREGARD_INLINE_LIMITS (old_result)
2786 3903397 : |= DECL_DISREGARD_INLINE_LIMITS (new_result);
2787 3903397 : check_redeclaration_exception_specification (newdecl, olddecl);
2788 :
2789 3903397 : 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 3903451 : if (DECL_INITIAL (new_result) != NULL_TREE)
2797 : {
2798 5388034 : DECL_SOURCE_LOCATION (olddecl)
2799 5388034 : = DECL_SOURCE_LOCATION (old_result)
2800 2694017 : = DECL_SOURCE_LOCATION (newdecl);
2801 2694017 : DECL_INITIAL (old_result) = DECL_INITIAL (new_result);
2802 2694017 : if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2803 : {
2804 2694017 : update_contract_arguments (new_result, old_result);
2805 :
2806 2694017 : DECL_ARGUMENTS (old_result) = DECL_ARGUMENTS (new_result);
2807 9720105 : for (tree p = DECL_ARGUMENTS (old_result); p; p = DECL_CHAIN (p))
2808 7026088 : DECL_CONTEXT (p) = old_result;
2809 :
2810 5388034 : if (tree fc = DECL_FRIEND_CONTEXT (new_result))
2811 18 : SET_DECL_FRIEND_CONTEXT (old_result, fc);
2812 : }
2813 : }
2814 :
2815 3903451 : return olddecl;
2816 : }
2817 :
2818 15341282 : if (types_match)
2819 : {
2820 15341081 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2821 14804668 : check_redeclaration_exception_specification (newdecl, olddecl);
2822 :
2823 : /* Automatically handles default parameters. */
2824 15341081 : tree oldtype = TREE_TYPE (olddecl);
2825 15341081 : 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 15341081 : if (TREE_CODE (newdecl) == TYPE_DECL)
2830 : {
2831 : /* But NEWTYPE might have an attribute, honor that. */
2832 46440 : tree tem = TREE_TYPE (newdecl);
2833 46440 : newtype = oldtype;
2834 :
2835 46440 : 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 46440 : 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 15294641 : else if (merge_attr)
2876 14742955 : newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2877 : else
2878 551686 : newtype = TREE_TYPE (newdecl);
2879 :
2880 15341081 : if (VAR_P (newdecl))
2881 : {
2882 489973 : 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 489973 : if (DECL_INITIALIZED_P (olddecl)
2888 1214 : && !DECL_EXTERNAL (olddecl)
2889 490059 : && !TREE_READONLY (olddecl))
2890 31 : TREE_READONLY (newdecl) = 0;
2891 489973 : DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
2892 979946 : DECL_NONTRIVIALLY_INITIALIZED_P (newdecl)
2893 489973 : |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
2894 489973 : if (DECL_DEPENDENT_INIT_P (olddecl))
2895 103092 : SET_DECL_DEPENDENT_INIT_P (newdecl, true);
2896 979946 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
2897 489973 : |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
2898 489973 : DECL_DECLARED_CONSTEXPR_P (newdecl)
2899 489973 : |= DECL_DECLARED_CONSTEXPR_P (olddecl);
2900 979946 : DECL_DECLARED_CONSTINIT_P (newdecl)
2901 489973 : |= DECL_DECLARED_CONSTINIT_P (olddecl);
2902 :
2903 : /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
2904 489973 : if (DECL_LANG_SPECIFIC (olddecl)
2905 976358 : && 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 1204 : if (flag_tm && TREE_CODE (newdecl) == FUNCTION_DECL
2918 1069 : && DECL_TEMPLATE_INSTANTIATION (olddecl)
2919 78 : && DECL_TEMPLATE_SPECIALIZATION (newdecl)
2920 54 : && tx_safe_fn_type_p (newtype)
2921 15341081 : && !tx_safe_fn_type_p (TREE_TYPE (newdecl)))
2922 0 : newtype = tx_unsafe_fn_variant (newtype);
2923 :
2924 15341081 : TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = newtype;
2925 :
2926 15341081 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2927 14804668 : check_default_args (newdecl);
2928 :
2929 : /* Lay the type out, unless already done. */
2930 15341081 : if (! same_type_p (newtype, oldtype)
2931 368 : && TREE_TYPE (newdecl) != error_mark_node
2932 15341449 : && !(processing_template_decl && uses_template_parms (newdecl)))
2933 285 : layout_type (TREE_TYPE (newdecl));
2934 :
2935 15341081 : if ((VAR_P (newdecl)
2936 14851108 : || TREE_CODE (newdecl) == PARM_DECL
2937 14851108 : || TREE_CODE (newdecl) == RESULT_DECL
2938 14851108 : || TREE_CODE (newdecl) == FIELD_DECL
2939 14851108 : || TREE_CODE (newdecl) == TYPE_DECL)
2940 15387521 : && !(processing_template_decl && uses_template_parms (newdecl)))
2941 377614 : layout_decl (newdecl, 0);
2942 :
2943 : /* Merge deprecatedness. */
2944 15341081 : if (TREE_DEPRECATED (newdecl))
2945 11419 : TREE_DEPRECATED (olddecl) = 1;
2946 :
2947 : /* Merge unavailability. */
2948 15341081 : if (TREE_UNAVAILABLE (newdecl))
2949 3 : TREE_UNAVAILABLE (olddecl) = 1;
2950 :
2951 : /* Preserve function specific target and optimization options */
2952 15341081 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2953 : {
2954 14804668 : if (DECL_FUNCTION_SPECIFIC_TARGET (olddecl)
2955 14804668 : && !DECL_FUNCTION_SPECIFIC_TARGET (newdecl))
2956 0 : DECL_FUNCTION_SPECIFIC_TARGET (newdecl)
2957 0 : = DECL_FUNCTION_SPECIFIC_TARGET (olddecl);
2958 :
2959 14804668 : if (DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl)
2960 14804668 : && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl))
2961 55 : DECL_FUNCTION_SPECIFIC_OPTIMIZATION (newdecl)
2962 55 : = DECL_FUNCTION_SPECIFIC_OPTIMIZATION (olddecl);
2963 :
2964 14804668 : if (!DECL_UNIQUE_FRIEND_P (olddecl))
2965 14291013 : DECL_UNIQUE_FRIEND_P (newdecl) = false;
2966 : }
2967 : else
2968 : {
2969 : /* Merge the const type qualifier. */
2970 536413 : if (TREE_READONLY (newdecl))
2971 143555 : TREE_READONLY (olddecl) = 1;
2972 : /* Merge the volatile type qualifier. */
2973 536413 : if (TREE_THIS_VOLATILE (newdecl))
2974 5 : TREE_THIS_VOLATILE (olddecl) = 1;
2975 : }
2976 :
2977 : /* Merge the initialization information. */
2978 15341081 : if (DECL_INITIAL (newdecl) == NULL_TREE
2979 15341081 : && DECL_INITIAL (olddecl) != NULL_TREE)
2980 : {
2981 176937 : DECL_INITIAL (newdecl) = DECL_INITIAL (olddecl);
2982 176937 : DECL_SOURCE_LOCATION (newdecl) = DECL_SOURCE_LOCATION (olddecl);
2983 176937 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2984 : {
2985 15383 : DECL_SAVED_TREE (newdecl) = DECL_SAVED_TREE (olddecl);
2986 15383 : DECL_STRUCT_FUNCTION (newdecl) = DECL_STRUCT_FUNCTION (olddecl);
2987 : }
2988 : }
2989 :
2990 15341081 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
2991 : {
2992 14804668 : DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
2993 14804668 : |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
2994 14804668 : DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
2995 14804668 : if (DECL_IS_OPERATOR_NEW_P (olddecl))
2996 53669 : DECL_SET_IS_OPERATOR_NEW (newdecl, true);
2997 14804668 : DECL_LOOPING_CONST_OR_PURE_P (newdecl)
2998 14804668 : |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
2999 14804668 : DECL_IS_REPLACEABLE_OPERATOR (newdecl)
3000 14804668 : |= DECL_IS_REPLACEABLE_OPERATOR (olddecl);
3001 :
3002 14804668 : if (merge_attr)
3003 14252982 : merge_attribute_bits (newdecl, olddecl);
3004 : else
3005 : {
3006 : /* Merge the noreturn bit. */
3007 551686 : TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
3008 551686 : TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
3009 551686 : TREE_NOTHROW (olddecl) = TREE_NOTHROW (newdecl);
3010 551686 : DECL_IS_MALLOC (olddecl) = DECL_IS_MALLOC (newdecl);
3011 551686 : DECL_PURE_P (olddecl) = DECL_PURE_P (newdecl);
3012 : }
3013 : /* Keep the old RTL. */
3014 14804668 : COPY_DECL_RTL (olddecl, newdecl);
3015 : }
3016 536413 : else if (VAR_P (newdecl)
3017 536413 : && (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 489899 : 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 15341282 : merge_weak (newdecl, olddecl);
3044 :
3045 15341282 : DECL_DEFER_OUTPUT (newdecl) |= DECL_DEFER_OUTPUT (olddecl);
3046 15341282 : TREE_PUBLIC (newdecl) = TREE_PUBLIC (olddecl);
3047 15341282 : TREE_STATIC (olddecl) = TREE_STATIC (newdecl) |= TREE_STATIC (olddecl);
3048 15341282 : if (! DECL_EXTERNAL (olddecl))
3049 51082 : DECL_EXTERNAL (newdecl) = 0;
3050 15341282 : if (! DECL_COMDAT (olddecl))
3051 6543035 : DECL_COMDAT (newdecl) = 0;
3052 :
3053 15341282 : 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 15341282 : new_template_info = NULL_TREE;
3076 15341282 : if (DECL_LANG_SPECIFIC (newdecl) && DECL_LANG_SPECIFIC (olddecl))
3077 : {
3078 15291272 : bool new_redefines_gnu_inline = false;
3079 :
3080 15291272 : if (new_defines_function
3081 15291272 : && ((DECL_INTERFACE_KNOWN (olddecl)
3082 1249 : && TREE_CODE (olddecl) == FUNCTION_DECL)
3083 8993121 : || (TREE_CODE (olddecl) == TEMPLATE_DECL
3084 0 : && (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl))
3085 : == FUNCTION_DECL))))
3086 2498 : new_redefines_gnu_inline = GNU_INLINE_P (STRIP_TEMPLATE (olddecl));
3087 :
3088 : if (!new_redefines_gnu_inline)
3089 : {
3090 15291194 : DECL_INTERFACE_KNOWN (newdecl) |= DECL_INTERFACE_KNOWN (olddecl);
3091 15291194 : DECL_NOT_REALLY_EXTERN (newdecl) |= DECL_NOT_REALLY_EXTERN (olddecl);
3092 15291194 : DECL_COMDAT (newdecl) |= DECL_COMDAT (olddecl);
3093 : }
3094 :
3095 15291272 : if (TREE_CODE (newdecl) != TYPE_DECL)
3096 : {
3097 15291208 : DECL_TEMPLATE_INSTANTIATED (newdecl)
3098 15291208 : |= DECL_TEMPLATE_INSTANTIATED (olddecl);
3099 15291208 : 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 15291208 : if (!DECL_USE_TEMPLATE (newdecl))
3106 14661738 : DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
3107 :
3108 15291208 : if (!DECL_TEMPLATE_SPECIALIZATION (newdecl))
3109 14739296 : DECL_INITIALIZED_IN_CLASS_P (newdecl)
3110 29478592 : |= 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 15291272 : DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
3116 :
3117 15291272 : if (LANG_DECL_HAS_MIN (newdecl))
3118 : {
3119 15291272 : DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
3120 15291272 : if (DECL_TEMPLATE_INFO (newdecl))
3121 : {
3122 629503 : new_template_info = DECL_TEMPLATE_INFO (newdecl);
3123 629503 : if (DECL_TEMPLATE_INSTANTIATION (olddecl)
3124 629503 : && DECL_TEMPLATE_SPECIALIZATION (newdecl))
3125 : /* Remember the presence of explicit specialization args. */
3126 1103378 : TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
3127 1103378 : = 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 15291272 : gcc_checking_assert (!DECL_TEMPLATE_INFO (olddecl)
3133 : || !non_templated_friend_p (olddecl));
3134 15291272 : DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
3135 : }
3136 :
3137 15291272 : if (DECL_DECLARES_FUNCTION_P (newdecl))
3138 : {
3139 : /* Only functions have these fields. */
3140 14804869 : DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
3141 14804869 : DECL_BEFRIENDING_CLASSES (newdecl)
3142 14804869 : = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
3143 14804869 : DECL_BEFRIENDING_CLASSES (olddecl));
3144 : /* DECL_THUNKS is only valid for virtual functions,
3145 : otherwise it is a DECL_FRIEND_CONTEXT. */
3146 14804869 : if (DECL_VIRTUAL_P (newdecl))
3147 618222 : SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
3148 28373294 : else if (tree fc = DECL_FRIEND_CONTEXT (newdecl))
3149 369799 : SET_DECL_FRIEND_CONTEXT (olddecl, fc);
3150 : }
3151 486403 : else if (VAR_P (newdecl))
3152 : {
3153 : /* Only variables have this field. */
3154 486339 : if (VAR_HAD_UNKNOWN_BOUND (olddecl))
3155 196 : SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
3156 : }
3157 : }
3158 :
3159 15341282 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3160 : {
3161 14804869 : merge_decl_arguments (newdecl, olddecl, new_defines_function,
3162 : types_match, false);
3163 :
3164 14804869 : if (DECL_TEMPLATE_INSTANTIATION (olddecl)
3165 14804869 : && !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 551686 : gcc_assert (DECL_TEMPLATE_SPECIALIZATION (newdecl));
3171 :
3172 551686 : 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 551686 : SET_DECL_TEMPLATE_SPECIALIZATION (olddecl);
3185 551686 : DECL_COMDAT (newdecl) = (TREE_PUBLIC (newdecl)
3186 1103219 : && 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 551686 : 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 551686 : gcc_assert (!merge_attr);
3196 :
3197 551686 : DECL_DECLARED_INLINE_P (olddecl)
3198 551686 : = DECL_DECLARED_INLINE_P (newdecl);
3199 :
3200 551686 : DECL_DISREGARD_INLINE_LIMITS (olddecl)
3201 551686 : = DECL_DISREGARD_INLINE_LIMITS (newdecl);
3202 :
3203 551686 : DECL_UNINLINABLE (olddecl) = DECL_UNINLINABLE (newdecl);
3204 : }
3205 14253183 : 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 14253105 : 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 14253099 : else if (DECL_PENDING_INLINE_P (newdecl))
3221 : ;
3222 14253099 : else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
3223 14253099 : DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
3224 28506198 : = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
3225 :
3226 14253105 : DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
3227 :
3228 42759315 : DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
3229 28506210 : = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
3230 :
3231 28506210 : DECL_DISREGARD_INLINE_LIMITS (newdecl)
3232 14253105 : = DECL_DISREGARD_INLINE_LIMITS (olddecl)
3233 14253105 : = (DECL_DISREGARD_INLINE_LIMITS (newdecl)
3234 28109514 : || DECL_DISREGARD_INLINE_LIMITS (olddecl));
3235 : }
3236 :
3237 : /* Preserve abstractness on cloned [cd]tors. */
3238 14804869 : DECL_ABSTRACT_P (newdecl) = DECL_ABSTRACT_P (olddecl);
3239 :
3240 : /* Update newdecl's parms to point at olddecl. */
3241 47076431 : for (tree parm = DECL_ARGUMENTS (newdecl); parm;
3242 32271562 : parm = DECL_CHAIN (parm))
3243 32271562 : DECL_CONTEXT (parm) = olddecl;
3244 :
3245 14804869 : 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 14804869 : if (! types_match || new_defines_function)
3252 : {
3253 : /* Update the contracts to reflect the new parameter names. */
3254 8994571 : 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 8994571 : for (tree oldarg = DECL_ARGUMENTS (olddecl);
3262 31529463 : oldarg; oldarg = DECL_CHAIN (oldarg))
3263 22534892 : 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 8994571 : DECL_ARGUMENTS (olddecl) = DECL_ARGUMENTS (newdecl);
3269 8994571 : 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 14804869 : if (fndecl_built_in_p (olddecl)
3275 14860696 : && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
3276 : {
3277 3897979 : 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 3897979 : COPY_DECL_RTL (olddecl, newdecl);
3281 3897979 : if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
3282 : {
3283 3897973 : enum built_in_function fncode = DECL_FUNCTION_CODE (newdecl);
3284 3897973 : 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 3897973 : switch (fncode)
3290 : {
3291 9773 : case BUILT_IN_STPCPY:
3292 9773 : set_builtin_decl_implicit_p (fncode, true);
3293 9773 : break;
3294 3888200 : default:
3295 3888200 : set_builtin_decl_declared_p (fncode, true);
3296 3888200 : break;
3297 : }
3298 : }
3299 :
3300 3897973 : copy_attributes_to_builtin (newdecl);
3301 : }
3302 : }
3303 14804869 : if (new_defines_function)
3304 : /* If defining a function declared with other language
3305 : linkage, use the previously declared language linkage. */
3306 8994370 : SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
3307 5810499 : else if (types_match)
3308 : {
3309 5810298 : DECL_RESULT (newdecl) = DECL_RESULT (olddecl);
3310 : /* Don't clear out the arguments if we're just redeclaring a
3311 : function. */
3312 5810298 : if (DECL_ARGUMENTS (olddecl))
3313 1880598 : DECL_ARGUMENTS (newdecl) = DECL_ARGUMENTS (olddecl);
3314 : }
3315 : }
3316 536413 : 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 15341282 : TREE_ADDRESSABLE (newdecl) = TREE_ADDRESSABLE (olddecl);
3321 15341282 : TREE_ASM_WRITTEN (newdecl) = TREE_ASM_WRITTEN (olddecl);
3322 15341282 : DECL_COMMON (newdecl) = DECL_COMMON (olddecl);
3323 15341282 : COPY_DECL_ASSEMBLER_NAME (olddecl, newdecl);
3324 :
3325 : /* Warn about conflicting visibility specifications. */
3326 15341282 : if (DECL_VISIBILITY_SPECIFIED (olddecl)
3327 5400217 : && DECL_VISIBILITY_SPECIFIED (newdecl)
3328 15352876 : && 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 15341282 : if (DECL_VISIBILITY_SPECIFIED (olddecl))
3339 : {
3340 5400217 : DECL_VISIBILITY (newdecl) = DECL_VISIBILITY (olddecl);
3341 5400217 : 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 15341282 : 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 15341282 : 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 15341228 : else if (DECL_ALIGN (olddecl) == DECL_ALIGN (newdecl)
3357 15341228 : && DECL_USER_ALIGN (olddecl) != DECL_USER_ALIGN (newdecl))
3358 3 : DECL_USER_ALIGN (newdecl) = 1;
3359 :
3360 15341282 : DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl);
3361 30682564 : if (DECL_WARN_IF_NOT_ALIGN (olddecl)
3362 15341282 : > DECL_WARN_IF_NOT_ALIGN (newdecl))
3363 0 : SET_DECL_WARN_IF_NOT_ALIGN (newdecl,
3364 : DECL_WARN_IF_NOT_ALIGN (olddecl));
3365 15341282 : if (TREE_CODE (newdecl) == FIELD_DECL)
3366 0 : DECL_PACKED (olddecl) = DECL_PACKED (newdecl);
3367 :
3368 : /* Merge module entity mapping information. */
3369 15341282 : if (DECL_LANG_SPECIFIC (olddecl)
3370 30632600 : && (DECL_MODULE_ENTITY_P (olddecl)
3371 15290986 : || DECL_MODULE_KEYED_DECLS_P (olddecl)))
3372 : {
3373 332 : retrofit_lang_decl (newdecl);
3374 332 : DECL_MODULE_ENTITY_P (newdecl) = DECL_MODULE_ENTITY_P (olddecl);
3375 332 : 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 15341282 : if (DECL_LANG_SPECIFIC (olddecl))
3381 : {
3382 15291318 : gcc_checking_assert (DECL_LANG_SPECIFIC (olddecl)
3383 : != DECL_LANG_SPECIFIC (newdecl));
3384 15291318 : ggc_free (DECL_LANG_SPECIFIC (olddecl));
3385 : }
3386 :
3387 : /* Merge the USED information. */
3388 15341282 : if (TREE_USED (olddecl))
3389 483657 : TREE_USED (newdecl) = 1;
3390 14857625 : else if (TREE_USED (newdecl))
3391 62 : TREE_USED (olddecl) = 1;
3392 :
3393 15341282 : if (VAR_P (newdecl))
3394 : {
3395 489973 : if (DECL_READ_P (olddecl))
3396 42027 : DECL_READ_P (newdecl) = 1;
3397 447946 : else if (DECL_READ_P (newdecl))
3398 3 : DECL_READ_P (olddecl) = 1;
3399 : }
3400 :
3401 15341282 : if (DECL_PRESERVE_P (olddecl))
3402 48 : DECL_PRESERVE_P (newdecl) = 1;
3403 15341234 : 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 15341282 : if (TREE_CODE (newdecl) == FUNCTION_DECL
3409 30146151 : && 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 15341282 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3419 : {
3420 14804869 : int function_size;
3421 14804869 : struct symtab_node *snode = symtab_node::get (olddecl);
3422 :
3423 14804869 : function_size = sizeof (struct tree_decl_common);
3424 :
3425 14804869 : memcpy ((char *) olddecl + sizeof (struct tree_common),
3426 : (char *) newdecl + sizeof (struct tree_common),
3427 : function_size - sizeof (struct tree_common));
3428 :
3429 14804869 : 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 14804869 : olddecl->decl_with_vis.symtab_node = snode;
3435 :
3436 14804869 : 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 629494 : reregister_specialization (newdecl,
3459 : new_template_info,
3460 : olddecl);
3461 : }
3462 : else
3463 : {
3464 536413 : size_t size = tree_code_size (TREE_CODE (newdecl));
3465 :
3466 536413 : 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 536413 : switch (TREE_CODE (newdecl))
3471 : {
3472 536413 : case LABEL_DECL:
3473 536413 : case VAR_DECL:
3474 536413 : case RESULT_DECL:
3475 536413 : case PARM_DECL:
3476 536413 : case FIELD_DECL:
3477 536413 : case TYPE_DECL:
3478 536413 : case CONST_DECL:
3479 536413 : {
3480 536413 : struct symtab_node *snode = NULL;
3481 :
3482 536413 : if (VAR_P (newdecl)
3483 536413 : && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl)
3484 3 : || DECL_EXTERNAL (olddecl)))
3485 489973 : snode = symtab_node::get (olddecl);
3486 536413 : memcpy ((char *) olddecl + sizeof (struct tree_decl_common),
3487 : (char *) newdecl + sizeof (struct tree_decl_common),
3488 : size - sizeof (struct tree_decl_common)
3489 536413 : + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *));
3490 536413 : if (VAR_P (newdecl))
3491 489973 : 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 15341282 : if (VAR_OR_FUNCTION_DECL_P (newdecl))
3504 : {
3505 15294842 : if (DECL_EXTERNAL (olddecl)
3506 491340 : || TREE_PUBLIC (olddecl)
3507 15294911 : || 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 15294842 : if (DECL_SECTION_NAME (newdecl) != NULL)
3514 7 : set_decl_section_name (olddecl, newdecl);
3515 :
3516 15294842 : 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 15294842 : if (VAR_P (newdecl)
3529 15294842 : && 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 15341282 : DECL_UID (olddecl) = olddecl_uid;
3538 :
3539 : /* NEWDECL contains the merged attribute lists.
3540 : Update OLDDECL to be the same. */
3541 15341282 : 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 15341282 : if (DECL_RTL_SET_P (olddecl)
3547 15341297 : && (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 15341282 : if (TREE_CODE (newdecl) == FUNCTION_DECL)
3561 14804869 : DECL_STRUCT_FUNCTION (newdecl) = NULL;
3562 15341282 : if (VAR_OR_FUNCTION_DECL_P (newdecl))
3563 : {
3564 15294842 : struct symtab_node *snode = symtab_node::get (newdecl);
3565 15294842 : if (snode)
3566 399 : snode->remove ();
3567 : }
3568 :
3569 15341282 : if (TREE_CODE (olddecl) == FUNCTION_DECL)
3570 : {
3571 14804869 : tree clone;
3572 15331145 : FOR_EACH_CLONE (clone, olddecl)
3573 : {
3574 526276 : DECL_ATTRIBUTES (clone) = DECL_ATTRIBUTES (olddecl);
3575 526276 : 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 15341282 : if (flag_concepts)
3582 15071257 : remove_constraints (newdecl);
3583 :
3584 15341282 : if (flag_contracts)
3585 : /* Remove the specifiers, and then remove the decl from the lookup. */
3586 959176 : remove_decl_with_fn_contracts_specifiers (newdecl);
3587 :
3588 : /* And similarly for any module tracking data. */
3589 15341282 : if (modules_p ())
3590 39815 : remove_defining_module (newdecl);
3591 :
3592 15341282 : ggc_free (newdecl);
3593 :
3594 15341282 : 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 15464794 : redeclaration_error_message (tree newdecl, tree olddecl)
3605 : {
3606 15464830 : 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 77761 : if (same_type_p (TREE_TYPE (newdecl), TREE_TYPE (olddecl)))
3612 : return NULL;
3613 : else
3614 : return G_("redefinition of %q#D");
3615 : }
3616 15387069 : 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 21986480 : if (DECL_LANG_SPECIFIC (olddecl) && DECL_PURE_VIRTUAL_P (olddecl)
3622 10993258 : && 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 21986450 : if (DECL_NAMESPACE_SCOPE_P (olddecl)
3628 2576352 : && DECL_CONTEXT (olddecl) != DECL_CONTEXT (newdecl)
3629 10993228 : && ! 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 10993225 : if (decl_defined_p (olddecl)
3637 10993225 : && 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 12694423 : if (DECL_DECLARED_INLINE_P (olddecl) && DECL_DECLARED_INLINE_P (newdecl))
3647 : {
3648 1652605 : bool olda = GNU_INLINE_P (olddecl);
3649 1652605 : bool newa = GNU_INLINE_P (newdecl);
3650 :
3651 1652605 : 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 10992988 : special_function_kind sfk = special_function_p (olddecl);
3666 10992988 : if (sfk == sfk_comparison && DECL_DEFAULTED_FN (newdecl))
3667 : return G_("comparison operator %q+D defaulted after "
3668 : "its first declaration");
3669 :
3670 10992985 : check_abi_tag_redeclaration
3671 10992985 : (olddecl, lookup_attribute ("abi_tag", DECL_ATTRIBUTES (olddecl)),
3672 10992985 : lookup_attribute ("abi_tag", DECL_ATTRIBUTES (newdecl)));
3673 :
3674 10992985 : return NULL;
3675 : }
3676 4393829 : else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
3677 : {
3678 3903490 : tree nt, ot;
3679 :
3680 3903490 : if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
3681 : return G_("redefinition of %q#D");
3682 :
3683 3903484 : 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 3903448 : if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
3688 : return NULL;
3689 :
3690 3903436 : nt = DECL_TEMPLATE_RESULT (newdecl);
3691 3903436 : if (DECL_TEMPLATE_INFO (nt))
3692 888871 : nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
3693 3903436 : ot = DECL_TEMPLATE_RESULT (olddecl);
3694 3903436 : if (DECL_TEMPLATE_INFO (ot))
3695 3903436 : ot = DECL_TEMPLATE_RESULT (template_for_substitution (ot));
3696 6597507 : if (DECL_INITIAL (nt) && DECL_INITIAL (ot)
3697 3903475 : && (!GNU_INLINE_P (ot) || GNU_INLINE_P (nt)))
3698 15 : return G_("redefinition of %q#D");
3699 :
3700 6286050 : if (DECL_DECLARED_INLINE_P (ot) && DECL_DECLARED_INLINE_P (nt))
3701 : {
3702 1725732 : bool olda = GNU_INLINE_P (ot);
3703 1725732 : bool newa = GNU_INLINE_P (nt);
3704 :
3705 1725732 : 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 3903421 : if ((cxx_dialect != cxx98)
3723 3885961 : && TREE_CODE (ot) == FUNCTION_DECL && DECL_UNIQUE_FRIEND_P (ot)
3724 4106257 : && !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 3903418 : return NULL;
3732 : }
3733 490339 : else if (VAR_P (newdecl)
3734 490255 : && (CP_DECL_THREAD_LOCAL_P (newdecl)
3735 490255 : != CP_DECL_THREAD_LOCAL_P (olddecl))
3736 490386 : && (! 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 490333 : 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 490100 : if ((VAR_P (newdecl) && DECL_ANON_UNION_VAR_P (newdecl))
3760 980269 : || (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 490166 : 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 2824 : if (cxx_dialect >= cxx17
3777 2749 : && VAR_P (olddecl)
3778 2693 : && DECL_CLASS_SCOPE_P (olddecl)
3779 2649 : && DECL_DECLARED_CONSTEXPR_P (olddecl)
3780 5461 : && !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 152 : 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 78527 : named_label_hash::hash (const value_type entry)
3815 : {
3816 78527 : return IDENTIFIER_HASH_VALUE (entry->name);
3817 : }
3818 :
3819 : bool
3820 75538 : named_label_hash::equal (const value_type entry, compare_type name)
3821 : {
3822 75538 : 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 24119 : lookup_label_1 (tree id, bool making_local_p)
3831 : {
3832 24119 : auto_cond_timevar tv (TV_NAME_LOOKUP);
3833 :
3834 : /* You can't use labels at global scope. */
3835 24119 : 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 24116 : if (!named_labels)
3842 4648 : named_labels = hash_table<named_label_hash>::create_ggc (13);
3843 :
3844 24116 : hashval_t hash = IDENTIFIER_HASH_VALUE (id);
3845 24116 : named_label_entry **slot
3846 24116 : = named_labels->find_slot_with_hash (id, hash, INSERT);
3847 24116 : named_label_entry *old = *slot;
3848 :
3849 24116 : if (old && old->label_decl)
3850 : {
3851 3458 : 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 20700 : named_label_entry *ent = NULL;
3865 33 : if (old && !old->label_decl)
3866 : ent = old;
3867 : else
3868 : {
3869 20667 : ent = ggc_cleared_alloc<named_label_entry> ();
3870 20667 : ent->name = id;
3871 20667 : ent->outer = old;
3872 20667 : *slot = ent;
3873 : }
3874 :
3875 : /* Now create the LABEL_DECL. */
3876 20679 : tree decl = build_decl (input_location, LABEL_DECL, id, void_type_node);
3877 :
3878 20679 : DECL_CONTEXT (decl) = current_function_decl;
3879 20679 : SET_DECL_MODE (decl, VOIDmode);
3880 20679 : 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 20679 : ent->label_decl = decl;
3888 :
3889 20679 : return ent;
3890 24119 : }
3891 :
3892 : /* Wrapper for lookup_label_1. */
3893 :
3894 : tree
3895 2952 : lookup_label (tree id)
3896 : {
3897 2952 : named_label_entry *ent = lookup_label_1 (id, false);
3898 2952 : 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 85071 : 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 85071 : tree type = TREE_TYPE (decl);
3929 :
3930 85071 : return (type != error_mark_node
3931 85053 : && VAR_P (decl)
3932 15025 : && !TREE_STATIC (decl)
3933 99960 : && (DECL_NONTRIVIALLY_INITIALIZED_P (decl)
3934 12975 : || 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 83148 : decl_instrument_init_bypass_p (tree decl)
3944 : {
3945 83148 : tree type = TREE_TYPE (decl);
3946 :
3947 83148 : return (flag_auto_var_init > AUTO_INIT_UNINITIALIZED
3948 5920 : && !processing_template_decl
3949 5674 : && type != error_mark_node
3950 5668 : && VAR_P (decl)
3951 1053 : && !TREE_STATIC (decl)
3952 1032 : && !DECL_EXTERNAL (decl)
3953 2036 : && !(DECL_NONTRIVIALLY_INITIALIZED_P (decl)
3954 1018 : || variably_modified_type_p (type, NULL_TREE))
3955 1018 : && !lookup_attribute (NULL, "indeterminate", DECL_ATTRIBUTES (decl))
3956 1018 : && !lookup_attribute ("uninitialized", DECL_ATTRIBUTES (decl))
3957 84166 : && !DECL_HAS_VALUE_EXPR_P (decl));
3958 : }
3959 :
3960 : /* Build .DEFERRED_INIT call for DECL. */
3961 :
3962 : static tree
3963 133 : build_deferred_init_call (tree decl)
3964 : {
3965 133 : tree decl_size_arg = TYPE_SIZE_UNIT (TREE_TYPE (decl));
3966 266 : tree init_type_arg = build_int_cst (integer_type_node,
3967 133 : (int) flag_auto_var_init);
3968 133 : location_t loc = DECL_SOURCE_LOCATION (decl);
3969 133 : tree decl_name;
3970 :
3971 133 : if (DECL_NAME (decl))
3972 133 : 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 133 : tree call = build_call_expr_internal_loc (loc, IFN_DEFERRED_INIT,
3981 133 : TREE_TYPE (decl), 3,
3982 : decl_size_arg, init_type_arg,
3983 : decl_name);
3984 133 : tree ret = build2_loc (loc, MODIFY_EXPR, void_type_node, decl, call);
3985 133 : 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 121 : maybe_add_deferred_init_calls (tree_stmt_iterator iter, tree case_label,
4007 : tree *decls, unsigned ndecls)
4008 : {
4009 121 : tree lab = NULL_TREE;
4010 185 : for (; !tsi_end_p (iter); tsi_prev (&iter))
4011 : {
4012 179 : 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 121 : if (!tsi_end_p (iter)
4024 115 : && TREE_CODE (tsi_stmt (iter)) == IF_STMT
4025 197 : && 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 70 : tree then_clause = THEN_CLAUSE (tsi_stmt (iter));
4036 70 : iter = tsi_last (then_clause);
4037 70 : bool add = false;
4038 378 : for (unsigned int i = 0; i < ndecls; ++i)
4039 : {
4040 308 : tree decl = decls[i];
4041 308 : if (!add)
4042 : {
4043 : /* Skip over labels/case labels after .DEFERRED_INIT for the
4044 : DECL we are looking for. */
4045 396 : while (!tsi_end_p (iter)
4046 396 : && (TREE_CODE (tsi_stmt (iter)) == LABEL_EXPR
4047 284 : || (TREE_CODE (tsi_stmt (iter)) == CASE_LABEL_EXPR
4048 25 : && !case_label)))
4049 118 : tsi_prev (&iter);
4050 278 : if (tsi_end_p (iter))
4051 : {
4052 : /* Reached the start, we'll need to prepend further
4053 : statements. */
4054 19 : add = true;
4055 19 : iter = tsi_start (then_clause);
4056 : }
4057 : else
4058 : {
4059 : /* Found something, assert it is .DEFERRED_INIT for
4060 : DECL. */
4061 259 : tree t = tsi_stmt (iter);
4062 259 : gcc_checking_assert (TREE_CODE (t) == EXPR_STMT);
4063 259 : t = EXPR_STMT_EXPR (t);
4064 259 : 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 259 : t = TREE_OPERAND (t, 1);
4069 259 : gcc_checking_assert (CALL_EXPR_FN (t) == NULL_TREE
4070 : && (CALL_EXPR_IFN (t)
4071 : == IFN_DEFERRED_INIT));
4072 259 : tsi_prev (&iter);
4073 : }
4074 : }
4075 278 : if (add)
4076 : {
4077 : /* If reached the start in this or some earlier iteration,
4078 : prepend .DEFERRED_INIT call for DECL. */
4079 49 : tree t = build_deferred_init_call (decl);
4080 49 : STMT_IS_FULL_EXPR_P (t) = 1;
4081 49 : tsi_link_before (&iter, t, TSI_CONTINUE_LINKING);
4082 : }
4083 : }
4084 70 : 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 49 : tree t;
4118 49 : if (case_label)
4119 : t = case_label;
4120 : else
4121 : {
4122 40 : lab = create_artificial_label (UNKNOWN_LOCATION);
4123 40 : t = build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab);
4124 : }
4125 49 : 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 51 : tree new_then = push_stmt_list ();
4134 51 : if (!case_label)
4135 : {
4136 22 : lab = create_artificial_label (UNKNOWN_LOCATION);
4137 22 : add_stmt (build_stmt (UNKNOWN_LOCATION, LABEL_EXPR, lab));
4138 : }
4139 : else
4140 29 : add_stmt (case_label);
4141 135 : for (unsigned int i = ndecls; i; --i)
4142 84 : add_stmt (build_deferred_init_call (decls[i - 1]));
4143 51 : new_then = pop_stmt_list (new_then);
4144 51 : tree stmt = build4 (IF_STMT, void_type_node, boolean_false_node,
4145 : new_then, void_node, NULL_TREE);
4146 51 : IF_STMT_VACUOUS_INIT_P (stmt) = 1;
4147 51 : 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 45 : tsi_link_after (&iter, stmt, TSI_CONTINUE_LINKING);
4154 : }
4155 121 : 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 : bool complained
4201 373 : = emit_diagnostic (diag_kind, loc, 0,
4202 : decl ? G_("jump to label %qD")
4203 : : G_("jump to case label"), decl);
4204 286 : if (complained && locus)
4205 : {
4206 199 : if (computed)
4207 43 : inform (*locus, " as a possible target of computed goto");
4208 : else
4209 156 : inform (*locus, " from here");
4210 : }
4211 286 : return complained;
4212 : }
4213 :
4214 : /* Check that a single previously seen jump to a newly defined label
4215 : is OK. DECL is the LABEL_DECL or 0; LEVEL is the binding_level for
4216 : the jump context; NAMES are the names in scope in LEVEL at the jump
4217 : context; LOCUS is the source position of the jump or 0. COMPUTED
4218 : is a vec of decls if the jump is a computed goto. DIRECT_GOTO is a
4219 : vec of pointers to LABEL_DECLs that might need adjusting if vacuous
4220 : initializations are crossed for !!flag_auto_var_init. CASE_LABEL is
4221 : CASE_LABEL_EXPR to be moved if needed for the check_switch_goto case.
4222 : Returns non-zero if all is well, 2 if any vacuous initializers were
4223 : crossed. */
4224 :
4225 : static int
4226 1451264 : check_previous_goto_1 (tree decl, cp_binding_level *level, tree names,
4227 : bool exited_omp, const location_t *locus,
4228 : vec<tree, va_gc> *computed,
4229 : vec<named_label_fwd_direct_goto, va_gc> *direct_goto,
4230 : tree case_label)
4231 : {
4232 1451264 : auto_diagnostic_group d;
4233 1451264 : cp_binding_level *b;
4234 1451264 : bool complained = false;
4235 1451264 : int identified = 0;
4236 1451264 : bool saw_eh = false, saw_omp = false, saw_tm = false, saw_cxif = false;
4237 1451264 : bool saw_ceif = false, saw_se = false;
4238 1451264 : auto_vec<tree> vacuous_decls;
4239 1451264 : bool vacuous_inits = false;
4240 :
4241 1451264 : if (exited_omp)
4242 : {
4243 12 : complained = identify_goto (decl, input_location, locus,
4244 : diagnostics::kind::error,
4245 : computed);
4246 12 : if (complained)
4247 12 : inform (input_location, " exits OpenMP structured block");
4248 : saw_omp = true;
4249 : identified = 2;
4250 : }
4251 :
4252 4324754 : for (b = current_binding_level; b ; b = b->level_chain)
4253 : {
4254 2873490 : tree new_decls, old_decls = (b == level ? names : NULL_TREE);
4255 :
4256 2953387 : for (new_decls = b->names; new_decls != old_decls;
4257 149118 : new_decls = (DECL_P (new_decls) ? DECL_CHAIN (new_decls)
4258 69221 : : TREE_CHAIN (new_decls)))
4259 : {
4260 79897 : bool problem = decl_jump_unsafe (new_decls);
4261 79897 : if (! problem)
4262 : {
4263 79852 : if (decl_instrument_init_bypass_p (new_decls))
4264 : {
4265 311 : if (direct_goto || case_label)
4266 246 : vacuous_decls.safe_push (new_decls);
4267 : vacuous_inits = true;
4268 : }
4269 79852 : continue;
4270 : }
4271 :
4272 45 : if (!identified)
4273 : {
4274 45 : complained = identify_goto (decl, input_location, locus,
4275 : diagnostics::kind::error,
4276 : computed);
4277 45 : identified = 2;
4278 : }
4279 45 : if (complained)
4280 45 : inform (DECL_SOURCE_LOCATION (new_decls),
4281 : " crosses initialization of %q#D", new_decls);
4282 : }
4283 :
4284 2873490 : if (b == level)
4285 : break;
4286 :
4287 1422226 : const char *inf = NULL;
4288 1422226 : location_t loc = input_location;
4289 1422226 : switch (b->kind)
4290 : {
4291 3 : case sk_try:
4292 3 : if (!saw_eh)
4293 : inf = G_(" enters %<try%> block");
4294 : saw_eh = true;
4295 : break;
4296 :
4297 9 : case sk_catch:
4298 9 : if (!saw_eh)
4299 : inf = G_(" enters %<catch%> block");
4300 : saw_eh = true;
4301 : break;
4302 :
4303 102 : case sk_omp:
4304 102 : if (!saw_omp)
4305 : inf = G_(" enters OpenMP structured block");
4306 : saw_omp = true;
4307 : break;
4308 :
4309 3 : case sk_transaction:
4310 3 : if (!saw_tm)
4311 : inf = G_(" enters synchronized or atomic statement");
4312 : saw_tm = true;
4313 : break;
4314 :
4315 18 : case sk_stmt_expr:
4316 18 : if (!saw_se)
4317 : inf = G_(" enters statement expression");
4318 : saw_se = true;
4319 : break;
4320 :
4321 1421956 : case sk_block:
4322 1421956 : if (!saw_cxif && level_for_constexpr_if (b->level_chain))
4323 : {
4324 9 : inf = G_(" enters %<constexpr if%> statement");
4325 9 : loc = EXPR_LOCATION (b->level_chain->this_entity);
4326 : saw_cxif = true;
4327 : }
4328 1421947 : else if (!saw_ceif && level_for_consteval_if (b->level_chain))
4329 : {
4330 18 : inf = G_(" enters %<consteval if%> statement");
4331 18 : loc = EXPR_LOCATION (b->level_chain->this_entity);
4332 : saw_ceif = true;
4333 : }
4334 : break;
4335 :
4336 : default:
4337 : break;
4338 : }
4339 :
4340 : if (inf)
4341 : {
4342 141 : if (identified < 2)
4343 141 : complained = identify_goto (decl, input_location, locus,
4344 : diagnostics::kind::error,
4345 : computed);
4346 141 : identified = 2;
4347 141 : if (complained)
4348 141 : inform (loc, inf);
4349 : }
4350 : }
4351 :
4352 1451264 : if (!vec_safe_is_empty (computed))
4353 : {
4354 9 : if (!identified)
4355 6 : complained = identify_goto (decl, input_location, locus,
4356 : diagnostics::kind::error,
4357 : computed);
4358 9 : identified = 2;
4359 9 : if (complained)
4360 18 : for (tree d : computed)
4361 : {
4362 9 : if (DECL_P (d))
4363 6 : inform (DECL_SOURCE_LOCATION (d), " does not destroy %qD", d);
4364 3 : else if (d == get_identifier ("catch"))
4365 3 : inform (*locus, " does not clean up handled exception");
4366 : }
4367 : }
4368 :
4369 1451347 : if (!vacuous_decls.is_empty () && !seen_error ())
4370 : {
4371 81 : tree_stmt_iterator iter = tsi_last (cur_stmt_list);
4372 81 : if (case_label)
4373 : {
4374 38 : gcc_checking_assert (tsi_stmt (iter) == case_label);
4375 38 : tsi_delink (&iter);
4376 38 : iter = tsi_last (cur_stmt_list);
4377 : }
4378 81 : tree lab = maybe_add_deferred_init_calls (iter, case_label,
4379 : vacuous_decls.address (),
4380 : vacuous_decls.length ());
4381 81 : if (lab)
4382 : {
4383 : unsigned int i;
4384 : named_label_fwd_direct_goto *dgoto;
4385 167 : FOR_EACH_VEC_SAFE_ELT (direct_goto, i, dgoto)
4386 43 : *dgoto->direct_goto = lab;
4387 : }
4388 : }
4389 :
4390 1451264 : if (identified)
4391 : return 0;
4392 1451060 : return vacuous_inits ? 2 : 1;
4393 1451264 : }
4394 :
4395 : static void
4396 2106 : check_previous_goto (tree decl, struct named_label_use_entry *use)
4397 : {
4398 2106 : check_previous_goto_1 (decl, use->binding_level,
4399 2106 : use->names_in_scope, use->in_omp_scope,
4400 2106 : &use->o_goto_locus, use->computed_goto,
4401 : use->direct_goto, NULL_TREE);
4402 2106 : vec_free (use->direct_goto);
4403 2106 : }
4404 :
4405 : static int
4406 1449158 : check_switch_goto (cp_binding_level *level, tree case_label)
4407 : {
4408 1449158 : return check_previous_goto_1 (NULL_TREE, level, level->names,
4409 1449158 : false, NULL, nullptr, nullptr, case_label);
4410 : }
4411 :
4412 : /* Check that a new jump to a label ENT is OK. DECLP is a pointer
4413 : to a LABEL_DECL for direct gotos and NULL for computed gotos. */
4414 :
4415 : void
4416 2830 : check_goto_1 (named_label_entry *ent, tree *declp)
4417 : {
4418 2830 : auto_diagnostic_group d;
4419 2830 : tree decl = ent->label_decl;
4420 2830 : bool computed = declp == NULL;
4421 :
4422 : /* If the label hasn't been defined yet, defer checking. */
4423 2830 : if (! DECL_INITIAL (decl))
4424 : {
4425 : /* Don't bother creating another use if the last goto had the
4426 : same data, and will therefore create the same set of errors. */
4427 2175 : if (ent->uses
4428 658 : && ent->uses->binding_level == current_binding_level
4429 60 : && ent->uses->names_in_scope == current_binding_level->names)
4430 : {
4431 60 : if (declp
4432 54 : && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
4433 11 : && !processing_template_decl)
4434 9 : vec_safe_push (ent->uses->direct_goto,
4435 9 : named_label_fwd_direct_goto { declp });
4436 60 : return;
4437 : }
4438 :
4439 2115 : named_label_use_entry *new_use
4440 2115 : = ggc_alloc<named_label_use_entry> ();
4441 2115 : new_use->binding_level = current_binding_level;
4442 2115 : new_use->names_in_scope = current_binding_level->names;
4443 2115 : new_use->o_goto_locus = input_location;
4444 2115 : new_use->in_omp_scope = false;
4445 2115 : new_use->computed_goto = computed ? make_tree_vector () : nullptr;
4446 2115 : new_use->direct_goto = nullptr;
4447 2115 : if (declp
4448 2024 : && flag_auto_var_init > AUTO_INIT_UNINITIALIZED
4449 355 : && !processing_template_decl)
4450 298 : vec_safe_push (new_use->direct_goto,
4451 298 : named_label_fwd_direct_goto { declp });
4452 :
4453 2115 : new_use->next = ent->uses;
4454 2115 : ent->uses = new_use;
4455 2115 : return;
4456 : }
4457 :
4458 655 : bool saw_catch = false, complained = false;
4459 655 : int identified = 0;
4460 655 : tree bad;
4461 655 : unsigned ix;
4462 655 : unsigned n_bad_decls = 0;
4463 :
4464 655 : if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
4465 640 : || ent->in_constexpr_if || ent->in_consteval_if
4466 634 : || ent->in_omp_scope || ent->in_stmt_expr
4467 616 : || ent->has_bad_decls)
4468 : {
4469 45 : enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
4470 45 : if (ent->in_try_scope || ent->in_catch_scope || ent->in_constexpr_if
4471 30 : || ent->in_consteval_if || ent->in_transaction_scope
4472 24 : || ent->in_omp_scope || ent->in_stmt_expr)
4473 39 : diag_kind = diagnostics::kind::error;
4474 45 : complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4475 : &input_location, diag_kind, computed);
4476 45 : identified = 1 + (diag_kind == diagnostics::kind::error);
4477 : }
4478 :
4479 845 : FOR_EACH_VEC_SAFE_ELT (ent->bad_decls, ix, bad)
4480 : {
4481 190 : bool problem = decl_jump_unsafe (bad);
4482 190 : if (!problem)
4483 : {
4484 184 : gcc_checking_assert (decl_instrument_init_bypass_p (bad));
4485 184 : n_bad_decls++;
4486 184 : continue;
4487 : }
4488 :
4489 6 : if (DECL_ARTIFICIAL (bad))
4490 : {
4491 : /* Can't skip init of __exception_info. */
4492 0 : if (identified == 1)
4493 : {
4494 0 : complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4495 : &input_location,
4496 : diagnostics::kind::error,
4497 : computed);
4498 0 : identified = 2;
4499 : }
4500 0 : if (complained)
4501 0 : inform (DECL_SOURCE_LOCATION (bad), " enters %<catch%> block");
4502 : saw_catch = true;
4503 : }
4504 6 : else if (complained)
4505 6 : inform (DECL_SOURCE_LOCATION (bad),
4506 : " skips initialization of %q#D", bad);
4507 : }
4508 :
4509 655 : if (complained)
4510 : {
4511 45 : if (ent->in_try_scope)
4512 9 : inform (input_location, " enters %<try%> block");
4513 36 : else if (ent->in_catch_scope && !saw_catch)
4514 3 : inform (input_location, " enters %<catch%> block");
4515 33 : else if (ent->in_transaction_scope)
4516 3 : inform (input_location, " enters synchronized or atomic statement");
4517 30 : else if (ent->in_constexpr_if)
4518 3 : inform (input_location, " enters %<constexpr if%> statement");
4519 27 : else if (ent->in_consteval_if)
4520 3 : inform (input_location, " enters %<consteval if%> statement");
4521 24 : else if (ent->in_stmt_expr)
4522 15 : inform (input_location, " enters statement expression");
4523 : }
4524 :
4525 655 : if (ent->in_omp_scope)
4526 : {
4527 3 : if (complained)
4528 3 : inform (input_location, " enters OpenMP structured block");
4529 : }
4530 652 : else if (flag_openmp)
4531 69 : for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
4532 : {
4533 42 : if (b == ent->binding_level)
4534 : break;
4535 36 : if (b->kind == sk_omp)
4536 : {
4537 21 : if (identified < 2)
4538 : {
4539 42 : complained = identify_goto (decl,
4540 21 : DECL_SOURCE_LOCATION (decl),
4541 : &input_location,
4542 : diagnostics::kind::error,
4543 : computed);
4544 21 : identified = 2;
4545 : }
4546 21 : if (complained)
4547 21 : inform (input_location, " exits OpenMP structured block");
4548 : break;
4549 : }
4550 : }
4551 :
4552 : /* Warn if a computed goto might involve a local variable going out of scope
4553 : without being cleaned up. */
4554 655 : if (computed)
4555 : {
4556 71 : auto level = ent->binding_level;
4557 71 : auto names = ent->names_in_scope;
4558 71 : for (auto b = current_binding_level; ; b = b->level_chain)
4559 : {
4560 111 : if (b->kind == sk_catch)
4561 : {
4562 6 : if (!identified)
4563 : {
4564 6 : complained
4565 6 : = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4566 : &input_location, diagnostics::kind::error,
4567 : computed);
4568 6 : identified = 2;
4569 : }
4570 6 : if (complained)
4571 6 : inform (input_location,
4572 : " does not clean up handled exception");
4573 : }
4574 111 : tree end = b == level ? names : NULL_TREE;
4575 127 : for (tree d = b->names; d != end; d = DECL_CHAIN (d))
4576 : {
4577 16 : if (automatic_var_with_nontrivial_dtor_p (d))
4578 : {
4579 10 : if (!identified)
4580 : {
4581 10 : complained
4582 10 : = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
4583 : &input_location, diagnostics::kind::error,
4584 : computed);
4585 10 : identified = 2;
4586 : }
4587 10 : if (complained)
4588 10 : inform (DECL_SOURCE_LOCATION (d),
4589 : " does not destroy %qD", d);
4590 : }
4591 : }
4592 111 : if (b == level)
4593 : break;
4594 40 : }
4595 : }
4596 :
4597 655 : if (n_bad_decls && declp)
4598 46 : vec_safe_push (ent->direct_goto,
4599 46 : named_label_bck_direct_goto { declp, n_bad_decls });
4600 2830 : }
4601 :
4602 : /* Check that a new jump to a label *DECLP is OK. Called by
4603 : finish_goto_stmt. */
4604 :
4605 : void
4606 2790 : check_goto (tree *declp)
4607 : {
4608 2790 : if (!named_labels)
4609 : return;
4610 2775 : tree decl = *declp;
4611 2775 : if (TREE_CODE (decl) != LABEL_DECL)
4612 : {
4613 : /* We don't know where a computed goto is jumping,
4614 : so check all addressable labels. */
4615 312 : for (auto iter = named_labels->begin ();
4616 425 : iter != named_labels->end ();
4617 199 : ++iter)
4618 : {
4619 199 : auto ent = *iter;
4620 199 : if (ent->addressed)
4621 168 : check_goto_1 (ent, NULL);
4622 : }
4623 : }
4624 : else
4625 : {
4626 2662 : hashval_t hash = IDENTIFIER_HASH_VALUE (DECL_NAME (decl));
4627 2662 : named_label_entry **slot
4628 2662 : = named_labels->find_slot_with_hash (DECL_NAME (decl), hash, NO_INSERT);
4629 2662 : named_label_entry *ent = *slot;
4630 2662 : check_goto_1 (ent, declp);
4631 : }
4632 : }
4633 :
4634 : /* Check that a return is ok wrt OpenMP structured blocks.
4635 : Called by finish_return_stmt. Returns true if all is well. */
4636 :
4637 : bool
4638 278608 : check_omp_return (void)
4639 : {
4640 1105074 : for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
4641 826466 : if (b->kind == sk_omp)
4642 : {
4643 15 : error ("invalid exit from OpenMP structured block");
4644 15 : return false;
4645 : }
4646 826451 : else if (b->kind == sk_function_parms)
4647 : break;
4648 : return true;
4649 : }
4650 :
4651 : /* Define a label, specifying the location in the source file.
4652 : Return the LABEL_DECL node for the label. */
4653 :
4654 : tree
4655 20676 : define_label (location_t location, tree name)
4656 : {
4657 20676 : auto_cond_timevar tv (TV_NAME_LOOKUP);
4658 :
4659 : /* After labels, make any new cleanups in the function go into their
4660 : own new (temporary) binding contour. */
4661 20676 : for (cp_binding_level *p = current_binding_level;
4662 31316 : p->kind != sk_function_parms;
4663 10640 : p = p->level_chain)
4664 10640 : p->more_cleanups_ok = 0;
4665 :
4666 20676 : named_label_entry *ent = lookup_label_1 (name, false);
4667 20676 : tree decl = ent->label_decl;
4668 :
4669 20676 : if (DECL_INITIAL (decl) != NULL_TREE)
4670 : {
4671 6 : error ("duplicate label %qD", decl);
4672 6 : return error_mark_node;
4673 : }
4674 : else
4675 : {
4676 : /* Mark label as having been defined. */
4677 20670 : DECL_INITIAL (decl) = error_mark_node;
4678 : /* Say where in the source. */
4679 20670 : DECL_SOURCE_LOCATION (decl) = location;
4680 :
4681 20670 : ent->binding_level = current_binding_level;
4682 20670 : ent->names_in_scope = current_binding_level->names;
4683 :
4684 22776 : for (named_label_use_entry *use = ent->uses; use; use = use->next)
4685 2106 : check_previous_goto (decl, use);
4686 20670 : ent->uses = NULL;
4687 : }
4688 :
4689 20670 : return decl;
4690 20676 : }
4691 :
4692 : struct cp_switch
4693 : {
4694 : cp_binding_level *level;
4695 : struct cp_switch *next;
4696 : /* The SWITCH_STMT being built. */
4697 : tree switch_stmt;
4698 : /* A splay-tree mapping the low element of a case range to the high
4699 : element, or NULL_TREE if there is no high element. Used to
4700 : determine whether or not a new case label duplicates an old case
4701 : label. We need a tree, rather than simply a hash table, because
4702 : of the GNU case range extension. */
4703 : splay_tree cases;
4704 : /* Remember whether a default: case label has been seen. */
4705 : bool has_default_p;
4706 : /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT. */
4707 : bool break_stmt_seen_p;
4708 : /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
4709 : where BREAK_STMT doesn't belong to the SWITCH_STMT. */
4710 : bool in_loop_body_p;
4711 : };
4712 :
4713 : /* A stack of the currently active switch statements. The innermost
4714 : switch statement is on the top of the stack. There is no need to
4715 : mark the stack for garbage collection because it is only active
4716 : during the processing of the body of a function, and we never
4717 : collect at that point. */
4718 :
4719 : static struct cp_switch *switch_stack;
4720 :
4721 : /* Called right after a switch-statement condition is parsed.
4722 : SWITCH_STMT is the switch statement being parsed. */
4723 :
4724 : void
4725 667189 : push_switch (tree switch_stmt)
4726 : {
4727 667189 : struct cp_switch *p = XNEW (struct cp_switch);
4728 667189 : p->level = current_binding_level;
4729 667189 : p->next = switch_stack;
4730 667189 : p->switch_stmt = switch_stmt;
4731 667189 : p->cases = splay_tree_new (case_compare, NULL, NULL);
4732 667189 : p->has_default_p = false;
4733 667189 : p->break_stmt_seen_p = false;
4734 667189 : p->in_loop_body_p = false;
4735 667189 : switch_stack = p;
4736 667189 : }
4737 :
4738 : void
4739 667189 : pop_switch (void)
4740 : {
4741 667189 : struct cp_switch *cs = switch_stack;
4742 :
4743 : /* Emit warnings as needed. */
4744 667189 : location_t switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
4745 667189 : tree cond = SWITCH_STMT_COND (cs->switch_stmt);
4746 667189 : const bool bool_cond_p
4747 667189 : = (SWITCH_STMT_TYPE (cs->switch_stmt)
4748 667189 : && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
4749 667189 : if (!processing_template_decl)
4750 259358 : c_do_switch_warnings (cs->cases, switch_location,
4751 259358 : SWITCH_STMT_TYPE (cs->switch_stmt), cond,
4752 : bool_cond_p);
4753 :
4754 : /* For the benefit of block_may_fallthru remember if the switch body
4755 : case labels cover all possible values and if there are break; stmts. */
4756 667189 : if (cs->has_default_p
4757 667189 : || (!processing_template_decl
4758 39334 : && c_switch_covers_all_cases_p (cs->cases,
4759 39334 : SWITCH_STMT_TYPE (cs->switch_stmt))))
4760 487424 : SWITCH_STMT_ALL_CASES_P (cs->switch_stmt) = 1;
4761 667189 : if (!cs->break_stmt_seen_p)
4762 337639 : SWITCH_STMT_NO_BREAK_P (cs->switch_stmt) = 1;
4763 : /* Now that we're done with the switch warnings, set the switch type
4764 : to the type of the condition if the index type was of scoped enum type.
4765 : (Such types don't participate in the integer promotions.) We do this
4766 : because of bit-fields whose declared type is a scoped enum type:
4767 : gimplification will use the lowered index type, but convert the
4768 : case values to SWITCH_STMT_TYPE, which would have been the declared type
4769 : and verify_gimple_switch doesn't accept that. */
4770 667189 : if (is_bitfield_expr_with_lowered_type (cond))
4771 21074 : SWITCH_STMT_TYPE (cs->switch_stmt) = TREE_TYPE (cond);
4772 667189 : gcc_assert (!cs->in_loop_body_p);
4773 667189 : splay_tree_delete (cs->cases);
4774 667189 : switch_stack = switch_stack->next;
4775 667189 : free (cs);
4776 667189 : }
4777 :
4778 : /* Note that a BREAK_STMT is about to be added. If it is inside of
4779 : a SWITCH_STMT and not inside of a loop body inside of it, note
4780 : in switch_stack we've seen a BREAK_STMT. */
4781 :
4782 : void
4783 4634005 : note_break_stmt (void)
4784 : {
4785 4634005 : if (switch_stack && !switch_stack->in_loop_body_p)
4786 2585924 : switch_stack->break_stmt_seen_p = true;
4787 4634005 : }
4788 :
4789 : /* Note the start of processing of an iteration statement's body.
4790 : The note_break_stmt function will do nothing while processing it.
4791 : Return a flag that should be passed to note_iteration_stmt_body_end. */
4792 :
4793 : bool
4794 17482312 : note_iteration_stmt_body_start (void)
4795 : {
4796 17482312 : if (!switch_stack)
4797 : return false;
4798 182084 : bool ret = switch_stack->in_loop_body_p;
4799 182084 : switch_stack->in_loop_body_p = true;
4800 182084 : return ret;
4801 : }
4802 :
4803 : /* Note the end of processing of an iteration statement's body. */
4804 :
4805 : void
4806 17482312 : note_iteration_stmt_body_end (bool prev)
4807 : {
4808 17482312 : if (switch_stack)
4809 182084 : switch_stack->in_loop_body_p = prev;
4810 17482312 : }
4811 :
4812 : /* Convert a case constant VALUE in a switch to the type TYPE of the switch
4813 : condition. Note that if TYPE and VALUE are already integral we don't
4814 : really do the conversion because the language-independent
4815 : warning/optimization code will work better that way. */
4816 :
4817 : static tree
4818 2897992 : case_conversion (tree type, tree value)
4819 : {
4820 2897992 : if (value == NULL_TREE)
4821 : return value;
4822 :
4823 1229140 : value = mark_rvalue_use (value);
4824 :
4825 1229140 : if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
4826 950644 : type = type_promotes_to (type);
4827 :
4828 1229140 : tree ovalue = value;
4829 : /* The constant-expression VALUE shall be a converted constant expression
4830 : of the adjusted type of the switch condition, which doesn't allow
4831 : narrowing conversions. */
4832 1229140 : value = build_converted_constant_expr (type, value, tf_warning_or_error);
4833 :
4834 1229140 : if (cxx_dialect >= cxx11
4835 1229140 : && (SCOPED_ENUM_P (type)
4836 947523 : || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
4837 : /* Use the converted value. */;
4838 : else
4839 : /* The already integral case. */
4840 : value = ovalue;
4841 :
4842 1229140 : return cxx_constant_value (value);
4843 : }
4844 :
4845 : /* Note that we've seen a definition of a case label, and complain if this
4846 : is a bad place for one. */
4847 :
4848 : tree
4849 5320729 : finish_case_label (location_t loc, tree low_value, tree high_value)
4850 : {
4851 5320729 : tree cond, r;
4852 5320729 : cp_binding_level *p;
4853 5320729 : tree type;
4854 :
4855 5320729 : if (low_value == NULL_TREE && high_value == NULL_TREE)
4856 487388 : switch_stack->has_default_p = true;
4857 :
4858 5320729 : if (processing_template_decl)
4859 : {
4860 3871610 : tree label;
4861 :
4862 : /* For templates, just add the case label; we'll do semantic
4863 : analysis at instantiation-time. But diagnose case labels
4864 : in expansion statements with switch outside of it here. */
4865 3871610 : if (in_expansion_stmt)
4866 39 : for (cp_binding_level *b = current_binding_level;
4867 78 : b != switch_stack->level; b = b->level_chain)
4868 63 : if (b->kind == sk_template_for && b->this_entity)
4869 : {
4870 24 : auto_diagnostic_group d;
4871 24 : error ("jump to case label");
4872 24 : inform (EXPR_LOCATION (b->this_entity),
4873 : " enters %<template for%> statement");
4874 24 : return error_mark_node;
4875 24 : }
4876 3871586 : label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
4877 3871586 : return add_stmt (build_case_label (low_value, high_value, label));
4878 : }
4879 :
4880 : /* Find the condition on which this switch statement depends. */
4881 1449119 : cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
4882 1449119 : if (cond && TREE_CODE (cond) == TREE_LIST)
4883 0 : cond = TREE_VALUE (cond);
4884 :
4885 1449119 : int chk_switch_goto = check_switch_goto (switch_stack->level, NULL_TREE);
4886 1449119 : if (!chk_switch_goto)
4887 87 : return error_mark_node;
4888 :
4889 1449032 : type = SWITCH_STMT_TYPE (switch_stack->switch_stmt);
4890 1449032 : if (type == error_mark_node)
4891 : return error_mark_node;
4892 :
4893 1448996 : low_value = case_conversion (type, low_value);
4894 1448996 : high_value = case_conversion (type, high_value);
4895 :
4896 1448996 : r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
4897 :
4898 1448996 : if (r != error_mark_node && chk_switch_goto == 2)
4899 39 : check_switch_goto (switch_stack->level, r);
4900 :
4901 : /* After labels, make any new cleanups in the function go into their
4902 : own new (temporary) binding contour. */
4903 1448996 : for (p = current_binding_level;
4904 6141543 : p->kind != sk_function_parms;
4905 4692547 : p = p->level_chain)
4906 4692547 : p->more_cleanups_ok = 0;
4907 :
4908 : return r;
4909 : }
4910 :
4911 : struct typename_info {
4912 : tree scope;
4913 : tree name;
4914 : tree template_id;
4915 : tag_types tag_type;
4916 : };
4917 :
4918 : struct typename_hasher : ggc_ptr_hash<tree_node>
4919 : {
4920 : typedef typename_info *compare_type;
4921 :
4922 : /* Hash a TYPENAME_TYPE. */
4923 :
4924 : static hashval_t
4925 429350849 : hash (tree context, tree fullname)
4926 : {
4927 429350849 : hashval_t hash = 0;
4928 429350849 : hash = iterative_hash_object (context, hash);
4929 429350849 : hash = iterative_hash_object (fullname, hash);
4930 429350849 : return hash;
4931 : }
4932 :
4933 : static hashval_t
4934 60761911 : hash (const typename_info *ti)
4935 : {
4936 60761911 : return typename_hasher::hash (ti->scope, ti->template_id);
4937 : }
4938 :
4939 : static hashval_t
4940 368588938 : hash (tree t)
4941 : {
4942 368588938 : return typename_hasher::hash (TYPE_CONTEXT (t), TYPENAME_TYPE_FULLNAME (t));
4943 : }
4944 :
4945 : /* Compare two TYPENAME_TYPEs. */
4946 :
4947 : static bool
4948 435070626 : equal (tree t1, const typename_info *t2)
4949 : {
4950 435070626 : return (TYPE_IDENTIFIER (t1) == t2->name
4951 139122535 : && TYPE_CONTEXT (t1) == t2->scope
4952 30913506 : && TYPENAME_TYPE_FULLNAME (t1) == t2->template_id
4953 465972463 : && get_typename_tag (t1) == t2->tag_type);
4954 : }
4955 : };
4956 :
4957 : /* Build a TYPENAME_TYPE. If the type is `typename T::t', CONTEXT is
4958 : the type of `T', NAME is the IDENTIFIER_NODE for `t'.
4959 :
4960 : Returns the new TYPENAME_TYPE. */
4961 :
4962 : static GTY (()) hash_table<typename_hasher> *typename_htab;
4963 :
4964 : tree
4965 60761911 : build_typename_type (tree context, tree name, tree fullname,
4966 : enum tag_types tag_type)
4967 : {
4968 60761911 : typename_info ti;
4969 :
4970 60761911 : if (typename_htab == NULL)
4971 19110 : typename_htab = hash_table<typename_hasher>::create_ggc (61);
4972 :
4973 60761911 : ti.scope = FROB_CONTEXT (context);
4974 60761911 : ti.name = name;
4975 60761911 : ti.template_id = fullname;
4976 60761911 : ti.tag_type = tag_type;
4977 60761911 : hashval_t hash = typename_hasher::hash (&ti);
4978 :
4979 : /* See if we already have this type. */
4980 60761911 : tree *e = typename_htab->find_slot_with_hash (&ti, hash, INSERT);
4981 60761911 : tree t = *e;
4982 60761911 : if (*e)
4983 : t = *e;
4984 : else
4985 : {
4986 : /* Build the TYPENAME_TYPE. */
4987 30906072 : t = cxx_make_type (TYPENAME_TYPE);
4988 30906072 : TYPE_CONTEXT (t) = ti.scope;
4989 30906072 : TYPENAME_TYPE_FULLNAME (t) = ti.template_id;
4990 30906072 : set_typename_tag (t, ti.tag_type);
4991 :
4992 : /* Build the corresponding TYPE_DECL. */
4993 30906072 : tree d = build_decl (input_location, TYPE_DECL, name, t);
4994 30906072 : TYPE_NAME (t) = d;
4995 30906072 : TYPE_STUB_DECL (t) = d;
4996 30906072 : DECL_CONTEXT (d) = ti.scope;
4997 30906072 : DECL_ARTIFICIAL (d) = 1;
4998 :
4999 : /* Store it in the hash table. */
5000 30906072 : *e = t;
5001 :
5002 : /* TYPENAME_TYPEs must always be compared structurally, because
5003 : they may or may not resolve down to another type depending on
5004 : the currently open classes. */
5005 30906072 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5006 : }
5007 :
5008 60761911 : return t;
5009 : }
5010 :
5011 : /* Resolve `typename CONTEXT::NAME'. TAG_TYPE indicates the tag
5012 : provided to name the type. Returns an appropriate type, unless an
5013 : error occurs, in which case error_mark_node is returned. If we
5014 : locate a non-artificial TYPE_DECL and TF_KEEP_TYPE_DECL is set, we
5015 : return that, rather than the _TYPE it corresponds to, in other
5016 : cases we look through the type decl. If TF_ERROR is set, complain
5017 : about errors, otherwise be quiet. */
5018 :
5019 : tree
5020 252730216 : make_typename_type (tree context, tree name, enum tag_types tag_type,
5021 : tsubst_flags_t complain)
5022 : {
5023 252730216 : tree fullname;
5024 252730216 : tree t;
5025 252730216 : bool want_template;
5026 :
5027 252730216 : if (name == error_mark_node
5028 252730210 : || context == NULL_TREE
5029 252730210 : || context == error_mark_node)
5030 : return error_mark_node;
5031 :
5032 252730194 : if (TYPE_P (name))
5033 : {
5034 0 : if (!(TYPE_LANG_SPECIFIC (name)
5035 0 : && (CLASSTYPE_IS_TEMPLATE (name)
5036 0 : || CLASSTYPE_USE_TEMPLATE (name))))
5037 0 : name = TYPE_IDENTIFIER (name);
5038 : else
5039 : /* Create a TEMPLATE_ID_EXPR for the type. */
5040 0 : name = build_nt (TEMPLATE_ID_EXPR,
5041 0 : CLASSTYPE_TI_TEMPLATE (name),
5042 0 : CLASSTYPE_TI_ARGS (name));
5043 : }
5044 252730194 : else if (TREE_CODE (name) == TYPE_DECL)
5045 0 : name = DECL_NAME (name);
5046 :
5047 252730194 : fullname = name;
5048 :
5049 252730194 : if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
5050 : {
5051 4986391 : name = TREE_OPERAND (name, 0);
5052 4986391 : if (DECL_TYPE_TEMPLATE_P (name))
5053 0 : name = TREE_OPERAND (fullname, 0) = DECL_NAME (name);
5054 4986391 : if (TREE_CODE (name) != IDENTIFIER_NODE)
5055 : {
5056 0 : if (complain & tf_error)
5057 0 : error ("%qD is not a type", name);
5058 0 : return error_mark_node;
5059 : }
5060 : }
5061 252730194 : if (TREE_CODE (name) == TEMPLATE_DECL)
5062 : {
5063 0 : if (complain & tf_error)
5064 0 : error ("%qD used without template arguments", name);
5065 0 : return error_mark_node;
5066 : }
5067 252730194 : else if (is_overloaded_fn (name))
5068 : {
5069 3 : if (complain & tf_error)
5070 3 : error ("%qD is a function, not a type", name);
5071 3 : return error_mark_node;
5072 : }
5073 252730191 : gcc_assert (identifier_p (name));
5074 252730191 : gcc_assert (TYPE_P (context));
5075 :
5076 252730191 : if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
5077 : /* This can happen for C++17 variadic using (c++/88986). */;
5078 240005965 : else if (!MAYBE_CLASS_TYPE_P (context))
5079 : {
5080 6 : if (complain & tf_error)
5081 6 : error ("%q#T is not a class", context);
5082 6 : return error_mark_node;
5083 : }
5084 :
5085 : /* When the CONTEXT is a dependent type, NAME could refer to a
5086 : dependent base class of CONTEXT. But look inside it anyway
5087 : if CONTEXT is a currently open scope, in case it refers to a
5088 : member of the current instantiation or a non-dependent base;
5089 : lookup will stop when we hit a dependent base. */
5090 252730185 : if (!dependent_scope_p (context))
5091 : {
5092 : /* We generally don't ignore non-types during TYPENAME_TYPE lookup
5093 : (as per [temp.res.general]/3), unless
5094 : - the tag corresponds to a class-key or 'enum' so
5095 : [basic.lookup.elab] applies, or
5096 : - the tag corresponds to scope_type or tf_qualifying_scope is
5097 : set so [basic.lookup.qual]/1 applies, or
5098 : - we're inside a base-specifier so [class.derived.general]/2 applies;
5099 : the tag will already be class_type in that case.
5100 : TODO: If we'd set/track the scope_type tag thoroughly on all
5101 : TYPENAME_TYPEs that are followed by :: then we wouldn't need the
5102 : tf_qualifying_scope flag. */
5103 393207142 : bool want_type = (tag_type != none_type && tag_type != typename_type)
5104 196603571 : || (complain & tf_qualifying_scope);
5105 196603571 : t = lookup_member (context, name, /*protect=*/2, want_type, complain);
5106 : }
5107 : else
5108 : t = NULL_TREE;
5109 :
5110 271760147 : if ((!t || TREE_CODE (t) == TREE_LIST) && dependentish_scope_p (context))
5111 56127538 : return build_typename_type (context, name, fullname, tag_type);
5112 :
5113 196602647 : want_template = TREE_CODE (fullname) == TEMPLATE_ID_EXPR;
5114 :
5115 196602647 : if (!t)
5116 : {
5117 19029038 : if (complain & tf_error)
5118 : {
5119 223 : if (!COMPLETE_TYPE_P (context))
5120 18 : cxx_incomplete_type_error (NULL_TREE, context);
5121 : else
5122 409 : error (want_template ? G_("no class template named %q#T in %q#T")
5123 : : G_("no type named %q#T in %q#T"), name, context);
5124 : }
5125 19029038 : return error_mark_node;
5126 : }
5127 :
5128 : /* Pull out the template from an injected-class-name (or multiple). */
5129 177573609 : if (want_template)
5130 3160859 : t = maybe_get_template_decl_from_type_decl (t);
5131 :
5132 177573609 : if (TREE_CODE (t) == TREE_LIST)
5133 : {
5134 3 : if (complain & tf_error)
5135 : {
5136 3 : auto_diagnostic_group d;
5137 3 : error ("lookup of %qT in %qT is ambiguous", name, context);
5138 3 : print_candidates (input_location, t);
5139 3 : }
5140 3 : return error_mark_node;
5141 : }
5142 :
5143 177573606 : if (want_template && !DECL_TYPE_TEMPLATE_P (t))
5144 : {
5145 6 : if (complain & tf_error)
5146 6 : error ("%<typename %T::%D%> names %q#T, which is not a class template",
5147 : context, name, t);
5148 6 : return error_mark_node;
5149 : }
5150 177573600 : if (!want_template && TREE_CODE (t) != TYPE_DECL)
5151 : {
5152 1469 : if ((complain & tf_tst_ok) && cxx_dialect >= cxx17
5153 2941 : && DECL_TYPE_TEMPLATE_P (t))
5154 : /* The caller permits this typename-specifier to name a template
5155 : (because it appears in a CTAD-enabled context). */;
5156 : else
5157 : {
5158 23 : if (complain & tf_error)
5159 17 : error ("%<typename %T::%D%> names %q#D, which is not a type",
5160 : context, name, t);
5161 23 : return error_mark_node;
5162 : }
5163 : }
5164 :
5165 177573577 : if (!check_accessibility_of_qualified_id (t, /*object_type=*/NULL_TREE,
5166 : context, complain))
5167 42 : return error_mark_node;
5168 :
5169 177573535 : if (!want_template && DECL_TYPE_TEMPLATE_P (t))
5170 1458 : return make_template_placeholder (t);
5171 :
5172 177572077 : if (want_template)
5173 : {
5174 3160853 : t = lookup_template_class (t, TREE_OPERAND (fullname, 1),
5175 : NULL_TREE, context,
5176 : complain | tf_user);
5177 3160853 : if (t == error_mark_node)
5178 : return error_mark_node;
5179 3160848 : t = TYPE_NAME (t);
5180 : }
5181 :
5182 177572072 : if (DECL_ARTIFICIAL (t) || !(complain & tf_keep_type_decl))
5183 2156324 : t = TREE_TYPE (t);
5184 :
5185 177572072 : maybe_record_typedef_use (t);
5186 :
5187 177572072 : return t;
5188 : }
5189 :
5190 : /* Resolve `CONTEXT::template NAME'. Returns a TEMPLATE_DECL if the name
5191 : can be resolved or an UNBOUND_CLASS_TEMPLATE, unless an error occurs,
5192 : in which case error_mark_node is returned.
5193 :
5194 : If PARM_LIST is non-NULL, also make sure that the template parameter
5195 : list of TEMPLATE_DECL matches.
5196 :
5197 : If COMPLAIN zero, don't complain about any errors that occur. */
5198 :
5199 : tree
5200 174730 : make_unbound_class_template (tree context, tree name, tree parm_list,
5201 : tsubst_flags_t complain)
5202 : {
5203 174730 : if (TYPE_P (name))
5204 0 : name = TYPE_IDENTIFIER (name);
5205 174730 : else if (DECL_P (name))
5206 0 : name = DECL_NAME (name);
5207 174730 : gcc_assert (identifier_p (name));
5208 :
5209 174730 : if (!dependent_type_p (context)
5210 174730 : || currently_open_class (context))
5211 : {
5212 85516 : tree tmpl = NULL_TREE;
5213 :
5214 85516 : if (MAYBE_CLASS_TYPE_P (context))
5215 85510 : tmpl = lookup_field (context, name, 0, false);
5216 :
5217 85510 : if (tmpl && TREE_CODE (tmpl) == TYPE_DECL)
5218 3 : tmpl = maybe_get_template_decl_from_type_decl (tmpl);
5219 :
5220 85504 : if (!tmpl || !DECL_TYPE_TEMPLATE_P (tmpl))
5221 : {
5222 12 : if (complain & tf_error)
5223 9 : error ("no class template named %q#T in %q#T", name, context);
5224 12 : return error_mark_node;
5225 : }
5226 :
5227 85504 : if (parm_list
5228 85504 : && !comp_template_parms (DECL_TEMPLATE_PARMS (tmpl), parm_list))
5229 : {
5230 0 : if (complain & tf_error)
5231 : {
5232 0 : auto_diagnostic_group d;
5233 0 : error ("template parameters do not match template %qD", tmpl);
5234 0 : inform (DECL_SOURCE_LOCATION (tmpl),
5235 : "%qD declared here", tmpl);
5236 0 : }
5237 0 : return error_mark_node;
5238 : }
5239 :
5240 85504 : if (!perform_or_defer_access_check (TYPE_BINFO (context), tmpl, tmpl,
5241 : complain))
5242 0 : return error_mark_node;
5243 :
5244 : return tmpl;
5245 : }
5246 :
5247 89214 : return make_unbound_class_template_raw (context, name, parm_list);
5248 : }
5249 :
5250 : /* Build an UNBOUND_CLASS_TEMPLATE. */
5251 :
5252 : tree
5253 89266 : make_unbound_class_template_raw (tree context, tree name, tree parm_list)
5254 : {
5255 : /* Build the UNBOUND_CLASS_TEMPLATE. */
5256 89266 : tree t = cxx_make_type (UNBOUND_CLASS_TEMPLATE);
5257 89266 : TYPE_CONTEXT (t) = FROB_CONTEXT (context);
5258 89266 : TREE_TYPE (t) = NULL_TREE;
5259 89266 : SET_TYPE_STRUCTURAL_EQUALITY (t);
5260 :
5261 : /* Build the corresponding TEMPLATE_DECL. */
5262 89266 : tree d = build_decl (input_location, TEMPLATE_DECL, name, t);
5263 89266 : TYPE_NAME (t) = d;
5264 89266 : TYPE_STUB_DECL (t) = d;
5265 89266 : DECL_CONTEXT (d) = TYPE_CONTEXT (t);
5266 89266 : DECL_ARTIFICIAL (d) = 1;
5267 89266 : DECL_TEMPLATE_PARMS (d) = parm_list;
5268 :
5269 89266 : return t;
5270 : }
5271 :
5272 :
5273 :
5274 : /* Push the declarations of builtin types into the global namespace.
5275 : RID_INDEX is the index of the builtin type in the array
5276 : RID_POINTERS. NAME is the name used when looking up the builtin
5277 : type. TYPE is the _TYPE node for the builtin type.
5278 :
5279 : The calls to set_global_binding below should be
5280 : eliminated. Built-in types should not be looked up name; their
5281 : names are keywords that the parser can recognize. However, there
5282 : is code in c-common.cc that uses identifier_global_value to look up
5283 : built-in types by name. */
5284 :
5285 : void
5286 4079539 : record_builtin_type (enum rid rid_index,
5287 : const char* name,
5288 : tree type)
5289 : {
5290 4079539 : tree decl = NULL_TREE;
5291 :
5292 4079539 : if (name)
5293 : {
5294 2406807 : tree tname = get_identifier (name);
5295 2406807 : tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type);
5296 2406807 : DECL_ARTIFICIAL (tdecl) = 1;
5297 2406807 : set_global_binding (tdecl);
5298 2406807 : decl = tdecl;
5299 : }
5300 :
5301 4079539 : if ((int) rid_index < (int) RID_MAX)
5302 2504601 : if (tree rname = ridpointers[(int) rid_index])
5303 1914225 : if (!decl || DECL_NAME (decl) != rname)
5304 : {
5305 1377544 : tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type);
5306 1377544 : DECL_ARTIFICIAL (rdecl) = 1;
5307 1377544 : set_global_binding (rdecl);
5308 1377544 : if (!decl)
5309 : decl = rdecl;
5310 : }
5311 :
5312 3784351 : if (decl)
5313 : {
5314 3489163 : if (!TYPE_NAME (type))
5315 2898787 : TYPE_NAME (type) = decl;
5316 3489163 : debug_hooks->type_decl (decl, 0);
5317 : }
5318 4079539 : }
5319 :
5320 : /* Push a type into the namespace so that the back ends ignore it. */
5321 :
5322 : static void
5323 295188 : record_unknown_type (tree type, const char* name)
5324 : {
5325 295188 : tree decl = pushdecl (build_decl (UNKNOWN_LOCATION,
5326 : TYPE_DECL, get_identifier (name), type));
5327 : /* Make sure the "unknown type" typedecl gets ignored for debug info. */
5328 295188 : DECL_IGNORED_P (decl) = 1;
5329 295188 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
5330 295188 : TYPE_SIZE (type) = TYPE_SIZE (void_type_node);
5331 295188 : SET_TYPE_ALIGN (type, 1);
5332 295188 : TYPE_USER_ALIGN (type) = 0;
5333 295188 : SET_TYPE_MODE (type, TYPE_MODE (void_type_node));
5334 295188 : }
5335 :
5336 : /* Create all the predefined identifiers. */
5337 :
5338 : static void
5339 98396 : initialize_predefined_identifiers (void)
5340 : {
5341 98396 : struct predefined_identifier
5342 : {
5343 : const char *name; /* Name. */
5344 : tree *node; /* Node to store it in. */
5345 : cp_identifier_kind kind; /* Kind of identifier. */
5346 : };
5347 :
5348 : /* A table of identifiers to create at startup. */
5349 98396 : static const predefined_identifier predefined_identifiers[] = {
5350 : {"C++", &lang_name_cplusplus, cik_normal},
5351 : {"C", &lang_name_c, cik_normal},
5352 : /* Some of these names have a trailing space so that it is
5353 : impossible for them to conflict with names written by users. */
5354 : {"__ct ", &ctor_identifier, cik_ctor},
5355 : {"__ct_base ", &base_ctor_identifier, cik_ctor},
5356 : {"__ct_comp ", &complete_ctor_identifier, cik_ctor},
5357 : {"__dt ", &dtor_identifier, cik_dtor},
5358 : {"__dt_base ", &base_dtor_identifier, cik_dtor},
5359 : {"__dt_comp ", &complete_dtor_identifier, cik_dtor},
5360 : {"__dt_del ", &deleting_dtor_identifier, cik_dtor},
5361 : {"__conv_op ", &conv_op_identifier, cik_conv_op},
5362 : {"__in_chrg", &in_charge_identifier, cik_normal},
5363 : {"__as_base ", &as_base_identifier, cik_normal},
5364 : {"this", &this_identifier, cik_normal},
5365 : {"__delta", &delta_identifier, cik_normal},
5366 : {"__pfn", &pfn_identifier, cik_normal},
5367 : {"_vptr", &vptr_identifier, cik_normal},
5368 : {"__vtt_parm", &vtt_parm_identifier, cik_normal},
5369 : {"::", &global_identifier, cik_normal},
5370 : /* The demangler expects anonymous namespaces to be called
5371 : something starting with '_GLOBAL__N_'. It no longer needs
5372 : to be unique to the TU. */
5373 : {"_GLOBAL__N_1", &anon_identifier, cik_normal},
5374 : {"auto", &auto_identifier, cik_normal},
5375 : {"decltype(auto)", &decltype_auto_identifier, cik_normal},
5376 : {"initializer_list", &init_list_identifier, cik_normal},
5377 : {"__for_range ", &for_range__identifier, cik_normal},
5378 : {"__for_begin ", &for_begin__identifier, cik_normal},
5379 : {"__for_end ", &for_end__identifier, cik_normal},
5380 : {"__for_range", &for_range_identifier, cik_normal},
5381 : {"__for_begin", &for_begin_identifier, cik_normal},
5382 : {"__for_end", &for_end_identifier, cik_normal},
5383 : {"abi_tag", &abi_tag_identifier, cik_normal},
5384 : {"aligned", &aligned_identifier, cik_normal},
5385 : {"begin", &begin_identifier, cik_normal},
5386 : {"end", &end_identifier, cik_normal},
5387 : {"get", &get__identifier, cik_normal},
5388 : {"gnu", &gnu_identifier, cik_normal},
5389 : {"tuple_element", &tuple_element_identifier, cik_normal},
5390 : {"tuple_size", &tuple_size_identifier, cik_normal},
5391 : {"type", &type_identifier, cik_normal},
5392 : {"value", &value_identifier, cik_normal},
5393 : {"_FUN", &fun_identifier, cik_normal},
5394 : {"__closure", &closure_identifier, cik_normal},
5395 : {"heap uninit", &heap_uninit_identifier, cik_normal},
5396 : {"heap ", &heap_identifier, cik_normal},
5397 : {"heap deleted", &heap_deleted_identifier, cik_normal},
5398 : {"heap [] uninit", &heap_vec_uninit_identifier, cik_normal},
5399 : {"heap []", &heap_vec_identifier, cik_normal},
5400 : {"omp", &omp_identifier, cik_normal},
5401 : {"internal ", &internal_identifier, cik_normal},
5402 : {"annotation ", &annotation_identifier, cik_normal},
5403 : {NULL, NULL, cik_normal}
5404 : };
5405 :
5406 4821404 : for (const predefined_identifier *pid = predefined_identifiers;
5407 4821404 : pid->name; ++pid)
5408 : {
5409 4723008 : *pid->node = get_identifier (pid->name);
5410 : /* Some of these identifiers already have a special kind. */
5411 4723008 : if (pid->kind != cik_normal)
5412 787168 : set_identifier_kind (*pid->node, pid->kind);
5413 : }
5414 98396 : }
5415 :
5416 : /* Build a specific variant of operator new. */
5417 :
5418 : static void
5419 175640 : cxx_build_operator_new (tree newtype)
5420 : {
5421 175640 : tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
5422 175640 : DECL_IS_MALLOC (opnew) = 1;
5423 175640 : DECL_SET_IS_OPERATOR_NEW (opnew, true);
5424 175640 : DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
5425 175640 : opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
5426 175640 : DECL_IS_MALLOC (opnew) = 1;
5427 175640 : DECL_SET_IS_OPERATOR_NEW (opnew, true);
5428 175640 : DECL_IS_REPLACEABLE_OPERATOR (opnew) = 1;
5429 175640 : }
5430 :
5431 : /* Build a specific variant of operator delete. */
5432 :
5433 : static void
5434 331410 : cxx_build_operator_delete (tree deltype)
5435 : {
5436 331410 : tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
5437 331410 : DECL_SET_IS_OPERATOR_DELETE (opdel, true);
5438 331410 : DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
5439 331410 : opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
5440 331410 : DECL_SET_IS_OPERATOR_DELETE (opdel, true);
5441 331410 : DECL_IS_REPLACEABLE_OPERATOR (opdel) = 1;
5442 331410 : }
5443 :
5444 : /* Declare all variants of operator new and delete. */
5445 :
5446 : static void
5447 98396 : cxx_init_operator_new_delete_decls (void)
5448 : {
5449 98396 : tree newattrs, extvisattr;
5450 98396 : tree newtype, deltype;
5451 98396 : tree ptr_ftype_sizetype;
5452 98396 : tree new_eh_spec;
5453 98396 : tree void_ftype_ptr = build_function_type_list (void_type_node,
5454 : ptr_type_node, NULL_TREE);
5455 98396 : void_ftype_ptr
5456 98396 : = build_exception_variant (void_ftype_ptr, empty_except_spec);
5457 :
5458 98396 : ptr_ftype_sizetype
5459 98396 : = build_function_type_list (ptr_type_node, size_type_node, NULL_TREE);
5460 98396 : if (cxx_dialect == cxx98)
5461 : {
5462 14197 : tree bad_alloc_id;
5463 14197 : tree bad_alloc_type_node;
5464 14197 : tree bad_alloc_decl;
5465 :
5466 14197 : push_nested_namespace (std_node);
5467 14197 : bad_alloc_id = get_identifier ("bad_alloc");
5468 14197 : bad_alloc_type_node = make_class_type (RECORD_TYPE);
5469 14197 : TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
5470 14197 : bad_alloc_decl
5471 14197 : = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
5472 14197 : DECL_CONTEXT (bad_alloc_decl) = current_namespace;
5473 14197 : pop_nested_namespace (std_node);
5474 :
5475 14197 : new_eh_spec
5476 14197 : = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
5477 : }
5478 : else
5479 84199 : new_eh_spec = noexcept_false_spec;
5480 :
5481 98396 : extvisattr = build_tree_list (get_identifier ("externally_visible"),
5482 : NULL_TREE);
5483 98396 : newattrs = tree_cons (get_identifier ("alloc_size"),
5484 : build_tree_list (NULL_TREE, integer_one_node),
5485 : extvisattr);
5486 98396 : newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs);
5487 98396 : newtype = build_exception_variant (newtype, new_eh_spec);
5488 98396 : deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
5489 98396 : deltype = build_exception_variant (deltype, empty_except_spec);
5490 98396 : cxx_build_operator_new (newtype);
5491 98396 : cxx_build_operator_delete (deltype);
5492 98396 : if (flag_sized_deallocation)
5493 : {
5494 : /* Also push the sized deallocation variants:
5495 : void operator delete(void*, std::size_t) throw();
5496 : void operator delete[](void*, std::size_t) throw(); */
5497 78531 : tree void_ftype_ptr_size
5498 78531 : = build_function_type_list (void_type_node, ptr_type_node,
5499 : size_type_node, NULL_TREE);
5500 78531 : deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
5501 : extvisattr);
5502 78531 : deltype = build_exception_variant (deltype, empty_except_spec);
5503 78531 : cxx_build_operator_delete (deltype);
5504 : }
5505 :
5506 98396 : if (aligned_new_threshold)
5507 : {
5508 77244 : push_nested_namespace (std_node);
5509 77244 : tree align_id = get_identifier ("align_val_t");
5510 77244 : align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
5511 : NULL_TREE, /*scoped*/true, NULL);
5512 77244 : pop_nested_namespace (std_node);
5513 :
5514 : /* operator new (size_t, align_val_t); */
5515 77244 : newtype = build_function_type_list (ptr_type_node, size_type_node,
5516 : align_type_node, NULL_TREE);
5517 77244 : newtype = cp_build_type_attribute_variant (newtype, newattrs);
5518 77244 : newtype = build_exception_variant (newtype, new_eh_spec);
5519 77244 : cxx_build_operator_new (newtype);
5520 :
5521 : /* operator delete (void *, align_val_t); */
5522 77244 : deltype = build_function_type_list (void_type_node, ptr_type_node,
5523 : align_type_node, NULL_TREE);
5524 77244 : deltype = cp_build_type_attribute_variant (deltype, extvisattr);
5525 77244 : deltype = build_exception_variant (deltype, empty_except_spec);
5526 77244 : cxx_build_operator_delete (deltype);
5527 :
5528 77244 : if (flag_sized_deallocation)
5529 : {
5530 : /* operator delete (void *, size_t, align_val_t); */
5531 77239 : deltype = build_function_type_list (void_type_node, ptr_type_node,
5532 : size_type_node, align_type_node,
5533 : NULL_TREE);
5534 77239 : deltype = cp_build_type_attribute_variant (deltype, extvisattr);
5535 77239 : deltype = build_exception_variant (deltype, empty_except_spec);
5536 77239 : cxx_build_operator_delete (deltype);
5537 : }
5538 : }
5539 98396 : }
5540 :
5541 : /* Create the predefined scalar types of C,
5542 : and some nodes representing standard constants (0, 1, (void *)0).
5543 : Initialize the global binding level.
5544 : Make definitions for built-in primitive functions. */
5545 :
5546 : void
5547 98396 : cxx_init_decl_processing (void)
5548 : {
5549 98396 : tree void_ftype;
5550 :
5551 : /* Create all the identifiers we need. */
5552 98396 : initialize_predefined_identifiers ();
5553 :
5554 : /* Create the global variables. */
5555 98396 : push_to_top_level ();
5556 :
5557 98396 : current_function_decl = NULL_TREE;
5558 98396 : current_binding_level = NULL;
5559 : /* Enter the global namespace. */
5560 98396 : gcc_assert (global_namespace == NULL_TREE);
5561 98396 : global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier,
5562 : void_type_node);
5563 98396 : TREE_PUBLIC (global_namespace) = true;
5564 98396 : DECL_MODULE_EXPORT_P (global_namespace) = true;
5565 98396 : DECL_CONTEXT (global_namespace)
5566 98396 : = build_translation_unit_decl (get_identifier (main_input_filename));
5567 : /* Remember whether we want the empty class passing ABI change warning
5568 : in this TU. */
5569 98396 : TRANSLATION_UNIT_WARN_EMPTY_P (DECL_CONTEXT (global_namespace))
5570 123544 : = warn_abi && abi_version_crosses (12);
5571 98396 : debug_hooks->register_main_translation_unit
5572 98396 : (DECL_CONTEXT (global_namespace));
5573 98396 : begin_scope (sk_namespace, global_namespace);
5574 98396 : current_namespace = global_namespace;
5575 :
5576 98396 : if (flag_visibility_ms_compat)
5577 6 : default_visibility = VISIBILITY_HIDDEN;
5578 :
5579 : /* Initially, C. */
5580 98396 : current_lang_name = lang_name_c;
5581 :
5582 : /* Create the `std' namespace. */
5583 98396 : push_namespace (get_identifier ("std"));
5584 98396 : std_node = current_namespace;
5585 98396 : pop_namespace ();
5586 :
5587 98396 : flag_noexcept_type = (cxx_dialect >= cxx17);
5588 :
5589 98396 : c_common_nodes_and_builtins ();
5590 :
5591 98396 : tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
5592 98396 : tree decl
5593 98396 : = add_builtin_function ("__builtin_is_constant_evaluated",
5594 : bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
5595 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5596 98396 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5597 :
5598 : /* The concrete return type of __builtin_source_location is
5599 : const std::source_location::__impl*, but we can't form the type
5600 : at this point. So we initially declare it with an auto return
5601 : type which we then "deduce" from require_deduced_type upon first use. */
5602 98396 : tree auto_ftype = build_function_type_list (make_auto (), NULL_TREE);
5603 98396 : decl = add_builtin_function ("__builtin_source_location",
5604 : auto_ftype, CP_BUILT_IN_SOURCE_LOCATION,
5605 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5606 98396 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5607 :
5608 98396 : tree bool_vaftype = build_varargs_function_type_list (boolean_type_node,
5609 : NULL_TREE);
5610 98396 : decl
5611 98396 : = add_builtin_function ("__builtin_is_corresponding_member",
5612 : bool_vaftype,
5613 : CP_BUILT_IN_IS_CORRESPONDING_MEMBER,
5614 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5615 98396 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5616 :
5617 98396 : decl
5618 98396 : = add_builtin_function ("__builtin_is_pointer_interconvertible_with_class",
5619 : bool_vaftype,
5620 : CP_BUILT_IN_IS_POINTER_INTERCONVERTIBLE_WITH_CLASS,
5621 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5622 98396 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5623 :
5624 98396 : if (cxx_dialect >= cxx26)
5625 : {
5626 23753 : tree void_ptrintftype
5627 23753 : = build_function_type_list (void_type_node, ptr_type_node,
5628 : integer_type_node, NULL_TREE);
5629 23753 : decl = add_builtin_function ("__builtin_eh_ptr_adjust_ref",
5630 : void_ptrintftype,
5631 : CP_BUILT_IN_EH_PTR_ADJUST_REF,
5632 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5633 23753 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5634 :
5635 : /* Similar case to __builtin_source_location above. The concrete
5636 : return type is std::exception_ptr, but we can't form the type
5637 : at this point, so it is deduced later. */
5638 23753 : decl = add_builtin_function ("__builtin_current_exception",
5639 : auto_ftype, CP_BUILT_IN_CURRENT_EXCEPTION,
5640 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5641 23753 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5642 :
5643 23753 : tree int_ftype = build_function_type_list (integer_type_node, NULL_TREE);
5644 23753 : decl = add_builtin_function ("__builtin_uncaught_exceptions",
5645 : int_ftype, CP_BUILT_IN_UNCAUGHT_EXCEPTIONS,
5646 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5647 23753 : set_call_expr_flags (decl, ECF_PURE | ECF_NOTHROW | ECF_LEAF);
5648 : }
5649 :
5650 98396 : decl
5651 98396 : = add_builtin_function ("__builtin_is_string_literal",
5652 : bool_vaftype,
5653 : CP_BUILT_IN_IS_STRING_LITERAL,
5654 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5655 98396 : set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
5656 :
5657 98396 : tree void_vaintftype = build_varargs_function_type_list (void_type_node,
5658 : integer_type_node,
5659 : NULL_TREE);
5660 98396 : decl = add_builtin_function ("__builtin_constexpr_diag",
5661 : void_vaintftype,
5662 : CP_BUILT_IN_CONSTEXPR_DIAG,
5663 : BUILT_IN_FRONTEND, NULL, NULL_TREE);
5664 98396 : set_call_expr_flags (decl, ECF_NOTHROW | ECF_LEAF);
5665 :
5666 98396 : integer_two_node = build_int_cst (NULL_TREE, 2);
5667 :
5668 : /* Guess at the initial static decls size. */
5669 98396 : vec_alloc (static_decls, 500);
5670 :
5671 : /* ... and keyed classes. */
5672 98396 : vec_alloc (keyed_classes, 100);
5673 :
5674 98396 : record_builtin_type (RID_BOOL, "bool", boolean_type_node);
5675 98396 : truthvalue_type_node = boolean_type_node;
5676 98396 : truthvalue_false_node = boolean_false_node;
5677 98396 : truthvalue_true_node = boolean_true_node;
5678 :
5679 98396 : empty_except_spec = build_tree_list (NULL_TREE, NULL_TREE);
5680 98396 : noexcept_true_spec = build_tree_list (boolean_true_node, NULL_TREE);
5681 98396 : noexcept_false_spec = build_tree_list (boolean_false_node, NULL_TREE);
5682 98396 : noexcept_deferred_spec = build_tree_list (make_node (DEFERRED_NOEXCEPT),
5683 : NULL_TREE);
5684 :
5685 : #if 0
5686 : record_builtin_type (RID_MAX, NULL, string_type_node);
5687 : #endif
5688 :
5689 98396 : delta_type_node = ptrdiff_type_node;
5690 98396 : vtable_index_type = ptrdiff_type_node;
5691 :
5692 98396 : vtt_parm_type = build_pointer_type (const_ptr_type_node);
5693 98396 : void_ftype = build_function_type_list (void_type_node, NULL_TREE);
5694 :
5695 : /* Create the conversion operator marker. This operator's DECL_NAME
5696 : is in the identifier table, so we can use identifier equality to
5697 : find it. */
5698 98396 : conv_op_marker = build_lang_decl (FUNCTION_DECL, conv_op_identifier,
5699 : void_ftype);
5700 :
5701 : /* C++ extensions */
5702 :
5703 98396 : unknown_type_node = make_node (LANG_TYPE);
5704 98396 : record_unknown_type (unknown_type_node, "unknown type");
5705 :
5706 : /* Indirecting an UNKNOWN_TYPE node yields an UNKNOWN_TYPE node. */
5707 98396 : TREE_TYPE (unknown_type_node) = unknown_type_node;
5708 :
5709 : /* Looking up TYPE_POINTER_TO and TYPE_REFERENCE_TO yield the same
5710 : result. */
5711 98396 : TYPE_POINTER_TO (unknown_type_node) = unknown_type_node;
5712 98396 : TYPE_REFERENCE_TO (unknown_type_node) = unknown_type_node;
5713 :
5714 98396 : init_list_type_node = make_node (LANG_TYPE);
5715 98396 : record_unknown_type (init_list_type_node, "init list");
5716 :
5717 : /* Used when parsing to distinguish parameter-lists () and (void). */
5718 98396 : explicit_void_list_node = build_tree_list (NULL_TREE, void_type_node);
5719 :
5720 98396 : {
5721 : /* Make sure we get a unique function type, so we can give
5722 : its pointer type a name. (This wins for gdb.) */
5723 98396 : tree vfunc_type = make_node (FUNCTION_TYPE);
5724 98396 : TREE_TYPE (vfunc_type) = integer_type_node;
5725 98396 : TYPE_ARG_TYPES (vfunc_type) = NULL_TREE;
5726 98396 : layout_type (vfunc_type);
5727 :
5728 98396 : vtable_entry_type = build_pointer_type (vfunc_type);
5729 : }
5730 98396 : record_builtin_type (RID_MAX, "__vtbl_ptr_type", vtable_entry_type);
5731 :
5732 98396 : vtbl_type_node
5733 98396 : = build_cplus_array_type (vtable_entry_type, NULL_TREE);
5734 98396 : layout_type (vtbl_type_node);
5735 98396 : vtbl_type_node = cp_build_qualified_type (vtbl_type_node, TYPE_QUAL_CONST);
5736 98396 : record_builtin_type (RID_MAX, NULL, vtbl_type_node);
5737 98396 : vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
5738 98396 : layout_type (vtbl_ptr_type_node);
5739 98396 : record_builtin_type (RID_MAX, NULL, vtbl_ptr_type_node);
5740 :
5741 98396 : push_namespace (get_identifier ("__cxxabiv1"));
5742 98396 : abi_node = current_namespace;
5743 98396 : pop_namespace ();
5744 :
5745 98396 : any_targ_node = make_node (LANG_TYPE);
5746 98396 : record_unknown_type (any_targ_node, "any type");
5747 :
5748 : /* Now, C++. */
5749 98396 : current_lang_name = lang_name_cplusplus;
5750 :
5751 98396 : if (aligned_new_threshold > 1
5752 98396 : && !pow2p_hwi (aligned_new_threshold))
5753 : {
5754 0 : error ("%<-faligned-new=%d%> is not a power of two",
5755 : aligned_new_threshold);
5756 0 : aligned_new_threshold = 1;
5757 : }
5758 98396 : if (aligned_new_threshold == -1)
5759 119534 : aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
5760 98396 : if (aligned_new_threshold == 1)
5761 77241 : aligned_new_threshold = malloc_alignment () / BITS_PER_UNIT;
5762 :
5763 : /* Ensure attribs.cc is initialized. */
5764 98396 : init_attributes ();
5765 98396 : cxx_init_operator_new_delete_decls ();
5766 :
5767 : /* C++-specific nullptr initialization. */
5768 98396 : if (abi_version_at_least (9))
5769 98225 : SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
5770 98396 : record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
5771 :
5772 98396 : if (! supports_one_only ())
5773 0 : flag_weak = 0;
5774 :
5775 98396 : abort_fndecl
5776 98396 : = build_library_fn_ptr ("__cxa_pure_virtual", void_ftype,
5777 : ECF_NORETURN | ECF_NOTHROW | ECF_COLD);
5778 98396 : if (flag_weak)
5779 : /* If no definition is available, resolve references to NULL. */
5780 98366 : declare_weak (abort_fndecl);
5781 :
5782 : /* Perform other language dependent initializations. */
5783 98396 : init_class_processing ();
5784 98396 : init_rtti_processing ();
5785 98396 : init_template_processing ();
5786 :
5787 98396 : if (flag_exceptions)
5788 97141 : init_exception_processing ();
5789 :
5790 98396 : if (flag_contracts)
5791 23799 : init_contracts ();
5792 :
5793 98396 : if (modules_p ())
5794 4901 : init_modules (parse_in);
5795 :
5796 98396 : if (flag_reflection)
5797 602 : init_reflection ();
5798 :
5799 98396 : make_fname_decl = cp_make_fname_decl;
5800 98396 : start_fname_decls ();
5801 :
5802 : /* Show we use EH for cleanups. */
5803 98396 : if (flag_exceptions)
5804 97141 : using_eh_for_cleanups ();
5805 :
5806 : /* Check that the hardware interference sizes are at least
5807 : alignof(max_align_t), as required by the standard. */
5808 98396 : const int max_align = max_align_t_align () / BITS_PER_UNIT;
5809 98396 : if (OPTION_SET_P (param_destruct_interfere_size))
5810 : {
5811 0 : if (param_destruct_interfere_size < max_align)
5812 0 : error ("%<--param destructive-interference-size=%d%> is less than "
5813 : "%d", param_destruct_interfere_size, max_align);
5814 0 : else if (param_destruct_interfere_size < param_l1_cache_line_size)
5815 0 : warning (OPT_Winterference_size,
5816 : "%<--param destructive-interference-size=%d%> "
5817 : "is less than %<--param l1-cache-line-size=%d%>",
5818 : param_destruct_interfere_size, param_l1_cache_line_size);
5819 : }
5820 98396 : else if (param_destruct_interfere_size)
5821 : /* Assume the internal value is OK. */;
5822 0 : else if (param_l1_cache_line_size >= max_align)
5823 0 : param_destruct_interfere_size = param_l1_cache_line_size;
5824 : /* else leave it unset. */
5825 :
5826 98396 : if (OPTION_SET_P (param_construct_interfere_size))
5827 : {
5828 0 : if (param_construct_interfere_size < max_align)
5829 0 : error ("%<--param constructive-interference-size=%d%> is less than "
5830 : "%d", param_construct_interfere_size, max_align);
5831 0 : else if (param_construct_interfere_size > param_l1_cache_line_size
5832 0 : && param_l1_cache_line_size >= max_align)
5833 0 : warning (OPT_Winterference_size,
5834 : "%<--param constructive-interference-size=%d%> "
5835 : "is greater than %<--param l1-cache-line-size=%d%>",
5836 : param_construct_interfere_size, param_l1_cache_line_size);
5837 : }
5838 98396 : else if (param_construct_interfere_size)
5839 : /* Assume the internal value is OK. */;
5840 0 : else if (param_l1_cache_line_size >= max_align)
5841 0 : param_construct_interfere_size = param_l1_cache_line_size;
5842 98396 : }
5843 :
5844 : /* Enter an abi node in global-module context. returns a cookie to
5845 : give to pop_abi_namespace. */
5846 :
5847 : unsigned
5848 56871 : push_abi_namespace (tree node)
5849 : {
5850 56871 : push_nested_namespace (node);
5851 56871 : push_visibility ("default", 2);
5852 56871 : unsigned flags = module_kind;
5853 56871 : module_kind = 0;
5854 56871 : return flags;
5855 : }
5856 :
5857 : /* Pop an abi namespace, FLAGS is the cookie push_abi_namespace gave
5858 : you. */
5859 :
5860 : void
5861 56871 : pop_abi_namespace (unsigned flags, tree node)
5862 : {
5863 56871 : module_kind = flags;
5864 56871 : pop_visibility (2);
5865 56871 : pop_nested_namespace (node);
5866 56871 : }
5867 :
5868 : /* Create the VAR_DECL for __FUNCTION__ etc. ID is the name to give
5869 : the decl, LOC is the location to give the decl, NAME is the
5870 : initialization string and TYPE_DEP indicates whether NAME depended
5871 : on the type of the function. We make use of that to detect
5872 : __PRETTY_FUNCTION__ inside a template fn. This is being done lazily
5873 : at the point of first use, so we mustn't push the decl now. */
5874 :
5875 : static tree
5876 176941 : cp_make_fname_decl (location_t loc, tree id, int type_dep)
5877 : {
5878 176941 : tree domain = NULL_TREE;
5879 176941 : tree init = NULL_TREE;
5880 :
5881 176941 : if (!(type_dep && current_function_decl && in_template_context))
5882 : {
5883 47601 : const char *name = NULL;
5884 47601 : bool release_name = false;
5885 :
5886 47601 : if (current_function_decl == NULL_TREE)
5887 : name = "top level";
5888 47587 : else if (type_dep == 0)
5889 : {
5890 : /* __FUNCTION__ */
5891 581 : name = fname_as_string (type_dep);
5892 581 : release_name = true;
5893 : }
5894 : else
5895 : {
5896 : /* __PRETTY_FUNCTION__ */
5897 47006 : gcc_checking_assert (type_dep == 1);
5898 47006 : name = cxx_printable_name (current_function_decl, 2);
5899 : }
5900 :
5901 47587 : if (!release_name)
5902 : {
5903 47020 : cpp_string cstr = { 0, 0 }, strname;
5904 47020 : size_t len = strlen (name) + 3; /* Two for '"'s. One for NULL. */
5905 47020 : char *namep = XNEWVEC (char, len);
5906 47020 : snprintf (namep, len, "\"%s\"", name);
5907 47020 : strname.text = (unsigned char *) namep;
5908 47020 : strname.len = len - 1;
5909 47020 : if (cpp_interpret_string (parse_in, &strname, 1, &cstr, CPP_STRING))
5910 : {
5911 47020 : name = (const char *) cstr.text;
5912 47020 : release_name = true;
5913 : }
5914 :
5915 47020 : XDELETEVEC (namep);
5916 : }
5917 :
5918 47601 : size_t length = strlen (name);
5919 47601 : domain = build_index_type (size_int (length));
5920 47601 : init = build_string (length + 1, name);
5921 47601 : if (release_name)
5922 47601 : free (const_cast<char *> (name));
5923 : }
5924 :
5925 176941 : tree type = cp_build_qualified_type (char_type_node, TYPE_QUAL_CONST);
5926 176941 : type = build_cplus_array_type (type, domain);
5927 :
5928 176941 : if (init)
5929 47601 : TREE_TYPE (init) = type;
5930 : else
5931 129340 : init = error_mark_node;
5932 :
5933 176941 : tree decl = build_decl (loc, VAR_DECL, id, type);
5934 :
5935 176941 : TREE_READONLY (decl) = 1;
5936 176941 : DECL_ARTIFICIAL (decl) = 1;
5937 176941 : DECL_DECLARED_CONSTEXPR_P (decl) = 1;
5938 176941 : TREE_STATIC (decl) = 1;
5939 :
5940 176941 : TREE_USED (decl) = 1;
5941 :
5942 176941 : SET_DECL_VALUE_EXPR (decl, init);
5943 176941 : DECL_HAS_VALUE_EXPR_P (decl) = 1;
5944 : /* For decl_constant_var_p. */
5945 176941 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
5946 :
5947 176941 : if (current_function_decl)
5948 : {
5949 176927 : DECL_CONTEXT (decl) = current_function_decl;
5950 176927 : decl = pushdecl_outermost_localscope (decl);
5951 176927 : if (decl != error_mark_node)
5952 176924 : add_decl_expr (decl);
5953 : else
5954 3 : gcc_assert (seen_error ());
5955 : }
5956 : else
5957 : {
5958 14 : DECL_THIS_STATIC (decl) = true;
5959 14 : decl = pushdecl_top_level_and_finish (decl, NULL_TREE);
5960 : }
5961 :
5962 176941 : return decl;
5963 : }
5964 :
5965 : /* Install DECL as a builtin function at current global scope. Return
5966 : the new decl (if we found an existing version). Also installs it
5967 : into ::std, if it's not '_*'. */
5968 :
5969 : tree
5970 227917138 : cxx_builtin_function (tree decl)
5971 : {
5972 227917138 : retrofit_lang_decl (decl);
5973 :
5974 227917138 : DECL_ARTIFICIAL (decl) = 1;
5975 227917138 : SET_DECL_LANGUAGE (decl, lang_c);
5976 : /* Runtime library routines are, by definition, available in an
5977 : external shared object. */
5978 227917138 : DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
5979 227917138 : DECL_VISIBILITY_SPECIFIED (decl) = 1;
5980 :
5981 227917138 : tree id = DECL_NAME (decl);
5982 227917138 : const char *name = IDENTIFIER_POINTER (id);
5983 227917138 : bool hiding = false;
5984 227917138 : if (name[0] != '_' || name[1] != '_')
5985 : /* In the user's namespace, it must be declared before use. */
5986 : hiding = true;
5987 191167503 : else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
5988 191167503 : && !startswith (name + 2, "builtin_")
5989 214053431 : && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
5990 : "_chk", strlen ("_chk") + 1))
5991 : /* Treat __*_chk fortification functions as anticipated as well,
5992 : unless they are __builtin_*_chk. */
5993 : hiding = true;
5994 :
5995 : /* All builtins that don't begin with an '_' should additionally
5996 : go in the 'std' namespace. */
5997 227917138 : if (name[0] != '_')
5998 : {
5999 36615449 : tree std_decl = copy_decl (decl);
6000 :
6001 36615449 : push_nested_namespace (std_node);
6002 36615449 : DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
6003 36615449 : pushdecl (std_decl, hiding);
6004 36615449 : pop_nested_namespace (std_node);
6005 : }
6006 :
6007 227917138 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
6008 227917138 : decl = pushdecl (decl, hiding);
6009 :
6010 227917138 : return decl;
6011 : }
6012 :
6013 : /* Like cxx_builtin_function, but guarantee the function is added to the global
6014 : scope. This is to allow function specific options to add new machine
6015 : dependent builtins when the target ISA changes via attribute((target(...)))
6016 : which saves space on program startup if the program does not use non-generic
6017 : ISAs. */
6018 :
6019 : tree
6020 764537 : cxx_builtin_function_ext_scope (tree decl)
6021 : {
6022 764537 : push_nested_namespace (global_namespace);
6023 764537 : decl = cxx_builtin_function (decl);
6024 764537 : pop_nested_namespace (global_namespace);
6025 :
6026 764537 : return decl;
6027 : }
6028 :
6029 : /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL. */
6030 :
6031 : tree
6032 0 : cxx_simulate_builtin_function_decl (tree decl)
6033 : {
6034 0 : retrofit_lang_decl (decl);
6035 :
6036 0 : DECL_ARTIFICIAL (decl) = 1;
6037 0 : SET_DECL_LANGUAGE (decl, lang_cplusplus);
6038 0 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
6039 0 : return pushdecl (decl);
6040 : }
6041 :
6042 : /* Generate a FUNCTION_DECL with the typical flags for a runtime library
6043 : function. Not called directly. */
6044 :
6045 : static tree
6046 1582761 : build_library_fn (tree name, enum tree_code operator_code, tree type,
6047 : int ecf_flags)
6048 : {
6049 1582761 : tree fn = build_lang_decl (FUNCTION_DECL, name, type);
6050 1582761 : DECL_EXTERNAL (fn) = 1;
6051 1582761 : TREE_PUBLIC (fn) = 1;
6052 1582761 : DECL_ARTIFICIAL (fn) = 1;
6053 1582761 : DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
6054 1582761 : = OVL_OP_INFO (false, operator_code)->ovl_op_code;
6055 1582761 : SET_DECL_LANGUAGE (fn, lang_c);
6056 : /* Runtime library routines are, by definition, available in an
6057 : external shared object. */
6058 1582761 : DECL_VISIBILITY (fn) = VISIBILITY_DEFAULT;
6059 1582761 : DECL_VISIBILITY_SPECIFIED (fn) = 1;
6060 1582761 : set_call_expr_flags (fn, ecf_flags);
6061 1582761 : return fn;
6062 : }
6063 :
6064 : /* Returns the _DECL for a library function with C++ linkage. */
6065 :
6066 : static tree
6067 1111434 : build_cp_library_fn (tree name, enum tree_code operator_code, tree type,
6068 : int ecf_flags)
6069 : {
6070 1111434 : tree fn = build_library_fn (name, operator_code, type, ecf_flags);
6071 1111434 : DECL_CONTEXT (fn) = FROB_CONTEXT (current_namespace);
6072 1111434 : SET_DECL_LANGUAGE (fn, lang_cplusplus);
6073 1111434 : return fn;
6074 : }
6075 :
6076 : /* Like build_library_fn, but takes a C string instead of an
6077 : IDENTIFIER_NODE. */
6078 :
6079 : tree
6080 103091 : build_library_fn_ptr (const char* name, tree type, int ecf_flags)
6081 : {
6082 103091 : return build_library_fn (get_identifier (name), ERROR_MARK, type, ecf_flags);
6083 : }
6084 :
6085 : /* Like build_cp_library_fn, but takes a C string instead of an
6086 : IDENTIFIER_NODE. */
6087 :
6088 : tree
6089 97334 : build_cp_library_fn_ptr (const char* name, tree type, int ecf_flags)
6090 : {
6091 97334 : return build_cp_library_fn (get_identifier (name), ERROR_MARK, type,
6092 97334 : ecf_flags);
6093 : }
6094 :
6095 : /* Like build_library_fn, but also pushes the function so that we will
6096 : be able to find it via get_global_binding. Also, the function
6097 : may throw exceptions listed in RAISES. */
6098 :
6099 : tree
6100 368236 : push_library_fn (tree name, tree type, tree raises, int ecf_flags)
6101 : {
6102 368236 : if (raises)
6103 40597 : type = build_exception_variant (type, raises);
6104 :
6105 368236 : tree fn = build_library_fn (name, ERROR_MARK, type, ecf_flags);
6106 368236 : return pushdecl_top_level (fn);
6107 : }
6108 :
6109 : /* Like build_cp_library_fn, but also pushes the function so that it
6110 : will be found by normal lookup. */
6111 :
6112 : static tree
6113 1014100 : push_cp_library_fn (enum tree_code operator_code, tree type,
6114 : int ecf_flags)
6115 : {
6116 1014100 : tree fn = build_cp_library_fn (ovl_op_identifier (false, operator_code),
6117 : operator_code, type, ecf_flags);
6118 1014100 : pushdecl (fn);
6119 1014100 : if (flag_tm)
6120 3088 : apply_tm_attr (fn, get_identifier ("transaction_safe"));
6121 1014100 : return fn;
6122 : }
6123 :
6124 : /* Like push_library_fn, but also note that this function throws
6125 : and does not return. Used for __throw_foo and the like. */
6126 :
6127 : tree
6128 107817 : push_throw_library_fn (tree name, tree type)
6129 : {
6130 107817 : tree fn = push_library_fn (name, type, NULL_TREE,
6131 : ECF_NORETURN | ECF_XTHROW | ECF_COLD);
6132 107817 : return fn;
6133 : }
6134 :
6135 : /* When we call finish_struct for an anonymous union, we create
6136 : default copy constructors and such. But, an anonymous union
6137 : shouldn't have such things; this function undoes the damage to the
6138 : anonymous union type T.
6139 :
6140 : (The reason that we create the synthesized methods is that we don't
6141 : distinguish `union { int i; }' from `typedef union { int i; } U'.
6142 : The first is an anonymous union; the second is just an ordinary
6143 : union type.) */
6144 :
6145 : void
6146 171000 : fixup_anonymous_aggr (tree t)
6147 : {
6148 : /* Wipe out memory of synthesized methods. */
6149 171000 : TYPE_HAS_USER_CONSTRUCTOR (t) = 0;
6150 171000 : TYPE_HAS_DEFAULT_CONSTRUCTOR (t) = 0;
6151 171000 : TYPE_HAS_COPY_CTOR (t) = 0;
6152 171000 : TYPE_HAS_CONST_COPY_CTOR (t) = 0;
6153 171000 : TYPE_HAS_COPY_ASSIGN (t) = 0;
6154 171000 : TYPE_HAS_CONST_COPY_ASSIGN (t) = 0;
6155 :
6156 : /* Splice the implicitly generated functions out of TYPE_FIELDS and diagnose
6157 : invalid members. */
6158 1000554 : for (tree probe, *prev_p = &TYPE_FIELDS (t); (probe = *prev_p);)
6159 : {
6160 829554 : if (TREE_CODE (probe) == FUNCTION_DECL && DECL_ARTIFICIAL (probe))
6161 0 : *prev_p = DECL_CHAIN (probe);
6162 : else
6163 829554 : prev_p = &DECL_CHAIN (probe);
6164 :
6165 829554 : if (DECL_ARTIFICIAL (probe)
6166 829554 : && (!DECL_IMPLICIT_TYPEDEF_P (probe)
6167 74930 : || TYPE_ANON_P (TREE_TYPE (probe))))
6168 280762 : continue;
6169 :
6170 548792 : if (TREE_CODE (probe) != FIELD_DECL
6171 548738 : || (TREE_PRIVATE (probe) || TREE_PROTECTED (probe)))
6172 : {
6173 : /* We already complained about static data members in
6174 : finish_static_data_member_decl. */
6175 66 : if (!VAR_P (probe))
6176 : {
6177 51 : auto_diagnostic_group d;
6178 51 : if (permerror (DECL_SOURCE_LOCATION (probe),
6179 51 : TREE_CODE (t) == UNION_TYPE
6180 : ? "%q#D invalid; an anonymous union may "
6181 : "only have public non-static data members"
6182 : : "%q#D invalid; an anonymous struct may "
6183 : "only have public non-static data members", probe))
6184 : {
6185 51 : static bool hint;
6186 51 : if (flag_permissive && !hint)
6187 : {
6188 6 : hint = true;
6189 6 : inform (DECL_SOURCE_LOCATION (probe),
6190 : "this flexibility is deprecated and will be "
6191 : "removed");
6192 : }
6193 : }
6194 51 : }
6195 : }
6196 : }
6197 :
6198 : /* Splice all functions out of CLASSTYPE_MEMBER_VEC. */
6199 171000 : vec<tree,va_gc>* vec = CLASSTYPE_MEMBER_VEC (t);
6200 171000 : unsigned store = 0;
6201 510758 : for (tree elt : vec)
6202 339758 : if (!is_overloaded_fn (elt))
6203 339737 : (*vec)[store++] = elt;
6204 171000 : vec_safe_truncate (vec, store);
6205 :
6206 : /* Wipe RTTI info. */
6207 171000 : SET_CLASSTYPE_TYPEINFO_VAR (t, NULL_TREE);
6208 :
6209 : /* Anonymous aggregates cannot have fields with ctors, dtors or complex
6210 : assignment operators (because they cannot have these methods themselves).
6211 : For anonymous unions this is already checked because they are not allowed
6212 : in any union, otherwise we have to check it. */
6213 171000 : if (TREE_CODE (t) != UNION_TYPE)
6214 : {
6215 36781 : tree field, type;
6216 :
6217 36781 : if (BINFO_N_BASE_BINFOS (TYPE_BINFO (t)))
6218 : {
6219 9 : error_at (location_of (t), "anonymous struct with base classes");
6220 : /* Avoid ICE after error on anon-struct9.C. */
6221 9 : TYPE_NEEDS_CONSTRUCTING (t) = false;
6222 : }
6223 :
6224 147956 : for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
6225 111175 : if (TREE_CODE (field) == FIELD_DECL)
6226 : {
6227 74293 : type = TREE_TYPE (field);
6228 74293 : if (CLASS_TYPE_P (type))
6229 : {
6230 61 : if (TYPE_NEEDS_CONSTRUCTING (type))
6231 6 : error ("member %q+#D with constructor not allowed "
6232 : "in anonymous aggregate", field);
6233 61 : if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
6234 0 : error ("member %q+#D with destructor not allowed "
6235 : "in anonymous aggregate", field);
6236 61 : if (TYPE_HAS_COMPLEX_COPY_ASSIGN (type))
6237 0 : error ("member %q+#D with copy assignment operator "
6238 : "not allowed in anonymous aggregate", field);
6239 : }
6240 : }
6241 : }
6242 171000 : }
6243 :
6244 : /* Warn for an attribute located at LOCATION that appertains to the
6245 : class type CLASS_TYPE that has not been properly placed after its
6246 : class-key, in it class-specifier. */
6247 :
6248 : void
6249 109 : warn_misplaced_attr_for_class_type (location_t location,
6250 : tree class_type)
6251 : {
6252 109 : gcc_assert (OVERLOAD_TYPE_P (class_type));
6253 :
6254 109 : auto_diagnostic_group d;
6255 109 : if (warning_at (location, OPT_Wattributes,
6256 : "attribute ignored in declaration "
6257 : "of %q#T", class_type))
6258 109 : inform (location,
6259 : "attribute for %q#T must follow the %qs keyword",
6260 : class_type, class_key_or_enum_as_string (class_type));
6261 109 : }
6262 :
6263 : /* Returns the cv-qualifiers that apply to the type specified
6264 : by the DECLSPECS. */
6265 :
6266 : static int
6267 1020644158 : get_type_quals (const cp_decl_specifier_seq *declspecs)
6268 : {
6269 1020644158 : int type_quals = TYPE_UNQUALIFIED;
6270 :
6271 1020644158 : if (decl_spec_seq_has_spec_p (declspecs, ds_const))
6272 105742490 : type_quals |= TYPE_QUAL_CONST;
6273 1020644158 : if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
6274 1692079 : type_quals |= TYPE_QUAL_VOLATILE;
6275 1020644158 : if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
6276 34 : type_quals |= TYPE_QUAL_RESTRICT;
6277 :
6278 1020644158 : return type_quals;
6279 : }
6280 :
6281 : /* Make sure that a declaration with no declarator is well-formed, i.e.
6282 : just declares a tagged type or anonymous union.
6283 :
6284 : Returns the type declared; or NULL_TREE if none. */
6285 :
6286 : tree
6287 36565486 : check_tag_decl (cp_decl_specifier_seq *declspecs,
6288 : bool explicit_type_instantiation_p)
6289 : {
6290 36565486 : int saw_friend = decl_spec_seq_has_spec_p (declspecs, ds_friend);
6291 36565486 : int saw_typedef = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
6292 : /* If a class, struct, or enum type is declared by the DECLSPECS
6293 : (i.e, if a class-specifier, enum-specifier, or non-typename
6294 : elaborated-type-specifier appears in the DECLSPECS),
6295 : DECLARED_TYPE is set to the corresponding type. */
6296 36565486 : tree declared_type = NULL_TREE;
6297 36565486 : bool error_p = false;
6298 :
6299 36565486 : if (declspecs->multiple_types_p)
6300 26 : error_at (smallest_type_location (declspecs),
6301 : "multiple types in one declaration");
6302 36565460 : else if (declspecs->redefined_builtin_type)
6303 : {
6304 21 : location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
6305 21 : if (!in_system_header_at (loc))
6306 9 : permerror (loc, "redeclaration of C++ built-in type %qT",
6307 : declspecs->redefined_builtin_type);
6308 21 : return NULL_TREE;
6309 : }
6310 :
6311 36565465 : if (declspecs->type
6312 36565450 : && TYPE_P (declspecs->type)
6313 72781339 : && ((TREE_CODE (declspecs->type) != TYPENAME_TYPE
6314 36215104 : && MAYBE_CLASS_TYPE_P (declspecs->type))
6315 1829075 : || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
6316 : declared_type = declspecs->type;
6317 350406 : else if (declspecs->type == error_mark_node)
6318 1499 : error_p = true;
6319 :
6320 36565465 : if (type_uses_auto (declared_type))
6321 : {
6322 8 : error_at (declspecs->locations[ds_type_spec],
6323 : "%<auto%> can only be specified for variables "
6324 : "or function declarations");
6325 8 : return error_mark_node;
6326 : }
6327 :
6328 36565457 : if (declared_type && !OVERLOAD_TYPE_P (declared_type))
6329 : declared_type = NULL_TREE;
6330 :
6331 36565457 : if (!declared_type && !saw_friend && !error_p)
6332 91 : permerror (input_location, "declaration does not declare anything");
6333 : /* Check for an anonymous union. */
6334 36215024 : else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
6335 105509900 : && TYPE_UNNAMED_P (declared_type))
6336 : {
6337 : /* 7/3 In a simple-declaration, the optional init-declarator-list
6338 : can be omitted only when declaring a class (clause 9) or
6339 : enumeration (7.2), that is, when the decl-specifier-seq contains
6340 : either a class-specifier, an elaborated-type-specifier with
6341 : a class-key (9.1), or an enum-specifier. In these cases and
6342 : whenever a class-specifier or enum-specifier is present in the
6343 : decl-specifier-seq, the identifiers in these specifiers are among
6344 : the names being declared by the declaration (as class-name,
6345 : enum-names, or enumerators, depending on the syntax). In such
6346 : cases, and except for the declaration of an unnamed bit-field (9.6),
6347 : the decl-specifier-seq shall introduce one or more names into the
6348 : program, or shall redeclare a name introduced by a previous
6349 : declaration. [Example:
6350 : enum { }; // ill-formed
6351 : typedef class { }; // ill-formed
6352 : --end example] */
6353 171006 : if (saw_typedef)
6354 : {
6355 6 : error_at (declspecs->locations[ds_typedef],
6356 : "missing type-name in typedef-declaration");
6357 6 : return NULL_TREE;
6358 : }
6359 171000 : /* Anonymous unions are objects, so they can have specifiers. */;
6360 171000 : SET_ANON_AGGR_TYPE_P (declared_type);
6361 :
6362 171000 : if (TREE_CODE (declared_type) != UNION_TYPE)
6363 36781 : pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
6364 36781 : OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
6365 : }
6366 :
6367 : else
6368 : {
6369 36394360 : if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
6370 9 : error_at (declspecs->locations[ds_inline],
6371 : "%<inline%> can only be specified for functions");
6372 36394351 : else if (decl_spec_seq_has_spec_p (declspecs, ds_virtual))
6373 3 : error_at (declspecs->locations[ds_virtual],
6374 : "%<virtual%> can only be specified for functions");
6375 36394348 : else if (saw_friend
6376 36394348 : && (!current_class_type
6377 2040889 : || current_scope () != current_class_type))
6378 0 : error_at (declspecs->locations[ds_friend],
6379 : "%<friend%> can only be specified inside a class");
6380 36394348 : else if (decl_spec_seq_has_spec_p (declspecs, ds_explicit))
6381 3 : error_at (declspecs->locations[ds_explicit],
6382 : "%<explicit%> can only be specified for constructors");
6383 36394345 : else if (declspecs->storage_class)
6384 3 : error_at (declspecs->locations[ds_storage_class],
6385 : "a storage class can only be specified for objects "
6386 : "and functions");
6387 36394342 : else if (decl_spec_seq_has_spec_p (declspecs, ds_const))
6388 9 : error_at (declspecs->locations[ds_const],
6389 : "%<const%> can only be specified for objects and "
6390 : "functions");
6391 36394333 : else if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
6392 3 : error_at (declspecs->locations[ds_volatile],
6393 : "%<volatile%> can only be specified for objects and "
6394 : "functions");
6395 36394330 : else if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
6396 3 : error_at (declspecs->locations[ds_restrict],
6397 : "%<__restrict%> can only be specified for objects and "
6398 : "functions");
6399 36394327 : else if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
6400 3 : error_at (declspecs->locations[ds_thread],
6401 : "%<__thread%> can only be specified for objects "
6402 : "and functions");
6403 36394324 : else if (saw_typedef)
6404 24 : warning_at (declspecs->locations[ds_typedef], 0,
6405 : "%<typedef%> was ignored in this declaration");
6406 36394300 : else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
6407 9 : error_at (declspecs->locations[ds_constexpr],
6408 : "%qs cannot be used for type declarations", "constexpr");
6409 36394291 : else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
6410 3 : error_at (declspecs->locations[ds_constinit],
6411 : "%qs cannot be used for type declarations", "constinit");
6412 36394288 : else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
6413 3 : error_at (declspecs->locations[ds_consteval],
6414 : "%qs cannot be used for type declarations", "consteval");
6415 : }
6416 :
6417 36565451 : if (declspecs->attributes && warn_attributes && declared_type)
6418 : {
6419 30 : location_t loc;
6420 24 : if (!CLASS_TYPE_P (declared_type)
6421 54 : || !CLASSTYPE_TEMPLATE_INSTANTIATION (declared_type))
6422 : /* For a non-template class, use the name location. */
6423 21 : loc = location_of (declared_type);
6424 : else
6425 : /* For a template class (an explicit instantiation), use the
6426 : current location. */
6427 9 : loc = input_location;
6428 :
6429 30 : if (explicit_type_instantiation_p)
6430 : /* [dcl.attr.grammar]/4:
6431 :
6432 : No attribute-specifier-seq shall appertain to an explicit
6433 : instantiation. */
6434 : {
6435 6 : auto_diagnostic_group d;
6436 6 : if (warning_at (loc, OPT_Wattributes,
6437 : "attribute ignored in explicit instantiation %q#T",
6438 : declared_type))
6439 6 : inform (loc,
6440 : "no attribute can be applied to "
6441 : "an explicit instantiation");
6442 6 : }
6443 : else
6444 24 : warn_misplaced_attr_for_class_type (loc, declared_type);
6445 : }
6446 :
6447 36565451 : if (declspecs->std_attributes
6448 85 : && declared_type
6449 36565533 : && any_nonignored_attribute_p (declspecs->std_attributes))
6450 : {
6451 82 : auto_diagnostic_group d;
6452 82 : if (warning_at (declspecs->locations[ds_std_attribute], OPT_Wattributes,
6453 : "attribute ignored"))
6454 82 : inform (declspecs->locations[ds_std_attribute],
6455 : "an attribute that appertains to a type-specifier is ignored");
6456 82 : }
6457 :
6458 : return declared_type;
6459 : }
6460 :
6461 : /* Called when a declaration is seen that contains no names to declare.
6462 : If its type is a reference to a structure, union or enum inherited
6463 : from a containing scope, shadow that tag name for the current scope
6464 : with a forward reference.
6465 : If its type defines a new named structure or union
6466 : or defines an enum, it is valid but we need not do anything here.
6467 : Otherwise, it is an error.
6468 :
6469 : C++: may have to grok the declspecs to learn about static,
6470 : complain for anonymous unions.
6471 :
6472 : Returns the TYPE declared -- or NULL_TREE if none. */
6473 :
6474 : tree
6475 32039405 : shadow_tag (cp_decl_specifier_seq *declspecs)
6476 : {
6477 32039405 : tree t = check_tag_decl (declspecs,
6478 : /*explicit_type_instantiation_p=*/false);
6479 :
6480 32039405 : if (!t)
6481 : return NULL_TREE;
6482 :
6483 32037892 : t = maybe_process_partial_specialization (t);
6484 32037892 : if (t == error_mark_node)
6485 : return NULL_TREE;
6486 :
6487 : /* This is where the variables in an anonymous union are
6488 : declared. An anonymous union declaration looks like:
6489 : union { ... } ;
6490 : because there is no declarator after the union, the parser
6491 : sends that declaration here. */
6492 32036054 : if (ANON_AGGR_TYPE_P (t))
6493 : {
6494 316 : fixup_anonymous_aggr (t);
6495 :
6496 316 : if (TYPE_FIELDS (t))
6497 : {
6498 316 : tree decl = grokdeclarator (/*declarator=*/NULL,
6499 : declspecs, NORMAL, 0, NULL);
6500 316 : finish_anon_union (decl);
6501 : }
6502 : }
6503 :
6504 : return t;
6505 : }
6506 :
6507 : /* Decode a "typename", such as "int **", returning a ..._TYPE node. */
6508 :
6509 : tree
6510 398519124 : groktypename (cp_decl_specifier_seq *type_specifiers,
6511 : const cp_declarator *declarator,
6512 : bool is_template_arg)
6513 : {
6514 398519124 : tree attrs;
6515 398519124 : tree type;
6516 65855916 : enum decl_context context
6517 398519124 : = is_template_arg ? TEMPLATE_TYPE_ARG : TYPENAME;
6518 398519124 : attrs = type_specifiers->attributes;
6519 398519124 : type_specifiers->attributes = NULL_TREE;
6520 398519124 : type = grokdeclarator (declarator, type_specifiers, context, 0, &attrs);
6521 398519124 : if (attrs && type != error_mark_node)
6522 : {
6523 674 : if (CLASS_TYPE_P (type))
6524 6 : warning (OPT_Wattributes, "ignoring attributes applied to class type %qT "
6525 : "outside of definition", type);
6526 668 : else if (MAYBE_CLASS_TYPE_P (type))
6527 : /* A template type parameter or other dependent type. */
6528 9 : warning (OPT_Wattributes, "ignoring attributes applied to dependent "
6529 : "type %qT without an associated declaration", type);
6530 : else
6531 659 : cplus_decl_attributes (&type, attrs, 0);
6532 : }
6533 398519124 : return type;
6534 : }
6535 :
6536 : /* Process a DECLARATOR for a function-scope or namespace-scope
6537 : variable or function declaration.
6538 : (Function definitions go through start_function; class member
6539 : declarations appearing in the body of the class go through
6540 : grokfield.) The DECL corresponding to the DECLARATOR is returned.
6541 : If an error occurs, the error_mark_node is returned instead.
6542 :
6543 : DECLSPECS are the decl-specifiers for the declaration. INITIALIZED is
6544 : SD_INITIALIZED if an explicit initializer is present, or SD_DEFAULTED
6545 : for an explicitly defaulted function, or SD_DELETED for an explicitly
6546 : deleted function, but 0 (SD_UNINITIALIZED) if this is a variable
6547 : implicitly initialized via a default constructor. It can also be
6548 : SD_DECOMPOSITION which behaves much like SD_INITIALIZED, but we also
6549 : mark the new decl as DECL_DECOMPOSITION_P.
6550 :
6551 : ATTRIBUTES and PREFIX_ATTRIBUTES are GNU attributes associated with this
6552 : declaration.
6553 :
6554 : The scope represented by the context of the returned DECL is pushed
6555 : (if it is not the global namespace) and is assigned to
6556 : *PUSHED_SCOPE_P. The caller is then responsible for calling
6557 : pop_scope on *PUSHED_SCOPE_P if it is set. */
6558 :
6559 : tree
6560 125466552 : start_decl (const cp_declarator *declarator,
6561 : cp_decl_specifier_seq *declspecs,
6562 : int initialized,
6563 : tree attributes,
6564 : tree prefix_attributes,
6565 : tree *pushed_scope_p)
6566 : {
6567 125466552 : tree decl;
6568 125466552 : tree context;
6569 125466552 : bool was_public;
6570 125466552 : int flags;
6571 125466552 : bool alias;
6572 125466552 : tree initial;
6573 :
6574 125466552 : *pushed_scope_p = NULL_TREE;
6575 :
6576 125466552 : if (prefix_attributes != error_mark_node)
6577 125466550 : attributes = attr_chainon (attributes, prefix_attributes);
6578 :
6579 125466552 : decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
6580 : &attributes);
6581 :
6582 125466552 : if (decl == NULL_TREE || VOID_TYPE_P (decl)
6583 125466552 : || decl == error_mark_node
6584 125464401 : || prefix_attributes == error_mark_node)
6585 2153 : return error_mark_node;
6586 :
6587 125464399 : context = CP_DECL_CONTEXT (decl);
6588 125464399 : if (context != global_namespace)
6589 21800112 : *pushed_scope_p = push_scope (context);
6590 :
6591 125464399 : if (initialized && TREE_CODE (decl) == TYPE_DECL)
6592 : {
6593 27 : error_at (DECL_SOURCE_LOCATION (decl),
6594 : "typedef %qD is initialized (use %qs instead)",
6595 : decl, "decltype");
6596 27 : return error_mark_node;
6597 : }
6598 :
6599 125464372 : if (flag_contracts
6600 9222135 : && TREE_CODE (decl) == FUNCTION_DECL
6601 2604556 : && !processing_template_decl
6602 2102408 : && DECL_RESULT (decl)
6603 127562404 : && is_auto (TREE_TYPE (DECL_RESULT (decl))))
6604 32 : for (tree ca = get_fn_contract_specifiers (decl); ca; ca = TREE_CHAIN (ca))
6605 6 : if (POSTCONDITION_P (CONTRACT_STATEMENT (ca))
6606 6 : && POSTCONDITION_IDENTIFIER (CONTRACT_STATEMENT (ca)))
6607 : {
6608 2 : error_at (DECL_SOURCE_LOCATION (decl),
6609 : "postconditions with deduced result name types must only"
6610 : " appear on function definitions");
6611 2 : return error_mark_node;
6612 : }
6613 : /* Save the DECL_INITIAL value in case it gets clobbered to assist
6614 : with attribute validation. */
6615 125464370 : initial = DECL_INITIAL (decl);
6616 :
6617 125464370 : if (initialized)
6618 : {
6619 60485243 : if (! toplevel_bindings_p ()
6620 60485243 : && DECL_EXTERNAL (decl))
6621 3 : warning (0, "declaration of %q#D has %<extern%> and is initialized",
6622 : decl);
6623 60485243 : DECL_EXTERNAL (decl) = 0;
6624 60485243 : if (toplevel_bindings_p ())
6625 7158582 : TREE_STATIC (decl) = 1;
6626 : /* Tell 'cplus_decl_attributes' this is an initialized decl,
6627 : even though we might not yet have the initializer expression. */
6628 60485243 : if (!DECL_INITIAL (decl))
6629 59926766 : DECL_INITIAL (decl) = error_mark_node;
6630 : }
6631 125464370 : alias = lookup_attribute ("alias", DECL_ATTRIBUTES (decl)) != 0;
6632 :
6633 125464370 : if (alias && TREE_CODE (decl) == FUNCTION_DECL)
6634 3985 : record_key_method_defined (decl);
6635 :
6636 : /* If this is a typedef that names the class for linkage purposes
6637 : (7.1.3p8), apply any attributes directly to the type. */
6638 125464370 : if (TREE_CODE (decl) == TYPE_DECL
6639 125464370 : && TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl))
6640 : flags = ATTR_FLAG_TYPE_IN_PLACE;
6641 : else
6642 : flags = 0;
6643 :
6644 : /* Set attributes here so if duplicate decl, will have proper attributes. */
6645 125464370 : cplus_decl_attributes (&decl, attributes, flags);
6646 :
6647 : /* Restore the original DECL_INITIAL that we may have clobbered earlier to
6648 : assist with attribute validation. */
6649 125464370 : DECL_INITIAL (decl) = initial;
6650 :
6651 : /* Dllimported symbols cannot be defined. Static data members (which
6652 : can be initialized in-class and dllimported) go through grokfield,
6653 : not here, so we don't need to exclude those decls when checking for
6654 : a definition. */
6655 125464370 : if (initialized && DECL_DLLIMPORT_P (decl))
6656 : {
6657 0 : error_at (DECL_SOURCE_LOCATION (decl),
6658 : "definition of %q#D is marked %<dllimport%>", decl);
6659 0 : DECL_DLLIMPORT_P (decl) = 0;
6660 : }
6661 :
6662 : /* If #pragma weak was used, mark the decl weak now. */
6663 125464370 : if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
6664 45991848 : maybe_apply_pragma_weak (decl);
6665 :
6666 125464370 : if (TREE_CODE (decl) == FUNCTION_DECL
6667 37248758 : && DECL_DECLARED_INLINE_P (decl)
6668 3184050 : && DECL_UNINLINABLE (decl)
6669 125464370 : && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
6670 : {
6671 0 : auto_urlify_attributes sentinel;
6672 0 : warning_at (DECL_SOURCE_LOCATION (decl), 0,
6673 : "inline function %qD given attribute %qs", decl, "noinline");
6674 0 : }
6675 :
6676 125464370 : if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
6677 : {
6678 837890 : bool this_tmpl = (current_template_depth
6679 837890 : > template_class_depth (context));
6680 837890 : if (VAR_P (decl))
6681 : {
6682 486356 : tree field = lookup_field (context, DECL_NAME (decl), 0, false);
6683 486356 : if (field == NULL_TREE
6684 486356 : || !(VAR_P (field) || variable_template_p (field)))
6685 6 : error ("%q+#D is not a static data member of %q#T", decl, context);
6686 486350 : else if (variable_template_p (field)
6687 486350 : && (DECL_LANG_SPECIFIC (decl)
6688 147 : && DECL_TEMPLATE_SPECIALIZATION (decl)))
6689 : /* OK, specialization was already checked. */;
6690 486281 : else if (variable_template_p (field) && !this_tmpl)
6691 : {
6692 3 : auto_diagnostic_group d;
6693 3 : error_at (DECL_SOURCE_LOCATION (decl),
6694 : "non-member-template declaration of %qD", decl);
6695 3 : inform (DECL_SOURCE_LOCATION (field), "does not match "
6696 : "member template declaration here");
6697 3 : return error_mark_node;
6698 3 : }
6699 : else
6700 : {
6701 486278 : if (variable_template_p (field))
6702 75 : field = DECL_TEMPLATE_RESULT (field);
6703 :
6704 486278 : if (DECL_CONTEXT (field) != context)
6705 : {
6706 3 : if (!same_type_p (DECL_CONTEXT (field), context))
6707 3 : permerror (input_location, "ISO C++ does not permit %<%T::%D%> "
6708 : "to be defined as %<%T::%D%>",
6709 3 : DECL_CONTEXT (field), DECL_NAME (decl),
6710 3 : context, DECL_NAME (decl));
6711 3 : DECL_CONTEXT (decl) = DECL_CONTEXT (field);
6712 : }
6713 :
6714 486278 : if (modules_p () && !module_may_redeclare (field))
6715 30 : return error_mark_node;
6716 :
6717 : /* Static data member are tricky; an in-class initialization
6718 : still doesn't provide a definition, so the in-class
6719 : declaration will have DECL_EXTERNAL set, but will have an
6720 : initialization. Thus, duplicate_decls won't warn
6721 : about this situation, and so we check here. */
6722 486248 : if (initialized && DECL_INITIALIZED_IN_CLASS_P (field))
6723 9 : error ("duplicate initialization of %qD", decl);
6724 486248 : field = duplicate_decls (decl, field);
6725 486248 : if (field == error_mark_node)
6726 : return error_mark_node;
6727 486192 : else if (field)
6728 486192 : decl = field;
6729 : }
6730 : }
6731 : else
6732 : {
6733 351546 : tree field = check_classfn (context, decl,
6734 : this_tmpl
6735 12 : ? current_template_parms
6736 : : NULL_TREE);
6737 351459 : if (field && field != error_mark_node
6738 702993 : && duplicate_decls (decl, field))
6739 351459 : decl = field;
6740 : }
6741 :
6742 : /* cp_finish_decl sets DECL_EXTERNAL if DECL_IN_AGGR_P is set. */
6743 837801 : DECL_IN_AGGR_P (decl) = 0;
6744 : /* Do not mark DECL as an explicit specialization if it was not
6745 : already marked as an instantiation; a declaration should
6746 : never be marked as a specialization unless we know what
6747 : template is being specialized. */
6748 837801 : if (DECL_LANG_SPECIFIC (decl) && DECL_USE_TEMPLATE (decl))
6749 : {
6750 349593 : SET_DECL_TEMPLATE_SPECIALIZATION (decl);
6751 349593 : if (TREE_CODE (decl) == FUNCTION_DECL)
6752 329442 : DECL_COMDAT (decl) = (TREE_PUBLIC (decl)
6753 329442 : && DECL_NONGNU_INLINE_P (decl));
6754 : else
6755 20151 : DECL_COMDAT (decl) = false;
6756 :
6757 : /* [temp.expl.spec] An explicit specialization of a static data
6758 : member of a template is a definition if the declaration
6759 : includes an initializer; otherwise, it is a declaration.
6760 :
6761 : We check for processing_specialization so this only applies
6762 : to the new specialization syntax. */
6763 349593 : if (!initialized && processing_specialization)
6764 349391 : DECL_EXTERNAL (decl) = 1;
6765 : }
6766 :
6767 1187240 : if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
6768 : /* Aliases are definitions. */
6769 837837 : && !alias)
6770 : {
6771 9 : permerror (declarator->id_loc,
6772 : "declaration of %q#D outside of class is not definition",
6773 : decl);
6774 : }
6775 : }
6776 :
6777 : /* Create a DECL_LANG_SPECIFIC so that DECL_DECOMPOSITION_P works. */
6778 125464281 : if (initialized == SD_DECOMPOSITION)
6779 440561 : fit_decomposition_lang_decl (decl, NULL_TREE);
6780 :
6781 125464281 : was_public = TREE_PUBLIC (decl);
6782 :
6783 213672348 : if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
6784 126022782 : && current_function_decl)
6785 : {
6786 : /* A function-scope decl of some namespace-scope decl. */
6787 60029 : DECL_LOCAL_DECL_P (decl) = true;
6788 60029 : if (named_module_attach_p ())
6789 3 : error_at (declarator->id_loc,
6790 : "block-scope extern declaration %q#D must not be"
6791 : " attached to a named module", decl);
6792 : }
6793 :
6794 : /* Enter this declaration into the symbol table. Don't push the plain
6795 : VAR_DECL for a variable template. */
6796 125464281 : if (!template_parm_scope_p ()
6797 125464281 : || !VAR_P (decl))
6798 121489793 : decl = maybe_push_decl (decl);
6799 :
6800 125464281 : if (processing_template_decl)
6801 79466938 : decl = push_template_decl (decl);
6802 :
6803 125464281 : if (decl == error_mark_node)
6804 : return error_mark_node;
6805 :
6806 125463845 : if (VAR_P (decl)
6807 66603702 : && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
6808 67322 : && !DECL_THIS_STATIC (decl) && !DECL_ARTIFICIAL (decl)
6809 : /* But not templated variables. */
6810 125492306 : && !(DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl)))
6811 : {
6812 : /* This is a const variable with implicit 'static'. Set
6813 : DECL_THIS_STATIC so we can tell it from variables that are
6814 : !TREE_PUBLIC because of the anonymous namespace. */
6815 28461 : gcc_assert (CP_TYPE_CONST_P (TREE_TYPE (decl)) || errorcount);
6816 28461 : DECL_THIS_STATIC (decl) = 1;
6817 : }
6818 :
6819 70859307 : if (current_function_decl && VAR_P (decl)
6820 58645122 : && maybe_constexpr_fn (current_function_decl)
6821 140066536 : && cxx_dialect < cxx23)
6822 : {
6823 12520041 : bool ok = false;
6824 12520041 : if (CP_DECL_THREAD_LOCAL_P (decl) && !DECL_REALLY_EXTERN (decl))
6825 : {
6826 9 : if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
6827 18 : error_at (DECL_SOURCE_LOCATION (decl),
6828 : "%qD defined %<thread_local%> in %qs function only "
6829 : "available with %<-std=c++23%> or %<-std=gnu++23%>", decl,
6830 9 : DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
6831 : ? "consteval" : "constexpr");
6832 : }
6833 12520032 : else if (TREE_STATIC (decl))
6834 : {
6835 50 : if (DECL_DECLARED_CONSTEXPR_P (current_function_decl))
6836 72 : error_at (DECL_SOURCE_LOCATION (decl),
6837 : "%qD defined %<static%> in %qs function only available "
6838 : "with %<-std=c++23%> or %<-std=gnu++23%>", decl,
6839 36 : DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
6840 : ? "consteval" : "constexpr");
6841 : }
6842 : else
6843 : ok = true;
6844 45 : if (!ok)
6845 59 : cp_function_chain->invalid_constexpr = true;
6846 : }
6847 :
6848 125463845 : if (!processing_template_decl && VAR_P (decl))
6849 8399538 : start_decl_1 (decl, initialized);
6850 :
6851 125463842 : return decl;
6852 : }
6853 :
6854 : /* Process the declaration of a variable DECL. INITIALIZED is true
6855 : iff DECL is explicitly initialized. (INITIALIZED is false if the
6856 : variable is initialized via an implicitly-called constructor.)
6857 : This function must be called for ordinary variables (including, for
6858 : example, implicit instantiations of templates), but must not be
6859 : called for template declarations. */
6860 :
6861 : void
6862 8407734 : start_decl_1 (tree decl, bool initialized)
6863 : {
6864 8407734 : gcc_checking_assert (!processing_template_decl);
6865 :
6866 8407734 : if (error_operand_p (decl))
6867 : return;
6868 :
6869 8407719 : gcc_checking_assert (VAR_P (decl));
6870 :
6871 8407719 : tree type = TREE_TYPE (decl);
6872 8407719 : bool complete_p = COMPLETE_TYPE_P (type);
6873 8407719 : bool aggregate_definition_p
6874 8407719 : = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
6875 :
6876 : /* If an explicit initializer is present, or if this is a definition
6877 : of an aggregate, then we need a complete type at this point.
6878 : (Scalars are always complete types, so there is nothing to
6879 : check.) This code just sets COMPLETE_P; errors (if necessary)
6880 : are issued below. */
6881 4347797 : if ((initialized || aggregate_definition_p)
6882 7396680 : && !complete_p
6883 5964782 : && COMPLETE_TYPE_P (complete_type (type)))
6884 : {
6885 328354 : complete_p = true;
6886 : /* We will not yet have set TREE_READONLY on DECL if the type
6887 : was "const", but incomplete, before this point. But, now, we
6888 : have a complete type, so we can try again. */
6889 328354 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
6890 : }
6891 :
6892 8407716 : if (initialized)
6893 : /* Is it valid for this decl to have an initializer at all? */
6894 : {
6895 : /* Don't allow initializations for incomplete types except for
6896 : arrays which might be completed by the initialization. */
6897 6662236 : if (complete_p)
6898 : ; /* A complete type is ok. */
6899 1288394 : else if (type_uses_auto (type))
6900 : ; /* An auto type is ok. */
6901 119512 : else if (TREE_CODE (type) != ARRAY_TYPE)
6902 : {
6903 27 : auto_diagnostic_group d;
6904 27 : error ("variable %q#D has initializer but incomplete type", decl);
6905 48 : maybe_suggest_missing_header (input_location,
6906 27 : TYPE_IDENTIFIER (type),
6907 27 : CP_TYPE_CONTEXT (type));
6908 27 : type = TREE_TYPE (decl) = error_mark_node;
6909 27 : }
6910 119485 : else if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
6911 : {
6912 0 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
6913 0 : error ("elements of array %q#D have incomplete type", decl);
6914 : /* else we already gave an error in start_decl. */
6915 : }
6916 : }
6917 1745480 : else if (aggregate_definition_p && !complete_p)
6918 : {
6919 234 : if (type_uses_auto (type))
6920 69 : gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (type));
6921 : else
6922 : {
6923 165 : auto_diagnostic_group d;
6924 165 : error ("aggregate %q#D has incomplete type and cannot be defined",
6925 : decl);
6926 285 : maybe_suggest_missing_header (input_location,
6927 165 : TYPE_IDENTIFIER (type),
6928 165 : CP_TYPE_CONTEXT (type));
6929 : /* Change the type so that assemble_variable will give
6930 : DECL an rtl we can live with: (mem (const_int 0)). */
6931 165 : type = TREE_TYPE (decl) = error_mark_node;
6932 165 : }
6933 : }
6934 :
6935 : /* Create a new scope to hold this declaration if necessary.
6936 : Whether or not a new scope is necessary cannot be determined
6937 : until after the type has been completed; if the type is a
6938 : specialization of a class template it is not until after
6939 : instantiation has occurred that TYPE_HAS_NONTRIVIAL_DESTRUCTOR
6940 : will be set correctly. */
6941 8407716 : maybe_push_cleanup_level (type);
6942 : }
6943 :
6944 : /* Given a parenthesized list of values INIT, create a CONSTRUCTOR to handle
6945 : C++20 P0960. TYPE is the type of the object we're initializing. */
6946 :
6947 : tree
6948 301 : do_aggregate_paren_init (tree init, tree type)
6949 : {
6950 301 : tree val = TREE_VALUE (init);
6951 :
6952 301 : if (TREE_CHAIN (init) == NULL_TREE)
6953 : {
6954 : /* If the list has a single element and it's a string literal,
6955 : then it's the initializer for the array as a whole. */
6956 185 : if (TREE_CODE (type) == ARRAY_TYPE
6957 185 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
6958 231 : && TREE_CODE (tree_strip_any_location_wrapper (val))
6959 : == STRING_CST)
6960 : return val;
6961 : /* Handle non-standard extensions like compound literals. This also
6962 : prevents triggering aggregate parenthesized-initialization in
6963 : compiler-generated code for =default. */
6964 146 : else if (same_type_ignoring_top_level_qualifiers_p (type,
6965 146 : TREE_TYPE (val)))
6966 : return val;
6967 : }
6968 :
6969 200 : init = build_constructor_from_list (init_list_type_node, init);
6970 200 : CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
6971 200 : CONSTRUCTOR_IS_PAREN_INIT (init) = true;
6972 200 : return init;
6973 : }
6974 :
6975 : /* Handle initialization of references. DECL, TYPE, and INIT have the
6976 : same meaning as in cp_finish_decl. *CLEANUP must be NULL on entry,
6977 : but will be set to a new CLEANUP_STMT if a temporary is created
6978 : that must be destroyed subsequently.
6979 :
6980 : Returns an initializer expression to use to initialize DECL, or
6981 : NULL if the initialization can be performed statically.
6982 :
6983 : Quotes on semantics can be found in ARM 8.4.3. */
6984 :
6985 : static tree
6986 358549 : grok_reference_init (tree decl, tree type, tree init, int flags)
6987 : {
6988 358549 : if (init == NULL_TREE)
6989 : {
6990 15 : if ((DECL_LANG_SPECIFIC (decl) == 0
6991 3 : || DECL_IN_AGGR_P (decl) == 0)
6992 18 : && ! DECL_THIS_EXTERN (decl))
6993 15 : error_at (DECL_SOURCE_LOCATION (decl),
6994 : "%qD declared as reference but not initialized", decl);
6995 15 : return NULL_TREE;
6996 : }
6997 :
6998 358534 : tree ttype = TREE_TYPE (type);
6999 358534 : if (TREE_CODE (init) == TREE_LIST)
7000 : {
7001 : /* This handles (C++20 only) code like
7002 :
7003 : const A& r(1, 2, 3);
7004 :
7005 : where we treat the parenthesized list as a CONSTRUCTOR. */
7006 1167 : if (TREE_TYPE (init) == NULL_TREE
7007 1167 : && CP_AGGREGATE_TYPE_P (ttype)
7008 69 : && !DECL_DECOMPOSITION_P (decl)
7009 1233 : && (cxx_dialect >= cxx20))
7010 : {
7011 : /* We don't know yet if we should treat const A& r(1) as
7012 : const A& r{1}. */
7013 60 : if (list_length (init) == 1)
7014 : {
7015 39 : flags |= LOOKUP_AGGREGATE_PAREN_INIT;
7016 39 : init = build_x_compound_expr_from_list (init, ELK_INIT,
7017 : tf_warning_or_error);
7018 : }
7019 : /* If the list had more than one element, the code is ill-formed
7020 : pre-C++20, so we can build a constructor right away. */
7021 : else
7022 21 : init = do_aggregate_paren_init (init, ttype);
7023 : }
7024 : else
7025 1107 : init = build_x_compound_expr_from_list (init, ELK_INIT,
7026 : tf_warning_or_error);
7027 : }
7028 :
7029 358534 : if (TREE_CODE (ttype) != ARRAY_TYPE
7030 358534 : && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
7031 : /* Note: default conversion is only called in very special cases. */
7032 12 : init = decay_conversion (init, tf_warning_or_error);
7033 :
7034 : /* check_initializer handles this for non-reference variables, but for
7035 : references we need to do it here or the initializer will get the
7036 : incomplete array type and confuse later calls to
7037 : cp_complete_array_type. */
7038 358534 : if (TREE_CODE (ttype) == ARRAY_TYPE
7039 22487 : && TYPE_DOMAIN (ttype) == NULL_TREE
7040 358617 : && (BRACE_ENCLOSED_INITIALIZER_P (init)
7041 50 : || TREE_CODE (init) == STRING_CST))
7042 : {
7043 33 : cp_complete_array_type (&ttype, init, false);
7044 33 : if (ttype != TREE_TYPE (type))
7045 33 : type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
7046 : }
7047 :
7048 : /* Convert INIT to the reference type TYPE. This may involve the
7049 : creation of a temporary, whose lifetime must be the same as that
7050 : of the reference. If so, a DECL_EXPR for the temporary will be
7051 : added just after the DECL_EXPR for DECL. That's why we don't set
7052 : DECL_INITIAL for local references (instead assigning to them
7053 : explicitly); we need to allow the temporary to be initialized
7054 : first. */
7055 358534 : return initialize_reference (type, init, flags,
7056 358534 : tf_warning_or_error);
7057 : }
7058 :
7059 : /* Designated initializers in arrays are not supported in GNU C++.
7060 : The parser cannot detect this error since it does not know whether
7061 : a given brace-enclosed initializer is for a class type or for an
7062 : array. This function checks that CE does not use a designated
7063 : initializer. If it does, an error is issued. Returns true if CE
7064 : is valid, i.e., does not have a designated initializer. */
7065 :
7066 : bool
7067 148315282 : check_array_designated_initializer (constructor_elt *ce,
7068 : unsigned HOST_WIDE_INT index)
7069 : {
7070 : /* Designated initializers for array elements are not supported. */
7071 148315282 : if (ce->index)
7072 : {
7073 : /* The parser only allows identifiers as designated
7074 : initializers. */
7075 100083870 : if (ce->index == error_mark_node)
7076 : {
7077 0 : error ("name used in a GNU-style designated "
7078 : "initializer for an array");
7079 0 : return false;
7080 : }
7081 100083870 : else if (identifier_p (ce->index))
7082 : {
7083 19 : error ("name %qD used in a GNU-style designated "
7084 : "initializer for an array", ce->index);
7085 19 : ce->index = error_mark_node;
7086 19 : return false;
7087 : }
7088 :
7089 100083851 : tree ce_index = build_expr_type_conversion (WANT_INT | WANT_ENUM,
7090 : ce->index, true);
7091 100083851 : if (ce_index
7092 100083848 : && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ce_index))
7093 200167696 : && (TREE_CODE (ce_index = fold_non_dependent_expr (ce_index))
7094 : == INTEGER_CST))
7095 : {
7096 : /* A C99 designator is OK if it matches the current index. */
7097 100083845 : if (wi::to_wide (ce_index) == index)
7098 : {
7099 100083839 : ce->index = ce_index;
7100 100083839 : return true;
7101 : }
7102 : else
7103 6 : sorry ("non-trivial designated initializers not supported");
7104 : }
7105 : else
7106 6 : error_at (cp_expr_loc_or_input_loc (ce->index),
7107 : "C99 designator %qE is not an integral constant-expression",
7108 : ce->index);
7109 :
7110 12 : return false;
7111 : }
7112 :
7113 : return true;
7114 : }
7115 :
7116 : /* When parsing `int a[] = {1, 2};' we don't know the size of the
7117 : array until we finish parsing the initializer. If that's the
7118 : situation we're in, update DECL accordingly. */
7119 :
7120 : static void
7121 72175583 : maybe_deduce_size_from_array_init (tree decl, tree init)
7122 : {
7123 72175583 : tree type = TREE_TYPE (decl);
7124 :
7125 72175583 : if (TREE_CODE (type) == ARRAY_TYPE
7126 921489 : && TYPE_DOMAIN (type) == NULL_TREE
7127 72773709 : && TREE_CODE (decl) != TYPE_DECL)
7128 : {
7129 : /* do_default is really a C-ism to deal with tentative definitions.
7130 : But let's leave it here to ease the eventual merge. */
7131 598126 : int do_default = !DECL_EXTERNAL (decl);
7132 598126 : tree initializer = init ? init : DECL_INITIAL (decl);
7133 598126 : int failure = 0;
7134 :
7135 : /* Check that there are no designated initializers in INIT, as
7136 : those are not supported in GNU C++, and as the middle-end
7137 : will crash if presented with a non-numeric designated
7138 : initializer. */
7139 598126 : if (initializer && BRACE_ENCLOSED_INITIALIZER_P (initializer))
7140 : {
7141 141190 : vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initializer);
7142 141190 : constructor_elt *ce;
7143 141190 : HOST_WIDE_INT i, j = 0;
7144 46517336 : FOR_EACH_VEC_SAFE_ELT (v, i, ce)
7145 : {
7146 46376881 : if (instantiation_dependent_expression_p (ce->index))
7147 72175583 : return;
7148 46376875 : if (!check_array_designated_initializer (ce, j))
7149 1 : failure = 1;
7150 : /* If an un-designated initializer is type-dependent, we can't
7151 : check brace elision yet. */
7152 46376875 : if (ce->index == NULL_TREE
7153 46376875 : && type_dependent_expression_p (ce->value))
7154 : return;
7155 46376146 : if (TREE_CODE (ce->value) == RAW_DATA_CST)
7156 200 : j += RAW_DATA_LENGTH (ce->value);
7157 : else
7158 46375946 : ++j;
7159 : }
7160 : }
7161 :
7162 140455 : if (failure)
7163 1 : TREE_TYPE (decl) = error_mark_node;
7164 : else
7165 : {
7166 597390 : failure = cp_complete_array_type (&TREE_TYPE (decl), initializer,
7167 : do_default);
7168 597390 : if (failure == 1)
7169 : {
7170 33 : error_at (cp_expr_loc_or_loc (initializer,
7171 30 : DECL_SOURCE_LOCATION (decl)),
7172 : "initializer fails to determine size of %qD", decl);
7173 : }
7174 597360 : else if (failure == 2)
7175 : {
7176 30 : if (do_default)
7177 : {
7178 6 : error_at (DECL_SOURCE_LOCATION (decl),
7179 : "array size missing in %qD", decl);
7180 : }
7181 : /* If a `static' var's size isn't known, make it extern as
7182 : well as static, so it does not get allocated. If it's not
7183 : `static', then don't mark it extern; finish_incomplete_decl
7184 : will give it a default size and it will get allocated. */
7185 24 : else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl))
7186 0 : DECL_EXTERNAL (decl) = 1;
7187 : }
7188 597330 : else if (failure == 3)
7189 : {
7190 6 : error_at (DECL_SOURCE_LOCATION (decl),
7191 : "zero-size array %qD", decl);
7192 : }
7193 : }
7194 :
7195 597391 : cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl);
7196 :
7197 597391 : relayout_decl (decl);
7198 :
7199 : /* Update the type of the corresponding TEMPLATE_DECL to match. */
7200 597391 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
7201 : {
7202 208 : tree tmpl = template_for_substitution (decl);
7203 208 : if (DECL_TEMPLATE_RESULT (tmpl) == decl)
7204 50 : TREE_TYPE (tmpl) = TREE_TYPE (decl);
7205 : }
7206 : }
7207 : }
7208 :
7209 : /* Set DECL_SIZE, DECL_ALIGN, etc. for DECL (a VAR_DECL), and issue
7210 : any appropriate error messages regarding the layout. */
7211 :
7212 : static void
7213 61756690 : layout_var_decl (tree decl)
7214 : {
7215 61756690 : tree type;
7216 :
7217 61756690 : type = TREE_TYPE (decl);
7218 61756690 : if (type == error_mark_node)
7219 : return;
7220 :
7221 : /* If we haven't already laid out this declaration, do so now.
7222 : Note that we must not call complete type for an external object
7223 : because it's type might involve templates that we are not
7224 : supposed to instantiate yet. (And it's perfectly valid to say
7225 : `extern X x' for some incomplete type `X'.) */
7226 61756643 : if (!DECL_EXTERNAL (decl))
7227 51634676 : complete_type (type);
7228 61756643 : if (!DECL_SIZE (decl)
7229 602021 : && TREE_TYPE (decl) != error_mark_node
7230 62358664 : && complete_or_array_type_p (type))
7231 457788 : layout_decl (decl, 0);
7232 :
7233 61756643 : if (!DECL_EXTERNAL (decl) && DECL_SIZE (decl) == NULL_TREE)
7234 : {
7235 : /* An automatic variable with an incomplete type: that is an error.
7236 : Don't talk about array types here, since we took care of that
7237 : message in grokdeclarator. */
7238 17 : error_at (DECL_SOURCE_LOCATION (decl),
7239 : "storage size of %qD isn%'t known", decl);
7240 17 : TREE_TYPE (decl) = error_mark_node;
7241 : }
7242 : #if 0
7243 : /* Keep this code around in case we later want to control debug info
7244 : based on whether a type is "used". (jason 1999-11-11) */
7245 :
7246 : else if (!DECL_EXTERNAL (decl) && MAYBE_CLASS_TYPE_P (ttype))
7247 : /* Let debugger know it should output info for this type. */
7248 : note_debug_info_needed (ttype);
7249 :
7250 : if (TREE_STATIC (decl) && DECL_CLASS_SCOPE_P (decl))
7251 : note_debug_info_needed (DECL_CONTEXT (decl));
7252 : #endif
7253 :
7254 113391319 : if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
7255 38096684 : && DECL_SIZE (decl) != NULL_TREE
7256 99580089 : && ! TREE_CONSTANT (DECL_SIZE (decl)))
7257 : {
7258 6 : if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
7259 6 : && !DECL_LOCAL_DECL_P (decl))
7260 0 : constant_expression_warning (DECL_SIZE (decl));
7261 : else
7262 : {
7263 6 : error_at (DECL_SOURCE_LOCATION (decl),
7264 : "storage size of %qD isn%'t constant", decl);
7265 6 : TREE_TYPE (decl) = error_mark_node;
7266 6 : type = error_mark_node;
7267 : }
7268 : }
7269 :
7270 : /* If the final element initializes a flexible array field, adjust
7271 : the size of the DECL with the initializer based on whether the
7272 : DECL is a union or a structure. */
7273 61756643 : if (type != error_mark_node
7274 61756637 : && DECL_INITIAL (decl)
7275 36519906 : && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
7276 5018838 : && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl)))
7277 3383875 : && DECL_SIZE (decl) != NULL_TREE
7278 3383875 : && TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST
7279 3383875 : && COMPLETE_TYPE_P (type)
7280 3383875 : && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
7281 65140518 : && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type)))
7282 : {
7283 3383875 : constructor_elt &elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ();
7284 3383875 : if (elt.index)
7285 : {
7286 1232037 : tree itype = TREE_TYPE (elt.index);
7287 1232037 : tree vtype = TREE_TYPE (elt.value);
7288 1232037 : if (TREE_CODE (itype) == ARRAY_TYPE
7289 80327 : && TYPE_DOMAIN (itype) == NULL
7290 275 : && TREE_CODE (vtype) == ARRAY_TYPE
7291 1232312 : && COMPLETE_TYPE_P (vtype))
7292 : {
7293 : /* For a structure, add the size of the initializer to the DECL's
7294 : size. */
7295 275 : if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE)
7296 : {
7297 260 : DECL_SIZE (decl)
7298 260 : = size_binop (PLUS_EXPR, DECL_SIZE (decl),
7299 : TYPE_SIZE (vtype));
7300 260 : DECL_SIZE_UNIT (decl)
7301 520 : = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl),
7302 : TYPE_SIZE_UNIT (vtype));
7303 : }
7304 : /* For a union, the DECL's size is the maximum of the current size
7305 : and the size of the initializer. */
7306 : else
7307 : {
7308 15 : DECL_SIZE (decl)
7309 15 : = size_binop (MAX_EXPR, DECL_SIZE (decl),
7310 : TYPE_SIZE (vtype));
7311 15 : DECL_SIZE_UNIT (decl)
7312 30 : = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl),
7313 : TYPE_SIZE_UNIT (vtype));
7314 : }
7315 : }
7316 : }
7317 : }
7318 : }
7319 :
7320 : /* If a local static variable is declared in an inline function, or if
7321 : we have a weak definition, we must endeavor to create only one
7322 : instance of the variable at link-time. */
7323 :
7324 : void
7325 76020124 : maybe_commonize_var (tree decl)
7326 : {
7327 : /* Don't mess with __FUNCTION__ and similar. But do handle structured
7328 : bindings. */
7329 76020124 : if (DECL_ARTIFICIAL (decl) && !DECL_DECOMPOSITION_P (decl))
7330 : return;
7331 :
7332 : /* Static data in a function with comdat linkage also has comdat
7333 : linkage. */
7334 70877844 : if ((TREE_STATIC (decl)
7335 46939713 : && DECL_FUNCTION_SCOPE_P (decl)
7336 135461 : && vague_linkage_p (DECL_CONTEXT (decl)))
7337 164940394 : || (TREE_PUBLIC (decl) && DECL_INLINE_VAR_P (decl)))
7338 : {
7339 41080526 : if (flag_weak)
7340 : {
7341 : /* With weak symbols, we simply make the variable COMDAT;
7342 : that will cause copies in multiple translations units to
7343 : be merged. */
7344 41080499 : comdat_linkage (decl);
7345 : }
7346 : else
7347 : {
7348 27 : if (DECL_INITIAL (decl) == NULL_TREE
7349 27 : || DECL_INITIAL (decl) == error_mark_node)
7350 : {
7351 : /* Without weak symbols, we can use COMMON to merge
7352 : uninitialized variables. */
7353 24 : TREE_PUBLIC (decl) = 1;
7354 24 : DECL_COMMON (decl) = 1;
7355 : }
7356 : else
7357 : {
7358 : /* While for initialized variables, we must use internal
7359 : linkage -- which means that multiple copies will not
7360 : be merged. */
7361 3 : TREE_PUBLIC (decl) = 0;
7362 3 : DECL_COMMON (decl) = 0;
7363 3 : DECL_INTERFACE_KNOWN (decl) = 1;
7364 3 : const char *msg;
7365 3 : if (DECL_INLINE_VAR_P (decl))
7366 : msg = G_("sorry: semantics of inline variable "
7367 : "%q#D are wrong (you%'ll wind up with "
7368 : "multiple copies)");
7369 : else
7370 : msg = G_("sorry: semantics of inline function "
7371 : "static data %q#D are wrong (you%'ll wind "
7372 : "up with multiple copies)");
7373 3 : auto_diagnostic_group d;
7374 3 : if (warning_at (DECL_SOURCE_LOCATION (decl), 0,
7375 : msg, decl))
7376 3 : inform (DECL_SOURCE_LOCATION (decl),
7377 : "you can work around this by removing the initializer");
7378 3 : }
7379 : }
7380 : }
7381 : }
7382 :
7383 : /* Issue an error message if DECL is an uninitialized const variable.
7384 : CONSTEXPR_CONTEXT_P is true when the function is called in a constexpr
7385 : context from potential_constant_expression. Returns true if all is well,
7386 : false otherwise. */
7387 :
7388 : bool
7389 8508549 : check_for_uninitialized_const_var (tree decl, bool constexpr_context_p,
7390 : tsubst_flags_t complain)
7391 : {
7392 8508549 : tree type = strip_array_types (TREE_TYPE (decl));
7393 :
7394 : /* ``Unless explicitly declared extern, a const object does not have
7395 : external linkage and must be initialized. ($8.4; $12.1)'' ARM
7396 : 7.1.6 */
7397 8508549 : if (VAR_P (decl)
7398 8508549 : && !TYPE_REF_P (type)
7399 8465094 : && (CP_TYPE_CONST_P (type)
7400 : /* C++20 permits trivial default initialization in constexpr
7401 : context (P1331R2). */
7402 6569711 : || (cxx_dialect < cxx20
7403 136500 : && (constexpr_context_p
7404 123124 : || var_in_constexpr_fn (decl))))
7405 10419404 : && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
7406 : {
7407 627919 : tree field = default_init_uninitialized_part (type);
7408 627919 : if (!field)
7409 : return true;
7410 :
7411 3914 : auto_diagnostic_group d;
7412 3914 : bool show_notes = true;
7413 :
7414 3914 : if (!constexpr_context_p || cxx_dialect >= cxx20)
7415 : {
7416 188 : if (CP_TYPE_CONST_P (type))
7417 : {
7418 90 : if (complain & tf_error)
7419 84 : show_notes = permerror (DECL_SOURCE_LOCATION (decl),
7420 : "uninitialized %<const %D%>", decl);
7421 : }
7422 : else
7423 : {
7424 98 : if (!is_instantiation_of_constexpr (current_function_decl)
7425 98 : && (complain & tf_error))
7426 21 : error_at (DECL_SOURCE_LOCATION (decl),
7427 : "uninitialized variable %qD in %<constexpr%> "
7428 : "function", decl);
7429 : else
7430 : show_notes = false;
7431 98 : cp_function_chain->invalid_constexpr = true;
7432 : }
7433 : }
7434 3726 : else if (complain & tf_error)
7435 2 : error_at (DECL_SOURCE_LOCATION (decl),
7436 : "uninitialized variable %qD in %<constexpr%> context",
7437 : decl);
7438 :
7439 3914 : if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
7440 : {
7441 62 : tree defaulted_ctor;
7442 :
7443 62 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
7444 : "%q#T has no user-provided default constructor", type);
7445 62 : defaulted_ctor = in_class_defaulted_default_constructor (type);
7446 62 : if (defaulted_ctor)
7447 33 : inform (DECL_SOURCE_LOCATION (defaulted_ctor),
7448 : "constructor is not user-provided because it is "
7449 : "explicitly defaulted in the class body");
7450 62 : inform (DECL_SOURCE_LOCATION (field),
7451 : "and the implicitly-defined constructor does not "
7452 : "initialize %q#D", field);
7453 : }
7454 :
7455 3914 : return false;
7456 3914 : }
7457 :
7458 : return true;
7459 : }
7460 :
7461 : /* Structure holding the current initializer being processed by reshape_init.
7462 : CUR is a pointer to the current element being processed, END is a pointer
7463 : after the last element present in the initializer and RAW_IDX is index into
7464 : RAW_DATA_CST if that is CUR elt. */
7465 : struct reshape_iter
7466 : {
7467 : constructor_elt *cur;
7468 : constructor_elt *end;
7469 : unsigned raw_idx;
7470 : };
7471 :
7472 : static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
7473 :
7474 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
7475 : returned is the next FIELD_DECL (possibly FIELD itself) that can be
7476 : initialized as if for an aggregate class. If there are no more such fields,
7477 : the return value will be NULL. */
7478 :
7479 : tree
7480 13303049 : next_aggregate_field (tree field)
7481 : {
7482 13303049 : while (field
7483 52939685 : && (TREE_CODE (field) != FIELD_DECL
7484 8255698 : || DECL_UNNAMED_BIT_FIELD (field)
7485 8255543 : || (DECL_ARTIFICIAL (field)
7486 : /* In C++17, aggregates can have bases. */
7487 179104 : && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field)))))
7488 39636636 : field = DECL_CHAIN (field);
7489 :
7490 13303049 : return field;
7491 : }
7492 :
7493 : /* FIELD is an element of TYPE_FIELDS or NULL. In the former case, the value
7494 : returned is the next FIELD_DECL (possibly FIELD itself) that corresponds
7495 : to a subobject. If there are no more such fields, the return value will be
7496 : NULL. */
7497 :
7498 : tree
7499 64489556 : next_subobject_field (tree field)
7500 : {
7501 64489556 : while (field
7502 830702549 : && (TREE_CODE (field) != FIELD_DECL
7503 28538305 : || DECL_UNNAMED_BIT_FIELD (field)
7504 28538173 : || (DECL_ARTIFICIAL (field)
7505 8025153 : && !DECL_FIELD_IS_BASE (field)
7506 1740230 : && !DECL_VIRTUAL_P (field))))
7507 766212993 : field = DECL_CHAIN (field);
7508 :
7509 64489556 : return field;
7510 : }
7511 :
7512 : /* Return true for [dcl.init.list] direct-list-initialization from
7513 : single element of enumeration with a fixed underlying type. */
7514 :
7515 : bool
7516 177486540 : is_direct_enum_init (tree type, tree init)
7517 : {
7518 177486540 : if (cxx_dialect >= cxx17
7519 175433091 : && TREE_CODE (type) == ENUMERAL_TYPE
7520 7193354 : && ENUM_FIXED_UNDERLYING_TYPE_P (type)
7521 4887109 : && TREE_CODE (init) == CONSTRUCTOR
7522 400372 : && CONSTRUCTOR_IS_DIRECT_INIT (init)
7523 194869 : && CONSTRUCTOR_NELTS (init) == 1
7524 216 : && TREE_CODE (CONSTRUCTOR_ELT (init, 0)->value) != RAW_DATA_CST
7525 : /* DR 2374: The single element needs to be implicitly
7526 : convertible to the underlying type of the enum. */
7527 216 : && !type_dependent_expression_p (CONSTRUCTOR_ELT (init, 0)->value)
7528 177486754 : && can_convert_arg (ENUM_UNDERLYING_TYPE (type),
7529 214 : TREE_TYPE (CONSTRUCTOR_ELT (init, 0)->value),
7530 214 : CONSTRUCTOR_ELT (init, 0)->value,
7531 : LOOKUP_IMPLICIT, tf_none))
7532 : return true;
7533 : return false;
7534 : }
7535 :
7536 : /* Helper function for reshape_init*. Split first element of
7537 : RAW_DATA_CST or return NULL for other elements. Set *INC_CUR
7538 : to true if the whole d->cur has been consumed. */
7539 :
7540 : static tree
7541 59005408 : cp_maybe_split_raw_data (reshape_iter *d, bool *inc_cur)
7542 : {
7543 59005408 : *inc_cur = true;
7544 59005408 : if (TREE_CODE (d->cur->value) != RAW_DATA_CST)
7545 : return NULL_TREE;
7546 30720 : tree ret = *raw_data_iterator (d->cur->value, d->raw_idx++);
7547 30720 : if (d->raw_idx != (unsigned) RAW_DATA_LENGTH (d->cur->value))
7548 30588 : *inc_cur = false;
7549 : else
7550 132 : d->raw_idx = 0;
7551 : return ret;
7552 : }
7553 :
7554 : /* Wrapper around that which for RAW_DATA_CST in INIT
7555 : (as well as in D->cur->value) peels off the first element
7556 : of the raw data and returns it, otherwise increments
7557 : D->cur and returns INIT. */
7558 :
7559 : static tree
7560 59005392 : consume_init (tree init, reshape_iter *d)
7561 : {
7562 59005392 : bool inc_cur;
7563 59005392 : if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
7564 30720 : init = raw_init;
7565 59005392 : if (inc_cur)
7566 58974804 : d->cur++;
7567 59005392 : return init;
7568 : }
7569 :
7570 : /* Subroutine of reshape_init_array and reshape_init_vector, which does
7571 : the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
7572 : INTEGER_CST representing the size of the array minus one (the maximum index),
7573 : or NULL_TREE if the array was declared without specifying the size. D is
7574 : the iterator within the constructor. */
7575 :
7576 : static tree
7577 449297 : reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
7578 : tree first_initializer_p, bool vector_p,
7579 : tsubst_flags_t complain)
7580 : {
7581 449297 : tree new_init;
7582 449297 : bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
7583 449297 : unsigned HOST_WIDE_INT max_index_cst = 0;
7584 449297 : unsigned HOST_WIDE_INT index;
7585 :
7586 : /* The initializer for an array is always a CONSTRUCTOR. If this is the
7587 : outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
7588 : to build a new one. But don't reuse if not complaining; if this is
7589 : tentative, we might also reshape to another type (95319). */
7590 449297 : bool reuse = (first_initializer_p
7591 394312 : && (complain & tf_error)
7592 393066 : && !CP_AGGREGATE_TYPE_P (elt_type)
7593 780379 : && !TREE_SIDE_EFFECTS (first_initializer_p));
7594 122771 : if (reuse)
7595 : new_init = first_initializer_p;
7596 : else
7597 122771 : new_init = build_constructor (init_list_type_node, NULL);
7598 :
7599 449297 : if (sized_array_p)
7600 : {
7601 268213 : poly_uint64 midx;
7602 : /* Minus 1 is used for zero sized arrays. */
7603 268213 : if (integer_all_onesp (max_index))
7604 24 : return new_init;
7605 :
7606 268189 : if (tree_fits_poly_uint64_p (max_index))
7607 268189 : midx = tree_to_poly_uint64 (max_index);
7608 : /* sizetype is sign extended, not zero extended. */
7609 : else
7610 0 : midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
7611 :
7612 : /* For VLA vectors, we restict the number of elements in the constructor
7613 : to lower bound of the VLA elements. */
7614 268189 : max_index_cst = constant_lower_bound (midx);
7615 : }
7616 :
7617 449273 : constructor_elt *first_cur = d->cur;
7618 : /* Loop until there are no more initializers. */
7619 54213404 : for (index = 0;
7620 54213404 : d->cur != d->end && (!sized_array_p || index <= max_index_cst);
7621 : ++index)
7622 : {
7623 53764311 : tree elt_init;
7624 53764311 : constructor_elt *old_cur = d->cur;
7625 53764311 : unsigned int old_raw_idx = d->raw_idx;
7626 53764311 : bool old_raw_data_cst = TREE_CODE (d->cur->value) == RAW_DATA_CST;
7627 :
7628 53764311 : if (d->cur->index)
7629 5554011 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7630 53764311 : check_array_designated_initializer (d->cur, index);
7631 53764311 : if (TREE_CODE (d->cur->value) == RAW_DATA_CST
7632 32732 : && (TREE_CODE (elt_type) == INTEGER_TYPE
7633 10233 : || is_byte_access_type (elt_type))
7634 22499 : && TYPE_PRECISION (elt_type) == CHAR_BIT
7635 1838 : && (!sized_array_p || index < max_index_cst)
7636 53766137 : && !vector_p)
7637 : {
7638 506 : elt_init = d->cur->value;
7639 506 : unsigned int off = d->raw_idx;
7640 506 : unsigned int len = RAW_DATA_LENGTH (elt_init) - off;
7641 506 : if (!sized_array_p || len <= max_index_cst - index + 1)
7642 : {
7643 497 : d->cur++;
7644 497 : d->raw_idx = 0;
7645 : }
7646 : else
7647 : {
7648 9 : len = max_index_cst - index + 1;
7649 9 : d->raw_idx += len;
7650 : }
7651 506 : if (!reuse || off || d->cur == old_cur)
7652 : {
7653 27 : elt_init = copy_node (elt_init);
7654 27 : RAW_DATA_LENGTH (elt_init) = len;
7655 27 : RAW_DATA_POINTER (elt_init) += off;
7656 : }
7657 506 : TREE_TYPE (elt_init) = elt_type;
7658 : }
7659 : else
7660 53763805 : elt_init = reshape_init_r (elt_type, d,
7661 : /*first_initializer_p=*/NULL_TREE,
7662 : complain);
7663 53764311 : if (elt_init == error_mark_node)
7664 : return error_mark_node;
7665 53764134 : tree idx = size_int (index);
7666 53764134 : if (reuse && old_raw_data_cst && d->cur == old_cur)
7667 : {
7668 : /* We need to stop reusing as some RAW_DATA_CST in the original
7669 : ctor had to be split. */
7670 72 : new_init = build_constructor (init_list_type_node, NULL);
7671 72 : if (index)
7672 : {
7673 72 : vec_safe_grow (CONSTRUCTOR_ELTS (new_init), index);
7674 72 : memcpy (CONSTRUCTOR_ELT (new_init, 0), first_cur,
7675 72 : (d->cur - first_cur)
7676 : * sizeof (*CONSTRUCTOR_ELT (new_init, 0)));
7677 72 : if (CONSTRUCTOR_IS_DESIGNATED_INIT (first_initializer_p))
7678 : {
7679 : unsigned int j;
7680 : tree nidx, nval;
7681 4 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (new_init),
7682 : j, nidx, nval)
7683 4 : if (nidx)
7684 : {
7685 4 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = 1;
7686 4 : (void) nval;
7687 4 : break;
7688 : }
7689 : }
7690 : }
7691 : reuse = false;
7692 : }
7693 53764062 : if (reuse)
7694 : {
7695 52582576 : old_cur->index = idx;
7696 52582576 : old_cur->value = elt_init;
7697 : }
7698 : else
7699 1181558 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
7700 : idx, elt_init);
7701 53764134 : if (!TREE_CONSTANT (elt_init))
7702 185624 : TREE_CONSTANT (new_init) = false;
7703 :
7704 : /* This can happen with an invalid initializer (c++/54501). */
7705 53764134 : if (d->cur == old_cur
7706 32082 : && !sized_array_p
7707 14085 : && d->raw_idx == old_raw_idx)
7708 : break;
7709 :
7710 53764131 : if (TREE_CODE (elt_init) == RAW_DATA_CST)
7711 506 : index += RAW_DATA_LENGTH (elt_init) - 1;
7712 : }
7713 :
7714 : return new_init;
7715 : }
7716 :
7717 : /* Subroutine of reshape_init_r, processes the initializers for arrays.
7718 : Parameters are the same of reshape_init_r. */
7719 :
7720 : static tree
7721 401298 : reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
7722 : tsubst_flags_t complain)
7723 : {
7724 401298 : tree max_index = NULL_TREE;
7725 :
7726 401298 : gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
7727 :
7728 401298 : if (TYPE_DOMAIN (type))
7729 220262 : max_index = array_type_nelts_minus_one (type);
7730 :
7731 401298 : return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
7732 401298 : first_initializer_p, false, complain);
7733 : }
7734 :
7735 : /* Subroutine of reshape_init_r, processes the initializers for vectors.
7736 : Parameters are the same of reshape_init_r. */
7737 :
7738 : static tree
7739 47999 : reshape_init_vector (tree type, reshape_iter *d, tsubst_flags_t complain)
7740 : {
7741 47999 : tree max_index = NULL_TREE;
7742 :
7743 47999 : gcc_assert (VECTOR_TYPE_P (type));
7744 :
7745 47999 : if (COMPOUND_LITERAL_P (d->cur->value))
7746 : {
7747 0 : tree value = d->cur->value;
7748 0 : if (!same_type_p (TREE_TYPE (value), type))
7749 : {
7750 0 : if (complain & tf_error)
7751 0 : error ("invalid type %qT as initializer for a vector of type %qT",
7752 0 : TREE_TYPE (d->cur->value), type);
7753 0 : value = error_mark_node;
7754 : }
7755 0 : ++d->cur;
7756 0 : return value;
7757 : }
7758 :
7759 : /* For a vector, we initialize it as an array of the appropriate size. */
7760 47999 : if (VECTOR_TYPE_P (type))
7761 47999 : max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
7762 :
7763 47999 : return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
7764 47999 : NULL_TREE, true, complain);
7765 : }
7766 :
7767 : /* Subroutine of reshape_init*: We're initializing an element with TYPE from
7768 : INIT, in isolation from any designator or other initializers. */
7769 :
7770 : static tree
7771 486871 : reshape_single_init (tree type, tree init, tsubst_flags_t complain)
7772 : {
7773 : /* We could also implement this by wrapping init in a new CONSTRUCTOR and
7774 : calling reshape_init, but this way can just live on the stack. */
7775 486871 : constructor_elt elt = { /*index=*/NULL_TREE, init };
7776 486871 : reshape_iter iter = { &elt, &elt + 1, 0 };
7777 486871 : return reshape_init_r (type, &iter,
7778 : /*first_initializer_p=*/NULL_TREE,
7779 486871 : complain);
7780 : }
7781 :
7782 : /* Subroutine of reshape_init_r, processes the initializers for classes
7783 : or union. Parameters are the same of reshape_init_r. */
7784 :
7785 : static tree
7786 3207252 : reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
7787 : tsubst_flags_t complain)
7788 : {
7789 3207252 : tree field;
7790 3207252 : tree new_init;
7791 :
7792 3207252 : gcc_assert (CLASS_TYPE_P (type));
7793 :
7794 : /* The initializer for a class is always a CONSTRUCTOR. */
7795 3207252 : new_init = build_constructor (init_list_type_node, NULL);
7796 :
7797 3207252 : int binfo_idx = -1;
7798 3207252 : tree binfo = TYPE_BINFO (type);
7799 3207252 : tree base_binfo = NULL_TREE;
7800 3207252 : if (cxx_dialect >= cxx17 && uses_template_parms (type))
7801 : {
7802 : /* We get here from maybe_aggr_guide for C++20 class template argument
7803 : deduction. In this case we need to look through the binfo because a
7804 : template doesn't have base fields. */
7805 1415 : binfo_idx = 0;
7806 1415 : BINFO_BASE_ITERATE (binfo, binfo_idx, base_binfo);
7807 : }
7808 67 : if (base_binfo)
7809 : field = base_binfo;
7810 : else
7811 3207185 : field = next_aggregate_field (TYPE_FIELDS (type));
7812 :
7813 3207252 : if (!field)
7814 : {
7815 : /* [dcl.init.aggr]
7816 :
7817 : An initializer for an aggregate member that is an
7818 : empty class shall have the form of an empty
7819 : initializer-list {}. */
7820 322 : if (!first_initializer_p)
7821 : {
7822 268 : if (complain & tf_error)
7823 13 : error ("initializer for %qT must be brace-enclosed", type);
7824 268 : return error_mark_node;
7825 : }
7826 : return new_init;
7827 : }
7828 :
7829 : /* For C++20 CTAD, handle pack expansions in the base list. */
7830 : tree last_was_pack_expansion = NULL_TREE;
7831 :
7832 : /* Loop through the initializable fields, gathering initializers. */
7833 9575866 : while (d->cur != d->end)
7834 : {
7835 6473352 : tree field_init;
7836 6473352 : constructor_elt *old_cur = d->cur;
7837 6473352 : unsigned old_raw_idx = d->raw_idx;
7838 6473352 : bool direct_desig = false;
7839 :
7840 : /* Handle C++20 designated initializers. */
7841 6473352 : if (d->cur->index)
7842 : {
7843 487037 : if (d->cur->index == error_mark_node)
7844 : return error_mark_node;
7845 :
7846 487031 : if (TREE_CODE (d->cur->index) == FIELD_DECL)
7847 : {
7848 : /* We already reshaped this; we should have returned early from
7849 : reshape_init. */
7850 0 : gcc_checking_assert (false);
7851 : if (field != d->cur->index)
7852 : {
7853 : if (tree id = DECL_NAME (d->cur->index))
7854 : gcc_checking_assert (d->cur->index
7855 : == get_class_binding (type, id));
7856 : field = d->cur->index;
7857 : }
7858 : }
7859 487031 : else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
7860 : {
7861 487025 : CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
7862 487025 : field = get_class_binding (type, d->cur->index);
7863 487025 : direct_desig = true;
7864 : }
7865 : else
7866 : {
7867 6 : if (complain & tf_error)
7868 6 : error ("%<[%E] =%> used in a GNU-style designated initializer"
7869 : " for class %qT", d->cur->index, type);
7870 6 : return error_mark_node;
7871 : }
7872 :
7873 487025 : if (!field && ANON_AGGR_TYPE_P (type))
7874 : /* Apparently the designator isn't for a member of this anonymous
7875 : struct, so head back to the enclosing class. */
7876 : break;
7877 :
7878 487022 : if (!field || TREE_CODE (field) != FIELD_DECL)
7879 : {
7880 18 : if (complain & tf_error)
7881 : {
7882 6 : if (field && TREE_CODE (field) == TREE_LIST)
7883 : {
7884 3 : auto_diagnostic_group g;
7885 3 : error ("request for member %qD is ambiguous",
7886 3 : d->cur->index);
7887 3 : print_candidates (input_location, field);
7888 3 : }
7889 : else
7890 3 : error ("%qT has no non-static data member named %qD", type,
7891 3 : d->cur->index);
7892 : }
7893 18 : return error_mark_node;
7894 : }
7895 :
7896 : /* If the element is an anonymous union object and the initializer
7897 : list is a designated-initializer-list, the anonymous union object
7898 : is initialized by the designated-initializer-list { D }, where D
7899 : is the designated-initializer-clause naming a member of the
7900 : anonymous union object. */
7901 487004 : tree ictx = DECL_CONTEXT (field);
7902 487004 : if (!same_type_ignoring_top_level_qualifiers_p (ictx, type))
7903 : {
7904 : /* Find the anon aggr that is a direct member of TYPE. */
7905 146 : while (ANON_AGGR_TYPE_P (ictx))
7906 : {
7907 143 : tree cctx = TYPE_CONTEXT (ictx);
7908 143 : if (same_type_ignoring_top_level_qualifiers_p (cctx, type))
7909 130 : goto found;
7910 : ictx = cctx;
7911 : }
7912 :
7913 : /* Not found, e.g. FIELD is a member of a base class. */
7914 3 : if (complain & tf_error)
7915 3 : error ("%qD is not a direct member of %qT", field, type);
7916 3 : return error_mark_node;
7917 :
7918 130 : found:
7919 : /* Now find the TYPE member with that anon aggr type. */
7920 130 : tree aafield = TYPE_FIELDS (type);
7921 1110 : for (; aafield; aafield = TREE_CHAIN (aafield))
7922 1110 : if (TREE_TYPE (aafield) == ictx)
7923 : break;
7924 0 : gcc_assert (aafield);
7925 : field = aafield;
7926 : direct_desig = false;
7927 : }
7928 : }
7929 :
7930 : /* If we processed all the member of the class, we are done. */
7931 6473186 : if (!field)
7932 : break;
7933 :
7934 12945713 : last_was_pack_expansion = (PACK_EXPANSION_P (TREE_TYPE (field))
7935 6472866 : ? field : NULL_TREE);
7936 6472866 : if (last_was_pack_expansion)
7937 : /* Each non-trailing aggregate element that is a pack expansion is
7938 : assumed to correspond to no elements of the initializer list. */
7939 19 : goto continue_;
7940 :
7941 6472847 : if (direct_desig)
7942 : {
7943 : /* The designated field F is initialized from this one element.
7944 :
7945 : Note that we don't want to do this if we found the designator
7946 : inside an anon aggr above; we use the normal code to implement:
7947 :
7948 : "If the element is an anonymous union member and the initializer
7949 : list is a brace-enclosed designated- initializer-list, the element
7950 : is initialized by the designated-initializer-list { D }, where D
7951 : is the designated- initializer-clause naming a member of the
7952 : anonymous union member." */
7953 486871 : gcc_checking_assert (TREE_CODE (d->cur->value) != RAW_DATA_CST);
7954 486871 : field_init = reshape_single_init (TREE_TYPE (field),
7955 : d->cur->value, complain);
7956 486871 : d->cur++;
7957 : }
7958 : else
7959 5985976 : field_init = reshape_init_r (TREE_TYPE (field), d,
7960 : /*first_initializer_p=*/NULL_TREE,
7961 : complain);
7962 :
7963 6472847 : if (field_init == error_mark_node)
7964 : return error_mark_node;
7965 :
7966 6472560 : if (d->cur == old_cur && d->cur->index && d->raw_idx == old_raw_idx)
7967 : {
7968 : /* This can happen with an invalid initializer for a flexible
7969 : array member (c++/54441). */
7970 0 : if (complain & tf_error)
7971 0 : error ("invalid initializer for %q#D", field);
7972 0 : return error_mark_node;
7973 : }
7974 :
7975 6472560 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), field, field_init);
7976 :
7977 : /* [dcl.init.aggr]
7978 :
7979 : When a union is initialized with a brace-enclosed
7980 : initializer, the braces shall only contain an
7981 : initializer for the first member of the union. */
7982 6472560 : if (TREE_CODE (type) == UNION_TYPE)
7983 : break;
7984 :
7985 6368917 : continue_:
7986 6368936 : if (base_binfo)
7987 : {
7988 82 : if (BINFO_BASE_ITERATE (binfo, ++binfo_idx, base_binfo))
7989 : field = base_binfo;
7990 : else
7991 35 : field = next_aggregate_field (TYPE_FIELDS (type));
7992 : }
7993 : else
7994 6368854 : field = next_aggregate_field (DECL_CHAIN (field));
7995 : }
7996 :
7997 : /* A trailing aggregate element that is a pack expansion is assumed to
7998 : correspond to all remaining elements of the initializer list (if any). */
7999 3206610 : if (last_was_pack_expansion)
8000 : {
8001 16 : tree init = d->cur->value;
8002 16 : bool inc_cur;
8003 16 : if (tree raw_init = cp_maybe_split_raw_data (d, &inc_cur))
8004 0 : init = raw_init;
8005 16 : CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
8006 : last_was_pack_expansion, init);
8007 46 : while (d->cur != d->end)
8008 30 : d->cur++;
8009 : }
8010 :
8011 : return new_init;
8012 : }
8013 :
8014 : /* Subroutine of reshape_init_r. We're in a context where C99 initializer
8015 : designators are not valid; either complain or return true to indicate
8016 : that reshape_init_r should return error_mark_node. */
8017 :
8018 : static bool
8019 240508 : has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
8020 : {
8021 240508 : if (d->cur->index)
8022 : {
8023 30 : if (complain & tf_error)
8024 45 : error_at (cp_expr_loc_or_input_loc (d->cur->index),
8025 : "C99 designator %qE outside aggregate initializer",
8026 : d->cur->index);
8027 : else
8028 : return true;
8029 : }
8030 : return false;
8031 : }
8032 :
8033 : /* Subroutine of reshape_init, which processes a single initializer (part of
8034 : a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
8035 : iterator within the CONSTRUCTOR which points to the initializer to process.
8036 : If this is the first initializer of the outermost CONSTRUCTOR node,
8037 : FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE. */
8038 :
8039 : static tree
8040 64125771 : reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
8041 : tsubst_flags_t complain)
8042 : {
8043 64125771 : tree init = d->cur->value;
8044 :
8045 64125771 : if (error_operand_p (init))
8046 129 : return error_mark_node;
8047 :
8048 3888993 : if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
8049 64365971 : && has_designator_problem (d, complain))
8050 0 : return error_mark_node;
8051 :
8052 64125642 : tree stripped_init = tree_strip_any_location_wrapper (init);
8053 :
8054 64125642 : if (TREE_CODE (type) == COMPLEX_TYPE)
8055 : {
8056 : /* A complex type can be initialized from one or two initializers,
8057 : but braces are not elided. */
8058 678 : init = consume_init (init, d);
8059 678 : if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
8060 : {
8061 9 : if (CONSTRUCTOR_NELTS (stripped_init) > 2)
8062 : {
8063 0 : if (complain & tf_error)
8064 0 : error ("too many initializers for %qT", type);
8065 : else
8066 0 : return error_mark_node;
8067 : }
8068 : }
8069 669 : else if (first_initializer_p && d->cur != d->end)
8070 : {
8071 36 : if (error_operand_p (d->cur->value)
8072 36 : || has_designator_problem (d, complain))
8073 0 : return error_mark_node;
8074 36 : vec<constructor_elt, va_gc> *v = 0;
8075 36 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
8076 36 : init = consume_init (d->cur->value, d);
8077 36 : CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init);
8078 36 : init = build_constructor (init_list_type_node, v);
8079 : }
8080 678 : return init;
8081 : }
8082 :
8083 : /* A non-aggregate type is always initialized with a single
8084 : initializer. */
8085 128193125 : if (!CP_AGGREGATE_TYPE_P (type)
8086 : /* As is an array with dependent bound, which we can see
8087 : during C++20 aggregate CTAD. */
8088 69193090 : || (cxx_dialect >= cxx20
8089 5019301 : && TREE_CODE (type) == ARRAY_TYPE
8090 492431 : && uses_template_parms (TYPE_DOMAIN (type))))
8091 : {
8092 : /* It is invalid to initialize a non-aggregate type with a
8093 : brace-enclosed initializer before C++0x.
8094 : We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
8095 : of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
8096 : a CONSTRUCTOR (with a record type). */
8097 59000046 : if (TREE_CODE (stripped_init) == CONSTRUCTOR
8098 : /* Don't complain about a capture-init. */
8099 292637 : && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
8100 59282803 : && BRACE_ENCLOSED_INITIALIZER_P (stripped_init)) /* p7626.C */
8101 : {
8102 282718 : if (SCALAR_TYPE_P (type))
8103 : {
8104 477 : if (cxx_dialect < cxx11)
8105 : {
8106 16 : if (complain & tf_error)
8107 16 : error ("braces around scalar initializer for type %qT",
8108 : type);
8109 16 : init = error_mark_node;
8110 : }
8111 461 : else if (first_initializer_p
8112 461 : || (CONSTRUCTOR_NELTS (stripped_init) > 0
8113 296 : && (BRACE_ENCLOSED_INITIALIZER_P
8114 : (CONSTRUCTOR_ELT (stripped_init,0)->value))))
8115 : {
8116 13 : if (complain & tf_error)
8117 13 : error ("too many braces around scalar initializer "
8118 : "for type %qT", type);
8119 13 : init = error_mark_node;
8120 : }
8121 : }
8122 : else
8123 282241 : maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
8124 : }
8125 59000046 : return consume_init (init, d);
8126 : }
8127 :
8128 : /* "If T is a class type and the initializer list has a single element of
8129 : type cv U, where U is T or a class derived from T, the object is
8130 : initialized from that element." Even if T is an aggregate. */
8131 5100945 : if (cxx_dialect >= cxx11 && (CLASS_TYPE_P (type) || VECTOR_TYPE_P (type))
8132 4582937 : && first_initializer_p
8133 : /* But not if it's a designated init. */
8134 3239754 : && !d->cur->index
8135 2995652 : && d->end - d->cur == 1
8136 581994 : && TREE_CODE (init) != RAW_DATA_CST
8137 5706912 : && reference_related_p (type, TREE_TYPE (init)))
8138 : {
8139 422 : d->cur++;
8140 422 : return init;
8141 : }
8142 :
8143 : /* [dcl.init.aggr]
8144 :
8145 : All implicit type conversions (clause _conv_) are considered when
8146 : initializing the aggregate member with an initializer from an
8147 : initializer-list. If the initializer can initialize a member,
8148 : the member is initialized. Otherwise, if the member is itself a
8149 : non-empty subaggregate, brace elision is assumed and the
8150 : initializer is considered for the initialization of the first
8151 : member of the subaggregate. */
8152 2074219 : if ((TREE_CODE (init) != CONSTRUCTOR || COMPOUND_LITERAL_P (init))
8153 : /* But don't try this for the first initializer, since that would be
8154 : looking through the outermost braces; A a2 = { a1 }; is not a
8155 : valid aggregate initialization. */
8156 3050340 : && !first_initializer_p
8157 5138330 : && (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (init))
8158 9238 : || can_convert_arg (type, TREE_TYPE (init),
8159 9238 : TREE_CODE (init) == RAW_DATA_CST
8160 5126102 : ? build_int_cst (integer_type_node,
8161 1606 : *(const unsigned char *)
8162 1606 : RAW_DATA_POINTER (init))
8163 : : init,
8164 : LOOKUP_NORMAL, complain)))
8165 4632 : return consume_init (init, d);
8166 :
8167 : /* [dcl.init.string]
8168 :
8169 : A char array (whether plain char, signed char, or unsigned char)
8170 : can be initialized by a string-literal (optionally enclosed in
8171 : braces); a wchar_t array can be initialized by a wide
8172 : string-literal (optionally enclosed in braces). */
8173 5119864 : if (TREE_CODE (type) == ARRAY_TYPE
8174 5119864 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
8175 : {
8176 122879 : tree str_init = init;
8177 122879 : tree stripped_str_init = stripped_init;
8178 122879 : reshape_iter stripd = {};
8179 :
8180 : /* Strip one level of braces if and only if they enclose a single
8181 : element (as allowed by [dcl.init.string]). */
8182 122879 : if (!first_initializer_p
8183 11833 : && TREE_CODE (stripped_str_init) == CONSTRUCTOR
8184 133576 : && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
8185 : {
8186 392 : stripd.cur = CONSTRUCTOR_ELT (stripped_str_init, 0);
8187 392 : str_init = stripd.cur->value;
8188 392 : stripped_str_init = tree_strip_any_location_wrapper (str_init);
8189 : }
8190 :
8191 : /* If it's a string literal, then it's the initializer for the array
8192 : as a whole. Otherwise, continue with normal initialization for
8193 : array types (one value per array element). */
8194 122879 : if (TREE_CODE (stripped_str_init) == STRING_CST)
8195 : {
8196 72 : if ((first_initializer_p && has_designator_problem (d, complain))
8197 1062 : || (stripd.cur && has_designator_problem (&stripd, complain)))
8198 990 : return error_mark_node;
8199 990 : d->cur++;
8200 990 : return str_init;
8201 : }
8202 : }
8203 :
8204 : /* The following cases are about aggregates. If we are not within a full
8205 : initializer already, and there is not a CONSTRUCTOR, it means that there
8206 : is a missing set of braces (that is, we are processing the case for
8207 : which reshape_init exists). */
8208 5118874 : bool braces_elided_p = false;
8209 5118874 : if (!first_initializer_p)
8210 : {
8211 1470704 : if (TREE_CODE (stripped_init) == CONSTRUCTOR)
8212 : {
8213 1462356 : tree init_type = TREE_TYPE (init);
8214 1462356 : if (init_type && TYPE_PTRMEMFUNC_P (init_type))
8215 : /* There is no need to call reshape_init for pointer-to-member
8216 : function initializers, as they are always constructed correctly
8217 : by the front end. Here we have e.g. {.__pfn=0B, .__delta=0},
8218 : which is missing outermost braces. We should warn below, and
8219 : one of the routines below will wrap it in additional { }. */;
8220 : /* For a nested compound literal, proceed to specialized routines,
8221 : to handle initialization of arrays and similar. */
8222 1462347 : else if (COMPOUND_LITERAL_P (stripped_init))
8223 7 : gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
8224 : /* If we have an unresolved designator, we need to find the member it
8225 : designates within TYPE, so proceed to the routines below. For
8226 : FIELD_DECL or INTEGER_CST designators, we're already initializing
8227 : the designated element. */
8228 1462340 : else if (d->cur->index
8229 30 : && TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
8230 : /* Brace elision with designators is only permitted for anonymous
8231 : aggregates. */
8232 15 : gcc_checking_assert (ANON_AGGR_TYPE_P (type));
8233 : /* A CONSTRUCTOR of the target's type is a previously
8234 : digested initializer. */
8235 1462325 : else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
8236 : {
8237 0 : ++d->cur;
8238 0 : return init;
8239 : }
8240 : else
8241 : {
8242 : /* Something that hasn't been reshaped yet. */
8243 1462325 : ++d->cur;
8244 1462325 : gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
8245 1462325 : return reshape_init (type, init, complain);
8246 : }
8247 : }
8248 :
8249 8379 : if (complain & tf_warning)
8250 7225 : warning (OPT_Wmissing_braces,
8251 : "missing braces around initializer for %qT",
8252 : type);
8253 : braces_elided_p = true;
8254 : }
8255 :
8256 : /* Dispatch to specialized routines. */
8257 3656549 : tree new_init;
8258 3656549 : if (CLASS_TYPE_P (type))
8259 3207252 : new_init = reshape_init_class (type, d, first_initializer_p, complain);
8260 449297 : else if (TREE_CODE (type) == ARRAY_TYPE)
8261 401298 : new_init = reshape_init_array (type, d, first_initializer_p, complain);
8262 47999 : else if (VECTOR_TYPE_P (type))
8263 47999 : new_init = reshape_init_vector (type, d, complain);
8264 : else
8265 0 : gcc_unreachable ();
8266 :
8267 3656549 : if (braces_elided_p
8268 8379 : && TREE_CODE (new_init) == CONSTRUCTOR)
8269 8105 : CONSTRUCTOR_BRACES_ELIDED_P (new_init) = true;
8270 :
8271 : return new_init;
8272 : }
8273 :
8274 : /* Undo the brace-elision allowed by [dcl.init.aggr] in a
8275 : brace-enclosed aggregate initializer.
8276 :
8277 : INIT is the CONSTRUCTOR containing the list of initializers describing
8278 : a brace-enclosed initializer for an entity of the indicated aggregate TYPE.
8279 : It may not presently match the shape of the TYPE; for example:
8280 :
8281 : struct S { int a; int b; };
8282 : struct S a[] = { 1, 2, 3, 4 };
8283 :
8284 : Here INIT will hold a vector of four elements, rather than a
8285 : vector of two elements, each itself a vector of two elements. This
8286 : routine transforms INIT from the former form into the latter. The
8287 : revised CONSTRUCTOR node is returned. */
8288 :
8289 : tree
8290 11421586 : reshape_init (tree type, tree init, tsubst_flags_t complain)
8291 : {
8292 11421586 : vec<constructor_elt, va_gc> *v;
8293 11421586 : reshape_iter d;
8294 11421586 : tree new_init;
8295 :
8296 11421586 : gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init));
8297 :
8298 11421586 : v = CONSTRUCTOR_ELTS (init);
8299 :
8300 : /* An empty constructor does not need reshaping, and it is always a valid
8301 : initializer. */
8302 11422337 : if (vec_safe_is_empty (v))
8303 : return init;
8304 :
8305 3890078 : if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
8306 : /* Already reshaped. */
8307 : return init;
8308 :
8309 : /* Brace elision is not performed for a CONSTRUCTOR representing
8310 : parenthesized aggregate initialization. */
8311 3889932 : if (CONSTRUCTOR_IS_PAREN_INIT (init))
8312 : {
8313 639 : tree elt = (*v)[0].value;
8314 : /* If we're initializing a char array from a string-literal that is
8315 : enclosed in braces, unwrap it here. */
8316 639 : if (TREE_CODE (type) == ARRAY_TYPE
8317 266 : && vec_safe_length (v) == 1
8318 144 : && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
8319 678 : && TREE_CODE (tree_strip_any_location_wrapper (elt)) == STRING_CST)
8320 : return elt;
8321 605 : return init;
8322 : }
8323 :
8324 : /* Handle [dcl.init.list] direct-list-initialization from
8325 : single element of enumeration with a fixed underlying type. */
8326 3889293 : if (is_direct_enum_init (type, init))
8327 : {
8328 174 : tree elt = CONSTRUCTOR_ELT (init, 0)->value;
8329 174 : type = cv_unqualified (type);
8330 174 : if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
8331 : {
8332 159 : warning_sentinel w (warn_useless_cast);
8333 159 : warning_sentinel w2 (warn_ignored_qualifiers);
8334 159 : return cp_build_c_cast (input_location, type, elt,
8335 : tf_warning_or_error);
8336 159 : }
8337 : else
8338 15 : return error_mark_node;
8339 : }
8340 :
8341 : /* Recurse on this CONSTRUCTOR. */
8342 3889119 : d.cur = &(*v)[0];
8343 3889119 : d.end = d.cur + v->length ();
8344 3889119 : d.raw_idx = 0;
8345 :
8346 3889119 : new_init = reshape_init_r (type, &d, init, complain);
8347 3889119 : if (new_init == error_mark_node)
8348 : return error_mark_node;
8349 :
8350 : /* Make sure all the element of the constructor were used. Otherwise,
8351 : issue an error about exceeding initializers. */
8352 3888496 : if (d.cur != d.end)
8353 : {
8354 206 : if (complain & tf_error)
8355 63 : error ("too many initializers for %qT", type);
8356 206 : return error_mark_node;
8357 : }
8358 :
8359 3888290 : if (CONSTRUCTOR_IS_DIRECT_INIT (init)
8360 3888290 : && BRACE_ENCLOSED_INITIALIZER_P (new_init))
8361 518793 : CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
8362 3888290 : if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
8363 3888290 : && BRACE_ENCLOSED_INITIALIZER_P (new_init))
8364 51690 : gcc_checking_assert (CONSTRUCTOR_IS_DESIGNATED_INIT (new_init)
8365 : || seen_error ());
8366 :
8367 : return new_init;
8368 : }
8369 :
8370 : /* Verify array initializer. Returns true if errors have been reported. */
8371 :
8372 : bool
8373 954020 : check_array_initializer (tree decl, tree type, tree init)
8374 : {
8375 954020 : tree element_type = TREE_TYPE (type);
8376 :
8377 : /* Structured binding when initialized with an array type needs
8378 : to have complete type. */
8379 954020 : if (decl
8380 943047 : && DECL_DECOMPOSITION_P (decl)
8381 3269 : && DECL_DECOMP_IS_BASE (decl)
8382 957289 : && !COMPLETE_TYPE_P (type))
8383 : {
8384 0 : error_at (DECL_SOURCE_LOCATION (decl),
8385 : "structured binding has incomplete type %qT", type);
8386 0 : TREE_TYPE (decl) = error_mark_node;
8387 0 : return true;
8388 : }
8389 :
8390 : /* The array type itself need not be complete, because the
8391 : initializer may tell us how many elements are in the array.
8392 : But, the elements of the array must be complete. */
8393 954020 : if (!COMPLETE_TYPE_P (complete_type (element_type)))
8394 : {
8395 15 : if (decl)
8396 9 : error_at (DECL_SOURCE_LOCATION (decl),
8397 : "elements of array %q#D have incomplete type", decl);
8398 : else
8399 6 : error ("elements of array %q#T have incomplete type", type);
8400 15 : return true;
8401 : }
8402 :
8403 954005 : location_t loc = (decl ? location_of (decl) : input_location);
8404 954005 : if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
8405 : return true;
8406 :
8407 : /* A compound literal can't have variable size. */
8408 954005 : if (init && !decl
8409 954005 : && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
8410 10964 : || !TREE_CONSTANT (TYPE_SIZE (element_type))))
8411 : {
8412 3 : error ("variable-sized compound literal");
8413 3 : return true;
8414 : }
8415 : return false;
8416 : }
8417 :
8418 : /* Subroutine of check_initializer; args are passed down from that function.
8419 : Set stmts_are_full_exprs_p to 1 across a call to build_aggr_init. */
8420 :
8421 : static tree
8422 2857959 : build_aggr_init_full_exprs (tree decl, tree init, int flags)
8423 : {
8424 2857959 : gcc_assert (stmts_are_full_exprs_p ());
8425 2857959 : if (init)
8426 2325124 : maybe_warn_pessimizing_move (init, TREE_TYPE (decl), /*return_p*/false);
8427 2857959 : return build_aggr_init (decl, init, flags, tf_warning_or_error);
8428 : }
8429 :
8430 : /* Verify INIT (the initializer for DECL), and record the
8431 : initialization in DECL_INITIAL, if appropriate. CLEANUP is as for
8432 : grok_reference_init.
8433 :
8434 : If the return value is non-NULL, it is an expression that must be
8435 : evaluated dynamically to initialize DECL. */
8436 :
8437 : static tree
8438 55070673 : check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
8439 : {
8440 55070673 : tree type;
8441 55070673 : tree init_code = NULL;
8442 55070673 : tree core_type;
8443 :
8444 : /* Things that are going to be initialized need to have complete
8445 : type. */
8446 55070673 : TREE_TYPE (decl) = type = complete_type (TREE_TYPE (decl));
8447 :
8448 55070673 : if (DECL_HAS_VALUE_EXPR_P (decl))
8449 : {
8450 : /* A variable with DECL_HAS_VALUE_EXPR_P set is just a placeholder,
8451 : it doesn't have storage to be initialized. */
8452 108 : gcc_assert (init == NULL_TREE);
8453 : return NULL_TREE;
8454 : }
8455 :
8456 55070565 : if (type == error_mark_node)
8457 : /* We will have already complained. */
8458 : return NULL_TREE;
8459 :
8460 55070565 : if (TREE_CODE (type) == ARRAY_TYPE)
8461 : {
8462 943047 : if (check_array_initializer (decl, type, init))
8463 : return NULL_TREE;
8464 : }
8465 54127518 : else if (!COMPLETE_TYPE_P (type))
8466 : {
8467 37 : error_at (DECL_SOURCE_LOCATION (decl),
8468 : "%q#D has incomplete type", decl);
8469 37 : TREE_TYPE (decl) = error_mark_node;
8470 37 : return NULL_TREE;
8471 : }
8472 : else
8473 : /* There is no way to make a variable-sized class type in GNU C++. */
8474 54127481 : gcc_assert (TREE_CONSTANT (TYPE_SIZE (type)));
8475 :
8476 55070519 : if (init && BRACE_ENCLOSED_INITIALIZER_P (init))
8477 : {
8478 2749398 : int init_len = CONSTRUCTOR_NELTS (init);
8479 2749398 : if (SCALAR_TYPE_P (type))
8480 : {
8481 63974 : if (init_len == 0)
8482 : {
8483 32465 : maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
8484 32465 : init = build_zero_init (type, NULL_TREE, false);
8485 : }
8486 31509 : else if (init_len != 1 && TREE_CODE (type) != COMPLEX_TYPE)
8487 : {
8488 12 : error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
8489 : "scalar object %qD requires one element in "
8490 : "initializer", decl);
8491 6 : TREE_TYPE (decl) = error_mark_node;
8492 6 : return NULL_TREE;
8493 : }
8494 : }
8495 : }
8496 :
8497 55070513 : if (TREE_CODE (decl) == CONST_DECL)
8498 : {
8499 0 : gcc_assert (!TYPE_REF_P (type));
8500 :
8501 0 : DECL_INITIAL (decl) = init;
8502 :
8503 0 : gcc_assert (init != NULL_TREE);
8504 : init = NULL_TREE;
8505 : }
8506 55070513 : else if (!init && DECL_REALLY_EXTERN (decl))
8507 : ;
8508 55070513 : else if (flag_openmp
8509 188128 : && VAR_P (decl)
8510 188128 : && DECL_LANG_SPECIFIC (decl)
8511 110472 : && DECL_OMP_DECLARE_MAPPER_P (decl)
8512 55070513 : && TREE_CODE (init) == OMP_DECLARE_MAPPER)
8513 : return NULL_TREE;
8514 4026893 : else if (init || type_build_ctor_call (type)
8515 58564568 : || TYPE_REF_P (type))
8516 : {
8517 51576473 : if (TYPE_REF_P (type))
8518 : {
8519 358549 : init = grok_reference_init (decl, type, init, flags);
8520 358549 : flags |= LOOKUP_ALREADY_DIGESTED;
8521 : }
8522 51217924 : else if (!init)
8523 532838 : check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
8524 : tf_warning_or_error);
8525 : /* Do not reshape constructors of vectors (they don't need to be
8526 : reshaped. */
8527 50685086 : else if (BRACE_ENCLOSED_INITIALIZER_P (init))
8528 : {
8529 2716572 : if (is_std_init_list (type))
8530 : {
8531 333 : init = perform_implicit_conversion (type, init,
8532 : tf_warning_or_error);
8533 333 : flags |= LOOKUP_ALREADY_DIGESTED;
8534 : }
8535 2716239 : else if (TYPE_NON_AGGREGATE_CLASS (type))
8536 : {
8537 : /* Don't reshape if the class has constructors. */
8538 431083 : if (cxx_dialect == cxx98)
8539 6 : error_at (cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (decl)),
8540 : "in C++98 %qD must be initialized by "
8541 : "constructor, not by %<{...}%>",
8542 : decl);
8543 : }
8544 2285156 : else if (VECTOR_TYPE_P (type) && TYPE_VECTOR_OPAQUE (type))
8545 : {
8546 0 : error ("opaque vector types cannot be initialized");
8547 0 : init = error_mark_node;
8548 : }
8549 : else
8550 : {
8551 2285156 : init = reshape_init (type, init, tf_warning_or_error);
8552 2285156 : flags |= LOOKUP_NO_NARROWING;
8553 : }
8554 : }
8555 : /* [dcl.init] "Otherwise, if the destination type is an array, the object
8556 : is initialized as follows..." So handle things like
8557 :
8558 : int a[](1, 2, 3);
8559 :
8560 : which is permitted in C++20 by P0960. */
8561 47968514 : else if (TREE_CODE (init) == TREE_LIST
8562 721443 : && TREE_TYPE (init) == NULL_TREE
8563 721443 : && TREE_CODE (type) == ARRAY_TYPE
8564 174 : && !DECL_DECOMPOSITION_P (decl)
8565 47968658 : && (cxx_dialect >= cxx20))
8566 134 : init = do_aggregate_paren_init (init, type);
8567 47968380 : else if (TREE_CODE (init) == TREE_LIST
8568 721309 : && TREE_TYPE (init) != unknown_type_node
8569 48689689 : && !MAYBE_CLASS_TYPE_P (type))
8570 : {
8571 127227 : gcc_assert (TREE_CODE (decl) != RESULT_DECL);
8572 :
8573 : /* We get here with code like `int a (2);' */
8574 127227 : init = build_x_compound_expr_from_list (init, ELK_INIT,
8575 : tf_warning_or_error);
8576 : }
8577 :
8578 : /* If DECL has an array type without a specific bound, deduce the
8579 : array size from the initializer. */
8580 51576473 : maybe_deduce_size_from_array_init (decl, init);
8581 51576473 : type = TREE_TYPE (decl);
8582 51576473 : if (type == error_mark_node)
8583 : return NULL_TREE;
8584 :
8585 99905895 : if (((type_build_ctor_call (type) || CLASS_TYPE_P (type))
8586 4901643 : && !(flags & LOOKUP_ALREADY_DIGESTED)
8587 4901310 : && !(init && BRACE_ENCLOSED_INITIALIZER_P (init)
8588 2478877 : && CP_AGGREGATE_TYPE_P (type)
8589 2047794 : && (CLASS_TYPE_P (type)
8590 : /* The call to build_aggr_init below could end up
8591 : calling build_vec_init, which may break when we
8592 : are processing a template. */
8593 1392 : || processing_template_decl
8594 1323 : || !TYPE_NEEDS_CONSTRUCTING (type)
8595 1291 : || type_has_extended_temps (type))))
8596 100298191 : || (DECL_DECOMPOSITION_P (decl) && TREE_CODE (type) == ARRAY_TYPE))
8597 : {
8598 2857959 : init_code = build_aggr_init_full_exprs (decl, init, flags);
8599 :
8600 : /* A constructor call is a non-trivial initializer even if
8601 : it isn't explicitly written. */
8602 2857959 : if (TREE_SIDE_EFFECTS (init_code))
8603 2835781 : DECL_NONTRIVIALLY_INITIALIZED_P (decl) = true;
8604 :
8605 : /* If this is a constexpr initializer, expand_default_init will
8606 : have returned an INIT_EXPR rather than a CALL_EXPR. In that
8607 : case, pull the initializer back out and pass it down into
8608 : store_init_value. */
8609 7560014 : while (true)
8610 : {
8611 7560014 : if (TREE_CODE (init_code) == EXPR_STMT
8612 4729576 : || TREE_CODE (init_code) == STMT_EXPR
8613 4693288 : || TREE_CODE (init_code) == CONVERT_EXPR)
8614 4665855 : init_code = TREE_OPERAND (init_code, 0);
8615 2894159 : else if (TREE_CODE (init_code) == BIND_EXPR)
8616 36200 : init_code = BIND_EXPR_BODY (init_code);
8617 : else
8618 : break;
8619 : }
8620 2857959 : if (TREE_CODE (init_code) == INIT_EXPR)
8621 : {
8622 : /* In C++20, the call to build_aggr_init could have created
8623 : an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
8624 : A(1, 2). */
8625 1821163 : tree rhs = TREE_OPERAND (init_code, 1);
8626 1821163 : if (processing_template_decl && TREE_CODE (rhs) == TARGET_EXPR)
8627 : /* Avoid leaking TARGET_EXPR into template trees. */
8628 18134 : rhs = build_implicit_conv_flags (type, init, flags);
8629 1821163 : init = rhs;
8630 :
8631 1821163 : init_code = NULL_TREE;
8632 : /* Don't call digest_init; it's unnecessary and will complain
8633 : about aggregate initialization of non-aggregate classes. */
8634 1821139 : flags |= LOOKUP_ALREADY_DIGESTED;
8635 : }
8636 1036796 : else if (DECL_DECLARED_CONSTEXPR_P (decl)
8637 2055188 : || DECL_DECLARED_CONSTINIT_P (decl))
8638 : {
8639 : /* Declared constexpr or constinit, but no suitable initializer;
8640 : massage init appropriately so we can pass it into
8641 : store_init_value for the error. */
8642 18422 : tree new_init = NULL_TREE;
8643 18422 : if (!processing_template_decl
8644 291 : && TREE_CODE (init_code) == CALL_EXPR)
8645 232 : new_init = build_cplus_new (type, init_code, tf_none);
8646 18166 : else if (CLASS_TYPE_P (type)
8647 36356 : && (!init || TREE_CODE (init) == TREE_LIST))
8648 18065 : new_init = build_functional_cast (input_location, type,
8649 : init, tf_none);
8650 18297 : if (new_init)
8651 : {
8652 18297 : init = new_init;
8653 18297 : if (TREE_CODE (init) == TARGET_EXPR
8654 257 : && !(flags & LOOKUP_ONLYCONVERTING))
8655 257 : TARGET_EXPR_DIRECT_INIT_P (init) = true;
8656 : }
8657 : init_code = NULL_TREE;
8658 : }
8659 : else
8660 : init = NULL_TREE;
8661 : }
8662 :
8663 50558095 : if (init && TREE_CODE (init) != TREE_VEC)
8664 : {
8665 50558080 : init_code = store_init_value (decl, init, cleanups, flags);
8666 :
8667 50555383 : if (DECL_INITIAL (decl)
8668 36642885 : && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR
8669 53458752 : && !vec_safe_is_empty (CONSTRUCTOR_ELTS (DECL_INITIAL (decl))))
8670 : {
8671 1268270 : tree elt = CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->last ().value;
8672 1268270 : if (TREE_CODE (TREE_TYPE (elt)) == ARRAY_TYPE
8673 1268270 : && TYPE_SIZE (TREE_TYPE (elt)) == NULL_TREE)
8674 36 : cp_complete_array_type (&TREE_TYPE (elt), elt, false);
8675 : }
8676 :
8677 1768769 : if (pedantic && TREE_CODE (type) == ARRAY_TYPE
8678 56195 : && DECL_INITIAL (decl)
8679 55673 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8680 50607534 : && PAREN_STRING_LITERAL_P (DECL_INITIAL (decl)))
8681 6 : warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
8682 3 : DECL_SOURCE_LOCATION (decl)),
8683 3 : 0, "array %qD initialized by parenthesized "
8684 : "string literal %qE",
8685 3 : decl, DECL_INITIAL (decl));
8686 : init = NULL_TREE;
8687 : }
8688 : }
8689 3494040 : else if (!init && REFLECTION_TYPE_P (type))
8690 : {
8691 : /* [dcl.init.general]: To default-initialize an object of type
8692 : std::meta::info means that the object is zero-initialized. */
8693 77 : DECL_INITIAL (decl)
8694 77 : = build_zero_init (type, NULL_TREE, /*static_storage_p=*/false);
8695 77 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
8696 77 : TREE_CONSTANT (decl) = true;
8697 77 : init = NULL_TREE;
8698 : }
8699 : else
8700 : {
8701 6987926 : if (CLASS_TYPE_P (core_type = strip_array_types (type))
8702 4209475 : && (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type)
8703 715499 : || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)))
8704 19 : diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false,
8705 : /*complain=*/true);
8706 :
8707 3493963 : check_for_uninitialized_const_var (decl, /*constexpr_context_p=*/false,
8708 : tf_warning_or_error);
8709 : }
8710 :
8711 77 : if (init && init != error_mark_node)
8712 0 : init_code = cp_build_init_expr (decl, init);
8713 :
8714 15066639 : if (init_code && !TREE_SIDE_EFFECTS (init_code)
8715 55122351 : && init_code != error_mark_node)
8716 : init_code = NULL_TREE;
8717 :
8718 55015531 : if (init_code)
8719 : {
8720 : /* We might have set these in cp_finish_decl. */
8721 15014358 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
8722 15014358 : TREE_CONSTANT (decl) = false;
8723 : }
8724 :
8725 15014358 : if (init_code
8726 15014358 : && DECL_IN_AGGR_P (decl)
8727 6 : && DECL_INITIALIZED_IN_CLASS_P (decl))
8728 : {
8729 0 : static int explained = 0;
8730 :
8731 0 : auto_diagnostic_group d;
8732 0 : if (cxx_dialect < cxx11)
8733 0 : error ("initializer invalid for static member with constructor");
8734 0 : else if (cxx_dialect < cxx17)
8735 0 : error ("non-constant in-class initialization invalid for static "
8736 : "member %qD", decl);
8737 : else
8738 0 : error ("non-constant in-class initialization invalid for non-inline "
8739 : "static member %qD", decl);
8740 0 : if (!explained)
8741 : {
8742 0 : inform (input_location,
8743 : "(an out of class initialization is required)");
8744 0 : explained = 1;
8745 : }
8746 0 : return NULL_TREE;
8747 0 : }
8748 :
8749 : return init_code;
8750 : }
8751 :
8752 : /* If DECL is not a local variable, give it RTL. */
8753 :
8754 : static void
8755 118035044 : make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec)
8756 : {
8757 118035044 : int toplev = toplevel_bindings_p ();
8758 118035044 : int defer_p;
8759 :
8760 : /* Set the DECL_ASSEMBLER_NAME for the object. */
8761 118035044 : if (asmspec)
8762 : {
8763 : /* The `register' keyword, when used together with an
8764 : asm-specification, indicates that the variable should be
8765 : placed in a particular register. */
8766 978476 : if (VAR_P (decl) && DECL_REGISTER (decl))
8767 : {
8768 87 : if (TREE_ADDRESSABLE (decl))
8769 3 : error_at (DECL_SOURCE_LOCATION (decl),
8770 : "address of explicit register variable %qD requested",
8771 : decl);
8772 : else
8773 : {
8774 84 : set_user_assembler_name (decl, asmspec);
8775 84 : DECL_HARD_REGISTER (decl) = 1;
8776 : }
8777 : }
8778 : else
8779 : {
8780 978389 : if (TREE_CODE (decl) == FUNCTION_DECL
8781 978389 : && fndecl_built_in_p (decl, BUILT_IN_NORMAL))
8782 77214 : set_builtin_user_assembler_name (decl, asmspec);
8783 978389 : set_user_assembler_name (decl, asmspec);
8784 978389 : if (DECL_LOCAL_DECL_P (decl))
8785 6 : if (auto ns_decl = DECL_LOCAL_DECL_ALIAS (decl))
8786 : /* We have to propagate the name to the ns-alias.
8787 : This is horrible, as we're affecting a
8788 : possibly-shared decl. Again, a one-true-decl
8789 : model breaks down. */
8790 6 : if (ns_decl != error_mark_node)
8791 6 : set_user_assembler_name (ns_decl, asmspec);
8792 : }
8793 : }
8794 :
8795 : /* Handle non-variables up front. */
8796 118035044 : if (!VAR_P (decl))
8797 : {
8798 56420962 : rest_of_decl_compilation (decl, toplev, at_eof);
8799 56420962 : return;
8800 : }
8801 :
8802 : /* If we see a class member here, it should be a static data
8803 : member. */
8804 61614082 : if (DECL_LANG_SPECIFIC (decl) && DECL_IN_AGGR_P (decl))
8805 : {
8806 5398651 : gcc_assert (TREE_STATIC (decl));
8807 : /* An in-class declaration of a static data member should be
8808 : external; it is only a declaration, and not a definition. */
8809 5398651 : if (init == NULL_TREE)
8810 5398626 : gcc_assert (DECL_EXTERNAL (decl)
8811 : || !TREE_PUBLIC (decl));
8812 : }
8813 :
8814 : /* We don't create any RTL for local variables. */
8815 61614082 : if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
8816 : return;
8817 :
8818 : /* Don't output reflection variables. */
8819 37954253 : if (consteval_only_p (decl))
8820 : {
8821 : /* Disable assemble_variable. */
8822 787 : DECL_EXTERNAL (decl) = true;
8823 : /* Undo make_decl_one_only. */
8824 787 : if (DECL_COMDAT_GROUP (decl))
8825 : {
8826 135 : symtab_node *node = symtab_node::get (decl);
8827 135 : node->set_comdat_group (NULL);
8828 135 : node->dissolve_same_comdat_group_list ();
8829 : }
8830 787 : return;
8831 : }
8832 :
8833 : /* We defer emission of local statics until the corresponding
8834 : DECL_EXPR is expanded. But with constexpr its function might never
8835 : be expanded, so go ahead and tell cgraph about the variable now. */
8836 75906932 : defer_p = ((DECL_FUNCTION_SCOPE_P (decl)
8837 135698 : && !var_in_maybe_constexpr_fn (decl))
8838 75771906 : || DECL_VIRTUAL_P (decl));
8839 :
8840 : /* Defer template instantiations. */
8841 37953466 : if (DECL_LANG_SPECIFIC (decl)
8842 37953466 : && DECL_IMPLICIT_INSTANTIATION (decl))
8843 : defer_p = 1;
8844 :
8845 : /* If we're not deferring, go ahead and assemble the variable. */
8846 19399731 : if (!defer_p)
8847 17073530 : rest_of_decl_compilation (decl, toplev, at_eof);
8848 : }
8849 :
8850 : /* walk_tree helper for wrap_temporary_cleanups, below. */
8851 :
8852 : static tree
8853 10489987 : wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data)
8854 : {
8855 : /* Stop at types or full-expression boundaries. */
8856 10489987 : if (TYPE_P (*stmt_p)
8857 10489775 : || TREE_CODE (*stmt_p) == CLEANUP_POINT_EXPR)
8858 : {
8859 442 : *walk_subtrees = 0;
8860 442 : return NULL_TREE;
8861 : }
8862 :
8863 10489545 : if (TREE_CODE (*stmt_p) == TARGET_EXPR)
8864 : {
8865 220436 : tree guard = (tree)data;
8866 220436 : tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p);
8867 :
8868 110143 : if (tcleanup && !CLEANUP_EH_ONLY (*stmt_p)
8869 327304 : && !expr_noexcept_p (tcleanup, tf_none))
8870 : {
8871 145 : tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard);
8872 : /* Tell honor_protect_cleanup_actions to handle this as a separate
8873 : cleanup. */
8874 145 : TRY_CATCH_IS_CLEANUP (tcleanup) = 1;
8875 145 : TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup;
8876 : }
8877 : }
8878 :
8879 : return NULL_TREE;
8880 : }
8881 :
8882 : /* We're initializing a local variable which has a cleanup GUARD. If there
8883 : are any temporaries used in the initializer INIT of this variable, we
8884 : need to wrap their cleanups with TRY_CATCH_EXPR (, GUARD) so that the
8885 : variable will be cleaned up properly if one of them throws.
8886 :
8887 : Unfortunately, there's no way to express this properly in terms of
8888 : nesting, as the regions for the temporaries overlap the region for the
8889 : variable itself; if there are two temporaries, the variable needs to be
8890 : the first thing destroyed if either of the temporary destructors throws.
8891 : However, we only want to run the variable's cleanup if it actually got
8892 : constructed. So we need to guard the temporary cleanups with the
8893 : variable's cleanup if they are run on the normal path, but not if they
8894 : are run on the exceptional path. We implement this by telling
8895 : honor_protect_cleanup_actions to strip the variable cleanup from the
8896 : exceptional path.
8897 :
8898 : Another approach could be to make the variable cleanup region enclose
8899 : initialization, but depend on a flag to indicate that the variable is
8900 : initialized; that's effectively what we do for arrays. But the current
8901 : approach works fine for non-arrays, and has no code overhead in the usual
8902 : case where the temporary destructors are noexcept. */
8903 :
8904 : static void
8905 948698 : wrap_temporary_cleanups (tree init, tree guard)
8906 : {
8907 948698 : if (TREE_CODE (guard) == BIND_EXPR)
8908 : {
8909 : /* An array cleanup region already encloses any temporary cleanups,
8910 : don't wrap it around them again. */
8911 407 : gcc_checking_assert (BIND_EXPR_VEC_DTOR (guard));
8912 : return;
8913 : }
8914 948291 : cp_walk_tree_without_duplicates (&init, wrap_cleanups_r, (void *)guard);
8915 : }
8916 :
8917 : /* Generate code to initialize DECL (a local variable). */
8918 :
8919 : static void
8920 23659811 : initialize_local_var (tree decl, tree init, bool decomp)
8921 : {
8922 23659811 : tree type = TREE_TYPE (decl);
8923 23659811 : tree cleanup;
8924 23659811 : int already_used;
8925 :
8926 23659811 : gcc_assert (VAR_P (decl) || TREE_CODE (decl) == RESULT_DECL);
8927 23659811 : gcc_assert (!TREE_STATIC (decl));
8928 :
8929 23659811 : if (DECL_SIZE (decl) == NULL_TREE)
8930 : {
8931 : /* If we used it already as memory, it must stay in memory. */
8932 0 : DECL_INITIAL (decl) = NULL_TREE;
8933 0 : TREE_ADDRESSABLE (decl) = TREE_USED (decl);
8934 0 : return;
8935 : }
8936 :
8937 23659811 : if (type == error_mark_node)
8938 : return;
8939 :
8940 : /* Compute and store the initial value. */
8941 23659811 : already_used = TREE_USED (decl) || TREE_USED (type);
8942 23659811 : if (TREE_USED (type))
8943 32 : DECL_READ_P (decl) = 1;
8944 :
8945 : /* Generate a cleanup, if necessary. */
8946 23659811 : cleanup = (decomp ? NULL_TREE
8947 23627214 : : cxx_maybe_build_cleanup (decl, tf_warning_or_error));
8948 :
8949 : /* Perform the initialization. */
8950 23659811 : if (init)
8951 : {
8952 15000194 : tree rinit = (TREE_CODE (init) == INIT_EXPR
8953 15000194 : ? TREE_OPERAND (init, 1) : NULL_TREE);
8954 13746718 : if (rinit && !TREE_SIDE_EFFECTS (rinit)
8955 21297554 : && TREE_OPERAND (init, 0) == decl)
8956 : {
8957 : /* Stick simple initializers in DECL_INITIAL so that
8958 : -Wno-init-self works (c++/34772). */
8959 7550836 : DECL_INITIAL (decl) = rinit;
8960 :
8961 7550836 : if (warn_init_self && TYPE_REF_P (type))
8962 : {
8963 2469 : STRIP_NOPS (rinit);
8964 2469 : if (rinit == decl)
8965 3 : warning_at (DECL_SOURCE_LOCATION (decl),
8966 3 : OPT_Winit_self,
8967 : "reference %qD is initialized with itself", decl);
8968 : }
8969 : }
8970 : else
8971 : {
8972 7449358 : int saved_stmts_are_full_exprs_p;
8973 :
8974 : /* If we're only initializing a single object, guard the
8975 : destructors of any temporaries used in its initializer with
8976 : its destructor. */
8977 7449358 : if (cleanup)
8978 945993 : wrap_temporary_cleanups (init, cleanup);
8979 :
8980 7449358 : gcc_assert (building_stmt_list_p ());
8981 7449358 : saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
8982 : /* Avoid CLEANUP_POINT_EXPR for the structured binding
8983 : bases, those will have CLEANUP_POINT_EXPR at the end of
8984 : code emitted by cp_finish_decomp. */
8985 7449358 : if (decomp)
8986 32144 : current_stmt_tree ()->stmts_are_full_exprs_p = 0;
8987 : else
8988 7417214 : current_stmt_tree ()->stmts_are_full_exprs_p = 1;
8989 7449358 : finish_expr_stmt (init);
8990 7449358 : current_stmt_tree ()->stmts_are_full_exprs_p
8991 7449358 : = saved_stmts_are_full_exprs_p;
8992 : }
8993 : }
8994 :
8995 : /* Set this to 0 so we can tell whether an aggregate which was
8996 : initialized was ever used. Don't do this if it has a
8997 : destructor, so we don't complain about the 'resource
8998 : allocation is initialization' idiom. Now set
8999 : attribute((unused)) on types so decls of that type will be
9000 : marked used. (see TREE_USED, above.) */
9001 23659811 : if (TYPE_NEEDS_CONSTRUCTING (type)
9002 2073091 : && ! already_used
9003 5608 : && TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
9004 23663176 : && DECL_NAME (decl))
9005 3319 : TREE_USED (decl) = 0;
9006 23656492 : else if (already_used)
9007 20738811 : TREE_USED (decl) = 1;
9008 :
9009 23659811 : if (cleanup)
9010 959130 : finish_decl_cleanup (decl, cleanup);
9011 : }
9012 :
9013 : /* DECL is a VAR_DECL for a compiler-generated variable with static
9014 : storage duration (like a virtual table) whose initializer is a
9015 : compile-time constant. Initialize the variable and provide it to the
9016 : back end. */
9017 :
9018 : void
9019 2151838 : initialize_artificial_var (tree decl, vec<constructor_elt, va_gc> *v)
9020 : {
9021 2151838 : tree init;
9022 2151838 : gcc_assert (DECL_ARTIFICIAL (decl));
9023 2151838 : init = build_constructor (TREE_TYPE (decl), v);
9024 2151838 : gcc_assert (TREE_CODE (init) == CONSTRUCTOR);
9025 2151838 : DECL_INITIAL (decl) = init;
9026 2151838 : DECL_INITIALIZED_P (decl) = 1;
9027 : /* Mark the decl as constexpr so that we can access its content
9028 : at compile time. */
9029 2151838 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
9030 2151838 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
9031 2151838 : determine_visibility (decl);
9032 2151838 : layout_var_decl (decl);
9033 2151838 : maybe_commonize_var (decl);
9034 2151838 : make_rtl_for_nonlocal_decl (decl, init, /*asmspec=*/NULL);
9035 2151838 : }
9036 :
9037 : /* INIT is the initializer for a variable, as represented by the
9038 : parser. Returns true iff INIT is value-dependent. */
9039 :
9040 : static bool
9041 9375602 : value_dependent_init_p (tree init)
9042 : {
9043 9375602 : if (TREE_CODE (init) == TREE_LIST)
9044 : /* A parenthesized initializer, e.g.: int i (3, 2); ? */
9045 20099 : return any_value_dependent_elements_p (init);
9046 9355503 : else if (TREE_CODE (init) == CONSTRUCTOR)
9047 : /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
9048 : {
9049 69246 : if (dependent_type_p (TREE_TYPE (init)))
9050 : return true;
9051 :
9052 69240 : vec<constructor_elt, va_gc> *elts;
9053 69240 : size_t nelts;
9054 69240 : size_t i;
9055 :
9056 69240 : elts = CONSTRUCTOR_ELTS (init);
9057 69240 : nelts = vec_safe_length (elts);
9058 602037 : for (i = 0; i < nelts; ++i)
9059 560634 : if (value_dependent_init_p ((*elts)[i].value))
9060 : return true;
9061 : }
9062 : else
9063 : /* It must be a simple expression, e.g., int i = 3; */
9064 9286257 : return value_dependent_expression_p (init);
9065 :
9066 : return false;
9067 : }
9068 :
9069 : /* A helper function to be called via walk_tree. If any label exists
9070 : under *TP, it is (going to be) forced. Set has_forced_label_in_static. */
9071 :
9072 : static tree
9073 337 : notice_forced_label_r (tree *tp, int *walk_subtrees, void *)
9074 : {
9075 337 : if (TYPE_P (*tp))
9076 0 : *walk_subtrees = 0;
9077 337 : if (TREE_CODE (*tp) == LABEL_DECL)
9078 6 : cfun->has_forced_label_in_static = 1;
9079 337 : return NULL_TREE;
9080 : }
9081 :
9082 : /* Return true if DECL has either a trivial destructor, or for C++20
9083 : is constexpr and has a constexpr destructor. */
9084 :
9085 : static bool
9086 59956414 : decl_maybe_constant_destruction (tree decl, tree type)
9087 : {
9088 59956414 : return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
9089 59956414 : || (cxx_dialect >= cxx20
9090 3955759 : && VAR_P (decl)
9091 3955438 : && DECL_DECLARED_CONSTEXPR_P (decl)
9092 370 : && type_has_constexpr_destructor (strip_array_types (type))));
9093 : }
9094 :
9095 : static tree declare_simd_adjust_this (tree *, int *, void *);
9096 :
9097 : /* Helper function of omp_declare_variant_finalize. Finalize one
9098 : "omp declare variant base" attribute. Return true if it should be
9099 : removed. */
9100 :
9101 : static bool
9102 1751 : omp_declare_variant_finalize_one (tree decl, tree attr)
9103 : {
9104 1751 : if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
9105 : {
9106 164 : walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
9107 : DECL_ARGUMENTS (decl), NULL);
9108 164 : walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
9109 : DECL_ARGUMENTS (decl), NULL);
9110 : }
9111 :
9112 1751 : tree ctx = TREE_VALUE (TREE_VALUE (attr));
9113 1751 : tree simd = omp_get_context_selector (ctx, OMP_TRAIT_SET_CONSTRUCT,
9114 : OMP_TRAIT_CONSTRUCT_SIMD);
9115 1751 : if (simd)
9116 : {
9117 51 : TREE_VALUE (simd)
9118 51 : = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
9119 51 : OMP_TS_PROPERTIES (simd));
9120 : /* FIXME, adjusting simd args unimplemented. */
9121 51 : return true;
9122 : }
9123 :
9124 1700 : tree chain = TREE_CHAIN (TREE_VALUE (attr));
9125 1700 : location_t varid_loc
9126 1700 : = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
9127 1700 : location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
9128 1700 : cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
9129 1700 : tree variant = TREE_PURPOSE (TREE_VALUE (attr));
9130 :
9131 1700 : location_t save_loc = input_location;
9132 1700 : input_location = varid_loc;
9133 :
9134 1700 : releasing_vec args;
9135 1700 : tree parm = DECL_ARGUMENTS (decl);
9136 1700 : if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
9137 164 : parm = DECL_CHAIN (parm);
9138 3022 : for (; parm; parm = DECL_CHAIN (parm))
9139 1322 : vec_safe_push (args, forward_parm (parm));
9140 :
9141 1700 : unsigned nappend_args = 0;
9142 1700 : tree append_args_list = TREE_CHAIN (TREE_CHAIN (chain));
9143 1700 : if (append_args_list)
9144 : {
9145 354 : append_args_list = TREE_VALUE (append_args_list);
9146 354 : append_args_list = (append_args_list && TREE_CHAIN (append_args_list)
9147 591 : ? TREE_VALUE (TREE_CHAIN (append_args_list))
9148 : : NULL_TREE);
9149 741 : for (tree t = append_args_list; t; t = TREE_CHAIN (t))
9150 387 : nappend_args++;
9151 354 : if (nappend_args)
9152 : {
9153 237 : tree type;
9154 237 : if ((type = lookup_qualified_name (global_namespace,
9155 : "omp_interop_t",
9156 : LOOK_want::NORMAL,
9157 : /*complain*/false)) == NULL_TREE
9158 237 : || !c_omp_interop_t_p (TREE_TYPE (type)))
9159 : {
9160 24 : location_t loc = input_location;
9161 24 : variant = tree_strip_any_location_wrapper (variant);
9162 24 : if (!identifier_p (variant))
9163 : {
9164 21 : if (TREE_CODE (variant) == OVERLOAD && OVL_SINGLE_P (variant))
9165 21 : variant = OVL_FIRST (variant);
9166 21 : loc = EXPR_LOC_OR_LOC (variant,
9167 : DECL_SOURCE_LOCATION (variant));
9168 : }
9169 24 : error_at (loc, "argument %d of %qE must be of %<omp_interop_t%>",
9170 24 : args->length () + 1, variant);
9171 24 : inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
9172 : "%<append_args%> specified here");
9173 24 : return true;
9174 : }
9175 564 : for (unsigned i = 0; i < nappend_args; i++)
9176 351 : vec_safe_push (args, build_stub_object (TREE_TYPE (type)));
9177 : }
9178 : }
9179 :
9180 1676 : bool koenig_p = false;
9181 1676 : if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
9182 : {
9183 1606 : if (identifier_p (variant)
9184 : /* In C++20, we may need to perform ADL for a template
9185 : name. */
9186 1582 : || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
9187 18 : && identifier_p (TREE_OPERAND (variant, 0))))
9188 : {
9189 24 : if (!args->is_empty ())
9190 : {
9191 24 : koenig_p = true;
9192 24 : if (!any_type_dependent_arguments_p (args))
9193 21 : variant = perform_koenig_lookup (variant, args,
9194 : tf_warning_or_error);
9195 : }
9196 : else
9197 0 : variant = unqualified_fn_lookup_error (variant);
9198 : }
9199 1582 : else if (!args->is_empty () && is_overloaded_fn (variant))
9200 : {
9201 830 : tree fn = get_first_fn (variant);
9202 830 : fn = STRIP_TEMPLATE (fn);
9203 830 : if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
9204 830 : || DECL_FUNCTION_MEMBER_P (fn)
9205 717 : || DECL_LOCAL_DECL_P (fn)))
9206 : {
9207 717 : koenig_p = true;
9208 717 : if (!any_type_dependent_arguments_p (args))
9209 666 : variant = perform_koenig_lookup (variant, args,
9210 : tf_warning_or_error);
9211 : }
9212 : }
9213 : }
9214 :
9215 1676 : if (idk == CP_ID_KIND_QUALIFIED)
9216 6 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
9217 : koenig_p, tf_warning_or_error);
9218 1670 : else if (idk == CP_ID_KIND_NONE
9219 64 : && TREE_CODE (variant) == FUNCTION_DECL
9220 64 : && DECL_IOBJ_MEMBER_FUNCTION_P (variant)
9221 1718 : && CLASS_TYPE_P (DECL_CONTEXT (decl)))
9222 : {
9223 48 : tree saved_ccp = current_class_ptr;
9224 48 : tree saved_ccr = current_class_ref;
9225 48 : current_class_ptr = NULL_TREE;
9226 48 : current_class_ref = NULL_TREE;
9227 48 : inject_this_parameter (DECL_CONTEXT (decl), TYPE_UNQUALIFIED);
9228 48 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
9229 : koenig_p, tf_warning_or_error);
9230 48 : current_class_ptr = saved_ccp;
9231 48 : current_class_ref = saved_ccr;
9232 : }
9233 : else
9234 1622 : variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
9235 : koenig_p, tf_warning_or_error);
9236 1676 : if (variant == error_mark_node && !processing_template_decl)
9237 : return true;
9238 :
9239 1610 : if (TREE_CODE (variant) == TARGET_EXPR)
9240 9 : variant = TARGET_EXPR_INITIAL (variant);
9241 :
9242 3211 : variant = cp_get_callee_fndecl_nofold (STRIP_REFERENCE_REF (variant));
9243 1610 : input_location = save_loc;
9244 :
9245 1610 : if (variant == decl)
9246 : {
9247 0 : error_at (varid_loc, "variant %qD is the same as base function",
9248 : variant);
9249 0 : return true;
9250 : }
9251 :
9252 1610 : if (variant)
9253 : {
9254 1526 : bool fail;
9255 1526 : const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
9256 1526 : if (!nappend_args)
9257 1367 : fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
9258 : COMPARE_STRICT);
9259 : else
9260 : {
9261 159 : unsigned nbase_args = 0;
9262 159 : for (tree t = TYPE_ARG_TYPES (TREE_TYPE (decl));
9263 756 : t && TREE_VALUE (t) != void_type_node; t = TREE_CHAIN (t))
9264 240 : nbase_args++;
9265 159 : tree vargs, varg;
9266 159 : vargs = varg = TYPE_ARG_TYPES (TREE_TYPE (variant));
9267 399 : for (unsigned i = 0; i < nbase_args && varg;
9268 240 : i++, varg = TREE_CHAIN (varg))
9269 240 : vargs = varg;
9270 417 : for (unsigned i = 0; i < nappend_args && varg; i++)
9271 258 : varg = TREE_CHAIN (varg);
9272 159 : tree saved_vargs;
9273 159 : int saved_no_named_args_stdarg = 0;
9274 159 : if (nbase_args)
9275 : {
9276 111 : saved_vargs = TREE_CHAIN (vargs);
9277 111 : TREE_CHAIN (vargs) = varg;
9278 : }
9279 : else
9280 : {
9281 48 : saved_vargs = vargs;
9282 48 : TYPE_ARG_TYPES (TREE_TYPE (variant)) = varg;
9283 48 : saved_no_named_args_stdarg
9284 48 : = TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant));
9285 48 : if (TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (decl))
9286 48 : && varg == NULL_TREE)
9287 2 : TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant)) = 1;
9288 : }
9289 : /* Skip assert check that TYPE_CANONICAL is the same. */
9290 159 : fail = !comptypes (TREE_TYPE (decl), TREE_TYPE (variant),
9291 : COMPARE_STRUCTURAL);
9292 159 : if (nbase_args)
9293 111 : TREE_CHAIN (vargs) = saved_vargs;
9294 : else
9295 : {
9296 48 : TYPE_ARG_TYPES (TREE_TYPE (variant)) = saved_vargs;
9297 48 : TYPE_NO_NAMED_ARGS_STDARG_P (TREE_TYPE (variant))
9298 96 : = saved_no_named_args_stdarg;
9299 : }
9300 159 : varg = saved_vargs;
9301 159 : if (!fail && !processing_template_decl)
9302 402 : for (unsigned i = 0; i < nappend_args;
9303 246 : i++, varg = TREE_CHAIN (varg))
9304 507 : if (!varg || !c_omp_interop_t_p (TREE_VALUE (varg)))
9305 : {
9306 9 : error_at (DECL_SOURCE_LOCATION (variant),
9307 : "argument %d of %qD must be of %<omp_interop_t%>",
9308 9 : nbase_args + i + 1, variant);
9309 9 : inform (EXPR_LOCATION (TREE_PURPOSE (append_args_list)),
9310 : "%<append_args%> specified here");
9311 9 : break;
9312 : }
9313 : }
9314 1526 : if (fail)
9315 : {
9316 69 : error_at (varid_loc, "variant %qD and base %qD have incompatible "
9317 : "types", variant, decl);
9318 69 : return true;
9319 : }
9320 1457 : if (fndecl_built_in_p (variant)
9321 1457 : && (startswith (varname, "__builtin_")
9322 0 : || startswith (varname, "__sync_")
9323 0 : || startswith (varname, "__atomic_")))
9324 : {
9325 6 : error_at (varid_loc, "variant %qD is a built-in", variant);
9326 6 : return true;
9327 : }
9328 : else
9329 : {
9330 1451 : tree construct
9331 1451 : = omp_get_context_selector_list (ctx, OMP_TRAIT_SET_CONSTRUCT);
9332 1451 : omp_mark_declare_variant (match_loc, variant, construct);
9333 1451 : if (!omp_context_selector_matches (ctx, NULL_TREE, false))
9334 : return true;
9335 1039 : TREE_PURPOSE (TREE_VALUE (attr)) = variant;
9336 :
9337 : // Prepend adjust_args list to variant attributes
9338 1039 : tree adjust_args_list = TREE_CHAIN (TREE_CHAIN (chain));
9339 1039 : if (adjust_args_list != NULL_TREE)
9340 : {
9341 507 : if (DECL_NONSTATIC_MEMBER_P (variant)
9342 285 : && TREE_VALUE (adjust_args_list))
9343 : {
9344 : /* Shift arg position for the added 'this' pointer. */
9345 : /* Handle need_device_ptr */
9346 21 : for (tree t = TREE_PURPOSE (TREE_VALUE (adjust_args_list));
9347 51 : t; t = TREE_CHAIN (t))
9348 30 : TREE_VALUE (t)
9349 30 : = build_int_cst (TREE_TYPE (t),
9350 30 : tree_to_uhwi (TREE_VALUE (t)) + 1);
9351 : }
9352 264 : if (DECL_NONSTATIC_MEMBER_P (variant) && append_args_list)
9353 : {
9354 : /* Shift likewise the number of args after which the
9355 : interop object should be added. */
9356 6 : tree nargs = TREE_CHAIN (TREE_VALUE (adjust_args_list));
9357 6 : TREE_PURPOSE (nargs)
9358 6 : = build_int_cst (TREE_TYPE (nargs),
9359 6 : tree_to_uhwi (TREE_PURPOSE (nargs)) + 1);
9360 : }
9361 528 : for (tree t = append_args_list; t; t = TREE_CHAIN (t))
9362 264 : TREE_VALUE (t)
9363 264 : = cp_finish_omp_init_prefer_type (TREE_VALUE (t));
9364 528 : DECL_ATTRIBUTES (variant) = tree_cons (
9365 : get_identifier ("omp declare variant variant args"),
9366 528 : TREE_VALUE (adjust_args_list), DECL_ATTRIBUTES (variant));
9367 : }
9368 : }
9369 : }
9370 84 : else if (!processing_template_decl)
9371 : {
9372 0 : error_at (varid_loc, "could not find variant declaration");
9373 0 : return true;
9374 : }
9375 :
9376 : return false;
9377 1700 : }
9378 :
9379 : /* Helper function, finish up "omp declare variant base" attribute
9380 : now that there is a DECL. ATTR is the first "omp declare variant base"
9381 : attribute. */
9382 :
9383 : void
9384 1546 : omp_declare_variant_finalize (tree decl, tree attr)
9385 : {
9386 1546 : size_t attr_len = strlen ("omp declare variant base");
9387 1546 : tree *list = &DECL_ATTRIBUTES (decl);
9388 1546 : bool remove_all = false;
9389 1546 : location_t match_loc = DECL_SOURCE_LOCATION (decl);
9390 1546 : if (TREE_CHAIN (TREE_VALUE (attr))
9391 1546 : && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
9392 3092 : && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
9393 1546 : match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
9394 3092 : if (DECL_CONSTRUCTOR_P (decl))
9395 : {
9396 27 : error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
9397 27 : remove_all = true;
9398 : }
9399 1519 : else if (DECL_DESTRUCTOR_P (decl))
9400 : {
9401 9 : error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
9402 9 : remove_all = true;
9403 : }
9404 1510 : else if (DECL_DEFAULTED_FN (decl))
9405 : {
9406 2 : error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
9407 2 : remove_all = true;
9408 : }
9409 1508 : else if (DECL_DELETED_FN (decl))
9410 : {
9411 2 : error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
9412 2 : remove_all = true;
9413 : }
9414 1506 : else if (DECL_VIRTUAL_P (decl))
9415 : {
9416 0 : error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
9417 0 : remove_all = true;
9418 : }
9419 : /* This loop is like private_lookup_attribute, except that it works
9420 : with tree * rather than tree, as we might want to remove the
9421 : attributes that are diagnosed as errorneous. */
9422 3349 : while (*list)
9423 : {
9424 1803 : tree attr = get_attribute_name (*list);
9425 1803 : size_t ident_len = IDENTIFIER_LENGTH (attr);
9426 4729 : if (cmp_attribs ("omp declare variant base", attr_len,
9427 1803 : IDENTIFIER_POINTER (attr), ident_len))
9428 : {
9429 1791 : if (remove_all || omp_declare_variant_finalize_one (decl, *list))
9430 : {
9431 668 : *list = TREE_CHAIN (*list);
9432 668 : continue;
9433 : }
9434 : }
9435 1135 : list = &TREE_CHAIN (*list);
9436 : }
9437 1546 : }
9438 :
9439 : static void cp_maybe_mangle_decomp (tree, cp_decomp *);
9440 :
9441 : /* Finish processing of a declaration;
9442 : install its line number and initial value.
9443 : If the length of an array type is not known before,
9444 : it must be determined now, from the initial value, or it is an error.
9445 :
9446 : INIT is the initializer (if any) for DECL. If INIT_CONST_EXPR_P is
9447 : true, then INIT is an integral constant expression.
9448 :
9449 : FLAGS is LOOKUP_ONLYCONVERTING if the = init syntax was used, else 0
9450 : if the (init) syntax was used.
9451 :
9452 : DECOMP is first identifier's DECL and identifier count in a structured
9453 : bindings, nullptr if not a structured binding. */
9454 :
9455 : void
9456 318623581 : cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
9457 : tree asmspec_tree, int flags, cp_decomp *decomp)
9458 : {
9459 318623581 : vec<tree, va_gc> *cleanups = NULL;
9460 318623581 : const char *asmspec = NULL;
9461 318623581 : int was_readonly = 0;
9462 318623581 : bool var_definition_p = false;
9463 318623581 : tree auto_node;
9464 318623581 : auto_vec<tree> extra_cleanups;
9465 318623581 : tree aggregates1 = NULL_TREE;
9466 318623581 : struct decomp_cleanup {
9467 : tree decl;
9468 : cp_decomp *&decomp;
9469 318620884 : ~decomp_cleanup ()
9470 : {
9471 318620884 : if (decomp && DECL_DECOMPOSITION_P (decl))
9472 214137 : cp_finish_decomp (decl, decomp);
9473 318620884 : }
9474 318623581 : } decomp_cl = { decl, decomp };
9475 :
9476 318623581 : if (decl == error_mark_node)
9477 : return;
9478 318623541 : else if (! decl)
9479 : {
9480 0 : if (init)
9481 0 : error ("assignment (not initialization) in declaration");
9482 0 : return;
9483 : }
9484 :
9485 318623541 : gcc_assert (TREE_CODE (decl) != RESULT_DECL);
9486 : /* Parameters are handled by store_parm_decls, not cp_finish_decl. */
9487 318623541 : gcc_assert (TREE_CODE (decl) != PARM_DECL);
9488 :
9489 318623541 : tree type = TREE_TYPE (decl);
9490 318623541 : if (type == error_mark_node)
9491 : return;
9492 :
9493 318622942 : if (VAR_P (decl) && is_copy_initialization (init))
9494 94632737 : flags |= LOOKUP_ONLYCONVERTING;
9495 :
9496 : /* Warn about register storage specifiers except when in GNU global
9497 : or local register variable extension. */
9498 318622942 : if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec_tree == NULL_TREE)
9499 : {
9500 1931 : if (cxx_dialect >= cxx17)
9501 1282 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
9502 : "ISO C++17 does not allow %<register%> storage "
9503 : "class specifier");
9504 : else
9505 649 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
9506 : "%<register%> storage class specifier used");
9507 : }
9508 :
9509 : /* If a name was specified, get the string. */
9510 318622942 : if (at_namespace_scope_p ())
9511 68872282 : asmspec_tree = maybe_apply_renaming_pragma (decl, asmspec_tree);
9512 318622942 : if (asmspec_tree && asmspec_tree != error_mark_node)
9513 978485 : asmspec = TREE_STRING_POINTER (asmspec_tree);
9514 :
9515 318622942 : bool in_class_decl
9516 318622942 : = (current_class_type
9517 200141330 : && CP_DECL_CONTEXT (decl) == current_class_type
9518 133204110 : && TYPE_BEING_DEFINED (current_class_type)
9519 449794565 : && !CLASSTYPE_TEMPLATE_INSTANTIATION (current_class_type));
9520 :
9521 126183279 : if (in_class_decl
9522 126183279 : && (DECL_INITIAL (decl) || init))
9523 92526429 : DECL_INITIALIZED_IN_CLASS_P (decl) = 1;
9524 :
9525 318622942 : if (VAR_P (decl)
9526 318622942 : && (auto_node = type_uses_auto (type)))
9527 : {
9528 13176071 : tree d_init;
9529 13176071 : if (init == NULL_TREE)
9530 : {
9531 2845 : if (DECL_LANG_SPECIFIC (decl)
9532 2762 : && DECL_TEMPLATE_INSTANTIATION (decl)
9533 5604 : && !DECL_TEMPLATE_INSTANTIATED (decl))
9534 : {
9535 : /* init is null because we're deferring instantiating the
9536 : initializer until we need it. Well, we need it now. */
9537 2753 : instantiate_decl (decl, /*defer_ok*/true, /*expl*/false);
9538 2753 : return;
9539 : }
9540 :
9541 92 : if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
9542 : /* Class deduction with no initializer is OK. */;
9543 : else
9544 : {
9545 : /* Ordinary auto deduction without an initializer, a situation
9546 : which grokdeclarator already detects and rejects for the most
9547 : part. But we can still get here if we're instantiating a
9548 : variable template before we've fully parsed (and attached) its
9549 : initializer, e.g. template<class> auto x = x<int>; */
9550 3 : error_at (DECL_SOURCE_LOCATION (decl),
9551 : "declaration of %q#D has no initializer", decl);
9552 3 : TREE_TYPE (decl) = error_mark_node;
9553 3 : return;
9554 : }
9555 : }
9556 13173315 : d_init = init;
9557 13173315 : if (d_init)
9558 : {
9559 13173226 : if (TREE_CODE (d_init) == TREE_LIST
9560 13224454 : && !CLASS_PLACEHOLDER_TEMPLATE (auto_node))
9561 27811 : d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
9562 : tf_warning_or_error);
9563 13173226 : d_init = resolve_nondeduced_context (d_init, tf_warning_or_error);
9564 : /* Force auto deduction now. Use tf_none to avoid redundant warnings
9565 : on deprecated-14.C. */
9566 13173226 : mark_single_function (d_init, tf_none);
9567 : }
9568 13173315 : enum auto_deduction_context adc = adc_variable_type;
9569 13173315 : if (DECL_DECOMPOSITION_P (decl))
9570 : adc = adc_decomp_type;
9571 13173315 : tree outer_targs = NULL_TREE;
9572 13173315 : if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (auto_node)
9573 303 : && DECL_LANG_SPECIFIC (decl)
9574 126 : && DECL_TEMPLATE_INFO (decl)
9575 13173372 : && !DECL_FUNCTION_SCOPE_P (decl))
9576 : /* The outer template arguments might be needed for satisfaction.
9577 : (For function scope variables, do_auto_deduction will obtain the
9578 : outer template arguments from current_function_decl.) */
9579 57 : outer_targs = DECL_TI_ARGS (decl);
9580 13173315 : type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node,
9581 : tf_warning_or_error, adc,
9582 : outer_targs, flags);
9583 13173315 : if (type == error_mark_node)
9584 : return;
9585 13172311 : if (TREE_CODE (type) == FUNCTION_TYPE)
9586 : {
9587 3 : error ("initializer for %<decltype(auto) %D%> has function type; "
9588 : "did you forget the %<()%>?", decl);
9589 3 : TREE_TYPE (decl) = error_mark_node;
9590 3 : return;
9591 : }
9592 : /* As in start_decl_1, complete so TREE_READONLY is set properly. */
9593 13172308 : if (!processing_template_decl
9594 3014570 : && !type_uses_auto (type)
9595 16186871 : && !COMPLETE_TYPE_P (complete_type (type)))
9596 : {
9597 18 : auto_diagnostic_group d;
9598 18 : error_at (location_of (decl),
9599 : "deduced type %qT for %qD is incomplete", type, decl);
9600 18 : cxx_incomplete_type_inform (type);
9601 18 : TREE_TYPE (decl) = error_mark_node;
9602 18 : return;
9603 18 : }
9604 :
9605 : /* Now that we have a type, try these again. */
9606 13172290 : layout_decl (decl, 0);
9607 13172290 : cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
9608 :
9609 : /* Update the type of the corresponding TEMPLATE_DECL to match. */
9610 13172290 : if (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INFO (decl))
9611 : {
9612 34876 : tree tmpl = template_for_substitution (decl);
9613 34876 : if (DECL_TEMPLATE_RESULT (tmpl) == decl)
9614 31066 : TREE_TYPE (tmpl) = type;
9615 : }
9616 : }
9617 :
9618 318619161 : if (ensure_literal_type_for_constexpr_object (decl) == error_mark_node)
9619 : {
9620 65 : DECL_DECLARED_CONSTEXPR_P (decl) = 0;
9621 65 : if (VAR_P (decl) && DECL_CLASS_SCOPE_P (decl))
9622 : {
9623 6 : init = NULL_TREE;
9624 6 : DECL_EXTERNAL (decl) = 1;
9625 : }
9626 : }
9627 :
9628 318619161 : if (VAR_P (decl)
9629 119887573 : && DECL_CLASS_SCOPE_P (decl)
9630 19438677 : && verify_type_context (DECL_SOURCE_LOCATION (decl),
9631 : TCTX_STATIC_STORAGE, type)
9632 338057838 : && DECL_INITIALIZED_IN_CLASS_P (decl))
9633 18118192 : check_static_variable_definition (decl, type);
9634 :
9635 318619161 : if (!processing_template_decl && VAR_P (decl) && is_global_var (decl))
9636 : {
9637 35804967 : type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
9638 35804967 : ? TCTX_THREAD_STORAGE
9639 : : TCTX_STATIC_STORAGE);
9640 35804967 : verify_type_context (input_location, context, TREE_TYPE (decl));
9641 : }
9642 :
9643 318619161 : if (init && TREE_CODE (decl) == FUNCTION_DECL)
9644 : {
9645 558486 : tree clone;
9646 558486 : if (init == ridpointers[(int)RID_DELETE]
9647 558486 : || (TREE_CODE (init) == STRING_CST
9648 30 : && TREE_TYPE (init) == ridpointers[(int)RID_DELETE]))
9649 : {
9650 : /* FIXME check this is 1st decl. */
9651 536388 : if (UNLIKELY (DECL_MAIN_P (decl)))
9652 : {
9653 : /* [basic.start.main]/3: A program that defines main as deleted
9654 : is ill-formed. */
9655 6 : error ("%<::main%> cannot be deleted");
9656 6 : DECL_INITIAL (decl) = error_mark_node;
9657 : }
9658 : else
9659 : {
9660 536382 : DECL_DELETED_FN (decl) = 1;
9661 536382 : DECL_DECLARED_INLINE_P (decl) = 1;
9662 536382 : DECL_INITIAL (decl)
9663 536382 : = TREE_CODE (init) == STRING_CST ? init : error_mark_node;
9664 536400 : FOR_EACH_CLONE (clone, decl)
9665 : {
9666 18 : DECL_DELETED_FN (clone) = 1;
9667 18 : DECL_DECLARED_INLINE_P (clone) = 1;
9668 18 : DECL_INITIAL (clone) = DECL_INITIAL (decl);
9669 : }
9670 : }
9671 536388 : init = NULL_TREE;
9672 : }
9673 22098 : else if (init == ridpointers[(int)RID_DEFAULT])
9674 : {
9675 22086 : if (defaultable_fn_check (decl))
9676 22062 : DECL_DEFAULTED_FN (decl) = 1;
9677 : else
9678 24 : DECL_INITIAL (decl) = NULL_TREE;
9679 : }
9680 : }
9681 :
9682 318619161 : if (init && VAR_P (decl))
9683 : {
9684 104099695 : DECL_NONTRIVIALLY_INITIALIZED_P (decl) = 1;
9685 : /* If DECL is a reference, then we want to know whether init is a
9686 : reference constant; init_const_expr_p as passed tells us whether
9687 : it's an rvalue constant. */
9688 104099695 : if (TYPE_REF_P (type))
9689 2254375 : init_const_expr_p = potential_constant_expression (init);
9690 104099695 : if (init_const_expr_p)
9691 : {
9692 : /* Set these flags now for templates. We'll update the flags in
9693 : store_init_value for instantiations. */
9694 91593071 : DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
9695 91593071 : if (decl_maybe_constant_var_p (decl)
9696 : /* FIXME setting TREE_CONSTANT on refs breaks the back end. */
9697 91593071 : && !TYPE_REF_P (type))
9698 40102403 : TREE_CONSTANT (decl) = true;
9699 : }
9700 : /* This is handled mostly by gimplify.cc, but we have to deal with
9701 : not warning about int x = x; as it is a GCC extension to turn off
9702 : this warning but only if warn_init_self is zero. */
9703 104099695 : if (!DECL_EXTERNAL (decl)
9704 102510110 : && !TREE_STATIC (decl)
9705 69505344 : && decl == tree_strip_any_location_wrapper (init)
9706 104103515 : && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self))
9707 3796 : suppress_warning (decl, OPT_Winit_self);
9708 : }
9709 214519466 : else if (VAR_P (decl)
9710 15787878 : && COMPLETE_TYPE_P (type)
9711 12344718 : && !TYPE_REF_P (type)
9712 12344351 : && !dependent_type_p (type)
9713 226568957 : && is_really_empty_class (type, /*ignore_vptr*/false))
9714 : /* We have no initializer but there's nothing to initialize anyway.
9715 : Treat DECL as constant due to c++/109876. */
9716 571922 : TREE_CONSTANT (decl) = true;
9717 :
9718 318619161 : if (flag_openmp
9719 841881 : && TREE_CODE (decl) == FUNCTION_DECL
9720 : /* #pragma omp declare variant on methods handled in finish_struct
9721 : instead. */
9722 318981954 : && (!DECL_OBJECT_MEMBER_FUNCTION_P (decl)
9723 139333 : || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
9724 223923 : if (tree attr = lookup_attribute ("omp declare variant base",
9725 223923 : DECL_ATTRIBUTES (decl)))
9726 970 : omp_declare_variant_finalize (decl, attr);
9727 :
9728 318619161 : if (processing_template_decl)
9729 : {
9730 183026173 : bool type_dependent_p;
9731 :
9732 : /* Add this declaration to the statement-tree. */
9733 183026173 : if (at_function_scope_p ())
9734 66123666 : add_decl_expr (decl);
9735 :
9736 183026173 : type_dependent_p = dependent_type_p (type);
9737 :
9738 183026173 : if (check_for_bare_parameter_packs (init))
9739 : {
9740 3 : init = NULL_TREE;
9741 3 : DECL_INITIAL (decl) = NULL_TREE;
9742 : }
9743 :
9744 : /* Generally, initializers in templates are expanded when the
9745 : template is instantiated. But, if DECL is a variable constant
9746 : then it can be used in future constant expressions, so its value
9747 : must be available. */
9748 :
9749 183026173 : bool dep_init = false;
9750 :
9751 183026173 : if (!VAR_P (decl) || type_dependent_p)
9752 : /* We can't do anything if the decl has dependent type. */;
9753 22875428 : else if (init
9754 21213122 : && (init_const_expr_p || DECL_DECLARED_CONSTEXPR_P (decl))
9755 17260262 : && !TYPE_REF_P (type)
9756 17228463 : && decl_maybe_constant_var_p (decl)
9757 31690396 : && !(dep_init = value_dependent_init_p (init)))
9758 : {
9759 : /* This variable seems to be a non-dependent constant, so process
9760 : its initializer. If check_initializer returns non-null the
9761 : initialization wasn't constant after all. */
9762 2276318 : tree init_code;
9763 2276318 : cleanups = make_tree_vector ();
9764 2276318 : init_code = check_initializer (decl, init, flags, &cleanups);
9765 2276318 : if (init_code == NULL_TREE)
9766 2276318 : init = NULL_TREE;
9767 2276318 : release_tree_vector (cleanups);
9768 : }
9769 : else
9770 : {
9771 20599110 : gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
9772 : /* Try to deduce array size. */
9773 20599110 : maybe_deduce_size_from_array_init (decl, init);
9774 : /* And complain about multiple initializers. */
9775 18936804 : if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
9776 20699075 : && !MAYBE_CLASS_TYPE_P (type))
9777 7 : init = build_x_compound_expr_from_list (init, ELK_INIT,
9778 : tf_warning_or_error);
9779 : }
9780 :
9781 183026173 : if (init)
9782 54724678 : DECL_INITIAL (decl) = init;
9783 :
9784 183026173 : if (dep_init)
9785 : {
9786 6538650 : retrofit_lang_decl (decl);
9787 6538650 : SET_DECL_DEPENDENT_INIT_P (decl, true);
9788 : }
9789 :
9790 183026173 : if (VAR_P (decl) && DECL_REGISTER (decl) && asmspec)
9791 : {
9792 9 : if (TREE_ADDRESSABLE (decl))
9793 3 : error_at (DECL_SOURCE_LOCATION (decl),
9794 : "address of explicit register variable %qD requested",
9795 : decl);
9796 : else
9797 : {
9798 6 : set_user_assembler_name (decl, asmspec);
9799 6 : DECL_HARD_REGISTER (decl) = 1;
9800 : }
9801 : }
9802 183026173 : return;
9803 : }
9804 :
9805 : /* Just store non-static data member initializers for later. */
9806 135592988 : if (init && TREE_CODE (decl) == FIELD_DECL)
9807 585080 : DECL_INITIAL (decl) = init;
9808 :
9809 : /* Take care of TYPE_DECLs up front. */
9810 135592988 : if (TREE_CODE (decl) == TYPE_DECL)
9811 : {
9812 10619303 : if (type != error_mark_node
9813 10619303 : && MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
9814 : {
9815 5147701 : if (TREE_TYPE (DECL_NAME (decl)) && TREE_TYPE (decl) != type)
9816 0 : warning (0, "shadowing previous type declaration of %q#D", decl);
9817 5147701 : set_identifier_type_value (DECL_NAME (decl), decl);
9818 : }
9819 :
9820 : /* If we have installed this as the canonical typedef for this
9821 : type, and that type has not been defined yet, delay emitting
9822 : the debug information for it, as we will emit it later. */
9823 10619303 : if (TYPE_MAIN_DECL (TREE_TYPE (decl)) == decl
9824 10619303 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
9825 568206 : TYPE_DECL_SUPPRESS_DEBUG (decl) = 1;
9826 :
9827 10619303 : rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl),
9828 : at_eof);
9829 10619303 : return;
9830 : }
9831 :
9832 : /* A reference will be modified here, as it is initialized. */
9833 124973685 : if (! DECL_EXTERNAL (decl)
9834 60876958 : && TREE_READONLY (decl)
9835 161354083 : && TYPE_REF_P (type))
9836 : {
9837 236700 : was_readonly = 1;
9838 236700 : TREE_READONLY (decl) = 0;
9839 : }
9840 :
9841 : /* This needs to happen before extend_ref_init_temps. */
9842 124973685 : if (VAR_OR_FUNCTION_DECL_P (decl))
9843 : {
9844 115885927 : if (VAR_P (decl))
9845 59464965 : maybe_commonize_var (decl);
9846 115885927 : determine_visibility (decl);
9847 : }
9848 :
9849 124973685 : if (VAR_P (decl))
9850 : {
9851 59464965 : duration_kind dk = decl_storage_duration (decl);
9852 : /* [dcl.constinit]/1 "The constinit specifier shall be applied
9853 : only to a declaration of a variable with static or thread storage
9854 : duration." */
9855 59464965 : if (DECL_DECLARED_CONSTINIT_P (decl)
9856 59464965 : && !(dk == dk_thread || dk == dk_static))
9857 : {
9858 24 : error_at (DECL_SOURCE_LOCATION (decl),
9859 : "%<constinit%> can only be applied to a variable with "
9860 : "static or thread storage duration");
9861 24 : return;
9862 : }
9863 :
9864 59464941 : if (decomp)
9865 : {
9866 42922 : if (DECL_DECLARED_CONSTINIT_P (decl) && cxx_dialect < cxx26)
9867 40 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wc__26_extensions,
9868 : "%<constinit%> can be applied to structured binding "
9869 : "only with %<-std=c++2c%> or %<-std=gnu++2c%>");
9870 42922 : cp_maybe_mangle_decomp (decl, decomp);
9871 42922 : if (TREE_STATIC (decl) && !DECL_FUNCTION_SCOPE_P (decl))
9872 : {
9873 501 : if (CP_DECL_THREAD_LOCAL_P (decl))
9874 37 : aggregates1 = tls_aggregates;
9875 : else
9876 464 : aggregates1 = static_aggregates;
9877 : }
9878 : }
9879 :
9880 : /* Detect stuff like 'info r = ^^int;' outside a manifestly
9881 : constant-evaluated context. */
9882 59464941 : check_out_of_consteval_use (decl);
9883 :
9884 : /* If this is a local variable that will need a mangled name,
9885 : register it now. We must do this before processing the
9886 : initializer for the variable, since the initialization might
9887 : require a guard variable, and since the mangled name of the
9888 : guard variable will depend on the mangled name of this
9889 : variable. */
9890 118929882 : if (DECL_FUNCTION_SCOPE_P (decl)
9891 23795613 : && TREE_STATIC (decl)
9892 59600725 : && !DECL_ARTIFICIAL (decl))
9893 : {
9894 : /* The variable holding an anonymous union will have had its
9895 : discriminator set in finish_anon_union, after which it's
9896 : NAME will have been cleared. */
9897 135138 : if (DECL_NAME (decl))
9898 135093 : determine_local_discriminator (decl);
9899 : /* Normally has_forced_label_in_static is set during GIMPLE
9900 : lowering, but [cd]tors are never actually compiled directly.
9901 : We need to set this early so we can deal with the label
9902 : address extension. */
9903 135138 : if ((DECL_CONSTRUCTOR_P (current_function_decl)
9904 135109 : || DECL_DESTRUCTOR_P (current_function_decl))
9905 135148 : && init)
9906 : {
9907 29 : walk_tree (&init, notice_forced_label_r, NULL, NULL);
9908 29 : add_local_decl (cfun, decl);
9909 : }
9910 135138 : if (!consteval_only_p (decl))
9911 : /* And make sure it's in the symbol table for
9912 : c_parse_final_cleanups to find. */
9913 135066 : varpool_node::get_create (decl);
9914 : }
9915 :
9916 59464941 : if (flag_openmp
9917 192710 : && VAR_P (decl)
9918 192710 : && DECL_LANG_SPECIFIC (decl)
9919 115340 : && DECL_OMP_DECLARE_MAPPER_P (decl)
9920 59464945 : && init)
9921 : {
9922 3 : gcc_assert (TREE_CODE (init) == OMP_DECLARE_MAPPER);
9923 3 : DECL_INITIAL (decl) = init;
9924 : }
9925 : /* Convert the initializer to the type of DECL, if we have not
9926 : already initialized DECL. */
9927 59464938 : else if (!DECL_INITIALIZED_P (decl)
9928 : /* If !DECL_EXTERNAL then DECL is being defined. In the
9929 : case of a static data member initialized inside the
9930 : class-specifier, there can be an initializer even if DECL
9931 : is *not* defined. */
9932 59464938 : && (!DECL_EXTERNAL (decl) || init))
9933 : {
9934 52794355 : cleanups = make_tree_vector ();
9935 52794355 : init = check_initializer (decl, init, flags, &cleanups);
9936 :
9937 : /* Handle:
9938 :
9939 : [dcl.init]
9940 :
9941 : The memory occupied by any object of static storage
9942 : duration is zero-initialized at program startup before
9943 : any other initialization takes place.
9944 :
9945 : We cannot create an appropriate initializer until after
9946 : the type of DECL is finalized. If DECL_INITIAL is set,
9947 : then the DECL is statically initialized, and any
9948 : necessary zero-initialization has already been performed. */
9949 52791658 : if (TREE_STATIC (decl) && !DECL_INITIAL (decl))
9950 500848 : DECL_INITIAL (decl) = build_zero_init (TREE_TYPE (decl),
9951 : /*nelts=*/NULL_TREE,
9952 : /*static_storage_p=*/true);
9953 : /* Remember that the initialization for this variable has
9954 : taken place. */
9955 52791658 : DECL_INITIALIZED_P (decl) = 1;
9956 : /* This declaration is the definition of this variable,
9957 : unless we are initializing a static data member within
9958 : the class specifier. */
9959 52791658 : if (!DECL_EXTERNAL (decl))
9960 59462244 : var_definition_p = true;
9961 : }
9962 : /* If the variable has an array type, lay out the type, even if
9963 : there is no initializer. It is valid to index through the
9964 : array, and we must get TYPE_ALIGN set correctly on the array
9965 : type. */
9966 6670583 : else if (TREE_CODE (type) == ARRAY_TYPE)
9967 211105 : layout_type (type);
9968 :
9969 59462244 : if (TREE_STATIC (decl)
9970 35254293 : && !at_function_scope_p ()
9971 94580753 : && current_function_decl == NULL)
9972 : /* So decl is a global variable or a static member of a
9973 : non local class. Record the types it uses
9974 : so that we can decide later to emit debug info for them. */
9975 35118497 : record_types_used_by_current_var_decl (decl);
9976 : }
9977 :
9978 : /* Add this declaration to the statement-tree. This needs to happen
9979 : after the call to check_initializer so that the DECL_EXPR for a
9980 : reference temp is added before the DECL_EXPR for the reference itself. */
9981 124970964 : if (DECL_FUNCTION_SCOPE_P (decl))
9982 : {
9983 : /* If we're building a variable sized type, and we might be
9984 : reachable other than via the top of the current binding
9985 : level, then create a new BIND_EXPR so that we deallocate
9986 : the object at the right time. */
9987 23795613 : if (VAR_P (decl)
9988 23795613 : && DECL_SIZE (decl)
9989 23735963 : && !TREE_CONSTANT (DECL_SIZE (decl))
9990 23796643 : && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
9991 : {
9992 3 : tree bind;
9993 3 : bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL);
9994 3 : TREE_SIDE_EFFECTS (bind) = 1;
9995 3 : add_stmt (bind);
9996 3 : BIND_EXPR_BODY (bind) = push_stmt_list ();
9997 : }
9998 23795613 : add_decl_expr (decl);
9999 : }
10000 :
10001 124970964 : tree decomp_init = NULL_TREE;
10002 : /* Let the middle end know about variables and functions -- but not
10003 : static data members in uninstantiated class templates. */
10004 124970964 : if (VAR_OR_FUNCTION_DECL_P (decl))
10005 : {
10006 115883206 : if (VAR_P (decl))
10007 : {
10008 59462244 : layout_var_decl (decl);
10009 59462244 : if (!flag_weak)
10010 : /* Check again now that we have an initializer. */
10011 57 : maybe_commonize_var (decl);
10012 : /* A class-scope constexpr variable with an out-of-class declaration.
10013 : C++17 makes them implicitly inline, but still force it out. */
10014 80266997 : if (DECL_INLINE_VAR_P (decl)
10015 27831826 : && !DECL_VAR_DECLARED_INLINE_P (decl)
10016 12574910 : && !DECL_TEMPLATE_INSTANTIATION (decl)
10017 44728447 : && !in_class_decl)
10018 103 : mark_needed (decl);
10019 : }
10020 :
10021 115883206 : if (var_definition_p
10022 : /* With -fmerge-all-constants, gimplify_init_constructor
10023 : might add TREE_STATIC to aggregate variables. */
10024 51633434 : && (TREE_STATIC (decl)
10025 23659974 : || (flag_merge_constants >= 2
10026 38 : && AGGREGATE_TYPE_P (type))))
10027 : {
10028 : /* If a TREE_READONLY variable needs initialization
10029 : at runtime, it is no longer readonly and we need to
10030 : avoid MEM_READONLY_P being set on RTL created for it. */
10031 27973463 : if (init)
10032 : {
10033 14156 : if (TREE_READONLY (decl))
10034 510 : TREE_READONLY (decl) = 0;
10035 : was_readonly = 0;
10036 : }
10037 27959307 : else if (was_readonly)
10038 2481 : TREE_READONLY (decl) = 1;
10039 :
10040 : /* Likewise if it needs destruction. */
10041 27973463 : if (!decl_maybe_constant_destruction (decl, type))
10042 3414 : TREE_READONLY (decl) = 0;
10043 : }
10044 87909743 : else if (VAR_P (decl)
10045 31488781 : && CP_DECL_THREAD_LOCAL_P (decl)
10046 18638 : && (!DECL_EXTERNAL (decl) || flag_extern_tls_init)
10047 18638 : && (was_readonly || TREE_READONLY (decl))
10048 87909758 : && var_needs_tls_wrapper (decl))
10049 : {
10050 : /* TLS variables need dynamic initialization by the TLS wrapper
10051 : function, we don't want to hoist accesses to it before the
10052 : wrapper. */
10053 6 : was_readonly = 0;
10054 6 : TREE_READONLY (decl) = 0;
10055 : }
10056 :
10057 115883206 : make_rtl_for_nonlocal_decl (decl, init, asmspec);
10058 :
10059 : /* Check for abstractness of the type. */
10060 115883206 : if (var_definition_p)
10061 51633434 : abstract_virtuals_error (decl, type);
10062 :
10063 115883206 : if (decomp && !cp_finish_decomp (decl, decomp, true))
10064 10078 : decomp = NULL;
10065 :
10066 115883206 : if (TREE_TYPE (decl) == error_mark_node)
10067 : /* No initialization required. */
10068 : ;
10069 115883136 : else if (TREE_CODE (decl) == FUNCTION_DECL)
10070 : {
10071 56420962 : if (init)
10072 : {
10073 584 : if (init == ridpointers[(int)RID_DEFAULT])
10074 : {
10075 : /* An out-of-class default definition is defined at
10076 : the point where it is explicitly defaulted. */
10077 572 : if (DECL_DELETED_FN (decl))
10078 6 : maybe_explain_implicit_delete (decl);
10079 566 : else if (DECL_INITIAL (decl) == error_mark_node)
10080 542 : synthesize_method (decl);
10081 : }
10082 : else
10083 24 : error_at (cp_expr_loc_or_loc (init,
10084 12 : DECL_SOURCE_LOCATION (decl)),
10085 : "function %q#D is initialized like a variable",
10086 : decl);
10087 : }
10088 : /* else no initialization required. */
10089 : }
10090 59462174 : else if (DECL_EXTERNAL (decl)
10091 59462174 : && ! (DECL_LANG_SPECIFIC (decl)
10092 7527859 : && DECL_NOT_REALLY_EXTERN (decl)))
10093 : {
10094 : /* check_initializer will have done any constant initialization. */
10095 : }
10096 : /* A variable definition. */
10097 53497291 : else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
10098 : {
10099 : /* Initialize the local variable. */
10100 23659811 : if (!decomp)
10101 23627214 : initialize_local_var (decl, init, false);
10102 : else
10103 : {
10104 32597 : tree cleanup = NULL_TREE;
10105 32597 : if (DECL_SIZE (decl))
10106 32597 : cleanup = cxx_maybe_build_cleanup (decl, tf_warning_or_error);
10107 : /* If cp_finish_decomp needs to emit any code, we need to emit that
10108 : code after code emitted by initialize_local_var in a single
10109 : CLEANUP_POINT_EXPR, so that temporaries are destructed only
10110 : after the cp_finish_decomp emitted code.
10111 : If there are any cleanups, either extend_ref_init_temps
10112 : created ones or e.g. array destruction, push those first
10113 : with the cleanups guarded on a bool temporary, initially
10114 : set to false and set to true after initialize_local_var
10115 : emitted code. */
10116 32597 : tree guard = NULL_TREE;
10117 32597 : if (cleanups || cleanup)
10118 : {
10119 32597 : guard = get_internal_target_expr (boolean_false_node);
10120 32597 : add_stmt (guard);
10121 32597 : guard = TARGET_EXPR_SLOT (guard);
10122 : }
10123 32597 : tree sl = push_stmt_list ();
10124 32597 : initialize_local_var (decl, init, true);
10125 32597 : if (guard)
10126 : {
10127 32597 : add_stmt (build2 (MODIFY_EXPR, boolean_type_node,
10128 : guard, boolean_true_node));
10129 32615 : for (tree &t : *cleanups)
10130 18 : t = build3 (COND_EXPR, void_type_node,
10131 : guard, t, void_node);
10132 32597 : if (cleanup)
10133 25 : cleanup = build3 (COND_EXPR, void_type_node,
10134 : guard, cleanup, void_node);
10135 : }
10136 32597 : unsigned before = stmt_list_stack->length ();
10137 32597 : cp_finish_decomp (decl, decomp);
10138 32597 : decomp = NULL;
10139 32597 : unsigned n_extra_cleanups = stmt_list_stack->length () - before;
10140 32597 : sl = pop_stmt_list (sl);
10141 32597 : if (n_extra_cleanups)
10142 : {
10143 : /* If cp_finish_decomp needs any cleanups, such as for
10144 : extend_ref_init_temps created vars, pop_stmt_list
10145 : popped that all, so push those extra cleanups around
10146 : the whole sequence with a guard variable. */
10147 15 : gcc_assert (TREE_CODE (sl) == STATEMENT_LIST);
10148 15 : guard = get_internal_target_expr (integer_zero_node);
10149 15 : add_stmt (guard);
10150 15 : guard = TARGET_EXPR_SLOT (guard);
10151 63 : for (unsigned i = 0; i < n_extra_cleanups; ++i)
10152 : {
10153 48 : tree_stmt_iterator tsi = tsi_last (sl);
10154 48 : gcc_assert (!tsi_end_p (tsi));
10155 48 : tree last = tsi_stmt (tsi);
10156 48 : gcc_assert (TREE_CODE (last) == CLEANUP_STMT
10157 : && !CLEANUP_EH_ONLY (last));
10158 48 : tree cst = build_int_cst (integer_type_node, i + 1);
10159 96 : tree cl = build3 (COND_EXPR, void_type_node,
10160 : build2 (GE_EXPR, boolean_type_node,
10161 : guard, cst),
10162 48 : CLEANUP_EXPR (last), void_node);
10163 48 : extra_cleanups.safe_push (cl);
10164 48 : tsi_link_before (&tsi, build2 (MODIFY_EXPR,
10165 : integer_type_node,
10166 : guard, cst),
10167 : TSI_SAME_STMT);
10168 48 : tree sl2 = CLEANUP_BODY (last);
10169 48 : gcc_assert (TREE_CODE (sl2) == STATEMENT_LIST);
10170 48 : tsi_link_before (&tsi, sl2, TSI_SAME_STMT);
10171 48 : tsi_delink (&tsi);
10172 : }
10173 : }
10174 32597 : decomp_init = maybe_cleanup_point_expr_void (sl);
10175 32597 : if (cleanup)
10176 25 : finish_decl_cleanup (decl, cleanup);
10177 : }
10178 : }
10179 :
10180 : /* If a variable is defined, and then a subsequent
10181 : definition with external linkage is encountered, we will
10182 : get here twice for the same variable. We want to avoid
10183 : calling expand_static_init more than once. For variables
10184 : that are not static data members, we can call
10185 : expand_static_init only when we actually process the
10186 : initializer. It is not legal to redeclare a static data
10187 : member, so this issue does not arise in that case. */
10188 29837480 : else if (var_definition_p && TREE_STATIC (decl))
10189 : {
10190 27972671 : if (decomp && DECL_FUNCTION_SCOPE_P (decl))
10191 : {
10192 102 : tree sl = push_stmt_list ();
10193 102 : auto saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
10194 102 : current_stmt_tree ()->stmts_are_full_exprs_p = 0;
10195 102 : expand_static_init (decl, init);
10196 102 : current_stmt_tree ()->stmts_are_full_exprs_p
10197 102 : = saved_stmts_are_full_exprs_p;
10198 102 : cp_finish_decomp (decl, decomp);
10199 102 : decomp = NULL;
10200 102 : sl = pop_stmt_list (sl);
10201 102 : sl = maybe_cleanup_point_expr_void (sl);
10202 102 : add_stmt (sl);
10203 : }
10204 : else
10205 27972569 : expand_static_init (decl, init);
10206 : }
10207 : }
10208 :
10209 : /* If a CLEANUP_STMT was created to destroy a temporary bound to a
10210 : reference, insert it in the statement-tree now. */
10211 124970964 : if (cleanups)
10212 : {
10213 52794363 : for (tree t : *cleanups)
10214 : {
10215 2705 : push_cleanup (NULL_TREE, t, false);
10216 : /* As in initialize_local_var. */
10217 2705 : wrap_temporary_cleanups (init, t);
10218 : }
10219 52791658 : release_tree_vector (cleanups);
10220 : }
10221 :
10222 124971042 : for (tree t : &extra_cleanups)
10223 48 : push_cleanup (NULL_TREE, t, false);
10224 :
10225 124970964 : if (decomp_init)
10226 32597 : add_stmt (decomp_init);
10227 :
10228 124970964 : if (decomp
10229 145 : && var_definition_p
10230 145 : && TREE_STATIC (decl)
10231 124971109 : && !DECL_FUNCTION_SCOPE_P (decl))
10232 : {
10233 145 : tree &aggregates3 = (CP_DECL_THREAD_LOCAL_P (decl)
10234 145 : ? tls_aggregates : static_aggregates);
10235 145 : tree aggregates2 = aggregates3;
10236 145 : if (aggregates2 != aggregates1)
10237 : {
10238 66 : cp_finish_decomp (decl, decomp);
10239 66 : decomp = NULL;
10240 66 : if (aggregates3 != aggregates2)
10241 : {
10242 : /* If there are dynamic initializers for the structured
10243 : binding base or associated extended ref temps and also
10244 : dynamic initializers for the structured binding non-base
10245 : vars, mark them. */
10246 267 : for (tree t = aggregates3; t != aggregates2; t = TREE_CHAIN (t))
10247 204 : STATIC_INIT_DECOMP_NONBASE_P (t) = 1;
10248 150 : for (tree t = aggregates2; t != aggregates1; t = TREE_CHAIN (t))
10249 87 : STATIC_INIT_DECOMP_BASE_P (t) = 1;
10250 : }
10251 : }
10252 : }
10253 :
10254 124970964 : if (was_readonly)
10255 236131 : TREE_READONLY (decl) = 1;
10256 :
10257 124970964 : if (flag_openmp
10258 435849 : && VAR_P (decl)
10259 125163674 : && lookup_attribute ("omp declare target implicit",
10260 192710 : DECL_ATTRIBUTES (decl)))
10261 : {
10262 52 : DECL_ATTRIBUTES (decl)
10263 52 : = remove_attribute ("omp declare target implicit",
10264 52 : DECL_ATTRIBUTES (decl));
10265 52 : complete_type (TREE_TYPE (decl));
10266 52 : if (!omp_mappable_type (TREE_TYPE (decl)))
10267 : {
10268 30 : auto_diagnostic_group d;
10269 30 : error ("%q+D in declare target directive does not have mappable"
10270 : " type", decl);
10271 30 : if (TREE_TYPE (decl) != error_mark_node
10272 30 : && !COMPLETE_TYPE_P (TREE_TYPE (decl)))
10273 30 : cxx_incomplete_type_inform (TREE_TYPE (decl));
10274 30 : }
10275 22 : else if (!lookup_attribute ("omp declare target",
10276 22 : DECL_ATTRIBUTES (decl))
10277 44 : && !lookup_attribute ("omp declare target link",
10278 22 : DECL_ATTRIBUTES (decl)))
10279 : {
10280 22 : DECL_ATTRIBUTES (decl)
10281 22 : = tree_cons (get_identifier ("omp declare target"),
10282 22 : NULL_TREE, DECL_ATTRIBUTES (decl));
10283 22 : symtab_node *node = symtab_node::get (decl);
10284 22 : if (node != NULL)
10285 : {
10286 19 : node->offloadable = 1;
10287 19 : if (ENABLE_OFFLOADING)
10288 : {
10289 : g->have_offload = true;
10290 : if (is_a <varpool_node *> (node))
10291 : vec_safe_push (offload_vars, decl);
10292 : }
10293 : }
10294 : }
10295 : }
10296 :
10297 : /* This is the last point we can lower alignment so give the target the
10298 : chance to do so. */
10299 124970964 : if (VAR_P (decl)
10300 59462244 : && !is_global_var (decl)
10301 148630938 : && !DECL_HARD_REGISTER (decl))
10302 23659921 : targetm.lower_local_decl_alignment (decl);
10303 :
10304 124970964 : invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
10305 318620884 : }
10306 :
10307 : /* For class TYPE return itself or some its bases that contain
10308 : any direct non-static data members. Return error_mark_node if an
10309 : error has been diagnosed. */
10310 :
10311 : static tree
10312 15708 : find_decomp_class_base (location_t loc, tree type, tree ret,
10313 : tsubst_flags_t complain)
10314 : {
10315 31416 : if (LAMBDA_TYPE_P (type))
10316 : {
10317 12 : if (complain & tf_error)
10318 : {
10319 12 : auto_diagnostic_group d;
10320 12 : error_at (loc, "cannot decompose lambda closure type %qT", type);
10321 12 : inform (location_of (type), "lambda declared here");
10322 12 : }
10323 12 : return error_mark_node;
10324 : }
10325 :
10326 15696 : bool member_seen = false;
10327 148588 : for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
10328 233788 : if (TREE_CODE (field) != FIELD_DECL
10329 32210 : || DECL_ARTIFICIAL (field)
10330 165041 : || DECL_UNNAMED_BIT_FIELD (field))
10331 100857 : continue;
10332 32074 : else if (ret)
10333 : return type;
10334 32048 : else if (ANON_AGGR_TYPE_P (TREE_TYPE (field)))
10335 : {
10336 8 : if ((complain & tf_error) == 0)
10337 0 : return error_mark_node;
10338 8 : auto_diagnostic_group d;
10339 8 : if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE)
10340 4 : error_at (loc, "cannot decompose class type %qT because it has an "
10341 : "anonymous struct member", type);
10342 : else
10343 4 : error_at (loc, "cannot decompose class type %qT because it has an "
10344 : "anonymous union member", type);
10345 8 : inform (DECL_SOURCE_LOCATION (field), "declared here");
10346 8 : return error_mark_node;
10347 8 : }
10348 32040 : else if (!accessible_p (type, field, true))
10349 : {
10350 5 : if ((complain & tf_error) == 0)
10351 0 : return error_mark_node;
10352 5 : auto_diagnostic_group d;
10353 5 : error_at (loc, "cannot decompose inaccessible member %qD of %qT",
10354 : field, type);
10355 5 : inform (DECL_SOURCE_LOCATION (field),
10356 5 : TREE_PRIVATE (field)
10357 : ? G_("declared private here")
10358 : : G_("declared protected here"));
10359 5 : return error_mark_node;
10360 5 : }
10361 : else
10362 : member_seen = true;
10363 :
10364 15657 : tree base_binfo, binfo;
10365 15657 : tree orig_ret = ret;
10366 15657 : int i;
10367 15657 : if (member_seen)
10368 15555 : ret = type;
10369 15721 : for (binfo = TYPE_BINFO (type), i = 0;
10370 15721 : BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
10371 : {
10372 84 : auto_diagnostic_group d;
10373 84 : tree t = find_decomp_class_base (loc, TREE_TYPE (base_binfo), ret,
10374 : complain);
10375 84 : if (t == error_mark_node)
10376 : {
10377 3 : if (complain & tf_error)
10378 3 : inform (location_of (type), "in base class of %qT", type);
10379 3 : return error_mark_node;
10380 : }
10381 81 : if (t != NULL_TREE && t != ret)
10382 : {
10383 54 : if (ret == type)
10384 : {
10385 10 : if (complain & tf_error)
10386 10 : error_at (loc, "cannot decompose class type %qT: both it and "
10387 : "its base class %qT have non-static data "
10388 : "members", type, t);
10389 10 : return error_mark_node;
10390 : }
10391 44 : else if (orig_ret != NULL_TREE)
10392 : return t;
10393 44 : else if (ret != NULL_TREE)
10394 : {
10395 7 : if (complain & tf_error)
10396 7 : error_at (loc, "cannot decompose class type %qT: its base "
10397 : "classes %qT and %qT have non-static data "
10398 : "members", type, ret, t);
10399 7 : return error_mark_node;
10400 : }
10401 : else
10402 : ret = t;
10403 : }
10404 84 : }
10405 : return ret;
10406 : }
10407 :
10408 : /* Return std::tuple_size<TYPE>::value. */
10409 :
10410 : static tree
10411 90851 : get_tuple_size (tree type)
10412 : {
10413 90851 : tree args = make_tree_vec (1);
10414 90851 : TREE_VEC_ELT (args, 0) = type;
10415 90851 : tree inst = lookup_template_class (tuple_size_identifier, args,
10416 : /*in_decl*/NULL_TREE,
10417 : /*context*/std_node,
10418 : tf_none);
10419 90851 : inst = complete_type (inst);
10420 90851 : if (inst == error_mark_node
10421 89380 : || !COMPLETE_TYPE_P (inst)
10422 166036 : || !CLASS_TYPE_P (inst))
10423 : return NULL_TREE;
10424 75185 : tree val = lookup_qualified_name (inst, value_identifier,
10425 : LOOK_want::NORMAL, /*complain*/false);
10426 75185 : if (val == error_mark_node)
10427 : return NULL_TREE;
10428 75179 : if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
10429 75179 : val = maybe_constant_value (val, NULL_TREE, mce_true);
10430 75179 : if (TREE_CODE (val) == INTEGER_CST)
10431 : return val;
10432 : else
10433 6 : return error_mark_node;
10434 : }
10435 :
10436 : /* Return std::tuple_element<I,TYPE>::type. */
10437 :
10438 : static tree
10439 85313 : get_tuple_element_type (tree type, unsigned HOST_WIDE_INT i)
10440 : {
10441 85313 : tree args = make_tree_vec (2);
10442 85313 : TREE_VEC_ELT (args, 0) = build_int_cst (integer_type_node, i);
10443 85313 : TREE_VEC_ELT (args, 1) = type;
10444 85313 : tree inst = lookup_template_class (tuple_element_identifier, args,
10445 : /*in_decl*/NULL_TREE,
10446 : /*context*/std_node,
10447 : tf_warning_or_error);
10448 85313 : return make_typename_type (inst, type_identifier,
10449 85313 : none_type, tf_warning_or_error);
10450 : }
10451 :
10452 : /* Return e.get<i>() or get<i>(e). */
10453 :
10454 : static tree
10455 85322 : get_tuple_decomp_init (tree decl, unsigned HOST_WIDE_INT i)
10456 : {
10457 85322 : tree targs = make_tree_vec (1);
10458 85322 : TREE_VEC_ELT (targs, 0) = build_int_cst (integer_type_node, i);
10459 :
10460 85322 : tree etype = TREE_TYPE (decl);
10461 85322 : tree e = convert_from_reference (decl);
10462 :
10463 : /* [The id-expression] e is an lvalue if the type of the entity e is an
10464 : lvalue reference and an xvalue otherwise. */
10465 85322 : if (!TYPE_REF_P (etype)
10466 85322 : || TYPE_REF_IS_RVALUE (etype))
10467 84023 : e = move (e);
10468 :
10469 85322 : tree fns = lookup_qualified_name (TREE_TYPE (e), get__identifier,
10470 : LOOK_want::NORMAL, /*complain*/false);
10471 85322 : bool use_member_get = false;
10472 :
10473 : /* To use a member get, member lookup must find at least one
10474 : declaration that is a function template
10475 : whose first template parameter is a non-type parameter. */
10476 253497 : for (lkp_iterator iter (MAYBE_BASELINK_FUNCTIONS (fns)); iter; ++iter)
10477 : {
10478 85322 : tree fn = *iter;
10479 85322 : if (TREE_CODE (fn) == TEMPLATE_DECL)
10480 : {
10481 2472 : tree tparms = DECL_TEMPLATE_PARMS (fn);
10482 2472 : tree parm = TREE_VEC_ELT (INNERMOST_TEMPLATE_PARMS (tparms), 0);
10483 2472 : if (TREE_CODE (TREE_VALUE (parm)) == PARM_DECL)
10484 : {
10485 : use_member_get = true;
10486 : break;
10487 : }
10488 : }
10489 : }
10490 :
10491 85322 : if (use_member_get)
10492 : {
10493 2469 : fns = lookup_template_function (fns, targs);
10494 2469 : return build_new_method_call (e, fns, /*args*/NULL,
10495 : /*path*/NULL_TREE, LOOKUP_NORMAL,
10496 2469 : /*fn_p*/NULL, tf_warning_or_error);
10497 : }
10498 : else
10499 : {
10500 82853 : releasing_vec args (make_tree_vector_single (e));
10501 82853 : fns = lookup_template_function (get__identifier, targs);
10502 82853 : fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
10503 82853 : return finish_call_expr (fns, &args, /*novirt*/false,
10504 : /*koenig*/true, tf_warning_or_error);
10505 82853 : }
10506 : }
10507 :
10508 : /* It's impossible to recover the decltype of a tuple decomposition variable
10509 : based on the actual type of the variable, so store it in a hash table. */
10510 :
10511 : static GTY((cache)) decl_tree_cache_map *decomp_type_table;
10512 :
10513 : tree
10514 622 : lookup_decomp_type (tree v)
10515 : {
10516 622 : if (decomp_type_table)
10517 495 : if (tree *slot = decomp_type_table->get (v))
10518 431 : return *slot;
10519 : return NULL_TREE;
10520 : }
10521 :
10522 : /* Mangle a decomposition declaration if needed. Arguments like
10523 : in cp_finish_decomp. */
10524 :
10525 : static void
10526 42922 : cp_maybe_mangle_decomp (tree decl, cp_decomp *decomp)
10527 : {
10528 42922 : if (!processing_template_decl
10529 42922 : && !error_operand_p (decl)
10530 85844 : && TREE_STATIC (decl))
10531 : {
10532 764 : auto_vec<tree, 16> v;
10533 764 : v.safe_grow (decomp->count, true);
10534 764 : tree d = decomp->decl;
10535 2641 : for (unsigned int i = 0; i < decomp->count; i++, d = DECL_CHAIN (d))
10536 1877 : v[decomp->count - i - 1] = d;
10537 764 : if (DECL_FUNCTION_SCOPE_P (decl))
10538 : {
10539 : size_t sz = 3;
10540 919 : for (unsigned int i = 0; i < decomp->count; ++i)
10541 656 : sz += IDENTIFIER_LENGTH (DECL_NAME (v[i])) + 1;
10542 263 : char *name = XALLOCAVEC (char, sz);
10543 263 : name[0] = 'D';
10544 263 : name[1] = 'C';
10545 263 : char *p = name + 2;
10546 919 : for (unsigned int i = 0; i < decomp->count; ++i)
10547 : {
10548 656 : size_t len = IDENTIFIER_LENGTH (DECL_NAME (v[i]));
10549 656 : *p++ = ' ';
10550 656 : memcpy (p, IDENTIFIER_POINTER (DECL_NAME (v[i])), len);
10551 656 : p += len;
10552 : }
10553 263 : *p = '\0';
10554 263 : determine_local_discriminator (decl, get_identifier (name));
10555 : }
10556 764 : SET_DECL_ASSEMBLER_NAME (decl, mangle_decomp (decl, v));
10557 764 : maybe_apply_pragma_weak (decl);
10558 764 : }
10559 42922 : }
10560 :
10561 : /* Append #i to DECL_NAME (decl) or for name independent decls
10562 : clear DECL_NAME (decl). */
10563 :
10564 : static void
10565 14842 : set_sb_pack_name (tree decl, unsigned HOST_WIDE_INT i)
10566 : {
10567 14842 : if (name_independent_decl_p (decl))
10568 : /* Only "_" names are treated as name independent, "_#0" etc. is not and
10569 : because we pushdecl the individual decl elements of structured binding
10570 : pack, we could get redeclaration errors if there are 2 or more name
10571 : independent structured binding packs in the same scope. */
10572 312 : DECL_NAME (decl) = NULL_TREE;
10573 : else
10574 : {
10575 14530 : tree name = DECL_NAME (decl);
10576 14530 : size_t len = IDENTIFIER_LENGTH (name) + 22;
10577 14530 : char *n = XALLOCAVEC (char, len);
10578 14530 : snprintf (n, len, "%s#" HOST_WIDE_INT_PRINT_UNSIGNED,
10579 14530 : IDENTIFIER_POINTER (name), i);
10580 14530 : DECL_NAME (decl) = get_identifier (n);
10581 : }
10582 14842 : }
10583 :
10584 : /* Return structured binding size of TYPE or -1 if erroneous. */
10585 :
10586 : HOST_WIDE_INT
10587 528 : cp_decomp_size (location_t loc, tree type, tsubst_flags_t complain)
10588 : {
10589 528 : if (TYPE_REF_P (type))
10590 : {
10591 0 : type = complete_type (TREE_TYPE (type));
10592 0 : if (type == error_mark_node)
10593 : return -1;
10594 0 : if (!COMPLETE_TYPE_P (type))
10595 : {
10596 0 : if (complain & tf_error)
10597 0 : error_at (loc, "structured binding refers to incomplete type %qT",
10598 : type);
10599 0 : return -1;
10600 : }
10601 : }
10602 :
10603 528 : unsigned HOST_WIDE_INT eltscnt = 0;
10604 528 : if (TREE_CODE (type) == ARRAY_TYPE)
10605 : {
10606 306 : if (TYPE_DOMAIN (type) == NULL_TREE)
10607 : {
10608 9 : if (complain & tf_error)
10609 6 : error_at (loc, "cannot decompose array of unknown bound %qT",
10610 : type);
10611 9 : return -1;
10612 : }
10613 297 : tree nelts = array_type_nelts_top (type);
10614 297 : if (nelts == error_mark_node)
10615 : return -1;
10616 297 : if (!tree_fits_shwi_p (nelts))
10617 : {
10618 3 : if (complain & tf_error)
10619 3 : error_at (loc, "cannot decompose variable length array %qT", type);
10620 3 : return -1;
10621 : }
10622 294 : return tree_to_shwi (nelts);
10623 : }
10624 : /* 2 GNU extensions. */
10625 222 : else if (TREE_CODE (type) == COMPLEX_TYPE)
10626 : return 2;
10627 216 : else if (TREE_CODE (type) == VECTOR_TYPE)
10628 : {
10629 12 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
10630 : {
10631 : if (complain & tf_error)
10632 : error_at (loc, "cannot decompose variable length vector %qT", type);
10633 : return -1;
10634 : }
10635 12 : return eltscnt;
10636 : }
10637 204 : else if (tree tsize = get_tuple_size (type))
10638 : {
10639 33 : if (tsize == error_mark_node
10640 27 : || !tree_fits_shwi_p (tsize)
10641 60 : || tree_int_cst_sgn (tsize) < 0)
10642 : {
10643 9 : if (complain & tf_error)
10644 9 : error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
10645 : "constant expression", type);
10646 9 : return -1;
10647 : }
10648 24 : return tree_to_shwi (tsize);
10649 : }
10650 171 : else if (TREE_CODE (type) == UNION_TYPE)
10651 : {
10652 3 : if (complain & tf_error)
10653 3 : error_at (loc, "cannot decompose union type %qT", type);
10654 3 : return -1;
10655 : }
10656 168 : else if (!CLASS_TYPE_P (type))
10657 : {
10658 21 : if (complain & tf_error)
10659 18 : error_at (loc, "cannot decompose non-array non-class type %qT", type);
10660 21 : return -1;
10661 : }
10662 147 : else if (processing_template_decl && complete_type (type) == error_mark_node)
10663 : return -1;
10664 147 : else if (!COMPLETE_TYPE_P (type))
10665 : {
10666 3 : if (complain & tf_error)
10667 3 : error_at (loc, "structured binding refers to incomplete class type "
10668 : "%qT", type);
10669 3 : return -1;
10670 : }
10671 : else
10672 : {
10673 144 : tree btype = find_decomp_class_base (loc, type, NULL_TREE, complain);
10674 144 : if (btype == error_mark_node)
10675 : return -1;
10676 123 : else if (btype == NULL_TREE)
10677 : return 0;
10678 102 : if (btype != type)
10679 : {
10680 6 : tree binfo = lookup_base (type, btype, ba_check, NULL, complain);
10681 6 : if (binfo == NULL_TREE || binfo == error_mark_node)
10682 : return -1;
10683 : }
10684 1082 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
10685 1633 : if (TREE_CODE (field) != FIELD_DECL
10686 351 : || DECL_ARTIFICIAL (field)
10687 1337 : || DECL_UNNAMED_BIT_FIELD (field))
10688 647 : continue;
10689 : else
10690 339 : eltscnt++;
10691 96 : return eltscnt;
10692 : }
10693 : }
10694 :
10695 : /* Finish a decomposition declaration. DECL is the underlying declaration
10696 : "e", FIRST is the head of a chain of decls for the individual identifiers
10697 : chained through DECL_CHAIN in reverse order and COUNT is the number of
10698 : those decls. If TEST_P is true, return true if any code would need to be
10699 : actually emitted but don't emit it. Return false otherwise. */
10700 :
10701 : bool
10702 290664 : cp_finish_decomp (tree decl, cp_decomp *decomp, bool test_p)
10703 : {
10704 290664 : tree first = decomp->decl;
10705 290664 : unsigned count = decomp->count;
10706 290664 : if (error_operand_p (decl))
10707 : {
10708 63 : error_out:
10709 616 : while (count--)
10710 : {
10711 420 : TREE_TYPE (first) = error_mark_node;
10712 420 : if (DECL_HAS_VALUE_EXPR_P (first))
10713 : {
10714 9 : SET_DECL_VALUE_EXPR (first, NULL_TREE);
10715 9 : DECL_HAS_VALUE_EXPR_P (first) = 0;
10716 : }
10717 420 : first = DECL_CHAIN (first);
10718 : }
10719 196 : if (DECL_P (decl) && DECL_NAMESPACE_SCOPE_P (decl))
10720 51 : SET_DECL_ASSEMBLER_NAME (decl, get_identifier ("<decomp>"));
10721 196 : return false;
10722 : }
10723 :
10724 290601 : location_t loc = DECL_SOURCE_LOCATION (decl);
10725 290601 : if (type_dependent_expression_p (decl)
10726 : /* This happens for range for when not in templates.
10727 : Still add the DECL_VALUE_EXPRs for later processing. */
10728 290601 : || (!processing_template_decl
10729 76041 : && type_uses_auto (TREE_TYPE (decl))))
10730 : {
10731 587866 : for (unsigned int i = 0; i < count; i++)
10732 : {
10733 391839 : if (!DECL_HAS_VALUE_EXPR_P (first))
10734 : {
10735 391839 : tree v = build_nt (ARRAY_REF, decl,
10736 391839 : size_int (count - i - 1),
10737 : NULL_TREE, NULL_TREE);
10738 391839 : SET_DECL_VALUE_EXPR (first, v);
10739 391839 : DECL_HAS_VALUE_EXPR_P (first) = 1;
10740 : }
10741 391839 : if (processing_template_decl)
10742 391214 : fit_decomposition_lang_decl (first, decl);
10743 391839 : first = DECL_CHAIN (first);
10744 : }
10745 : return false;
10746 : }
10747 :
10748 94574 : auto_vec<tree, 16> v;
10749 94574 : v.safe_grow (count, true);
10750 94574 : tree d = first;
10751 94574 : int pack = -1;
10752 282466 : for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
10753 : {
10754 187892 : v[count - i - 1] = d;
10755 187892 : fit_decomposition_lang_decl (d, decl);
10756 187892 : if (DECL_PACK_P (d))
10757 3879 : pack = count - i - 1;
10758 : }
10759 :
10760 94574 : tree type = TREE_TYPE (decl);
10761 94574 : tree dexp = decl;
10762 :
10763 94574 : if (TYPE_REF_P (type))
10764 : {
10765 1860 : dexp = convert_from_reference (dexp);
10766 1860 : type = complete_type (TREE_TYPE (type));
10767 1860 : if (type == error_mark_node)
10768 133 : goto error_out;
10769 1860 : if (!COMPLETE_TYPE_P (type))
10770 : {
10771 3 : error_at (loc, "structured binding refers to incomplete type %qT",
10772 : type);
10773 3 : goto error_out;
10774 : }
10775 : }
10776 :
10777 94571 : tree eltype = NULL_TREE;
10778 94571 : unsigned HOST_WIDE_INT eltscnt = 0;
10779 : /* Structured binding packs when initializer is non-dependent should
10780 : have their DECL_VALUE_EXPR set to a TREE_VEC. First two elements
10781 : of that TREE_VEC are the base and index, what is normally represented
10782 : as DECL_VALUE_EXPR ARRAY_REF <base, index> where index is the index
10783 : of the pack first element. The remaining elements of the TREE_VEC
10784 : are VAR_DECLs for the pack elements. */
10785 94571 : tree packv = NULL_TREE;
10786 :
10787 94571 : if (TREE_CODE (type) == ARRAY_TYPE)
10788 : {
10789 3786 : tree nelts;
10790 3786 : nelts = array_type_nelts_top (type);
10791 3786 : if (nelts == error_mark_node)
10792 0 : goto error_out;
10793 3786 : if (DECL_DECOMP_BASE (decl))
10794 : {
10795 9 : error_at (loc, "array initializer for structured binding "
10796 : "declaration in condition");
10797 9 : goto error_out;
10798 : }
10799 3777 : if (!tree_fits_uhwi_p (nelts))
10800 : {
10801 3 : error_at (loc, "cannot decompose variable length array %qT", type);
10802 3 : goto error_out;
10803 : }
10804 3774 : eltscnt = tree_to_uhwi (nelts);
10805 3774 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10806 : {
10807 11 : cnt_mismatch:
10808 38 : auto_diagnostic_group d;
10809 38 : if (count > eltscnt)
10810 27 : error_n (loc, count,
10811 : "%u name provided for structured binding",
10812 : "%u names provided for structured binding", count);
10813 : else
10814 11 : error_n (loc, count,
10815 : "only %u name provided for structured binding",
10816 : "only %u names provided for structured binding", count);
10817 38 : inform_n (loc, eltscnt,
10818 : "while %qT decomposes into %wu element",
10819 : "while %qT decomposes into %wu elements",
10820 : type, eltscnt);
10821 38 : goto error_out;
10822 : }
10823 3763 : eltype = TREE_TYPE (type);
10824 8948 : for (unsigned int i = 0; i < count; i++)
10825 : {
10826 5185 : if ((unsigned) pack == i)
10827 : {
10828 2956 : packv = make_tree_vec (eltscnt - count + 3);
10829 15743 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10830 : {
10831 12787 : tree t;
10832 12787 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10833 12787 : set_sb_pack_name (t, j);
10834 12787 : maybe_push_decl (t);
10835 12787 : TREE_TYPE (t) = eltype;
10836 12787 : layout_decl (t, 0);
10837 12787 : if (!processing_template_decl)
10838 : {
10839 12700 : tree a = unshare_expr (dexp);
10840 12700 : a = build4 (ARRAY_REF, eltype, a, size_int (j + pack),
10841 : NULL_TREE, NULL_TREE);
10842 12700 : SET_DECL_VALUE_EXPR (t, a);
10843 12700 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10844 : }
10845 : }
10846 5185 : continue;
10847 2956 : }
10848 2229 : TREE_TYPE (v[i]) = eltype;
10849 2229 : layout_decl (v[i], 0);
10850 2229 : if (processing_template_decl)
10851 136 : continue;
10852 2093 : tree t = unshare_expr (dexp);
10853 2093 : unsigned HOST_WIDE_INT j = i;
10854 2093 : if (pack != -1 && (unsigned) pack < i)
10855 64 : j = i + eltscnt - count;
10856 2093 : t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
10857 2093 : SET_DECL_VALUE_EXPR (v[i], t);
10858 2093 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10859 : }
10860 : }
10861 : /* 2 GNU extensions. */
10862 90785 : else if (TREE_CODE (type) == COMPLEX_TYPE)
10863 : {
10864 78 : eltscnt = 2;
10865 78 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10866 3 : goto cnt_mismatch;
10867 75 : eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
10868 213 : for (unsigned int i = 0; i < count; i++)
10869 : {
10870 138 : if ((unsigned) pack == i)
10871 : {
10872 60 : packv = make_tree_vec (eltscnt - count + 3);
10873 132 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10874 : {
10875 72 : tree t;
10876 72 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10877 72 : set_sb_pack_name (t, j);
10878 72 : maybe_push_decl (t);
10879 72 : TREE_TYPE (t) = eltype;
10880 72 : layout_decl (t, 0);
10881 72 : if (!processing_template_decl)
10882 : {
10883 72 : tree a = build1 (pack + j ? IMAGPART_EXPR : REALPART_EXPR, eltype,
10884 : unshare_expr (dexp));
10885 48 : SET_DECL_VALUE_EXPR (t, a);
10886 48 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10887 : }
10888 : }
10889 60 : continue;
10890 60 : }
10891 78 : TREE_TYPE (v[i]) = eltype;
10892 78 : layout_decl (v[i], 0);
10893 78 : if (processing_template_decl)
10894 16 : continue;
10895 62 : tree t = unshare_expr (dexp);
10896 62 : unsigned HOST_WIDE_INT j = i;
10897 62 : if (pack != -1 && (unsigned) pack < i)
10898 16 : j = i + eltscnt - count;
10899 93 : t = build1 (j ? IMAGPART_EXPR : REALPART_EXPR, eltype, t);
10900 62 : SET_DECL_VALUE_EXPR (v[i], t);
10901 62 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10902 : }
10903 : }
10904 90707 : else if (TREE_CODE (type) == VECTOR_TYPE)
10905 : {
10906 60 : if (!TYPE_VECTOR_SUBPARTS (type).is_constant (&eltscnt))
10907 : {
10908 : error_at (loc, "cannot decompose variable length vector %qT", type);
10909 : goto error_out;
10910 : }
10911 60 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10912 3 : goto cnt_mismatch;
10913 57 : eltype = cp_build_qualified_type (TREE_TYPE (type), TYPE_QUALS (type));
10914 249 : for (unsigned int i = 0; i < count; i++)
10915 : {
10916 192 : if ((unsigned) pack == i)
10917 : {
10918 48 : packv = make_tree_vec (eltscnt - count + 3);
10919 708 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
10920 : {
10921 660 : tree t;
10922 660 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
10923 660 : set_sb_pack_name (t, j);
10924 660 : maybe_push_decl (t);
10925 660 : TREE_TYPE (t) = eltype;
10926 660 : layout_decl (t, 0);
10927 660 : if (!processing_template_decl)
10928 : {
10929 440 : tree a = unshare_expr (dexp);
10930 440 : location_t loc = DECL_SOURCE_LOCATION (t);
10931 440 : tree s = size_int (j + pack);
10932 440 : convert_vector_to_array_for_subscript (loc, &a, s);
10933 440 : a = build4 (ARRAY_REF, eltype, a, s,
10934 : NULL_TREE, NULL_TREE);
10935 440 : SET_DECL_VALUE_EXPR (t, a);
10936 440 : DECL_HAS_VALUE_EXPR_P (t) = 1;
10937 : }
10938 : }
10939 84 : continue;
10940 48 : }
10941 144 : TREE_TYPE (v[i]) = eltype;
10942 144 : layout_decl (v[i], 0);
10943 144 : if (processing_template_decl)
10944 36 : continue;
10945 108 : tree t = unshare_expr (dexp);
10946 108 : unsigned HOST_WIDE_INT j = i;
10947 108 : if (pack != -1 && (unsigned) pack < i)
10948 24 : j = i + eltscnt - count;
10949 108 : convert_vector_to_array_for_subscript (DECL_SOURCE_LOCATION (v[i]),
10950 108 : &t, size_int (j));
10951 108 : t = build4 (ARRAY_REF, eltype, t, size_int (j), NULL_TREE, NULL_TREE);
10952 108 : SET_DECL_VALUE_EXPR (v[i], t);
10953 108 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
10954 : }
10955 : }
10956 90647 : else if (tree tsize = get_tuple_size (type))
10957 : {
10958 75146 : if (tsize == error_mark_node)
10959 : {
10960 0 : error_at (loc, "%<std::tuple_size<%T>::value%> is not an integral "
10961 : "constant expression", type);
10962 0 : goto error_out;
10963 : }
10964 75146 : if (!tree_fits_uhwi_p (tsize))
10965 : {
10966 12 : auto_diagnostic_group d;
10967 12 : error_n (loc, count,
10968 : "%u name provided for structured binding",
10969 : "%u names provided for structured binding", count);
10970 12 : inform (loc, "while %qT decomposes into %E elements",
10971 : type, tsize);
10972 12 : goto error_out;
10973 12 : }
10974 75134 : eltscnt = tree_to_uhwi (tsize);
10975 75134 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
10976 6 : goto cnt_mismatch;
10977 75128 : if (test_p && eltscnt)
10978 94441 : return true;
10979 42284 : if (!processing_template_decl && DECL_DECOMP_BASE (decl) && eltscnt)
10980 : {
10981 : /* For structured bindings used in conditions we need to evaluate
10982 : the conversion of decl (aka e in the standard) to bool or
10983 : integral/enumeral type (the latter for switch conditions)
10984 : before the get methods. */
10985 86 : tree cond = convert_from_reference (decl);
10986 86 : if (integer_onep (DECL_DECOMP_BASE (decl)))
10987 : /* switch condition. */
10988 18 : cond = build_expr_type_conversion (WANT_INT | WANT_ENUM,
10989 : cond, true);
10990 : else
10991 : /* if/while/for condition. */
10992 68 : cond = contextual_conv_bool (cond, tf_warning_or_error);
10993 86 : if (cond && !error_operand_p (cond))
10994 : {
10995 : /* Wrap that value into a TARGET_EXPR, emit it right
10996 : away and save for later uses in the cp_parse_condition
10997 : or its instantiation. */
10998 86 : cond = get_internal_target_expr (cond);
10999 86 : add_stmt (cond);
11000 86 : DECL_DECOMP_BASE (decl) = cond;
11001 : }
11002 : }
11003 42284 : int save_read = DECL_READ_P (decl);
11004 127078 : for (unsigned i = 0; i < count; ++i)
11005 : {
11006 84815 : location_t sloc = input_location;
11007 84815 : location_t dloc = DECL_SOURCE_LOCATION (v[i]);
11008 :
11009 84815 : if ((unsigned) pack == i)
11010 : {
11011 320 : packv = make_tree_vec (eltscnt - count + 3);
11012 1147 : for (unsigned HOST_WIDE_INT j = 0; j < eltscnt - count + 1; ++j)
11013 : {
11014 827 : tree t;
11015 827 : TREE_VEC_ELT (packv, j + 2) = t = copy_node (v[pack]);
11016 827 : set_sb_pack_name (t, j);
11017 827 : input_location = dloc;
11018 827 : tree init = get_tuple_decomp_init (decl, j + pack);
11019 827 : tree eltype = (init == error_mark_node ? error_mark_node
11020 827 : : get_tuple_element_type (type, j + pack));
11021 827 : input_location = sloc;
11022 :
11023 827 : if (VOID_TYPE_P (eltype))
11024 : {
11025 0 : error ("%<std::tuple_element<%wu, %T>::type%> is "
11026 : "%<void%>", j + pack, type);
11027 0 : eltype = error_mark_node;
11028 : }
11029 827 : if (init == error_mark_node || eltype == error_mark_node)
11030 : {
11031 0 : inform (dloc, "in initialization of structured binding "
11032 0 : "pack %qD", v[pack]);
11033 0 : goto error_out;
11034 : }
11035 827 : maybe_push_decl (t);
11036 : /* Save the decltype away before reference collapse. */
11037 827 : hash_map_safe_put<hm_ggc> (decomp_type_table, t, eltype);
11038 827 : if (glvalue_p (init))
11039 770 : eltype = cp_build_reference_type (eltype, !lvalue_p (init));
11040 827 : TREE_TYPE (t) = eltype;
11041 827 : layout_decl (t, 0);
11042 827 : DECL_HAS_VALUE_EXPR_P (t) = 0;
11043 827 : if (!processing_template_decl)
11044 : {
11045 597 : copy_linkage (t, decl);
11046 597 : tree name = DECL_NAME (t);
11047 597 : if (TREE_STATIC (decl))
11048 44 : DECL_NAME (t) = DECL_NAME (v[pack]);
11049 597 : cp_finish_decl (t, init, /*constexpr*/false,
11050 : /*asm*/NULL_TREE, LOOKUP_NORMAL);
11051 597 : if (TREE_STATIC (decl))
11052 : {
11053 44 : DECL_ASSEMBLER_NAME (t);
11054 44 : DECL_NAME (t) = name;
11055 : }
11056 : }
11057 : }
11058 320 : continue;
11059 320 : }
11060 :
11061 84495 : unsigned HOST_WIDE_INT j = i;
11062 84495 : if (pack != -1 && (unsigned) pack < i)
11063 235 : j = i + eltscnt - count;
11064 84495 : input_location = dloc;
11065 84495 : tree init = get_tuple_decomp_init (decl, j);
11066 84495 : tree eltype = (init == error_mark_node ? error_mark_node
11067 84486 : : get_tuple_element_type (type, j));
11068 84495 : input_location = sloc;
11069 :
11070 84495 : if (VOID_TYPE_P (eltype))
11071 : {
11072 3 : error ("%<std::tuple_element<%wu, %T>::type%> is %<void%>",
11073 : j, type);
11074 3 : eltype = error_mark_node;
11075 : }
11076 84495 : if (init == error_mark_node || eltype == error_mark_node)
11077 : {
11078 21 : inform (dloc, "in initialization of structured binding "
11079 21 : "variable %qD", v[i]);
11080 21 : goto error_out;
11081 : }
11082 : /* Save the decltype away before reference collapse. */
11083 84474 : hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
11084 84474 : if (glvalue_p (init))
11085 84132 : eltype = cp_build_reference_type (eltype, !lvalue_p (init));
11086 84474 : TREE_TYPE (v[i]) = eltype;
11087 84474 : layout_decl (v[i], 0);
11088 84474 : if (DECL_HAS_VALUE_EXPR_P (v[i]))
11089 : {
11090 : /* In this case the names are variables, not just proxies. */
11091 220 : SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
11092 220 : DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
11093 : }
11094 84474 : if (!processing_template_decl)
11095 : {
11096 65616 : copy_linkage (v[i], decl);
11097 65616 : cp_finish_decl (v[i], init, /*constexpr*/false,
11098 : /*asm*/NULL_TREE, LOOKUP_NORMAL);
11099 : }
11100 : }
11101 : /* Ignore reads from the underlying decl performed during initialization
11102 : of the individual variables. If those will be read, we'll mark
11103 : the underlying decl as read at that point. */
11104 42263 : DECL_READ_P (decl) = save_read;
11105 : }
11106 15501 : else if (TREE_CODE (type) == UNION_TYPE)
11107 : {
11108 3 : error_at (loc, "cannot decompose union type %qT", type);
11109 3 : goto error_out;
11110 : }
11111 15498 : else if (!CLASS_TYPE_P (type))
11112 : {
11113 16 : error_at (loc, "cannot decompose non-array non-class type %qT", type);
11114 16 : goto error_out;
11115 : }
11116 15482 : else if (processing_template_decl && complete_type (type) == error_mark_node)
11117 0 : goto error_out;
11118 15482 : else if (processing_template_decl && !COMPLETE_TYPE_P (type))
11119 2 : pedwarn (loc, 0, "structured binding refers to incomplete class type %qT",
11120 : type);
11121 : else
11122 : {
11123 15480 : tree btype = find_decomp_class_base (loc, type, NULL_TREE,
11124 : tf_warning_or_error);
11125 15480 : if (btype == error_mark_node)
11126 21 : goto error_out;
11127 15459 : else if (btype == NULL_TREE)
11128 : {
11129 23 : if (pack == 0 && count == 1)
11130 : {
11131 16 : eltscnt = 0;
11132 16 : packv = make_tree_vec (2);
11133 16 : goto done;
11134 : }
11135 7 : error_at (loc, "cannot decompose class type %qT without non-static "
11136 : "data members", type);
11137 7 : goto error_out;
11138 : }
11139 145837 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
11140 229144 : if (TREE_CODE (field) != FIELD_DECL
11141 31674 : || DECL_ARTIFICIAL (field)
11142 162071 : || DECL_UNNAMED_BIT_FIELD (field))
11143 98743 : continue;
11144 : else
11145 31658 : eltscnt++;
11146 15436 : if (pack != -1 ? count - 1 > eltscnt : count != eltscnt)
11147 15 : goto cnt_mismatch;
11148 15421 : tree t = dexp;
11149 15421 : if (type != btype)
11150 : {
11151 18 : t = convert_to_base (t, btype, /*check_access*/true,
11152 : /*nonnull*/false, tf_warning_or_error);
11153 18 : type = btype;
11154 : }
11155 15421 : unsigned HOST_WIDE_INT j = 0;
11156 15421 : unsigned int i = 0;
11157 145626 : for (tree field = TYPE_FIELDS (btype); field; field = TREE_CHAIN (field))
11158 228789 : if (TREE_CODE (field) != FIELD_DECL
11159 31637 : || DECL_ARTIFICIAL (field)
11160 161838 : || DECL_UNNAMED_BIT_FIELD (field))
11161 98584 : continue;
11162 : else
11163 : {
11164 31621 : tree tt = finish_non_static_data_member (field, unshare_expr (t),
11165 : NULL_TREE);
11166 31621 : if (REFERENCE_REF_P (tt))
11167 30 : tt = TREE_OPERAND (tt, 0);
11168 31621 : if (pack != -1 && j >= (unsigned) pack)
11169 : {
11170 677 : if (j == (unsigned) pack)
11171 : {
11172 225 : packv = make_tree_vec (eltscnt - count + 3);
11173 225 : i++;
11174 : }
11175 677 : if (j < (unsigned) pack + eltscnt - (count - 1))
11176 : {
11177 496 : tree t;
11178 496 : TREE_VEC_ELT (packv, j + 3 - i) = t = copy_node (v[pack]);
11179 496 : set_sb_pack_name (t, j + 1 - i);
11180 496 : maybe_push_decl (t);
11181 496 : TREE_TYPE (t) = TREE_TYPE (tt);
11182 496 : layout_decl (t, 0);
11183 496 : if (!processing_template_decl)
11184 : {
11185 375 : SET_DECL_VALUE_EXPR (t, tt);
11186 375 : DECL_HAS_VALUE_EXPR_P (t) = 1;
11187 : }
11188 : else
11189 121 : DECL_HAS_VALUE_EXPR_P (t) = 0;
11190 496 : j++;
11191 496 : continue;
11192 496 : }
11193 : }
11194 31125 : TREE_TYPE (v[i]) = TREE_TYPE (tt);
11195 31125 : layout_decl (v[i], 0);
11196 31125 : if (!processing_template_decl)
11197 : {
11198 12709 : SET_DECL_VALUE_EXPR (v[i], tt);
11199 12709 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11200 : }
11201 31125 : i++;
11202 31125 : j++;
11203 : }
11204 15421 : if (pack != -1 && j == (unsigned) pack)
11205 : {
11206 20 : gcc_checking_assert (eltscnt == count - 1);
11207 20 : packv = make_tree_vec (2);
11208 : }
11209 : }
11210 61597 : done:
11211 61597 : if (packv)
11212 : {
11213 3645 : gcc_checking_assert (pack != -1);
11214 3645 : TREE_VEC_ELT (packv, 0) = decl;
11215 3645 : TREE_VEC_ELT (packv, 1) = size_int (pack);
11216 3645 : SET_DECL_VALUE_EXPR (v[pack], packv);
11217 3645 : DECL_HAS_VALUE_EXPR_P (v[pack]) = 1;
11218 3645 : DECL_IGNORED_P (v[pack]) = 1;
11219 3645 : if (!processing_template_decl)
11220 17540 : for (unsigned int i = 0; i < TREE_VEC_LENGTH (packv) - 2U; ++i)
11221 14160 : pushdecl (TREE_VEC_ELT (packv, 2 + i));
11222 : }
11223 61597 : if (processing_template_decl)
11224 : {
11225 56503 : for (unsigned int i = 0; i < count; i++)
11226 37729 : if (!DECL_HAS_VALUE_EXPR_P (v[i]))
11227 : {
11228 37317 : tree a = build_nt (ARRAY_REF, decl, size_int (i),
11229 : NULL_TREE, NULL_TREE);
11230 37317 : SET_DECL_VALUE_EXPR (v[i], a);
11231 37317 : DECL_HAS_VALUE_EXPR_P (v[i]) = 1;
11232 : }
11233 : }
11234 42823 : else if (DECL_NAMESPACE_SCOPE_P (decl) && !seen_error ())
11235 : {
11236 367 : tree attr = NULL_TREE, *pa = &attr;
11237 1281 : for (unsigned int i = 0; i < count; i++)
11238 914 : if ((unsigned) pack != i
11239 914 : && DECL_HAS_VALUE_EXPR_P (v[i])
11240 1488 : && !DECL_IGNORED_P (v[i]))
11241 : {
11242 574 : (*debug_hooks->early_global_decl) (v[i]);
11243 574 : *pa = build_tree_list (NULL_TREE, v[i]);
11244 574 : pa = &TREE_CHAIN (*pa);
11245 : }
11246 367 : if (attr)
11247 252 : DECL_ATTRIBUTES (decl)
11248 504 : = tree_cons (get_identifier ("structured bindings"),
11249 252 : attr, DECL_ATTRIBUTES (decl));
11250 : }
11251 : return false;
11252 : }
11253 :
11254 : /* Returns a declaration for a VAR_DECL as if:
11255 :
11256 : extern "C" TYPE NAME;
11257 :
11258 : had been seen. Used to create compiler-generated global
11259 : variables. */
11260 :
11261 : static tree
11262 2190 : declare_global_var (tree name, tree type)
11263 : {
11264 2190 : auto cookie = push_abi_namespace (global_namespace);
11265 2190 : tree decl = build_decl (input_location, VAR_DECL, name, type);
11266 2190 : TREE_PUBLIC (decl) = 1;
11267 2190 : DECL_EXTERNAL (decl) = 1;
11268 2190 : DECL_ARTIFICIAL (decl) = 1;
11269 2190 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
11270 : /* If the user has explicitly declared this variable (perhaps
11271 : because the code we are compiling is part of a low-level runtime
11272 : library), then it is possible that our declaration will be merged
11273 : with theirs by pushdecl. */
11274 2190 : decl = pushdecl (decl);
11275 2190 : cp_finish_decl (decl, NULL_TREE, false, NULL_TREE, 0);
11276 2190 : pop_abi_namespace (cookie, global_namespace);
11277 :
11278 2190 : return decl;
11279 : }
11280 :
11281 : /* Returns the type for the argument to "atexit" corresponding to the function
11282 : to be called when the program exits. */
11283 :
11284 : static tree
11285 24 : get_atexit_fn_ptr_type ()
11286 : {
11287 24 : if (!atexit_fn_ptr_type_node)
11288 : {
11289 12 : tree fn_type = build_function_type_list (void_type_node, NULL_TREE);
11290 12 : atexit_fn_ptr_type_node = build_pointer_type (fn_type);
11291 : }
11292 :
11293 24 : return atexit_fn_ptr_type_node;
11294 : }
11295 :
11296 : /* Returns the type for the argument to "__cxa_atexit", "__cxa_thread_atexit"
11297 : or "__cxa_throw" corresponding to the destructor to be called when the
11298 : program exits. */
11299 :
11300 : tree
11301 18366 : get_cxa_atexit_fn_ptr_type ()
11302 : {
11303 18366 : if (!cleanup_type)
11304 : {
11305 13821 : tree fntype = build_function_type_list (void_type_node,
11306 : ptr_type_node, NULL_TREE);
11307 13821 : fntype = targetm.cxx.adjust_cdtor_callabi_fntype (fntype);
11308 13821 : cleanup_type = build_pointer_type (fntype);
11309 : }
11310 :
11311 18366 : return cleanup_type;
11312 : }
11313 :
11314 : /* Returns a pointer to the `atexit' function. Note that if
11315 : FLAG_USE_CXA_ATEXIT is nonzero, then this will actually be the new
11316 : `__cxa_atexit' function specified in the IA64 C++ ABI. */
11317 :
11318 : static tree
11319 3339 : get_atexit_node (void)
11320 : {
11321 3339 : tree atexit_fndecl;
11322 3339 : tree fn_type;
11323 3339 : tree fn_ptr_type;
11324 3339 : const char *name;
11325 3339 : bool use_aeabi_atexit;
11326 3339 : tree ctx = global_namespace;
11327 :
11328 3339 : if (atexit_node)
11329 : return atexit_node;
11330 :
11331 2153 : if (flag_use_cxa_atexit && !targetm.cxx.use_atexit_for_cxa_atexit ())
11332 : {
11333 : /* The declaration for `__cxa_atexit' is:
11334 :
11335 : int __cxa_atexit (void (*)(void *), void *, void *)
11336 :
11337 : We build up the argument types and then the function type
11338 : itself. */
11339 2141 : tree argtype0, argtype1, argtype2;
11340 :
11341 2141 : use_aeabi_atexit = targetm.cxx.use_aeabi_atexit ();
11342 : /* First, build the pointer-to-function type for the first
11343 : argument. */
11344 2141 : fn_ptr_type = get_cxa_atexit_fn_ptr_type ();
11345 : /* Then, build the rest of the argument types. */
11346 2141 : argtype2 = ptr_type_node;
11347 2141 : if (use_aeabi_atexit)
11348 : {
11349 : argtype1 = fn_ptr_type;
11350 : argtype0 = ptr_type_node;
11351 : }
11352 : else
11353 : {
11354 2141 : argtype1 = ptr_type_node;
11355 2141 : argtype0 = fn_ptr_type;
11356 : }
11357 : /* And the final __cxa_atexit type. */
11358 2141 : fn_type = build_function_type_list (integer_type_node,
11359 : argtype0, argtype1, argtype2,
11360 : NULL_TREE);
11361 : /* ... which needs noexcept. */
11362 2141 : fn_type = build_exception_variant (fn_type, noexcept_true_spec);
11363 2141 : if (use_aeabi_atexit)
11364 : {
11365 0 : name = "__aeabi_atexit";
11366 0 : push_to_top_level ();
11367 0 : int n = push_namespace (get_identifier ("__aeabiv1"), false);
11368 0 : ctx = current_namespace;
11369 0 : while (n--)
11370 0 : pop_namespace ();
11371 0 : pop_from_top_level ();
11372 : }
11373 : else
11374 : {
11375 2141 : name = "__cxa_atexit";
11376 2141 : ctx = abi_node;
11377 : }
11378 : }
11379 : else
11380 : {
11381 : /* The declaration for `atexit' is:
11382 :
11383 : int atexit (void (*)());
11384 :
11385 : We build up the argument types and then the function type
11386 : itself. */
11387 12 : fn_ptr_type = get_atexit_fn_ptr_type ();
11388 : /* Build the final atexit type. */
11389 12 : fn_type = build_function_type_list (integer_type_node,
11390 : fn_ptr_type, NULL_TREE);
11391 : /* ... which needs noexcept. */
11392 12 : fn_type = build_exception_variant (fn_type, noexcept_true_spec);
11393 12 : name = "atexit";
11394 : }
11395 :
11396 : /* Now, build the function declaration. */
11397 2153 : push_lang_context (lang_name_c);
11398 2153 : auto cookie = push_abi_namespace (ctx);
11399 2153 : atexit_fndecl = build_library_fn_ptr (name, fn_type, ECF_LEAF | ECF_NOTHROW);
11400 2153 : DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
11401 : /* Install as hidden builtin so we're (a) more relaxed about
11402 : exception spec matching and (b) will not give a confusing location
11403 : in diagnostic and (c) won't magically appear in user-visible name
11404 : lookups. */
11405 2153 : DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
11406 2153 : atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
11407 2153 : pop_abi_namespace (cookie, ctx);
11408 2153 : mark_used (atexit_fndecl);
11409 2153 : pop_lang_context ();
11410 2153 : atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
11411 :
11412 2153 : return atexit_node;
11413 : }
11414 :
11415 : /* Like get_atexit_node, but for thread-local cleanups. */
11416 :
11417 : static tree
11418 98 : get_thread_atexit_node (void)
11419 : {
11420 98 : if (thread_atexit_node)
11421 : return thread_atexit_node;
11422 :
11423 : /* The declaration for `__cxa_thread_atexit' is:
11424 :
11425 : int __cxa_thread_atexit (void (*)(void *), void *, void *) */
11426 59 : tree fn_type = build_function_type_list (integer_type_node,
11427 : get_cxa_atexit_fn_ptr_type (),
11428 : ptr_type_node, ptr_type_node,
11429 : NULL_TREE);
11430 :
11431 : /* Now, build the function declaration, as with __cxa_atexit. */
11432 59 : unsigned flags = push_abi_namespace ();
11433 59 : tree atexit_fndecl = build_library_fn_ptr ("__cxa_thread_atexit", fn_type,
11434 : ECF_LEAF | ECF_NOTHROW);
11435 59 : DECL_CONTEXT (atexit_fndecl) = FROB_CONTEXT (current_namespace);
11436 59 : DECL_SOURCE_LOCATION (atexit_fndecl) = BUILTINS_LOCATION;
11437 59 : atexit_fndecl = pushdecl (atexit_fndecl, /*hiding=*/true);
11438 59 : pop_abi_namespace (flags);
11439 59 : mark_used (atexit_fndecl);
11440 59 : thread_atexit_node = decay_conversion (atexit_fndecl, tf_warning_or_error);
11441 :
11442 59 : return thread_atexit_node;
11443 : }
11444 :
11445 : /* Returns the __dso_handle VAR_DECL. */
11446 :
11447 : static tree
11448 3425 : get_dso_handle_node (void)
11449 : {
11450 3425 : if (dso_handle_node)
11451 : return dso_handle_node;
11452 :
11453 : /* Declare the variable. */
11454 2190 : dso_handle_node = declare_global_var (get_identifier ("__dso_handle"),
11455 : ptr_type_node);
11456 :
11457 : #ifdef HAVE_GAS_HIDDEN
11458 2190 : if (dso_handle_node != error_mark_node)
11459 : {
11460 2187 : DECL_VISIBILITY (dso_handle_node) = VISIBILITY_HIDDEN;
11461 2187 : DECL_VISIBILITY_SPECIFIED (dso_handle_node) = 1;
11462 : }
11463 : #endif
11464 :
11465 2190 : return dso_handle_node;
11466 : }
11467 :
11468 : /* Begin a new function with internal linkage whose job will be simply
11469 : to destroy some particular DECL. OB_PARM is true if object pointer
11470 : is passed to the cleanup function, otherwise no argument is passed. */
11471 :
11472 : static tree
11473 370 : start_cleanup_fn (tree decl, bool ob_parm, bool omp_target)
11474 : {
11475 370 : push_to_top_level ();
11476 :
11477 : /* No need to mangle this. */
11478 370 : push_lang_context (lang_name_c);
11479 :
11480 : /* Build the name of the function. */
11481 370 : gcc_checking_assert (HAS_DECL_ASSEMBLER_NAME_P (decl));
11482 370 : const char *dname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
11483 370 : dname = targetm.strip_name_encoding (dname);
11484 737 : char *name = ACONCAT ((omp_target ? "__omp_tcf" : "__tcf", dname, NULL));
11485 :
11486 370 : tree fntype = TREE_TYPE (ob_parm ? get_cxa_atexit_fn_ptr_type ()
11487 : : get_atexit_fn_ptr_type ());
11488 : /* Build the function declaration. */
11489 370 : tree fndecl = build_lang_decl (FUNCTION_DECL, get_identifier (name), fntype);
11490 370 : DECL_CONTEXT (fndecl) = FROB_CONTEXT (current_namespace);
11491 : /* It's a function with internal linkage, generated by the
11492 : compiler. */
11493 370 : TREE_PUBLIC (fndecl) = 0;
11494 370 : DECL_ARTIFICIAL (fndecl) = 1;
11495 : /* Make the function `inline' so that it is only emitted if it is
11496 : actually needed. It is unlikely that it will be inlined, since
11497 : it is only called via a function pointer, but we avoid unnecessary
11498 : emissions this way. */
11499 370 : DECL_DECLARED_INLINE_P (fndecl) = 1;
11500 370 : DECL_INTERFACE_KNOWN (fndecl) = 1;
11501 370 : if (ob_parm)
11502 : {
11503 : /* Build the parameter. */
11504 358 : tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node);
11505 358 : TREE_USED (parmdecl) = 1;
11506 358 : DECL_READ_P (parmdecl) = 1;
11507 358 : DECL_ARGUMENTS (fndecl) = parmdecl;
11508 : }
11509 :
11510 370 : fndecl = pushdecl (fndecl, /*hidden=*/true);
11511 370 : if (omp_target)
11512 : {
11513 3 : DECL_ATTRIBUTES (fndecl)
11514 3 : = tree_cons (get_identifier ("omp declare target"), NULL_TREE,
11515 3 : DECL_ATTRIBUTES (fndecl));
11516 3 : DECL_ATTRIBUTES (fndecl)
11517 6 : = tree_cons (get_identifier ("omp declare target nohost"), NULL_TREE,
11518 3 : DECL_ATTRIBUTES (fndecl));
11519 : }
11520 370 : start_preparsed_function (fndecl, NULL_TREE, SF_PRE_PARSED);
11521 :
11522 370 : pop_lang_context ();
11523 :
11524 370 : return current_function_decl;
11525 : }
11526 :
11527 : /* Finish the cleanup function begun by start_cleanup_fn. */
11528 :
11529 : static void
11530 370 : end_cleanup_fn (void)
11531 : {
11532 370 : expand_or_defer_fn (finish_function (/*inline_p=*/false));
11533 :
11534 370 : pop_from_top_level ();
11535 370 : }
11536 :
11537 : /* Generate code to handle the destruction of DECL, an object with
11538 : static storage duration. */
11539 :
11540 : tree
11541 14980 : register_dtor_fn (tree decl, bool omp_target)
11542 : {
11543 14980 : tree cleanup;
11544 14980 : tree addr;
11545 14980 : tree compound_stmt;
11546 14980 : tree fcall;
11547 14980 : tree type;
11548 14980 : bool ob_parm, dso_parm, use_dtor;
11549 14980 : tree arg0, arg1, arg2;
11550 14980 : tree atex_node;
11551 :
11552 14980 : type = TREE_TYPE (decl);
11553 14980 : if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
11554 11543 : return void_node;
11555 :
11556 3437 : if (decl_maybe_constant_destruction (decl, type)
11557 3437 : && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
11558 : {
11559 0 : cxx_maybe_build_cleanup (decl, tf_warning_or_error);
11560 0 : return void_node;
11561 : }
11562 :
11563 : /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
11564 : "__aeabi_atexit"), and DECL is a class object, we can just pass the
11565 : destructor to "__cxa_atexit"; we don't have to build a temporary
11566 : function to do the cleanup. */
11567 6874 : dso_parm = (flag_use_cxa_atexit
11568 3437 : && !targetm.cxx.use_atexit_for_cxa_atexit ());
11569 3437 : ob_parm = (CP_DECL_THREAD_LOCAL_P (decl) || dso_parm);
11570 3425 : use_dtor = ob_parm && CLASS_TYPE_P (type);
11571 3437 : if (use_dtor)
11572 : {
11573 3067 : cleanup = get_class_binding (type, complete_dtor_identifier);
11574 :
11575 : /* Make sure it is accessible. */
11576 3067 : perform_or_defer_access_check (TYPE_BINFO (type), cleanup, cleanup,
11577 : tf_warning_or_error);
11578 : }
11579 : else
11580 : {
11581 : /* Call build_cleanup before we enter the anonymous function so
11582 : that any access checks will be done relative to the current
11583 : scope, rather than the scope of the anonymous function. */
11584 370 : build_cleanup (decl);
11585 :
11586 : /* Now start the function. */
11587 370 : cleanup = start_cleanup_fn (decl, ob_parm, omp_target);
11588 :
11589 : /* Now, recompute the cleanup. It may contain SAVE_EXPRs that refer
11590 : to the original function, rather than the anonymous one. That
11591 : will make the back end think that nested functions are in use,
11592 : which causes confusion. */
11593 370 : push_deferring_access_checks (dk_no_check);
11594 370 : fcall = build_cleanup (decl);
11595 370 : pop_deferring_access_checks ();
11596 :
11597 : /* Create the body of the anonymous function. */
11598 370 : compound_stmt = begin_compound_stmt (BCS_FN_BODY);
11599 370 : finish_expr_stmt (fcall);
11600 370 : finish_compound_stmt (compound_stmt);
11601 370 : end_cleanup_fn ();
11602 : }
11603 :
11604 : /* Call atexit with the cleanup function. */
11605 3437 : mark_used (cleanup);
11606 3437 : cleanup = build_address (cleanup);
11607 :
11608 3437 : if (CP_DECL_THREAD_LOCAL_P (decl))
11609 98 : atex_node = get_thread_atexit_node ();
11610 : else
11611 3339 : atex_node = get_atexit_node ();
11612 :
11613 3437 : if (use_dtor)
11614 : {
11615 : /* We must convert CLEANUP to the type that "__cxa_atexit"
11616 : expects. */
11617 3067 : cleanup = build_nop (get_cxa_atexit_fn_ptr_type (), cleanup);
11618 : /* "__cxa_atexit" will pass the address of DECL to the
11619 : cleanup function. */
11620 3067 : mark_used (decl);
11621 3067 : addr = build_address (decl);
11622 : /* The declared type of the parameter to "__cxa_atexit" is
11623 : "void *". For plain "T*", we could just let the
11624 : machinery in cp_build_function_call convert it -- but if the
11625 : type is "cv-qualified T *", then we need to convert it
11626 : before passing it in, to avoid spurious errors. */
11627 3067 : addr = build_nop (ptr_type_node, addr);
11628 : }
11629 : else
11630 : /* Since the cleanup functions we build ignore the address
11631 : they're given, there's no reason to pass the actual address
11632 : in, and, in general, it's cheaper to pass NULL than any
11633 : other value. */
11634 370 : addr = null_pointer_node;
11635 :
11636 3437 : if (dso_parm)
11637 3425 : arg2 = cp_build_addr_expr (get_dso_handle_node (),
11638 : tf_warning_or_error);
11639 12 : else if (ob_parm)
11640 : /* Just pass NULL to the dso handle parm if we don't actually
11641 : have a DSO handle on this target. */
11642 0 : arg2 = null_pointer_node;
11643 : else
11644 : arg2 = NULL_TREE;
11645 :
11646 3425 : if (ob_parm)
11647 : {
11648 3425 : if (!CP_DECL_THREAD_LOCAL_P (decl)
11649 3425 : && targetm.cxx.use_aeabi_atexit ())
11650 : {
11651 : arg1 = cleanup;
11652 : arg0 = addr;
11653 : }
11654 : else
11655 : {
11656 : arg1 = addr;
11657 : arg0 = cleanup;
11658 : }
11659 : }
11660 : else
11661 : {
11662 : arg0 = cleanup;
11663 : arg1 = NULL_TREE;
11664 : }
11665 3437 : return cp_build_function_call_nary (atex_node, tf_warning_or_error,
11666 3437 : arg0, arg1, arg2, NULL_TREE);
11667 : }
11668 :
11669 : /* DECL is a VAR_DECL with static storage duration. INIT, if present,
11670 : is its initializer. Generate code to handle the construction
11671 : and destruction of DECL. */
11672 :
11673 : static void
11674 27972671 : expand_static_init (tree decl, tree init)
11675 : {
11676 27972671 : gcc_assert (VAR_P (decl));
11677 27972671 : gcc_assert (TREE_STATIC (decl));
11678 :
11679 : /* Some variables require no dynamic initialization. */
11680 27972671 : if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
11681 : {
11682 : /* Make sure the destructor is callable. */
11683 27969260 : cxx_maybe_build_cleanup (decl, tf_warning_or_error);
11684 27969260 : if (!init)
11685 : return;
11686 : }
11687 :
11688 15849 : if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
11689 14926 : && !DECL_FUNCTION_SCOPE_P (decl))
11690 : {
11691 15 : auto_diagnostic_group d;
11692 15 : location_t dloc = DECL_SOURCE_LOCATION (decl);
11693 15 : if (init)
11694 12 : error_at (dloc, "non-local variable %qD declared %<__thread%> "
11695 : "needs dynamic initialization", decl);
11696 : else
11697 3 : error_at (dloc, "non-local variable %qD declared %<__thread%> "
11698 : "has a non-trivial destructor", decl);
11699 15 : static bool informed;
11700 15 : if (!informed)
11701 : {
11702 6 : inform (dloc, "C++11 %<thread_local%> allows dynamic "
11703 : "initialization and destruction");
11704 6 : informed = true;
11705 : }
11706 15 : return;
11707 15 : }
11708 :
11709 14882 : if (DECL_FUNCTION_SCOPE_P (decl))
11710 : {
11711 : /* Emit code to perform this initialization but once. */
11712 3850 : tree if_stmt = NULL_TREE, inner_if_stmt = NULL_TREE;
11713 3850 : tree then_clause = NULL_TREE, inner_then_clause = NULL_TREE;
11714 3850 : tree guard, guard_addr;
11715 3850 : tree flag, begin;
11716 : /* We don't need thread-safety code for thread-local vars. */
11717 3850 : bool thread_guard = (flag_threadsafe_statics
11718 3850 : && !CP_DECL_THREAD_LOCAL_P (decl));
11719 :
11720 : /* Emit code to perform this initialization but once. This code
11721 : looks like:
11722 :
11723 : static <type> guard;
11724 : if (!__atomic_load (guard.first_byte)) {
11725 : if (__cxa_guard_acquire (&guard)) {
11726 : bool flag = false;
11727 : try {
11728 : // Do initialization.
11729 : flag = true; __cxa_guard_release (&guard);
11730 : // Register variable for destruction at end of program.
11731 : } catch {
11732 : if (!flag) __cxa_guard_abort (&guard);
11733 : }
11734 : }
11735 : }
11736 :
11737 : Note that the `flag' variable is only set to 1 *after* the
11738 : initialization is complete. This ensures that an exception,
11739 : thrown during the construction, will cause the variable to
11740 : reinitialized when we pass through this code again, as per:
11741 :
11742 : [stmt.dcl]
11743 :
11744 : If the initialization exits by throwing an exception, the
11745 : initialization is not complete, so it will be tried again
11746 : the next time control enters the declaration.
11747 :
11748 : This process should be thread-safe, too; multiple threads
11749 : should not be able to initialize the variable more than
11750 : once. */
11751 :
11752 : /* Create the guard variable. */
11753 3850 : guard = get_guard (decl);
11754 :
11755 : /* Begin the conditional initialization. */
11756 3850 : if_stmt = begin_if_stmt ();
11757 :
11758 3850 : finish_if_stmt_cond (get_guard_cond (guard, thread_guard), if_stmt);
11759 3850 : then_clause = begin_compound_stmt (BCS_NO_SCOPE);
11760 :
11761 3850 : if (thread_guard)
11762 : {
11763 3705 : tree vfntype = NULL_TREE;
11764 3705 : tree acquire_name, release_name, abort_name;
11765 3705 : tree acquire_fn, release_fn, abort_fn;
11766 3705 : guard_addr = build_address (guard);
11767 :
11768 3705 : acquire_name = get_identifier ("__cxa_guard_acquire");
11769 3705 : release_name = get_identifier ("__cxa_guard_release");
11770 3705 : abort_name = get_identifier ("__cxa_guard_abort");
11771 3705 : acquire_fn = get_global_binding (acquire_name);
11772 3705 : release_fn = get_global_binding (release_name);
11773 3705 : abort_fn = get_global_binding (abort_name);
11774 3705 : if (!acquire_fn)
11775 2102 : acquire_fn = push_library_fn
11776 2102 : (acquire_name, build_function_type_list (integer_type_node,
11777 2102 : TREE_TYPE (guard_addr),
11778 : NULL_TREE),
11779 : NULL_TREE, ECF_NOTHROW);
11780 3705 : if (!release_fn || !abort_fn)
11781 2105 : vfntype = build_function_type_list (void_type_node,
11782 2105 : TREE_TYPE (guard_addr),
11783 : NULL_TREE);
11784 2105 : if (!release_fn)
11785 2105 : release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
11786 : ECF_NOTHROW);
11787 3705 : if (!abort_fn)
11788 2105 : abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
11789 : ECF_NOTHROW | ECF_LEAF);
11790 :
11791 3705 : inner_if_stmt = begin_if_stmt ();
11792 3705 : finish_if_stmt_cond (build_call_n (acquire_fn, 1, guard_addr),
11793 : inner_if_stmt);
11794 :
11795 3705 : inner_then_clause = begin_compound_stmt (BCS_NO_SCOPE);
11796 3705 : begin = get_internal_target_expr (boolean_false_node);
11797 3705 : flag = TARGET_EXPR_SLOT (begin);
11798 :
11799 3705 : TARGET_EXPR_CLEANUP (begin)
11800 3705 : = build3 (COND_EXPR, void_type_node, flag,
11801 : void_node,
11802 : build_call_n (abort_fn, 1, guard_addr));
11803 3705 : CLEANUP_EH_ONLY (begin) = 1;
11804 :
11805 : /* Do the initialization itself. */
11806 3705 : init = add_stmt_to_compound (begin, init);
11807 3705 : init = add_stmt_to_compound (init,
11808 : build2 (MODIFY_EXPR, void_type_node,
11809 : flag, boolean_true_node));
11810 :
11811 : /* Use atexit to register a function for destroying this static
11812 : variable. Do this before calling __cxa_guard_release. */
11813 3705 : init = add_stmt_to_compound (init, register_dtor_fn (decl));
11814 :
11815 3705 : init = add_stmt_to_compound (init, build_call_n (release_fn, 1,
11816 : guard_addr));
11817 : }
11818 : else
11819 : {
11820 145 : init = add_stmt_to_compound (init, set_guard (guard));
11821 :
11822 : /* Use atexit to register a function for destroying this static
11823 : variable. */
11824 145 : init = add_stmt_to_compound (init, register_dtor_fn (decl));
11825 : }
11826 :
11827 3850 : finish_expr_stmt (init);
11828 :
11829 3850 : if (thread_guard)
11830 : {
11831 3705 : finish_compound_stmt (inner_then_clause);
11832 3705 : finish_then_clause (inner_if_stmt);
11833 3705 : finish_if_stmt (inner_if_stmt);
11834 : }
11835 :
11836 3850 : finish_compound_stmt (then_clause);
11837 3850 : finish_then_clause (if_stmt);
11838 3850 : finish_if_stmt (if_stmt);
11839 : }
11840 11032 : else if (CP_DECL_THREAD_LOCAL_P (decl))
11841 795 : tls_aggregates = tree_cons (init, decl, tls_aggregates);
11842 : else
11843 10237 : static_aggregates = tree_cons (init, decl, static_aggregates);
11844 : }
11845 :
11846 :
11847 : /* Make TYPE a complete type based on INITIAL_VALUE.
11848 : Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
11849 : 2 if there was no information (in which case assume 0 if DO_DEFAULT),
11850 : 3 if the initializer list is empty (in pedantic mode). */
11851 :
11852 : int
11853 599119 : cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
11854 : {
11855 599119 : int failure;
11856 599119 : tree type, elt_type;
11857 :
11858 : /* Don't get confused by a CONSTRUCTOR for some other type. */
11859 599089 : if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
11860 142126 : && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
11861 599449 : && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
11862 : return 1;
11863 :
11864 599116 : if (initial_value)
11865 : {
11866 : /* An array of character type can be initialized from a
11867 : brace-enclosed string constant so call reshape_init to
11868 : remove the optional braces from a braced string literal. */
11869 599086 : if (char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (*ptype)))
11870 599086 : && BRACE_ENCLOSED_INITIALIZER_P (initial_value))
11871 48622 : initial_value = reshape_init (*ptype, initial_value,
11872 : tf_warning_or_error);
11873 :
11874 : /* If any of the elements are parameter packs, we can't actually
11875 : complete this type now because the array size is dependent. */
11876 599086 : if (TREE_CODE (initial_value) == CONSTRUCTOR)
11877 46808238 : for (auto &e: CONSTRUCTOR_ELTS (initial_value))
11878 46382276 : if (PACK_EXPANSION_P (e.value))
11879 : return 0;
11880 : }
11881 :
11882 599116 : failure = complete_array_type (ptype, initial_value, do_default);
11883 :
11884 : /* We can create the array before the element type is complete, which
11885 : means that we didn't have these two bits set in the original type
11886 : either. In completing the type, we are expected to propagate these
11887 : bits. See also complete_type which does the same thing for arrays
11888 : of fixed size. */
11889 599116 : type = *ptype;
11890 1198229 : if (type != error_mark_node && TYPE_DOMAIN (type))
11891 : {
11892 599089 : elt_type = TREE_TYPE (type);
11893 599089 : TYPE_NEEDS_CONSTRUCTING (type) = TYPE_NEEDS_CONSTRUCTING (elt_type);
11894 1198178 : TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
11895 599089 : = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (elt_type);
11896 : }
11897 :
11898 : return failure;
11899 : }
11900 :
11901 : /* As above, but either give an error or reject zero-size arrays, depending
11902 : on COMPLAIN. */
11903 :
11904 : int
11905 1197 : cp_complete_array_type_or_error (tree *ptype, tree initial_value,
11906 : bool do_default, tsubst_flags_t complain)
11907 : {
11908 1197 : int failure;
11909 1197 : bool sfinae = !(complain & tf_error);
11910 : /* In SFINAE context we can't be lenient about zero-size arrays. */
11911 1197 : if (sfinae)
11912 3 : ++pedantic;
11913 1197 : failure = cp_complete_array_type (ptype, initial_value, do_default);
11914 1197 : if (sfinae)
11915 3 : --pedantic;
11916 1197 : if (failure)
11917 : {
11918 3 : if (sfinae)
11919 : /* Not an error. */;
11920 0 : else if (failure == 1)
11921 0 : error ("initializer fails to determine size of %qT", *ptype);
11922 0 : else if (failure == 2)
11923 : {
11924 0 : if (do_default)
11925 0 : error ("array size missing in %qT", *ptype);
11926 : }
11927 0 : else if (failure == 3)
11928 0 : error ("zero-size array %qT", *ptype);
11929 3 : *ptype = error_mark_node;
11930 : }
11931 1197 : return failure;
11932 : }
11933 :
11934 : /* Return zero if something is declared to be a member of type
11935 : CTYPE when in the context of CUR_TYPE. STRING is the error
11936 : message to print in that case. Otherwise, quietly return 1. */
11937 :
11938 : static int
11939 25984537 : member_function_or_else (tree ctype, tree cur_type, enum overload_flags flags)
11940 : {
11941 25984537 : if (ctype && ctype != cur_type)
11942 : {
11943 0 : if (flags == DTOR_FLAG)
11944 0 : error ("destructor for alien class %qT cannot be a member", ctype);
11945 : else
11946 0 : error ("constructor for alien class %qT cannot be a member", ctype);
11947 0 : return 0;
11948 : }
11949 : return 1;
11950 : }
11951 :
11952 : /* Subroutine of `grokdeclarator'. */
11953 :
11954 : /* Generate errors possibly applicable for a given set of specifiers.
11955 : This is for ARM $7.1.2. */
11956 :
11957 : static void
11958 434859588 : bad_specifiers (tree object,
11959 : enum bad_spec_place type,
11960 : int virtualp,
11961 : int quals,
11962 : int inlinep,
11963 : int friendp,
11964 : int raises,
11965 : const location_t* locations)
11966 : {
11967 434859588 : switch (type)
11968 : {
11969 67078516 : case BSP_VAR:
11970 67078516 : if (virtualp)
11971 0 : error_at (locations[ds_virtual],
11972 : "%qD declared as a %<virtual%> variable", object);
11973 67078516 : if (quals)
11974 3 : error ("%<const%> and %<volatile%> function specifiers on "
11975 : "%qD invalid in variable declaration", object);
11976 : break;
11977 289055689 : case BSP_PARM:
11978 289055689 : if (virtualp)
11979 0 : error_at (locations[ds_virtual],
11980 : "%qD declared as a %<virtual%> parameter", object);
11981 289055689 : if (inlinep)
11982 6 : error_at (locations[ds_inline],
11983 : "%qD declared as an %<inline%> parameter", object);
11984 289055689 : if (quals)
11985 3 : error ("%<const%> and %<volatile%> function specifiers on "
11986 : "%qD invalid in parameter declaration", object);
11987 : break;
11988 46436594 : case BSP_TYPE:
11989 46436594 : if (virtualp)
11990 0 : error_at (locations[ds_virtual],
11991 : "%qD declared as a %<virtual%> type", object);
11992 46436594 : if (inlinep)
11993 6 : error_at (locations[ds_inline],
11994 : "%qD declared as an %<inline%> type", object);
11995 46436594 : if (quals)
11996 0 : error ("%<const%> and %<volatile%> function specifiers on "
11997 : "%qD invalid in type declaration", object);
11998 : break;
11999 32288789 : case BSP_FIELD:
12000 32288789 : if (virtualp)
12001 6 : error_at (locations[ds_virtual],
12002 : "%qD declared as a %<virtual%> field", object);
12003 32288789 : if (inlinep)
12004 6 : error_at (locations[ds_inline],
12005 : "%qD declared as an %<inline%> field", object);
12006 32288789 : if (quals)
12007 0 : error ("%<const%> and %<volatile%> function specifiers on "
12008 : "%qD invalid in field declaration", object);
12009 : break;
12010 0 : default:
12011 0 : gcc_unreachable();
12012 : }
12013 434859588 : if (friendp)
12014 0 : error ("%q+D declared as a friend", object);
12015 434859588 : if (raises
12016 113 : && !flag_noexcept_type
12017 434859609 : && (TREE_CODE (object) == TYPE_DECL
12018 15 : || (!TYPE_PTRFN_P (TREE_TYPE (object))
12019 5 : && !TYPE_REFFN_P (TREE_TYPE (object))
12020 4 : && !TYPE_PTRMEMFUNC_P (TREE_TYPE (object)))))
12021 6 : error ("%q+D declared with an exception specification", object);
12022 434859588 : }
12023 :
12024 : /* DECL is a member function or static data member and is presently
12025 : being defined. Check that the definition is taking place in a
12026 : valid namespace. */
12027 :
12028 : static void
12029 95500271 : check_class_member_definition_namespace (tree decl)
12030 : {
12031 : /* These checks only apply to member functions and static data
12032 : members. */
12033 95500271 : gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
12034 : /* We check for problems with specializations in pt.cc in
12035 : check_specialization_namespace, where we can issue better
12036 : diagnostics. */
12037 95500271 : if (processing_specialization)
12038 : return;
12039 : /* We check this in check_explicit_instantiation_namespace. */
12040 95361066 : if (processing_explicit_instantiation)
12041 : return;
12042 : /* [class.mfct]
12043 :
12044 : A member function definition that appears outside of the
12045 : class definition shall appear in a namespace scope enclosing
12046 : the class definition.
12047 :
12048 : [class.static.data]
12049 :
12050 : The definition for a static data member shall appear in a
12051 : namespace scope enclosing the member's class definition. */
12052 95360986 : if (!is_ancestor (current_namespace, DECL_CONTEXT (decl)))
12053 18 : permerror (input_location, "definition of %qD is not in namespace enclosing %qT",
12054 18 : decl, DECL_CONTEXT (decl));
12055 : }
12056 :
12057 : /* Build a PARM_DECL for the "this" parameter of FN. TYPE is the
12058 : METHOD_TYPE for a non-static member function; QUALS are the
12059 : cv-qualifiers that apply to the function. */
12060 :
12061 : tree
12062 232099300 : build_this_parm (tree fn, tree type, cp_cv_quals quals)
12063 : {
12064 232099300 : tree this_type;
12065 232099300 : tree qual_type;
12066 232099300 : tree parm;
12067 232099300 : cp_cv_quals this_quals;
12068 :
12069 232099300 : if (CLASS_TYPE_P (type))
12070 : {
12071 101768668 : this_type
12072 101768668 : = cp_build_qualified_type (type, quals & ~TYPE_QUAL_RESTRICT);
12073 101768668 : this_type = build_pointer_type (this_type);
12074 : }
12075 : else
12076 130330632 : this_type = type_of_this_parm (type);
12077 : /* The `this' parameter is implicitly `const'; it cannot be
12078 : assigned to. */
12079 232099300 : this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST;
12080 232099300 : qual_type = cp_build_qualified_type (this_type, this_quals);
12081 232099300 : parm = build_artificial_parm (fn, this_identifier, qual_type);
12082 232099300 : cp_apply_type_quals_to_decl (this_quals, parm);
12083 232099300 : return parm;
12084 : }
12085 :
12086 : /* DECL is a static member function. Complain if it was declared
12087 : with function-cv-quals. */
12088 :
12089 : static void
12090 10247284 : check_static_quals (tree decl, cp_cv_quals quals)
12091 : {
12092 0 : if (quals != TYPE_UNQUALIFIED)
12093 6 : error ("static member function %q#D declared with type qualifiers",
12094 : decl);
12095 0 : }
12096 :
12097 : /* Helper function. Replace the temporary this parameter injected
12098 : during cp_finish_omp_declare_simd with the real this parameter. */
12099 :
12100 : static tree
12101 2692 : declare_simd_adjust_this (tree *tp, int *walk_subtrees, void *data)
12102 : {
12103 2692 : tree this_parm = (tree) data;
12104 2692 : if (TREE_CODE (*tp) == PARM_DECL
12105 450 : && DECL_NAME (*tp) == this_identifier
12106 2965 : && *tp != this_parm)
12107 273 : *tp = this_parm;
12108 2419 : else if (TYPE_P (*tp))
12109 33 : *walk_subtrees = 0;
12110 2692 : return NULL_TREE;
12111 : }
12112 :
12113 : /* CTYPE is class type, or null if non-class.
12114 : TYPE is type this FUNCTION_DECL should have, either FUNCTION_TYPE
12115 : or METHOD_TYPE.
12116 : DECLARATOR is the function's name.
12117 : PARMS is a chain of PARM_DECLs for the function.
12118 : VIRTUALP is truthvalue of whether the function is virtual or not.
12119 : FLAGS are to be passed through to `grokclassfn'.
12120 : QUALS are qualifiers indicating whether the function is `const'
12121 : or `volatile'.
12122 : RAISES is a list of exceptions that this function can raise.
12123 : CHECK is 1 if we must find this method in CTYPE, 0 if we should
12124 : not look, and -1 if we should not call `grokclassfn' at all.
12125 :
12126 : SFK is the kind of special function (if any) for the new function.
12127 :
12128 : Returns `NULL_TREE' if something goes wrong, after issuing
12129 : applicable error messages. */
12130 :
12131 : static tree
12132 184792457 : grokfndecl (tree ctype,
12133 : tree type,
12134 : tree declarator,
12135 : tree parms,
12136 : tree orig_declarator,
12137 : const cp_decl_specifier_seq *declspecs,
12138 : tree decl_reqs,
12139 : int virtualp,
12140 : enum overload_flags flags,
12141 : cp_cv_quals quals,
12142 : cp_ref_qualifier rqual,
12143 : tree raises,
12144 : int check,
12145 : int friendp,
12146 : int publicp,
12147 : int inlinep,
12148 : int initialized,
12149 : bool xobj_func_p,
12150 : special_function_kind sfk,
12151 : bool funcdef_flag,
12152 : bool late_return_type_p,
12153 : int template_count,
12154 : tree in_namespace,
12155 : tree* attrlist,
12156 : tree contract_specifiers,
12157 : location_t location)
12158 : {
12159 184792457 : tree decl;
12160 184792457 : tree t;
12161 :
12162 184792457 : if (location == UNKNOWN_LOCATION)
12163 0 : location = input_location;
12164 :
12165 : /* Was the concept specifier present? */
12166 184792457 : bool concept_p = inlinep & 4;
12167 :
12168 184792457 : if (concept_p)
12169 : {
12170 15 : error_at (location, "function concepts are no longer supported");
12171 15 : return NULL_TREE;
12172 : }
12173 :
12174 184792442 : type = build_cp_fntype_variant (type, rqual, raises, late_return_type_p);
12175 :
12176 184792442 : decl = build_lang_decl_loc (location, FUNCTION_DECL, declarator, type);
12177 :
12178 : /* Set the constraints on the declaration. */
12179 184792442 : if (flag_concepts)
12180 : {
12181 180524122 : tree tmpl_reqs = NULL_TREE;
12182 180524122 : tree ctx = friendp ? current_class_type : ctype;
12183 180524122 : bool block_local = TREE_CODE (current_scope ()) == FUNCTION_DECL;
12184 180524122 : bool memtmpl = (!block_local
12185 180524122 : && (current_template_depth
12186 180468592 : > template_class_depth (ctx)));
12187 49734162 : if (memtmpl)
12188 : {
12189 49734162 : if (!current_template_parms)
12190 : /* If there are no template parameters, something must have
12191 : gone wrong. */
12192 0 : gcc_assert (seen_error ());
12193 : else
12194 49734162 : tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
12195 : }
12196 180524122 : tree ci = build_constraints (tmpl_reqs, decl_reqs);
12197 : /* C++20 CA378: Remove non-templated constrained functions. */
12198 : /* [temp.friend]/9 A non-template friend declaration with a
12199 : requires-clause shall be a definition. A friend function template with
12200 : a constraint that depends on a template parameter from an enclosing
12201 : template shall be a definition. */
12202 180524122 : if (ci
12203 9351307 : && (block_local
12204 9351304 : || !processing_template_decl
12205 9351244 : || (friendp && !memtmpl && !funcdef_flag)))
12206 : {
12207 72 : if (!friendp || !processing_template_decl)
12208 63 : error_at (location, "constraints on a non-templated function");
12209 : else
12210 9 : error_at (location, "constrained non-template friend declaration"
12211 : " must be a definition");
12212 : ci = NULL_TREE;
12213 : }
12214 180524122 : set_constraints (decl, ci);
12215 1150473 : if (ci && friendp && memtmpl && !funcdef_flag
12216 180560300 : && uses_outer_template_parms_in_constraints (decl, ctx))
12217 6 : error_at (location, "friend function template with constraints that "
12218 : "depend on outer template parameters must be a definition");
12219 : }
12220 :
12221 184792442 : if (TREE_CODE (type) == METHOD_TYPE)
12222 : {
12223 99869178 : tree parm = build_this_parm (decl, type, quals);
12224 99869178 : DECL_CHAIN (parm) = parms;
12225 99869178 : parms = parm;
12226 :
12227 : /* Allocate space to hold the vptr bit if needed. */
12228 99869178 : SET_DECL_ALIGN (decl, MINIMUM_METHOD_BOUNDARY);
12229 : }
12230 :
12231 184792442 : DECL_ARGUMENTS (decl) = parms;
12232 558458967 : for (t = parms; t; t = DECL_CHAIN (t))
12233 : {
12234 373666525 : DECL_CONTEXT (t) = decl;
12235 373666525 : if (flag_reflection
12236 3658648 : && initialized == SD_INITIALIZED
12237 374400340 : && DECL_ATTRIBUTES (t))
12238 1675 : for (tree a = DECL_ATTRIBUTES (t);
12239 1677 : (a = lookup_annotation (a));
12240 2 : a = TREE_CHAIN (a))
12241 : {
12242 2 : gcc_checking_assert (TREE_CODE (TREE_VALUE (a)) == TREE_LIST);
12243 : /* Mark TREE_PURPOSE of the value that it is an annotation
12244 : on an argument of a function definition (rather than
12245 : annotation from function declaration). For function parameter
12246 : reflection all annotations are listed, while for variable_of
12247 : only those marked here. Annotation is marked as coming from
12248 : function definition's argument if it has TREE_PURPOSE
12249 : void_node or INTEGER_CST with signed type. */
12250 2 : tree val = TREE_VALUE (a);
12251 2 : gcc_assert (TREE_PURPOSE (val) == NULL_TREE);
12252 2 : TREE_PURPOSE (val) = void_node;
12253 : }
12254 : }
12255 :
12256 : /* Propagate volatile out from type to decl. */
12257 184792442 : if (TYPE_VOLATILE (type))
12258 0 : TREE_THIS_VOLATILE (decl) = 1;
12259 :
12260 : /* Setup decl according to sfk. */
12261 184792442 : switch (sfk)
12262 : {
12263 23724913 : case sfk_constructor:
12264 23724913 : case sfk_copy_constructor:
12265 23724913 : case sfk_move_constructor:
12266 23724913 : DECL_CXX_CONSTRUCTOR_P (decl) = 1;
12267 23724913 : DECL_NAME (decl) = ctor_identifier;
12268 23724913 : break;
12269 3204697 : case sfk_destructor:
12270 3204697 : DECL_CXX_DESTRUCTOR_P (decl) = 1;
12271 3204697 : DECL_NAME (decl) = dtor_identifier;
12272 3204697 : break;
12273 1178198 : case sfk_deduction_guide:
12274 : /* Give deduction guides a definition even though they don't really
12275 : have one: the restriction that you can't repeat a deduction guide
12276 : makes them more like a definition anyway. */
12277 1178198 : DECL_INITIAL (decl) = void_node;
12278 : /* But to ensure that external-linkage deduction guides in header units
12279 : don't fall afoul of [module.import] p6, mark them as inline. */
12280 1178198 : DECL_DECLARED_INLINE_P (decl) = true;
12281 1178198 : break;
12282 : default:
12283 : break;
12284 : }
12285 :
12286 184792442 : if (friendp && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)
12287 : {
12288 90976 : if (funcdef_flag)
12289 3 : error_at (location,
12290 : "defining explicit specialization %qD in friend declaration",
12291 : orig_declarator);
12292 : else
12293 : {
12294 90973 : tree fns = TREE_OPERAND (orig_declarator, 0);
12295 90973 : tree args = TREE_OPERAND (orig_declarator, 1);
12296 :
12297 90973 : if (PROCESSING_REAL_TEMPLATE_DECL_P ())
12298 : {
12299 : /* Something like `template <class T> friend void f<T>()'. */
12300 6 : error_at (location,
12301 : "invalid use of template-id %qD in declaration "
12302 : "of primary template",
12303 : orig_declarator);
12304 6 : return NULL_TREE;
12305 : }
12306 :
12307 : /* A friend declaration of the form friend void f<>(). Record
12308 : the information in the TEMPLATE_ID_EXPR. */
12309 90967 : SET_DECL_IMPLICIT_INSTANTIATION (decl);
12310 :
12311 90967 : gcc_assert (identifier_p (fns) || OVL_P (fns));
12312 90967 : DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
12313 :
12314 : /* Remember the befriending class like push_template_decl does for
12315 : template friends. */
12316 90967 : gcc_checking_assert (!DECL_CHAIN (decl));
12317 90967 : DECL_CHAIN (decl) = current_scope ();
12318 :
12319 294705 : for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
12320 203743 : if (TREE_PURPOSE (t)
12321 203743 : && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
12322 : {
12323 5 : error_at (defparse_location (TREE_PURPOSE (t)),
12324 : "default arguments are not allowed in declaration "
12325 : "of friend template specialization %qD",
12326 : decl);
12327 5 : return NULL_TREE;
12328 : }
12329 :
12330 90962 : if (inlinep & 1)
12331 : {
12332 5 : error_at (declspecs->locations[ds_inline],
12333 : "%<inline%> is not allowed in declaration of friend "
12334 : "template specialization %qD",
12335 : decl);
12336 5 : return NULL_TREE;
12337 : }
12338 : }
12339 : }
12340 :
12341 : /* C++17 11.3.6/4: "If a friend declaration specifies a default argument
12342 : expression, that declaration shall be a definition..." */
12343 184792426 : if (friendp && !funcdef_flag)
12344 : {
12345 1788877 : bool has_errored = false;
12346 1788877 : for (tree t = FUNCTION_FIRST_USER_PARMTYPE (decl);
12347 5019139 : t && t != void_list_node; t = TREE_CHAIN (t))
12348 3230262 : if (TREE_PURPOSE (t))
12349 : {
12350 51 : enum diagnostics::kind diag_kind = diagnostics::kind::permerror;
12351 : /* For templates, mark the default argument as erroneous and give a
12352 : hard error. */
12353 51 : if (processing_template_decl)
12354 : {
12355 33 : diag_kind = diagnostics::kind::error;
12356 33 : TREE_PURPOSE (t) = error_mark_node;
12357 : }
12358 51 : if (!has_errored)
12359 : {
12360 48 : has_errored = true;
12361 48 : emit_diagnostic (diag_kind,
12362 48 : DECL_SOURCE_LOCATION (decl),
12363 48 : /*diagnostics::option_id=*/0,
12364 : "friend declaration of %qD specifies default "
12365 : "arguments and isn%'t a definition", decl);
12366 : }
12367 : }
12368 : }
12369 :
12370 : /* If this decl has namespace scope, set that up. */
12371 184792426 : if (in_namespace)
12372 226189 : set_decl_namespace (decl, in_namespace, friendp);
12373 184566237 : else if (ctype)
12374 110020429 : DECL_CONTEXT (decl) = ctype;
12375 : else
12376 74545808 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_decl_namespace ());
12377 :
12378 : /* `main' and builtins have implicit 'C' linkage. */
12379 184792426 : if (ctype == NULL_TREE
12380 74771997 : && DECL_FILE_SCOPE_P (decl)
12381 31039657 : && current_lang_name == lang_name_cplusplus
12382 187736856 : && (MAIN_NAME_P (declarator)
12383 2910951 : || (IDENTIFIER_LENGTH (declarator) > 10
12384 2091016 : && IDENTIFIER_POINTER (declarator)[0] == '_'
12385 1633241 : && IDENTIFIER_POINTER (declarator)[1] == '_'
12386 341057 : && startswith (IDENTIFIER_POINTER (declarator) + 2,
12387 : "builtin_"))
12388 2910933 : || (targetcm.cxx_implicit_extern_c
12389 0 : && (targetcm.cxx_implicit_extern_c
12390 0 : (IDENTIFIER_POINTER (declarator))))))
12391 33497 : SET_DECL_LANGUAGE (decl, lang_c);
12392 :
12393 184792426 : DECL_STATIC_FUNCTION_P (decl)
12394 184792426 : = !xobj_func_p && ctype && TREE_CODE (type) == FUNCTION_TYPE;
12395 184792426 : DECL_FUNCTION_XOBJ_FLAG (decl) = xobj_func_p;
12396 :
12397 184792426 : if (initialized == SD_DELETED)
12398 4105993 : DECL_DELETED_FN (decl) = 1;
12399 :
12400 184792426 : if (ctype && funcdef_flag)
12401 95013826 : check_class_member_definition_namespace (decl);
12402 :
12403 184792426 : if (ctype == NULL_TREE && DECL_MAIN_P (decl))
12404 : {
12405 33485 : if (PROCESSING_REAL_TEMPLATE_DECL_P())
12406 9 : error_at (location, "cannot declare %<::main%> to be a template");
12407 33485 : if (inlinep & 1)
12408 3 : error_at (declspecs->locations[ds_inline],
12409 : "cannot declare %<::main%> to be inline");
12410 33485 : if (inlinep & 2)
12411 6 : error_at (declspecs->locations[ds_constexpr],
12412 : "cannot declare %<::main%> to be %qs", "constexpr");
12413 33485 : if (inlinep & 8)
12414 3 : error_at (declspecs->locations[ds_consteval],
12415 : "cannot declare %<::main%> to be %qs", "consteval");
12416 33485 : if (!publicp)
12417 0 : error_at (location, "cannot declare %<::main%> to be static");
12418 33485 : if (current_lang_name != lang_name_cplusplus)
12419 12 : pedwarn (location, OPT_Wpedantic, "cannot declare %<::main%> with a"
12420 : " linkage specification other than %<extern \"C++\"%>");
12421 33485 : if (module_attach_p ())
12422 : {
12423 3 : auto_diagnostic_group adg;
12424 3 : error_at (location, "cannot attach %<::main%> to a named module");
12425 3 : inform (location, "use %<extern \"C++\"%> to attach it to the "
12426 : "global module instead");
12427 3 : }
12428 : inlinep = 0;
12429 : publicp = 1;
12430 : }
12431 :
12432 : /* Members of anonymous types and local classes have no linkage; make
12433 : them internal. If a typedef is made later, this will be changed. */
12434 184792426 : if (ctype && !TREE_PUBLIC (TYPE_MAIN_DECL (ctype)))
12435 : publicp = 0;
12436 184779285 : else if (ctype && decl_function_context (TYPE_MAIN_DECL (ctype)))
12437 : /* But members of local classes in a module CMI should have their
12438 : definitions exported, in case they are (directly or indirectly)
12439 : used by an importer. We don't just use module_has_cmi_p here
12440 : because for entities in the GMF we don't yet know whether this
12441 : module will have a CMI, so we'll conservatively assume it might. */
12442 2152958 : publicp = module_maybe_has_cmi_p ();
12443 :
12444 184779285 : if (publicp && cxx_dialect == cxx98)
12445 : {
12446 : /* [basic.link]: A name with no linkage (notably, the name of a class
12447 : or enumeration declared in a local scope) shall not be used to
12448 : declare an entity with linkage.
12449 :
12450 : DR 757 relaxes this restriction for C++0x. */
12451 1098663 : no_linkage_error (decl);
12452 : }
12453 :
12454 184792426 : TREE_PUBLIC (decl) = publicp;
12455 184792426 : if (! publicp)
12456 : {
12457 2265875 : DECL_INTERFACE_KNOWN (decl) = 1;
12458 2265875 : DECL_NOT_REALLY_EXTERN (decl) = 1;
12459 : }
12460 :
12461 : /* If the declaration was declared inline, mark it as such. */
12462 184792426 : if (inlinep)
12463 : {
12464 69824786 : DECL_DECLARED_INLINE_P (decl) = 1;
12465 69824786 : if (publicp)
12466 69587211 : DECL_COMDAT (decl) = 1;
12467 : }
12468 69824786 : if (inlinep & 2)
12469 51027841 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
12470 133764585 : else if (inlinep & 8)
12471 : {
12472 959697 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
12473 959697 : SET_DECL_IMMEDIATE_FUNCTION_P (decl);
12474 : }
12475 :
12476 184792426 : DECL_EXTERNAL (decl) = 1;
12477 184792426 : if (TREE_CODE (type) == FUNCTION_TYPE)
12478 : {
12479 84923248 : if (quals || rqual)
12480 272 : TREE_TYPE (decl) = apply_memfn_quals (TREE_TYPE (decl),
12481 : TYPE_UNQUALIFIED,
12482 : REF_QUAL_NONE);
12483 84923248 : auto_diagnostic_group d;
12484 84923248 : if (quals)
12485 423 : error (!ctype
12486 : ? G_("non-member function %qD cannot have cv-qualifier")
12487 : : !xobj_func_p
12488 198 : ? G_("static member function %qD cannot have cv-qualifier")
12489 : : G_("explicit object member function "
12490 : "%qD cannot have cv-qualifier"),
12491 : decl);
12492 84923248 : if (rqual)
12493 355 : error (!ctype
12494 : ? G_("non-member function %qD cannot have ref-qualifier")
12495 : : !xobj_func_p
12496 176 : ? G_("static member function %qD cannot have ref-qualifier")
12497 : : G_("explicit object member function "
12498 : "%qD cannot have ref-qualifier"),
12499 : decl);
12500 :
12501 84923248 : if (xobj_func_p && (quals || rqual))
12502 242 : inform (DECL_SOURCE_LOCATION (DECL_ARGUMENTS (decl)),
12503 : "explicit object parameter declared here");
12504 84923248 : quals = TYPE_UNQUALIFIED;
12505 84923248 : rqual = REF_QUAL_NONE;
12506 :
12507 84923248 : }
12508 :
12509 184792426 : if (deduction_guide_p (decl))
12510 : {
12511 1178198 : tree type = TREE_TYPE (DECL_NAME (decl));
12512 1178198 : if (in_namespace == NULL_TREE
12513 1178198 : && CP_DECL_CONTEXT (decl) != CP_TYPE_CONTEXT (type))
12514 : {
12515 3 : auto_diagnostic_group d;
12516 3 : error_at (location, "deduction guide %qD must be declared in the "
12517 : "same scope as %qT", decl, type);
12518 3 : inform (location_of (type), " declared here");
12519 3 : return NULL_TREE;
12520 3 : }
12521 2356390 : if (DECL_CLASS_SCOPE_P (decl)
12522 1178235 : && current_access_specifier != declared_access (TYPE_NAME (type)))
12523 : {
12524 3 : auto_diagnostic_group d;
12525 3 : error_at (location, "deduction guide %qD must have the same access "
12526 : "as %qT", decl, type);
12527 3 : inform (location_of (type), " declared here");
12528 3 : }
12529 1178195 : if (funcdef_flag)
12530 3 : error_at (location,
12531 : "deduction guide %qD must not have a function body", decl);
12532 : }
12533 342565563 : else if (IDENTIFIER_ANY_OP_P (DECL_NAME (decl))
12534 195240172 : && !grok_op_properties (decl, /*complain=*/true))
12535 : return NULL_TREE;
12536 183614081 : else if (UDLIT_OPER_P (DECL_NAME (decl)))
12537 : {
12538 301087 : bool long_long_unsigned_p;
12539 301087 : bool long_double_p;
12540 301087 : const char *suffix = NULL;
12541 : /* [over.literal]/6: Literal operators shall not have C linkage. */
12542 301087 : if (DECL_LANGUAGE (decl) == lang_c)
12543 : {
12544 6 : auto_diagnostic_group d;
12545 6 : error_at (location, "literal operator with C linkage");
12546 6 : maybe_show_extern_c_location ();
12547 6 : return NULL_TREE;
12548 6 : }
12549 :
12550 301081 : if (DECL_NAMESPACE_SCOPE_P (decl))
12551 : {
12552 301075 : if (!check_literal_operator_args (decl, &long_long_unsigned_p,
12553 : &long_double_p))
12554 : {
12555 42 : error_at (location, "%qD has invalid argument list", decl);
12556 42 : return NULL_TREE;
12557 : }
12558 :
12559 301033 : suffix = UDLIT_OP_SUFFIX (DECL_NAME (decl));
12560 301033 : if (long_long_unsigned_p)
12561 : {
12562 45378 : if (cpp_interpret_int_suffix (parse_in, suffix, strlen (suffix)))
12563 68 : warning_at (location, 0, "integer suffix %qs"
12564 : " shadowed by implementation", suffix);
12565 : }
12566 255655 : else if (long_double_p)
12567 : {
12568 83296 : if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
12569 80 : warning_at (location, 0, "floating-point suffix %qs"
12570 : " shadowed by implementation", suffix);
12571 : }
12572 : /* 17.6.3.3.5 */
12573 301033 : if (suffix[0] != '_'
12574 300458 : && !current_function_decl && !(friendp && !funcdef_flag))
12575 300452 : warning_at (location, OPT_Wliteral_suffix,
12576 : "literal operator suffixes not preceded by %<_%>"
12577 : " are reserved for future standardization");
12578 : }
12579 : else
12580 : {
12581 6 : error_at (location, "%qD must be a non-member function", decl);
12582 6 : return NULL_TREE;
12583 : }
12584 : }
12585 :
12586 183614030 : if (funcdef_flag)
12587 : /* Make the init_value nonzero so pushdecl knows this is not
12588 : tentative. error_mark_node is replaced later with the BLOCK. */
12589 130087109 : DECL_INITIAL (decl) = error_mark_node;
12590 :
12591 184792222 : if (TYPE_NOTHROW_P (type) || nothrow_libfn_p (decl))
12592 70114367 : TREE_NOTHROW (decl) = 1;
12593 :
12594 184792222 : if (flag_openmp || flag_openmp_simd)
12595 : {
12596 : /* Adjust "omp declare simd" attributes. */
12597 473753 : tree ods = lookup_attribute ("omp declare simd", *attrlist);
12598 473753 : if (ods)
12599 : {
12600 : tree attr;
12601 2033 : for (attr = ods; attr;
12602 1078 : attr = lookup_attribute ("omp declare simd", TREE_CHAIN (attr)))
12603 : {
12604 1078 : if (TREE_CODE (type) == METHOD_TYPE)
12605 204 : walk_tree (&TREE_VALUE (attr), declare_simd_adjust_this,
12606 : DECL_ARGUMENTS (decl), NULL);
12607 1078 : if (TREE_VALUE (attr) != NULL_TREE)
12608 : {
12609 872 : tree cl = TREE_VALUE (TREE_VALUE (attr));
12610 872 : cl = c_omp_declare_simd_clauses_to_numbers
12611 872 : (DECL_ARGUMENTS (decl), cl);
12612 872 : if (cl)
12613 872 : TREE_VALUE (TREE_VALUE (attr)) = cl;
12614 : else
12615 0 : TREE_VALUE (attr) = NULL_TREE;
12616 : }
12617 : }
12618 : }
12619 : }
12620 :
12621 : /* Caller will do the rest of this. */
12622 184792222 : if (check < 0)
12623 : {
12624 6266109 : if (decl && decl != error_mark_node && contract_specifiers)
12625 16 : set_fn_contract_specifiers (decl, contract_specifiers);
12626 6266109 : return decl;
12627 : }
12628 :
12629 178526113 : if (ctype != NULL_TREE)
12630 110020123 : grokclassfn (ctype, decl, flags);
12631 :
12632 : /* 12.4/3 */
12633 178526113 : if (cxx_dialect >= cxx11
12634 354872446 : && DECL_DESTRUCTOR_P (decl)
12635 3184503 : && !TYPE_BEING_DEFINED (DECL_CONTEXT (decl))
12636 178688776 : && !processing_template_decl)
12637 83168 : deduce_noexcept_on_destructor (decl);
12638 :
12639 178526113 : set_originating_module (decl);
12640 :
12641 178526113 : decl = check_explicit_specialization (orig_declarator, decl,
12642 : template_count,
12643 178526113 : 2 * funcdef_flag +
12644 178526113 : 4 * (friendp != 0),
12645 : *attrlist);
12646 178526113 : if (decl == error_mark_node)
12647 : return NULL_TREE;
12648 :
12649 178525866 : if (DECL_STATIC_FUNCTION_P (decl))
12650 10077443 : check_static_quals (decl, quals);
12651 :
12652 178525866 : if (attrlist)
12653 : {
12654 178525866 : cplus_decl_attributes (&decl, *attrlist, 0);
12655 178525866 : *attrlist = NULL_TREE;
12656 : }
12657 :
12658 : /* Update now we have a decl and maybe know the return type. */
12659 178525866 : if (contract_specifiers)
12660 : {
12661 555 : tree t = decl;
12662 555 : if (TREE_CODE (decl) == TEMPLATE_DECL)
12663 2 : t = DECL_TEMPLATE_RESULT (decl);
12664 555 : set_fn_contract_specifiers (t, contract_specifiers);
12665 555 : rebuild_postconditions (t);
12666 : }
12667 :
12668 : /* Check main's type after attributes have been applied. */
12669 178525866 : if (ctype == NULL_TREE && DECL_MAIN_P (decl))
12670 : {
12671 33473 : if (!same_type_p (TREE_TYPE (TREE_TYPE (decl)),
12672 : integer_type_node))
12673 : {
12674 20 : tree dtype = TREE_TYPE (decl);
12675 20 : tree oldtypeargs = TYPE_ARG_TYPES (dtype);
12676 20 : tree newtype;
12677 20 : error_at (declspecs->locations[ds_type_spec],
12678 : "%<::main%> must return %<int%>");
12679 60 : newtype = build_function_type (integer_type_node, oldtypeargs,
12680 20 : TYPE_NO_NAMED_ARGS_STDARG_P (dtype));
12681 20 : TREE_TYPE (decl) = newtype;
12682 : }
12683 33473 : if (warn_main)
12684 33451 : check_main_parameter_types (decl);
12685 : }
12686 :
12687 178525866 : if (ctype != NULL_TREE && check)
12688 : {
12689 8809090 : tree old_decl = check_classfn (ctype, decl,
12690 8809090 : (current_template_depth
12691 8809090 : > template_class_depth (ctype))
12692 2138960 : ? current_template_parms
12693 : : NULL_TREE);
12694 :
12695 8809090 : if (old_decl == error_mark_node)
12696 : return NULL_TREE;
12697 :
12698 8808982 : if (old_decl)
12699 : {
12700 8419989 : tree ok;
12701 8419989 : tree pushed_scope;
12702 :
12703 8419989 : if (TREE_CODE (old_decl) == TEMPLATE_DECL)
12704 : /* Because grokfndecl is always supposed to return a
12705 : FUNCTION_DECL, we pull out the DECL_TEMPLATE_RESULT
12706 : here. We depend on our callers to figure out that its
12707 : really a template that's being returned. */
12708 2138948 : old_decl = DECL_TEMPLATE_RESULT (old_decl);
12709 :
12710 8419989 : if (DECL_STATIC_FUNCTION_P (old_decl)
12711 8419989 : && TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
12712 : {
12713 : /* Remove the `this' parm added by grokclassfn. */
12714 169841 : revert_static_member_fn (decl);
12715 169841 : check_static_quals (decl, quals);
12716 : }
12717 8419989 : if (DECL_ARTIFICIAL (old_decl))
12718 : {
12719 9 : error ("definition of implicitly-declared %qD", old_decl);
12720 9 : return NULL_TREE;
12721 : }
12722 8419980 : else if (DECL_DEFAULTED_FN (old_decl))
12723 : {
12724 3 : auto_diagnostic_group d;
12725 3 : error ("definition of explicitly-defaulted %q+D", decl);
12726 3 : inform (DECL_SOURCE_LOCATION (old_decl),
12727 : "%q#D explicitly defaulted here", old_decl);
12728 3 : return NULL_TREE;
12729 3 : }
12730 :
12731 8419977 : if (modules_p () && !module_may_redeclare (old_decl))
12732 : return NULL_TREE;
12733 :
12734 : /* Since we've smashed OLD_DECL to its
12735 : DECL_TEMPLATE_RESULT, we must do the same to DECL. */
12736 8419917 : if (TREE_CODE (decl) == TEMPLATE_DECL)
12737 1100 : decl = DECL_TEMPLATE_RESULT (decl);
12738 :
12739 : /* Attempt to merge the declarations. This can fail, in
12740 : the case of some invalid specialization declarations. */
12741 8419917 : pushed_scope = push_scope (ctype);
12742 8419917 : ok = duplicate_decls (decl, old_decl);
12743 8419917 : if (pushed_scope)
12744 8419917 : pop_scope (pushed_scope);
12745 8419917 : if (!ok)
12746 : {
12747 0 : error ("no %q#D member function declared in class %qT",
12748 : decl, ctype);
12749 0 : return NULL_TREE;
12750 : }
12751 8419917 : if (ok == error_mark_node)
12752 : return NULL_TREE;
12753 : return old_decl;
12754 : }
12755 : }
12756 :
12757 340211538 : if (DECL_CONSTRUCTOR_P (decl) && !grok_ctor_properties (ctype, decl))
12758 : return NULL_TREE;
12759 :
12760 : /* Don't call check_consteval_only_fn for defaulted functions. Those are
12761 : immediate-escalating functions but at this point DECL_DEFAULTED_P has
12762 : not been set. */
12763 170105766 : if (initialized != SD_DEFAULTED)
12764 163659591 : check_consteval_only_fn (decl);
12765 :
12766 170105766 : if (ctype == NULL_TREE || check)
12767 68894793 : return decl;
12768 :
12769 101210973 : if (virtualp)
12770 4078257 : DECL_VIRTUAL_P (decl) = 1;
12771 :
12772 101210973 : return decl;
12773 : }
12774 :
12775 : /* decl is a FUNCTION_DECL.
12776 : specifiers are the parsed virt-specifiers.
12777 :
12778 : Set flags to reflect the virt-specifiers.
12779 :
12780 : Returns decl. */
12781 :
12782 : static tree
12783 107477179 : set_virt_specifiers (tree decl, cp_virt_specifiers specifiers)
12784 : {
12785 107477179 : if (decl == NULL_TREE)
12786 : return decl;
12787 107477082 : if (specifiers & VIRT_SPEC_OVERRIDE)
12788 321191 : DECL_OVERRIDE_P (decl) = 1;
12789 107477082 : if (specifiers & VIRT_SPEC_FINAL)
12790 9595 : DECL_FINAL_P (decl) = 1;
12791 : return decl;
12792 : }
12793 :
12794 : /* DECL is a VAR_DECL for a static data member. Set flags to reflect
12795 : the linkage that DECL will receive in the object file. */
12796 :
12797 : static void
12798 13219299 : set_linkage_for_static_data_member (tree decl)
12799 : {
12800 : /* A static data member always has static storage duration and
12801 : external linkage. Note that static data members are forbidden in
12802 : local classes -- the only situation in which a class has
12803 : non-external linkage. */
12804 13219299 : TREE_PUBLIC (decl) = 1;
12805 13219299 : TREE_STATIC (decl) = 1;
12806 : /* For non-template classes, static data members are always put
12807 : out in exactly those files where they are defined, just as
12808 : with ordinary namespace-scope variables. */
12809 13219299 : if (!processing_template_decl)
12810 10061402 : DECL_INTERFACE_KNOWN (decl) = 1;
12811 13219299 : }
12812 :
12813 : /* Create a VAR_DECL named NAME with the indicated TYPE.
12814 :
12815 : If SCOPE is non-NULL, it is the class type or namespace containing
12816 : the variable. If SCOPE is NULL, the variable should is created in
12817 : the innermost enclosing scope. */
12818 :
12819 : static tree
12820 67078568 : grokvardecl (tree type,
12821 : tree name,
12822 : tree orig_declarator,
12823 : const cp_decl_specifier_seq *declspecs,
12824 : int initialized,
12825 : int type_quals,
12826 : int inlinep,
12827 : bool conceptp,
12828 : int template_count,
12829 : tree scope,
12830 : location_t location)
12831 : {
12832 67078568 : tree decl;
12833 67078568 : tree explicit_scope;
12834 :
12835 67078568 : gcc_assert (!name || identifier_p (name));
12836 :
12837 67078568 : bool constp = (type_quals & TYPE_QUAL_CONST) != 0;
12838 67078568 : bool volatilep = (type_quals & TYPE_QUAL_VOLATILE) != 0;
12839 :
12840 : /* Compute the scope in which to place the variable, but remember
12841 : whether or not that scope was explicitly specified by the user. */
12842 67078568 : explicit_scope = scope;
12843 67078568 : if (!scope)
12844 : {
12845 : /* An explicit "extern" specifier indicates a namespace-scope
12846 : variable. */
12847 66578034 : if (declspecs->storage_class == sc_extern)
12848 546244 : scope = current_decl_namespace ();
12849 66031790 : else if (!at_function_scope_p ())
12850 6913533 : scope = current_scope ();
12851 : }
12852 :
12853 66578034 : if (scope
12854 7960311 : && (/* If the variable is a namespace-scope variable declared in a
12855 : template, we need DECL_LANG_SPECIFIC. */
12856 7960311 : (TREE_CODE (scope) == NAMESPACE_DECL && processing_template_decl)
12857 : /* Similarly for namespace-scope variables with language linkage
12858 : other than C++. */
12859 7473866 : || (TREE_CODE (scope) == NAMESPACE_DECL
12860 4323124 : && current_lang_name != lang_name_cplusplus)
12861 : /* Similarly for static data members. */
12862 4580742 : || TYPE_P (scope)
12863 : /* Similarly for explicit specializations. */
12864 4094297 : || (orig_declarator
12865 4093635 : && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
12866 4689973 : decl = build_lang_decl_loc (location, VAR_DECL, name, type);
12867 : else
12868 62388595 : decl = build_decl (location, VAR_DECL, name, type);
12869 :
12870 67078568 : if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
12871 14089 : set_decl_namespace (decl, explicit_scope, 0);
12872 : else
12873 67064479 : DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
12874 :
12875 67078568 : if (declspecs->storage_class == sc_extern)
12876 : {
12877 546244 : DECL_THIS_EXTERN (decl) = 1;
12878 546244 : DECL_EXTERNAL (decl) = !initialized;
12879 : }
12880 :
12881 67078568 : if (DECL_CLASS_SCOPE_P (decl))
12882 : {
12883 486445 : set_linkage_for_static_data_member (decl);
12884 : /* This function is only called with out-of-class definitions. */
12885 486445 : DECL_EXTERNAL (decl) = 0;
12886 486445 : check_class_member_definition_namespace (decl);
12887 : }
12888 : /* At top level, either `static' or no s.c. makes a definition
12889 : (perhaps tentative), and absence of `static' makes it public. */
12890 66592123 : else if (toplevel_bindings_p ())
12891 : {
12892 14945418 : TREE_PUBLIC (decl) = (declspecs->storage_class != sc_static
12893 7472709 : && (DECL_THIS_EXTERN (decl)
12894 6888655 : || ! constp
12895 6888655 : || volatilep
12896 6812247 : || inlinep
12897 522710 : || in_template_context
12898 28695 : || processing_specialization
12899 28626 : || module_attach_p ()));
12900 7472709 : TREE_STATIC (decl) = ! DECL_EXTERNAL (decl);
12901 : }
12902 : /* Not at top level, only `static' makes a static definition. */
12903 : else
12904 : {
12905 59119414 : TREE_STATIC (decl) = declspecs->storage_class == sc_static;
12906 59119414 : TREE_PUBLIC (decl) = DECL_EXTERNAL (decl);
12907 : }
12908 :
12909 67078568 : set_originating_module (decl);
12910 :
12911 67078568 : if (decl_spec_seq_has_spec_p (declspecs, ds_thread))
12912 : {
12913 19430 : if (DECL_EXTERNAL (decl) || TREE_STATIC (decl))
12914 : {
12915 19422 : CP_DECL_THREAD_LOCAL_P (decl) = true;
12916 : // NB: Set a tentative TLS model to avoid tls_model attribute
12917 : // warnings due to lack of thread storage duration. It will
12918 : // be updated by cplus_decl_attributes later.
12919 19422 : if (!processing_template_decl)
12920 19298 : set_decl_tls_model (decl, TLS_MODEL_REAL);
12921 : }
12922 19430 : if (declspecs->gnu_thread_keyword_p)
12923 18434 : SET_DECL_GNU_TLS_P (decl);
12924 : }
12925 :
12926 : /* If the type of the decl has no linkage, make sure that we'll
12927 : notice that in mark_used. */
12928 67078568 : if (cxx_dialect > cxx98
12929 66791087 : && decl_linkage (decl) != lk_none
12930 66118643 : && DECL_LANG_SPECIFIC (decl) == NULL
12931 61350520 : && !DECL_EXTERN_C_P (decl)
12932 128429088 : && no_linkage_check (TREE_TYPE (decl), /*relaxed_p=*/false))
12933 4275 : retrofit_lang_decl (decl);
12934 :
12935 67078568 : if (TREE_PUBLIC (decl))
12936 : {
12937 : /* [basic.link]: A name with no linkage (notably, the name of a class
12938 : or enumeration declared in a local scope) shall not be used to
12939 : declare an entity with linkage.
12940 :
12941 : DR 757 relaxes this restriction for C++0x. */
12942 7892725 : if (cxx_dialect < cxx11)
12943 22172 : no_linkage_error (decl);
12944 : }
12945 : else
12946 59185843 : DECL_INTERFACE_KNOWN (decl) = 1;
12947 :
12948 67078568 : if (DECL_NAME (decl)
12949 67078568 : && MAIN_NAME_P (DECL_NAME (decl)))
12950 : {
12951 12 : if (scope == global_namespace)
12952 6 : error_at (DECL_SOURCE_LOCATION (decl),
12953 : "cannot declare %<::main%> to be a global variable");
12954 6 : else if (DECL_EXTERN_C_P (decl))
12955 3 : error_at (DECL_SOURCE_LOCATION (decl),
12956 : "an entity named %<main%> cannot be declared with "
12957 : "C language linkage");
12958 : }
12959 :
12960 : /* Check if a variable is being declared as a concept. */
12961 67078568 : if (conceptp)
12962 : {
12963 30 : if (!processing_template_decl)
12964 13 : error_at (declspecs->locations[ds_concept],
12965 : "a non-template variable cannot be %<concept%>");
12966 17 : else if (!at_namespace_scope_p ())
12967 2 : error_at (declspecs->locations[ds_concept],
12968 : "concept must be defined at namespace scope");
12969 : else
12970 15 : error_at (declspecs->locations[ds_concept],
12971 : "variable concepts are no longer supported");
12972 30 : return NULL_TREE;
12973 : }
12974 67078538 : else if (flag_concepts
12975 67078538 : && current_template_depth > template_class_depth (scope))
12976 : {
12977 57662640 : tree ci = current_template_constraints ();
12978 57662640 : set_constraints (decl, ci);
12979 : }
12980 :
12981 : // Handle explicit specializations and instantiations of variable templates.
12982 67078538 : if (orig_declarator)
12983 66397603 : decl = check_explicit_specialization (orig_declarator, decl,
12984 : template_count, 0);
12985 :
12986 67078538 : return decl != error_mark_node ? decl : NULL_TREE;
12987 : }
12988 :
12989 : /* Create and return a canonical pointer to member function type, for
12990 : TYPE, which is a POINTER_TYPE to a METHOD_TYPE. */
12991 :
12992 : tree
12993 3103430 : build_ptrmemfunc_type (tree type)
12994 : {
12995 3103430 : tree field, fields;
12996 3103430 : tree t;
12997 :
12998 3103430 : if (type == error_mark_node)
12999 : return type;
13000 :
13001 : /* Make sure that we always have the unqualified pointer-to-member
13002 : type first. */
13003 3103430 : if (cp_cv_quals quals = cp_type_quals (type))
13004 : {
13005 0 : tree unqual = build_ptrmemfunc_type (TYPE_MAIN_VARIANT (type));
13006 0 : return cp_build_qualified_type (unqual, quals);
13007 : }
13008 :
13009 : /* If a canonical type already exists for this type, use it. We use
13010 : this method instead of type_hash_canon, because it only does a
13011 : simple equality check on the list of field members. */
13012 :
13013 3103430 : t = TYPE_PTRMEMFUNC_TYPE (type);
13014 3103430 : if (t)
13015 : return t;
13016 :
13017 1027246 : t = make_node (RECORD_TYPE);
13018 :
13019 : /* Let the front end know this is a pointer to member function. */
13020 1027246 : TYPE_PTRMEMFUNC_FLAG (t) = 1;
13021 :
13022 1027246 : field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
13023 1027246 : DECL_NONADDRESSABLE_P (field) = 1;
13024 1027246 : fields = field;
13025 :
13026 1027246 : field = build_decl (input_location, FIELD_DECL, delta_identifier,
13027 : delta_type_node);
13028 1027246 : DECL_NONADDRESSABLE_P (field) = 1;
13029 1027246 : DECL_CHAIN (field) = fields;
13030 1027246 : fields = field;
13031 :
13032 1027246 : finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
13033 :
13034 : /* Zap out the name so that the back end will give us the debugging
13035 : information for this anonymous RECORD_TYPE. */
13036 1027246 : TYPE_NAME (t) = NULL_TREE;
13037 :
13038 : /* Cache this pointer-to-member type so that we can find it again
13039 : later. */
13040 1027246 : TYPE_PTRMEMFUNC_TYPE (type) = t;
13041 :
13042 1027246 : if (TYPE_STRUCTURAL_EQUALITY_P (type))
13043 498756 : SET_TYPE_STRUCTURAL_EQUALITY (t);
13044 528490 : else if (TYPE_CANONICAL (type) != type)
13045 344038 : TYPE_CANONICAL (t) = build_ptrmemfunc_type (TYPE_CANONICAL (type));
13046 :
13047 : return t;
13048 : }
13049 :
13050 : /* Create and return a pointer to data member type. */
13051 :
13052 : tree
13053 318596 : build_ptrmem_type (tree class_type, tree member_type)
13054 : {
13055 318596 : if (TREE_CODE (member_type) == METHOD_TYPE)
13056 : {
13057 58356 : cp_cv_quals quals = type_memfn_quals (member_type);
13058 58356 : cp_ref_qualifier rqual = type_memfn_rqual (member_type);
13059 58356 : member_type = build_memfn_type (member_type, class_type, quals, rqual);
13060 58356 : return build_ptrmemfunc_type (build_pointer_type (member_type));
13061 : }
13062 : else
13063 : {
13064 260240 : gcc_assert (TREE_CODE (member_type) != FUNCTION_TYPE);
13065 260240 : return build_offset_type (class_type, member_type);
13066 : }
13067 : }
13068 :
13069 : /* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
13070 : Check to see that the definition is valid. Issue appropriate error
13071 : messages. */
13072 :
13073 : static void
13074 18118192 : check_static_variable_definition (tree decl, tree type)
13075 : {
13076 : /* Avoid redundant diagnostics on out-of-class definitions. */
13077 18118192 : if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
13078 : ;
13079 : /* Can't check yet if we don't know the type. */
13080 16763306 : else if (dependent_type_p (type))
13081 : ;
13082 : /* If DECL is declared constexpr, we'll do the appropriate checks
13083 : in check_initializer. Similarly for inline static data members. */
13084 16239157 : else if (DECL_P (decl)
13085 16239157 : && (DECL_DECLARED_CONSTEXPR_P (decl)
13086 2621295 : || DECL_VAR_DECLARED_INLINE_P (decl)))
13087 : ;
13088 2620819 : else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
13089 : {
13090 56 : if (!COMPLETE_TYPE_P (type))
13091 11 : error_at (DECL_SOURCE_LOCATION (decl),
13092 : "in-class initialization of static data member %q#D of "
13093 : "incomplete type", decl);
13094 45 : else if (literal_type_p (type))
13095 39 : permerror (DECL_SOURCE_LOCATION (decl),
13096 : "%<constexpr%> needed for in-class initialization of "
13097 : "static data member %q#D of non-integral type", decl);
13098 : else
13099 6 : error_at (DECL_SOURCE_LOCATION (decl),
13100 : "in-class initialization of static data member %q#D of "
13101 : "non-literal type", decl);
13102 : }
13103 : /* Motion 10 at San Diego: If a static const integral data member is
13104 : initialized with an integral constant expression, the initializer
13105 : may appear either in the declaration (within the class), or in
13106 : the definition, but not both. If it appears in the class, the
13107 : member is a member constant. The file-scope definition is always
13108 : required. */
13109 2620763 : else if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
13110 11 : error_at (DECL_SOURCE_LOCATION (decl),
13111 : "invalid in-class initialization of static data member "
13112 : "of non-integral type %qT",
13113 : type);
13114 2620752 : else if (!CP_TYPE_CONST_P (type))
13115 5 : error_at (DECL_SOURCE_LOCATION (decl),
13116 : "ISO C++ forbids in-class initialization of non-const "
13117 : "static member %qD",
13118 : decl);
13119 2620747 : else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
13120 5 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
13121 : "ISO C++ forbids initialization of member constant "
13122 : "%qD of non-integral type %qT", decl, type);
13123 18118192 : }
13124 :
13125 : /* *expr_p is part of the TYPE_SIZE of a variably-sized array. If any
13126 : SAVE_EXPRs in *expr_p wrap expressions with side-effects, break those
13127 : expressions out into temporary variables so that walk_tree doesn't
13128 : step into them (c++/15764). */
13129 :
13130 : static tree
13131 3404 : stabilize_save_expr_r (tree *expr_p, int *walk_subtrees, void *data)
13132 : {
13133 3404 : hash_set<tree> *pset = (hash_set<tree> *)data;
13134 3404 : tree expr = *expr_p;
13135 3404 : if (TREE_CODE (expr) == SAVE_EXPR)
13136 : {
13137 1483 : tree op = TREE_OPERAND (expr, 0);
13138 1483 : cp_walk_tree (&op, stabilize_save_expr_r, data, pset);
13139 1483 : if (TREE_SIDE_EFFECTS (op))
13140 56 : TREE_OPERAND (expr, 0) = get_temp_regvar (TREE_TYPE (op), op);
13141 1483 : *walk_subtrees = 0;
13142 : }
13143 1921 : else if (!EXPR_P (expr) || !TREE_SIDE_EFFECTS (expr))
13144 1746 : *walk_subtrees = 0;
13145 3404 : return NULL;
13146 : }
13147 :
13148 : /* Entry point for the above. */
13149 :
13150 : static void
13151 1542 : stabilize_vla_size (tree size)
13152 : {
13153 1542 : hash_set<tree> pset;
13154 : /* Break out any function calls into temporary variables. */
13155 1542 : cp_walk_tree (&size, stabilize_save_expr_r, &pset, &pset);
13156 1542 : }
13157 :
13158 : /* Reduce a SIZEOF_EXPR to its value. */
13159 :
13160 : tree
13161 11452469 : fold_sizeof_expr (tree t)
13162 : {
13163 11452469 : tree r;
13164 11452469 : if (SIZEOF_EXPR_TYPE_P (t))
13165 10897132 : r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
13166 10897132 : TREE_TYPE (TREE_OPERAND (t, 0)),
13167 : SIZEOF_EXPR, false, false);
13168 555337 : else if (TYPE_P (TREE_OPERAND (t, 0)))
13169 0 : r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
13170 0 : TREE_OPERAND (t, 0), SIZEOF_EXPR,
13171 : false, false);
13172 : else
13173 555337 : r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
13174 555337 : TREE_OPERAND (t, 0), SIZEOF_EXPR,
13175 : false, false);
13176 11452469 : if (r == error_mark_node)
13177 67 : r = size_one_node;
13178 11452469 : r = cp_fold_convert (size_type_node, r);
13179 11452469 : return r;
13180 : }
13181 :
13182 : /* Given the SIZE (i.e., number of elements) in an array, compute
13183 : an appropriate index type for the array. If non-NULL, NAME is
13184 : the name of the entity being declared. */
13185 :
13186 : static tree
13187 3286956 : compute_array_index_type_loc (location_t name_loc, tree name, tree size,
13188 : tsubst_flags_t complain)
13189 : {
13190 3286956 : if (error_operand_p (size))
13191 34 : return error_mark_node;
13192 :
13193 : /* The type of the index being computed. */
13194 3286922 : tree itype;
13195 :
13196 : /* The original numeric size as seen in the source code before
13197 : conversion to size_t. */
13198 3286922 : tree origsize = size;
13199 :
13200 3286922 : location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
13201 :
13202 3286922 : if (!type_dependent_expression_p (size))
13203 : {
13204 3241824 : origsize = size = mark_rvalue_use (size);
13205 :
13206 37534 : if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
13207 3241984 : && TREE_SIDE_EFFECTS (size))
13208 : /* In C++98, we mark a non-constant array bound with a magic
13209 : NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case. */;
13210 : else
13211 : {
13212 3241823 : size = build_converted_constant_expr (size_type_node, size, complain);
13213 : /* Pedantically a constant expression is required here and so
13214 : __builtin_is_constant_evaluated () should fold to true if it
13215 : is successfully folded into a constant. */
13216 3241823 : size = fold_non_dependent_expr (size, complain,
13217 : /*manifestly_const_eval=*/true);
13218 :
13219 3241823 : if (!TREE_CONSTANT (size))
13220 126655 : size = origsize;
13221 : }
13222 :
13223 3241824 : if (error_operand_p (size))
13224 3 : return error_mark_node;
13225 :
13226 : /* The array bound must be an integer type. */
13227 3241821 : tree type = TREE_TYPE (size);
13228 3241821 : if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
13229 : {
13230 21 : if (!(complain & tf_error))
13231 0 : return error_mark_node;
13232 21 : if (name)
13233 18 : error_at (loc, "size of array %qD has non-integral type %qT",
13234 : name, type);
13235 : else
13236 3 : error_at (loc, "size of array has non-integral type %qT", type);
13237 21 : size = integer_one_node;
13238 : }
13239 : }
13240 :
13241 : /* A type is dependent if it is...an array type constructed from any
13242 : dependent type or whose size is specified by a constant expression
13243 : that is value-dependent. */
13244 : /* We can only call value_dependent_expression_p on integral constant
13245 : expressions. */
13246 3286919 : if (processing_template_decl
13247 1459516 : && potential_constant_expression (size)
13248 4746410 : && value_dependent_expression_p (size))
13249 : {
13250 : /* Just build the index type and mark that it requires
13251 : structural equality checks. */
13252 837288 : in_template:
13253 837288 : itype = build_index_type (build_min (MINUS_EXPR, sizetype,
13254 : size, size_one_node));
13255 837288 : TYPE_DEPENDENT_P (itype) = 1;
13256 837288 : TYPE_DEPENDENT_P_VALID (itype) = 1;
13257 837288 : SET_TYPE_STRUCTURAL_EQUALITY (itype);
13258 837288 : return itype;
13259 : }
13260 :
13261 2460898 : if (TREE_CODE (size) != INTEGER_CST)
13262 : {
13263 13209 : tree folded = cp_fully_fold (size);
13264 13209 : if (TREE_CODE (folded) == INTEGER_CST)
13265 : {
13266 218 : if (name)
13267 144 : pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
13268 : "integral constant-expression", name);
13269 : else
13270 74 : pedwarn (loc, OPT_Wpedantic,
13271 : "size of array is not an integral constant-expression");
13272 : }
13273 13209 : if (TREE_CONSTANT (size) && !TREE_CONSTANT (folded))
13274 : /* We might have lost the TREE_CONSTANT flag e.g. when we are
13275 : folding a conversion from a pointer to integral type. In that
13276 : case issue an error below and don't treat this as a VLA. */;
13277 : else
13278 : /* Use the folded result for VLAs, too; it will have resolved
13279 : SIZEOF_EXPR. */
13280 : size = folded;
13281 : }
13282 :
13283 : /* Normally, the array-bound will be a constant. */
13284 2460898 : if (TREE_CODE (size) == INTEGER_CST)
13285 : {
13286 : /* The size to use in diagnostics that reflects the constant
13287 : size used in the source, rather than SIZE massaged above. */
13288 2447907 : tree diagsize = size;
13289 :
13290 : /* If the original size before conversion to size_t was signed
13291 : and negative, convert it to ssizetype to restore the sign. */
13292 2447907 : if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
13293 : && TREE_CODE (size) == INTEGER_CST
13294 2447907 : && tree_int_cst_sign_bit (size))
13295 : {
13296 237 : diagsize = fold_convert (ssizetype, size);
13297 :
13298 : /* Clear the overflow bit that may have been set as a result
13299 : of the conversion from the sizetype of the new size to
13300 : ssizetype. */
13301 237 : TREE_OVERFLOW (diagsize) = false;
13302 : }
13303 :
13304 : /* Verify that the array has a positive number of elements
13305 : and issue the appropriate diagnostic if it doesn't. */
13306 2447907 : if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
13307 : {
13308 468 : if (!(complain & tf_error))
13309 15 : return error_mark_node;
13310 453 : size = integer_one_node;
13311 : }
13312 : /* As an extension we allow zero-sized arrays. */
13313 2447439 : else if (integer_zerop (size))
13314 : {
13315 3189 : if (!(complain & tf_error))
13316 : /* We must fail if performing argument deduction (as
13317 : indicated by the state of complain), so that
13318 : another substitution can be found. */
13319 8 : return error_mark_node;
13320 3181 : else if (name)
13321 2902 : pedwarn (loc, OPT_Wpedantic,
13322 : "ISO C++ forbids zero-size array %qD", name);
13323 : else
13324 279 : pedwarn (loc, OPT_Wpedantic,
13325 : "ISO C++ forbids zero-size array");
13326 : }
13327 : }
13328 12991 : else if (TREE_CONSTANT (size)
13329 : /* We don't allow VLAs at non-function scopes, or during
13330 : tentative template substitution. */
13331 12976 : || !at_function_scope_p ()
13332 25806 : || !(complain & tf_error))
13333 : {
13334 182 : if (!(complain & tf_error))
13335 134 : return error_mark_node;
13336 : /* `(int) &fn' is not a valid array bound. */
13337 48 : if (name)
13338 37 : error_at (loc,
13339 : "size of array %qD is not an integral constant-expression",
13340 : name);
13341 : else
13342 11 : error_at (loc, "size of array is not an integral constant-expression");
13343 48 : size = integer_one_node;
13344 : }
13345 12809 : else if (pedantic && warn_vla != 0)
13346 : {
13347 30 : if (name)
13348 15 : pedwarn (name_loc, OPT_Wvla,
13349 : "ISO C++ forbids variable length array %qD", name);
13350 : else
13351 15 : pedwarn (input_location, OPT_Wvla,
13352 : "ISO C++ forbids variable length array");
13353 : }
13354 12779 : else if (warn_vla > 0)
13355 : {
13356 3 : if (name)
13357 3 : warning_at (name_loc, OPT_Wvla,
13358 : "variable length array %qD is used", name);
13359 : else
13360 0 : warning (OPT_Wvla,
13361 : "variable length array is used");
13362 : }
13363 :
13364 2460741 : if (processing_template_decl && !TREE_CONSTANT (size))
13365 11267 : goto in_template;
13366 : else
13367 : {
13368 2449474 : if (!TREE_CONSTANT (size))
13369 : {
13370 : /* A variable sized array. Arrange for the SAVE_EXPR on the inside
13371 : of the MINUS_EXPR, which allows the -1 to get folded with the +1
13372 : that happens when building TYPE_SIZE. */
13373 1542 : size = variable_size (size);
13374 1542 : stabilize_vla_size (size);
13375 : }
13376 :
13377 : /* Compute the index of the largest element in the array. It is
13378 : one less than the number of elements in the array. We save
13379 : and restore PROCESSING_TEMPLATE_DECL so that computations in
13380 : cp_build_binary_op will be appropriately folded. */
13381 2449474 : {
13382 2449474 : processing_template_decl_sentinel s;
13383 2449474 : itype = cp_build_binary_op (input_location,
13384 : MINUS_EXPR,
13385 : cp_convert (ssizetype, size, complain),
13386 : cp_convert (ssizetype, integer_one_node,
13387 : complain),
13388 : complain);
13389 2449474 : itype = maybe_constant_value (itype, NULL_TREE, mce_true);
13390 2449474 : }
13391 :
13392 2449474 : if (!TREE_CONSTANT (itype))
13393 : {
13394 1542 : if (sanitize_flags_p (SANITIZE_VLA)
13395 1542 : && current_function_decl != NULL_TREE)
13396 : {
13397 : /* We have to add 1 -- in the ubsan routine we generate
13398 : LE_EXPR rather than LT_EXPR. */
13399 78 : tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
13400 : build_one_cst (TREE_TYPE (itype)));
13401 78 : t = ubsan_instrument_vla (input_location, t);
13402 78 : finish_expr_stmt (t);
13403 : }
13404 : }
13405 : /* Make sure that there was no overflow when creating to a signed
13406 : index type. (For example, on a 32-bit machine, an array with
13407 : size 2^32 - 1 is too big.) */
13408 2447932 : else if (TREE_CODE (itype) == INTEGER_CST
13409 2447932 : && TREE_OVERFLOW (itype))
13410 : {
13411 0 : if (!(complain & tf_error))
13412 0 : return error_mark_node;
13413 0 : error ("overflow in array dimension");
13414 0 : TREE_OVERFLOW (itype) = 0;
13415 : }
13416 : }
13417 :
13418 : /* Create and return the appropriate index type. */
13419 2449474 : itype = build_index_type (itype);
13420 :
13421 : /* If the index type were dependent, we would have returned early, so
13422 : remember that it isn't. */
13423 2449474 : TYPE_DEPENDENT_P (itype) = 0;
13424 2449474 : TYPE_DEPENDENT_P_VALID (itype) = 1;
13425 2449474 : return itype;
13426 : }
13427 :
13428 : tree
13429 572486 : compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
13430 : {
13431 572486 : return compute_array_index_type_loc (input_location, name, size, complain);
13432 : }
13433 :
13434 : /* Returns the scope (if any) in which the entity declared by
13435 : DECLARATOR will be located. If the entity was declared with an
13436 : unqualified name, NULL_TREE is returned. */
13437 :
13438 : tree
13439 737828779 : get_scope_of_declarator (const cp_declarator *declarator)
13440 : {
13441 855039748 : while (declarator && declarator->kind != cdk_id)
13442 117210969 : declarator = declarator->declarator;
13443 :
13444 : /* If the declarator-id is a SCOPE_REF, the scope in which the
13445 : declaration occurs is the first operand. */
13446 737828779 : if (declarator
13447 736624442 : && declarator->u.id.qualifying_scope)
13448 : return declarator->u.id.qualifying_scope;
13449 :
13450 : /* Otherwise, the declarator is not a qualified name; the entity will
13451 : be declared in the current scope. */
13452 : return NULL_TREE;
13453 : }
13454 :
13455 : /* Returns an ARRAY_TYPE for an array with SIZE elements of the
13456 : indicated TYPE. If non-NULL, NAME is the NAME of the declaration
13457 : with this type. */
13458 :
13459 : static tree
13460 3503931 : create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
13461 : {
13462 3503931 : tree itype = NULL_TREE;
13463 :
13464 : /* If things have already gone awry, bail now. */
13465 3503931 : if (type == error_mark_node || size == error_mark_node)
13466 : return error_mark_node;
13467 :
13468 : /* [dcl.type.class.deduct] prohibits forming an array of placeholder
13469 : for a deduced class type. */
13470 3503868 : if (template_placeholder_p (type))
13471 : {
13472 6 : if (name)
13473 0 : error_at (loc, "%qD declared as array of template placeholder "
13474 : "type %qT", name, type);
13475 : else
13476 6 : error ("creating array of template placeholder type %qT", type);
13477 6 : return error_mark_node;
13478 : }
13479 :
13480 : /* If there are some types which cannot be array elements,
13481 : issue an error-message and return. */
13482 3503862 : switch (TREE_CODE (type))
13483 : {
13484 3 : case VOID_TYPE:
13485 3 : if (name)
13486 0 : error_at (loc, "declaration of %qD as array of void", name);
13487 : else
13488 3 : error ("creating array of void");
13489 3 : return error_mark_node;
13490 :
13491 6 : case FUNCTION_TYPE:
13492 6 : if (name)
13493 6 : error_at (loc, "declaration of %qD as array of functions", name);
13494 : else
13495 0 : error ("creating array of functions");
13496 6 : return error_mark_node;
13497 :
13498 21 : case REFERENCE_TYPE:
13499 21 : if (name)
13500 15 : error_at (loc, "declaration of %qD as array of references", name);
13501 : else
13502 6 : error ("creating array of references");
13503 21 : return error_mark_node;
13504 :
13505 0 : case METHOD_TYPE:
13506 0 : if (name)
13507 0 : error_at (loc, "declaration of %qD as array of function members",
13508 : name);
13509 : else
13510 0 : error ("creating array of function members");
13511 0 : return error_mark_node;
13512 :
13513 3503832 : default:
13514 3503832 : break;
13515 : }
13516 :
13517 3503832 : if (!verify_type_context (name ? loc : input_location,
13518 : TCTX_ARRAY_ELEMENT, type))
13519 0 : return error_mark_node;
13520 :
13521 : /* [dcl.array]
13522 :
13523 : The constant expressions that specify the bounds of the arrays
13524 : can be omitted only for the first member of the sequence. */
13525 3503832 : if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
13526 : {
13527 30 : if (name)
13528 24 : error_at (loc, "declaration of %qD as multidimensional array must "
13529 : "have bounds for all dimensions except the first",
13530 : name);
13531 : else
13532 6 : error ("multidimensional array must have bounds for all "
13533 : "dimensions except the first");
13534 :
13535 30 : return error_mark_node;
13536 : }
13537 :
13538 : /* Figure out the index type for the array. */
13539 3503802 : if (size)
13540 : {
13541 2714470 : itype = compute_array_index_type_loc (loc, name, size,
13542 : tf_warning_or_error);
13543 2714470 : if (type_uses_auto (type)
13544 2714470 : && variably_modified_type_p (itype, /*fn=*/NULL_TREE))
13545 : {
13546 9 : sorry_at (loc, "variable-length array of %<auto%>");
13547 9 : return error_mark_node;
13548 : }
13549 : }
13550 :
13551 3503793 : return build_cplus_array_type (type, itype);
13552 : }
13553 :
13554 : /* Returns the smallest location that is not UNKNOWN_LOCATION. */
13555 :
13556 : static location_t
13557 1022336460 : min_location (location_t loca, location_t locb)
13558 : {
13559 1022336460 : if (loca == UNKNOWN_LOCATION
13560 1022336460 : || (locb != UNKNOWN_LOCATION
13561 107190538 : && linemap_location_before_p (line_table, locb, loca)))
13562 916301379 : return locb;
13563 : return loca;
13564 : }
13565 :
13566 : /* Returns the smallest location != UNKNOWN_LOCATION among the
13567 : three stored in LOCATIONS[ds_const], LOCATIONS[ds_volatile],
13568 : and LOCATIONS[ds_restrict]. */
13569 :
13570 : static location_t
13571 1020644260 : smallest_type_quals_location (int type_quals, const location_t* locations)
13572 : {
13573 1020644260 : location_t loc = UNKNOWN_LOCATION;
13574 :
13575 1020644260 : if (type_quals & TYPE_QUAL_CONST)
13576 105742523 : loc = locations[ds_const];
13577 :
13578 1020644260 : if (type_quals & TYPE_QUAL_VOLATILE)
13579 1692109 : loc = min_location (loc, locations[ds_volatile]);
13580 :
13581 1020644260 : if (type_quals & TYPE_QUAL_RESTRICT)
13582 43 : loc = min_location (loc, locations[ds_restrict]);
13583 :
13584 1020644260 : return loc;
13585 : }
13586 :
13587 : /* Returns the smallest among the latter and locations[ds_type_spec]. */
13588 :
13589 : static location_t
13590 1020644239 : smallest_type_location (int type_quals, const location_t* locations)
13591 : {
13592 1020644239 : location_t loc = smallest_type_quals_location (type_quals, locations);
13593 1020644239 : return min_location (loc, locations[ds_type_spec]);
13594 : }
13595 :
13596 : static location_t
13597 26 : smallest_type_location (const cp_decl_specifier_seq *declspecs)
13598 : {
13599 26 : int type_quals = get_type_quals (declspecs);
13600 26 : return smallest_type_location (type_quals, declspecs->locations);
13601 : }
13602 :
13603 : /* Returns whether DECLARATOR represented a pointer or a reference and if so,
13604 : strip out the pointer/reference declarator(s). */
13605 :
13606 : static bool
13607 29106502 : maybe_strip_indirect_ref (const cp_declarator** declarator)
13608 : {
13609 29106502 : bool indirect_ref_p = false;
13610 58213151 : while (declarator && *declarator
13611 29106649 : && ((*declarator)->kind == cdk_pointer
13612 29106649 : || (*declarator)->kind == cdk_reference))
13613 : {
13614 147 : indirect_ref_p = true;
13615 147 : *declarator = (*declarator)->declarator;
13616 : }
13617 29106502 : return indirect_ref_p;
13618 : }
13619 :
13620 : /* Check that it's OK to declare a function with the indicated TYPE, TYPE_QUALS
13621 : and DECLARATOR. SFK indicates the kind of special function (if any) that
13622 : this function is. OPTYPE is the type given in a conversion operator
13623 : declaration, or the class type for a constructor/destructor.
13624 : Returns the actual return type of the function; that may be different
13625 : than TYPE if an error occurs, or for certain special functions. */
13626 :
13627 : static tree
13628 29106502 : check_special_function_return_type (special_function_kind sfk,
13629 : tree type,
13630 : tree optype,
13631 : int type_quals,
13632 : const cp_declarator** declarator,
13633 : const location_t* locations)
13634 : {
13635 29106502 : gcc_assert (declarator);
13636 29106502 : location_t rettype_loc = (type
13637 29106502 : ? smallest_type_location (type_quals, locations)
13638 29106421 : : (*declarator)->id_loc);
13639 29106502 : switch (sfk)
13640 : {
13641 23724955 : case sfk_constructor:
13642 23724955 : if (maybe_strip_indirect_ref (declarator) || type)
13643 81 : error_at (rettype_loc,
13644 : "return type specification for constructor invalid");
13645 23724874 : else if (type_quals != TYPE_UNQUALIFIED)
13646 15 : error_at (smallest_type_quals_location (type_quals, locations),
13647 : "qualifiers are not allowed on constructor declaration");
13648 :
13649 23724955 : if (targetm.cxx.cdtor_returns_this ())
13650 0 : type = build_pointer_type (optype);
13651 : else
13652 23724955 : type = void_type_node;
13653 : break;
13654 :
13655 3204748 : case sfk_destructor:
13656 3204748 : if (maybe_strip_indirect_ref (declarator) || type)
13657 45 : error_at (rettype_loc,
13658 : "return type specification for destructor invalid");
13659 3204703 : else if (type_quals != TYPE_UNQUALIFIED)
13660 3 : error_at (smallest_type_quals_location (type_quals, locations),
13661 : "qualifiers are not allowed on destructor declaration");
13662 :
13663 : /* We can't use the proper return type here because we run into
13664 : problems with ambiguous bases and covariant returns. */
13665 3204748 : if (targetm.cxx.cdtor_returns_this ())
13666 0 : type = build_pointer_type (void_type_node);
13667 : else
13668 3204748 : type = void_type_node;
13669 : break;
13670 :
13671 998595 : case sfk_conversion:
13672 998595 : if (maybe_strip_indirect_ref (declarator) || type)
13673 42 : error_at (rettype_loc,
13674 : "return type specified for %<operator %T%>", optype);
13675 998553 : else if (type_quals != TYPE_UNQUALIFIED)
13676 3 : error_at (smallest_type_quals_location (type_quals, locations),
13677 : "qualifiers are not allowed on declaration of "
13678 : "%<operator %T%>", optype);
13679 :
13680 : type = optype;
13681 : break;
13682 :
13683 1178204 : case sfk_deduction_guide:
13684 1178204 : if (maybe_strip_indirect_ref (declarator) || type)
13685 0 : error_at (rettype_loc,
13686 : "return type specified for deduction guide");
13687 1178204 : else if (type_quals != TYPE_UNQUALIFIED)
13688 0 : error_at (smallest_type_quals_location (type_quals, locations),
13689 : "qualifiers are not allowed on declaration of "
13690 : "deduction guide");
13691 1178204 : if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
13692 : {
13693 3 : error ("template template parameter %qT in declaration of "
13694 : "deduction guide", optype);
13695 3 : type = error_mark_node;
13696 : }
13697 : else
13698 1178201 : type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
13699 31811508 : for (int i = 0; i < ds_last; ++i)
13700 30633304 : if (i != ds_explicit && locations[i])
13701 3 : error_at (locations[i],
13702 : "%<decl-specifier%> in declaration of deduction guide");
13703 : break;
13704 :
13705 0 : default:
13706 0 : gcc_unreachable ();
13707 : }
13708 :
13709 29106502 : return type;
13710 : }
13711 :
13712 : /* A variable or data member (whose unqualified name is IDENTIFIER)
13713 : has been declared with the indicated TYPE. If the TYPE is not
13714 : acceptable, issue an error message and return a type to use for
13715 : error-recovery purposes. */
13716 :
13717 : tree
13718 320221601 : check_var_type (tree identifier, tree type, location_t loc)
13719 : {
13720 320221601 : if (VOID_TYPE_P (type))
13721 : {
13722 86 : if (!identifier)
13723 0 : error_at (loc, "unnamed variable or field declared void");
13724 86 : else if (identifier_p (identifier))
13725 : {
13726 86 : gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
13727 86 : error_at (loc, "variable or field %qE declared void",
13728 : identifier);
13729 : }
13730 : else
13731 0 : error_at (loc, "variable or field declared void");
13732 86 : type = error_mark_node;
13733 : }
13734 :
13735 320221601 : return type;
13736 : }
13737 :
13738 : /* Handle declaring DECL as an inline variable. */
13739 :
13740 : static void
13741 6464538 : mark_inline_variable (tree decl, location_t loc)
13742 : {
13743 6464538 : bool inlinep = true;
13744 6464538 : if (! toplevel_bindings_p ())
13745 : {
13746 24 : error_at (loc, "%<inline%> specifier invalid for variable "
13747 : "%qD declared at block scope", decl);
13748 24 : inlinep = false;
13749 : }
13750 6464514 : else if (cxx_dialect < cxx17)
13751 652 : pedwarn (loc, OPT_Wc__17_extensions, "inline variables are only available "
13752 : "with %<-std=c++17%> or %<-std=gnu++17%>");
13753 676 : if (inlinep)
13754 : {
13755 6464514 : retrofit_lang_decl (decl);
13756 6464514 : SET_DECL_VAR_DECLARED_INLINE_P (decl);
13757 : }
13758 6464538 : }
13759 :
13760 :
13761 : /* Diagnose -Wnon-c-typedef-for-linkage pedwarn. TYPE is the unnamed class
13762 : with a typedef name for linkage purposes with freshly updated TYPE_NAME,
13763 : ORIG is the anonymous TYPE_NAME before that change. */
13764 :
13765 : static bool
13766 42 : diagnose_non_c_class_typedef_for_linkage (tree type, tree orig)
13767 : {
13768 42 : gcc_rich_location richloc (DECL_SOURCE_LOCATION (orig));
13769 42 : tree name = DECL_NAME (TYPE_NAME (type));
13770 42 : richloc.add_fixit_insert_before (IDENTIFIER_POINTER (name));
13771 42 : return pedwarn (&richloc, OPT_Wnon_c_typedef_for_linkage,
13772 : "anonymous non-C-compatible type given name for linkage "
13773 42 : "purposes by %<typedef%> declaration");
13774 42 : }
13775 :
13776 : /* Diagnose -Wnon-c-typedef-for-linkage violations on T. TYPE and ORIG
13777 : like for diagnose_non_c_class_typedef_for_linkage, T is initially equal
13778 : to TYPE but during recursion can be set to nested classes. */
13779 :
13780 : static bool
13781 506328 : maybe_diagnose_non_c_class_typedef_for_linkage (tree type, tree orig, tree t)
13782 : {
13783 506328 : if (!BINFO_BASE_BINFOS (TYPE_BINFO (t))->is_empty ())
13784 : {
13785 6 : auto_diagnostic_group d;
13786 6 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13787 9 : inform (type == t ? DECL_SOURCE_LOCATION (orig)
13788 3 : : DECL_SOURCE_LOCATION (TYPE_NAME (t)),
13789 : "type is not C-compatible because it has a base class");
13790 6 : return true;
13791 6 : }
13792 2382009 : for (tree field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
13793 1875748 : switch (TREE_CODE (field))
13794 : {
13795 9 : case VAR_DECL:
13796 : /* static data members have been diagnosed already. */
13797 9 : continue;
13798 1247968 : case FIELD_DECL:
13799 1247968 : if (DECL_INITIAL (field))
13800 : {
13801 4 : auto_diagnostic_group d;
13802 4 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13803 4 : inform (DECL_SOURCE_LOCATION (field),
13804 : "type is not C-compatible because %qD has default "
13805 : "member initializer", field);
13806 4 : return true;
13807 4 : }
13808 1247964 : continue;
13809 9 : case CONST_DECL:
13810 9 : continue;
13811 627683 : case TYPE_DECL:
13812 627683 : if (DECL_SELF_REFERENCE_P (field))
13813 506296 : continue;
13814 121387 : if (DECL_IMPLICIT_TYPEDEF_P (field))
13815 : {
13816 121377 : if (TREE_CODE (TREE_TYPE (field)) == ENUMERAL_TYPE)
13817 3 : continue;
13818 121374 : if (CLASS_TYPE_P (TREE_TYPE (field)))
13819 : {
13820 121374 : tree tf = TREE_TYPE (field);
13821 121374 : if (maybe_diagnose_non_c_class_typedef_for_linkage (type, orig,
13822 : tf))
13823 : return true;
13824 121349 : continue;
13825 121349 : }
13826 : }
13827 : /* FALLTHRU */
13828 32 : case FUNCTION_DECL:
13829 32 : case TEMPLATE_DECL:
13830 32 : {
13831 32 : auto_diagnostic_group d;
13832 32 : if (diagnose_non_c_class_typedef_for_linkage (type, orig))
13833 32 : inform (DECL_SOURCE_LOCATION (field),
13834 : "type is not C-compatible because it contains %qD "
13835 : "declaration", field);
13836 32 : return true;
13837 32 : }
13838 : default:
13839 : break;
13840 1247982 : }
13841 : return false;
13842 : }
13843 :
13844 : /* Assign a typedef-given name to a class or enumeration type declared
13845 : as anonymous at first. This was split out of grokdeclarator
13846 : because it is also used in libcc1. */
13847 :
13848 : void
13849 386750 : name_unnamed_type (tree type, tree decl)
13850 : {
13851 1160250 : gcc_assert (TYPE_UNNAMED_P (type)
13852 : || enum_with_enumerator_for_linkage_p (type));
13853 :
13854 386750 : tree orig = TYPE_NAME (type);
13855 386750 : if (flag_reflection)
13856 : {
13857 : /* For -freflection for typedef struct { ... } S; ^^S needs to be
13858 : a reflection of a type alias. So, TREE_TYPE (DECL) can't be
13859 : TYPE. Instead of what we do below, override DECL_NAME (orig). */
13860 7343 : DECL_NAME (orig) = DECL_NAME (decl);
13861 7343 : TYPE_DECL_FOR_LINKAGE_PURPOSES_P (orig) = 1;
13862 : }
13863 : else
13864 : /* Replace the anonymous decl with the real decl. Be careful not to
13865 : rename other typedefs (such as the self-reference) of type. */
13866 1136495 : for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
13867 757088 : if (TYPE_NAME (t) == orig)
13868 379407 : TYPE_NAME (t) = decl;
13869 386750 : TYPE_DECL_FOR_LINKAGE_PURPOSES_P (decl) = 1;
13870 :
13871 : /* If this is a typedef within a template class, the nested
13872 : type is a (non-primary) template. The name for the
13873 : template needs updating as well. */
13874 386750 : if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
13875 66 : DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)) = DECL_NAME (decl);
13876 :
13877 : /* Adjust linkage now that we aren't unnamed anymore. */
13878 386750 : reset_type_linkage (type);
13879 :
13880 386750 : if (CLASS_TYPE_P (type) && warn_non_c_typedef_for_linkage)
13881 384954 : maybe_diagnose_non_c_class_typedef_for_linkage (type, orig, type);
13882 :
13883 : /* FIXME remangle member functions; member functions of a
13884 : type with external linkage have external linkage. */
13885 :
13886 : /* Check that our job is done, and that it would fail if we
13887 : attempted to do it again. */
13888 773500 : gcc_assert (!TYPE_UNNAMED_P (type)
13889 : && !enum_with_enumerator_for_linkage_p (type));
13890 386750 : }
13891 :
13892 : /* Check that decltype(auto) was well-formed: only plain decltype(auto)
13893 : is allowed. TYPE might contain a decltype(auto). Returns true if
13894 : there was a problem, false otherwise. */
13895 :
13896 : static bool
13897 621835890 : check_decltype_auto (location_t loc, tree type)
13898 : {
13899 621835890 : if (tree a = type_uses_auto (type))
13900 : {
13901 17038294 : if (AUTO_IS_DECLTYPE (a))
13902 : {
13903 594740 : if (a != type)
13904 : {
13905 33 : error_at (loc, "%qT as type rather than plain "
13906 : "%<decltype(auto)%>", type);
13907 33 : return true;
13908 : }
13909 594707 : else if (TYPE_QUALS (type) != TYPE_UNQUALIFIED)
13910 : {
13911 37 : error_at (loc, "%<decltype(auto)%> cannot be cv-qualified");
13912 37 : return true;
13913 : }
13914 : }
13915 : }
13916 : return false;
13917 : }
13918 :
13919 : /* Issue an error about two mutually incompatible declspecs
13920 : with the given names and locations
13921 : e.g. "error: `signed' and `unsigned' specified together" */
13922 :
13923 : static void
13924 66 : complain_about_incompatible_declspecs (const char *name_a, location_t loc_a,
13925 : const char *name_b, location_t loc_b)
13926 : {
13927 66 : gcc_rich_location richloc (loc_a, nullptr, highlight_colors::lhs);
13928 66 : richloc.add_range (loc_b, SHOW_RANGE_WITHOUT_CARET,
13929 : nullptr, highlight_colors::rhs);
13930 66 : pp_element_quoted_string e_name_a (name_a, highlight_colors::lhs);
13931 66 : pp_element_quoted_string e_name_b (name_b, highlight_colors::rhs);
13932 66 : error_at (&richloc, "%e and %e specified together",
13933 : &e_name_a, &e_name_b);
13934 66 : }
13935 :
13936 : /* Given declspecs and a declarator (abstract or otherwise), determine
13937 : the name and type of the object declared and construct a DECL node
13938 : for it.
13939 :
13940 : DECLSPECS points to the representation of declaration-specifier
13941 : sequence that precedes declarator.
13942 :
13943 : DECL_CONTEXT says which syntactic context this declaration is in:
13944 : NORMAL for most contexts. Make a VAR_DECL or FUNCTION_DECL or TYPE_DECL.
13945 : FUNCDEF for a function definition. Like NORMAL but a few different
13946 : error messages in each case. Return value may be zero meaning
13947 : this definition is too screwy to try to parse.
13948 : MEMFUNCDEF for a function definition. Like FUNCDEF but prepares to
13949 : handle member functions (which have FIELD context).
13950 : Return value may be zero meaning this definition is too screwy to
13951 : try to parse.
13952 : PARM for a parameter declaration (either within a function prototype
13953 : or before a function body). Make a PARM_DECL, or return void_type_node.
13954 : TPARM for a template parameter declaration.
13955 : CATCHPARM for a parameter declaration before a catch clause.
13956 : TYPENAME if for a typename (in a cast or sizeof).
13957 : Don't make a DECL node; just return the ..._TYPE node.
13958 : FIELD for a struct or union field; make a FIELD_DECL.
13959 : BITFIELD for a field with specified width.
13960 :
13961 : INITIALIZED is as for start_decl.
13962 :
13963 : ATTRLIST is a pointer to the list of attributes, which may be NULL
13964 : if there are none; *ATTRLIST may be modified if attributes from inside
13965 : the declarator should be applied to the declaration.
13966 :
13967 : When this function is called, scoping variables (such as
13968 : CURRENT_CLASS_TYPE) should reflect the scope in which the
13969 : declaration occurs, not the scope in which the new declaration will
13970 : be placed. For example, on:
13971 :
13972 : void S::f() { ... }
13973 :
13974 : when grokdeclarator is called for `S::f', the CURRENT_CLASS_TYPE
13975 : should not be `S'.
13976 :
13977 : Returns a DECL (if a declarator is present), a TYPE (if there is no
13978 : declarator, in cases like "struct S;"), or the ERROR_MARK_NODE if an
13979 : error occurs. */
13980 :
13981 : tree
13982 1020644132 : grokdeclarator (const cp_declarator *declarator,
13983 : cp_decl_specifier_seq *declspecs,
13984 : enum decl_context decl_context,
13985 : int initialized,
13986 : tree* attrlist)
13987 : {
13988 1020644132 : tree type = NULL_TREE;
13989 1020644132 : int longlong = 0;
13990 1020644132 : int explicit_intN = 0;
13991 1020644132 : int int_n_alt = 0;
13992 1020644132 : int virtualp, explicitp, friendp, inlinep, staticp;
13993 1020644132 : int explicit_int = 0;
13994 1020644132 : int explicit_char = 0;
13995 1020644132 : int defaulted_int = 0;
13996 :
13997 1020644132 : tree typedef_decl = NULL_TREE;
13998 1020644132 : const char *name = NULL;
13999 1020644132 : tree typedef_type = NULL_TREE;
14000 : /* True if this declarator is a function definition. */
14001 1020644132 : bool funcdef_flag = false;
14002 1020644132 : cp_declarator_kind innermost_code = cdk_error;
14003 1020644132 : int bitfield = 0;
14004 : #if 0
14005 : /* See the code below that used this. */
14006 : tree decl_attr = NULL_TREE;
14007 : #endif
14008 :
14009 : /* Keep track of what sort of function is being processed
14010 : so that we can warn about default return values, or explicit
14011 : return values which do not match prescribed defaults. */
14012 1020644132 : special_function_kind sfk = sfk_none;
14013 :
14014 1020644132 : tree dname = NULL_TREE;
14015 1020644132 : tree ctor_return_type = NULL_TREE;
14016 1020644132 : enum overload_flags flags = NO_SPECIAL;
14017 : /* cv-qualifiers that apply to the declarator, for a declaration of
14018 : a member function. */
14019 1020644132 : cp_cv_quals memfn_quals = TYPE_UNQUALIFIED;
14020 : /* virt-specifiers that apply to the declarator, for a declaration of
14021 : a member function. */
14022 1020644132 : cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
14023 : /* ref-qualifier that applies to the declarator, for a declaration of
14024 : a member function. */
14025 1020644132 : cp_ref_qualifier rqual = REF_QUAL_NONE;
14026 : /* cv-qualifiers that apply to the type specified by the DECLSPECS. */
14027 1020644132 : int type_quals = get_type_quals (declspecs);
14028 1020644132 : tree raises = NULL_TREE;
14029 1020644132 : int template_count = 0;
14030 1020644132 : tree returned_attrs = NULL_TREE;
14031 1020644132 : tree contract_specifiers = NULL_TREE;
14032 1020644132 : tree parms = NULL_TREE;
14033 1020644132 : const cp_declarator *id_declarator;
14034 : /* The unqualified name of the declarator; either an
14035 : IDENTIFIER_NODE, BIT_NOT_EXPR, or TEMPLATE_ID_EXPR. */
14036 1020644132 : tree unqualified_id;
14037 : /* The class type, if any, in which this entity is located,
14038 : or NULL_TREE if none. Note that this value may be different from
14039 : the current class type; for example if an attempt is made to declare
14040 : "A::f" inside "B", this value will be "A". */
14041 1020644132 : tree ctype = current_class_type;
14042 : /* The NAMESPACE_DECL for the namespace in which this entity is
14043 : located. If an unqualified name is used to declare the entity,
14044 : this value will be NULL_TREE, even if the entity is located at
14045 : namespace scope. */
14046 1020644132 : tree in_namespace = NULL_TREE;
14047 1020644132 : cp_storage_class storage_class;
14048 1020644132 : bool unsigned_p, signed_p, short_p, long_p, thread_p;
14049 1020644132 : bool type_was_error_mark_node = false;
14050 1020644132 : bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
14051 1020644132 : bool template_type_arg = false;
14052 1020644132 : bool template_parm_flag = false;
14053 1020644132 : bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
14054 1020644132 : bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
14055 1020644132 : bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
14056 1020644132 : bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
14057 1020644132 : bool late_return_type_p = false;
14058 1020644132 : bool array_parameter_p = false;
14059 1020644132 : tree reqs = NULL_TREE;
14060 :
14061 1020644132 : signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
14062 1020644132 : unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
14063 1020644132 : short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
14064 1020644132 : long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
14065 1020644132 : longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
14066 1020644132 : explicit_intN = declspecs->explicit_intN_p;
14067 1020644132 : int_n_alt = declspecs->int_n_alt;
14068 1020644132 : thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
14069 :
14070 : // Was concept_p specified? Note that ds_concept
14071 : // implies ds_constexpr!
14072 1020644132 : bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
14073 1020644132 : if (concept_p)
14074 117 : constexpr_p = true;
14075 :
14076 1020644132 : if (decl_context == FUNCDEF)
14077 : funcdef_flag = true, decl_context = NORMAL;
14078 : else if (decl_context == MEMFUNCDEF)
14079 : funcdef_flag = true, decl_context = FIELD;
14080 : else if (decl_context == BITFIELD)
14081 : bitfield = 1, decl_context = FIELD;
14082 : else if (decl_context == TEMPLATE_TYPE_ARG)
14083 : template_type_arg = true, decl_context = TYPENAME;
14084 : else if (decl_context == TPARM)
14085 10758196 : template_parm_flag = true, decl_context = PARM;
14086 :
14087 1020644132 : if (initialized == SD_DEFAULTED || initialized == SD_DELETED)
14088 10762643 : funcdef_flag = true;
14089 :
14090 1020644132 : location_t typespec_loc = loc_or_input_loc (smallest_type_location
14091 : (type_quals,
14092 1020644132 : declspecs->locations));
14093 1020644132 : location_t id_loc;
14094 1020644132 : location_t init_loc;
14095 1020644132 : if (declarator)
14096 : {
14097 616075884 : id_loc = loc_or_input_loc (declarator->id_loc);
14098 616075884 : init_loc = loc_or_input_loc (declarator->init_loc);
14099 : }
14100 : else
14101 404568248 : init_loc = id_loc = input_location;
14102 :
14103 : /* Look inside a declarator for the name being declared
14104 : and get it as a string, for an error message. */
14105 1020644132 : for (id_declarator = declarator;
14106 1401872675 : id_declarator;
14107 381228543 : id_declarator = id_declarator->declarator)
14108 : {
14109 956481650 : if (id_declarator->kind != cdk_id)
14110 381228568 : innermost_code = id_declarator->kind;
14111 :
14112 956481650 : switch (id_declarator->kind)
14113 : {
14114 187114508 : case cdk_function:
14115 187114508 : if (id_declarator->declarator
14116 186745365 : && id_declarator->declarator->kind == cdk_id)
14117 : {
14118 184930696 : sfk = id_declarator->declarator->u.id.sfk;
14119 184930696 : if (sfk == sfk_destructor)
14120 3204751 : flags = DTOR_FLAG;
14121 : }
14122 : break;
14123 :
14124 575253082 : case cdk_id:
14125 575253082 : {
14126 575253082 : tree qualifying_scope = id_declarator->u.id.qualifying_scope;
14127 575253082 : tree decl = id_declarator->u.id.unqualified_name;
14128 575253082 : if (!decl)
14129 : break;
14130 575253082 : if (qualifying_scope)
14131 : {
14132 9536357 : if (check_for_bare_parameter_packs (qualifying_scope,
14133 9536357 : id_declarator->id_loc))
14134 6 : return error_mark_node;
14135 9536351 : if (at_function_scope_p ())
14136 : {
14137 : /* [dcl.meaning]
14138 :
14139 : A declarator-id shall not be qualified except
14140 : for ...
14141 :
14142 : None of the cases are permitted in block
14143 : scope. */
14144 0 : if (qualifying_scope == global_namespace)
14145 0 : error ("invalid use of qualified-name %<::%D%>",
14146 : decl);
14147 0 : else if (TYPE_P (qualifying_scope))
14148 0 : error ("invalid use of qualified-name %<%T::%D%>",
14149 : qualifying_scope, decl);
14150 : else
14151 0 : error ("invalid use of qualified-name %<%D::%D%>",
14152 : qualifying_scope, decl);
14153 0 : return error_mark_node;
14154 : }
14155 9536351 : else if (TYPE_P (qualifying_scope))
14156 : {
14157 9296031 : ctype = qualifying_scope;
14158 9296031 : if (!MAYBE_CLASS_TYPE_P (ctype))
14159 : {
14160 6 : error_at (id_declarator->id_loc,
14161 : "%q#T is not a class or namespace", ctype);
14162 6 : ctype = NULL_TREE;
14163 : }
14164 9296025 : else if (innermost_code != cdk_function
14165 486496 : && current_class_type
14166 9296040 : && !uniquely_derived_from_p (ctype,
14167 : current_class_type))
14168 : {
14169 9 : error_at (id_declarator->id_loc,
14170 : "invalid use of qualified-name %<%T::%D%>",
14171 : qualifying_scope, decl);
14172 9 : return error_mark_node;
14173 : }
14174 : }
14175 240320 : else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
14176 575253067 : in_namespace = qualifying_scope;
14177 : }
14178 575253067 : switch (TREE_CODE (decl))
14179 : {
14180 3204766 : case BIT_NOT_EXPR:
14181 3204766 : {
14182 3204766 : if (innermost_code != cdk_function)
14183 : {
14184 6 : error_at (EXPR_LOCATION (decl),
14185 : "declaration of %qE as non-function", decl);
14186 6 : return error_mark_node;
14187 : }
14188 3204760 : else if (!qualifying_scope
14189 3204760 : && !(current_class_type && at_class_scope_p ()))
14190 : {
14191 9 : error_at (EXPR_LOCATION (decl),
14192 : "declaration of %qE as non-member", decl);
14193 9 : return error_mark_node;
14194 : }
14195 :
14196 3204751 : tree type = TREE_OPERAND (decl, 0);
14197 3204751 : if (TYPE_P (type))
14198 3204748 : type = constructor_name (type);
14199 3204751 : name = identifier_to_locale (IDENTIFIER_POINTER (type));
14200 3204751 : dname = decl;
14201 : }
14202 3204751 : break;
14203 :
14204 2707490 : case TEMPLATE_ID_EXPR:
14205 2707490 : {
14206 2707490 : tree fns = TREE_OPERAND (decl, 0);
14207 :
14208 2707490 : dname = fns;
14209 3644015 : if (!identifier_p (dname))
14210 2707466 : dname = OVL_NAME (dname);
14211 : }
14212 : /* Fall through. */
14213 :
14214 572048301 : case IDENTIFIER_NODE:
14215 572048301 : if (identifier_p (decl))
14216 569340811 : dname = decl;
14217 :
14218 572048301 : if (IDENTIFIER_KEYWORD_P (dname))
14219 : {
14220 0 : error ("declarator-id missing; using reserved word %qD",
14221 : dname);
14222 0 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14223 : }
14224 572048301 : else if (!IDENTIFIER_CONV_OP_P (dname))
14225 571049703 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14226 : else
14227 : {
14228 998598 : gcc_assert (flags == NO_SPECIAL);
14229 998598 : flags = TYPENAME_FLAG;
14230 998598 : sfk = sfk_conversion;
14231 998598 : tree glob = get_global_binding (dname);
14232 998598 : if (glob && TREE_CODE (glob) == TYPE_DECL)
14233 0 : name = identifier_to_locale (IDENTIFIER_POINTER (dname));
14234 : else
14235 : name = "<invalid operator>";
14236 : }
14237 : break;
14238 :
14239 0 : default:
14240 0 : gcc_unreachable ();
14241 : }
14242 : break;
14243 : }
14244 :
14245 : case cdk_array:
14246 : case cdk_pointer:
14247 : case cdk_reference:
14248 : case cdk_ptrmem:
14249 : break;
14250 :
14251 : case cdk_decomp:
14252 956481595 : name = "structured binding";
14253 : break;
14254 :
14255 25 : case cdk_error:
14256 25 : return error_mark_node;
14257 :
14258 0 : default:
14259 0 : gcc_unreachable ();
14260 : }
14261 956481595 : if (id_declarator->kind == cdk_id)
14262 : break;
14263 : }
14264 :
14265 : /* [dcl.fct.edf]
14266 :
14267 : The declarator in a function-definition shall have the form
14268 : D1 ( parameter-declaration-clause) ... */
14269 1020644077 : if (funcdef_flag && innermost_code != cdk_function)
14270 : {
14271 3 : error_at (id_loc, "function definition does not declare parameters");
14272 3 : return error_mark_node;
14273 : }
14274 :
14275 1020644074 : if (flags == TYPENAME_FLAG
14276 1020644074 : && innermost_code != cdk_function
14277 3 : && ! (ctype && !declspecs->any_specifiers_p))
14278 : {
14279 3 : error_at (id_loc, "declaration of %qD as non-function", dname);
14280 3 : return error_mark_node;
14281 : }
14282 :
14283 1020644071 : if (dname && identifier_p (dname))
14284 : {
14285 572048295 : if (UDLIT_OPER_P (dname)
14286 572048295 : && innermost_code != cdk_function)
14287 : {
14288 6 : error_at (id_loc, "declaration of %qD as non-function", dname);
14289 6 : return error_mark_node;
14290 : }
14291 :
14292 572048289 : if (IDENTIFIER_ANY_OP_P (dname))
14293 : {
14294 36288896 : if (typedef_p)
14295 : {
14296 3 : error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
14297 3 : return error_mark_node;
14298 : }
14299 36288893 : else if (decl_context == PARM || decl_context == CATCHPARM)
14300 : {
14301 15 : error_at (id_loc, "declaration of %qD as parameter", dname);
14302 15 : return error_mark_node;
14303 : }
14304 : }
14305 : }
14306 :
14307 : /* Anything declared one level down from the top level
14308 : must be one of the parameters of a function
14309 : (because the body is at least two levels down). */
14310 :
14311 : /* This heuristic cannot be applied to C++ nodes! Fixed, however,
14312 : by not allowing C++ class definitions to specify their parameters
14313 : with xdecls (must be spec.d in the parmlist).
14314 :
14315 : Since we now wait to push a class scope until we are sure that
14316 : we are in a legitimate method context, we must set oldcname
14317 : explicitly (since current_class_name is not yet alive).
14318 :
14319 : We also want to avoid calling this a PARM if it is in a namespace. */
14320 :
14321 1020644047 : if (decl_context == NORMAL && !toplevel_bindings_p ())
14322 : {
14323 70859788 : cp_binding_level *b = current_binding_level;
14324 70859788 : current_binding_level = b->level_chain;
14325 70859788 : if (current_binding_level != 0 && toplevel_bindings_p ())
14326 : decl_context = PARM;
14327 70859788 : current_binding_level = b;
14328 : }
14329 :
14330 1020644047 : if (name == NULL)
14331 445171059 : name = decl_context == PARM ? "parameter" : "type name";
14332 :
14333 1020644047 : if (consteval_p && constexpr_p)
14334 : {
14335 6 : error_at (declspecs->locations[ds_consteval],
14336 : "both %qs and %qs specified", "constexpr", "consteval");
14337 6 : return error_mark_node;
14338 : }
14339 :
14340 1020644041 : if (concept_p && typedef_p)
14341 : {
14342 9 : error_at (declspecs->locations[ds_concept],
14343 : "%qs cannot appear in a typedef declaration", "concept");
14344 9 : return error_mark_node;
14345 : }
14346 :
14347 1020644032 : if (constexpr_p && typedef_p)
14348 : {
14349 3 : error_at (declspecs->locations[ds_constexpr],
14350 : "%qs cannot appear in a typedef declaration", "constexpr");
14351 3 : return error_mark_node;
14352 : }
14353 :
14354 1020644029 : if (consteval_p && typedef_p)
14355 : {
14356 3 : error_at (declspecs->locations[ds_consteval],
14357 : "%qs cannot appear in a typedef declaration", "consteval");
14358 3 : return error_mark_node;
14359 : }
14360 :
14361 1020644026 : if (constinit_p && typedef_p)
14362 : {
14363 3 : error_at (declspecs->locations[ds_constinit],
14364 : "%qs cannot appear in a typedef declaration", "constinit");
14365 3 : return error_mark_node;
14366 : }
14367 :
14368 : /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
14369 : keywords shall appear in a decl-specifier-seq." */
14370 1020644023 : if (constinit_p && constexpr_p)
14371 : {
14372 6 : gcc_rich_location richloc (declspecs->locations[ds_constinit]);
14373 6 : richloc.add_range (declspecs->locations[ds_constexpr]);
14374 6 : error_at (&richloc,
14375 : "can use at most one of the %<constinit%> and %<constexpr%> "
14376 : "specifiers");
14377 6 : return error_mark_node;
14378 6 : }
14379 :
14380 : /* If there were multiple types specified in the decl-specifier-seq,
14381 : issue an error message. */
14382 1020644017 : if (declspecs->multiple_types_p)
14383 : {
14384 1501 : error_at (typespec_loc,
14385 : "two or more data types in declaration of %qs", name);
14386 1501 : return error_mark_node;
14387 : }
14388 :
14389 1020642516 : if (declspecs->conflicting_specifiers_p)
14390 31 : return error_mark_node;
14391 :
14392 : /* Extract the basic type from the decl-specifier-seq. */
14393 1020642485 : type = declspecs->type;
14394 1020642485 : if (type == error_mark_node)
14395 : {
14396 1193 : type = NULL_TREE;
14397 1193 : type_was_error_mark_node = true;
14398 : }
14399 :
14400 : /* Ignore erroneous attributes. */
14401 1020642485 : if (attrlist && *attrlist == error_mark_node)
14402 12 : *attrlist = NULL_TREE;
14403 :
14404 : /* An object declared as __attribute__((unavailable)) suppresses
14405 : any reports of being declared with unavailable or deprecated
14406 : items. An object declared as __attribute__((deprecated))
14407 : suppresses warnings of uses of other deprecated items. */
14408 1020642485 : auto ds = make_temp_override (deprecated_state);
14409 1020642485 : if (attrlist && lookup_attribute ("unavailable", *attrlist))
14410 171 : deprecated_state = UNAVAILABLE_DEPRECATED_SUPPRESS;
14411 1020642314 : else if (attrlist && lookup_attribute ("deprecated", *attrlist))
14412 783138 : deprecated_state = DEPRECATED_SUPPRESS;
14413 :
14414 1020642485 : cp_handle_deprecated_or_unavailable (type);
14415 1020642485 : if (type && TREE_CODE (type) == TYPE_DECL)
14416 : {
14417 710868036 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
14418 710868036 : typedef_decl = type;
14419 710868036 : type = TREE_TYPE (typedef_decl);
14420 710868036 : if (DECL_ARTIFICIAL (typedef_decl))
14421 516716908 : cp_handle_deprecated_or_unavailable (type);
14422 : }
14423 : /* No type at all: default to `int', and set DEFAULTED_INT
14424 : because it was not a user-defined typedef. */
14425 1020642485 : if (type == NULL_TREE)
14426 : {
14427 38065286 : if (signed_p || unsigned_p || long_p || short_p)
14428 : {
14429 : /* These imply 'int'. */
14430 8957191 : type = integer_type_node;
14431 8957191 : defaulted_int = 1;
14432 : }
14433 : /* If we just have "complex", it is equivalent to "complex double". */
14434 29108095 : else if (!longlong && !explicit_intN
14435 29108095 : && decl_spec_seq_has_spec_p (declspecs, ds_complex))
14436 : {
14437 81 : type = double_type_node;
14438 81 : pedwarn (declspecs->locations[ds_complex], OPT_Wpedantic,
14439 : "ISO C++ does not support plain %<complex%> meaning "
14440 : "%<double complex%>");
14441 : }
14442 : }
14443 : /* Gather flags. */
14444 1020642485 : explicit_int = declspecs->explicit_int_p;
14445 1020642485 : explicit_char = declspecs->explicit_char_p;
14446 :
14447 : #if 0
14448 : /* See the code below that used this. */
14449 : if (typedef_decl)
14450 : decl_attr = DECL_ATTRIBUTES (typedef_decl);
14451 : #endif
14452 1020642485 : typedef_type = type;
14453 :
14454 1020642485 : if (sfk == sfk_conversion || sfk == sfk_deduction_guide)
14455 2176799 : ctor_return_type = TREE_TYPE (dname);
14456 : else
14457 : ctor_return_type = ctype;
14458 :
14459 1020642485 : if (sfk != sfk_none)
14460 : {
14461 29106502 : type = check_special_function_return_type (sfk, type,
14462 : ctor_return_type,
14463 : type_quals,
14464 : &declarator,
14465 : declspecs->locations);
14466 29106502 : type_quals = TYPE_UNQUALIFIED;
14467 : }
14468 991535983 : else if (type == NULL_TREE)
14469 : {
14470 1593 : int is_main;
14471 :
14472 1593 : explicit_int = -1;
14473 :
14474 : /* We handle `main' specially here, because 'main () { }' is so
14475 : common. With no options, it is allowed. With -Wreturn-type,
14476 : it is a warning. It is only an error with -pedantic-errors. */
14477 3186 : is_main = (funcdef_flag
14478 3420 : && dname && identifier_p (dname)
14479 234 : && MAIN_NAME_P (dname)
14480 68 : && ctype == NULL_TREE
14481 68 : && in_namespace == NULL_TREE
14482 1661 : && current_namespace == global_namespace);
14483 :
14484 1593 : if (type_was_error_mark_node)
14485 : /* We've already issued an error, don't complain more. */;
14486 400 : else if (in_system_header_at (id_loc) || flag_ms_extensions)
14487 : /* Allow it, sigh. */;
14488 338 : else if (! is_main)
14489 276 : permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
14490 : name);
14491 62 : else if (pedantic)
14492 4 : pedwarn (id_loc, OPT_Wpedantic,
14493 : "ISO C++ forbids declaration of %qs with no type", name);
14494 : else
14495 58 : warning_at (id_loc, OPT_Wreturn_type,
14496 : "ISO C++ forbids declaration of %qs with no type", name);
14497 :
14498 1593 : if (type_was_error_mark_node && template_parm_flag)
14499 : /* FIXME we should be able to propagate the error_mark_node as is
14500 : for other contexts too. */
14501 149 : type = error_mark_node;
14502 : else
14503 1444 : type = integer_type_node;
14504 : }
14505 :
14506 1020642485 : ctype = NULL_TREE;
14507 :
14508 1020642485 : if (explicit_intN)
14509 : {
14510 1078550 : if (! int_n_enabled_p[declspecs->int_n_idx])
14511 : {
14512 0 : error_at (declspecs->locations[ds_type_spec],
14513 : "%<__int%d%> is not supported by this target",
14514 0 : int_n_data[declspecs->int_n_idx].bitsize);
14515 0 : explicit_intN = false;
14516 : }
14517 : /* Don't pedwarn if the alternate "__intN__" form has been used instead
14518 : of "__intN". */
14519 1078550 : else if (!int_n_alt && pedantic)
14520 6842 : pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
14521 : "ISO C++ does not support %<__int%d%> for %qs",
14522 6842 : int_n_data[declspecs->int_n_idx].bitsize, name);
14523 : }
14524 :
14525 : /* Now process the modifiers that were specified
14526 : and check for invalid combinations. */
14527 :
14528 : /* Long double is a special combination. */
14529 1020642485 : if (long_p && !longlong && TYPE_MAIN_VARIANT (type) == double_type_node)
14530 : {
14531 8686660 : long_p = false;
14532 8686660 : type = cp_build_qualified_type (long_double_type_node,
14533 : cp_type_quals (type));
14534 : }
14535 :
14536 : /* Check all other uses of type modifiers. */
14537 :
14538 1020642485 : if (unsigned_p || signed_p || long_p || short_p)
14539 : {
14540 20742699 : location_t loc;
14541 20742699 : const char *key;
14542 20742699 : if (unsigned_p)
14543 : {
14544 14091085 : key = "unsigned";
14545 14091085 : loc = declspecs->locations[ds_unsigned];
14546 : }
14547 6651614 : else if (signed_p)
14548 : {
14549 1022207 : key = "signed";
14550 1022207 : loc = declspecs->locations[ds_signed];
14551 : }
14552 5629407 : else if (longlong)
14553 : {
14554 2194458 : key = "long long";
14555 2194458 : loc = declspecs->locations[ds_long_long];
14556 : }
14557 3434949 : else if (long_p)
14558 : {
14559 2889233 : key = "long";
14560 2889233 : loc = declspecs->locations[ds_long];
14561 : }
14562 : else /* if (short_p) */
14563 : {
14564 545716 : key = "short";
14565 545716 : loc = declspecs->locations[ds_short];
14566 : }
14567 :
14568 20742699 : int ok = 0;
14569 :
14570 20742699 : if (signed_p && unsigned_p)
14571 54 : complain_about_incompatible_declspecs
14572 54 : ("signed", declspecs->locations[ds_signed],
14573 : "unsigned", declspecs->locations[ds_unsigned]);
14574 20742645 : else if (long_p && short_p)
14575 12 : complain_about_incompatible_declspecs
14576 12 : ("long", declspecs->locations[ds_long],
14577 : "short", declspecs->locations[ds_short]);
14578 20742633 : else if (TREE_CODE (type) != INTEGER_TYPE
14579 20742620 : || type == char8_type_node
14580 20742596 : || type == char16_type_node
14581 20742572 : || type == char32_type_node
14582 20742548 : || ((long_p || short_p)
14583 10871637 : && (explicit_char || explicit_intN)))
14584 418 : error_at (loc, "%qs specified with %qT", key, type);
14585 20742215 : else if (!explicit_int && !defaulted_int
14586 20742215 : && !explicit_char && !explicit_intN)
14587 : {
14588 30 : if (typedef_decl)
14589 : {
14590 27 : pedwarn (loc, OPT_Wpedantic,
14591 : "%qs specified with typedef-name %qD",
14592 : key, typedef_decl);
14593 27 : ok = !flag_pedantic_errors;
14594 : /* PR108099: __int128_t comes from c_common_nodes_and_builtins,
14595 : and is not built as a typedef. */
14596 27 : if (is_typedef_decl (typedef_decl))
14597 18 : type = DECL_ORIGINAL_TYPE (typedef_decl);
14598 : }
14599 3 : else if (declspecs->decltype_p)
14600 0 : error_at (loc, "%qs specified with %<decltype%>", key);
14601 : else
14602 3 : error_at (loc, "%qs specified with %<typeof%>", key);
14603 : }
14604 : else
14605 : ok = 1;
14606 :
14607 : /* Discard the type modifiers if they are invalid. */
14608 514 : if (! ok)
14609 : {
14610 : unsigned_p = false;
14611 : signed_p = false;
14612 : long_p = false;
14613 : short_p = false;
14614 : longlong = 0;
14615 : }
14616 : }
14617 :
14618 : /* Decide whether an integer type is signed or not.
14619 : Optionally treat bitfields as signed by default. */
14620 1020641995 : if (unsigned_p
14621 : /* [class.bit]
14622 :
14623 : It is implementation-defined whether a plain (neither
14624 : explicitly signed or unsigned) char, short, int, or long
14625 : bit-field is signed or unsigned.
14626 :
14627 : Naturally, we extend this to long long as well. Note that
14628 : this does not include wchar_t. */
14629 1020642485 : || (bitfield && !flag_signed_bitfields
14630 18 : && !signed_p
14631 : /* A typedef for plain `int' without `signed' can be
14632 : controlled just like plain `int', but a typedef for
14633 : `signed int' cannot be so controlled. */
14634 18 : && !(typedef_decl
14635 18 : && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl))
14636 13 : && TREE_CODE (type) == INTEGER_TYPE
14637 10 : && !same_type_p (TYPE_MAIN_VARIANT (type), wchar_type_node)))
14638 : {
14639 14090870 : if (explicit_intN)
14640 509930 : type = int_n_trees[declspecs->int_n_idx].unsigned_type;
14641 13580940 : else if (longlong)
14642 1391773 : type = long_long_unsigned_type_node;
14643 12189167 : else if (long_p)
14644 2263356 : type = long_unsigned_type_node;
14645 9925811 : else if (short_p)
14646 1383363 : type = short_unsigned_type_node;
14647 8542448 : else if (type == char_type_node)
14648 1869367 : type = unsigned_char_type_node;
14649 6673081 : else if (typedef_decl)
14650 25 : type = c_common_unsigned_type (type);
14651 : else
14652 6673056 : type = unsigned_type_node;
14653 : }
14654 1006551615 : else if (signed_p && type == char_type_node)
14655 676912 : type = signed_char_type_node;
14656 1005874703 : else if (explicit_intN)
14657 568620 : type = int_n_trees[declspecs->int_n_idx].signed_type;
14658 1005306083 : else if (longlong)
14659 2256181 : type = long_long_integer_type_node;
14660 1003049902 : else if (long_p)
14661 2954839 : type = long_integer_type_node;
14662 1000095063 : else if (short_p)
14663 621792 : type = short_integer_type_node;
14664 999473271 : else if (signed_p && typedef_decl)
14665 9 : type = c_common_signed_type (type);
14666 :
14667 1020642485 : if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
14668 : {
14669 1176495 : if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
14670 3 : error_at (declspecs->locations[ds_complex],
14671 : "complex invalid for %qs", name);
14672 : /* If a modifier is specified, the resulting complex is the complex
14673 : form of TYPE. E.g, "complex short" is "complex short int". */
14674 1176492 : else if (type == integer_type_node)
14675 171 : type = complex_integer_type_node;
14676 1176321 : else if (type == float_type_node)
14677 335993 : type = complex_float_type_node;
14678 840328 : else if (type == double_type_node)
14679 336530 : type = complex_double_type_node;
14680 503798 : else if (type == long_double_type_node)
14681 336034 : type = complex_long_double_type_node;
14682 : else
14683 167764 : type = build_complex_type (type);
14684 : }
14685 :
14686 : /* If we're using the injected-class-name to form a compound type or a
14687 : declaration, replace it with the underlying class so we don't get
14688 : redundant typedefs in the debug output. But if we are returning the
14689 : type unchanged, leave it alone so that it's available to
14690 : maybe_get_template_decl_from_type_decl. */
14691 200885181 : if (CLASS_TYPE_P (type)
14692 200823039 : && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
14693 34106858 : && type == TREE_TYPE (TYPE_NAME (type))
14694 1054749343 : && (declarator || type_quals))
14695 32617665 : type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
14696 :
14697 1020642485 : type_quals |= cp_type_quals (type);
14698 2041284970 : type = cp_build_qualified_type
14699 2041284970 : (type, type_quals, ((((typedef_decl && !DECL_ARTIFICIAL (typedef_decl))
14700 826491357 : || declspecs->decltype_p)
14701 : ? tf_ignore_bad_quals : 0) | tf_warning_or_error));
14702 : /* We might have ignored or rejected some of the qualifiers. */
14703 1020642485 : type_quals = cp_type_quals (type);
14704 :
14705 1005180570 : if (cxx_dialect >= cxx17 && type && is_auto (type)
14706 21909435 : && innermost_code != cdk_function
14707 : /* Placeholder in parm gets a better error below. */
14708 13716118 : && !(decl_context == PARM || decl_context == CATCHPARM)
14709 1034330493 : && id_declarator && declarator != id_declarator)
14710 1125635 : if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
14711 : {
14712 16 : auto_diagnostic_group g;
14713 16 : gcc_rich_location richloc (typespec_loc);
14714 16 : richloc.add_fixit_insert_after ("<>");
14715 16 : error_at (&richloc, "missing template argument list after %qE; "
14716 : "for deduction, template placeholder must be followed "
14717 : "by a simple declarator-id", tmpl);
14718 16 : inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
14719 16 : type = error_mark_node;
14720 16 : }
14721 :
14722 1020642485 : staticp = 0;
14723 1020642485 : inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
14724 1020642485 : virtualp = decl_spec_seq_has_spec_p (declspecs, ds_virtual);
14725 1020642485 : explicitp = decl_spec_seq_has_spec_p (declspecs, ds_explicit);
14726 :
14727 1020642485 : storage_class = declspecs->storage_class;
14728 1020642485 : if (storage_class == sc_static)
14729 23122400 : staticp = 1 + (decl_context == FIELD);
14730 997520085 : else if (decl_context == FIELD && sfk == sfk_deduction_guide)
14731 : /* Treat class-scope deduction guides as static member functions
14732 : so that they get a FUNCTION_TYPE instead of a METHOD_TYPE. */
14733 22802822 : staticp = 2;
14734 :
14735 1020642485 : if (virtualp)
14736 : {
14737 4078380 : if (staticp == 2)
14738 : {
14739 21 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
14740 21 : richloc.add_range (declspecs->locations[ds_storage_class]);
14741 21 : error_at (&richloc, "member %qD cannot be declared both %<virtual%> "
14742 : "and %<static%>", dname);
14743 21 : storage_class = sc_none;
14744 21 : staticp = 0;
14745 21 : }
14746 4078380 : if (constexpr_p && pedantic && cxx_dialect < cxx20)
14747 : {
14748 6 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
14749 6 : richloc.add_range (declspecs->locations[ds_constexpr]);
14750 6 : pedwarn (&richloc, OPT_Wc__20_extensions, "member %qD can be "
14751 : "declared both %<virtual%> and %<constexpr%> only in "
14752 : "%<-std=c++20%> or %<-std=gnu++20%>", dname);
14753 6 : }
14754 : }
14755 1020642485 : friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
14756 :
14757 : /* Issue errors about use of storage classes for parameters. */
14758 1020642485 : if (decl_context == PARM)
14759 : {
14760 289055840 : if (typedef_p)
14761 : {
14762 24 : error_at (declspecs->locations[ds_typedef],
14763 : "typedef declaration invalid in parameter declaration");
14764 24 : return error_mark_node;
14765 : }
14766 289055816 : else if (template_parm_flag && storage_class != sc_none)
14767 : {
14768 16 : error_at (min_location (declspecs->locations[ds_thread],
14769 : declspecs->locations[ds_storage_class]),
14770 : "storage class specified for template parameter %qs",
14771 : name);
14772 16 : return error_mark_node;
14773 : }
14774 289055800 : else if (storage_class == sc_static
14775 289055800 : || storage_class == sc_extern
14776 289055797 : || thread_p)
14777 : {
14778 9 : error_at (min_location (declspecs->locations[ds_thread],
14779 : declspecs->locations[ds_storage_class]),
14780 : "storage class specified for parameter %qs", name);
14781 9 : return error_mark_node;
14782 : }
14783 :
14784 : /* Function parameters cannot be concept. */
14785 289055791 : if (concept_p)
14786 : {
14787 9 : error_at (declspecs->locations[ds_concept],
14788 : "a parameter cannot be declared %qs", "concept");
14789 9 : concept_p = 0;
14790 9 : constexpr_p = 0;
14791 : }
14792 : /* Function parameters cannot be constexpr. If we saw one, moan
14793 : and pretend it wasn't there. */
14794 289055782 : else if (constexpr_p)
14795 : {
14796 9 : error_at (declspecs->locations[ds_constexpr],
14797 : "a parameter cannot be declared %qs", "constexpr");
14798 9 : constexpr_p = 0;
14799 : }
14800 289055791 : if (constinit_p)
14801 : {
14802 6 : error_at (declspecs->locations[ds_constinit],
14803 : "a parameter cannot be declared %qs", "constinit");
14804 6 : constinit_p = 0;
14805 : }
14806 289055791 : if (consteval_p)
14807 : {
14808 3 : error_at (declspecs->locations[ds_consteval],
14809 : "a parameter cannot be declared %qs", "consteval");
14810 3 : consteval_p = 0;
14811 : }
14812 : }
14813 :
14814 : /* Give error if `virtual' is used outside of class declaration. */
14815 1020642436 : if (virtualp
14816 4078380 : && (current_class_name == NULL_TREE || decl_context != FIELD))
14817 : {
14818 68 : error_at (declspecs->locations[ds_virtual],
14819 : "%<virtual%> outside class declaration");
14820 68 : virtualp = 0;
14821 : }
14822 :
14823 1020642436 : if (innermost_code == cdk_decomp)
14824 : {
14825 210202 : location_t loc = (declarator->kind == cdk_reference
14826 219966 : ? declarator->declarator->id_loc : declarator->id_loc);
14827 219966 : if (inlinep)
14828 29 : error_at (declspecs->locations[ds_inline],
14829 : "structured binding declaration cannot be %qs", "inline");
14830 219966 : if (typedef_p)
14831 29 : error_at (declspecs->locations[ds_typedef],
14832 : "structured binding declaration cannot be %qs", "typedef");
14833 219966 : if (constexpr_p && !concept_p && cxx_dialect < cxx26)
14834 99 : pedwarn (declspecs->locations[ds_constexpr], OPT_Wc__26_extensions,
14835 : "structured binding declaration can be %qs only with "
14836 : "%<-std=c++2c%> or %<-std=gnu++2c%>", "constexpr");
14837 219966 : if (consteval_p)
14838 13 : error_at (declspecs->locations[ds_consteval], "structured "
14839 : "binding declaration cannot be %qs", "consteval");
14840 219966 : if (thread_p && cxx_dialect < cxx20)
14841 75 : pedwarn (declspecs->locations[ds_thread], OPT_Wc__20_extensions,
14842 : "structured binding declaration can be %qs only in "
14843 : "%<-std=c++20%> or %<-std=gnu++20%>",
14844 75 : declspecs->gnu_thread_keyword_p
14845 : ? "__thread" : "thread_local");
14846 219966 : if (concept_p)
14847 : {
14848 0 : error_at (declspecs->locations[ds_concept],
14849 : "structured binding declaration cannot be %qs", "concept");
14850 0 : constexpr_p = 0;
14851 : }
14852 : /* [dcl.struct.bind] "A cv that includes volatile is deprecated." */
14853 219966 : if (type_quals & TYPE_QUAL_VOLATILE)
14854 26 : warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
14855 : "%<volatile%>-qualified structured binding is deprecated");
14856 219966 : switch (storage_class)
14857 : {
14858 : case sc_none:
14859 : break;
14860 28 : case sc_register:
14861 28 : error_at (loc, "structured binding declaration cannot be %qs",
14862 : "register");
14863 28 : break;
14864 246 : case sc_static:
14865 246 : if (cxx_dialect < cxx20)
14866 185 : pedwarn (loc, OPT_Wc__20_extensions,
14867 : "structured binding declaration can be %qs only in "
14868 : "%<-std=c++20%> or %<-std=gnu++20%>", "static");
14869 : break;
14870 29 : case sc_extern:
14871 29 : error_at (loc, "structured binding declaration cannot be %qs",
14872 : "extern");
14873 29 : break;
14874 28 : case sc_mutable:
14875 28 : error_at (loc, "structured binding declaration cannot be %qs",
14876 : "mutable");
14877 28 : break;
14878 0 : case sc_auto:
14879 0 : error_at (loc, "structured binding declaration cannot be "
14880 : "C++98 %<auto%>");
14881 0 : break;
14882 0 : default:
14883 0 : gcc_unreachable ();
14884 : }
14885 219966 : if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
14886 219966 : || TYPE_IDENTIFIER (type) != auto_identifier)
14887 : {
14888 3 : if (type != error_mark_node)
14889 : {
14890 3 : auto_diagnostic_group d;
14891 3 : error_at (loc, "structured binding declaration cannot have "
14892 : "type %qT", type);
14893 3 : inform (loc,
14894 : "type must be cv-qualified %<auto%> or reference to "
14895 : "cv-qualified %<auto%>");
14896 3 : }
14897 3 : type = build_qualified_type (make_auto (), type_quals);
14898 3 : declspecs->type = type;
14899 : }
14900 219963 : else if (PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
14901 51 : pedwarn (loc, OPT_Wpedantic,
14902 : "structured binding declaration cannot have constrained "
14903 : "%<auto%> type %qT", type);
14904 219966 : inlinep = 0;
14905 219966 : typedef_p = 0;
14906 219966 : consteval_p = 0;
14907 219966 : concept_p = 0;
14908 219966 : if (storage_class != sc_static)
14909 : {
14910 219720 : storage_class = sc_none;
14911 219720 : declspecs->storage_class = sc_none;
14912 : }
14913 : }
14914 :
14915 : /* Static anonymous unions are dealt with here. */
14916 1020642436 : if (staticp && decl_context == TYPENAME
14917 0 : && declspecs->type
14918 1020642436 : && ANON_AGGR_TYPE_P (declspecs->type))
14919 : decl_context = FIELD;
14920 :
14921 : /* Warn about storage classes that are invalid for certain
14922 : kinds of declarations (parameters, typenames, etc.). */
14923 1020642436 : if (thread_p
14924 19875 : && ((storage_class
14925 19875 : && storage_class != sc_extern
14926 526 : && storage_class != sc_static)
14927 19864 : || typedef_p))
14928 : {
14929 17 : location_t loc
14930 17 : = min_location (declspecs->locations[ds_thread],
14931 : declspecs->locations[ds_storage_class]);
14932 17 : error_at (loc, "multiple storage classes in declaration of %qs", name);
14933 17 : thread_p = false;
14934 : }
14935 1020642436 : if (decl_context != NORMAL
14936 855110417 : && ((storage_class != sc_none
14937 855110417 : && storage_class != sc_mutable)
14938 832307608 : || thread_p))
14939 : {
14940 22802812 : if ((decl_context == PARM || decl_context == CATCHPARM)
14941 36 : && (storage_class == sc_register
14942 36 : || storage_class == sc_auto))
14943 : ;
14944 22802776 : else if (typedef_p)
14945 : ;
14946 22802776 : else if (decl_context == FIELD
14947 : /* C++ allows static class elements. */
14948 22802776 : && storage_class == sc_static)
14949 : /* C++ also allows inlines and signed and unsigned elements,
14950 : but in those cases we don't come in here. */
14951 : ;
14952 : else
14953 : {
14954 15 : location_t loc
14955 15 : = min_location (declspecs->locations[ds_thread],
14956 : declspecs->locations[ds_storage_class]);
14957 15 : if (decl_context == FIELD)
14958 15 : error_at (loc, "storage class specified for %qs", name);
14959 0 : else if (decl_context == PARM || decl_context == CATCHPARM)
14960 0 : error_at (loc, "storage class specified for parameter %qs", name);
14961 : else
14962 0 : error_at (loc, "storage class specified for typename");
14963 15 : if (storage_class == sc_register
14964 15 : || storage_class == sc_auto
14965 15 : || storage_class == sc_extern
14966 3 : || thread_p)
14967 15 : storage_class = sc_none;
14968 : }
14969 : }
14970 997839624 : else if (storage_class == sc_extern && funcdef_flag
14971 997839624 : && ! toplevel_bindings_p ())
14972 0 : error ("nested function %qs declared %<extern%>", name);
14973 997839624 : else if (toplevel_bindings_p ())
14974 : {
14975 464256208 : if (storage_class == sc_auto)
14976 2 : error_at (declspecs->locations[ds_storage_class],
14977 : "top-level declaration of %qs specifies %<auto%>", name);
14978 : }
14979 533583416 : else if (thread_p
14980 533583416 : && storage_class != sc_extern
14981 237 : && storage_class != sc_static)
14982 : {
14983 204 : if (declspecs->gnu_thread_keyword_p)
14984 49 : pedwarn (declspecs->locations[ds_thread],
14985 49 : 0, "function-scope %qs implicitly auto and "
14986 : "declared %<__thread%>", name);
14987 :
14988 : /* When thread_local is applied to a variable of block scope the
14989 : storage-class-specifier static is implied if it does not appear
14990 : explicitly. */
14991 204 : storage_class = declspecs->storage_class = sc_static;
14992 204 : staticp = 1;
14993 : }
14994 :
14995 1020642436 : if (storage_class && friendp)
14996 : {
14997 12 : error_at (min_location (declspecs->locations[ds_thread],
14998 : declspecs->locations[ds_storage_class]),
14999 : "storage class specifiers invalid in friend function "
15000 : "declarations");
15001 12 : storage_class = sc_none;
15002 12 : staticp = 0;
15003 : }
15004 :
15005 1020642436 : if (!id_declarator)
15006 : unqualified_id = NULL_TREE;
15007 : else
15008 : {
15009 575251491 : unqualified_id = id_declarator->u.id.unqualified_name;
15010 575251491 : switch (TREE_CODE (unqualified_id))
15011 : {
15012 3204751 : case BIT_NOT_EXPR:
15013 3204751 : unqualified_id = TREE_OPERAND (unqualified_id, 0);
15014 3204751 : if (TYPE_P (unqualified_id))
15015 3204748 : unqualified_id = constructor_name (unqualified_id);
15016 : break;
15017 :
15018 : case IDENTIFIER_NODE:
15019 : case TEMPLATE_ID_EXPR:
15020 : break;
15021 :
15022 0 : default:
15023 0 : gcc_unreachable ();
15024 : }
15025 : }
15026 :
15027 1020642436 : if (declspecs->std_attributes)
15028 : {
15029 723 : location_t attr_loc = declspecs->locations[ds_std_attribute];
15030 723 : auto_diagnostic_group d;
15031 723 : if (any_nonignored_attribute_p (declspecs->std_attributes)
15032 723 : && warning_at (attr_loc, OPT_Wattributes, "attribute ignored"))
15033 720 : inform (attr_loc, "an attribute that appertains to a type-specifier "
15034 : "is ignored");
15035 723 : }
15036 :
15037 : /* Skip over build_memfn_type when a FUNCTION_DECL is an xobj memfn. */
15038 : bool is_xobj_member_function = false;
15039 : /* Determine the type of the entity declared by recurring on the
15040 : declarator. */
15041 1401649001 : for (; declarator; declarator = declarator->declarator)
15042 : {
15043 956478048 : const cp_declarator *inner_declarator;
15044 956478048 : tree attrs;
15045 :
15046 956478048 : if (type == error_mark_node)
15047 604 : return error_mark_node;
15048 :
15049 956477721 : attrs = declarator->attributes;
15050 956477721 : if (attrs)
15051 : {
15052 13469 : int attr_flags;
15053 :
15054 13469 : attr_flags = 0;
15055 13469 : if (declarator->kind == cdk_id)
15056 12761 : attr_flags |= (int) ATTR_FLAG_DECL_NEXT;
15057 13469 : if (declarator->kind == cdk_function)
15058 691 : attr_flags |= (int) ATTR_FLAG_FUNCTION_NEXT;
15059 13469 : if (declarator->kind == cdk_array)
15060 2 : attr_flags |= (int) ATTR_FLAG_ARRAY_NEXT;
15061 13469 : tree late_attrs = NULL_TREE;
15062 13469 : if (decl_context != PARM && decl_context != TYPENAME)
15063 : /* Assume that any attributes that get applied late to
15064 : templates will DTRT when applied to the declaration
15065 : as a whole. */
15066 13457 : late_attrs = splice_template_attributes (&attrs, type);
15067 13469 : returned_attrs = decl_attributes (&type,
15068 : attr_chainon (returned_attrs,
15069 : attrs),
15070 : attr_flags);
15071 13469 : returned_attrs = attr_chainon (late_attrs, returned_attrs);
15072 : }
15073 :
15074 956477721 : inner_declarator = declarator->declarator;
15075 :
15076 : /* We don't want to warn in parameter context because we don't
15077 : yet know if the parse will succeed, and this might turn out
15078 : to be a constructor call. */
15079 956477721 : if (decl_context != PARM
15080 956477721 : && decl_context != TYPENAME
15081 555227250 : && !typedef_p
15082 507702343 : && declarator->parenthesized != UNKNOWN_LOCATION
15083 : /* If the type is class-like and the inner name used a
15084 : global namespace qualifier, we need the parens.
15085 : Unfortunately all we can tell is whether a qualified name
15086 : was used or not. */
15087 956477902 : && !(inner_declarator
15088 126 : && inner_declarator->kind == cdk_id
15089 108 : && inner_declarator->u.id.qualifying_scope
15090 18 : && (MAYBE_CLASS_TYPE_P (type)
15091 12 : || TREE_CODE (type) == ENUMERAL_TYPE)))
15092 : {
15093 169 : auto_diagnostic_group d;
15094 169 : if (warning_at (declarator->parenthesized, OPT_Wparentheses,
15095 : "unnecessary parentheses in declaration of %qs",
15096 : name))
15097 : {
15098 42 : gcc_rich_location iloc (declarator->parenthesized);
15099 42 : iloc.add_fixit_remove (get_start (declarator->parenthesized));
15100 42 : iloc.add_fixit_remove (get_finish (declarator->parenthesized));
15101 42 : inform (&iloc, "remove parentheses");
15102 42 : }
15103 169 : }
15104 956477721 : if (declarator->kind == cdk_id || declarator->kind == cdk_decomp)
15105 : break;
15106 :
15107 381006842 : switch (declarator->kind)
15108 : {
15109 3503931 : case cdk_array:
15110 7007862 : type = create_array_type_for_decl (dname, type,
15111 3503931 : declarator->u.array.bounds,
15112 3503931 : declarator->id_loc);
15113 3503931 : if (!valid_array_size_p (dname
15114 : ? declarator->id_loc : input_location,
15115 : type, dname))
15116 267 : type = error_mark_node;
15117 :
15118 3503931 : if (declarator->std_attributes)
15119 : /* [dcl.array]/1:
15120 :
15121 : The optional attribute-specifier-seq appertains to the
15122 : array type. */
15123 193 : cplus_decl_attributes (&type, declarator->std_attributes, 0);
15124 : break;
15125 :
15126 187114472 : case cdk_function:
15127 187114472 : {
15128 187114472 : tree arg_types;
15129 187114472 : int funcdecl_p;
15130 :
15131 : /* Declaring a function type. */
15132 :
15133 : /* Pick up type qualifiers which should be applied to `this'. */
15134 187114472 : memfn_quals = declarator->u.function.qualifiers;
15135 : /* Pick up virt-specifiers. */
15136 187114472 : virt_specifiers = declarator->u.function.virt_specifiers;
15137 : /* And ref-qualifier, too */
15138 187114472 : rqual = declarator->u.function.ref_qualifier;
15139 : /* And tx-qualifier. */
15140 187114472 : tree tx_qual = declarator->u.function.tx_qualifier;
15141 : /* Pick up the exception specifications. */
15142 187114472 : raises = declarator->u.function.exception_specification;
15143 : /* If the exception-specification is ill-formed, let's pretend
15144 : there wasn't one. */
15145 187114472 : if (raises == error_mark_node)
15146 9 : raises = NULL_TREE;
15147 :
15148 374228944 : auto find_xobj_parm = [](tree parm_list)
15149 : {
15150 : /* There is no need to iterate over the list,
15151 : only the first parm can be a valid xobj parm. */
15152 374009060 : if (!parm_list || TREE_PURPOSE (parm_list) != this_identifier)
15153 : return NULL_TREE;
15154 : /* If we make it here, we are looking at an xobj parm.
15155 :
15156 : Non-null 'purpose' usually means the parm has a default
15157 : argument, we don't want to violate this assumption. */
15158 75047 : TREE_PURPOSE (parm_list) = NULL_TREE;
15159 75047 : return TREE_VALUE (parm_list);
15160 : };
15161 :
15162 187114472 : tree xobj_parm
15163 187114472 : = find_xobj_parm (declarator->u.function.parameters);
15164 187114472 : is_xobj_member_function = xobj_parm;
15165 :
15166 187114472 : if (xobj_parm && cxx_dialect < cxx23)
15167 41991 : pedwarn (DECL_SOURCE_LOCATION (xobj_parm), OPT_Wc__23_extensions,
15168 : "explicit object member function only available "
15169 : "with %<-std=c++23%> or %<-std=gnu++23%>");
15170 :
15171 187114472 : if (xobj_parm && decl_context == TYPENAME)
15172 : {
15173 : /* We inform in every case, just differently depending on what
15174 : case it is. */
15175 6 : auto_diagnostic_group d;
15176 6 : bool ptr_type = true;
15177 : /* If declarator->kind is cdk_function and we are at the end of
15178 : the declarator chain, we are looking at a function type. */
15179 6 : if (!declarator->declarator)
15180 : {
15181 2 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15182 : "a function type cannot "
15183 : "have an explicit object parameter");
15184 2 : ptr_type = false;
15185 : }
15186 4 : else if (declarator->declarator->kind == cdk_pointer)
15187 2 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15188 : "a pointer to function type cannot "
15189 : "have an explicit object parameter");
15190 2 : else if (declarator->declarator->kind == cdk_ptrmem)
15191 2 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15192 : "a pointer to member function type "
15193 : "cannot have an explicit object parameter");
15194 : else
15195 0 : gcc_unreachable ();
15196 :
15197 : /* The locations being used here are probably not correct. */
15198 4 : if (ptr_type)
15199 4 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15200 : "the type of a pointer to explicit object member "
15201 : "function is a regular pointer to function type");
15202 : else
15203 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15204 : "the type of an explicit object "
15205 : "member function is a regular function type");
15206 : /* Ideally we should synthesize the correct syntax
15207 : for the user, perhaps this could be added later. */
15208 6 : }
15209 : /* Since a valid xobj parm has its purpose cleared in find_xobj_parm
15210 : the first parm node will never erroneously be detected here. */
15211 187114472 : {
15212 187114472 : auto_diagnostic_group d;
15213 187114472 : bool bad_xobj_parm_encountered = false;
15214 187114472 : for (tree parm = declarator->u.function.parameters;
15215 464529076 : parm && parm != void_list_node;
15216 277414604 : parm = TREE_CHAIN (parm))
15217 : {
15218 277414604 : if (TREE_PURPOSE (parm) != this_identifier)
15219 277414598 : continue;
15220 6 : bad_xobj_parm_encountered = true;
15221 6 : TREE_PURPOSE (parm) = NULL_TREE;
15222 6 : gcc_rich_location bad_xobj_parm
15223 6 : (DECL_SOURCE_LOCATION (TREE_VALUE (parm)));
15224 6 : error_at (&bad_xobj_parm,
15225 : "only the first parameter of a member function "
15226 : "can be declared as an explicit object parameter");
15227 6 : }
15228 187114472 : if (bad_xobj_parm_encountered && xobj_parm)
15229 0 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15230 : "valid explicit object parameter declared here");
15231 187114472 : }
15232 :
15233 187114472 : if (reqs)
15234 3 : error_at (location_of (reqs), "requires-clause on return type");
15235 187114472 : reqs = declarator->u.function.requires_clause;
15236 :
15237 : /* Say it's a definition only for the CALL_EXPR
15238 : closest to the identifier. */
15239 187114472 : funcdecl_p = inner_declarator && inner_declarator->kind == cdk_id;
15240 :
15241 : /* Handle a late-specified return type. */
15242 187114472 : tree late_return_type = declarator->u.function.late_return_type;
15243 187114472 : if (tree auto_node = type_uses_auto (type))
15244 : {
15245 8205026 : if (!late_return_type)
15246 : {
15247 4711703 : if (!funcdecl_p)
15248 : /* auto (*fp)() = f; is OK. */;
15249 4711669 : else if (current_class_type
15250 8645191 : && LAMBDA_TYPE_P (current_class_type))
15251 : /* OK for C++11 lambdas. */;
15252 3089075 : else if (cxx_dialect < cxx14)
15253 : {
15254 7 : auto_diagnostic_group d;
15255 7 : error_at (typespec_loc, "%qs function uses "
15256 : "%<auto%> type specifier without "
15257 : "trailing return type", name);
15258 7 : inform (typespec_loc,
15259 : "deduced return type only available "
15260 : "with %<-std=c++14%> or %<-std=gnu++14%>");
15261 7 : }
15262 3089068 : else if (virtualp)
15263 : {
15264 6 : error_at (typespec_loc, "virtual function "
15265 : "cannot have deduced return type");
15266 6 : virtualp = false;
15267 : }
15268 : }
15269 3493323 : else if (!is_auto (type) && sfk != sfk_conversion)
15270 : {
15271 15 : error_at (typespec_loc, "%qs function with trailing "
15272 : "return type has %qT as its type rather "
15273 : "than plain %<auto%>", name, type);
15274 274 : return error_mark_node;
15275 : }
15276 3493308 : else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
15277 : {
15278 9 : if (funcdecl_p)
15279 3 : error_at (typespec_loc,
15280 : "%qs function with trailing return type "
15281 : "has %<decltype(auto)%> as its type "
15282 : "rather than plain %<auto%>", name);
15283 : else
15284 6 : error_at (typespec_loc,
15285 : "invalid use of %<decltype(auto)%>");
15286 9 : return error_mark_node;
15287 : }
15288 3493299 : else if (is_constrained_auto (type))
15289 : {
15290 6 : if (funcdecl_p)
15291 3 : error_at (typespec_loc,
15292 : "%qs function with trailing return type "
15293 : "has constrained %<auto%> type specifier "
15294 : "rather than plain %<auto%>",
15295 : name);
15296 : else
15297 3 : error_at (typespec_loc,
15298 : "invalid use of constrained %<auto%> type");
15299 6 : return error_mark_node;
15300 : }
15301 8204996 : tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
15302 8204996 : if (!tmpl)
15303 7026788 : if (tree late_auto = type_uses_auto (late_return_type))
15304 35447 : tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
15305 7026788 : if (tmpl)
15306 : {
15307 1178213 : if (!funcdecl_p || !dguide_name_p (unqualified_id))
15308 : {
15309 12 : auto_diagnostic_group g;
15310 12 : error_at (typespec_loc, "deduced class "
15311 : "type %qD in function return type",
15312 12 : DECL_NAME (tmpl));
15313 12 : inform (DECL_SOURCE_LOCATION (tmpl),
15314 : "%qD declared here", tmpl);
15315 12 : return error_mark_node;
15316 12 : }
15317 1178201 : else if (!late_return_type)
15318 : {
15319 3 : auto_diagnostic_group d;
15320 3 : error_at (declarator->id_loc, "deduction guide "
15321 : "for %qT must have trailing return "
15322 3 : "type", TREE_TYPE (tmpl));
15323 3 : inform (DECL_SOURCE_LOCATION (tmpl),
15324 : "%qD declared here", tmpl);
15325 3 : return error_mark_node;
15326 3 : }
15327 1178198 : else if (CLASS_TYPE_P (late_return_type)
15328 1178198 : && CLASSTYPE_TEMPLATE_INFO (late_return_type)
15329 2356396 : && (CLASSTYPE_TI_TEMPLATE (late_return_type)
15330 : == tmpl))
15331 : /* OK */;
15332 : else
15333 0 : error ("trailing return type %qT of deduction guide "
15334 : "is not a specialization of %qT",
15335 0 : late_return_type, TREE_TYPE (tmpl));
15336 : }
15337 : }
15338 178909446 : else if (late_return_type
15339 178909446 : && sfk != sfk_conversion)
15340 : {
15341 37 : if (late_return_type == error_mark_node)
15342 : return error_mark_node;
15343 37 : if (cxx_dialect < cxx11)
15344 : /* Not using maybe_warn_cpp0x because this should
15345 : always be an error. */
15346 1 : error_at (typespec_loc,
15347 : "trailing return type only available "
15348 : "with %<-std=c++11%> or %<-std=gnu++11%>");
15349 : else
15350 36 : error_at (typespec_loc, "%qs function with trailing "
15351 : "return type not declared with %<auto%> "
15352 : "type specifier", name);
15353 37 : return error_mark_node;
15354 : }
15355 187114390 : if (late_return_type && sfk == sfk_conversion)
15356 : {
15357 14 : error ("a conversion function cannot have a trailing return type");
15358 14 : return error_mark_node;
15359 : }
15360 187114376 : type = splice_late_return_type (type, late_return_type);
15361 187114376 : if (type == error_mark_node)
15362 : return error_mark_node;
15363 :
15364 187114299 : if (late_return_type)
15365 : {
15366 3493203 : late_return_type_p = true;
15367 3493203 : type_quals = cp_type_quals (type);
15368 : }
15369 :
15370 187114299 : if (type_quals != TYPE_UNQUALIFIED)
15371 : {
15372 : /* It's wrong, for instance, to issue a -Wignored-qualifiers
15373 : warning for
15374 : static_assert(!is_same_v<void(*)(), const void(*)()>);
15375 : because there the qualifier matters. */
15376 11749 : if (funcdecl_p && (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)))
15377 232 : warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
15378 : "qualifiers ignored on function return type");
15379 : /* [dcl.fct] "A volatile-qualified return type is
15380 : deprecated." */
15381 11749 : if (type_quals & TYPE_QUAL_VOLATILE)
15382 599 : warning_at (typespec_loc, OPT_Wvolatile,
15383 : "%<volatile%>-qualified return type is "
15384 : "deprecated");
15385 :
15386 : /* We now know that the TYPE_QUALS don't apply to the
15387 : decl, but to its return type. */
15388 : type_quals = TYPE_UNQUALIFIED;
15389 : }
15390 :
15391 : /* Error about some types functions can't return. */
15392 :
15393 187114299 : if (TREE_CODE (type) == FUNCTION_TYPE)
15394 : {
15395 30 : error_at (typespec_loc, "%qs declared as function returning "
15396 : "a function", name);
15397 30 : return error_mark_node;
15398 : }
15399 187114269 : if (TREE_CODE (type) == ARRAY_TYPE)
15400 : {
15401 6 : error_at (typespec_loc, "%qs declared as function returning "
15402 : "an array", name);
15403 6 : return error_mark_node;
15404 : }
15405 187114263 : if (constinit_p && funcdecl_p)
15406 : {
15407 15 : error_at (declspecs->locations[ds_constinit],
15408 : "%<constinit%> on function return type is not "
15409 : "allowed");
15410 15 : return error_mark_node;
15411 : }
15412 :
15413 187114248 : if (check_decltype_auto (typespec_loc, type))
15414 50 : return error_mark_node;
15415 :
15416 187114198 : if (ctype == NULL_TREE
15417 187114198 : && decl_context == FIELD
15418 : && funcdecl_p
15419 107787189 : && friendp == 0)
15420 101211256 : ctype = current_class_type;
15421 :
15422 187114198 : if (ctype && (sfk == sfk_constructor
15423 101211256 : || sfk == sfk_destructor))
15424 : {
15425 : /* We are within a class's scope. If our declarator name
15426 : is the same as the class name, and we are defining
15427 : a function, then it is a constructor/destructor, and
15428 : therefore returns a void type. */
15429 :
15430 : /* ISO C++ 12.4/2. A destructor may not be declared
15431 : const or volatile. A destructor may not be static.
15432 : A destructor may not be declared with ref-qualifier.
15433 :
15434 : ISO C++ 12.1. A constructor may not be declared
15435 : const or volatile. A constructor may not be
15436 : virtual. A constructor may not be static.
15437 : A constructor may not be declared with ref-qualifier. */
15438 25984537 : if (staticp == 2)
15439 9 : error_at (declspecs->locations[ds_storage_class],
15440 : (flags == DTOR_FLAG)
15441 : ? G_("destructor cannot be static member "
15442 : "function")
15443 : : G_("constructor cannot be static member "
15444 : "function"));
15445 25984537 : if (memfn_quals)
15446 : {
15447 9 : error ((flags == DTOR_FLAG)
15448 : ? G_("destructors may not be cv-qualified")
15449 : : G_("constructors may not be cv-qualified"));
15450 9 : memfn_quals = TYPE_UNQUALIFIED;
15451 : }
15452 :
15453 25984537 : if (rqual)
15454 : {
15455 6 : maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
15456 6 : error ((flags == DTOR_FLAG)
15457 : ? G_("destructors may not be ref-qualified")
15458 : : G_("constructors may not be ref-qualified"));
15459 6 : rqual = REF_QUAL_NONE;
15460 : }
15461 :
15462 25984537 : if (decl_context == FIELD
15463 25984537 : && !member_function_or_else (ctype,
15464 : current_class_type,
15465 : flags))
15466 0 : return error_mark_node;
15467 :
15468 25984537 : if (flags != DTOR_FLAG)
15469 : {
15470 : /* It's a constructor. */
15471 22943906 : if (explicitp == 1)
15472 5359242 : explicitp = 2;
15473 22943906 : if (virtualp)
15474 : {
15475 3 : permerror (declspecs->locations[ds_virtual],
15476 : "constructors cannot be declared %<virtual%>");
15477 3 : virtualp = 0;
15478 : }
15479 22943906 : if (decl_context == FIELD
15480 22943906 : && sfk != sfk_constructor)
15481 0 : return error_mark_node;
15482 : }
15483 25984537 : if (decl_context == FIELD)
15484 25984537 : staticp = 0;
15485 : }
15486 161129661 : else if (friendp)
15487 : {
15488 6266200 : if (virtualp)
15489 : {
15490 : /* Cannot be both friend and virtual. */
15491 12 : gcc_rich_location richloc (declspecs->locations[ds_virtual]);
15492 12 : richloc.add_range (declspecs->locations[ds_friend]);
15493 12 : error_at (&richloc, "virtual functions cannot be friends");
15494 12 : friendp = 0;
15495 12 : }
15496 6266200 : if (decl_context == NORMAL)
15497 0 : error_at (declarator->id_loc,
15498 : "friend declaration not in class definition");
15499 6266200 : if (current_function_decl && funcdef_flag)
15500 : {
15501 9 : error_at (declarator->id_loc,
15502 : "cannot define friend function %qs in a local "
15503 : "class definition", name);
15504 9 : friendp = 0;
15505 : }
15506 : /* [class.friend]/6: A function can be defined in a friend
15507 : declaration if the function name is unqualified. */
15508 6266200 : if (funcdef_flag && in_namespace)
15509 : {
15510 6 : if (in_namespace == global_namespace)
15511 3 : error_at (declarator->id_loc,
15512 : "friend function definition %qs cannot have "
15513 : "a name qualified with %<::%>", name);
15514 : else
15515 3 : error_at (declarator->id_loc,
15516 : "friend function definition %qs cannot have "
15517 : "a name qualified with %<%D::%>", name,
15518 : in_namespace);
15519 : }
15520 : }
15521 154863461 : else if (ctype && sfk == sfk_conversion)
15522 : {
15523 998148 : if (explicitp == 1)
15524 : {
15525 467205 : maybe_warn_cpp0x (CPP0X_EXPLICIT_CONVERSION);
15526 467205 : explicitp = 2;
15527 : }
15528 : }
15529 153865313 : else if (sfk == sfk_deduction_guide)
15530 : {
15531 1178198 : if (explicitp == 1)
15532 187114198 : explicitp = 2;
15533 : }
15534 :
15535 187114198 : if (xobj_parm)
15536 : {
15537 75047 : if (!ctype
15538 75047 : && decl_context == NORMAL
15539 49 : && (in_namespace
15540 49 : || !declarator->declarator->u.id.qualifying_scope))
15541 4 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15542 : "a non-member function cannot have "
15543 : "an explicit object parameter");
15544 : else
15545 : {
15546 75043 : if (virtualp)
15547 : {
15548 16 : auto_diagnostic_group d;
15549 16 : error_at (declspecs->locations[ds_virtual],
15550 : "an explicit object member function cannot "
15551 : "be %<virtual%>");
15552 16 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15553 : "explicit object parameter declared here");
15554 16 : virtualp = false;
15555 16 : }
15556 75043 : if (staticp >= 2)
15557 : {
15558 2 : auto_diagnostic_group d;
15559 2 : error_at (declspecs->locations[ds_storage_class],
15560 : "an explicit object member function cannot "
15561 : "be %<static%>");
15562 2 : inform (DECL_SOURCE_LOCATION (xobj_parm),
15563 : "explicit object parameter declared here");
15564 2 : }
15565 75043 : if (unqualified_id
15566 187189235 : && identifier_p (unqualified_id)
15567 150080 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
15568 8 : error_at (DECL_SOURCE_LOCATION (xobj_parm),
15569 : "%qD cannot be an explicit object member "
15570 : "function", unqualified_id);
15571 : }
15572 : }
15573 187114198 : tree pushed_scope = NULL_TREE;
15574 187114198 : if (funcdecl_p
15575 187114198 : && decl_context != FIELD
15576 77452977 : && inner_declarator->u.id.qualifying_scope
15577 195924708 : && CLASS_TYPE_P (inner_declarator->u.id.qualifying_scope))
15578 8809183 : pushed_scope
15579 8809183 : = push_scope (inner_declarator->u.id.qualifying_scope);
15580 :
15581 187114198 : arg_types = grokparms (declarator->u.function.parameters, &parms);
15582 :
15583 187114198 : if (pushed_scope)
15584 8809183 : pop_scope (pushed_scope);
15585 :
15586 187114198 : if (inner_declarator
15587 186745072 : && inner_declarator->kind == cdk_id
15588 184930433 : && inner_declarator->u.id.sfk == sfk_destructor
15589 3204742 : && arg_types != void_list_node)
15590 : {
15591 20 : error_at (declarator->id_loc,
15592 : "destructors may not have parameters");
15593 20 : arg_types = void_list_node;
15594 20 : parms = NULL_TREE;
15595 20 : is_xobj_member_function = false;
15596 : }
15597 :
15598 187114198 : type = cp_build_function_type (type, arg_types);
15599 :
15600 187114198 : tree attrs = declarator->std_attributes;
15601 187114198 : if (tx_qual)
15602 : {
15603 242 : tree att = build_tree_list (tx_qual, NULL_TREE);
15604 : /* transaction_safe applies to the type, but
15605 : transaction_safe_dynamic applies to the function. */
15606 242 : if (is_attribute_p ("transaction_safe", tx_qual))
15607 213 : attrs = attr_chainon (attrs, att);
15608 : else
15609 29 : returned_attrs = attr_chainon (returned_attrs, att);
15610 : }
15611 :
15612 : /* Actually apply the contract attributes to the declaration. */
15613 187114198 : if (flag_contracts)
15614 14386006 : contract_specifiers
15615 14386006 : = attr_chainon (contract_specifiers,
15616 14386006 : declarator->u.function.contract_specifiers);
15617 :
15618 187114198 : if (attrs)
15619 : /* [dcl.fct]/2:
15620 :
15621 : The optional attribute-specifier-seq appertains to
15622 : the function type. */
15623 497 : cplus_decl_attributes (&type, attrs, 0);
15624 :
15625 187114198 : if (raises)
15626 74562843 : type = build_exception_variant (type, raises);
15627 : }
15628 187114198 : break;
15629 :
15630 190388439 : case cdk_pointer:
15631 190388439 : case cdk_reference:
15632 190388439 : case cdk_ptrmem:
15633 : /* Filter out pointers-to-references and references-to-references.
15634 : We can get these if a TYPE_DECL is used. */
15635 :
15636 190388439 : if (TYPE_REF_P (type))
15637 : {
15638 239 : if (declarator->kind != cdk_reference)
15639 : {
15640 3 : error ("cannot declare pointer to %q#T", type);
15641 3 : type = TREE_TYPE (type);
15642 : }
15643 :
15644 : /* In C++0x, we allow reference to reference declarations
15645 : that occur indirectly through typedefs [7.1.3/8 dcl.typedef]
15646 : and template type arguments [14.3.1/4 temp.arg.type]. The
15647 : check for direct reference to reference declarations, which
15648 : are still forbidden, occurs below. Reasoning behind the change
15649 : can be found in DR106, DR540, and the rvalue reference
15650 : proposals. */
15651 236 : else if (cxx_dialect == cxx98)
15652 : {
15653 0 : error ("cannot declare reference to %q#T", type);
15654 0 : type = TREE_TYPE (type);
15655 : }
15656 : }
15657 190388200 : else if (VOID_TYPE_P (type))
15658 : {
15659 5023598 : if (declarator->kind == cdk_reference)
15660 4 : error ("cannot declare reference to %q#T", type);
15661 5023594 : else if (declarator->kind == cdk_ptrmem)
15662 3 : error ("cannot declare pointer to %q#T member", type);
15663 : }
15664 :
15665 : /* We now know that the TYPE_QUALS don't apply to the decl,
15666 : but to the target of the pointer. */
15667 190388439 : type_quals = TYPE_UNQUALIFIED;
15668 :
15669 : /* This code used to handle METHOD_TYPE, but I don't think it's
15670 : possible to get it here anymore. */
15671 190388439 : gcc_assert (TREE_CODE (type) != METHOD_TYPE);
15672 190388439 : if (declarator->kind == cdk_ptrmem
15673 1092623 : && TREE_CODE (type) == FUNCTION_TYPE)
15674 : {
15675 884801 : memfn_quals |= type_memfn_quals (type);
15676 1769602 : type = build_memfn_type (type,
15677 884801 : declarator->u.pointer.class_type,
15678 : memfn_quals,
15679 : rqual);
15680 884801 : if (type == error_mark_node)
15681 : return error_mark_node;
15682 :
15683 : rqual = REF_QUAL_NONE;
15684 : memfn_quals = TYPE_UNQUALIFIED;
15685 : }
15686 :
15687 190388436 : if (TREE_CODE (type) == FUNCTION_TYPE
15688 190388436 : && (type_memfn_quals (type) != TYPE_UNQUALIFIED
15689 1001299 : || type_memfn_rqual (type) != REF_QUAL_NONE))
15690 15 : error (declarator->kind == cdk_reference
15691 : ? G_("cannot declare reference to qualified function type %qT")
15692 : : G_("cannot declare pointer to qualified function type %qT"),
15693 : type);
15694 :
15695 : /* When the pointed-to type involves components of variable size,
15696 : care must be taken to ensure that the size evaluation code is
15697 : emitted early enough to dominate all the possible later uses
15698 : and late enough for the variables on which it depends to have
15699 : been assigned.
15700 :
15701 : This is expected to happen automatically when the pointed-to
15702 : type has a name/declaration of it's own, but special attention
15703 : is required if the type is anonymous.
15704 :
15705 : We handle the NORMAL and FIELD contexts here by inserting a
15706 : dummy statement that just evaluates the size at a safe point
15707 : and ensures it is not deferred until e.g. within a deeper
15708 : conditional context (c++/43555).
15709 :
15710 : We expect nothing to be needed here for PARM or TYPENAME.
15711 : Evaluating the size at this point for TYPENAME would
15712 : actually be incorrect, as we might be in the middle of an
15713 : expression with side effects on the pointed-to type size
15714 : "arguments" prior to the pointer declaration point and the
15715 : size evaluation could end up prior to the side effects. */
15716 :
15717 190388436 : if (!TYPE_NAME (type)
15718 5396253 : && (decl_context == NORMAL || decl_context == FIELD)
15719 605058 : && at_function_scope_p ()
15720 190428342 : && variably_modified_type_p (type, NULL_TREE))
15721 : {
15722 119 : TYPE_NAME (type) = build_decl (UNKNOWN_LOCATION, TYPE_DECL,
15723 : NULL_TREE, type);
15724 119 : add_decl_expr (TYPE_NAME (type));
15725 : }
15726 :
15727 190388436 : if (declarator->kind == cdk_reference)
15728 : {
15729 : /* In C++0x, the type we are creating a reference to might be
15730 : a typedef which is itself a reference type. In that case,
15731 : we follow the reference collapsing rules in
15732 : [7.1.3/8 dcl.typedef] to create the final reference type:
15733 :
15734 : "If a typedef TD names a type that is a reference to a type
15735 : T, an attempt to create the type 'lvalue reference to cv TD'
15736 : creates the type 'lvalue reference to T,' while an attempt
15737 : to create the type "rvalue reference to cv TD' creates the
15738 : type TD."
15739 : */
15740 127432425 : if (VOID_TYPE_P (type))
15741 : /* We already gave an error. */;
15742 127432421 : else if (TYPE_REF_P (type))
15743 : {
15744 236 : if (declarator->u.reference.rvalue_ref)
15745 : /* Leave type alone. */;
15746 : else
15747 116 : type = cp_build_reference_type (TREE_TYPE (type), false);
15748 : }
15749 : else
15750 127432185 : type = cp_build_reference_type
15751 127432185 : (type, declarator->u.reference.rvalue_ref);
15752 :
15753 : /* In C++0x, we need this check for direct reference to
15754 : reference declarations, which are forbidden by
15755 : [8.3.2/5 dcl.ref]. Reference to reference declarations
15756 : are only allowed indirectly through typedefs and template
15757 : type arguments. Example:
15758 :
15759 : void foo(int & &); // invalid ref-to-ref decl
15760 :
15761 : typedef int & int_ref;
15762 : void foo(int_ref &); // valid ref-to-ref decl
15763 : */
15764 127432425 : if (inner_declarator && inner_declarator->kind == cdk_reference)
15765 1 : error ("cannot declare reference to %q#T, which is not "
15766 : "a typedef or a template type argument", type);
15767 : }
15768 62956011 : else if (TREE_CODE (type) == METHOD_TYPE)
15769 884798 : type = build_ptrmemfunc_type (build_pointer_type (type));
15770 62071213 : else if (declarator->kind == cdk_ptrmem)
15771 : {
15772 207822 : gcc_assert (TREE_CODE (declarator->u.pointer.class_type)
15773 : != NAMESPACE_DECL);
15774 207822 : if (declarator->u.pointer.class_type == error_mark_node)
15775 : /* We will already have complained. */
15776 3 : type = error_mark_node;
15777 : else
15778 207819 : type = build_ptrmem_type (declarator->u.pointer.class_type,
15779 : type);
15780 : }
15781 : else
15782 61863391 : type = build_pointer_type (type);
15783 :
15784 : /* Process a list of type modifier keywords (such as
15785 : const or volatile) that were given inside the `*' or `&'. */
15786 :
15787 190388436 : if (declarator->u.pointer.qualifiers)
15788 : {
15789 8358120 : type
15790 8358120 : = cp_build_qualified_type (type,
15791 : declarator->u.pointer.qualifiers);
15792 8358120 : type_quals = cp_type_quals (type);
15793 : }
15794 :
15795 : /* Apply C++11 attributes to the pointer, and not to the
15796 : type pointed to. This is unlike what is done for GNU
15797 : attributes above. It is to comply with [dcl.ptr]/1:
15798 :
15799 : [the optional attribute-specifier-seq (7.6.1) appertains
15800 : to the pointer and not to the object pointed to]. */
15801 190388436 : if (declarator->std_attributes)
15802 173 : cplus_decl_attributes (&type, declarator->std_attributes, 0);
15803 :
15804 : ctype = NULL_TREE;
15805 : break;
15806 :
15807 : case cdk_error:
15808 : break;
15809 :
15810 0 : default:
15811 0 : gcc_unreachable ();
15812 : }
15813 : }
15814 :
15815 1020641832 : id_loc = declarator ? declarator->id_loc : input_location;
15816 :
15817 1020641832 : if (innermost_code != cdk_function
15818 : /* Don't check this if it can be the artifical decltype(auto)
15819 : we created when building a constraint in a compound-requirement:
15820 : that the type-constraint is plain is going to be checked in
15821 : cp_parser_compound_requirement. */
15822 1020641832 : && decl_context != TYPENAME
15823 1020641832 : && check_decltype_auto (id_loc, type))
15824 20 : return error_mark_node;
15825 :
15826 : /* A `constexpr' specifier used in an object declaration declares
15827 : the object as `const'. */
15828 1020641812 : if (constexpr_p && innermost_code != cdk_function)
15829 : {
15830 : /* DR1688 says that a `constexpr' specifier in combination with
15831 : `volatile' is valid. */
15832 :
15833 19129520 : if (!TYPE_REF_P (type))
15834 : {
15835 19114617 : type_quals |= TYPE_QUAL_CONST;
15836 19114617 : type = cp_build_qualified_type (type, type_quals);
15837 : }
15838 : }
15839 :
15840 575250896 : if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
15841 2707488 : && !FUNC_OR_METHOD_TYPE_P (type)
15842 1022412751 : && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
15843 : {
15844 0 : error ("template-id %qD used as a declarator",
15845 : unqualified_id);
15846 0 : unqualified_id = dname;
15847 : }
15848 :
15849 : /* If TYPE is a FUNCTION_TYPE, but the function name was explicitly
15850 : qualified with a class-name, turn it into a METHOD_TYPE, unless
15851 : we know that the function is static. We take advantage of this
15852 : opportunity to do other processing that pertains to entities
15853 : explicitly declared to be class members. Note that if DECLARATOR
15854 : is non-NULL, we know it is a cdk_id declarator; otherwise, we
15855 : would not have exited the loop above. */
15856 1020641812 : if (declarator
15857 575470862 : && declarator->kind == cdk_id
15858 575250896 : && declarator->u.id.qualifying_scope
15859 1030178154 : && MAYBE_CLASS_TYPE_P (declarator->u.id.qualifying_scope))
15860 : {
15861 9296016 : ctype = declarator->u.id.qualifying_scope;
15862 9296016 : ctype = TYPE_MAIN_VARIANT (ctype);
15863 9296016 : template_count = num_template_headers_for_class (ctype);
15864 :
15865 9296016 : if (ctype == current_class_type)
15866 : {
15867 54 : if (friendp)
15868 : {
15869 15 : permerror (declspecs->locations[ds_friend],
15870 : "member functions are implicitly "
15871 : "friends of their class");
15872 15 : friendp = 0;
15873 : }
15874 : else
15875 39 : permerror (id_loc, "extra qualification %<%T::%> on member %qs",
15876 : ctype, name);
15877 : }
15878 9295962 : else if (/* If the qualifying type is already complete, then we
15879 : can skip the following checks. */
15880 9295962 : !COMPLETE_TYPE_P (ctype)
15881 154 : && (/* If the function is being defined, then
15882 : qualifying type must certainly be complete. */
15883 : funcdef_flag
15884 : /* A friend declaration of "T::f" is OK, even if
15885 : "T" is a template parameter. But, if this
15886 : function is not a friend, the qualifying type
15887 : must be a class. */
15888 117 : || (!friendp && !CLASS_TYPE_P (ctype))
15889 : /* For a declaration, the type need not be
15890 : complete, if either it is dependent (since there
15891 : is no meaningful definition of complete in that
15892 : case) or the qualifying class is currently being
15893 : defined. */
15894 129 : || !(dependent_type_p (ctype)
15895 24 : || currently_open_class (ctype)))
15896 : /* Check that the qualifying type is complete. */
15897 9296026 : && !complete_type_or_else (ctype, NULL_TREE))
15898 64 : return error_mark_node;
15899 9295898 : else if (TREE_CODE (type) == FUNCTION_TYPE)
15900 : {
15901 8809432 : if (current_class_type
15902 276 : && (!friendp || funcdef_flag || initialized))
15903 : {
15904 57 : error_at (id_loc, funcdef_flag || initialized
15905 : ? G_("cannot define member function %<%T::%s%> "
15906 : "within %qT")
15907 : : G_("cannot declare member function %<%T::%s%> "
15908 : "within %qT"),
15909 : ctype, name, current_class_type);
15910 48 : return error_mark_node;
15911 : }
15912 : }
15913 486466 : else if (typedef_p && current_class_type)
15914 : {
15915 0 : error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
15916 : ctype, name, current_class_type);
15917 0 : return error_mark_node;
15918 : }
15919 : }
15920 :
15921 1020641700 : if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
15922 57113644 : ctype = current_class_type;
15923 :
15924 : /* Now TYPE has the actual type. */
15925 :
15926 1020641700 : if (returned_attrs)
15927 : {
15928 2938 : if (attrlist)
15929 2938 : *attrlist = attr_chainon (returned_attrs, *attrlist);
15930 : else
15931 : attrlist = &returned_attrs;
15932 : }
15933 :
15934 1020641700 : if (declarator
15935 575470750 : && declarator->kind == cdk_id
15936 575250784 : && declarator->std_attributes
15937 555076 : && attrlist != NULL)
15938 : {
15939 : /* [dcl.meaning]/1: The optional attribute-specifier-seq following
15940 : a declarator-id appertains to the entity that is declared. */
15941 555073 : if (declarator->std_attributes != error_mark_node)
15942 : {
15943 555055 : if (flag_reflection
15944 : && declarator->std_attributes != error_mark_node
15945 13369 : && lookup_annotation (declarator->std_attributes)
15946 20 : && *attrlist != error_mark_node
15947 555075 : && lookup_annotation (*attrlist))
15948 : /* If there are annotations in both lists, ensure
15949 : declarator->std_attributes go after *attrlist. See
15950 : PR124399. */
15951 7 : *attrlist = chainon (copy_list (*attrlist),
15952 7 : declarator->std_attributes);
15953 : else
15954 555048 : *attrlist = attr_chainon (declarator->std_attributes, *attrlist);
15955 : }
15956 : else
15957 : /* We should have already diagnosed the issue (c++/78344). */
15958 18 : gcc_assert (seen_error ());
15959 : }
15960 :
15961 : /* Handle parameter packs. */
15962 1020641700 : if (parameter_pack_p)
15963 : {
15964 2996242 : if (decl_context == PARM)
15965 : /* Turn the type into a pack expansion.*/
15966 2996242 : type = make_pack_expansion (type);
15967 : else
15968 0 : error ("non-parameter %qs cannot be a parameter pack", name);
15969 : }
15970 :
15971 1020641700 : if ((decl_context == FIELD || decl_context == PARM)
15972 453646747 : && !processing_template_decl
15973 1165775682 : && variably_modified_type_p (type, NULL_TREE))
15974 : {
15975 12 : if (decl_context == FIELD)
15976 6 : error_at (id_loc,
15977 : "data member may not have variably modified type %qT", type);
15978 : else
15979 6 : error_at (id_loc,
15980 : "parameter may not have variably modified type %qT", type);
15981 12 : type = error_mark_node;
15982 : }
15983 :
15984 1020641700 : if (explicitp == 1 || (explicitp && friendp))
15985 : {
15986 : /* [dcl.fct.spec] (C++11) The explicit specifier shall be used only
15987 : in the declaration of a constructor or conversion function within
15988 : a class definition. */
15989 74 : if (!current_class_type)
15990 59 : error_at (declspecs->locations[ds_explicit],
15991 : "%<explicit%> outside class declaration");
15992 15 : else if (friendp)
15993 12 : error_at (declspecs->locations[ds_explicit],
15994 : "%<explicit%> in friend declaration");
15995 : else
15996 3 : error_at (declspecs->locations[ds_explicit],
15997 : "only declarations of constructors and conversion operators "
15998 : "can be %<explicit%>");
15999 : explicitp = 0;
16000 : }
16001 :
16002 1020641700 : if (storage_class == sc_mutable)
16003 : {
16004 135853 : location_t sloc = declspecs->locations[ds_storage_class];
16005 135853 : if (decl_context != FIELD || friendp)
16006 : {
16007 30 : error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
16008 : name);
16009 30 : storage_class = sc_none;
16010 : }
16011 135823 : else if (decl_context == TYPENAME || typedef_p)
16012 : {
16013 0 : error_at (sloc,
16014 : "non-object member %qs cannot be declared %<mutable%>",
16015 : name);
16016 0 : storage_class = sc_none;
16017 : }
16018 135823 : else if (FUNC_OR_METHOD_TYPE_P (type))
16019 : {
16020 3 : error_at (sloc, "function %qs cannot be declared %<mutable%>",
16021 : name);
16022 3 : storage_class = sc_none;
16023 : }
16024 135820 : else if (staticp)
16025 : {
16026 0 : error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
16027 : name);
16028 0 : storage_class = sc_none;
16029 : }
16030 135820 : else if (type_quals & TYPE_QUAL_CONST)
16031 : {
16032 9 : error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
16033 : name);
16034 9 : storage_class = sc_none;
16035 : }
16036 135811 : else if (TYPE_REF_P (type))
16037 : {
16038 6 : permerror (sloc, "reference %qs cannot be declared %<mutable%>",
16039 : name);
16040 6 : storage_class = sc_none;
16041 : }
16042 : }
16043 :
16044 : /* If this is declaring a typedef name, return a TYPE_DECL. */
16045 1020641700 : if (typedef_p && decl_context != TYPENAME)
16046 : {
16047 46436600 : bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
16048 46436600 : tree decl;
16049 :
16050 46436600 : if (funcdef_flag)
16051 : {
16052 6 : if (decl_context == NORMAL)
16053 3 : error_at (id_loc,
16054 : "typedef may not be a function definition");
16055 : else
16056 3 : error_at (id_loc,
16057 : "typedef may not be a member function definition");
16058 6 : return error_mark_node;
16059 : }
16060 :
16061 : /* This declaration:
16062 :
16063 : typedef void f(int) const;
16064 :
16065 : declares a function type which is not a member of any
16066 : particular class, but which is cv-qualified; for
16067 : example "f S::*" declares a pointer to a const-qualified
16068 : member function of S. We record the cv-qualification in the
16069 : function type. */
16070 46436594 : if ((rqual || memfn_quals) && TREE_CODE (type) == FUNCTION_TYPE)
16071 : {
16072 62 : type = apply_memfn_quals (type, memfn_quals, rqual);
16073 :
16074 : /* We have now dealt with these qualifiers. */
16075 62 : memfn_quals = TYPE_UNQUALIFIED;
16076 62 : rqual = REF_QUAL_NONE;
16077 : }
16078 :
16079 46436594 : if (type_uses_auto (type))
16080 : {
16081 62 : if (alias_p)
16082 20 : error_at (declspecs->locations[ds_type_spec],
16083 : "%<auto%> not allowed in alias declaration");
16084 : else
16085 42 : error_at (declspecs->locations[ds_type_spec],
16086 : "typedef declared %<auto%>");
16087 62 : type = error_mark_node;
16088 : }
16089 :
16090 46436594 : if (reqs)
16091 3 : error_at (location_of (reqs), "requires-clause on typedef");
16092 :
16093 46436594 : if (id_declarator && declarator->u.id.qualifying_scope)
16094 : {
16095 21 : error_at (id_loc, "typedef name may not be a nested-name-specifier");
16096 21 : type = error_mark_node;
16097 : }
16098 :
16099 46436594 : if (decl_context == FIELD)
16100 24824994 : decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
16101 : else
16102 21611600 : decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
16103 :
16104 46436594 : if (decl_context != FIELD)
16105 : {
16106 21611600 : if (!current_function_decl)
16107 9456248 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
16108 12155352 : else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (current_function_decl))
16109 : /* The TYPE_DECL is "abstract" because there will be
16110 : clones of this constructor/destructor, and there will
16111 : be copies of this TYPE_DECL generated in those
16112 : clones. The decloning optimization (for space) may
16113 : revert this subsequently if it determines that
16114 : the clones should share a common implementation. */
16115 155008 : DECL_ABSTRACT_P (decl) = true;
16116 :
16117 21611600 : set_originating_module (decl);
16118 : }
16119 24824994 : else if (current_class_type
16120 24824994 : && constructor_name_p (unqualified_id, current_class_type))
16121 3 : permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
16122 : "as enclosing class",
16123 : unqualified_id);
16124 :
16125 : /* If the user declares "typedef struct {...} foo" then the
16126 : struct will have an anonymous name. Fill that name in now.
16127 : Nothing can refer to it, so nothing needs know about the name
16128 : change. */
16129 46436594 : if (type != error_mark_node
16130 46436511 : && unqualified_id
16131 46436508 : && TYPE_NAME (type)
16132 43191520 : && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
16133 86262757 : && (TYPE_UNNAMED_P (type)
16134 : /* An enum may have previously used an enumerator for linkage
16135 : purposes, but we want the typedef name to take priority. */
16136 42805092 : || enum_with_enumerator_for_linkage_p (type))
16137 386844 : && declspecs->type_definition_p
16138 386771 : && attributes_naming_typedef_ok (*attrlist)
16139 46823362 : && cp_type_quals (type) == TYPE_UNQUALIFIED)
16140 386750 : name_unnamed_type (type, decl);
16141 :
16142 46436594 : if (signed_p
16143 46436594 : || (typedef_decl && C_TYPEDEF_EXPLICITLY_SIGNED (typedef_decl)))
16144 370834 : C_TYPEDEF_EXPLICITLY_SIGNED (decl) = 1;
16145 :
16146 46436594 : bad_specifiers (decl, BSP_TYPE, virtualp,
16147 : memfn_quals != TYPE_UNQUALIFIED,
16148 : inlinep, friendp, raises != NULL_TREE,
16149 : declspecs->locations);
16150 :
16151 46436594 : if (alias_p)
16152 : /* Acknowledge that this was written:
16153 : `using analias = atype;'. */
16154 20831684 : TYPE_DECL_ALIAS_P (decl) = 1;
16155 :
16156 46436594 : return decl;
16157 : }
16158 :
16159 : /* Detect the case of an array type of unspecified size
16160 : which came, as such, direct from a typedef name.
16161 : We must copy the type, so that the array's domain can be
16162 : individually set by the object's initializer. */
16163 :
16164 974205100 : if (type && typedef_type
16165 945097285 : && TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
16166 974787600 : && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (typedef_type))
16167 81 : type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
16168 :
16169 : /* Detect where we're using a typedef of function type to declare a
16170 : function. PARMS will not be set, so we must create it now. */
16171 :
16172 974205100 : if (type == typedef_type && TREE_CODE (type) == FUNCTION_TYPE)
16173 : {
16174 15356 : tree decls = NULL_TREE;
16175 15356 : tree args;
16176 :
16177 15356 : for (args = TYPE_ARG_TYPES (type);
16178 33179 : args && args != void_list_node;
16179 17823 : args = TREE_CHAIN (args))
16180 : {
16181 17823 : tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE,
16182 17823 : TREE_VALUE (args));
16183 :
16184 17823 : DECL_CHAIN (decl) = decls;
16185 17823 : decls = decl;
16186 : }
16187 :
16188 15356 : parms = nreverse (decls);
16189 :
16190 15356 : if (decl_context != TYPENAME)
16191 : {
16192 : /* The qualifiers on the function type become the qualifiers on
16193 : the non-static member function. */
16194 14640 : memfn_quals |= type_memfn_quals (type);
16195 14640 : rqual = type_memfn_rqual (type);
16196 14640 : type_quals = TYPE_UNQUALIFIED;
16197 14640 : raises = TYPE_RAISES_EXCEPTIONS (type);
16198 : }
16199 : }
16200 :
16201 : /* If this is a type name (such as, in a cast or sizeof),
16202 : compute the type and return it now. */
16203 :
16204 974204384 : if (decl_context == TYPENAME)
16205 : {
16206 : /* Note that here we don't care about type_quals. */
16207 :
16208 : /* Special case: "friend class foo" looks like a TYPENAME context. */
16209 400989419 : if (friendp)
16210 : {
16211 0 : if (inlinep)
16212 : {
16213 0 : error ("%<inline%> specified for friend class declaration");
16214 0 : inlinep = 0;
16215 : }
16216 :
16217 0 : if (!current_aggr)
16218 : {
16219 : /* Don't allow friend declaration without a class-key. */
16220 0 : if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
16221 0 : permerror (input_location, "template parameters cannot be friends");
16222 0 : else if (TREE_CODE (type) == TYPENAME_TYPE)
16223 0 : permerror (input_location, "friend declaration requires class-key, "
16224 : "i.e. %<friend class %T::%D%>",
16225 0 : TYPE_CONTEXT (type), TYPENAME_TYPE_FULLNAME (type));
16226 : else
16227 0 : permerror (input_location, "friend declaration requires class-key, "
16228 : "i.e. %<friend %#T%>",
16229 : type);
16230 : }
16231 :
16232 : /* Only try to do this stuff if we didn't already give up. */
16233 0 : if (type != integer_type_node)
16234 : {
16235 : /* A friendly class? */
16236 0 : if (current_class_type)
16237 0 : make_friend_class (current_class_type, TYPE_MAIN_VARIANT (type),
16238 : /*complain=*/true);
16239 : else
16240 0 : error ("trying to make class %qT a friend of global scope",
16241 : type);
16242 :
16243 0 : type = void_type_node;
16244 : }
16245 : }
16246 400989419 : else if (memfn_quals || rqual)
16247 : {
16248 10459 : if (ctype == NULL_TREE
16249 10459 : && TREE_CODE (type) == METHOD_TYPE)
16250 0 : ctype = TYPE_METHOD_BASETYPE (type);
16251 :
16252 10459 : if (ctype)
16253 0 : type = build_memfn_type (type, ctype, memfn_quals, rqual);
16254 : /* Core issue #547: need to allow this in template type args.
16255 : Allow it in general in C++11 for alias-declarations. */
16256 10459 : else if ((template_type_arg || cxx_dialect >= cxx11)
16257 10457 : && TREE_CODE (type) == FUNCTION_TYPE)
16258 10455 : type = apply_memfn_quals (type, memfn_quals, rqual);
16259 : else
16260 4 : error ("invalid qualifiers on non-member function type");
16261 : }
16262 :
16263 400989419 : if (reqs)
16264 3 : error_at (location_of (reqs), "requires-clause on type-id");
16265 :
16266 400989419 : return type;
16267 : }
16268 573215681 : else if (unqualified_id == NULL_TREE && decl_context != PARM
16269 812728 : && decl_context != CATCHPARM
16270 352066 : && TREE_CODE (type) != UNION_TYPE
16271 351759 : && ! bitfield
16272 351759 : && innermost_code != cdk_decomp)
16273 : {
16274 9 : error ("abstract declarator %qT used as declaration", type);
16275 9 : return error_mark_node;
16276 : }
16277 :
16278 573215672 : if (!FUNC_OR_METHOD_TYPE_P (type))
16279 : {
16280 : /* Only functions may be declared using an operator-function-id. */
16281 388323521 : if (dname && IDENTIFIER_ANY_OP_P (dname))
16282 : {
16283 8 : error_at (id_loc, "declaration of %qD as non-function", dname);
16284 8 : return error_mark_node;
16285 : }
16286 :
16287 388323513 : if (reqs)
16288 15 : error_at (location_of (reqs),
16289 : "requires-clause on declaration of non-function type %qT",
16290 : type);
16291 : }
16292 :
16293 : /* We don't check parameter types here because we can emit a better
16294 : error message later. */
16295 573215664 : if (decl_context != PARM)
16296 : {
16297 284159975 : type = check_var_type (unqualified_id, type, id_loc);
16298 284159975 : if (type == error_mark_node)
16299 : return error_mark_node;
16300 : }
16301 :
16302 : /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
16303 : or a FUNCTION_DECL, depending on DECL_CONTEXT and TYPE. */
16304 :
16305 573215584 : if (decl_context == PARM || decl_context == CATCHPARM)
16306 : {
16307 289529643 : if (ctype || in_namespace)
16308 0 : error ("cannot use %<::%> in parameter declaration");
16309 :
16310 289529643 : tree auto_node = type_uses_auto (type);
16311 289529643 : if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
16312 : {
16313 121 : bool err_p = true;
16314 121 : if (cxx_dialect >= cxx14)
16315 : {
16316 214 : if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
16317 3 : error_at (typespec_loc,
16318 : "cannot declare a parameter with %<decltype(auto)%>");
16319 110 : else if (tree c = CLASS_PLACEHOLDER_TEMPLATE (auto_node))
16320 : {
16321 6 : auto_diagnostic_group g;
16322 6 : gcc_rich_location richloc (typespec_loc);
16323 6 : richloc.add_fixit_insert_after ("<>");
16324 6 : error_at (&richloc,
16325 : "missing template argument list after %qE; template "
16326 : "placeholder not permitted in parameter", c);
16327 6 : if (decl_context == PARM && cxx_dialect >= cxx20)
16328 5 : inform (typespec_loc, "or use %<auto%> for an "
16329 : "abbreviated function template");
16330 6 : inform (DECL_SOURCE_LOCATION (c), "%qD declared here", c);
16331 6 : }
16332 104 : else if (decl_context == CATCHPARM || template_parm_flag)
16333 14 : error_at (typespec_loc,
16334 : "%<auto%> parameter not permitted in this context");
16335 : else
16336 : /* Do not issue an error while tentatively parsing a function
16337 : parameter: for T t(auto(a), 42);, when we just saw the 1st
16338 : parameter, we don't know yet that this construct won't be
16339 : a function declaration. Defer the checking to
16340 : cp_parser_parameter_declaration_clause. */
16341 : err_p = false;
16342 : }
16343 : else
16344 8 : error_at (typespec_loc, "parameter declared %<auto%>");
16345 31 : if (err_p)
16346 31 : type = error_mark_node;
16347 : }
16348 :
16349 : /* A parameter declared as an array of T is really a pointer to T.
16350 : One declared as a function is really a pointer to a function.
16351 : One declared as a member is really a pointer to member. */
16352 :
16353 289529643 : if (TREE_CODE (type) == ARRAY_TYPE)
16354 : {
16355 : /* Transfer const-ness of array into that of type pointed to. */
16356 749706 : type = build_pointer_type (TREE_TYPE (type));
16357 749706 : type_quals = TYPE_UNQUALIFIED;
16358 749706 : array_parameter_p = true;
16359 : }
16360 288779937 : else if (TREE_CODE (type) == FUNCTION_TYPE)
16361 99634 : type = build_pointer_type (type);
16362 : }
16363 :
16364 142795714 : if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
16365 : /* Don't convert xobj member functions to METHOD_TYPE. */
16366 110020474 : && !is_xobj_member_function
16367 673091102 : && !(unqualified_id
16368 199744357 : && identifier_p (unqualified_id)
16369 99875134 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
16370 : {
16371 99869223 : cp_cv_quals real_quals = memfn_quals;
16372 99869223 : if (cxx_dialect < cxx14 && constexpr_p
16373 689952 : && sfk != sfk_constructor && sfk != sfk_destructor)
16374 3894 : real_quals |= TYPE_QUAL_CONST;
16375 99869223 : type = build_memfn_type (type, ctype, real_quals, rqual);
16376 : }
16377 :
16378 573215584 : {
16379 573215584 : tree decl = NULL_TREE;
16380 :
16381 573215584 : if (decl_context == PARM)
16382 : {
16383 289055689 : decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type);
16384 289055689 : DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p;
16385 :
16386 289055689 : bad_specifiers (decl, BSP_PARM, virtualp,
16387 : memfn_quals != TYPE_UNQUALIFIED,
16388 : inlinep, friendp, raises != NULL_TREE,
16389 : declspecs->locations);
16390 : }
16391 284159895 : else if (decl_context == FIELD)
16392 : {
16393 139766049 : if (!staticp && !friendp && !FUNC_OR_METHOD_TYPE_P (type))
16394 19555941 : if (tree auto_node = type_uses_auto (type))
16395 : {
16396 24 : location_t tloc = declspecs->locations[ds_type_spec];
16397 24 : if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
16398 6 : error_at (tloc, "invalid use of template-name %qE without an "
16399 : "argument list",
16400 6 : CLASS_PLACEHOLDER_TEMPLATE (auto_node));
16401 : else
16402 18 : error_at (tloc, "non-static data member declared with "
16403 : "placeholder %qT", auto_node);
16404 24 : type = error_mark_node;
16405 : }
16406 :
16407 : /* The C99 flexible array extension. */
16408 116963272 : if (!staticp && TREE_CODE (type) == ARRAY_TYPE
16409 140866480 : && TYPE_DOMAIN (type) == NULL_TREE)
16410 : {
16411 1400 : if (ctype
16412 1400 : && (TREE_CODE (ctype) == UNION_TYPE
16413 1400 : || TREE_CODE (ctype) == QUAL_UNION_TYPE))
16414 84 : pedwarn (id_loc, OPT_Wpedantic,
16415 : "flexible array member in union is a GCC extension");
16416 :
16417 : else
16418 : {
16419 : /* Array is a flexible member. */
16420 1316 : if (name)
16421 1316 : pedwarn (id_loc, OPT_Wpedantic,
16422 : "ISO C++ forbids flexible array member %qs", name);
16423 : else
16424 : pedwarn (input_location, OPT_Wpedantic,
16425 : "ISO C++ forbids flexible array members");
16426 :
16427 : /* Flexible array member has a null domain. */
16428 1316 : type = build_cplus_array_type (TREE_TYPE (type), NULL_TREE);
16429 : }
16430 : }
16431 :
16432 139766049 : if (type == error_mark_node)
16433 : {
16434 : /* Happens when declaring arrays of sizes which
16435 : are error_mark_node, for example. */
16436 24 : decl = NULL_TREE;
16437 : }
16438 139766025 : else if (in_namespace && !friendp)
16439 : {
16440 : /* Something like struct S { int N::j; }; */
16441 6 : error_at (id_loc, "invalid use of %<::%>");
16442 6 : return error_mark_node;
16443 : }
16444 139766019 : else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
16445 : {
16446 107477233 : int publicp = 0;
16447 107477233 : tree function_context;
16448 :
16449 107477233 : if (friendp == 0)
16450 : {
16451 : /* This should never happen in pure C++ (the check
16452 : could be an assert). It could happen in
16453 : Objective-C++ if someone writes invalid code that
16454 : uses a function declaration for an instance
16455 : variable or property (instance variables and
16456 : properties are parsed as FIELD_DECLs, but they are
16457 : part of an Objective-C class, not a C++ class).
16458 : That code is invalid and is caught by this
16459 : check. */
16460 101211090 : if (!ctype)
16461 : {
16462 0 : error ("declaration of function %qD in invalid context",
16463 : unqualified_id);
16464 0 : return error_mark_node;
16465 : }
16466 :
16467 : /* ``A union may [ ... ] not [ have ] virtual functions.''
16468 : ARM 9.5 */
16469 101211090 : if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
16470 : {
16471 3 : error_at (declspecs->locations[ds_virtual],
16472 : "function %qD declared %<virtual%> inside a union",
16473 : unqualified_id);
16474 3 : return error_mark_node;
16475 : }
16476 :
16477 4078266 : if (virtualp
16478 111555496 : && identifier_p (unqualified_id)
16479 4078266 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16480 : {
16481 9 : error_at (declspecs->locations[ds_virtual],
16482 : "%qD cannot be declared %<virtual%>, since it "
16483 : "is always static", unqualified_id);
16484 9 : virtualp = 0;
16485 : }
16486 : }
16487 :
16488 : /* Check that the name used for a destructor makes sense. */
16489 107477230 : if (sfk == sfk_destructor)
16490 : {
16491 3040667 : tree uqname = id_declarator->u.id.unqualified_name;
16492 :
16493 3040667 : if (!ctype)
16494 : {
16495 12 : gcc_assert (friendp);
16496 12 : error_at (id_loc, "expected qualified name in friend "
16497 : "declaration for destructor %qD", uqname);
16498 12 : return error_mark_node;
16499 : }
16500 :
16501 3040655 : if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
16502 : {
16503 9 : error_at (id_loc, "declaration of %qD as member of %qT",
16504 : uqname, ctype);
16505 9 : return error_mark_node;
16506 : }
16507 3040646 : if (concept_p)
16508 : {
16509 9 : error_at (declspecs->locations[ds_concept],
16510 : "a destructor cannot be %qs", "concept");
16511 9 : return error_mark_node;
16512 : }
16513 3040637 : if (constexpr_p && cxx_dialect < cxx20)
16514 : {
16515 6 : error_at (declspecs->locations[ds_constexpr],
16516 : "%<constexpr%> destructors only available"
16517 : " with %<-std=c++20%> or %<-std=gnu++20%>");
16518 6 : return error_mark_node;
16519 : }
16520 3040631 : if (consteval_p)
16521 : {
16522 3 : error_at (declspecs->locations[ds_consteval],
16523 : "a destructor cannot be %qs", "consteval");
16524 3 : return error_mark_node;
16525 : }
16526 : }
16527 104436563 : else if (sfk == sfk_constructor && friendp && !ctype)
16528 : {
16529 0 : error ("expected qualified name in friend declaration "
16530 : "for constructor %qD",
16531 0 : id_declarator->u.id.unqualified_name);
16532 0 : return error_mark_node;
16533 : }
16534 107477191 : if (sfk == sfk_constructor)
16535 22943930 : if (concept_p)
16536 : {
16537 9 : error_at (declspecs->locations[ds_concept],
16538 : "a constructor cannot be %<concept%>");
16539 9 : return error_mark_node;
16540 : }
16541 84533261 : if (concept_p)
16542 : {
16543 9 : error_at (declspecs->locations[ds_concept],
16544 : "a concept cannot be a member function");
16545 9 : concept_p = false;
16546 : }
16547 107477173 : else if (consteval_p
16548 108211581 : && identifier_p (unqualified_id)
16549 108211572 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16550 : {
16551 9 : error_at (declspecs->locations[ds_consteval],
16552 : "%qD cannot be %qs", unqualified_id, "consteval");
16553 9 : consteval_p = false;
16554 : }
16555 :
16556 107477182 : if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16557 : {
16558 90997 : tree tmpl = TREE_OPERAND (unqualified_id, 0);
16559 90997 : if (variable_template_p (tmpl))
16560 : {
16561 3 : auto_diagnostic_group d;
16562 3 : error_at (id_loc, "specialization of variable template "
16563 : "%qD declared as function", tmpl);
16564 3 : inform (DECL_SOURCE_LOCATION (tmpl),
16565 : "variable template declared here");
16566 3 : return error_mark_node;
16567 3 : }
16568 : }
16569 :
16570 : /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
16571 107477179 : function_context
16572 : = (ctype != NULL_TREE
16573 107477179 : ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
16574 214954358 : publicp = ((! friendp || ! staticp)
16575 107477179 : && function_context == NULL_TREE);
16576 :
16577 107477179 : decl = grokfndecl (ctype, type,
16578 107477179 : TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
16579 : ? unqualified_id : dname,
16580 : parms,
16581 : unqualified_id,
16582 : declspecs,
16583 : reqs,
16584 : virtualp, flags, memfn_quals, rqual, raises,
16585 : friendp ? -1 : 0, friendp, publicp,
16586 107477179 : inlinep | (2 * constexpr_p) | (4 * concept_p)
16587 107477179 : | (8 * consteval_p),
16588 : initialized,
16589 : is_xobj_member_function, sfk,
16590 : funcdef_flag, late_return_type_p,
16591 : template_count, in_namespace,
16592 : attrlist, contract_specifiers, id_loc);
16593 107477179 : decl = set_virt_specifiers (decl, virt_specifiers);
16594 107477179 : if (decl == NULL_TREE)
16595 97 : return error_mark_node;
16596 : #if 0
16597 : /* This clobbers the attrs stored in `decl' from `attrlist'. */
16598 : /* The decl and setting of decl_attr is also turned off. */
16599 : decl = build_decl_attribute_variant (decl, decl_attr);
16600 : #endif
16601 :
16602 : /* [class.conv.ctor]
16603 :
16604 : A constructor declared without the function-specifier
16605 : explicit that can be called with a single parameter
16606 : specifies a conversion from the type of its first
16607 : parameter to the type of its class. Such a constructor
16608 : is called a converting constructor. */
16609 107477082 : if (explicitp == 2)
16610 5826447 : DECL_NONCONVERTING_P (decl) = 1;
16611 :
16612 107477082 : if (declspecs->explicit_specifier)
16613 391652 : store_explicit_specifier (decl, declspecs->explicit_specifier);
16614 : }
16615 32288786 : else if (!staticp
16616 32288786 : && ((current_class_type
16617 19555932 : && same_type_p (TYPE_MAIN_VARIANT (type),
16618 : current_class_type))
16619 19555836 : || (!dependent_type_p (type)
16620 11864064 : && !COMPLETE_TYPE_P (complete_type (type))
16621 1448 : && (!complete_or_array_type_p (type)
16622 1373 : || initialized == SD_UNINITIALIZED))))
16623 : {
16624 1511 : if (TREE_CODE (type) != ARRAY_TYPE
16625 1511 : || !COMPLETE_TYPE_P (TREE_TYPE (type)))
16626 : {
16627 171 : if (unqualified_id)
16628 : {
16629 126 : auto_diagnostic_group d;
16630 126 : error_at (id_loc, "field %qD has incomplete type %qT",
16631 : unqualified_id, type);
16632 126 : cxx_incomplete_type_inform (strip_array_types (type));
16633 126 : }
16634 : else
16635 45 : error ("name %qT has incomplete type", type);
16636 :
16637 171 : type = error_mark_node;
16638 171 : decl = NULL_TREE;
16639 : }
16640 : }
16641 51841684 : else if (!verify_type_context (input_location,
16642 : staticp
16643 : ? TCTX_STATIC_STORAGE
16644 : : TCTX_FIELD, type))
16645 : {
16646 0 : type = error_mark_node;
16647 0 : decl = NULL_TREE;
16648 : }
16649 : else
16650 : {
16651 32287269 : if (friendp)
16652 : {
16653 12 : if (unqualified_id)
16654 9 : error_at (id_loc,
16655 : "%qE is neither function nor member function; "
16656 : "cannot be declared friend", unqualified_id);
16657 : else
16658 3 : error ("unnamed field is neither function nor member "
16659 : "function; cannot be declared friend");
16660 12 : return error_mark_node;
16661 : }
16662 32287257 : decl = NULL_TREE;
16663 : }
16664 :
16665 139765874 : if (friendp)
16666 : {
16667 6266112 : if (flag_reflection && !funcdef_flag && decl)
16668 : {
16669 7549 : if (attrlist && lookup_annotation (*attrlist))
16670 : {
16671 : /* Remove the annotations to avoid spurious warning
16672 : below. */
16673 4 : *attrlist = remove_attribute ("internal ", "annotation ",
16674 : *attrlist);
16675 4 : error_at (id_loc, "annotation applied to non-defining "
16676 : "friend declaration %qD", decl);
16677 : }
16678 7549 : for (tree arg = DECL_ARGUMENTS (decl);
16679 17377 : arg; arg = DECL_CHAIN (arg))
16680 9828 : if (lookup_annotation (DECL_ATTRIBUTES (arg)))
16681 4 : error_at (DECL_SOURCE_LOCATION (arg),
16682 : "annotation applied to parameter %qD of "
16683 : "non-defining friend declaration", arg);
16684 : }
16685 : /* Packages tend to use GNU attributes on friends, so we only
16686 : warn for standard attributes. */
16687 6266112 : if (attrlist
16688 6266112 : && !funcdef_flag
16689 6266112 : && cxx11_attribute_p (*attrlist))
16690 : {
16691 27 : *attrlist = NULL_TREE;
16692 27 : auto_diagnostic_group d;
16693 27 : if (warning_at (id_loc, OPT_Wattributes, "attribute ignored"))
16694 27 : inform (id_loc, "an attribute that appertains to a friend "
16695 : "declaration that is not a definition is ignored");
16696 27 : }
16697 : /* Friends are treated specially. */
16698 6266112 : if (ctype == current_class_type)
16699 : ; /* We already issued a permerror. */
16700 6266112 : else if (decl && DECL_NAME (decl))
16701 : {
16702 6266109 : set_originating_module (decl, true);
16703 :
16704 6266109 : if (initialized)
16705 : /* Kludge: We need funcdef_flag to be true in do_friend for
16706 : in-class defaulted functions, but that breaks grokfndecl.
16707 : So set it here. */
16708 207823 : funcdef_flag = true;
16709 :
16710 6266109 : cplus_decl_attributes (&decl, *attrlist, 0);
16711 6266109 : *attrlist = NULL_TREE;
16712 :
16713 6266109 : tree scope = ctype ? ctype : in_namespace;
16714 6266109 : decl = do_friend (scope, unqualified_id, decl,
16715 : flags, funcdef_flag);
16716 6266109 : return decl;
16717 : }
16718 : else
16719 3 : return error_mark_node;
16720 : }
16721 :
16722 : /* Structure field. It may not be a function, except for C++. */
16723 :
16724 133499762 : if (decl == NULL_TREE)
16725 : {
16726 32288789 : if (staticp)
16727 : {
16728 : /* C++ allows static class members. All other work
16729 : for this is done by grokfield. */
16730 12732854 : decl = build_lang_decl_loc (id_loc, VAR_DECL,
16731 : dname, type);
16732 12732854 : if (unqualified_id
16733 12732851 : && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16734 : {
16735 41498 : decl = check_explicit_specialization (unqualified_id, decl,
16736 : template_count,
16737 : concept_p * 8);
16738 41498 : if (decl == error_mark_node)
16739 : return error_mark_node;
16740 : }
16741 12732854 : set_linkage_for_static_data_member (decl);
16742 12732854 : if (concept_p)
16743 15 : error_at (declspecs->locations[ds_concept],
16744 : "static data member %qE declared %qs",
16745 : unqualified_id, "concept");
16746 12732839 : else if (constexpr_p && !initialized)
16747 : {
16748 9 : error_at (DECL_SOURCE_LOCATION (decl),
16749 : "%<constexpr%> static data member %qD must "
16750 : "have an initializer", decl);
16751 9 : constexpr_p = false;
16752 : }
16753 12732854 : if (consteval_p)
16754 3 : error_at (declspecs->locations[ds_consteval],
16755 : "static data member %qE declared %qs",
16756 : unqualified_id, "consteval");
16757 :
16758 12732854 : if (inlinep)
16759 21791 : mark_inline_variable (decl, declspecs->locations[ds_inline]);
16760 :
16761 12732854 : if (!DECL_VAR_DECLARED_INLINE_P (decl)
16762 12732854 : && !(cxx_dialect >= cxx17 && constexpr_p))
16763 : /* Even if there is an in-class initialization, DECL
16764 : is considered undefined until an out-of-class
16765 : definition is provided, unless this is an inline
16766 : variable. */
16767 1802499 : DECL_EXTERNAL (decl) = 1;
16768 :
16769 12732854 : if (thread_p)
16770 : {
16771 421 : CP_DECL_THREAD_LOCAL_P (decl) = true;
16772 421 : if (!processing_template_decl)
16773 375 : set_decl_tls_model (decl, decl_default_tls_model (decl));
16774 421 : if (declspecs->gnu_thread_keyword_p)
16775 34 : SET_DECL_GNU_TLS_P (decl);
16776 : }
16777 :
16778 : /* Set the constraints on the declaration. */
16779 12732854 : bool memtmpl = (current_template_depth
16780 12732854 : > template_class_depth (current_class_type));
16781 12732854 : if (memtmpl)
16782 : {
16783 368067 : tree ci = current_template_constraints ();
16784 368067 : set_constraints (decl, ci);
16785 : }
16786 : }
16787 : else
16788 : {
16789 19555935 : if (concept_p)
16790 : {
16791 12 : error_at (declspecs->locations[ds_concept],
16792 : "non-static data member %qE declared %qs",
16793 : unqualified_id, "concept");
16794 12 : concept_p = false;
16795 12 : constexpr_p = false;
16796 : }
16797 19555923 : else if (constexpr_p)
16798 : {
16799 9 : error_at (declspecs->locations[ds_constexpr],
16800 : "non-static data member %qE declared %qs",
16801 : unqualified_id, "constexpr");
16802 9 : constexpr_p = false;
16803 : }
16804 19555935 : if (constinit_p)
16805 : {
16806 6 : error_at (declspecs->locations[ds_constinit],
16807 : "non-static data member %qE declared %qs",
16808 : unqualified_id, "constinit");
16809 6 : constinit_p = false;
16810 : }
16811 19555935 : if (consteval_p)
16812 : {
16813 3 : error_at (declspecs->locations[ds_consteval],
16814 : "non-static data member %qE declared %qs",
16815 : unqualified_id, "consteval");
16816 3 : consteval_p = false;
16817 : }
16818 19555935 : decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
16819 19555935 : DECL_NONADDRESSABLE_P (decl) = bitfield;
16820 19555935 : if (bitfield && !unqualified_id)
16821 131775 : DECL_PADDING_P (decl) = 1;
16822 :
16823 19555935 : if (storage_class == sc_mutable)
16824 : {
16825 135805 : DECL_MUTABLE_P (decl) = 1;
16826 135805 : storage_class = sc_none;
16827 : }
16828 :
16829 19555935 : if (initialized)
16830 : {
16831 : /* An attempt is being made to initialize a non-static
16832 : member. This is new in C++11. */
16833 2232289 : maybe_warn_cpp0x (CPP0X_NSDMI, init_loc);
16834 :
16835 : /* If this has been parsed with static storage class, but
16836 : errors forced staticp to be cleared, ensure NSDMI is
16837 : not present. */
16838 2232289 : if (declspecs->storage_class == sc_static)
16839 3 : DECL_INITIAL (decl) = error_mark_node;
16840 : }
16841 : }
16842 :
16843 51844724 : bad_specifiers (decl, BSP_FIELD, virtualp,
16844 : memfn_quals != TYPE_UNQUALIFIED,
16845 : staticp ? false : inlinep, friendp,
16846 : raises != NULL_TREE,
16847 : declspecs->locations);
16848 : }
16849 : }
16850 144393846 : else if (FUNC_OR_METHOD_TYPE_P (type))
16851 : {
16852 77315278 : tree original_name;
16853 77315278 : int publicp = 0;
16854 :
16855 77315278 : if (!unqualified_id)
16856 0 : return error_mark_node;
16857 :
16858 77315278 : if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
16859 : original_name = dname;
16860 : else
16861 76469732 : original_name = unqualified_id;
16862 : // FIXME:gcc_assert (original_name == dname);
16863 :
16864 77315278 : if (storage_class == sc_auto)
16865 1 : error_at (declspecs->locations[ds_storage_class],
16866 : "storage class %<auto%> invalid for function %qs", name);
16867 77315277 : else if (storage_class == sc_register)
16868 7 : error_at (declspecs->locations[ds_storage_class],
16869 : "storage class %<register%> invalid for function %qs",
16870 : name);
16871 77315270 : else if (thread_p)
16872 : {
16873 12 : if (declspecs->gnu_thread_keyword_p)
16874 12 : error_at (declspecs->locations[ds_thread],
16875 : "storage class %<__thread%> invalid for function %qs",
16876 : name);
16877 : else
16878 0 : error_at (declspecs->locations[ds_thread],
16879 : "storage class %<thread_local%> invalid for "
16880 : "function %qs", name);
16881 : }
16882 77315258 : else if (constinit_p)
16883 3 : error_at (declspecs->locations[ds_constinit],
16884 : "%<constinit%> specifier invalid for function %qs", name);
16885 :
16886 77315278 : if (virt_specifiers)
16887 6 : error ("virt-specifiers in %qs not allowed outside a class "
16888 : "definition", name);
16889 : /* Function declaration not at top level.
16890 : Storage classes other than `extern' are not allowed
16891 : and `extern' makes no difference. */
16892 77315278 : if (! toplevel_bindings_p ()
16893 58896 : && (storage_class == sc_static
16894 58887 : || decl_spec_seq_has_spec_p (declspecs, ds_inline))
16895 77315290 : && pedantic)
16896 : {
16897 9 : if (storage_class == sc_static)
16898 6 : pedwarn (declspecs->locations[ds_storage_class], OPT_Wpedantic,
16899 : "%<static%> specifier invalid for function %qs "
16900 : "declared out of global scope", name);
16901 : else
16902 3 : pedwarn (declspecs->locations[ds_inline], OPT_Wpedantic,
16903 : "%<inline%> specifier invalid for function %qs "
16904 : "declared out of global scope", name);
16905 : }
16906 :
16907 77315278 : if (ctype == NULL_TREE)
16908 : {
16909 68506128 : if (virtualp)
16910 : {
16911 0 : error ("virtual non-class function %qs", name);
16912 0 : virtualp = 0;
16913 : }
16914 68506128 : else if (sfk == sfk_constructor
16915 68506128 : || sfk == sfk_destructor)
16916 : {
16917 3 : error (funcdef_flag
16918 : ? G_("%qs defined in a non-class scope")
16919 : : G_("%qs declared in a non-class scope"), name);
16920 3 : sfk = sfk_none;
16921 : }
16922 : }
16923 77315278 : if (consteval_p
16924 77539720 : && identifier_p (unqualified_id)
16925 77539720 : && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
16926 : {
16927 9 : error_at (declspecs->locations[ds_consteval],
16928 : "%qD cannot be %qs", unqualified_id, "consteval");
16929 9 : consteval_p = false;
16930 : }
16931 :
16932 : /* Record whether the function is public. */
16933 77315278 : publicp = (ctype != NULL_TREE
16934 77315278 : || storage_class != sc_static);
16935 :
16936 154630556 : decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
16937 : declspecs, reqs, virtualp, flags, memfn_quals, rqual, raises,
16938 : 1, friendp,
16939 : publicp,
16940 77315278 : inlinep | (2 * constexpr_p) | (4 * concept_p)
16941 77315278 : | (8 * consteval_p),
16942 : initialized,
16943 : is_xobj_member_function, sfk,
16944 : funcdef_flag,
16945 : late_return_type_p,
16946 : template_count, in_namespace, attrlist,
16947 : contract_specifiers, id_loc);
16948 77315278 : if (decl == NULL_TREE)
16949 592 : return error_mark_node;
16950 :
16951 77314686 : if (explicitp == 2)
16952 10424 : DECL_NONCONVERTING_P (decl) = 1;
16953 77314686 : if (staticp == 1)
16954 : {
16955 110257 : int invalid_static = 0;
16956 :
16957 : /* Don't allow a static member function in a class, and forbid
16958 : declaring main to be static. */
16959 110257 : if (TREE_CODE (type) == METHOD_TYPE)
16960 : {
16961 0 : permerror (input_location, "cannot declare member function %qD to have "
16962 : "static linkage", decl);
16963 0 : invalid_static = 1;
16964 : }
16965 110257 : else if (current_function_decl)
16966 : {
16967 : /* 7.1.1: There can be no static function declarations within a
16968 : block. */
16969 9 : error_at (declspecs->locations[ds_storage_class],
16970 : "cannot declare static function inside another function");
16971 9 : invalid_static = 1;
16972 : }
16973 :
16974 9 : if (invalid_static)
16975 : {
16976 77314686 : staticp = 0;
16977 : storage_class = sc_none;
16978 : }
16979 : }
16980 77314686 : if (declspecs->explicit_specifier)
16981 3 : store_explicit_specifier (decl, declspecs->explicit_specifier);
16982 : }
16983 : else
16984 : {
16985 : /* It's a variable. */
16986 :
16987 : /* An uninitialized decl with `extern' is a reference. */
16988 133670691 : decl = grokvardecl (type, dname, unqualified_id,
16989 : declspecs,
16990 : initialized,
16991 : type_quals,
16992 : inlinep,
16993 : concept_p,
16994 : template_count,
16995 : ctype ? ctype : in_namespace,
16996 : id_loc);
16997 67078568 : if (decl == NULL_TREE)
16998 52 : return error_mark_node;
16999 :
17000 67078516 : bad_specifiers (decl, BSP_VAR, virtualp,
17001 : memfn_quals != TYPE_UNQUALIFIED,
17002 : inlinep, friendp, raises != NULL_TREE,
17003 : declspecs->locations);
17004 :
17005 67078516 : if (ctype)
17006 : {
17007 486439 : DECL_CONTEXT (decl) = ctype;
17008 486439 : if (staticp == 1)
17009 : {
17010 6 : permerror (declspecs->locations[ds_storage_class],
17011 : "%<static%> may not be used when defining "
17012 : "(as opposed to declaring) a static data member");
17013 6 : staticp = 0;
17014 6 : storage_class = sc_none;
17015 : }
17016 486439 : if (storage_class == sc_register && TREE_STATIC (decl))
17017 : {
17018 0 : error ("static member %qD declared %<register%>", decl);
17019 0 : storage_class = sc_none;
17020 : }
17021 486439 : if (storage_class == sc_extern && pedantic)
17022 : {
17023 0 : pedwarn (input_location, OPT_Wpedantic,
17024 : "cannot explicitly declare member %q#D to have "
17025 : "extern linkage", decl);
17026 0 : storage_class = sc_none;
17027 : }
17028 : }
17029 66592077 : else if (constexpr_p && DECL_EXTERNAL (decl))
17030 : {
17031 13 : error_at (DECL_SOURCE_LOCATION (decl),
17032 : "declaration of %<constexpr%> variable %qD "
17033 : "is not a definition", decl);
17034 13 : constexpr_p = false;
17035 : }
17036 67078516 : if (consteval_p)
17037 : {
17038 13 : error_at (DECL_SOURCE_LOCATION (decl),
17039 : "a variable cannot be declared %<consteval%>");
17040 13 : consteval_p = false;
17041 : }
17042 :
17043 67078516 : if (inlinep)
17044 6442747 : mark_inline_variable (decl, declspecs->locations[ds_inline]);
17045 67078516 : if (innermost_code == cdk_decomp)
17046 : {
17047 219966 : gcc_assert (declarator && declarator->kind == cdk_decomp);
17048 219966 : DECL_SOURCE_LOCATION (decl) = id_loc;
17049 219966 : DECL_ARTIFICIAL (decl) = 1;
17050 219966 : fit_decomposition_lang_decl (decl, NULL_TREE);
17051 : }
17052 : }
17053 :
17054 566948653 : if (VAR_P (decl) && !initialized)
17055 7363273 : if (tree auto_node = type_uses_auto (type))
17056 99 : if (!CLASS_PLACEHOLDER_TEMPLATE (auto_node))
17057 : {
17058 18 : location_t loc = declspecs->locations[ds_type_spec];
17059 18 : error_at (loc, "declaration of %q#D has no initializer", decl);
17060 18 : TREE_TYPE (decl) = error_mark_node;
17061 : }
17062 :
17063 566948653 : if (storage_class == sc_extern && initialized && !funcdef_flag)
17064 : {
17065 269 : if (toplevel_bindings_p ())
17066 : {
17067 : /* It's common practice (and completely valid) to have a const
17068 : be initialized and declared extern. */
17069 245 : if (!(type_quals & TYPE_QUAL_CONST))
17070 20 : warning_at (DECL_SOURCE_LOCATION (decl), 0,
17071 : "%qs initialized and declared %<extern%>", name);
17072 : }
17073 : else
17074 : {
17075 24 : error_at (DECL_SOURCE_LOCATION (decl),
17076 : "%qs has both %<extern%> and initializer", name);
17077 24 : return error_mark_node;
17078 : }
17079 : }
17080 :
17081 : /* Record `register' declaration for warnings on &
17082 : and in case doing stupid register allocation. */
17083 :
17084 566948629 : if (storage_class == sc_register)
17085 : {
17086 2069 : DECL_REGISTER (decl) = 1;
17087 : /* Warn about register storage specifiers on PARM_DECLs. */
17088 2069 : if (TREE_CODE (decl) == PARM_DECL)
17089 : {
17090 35 : if (cxx_dialect >= cxx17)
17091 24 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
17092 : "ISO C++17 does not allow %<register%> storage "
17093 : "class specifier");
17094 : else
17095 11 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wregister,
17096 : "%<register%> storage class specifier used");
17097 : }
17098 : }
17099 566946560 : else if (storage_class == sc_extern)
17100 30497400 : DECL_THIS_EXTERN (decl) = 1;
17101 536449160 : else if (storage_class == sc_static)
17102 23122505 : DECL_THIS_STATIC (decl) = 1;
17103 :
17104 566948629 : if (VAR_P (decl))
17105 : {
17106 : /* Set constexpr flag on vars (functions got it in grokfndecl). */
17107 79811346 : if (constexpr_p)
17108 19129447 : DECL_DECLARED_CONSTEXPR_P (decl) = true;
17109 : /* And the constinit flag (which only applies to variables). */
17110 60681899 : else if (constinit_p)
17111 438 : DECL_DECLARED_CONSTINIT_P (decl) = true;
17112 : }
17113 487137283 : else if (TREE_CODE (decl) == FUNCTION_DECL)
17114 : {
17115 : /* If we saw a return type, record its location. */
17116 178525659 : location_t loc = declspecs->locations[ds_type_spec];
17117 178525659 : if (loc == UNKNOWN_LOCATION)
17118 : /* Build DECL_RESULT in start_preparsed_function. */;
17119 146160644 : else if (!DECL_RESULT (decl))
17120 : {
17121 146124065 : tree restype = TREE_TYPE (TREE_TYPE (decl));
17122 146124065 : tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
17123 146124065 : DECL_ARTIFICIAL (resdecl) = 1;
17124 146124065 : DECL_IGNORED_P (resdecl) = 1;
17125 146124065 : DECL_RESULT (decl) = resdecl;
17126 : }
17127 36579 : else if (funcdef_flag)
17128 3 : DECL_SOURCE_LOCATION (DECL_RESULT (decl)) = loc;
17129 : }
17130 :
17131 : /* Record constancy and volatility on the DECL itself . There's
17132 : no need to do this when processing a template; we'll do this
17133 : for the instantiated declaration based on the type of DECL. */
17134 566948629 : if (!processing_template_decl
17135 : /* Don't do it for instantiated variable templates either,
17136 : cp_apply_type_quals_to_decl should have been called on it
17137 : already and might have been overridden in cp_finish_decl
17138 : if initializer needs runtime initialization. */
17139 566948629 : && (!VAR_P (decl) || !DECL_TEMPLATE_INSTANTIATED (decl)))
17140 189954980 : cp_apply_type_quals_to_decl (type_quals, decl);
17141 :
17142 566948629 : return decl;
17143 : }
17144 1020642479 : }
17145 :
17146 : /* Subroutine of start_function. Ensure that each of the parameter
17147 : types (as listed in PARMS) is complete, as is required for a
17148 : function definition. */
17149 :
17150 : static void
17151 157955161 : require_complete_types_for_parms (tree parms)
17152 : {
17153 468157955 : for (; parms; parms = DECL_CHAIN (parms))
17154 : {
17155 310202794 : if (dependent_type_p (TREE_TYPE (parms)))
17156 173894280 : continue;
17157 136308514 : if (!VOID_TYPE_P (TREE_TYPE (parms))
17158 136308514 : && complete_type_or_else (TREE_TYPE (parms), parms))
17159 : {
17160 136308433 : relayout_decl (parms);
17161 136308433 : DECL_ARG_TYPE (parms) = type_passed_as (TREE_TYPE (parms));
17162 :
17163 136308433 : abstract_virtuals_error (parms, TREE_TYPE (parms));
17164 136308433 : maybe_warn_parm_abi (TREE_TYPE (parms),
17165 136308433 : DECL_SOURCE_LOCATION (parms));
17166 : }
17167 : else
17168 : /* grokparms or complete_type_or_else will have already issued
17169 : an error. */
17170 81 : TREE_TYPE (parms) = error_mark_node;
17171 : }
17172 157955161 : }
17173 :
17174 : /* Returns nonzero if T is a local variable. */
17175 :
17176 : int
17177 168039890 : local_variable_p (const_tree t)
17178 : {
17179 168039890 : if ((VAR_P (t)
17180 63965094 : && (DECL_LOCAL_DECL_P (t)
17181 63965094 : || !DECL_CONTEXT (t)
17182 63924183 : || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
17183 173417094 : || (TREE_CODE (t) == PARM_DECL))
17184 149672950 : return 1;
17185 :
17186 : return 0;
17187 : }
17188 :
17189 : /* Like local_variable_p, but suitable for use as a tree-walking
17190 : function. */
17191 :
17192 : static tree
17193 5370304 : local_variable_p_walkfn (tree *tp, int *walk_subtrees,
17194 : void * /*data*/)
17195 : {
17196 5370304 : if (unevaluated_p (TREE_CODE (*tp)))
17197 : {
17198 : /* DR 2082 permits local variables in unevaluated contexts
17199 : within a default argument. */
17200 22 : *walk_subtrees = 0;
17201 22 : return NULL_TREE;
17202 : }
17203 :
17204 5370282 : if (local_variable_p (*tp)
17205 5370282 : && (!DECL_ARTIFICIAL (*tp) || DECL_NAME (*tp) == this_identifier))
17206 : return *tp;
17207 5370282 : else if (TYPE_P (*tp))
17208 30 : *walk_subtrees = 0;
17209 :
17210 : return NULL_TREE;
17211 : }
17212 :
17213 : /* Check that ARG, which is a default-argument expression for a
17214 : parameter DECL, is valid. Returns ARG, or ERROR_MARK_NODE, if
17215 : something goes wrong. DECL may also be a _TYPE node, rather than a
17216 : DECL, if there is no DECL available. */
17217 :
17218 : tree
17219 2677688 : check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
17220 : {
17221 2677688 : tree var;
17222 2677688 : tree decl_type;
17223 :
17224 2677688 : if (TREE_CODE (arg) == DEFERRED_PARSE)
17225 : /* We get a DEFERRED_PARSE when looking at an in-class declaration
17226 : with a default argument. Ignore the argument for now; we'll
17227 : deal with it after the class is complete. */
17228 : return arg;
17229 :
17230 1889560 : if (TYPE_P (decl))
17231 : {
17232 : decl_type = decl;
17233 : decl = NULL_TREE;
17234 : }
17235 : else
17236 562656 : decl_type = TREE_TYPE (decl);
17237 :
17238 1889560 : if (arg == error_mark_node
17239 1889440 : || decl == error_mark_node
17240 1889431 : || TREE_TYPE (arg) == error_mark_node
17241 3778991 : || decl_type == error_mark_node)
17242 : /* Something already went wrong. There's no need to check
17243 : further. */
17244 : return error_mark_node;
17245 :
17246 : /* [dcl.fct.default]
17247 :
17248 : A default argument expression is implicitly converted to the
17249 : parameter type. */
17250 1889431 : ++cp_unevaluated_operand;
17251 : /* Avoid digest_init clobbering the initializer. */
17252 1889431 : tree carg = BRACE_ENCLOSED_INITIALIZER_P (arg) ? unshare_expr (arg): arg;
17253 1889431 : perform_implicit_conversion_flags (decl_type, carg, complain,
17254 : LOOKUP_IMPLICIT);
17255 1889431 : --cp_unevaluated_operand;
17256 :
17257 : /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
17258 : the call sites. */
17259 1502682 : if (TYPE_PTR_OR_PTRMEM_P (decl_type)
17260 386764 : && null_ptr_cst_p (arg)
17261 : /* Don't lose side-effects as in PR90473. */
17262 2254831 : && !TREE_SIDE_EFFECTS (arg))
17263 365397 : return nullptr_node;
17264 :
17265 : /* [dcl.fct.default]
17266 :
17267 : Local variables shall not be used in default argument
17268 : expressions.
17269 :
17270 : The keyword `this' shall not be used in a default argument of a
17271 : member function. */
17272 1524034 : var = cp_walk_tree_without_duplicates (&arg, local_variable_p_walkfn, NULL);
17273 1524034 : if (var)
17274 : {
17275 0 : if (complain & tf_warning_or_error)
17276 : {
17277 0 : if (DECL_NAME (var) == this_identifier)
17278 0 : permerror (input_location, "default argument %qE uses %qD",
17279 : arg, var);
17280 : else
17281 0 : error ("default argument %qE uses local variable %qD", arg, var);
17282 : }
17283 0 : return error_mark_node;
17284 : }
17285 :
17286 : /* All is well. */
17287 1524034 : return arg;
17288 : }
17289 :
17290 : /* Returns a deprecated type used within TYPE, or NULL_TREE if none. */
17291 :
17292 : static tree
17293 276494393 : type_is_deprecated (tree type)
17294 : {
17295 407743658 : enum tree_code code;
17296 407743658 : if (TREE_DEPRECATED (type))
17297 : return type;
17298 407703977 : if (TYPE_NAME (type))
17299 : {
17300 272354876 : if (TREE_DEPRECATED (TYPE_NAME (type)))
17301 : return type;
17302 : else
17303 : {
17304 272354870 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
17305 272354870 : return NULL_TREE;
17306 : }
17307 : }
17308 :
17309 : /* Do warn about using typedefs to a deprecated class. */
17310 135349101 : if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
17311 0 : return type_is_deprecated (TYPE_MAIN_VARIANT (type));
17312 :
17313 135349101 : code = TREE_CODE (type);
17314 :
17315 135349101 : if (code == POINTER_TYPE || code == REFERENCE_TYPE
17316 135349101 : || code == OFFSET_TYPE || code == FUNCTION_TYPE
17317 : || code == METHOD_TYPE || code == ARRAY_TYPE)
17318 131135128 : return type_is_deprecated (TREE_TYPE (type));
17319 :
17320 114137 : if (TYPE_PTRMEMFUNC_P (type))
17321 114137 : return type_is_deprecated
17322 114137 : (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
17323 :
17324 : return NULL_TREE;
17325 : }
17326 :
17327 : /* Returns an unavailable type used within TYPE, or NULL_TREE if none. */
17328 :
17329 : static tree
17330 277686195 : type_is_unavailable (tree type)
17331 : {
17332 409646410 : enum tree_code code;
17333 409646410 : if (TREE_UNAVAILABLE (type))
17334 : return type;
17335 409646404 : if (TYPE_NAME (type))
17336 : {
17337 273586296 : if (TREE_UNAVAILABLE (TYPE_NAME (type)))
17338 : return type;
17339 : else
17340 : {
17341 273586290 : cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
17342 273586290 : return NULL_TREE;
17343 : }
17344 : }
17345 :
17346 : /* Do warn about using typedefs to a deprecated class. */
17347 136060108 : if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
17348 0 : return type_is_deprecated (TYPE_MAIN_VARIANT (type));
17349 :
17350 136060108 : code = TREE_CODE (type);
17351 :
17352 136060108 : if (code == POINTER_TYPE || code == REFERENCE_TYPE
17353 136060108 : || code == OFFSET_TYPE || code == FUNCTION_TYPE
17354 : || code == METHOD_TYPE || code == ARRAY_TYPE)
17355 131738806 : return type_is_unavailable (TREE_TYPE (type));
17356 :
17357 221409 : if (TYPE_PTRMEMFUNC_P (type))
17358 221409 : return type_is_unavailable
17359 221409 : (TREE_TYPE (TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))));
17360 :
17361 : return NULL_TREE;
17362 : }
17363 :
17364 : /* Decode the list of parameter types for a function type.
17365 : Given the list of things declared inside the parens,
17366 : return a list of types.
17367 :
17368 : If this parameter does not end with an ellipsis, we append
17369 : void_list_node.
17370 :
17371 : *PARMS is set to the chain of PARM_DECLs created. */
17372 :
17373 : tree
17374 189940519 : grokparms (tree parmlist, tree *parms)
17375 : {
17376 189940519 : tree result = NULL_TREE;
17377 189940519 : tree decls = NULL_TREE;
17378 189940519 : tree parm;
17379 189940519 : int any_error = 0;
17380 :
17381 468237144 : for (parm = parmlist; parm != NULL_TREE; parm = TREE_CHAIN (parm))
17382 : {
17383 465862391 : tree type = NULL_TREE;
17384 465862391 : tree init = TREE_PURPOSE (parm);
17385 465862391 : tree decl = TREE_VALUE (parm);
17386 :
17387 465862391 : if (parm == void_list_node || parm == explicit_void_list_node)
17388 : break;
17389 :
17390 278296639 : if (! decl || TREE_TYPE (decl) == error_mark_node)
17391 : {
17392 187 : any_error = 1;
17393 187 : continue;
17394 : }
17395 :
17396 278296452 : type = TREE_TYPE (decl);
17397 278296452 : if (VOID_TYPE_P (type))
17398 : {
17399 80 : if (same_type_p (type, void_type_node)
17400 71 : && !init
17401 59 : && !DECL_NAME (decl) && !result
17402 106 : && TREE_CHAIN (parm) == void_list_node)
17403 : /* DR 577: A parameter list consisting of a single
17404 : unnamed parameter of non-dependent type 'void'. */
17405 : break;
17406 66 : else if (cv_qualified_p (type))
17407 9 : error_at (DECL_SOURCE_LOCATION (decl),
17408 : "invalid use of cv-qualified type %qT in "
17409 : "parameter declaration", type);
17410 : else
17411 57 : error_at (DECL_SOURCE_LOCATION (decl),
17412 : "invalid use of type %<void%> in parameter "
17413 : "declaration");
17414 : /* It's not a good idea to actually create parameters of
17415 : type `void'; other parts of the compiler assume that a
17416 : void type terminates the parameter list. */
17417 66 : type = error_mark_node;
17418 66 : TREE_TYPE (decl) = error_mark_node;
17419 : }
17420 :
17421 278296438 : if (type != error_mark_node)
17422 : {
17423 278296372 : if (deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
17424 : {
17425 277686195 : tree unavailtype = type_is_unavailable (type);
17426 277686195 : if (unavailtype)
17427 12 : cp_handle_deprecated_or_unavailable (unavailtype);
17428 : }
17429 278296372 : if (deprecated_state != DEPRECATED_SUPPRESS
17430 278296372 : && deprecated_state != UNAVAILABLE_DEPRECATED_SUPPRESS)
17431 : {
17432 276494393 : tree deptype = type_is_deprecated (type);
17433 276494393 : if (deptype)
17434 39687 : cp_handle_deprecated_or_unavailable (deptype);
17435 : }
17436 :
17437 : /* [dcl.fct] "A parameter with volatile-qualified type is
17438 : deprecated." */
17439 278296372 : if (CP_TYPE_VOLATILE_P (type))
17440 504 : warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
17441 : "%<volatile%>-qualified parameter is "
17442 : "deprecated");
17443 :
17444 : /* Top-level qualifiers on the parameters are
17445 : ignored for function types. */
17446 278296372 : type = cp_build_qualified_type (type, 0);
17447 278296372 : if (TREE_CODE (type) == METHOD_TYPE)
17448 : {
17449 0 : error ("parameter %qD invalidly declared method type", decl);
17450 0 : type = build_pointer_type (type);
17451 0 : TREE_TYPE (decl) = type;
17452 : }
17453 278296372 : else if (cxx_dialect < cxx17 && INDIRECT_TYPE_P (type))
17454 : {
17455 : /* Before C++17 DR 393:
17456 : [dcl.fct]/6, parameter types cannot contain pointers
17457 : (references) to arrays of unknown bound. */
17458 1700159 : tree t = TREE_TYPE (type);
17459 1700159 : int ptr = TYPE_PTR_P (type);
17460 :
17461 1863795 : while (1)
17462 : {
17463 1781977 : if (TYPE_PTR_P (t))
17464 : ptr = 1;
17465 1703352 : else if (TREE_CODE (t) != ARRAY_TYPE)
17466 : break;
17467 3203 : else if (!TYPE_DOMAIN (t))
17468 : break;
17469 81818 : t = TREE_TYPE (t);
17470 : }
17471 1700159 : if (TREE_CODE (t) == ARRAY_TYPE)
17472 16 : pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
17473 : ptr
17474 : ? G_("parameter %qD includes pointer to array of "
17475 : "unknown bound %qT")
17476 : : G_("parameter %qD includes reference to array of "
17477 : "unknown bound %qT"),
17478 : decl, t);
17479 : }
17480 :
17481 278296372 : if (init && !processing_template_decl)
17482 1350775 : init = check_default_argument (decl, init, tf_warning_or_error);
17483 : }
17484 :
17485 278296438 : DECL_CHAIN (decl) = decls;
17486 278296438 : decls = decl;
17487 278296438 : result = tree_cons (init, type, result);
17488 : }
17489 189940519 : decls = nreverse (decls);
17490 189940519 : result = nreverse (result);
17491 189940519 : if (parm)
17492 187565766 : result = chainon (result, void_list_node);
17493 189940519 : *parms = decls;
17494 189940519 : if (any_error)
17495 173 : result = NULL_TREE;
17496 :
17497 173 : if (any_error)
17498 : /* We had parm errors, recover by giving the function (...) type. */
17499 173 : result = NULL_TREE;
17500 :
17501 189940519 : return result;
17502 : }
17503 :
17504 :
17505 : /* D is a constructor or overloaded `operator='.
17506 :
17507 : Let T be the class in which D is declared. Then, this function
17508 : returns:
17509 :
17510 : -1 if D's is an ill-formed constructor or copy assignment operator
17511 : whose first parameter is of type `T'.
17512 : 0 if D is not a copy constructor or copy assignment
17513 : operator.
17514 : 1 if D is a copy constructor or copy assignment operator whose
17515 : first parameter is a reference to non-const qualified T.
17516 : 2 if D is a copy constructor or copy assignment operator whose
17517 : first parameter is a reference to const qualified T.
17518 :
17519 : This function can be used as a predicate. Positive values indicate
17520 : a copy constructor and nonzero values indicate a copy assignment
17521 : operator. */
17522 :
17523 : int
17524 332378241 : copy_fn_p (const_tree d)
17525 : {
17526 332378241 : tree args;
17527 332378241 : tree arg_type;
17528 332378241 : int result = 1;
17529 :
17530 332378241 : gcc_assert (DECL_FUNCTION_MEMBER_P (d));
17531 :
17532 332378241 : if (TREE_CODE (d) == TEMPLATE_DECL
17533 332378241 : || (DECL_TEMPLATE_INFO (d)
17534 147771828 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
17535 : /* Instantiations of template member functions are never copy
17536 : functions. Note that member functions of templated classes are
17537 : represented as template functions internally, and we must
17538 : accept those as copy functions. */
17539 : return 0;
17540 :
17541 280973823 : if (!DECL_CONSTRUCTOR_P (d)
17542 280973823 : && DECL_NAME (d) != assign_op_identifier)
17543 : return 0;
17544 :
17545 280179130 : if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
17546 : {
17547 126 : tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
17548 126 : if (!TYPE_REF_P (object_param)
17549 120 : || TYPE_REF_IS_RVALUE (object_param)
17550 : /* Reject unrelated object parameters. */
17551 108 : || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
17552 234 : || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
17553 24 : return 0;
17554 102 : args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
17555 : }
17556 : else
17557 280179004 : args = FUNCTION_FIRST_USER_PARMTYPE (d);
17558 280179106 : if (!args)
17559 : return 0;
17560 :
17561 280171555 : arg_type = TREE_VALUE (args);
17562 280171555 : if (arg_type == error_mark_node)
17563 : return 0;
17564 :
17565 280171520 : if (TYPE_MAIN_VARIANT (arg_type) == DECL_CONTEXT (d))
17566 : {
17567 : /* Pass by value copy assignment operator. */
17568 : result = -1;
17569 : }
17570 280170271 : else if (TYPE_REF_P (arg_type)
17571 177139655 : && !TYPE_REF_IS_RVALUE (arg_type)
17572 392447532 : && TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)) == DECL_CONTEXT (d))
17573 : {
17574 89988113 : if (CP_TYPE_CONST_P (TREE_TYPE (arg_type)))
17575 89823439 : result = 2;
17576 : }
17577 : else
17578 : return 0;
17579 :
17580 89989362 : args = TREE_CHAIN (args);
17581 :
17582 92753896 : if (args && args != void_list_node && !TREE_PURPOSE (args))
17583 : /* There are more non-optional args. */
17584 : return 0;
17585 :
17586 : return result;
17587 : }
17588 :
17589 : /* D is a constructor or overloaded `operator='.
17590 :
17591 : Let T be the class in which D is declared. Then, this function
17592 : returns true when D is a move constructor or move assignment
17593 : operator, false otherwise. */
17594 :
17595 : bool
17596 153355271 : move_fn_p (const_tree d)
17597 : {
17598 153355271 : if (cxx_dialect == cxx98)
17599 : /* There are no move constructors if we are in C++98 mode. */
17600 : return false;
17601 :
17602 153284598 : if (TREE_CODE (d) == TEMPLATE_DECL
17603 153284598 : || (DECL_TEMPLATE_INFO (d)
17604 62423225 : && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (d))))
17605 : /* Instantiations of template member functions are never move
17606 : functions. Note that member functions of templated classes are
17607 : represented as template functions internally, and we must
17608 : accept those as move functions. */
17609 : return 0;
17610 :
17611 124928940 : return move_signature_fn_p (d);
17612 : }
17613 :
17614 : /* D is a constructor or overloaded `operator='.
17615 :
17616 : Then, this function returns true when D has the same signature as a move
17617 : constructor or move assignment operator (because either it is such a
17618 : ctor/op= or it is a template specialization with the same signature),
17619 : false otherwise. */
17620 :
17621 : bool
17622 124928940 : move_signature_fn_p (const_tree d)
17623 : {
17624 124928940 : tree args;
17625 124928940 : tree arg_type;
17626 124928940 : bool result = false;
17627 :
17628 124928940 : if (!DECL_CONSTRUCTOR_P (d)
17629 124928940 : && DECL_NAME (d) != assign_op_identifier)
17630 : return 0;
17631 :
17632 124928871 : if (DECL_XOBJ_MEMBER_FUNCTION_P (d))
17633 : {
17634 68 : tree object_param = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (d)));
17635 68 : if (!TYPE_REF_P (object_param)
17636 64 : || TYPE_REF_IS_RVALUE (object_param)
17637 : /* Reject unrelated object parameters. */
17638 56 : || TYPE_MAIN_VARIANT (TREE_TYPE (object_param)) != DECL_CONTEXT (d)
17639 124 : || CP_TYPE_CONST_P (TREE_TYPE (object_param)))
17640 16 : return 0;
17641 52 : args = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (d)));
17642 : }
17643 : else
17644 124928803 : args = FUNCTION_FIRST_USER_PARMTYPE (d);
17645 124928855 : if (!args)
17646 : return 0;
17647 :
17648 124926056 : arg_type = TREE_VALUE (args);
17649 124926056 : if (arg_type == error_mark_node)
17650 : return 0;
17651 :
17652 124926048 : if (TYPE_REF_P (arg_type)
17653 63503131 : && TYPE_REF_IS_RVALUE (arg_type)
17654 174408732 : && same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (arg_type)),
17655 : DECL_CONTEXT (d)))
17656 : result = true;
17657 :
17658 124926048 : args = TREE_CHAIN (args);
17659 :
17660 139536342 : if (args && args != void_list_node && !TREE_PURPOSE (args))
17661 : /* There are more non-optional args. */
17662 : return false;
17663 :
17664 : return result;
17665 : }
17666 :
17667 : /* Remember any special properties of member function DECL. */
17668 :
17669 : void
17670 342030226 : grok_special_member_properties (tree decl)
17671 : {
17672 342030226 : tree class_type;
17673 :
17674 342030226 : if (TREE_CODE (decl) == USING_DECL
17675 342030226 : || !DECL_OBJECT_MEMBER_FUNCTION_P (decl))
17676 : return;
17677 :
17678 321277229 : class_type = DECL_CONTEXT (decl);
17679 321277229 : if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
17680 : {
17681 144873219 : int ctor = copy_fn_p (decl);
17682 :
17683 144873219 : if (!DECL_ARTIFICIAL (decl))
17684 101244351 : TYPE_HAS_USER_CONSTRUCTOR (class_type) = 1;
17685 :
17686 144873219 : if (ctor > 0)
17687 : {
17688 : /* [class.copy]
17689 :
17690 : A non-template constructor for class X is a copy
17691 : constructor if its first parameter is of type X&, const
17692 : X&, volatile X& or const volatile X&, and either there
17693 : are no other parameters or else all other parameters have
17694 : default arguments. */
17695 29393588 : TYPE_HAS_COPY_CTOR (class_type) = 1;
17696 29393588 : if (ctor > 1)
17697 29317044 : TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
17698 : }
17699 :
17700 144873219 : if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
17701 30829942 : TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
17702 :
17703 144873219 : if (is_list_ctor (decl))
17704 1485585 : TYPE_HAS_LIST_CTOR (class_type) = 1;
17705 :
17706 144873219 : if (maybe_constexpr_fn (decl)
17707 144873219 : && !ctor && !move_fn_p (decl))
17708 52249079 : TYPE_HAS_CONSTEXPR_CTOR (class_type) = 1;
17709 : }
17710 176404010 : else if (DECL_NAME (decl) == assign_op_identifier)
17711 : {
17712 : /* [class.copy]
17713 :
17714 : A non-template assignment operator for class X is a copy
17715 : assignment operator if its parameter is of type X, X&, const
17716 : X&, volatile X& or const volatile X&. */
17717 :
17718 14777094 : int assop = copy_fn_p (decl);
17719 :
17720 14777094 : if (assop)
17721 : {
17722 7526930 : TYPE_HAS_COPY_ASSIGN (class_type) = 1;
17723 7526930 : if (assop != 1)
17724 7499176 : TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
17725 : }
17726 : }
17727 161626916 : else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
17728 2668691 : TYPE_HAS_CONVERSION (class_type) = true;
17729 :
17730 : /* Destructors are handled in check_methods. */
17731 : }
17732 :
17733 : /* Check a constructor DECL has the correct form. Complains
17734 : if the class has a constructor of the form X(X). */
17735 :
17736 : bool
17737 46837247 : grok_ctor_properties (const_tree ctype, const_tree decl)
17738 : {
17739 46837247 : int ctor_parm = copy_fn_p (decl);
17740 :
17741 46837247 : if (ctor_parm < 0)
17742 : {
17743 : /* [class.copy]
17744 :
17745 : A declaration of a constructor for a class X is ill-formed if
17746 : its first parameter is of type (optionally cv-qualified) X
17747 : and either there are no other parameters or else all other
17748 : parameters have default arguments.
17749 :
17750 : We *don't* complain about member template instantiations that
17751 : have this form, though; they can occur as we try to decide
17752 : what constructor to use during overload resolution. Since
17753 : overload resolution will never prefer such a constructor to
17754 : the non-template copy constructor (which is either explicitly
17755 : or implicitly defined), there's no need to worry about their
17756 : existence. Theoretically, they should never even be
17757 : instantiated, but that's hard to forestall. */
17758 9 : error_at (DECL_SOURCE_LOCATION (decl),
17759 : "invalid constructor; you probably meant %<%T (const %T&)%>",
17760 : ctype, ctype);
17761 9 : return false;
17762 : }
17763 :
17764 : return true;
17765 : }
17766 :
17767 : /* DECL is a declaration for an overloaded or conversion operator. If
17768 : COMPLAIN is true, errors are issued for invalid declarations. */
17769 :
17770 : bool
17771 58313457 : grok_op_properties (tree decl, bool complain)
17772 : {
17773 58313457 : tree argtypes = TYPE_ARG_TYPES (TREE_TYPE (decl));
17774 58313457 : bool const methodp = DECL_IOBJ_MEMBER_FUNCTION_P (decl);
17775 58313457 : tree name = DECL_NAME (decl);
17776 58313457 : location_t loc = DECL_SOURCE_LOCATION (decl);
17777 :
17778 58313457 : tree class_type = DECL_CONTEXT (decl);
17779 58313457 : if (class_type && !CLASS_TYPE_P (class_type))
17780 : class_type = NULL_TREE;
17781 :
17782 58313457 : tree_code operator_code;
17783 58313457 : unsigned op_flags;
17784 58313457 : if (IDENTIFIER_CONV_OP_P (name))
17785 : {
17786 : /* Conversion operators are TYPE_EXPR for the purposes of this
17787 : function. */
17788 : operator_code = TYPE_EXPR;
17789 : op_flags = OVL_OP_FLAG_UNARY;
17790 : }
17791 : else
17792 : {
17793 56016748 : const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (name);
17794 :
17795 56016748 : operator_code = ovl_op->tree_code;
17796 56016748 : op_flags = ovl_op->flags;
17797 56016748 : gcc_checking_assert (operator_code != ERROR_MARK);
17798 56016748 : DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
17799 : }
17800 :
17801 56016748 : if (op_flags & OVL_OP_FLAG_ALLOC)
17802 : {
17803 : /* operator new and operator delete are quite special. */
17804 329476 : if (class_type)
17805 7447 : switch (op_flags)
17806 : {
17807 5025 : case OVL_OP_FLAG_ALLOC:
17808 5025 : TYPE_HAS_NEW_OPERATOR (class_type) = 1;
17809 5025 : break;
17810 :
17811 2151 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE:
17812 2151 : TYPE_GETS_DELETE (class_type) |= 1;
17813 2151 : break;
17814 :
17815 132 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_VEC:
17816 132 : TYPE_HAS_ARRAY_NEW_OPERATOR (class_type) = 1;
17817 132 : break;
17818 :
17819 139 : case OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE | OVL_OP_FLAG_VEC:
17820 139 : TYPE_GETS_DELETE (class_type) |= 2;
17821 139 : break;
17822 :
17823 0 : default:
17824 0 : gcc_unreachable ();
17825 : }
17826 :
17827 : /* [basic.std.dynamic.allocation]/1:
17828 :
17829 : A program is ill-formed if an allocation function is declared
17830 : in a namespace scope other than global scope or declared
17831 : static in global scope.
17832 :
17833 : The same also holds true for deallocation functions. */
17834 329476 : if (DECL_NAMESPACE_SCOPE_P (decl))
17835 : {
17836 322029 : if (CP_DECL_CONTEXT (decl) != global_namespace)
17837 : {
17838 6 : error_at (loc, "%qD may not be declared within a namespace",
17839 : decl);
17840 6 : return false;
17841 : }
17842 :
17843 322023 : if (!TREE_PUBLIC (decl))
17844 : {
17845 6 : error_at (loc, "%qD may not be declared as static", decl);
17846 6 : return false;
17847 : }
17848 : }
17849 :
17850 : /* Check for replaceable global new/delete operators with
17851 : const std::nothrow_t & last argument, other replaceable global
17852 : new/delete operators are marked in cxx_init_decl_processing. */
17853 329464 : if (CP_DECL_CONTEXT (decl) == global_namespace)
17854 : {
17855 322017 : tree args = argtypes;
17856 322017 : if (args
17857 322005 : && args != void_list_node
17858 966009 : && same_type_p (TREE_VALUE (args),
17859 : (op_flags & OVL_OP_FLAG_DELETE)
17860 : ? ptr_type_node : size_type_node))
17861 : {
17862 321975 : args = TREE_CHAIN (args);
17863 321975 : if (aligned_allocation_fn_p (decl))
17864 103668 : args = TREE_CHAIN (args);
17865 321975 : if (args
17866 321969 : && args != void_list_node
17867 536879 : && TREE_CHAIN (args) == void_list_node)
17868 : {
17869 188943 : tree t = TREE_VALUE (args);
17870 188943 : if (TYPE_REF_P (t)
17871 107179 : && !TYPE_REF_IS_RVALUE (t)
17872 107179 : && (t = TREE_TYPE (t))
17873 107179 : && TYPE_QUALS (t) == TYPE_QUAL_CONST
17874 295662 : && is_std_class (t, "nothrow_t"))
17875 106719 : DECL_IS_REPLACEABLE_OPERATOR (decl) = 1;
17876 : }
17877 : }
17878 : }
17879 :
17880 329464 : if (op_flags & OVL_OP_FLAG_DELETE)
17881 : {
17882 188624 : DECL_SET_IS_OPERATOR_DELETE (decl, true);
17883 188624 : coerce_delete_type (decl, loc);
17884 : }
17885 : else
17886 : {
17887 140840 : DECL_SET_IS_OPERATOR_NEW (decl, true);
17888 140840 : TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
17889 : }
17890 :
17891 329464 : return true;
17892 : }
17893 :
17894 : /* An operator function must either be a non-static member function
17895 : or have at least one parameter of a class, a reference to a class,
17896 : an enumeration, or a reference to an enumeration. 13.4.0.6 */
17897 57983981 : if (!DECL_OBJECT_MEMBER_FUNCTION_P (decl))
17898 : {
17899 14958054 : if (operator_code == TYPE_EXPR
17900 14958054 : || operator_code == COMPONENT_REF
17901 14958033 : || operator_code == NOP_EXPR)
17902 : {
17903 33 : error_at (loc, "%qD must be a non-static member function", decl);
17904 33 : return false;
17905 : }
17906 :
17907 14958021 : if (operator_code == CALL_EXPR || operator_code == ARRAY_REF)
17908 : {
17909 126808 : if (! DECL_STATIC_FUNCTION_P (decl))
17910 : {
17911 12 : error_at (loc, "%qD must be a member function", decl);
17912 12 : return false;
17913 : }
17914 126796 : if (cxx_dialect < cxx23
17915 : /* For lambdas we diagnose static lambda specifier elsewhere. */
17916 209826 : && (operator_code == ARRAY_REF || ! LAMBDA_FUNCTION_P (decl))
17917 : /* For instantiations, we have diagnosed this already. */
17918 231695 : && ! DECL_USE_TEMPLATE (decl))
17919 104893 : pedwarn (loc, OPT_Wc__23_extensions, "%qD may be a static member "
17920 : "function only with %<-std=c++23%> or %<-std=gnu++23%>",
17921 : decl);
17922 126796 : if (operator_code == ARRAY_REF)
17923 : /* static operator[] should have exactly one argument
17924 : for C++20 and earlier, so that it isn't multidimensional. */
17925 : op_flags = OVL_OP_FLAG_UNARY;
17926 : }
17927 14831213 : else if (DECL_STATIC_FUNCTION_P (decl))
17928 : {
17929 9 : error_at (loc, "%qD must be either a non-static member "
17930 : "function or a non-member function", decl);
17931 9 : return false;
17932 : }
17933 : else
17934 408299 : for (tree arg = argtypes; ; arg = TREE_CHAIN (arg))
17935 : {
17936 15239503 : if (!arg || arg == void_list_node)
17937 : {
17938 18 : if (complain)
17939 15 : error_at (loc, "%qD must have an argument of class or "
17940 : "enumerated type", decl);
17941 18 : return false;
17942 : }
17943 :
17944 15239485 : tree type = non_reference (TREE_VALUE (arg));
17945 15239485 : if (type == error_mark_node)
17946 : return false;
17947 :
17948 : /* MAYBE_CLASS_TYPE_P, rather than CLASS_TYPE_P, is used
17949 : because these checks are performed even on template
17950 : functions. */
17951 15239482 : if (MAYBE_CLASS_TYPE_P (type)
17952 1385120 : || TREE_CODE (type) == ENUMERAL_TYPE)
17953 : break;
17954 408299 : }
17955 : }
17956 :
17957 57981937 : if (operator_code == CALL_EXPR)
17958 : /* There are no further restrictions on the arguments to an overloaded
17959 : "operator ()". */
17960 : return true;
17961 :
17962 : /* C++23 allows an arbitrary number of parameters and default arguments for
17963 : operator[], and none of the other checks below apply. */
17964 48497052 : if (operator_code == ARRAY_REF && cxx_dialect >= cxx23)
17965 : return true;
17966 :
17967 48281285 : if (operator_code == COND_EXPR)
17968 : {
17969 : /* 13.4.0.3 */
17970 6 : error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
17971 6 : return false;
17972 : }
17973 :
17974 : /* Count the number of arguments and check for ellipsis. */
17975 : int arity = 0;
17976 137249281 : for (tree arg = argtypes; arg != void_list_node; arg = TREE_CHAIN (arg))
17977 : {
17978 88968017 : if (!arg)
17979 : {
17980 15 : error_at (loc, "%qD must not have variable number of arguments",
17981 : decl);
17982 15 : return false;
17983 : }
17984 88968002 : ++arity;
17985 : }
17986 : /* FIXME: We need tests for these errors with xobj member functions. */
17987 : /* Verify correct number of arguments. */
17988 48281264 : switch (op_flags)
17989 : {
17990 9959993 : case OVL_OP_FLAG_AMBIARY:
17991 9959993 : if (arity == 1)
17992 : {
17993 : /* We have a unary instance of an ambi-ary op. Remap to the
17994 : unary one. */
17995 4287318 : unsigned alt = ovl_op_alternate[ovl_op_mapping [operator_code]];
17996 4287318 : const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
17997 4287318 : gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
17998 4287318 : operator_code = ovl_op->tree_code;
17999 4287318 : DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
18000 : }
18001 5672675 : else if (arity != 2)
18002 : {
18003 : /* This was an ambiguous operator but is invalid. */
18004 3 : error_at (loc,
18005 : methodp
18006 : ? G_("%qD must have either zero or one argument")
18007 : : G_("%qD must have either one or two arguments"), decl);
18008 3 : return false;
18009 : }
18010 5672672 : else if ((operator_code == POSTINCREMENT_EXPR
18011 5672672 : || operator_code == POSTDECREMENT_EXPR)
18012 2636391 : && ! processing_template_decl
18013 : /* x++ and x--'s second argument must be an int. */
18014 7409510 : && ! same_type_p (TREE_VALUE (TREE_CHAIN (argtypes)),
18015 : integer_type_node))
18016 : {
18017 15 : error_at (loc,
18018 : methodp
18019 : ? G_("postfix %qD must have %<int%> as its argument")
18020 : : G_("postfix %qD must have %<int%> as its second argument"),
18021 : decl);
18022 15 : return false;
18023 : }
18024 : break;
18025 :
18026 3307238 : case OVL_OP_FLAG_UNARY:
18027 3307238 : if (arity != 1)
18028 : {
18029 9 : error_at (loc,
18030 : methodp
18031 : ? G_("%qD must have no arguments")
18032 : : G_("%qD must have exactly one argument"), decl);
18033 9 : return false;
18034 : }
18035 : break;
18036 :
18037 35014033 : case OVL_OP_FLAG_BINARY:
18038 35014033 : if (arity != 2)
18039 : {
18040 3 : error_at (loc,
18041 : methodp
18042 : ? G_("%qD must have exactly one argument")
18043 : : G_("%qD must have exactly two arguments"), decl);
18044 3 : return false;
18045 : }
18046 : break;
18047 :
18048 0 : default:
18049 0 : gcc_unreachable ();
18050 : }
18051 :
18052 : /* There can be no default arguments. */
18053 137249140 : for (tree arg = argtypes; arg && arg != void_list_node;
18054 88967906 : arg = TREE_CHAIN (arg))
18055 88967921 : if (TREE_PURPOSE (arg))
18056 : {
18057 15 : TREE_PURPOSE (arg) = NULL_TREE;
18058 15 : error_at (loc, "%qD cannot have default arguments", decl);
18059 15 : return false;
18060 : }
18061 :
18062 : /* At this point the declaration is well-formed. It may not be
18063 : sensible though. */
18064 :
18065 : /* Check member function warnings only on the in-class declaration.
18066 : There's no point warning on an out-of-class definition. */
18067 48281219 : if (class_type && class_type != current_class_type)
18068 : return true;
18069 :
18070 : /* Warn about conversion operators that will never be used. */
18071 46440482 : if (IDENTIFIER_CONV_OP_P (name)
18072 2296267 : && ! DECL_TEMPLATE_INFO (decl)
18073 47438621 : && warn_class_conversion)
18074 : {
18075 998106 : tree t = TREE_TYPE (name);
18076 998106 : int ref = TYPE_REF_P (t);
18077 :
18078 998106 : if (ref)
18079 21003 : t = TYPE_MAIN_VARIANT (TREE_TYPE (t));
18080 :
18081 998106 : if (VOID_TYPE_P (t))
18082 9 : warning_at (loc, OPT_Wclass_conversion, "converting %qT to %<void%> "
18083 : "will never use a type conversion operator", class_type);
18084 998097 : else if (class_type)
18085 : {
18086 998097 : if (same_type_ignoring_top_level_qualifiers_p (t, class_type))
18087 24 : warning_at (loc, OPT_Wclass_conversion,
18088 : ref
18089 : ? G_("converting %qT to a reference to the same type "
18090 : "will never use a type conversion operator")
18091 : : G_("converting %qT to the same type "
18092 : "will never use a type conversion operator"),
18093 : class_type);
18094 : /* Don't force t to be complete here. */
18095 998082 : else if (MAYBE_CLASS_TYPE_P (t)
18096 570951 : && COMPLETE_TYPE_P (t)
18097 152922 : && DERIVED_FROM_P (t, class_type))
18098 30 : warning_at (loc, OPT_Wclass_conversion,
18099 : ref
18100 : ? G_("converting %qT to a reference to a base class "
18101 : "%qT will never use a type conversion operator")
18102 : : G_("converting %qT to a base class %qT "
18103 : "will never use a type conversion operator"),
18104 : class_type, t);
18105 : }
18106 : }
18107 :
18108 46440482 : if (!warn_ecpp)
18109 : return true;
18110 :
18111 : /* Effective C++ rules below. */
18112 :
18113 : /* More Effective C++ rule 7. */
18114 54 : if (operator_code == TRUTH_ANDIF_EXPR
18115 54 : || operator_code == TRUTH_ORIF_EXPR
18116 54 : || operator_code == COMPOUND_EXPR)
18117 0 : warning_at (loc, OPT_Weffc__,
18118 : "user-defined %qD always evaluates both arguments", decl);
18119 :
18120 : /* More Effective C++ rule 6. */
18121 54 : if (operator_code == POSTINCREMENT_EXPR
18122 : || operator_code == POSTDECREMENT_EXPR
18123 : || operator_code == PREINCREMENT_EXPR
18124 54 : || operator_code == PREDECREMENT_EXPR)
18125 : {
18126 0 : tree arg = TREE_VALUE (argtypes);
18127 0 : tree ret = TREE_TYPE (TREE_TYPE (decl));
18128 0 : if (methodp || TYPE_REF_P (arg))
18129 0 : arg = TREE_TYPE (arg);
18130 0 : arg = TYPE_MAIN_VARIANT (arg);
18131 :
18132 0 : if (operator_code == PREINCREMENT_EXPR
18133 : || operator_code == PREDECREMENT_EXPR)
18134 : {
18135 0 : if (!TYPE_REF_P (ret)
18136 0 : || !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (ret)), arg))
18137 0 : warning_at (loc, OPT_Weffc__, "prefix %qD should return %qT", decl,
18138 : build_reference_type (arg));
18139 : }
18140 : else
18141 : {
18142 0 : if (!same_type_p (TYPE_MAIN_VARIANT (ret), arg))
18143 0 : warning_at (loc, OPT_Weffc__,
18144 : "postfix %qD should return %qT", decl, arg);
18145 : }
18146 : }
18147 :
18148 : /* Effective C++ rule 23. */
18149 54 : if (!DECL_ASSIGNMENT_OPERATOR_P (decl)
18150 : && (operator_code == PLUS_EXPR
18151 9 : || operator_code == MINUS_EXPR
18152 9 : || operator_code == TRUNC_DIV_EXPR
18153 : || operator_code == MULT_EXPR
18154 : || operator_code == TRUNC_MOD_EXPR)
18155 60 : && TYPE_REF_P (TREE_TYPE (TREE_TYPE (decl))))
18156 3 : warning_at (loc, OPT_Weffc__, "%qD should return by value", decl);
18157 :
18158 : return true;
18159 : }
18160 :
18161 : /* Return a string giving the keyword associate with CODE. */
18162 :
18163 : const char *
18164 3392 : tag_name (enum tag_types code)
18165 : {
18166 3392 : switch (code)
18167 : {
18168 : case record_type:
18169 : return "struct";
18170 107 : case class_type:
18171 107 : return "class";
18172 3 : case union_type:
18173 3 : return "union";
18174 9 : case enum_type:
18175 9 : return "enum";
18176 3184 : case typename_type:
18177 3184 : case none_type:
18178 3184 : return "typename";
18179 29 : case scope_type:
18180 29 : return nullptr;
18181 : }
18182 0 : gcc_unreachable ();
18183 : }
18184 :
18185 : /* Name lookup in an elaborated-type-specifier (after the keyword
18186 : indicated by TAG_CODE) has found the TYPE_DECL DECL. If the
18187 : elaborated-type-specifier is invalid, issue a diagnostic and return
18188 : error_mark_node; otherwise, return the *_TYPE to which it referred.
18189 : If ALLOW_TEMPLATE_P is true, TYPE may be a class template. */
18190 :
18191 : tree
18192 11940232 : check_elaborated_type_specifier (enum tag_types tag_code,
18193 : tree decl,
18194 : bool allow_template_p)
18195 : {
18196 11940232 : tree type;
18197 :
18198 : /* In the case of:
18199 :
18200 : struct S { struct S *p; };
18201 :
18202 : name lookup will find the TYPE_DECL for the implicit "S::S"
18203 : typedef. Adjust for that here. */
18204 11940232 : if (DECL_SELF_REFERENCE_P (decl))
18205 404184 : decl = TYPE_NAME (TREE_TYPE (decl));
18206 :
18207 11940232 : type = TREE_TYPE (decl);
18208 :
18209 : /* Check TEMPLATE_TYPE_PARM first because DECL_IMPLICIT_TYPEDEF_P
18210 : is false for this case as well. */
18211 11940232 : if (TREE_CODE (type) == TEMPLATE_TYPE_PARM)
18212 : {
18213 9 : error ("using template type parameter %qT after %qs",
18214 : type, tag_name (tag_code));
18215 9 : return error_mark_node;
18216 : }
18217 : /* Accept template template parameters. */
18218 11940223 : else if (allow_template_p
18219 6705063 : && (TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
18220 6705051 : || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM))
18221 : ;
18222 : /* [dcl.type.elab]
18223 :
18224 : If the identifier resolves to a typedef-name or the
18225 : simple-template-id resolves to an alias template
18226 : specialization, the elaborated-type-specifier is ill-formed.
18227 :
18228 : In other words, the only legitimate declaration to use in the
18229 : elaborated type specifier is the implicit typedef created when
18230 : the type is declared. */
18231 11940208 : else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
18232 404308 : && !DECL_SELF_REFERENCE_P (decl)
18233 11940332 : && tag_code != typename_type)
18234 : {
18235 78 : auto_diagnostic_group d;
18236 78 : if (alias_template_specialization_p (type, nt_opaque))
18237 21 : error ("using alias template specialization %qT after %qs",
18238 : type, tag_name (tag_code));
18239 : else
18240 57 : error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
18241 78 : inform (DECL_SOURCE_LOCATION (decl),
18242 : "%qD has a previous declaration here", decl);
18243 78 : return error_mark_node;
18244 78 : }
18245 11940130 : else if (TREE_CODE (type) != RECORD_TYPE
18246 11940130 : && TREE_CODE (type) != UNION_TYPE
18247 : && tag_code != enum_type
18248 70009 : && tag_code != typename_type)
18249 : {
18250 6 : auto_diagnostic_group d;
18251 6 : error ("%qT referred to as %qs", type, tag_name (tag_code));
18252 6 : inform (location_of (type), "%qT has a previous declaration here", type);
18253 6 : return error_mark_node;
18254 6 : }
18255 11940124 : else if (TREE_CODE (type) != ENUMERAL_TYPE
18256 11870157 : && tag_code == enum_type)
18257 : {
18258 3 : auto_diagnostic_group d;
18259 3 : error ("%qT referred to as enum", type);
18260 3 : inform (location_of (type), "%qT has a previous declaration here", type);
18261 3 : return error_mark_node;
18262 3 : }
18263 11940121 : else if (!allow_template_p
18264 5235100 : && TREE_CODE (type) == RECORD_TYPE
18265 17053499 : && CLASSTYPE_IS_TEMPLATE (type))
18266 : {
18267 : /* If a class template appears as elaborated type specifier
18268 : without a template header such as:
18269 :
18270 : template <class T> class C {};
18271 : void f(class C); // No template header here
18272 :
18273 : then the required template argument is missing. */
18274 18 : error ("template argument required for %<%s %T%>",
18275 : tag_name (tag_code),
18276 18 : DECL_NAME (CLASSTYPE_TI_TEMPLATE (type)));
18277 18 : return error_mark_node;
18278 : }
18279 :
18280 : return type;
18281 : }
18282 :
18283 : /* Lookup NAME of an elaborated type specifier according to SCOPE and
18284 : issue diagnostics if necessary. Return *_TYPE node upon success,
18285 : NULL_TREE when the NAME is not found, and ERROR_MARK_NODE for type
18286 : error. */
18287 :
18288 : static tree
18289 25665146 : lookup_and_check_tag (enum tag_types tag_code, tree name,
18290 : TAG_how how, bool template_header_p)
18291 : {
18292 25665146 : tree decl;
18293 25665146 : if (how == TAG_how::GLOBAL)
18294 : {
18295 : /* First try ordinary name lookup, ignoring hidden class name
18296 : injected via friend declaration. */
18297 2099874 : decl = lookup_name (name, LOOK_want::TYPE);
18298 : /* If that fails, the name will be placed in the smallest
18299 : non-class, non-function-prototype scope according to 3.3.1/5.
18300 : We may already have a hidden name declared as friend in this
18301 : scope. So lookup again but not ignoring hidden names.
18302 : If we find one, that name will be made visible rather than
18303 : creating a new tag. */
18304 2099874 : if (!decl)
18305 18129 : decl = lookup_elaborated_type (name, TAG_how::INNERMOST_NON_CLASS);
18306 : }
18307 : else
18308 23565272 : decl = lookup_elaborated_type (name, how);
18309 :
18310 23583401 : if (!decl)
18311 : /* We found nothing. */
18312 : return NULL_TREE;
18313 :
18314 5845304 : if (TREE_CODE (decl) == TREE_LIST)
18315 : {
18316 3 : auto_diagnostic_group d;
18317 3 : error ("reference to %qD is ambiguous", name);
18318 3 : print_candidates (input_location, decl);
18319 3 : return error_mark_node;
18320 3 : }
18321 :
18322 2363550 : if (DECL_CLASS_TEMPLATE_P (decl)
18323 2363544 : && !template_header_p
18324 8208845 : && how == TAG_how::CURRENT_ONLY)
18325 : {
18326 12 : auto_diagnostic_group d;
18327 12 : error ("class template %qD redeclared as non-template", name);
18328 12 : inform (location_of (decl), "previous declaration here");
18329 12 : CLASSTYPE_ERRONEOUS (TREE_TYPE (decl)) = true;
18330 12 : return error_mark_node;
18331 12 : }
18332 :
18333 2363538 : if (DECL_CLASS_TEMPLATE_P (decl)
18334 : /* If scope is TAG_how::CURRENT_ONLY we're defining a class,
18335 : so ignore a template template parameter. */
18336 5845295 : || (how != TAG_how::CURRENT_ONLY && DECL_TEMPLATE_TEMPLATE_PARM_P (decl)))
18337 2363535 : decl = DECL_TEMPLATE_RESULT (decl);
18338 :
18339 5845289 : if (TREE_CODE (decl) != TYPE_DECL)
18340 : /* Found not-a-type. */
18341 : return NULL_TREE;
18342 :
18343 : /* Look for invalid nested type:
18344 : class C {
18345 : class C {};
18346 : }; */
18347 5845268 : if (how == TAG_how::CURRENT_ONLY && DECL_SELF_REFERENCE_P (decl))
18348 : {
18349 6 : error ("%qD has the same name as the class in which it is "
18350 : "declared", decl);
18351 6 : return error_mark_node;
18352 : }
18353 :
18354 : /* Two cases we need to consider when deciding if a class
18355 : template is allowed as an elaborated type specifier:
18356 : 1. It is a self reference to its own class.
18357 : 2. It comes with a template header.
18358 :
18359 : For example:
18360 :
18361 : template <class T> class C {
18362 : class C *c1; // DECL_SELF_REFERENCE_P is true
18363 : class D;
18364 : };
18365 : template <class U> class C; // template_header_p is true
18366 : template <class T> class C<T>::D {
18367 : class C *c2; // DECL_SELF_REFERENCE_P is true
18368 : }; */
18369 :
18370 17535786 : tree t = check_elaborated_type_specifier (tag_code, decl,
18371 : template_header_p
18372 11286355 : | DECL_SELF_REFERENCE_P (decl));
18373 2535255 : if (template_header_p && t && CLASS_TYPE_P (t)
18374 8380505 : && (!CLASSTYPE_TEMPLATE_INFO (t)
18375 2535225 : || (!PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (t)))))
18376 : {
18377 21 : auto_diagnostic_group d;
18378 21 : error ("%qT is not a template", t);
18379 21 : inform (location_of (t), "previous declaration here");
18380 42 : if (TYPE_CLASS_SCOPE_P (t)
18381 24 : && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (t)))
18382 3 : inform (input_location,
18383 : "perhaps you want to explicitly add %<%T::%>",
18384 3 : TYPE_CONTEXT (t));
18385 21 : return error_mark_node;
18386 21 : }
18387 :
18388 : return t;
18389 : }
18390 :
18391 : /* Get the struct, enum or union (TAG_CODE says which) with tag NAME.
18392 : Define the tag as a forward-reference if it is not defined.
18393 :
18394 : If a declaration is given, process it here, and report an error if
18395 : multiple declarations are not identical.
18396 :
18397 : SCOPE is TS_CURRENT when this is also a definition. Only look in
18398 : the current frame for the name (since C++ allows new names in any
18399 : scope.) It is TS_WITHIN_ENCLOSING_NON_CLASS if this is a friend
18400 : declaration. Only look beginning from the current scope outward up
18401 : till the nearest non-class scope. Otherwise it is TS_GLOBAL.
18402 :
18403 : TEMPLATE_HEADER_P is true when this declaration is preceded by
18404 : a set of template parameters. */
18405 :
18406 : tree
18407 25550946 : xref_tag (enum tag_types tag_code, tree name,
18408 : TAG_how how, bool template_header_p)
18409 : {
18410 25550946 : enum tree_code code;
18411 25550946 : tree context = NULL_TREE;
18412 :
18413 25550946 : auto_cond_timevar tv (TV_NAME_LOOKUP);
18414 :
18415 25550946 : gcc_assert (identifier_p (name));
18416 :
18417 25550946 : switch (tag_code)
18418 : {
18419 : case record_type:
18420 : case class_type:
18421 : code = RECORD_TYPE;
18422 : break;
18423 : case union_type:
18424 : code = UNION_TYPE;
18425 : break;
18426 : case enum_type:
18427 : code = ENUMERAL_TYPE;
18428 : break;
18429 0 : default:
18430 0 : gcc_unreachable ();
18431 : }
18432 :
18433 : /* In case of anonymous name, xref_tag is only called to
18434 : make type node and push name. Name lookup is not required. */
18435 25550946 : tree t = NULL_TREE;
18436 25550946 : if (!IDENTIFIER_ANON_P (name))
18437 23381241 : t = lookup_and_check_tag (tag_code, name, how, template_header_p);
18438 :
18439 25550946 : if (t == error_mark_node)
18440 : return error_mark_node;
18441 :
18442 2807846 : if (how != TAG_how::CURRENT_ONLY && t && current_class_type
18443 1337737 : && template_class_depth (current_class_type)
18444 26145826 : && template_header_p)
18445 : {
18446 351245 : if (TREE_CODE (t) == TEMPLATE_TEMPLATE_PARM)
18447 : return t;
18448 :
18449 : /* Since HOW is not TAG_how::CURRENT_ONLY, we are not looking at
18450 : a definition of this tag. Since, in addition, we are
18451 : currently processing a (member) template declaration of a
18452 : template class, we must be very careful; consider:
18453 :
18454 : template <class X> struct S1
18455 :
18456 : template <class U> struct S2
18457 : {
18458 : template <class V> friend struct S1;
18459 : };
18460 :
18461 : Here, the S2::S1 declaration should not be confused with the
18462 : outer declaration. In particular, the inner version should
18463 : have a template parameter of level 2, not level 1.
18464 :
18465 : On the other hand, when presented with:
18466 :
18467 : template <class T> struct S1
18468 : {
18469 : template <class U> struct S2 {};
18470 : template <class U> friend struct S2;
18471 : };
18472 :
18473 : the friend must find S1::S2 eventually. We accomplish this
18474 : by making sure that the new type we create to represent this
18475 : declaration has the right TYPE_CONTEXT. */
18476 351242 : context = TYPE_CONTEXT (t);
18477 351242 : t = NULL_TREE;
18478 : }
18479 :
18480 25550832 : if (! t)
18481 : {
18482 : /* If no such tag is yet defined, create a forward-reference node
18483 : and record it as the "definition".
18484 : When a real declaration of this type is found,
18485 : the forward-reference will be altered into a real type. */
18486 20091153 : if (code == ENUMERAL_TYPE)
18487 : {
18488 13 : error ("use of enum %q#D without previous declaration", name);
18489 13 : return error_mark_node;
18490 : }
18491 :
18492 20091140 : t = make_class_type (code);
18493 20091140 : TYPE_CONTEXT (t) = context;
18494 20091140 : if (IDENTIFIER_LAMBDA_P (name))
18495 : /* Mark it as a lambda type right now. Our caller will
18496 : correct the value. */
18497 1449699 : SET_CLASSTYPE_LAMBDA_EXPR (t, error_mark_node);
18498 20091140 : t = pushtag (name, t, how);
18499 : }
18500 : else
18501 : {
18502 5459679 : if (template_header_p && MAYBE_CLASS_TYPE_P (t))
18503 : {
18504 : /* Check that we aren't trying to overload a class with different
18505 : constraints. */
18506 2183980 : if (!redeclare_class_template (t, current_template_parms,
18507 : current_template_constraints ()))
18508 60 : return error_mark_node;
18509 : }
18510 3275699 : else if (!processing_template_decl
18511 2948537 : && CLASS_TYPE_P (t)
18512 6197932 : && CLASSTYPE_IS_TEMPLATE (t))
18513 : {
18514 0 : auto_diagnostic_group d;
18515 0 : error ("redeclaration of %qT as a non-template", t);
18516 0 : inform (location_of (t), "previous declaration %qD", t);
18517 0 : return error_mark_node;
18518 0 : }
18519 :
18520 5459619 : if (modules_p ()
18521 5459619 : && how == TAG_how::CURRENT_ONLY)
18522 : {
18523 10877 : tree decl = TYPE_NAME (t);
18524 10877 : if (!module_may_redeclare (decl))
18525 15 : return error_mark_node;
18526 :
18527 10862 : tree not_tmpl = STRIP_TEMPLATE (decl);
18528 10862 : if (DECL_LANG_SPECIFIC (not_tmpl)
18529 4441 : && DECL_MODULE_ATTACH_P (not_tmpl)
18530 54 : && !DECL_MODULE_EXPORT_P (not_tmpl)
18531 10904 : && module_exporting_p ())
18532 : {
18533 6 : auto_diagnostic_group d;
18534 6 : error ("conflicting exporting for declaration %qD", decl);
18535 6 : inform (DECL_SOURCE_LOCATION (decl),
18536 : "previously declared here without exporting");
18537 6 : }
18538 :
18539 10862 : tree maybe_tmpl = decl;
18540 10862 : if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t))
18541 8057 : maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t);
18542 :
18543 : /* FIXME: we should do a more precise check for redefinitions
18544 : of a conflicting using-declaration here, as these diagnostics
18545 : are not ideal. */
18546 10862 : if (DECL_LANG_SPECIFIC (decl)
18547 4441 : && DECL_MODULE_IMPORT_P (decl)
18548 10916 : && CP_DECL_CONTEXT (decl) == current_namespace)
18549 : {
18550 : /* Push it into this TU's symbol slot. */
18551 51 : if (maybe_tmpl != decl)
18552 : /* We're in the template parm binding level.
18553 : Pushtag has logic to slide under that, but we're
18554 : not pushing a *new* type. */
18555 20 : push_nested_namespace (CP_DECL_CONTEXT (decl));
18556 :
18557 51 : pushdecl (maybe_tmpl);
18558 51 : if (maybe_tmpl != decl)
18559 20 : pop_nested_namespace (CP_DECL_CONTEXT (decl));
18560 : }
18561 :
18562 10862 : set_instantiating_module (maybe_tmpl);
18563 : }
18564 : }
18565 :
18566 : return t;
18567 25550946 : }
18568 :
18569 : /* Create the binfo hierarchy for REF with (possibly NULL) base list
18570 : BASE_LIST. For each element on BASE_LIST the TREE_PURPOSE is an
18571 : access_* node, and the TREE_VALUE is the type of the base-class.
18572 : Non-NULL TREE_TYPE indicates virtual inheritance. */
18573 :
18574 : void
18575 69272477 : xref_basetypes (tree ref, tree base_list)
18576 : {
18577 69272477 : tree *basep;
18578 69272477 : tree binfo, base_binfo;
18579 69272477 : unsigned max_vbases = 0; /* Maximum direct & indirect virtual bases. */
18580 69272477 : unsigned max_bases = 0; /* Maximum direct bases. */
18581 69272477 : unsigned max_dvbases = 0; /* Maximum direct virtual bases. */
18582 : /* Highest direct base index with annotations. */
18583 69272477 : unsigned max_annotated_base = 0;
18584 69272477 : int i;
18585 69272477 : tree default_access;
18586 69272477 : tree igo_prev; /* Track Inheritance Graph Order. */
18587 :
18588 69272477 : if (ref == error_mark_node)
18589 12 : return;
18590 :
18591 : /* The base of a derived class is private by default, all others are
18592 : public. */
18593 69272477 : default_access = (TREE_CODE (ref) == RECORD_TYPE
18594 68684949 : && CLASSTYPE_DECLARED_CLASS (ref)
18595 69272477 : ? access_private_node : access_public_node);
18596 :
18597 : /* First, make sure that any templates in base-classes are
18598 : instantiated. This ensures that if we call ourselves recursively
18599 : we do not get confused about which classes are marked and which
18600 : are not. */
18601 69272477 : basep = &base_list;
18602 101678727 : while (*basep)
18603 : {
18604 32406250 : tree basetype = TREE_VALUE (*basep);
18605 :
18606 : /* The dependent_type_p call below should really be dependent_scope_p
18607 : so that we give a hard error about using an incomplete type as a
18608 : base, but we allow it with a pedwarn for backward
18609 : compatibility. */
18610 32406250 : if (processing_template_decl
18611 32406250 : && CLASS_TYPE_P (basetype) && TYPE_BEING_DEFINED (basetype))
18612 3 : cxx_incomplete_type_diagnostic (NULL_TREE, basetype,
18613 : diagnostics::kind::pedwarn);
18614 32406250 : if (!dependent_type_p (basetype)
18615 32406250 : && !complete_type_or_else (basetype, NULL))
18616 : /* An incomplete type. Remove it from the list. */
18617 15 : *basep = TREE_CHAIN (*basep);
18618 : else
18619 : {
18620 32406235 : max_bases++;
18621 32406235 : if (TREE_CODE (TREE_PURPOSE (*basep)) == TREE_LIST)
18622 14 : max_annotated_base = max_bases;
18623 32406235 : if (TREE_TYPE (*basep))
18624 67202 : max_dvbases++;
18625 32406235 : if (CLASS_TYPE_P (basetype))
18626 31636916 : max_vbases += vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
18627 32406235 : basep = &TREE_CHAIN (*basep);
18628 : }
18629 : }
18630 69272477 : max_vbases += max_dvbases;
18631 :
18632 69272477 : TYPE_MARKED_P (ref) = 1;
18633 :
18634 : /* The binfo slot should be empty, unless this is an (ill-formed)
18635 : redefinition. */
18636 69272477 : gcc_assert (!TYPE_BINFO (ref) || TYPE_SIZE (ref));
18637 :
18638 69272477 : gcc_assert (TYPE_MAIN_VARIANT (ref) == ref);
18639 :
18640 69272477 : binfo = make_tree_binfo (max_bases);
18641 :
18642 69272477 : TYPE_BINFO (ref) = binfo;
18643 69272477 : BINFO_OFFSET (binfo) = size_zero_node;
18644 69272477 : BINFO_TYPE (binfo) = ref;
18645 :
18646 : /* Apply base-class info set up to the variants of this type. */
18647 69272477 : fixup_type_variants (ref);
18648 :
18649 69272477 : if (max_bases)
18650 : {
18651 31517022 : vec_alloc (BINFO_BASE_ACCESSES (binfo), max_bases + max_annotated_base);
18652 31517022 : BINFO_BASE_ACCESSES (binfo)->quick_grow (max_bases + max_annotated_base);
18653 : /* A C++98 POD cannot have base classes. */
18654 31517022 : CLASSTYPE_NON_LAYOUT_POD_P (ref) = true;
18655 :
18656 31517022 : if (TREE_CODE (ref) == UNION_TYPE)
18657 : {
18658 12 : error ("derived union %qT invalid", ref);
18659 12 : return;
18660 : }
18661 : }
18662 :
18663 31517010 : if (max_bases > 1)
18664 702108 : warning (OPT_Wmultiple_inheritance,
18665 : "%qT defined with multiple direct bases", ref);
18666 :
18667 69272465 : if (max_vbases)
18668 : {
18669 : /* An aggregate can't have virtual base classes. */
18670 200662 : CLASSTYPE_NON_AGGREGATE (ref) = true;
18671 :
18672 200662 : vec_alloc (CLASSTYPE_VBASECLASSES (ref), max_vbases);
18673 :
18674 200662 : if (max_dvbases)
18675 65995 : warning (OPT_Wvirtual_inheritance,
18676 : "%qT defined with direct virtual base", ref);
18677 : }
18678 :
18679 101678688 : for (igo_prev = binfo; base_list; base_list = TREE_CHAIN (base_list))
18680 : {
18681 32406223 : tree access = TREE_PURPOSE (base_list);
18682 32406223 : tree annotations = NULL_TREE;
18683 32406223 : if (TREE_CODE (access) == TREE_LIST)
18684 : {
18685 14 : annotations = TREE_VALUE (access);
18686 14 : access = TREE_PURPOSE (access);
18687 39 : for (tree *d = &annotations; *d; )
18688 : {
18689 25 : if (annotation_p (*d))
18690 : {
18691 25 : tree name = get_attribute_name (*d);
18692 25 : tree args = TREE_VALUE (*d);
18693 25 : const attribute_spec *as
18694 25 : = lookup_attribute_spec (TREE_PURPOSE (*d));
18695 25 : bool no_add_attrs = false;
18696 25 : as->handler (&binfo, name, args, 0, &no_add_attrs);
18697 25 : if (no_add_attrs)
18698 : {
18699 1 : *d = TREE_CHAIN (*d);
18700 1 : continue;
18701 : }
18702 : }
18703 24 : d = &TREE_CHAIN (*d);
18704 : }
18705 : }
18706 32406223 : int via_virtual = TREE_TYPE (base_list) != NULL_TREE;
18707 32406223 : tree basetype = TREE_VALUE (base_list);
18708 :
18709 32406223 : if (access == access_default_node)
18710 4373681 : access = default_access;
18711 :
18712 : /* Before C++17, an aggregate cannot have base classes. In C++17, an
18713 : aggregate can't have virtual, private, or protected base classes. */
18714 32406223 : if (cxx_dialect < cxx17
18715 32187901 : || access != access_public_node
18716 31279103 : || via_virtual)
18717 1191120 : CLASSTYPE_NON_AGGREGATE (ref) = true;
18718 :
18719 32406223 : if (PACK_EXPANSION_P (basetype))
18720 28371 : basetype = PACK_EXPANSION_PATTERN (basetype);
18721 32406223 : if (TREE_CODE (basetype) == TYPE_DECL)
18722 0 : basetype = TREE_TYPE (basetype);
18723 32406223 : if (!MAYBE_CLASS_TYPE_P (basetype) || TREE_CODE (basetype) == UNION_TYPE)
18724 : {
18725 24 : error ("base type %qT fails to be a struct or class type",
18726 : basetype);
18727 24 : goto dropped_base;
18728 : }
18729 :
18730 32406199 : base_binfo = NULL_TREE;
18731 32406199 : if (CLASS_TYPE_P (basetype) && !dependent_scope_p (basetype))
18732 : {
18733 25658534 : base_binfo = TYPE_BINFO (basetype);
18734 : /* The original basetype could have been a typedef'd type. */
18735 25658534 : basetype = BINFO_TYPE (base_binfo);
18736 :
18737 : /* Inherit flags from the base. */
18738 76975602 : TYPE_HAS_NEW_OPERATOR (ref)
18739 25658534 : |= TYPE_HAS_NEW_OPERATOR (basetype);
18740 76975602 : TYPE_HAS_ARRAY_NEW_OPERATOR (ref)
18741 25658534 : |= TYPE_HAS_ARRAY_NEW_OPERATOR (basetype);
18742 25658534 : TYPE_GETS_DELETE (ref) |= TYPE_GETS_DELETE (basetype);
18743 25658534 : TYPE_HAS_CONVERSION (ref) |= TYPE_HAS_CONVERSION (basetype);
18744 76975602 : CLASSTYPE_DIAMOND_SHAPED_P (ref)
18745 25658534 : |= CLASSTYPE_DIAMOND_SHAPED_P (basetype);
18746 76975602 : CLASSTYPE_REPEATED_BASE_P (ref)
18747 25658534 : |= CLASSTYPE_REPEATED_BASE_P (basetype);
18748 : }
18749 :
18750 : /* We must do this test after we've seen through a typedef
18751 : type. */
18752 32406199 : if (TYPE_MARKED_P (basetype))
18753 : {
18754 18 : if (basetype == ref)
18755 0 : error ("recursive type %qT undefined", basetype);
18756 : else
18757 18 : error ("duplicate base type %qT invalid", basetype);
18758 18 : goto dropped_base;
18759 : }
18760 :
18761 32406181 : if (PACK_EXPANSION_P (TREE_VALUE (base_list)))
18762 : /* Regenerate the pack expansion for the bases. */
18763 28371 : basetype = make_pack_expansion (basetype);
18764 :
18765 32406181 : TYPE_MARKED_P (basetype) = 1;
18766 :
18767 32406181 : base_binfo = copy_binfo (base_binfo, basetype, ref,
18768 : &igo_prev, via_virtual);
18769 32406181 : if (!BINFO_INHERITANCE_CHAIN (base_binfo))
18770 32338994 : BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
18771 :
18772 32406181 : unsigned len;
18773 32406181 : len = BINFO_N_BASE_BINFOS (binfo);
18774 32406181 : BINFO_BASE_APPEND (binfo, base_binfo);
18775 32406181 : BINFO_BASE_ACCESS (binfo, len) = access;
18776 32406181 : if (len < max_annotated_base)
18777 17 : BINFO_BASE_ACCESS (binfo, max_bases + len) = annotations;
18778 32406181 : continue;
18779 :
18780 42 : dropped_base:
18781 : /* Update max_vbases to reflect the reality that we are dropping
18782 : this base: if it reaches zero we want to undo the vec_alloc
18783 : above to avoid inconsistencies during error-recovery: eg, in
18784 : build_special_member_call, CLASSTYPE_VBASECLASSES non null
18785 : and vtt null (c++/27952). */
18786 42 : if (via_virtual)
18787 12 : max_vbases--;
18788 42 : if (CLASS_TYPE_P (basetype))
18789 30 : max_vbases
18790 33 : -= vec_safe_length (CLASSTYPE_VBASECLASSES (basetype));
18791 32406181 : }
18792 :
18793 69272465 : unsigned len = BINFO_N_BASE_BINFOS (binfo);
18794 69272465 : if (len < max_bases)
18795 : {
18796 42 : if (len && max_annotated_base)
18797 0 : memmove (&BINFO_BASE_ACCESS (binfo, len),
18798 0 : &BINFO_BASE_ACCESS (binfo, max_bases),
18799 0 : MIN (max_annotated_base, len) * sizeof (tree));
18800 42 : BINFO_BASE_ACCESSES (binfo)->truncate (len + MIN (max_annotated_base,
18801 : len));
18802 : }
18803 :
18804 69272465 : if (CLASSTYPE_VBASECLASSES (ref)
18805 69272465 : && max_vbases == 0)
18806 24 : vec_free (CLASSTYPE_VBASECLASSES (ref));
18807 :
18808 69473115 : if (vec_safe_length (CLASSTYPE_VBASECLASSES (ref)) < max_vbases)
18809 : /* If we didn't get max_vbases vbases, we must have shared at
18810 : least one of them, and are therefore diamond shaped. */
18811 21744 : CLASSTYPE_DIAMOND_SHAPED_P (ref) = 1;
18812 :
18813 : /* Unmark all the types. */
18814 101678646 : for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
18815 32406181 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
18816 69272465 : TYPE_MARKED_P (ref) = 0;
18817 :
18818 : /* Now see if we have a repeated base type. */
18819 69272465 : if (!CLASSTYPE_REPEATED_BASE_P (ref))
18820 : {
18821 175018293 : for (base_binfo = binfo; base_binfo;
18822 105746262 : base_binfo = TREE_CHAIN (base_binfo))
18823 : {
18824 105746978 : if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
18825 : {
18826 716 : CLASSTYPE_REPEATED_BASE_P (ref) = 1;
18827 716 : break;
18828 : }
18829 105746262 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 1;
18830 : }
18831 175018293 : for (base_binfo = binfo; base_binfo;
18832 105746262 : base_binfo = TREE_CHAIN (base_binfo))
18833 105746978 : if (TYPE_MARKED_P (BINFO_TYPE (base_binfo)))
18834 105746262 : TYPE_MARKED_P (BINFO_TYPE (base_binfo)) = 0;
18835 : else
18836 : break;
18837 : }
18838 : }
18839 :
18840 :
18841 : /* Copies the enum-related properties from type SRC to type DST.
18842 : Used with the underlying type of an enum and the enum itself. */
18843 : static void
18844 1936241 : copy_type_enum (tree dst, tree src)
18845 : {
18846 1936241 : tree t;
18847 3872500 : for (t = dst; t; t = TYPE_NEXT_VARIANT (t))
18848 : {
18849 1936259 : TYPE_MIN_VALUE (t) = TYPE_MIN_VALUE (src);
18850 1936259 : TYPE_MAX_VALUE (t) = TYPE_MAX_VALUE (src);
18851 1936259 : TYPE_SIZE (t) = TYPE_SIZE (src);
18852 1936259 : TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (src);
18853 1936259 : SET_TYPE_MODE (dst, TYPE_MODE (src));
18854 1936259 : TYPE_PRECISION (t) = TYPE_PRECISION (src);
18855 1936259 : unsigned valign = TYPE_ALIGN (src);
18856 1936259 : if (TYPE_USER_ALIGN (t))
18857 12 : valign = MAX (valign, TYPE_ALIGN (t));
18858 : else
18859 1936247 : TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (src);
18860 1936259 : SET_TYPE_ALIGN (t, valign);
18861 1936259 : TYPE_UNSIGNED (t) = TYPE_UNSIGNED (src);
18862 : }
18863 1936241 : }
18864 :
18865 : /* Begin compiling the definition of an enumeration type.
18866 : NAME is its name,
18867 :
18868 : if ENUMTYPE is not NULL_TREE then the type has alredy been found.
18869 :
18870 : UNDERLYING_TYPE is the type that will be used as the storage for
18871 : the enumeration type. This should be NULL_TREE if no storage type
18872 : was specified.
18873 :
18874 : ATTRIBUTES are any attributes specified after the enum-key.
18875 :
18876 : SCOPED_ENUM_P is true if this is a scoped enumeration type.
18877 :
18878 : if IS_NEW is not NULL, gets TRUE iff a new type is created.
18879 :
18880 : Returns the type object, as yet incomplete.
18881 : Also records info about it so that build_enumerator
18882 : may be used to declare the individual values as they are read. */
18883 :
18884 : tree
18885 2284041 : start_enum (tree name, tree enumtype, tree underlying_type,
18886 : tree attributes, bool scoped_enum_p, bool *is_new)
18887 : {
18888 2284041 : tree prevtype = NULL_TREE;
18889 2284041 : gcc_assert (identifier_p (name));
18890 :
18891 2284041 : if (is_new)
18892 1844851 : *is_new = false;
18893 : /* [C++0x dcl.enum]p5:
18894 :
18895 : If not explicitly specified, the underlying type of a scoped
18896 : enumeration type is int. */
18897 2284041 : if (!underlying_type && scoped_enum_p)
18898 168616 : underlying_type = integer_type_node;
18899 :
18900 2284041 : if (underlying_type)
18901 579517 : underlying_type = cv_unqualified (underlying_type);
18902 :
18903 : /* If this is the real definition for a previous forward reference,
18904 : fill in the contents in the same object that used to be the
18905 : forward reference. */
18906 2284041 : if (!enumtype)
18907 2283905 : enumtype = lookup_and_check_tag (enum_type, name,
18908 : /*tag_scope=*/TAG_how::CURRENT_ONLY,
18909 : /*template_header_p=*/false);
18910 :
18911 : /* In case of a template_decl, the only check that should be deferred
18912 : to instantiation time is the comparison of underlying types. */
18913 2284041 : if (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE)
18914 : {
18915 : /* Attempt to set the declaring module. */
18916 34381 : if (modules_p ())
18917 : {
18918 187 : tree decl = TYPE_NAME (enumtype);
18919 187 : if (!module_may_redeclare (decl))
18920 3 : enumtype = error_mark_node;
18921 : else
18922 184 : set_instantiating_module (decl);
18923 : }
18924 :
18925 34381 : if (enumtype == error_mark_node)
18926 : ;
18927 34585 : else if (scoped_enum_p != SCOPED_ENUM_P (enumtype))
18928 : {
18929 6 : auto_diagnostic_group d;
18930 6 : error_at (input_location, "scoped/unscoped mismatch "
18931 : "in enum %q#T", enumtype);
18932 6 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18933 : "previous definition here");
18934 6 : enumtype = error_mark_node;
18935 6 : }
18936 34372 : else if (ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) != !! underlying_type)
18937 : {
18938 0 : auto_diagnostic_group d;
18939 0 : error_at (input_location, "underlying type mismatch "
18940 : "in enum %q#T", enumtype);
18941 0 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18942 : "previous definition here");
18943 0 : enumtype = error_mark_node;
18944 0 : }
18945 34357 : else if (underlying_type && ENUM_UNDERLYING_TYPE (enumtype)
18946 68729 : && !same_type_p (underlying_type,
18947 : ENUM_UNDERLYING_TYPE (enumtype)))
18948 : {
18949 29 : auto_diagnostic_group d;
18950 29 : error_at (input_location, "different underlying type "
18951 : "in enum %q#T", enumtype);
18952 29 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
18953 : "previous definition here");
18954 29 : underlying_type = NULL_TREE;
18955 29 : }
18956 : }
18957 :
18958 2284041 : if (!enumtype || TREE_CODE (enumtype) != ENUMERAL_TYPE
18959 34372 : || processing_template_decl)
18960 : {
18961 : /* In case of error, make a dummy enum to allow parsing to
18962 : continue. */
18963 2249768 : if (enumtype == error_mark_node)
18964 : {
18965 9 : name = make_anon_name ();
18966 9 : enumtype = NULL_TREE;
18967 : }
18968 :
18969 : /* enumtype may be an ENUMERAL_TYPE if this is a redefinition
18970 : of an opaque enum, or an opaque enum of an already defined
18971 : enumeration (C++11).
18972 : In any other case, it'll be NULL_TREE. */
18973 2249768 : if (!enumtype)
18974 : {
18975 2249666 : if (is_new)
18976 1810479 : *is_new = true;
18977 : }
18978 2249768 : prevtype = enumtype;
18979 :
18980 : /* Do not push the decl more than once. */
18981 2249768 : if (!enumtype
18982 102 : || TREE_CODE (enumtype) != ENUMERAL_TYPE)
18983 : {
18984 2249669 : enumtype = cxx_make_type (ENUMERAL_TYPE);
18985 2249669 : enumtype = pushtag (name, enumtype);
18986 :
18987 2249669 : if (enumtype != error_mark_node)
18988 : {
18989 : /* The enum is considered opaque until the opening '{' of the
18990 : enumerator list. */
18991 2249651 : SET_OPAQUE_ENUM_P (enumtype, true);
18992 2249651 : ENUM_FIXED_UNDERLYING_TYPE_P (enumtype) = !! underlying_type;
18993 :
18994 : /* std::byte aliases anything. */
18995 2249651 : if (TYPE_CONTEXT (enumtype) == std_node
18996 2598174 : && !strcmp ("byte", TYPE_NAME_STRING (enumtype)))
18997 12803 : TYPE_ALIAS_SET (enumtype) = 0;
18998 : }
18999 : }
19000 : else
19001 99 : enumtype = xref_tag (enum_type, name);
19002 :
19003 2249768 : if (enumtype == error_mark_node)
19004 : return error_mark_node;
19005 : }
19006 :
19007 2284023 : SET_SCOPED_ENUM_P (enumtype, scoped_enum_p);
19008 :
19009 2284023 : cplus_decl_attributes (&enumtype, attributes, (int)ATTR_FLAG_TYPE_IN_PLACE);
19010 :
19011 2284023 : if (underlying_type)
19012 : {
19013 579485 : if (ENUM_UNDERLYING_TYPE (enumtype))
19014 : /* We already checked that it matches, don't change it to a different
19015 : typedef variant. */;
19016 545157 : else if (CP_INTEGRAL_TYPE_P (underlying_type))
19017 : {
19018 545088 : copy_type_enum (enumtype, underlying_type);
19019 545088 : ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
19020 : }
19021 69 : else if (dependent_type_p (underlying_type))
19022 56 : ENUM_UNDERLYING_TYPE (enumtype) = underlying_type;
19023 : else
19024 : {
19025 13 : error ("underlying type %qT of %qT must be an integral type",
19026 : underlying_type, enumtype);
19027 13 : copy_type_enum (enumtype, integer_type_node);
19028 13 : ENUM_UNDERLYING_TYPE (enumtype) = integer_type_node;
19029 : }
19030 : }
19031 :
19032 : /* If into a template class, the returned enum is always the first
19033 : declaration (opaque or not) seen. This way all the references to
19034 : this type will be to the same declaration. The following ones are used
19035 : only to check for definition errors. */
19036 2284023 : if (prevtype && processing_template_decl)
19037 : return prevtype;
19038 : else
19039 2283924 : return enumtype;
19040 : }
19041 :
19042 : /* Returns true if TYPE is an enum that uses an enumerator name for
19043 : linkage purposes at namespace scope. The term is defined in [dcl.enum]/12
19044 : for all enums, not just those at namespace scope, but for backward ABI
19045 : compatibility we want to treat those not at namespace scope the old way
19046 : and e.g. mangle the class scope ones based on their position within the
19047 : class rather than the first enumerator. */
19048 :
19049 : bool
19050 396160487 : enum_with_enumerator_for_linkage_p (tree type)
19051 : {
19052 396160487 : return (cxx_dialect >= cxx20
19053 391605335 : && UNSCOPED_ENUM_P (type)
19054 19280800 : && TYPE_ANON_P (type)
19055 2900237 : && TYPE_VALUES (type)
19056 397942853 : && TYPE_NAMESPACE_SCOPE_P (type));
19057 : }
19058 :
19059 : /* After processing and defining all the values of an enumeration type,
19060 : install their decls in the enumeration type.
19061 : ENUMTYPE is the type object. */
19062 :
19063 : void
19064 2183008 : finish_enum_value_list (tree enumtype)
19065 : {
19066 2183008 : tree values;
19067 2183008 : tree underlying_type;
19068 2183008 : tree decl;
19069 2183008 : tree value;
19070 2183008 : tree minnode, maxnode;
19071 2183008 : tree t;
19072 :
19073 2183008 : ENUM_BEING_DEFINED_P (enumtype) = 0;
19074 :
19075 2183008 : bool fixed_underlying_type_p
19076 2183008 : = ENUM_UNDERLYING_TYPE (enumtype) != NULL_TREE;
19077 :
19078 : /* We built up the VALUES in reverse order. */
19079 2183008 : TYPE_VALUES (enumtype) = nreverse (TYPE_VALUES (enumtype));
19080 :
19081 : /* For an enum defined in a template, just set the type of the values;
19082 : all further processing is postponed until the template is
19083 : instantiated. We need to set the type so that tsubst of a CONST_DECL
19084 : works. */
19085 2183008 : if (processing_template_decl)
19086 : {
19087 433574 : for (values = TYPE_VALUES (enumtype);
19088 774450 : values;
19089 433574 : values = TREE_CHAIN (values))
19090 433574 : TREE_TYPE (TREE_VALUE (values)) = enumtype;
19091 : return;
19092 : }
19093 :
19094 : /* Determine the minimum and maximum values of the enumerators. */
19095 1842132 : if (TYPE_VALUES (enumtype))
19096 : {
19097 : minnode = maxnode = NULL_TREE;
19098 :
19099 11137743 : for (values = TYPE_VALUES (enumtype);
19100 12944845 : values;
19101 11137743 : values = TREE_CHAIN (values))
19102 : {
19103 11137743 : decl = TREE_VALUE (values);
19104 :
19105 : /* [dcl.enum]: Following the closing brace of an enum-specifier,
19106 : each enumerator has the type of its enumeration. Prior to the
19107 : closing brace, the type of each enumerator is the type of its
19108 : initializing value. */
19109 11137743 : TREE_TYPE (decl) = enumtype;
19110 :
19111 : /* Update the minimum and maximum values, if appropriate. */
19112 11137743 : value = DECL_INITIAL (decl);
19113 11137743 : if (!value || TREE_CODE (value) != INTEGER_CST)
19114 7 : value = integer_zero_node;
19115 : /* Figure out what the minimum and maximum values of the
19116 : enumerators are. */
19117 11137743 : if (!minnode)
19118 : minnode = maxnode = value;
19119 9330641 : else if (tree_int_cst_lt (maxnode, value))
19120 : maxnode = value;
19121 1456135 : else if (tree_int_cst_lt (value, minnode))
19122 163918 : minnode = value;
19123 : }
19124 : }
19125 : else
19126 : /* [dcl.enum]
19127 :
19128 : If the enumerator-list is empty, the underlying type is as if
19129 : the enumeration had a single enumerator with value 0. */
19130 35030 : minnode = maxnode = integer_zero_node;
19131 :
19132 1842132 : if (!fixed_underlying_type_p)
19133 : {
19134 : /* Compute the number of bits require to represent all values of the
19135 : enumeration. We must do this before the type of MINNODE and
19136 : MAXNODE are transformed, since tree_int_cst_min_precision relies
19137 : on the TREE_TYPE of the value it is passed. */
19138 1391140 : signop sgn = tree_int_cst_sgn (minnode) >= 0 ? UNSIGNED : SIGNED;
19139 1391140 : int lowprec = tree_int_cst_min_precision (minnode, sgn);
19140 1391140 : int highprec = tree_int_cst_min_precision (maxnode, sgn);
19141 1391140 : int precision = MAX (lowprec, highprec);
19142 1391140 : unsigned int itk;
19143 1391140 : bool use_short_enum;
19144 :
19145 : /* Determine the underlying type of the enumeration.
19146 :
19147 : [dcl.enum]
19148 :
19149 : The underlying type of an enumeration is an integral type that
19150 : can represent all the enumerator values defined in the
19151 : enumeration. It is implementation-defined which integral type is
19152 : used as the underlying type for an enumeration except that the
19153 : underlying type shall not be larger than int unless the value of
19154 : an enumerator cannot fit in an int or unsigned int.
19155 :
19156 : We use "int" or an "unsigned int" as the underlying type, even if
19157 : a smaller integral type would work, unless the user has
19158 : explicitly requested that we use the smallest possible type. The
19159 : user can request that for all enumerations with a command line
19160 : flag, or for just one enumeration with an attribute. */
19161 :
19162 2782280 : use_short_enum = flag_short_enums
19163 1391140 : || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype));
19164 :
19165 : /* If the precision of the type was specified with an attribute and it
19166 : was too small, give an error. Otherwise, use it. */
19167 1391140 : if (TYPE_PRECISION (enumtype))
19168 : {
19169 11 : if (precision > TYPE_PRECISION (enumtype))
19170 0 : error ("specified mode too small for enumerated values");
19171 : else
19172 : {
19173 11 : use_short_enum = true;
19174 11 : precision = TYPE_PRECISION (enumtype);
19175 : }
19176 : }
19177 :
19178 2704013 : for (itk = (use_short_enum ? itk_char : itk_int);
19179 2704013 : itk != itk_none;
19180 : itk++)
19181 : {
19182 2704010 : underlying_type = integer_types[itk];
19183 2704010 : if (underlying_type != NULL_TREE
19184 2703992 : && TYPE_PRECISION (underlying_type) >= precision
19185 5405941 : && TYPE_SIGN (underlying_type) == sgn)
19186 : break;
19187 : }
19188 1391140 : if (itk == itk_none)
19189 : {
19190 : /* DR 377
19191 :
19192 : IF no integral type can represent all the enumerator values, the
19193 : enumeration is ill-formed. */
19194 3 : error ("no integral type can represent all of the enumerator values "
19195 : "for %qT", enumtype);
19196 3 : precision = TYPE_PRECISION (long_long_integer_type_node);
19197 3 : underlying_type = integer_types[itk_unsigned_long_long];
19198 : }
19199 :
19200 : /* [dcl.enum]
19201 :
19202 : The value of sizeof() applied to an enumeration type, an object
19203 : of an enumeration type, or an enumerator, is the value of sizeof()
19204 : applied to the underlying type. */
19205 1391140 : copy_type_enum (enumtype, underlying_type);
19206 :
19207 : /* Compute the minimum and maximum values for the type.
19208 :
19209 : [dcl.enum]
19210 :
19211 : For an enumeration where emin is the smallest enumerator and emax
19212 : is the largest, the values of the enumeration are the values of the
19213 : underlying type in the range bmin to bmax, where bmin and bmax are,
19214 : respectively, the smallest and largest values of the smallest bit-
19215 : field that can store emin and emax. */
19216 :
19217 : /* The middle-end currently assumes that types with TYPE_PRECISION
19218 : narrower than their underlying type are suitably zero or sign
19219 : extended to fill their mode. Similarly, it assumes that the front
19220 : end assures that a value of a particular type must be within
19221 : TYPE_MIN_VALUE and TYPE_MAX_VALUE.
19222 :
19223 : We used to set these fields based on bmin and bmax, but that led
19224 : to invalid assumptions like optimizing away bounds checking. So
19225 : now we just set the TYPE_PRECISION, TYPE_MIN_VALUE, and
19226 : TYPE_MAX_VALUE to the values for the mode above and only restrict
19227 : the ENUM_UNDERLYING_TYPE for the benefit of diagnostics. */
19228 1391140 : ENUM_UNDERLYING_TYPE (enumtype)
19229 1391140 : = build_distinct_type_copy (underlying_type);
19230 1391140 : TYPE_PRECISION (ENUM_UNDERLYING_TYPE (enumtype)) = precision;
19231 1391140 : set_min_and_max_values_for_integral_type
19232 1391140 : (ENUM_UNDERLYING_TYPE (enumtype), precision, sgn);
19233 :
19234 : /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE. */
19235 1391140 : if (flag_strict_enums)
19236 38 : set_min_and_max_values_for_integral_type (enumtype, precision, sgn);
19237 :
19238 1391140 : if (use_short_enum)
19239 : {
19240 122 : TYPE_PACKED (enumtype) = use_short_enum;
19241 122 : fixup_attribute_variants (enumtype);
19242 : }
19243 : }
19244 : else
19245 450992 : underlying_type = ENUM_UNDERLYING_TYPE (enumtype);
19246 :
19247 : /* If the enum is exported, mark the consts too. */
19248 1842132 : bool export_p = (UNSCOPED_ENUM_P (enumtype)
19249 1465396 : && DECL_MODULE_EXPORT_P (TYPE_STUB_DECL (enumtype))
19250 1842715 : && at_namespace_scope_p ());
19251 :
19252 : /* Convert each of the enumerators to the type of the underlying
19253 : type of the enumeration. */
19254 12979875 : for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
19255 : {
19256 11137743 : decl = TREE_VALUE (values);
19257 11137743 : iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
19258 11137743 : if (fixed_underlying_type_p)
19259 : /* If the enumeration type has a fixed underlying type, we
19260 : already checked all of the enumerator values. */
19261 3836977 : value = DECL_INITIAL (decl);
19262 : else
19263 7300766 : value = perform_implicit_conversion (underlying_type,
19264 7300766 : DECL_INITIAL (decl),
19265 : tf_warning_or_error);
19266 11137743 : if (!value)
19267 3 : value = integer_zero_node;
19268 : /* Do not clobber shared ints. But do share identical enumerators. */
19269 11137743 : value = fold_convert (enumtype, value);
19270 :
19271 11137743 : DECL_INITIAL (decl) = value;
19272 11137743 : if (export_p)
19273 3570 : DECL_MODULE_EXPORT_P (decl) = true;
19274 11137743 : }
19275 :
19276 : /* Fix up all variant types of this enum type. */
19277 3684293 : for (t = TYPE_MAIN_VARIANT (enumtype); t; t = TYPE_NEXT_VARIANT (t))
19278 1842161 : TYPE_VALUES (t) = TYPE_VALUES (enumtype);
19279 :
19280 1842132 : if (at_class_scope_p ()
19281 982360 : && COMPLETE_TYPE_P (current_class_type)
19282 1842196 : && UNSCOPED_ENUM_P (enumtype))
19283 : {
19284 45 : insert_late_enum_def_bindings (current_class_type, enumtype);
19285 : /* TYPE_FIELDS needs fixup. */
19286 45 : fixup_type_variants (current_class_type);
19287 : }
19288 :
19289 : /* P2115: An unnamed enum uses the name of its first enumerator for
19290 : linkage purposes; reset the type linkage if that is the case. */
19291 1842132 : if (enum_with_enumerator_for_linkage_p (enumtype))
19292 328962 : reset_type_linkage (enumtype);
19293 :
19294 : /* Finish debugging output for this type. */
19295 1842132 : rest_of_type_compilation (enumtype, namespace_bindings_p ());
19296 :
19297 : /* Each enumerator now has the type of its enumeration. Clear the cache
19298 : so that this change in types doesn't confuse us later on. */
19299 1842132 : clear_cv_and_fold_caches ();
19300 : }
19301 :
19302 : /* Finishes the enum type. This is called only the first time an
19303 : enumeration is seen, be it opaque or odinary.
19304 : ENUMTYPE is the type object. */
19305 :
19306 : void
19307 2172365 : finish_enum (tree enumtype)
19308 : {
19309 2172365 : if (processing_template_decl)
19310 : {
19311 340904 : if (at_function_scope_p ())
19312 9180 : add_stmt (build_min (TAG_DEFN, enumtype));
19313 340904 : return;
19314 : }
19315 :
19316 : /* If this is a forward declaration, there should not be any variants,
19317 : though we can get a variant in the middle of an enum-specifier with
19318 : wacky code like 'enum E { e = sizeof(const E*) };' */
19319 3662922 : gcc_assert (enumtype == TYPE_MAIN_VARIANT (enumtype)
19320 : && (TYPE_VALUES (enumtype)
19321 : || !TYPE_NEXT_VARIANT (enumtype)));
19322 : }
19323 :
19324 : /* Build and install a CONST_DECL for an enumeration constant of the
19325 : enumeration type ENUMTYPE whose NAME and VALUE (if any) are provided.
19326 : Apply ATTRIBUTES if available. LOC is the location of NAME.
19327 : Assignment of sequential values by default is handled here. */
19328 :
19329 : tree
19330 11571291 : build_enumerator (tree name, tree value, tree enumtype, tree attributes,
19331 : location_t loc)
19332 : {
19333 11571291 : tree decl;
19334 11571291 : tree context;
19335 11571291 : tree type;
19336 :
19337 : /* scalar_constant_value will pull out this expression, so make sure
19338 : it's folded as appropriate.
19339 :
19340 : Creating a TARGET_EXPR in a template breaks when substituting, and
19341 : here we would create it for instance when using a class prvalue with
19342 : a user-defined conversion function. So don't use such a tree. We
19343 : instantiate VALUE here to get errors about bad enumerators even in
19344 : a template that does not get instantiated. */
19345 11571291 : if (processing_template_decl)
19346 433574 : value = maybe_fold_non_dependent_expr (value);
19347 :
19348 : /* If the VALUE was erroneous, pretend it wasn't there; that will
19349 : result in the enum being assigned the next value in sequence. */
19350 11571291 : if (value == error_mark_node)
19351 : value = NULL_TREE;
19352 :
19353 : /* Remove no-op casts from the value. */
19354 11571253 : if (value)
19355 8640818 : STRIP_TYPE_NOPS (value);
19356 :
19357 11571291 : if (! processing_template_decl)
19358 : {
19359 : /* Validate and default VALUE. */
19360 11137717 : if (value != NULL_TREE)
19361 : {
19362 4956229 : if (!ENUM_UNDERLYING_TYPE (enumtype))
19363 : {
19364 2575540 : tree tmp_value = build_expr_type_conversion (WANT_INT | WANT_ENUM,
19365 : value, true);
19366 2575540 : if (tmp_value)
19367 4956229 : value = tmp_value;
19368 : }
19369 2380689 : else if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
19370 : (TREE_TYPE (value)))
19371 39 : value = perform_implicit_conversion_flags
19372 39 : (ENUM_UNDERLYING_TYPE (enumtype), value, tf_warning_or_error,
19373 : LOOKUP_IMPLICIT | LOOKUP_NO_NARROWING);
19374 :
19375 4956229 : if (value == error_mark_node)
19376 : value = NULL_TREE;
19377 :
19378 4956208 : if (value != NULL_TREE)
19379 : {
19380 4956208 : if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
19381 : (TREE_TYPE (value)))
19382 : {
19383 17 : error_at (cp_expr_loc_or_input_loc (value),
19384 : "enumerator value for %qD must have integral or "
19385 : "unscoped enumeration type", name);
19386 17 : value = NULL_TREE;
19387 : }
19388 : else
19389 : {
19390 4956191 : value = cxx_constant_value (value);
19391 :
19392 4956191 : if (TREE_CODE (value) != INTEGER_CST)
19393 : {
19394 47 : error ("enumerator value for %qD is not an integer "
19395 : "constant", name);
19396 47 : value = NULL_TREE;
19397 : }
19398 : }
19399 : }
19400 : }
19401 :
19402 : /* Default based on previous value. */
19403 64 : if (value == NULL_TREE)
19404 : {
19405 6181573 : if (TYPE_VALUES (enumtype))
19406 : {
19407 5651255 : tree prev_value;
19408 :
19409 : /* C++03 7.2/4: If no initializer is specified for the first
19410 : enumerator, the type is an unspecified integral
19411 : type. Otherwise the type is the same as the type of the
19412 : initializing value of the preceding enumerator unless the
19413 : incremented value is not representable in that type, in
19414 : which case the type is an unspecified integral type
19415 : sufficient to contain the incremented value. */
19416 5651255 : prev_value = DECL_INITIAL (TREE_VALUE (TYPE_VALUES (enumtype)));
19417 5651255 : if (TREE_CODE (prev_value) != INTEGER_CST)
19418 2 : value = error_mark_node;
19419 : else
19420 : {
19421 5651253 : wi::overflow_type overflowed;
19422 5651253 : tree type = TREE_TYPE (prev_value);
19423 5651253 : signop sgn = TYPE_SIGN (type);
19424 5651253 : widest_int wi = wi::add (wi::to_widest (prev_value), 1, sgn,
19425 5651253 : &overflowed);
19426 5651253 : if (!overflowed)
19427 : {
19428 5651253 : bool pos = !wi::neg_p (wi, sgn);
19429 5651253 : if (!wi::fits_to_tree_p (wi, type))
19430 : {
19431 : unsigned int itk;
19432 53 : for (itk = itk_int; itk != itk_none; itk++)
19433 : {
19434 53 : type = integer_types[itk];
19435 53 : if (type != NULL_TREE
19436 53 : && (pos || !TYPE_UNSIGNED (type))
19437 106 : && wi::fits_to_tree_p (wi, type))
19438 : break;
19439 : }
19440 17 : if (type && cxx_dialect < cxx11
19441 6 : && itk > itk_unsigned_long)
19442 3 : pedwarn (input_location, OPT_Wlong_long,
19443 : pos ? G_("\
19444 : incremented enumerator value is too large for %<unsigned long%>") : G_("\
19445 : incremented enumerator value is too large for %<long%>"));
19446 : }
19447 5651253 : if (type == NULL_TREE)
19448 0 : overflowed = wi::OVF_UNKNOWN;
19449 : else
19450 5651253 : value = wide_int_to_tree (type, wi);
19451 : }
19452 :
19453 5651253 : if (overflowed)
19454 : {
19455 0 : error ("overflow in enumeration values at %qD", name);
19456 0 : value = error_mark_node;
19457 : }
19458 5651253 : }
19459 : }
19460 : else
19461 530318 : value = integer_zero_node;
19462 : }
19463 :
19464 : /* Remove no-op casts from the value. */
19465 11137717 : STRIP_TYPE_NOPS (value);
19466 :
19467 : /* If the underlying type of the enum is fixed, check whether
19468 : the enumerator values fits in the underlying type. If it
19469 : does not fit, the program is ill-formed [C++0x dcl.enum]. */
19470 11137717 : if (ENUM_UNDERLYING_TYPE (enumtype)
19471 : && value
19472 11137717 : && TREE_CODE (value) == INTEGER_CST)
19473 : {
19474 3836949 : if (!int_fits_type_p (value, ENUM_UNDERLYING_TYPE (enumtype)))
19475 9 : error ("enumerator value %qE is outside the range of underlying "
19476 9 : "type %qT", value, ENUM_UNDERLYING_TYPE (enumtype));
19477 :
19478 : /* Convert the value to the appropriate type. */
19479 3836949 : value = fold_convert (ENUM_UNDERLYING_TYPE (enumtype), value);
19480 : }
19481 : }
19482 :
19483 : /* C++ associates enums with global, function, or class declarations. */
19484 11571291 : context = current_scope ();
19485 :
19486 : /* Build the actual enumeration constant. Note that the enumeration
19487 : constants have the underlying type of the enum (if it is fixed)
19488 : or the type of their initializer (if the underlying type of the
19489 : enum is not fixed):
19490 :
19491 : [ C++0x dcl.enum ]
19492 :
19493 : If the underlying type is fixed, the type of each enumerator
19494 : prior to the closing brace is the underlying type; if the
19495 : initializing value of an enumerator cannot be represented by
19496 : the underlying type, the program is ill-formed. If the
19497 : underlying type is not fixed, the type of each enumerator is
19498 : the type of its initializing value.
19499 :
19500 : If the underlying type is not fixed, it will be computed by
19501 : finish_enum and we will reset the type of this enumerator. Of
19502 : course, if we're processing a template, there may be no value. */
19503 11571291 : type = value ? TREE_TYPE (value) : NULL_TREE;
19504 :
19505 11571291 : decl = build_decl (loc, CONST_DECL, name, type);
19506 :
19507 11571291 : DECL_CONTEXT (decl) = enumtype;
19508 11571291 : TREE_CONSTANT (decl) = 1;
19509 11571291 : TREE_READONLY (decl) = 1;
19510 11571291 : DECL_INITIAL (decl) = value;
19511 :
19512 11571291 : if (attributes)
19513 122428 : cplus_decl_attributes (&decl, attributes, 0);
19514 :
19515 11571291 : if (context && context == current_class_type && !SCOPED_ENUM_P (enumtype))
19516 : {
19517 : /* In something like `struct S { enum E { i = 7 }; };' we put `i'
19518 : on the TYPE_FIELDS list for `S'. (That's so that you can say
19519 : things like `S::i' later.) */
19520 :
19521 : /* The enumerator may be getting declared outside of its enclosing
19522 : class, like so:
19523 :
19524 : class S { public: enum E : int; }; enum S::E : int { i = 7; };
19525 :
19526 : For which case we need to make sure that the access of `S::i'
19527 : matches the access of `S::E'. */
19528 2010124 : auto cas = make_temp_override (current_access_specifier);
19529 2010124 : set_current_access_from_decl (TYPE_NAME (enumtype));
19530 2010124 : finish_member_declaration (decl);
19531 2010124 : }
19532 : else
19533 9561167 : pushdecl (decl);
19534 :
19535 : /* Add this enumeration constant to the list for this type. */
19536 11571291 : TYPE_VALUES (enumtype) = tree_cons (name, decl, TYPE_VALUES (enumtype));
19537 :
19538 11571291 : return decl;
19539 : }
19540 :
19541 : /* Look for an enumerator with the given NAME within the enumeration
19542 : type ENUMTYPE. This routine is used primarily for qualified name
19543 : lookup into an enumerator in C++0x, e.g.,
19544 :
19545 : enum class Color { Red, Green, Blue };
19546 :
19547 : Color color = Color::Red;
19548 :
19549 : Returns the value corresponding to the enumerator, or
19550 : NULL_TREE if no such enumerator was found. */
19551 : tree
19552 27071566 : lookup_enumerator (tree enumtype, tree name)
19553 : {
19554 27071566 : tree e;
19555 27071566 : gcc_assert (enumtype && TREE_CODE (enumtype) == ENUMERAL_TYPE);
19556 :
19557 27071566 : e = purpose_member (name, TYPE_VALUES (enumtype));
19558 54143035 : return e? TREE_VALUE (e) : NULL_TREE;
19559 : }
19560 :
19561 : /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL. */
19562 :
19563 : tree
19564 0 : cxx_simulate_enum_decl (location_t loc, const char *name,
19565 : vec<string_int_pair> *values)
19566 : {
19567 0 : location_t saved_loc = input_location;
19568 0 : input_location = loc;
19569 :
19570 0 : tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
19571 : NULL_TREE, false, NULL);
19572 0 : if (!OPAQUE_ENUM_P (enumtype))
19573 : {
19574 0 : auto_diagnostic_group d;
19575 0 : error_at (loc, "multiple definition of %q#T", enumtype);
19576 0 : inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
19577 : "previous definition here");
19578 0 : return enumtype;
19579 0 : }
19580 0 : SET_OPAQUE_ENUM_P (enumtype, false);
19581 0 : DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
19582 :
19583 0 : for (const string_int_pair &value : values)
19584 0 : build_enumerator (get_identifier (value.first),
19585 0 : build_int_cst (integer_type_node, value.second),
19586 : enumtype, NULL_TREE, loc);
19587 :
19588 0 : finish_enum_value_list (enumtype);
19589 0 : finish_enum (enumtype);
19590 :
19591 0 : input_location = saved_loc;
19592 0 : return enumtype;
19593 : }
19594 :
19595 : /* Implement LANG_HOOKS_SIMULATE_RECORD_DECL. */
19596 :
19597 : tree
19598 0 : cxx_simulate_record_decl (location_t loc, const char *name,
19599 : array_slice<const tree> fields)
19600 : {
19601 0 : iloc_sentinel ils (loc);
19602 :
19603 0 : tree ident = get_identifier (name);
19604 0 : tree type = xref_tag (/*tag_code=*/record_type, ident);
19605 0 : if (type != error_mark_node
19606 0 : && (TREE_CODE (type) != RECORD_TYPE || COMPLETE_TYPE_P (type)))
19607 : {
19608 0 : error ("redefinition of %q#T", type);
19609 0 : type = error_mark_node;
19610 : }
19611 0 : if (type == error_mark_node)
19612 0 : return lhd_simulate_record_decl (loc, name, fields);
19613 :
19614 0 : xref_basetypes (type, NULL_TREE);
19615 0 : type = begin_class_definition (type);
19616 0 : if (type == error_mark_node)
19617 0 : return lhd_simulate_record_decl (loc, name, fields);
19618 :
19619 0 : for (tree field : fields)
19620 0 : finish_member_declaration (field);
19621 :
19622 0 : type = finish_struct (type, NULL_TREE);
19623 :
19624 0 : tree decl = build_decl (loc, TYPE_DECL, ident, type);
19625 0 : set_underlying_type (decl);
19626 0 : lang_hooks.decls.pushdecl (decl);
19627 :
19628 0 : return type;
19629 0 : }
19630 :
19631 : /* We're defining DECL. Make sure that its type is OK. */
19632 :
19633 : static void
19634 157955161 : check_function_type (tree decl, tree current_function_parms)
19635 : {
19636 157955161 : tree fntype = TREE_TYPE (decl);
19637 157955161 : tree return_type = complete_type (TREE_TYPE (fntype));
19638 :
19639 : /* In a function definition, arg types must be complete. */
19640 157955161 : require_complete_types_for_parms (current_function_parms);
19641 :
19642 157955161 : if (dependent_type_p (return_type)
19643 157955161 : || type_uses_auto (return_type))
19644 49831364 : return;
19645 108123797 : if (!COMPLETE_OR_VOID_TYPE_P (return_type))
19646 : {
19647 12 : tree args = TYPE_ARG_TYPES (fntype);
19648 :
19649 12 : error ("return type %q#T is incomplete", return_type);
19650 :
19651 : /* Make it return void instead. */
19652 12 : if (TREE_CODE (fntype) == METHOD_TYPE)
19653 3 : fntype = build_method_type_directly (TREE_TYPE (TREE_VALUE (args)),
19654 : void_type_node,
19655 3 : TREE_CHAIN (args));
19656 : else
19657 18 : fntype = build_function_type (void_type_node, args,
19658 9 : TYPE_NO_NAMED_ARGS_STDARG_P (fntype));
19659 12 : fntype = (cp_build_type_attribute_variant
19660 12 : (fntype, TYPE_ATTRIBUTES (TREE_TYPE (decl))));
19661 12 : fntype = cxx_copy_lang_qualifiers (fntype, TREE_TYPE (decl));
19662 12 : TREE_TYPE (decl) = fntype;
19663 : }
19664 : else
19665 : {
19666 108123785 : abstract_virtuals_error (decl, TREE_TYPE (fntype));
19667 108123785 : maybe_warn_parm_abi (TREE_TYPE (fntype),
19668 108123785 : DECL_SOURCE_LOCATION (decl));
19669 : }
19670 : }
19671 :
19672 : /* True iff FN is an implicitly-defined default constructor. */
19673 :
19674 : static bool
19675 16554457 : implicit_default_ctor_p (tree fn)
19676 : {
19677 16554457 : return (DECL_CONSTRUCTOR_P (fn)
19678 16554457 : && !user_provided_p (fn)
19679 18407118 : && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
19680 : }
19681 :
19682 : /* Clobber the contents of *this to let the back end know that the object
19683 : storage is dead when we enter the constructor or leave the destructor. */
19684 :
19685 : static tree
19686 1427237 : build_clobber_this (clobber_kind kind)
19687 : {
19688 : /* Clobbering an empty base is pointless, and harmful if its one byte
19689 : TYPE_SIZE overlays real data. */
19690 1427237 : if (is_empty_class (current_class_type))
19691 0 : return void_node;
19692 :
19693 : /* If we have virtual bases, clobber the whole object, but only if we're in
19694 : charge. If we don't have virtual bases, clobber the as-base type so we
19695 : don't mess with tail padding. */
19696 1427237 : bool vbases = CLASSTYPE_VBASECLASSES (current_class_type);
19697 :
19698 1427237 : tree ctype = current_class_type;
19699 1427237 : if (!vbases)
19700 1420235 : ctype = CLASSTYPE_AS_BASE (ctype);
19701 :
19702 1427237 : tree clobber = build_clobber (ctype, kind);
19703 :
19704 1427237 : tree thisref = current_class_ref;
19705 1427237 : if (ctype != current_class_type)
19706 : {
19707 167435 : thisref = build_nop (build_reference_type (ctype), current_class_ptr);
19708 167435 : thisref = convert_from_reference (thisref);
19709 : }
19710 :
19711 1427237 : tree exprstmt = build2 (MODIFY_EXPR, void_type_node, thisref, clobber);
19712 1427237 : if (kind == CLOBBER_OBJECT_BEGIN)
19713 0 : TREE_SET_CODE (exprstmt, INIT_EXPR);
19714 1427237 : if (vbases)
19715 7002 : exprstmt = build_if_in_charge (exprstmt);
19716 :
19717 : return exprstmt;
19718 : }
19719 :
19720 : /* Create the FUNCTION_DECL for a function definition.
19721 : DECLSPECS and DECLARATOR are the parts of the declaration;
19722 : they describe the function's name and the type it returns,
19723 : but twisted together in a fashion that parallels the syntax of C.
19724 :
19725 : FLAGS is a bitwise or of SF_PRE_PARSED (indicating that the
19726 : DECLARATOR is really the DECL for the function we are about to
19727 : process and that DECLSPECS should be ignored), SF_INCLASS_INLINE
19728 : indicating that the function is an inline defined in-class.
19729 :
19730 : This function creates a binding context for the function body
19731 : as well as setting up the FUNCTION_DECL in current_function_decl.
19732 :
19733 : For C++, we must first check whether that datum makes any sense.
19734 : For example, "class A local_a(1,2);" means that variable local_a
19735 : is an aggregate of type A, which should have a constructor
19736 : applied to it with the argument list [1, 2].
19737 :
19738 : On entry, DECL_INITIAL (decl1) should be NULL_TREE or error_mark_node,
19739 : or may be a BLOCK if the function has been defined previously
19740 : in this translation unit. On exit, DECL_INITIAL (decl1) will be
19741 : error_mark_node if the function has never been defined, or
19742 : a BLOCK if the function has been defined somewhere. */
19743 :
19744 : bool
19745 157955197 : start_preparsed_function (tree decl1, tree attrs, int flags)
19746 : {
19747 157955197 : tree ctype = NULL_TREE;
19748 157955197 : bool doing_friend = false;
19749 :
19750 : /* Sanity check. */
19751 157955197 : gcc_assert (VOID_TYPE_P (TREE_VALUE (void_list_node)));
19752 157955197 : gcc_assert (TREE_CHAIN (void_list_node) == NULL_TREE);
19753 :
19754 157955197 : tree fntype = TREE_TYPE (decl1);
19755 157955197 : if (DECL_CLASS_SCOPE_P (decl1))
19756 116361030 : ctype = DECL_CONTEXT (decl1);
19757 : else
19758 : {
19759 83188334 : ctype = DECL_FRIEND_CONTEXT (decl1);
19760 :
19761 41594166 : if (ctype)
19762 157955197 : doing_friend = true;
19763 : }
19764 :
19765 : /* Adjust for #pragma target/optimize if this is an artificial function that
19766 : (probably) didn't go through grokfndecl. We particularly don't want this
19767 : for deferred instantiations, which should match their template. */
19768 157955197 : if (DECL_ARTIFICIAL (decl1))
19769 3574457 : decl_attributes (&decl1, NULL_TREE, 0);
19770 :
19771 157955197 : if (DECL_DECLARED_INLINE_P (decl1)
19772 157955197 : && lookup_attribute ("noinline", attrs))
19773 : {
19774 0 : auto_urlify_attributes sentinel;
19775 0 : warning_at (DECL_SOURCE_LOCATION (decl1), 0,
19776 : "inline function %qD given attribute %qs", decl1, "noinline");
19777 0 : }
19778 :
19779 : /* Handle gnu_inline attribute. */
19780 157955197 : if (GNU_INLINE_P (decl1))
19781 : {
19782 1882847 : DECL_EXTERNAL (decl1) = 1;
19783 1882847 : DECL_NOT_REALLY_EXTERN (decl1) = 0;
19784 1882847 : DECL_INTERFACE_KNOWN (decl1) = 1;
19785 1882847 : DECL_DISREGARD_INLINE_LIMITS (decl1) = 1;
19786 : }
19787 :
19788 157955197 : if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (decl1))
19789 : /* This is a constructor, we must ensure that any default args
19790 : introduced by this definition are propagated to the clones
19791 : now. The clones are used directly in overload resolution. */
19792 19759602 : adjust_clone_args (decl1);
19793 :
19794 : /* Sometimes we don't notice that a function is a static member, and
19795 : build a METHOD_TYPE for it. Fix that up now. */
19796 157955197 : gcc_assert (!(DECL_STATIC_FUNCTION_P (decl1)
19797 : && TREE_CODE (TREE_TYPE (decl1)) == METHOD_TYPE));
19798 :
19799 : /* Set up current_class_type, and enter the scope of the class, if
19800 : appropriate. */
19801 157955197 : if (ctype)
19802 120758078 : push_nested_class (ctype);
19803 :
19804 : /* Now that we have entered the scope of the class, we must restore
19805 : the bindings for any template parameters surrounding DECL1, if it
19806 : is an inline member template. (Order is important; consider the
19807 : case where a template parameter has the same name as a field of
19808 : the class.) It is not until after this point that
19809 : PROCESSING_TEMPLATE_DECL is guaranteed to be set up correctly. */
19810 157955197 : if (flags & SF_INCLASS_INLINE)
19811 80999025 : maybe_begin_member_template_processing (decl1);
19812 :
19813 : /* Effective C++ rule 15. */
19814 157955197 : if (warn_ecpp
19815 123 : && DECL_ASSIGNMENT_OPERATOR_P (decl1)
19816 30 : && DECL_OVERLOADED_OPERATOR_IS (decl1, NOP_EXPR)
19817 157955227 : && VOID_TYPE_P (TREE_TYPE (fntype)))
19818 0 : warning (OPT_Weffc__,
19819 : "%<operator=%> should return a reference to %<*this%>");
19820 :
19821 : /* Make the init_value nonzero so pushdecl knows this is not tentative.
19822 : error_mark_node is replaced below (in poplevel) with the BLOCK. */
19823 157955197 : if (!DECL_INITIAL (decl1))
19824 34109625 : DECL_INITIAL (decl1) = error_mark_node;
19825 :
19826 : /* This function exists in static storage.
19827 : (This does not mean `static' in the C sense!) */
19828 157955197 : TREE_STATIC (decl1) = 1;
19829 :
19830 : /* We must call push_template_decl after current_class_type is set
19831 : up. (If we are processing inline definitions after exiting a
19832 : class scope, current_class_type will be NULL_TREE until set above
19833 : by push_nested_class.) */
19834 157955197 : if (processing_template_decl)
19835 : {
19836 92801420 : tree newdecl1 = push_template_decl (decl1, doing_friend);
19837 92801420 : if (newdecl1 == error_mark_node)
19838 : {
19839 36 : if (ctype)
19840 9 : pop_nested_class ();
19841 36 : return false;
19842 : }
19843 92801384 : decl1 = newdecl1;
19844 : }
19845 :
19846 : /* Make sure the parameter and return types are reasonable. When
19847 : you declare a function, these types can be incomplete, but they
19848 : must be complete when you define the function. */
19849 157955161 : check_function_type (decl1, DECL_ARGUMENTS (decl1));
19850 :
19851 : /* Build the return declaration for the function. */
19852 157955161 : tree restype = TREE_TYPE (fntype);
19853 :
19854 157955161 : if (DECL_RESULT (decl1) == NULL_TREE)
19855 : {
19856 : /* In a template instantiation, copy the return type location. When
19857 : parsing, the location will be set in grokdeclarator. */
19858 64890571 : location_t loc = input_location;
19859 64890571 : if (DECL_TEMPLATE_INSTANTIATION (decl1))
19860 : {
19861 30695407 : tree tmpl = template_for_substitution (decl1);
19862 30695407 : if (tree res = DECL_RESULT (DECL_TEMPLATE_RESULT (tmpl)))
19863 29817275 : loc = DECL_SOURCE_LOCATION (res);
19864 : }
19865 :
19866 64890571 : tree resdecl = build_decl (loc, RESULT_DECL, 0, restype);
19867 64890571 : DECL_ARTIFICIAL (resdecl) = 1;
19868 64890571 : DECL_IGNORED_P (resdecl) = 1;
19869 64890571 : DECL_RESULT (decl1) = resdecl;
19870 :
19871 64890571 : cp_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
19872 : }
19873 :
19874 : /* Record the decl so that the function name is defined.
19875 : If we already have a decl for this name, and it is a FUNCTION_DECL,
19876 : use the old decl. */
19877 157955161 : if (!processing_template_decl && !(flags & SF_PRE_PARSED))
19878 : {
19879 : /* A specialization is not used to guide overload resolution. */
19880 19627330 : if (!DECL_FUNCTION_MEMBER_P (decl1)
19881 19608118 : && !(DECL_USE_TEMPLATE (decl1) &&
19882 12520 : PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (decl1))))
19883 : {
19884 9394318 : tree olddecl = pushdecl (decl1);
19885 :
19886 9394318 : if (olddecl == error_mark_node)
19887 : /* If something went wrong when registering the declaration,
19888 : use DECL1; we have to have a FUNCTION_DECL to use when
19889 : parsing the body of the function. */
19890 : ;
19891 : else
19892 : {
19893 : /* Otherwise, OLDDECL is either a previous declaration
19894 : of the same function or DECL1 itself. */
19895 :
19896 9394105 : if (warn_missing_declarations
19897 21 : && olddecl == decl1
19898 15 : && !DECL_MAIN_P (decl1)
19899 15 : && TREE_PUBLIC (decl1)
19900 9394117 : && !DECL_DECLARED_INLINE_P (decl1))
19901 : {
19902 9 : tree context;
19903 :
19904 : /* Check whether DECL1 is in an anonymous
19905 : namespace. */
19906 9 : for (context = DECL_CONTEXT (decl1);
19907 18 : context;
19908 9 : context = DECL_CONTEXT (context))
19909 : {
19910 12 : if (TREE_CODE (context) == NAMESPACE_DECL
19911 12 : && DECL_NAME (context) == NULL_TREE)
19912 : break;
19913 : }
19914 :
19915 9 : if (context == NULL)
19916 6 : warning_at (DECL_SOURCE_LOCATION (decl1),
19917 6 : OPT_Wmissing_declarations,
19918 : "no previous declaration for %qD", decl1);
19919 : }
19920 :
19921 9394105 : decl1 = olddecl;
19922 : }
19923 : }
19924 : else
19925 : {
19926 : /* We need to set the DECL_CONTEXT. */
19927 806962 : if (!DECL_CONTEXT (decl1) && DECL_TEMPLATE_INFO (decl1))
19928 0 : DECL_CONTEXT (decl1) = DECL_CONTEXT (DECL_TI_TEMPLATE (decl1));
19929 : }
19930 10201280 : fntype = TREE_TYPE (decl1);
19931 10201280 : restype = TREE_TYPE (fntype);
19932 :
19933 : /* If #pragma weak applies, mark the decl appropriately now.
19934 : The pragma only applies to global functions. Because
19935 : determining whether or not the #pragma applies involves
19936 : computing the mangled name for the declaration, we cannot
19937 : apply the pragma until after we have merged this declaration
19938 : with any previous declarations; if the original declaration
19939 : has a linkage specification, that specification applies to
19940 : the definition as well, and may affect the mangled name. */
19941 10201280 : if (DECL_FILE_SCOPE_P (decl1))
19942 2498549 : maybe_apply_pragma_weak (decl1);
19943 : }
19944 :
19945 : /* We are now in the scope of the function being defined. */
19946 157955161 : current_function_decl = decl1;
19947 :
19948 : /* Save the parm names or decls from this function's declarator
19949 : where store_parm_decls will find them. */
19950 157955161 : tree current_function_parms = DECL_ARGUMENTS (decl1);
19951 :
19952 : /* Let the user know we're compiling this function. */
19953 157955161 : announce_function (decl1);
19954 :
19955 157955161 : gcc_assert (DECL_INITIAL (decl1));
19956 :
19957 : /* This function may already have been parsed, in which case just
19958 : return; our caller will skip over the body without parsing. */
19959 157955161 : if (DECL_INITIAL (decl1) != error_mark_node)
19960 : return true;
19961 :
19962 : /* Initialize RTL machinery. We cannot do this until
19963 : CURRENT_FUNCTION_DECL and DECL_RESULT are set up. We do this
19964 : even when processing a template; this is how we get
19965 : CFUN set up, and our per-function variables initialized.
19966 : FIXME factor out the non-RTL stuff. */
19967 157955161 : cp_binding_level *bl = current_binding_level;
19968 157955161 : allocate_struct_function (decl1, processing_template_decl);
19969 :
19970 : /* Initialize the language data structures. Whenever we start
19971 : a new function, we destroy temporaries in the usual way. */
19972 157955161 : cfun->language = ggc_cleared_alloc<language_function> ();
19973 157955161 : current_stmt_tree ()->stmts_are_full_exprs_p = 1;
19974 157955161 : current_binding_level = bl;
19975 :
19976 : /* If we are (erroneously) defining a function that we have already
19977 : defined before, wipe out what we knew before. */
19978 157955161 : gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
19979 157955161 : FNDECL_USED_AUTO (decl1) = false;
19980 157955161 : DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
19981 :
19982 157955161 : if (!processing_template_decl && type_uses_auto (restype))
19983 : {
19984 886774 : FNDECL_USED_AUTO (decl1) = true;
19985 886774 : DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
19986 : }
19987 :
19988 : /* Start the statement-tree, start the tree now. */
19989 157955161 : DECL_SAVED_TREE (decl1) = push_stmt_list ();
19990 :
19991 157955161 : if (DECL_IOBJ_MEMBER_FUNCTION_P (decl1))
19992 : {
19993 : /* We know that this was set up by `grokclassfn'. We do not
19994 : wait until `store_parm_decls', since evil parse errors may
19995 : never get us to that point. Here we keep the consistency
19996 : between `current_class_type' and `current_class_ptr'. */
19997 102730671 : tree t = DECL_ARGUMENTS (decl1);
19998 :
19999 102730671 : gcc_assert (t != NULL_TREE && TREE_CODE (t) == PARM_DECL);
20000 102730671 : gcc_assert (TYPE_PTR_P (TREE_TYPE (t)));
20001 :
20002 102730671 : cp_function_chain->x_current_class_ref
20003 102730671 : = cp_build_fold_indirect_ref (t);
20004 : /* Set this second to avoid shortcut in cp_build_indirect_ref. */
20005 102730671 : cp_function_chain->x_current_class_ptr = t;
20006 :
20007 : /* Constructors and destructors need to know whether they're "in
20008 : charge" of initializing virtual base classes. */
20009 102730671 : t = DECL_CHAIN (t);
20010 102730671 : if (DECL_HAS_IN_CHARGE_PARM_P (decl1))
20011 : {
20012 16513 : current_in_charge_parm = t;
20013 16513 : t = DECL_CHAIN (t);
20014 : }
20015 102730671 : if (DECL_HAS_VTT_PARM_P (decl1))
20016 : {
20017 33085 : gcc_assert (DECL_NAME (t) == vtt_parm_identifier);
20018 33085 : current_vtt_parm = t;
20019 : }
20020 : }
20021 :
20022 285199260 : bool honor_interface = (!DECL_TEMPLOID_INSTANTIATION (decl1)
20023 : /* Implicitly-defined methods (like the
20024 : destructor for a class in which no destructor
20025 : is explicitly declared) must not be defined
20026 : until their definition is needed. So, we
20027 : ignore interface specifications for
20028 : compiler-generated functions. */
20029 192324056 : && !DECL_ARTIFICIAL (decl1));
20030 157955161 : struct c_fileinfo *finfo
20031 157955161 : = get_fileinfo (LOCATION_FILE (DECL_SOURCE_LOCATION (decl1)));
20032 :
20033 157955161 : if (processing_template_decl)
20034 : /* Don't mess with interface flags. */;
20035 65153777 : else if (DECL_INTERFACE_KNOWN (decl1))
20036 : {
20037 19081266 : tree ctx = decl_function_context (decl1);
20038 :
20039 19081266 : if (DECL_NOT_REALLY_EXTERN (decl1))
20040 15207868 : DECL_EXTERNAL (decl1) = 0;
20041 :
20042 19081266 : if (ctx != NULL_TREE && vague_linkage_p (ctx))
20043 : /* This is a function in a local class in an extern inline
20044 : or template function. */
20045 2871281 : comdat_linkage (decl1);
20046 : }
20047 : /* If this function belongs to an interface, it is public.
20048 : If it belongs to someone else's interface, it is also external.
20049 : This only affects inlines and template instantiations. */
20050 46072511 : else if (!finfo->interface_unknown && honor_interface)
20051 : {
20052 106 : if (DECL_DECLARED_INLINE_P (decl1)
20053 106 : || DECL_TEMPLOID_INSTANTIATION (decl1))
20054 : {
20055 82 : DECL_EXTERNAL (decl1)
20056 164 : = (finfo->interface_only
20057 82 : || (DECL_DECLARED_INLINE_P (decl1)
20058 36 : && ! flag_implement_inlines
20059 0 : && !DECL_VINDEX (decl1)));
20060 :
20061 : /* For WIN32 we also want to put these in linkonce sections. */
20062 82 : maybe_make_one_only (decl1);
20063 : }
20064 : else
20065 24 : DECL_EXTERNAL (decl1) = 0;
20066 106 : DECL_INTERFACE_KNOWN (decl1) = 1;
20067 : /* If this function is in an interface implemented in this file,
20068 : make sure that the back end knows to emit this function
20069 : here. */
20070 106 : if (!DECL_EXTERNAL (decl1))
20071 60 : mark_needed (decl1);
20072 : }
20073 46072405 : else if (finfo->interface_unknown && finfo->interface_only
20074 0 : && honor_interface)
20075 : {
20076 : /* If MULTIPLE_SYMBOL_SPACES is defined and we saw a #pragma
20077 : interface, we will have both finfo->interface_unknown and
20078 : finfo->interface_only set. In that case, we don't want to
20079 : use the normal heuristics because someone will supply a
20080 : #pragma implementation elsewhere, and deducing it here would
20081 : produce a conflict. */
20082 0 : comdat_linkage (decl1);
20083 0 : DECL_EXTERNAL (decl1) = 0;
20084 0 : DECL_INTERFACE_KNOWN (decl1) = 1;
20085 0 : DECL_DEFER_OUTPUT (decl1) = 1;
20086 : }
20087 : else
20088 : {
20089 : /* This is a definition, not a reference.
20090 : So clear DECL_EXTERNAL, unless this is a GNU extern inline. */
20091 46072405 : if (!GNU_INLINE_P (decl1))
20092 46072402 : DECL_EXTERNAL (decl1) = 0;
20093 :
20094 46072405 : if ((DECL_DECLARED_INLINE_P (decl1)
20095 1851077 : || DECL_TEMPLOID_INSTANTIATION (decl1))
20096 47685922 : && ! DECL_INTERFACE_KNOWN (decl1))
20097 45834845 : DECL_DEFER_OUTPUT (decl1) = 1;
20098 : else
20099 237560 : DECL_INTERFACE_KNOWN (decl1) = 1;
20100 : }
20101 :
20102 : /* Determine the ELF visibility attribute for the function. We must not
20103 : do this before calling "pushdecl", as we must allow "duplicate_decls"
20104 : to merge any attributes appropriately. We also need to wait until
20105 : linkage is set. */
20106 157955161 : if (!DECL_CLONED_FUNCTION_P (decl1))
20107 142287414 : determine_visibility (decl1);
20108 :
20109 157955161 : if (!processing_template_decl)
20110 65153777 : maybe_instantiate_noexcept (decl1);
20111 :
20112 157955161 : begin_scope (sk_function_parms, decl1);
20113 :
20114 157955161 : ++function_depth;
20115 :
20116 157955161 : start_fname_decls ();
20117 :
20118 157955161 : store_parm_decls (current_function_parms);
20119 :
20120 157955161 : start_function_contracts (decl1);
20121 :
20122 157955161 : if (!processing_template_decl
20123 65153777 : && flag_lifetime_dse > 1
20124 130298242 : && DECL_CONSTRUCTOR_P (decl1)
20125 : /* Clobbering an empty base is harmful if it overlays real data. */
20126 18345083 : && !is_empty_class (current_class_type)
20127 : /* We can't clobber safely for an implicitly-defined default constructor
20128 : because part of the initialization might happen before we enter the
20129 : constructor, via AGGR_INIT_ZERO_FIRST (c++/68006). */
20130 16553823 : && !implicit_default_ctor_p (decl1)
20131 173384872 : && !lookup_attribute ("clobber *this",
20132 15429711 : DECL_ATTRIBUTES (current_class_ptr)))
20133 15420371 : DECL_ATTRIBUTES (current_class_ptr)
20134 30840742 : = tree_cons (get_identifier ("clobber *this"), NULL_TREE,
20135 15420371 : DECL_ATTRIBUTES (current_class_ptr));
20136 :
20137 157955161 : if (!processing_template_decl
20138 130307554 : && DECL_CONSTRUCTOR_P (decl1)
20139 18346325 : && sanitize_flags_p (SANITIZE_VPTR)
20140 1902 : && !DECL_CLONED_FUNCTION_P (decl1)
20141 157955795 : && !implicit_default_ctor_p (decl1))
20142 480 : cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
20143 :
20144 157955161 : if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
20145 157954592 : start_lambda_scope (decl1);
20146 :
20147 : return true;
20148 : }
20149 :
20150 :
20151 : /* Like start_preparsed_function, except that instead of a
20152 : FUNCTION_DECL, this function takes DECLSPECS and DECLARATOR.
20153 :
20154 : Returns true on success. If the DECLARATOR is not suitable
20155 : for a function, we return false, which tells the parser to
20156 : skip the entire function. */
20157 :
20158 : bool
20159 38126413 : start_function (cp_decl_specifier_seq *declspecs,
20160 : const cp_declarator *declarator,
20161 : tree attrs)
20162 : {
20163 38126413 : tree decl1;
20164 :
20165 38126413 : decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
20166 38126413 : invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
20167 38126413 : if (decl1 == error_mark_node)
20168 : return false;
20169 :
20170 38126048 : if (DECL_MAIN_P (decl1))
20171 : /* main must return int. grokfndecl should have corrected it
20172 : (and issued a diagnostic) if the user got it wrong. */
20173 33425 : gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
20174 : integer_type_node));
20175 :
20176 38126048 : return start_preparsed_function (decl1, attrs, /*flags=*/SF_DEFAULT);
20177 : }
20178 :
20179 : /* Returns true iff an EH_SPEC_BLOCK should be created in the body of
20180 : FN. */
20181 :
20182 : bool
20183 302247768 : use_eh_spec_block (tree fn)
20184 : {
20185 300315292 : return (flag_exceptions && flag_enforce_eh_specs
20186 300315292 : && !processing_template_decl
20187 : /* We insert the EH_SPEC_BLOCK only in the original
20188 : function; then, it is copied automatically to the
20189 : clones. */
20190 113594359 : && !DECL_CLONED_FUNCTION_P (fn)
20191 : /* Implicitly-generated constructors and destructors have
20192 : exception specifications. However, those specifications
20193 : are the union of the possible exceptions specified by the
20194 : constructors/destructors for bases and members, so no
20195 : unallowed exception will ever reach this function. By
20196 : not creating the EH_SPEC_BLOCK we save a little memory,
20197 : and we avoid spurious warnings about unreachable
20198 : code. */
20199 97967663 : && !DECL_DEFAULTED_FN (fn)
20200 397788693 : && !type_throw_all_p (TREE_TYPE (fn)));
20201 : }
20202 :
20203 : /* Helper function to push ARGS into the current lexical scope. DECL
20204 : is the function declaration. NONPARMS is used to handle enum
20205 : constants. */
20206 :
20207 : void
20208 153369275 : do_push_parm_decls (tree decl, tree args, tree *nonparms)
20209 : {
20210 : /* If we're doing semantic analysis, then we'll call pushdecl
20211 : for each of these. We must do them in reverse order so that
20212 : they end in the correct forward order. */
20213 153369275 : args = nreverse (args);
20214 :
20215 153369275 : tree next;
20216 470613706 : for (tree parm = args; parm; parm = next)
20217 : {
20218 317244431 : next = DECL_CHAIN (parm);
20219 317244431 : if (TREE_CODE (parm) == PARM_DECL)
20220 317244431 : pushdecl (parm);
20221 0 : else if (nonparms)
20222 : {
20223 : /* If we find an enum constant or a type tag, put it aside for
20224 : the moment. */
20225 0 : TREE_CHAIN (parm) = NULL_TREE;
20226 0 : *nonparms = chainon (*nonparms, parm);
20227 : }
20228 : }
20229 :
20230 : /* Get the decls in their original chain order and record in the
20231 : function. This is all and only the PARM_DECLs that were
20232 : pushed into scope by the loop above. */
20233 153369275 : DECL_ARGUMENTS (decl) = get_local_decls ();
20234 153369275 : }
20235 :
20236 : /* Store the parameter declarations into the current function declaration.
20237 : This is called after parsing the parameter declarations, before
20238 : digesting the body of the function.
20239 :
20240 : Also install to binding contour return value identifier, if any. */
20241 :
20242 : static void
20243 157955161 : store_parm_decls (tree current_function_parms)
20244 : {
20245 157955161 : tree fndecl = current_function_decl;
20246 :
20247 : /* This is a chain of any other decls that came in among the parm
20248 : declarations. If a parm is declared with enum {foo, bar} x;
20249 : then CONST_DECLs for foo and bar are put here. */
20250 157955161 : tree nonparms = NULL_TREE;
20251 :
20252 157955161 : if (current_function_parms)
20253 : {
20254 : /* This case is when the function was defined with an ANSI prototype.
20255 : The parms already have decls, so we need not do anything here
20256 : except record them as in effect
20257 : and complain if any redundant old-style parm decls were written. */
20258 :
20259 150040446 : tree specparms = current_function_parms;
20260 :
20261 : /* Must clear this because it might contain TYPE_DECLs declared
20262 : at class level. */
20263 150040446 : current_binding_level->names = NULL;
20264 :
20265 150040446 : do_push_parm_decls (fndecl, specparms, &nonparms);
20266 : }
20267 : else
20268 7914715 : DECL_ARGUMENTS (fndecl) = NULL_TREE;
20269 :
20270 : /* Now store the final chain of decls for the arguments
20271 : as the decl-chain of the current lexical scope.
20272 : Put the enumerators in as well, at the front so that
20273 : DECL_ARGUMENTS is not modified. */
20274 157955161 : current_binding_level->names = chainon (nonparms, DECL_ARGUMENTS (fndecl));
20275 :
20276 : /* Register cleanups for parameters with trivial_abi attribute, the cleanup
20277 : of which is the callee's responsibility. */
20278 157955161 : if (!processing_template_decl)
20279 171518019 : for (tree parm = DECL_ARGUMENTS (fndecl); parm; parm = DECL_CHAIN (parm))
20280 : {
20281 106364242 : if (TREE_CODE (parm) == PARM_DECL)
20282 : {
20283 106364242 : tree parm_type = TREE_TYPE (parm);
20284 106364242 : if (has_trivial_abi_attribute (parm_type))
20285 : {
20286 15 : tree cleanup
20287 15 : = cxx_maybe_build_cleanup (parm, tf_warning_or_error);
20288 15 : if (cleanup && cleanup != error_mark_node)
20289 15 : finish_decl_cleanup (parm, cleanup);
20290 : }
20291 : }
20292 : }
20293 :
20294 157955161 : if (use_eh_spec_block (current_function_decl))
20295 24230207 : current_eh_spec_block = begin_eh_spec_block ();
20296 157955161 : }
20297 :
20298 :
20299 : /* Mark CDTOR's implicit THIS argument for returning, if required by
20300 : the ABI.. Return the decl for THIS, if it is to be returned, and
20301 : NULL otherwise. */
20302 :
20303 : tree
20304 135119488 : maybe_prepare_return_this (tree cdtor)
20305 : {
20306 135119488 : if (targetm.cxx.cdtor_returns_this ())
20307 0 : if (tree val = DECL_ARGUMENTS (cdtor))
20308 : {
20309 0 : suppress_warning (val, OPT_Wuse_after_free);
20310 0 : return val;
20311 : }
20312 :
20313 : return NULL_TREE;
20314 : }
20315 :
20316 : /* Set the return value of the [cd]tor if the ABI wants that. */
20317 :
20318 : void
20319 7974389 : maybe_return_this ()
20320 : {
20321 7974389 : if (tree val = maybe_prepare_return_this (current_function_decl))
20322 : {
20323 : /* Return the address of the object. */
20324 0 : val = fold_convert (TREE_TYPE (DECL_RESULT (current_function_decl)), val);
20325 0 : val = build2 (MODIFY_EXPR, TREE_TYPE (val),
20326 0 : DECL_RESULT (current_function_decl), val);
20327 0 : tree exprstmt = build_stmt (input_location, RETURN_EXPR, val);
20328 0 : add_stmt (exprstmt);
20329 : }
20330 7974389 : }
20331 :
20332 : /* Do all the processing for the beginning of a destructor; set up the
20333 : vtable pointers and cleanups for bases and members. */
20334 :
20335 : static void
20336 1564631 : begin_destructor_body (void)
20337 : {
20338 1564631 : tree compound_stmt;
20339 :
20340 : /* If the CURRENT_CLASS_TYPE is incomplete, we will have already
20341 : issued an error message. We still want to try to process the
20342 : body of the function, but initialize_vtbl_ptrs will crash if
20343 : TYPE_BINFO is NULL. */
20344 1564631 : if (COMPLETE_TYPE_P (current_class_type))
20345 : {
20346 1564631 : compound_stmt = begin_compound_stmt (0);
20347 : /* Make all virtual function table pointers in non-virtual base
20348 : classes point to CURRENT_CLASS_TYPE's virtual function
20349 : tables. */
20350 1564631 : initialize_vtbl_ptrs (current_class_ptr);
20351 1564631 : finish_compound_stmt (compound_stmt);
20352 :
20353 1564631 : if (flag_lifetime_dse
20354 : /* Clobbering an empty base is harmful if it overlays real data. */
20355 1564631 : && !is_empty_class (current_class_type))
20356 : {
20357 1427300 : if (sanitize_flags_p (SANITIZE_VPTR)
20358 235 : && (flag_sanitize_recover & SANITIZE_VPTR) == 0
20359 1427363 : && TYPE_CONTAINS_VPTR_P (current_class_type))
20360 : {
20361 63 : tree binfo = TYPE_BINFO (current_class_type);
20362 63 : tree ref
20363 63 : = cp_build_fold_indirect_ref (current_class_ptr);
20364 :
20365 63 : tree vtbl_ptr = build_vfield_ref (ref, TREE_TYPE (binfo));
20366 63 : tree vtbl = build_zero_cst (TREE_TYPE (vtbl_ptr));
20367 63 : tree stmt = cp_build_modify_expr (input_location, vtbl_ptr,
20368 : NOP_EXPR, vtbl,
20369 : tf_warning_or_error);
20370 : /* If the vptr is shared with some virtual nearly empty base,
20371 : don't clear it if not in charge, the dtor of the virtual
20372 : nearly empty base will do that later. */
20373 63 : if (CLASSTYPE_VBASECLASSES (current_class_type))
20374 : {
20375 : tree c = current_class_type;
20376 66 : while (CLASSTYPE_PRIMARY_BINFO (c))
20377 : {
20378 63 : if (BINFO_VIRTUAL_P (CLASSTYPE_PRIMARY_BINFO (c)))
20379 : {
20380 36 : stmt = convert_to_void (stmt, ICV_STATEMENT,
20381 : tf_warning_or_error);
20382 36 : stmt = build_if_in_charge (stmt);
20383 36 : break;
20384 : }
20385 27 : c = BINFO_TYPE (CLASSTYPE_PRIMARY_BINFO (c));
20386 : }
20387 : }
20388 63 : finish_decl_cleanup (NULL_TREE, stmt);
20389 : }
20390 : else
20391 1427237 : finish_decl_cleanup (NULL_TREE,
20392 : build_clobber_this (CLOBBER_OBJECT_END));
20393 : }
20394 :
20395 : /* And insert cleanups for our bases and members so that they
20396 : will be properly destroyed if we throw. */
20397 1564631 : push_base_cleanups ();
20398 : }
20399 1564631 : }
20400 :
20401 : /* Do the necessary processing for the beginning of a function body, which
20402 : in this case includes member-initializers, but not the catch clauses of
20403 : a function-try-block. Currently, this means opening a binding level
20404 : for the member-initializers (in a ctor), member cleanups (in a dtor),
20405 : and capture proxies (in a lambda operator()). */
20406 :
20407 : tree
20408 124351317 : begin_function_body (void)
20409 : {
20410 255893166 : if (! FUNCTION_NEEDS_BODY_BLOCK (current_function_decl))
20411 : return NULL_TREE;
20412 :
20413 24219145 : if (processing_template_decl)
20414 : /* Do nothing now. */;
20415 : else
20416 : /* Always keep the BLOCK node associated with the outermost pair of
20417 : curly braces of a function. These are needed for correct
20418 : operation of dwarfout.c. */
20419 8079439 : keep_next_level (true);
20420 :
20421 24219145 : tree stmt = begin_compound_stmt (BCS_FN_BODY);
20422 24219145 : current_binding_level->artificial = 1;
20423 :
20424 24219145 : if (processing_template_decl)
20425 : /* Do nothing now. */;
20426 16158878 : else if (DECL_DESTRUCTOR_P (current_function_decl))
20427 1564631 : begin_destructor_body ();
20428 :
20429 : return stmt;
20430 : }
20431 :
20432 : /* Do the processing for the end of a function body. Currently, this means
20433 : closing out the cleanups for fully-constructed bases and members, and in
20434 : the case of the destructor, deleting the object if desired. Again, this
20435 : is only meaningful for [cd]tors, since they are the only functions where
20436 : there is a significant distinction between the main body and any
20437 : function catch clauses. Handling, say, main() return semantics here
20438 : would be wrong, as flowing off the end of a function catch clause for
20439 : main() would also need to return 0. */
20440 :
20441 : void
20442 124351293 : finish_function_body (tree compstmt)
20443 : {
20444 124351293 : if (compstmt == NULL_TREE)
20445 : return;
20446 :
20447 : /* Close the block. */
20448 24219145 : finish_compound_stmt (compstmt);
20449 :
20450 24219145 : if (processing_template_decl)
20451 : /* Do nothing now. */;
20452 8079439 : else if (DECL_CONSTRUCTOR_P (current_function_decl)
20453 8079439 : || DECL_DESTRUCTOR_P (current_function_decl))
20454 7675578 : maybe_return_this ();
20455 : }
20456 :
20457 : /* Given a function, returns the BLOCK corresponding to the outermost level
20458 : of curly braces, skipping the artificial block created for constructor
20459 : initializers. */
20460 :
20461 : tree
20462 333450 : outer_curly_brace_block (tree fndecl)
20463 : {
20464 333450 : tree block = DECL_INITIAL (fndecl);
20465 333450 : if (BLOCK_OUTER_CURLY_BRACE_P (block))
20466 : return block;
20467 1041 : block = BLOCK_SUBBLOCKS (block);
20468 1041 : if (BLOCK_OUTER_CURLY_BRACE_P (block))
20469 : return block;
20470 0 : block = BLOCK_SUBBLOCKS (block);
20471 0 : gcc_assert (BLOCK_OUTER_CURLY_BRACE_P (block));
20472 : return block;
20473 : }
20474 :
20475 : /* If FNDECL is a class's key method, add the class to the list of
20476 : keyed classes that should be emitted. */
20477 :
20478 : static void
20479 157959110 : record_key_method_defined (tree fndecl)
20480 : {
20481 213187525 : if (DECL_OBJECT_MEMBER_FUNCTION_P (fndecl)
20482 102806473 : && DECL_VIRTUAL_P (fndecl)
20483 160659939 : && !processing_template_decl)
20484 : {
20485 1382178 : tree fnclass = DECL_CONTEXT (fndecl);
20486 1382178 : if (fndecl == CLASSTYPE_KEY_METHOD (fnclass))
20487 : {
20488 19843 : tree classdecl = TYPE_NAME (fnclass);
20489 : /* Classes attached to a named module are already handled. */
20490 19843 : if (!DECL_LANG_SPECIFIC (classdecl)
20491 20152 : || !DECL_MODULE_ATTACH_P (classdecl))
20492 19798 : vec_safe_push (keyed_classes, fnclass);
20493 : }
20494 : }
20495 157959110 : }
20496 :
20497 : /* Attempt to add a fix-it hint to RICHLOC suggesting the insertion
20498 : of "return *this;" immediately before its location, using FNDECL's
20499 : first statement (if any) to give the indentation, if appropriate. */
20500 :
20501 : static void
20502 18 : add_return_star_this_fixit (gcc_rich_location *richloc, tree fndecl)
20503 : {
20504 18 : location_t indent = UNKNOWN_LOCATION;
20505 18 : tree stmts = expr_first (DECL_SAVED_TREE (fndecl));
20506 18 : if (stmts)
20507 9 : indent = EXPR_LOCATION (stmts);
20508 18 : richloc->add_fixit_insert_formatted ("return *this;",
20509 : richloc->get_loc (),
20510 : indent);
20511 18 : }
20512 :
20513 : /* Finish up a function declaration and compile that function
20514 : all the way to assembler language output. The free the storage
20515 : for the function definition. INLINE_P is TRUE if we just
20516 : finished processing the body of an in-class inline function
20517 : definition. (This processing will have taken place after the
20518 : class definition is complete.) */
20519 :
20520 : tree
20521 157955125 : finish_function (bool inline_p)
20522 : {
20523 157955125 : tree fndecl = current_function_decl;
20524 157955125 : tree fntype, ctype = NULL_TREE;
20525 157955125 : tree resumer = NULL_TREE, destroyer = NULL_TREE;
20526 :
20527 : /* When we get some parse errors, we can end up without a
20528 : current_function_decl, so cope. */
20529 157955125 : if (fndecl == NULL_TREE || fndecl == error_mark_node)
20530 0 : return error_mark_node;
20531 :
20532 157955125 : if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20533 157954556 : finish_lambda_scope ();
20534 :
20535 157955125 : if (c_dialect_objc ())
20536 0 : objc_finish_function ();
20537 :
20538 157955125 : record_key_method_defined (fndecl);
20539 :
20540 157955125 : fntype = TREE_TYPE (fndecl);
20541 :
20542 : /* TREE_READONLY (fndecl) = 1;
20543 : This caused &foo to be of type ptr-to-const-function
20544 : which then got a warning when stored in a ptr-to-function variable. */
20545 :
20546 157955125 : gcc_assert (building_stmt_list_p ());
20547 : /* The current function is being defined, so its DECL_INITIAL should
20548 : be set, and unless there's a multiple definition, it should be
20549 : error_mark_node. */
20550 157955125 : gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
20551 :
20552 157955125 : cp_coroutine_transform *coroutine = nullptr;
20553 157955125 : if (flag_coroutines
20554 155183464 : && !processing_template_decl
20555 63374068 : && DECL_COROUTINE_P (fndecl)
20556 157960027 : && !DECL_RAMP_FN (fndecl))
20557 : {
20558 1690 : gcc_checking_assert (!DECL_CLONED_FUNCTION_P (fndecl)
20559 : && !DECL_DEFAULTED_FN (fndecl));
20560 1690 : coroutine = new cp_coroutine_transform (fndecl, inline_p);
20561 1690 : if (coroutine && coroutine->cp_valid_coroutine ())
20562 1690 : coroutine->apply_transforms ();
20563 :
20564 : /* We should handle coroutine IFNs in middle end lowering. */
20565 1690 : cfun->coroutine_component = true;
20566 :
20567 : /* Do not try to process the ramp's EH unless outlining succeeded. */
20568 1690 : if (coroutine->cp_valid_coroutine () && use_eh_spec_block (fndecl))
20569 360 : finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
20570 : (TREE_TYPE (fndecl)),
20571 360 : current_eh_spec_block);
20572 :
20573 : /* If outlining succeeded, then add contracts handling if needed. */
20574 1690 : if (coroutine->cp_valid_coroutine ())
20575 1606 : maybe_apply_function_contracts (fndecl);
20576 : }
20577 : else
20578 : /* For a cloned function, we've already got all the code we need;
20579 : there's no need to add any extra bits. */
20580 157953435 : if (!DECL_CLONED_FUNCTION_P (fndecl))
20581 : {
20582 : /* Make it so that `main' always returns 0 by default. */
20583 142285688 : if (DECL_MAIN_FREESTANDING_P (current_function_decl)
20584 142319098 : && !TREE_THIS_VOLATILE (current_function_decl))
20585 33410 : finish_return_stmt (integer_zero_node);
20586 :
20587 142285688 : if (use_eh_spec_block (current_function_decl))
20588 24229844 : finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
20589 : (TREE_TYPE (current_function_decl)),
20590 24229844 : current_eh_spec_block);
20591 :
20592 142285688 : maybe_apply_function_contracts (current_function_decl);
20593 :
20594 : }
20595 :
20596 : /* If we're saving up tree structure, tie off the function now. */
20597 157955125 : DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
20598 :
20599 157955125 : finish_fname_decls ();
20600 :
20601 : /* This must come after expand_function_end because cleanups might
20602 : have declarations (from inline functions) that need to go into
20603 : this function's blocks. */
20604 :
20605 : /* If the current binding level isn't the outermost binding level
20606 : for this function, either there is a bug, or we have experienced
20607 : syntax errors and the statement tree is malformed. */
20608 157955125 : if (current_binding_level->kind != sk_function_parms)
20609 : {
20610 : /* Make sure we have already experienced errors. */
20611 12 : gcc_assert (errorcount);
20612 :
20613 : /* Throw away the broken statement tree and extra binding
20614 : levels. */
20615 12 : DECL_SAVED_TREE (fndecl) = alloc_stmt_list ();
20616 :
20617 27 : while (current_binding_level->kind != sk_function_parms)
20618 : {
20619 15 : if (current_binding_level->kind == sk_class)
20620 0 : pop_nested_class ();
20621 : else
20622 15 : poplevel (0, 0, 0);
20623 : }
20624 : }
20625 157955125 : poplevel (1, 0, 1);
20626 :
20627 : /* Statements should always be full-expressions at the outermost set
20628 : of curly braces for a function. */
20629 157955125 : gcc_assert (stmts_are_full_exprs_p ());
20630 :
20631 : /* If there are no return statements in a function with auto return type,
20632 : the return type is void. But if the declared type is something like
20633 : auto*, this is an error. */
20634 65153741 : if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
20635 158841899 : && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20636 : {
20637 120990 : if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20638 120975 : && !current_function_returns_value
20639 241757 : && !current_function_returns_null)
20640 : {
20641 : /* We haven't applied return type deduction because we haven't
20642 : seen any return statements. Do that now. */
20643 120767 : tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
20644 120767 : do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
20645 : void_node, node, tf_warning_or_error,
20646 : adc_return_type);
20647 :
20648 120767 : apply_deduced_return_type (fndecl, void_type_node);
20649 120767 : fntype = TREE_TYPE (fndecl);
20650 : }
20651 223 : else if (!current_function_returns_value
20652 6 : && !current_function_returns_null)
20653 : {
20654 6 : auto_diagnostic_group d;
20655 12 : error ("no return statements in function returning %qT",
20656 6 : DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
20657 6 : inform (input_location, "only plain %<auto%> return type can be "
20658 : "deduced to %<void%>");
20659 6 : }
20660 : }
20661 :
20662 157955125 : if (FNDECL_USED_AUTO (fndecl)
20663 157955125 : && TREE_TYPE (fntype) != DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
20664 886551 : if (location_t fcloc = failed_completion_location (fndecl))
20665 : {
20666 6 : auto_diagnostic_group adg;
20667 6 : if (warning (OPT_Wsfinae_incomplete_,
20668 : "defining %qD, which previously failed to be deduced "
20669 : "in a SFINAE context", fndecl)
20670 6 : && warn_sfinae_incomplete == 1)
20671 6 : inform (fcloc, "here. Use %qs for a diagnostic at that point",
20672 : "-Wsfinae-incomplete=2");
20673 6 : }
20674 :
20675 : /* Remember that we were in class scope. */
20676 157955125 : if (current_class_name)
20677 120758066 : ctype = current_class_type;
20678 :
20679 157955125 : if (DECL_DELETED_FN (fndecl))
20680 : {
20681 90 : DECL_INITIAL (fndecl) = error_mark_node;
20682 90 : DECL_SAVED_TREE (fndecl) = NULL_TREE;
20683 90 : goto cleanup;
20684 : }
20685 :
20686 157955035 : if (flag_openmp)
20687 323319 : if (tree attr = lookup_attribute ("omp declare variant base",
20688 323319 : DECL_ATTRIBUTES (fndecl)))
20689 265 : omp_declare_variant_finalize (fndecl, attr);
20690 :
20691 : /* Complain if there's just no return statement. */
20692 157955035 : if ((warn_return_type
20693 46999 : || (cxx_dialect >= cxx14
20694 38992 : && DECL_DECLARED_CONSTEXPR_P (fndecl)))
20695 157925254 : && !VOID_TYPE_P (TREE_TYPE (fntype))
20696 99245601 : && !dependent_type_p (TREE_TYPE (fntype))
20697 50306023 : && !current_function_returns_value && !current_function_returns_null
20698 : /* Don't complain if we abort or throw. */
20699 31015 : && !current_function_returns_abnormally
20700 : /* Don't complain if there's an infinite loop. */
20701 945 : && !current_function_infinite_loop
20702 : /* Don't complain if we are declared noreturn. */
20703 877 : && !TREE_THIS_VOLATILE (fndecl)
20704 871 : && !DECL_NAME (DECL_RESULT (fndecl))
20705 871 : && !warning_suppressed_p (fndecl, OPT_Wreturn_type)
20706 : /* Structor return values (if any) are set by the compiler. */
20707 1254 : && !DECL_CONSTRUCTOR_P (fndecl)
20708 627 : && !DECL_DESTRUCTOR_P (fndecl)
20709 157955662 : && targetm.warn_func_return (fndecl))
20710 : {
20711 621 : gcc_rich_location richloc (input_location);
20712 : /* Potentially add a "return *this;" fix-it hint for
20713 : assignment operators. */
20714 621 : if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
20715 : {
20716 39 : tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
20717 39 : if (TREE_CODE (valtype) == REFERENCE_TYPE
20718 32 : && current_class_ref
20719 26 : && same_type_ignoring_top_level_qualifiers_p
20720 26 : (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
20721 71 : && global_dc->option_enabled_p (OPT_Wreturn_type))
20722 18 : add_return_star_this_fixit (&richloc, fndecl);
20723 : }
20724 621 : if (cxx_dialect >= cxx14
20725 621 : && DECL_DECLARED_CONSTEXPR_P (fndecl))
20726 2 : error_at (&richloc, "no return statement in %<constexpr%> function "
20727 : "returning non-void");
20728 619 : else if (warning_at (&richloc, OPT_Wreturn_type,
20729 : "no return statement in function returning "
20730 : "non-void"))
20731 169 : suppress_warning (fndecl, OPT_Wreturn_type);
20732 621 : }
20733 :
20734 : /* Lambda closure members are implicitly constexpr if possible. */
20735 157955035 : if (cxx_dialect >= cxx17
20736 273090087 : && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
20737 1742600 : DECL_DECLARED_CONSTEXPR_P (fndecl)
20738 1742600 : = ((processing_template_decl
20739 544333 : || is_valid_constexpr_fn (fndecl, /*complain*/false))
20740 3484310 : && potential_constant_expression (DECL_SAVED_TREE (fndecl)));
20741 :
20742 : /* Invoke the pre-genericize plugin before we start munging things. */
20743 157955035 : if (!processing_template_decl)
20744 65153651 : invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
20745 :
20746 : /* Fold away non-ODR usages of constants so that we don't need to
20747 : try and stream them in modules if they're internal. */
20748 157955035 : if (!processing_template_decl)
20749 65153651 : cp_fold_function_non_odr_use (fndecl);
20750 :
20751 : /* Save constexpr function body before it gets munged by
20752 : the NRV transformation. */
20753 157955035 : maybe_save_constexpr_fundef (fndecl);
20754 :
20755 : /* Perform delayed folding before NRV transformation. */
20756 157955035 : if (!processing_template_decl
20757 130307302 : && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
20758 222147633 : && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20759 64192159 : cp_fold_function (fndecl);
20760 :
20761 : /* Set up the named return value optimization, if we can. Candidate
20762 : variables are selected in check_return_expr. */
20763 157955035 : if (tree r = current_function_return_value)
20764 : {
20765 41531693 : if (r != error_mark_node)
20766 214415 : finalize_nrv (fndecl, r);
20767 41531693 : current_function_return_value = NULL_TREE;
20768 : }
20769 :
20770 : /* Must mark the RESULT_DECL as being in this function. */
20771 157955035 : DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
20772 :
20773 : /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
20774 : to the FUNCTION_DECL node itself. */
20775 157955035 : BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
20776 :
20777 : /* Store the end of the function, so that we get good line number
20778 : info for the epilogue. */
20779 157955035 : cfun->function_end_locus = input_location;
20780 :
20781 : /* Complain about parameters that are only set, but never otherwise used. */
20782 157955035 : if (warn_unused_but_set_parameter
20783 994194 : && !processing_template_decl
20784 507435 : && errorcount == unused_but_set_errorcount
20785 158462467 : && !DECL_CLONED_FUNCTION_P (fndecl))
20786 : {
20787 396072 : tree decl;
20788 :
20789 396072 : for (decl = DECL_ARGUMENTS (fndecl);
20790 1055573 : decl;
20791 659501 : decl = DECL_CHAIN (decl))
20792 659501 : if (TREE_USED (decl)
20793 547092 : && TREE_CODE (decl) == PARM_DECL
20794 547092 : && !DECL_READ_P (decl)
20795 225 : && DECL_NAME (decl)
20796 225 : && !DECL_ARTIFICIAL (decl)
20797 225 : && !warning_suppressed_p (decl, OPT_Wunused_but_set_parameter_)
20798 225 : && !DECL_IN_SYSTEM_HEADER (decl)
20799 225 : && TREE_TYPE (decl) != error_mark_node
20800 225 : && !TYPE_REF_P (TREE_TYPE (decl))
20801 659726 : && (!CLASS_TYPE_P (TREE_TYPE (decl))
20802 0 : || !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (decl))))
20803 225 : warning_at (DECL_SOURCE_LOCATION (decl),
20804 225 : OPT_Wunused_but_set_parameter_,
20805 : "parameter %qD set but not used", decl);
20806 396072 : unused_but_set_errorcount = errorcount;
20807 : }
20808 :
20809 : /* Complain about locally defined typedefs that are not used in this
20810 : function. */
20811 157955035 : maybe_warn_unused_local_typedefs ();
20812 :
20813 : /* Possibly warn about unused parameters. */
20814 157955035 : if (warn_unused_parameter
20815 724812 : && !processing_template_decl
20816 158305074 : && !DECL_CLONED_FUNCTION_P (fndecl))
20817 268529 : do_warn_unused_parameter (fndecl);
20818 :
20819 : /* Genericize before inlining. */
20820 157955035 : if (!processing_template_decl
20821 130307302 : && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
20822 222145394 : && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
20823 64189920 : cp_genericize (fndecl);
20824 :
20825 : /* If this function can't throw any exceptions, remember that. */
20826 157955035 : if (!processing_template_decl
20827 65153651 : && !cp_function_chain->can_throw
20828 49905306 : && !flag_non_call_exceptions
20829 49896557 : && !decl_replaceable_p (fndecl,
20830 49896557 : opt_for_fn (fndecl, flag_semantic_interposition))
20831 207612204 : && !lookup_attribute ("noipa", DECL_ATTRIBUTES (fndecl)))
20832 49654677 : TREE_NOTHROW (fndecl) = 1;
20833 :
20834 157955125 : cleanup:
20835 :
20836 : /* We're leaving the context of this function, so zap cfun. It's still in
20837 : DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation. */
20838 157955125 : set_cfun (NULL);
20839 157955125 : current_function_decl = NULL;
20840 :
20841 : /* If this is an in-class inline definition, we may have to pop the
20842 : bindings for the template parameters that we added in
20843 : maybe_begin_member_template_processing when start_function was
20844 : called. */
20845 157955125 : if (inline_p)
20846 80999453 : maybe_end_member_template_processing ();
20847 :
20848 : /* Leave the scope of the class. */
20849 157955125 : if (ctype)
20850 120758066 : pop_nested_class ();
20851 :
20852 157955125 : --function_depth;
20853 :
20854 : /* Clean up. */
20855 157955125 : invoke_plugin_callbacks (PLUGIN_FINISH_PARSE_FUNCTION, fndecl);
20856 :
20857 : /* Build outlined functions for coroutines and contracts. */
20858 :
20859 157955125 : if (coroutine)
20860 : {
20861 : /* Emit the resumer and destroyer functions now, providing that we have
20862 : not encountered some fatal error. */
20863 1690 : if (coroutine->cp_valid_coroutine ())
20864 : {
20865 1606 : coroutine->finish_transforms ();
20866 1606 : resumer = coroutine->get_resumer ();
20867 1606 : destroyer = coroutine->get_destroyer ();
20868 1606 : expand_or_defer_fn (resumer);
20869 1606 : expand_or_defer_fn (destroyer);
20870 : }
20871 1690 : delete coroutine;
20872 : }
20873 :
20874 : /* If we have used outlined contracts checking functions, build and emit
20875 : them here. */
20876 157955125 : finish_function_outlined_contracts (fndecl);
20877 :
20878 157955125 : return fndecl;
20879 : }
20880 :
20881 : /* Create the FUNCTION_DECL for a function definition.
20882 : DECLSPECS and DECLARATOR are the parts of the declaration;
20883 : they describe the return type and the name of the function,
20884 : but twisted together in a fashion that parallels the syntax of C.
20885 :
20886 : This function creates a binding context for the function body
20887 : as well as setting up the FUNCTION_DECL in current_function_decl.
20888 :
20889 : Returns a FUNCTION_DECL on success.
20890 :
20891 : If the DECLARATOR is not suitable for a function (it defines a datum
20892 : instead), we return 0, which tells yyparse to report a parse error.
20893 :
20894 : May return void_type_node indicating that this method is actually
20895 : a friend. See grokfield for more details.
20896 :
20897 : Came here with a `.pushlevel' .
20898 :
20899 : DO NOT MAKE ANY CHANGES TO THIS CODE WITHOUT MAKING CORRESPONDING
20900 : CHANGES TO CODE IN `grokfield'. */
20901 :
20902 : tree
20903 81198318 : grokmethod (cp_decl_specifier_seq *declspecs,
20904 : const cp_declarator *declarator, tree attrlist)
20905 : {
20906 81198318 : tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
20907 81198318 : &attrlist);
20908 :
20909 81198318 : if (fndecl == error_mark_node)
20910 : return error_mark_node;
20911 :
20912 81198214 : if (attrlist)
20913 0 : cplus_decl_attributes (&fndecl, attrlist, 0);
20914 :
20915 : /* Pass friends other than inline friend functions back. */
20916 81198214 : if (fndecl == void_type_node)
20917 : return fndecl;
20918 :
20919 81198214 : if (DECL_IN_AGGR_P (fndecl))
20920 : {
20921 0 : if (DECL_CLASS_SCOPE_P (fndecl))
20922 0 : error ("%qD is already defined in class %qT", fndecl,
20923 0 : DECL_CONTEXT (fndecl));
20924 0 : return error_mark_node;
20925 : }
20926 :
20927 81198214 : check_template_shadow (fndecl);
20928 :
20929 : /* p1779 ABI-Isolation makes inline not a default for in-class
20930 : definitions attached to a named module. If the user explicitly
20931 : made it inline, grokdeclarator will already have done the right
20932 : things. */
20933 81198214 : if ((!named_module_attach_p ()
20934 1074 : || flag_module_implicit_inline
20935 : /* Lambda's operator function remains inline. */
20936 2112 : || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
20937 : /* If the user explicitly asked for this to be inline, we don't
20938 : need to do more, but more importantly we want to warn if we
20939 : can't inline it. */
20940 81197751 : && !DECL_DECLARED_INLINE_P (fndecl))
20941 : {
20942 46637492 : if (TREE_PUBLIC (fndecl))
20943 44660344 : DECL_COMDAT (fndecl) = 1;
20944 46637492 : DECL_DECLARED_INLINE_P (fndecl) = 1;
20945 : /* It's ok if we can't inline this. */
20946 46637492 : DECL_NO_INLINE_WARNING_P (fndecl) = 1;
20947 : }
20948 :
20949 : /* We process method specializations in finish_struct_1. */
20950 81198214 : if (processing_template_decl && !DECL_TEMPLATE_SPECIALIZATION (fndecl))
20951 : {
20952 : /* Avoid calling decl_spec_seq... until we have to. */
20953 65169179 : bool friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
20954 65169179 : fndecl = push_template_decl (fndecl, friendp);
20955 65169179 : if (fndecl == error_mark_node)
20956 : return fndecl;
20957 : }
20958 :
20959 81198206 : if (DECL_CHAIN (fndecl) && !decl_spec_seq_has_spec_p (declspecs, ds_friend))
20960 : {
20961 0 : fndecl = copy_node (fndecl);
20962 0 : TREE_CHAIN (fndecl) = NULL_TREE;
20963 : }
20964 :
20965 81198206 : cp_finish_decl (fndecl, NULL_TREE, false, NULL_TREE, 0);
20966 :
20967 81198206 : DECL_IN_AGGR_P (fndecl) = 1;
20968 81198206 : return fndecl;
20969 : }
20970 :
20971 :
20972 : /* VAR is a VAR_DECL. If its type is incomplete, remember VAR so that
20973 : we can lay it out later, when and if its type becomes complete.
20974 :
20975 : Also handle constexpr variables where the initializer involves
20976 : an unlowered PTRMEM_CST because the class isn't complete yet. */
20977 :
20978 : void
20979 100501467 : maybe_register_incomplete_var (tree var)
20980 : {
20981 100501467 : gcc_assert (VAR_P (var));
20982 :
20983 : /* Keep track of variables with incomplete types. */
20984 44019511 : if (!processing_template_decl && TREE_TYPE (var) != error_mark_node
20985 144519247 : && DECL_EXTERNAL (var))
20986 : {
20987 6426916 : tree inner_type = TREE_TYPE (var);
20988 :
20989 6578916 : while (TREE_CODE (inner_type) == ARRAY_TYPE)
20990 152000 : inner_type = TREE_TYPE (inner_type);
20991 6426916 : inner_type = TYPE_MAIN_VARIANT (inner_type);
20992 :
20993 6570766 : if ((!COMPLETE_TYPE_P (inner_type) && CLASS_TYPE_P (inner_type))
20994 : /* RTTI TD entries are created while defining the type_info. */
20995 6426916 : || (TYPE_LANG_SPECIFIC (inner_type)
20996 2291610 : && TYPE_BEING_DEFINED (inner_type)))
20997 : {
20998 143850 : incomplete_var iv = {var, inner_type};
20999 143850 : vec_safe_push (incomplete_vars, iv);
21000 : }
21001 12267368 : else if (!(DECL_LANG_SPECIFIC (var) && DECL_TEMPLATE_INFO (var))
21002 3440910 : && DECL_CLASS_SCOPE_P (var)
21003 1073334 : && TYPE_BEING_DEFINED (DECL_CONTEXT (var))
21004 1073334 : && decl_constant_var_p (var)
21005 6971508 : && (TYPE_PTRMEM_P (inner_type) || CLASS_TYPE_P (inner_type)))
21006 : {
21007 : /* When the outermost open class is complete we can resolve any
21008 : pointers-to-members. */
21009 20 : tree context = outermost_open_class ();
21010 20 : incomplete_var iv = {var, context};
21011 20 : vec_safe_push (incomplete_vars, iv);
21012 : }
21013 : }
21014 100501467 : }
21015 :
21016 : /* Called when a class type (given by TYPE) is defined. If there are
21017 : any existing VAR_DECLs whose type has been completed by this
21018 : declaration, update them now. */
21019 :
21020 : void
21021 69139288 : complete_vars (tree type)
21022 : {
21023 69139288 : unsigned ix;
21024 69139288 : incomplete_var *iv;
21025 :
21026 69794924 : for (ix = 0; vec_safe_iterate (incomplete_vars, ix, &iv); )
21027 : {
21028 655636 : if (same_type_p (type, iv->incomplete_type))
21029 : {
21030 142646 : tree var = iv->decl;
21031 142646 : tree type = TREE_TYPE (var);
21032 :
21033 142646 : if (type != error_mark_node
21034 142646 : && (TYPE_MAIN_VARIANT (strip_array_types (type))
21035 142643 : == iv->incomplete_type))
21036 : {
21037 : /* Complete the type of the variable. */
21038 142623 : complete_type (type);
21039 142623 : cp_apply_type_quals_to_decl (cp_type_quals (type), var);
21040 142623 : if (COMPLETE_TYPE_P (type))
21041 142608 : layout_var_decl (var);
21042 : }
21043 :
21044 : /* Remove this entry from the list. */
21045 142646 : incomplete_vars->unordered_remove (ix);
21046 : }
21047 : else
21048 512990 : ix++;
21049 : }
21050 69139288 : }
21051 :
21052 : /* If DECL is of a type which needs a cleanup, build and return an
21053 : expression to perform that cleanup here. Return NULL_TREE if no
21054 : cleanup need be done. DECL can also be a _REF when called from
21055 : split_nonconstant_init_1. */
21056 :
21057 : tree
21058 86191933 : cxx_maybe_build_cleanup (tree decl, tsubst_flags_t complain)
21059 : {
21060 86191933 : tree type;
21061 86191933 : tree attr;
21062 86191933 : tree cleanup;
21063 :
21064 : /* Assume no cleanup is required. */
21065 86191933 : cleanup = NULL_TREE;
21066 :
21067 86191933 : if (!decl || error_operand_p (decl))
21068 : return cleanup;
21069 :
21070 : /* Handle "__attribute__((cleanup))". We run the cleanup function
21071 : before the destructor since the destructor is what actually
21072 : terminates the lifetime of the object. */
21073 86191933 : if (DECL_P (decl))
21074 85929413 : attr = lookup_attribute ("cleanup", DECL_ATTRIBUTES (decl));
21075 : else
21076 : attr = NULL_TREE;
21077 85929413 : if (attr)
21078 : {
21079 159 : tree id;
21080 159 : tree fn;
21081 159 : tree arg;
21082 :
21083 : /* Get the name specified by the user for the cleanup function. */
21084 159 : id = TREE_VALUE (TREE_VALUE (attr));
21085 : /* Look up the name to find the cleanup function to call. It is
21086 : important to use lookup_name here because that is what is
21087 : used in c-common.cc:handle_cleanup_attribute when performing
21088 : initial checks on the attribute. Note that those checks
21089 : include ensuring that the function found is not an overloaded
21090 : function, or an object with an overloaded call operator,
21091 : etc.; we can rely on the fact that the function found is an
21092 : ordinary FUNCTION_DECL. */
21093 159 : fn = lookup_name (id);
21094 159 : arg = build_address (decl);
21095 159 : if (!mark_used (decl, complain) && !(complain & tf_error))
21096 0 : return error_mark_node;
21097 159 : cleanup = cp_build_function_call_nary (fn, complain, arg, NULL_TREE);
21098 159 : if (cleanup == error_mark_node)
21099 : return error_mark_node;
21100 : }
21101 : /* Handle ordinary C++ destructors. */
21102 86191921 : type = TREE_TYPE (decl);
21103 86191921 : if (type_build_dtor_call (type))
21104 : {
21105 6713938 : int flags = LOOKUP_NORMAL|LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR;
21106 6713938 : tree addr;
21107 6713938 : tree call;
21108 :
21109 6713938 : if (TREE_CODE (type) == ARRAY_TYPE)
21110 : addr = decl;
21111 : else
21112 6710605 : addr = build_address (decl);
21113 :
21114 6713938 : call = build_delete (input_location, TREE_TYPE (addr), addr,
21115 : sfk_complete_destructor, flags, 0, complain);
21116 6713938 : if (call == error_mark_node)
21117 : cleanup = error_mark_node;
21118 6713893 : else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
21119 : /* Discard the call. */;
21120 4006843 : else if (decl_maybe_constant_destruction (decl, type)
21121 4007004 : && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
21122 161 : cxx_constant_dtor (call, decl);
21123 4006682 : else if (cleanup)
21124 3 : cleanup = cp_build_compound_expr (cleanup, call, complain);
21125 : else
21126 : cleanup = call;
21127 : }
21128 :
21129 : /* build_delete sets the location of the destructor call to the
21130 : current location, even though the destructor is going to be
21131 : called later, at the end of the current scope. This can lead to
21132 : a "jumpy" behavior for users of debuggers when they step around
21133 : the end of the block. So let's unset the location of the
21134 : destructor call instead. */
21135 86191921 : protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
21136 86191921 : if (cleanup && CONVERT_EXPR_P (cleanup))
21137 0 : protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
21138 :
21139 0 : if (cleanup
21140 4006871 : && DECL_P (decl)
21141 4006431 : && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
21142 : /* Treat objects with destructors as used; the destructor may do
21143 : something substantive. */
21144 4006425 : && !mark_used (decl, complain) && !(complain & tf_error))
21145 0 : return error_mark_node;
21146 :
21147 4006871 : if (cleanup && cfun && !processing_template_decl
21148 89742562 : && !expr_noexcept_p (cleanup, tf_none))
21149 5332 : cp_function_chain->throwing_cleanup = true;
21150 :
21151 : return cleanup;
21152 : }
21153 :
21154 :
21155 : /* Return the FUNCTION_TYPE that corresponds to MEMFNTYPE, which can be a
21156 : FUNCTION_DECL, METHOD_TYPE, FUNCTION_TYPE, pointer or reference to
21157 : METHOD_TYPE or FUNCTION_TYPE, or pointer to member function. */
21158 :
21159 : tree
21160 5676885 : static_fn_type (tree memfntype)
21161 : {
21162 5676885 : tree fntype;
21163 5676885 : tree args;
21164 :
21165 5676885 : if (TYPE_PTRMEMFUNC_P (memfntype))
21166 20084 : memfntype = TYPE_PTRMEMFUNC_FN_TYPE (memfntype);
21167 5676885 : if (INDIRECT_TYPE_P (memfntype)
21168 4976377 : || TREE_CODE (memfntype) == FUNCTION_DECL)
21169 5510969 : memfntype = TREE_TYPE (memfntype);
21170 5676885 : if (TREE_CODE (memfntype) == FUNCTION_TYPE)
21171 : return memfntype;
21172 552469 : gcc_assert (TREE_CODE (memfntype) == METHOD_TYPE);
21173 552469 : args = TYPE_ARG_TYPES (memfntype);
21174 552469 : fntype = cp_build_function_type (TREE_TYPE (memfntype), TREE_CHAIN (args));
21175 552469 : fntype = apply_memfn_quals (fntype, type_memfn_quals (memfntype));
21176 552469 : fntype = (cp_build_type_attribute_variant
21177 552469 : (fntype, TYPE_ATTRIBUTES (memfntype)));
21178 552469 : fntype = cxx_copy_lang_qualifiers (fntype, memfntype);
21179 552469 : return fntype;
21180 : }
21181 :
21182 : /* DECL was originally constructed as a non-static member function,
21183 : but turned out to be static. Update it accordingly. */
21184 :
21185 : void
21186 171026 : revert_static_member_fn (tree decl)
21187 : {
21188 171026 : tree stype = static_fn_type (decl);
21189 171026 : cp_cv_quals quals = type_memfn_quals (stype);
21190 171026 : cp_ref_qualifier rqual = type_memfn_rqual (stype);
21191 :
21192 171026 : if (quals != TYPE_UNQUALIFIED || rqual != REF_QUAL_NONE)
21193 9 : stype = apply_memfn_quals (stype, TYPE_UNQUALIFIED, REF_QUAL_NONE);
21194 :
21195 171026 : TREE_TYPE (decl) = stype;
21196 :
21197 171026 : if (DECL_ARGUMENTS (decl))
21198 171026 : DECL_ARGUMENTS (decl) = DECL_CHAIN (DECL_ARGUMENTS (decl));
21199 171026 : DECL_STATIC_FUNCTION_P (decl) = 1;
21200 171026 : }
21201 :
21202 : /* Return which tree structure is used by T, or TS_CP_GENERIC if T is
21203 : one of the language-independent trees. */
21204 :
21205 : enum cp_tree_node_structure_enum
21206 36487280468 : cp_tree_node_structure (union lang_tree_node * t)
21207 : {
21208 36487280468 : switch (TREE_CODE (&t->generic))
21209 : {
21210 : case ARGUMENT_PACK_SELECT: return TS_CP_ARGUMENT_PACK_SELECT;
21211 150874474 : case BASELINK: return TS_CP_BASELINK;
21212 75644313 : case CONSTRAINT_INFO: return TS_CP_CONSTRAINT_INFO;
21213 10948237 : case DEFERRED_NOEXCEPT: return TS_CP_DEFERRED_NOEXCEPT;
21214 5706106 : case DEFERRED_PARSE: return TS_CP_DEFERRED_PARSE;
21215 1958719757 : case IDENTIFIER_NODE: return TS_CP_IDENTIFIER;
21216 2940035 : case LAMBDA_EXPR: return TS_CP_LAMBDA_EXPR;
21217 261110 : case BINDING_VECTOR: return TS_CP_BINDING_VECTOR;
21218 682841041 : case OVERLOAD: return TS_CP_OVERLOAD;
21219 674 : case PTRMEM_CST: return TS_CP_PTRMEM;
21220 15011596 : case STATIC_ASSERT: return TS_CP_STATIC_ASSERT;
21221 642595521 : case TEMPLATE_DECL: return TS_CP_TEMPLATE_DECL;
21222 1491062017 : case TEMPLATE_INFO: return TS_CP_TEMPLATE_INFO;
21223 653940864 : case TEMPLATE_PARM_INDEX: return TS_CP_TPI;
21224 14555130 : case TRAIT_EXPR: return TS_CP_TRAIT_EXPR;
21225 6 : case TU_LOCAL_ENTITY: return TS_CP_TU_LOCAL_ENTITY;
21226 3531331 : case USERDEF_LITERAL: return TS_CP_USERDEF_LITERAL;
21227 30778648256 : default: return TS_CP_GENERIC;
21228 : }
21229 : }
21230 :
21231 : bool
21232 8918 : cp_missing_noreturn_ok_p (tree decl)
21233 : {
21234 : /* A missing noreturn is ok for the `main' function. */
21235 8918 : return DECL_MAIN_P (decl);
21236 : }
21237 :
21238 : /* Return the decl used to identify the COMDAT group into which DECL should
21239 : be placed. */
21240 :
21241 : tree
21242 121175068 : cxx_comdat_group (tree decl)
21243 : {
21244 : /* Virtual tables, construction virtual tables, and virtual table
21245 : tables all go in a single COMDAT group, named after the primary
21246 : virtual table. */
21247 121175068 : if (VAR_P (decl) && DECL_VTABLE_OR_VTT_P (decl))
21248 513504 : decl = CLASSTYPE_VTABLES (DECL_CONTEXT (decl));
21249 : /* For all other DECLs, the COMDAT group is the mangled name of the
21250 : declaration itself. */
21251 : else
21252 : {
21253 120661564 : while (DECL_THUNK_P (decl))
21254 : {
21255 : /* If TARGET_USE_LOCAL_THUNK_ALIAS_P, use_thunk puts the thunk
21256 : into the same section as the target function. In that case
21257 : we must return target's name. */
21258 0 : tree target = THUNK_TARGET (decl);
21259 0 : if (TARGET_USE_LOCAL_THUNK_ALIAS_P (target)
21260 0 : && DECL_SECTION_NAME (target) != NULL
21261 0 : && DECL_ONE_ONLY (target))
21262 : decl = target;
21263 : else
21264 : break;
21265 : }
21266 : /* If a ctor/dtor has already set the comdat group by
21267 : maybe_clone_body, don't override it. */
21268 120661564 : if (SUPPORTS_ONE_ONLY
21269 120661564 : && TREE_CODE (decl) == FUNCTION_DECL
21270 120661564 : && DECL_CLONED_FUNCTION_P (decl))
21271 17586037 : if (tree comdat = DECL_COMDAT_GROUP (decl))
21272 : return comdat;
21273 : }
21274 :
21275 : return decl;
21276 : }
21277 :
21278 : /* Returns the return type for FN as written by the user, which may include
21279 : a placeholder for a deduced return type. */
21280 :
21281 : tree
21282 483631978 : fndecl_declared_return_type (tree fn)
21283 : {
21284 483631978 : fn = STRIP_TEMPLATE (fn);
21285 483631978 : if (FNDECL_USED_AUTO (fn))
21286 117398 : return DECL_SAVED_AUTO_RETURN_TYPE (fn);
21287 :
21288 483514580 : return TREE_TYPE (TREE_TYPE (fn));
21289 : }
21290 :
21291 : /* Returns true iff DECL is a variable or function declared with an auto type
21292 : that has not yet been deduced to a real type. */
21293 :
21294 : bool
21295 931302784 : undeduced_auto_decl (tree decl)
21296 : {
21297 931302784 : if (cxx_dialect < cxx11)
21298 : return false;
21299 928820767 : STRIP_ANY_LOCATION_WRAPPER (decl);
21300 411518964 : return ((VAR_OR_FUNCTION_DECL_P (decl)
21301 91995896 : || TREE_CODE (decl) == TEMPLATE_DECL)
21302 1248564036 : && type_uses_auto (TREE_TYPE (decl)));
21303 : }
21304 :
21305 : /* Complain if DECL has an undeduced return type. */
21306 :
21307 : bool
21308 301810272 : require_deduced_type (tree decl, tsubst_flags_t complain)
21309 : {
21310 301810272 : if (undeduced_auto_decl (decl))
21311 : {
21312 11390 : if (TREE_CODE (decl) == FUNCTION_DECL
21313 11390 : && fndecl_built_in_p (decl, CP_BUILT_IN_SOURCE_LOCATION,
21314 : BUILT_IN_FRONTEND))
21315 : {
21316 : /* Set the return type of __builtin_source_location. */
21317 9472 : tree type = get_source_location_impl_type ();
21318 9472 : if (type == error_mark_node)
21319 : {
21320 33 : inform (input_location, "using %qs", "__builtin_source_location");
21321 33 : return false;
21322 : }
21323 9439 : type = cp_build_qualified_type (type, TYPE_QUAL_CONST);
21324 9439 : type = build_pointer_type (type);
21325 9439 : apply_deduced_return_type (decl, type);
21326 9439 : return true;
21327 : }
21328 :
21329 1918 : if (TREE_CODE (decl) == FUNCTION_DECL
21330 1918 : && fndecl_built_in_p (decl, CP_BUILT_IN_CURRENT_EXCEPTION,
21331 : BUILT_IN_FRONTEND))
21332 : {
21333 : /* Set the return type of __builtin_current_exception. */
21334 1287 : tree name = get_identifier ("exception_ptr");
21335 1287 : tree eptr = lookup_qualified_name (std_node, name);
21336 1287 : tree fld;
21337 1287 : if (TREE_CODE (eptr) != TYPE_DECL
21338 1287 : || !CLASS_TYPE_P (TREE_TYPE (eptr))
21339 1287 : || !COMPLETE_TYPE_P (TREE_TYPE (eptr))
21340 1287 : || !(fld = next_aggregate_field (TYPE_FIELDS (TREE_TYPE (eptr))))
21341 1287 : || DECL_ARTIFICIAL (fld)
21342 1287 : || TREE_CODE (TREE_TYPE (fld)) != POINTER_TYPE
21343 1287 : || next_aggregate_field (DECL_CHAIN (fld))
21344 2574 : || !tree_int_cst_equal (TYPE_SIZE (TREE_TYPE (eptr)),
21345 1287 : TYPE_SIZE (TREE_TYPE (fld))))
21346 : {
21347 0 : error ("%qs used without %qs declaration",
21348 : "__builtin_current_exception", "std::exception_ptr");
21349 0 : return false;
21350 : }
21351 :
21352 1287 : apply_deduced_return_type (decl, TREE_TYPE (eptr));
21353 1287 : return true;
21354 : }
21355 :
21356 631 : if (warning_suppressed_p (decl) && seen_error ())
21357 : /* We probably already complained about deduction failure. */;
21358 475 : else if (complain & tf_error)
21359 70 : error ("use of %qD before deduction of %<auto%>", decl);
21360 631 : note_failed_type_completion (decl, complain);
21361 631 : return false;
21362 : }
21363 : return true;
21364 : }
21365 :
21366 : /* Create a representation of the explicit-specifier with
21367 : constant-expression of EXPR. COMPLAIN is as for tsubst. */
21368 :
21369 : tree
21370 7983645 : build_explicit_specifier (tree expr, tsubst_flags_t complain)
21371 : {
21372 7983645 : if (check_for_bare_parameter_packs (expr))
21373 3 : return error_mark_node;
21374 :
21375 7983642 : if (instantiation_dependent_expression_p (expr))
21376 : /* Wait for instantiation, tsubst_function_decl will handle it. */
21377 : return expr;
21378 :
21379 6460436 : expr = build_converted_constant_bool_expr (expr, complain);
21380 6460436 : expr = instantiate_non_dependent_expr (expr, complain);
21381 6460436 : expr = cxx_constant_value (expr, complain);
21382 6460436 : return expr;
21383 : }
21384 :
21385 : #include "gt-cp-decl.h"
|