comparison gcc/cp/class.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* Functions related to building classes and their related objects. 1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987-2017 Free Software Foundation, Inc. 2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com) 3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify 7 GCC is free software; you can redistribute it and/or modify
131 static void determine_primary_bases (tree); 131 static void determine_primary_bases (tree);
132 static void maybe_warn_about_overly_private_class (tree); 132 static void maybe_warn_about_overly_private_class (tree);
133 static void add_implicitly_declared_members (tree, tree*, int, int); 133 static void add_implicitly_declared_members (tree, tree*, int, int);
134 static tree fixed_type_or_null (tree, int *, int *); 134 static tree fixed_type_or_null (tree, int *, int *);
135 static tree build_simple_base_path (tree expr, tree binfo); 135 static tree build_simple_base_path (tree expr, tree binfo);
136 static tree build_vtbl_ref_1 (tree, tree);
137 static void build_vtbl_initializer (tree, tree, tree, tree, int *, 136 static void build_vtbl_initializer (tree, tree, tree, tree, int *,
138 vec<constructor_elt, va_gc> **); 137 vec<constructor_elt, va_gc> **);
139 static bool check_bitfield_decl (tree); 138 static bool check_bitfield_decl (tree);
140 static bool check_field_decl (tree, tree, int *, int *); 139 static bool check_field_decl (tree, tree, int *, int *);
141 static void check_field_decls (tree, tree *, int *, int *); 140 static void check_field_decls (tree, tree *, int *, int *);
179 static void dump_thunk (FILE *, int, tree); 178 static void dump_thunk (FILE *, int, tree);
180 static tree build_vtable (tree, tree, tree); 179 static tree build_vtable (tree, tree, tree);
181 static void initialize_vtable (tree, vec<constructor_elt, va_gc> *); 180 static void initialize_vtable (tree, vec<constructor_elt, va_gc> *);
182 static void layout_nonempty_base_or_field (record_layout_info, 181 static void layout_nonempty_base_or_field (record_layout_info,
183 tree, tree, splay_tree); 182 tree, tree, splay_tree);
184 static tree end_of_class (tree, int);
185 static bool layout_empty_base (record_layout_info, tree, tree, splay_tree);
186 static void accumulate_vtbl_inits (tree, tree, tree, tree, tree, 183 static void accumulate_vtbl_inits (tree, tree, tree, tree, tree,
187 vec<constructor_elt, va_gc> **); 184 vec<constructor_elt, va_gc> **);
188 static void dfs_accumulate_vtbl_inits (tree, tree, tree, tree, tree, 185 static void dfs_accumulate_vtbl_inits (tree, tree, tree, tree, tree,
189 vec<constructor_elt, va_gc> **); 186 vec<constructor_elt, va_gc> **);
190 static void build_rtti_vtbl_entries (tree, vtbl_init_data *); 187 static void build_rtti_vtbl_entries (tree, vtbl_init_data *);
201 static tree dfs_fixup_binfo_vtbls (tree, void *); 198 static tree dfs_fixup_binfo_vtbls (tree, void *);
202 static int record_subobject_offset (tree, tree, splay_tree); 199 static int record_subobject_offset (tree, tree, splay_tree);
203 static int check_subobject_offset (tree, tree, splay_tree); 200 static int check_subobject_offset (tree, tree, splay_tree);
204 static int walk_subobject_offsets (tree, subobject_offset_fn, 201 static int walk_subobject_offsets (tree, subobject_offset_fn,
205 tree, splay_tree, tree, int); 202 tree, splay_tree, tree, int);
206 static void record_subobject_offsets (tree, tree, splay_tree, bool);
207 static int layout_conflict_p (tree, tree, splay_tree, int); 203 static int layout_conflict_p (tree, tree, splay_tree, int);
208 static int splay_tree_compare_integer_csts (splay_tree_key k1, 204 static int splay_tree_compare_integer_csts (splay_tree_key k1,
209 splay_tree_key k2); 205 splay_tree_key k2);
210 static void warn_about_ambiguous_bases (tree); 206 static void warn_about_ambiguous_bases (tree);
211 static bool type_requires_array_cookie (tree); 207 static bool type_requires_array_cookie (tree);
212 static bool base_derived_from (tree, tree); 208 static bool base_derived_from (tree, tree);
213 static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree); 209 static int empty_base_at_nonzero_offset_p (tree, tree, splay_tree);
214 static tree end_of_base (tree); 210 static tree end_of_base (tree);
215 static tree get_vcall_index (tree, tree); 211 static tree get_vcall_index (tree, tree);
216 static bool type_maybe_constexpr_default_constructor (tree); 212 static bool type_maybe_constexpr_default_constructor (tree);
217
218 /* Variables shared between class.c and call.c. */
219
220 int n_vtables = 0;
221 int n_vtable_entries = 0;
222 int n_vtable_searches = 0;
223 int n_vtable_elems = 0;
224 int n_convert_harshness = 0;
225 int n_compute_conversion_costs = 0;
226 int n_inner_fields_searched = 0;
227 213
228 /* Return a COND_EXPR that executes TRUE_STMT if this execution of the 214 /* Return a COND_EXPR that executes TRUE_STMT if this execution of the
229 'structor is in charge of 'structing virtual bases, or FALSE_STMT 215 'structor is in charge of 'structing virtual bases, or FALSE_STMT
230 otherwise. */ 216 otherwise. */
231 217
286 } 272 }
287 273
288 probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr)); 274 probe = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
289 if (want_pointer) 275 if (want_pointer)
290 probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe)); 276 probe = TYPE_MAIN_VARIANT (TREE_TYPE (probe));
277 if (dependent_type_p (probe))
278 if (tree open = currently_open_class (probe))
279 probe = open;
291 280
292 if (code == PLUS_EXPR 281 if (code == PLUS_EXPR
293 && !SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe)) 282 && !SAME_BINFO_TYPE_P (BINFO_TYPE (d_binfo), probe))
294 { 283 {
295 /* This can happen when adjust_result_of_qualified_name_lookup can't 284 /* This can happen when adjust_result_of_qualified_name_lookup can't
378 { 367 {
379 expr = build_nop (ptr_target_type, expr); 368 expr = build_nop (ptr_target_type, expr);
380 goto indout; 369 goto indout;
381 } 370 }
382 371
372 if (!COMPLETE_TYPE_P (probe))
373 {
374 if (complain & tf_error)
375 error ("cannot convert from %qT to base class %qT because %qT is "
376 "incomplete", BINFO_TYPE (d_binfo), BINFO_TYPE (binfo),
377 BINFO_TYPE (d_binfo));
378 return error_mark_node;
379 }
380
383 /* If we're in an NSDMI, we don't have the full constructor context yet 381 /* If we're in an NSDMI, we don't have the full constructor context yet
384 that we need for converting to a virtual base, so just build a stub 382 that we need for converting to a virtual base, so just build a stub
385 CONVERT_EXPR and expand it later in bot_replace. */ 383 CONVERT_EXPR and expand it later in bot_replace. */
386 if (virtual_access && fixed_type_p < 0 384 if (virtual_access && fixed_type_p < 0
387 && current_scope () != current_function_decl) 385 && current_scope () != current_function_decl)
423 if (code == PLUS_EXPR && !virtual_access 421 if (code == PLUS_EXPR && !virtual_access
424 /* We don't build base fields for empty bases, and they aren't very 422 /* We don't build base fields for empty bases, and they aren't very
425 interesting to the optimizers anyway. */ 423 interesting to the optimizers anyway. */
426 && !has_empty) 424 && !has_empty)
427 { 425 {
428 expr = cp_build_indirect_ref (expr, RO_NULL, complain); 426 expr = cp_build_fold_indirect_ref (expr);
429 expr = build_simple_base_path (expr, binfo); 427 expr = build_simple_base_path (expr, binfo);
430 if (rvalue) 428 if (rvalue && lvalue_p (expr))
431 expr = move (expr); 429 expr = move (expr);
432 if (want_pointer) 430 if (want_pointer)
433 expr = build_address (expr); 431 expr = build_address (expr);
434 target_type = TREE_TYPE (expr); 432 target_type = TREE_TYPE (expr);
435 goto out; 433 goto out;
450 tree t; 448 tree t;
451 449
452 t = TREE_TYPE (TYPE_VFIELD (current_class_type)); 450 t = TREE_TYPE (TYPE_VFIELD (current_class_type));
453 t = build_pointer_type (t); 451 t = build_pointer_type (t);
454 v_offset = fold_convert (t, current_vtt_parm); 452 v_offset = fold_convert (t, current_vtt_parm);
455 v_offset = cp_build_indirect_ref (v_offset, RO_NULL, complain); 453 v_offset = cp_build_fold_indirect_ref (v_offset);
456 } 454 }
457 else 455 else
458 { 456 {
459 tree t = expr; 457 tree t = expr;
460 if (sanitize_flags_p (SANITIZE_VPTR) 458 if (sanitize_flags_p (SANITIZE_VPTR)
463 t = cp_ubsan_maybe_instrument_cast_to_vbase (input_location, 461 t = cp_ubsan_maybe_instrument_cast_to_vbase (input_location,
464 probe, expr); 462 probe, expr);
465 if (t == NULL_TREE) 463 if (t == NULL_TREE)
466 t = expr; 464 t = expr;
467 } 465 }
468 v_offset = build_vfield_ref (cp_build_indirect_ref (t, RO_NULL, 466 v_offset = build_vfield_ref (cp_build_fold_indirect_ref (t),
469 complain),
470 TREE_TYPE (TREE_TYPE (expr))); 467 TREE_TYPE (TREE_TYPE (expr)));
471 } 468 }
472 469
473 if (v_offset == error_mark_node) 470 if (v_offset == error_mark_node)
474 return error_mark_node; 471 return error_mark_node;
475 472
476 v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo)); 473 v_offset = fold_build_pointer_plus (v_offset, BINFO_VPTR_FIELD (v_binfo));
477 v_offset = build1 (NOP_EXPR, 474 v_offset = build1 (NOP_EXPR,
478 build_pointer_type (ptrdiff_type_node), 475 build_pointer_type (ptrdiff_type_node),
479 v_offset); 476 v_offset);
480 v_offset = cp_build_indirect_ref (v_offset, RO_NULL, complain); 477 v_offset = cp_build_fold_indirect_ref (v_offset);
481 TREE_CONSTANT (v_offset) = 1; 478 TREE_CONSTANT (v_offset) = 1;
482 479
483 offset = convert_to_integer (ptrdiff_type_node, 480 offset = convert_to_integer (ptrdiff_type_node,
484 size_diffop_loc (input_location, offset, 481 size_diffop_loc (input_location, offset,
485 BINFO_OFFSET (v_binfo))); 482 BINFO_OFFSET (v_binfo)));
514 null_test = NULL; 511 null_test = NULL;
515 512
516 indout: 513 indout:
517 if (!want_pointer) 514 if (!want_pointer)
518 { 515 {
519 expr = cp_build_indirect_ref (expr, RO_NULL, complain); 516 expr = cp_build_fold_indirect_ref (expr);
520 if (rvalue) 517 if (rvalue)
521 expr = move (expr); 518 expr = move (expr);
522 } 519 }
523 520
524 out: 521 out:
550 into `(*(a ? &b : &c)).x', and so on. A COND_EXPR is only 547 into `(*(a ? &b : &c)).x', and so on. A COND_EXPR is only
551 an lvalue in the front end; only _DECLs and _REFs are lvalues 548 an lvalue in the front end; only _DECLs and _REFs are lvalues
552 in the back end. */ 549 in the back end. */
553 temp = unary_complex_lvalue (ADDR_EXPR, expr); 550 temp = unary_complex_lvalue (ADDR_EXPR, expr);
554 if (temp) 551 if (temp)
555 expr = cp_build_indirect_ref (temp, RO_NULL, tf_warning_or_error); 552 expr = cp_build_fold_indirect_ref (temp);
556 553
557 return expr; 554 return expr;
558 } 555 }
559 556
560 /* Recurse. */ 557 /* Recurse. */
696 /* Given an object INSTANCE, return an expression which yields the 693 /* Given an object INSTANCE, return an expression which yields the
697 vtable element corresponding to INDEX. There are many special 694 vtable element corresponding to INDEX. There are many special
698 cases for INSTANCE which we take care of here, mainly to avoid 695 cases for INSTANCE which we take care of here, mainly to avoid
699 creating extra tree nodes when we don't have to. */ 696 creating extra tree nodes when we don't have to. */
700 697
701 static tree 698 tree
702 build_vtbl_ref_1 (tree instance, tree idx) 699 build_vtbl_ref (tree instance, tree idx)
703 { 700 {
704 tree aref; 701 tree aref;
705 tree vtbl = NULL_TREE; 702 tree vtbl = NULL_TREE;
706 703
707 /* Try to figure out what a reference refers to, and 704 /* Try to figure out what a reference refers to, and
727 TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx); 724 TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
728 725
729 return aref; 726 return aref;
730 } 727 }
731 728
732 tree
733 build_vtbl_ref (tree instance, tree idx)
734 {
735 tree aref = build_vtbl_ref_1 (instance, idx);
736
737 return aref;
738 }
739
740 /* Given a stable object pointer INSTANCE_PTR, return an expression which 729 /* Given a stable object pointer INSTANCE_PTR, return an expression which
741 yields a function pointer corresponding to vtable element INDEX. */ 730 yields a function pointer corresponding to vtable element INDEX. */
742 731
743 tree 732 tree
744 build_vfn_ref (tree instance_ptr, tree idx) 733 build_vfn_ref (tree instance_ptr, tree idx)
745 { 734 {
746 tree aref; 735 tree aref;
747 736
748 aref = build_vtbl_ref_1 (cp_build_indirect_ref (instance_ptr, RO_NULL, 737 aref = build_vtbl_ref (cp_build_fold_indirect_ref (instance_ptr), idx);
749 tf_warning_or_error),
750 idx);
751 738
752 /* When using function descriptors, the address of the 739 /* When using function descriptors, the address of the
753 vtable entry is treated as a function pointer. */ 740 vtable entry is treated as a function pointer. */
754 if (TARGET_VTABLE_USES_DESCRIPTORS) 741 if (TARGET_VTABLE_USES_DESCRIPTORS)
755 aref = build1 (NOP_EXPR, TREE_TYPE (aref), 742 aref = build1 (NOP_EXPR, TREE_TYPE (aref),
892 { 879 {
893 gcc_assert (TREE_TYPE (decl) == vtbl_type_node); 880 gcc_assert (TREE_TYPE (decl) == vtbl_type_node);
894 virtuals = NULL_TREE; 881 virtuals = NULL_TREE;
895 } 882 }
896 883
897 if (GATHER_STATISTICS)
898 {
899 n_vtables += 1;
900 n_vtable_elems += list_length (virtuals);
901 }
902
903 /* Initialize the association list for this type, based 884 /* Initialize the association list for this type, based
904 on our first approximation. */ 885 on our first approximation. */
905 BINFO_VTABLE (TYPE_BINFO (type)) = decl; 886 BINFO_VTABLE (TYPE_BINFO (type)) = decl;
906 BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals; 887 BINFO_VIRTUALS (TYPE_BINFO (type)) = virtuals;
907 SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type)); 888 SET_BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (type));
1009 add_method (tree type, tree method, bool via_using) 990 add_method (tree type, tree method, bool via_using)
1010 { 991 {
1011 if (method == error_mark_node) 992 if (method == error_mark_node)
1012 return false; 993 return false;
1013 994
1014 /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc. */
1015 grok_special_member_properties (method);
1016
1017 tree *slot = get_member_slot (type, DECL_NAME (method));
1018 tree current_fns = *slot;
1019
1020 gcc_assert (!DECL_EXTERN_C_P (method)); 995 gcc_assert (!DECL_EXTERN_C_P (method));
996
997 tree *slot = find_member_slot (type, DECL_NAME (method));
998 tree current_fns = slot ? *slot : NULL_TREE;
1021 999
1022 /* Check to see if we've already got this method. */ 1000 /* Check to see if we've already got this method. */
1023 for (ovl_iterator iter (current_fns); iter; ++iter) 1001 for (ovl_iterator iter (current_fns); iter; ++iter)
1024 { 1002 {
1025 tree fn = *iter; 1003 tree fn = *iter;
1099 && equivalently_constrained (fn, method)) 1077 && equivalently_constrained (fn, method))
1100 { 1078 {
1101 /* If these are versions of the same function, process and 1079 /* If these are versions of the same function, process and
1102 move on. */ 1080 move on. */
1103 if (TREE_CODE (fn) == FUNCTION_DECL 1081 if (TREE_CODE (fn) == FUNCTION_DECL
1104 && maybe_version_functions (method, fn)) 1082 && maybe_version_functions (method, fn, true))
1105 continue; 1083 continue;
1106 1084
1107 if (DECL_INHERITED_CTOR (method)) 1085 if (DECL_INHERITED_CTOR (method))
1108 { 1086 {
1109 if (DECL_INHERITED_CTOR (fn)) 1087 if (DECL_INHERITED_CTOR (fn))
1162 /* A class should never have more than one destructor. */ 1140 /* A class should never have more than one destructor. */
1163 gcc_assert (!current_fns || !DECL_DESTRUCTOR_P (method)); 1141 gcc_assert (!current_fns || !DECL_DESTRUCTOR_P (method));
1164 1142
1165 current_fns = ovl_insert (method, current_fns, via_using); 1143 current_fns = ovl_insert (method, current_fns, via_using);
1166 1144
1167 if (!DECL_CONV_FN_P (method) && !COMPLETE_TYPE_P (type)) 1145 if (!COMPLETE_TYPE_P (type) && !DECL_CONV_FN_P (method)
1168 push_class_level_binding (DECL_NAME (method), current_fns); 1146 && !push_class_level_binding (DECL_NAME (method), current_fns))
1147 return false;
1148
1149 if (!slot)
1150 slot = add_member_slot (type, DECL_NAME (method));
1151
1152 /* Maintain TYPE_HAS_USER_CONSTRUCTOR, etc. */
1153 grok_special_member_properties (method);
1169 1154
1170 *slot = current_fns; 1155 *slot = current_fns;
1171 1156
1172 return true; 1157 return true;
1173 } 1158 }
1331 } 1316 }
1332 1317
1333 /* Otherwise we're diagnosing missing tags. */ 1318 /* Otherwise we're diagnosing missing tags. */
1334 if (TREE_CODE (p->t) == FUNCTION_DECL) 1319 if (TREE_CODE (p->t) == FUNCTION_DECL)
1335 { 1320 {
1321 auto_diagnostic_group d;
1336 if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag " 1322 if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
1337 "that %qT (used in its return type) has", 1323 "that %qT (used in its return type) has",
1338 p->t, tag, *tp)) 1324 p->t, tag, *tp))
1339 inform (location_of (*tp), "%qT declared here", *tp); 1325 inform (location_of (*tp), "%qT declared here", *tp);
1340 } 1326 }
1341 else if (VAR_P (p->t)) 1327 else if (VAR_P (p->t))
1342 { 1328 {
1329 auto_diagnostic_group d;
1343 if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag " 1330 if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag "
1344 "that %qT (used in its type) has", p->t, tag, *tp)) 1331 "that %qT (used in its type) has", p->t, tag, *tp))
1345 inform (location_of (*tp), "%qT declared here", *tp); 1332 inform (location_of (*tp), "%qT declared here", *tp);
1346 } 1333 }
1347 else if (TYPE_P (p->subob)) 1334 else if (TYPE_P (p->subob))
1348 { 1335 {
1336 auto_diagnostic_group d;
1349 if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag " 1337 if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
1350 "that base %qT has", p->t, tag, p->subob)) 1338 "that base %qT has", p->t, tag, p->subob))
1351 inform (location_of (p->subob), "%qT declared here", 1339 inform (location_of (p->subob), "%qT declared here",
1352 p->subob); 1340 p->subob);
1353 } 1341 }
1354 else 1342 else
1355 { 1343 {
1344 auto_diagnostic_group d;
1356 if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag " 1345 if (warning (OPT_Wabi_tag, "%qT does not have the %E ABI tag "
1357 "that %qT (used in the type of %qD) has", 1346 "that %qT (used in the type of %qD) has",
1358 p->t, tag, *tp, p->subob)) 1347 p->t, tag, *tp, p->subob))
1359 { 1348 {
1360 inform (location_of (p->subob), "%qD declared here", 1349 inform (location_of (p->subob), "%qD declared here",
1520 tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t)); 1509 tree attr = lookup_attribute ("abi_tag", DECL_ATTRIBUTES (t));
1521 if (attr) 1510 if (attr)
1522 TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr)); 1511 TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
1523 else 1512 else
1524 DECL_ATTRIBUTES (t) 1513 DECL_ATTRIBUTES (t)
1525 = tree_cons (get_identifier ("abi_tag"), data.tags, 1514 = tree_cons (abi_tag_identifier, data.tags, DECL_ATTRIBUTES (t));
1526 DECL_ATTRIBUTES (t));
1527 } 1515 }
1528 1516
1529 mark_abi_tags (t, false); 1517 mark_abi_tags (t, false);
1530 1518
1531 return data.tags; 1519 return data.tags;
1593 tree attr = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t)); 1581 tree attr = lookup_attribute ("abi_tag", TYPE_ATTRIBUTES (t));
1594 if (attr) 1582 if (attr)
1595 TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr)); 1583 TREE_VALUE (attr) = chainon (data.tags, TREE_VALUE (attr));
1596 else 1584 else
1597 TYPE_ATTRIBUTES (t) 1585 TYPE_ATTRIBUTES (t)
1598 = tree_cons (get_identifier ("abi_tag"), data.tags, 1586 = tree_cons (abi_tag_identifier, data.tags, TYPE_ATTRIBUTES (t));
1599 TYPE_ATTRIBUTES (t));
1600 } 1587 }
1601 1588
1602 mark_abi_tags (t, false); 1589 mark_abi_tags (t, false);
1603 } 1590 }
1604 1591
2037 static void 2024 static void
2038 maybe_warn_about_overly_private_class (tree t) 2025 maybe_warn_about_overly_private_class (tree t)
2039 { 2026 {
2040 int has_member_fn = 0; 2027 int has_member_fn = 0;
2041 int has_nonprivate_method = 0; 2028 int has_nonprivate_method = 0;
2029 bool nonprivate_ctor = false;
2042 2030
2043 if (!warn_ctor_dtor_privacy 2031 if (!warn_ctor_dtor_privacy
2044 /* If the class has friends, those entities might create and 2032 /* If the class has friends, those entities might create and
2045 access instances, so we should not warn. */ 2033 access instances, so we should not warn. */
2046 || (CLASSTYPE_FRIEND_CLASSES (t) 2034 || (CLASSTYPE_FRIEND_CLASSES (t)
2067 /* Check to see if all (non-constructor, non-destructor) member 2055 /* Check to see if all (non-constructor, non-destructor) member
2068 functions are private. (Since there are no friends or 2056 functions are private. (Since there are no friends or
2069 non-private statics, we can't ever call any of the private member 2057 non-private statics, we can't ever call any of the private member
2070 functions.) */ 2058 functions.) */
2071 for (tree fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn)) 2059 for (tree fn = TYPE_FIELDS (t); fn; fn = DECL_CHAIN (fn))
2072 if (!DECL_DECLARES_FUNCTION_P (fn)) 2060 if (TREE_CODE (fn) == USING_DECL
2061 && DECL_NAME (fn) == ctor_identifier
2062 && !TREE_PRIVATE (fn))
2063 nonprivate_ctor = true;
2064 else if (!DECL_DECLARES_FUNCTION_P (fn))
2073 /* Not a function. */; 2065 /* Not a function. */;
2074 else if (DECL_ARTIFICIAL (fn)) 2066 else if (DECL_ARTIFICIAL (fn))
2075 /* We're not interested in compiler-generated methods; they don't 2067 /* We're not interested in compiler-generated methods; they don't
2076 provide any way to call private members. */; 2068 provide any way to call private members. */;
2077 else if (!TREE_PRIVATE (fn)) 2069 else if (!TREE_PRIVATE (fn))
2129 /* Warn about classes that have private constructors and no friends. */ 2121 /* Warn about classes that have private constructors and no friends. */
2130 if (TYPE_HAS_USER_CONSTRUCTOR (t) 2122 if (TYPE_HAS_USER_CONSTRUCTOR (t)
2131 /* Implicitly generated constructors are always public. */ 2123 /* Implicitly generated constructors are always public. */
2132 && !CLASSTYPE_LAZY_DEFAULT_CTOR (t)) 2124 && !CLASSTYPE_LAZY_DEFAULT_CTOR (t))
2133 { 2125 {
2134 bool nonprivate_ctor = false;
2135 tree copy_or_move = NULL_TREE; 2126 tree copy_or_move = NULL_TREE;
2136 2127
2137 /* If a non-template class does not define a copy 2128 /* If a non-template class does not define a copy
2138 constructor, one is defined for it, enabling it to avoid 2129 constructor, one is defined for it, enabling it to avoid
2139 this warning. For a template class, this does not 2130 this warning. For a template class, this does not
2448 2439
2449 /* Check for adjusting covariant return types. */ 2440 /* Check for adjusting covariant return types. */
2450 over_return = TREE_TYPE (TREE_TYPE (overrider_target)); 2441 over_return = TREE_TYPE (TREE_TYPE (overrider_target));
2451 base_return = TREE_TYPE (TREE_TYPE (target_fn)); 2442 base_return = TREE_TYPE (TREE_TYPE (target_fn));
2452 2443
2453 if (POINTER_TYPE_P (over_return) 2444 if (INDIRECT_TYPE_P (over_return)
2454 && TREE_CODE (over_return) == TREE_CODE (base_return) 2445 && TREE_CODE (over_return) == TREE_CODE (base_return)
2455 && CLASS_TYPE_P (TREE_TYPE (over_return)) 2446 && CLASS_TYPE_P (TREE_TYPE (over_return))
2456 && CLASS_TYPE_P (TREE_TYPE (base_return)) 2447 && CLASS_TYPE_P (TREE_TYPE (base_return))
2457 /* If the overrider is invalid, don't even try. */ 2448 /* If the overrider is invalid, don't even try. */
2458 && !DECL_INVALID_OVERRIDER_P (overrider_target)) 2449 && !DECL_INVALID_OVERRIDER_P (overrider_target))
2491 has already been checked), so we can just iterate along 2482 has already been checked), so we can just iterate along
2492 the binfos, which have been chained in inheritance graph 2483 the binfos, which have been chained in inheritance graph
2493 order. Of course it is lame that we have to repeat the 2484 order. Of course it is lame that we have to repeat the
2494 search here anyway -- we should really be caching pieces 2485 search here anyway -- we should really be caching pieces
2495 of the vtable and avoiding this repeated work. */ 2486 of the vtable and avoiding this repeated work. */
2496 tree thunk_binfo, base_binfo; 2487 tree thunk_binfo = NULL_TREE;
2488 tree base_binfo = TYPE_BINFO (base_return);
2497 2489
2498 /* Find the base binfo within the overriding function's 2490 /* Find the base binfo within the overriding function's
2499 return type. We will always find a thunk_binfo, except 2491 return type. We will always find a thunk_binfo, except
2500 when the covariancy is invalid (which we will have 2492 when the covariancy is invalid (which we will have
2501 already diagnosed). */ 2493 already diagnosed). */
2502 for (base_binfo = TYPE_BINFO (base_return), 2494 if (base_binfo)
2503 thunk_binfo = TYPE_BINFO (over_return); 2495 for (thunk_binfo = TYPE_BINFO (over_return); thunk_binfo;
2504 thunk_binfo; 2496 thunk_binfo = TREE_CHAIN (thunk_binfo))
2505 thunk_binfo = TREE_CHAIN (thunk_binfo)) 2497 if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo),
2506 if (SAME_BINFO_TYPE_P (BINFO_TYPE (thunk_binfo), 2498 BINFO_TYPE (base_binfo)))
2507 BINFO_TYPE (base_binfo))) 2499 break;
2508 break; 2500 gcc_assert (thunk_binfo || errorcount);
2509 2501
2510 /* See if virtual inheritance is involved. */ 2502 /* See if virtual inheritance is involved. */
2511 for (virtual_offset = thunk_binfo; 2503 for (virtual_offset = thunk_binfo;
2512 virtual_offset; 2504 virtual_offset;
2513 virtual_offset = BINFO_INHERITANCE_CHAIN (virtual_offset)) 2505 virtual_offset = BINFO_INHERITANCE_CHAIN (virtual_offset))
2881 /* Recursive helper for finish_struct_anon. */ 2873 /* Recursive helper for finish_struct_anon. */
2882 2874
2883 static void 2875 static void
2884 finish_struct_anon_r (tree field, bool complain) 2876 finish_struct_anon_r (tree field, bool complain)
2885 { 2877 {
2886 bool is_union = TREE_CODE (TREE_TYPE (field)) == UNION_TYPE; 2878 for (tree elt = TYPE_FIELDS (TREE_TYPE (field)); elt; elt = DECL_CHAIN (elt))
2887 tree elt = TYPE_FIELDS (TREE_TYPE (field));
2888 for (; elt; elt = DECL_CHAIN (elt))
2889 { 2879 {
2890 /* We're generally only interested in entities the user 2880 /* We're generally only interested in entities the user
2891 declared, but we also find nested classes by noticing 2881 declared, but we also find nested classes by noticing
2892 the TYPE_DECL that we create implicitly. You're 2882 the TYPE_DECL that we create implicitly. You're
2893 allowed to put one anonymous union inside another, 2883 allowed to put one anonymous union inside another,
2897 if (DECL_ARTIFICIAL (elt) 2887 if (DECL_ARTIFICIAL (elt)
2898 && (!DECL_IMPLICIT_TYPEDEF_P (elt) 2888 && (!DECL_IMPLICIT_TYPEDEF_P (elt)
2899 || TYPE_UNNAMED_P (TREE_TYPE (elt)))) 2889 || TYPE_UNNAMED_P (TREE_TYPE (elt))))
2900 continue; 2890 continue;
2901 2891
2902 if (TREE_CODE (elt) != FIELD_DECL) 2892 if (complain
2893 && (TREE_CODE (elt) != FIELD_DECL
2894 || (TREE_PRIVATE (elt) || TREE_PROTECTED (elt))))
2903 { 2895 {
2904 /* We already complained about static data members in 2896 /* We already complained about static data members in
2905 finish_static_data_member_decl. */ 2897 finish_static_data_member_decl. */
2906 if (complain && !VAR_P (elt)) 2898 if (!VAR_P (elt))
2907 { 2899 {
2908 if (is_union) 2900 auto_diagnostic_group d;
2909 permerror (DECL_SOURCE_LOCATION (elt), 2901 if (permerror (DECL_SOURCE_LOCATION (elt),
2910 "%q#D invalid; an anonymous union can " 2902 TREE_CODE (TREE_TYPE (field)) == UNION_TYPE
2911 "only have non-static data members", elt); 2903 ? "%q#D invalid; an anonymous union may "
2912 else 2904 "only have public non-static data members"
2913 permerror (DECL_SOURCE_LOCATION (elt), 2905 : "%q#D invalid; an anonymous struct may "
2914 "%q#D invalid; an anonymous struct can " 2906 "only have public non-static data members", elt))
2915 "only have non-static data members", elt); 2907 {
2916 } 2908 static bool hint;
2917 continue; 2909 if (flag_permissive && !hint)
2918 } 2910 {
2919 2911 hint = true;
2920 if (complain) 2912 inform (DECL_SOURCE_LOCATION (elt),
2921 { 2913 "this flexibility is deprecated and will be "
2922 if (TREE_PRIVATE (elt)) 2914 "removed");
2923 { 2915 }
2924 if (is_union) 2916 }
2925 permerror (DECL_SOURCE_LOCATION (elt),
2926 "private member %q#D in anonymous union", elt);
2927 else
2928 permerror (DECL_SOURCE_LOCATION (elt),
2929 "private member %q#D in anonymous struct", elt);
2930 }
2931 else if (TREE_PROTECTED (elt))
2932 {
2933 if (is_union)
2934 permerror (DECL_SOURCE_LOCATION (elt),
2935 "protected member %q#D in anonymous union", elt);
2936 else
2937 permerror (DECL_SOURCE_LOCATION (elt),
2938 "protected member %q#D in anonymous struct", elt);
2939 } 2917 }
2940 } 2918 }
2941 2919
2942 TREE_PRIVATE (elt) = TREE_PRIVATE (field); 2920 TREE_PRIVATE (elt) = TREE_PRIVATE (field);
2943 TREE_PROTECTED (elt) = TREE_PROTECTED (field); 2921 TREE_PROTECTED (elt) = TREE_PROTECTED (field);
2944 2922
2945 /* Recurse into the anonymous aggregates to handle correctly 2923 /* Recurse into the anonymous aggregates to correctly handle
2946 access control (c++/24926): 2924 access control (c++/24926):
2947 2925
2948 class A { 2926 class A {
2949 union { 2927 union {
2950 union { 2928 union {
3009 2987
3010 static tree 2988 static tree
3011 dfs_declare_virt_assop_and_dtor (tree binfo, void *data) 2989 dfs_declare_virt_assop_and_dtor (tree binfo, void *data)
3012 { 2990 {
3013 tree bv, fn, t = (tree)data; 2991 tree bv, fn, t = (tree)data;
3014 tree opname = cp_assignment_operator_id (NOP_EXPR); 2992 tree opname = assign_op_identifier;
3015 2993
3016 gcc_assert (t && CLASS_TYPE_P (t)); 2994 gcc_assert (t && CLASS_TYPE_P (t));
3017 gcc_assert (binfo && TREE_CODE (binfo) == TREE_BINFO); 2995 gcc_assert (binfo && TREE_CODE (binfo) == TREE_BINFO);
3018 2996
3019 if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo))) 2997 if (!TYPE_CONTAINS_VPTR_P (BINFO_TYPE (binfo)))
3074 /* We don't declare an inheriting ctor that would be a default, 3052 /* We don't declare an inheriting ctor that would be a default,
3075 copy or move ctor for derived or base. */ 3053 copy or move ctor for derived or base. */
3076 if (nparms == 0) 3054 if (nparms == 0)
3077 return; 3055 return;
3078 if (nparms == 1 3056 if (nparms == 1
3079 && TREE_CODE (parms[0]) == REFERENCE_TYPE) 3057 && TYPE_REF_P (parms[0]))
3080 { 3058 {
3081 tree parm = TYPE_MAIN_VARIANT (TREE_TYPE (parms[0])); 3059 tree parm = TYPE_MAIN_VARIANT (TREE_TYPE (parms[0]));
3082 if (parm == t || parm == DECL_CONTEXT (ctor)) 3060 if (parm == t || parm == DECL_CONTEXT (ctor))
3083 return; 3061 return;
3084 } 3062 }
3122 new_parms[i++] = TREE_VALUE (parms); 3100 new_parms[i++] = TREE_VALUE (parms);
3123 } 3101 }
3124 one_inheriting_sig (t, ctor, new_parms, i); 3102 one_inheriting_sig (t, ctor, new_parms, i);
3125 if (parms == NULL_TREE) 3103 if (parms == NULL_TREE)
3126 { 3104 {
3105 auto_diagnostic_group d;
3127 if (warning (OPT_Winherited_variadic_ctor, 3106 if (warning (OPT_Winherited_variadic_ctor,
3128 "the ellipsis in %qD is not inherited", ctor)) 3107 "the ellipsis in %qD is not inherited", ctor))
3129 inform (DECL_SOURCE_LOCATION (ctor), "%qD declared here", ctor); 3108 inform (DECL_SOURCE_LOCATION (ctor), "%qD declared here", ctor);
3130 } 3109 }
3131 } 3110 }
3276 || ((TREE_CODE (type) == ENUMERAL_TYPE 3255 || ((TREE_CODE (type) == ENUMERAL_TYPE
3277 || TREE_CODE (type) == BOOLEAN_TYPE) 3256 || TREE_CODE (type) == BOOLEAN_TYPE)
3278 && tree_int_cst_lt (TYPE_SIZE (type), w))) 3257 && tree_int_cst_lt (TYPE_SIZE (type), w)))
3279 warning_at (DECL_SOURCE_LOCATION (field), 0, 3258 warning_at (DECL_SOURCE_LOCATION (field), 0,
3280 "width of %qD exceeds its type", field); 3259 "width of %qD exceeds its type", field);
3281 else if (TREE_CODE (type) == ENUMERAL_TYPE 3260 else if (TREE_CODE (type) == ENUMERAL_TYPE)
3282 && (0 > (compare_tree_int 3261 {
3283 (w, TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type)))))) 3262 int prec = TYPE_PRECISION (ENUM_UNDERLYING_TYPE (type));
3284 warning_at (DECL_SOURCE_LOCATION (field), 0, 3263 if (compare_tree_int (w, prec) < 0)
3285 "%qD is too small to hold all values of %q#T", 3264 warning_at (DECL_SOURCE_LOCATION (field), 0,
3286 field, type); 3265 "%qD is too small to hold all values of %q#T",
3266 field, type);
3267 }
3287 } 3268 }
3288 3269
3289 if (w != error_mark_node) 3270 if (w != error_mark_node)
3290 { 3271 {
3291 DECL_SIZE (field) = fold_convert (bitsizetype, w); 3272 DECL_SIZE (field) = fold_convert (bitsizetype, w);
3481 { 3462 {
3482 error ("in C++98 %q+D may not be static because it is " 3463 error ("in C++98 %q+D may not be static because it is "
3483 "a member of a union", x); 3464 "a member of a union", x);
3484 continue; 3465 continue;
3485 } 3466 }
3486 if (TREE_CODE (type) == REFERENCE_TYPE 3467 if (TYPE_REF_P (type)
3487 && TREE_CODE (x) == FIELD_DECL) 3468 && TREE_CODE (x) == FIELD_DECL)
3488 { 3469 {
3489 error ("non-static data member %q+D in a union may not " 3470 error ("non-static data member %q+D in a union may not "
3490 "have reference type %qT", x, type); 3471 "have reference type %qT", x, type);
3491 continue; 3472 continue;
3535 field_access = this_field_access; 3516 field_access = this_field_access;
3536 else if (this_field_access != field_access) 3517 else if (this_field_access != field_access)
3537 CLASSTYPE_NON_STD_LAYOUT (t) = 1; 3518 CLASSTYPE_NON_STD_LAYOUT (t) = 1;
3538 3519
3539 /* If this is of reference type, check if it needs an init. */ 3520 /* If this is of reference type, check if it needs an init. */
3540 if (TREE_CODE (type) == REFERENCE_TYPE) 3521 if (TYPE_REF_P (type))
3541 { 3522 {
3542 CLASSTYPE_NON_LAYOUT_POD_P (t) = 1; 3523 CLASSTYPE_NON_LAYOUT_POD_P (t) = 1;
3543 CLASSTYPE_NON_STD_LAYOUT (t) = 1; 3524 CLASSTYPE_NON_STD_LAYOUT (t) = 1;
3544 if (DECL_INITIAL (x) == NULL_TREE) 3525 if (DECL_INITIAL (x) == NULL_TREE)
3545 SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1); 3526 SET_CLASSTYPE_REF_FIELDS_NEED_INIT (t, 1);
3613 { 3594 {
3614 error ("member %q+D cannot be declared both %<const%> " 3595 error ("member %q+D cannot be declared both %<const%> "
3615 "and %<mutable%>", x); 3596 "and %<mutable%>", x);
3616 continue; 3597 continue;
3617 } 3598 }
3618 if (TREE_CODE (type) == REFERENCE_TYPE) 3599 if (TYPE_REF_P (type))
3619 { 3600 {
3620 error ("member %q+D cannot be declared as a %<mutable%> " 3601 error ("member %q+D cannot be declared as a %<mutable%> "
3621 "reference", x); 3602 "reference", x);
3622 continue; 3603 continue;
3623 } 3604 }
3974 } 3955 }
3975 3956
3976 return 0; 3957 return 0;
3977 } 3958 }
3978 3959
3979 /* Record all of the empty subobjects of TYPE (either a type or a 3960 /* Return true iff FIELD_DECL DECL is potentially overlapping. */
3980 binfo). If IS_DATA_MEMBER is true, then a non-static data member 3961
3981 is being placed at OFFSET; otherwise, it is a base class that is 3962 static bool
3982 being placed at OFFSET. */ 3963 field_poverlapping_p (tree decl)
3964 {
3965 /* Base fields are actually potentially overlapping, but C++ bases go through
3966 a different code path based on binfos, and ObjC++ base fields are laid out
3967 in objc-act, so we don't want layout_class_type to mess with them. */
3968 if (DECL_FIELD_IS_BASE (decl))
3969 {
3970 gcc_checking_assert (c_dialect_objc ());
3971 return false;
3972 }
3973
3974 return lookup_attribute ("no_unique_address",
3975 DECL_ATTRIBUTES (decl));
3976 }
3977
3978 /* Record all of the empty subobjects of DECL_OR_BINFO. */
3983 3979
3984 static void 3980 static void
3985 record_subobject_offsets (tree type, 3981 record_subobject_offsets (tree decl_or_binfo,
3986 tree offset, 3982 splay_tree offsets)
3987 splay_tree offsets, 3983 {
3988 bool is_data_member) 3984 tree type, offset;
3989 { 3985 bool overlapping, vbases_p;
3986
3987 if (DECL_P (decl_or_binfo))
3988 {
3989 tree decl = decl_or_binfo;
3990 type = TREE_TYPE (decl);
3991 offset = byte_position (decl);
3992 overlapping = field_poverlapping_p (decl);
3993 vbases_p = true;
3994 }
3995 else
3996 {
3997 type = BINFO_TYPE (decl_or_binfo);
3998 offset = BINFO_OFFSET (decl_or_binfo);
3999 overlapping = true;
4000 vbases_p = false;
4001 }
4002
3990 tree max_offset; 4003 tree max_offset;
3991 /* If recording subobjects for a non-static data member or a 4004 /* If recording subobjects for a non-static data member or a
3992 non-empty base class , we do not need to record offsets beyond 4005 non-empty base class, we do not need to record offsets beyond
3993 the size of the biggest empty class. Additional data members 4006 the size of the biggest empty class. Additional data members
3994 will go at the end of the class. Additional base classes will go 4007 will go at the end of the class. Additional base classes will go
3995 either at offset zero (if empty, in which case they cannot 4008 either at offset zero (if empty, in which case they cannot
3996 overlap with offsets past the size of the biggest empty class) or 4009 overlap with offsets past the size of the biggest empty class) or
3997 at the end of the class. 4010 at the end of the class.
3999 However, if we are placing an empty base class, then we must record 4012 However, if we are placing an empty base class, then we must record
4000 all offsets, as either the empty class is at offset zero (where 4013 all offsets, as either the empty class is at offset zero (where
4001 other empty classes might later be placed) or at the end of the 4014 other empty classes might later be placed) or at the end of the
4002 class (where other objects might then be placed, so other empty 4015 class (where other objects might then be placed, so other empty
4003 subobjects might later overlap). */ 4016 subobjects might later overlap). */
4004 if (is_data_member 4017 if (!overlapping
4005 || !is_empty_class (BINFO_TYPE (type))) 4018 || !is_empty_class (type))
4006 max_offset = sizeof_biggest_empty_class; 4019 max_offset = sizeof_biggest_empty_class;
4007 else 4020 else
4008 max_offset = NULL_TREE; 4021 max_offset = NULL_TREE;
4009 walk_subobject_offsets (type, record_subobject_offset, offset, 4022 walk_subobject_offsets (type, record_subobject_offset, offset,
4010 offsets, max_offset, is_data_member); 4023 offsets, max_offset, vbases_p);
4011 } 4024 }
4012 4025
4013 /* Returns nonzero if any of the empty subobjects of TYPE (located at 4026 /* Returns nonzero if any of the empty subobjects of TYPE (located at
4014 OFFSET) conflict with entries in OFFSETS. If VBASES_P is nonzero, 4027 OFFSET) conflict with entries in OFFSETS. If VBASES_P is nonzero,
4015 virtual bases of TYPE are examined. */ 4028 virtual bases of TYPE are examined. */
4165 class of the type indicated by BINFO; OFFSETS gives the offsets of 4178 class of the type indicated by BINFO; OFFSETS gives the offsets of
4166 the empty bases allocated so far. T is the most derived 4179 the empty bases allocated so far. T is the most derived
4167 type. Return nonzero iff we added it at the end. */ 4180 type. Return nonzero iff we added it at the end. */
4168 4181
4169 static bool 4182 static bool
4170 layout_empty_base (record_layout_info rli, tree binfo, 4183 layout_empty_base_or_field (record_layout_info rli, tree binfo_or_decl,
4171 tree eoc, splay_tree offsets) 4184 splay_tree offsets)
4172 { 4185 {
4173 tree alignment; 4186 tree alignment;
4174 tree basetype = BINFO_TYPE (binfo);
4175 bool atend = false; 4187 bool atend = false;
4188 tree binfo = NULL_TREE;
4189 tree decl = NULL_TREE;
4190 tree type;
4191 if (TREE_CODE (binfo_or_decl) == TREE_BINFO)
4192 {
4193 binfo = binfo_or_decl;
4194 type = BINFO_TYPE (binfo);
4195 }
4196 else
4197 {
4198 decl = binfo_or_decl;
4199 type = TREE_TYPE (decl);
4200 }
4201
4202 /* On some platforms (ARM), even empty classes will not be
4203 byte-aligned. */
4204 tree eoc = round_up_loc (input_location,
4205 rli_size_unit_so_far (rli),
4206 CLASSTYPE_ALIGN_UNIT (type));
4176 4207
4177 /* This routine should only be used for empty classes. */ 4208 /* This routine should only be used for empty classes. */
4178 gcc_assert (is_empty_class (basetype)); 4209 gcc_assert (is_empty_class (type));
4179 alignment = ssize_int (CLASSTYPE_ALIGN_UNIT (basetype)); 4210 alignment = size_int (CLASSTYPE_ALIGN_UNIT (type));
4180
4181 if (!integer_zerop (BINFO_OFFSET (binfo)))
4182 propagate_binfo_offsets
4183 (binfo, size_diffop_loc (input_location,
4184 size_zero_node, BINFO_OFFSET (binfo)));
4185 4211
4186 /* This is an empty base class. We first try to put it at offset 4212 /* This is an empty base class. We first try to put it at offset
4187 zero. */ 4213 zero. */
4188 if (layout_conflict_p (binfo, 4214 tree offset = size_zero_node;
4189 BINFO_OFFSET (binfo), 4215 if (layout_conflict_p (type,
4216 offset,
4190 offsets, 4217 offsets,
4191 /*vbases_p=*/0)) 4218 /*vbases_p=*/0))
4192 { 4219 {
4193 /* That didn't work. Now, we move forward from the next 4220 /* That didn't work. Now, we move forward from the next
4194 available spot in the class. */ 4221 available spot in the class. */
4195 atend = true; 4222 atend = true;
4196 propagate_binfo_offsets (binfo, fold_convert (ssizetype, eoc)); 4223 offset = eoc;
4197 while (1) 4224 while (1)
4198 { 4225 {
4199 if (!layout_conflict_p (binfo, 4226 if (!layout_conflict_p (type,
4200 BINFO_OFFSET (binfo), 4227 offset,
4201 offsets, 4228 offsets,
4202 /*vbases_p=*/0)) 4229 /*vbases_p=*/0))
4203 /* We finally found a spot where there's no overlap. */ 4230 /* We finally found a spot where there's no overlap. */
4204 break; 4231 break;
4205 4232
4206 /* There's overlap here, too. Bump along to the next spot. */ 4233 /* There's overlap here, too. Bump along to the next spot. */
4207 propagate_binfo_offsets (binfo, alignment); 4234 offset = size_binop (PLUS_EXPR, offset, alignment);
4208 } 4235 }
4209 } 4236 }
4210 4237
4211 if (CLASSTYPE_USER_ALIGN (basetype)) 4238 if (CLASSTYPE_USER_ALIGN (type))
4212 { 4239 {
4213 rli->record_align = MAX (rli->record_align, CLASSTYPE_ALIGN (basetype)); 4240 rli->record_align = MAX (rli->record_align, CLASSTYPE_ALIGN (type));
4214 if (warn_packed) 4241 if (warn_packed)
4215 rli->unpacked_align = MAX (rli->unpacked_align, CLASSTYPE_ALIGN (basetype)); 4242 rli->unpacked_align = MAX (rli->unpacked_align, CLASSTYPE_ALIGN (type));
4216 TYPE_USER_ALIGN (rli->t) = 1; 4243 TYPE_USER_ALIGN (rli->t) = 1;
4244 }
4245
4246 if (binfo)
4247 /* Adjust BINFO_OFFSET (binfo) to be exactly OFFSET. */
4248 propagate_binfo_offsets (binfo,
4249 size_diffop (offset, BINFO_OFFSET (binfo)));
4250 else
4251 {
4252 DECL_FIELD_OFFSET (decl) = offset;
4253 DECL_FIELD_BIT_OFFSET (decl) = bitsize_zero_node;
4254 SET_DECL_OFFSET_ALIGN (decl, BITS_PER_UNIT);
4217 } 4255 }
4218 4256
4219 return atend; 4257 return atend;
4220 } 4258 }
4221 4259
4230 tree decl = build_decl (input_location, 4268 tree decl = build_decl (input_location,
4231 FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype)); 4269 FIELD_DECL, NULL_TREE, CLASSTYPE_AS_BASE (basetype));
4232 DECL_ARTIFICIAL (decl) = 1; 4270 DECL_ARTIFICIAL (decl) = 1;
4233 DECL_IGNORED_P (decl) = 1; 4271 DECL_IGNORED_P (decl) = 1;
4234 DECL_FIELD_CONTEXT (decl) = t; 4272 DECL_FIELD_CONTEXT (decl) = t;
4235 DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype); 4273 if (is_empty_class (basetype))
4236 DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype); 4274 /* CLASSTYPE_SIZE is one byte, but the field needs to have size zero. */
4275 DECL_SIZE (decl) = DECL_SIZE_UNIT (decl) = size_zero_node;
4276 else
4277 {
4278 DECL_SIZE (decl) = CLASSTYPE_SIZE (basetype);
4279 DECL_SIZE_UNIT (decl) = CLASSTYPE_SIZE_UNIT (basetype);
4280 }
4237 SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype)); 4281 SET_DECL_ALIGN (decl, CLASSTYPE_ALIGN (basetype));
4238 DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype); 4282 DECL_USER_ALIGN (decl) = CLASSTYPE_USER_ALIGN (basetype);
4239 SET_DECL_MODE (decl, TYPE_MODE (basetype)); 4283 SET_DECL_MODE (decl, TYPE_MODE (basetype));
4240 DECL_FIELD_IS_BASE (decl) = 1; 4284 DECL_FIELD_IS_BASE (decl) = 1;
4241 4285
4285 objects of the same type at the same address. */ 4329 objects of the same type at the same address. */
4286 layout_nonempty_base_or_field (rli, decl, binfo, offsets); 4330 layout_nonempty_base_or_field (rli, decl, binfo, offsets);
4287 } 4331 }
4288 else 4332 else
4289 { 4333 {
4290 tree eoc; 4334 bool atend = layout_empty_base_or_field (rli, binfo, offsets);
4291 bool atend;
4292
4293 /* On some platforms (ARM), even empty classes will not be
4294 byte-aligned. */
4295 eoc = round_up_loc (input_location,
4296 rli_size_unit_so_far (rli),
4297 CLASSTYPE_ALIGN_UNIT (basetype));
4298 atend = layout_empty_base (rli, binfo, eoc, offsets);
4299 /* A nearly-empty class "has no proper base class that is empty, 4335 /* A nearly-empty class "has no proper base class that is empty,
4300 not morally virtual, and at an offset other than zero." */ 4336 not morally virtual, and at an offset other than zero." */
4301 if (!BINFO_VIRTUAL_P (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t)) 4337 if (!BINFO_VIRTUAL_P (binfo) && CLASSTYPE_NEARLY_EMPTY_P (t))
4302 { 4338 {
4303 if (atend) 4339 if (atend)
4331 here because that was already done when the virtual table 4367 here because that was already done when the virtual table
4332 pointer was created. */ 4368 pointer was created. */
4333 } 4369 }
4334 4370
4335 /* Record the offsets of BINFO and its base subobjects. */ 4371 /* Record the offsets of BINFO and its base subobjects. */
4336 record_subobject_offsets (binfo, 4372 record_subobject_offsets (binfo, offsets);
4337 BINFO_OFFSET (binfo),
4338 offsets,
4339 /*is_data_member=*/false);
4340 4373
4341 return next_field; 4374 return next_field;
4342 } 4375 }
4343 4376
4344 /* Layout all of the non-virtual base classes. Record empty 4377 /* Layout all of the non-virtual base classes. Record empty
4481 4514
4482 /* If there was an in-charge parameter, drop it from the function 4515 /* If there was an in-charge parameter, drop it from the function
4483 type. */ 4516 type. */
4484 if (DECL_HAS_IN_CHARGE_PARM_P (clone)) 4517 if (DECL_HAS_IN_CHARGE_PARM_P (clone))
4485 { 4518 {
4486 tree basetype; 4519 tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
4487 tree parmtypes; 4520 tree parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
4488 tree exceptions;
4489
4490 exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (clone));
4491 basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
4492 parmtypes = TYPE_ARG_TYPES (TREE_TYPE (clone));
4493 /* Skip the `this' parameter. */ 4521 /* Skip the `this' parameter. */
4494 parmtypes = TREE_CHAIN (parmtypes); 4522 parmtypes = TREE_CHAIN (parmtypes);
4495 /* Skip the in-charge parameter. */ 4523 /* Skip the in-charge parameter. */
4496 parmtypes = TREE_CHAIN (parmtypes); 4524 parmtypes = TREE_CHAIN (parmtypes);
4497 /* And the VTT parm, in a complete [cd]tor. */ 4525 /* And the VTT parm, in a complete [cd]tor. */
4506 } 4534 }
4507 TREE_TYPE (clone) 4535 TREE_TYPE (clone)
4508 = build_method_type_directly (basetype, 4536 = build_method_type_directly (basetype,
4509 TREE_TYPE (TREE_TYPE (clone)), 4537 TREE_TYPE (TREE_TYPE (clone)),
4510 parmtypes); 4538 parmtypes);
4511 if (exceptions)
4512 TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone),
4513 exceptions);
4514 TREE_TYPE (clone) 4539 TREE_TYPE (clone)
4515 = cp_build_type_attribute_variant (TREE_TYPE (clone), 4540 = cp_build_type_attribute_variant (TREE_TYPE (clone),
4516 TYPE_ATTRIBUTES (TREE_TYPE (fn))); 4541 TYPE_ATTRIBUTES (TREE_TYPE (fn)));
4542 TREE_TYPE (clone)
4543 = cxx_copy_lang_qualifiers (TREE_TYPE (clone), TREE_TYPE (fn));
4517 } 4544 }
4518 4545
4519 /* Copy the function parameters. */ 4546 /* Copy the function parameters. */
4520 DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone)); 4547 DECL_ARGUMENTS (clone) = copy_list (DECL_ARGUMENTS (clone));
4521 /* Remove the in-charge parameter. */ 4548 /* Remove the in-charge parameter. */
4699 4726
4700 if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms)) 4727 if (TREE_PURPOSE (decl_parms) && !TREE_PURPOSE (clone_parms))
4701 { 4728 {
4702 /* A default parameter has been added. Adjust the 4729 /* A default parameter has been added. Adjust the
4703 clone's parameters. */ 4730 clone's parameters. */
4704 tree exceptions = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (clone));
4705 tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (clone));
4706 tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
4707 tree type;
4708
4709 clone_parms = orig_decl_parms; 4731 clone_parms = orig_decl_parms;
4710 4732
4711 if (DECL_HAS_VTT_PARM_P (clone)) 4733 if (DECL_HAS_VTT_PARM_P (clone))
4712 { 4734 {
4713 clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms), 4735 clone_parms = tree_cons (TREE_PURPOSE (orig_clone_parms),
4714 TREE_VALUE (orig_clone_parms), 4736 TREE_VALUE (orig_clone_parms),
4715 clone_parms); 4737 clone_parms);
4716 TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms); 4738 TREE_TYPE (clone_parms) = TREE_TYPE (orig_clone_parms);
4717 } 4739 }
4718 type = build_method_type_directly (basetype, 4740
4719 TREE_TYPE (TREE_TYPE (clone)), 4741 tree basetype = TYPE_METHOD_BASETYPE (TREE_TYPE (clone));
4720 clone_parms); 4742 tree type
4721 if (exceptions) 4743 = build_method_type_directly (basetype,
4722 type = build_exception_variant (type, exceptions); 4744 TREE_TYPE (TREE_TYPE (clone)),
4723 if (attrs) 4745 clone_parms);
4746 if (tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (clone)))
4724 type = cp_build_type_attribute_variant (type, attrs); 4747 type = cp_build_type_attribute_variant (type, attrs);
4748 type = cxx_copy_lang_qualifiers (type, TREE_TYPE (clone));
4725 TREE_TYPE (clone) = type; 4749 TREE_TYPE (clone) = type;
4726 4750
4727 clone_parms = NULL_TREE; 4751 clone_parms = NULL_TREE;
4728 break; 4752 break;
4729 } 4753 }
4905 { 4929 {
4906 return (DECL_CONSTRUCTOR_P (fn) 4930 return (DECL_CONSTRUCTOR_P (fn)
4907 && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn))); 4931 && sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (fn)));
4908 } 4932 }
4909 4933
4910 /* Returns true iff class T has a user-defined constructor that can be called 4934 /* Returns true iff class T has a user-provided constructor that can be called
4911 with more than zero arguments. */ 4935 with more than zero arguments. */
4912 4936
4913 bool 4937 bool
4914 type_has_user_nondefault_constructor (tree t) 4938 type_has_user_nondefault_constructor (tree t)
4915 { 4939 {
4917 return false; 4941 return false;
4918 4942
4919 for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) 4943 for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
4920 { 4944 {
4921 tree fn = *iter; 4945 tree fn = *iter;
4922 if (!DECL_ARTIFICIAL (fn) 4946 if (user_provided_p (fn)
4923 && (TREE_CODE (fn) == TEMPLATE_DECL 4947 && (TREE_CODE (fn) == TEMPLATE_DECL
4924 || (skip_artificial_parms_for (fn, DECL_ARGUMENTS (fn)) 4948 || (skip_artificial_parms_for (fn, DECL_ARGUMENTS (fn))
4925 != NULL_TREE))) 4949 != NULL_TREE)))
4926 return true; 4950 return true;
4927 } 4951 }
5036 vbase_has_user_provided_move_assign (tree type) 5060 vbase_has_user_provided_move_assign (tree type)
5037 { 5061 {
5038 /* Does the type itself have a user-provided move assignment operator? */ 5062 /* Does the type itself have a user-provided move assignment operator? */
5039 if (!CLASSTYPE_LAZY_MOVE_ASSIGN (type)) 5063 if (!CLASSTYPE_LAZY_MOVE_ASSIGN (type))
5040 for (ovl_iterator iter (get_class_binding_direct 5064 for (ovl_iterator iter (get_class_binding_direct
5041 (type, cp_assignment_operator_id (NOP_EXPR))); 5065 (type, assign_op_identifier));
5042 iter; ++iter) 5066 iter; ++iter)
5043 if (!DECL_ARTIFICIAL (*iter) && move_fn_p (*iter)) 5067 if (user_provided_p (*iter) && move_fn_p (*iter))
5044 return true; 5068 return true;
5045 5069
5046 /* Do any of its bases? */ 5070 /* Do any of its bases? */
5047 tree binfo = TYPE_BINFO (type); 5071 tree binfo = TYPE_BINFO (type);
5048 tree base_binfo; 5072 tree base_binfo;
5184 if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter)) 5208 if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
5185 return true; 5209 return true;
5186 5210
5187 if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t)) 5211 if (!CLASSTYPE_LAZY_MOVE_ASSIGN (t))
5188 for (ovl_iterator iter (get_class_binding_direct 5212 for (ovl_iterator iter (get_class_binding_direct
5189 (t, cp_assignment_operator_id (NOP_EXPR))); 5213 (t, assign_op_identifier));
5190 iter; ++iter) 5214 iter; ++iter)
5191 if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter)) 5215 if ((!user_p || !DECL_ARTIFICIAL (*iter)) && move_fn_p (*iter))
5192 return true; 5216 return true;
5193 5217
5194 return false; 5218 return false;
5219 }
5220
5221 /* True iff T has a move constructor that is not deleted. */
5222
5223 bool
5224 classtype_has_non_deleted_move_ctor (tree t)
5225 {
5226 if (CLASSTYPE_LAZY_MOVE_CTOR (t))
5227 lazily_declare_fn (sfk_move_constructor, t);
5228 for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
5229 if (move_fn_p (*iter) && !DECL_DELETED_FN (*iter))
5230 return true;
5231 return false;
5232 }
5233
5234 /* If T, a class, has a user-provided copy constructor, copy assignment
5235 operator, or destructor, returns that function. Otherwise, null. */
5236
5237 tree
5238 classtype_has_user_copy_or_dtor (tree t)
5239 {
5240 if (!CLASSTYPE_LAZY_COPY_CTOR (t))
5241 for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
5242 {
5243 tree fn = *iter;
5244 if (user_provided_p (fn) && copy_fn_p (fn))
5245 return fn;
5246 }
5247
5248 if (!CLASSTYPE_LAZY_COPY_ASSIGN (t))
5249 for (ovl_iterator iter (get_class_binding_direct
5250 (t, assign_op_identifier));
5251 iter; ++iter)
5252 {
5253 tree fn = *iter;
5254 if (user_provided_p (fn) && copy_fn_p (fn))
5255 return fn;
5256 }
5257
5258 if (!CLASSTYPE_LAZY_DESTRUCTOR (t))
5259 {
5260 tree fn = CLASSTYPE_DESTRUCTOR (t);
5261 if (user_provided_p (fn))
5262 return fn;
5263 }
5264
5265 return NULL_TREE;
5195 } 5266 }
5196 5267
5197 /* Nonzero if we need to build up a constructor call when initializing an 5268 /* Nonzero if we need to build up a constructor call when initializing an
5198 object of this class, either because it has a user-declared constructor 5269 object of this class, either because it has a user-declared constructor
5199 or because it doesn't have a default constructor (so we need to give an 5270 or because it doesn't have a default constructor (so we need to give an
5222 for (ovl_iterator iter (get_class_binding (inner, complete_ctor_identifier)); 5293 for (ovl_iterator iter (get_class_binding (inner, complete_ctor_identifier));
5223 iter; ++iter) 5294 iter; ++iter)
5224 { 5295 {
5225 tree fn = *iter; 5296 tree fn = *iter;
5226 if (!DECL_ARTIFICIAL (fn) 5297 if (!DECL_ARTIFICIAL (fn)
5298 || TREE_DEPRECATED (fn)
5227 || DECL_DELETED_FN (fn)) 5299 || DECL_DELETED_FN (fn))
5228 return true; 5300 return true;
5229 } 5301 }
5230 return false; 5302 return false;
5231 } 5303 }
5249 for (ovl_iterator iter (get_class_binding (inner, complete_dtor_identifier)); 5321 for (ovl_iterator iter (get_class_binding (inner, complete_dtor_identifier));
5250 iter; ++iter) 5322 iter; ++iter)
5251 { 5323 {
5252 tree fn = *iter; 5324 tree fn = *iter;
5253 if (!DECL_ARTIFICIAL (fn) 5325 if (!DECL_ARTIFICIAL (fn)
5326 || TREE_DEPRECATED (fn)
5254 || DECL_DELETED_FN (fn)) 5327 || DECL_DELETED_FN (fn))
5255 return true; 5328 return true;
5256 } 5329 }
5257 return false; 5330 return false;
5258 } 5331 }
5302 /* If the usual deallocation function is a two-argument whose second 5375 /* If the usual deallocation function is a two-argument whose second
5303 argument is of type `size_t', then we have to pass the size of 5376 argument is of type `size_t', then we have to pass the size of
5304 the array to the deallocation function, so we will need to store 5377 the array to the deallocation function, so we will need to store
5305 a cookie. */ 5378 a cookie. */
5306 fns = lookup_fnfields (TYPE_BINFO (type), 5379 fns = lookup_fnfields (TYPE_BINFO (type),
5307 cp_operator_id (VEC_DELETE_EXPR), 5380 ovl_op_identifier (false, VEC_DELETE_EXPR),
5308 /*protect=*/0); 5381 /*protect=*/0);
5309 /* If there are no `operator []' members, or the lookup is 5382 /* If there are no `operator []' members, or the lookup is
5310 ambiguous, then we don't need a cookie. */ 5383 ambiguous, then we don't need a cookie. */
5311 if (!fns || fns == error_mark_node) 5384 if (!fns || fns == error_mark_node)
5312 return false; 5385 return false;
5366 && DECL_DECLARED_CONSTEXPR_P (fn) 5439 && DECL_DECLARED_CONSTEXPR_P (fn)
5367 && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn) 5440 && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)
5368 && !DECL_CONSTRUCTOR_P (fn)) 5441 && !DECL_CONSTRUCTOR_P (fn))
5369 { 5442 {
5370 DECL_DECLARED_CONSTEXPR_P (fn) = false; 5443 DECL_DECLARED_CONSTEXPR_P (fn) = false;
5371 if (!DECL_GENERATED_P (fn) 5444 if (!DECL_GENERATED_P (fn))
5372 && pedwarn (DECL_SOURCE_LOCATION (fn), OPT_Wpedantic, 5445 {
5373 "enclosing class of constexpr non-static member " 5446 auto_diagnostic_group d;
5374 "function %q+#D is not a literal type", fn)) 5447 if (pedwarn (DECL_SOURCE_LOCATION (fn), OPT_Wpedantic,
5375 explain_non_literal_class (t); 5448 "enclosing class of %<constexpr%> non-static "
5449 "member function %q+#D is not a literal type", fn))
5450 explain_non_literal_class (t);
5451 }
5376 } 5452 }
5377 } 5453 }
5378 5454
5379 /* T is a non-literal type used in a context which requires a constant 5455 /* T is a non-literal type used in a context which requires a constant
5380 expression. Explain why it isn't literal. */ 5456 expression. Explain why it isn't literal. */
5392 diagnosed = new hash_set<tree>; 5468 diagnosed = new hash_set<tree>;
5393 if (diagnosed->add (t)) 5469 if (diagnosed->add (t))
5394 /* Already explained. */ 5470 /* Already explained. */
5395 return; 5471 return;
5396 5472
5397 inform (0, "%q+T is not literal because:", t); 5473 auto_diagnostic_group d;
5474 inform (UNKNOWN_LOCATION, "%q+T is not literal because:", t);
5398 if (cxx_dialect < cxx17 && LAMBDA_TYPE_P (t)) 5475 if (cxx_dialect < cxx17 && LAMBDA_TYPE_P (t))
5399 inform (0, " %qT is a closure type, which is only literal in " 5476 inform (UNKNOWN_LOCATION,
5477 " %qT is a closure type, which is only literal in "
5400 "C++17 and later", t); 5478 "C++17 and later", t);
5401 else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)) 5479 else if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t))
5402 inform (0, " %q+T has a non-trivial destructor", t); 5480 inform (UNKNOWN_LOCATION, " %q+T has a non-trivial destructor", t);
5403 else if (CLASSTYPE_NON_AGGREGATE (t) 5481 else if (CLASSTYPE_NON_AGGREGATE (t)
5404 && !TYPE_HAS_TRIVIAL_DFLT (t) 5482 && !TYPE_HAS_TRIVIAL_DFLT (t)
5405 && !LAMBDA_TYPE_P (t) 5483 && !LAMBDA_TYPE_P (t)
5406 && !TYPE_HAS_CONSTEXPR_CTOR (t)) 5484 && !TYPE_HAS_CONSTEXPR_CTOR (t))
5407 { 5485 {
5408 inform (0, " %q+T is not an aggregate, does not have a trivial " 5486 inform (UNKNOWN_LOCATION,
5409 "default constructor, and has no constexpr constructor that " 5487 " %q+T is not an aggregate, does not have a trivial "
5488 "default constructor, and has no %<constexpr%> constructor that "
5410 "is not a copy or move constructor", t); 5489 "is not a copy or move constructor", t);
5411 if (type_has_non_user_provided_default_constructor (t)) 5490 if (type_has_non_user_provided_default_constructor (t))
5412 /* Note that we can't simply call locate_ctor because when the 5491 /* Note that we can't simply call locate_ctor because when the
5413 constructor is deleted it just returns NULL_TREE. */ 5492 constructor is deleted it just returns NULL_TREE. */
5414 for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter) 5493 for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
5435 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++) 5514 BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
5436 { 5515 {
5437 tree basetype = TREE_TYPE (base_binfo); 5516 tree basetype = TREE_TYPE (base_binfo);
5438 if (!CLASSTYPE_LITERAL_P (basetype)) 5517 if (!CLASSTYPE_LITERAL_P (basetype))
5439 { 5518 {
5440 inform (0, " base class %qT of %q+T is non-literal", 5519 inform (UNKNOWN_LOCATION,
5520 " base class %qT of %q+T is non-literal",
5441 basetype, t); 5521 basetype, t);
5442 explain_non_literal_class (basetype); 5522 explain_non_literal_class (basetype);
5443 return; 5523 return;
5444 } 5524 }
5445 } 5525 }
5538 constructors ... and no virtual functions. 5618 constructors ... and no virtual functions.
5539 5619
5540 Again, other conditions for being an aggregate are checked 5620 Again, other conditions for being an aggregate are checked
5541 elsewhere. */ 5621 elsewhere. */
5542 CLASSTYPE_NON_AGGREGATE (t) 5622 CLASSTYPE_NON_AGGREGATE (t)
5543 |= (type_has_user_provided_or_explicit_constructor (t) 5623 |= ((cxx_dialect < cxx2a
5624 ? type_has_user_provided_or_explicit_constructor (t)
5625 : TYPE_HAS_USER_CONSTRUCTOR (t))
5544 || TYPE_POLYMORPHIC_P (t)); 5626 || TYPE_POLYMORPHIC_P (t));
5545 /* This is the C++98/03 definition of POD; it changed in C++0x, but we 5627 /* This is the C++98/03 definition of POD; it changed in C++0x, but we
5546 retain the old definition internally for ABI reasons. */ 5628 retain the old definition internally for ABI reasons. */
5547 CLASSTYPE_NON_LAYOUT_POD_P (t) 5629 CLASSTYPE_NON_LAYOUT_POD_P (t)
5548 |= (CLASSTYPE_NON_AGGREGATE (t) 5630 |= (CLASSTYPE_NON_AGGREGATE (t)
5603 if (TREE_CODE (field) != FIELD_DECL 5685 if (TREE_CODE (field) != FIELD_DECL
5604 || DECL_INITIAL (field) != NULL_TREE) 5686 || DECL_INITIAL (field) != NULL_TREE)
5605 continue; 5687 continue;
5606 5688
5607 type = TREE_TYPE (field); 5689 type = TREE_TYPE (field);
5608 if (TREE_CODE (type) == REFERENCE_TYPE) 5690 if (TYPE_REF_P (type))
5609 warning_at (DECL_SOURCE_LOCATION (field), 5691 warning_at (DECL_SOURCE_LOCATION (field),
5610 OPT_Wuninitialized, "non-static reference %q#D " 5692 OPT_Wuninitialized, "non-static reference %q#D "
5611 "in class without a constructor", field); 5693 "in class without a constructor", field);
5612 else if (CP_TYPE_CONST_P (type) 5694 else if (CP_TYPE_CONST_P (type)
5613 && (!CLASS_TYPE_P (type) 5695 && (!CLASS_TYPE_P (type)
5638 : !no_const_asn_ref); 5720 : !no_const_asn_ref);
5639 bool fn_const_p = (copy == 2); 5721 bool fn_const_p = (copy == 2);
5640 5722
5641 if (fn_const_p && !imp_const_p) 5723 if (fn_const_p && !imp_const_p)
5642 /* If the function is defaulted outside the class, we just 5724 /* If the function is defaulted outside the class, we just
5643 give the synthesis error. */ 5725 give the synthesis error. Core Issue #1331 says this is
5644 error ("%q+D declared to take const reference, but implicit " 5726 no longer ill-formed, it is defined as deleted instead. */
5645 "declaration would take non-const", fn); 5727 DECL_DELETED_FN (fn) = true;
5646 } 5728 }
5647 defaulted_late_check (fn); 5729 defaulted_late_check (fn);
5648 } 5730 }
5649 5731
5650 if (LAMBDA_TYPE_P (t)) 5732 if (LAMBDA_TYPE_P (t))
5845 return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size); 5927 return size_binop (PLUS_EXPR, BINFO_OFFSET (binfo), size);
5846 } 5928 }
5847 5929
5848 /* Returns the offset of the byte just past the end of the base class 5930 /* Returns the offset of the byte just past the end of the base class
5849 with the highest offset in T. If INCLUDE_VIRTUALS_P is zero, then 5931 with the highest offset in T. If INCLUDE_VIRTUALS_P is zero, then
5850 only non-virtual bases are included. */ 5932 only non-virtual bases are included. If INCLUDE_FIELDS_P is true,
5933 then also consider non-static data members. */
5851 5934
5852 static tree 5935 static tree
5853 end_of_class (tree t, int include_virtuals_p) 5936 end_of_class (tree t, bool include_virtuals_p, bool include_fields_p = false)
5854 { 5937 {
5855 tree result = size_zero_node; 5938 tree result = size_zero_node;
5856 vec<tree, va_gc> *vbases; 5939 vec<tree, va_gc> *vbases;
5857 tree binfo; 5940 tree binfo;
5858 tree base_binfo; 5941 tree base_binfo;
5870 5953
5871 offset = end_of_base (base_binfo); 5954 offset = end_of_base (base_binfo);
5872 if (tree_int_cst_lt (result, offset)) 5955 if (tree_int_cst_lt (result, offset))
5873 result = offset; 5956 result = offset;
5874 } 5957 }
5958
5959 if (include_fields_p)
5960 for (tree field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
5961 if (TREE_CODE (field) == FIELD_DECL)
5962 {
5963 offset = size_binop (PLUS_EXPR, DECL_FIELD_OFFSET (field),
5964 DECL_SIZE_UNIT (field));
5965 if (tree_int_cst_lt (result, offset))
5966 result = offset;
5967 }
5875 5968
5876 if (include_virtuals_p) 5969 if (include_virtuals_p)
5877 for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0; 5970 for (vbases = CLASSTYPE_VBASECLASSES (t), i = 0;
5878 vec_safe_iterate (vbases, i, &base_binfo); i++) 5971 vec_safe_iterate (vbases, i, &base_binfo); i++)
5879 { 5972 {
6056 type = TREE_TYPE (field); 6149 type = TREE_TYPE (field);
6057 if (type == error_mark_node) 6150 if (type == error_mark_node)
6058 continue; 6151 continue;
6059 6152
6060 padding = NULL_TREE; 6153 padding = NULL_TREE;
6154
6155 bool might_overlap = field_poverlapping_p (field);
6156
6157 if (might_overlap && CLASS_TYPE_P (type)
6158 && CLASSTYPE_NON_LAYOUT_POD_P (type))
6159 {
6160 /* if D is a potentially-overlapping data member, update sizeof(C) to
6161 max (sizeof(C), offset(D)+max (nvsize(D), dsize(D))). */
6162 tree nvsize = CLASSTYPE_SIZE_UNIT (type);
6163 tree dsize = end_of_class (type, /*vbases*/true, /*fields*/true);
6164 if (tree_int_cst_le (dsize, nvsize))
6165 {
6166 DECL_SIZE_UNIT (field) = nvsize;
6167 DECL_SIZE (field) = CLASSTYPE_SIZE (type);
6168 }
6169 else
6170 {
6171 DECL_SIZE_UNIT (field) = dsize;
6172 DECL_SIZE (field) = bit_from_pos (dsize, bitsize_zero_node);
6173 }
6174 }
6061 6175
6062 /* If this field is a bit-field whose width is greater than its 6176 /* If this field is a bit-field whose width is greater than its
6063 type, then there are some special rules for allocating 6177 type, then there are some special rules for allocating
6064 it. */ 6178 it. */
6065 if (DECL_C_BIT_FIELD (field) 6179 if (DECL_C_BIT_FIELD (field)
6123 field is effectively invisible. */ 6237 field is effectively invisible. */
6124 DECL_SIZE (field) = TYPE_SIZE (type); 6238 DECL_SIZE (field) = TYPE_SIZE (type);
6125 /* We must also reset the DECL_MODE of the field. */ 6239 /* We must also reset the DECL_MODE of the field. */
6126 SET_DECL_MODE (field, TYPE_MODE (type)); 6240 SET_DECL_MODE (field, TYPE_MODE (type));
6127 } 6241 }
6242 else if (might_overlap && is_empty_class (type))
6243 layout_empty_base_or_field (rli, field, empty_base_offsets);
6128 else 6244 else
6129 layout_nonempty_base_or_field (rli, field, NULL_TREE, 6245 layout_nonempty_base_or_field (rli, field, NULL_TREE,
6130 empty_base_offsets); 6246 empty_base_offsets);
6131 6247
6132 /* Remember the location of any empty classes in FIELD. */ 6248 /* Remember the location of any empty classes in FIELD. */
6133 record_subobject_offsets (TREE_TYPE (field), 6249 record_subobject_offsets (field, empty_base_offsets);
6134 byte_position(field),
6135 empty_base_offsets,
6136 /*is_data_member=*/true);
6137 6250
6138 /* If a bit-field does not immediately follow another bit-field, 6251 /* If a bit-field does not immediately follow another bit-field,
6139 and yet it starts in the middle of a byte, we have failed to 6252 and yet it starts in the middle of a byte, we have failed to
6140 comply with the ABI. */ 6253 comply with the ABI. */
6141 if (warn_abi 6254 if (warn_abi
6193 DECL_BIT_FIELD (padding_field) = 1; 6306 DECL_BIT_FIELD (padding_field) = 1;
6194 DECL_SIZE (padding_field) = padding; 6307 DECL_SIZE (padding_field) = padding;
6195 DECL_CONTEXT (padding_field) = t; 6308 DECL_CONTEXT (padding_field) = t;
6196 DECL_ARTIFICIAL (padding_field) = 1; 6309 DECL_ARTIFICIAL (padding_field) = 1;
6197 DECL_IGNORED_P (padding_field) = 1; 6310 DECL_IGNORED_P (padding_field) = 1;
6311 DECL_PADDING_P (padding_field) = 1;
6198 layout_nonempty_base_or_field (rli, padding_field, 6312 layout_nonempty_base_or_field (rli, padding_field,
6199 NULL_TREE, 6313 NULL_TREE,
6200 empty_base_offsets); 6314 empty_base_offsets);
6201 } 6315 }
6202 6316
6243 size_binop (MULT_EXPR, 6357 size_binop (MULT_EXPR,
6244 fold_convert (bitsizetype, eoc), 6358 fold_convert (bitsizetype, eoc),
6245 bitsize_int (BITS_PER_UNIT))); 6359 bitsize_int (BITS_PER_UNIT)));
6246 SET_TYPE_ALIGN (base_t, rli->record_align); 6360 SET_TYPE_ALIGN (base_t, rli->record_align);
6247 TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t); 6361 TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t);
6362 TYPE_TYPELESS_STORAGE (base_t) = TYPE_TYPELESS_STORAGE (t);
6248 6363
6249 /* Copy the non-static data members of T. This will include its 6364 /* Copy the non-static data members of T. This will include its
6250 direct non-virtual bases & vtable. */ 6365 direct non-virtual bases & vtable. */
6251 next_field = &TYPE_FIELDS (base_t); 6366 next_field = &TYPE_FIELDS (base_t);
6252 for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field)) 6367 for (field = TYPE_FIELDS (t); field; field = DECL_CHAIN (field))
6462 /* Determine the type of the array element or object referenced 6577 /* Determine the type of the array element or object referenced
6463 by the member so that it can be checked for flexible array 6578 by the member so that it can be checked for flexible array
6464 members if it hasn't been yet. */ 6579 members if it hasn't been yet. */
6465 tree eltype = fldtype; 6580 tree eltype = fldtype;
6466 while (TREE_CODE (eltype) == ARRAY_TYPE 6581 while (TREE_CODE (eltype) == ARRAY_TYPE
6467 || TREE_CODE (eltype) == POINTER_TYPE 6582 || INDIRECT_TYPE_P (eltype))
6468 || TREE_CODE (eltype) == REFERENCE_TYPE)
6469 eltype = TREE_TYPE (eltype); 6583 eltype = TREE_TYPE (eltype);
6470 6584
6471 if (RECORD_OR_UNION_TYPE_P (eltype)) 6585 if (RECORD_OR_UNION_TYPE_P (eltype))
6472 { 6586 {
6473 if (fmem->array && !fmem->after[bool (pun)]) 6587 if (fmem->array && !fmem->after[bool (pun)])
6560 else 6674 else
6561 { 6675 {
6562 /* Flexible array members have no upper bound. */ 6676 /* Flexible array members have no upper bound. */
6563 if (fmem->array) 6677 if (fmem->array)
6564 { 6678 {
6565 /* Replace the zero-length array if it's been stored and
6566 reset the after pointer. */
6567 if (TYPE_DOMAIN (TREE_TYPE (fmem->array))) 6679 if (TYPE_DOMAIN (TREE_TYPE (fmem->array)))
6568 { 6680 {
6681 /* Replace the zero-length array if it's been stored and
6682 reset the after pointer. */
6569 fmem->after[bool (pun)] = NULL_TREE; 6683 fmem->after[bool (pun)] = NULL_TREE;
6570 fmem->array = fld; 6684 fmem->array = fld;
6571 fmem->enclosing = pstr; 6685 fmem->enclosing = pstr;
6572 } 6686 }
6687 else if (!fmem->after[bool (pun)])
6688 /* Make a record of another flexible array member. */
6689 fmem->after[bool (pun)] = fld;
6573 } 6690 }
6574 else 6691 else
6575 { 6692 {
6576 fmem->array = fld; 6693 fmem->array = fld;
6577 fmem->enclosing = pstr; 6694 fmem->enclosing = pstr;
6584 a flexible array member (or the zero-length array extension). */ 6701 a flexible array member (or the zero-length array extension). */
6585 6702
6586 static void 6703 static void
6587 diagnose_invalid_flexarray (const flexmems_t *fmem) 6704 diagnose_invalid_flexarray (const flexmems_t *fmem)
6588 { 6705 {
6589 if (fmem->array && fmem->enclosing 6706 if (fmem->array && fmem->enclosing)
6590 && pedwarn (location_of (fmem->enclosing), OPT_Wpedantic, 6707 {
6591 TYPE_DOMAIN (TREE_TYPE (fmem->array)) 6708 auto_diagnostic_group d;
6592 ? G_("invalid use of %q#T with a zero-size array " 6709 if (pedwarn (location_of (fmem->enclosing), OPT_Wpedantic,
6593 "in %q#D") 6710 TYPE_DOMAIN (TREE_TYPE (fmem->array))
6594 : G_("invalid use of %q#T with a flexible array member " 6711 ? G_("invalid use of %q#T with a zero-size array "
6595 "in %q#T"), 6712 "in %q#D")
6596 DECL_CONTEXT (fmem->array), 6713 : G_("invalid use of %q#T with a flexible array member "
6597 DECL_CONTEXT (fmem->enclosing))) 6714 "in %q#T"),
6598 inform (DECL_SOURCE_LOCATION (fmem->array), 6715 DECL_CONTEXT (fmem->array),
6599 "array member %q#D declared here", fmem->array); 6716 DECL_CONTEXT (fmem->enclosing)))
6717 inform (DECL_SOURCE_LOCATION (fmem->array),
6718 "array member %q#D declared here", fmem->array);
6719 }
6600 } 6720 }
6601 6721
6602 /* Issue diagnostics for invalid flexible array members or zero-length 6722 /* Issue diagnostics for invalid flexible array members or zero-length
6603 arrays that are not the last elements of the containing class or its 6723 arrays that are not the last elements of the containing class or its
6604 base classes or that are its sole members. */ 6724 base classes or that are its sole members. */
6629 6749
6630 if (msg) 6750 if (msg)
6631 { 6751 {
6632 location_t loc = DECL_SOURCE_LOCATION (fmem->array); 6752 location_t loc = DECL_SOURCE_LOCATION (fmem->array);
6633 6753
6754 auto_diagnostic_group d;
6634 if (pedwarn (loc, OPT_Wpedantic, msg, fmem->array, t)) 6755 if (pedwarn (loc, OPT_Wpedantic, msg, fmem->array, t))
6635 { 6756 {
6636 inform (location_of (t), "in the definition of %q#T", t); 6757 inform (location_of (t), "in the definition of %q#T", t);
6637 diagd = true; 6758 diagd = true;
6638 } 6759 }
6648 if (msg) 6769 if (msg)
6649 { 6770 {
6650 location_t loc = DECL_SOURCE_LOCATION (fmem->array); 6771 location_t loc = DECL_SOURCE_LOCATION (fmem->array);
6651 diagd = true; 6772 diagd = true;
6652 6773
6774 auto_diagnostic_group d;
6653 error_at (loc, msg, fmem->array, t); 6775 error_at (loc, msg, fmem->array, t);
6654 6776
6655 /* In the unlikely event that the member following the flexible 6777 /* In the unlikely event that the member following the flexible
6656 array member is declared in a different class, or the member 6778 array member is declared in a different class, or the member
6657 overlaps another member of a common union, point to it. 6779 overlaps another member of a common union, point to it.
7069 if (is_std_init_list (t)) 7191 if (is_std_init_list (t))
7070 { 7192 {
7071 /* People keep complaining that the compiler crashes on an invalid 7193 /* People keep complaining that the compiler crashes on an invalid
7072 definition of initializer_list, so I guess we should explicitly 7194 definition of initializer_list, so I guess we should explicitly
7073 reject it. What the compiler internals care about is that it's a 7195 reject it. What the compiler internals care about is that it's a
7074 template and has a pointer field followed by an integer field. */ 7196 template and has a pointer field followed by size_type field. */
7075 bool ok = false; 7197 bool ok = false;
7076 if (processing_template_decl) 7198 if (processing_template_decl)
7077 { 7199 {
7078 tree f = next_initializable_field (TYPE_FIELDS (t)); 7200 tree f = next_initializable_field (TYPE_FIELDS (t));
7079 if (f && TREE_CODE (TREE_TYPE (f)) == POINTER_TYPE) 7201 if (f && TYPE_PTR_P (TREE_TYPE (f)))
7080 { 7202 {
7081 f = next_initializable_field (DECL_CHAIN (f)); 7203 f = next_initializable_field (DECL_CHAIN (f));
7082 if (f && same_type_p (TREE_TYPE (f), size_type_node)) 7204 if (f && same_type_p (TREE_TYPE (f), size_type_node))
7083 ok = true; 7205 ok = true;
7084 } 7206 }
7085 } 7207 }
7086 if (!ok) 7208 if (!ok)
7087 fatal_error (input_location, 7209 fatal_error (input_location, "definition of %qD does not match "
7088 "definition of std::initializer_list does not match " 7210 "%<#include <initializer_list>%>", TYPE_NAME (t));
7089 "#include <initializer_list>");
7090 } 7211 }
7091 7212
7092 input_location = saved_loc; 7213 input_location = saved_loc;
7093 7214
7094 TYPE_BEING_DEFINED (t) = 0; 7215 TYPE_BEING_DEFINED (t) = 0;
7123 #define RECUR(T) fixed_type_or_null((T), nonnull, cdtorp) 7244 #define RECUR(T) fixed_type_or_null((T), nonnull, cdtorp)
7124 7245
7125 switch (TREE_CODE (instance)) 7246 switch (TREE_CODE (instance))
7126 { 7247 {
7127 case INDIRECT_REF: 7248 case INDIRECT_REF:
7128 if (POINTER_TYPE_P (TREE_TYPE (instance))) 7249 if (INDIRECT_TYPE_P (TREE_TYPE (instance)))
7129 return NULL_TREE; 7250 return NULL_TREE;
7130 else 7251 else
7131 return RECUR (TREE_OPERAND (instance, 0)); 7252 return RECUR (TREE_OPERAND (instance, 0));
7132 7253
7133 case CALL_EXPR: 7254 case CALL_EXPR:
7134 /* This is a call to a constructor, hence it's never zero. */ 7255 /* This is a call to a constructor, hence it's never zero. */
7135 if (TREE_HAS_CONSTRUCTOR (instance)) 7256 if (CALL_EXPR_FN (instance)
7257 && TREE_HAS_CONSTRUCTOR (instance))
7136 { 7258 {
7137 if (nonnull) 7259 if (nonnull)
7138 *nonnull = 1; 7260 *nonnull = 1;
7139 return TREE_TYPE (instance); 7261 return TREE_TYPE (instance);
7140 } 7262 }
7219 if (cdtorp) 7341 if (cdtorp)
7220 *cdtorp = 1; 7342 *cdtorp = 1;
7221 return TREE_TYPE (TREE_TYPE (instance)); 7343 return TREE_TYPE (TREE_TYPE (instance));
7222 } 7344 }
7223 } 7345 }
7224 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE) 7346 else if (TYPE_REF_P (TREE_TYPE (instance)))
7225 { 7347 {
7226 /* We only need one hash table because it is always left empty. */ 7348 /* We only need one hash table because it is always left empty. */
7227 if (!fixed_type_or_null_ref_ht) 7349 if (!fixed_type_or_null_ref_ht)
7228 fixed_type_or_null_ref_ht 7350 fixed_type_or_null_ref_ht
7229 = new hash_table<nofree_ptr_hash<tree_node> > (37); 7351 = new hash_table<nofree_ptr_hash<tree_node> > (37);
7292 } 7414 }
7293 7415
7294 fixed = fixed_type_or_null (instance, nonnull, &cdtorp); 7416 fixed = fixed_type_or_null (instance, nonnull, &cdtorp);
7295 if (fixed == NULL_TREE) 7417 if (fixed == NULL_TREE)
7296 return 0; 7418 return 0;
7297 if (POINTER_TYPE_P (t)) 7419 if (INDIRECT_TYPE_P (t))
7298 t = TREE_TYPE (t); 7420 t = TREE_TYPE (t);
7299 if (!same_type_ignoring_top_level_qualifiers_p (t, fixed)) 7421 if (!same_type_ignoring_top_level_qualifiers_p (t, fixed))
7300 return 0; 7422 return 0;
7301 return cdtorp ? -1 : 1; 7423 return cdtorp ? -1 : 1;
7302 } 7424 }
7441 { 7563 {
7442 if (current_class_depth) 7564 if (current_class_depth)
7443 --current_class_stack[current_class_depth - 1].hidden; 7565 --current_class_stack[current_class_depth - 1].hidden;
7444 } 7566 }
7445 7567
7446 /* Returns 1 if the class type currently being defined is either T or 7568 /* If the class type currently being defined is either T or
7447 a nested type of T. Returns the type from the current_class_stack, 7569 a nested type of T, returns the type from the current_class_stack,
7448 which might be equivalent to but not equal to T in case of 7570 which might be equivalent to but not equal to T in case of
7449 constrained partial specializations. */ 7571 constrained partial specializations. */
7450 7572
7451 tree 7573 tree
7452 currently_open_class (tree t) 7574 currently_open_class (tree t)
7778 /* Try to do argument deduction. */ 7900 /* Try to do argument deduction. */
7779 targs = make_tree_vec (DECL_NTPARMS (fn)); 7901 targs = make_tree_vec (DECL_NTPARMS (fn));
7780 instantiation = fn_type_unification (fn, explicit_targs, targs, args, 7902 instantiation = fn_type_unification (fn, explicit_targs, targs, args,
7781 nargs, ret, 7903 nargs, ret,
7782 DEDUCE_EXACT, LOOKUP_NORMAL, 7904 DEDUCE_EXACT, LOOKUP_NORMAL,
7783 false, false); 7905 NULL, false, false);
7784 if (instantiation == error_mark_node) 7906 if (instantiation == error_mark_node)
7785 /* Instantiation failed. */ 7907 /* Instantiation failed. */
7786 continue; 7908 continue;
7787 7909
7788 /* Constraints must be satisfied. This is done before 7910 /* Constraints must be satisfied. This is done before
7881 static int explained; 8003 static int explained;
7882 8004
7883 if (!(complain & tf_error)) 8005 if (!(complain & tf_error))
7884 return error_mark_node; 8006 return error_mark_node;
7885 8007
7886 permerror (input_location, "assuming pointer to member %qD", fn); 8008 auto_diagnostic_group d;
7887 if (!explained) 8009 if (permerror (input_location, "assuming pointer to member %qD", fn)
7888 { 8010 && !explained)
7889 inform (input_location, "(a pointer to member can only be formed with %<&%E%>)", fn); 8011 {
8012 inform (input_location, "(a pointer to member can only be "
8013 "formed with %<&%E%>)", fn);
7890 explained = 1; 8014 explained = 1;
7891 } 8015 }
7892 } 8016 }
7893 8017
7894 /* If a pointer to a function that is multi-versioned is requested, the 8018 /* If a pointer to a function that is multi-versioned is requested, the
7985 rhs, TREE_TYPE (rhs), fntype); 8109 rhs, TREE_TYPE (rhs), fntype);
7986 return error_mark_node; 8110 return error_mark_node;
7987 } 8111 }
7988 } 8112 }
7989 8113
7990 if (BASELINK_P (rhs))
7991 {
7992 access_path = BASELINK_ACCESS_BINFO (rhs);
7993 rhs = BASELINK_FUNCTIONS (rhs);
7994 }
7995
7996 /* If we are in a template, and have a NON_DEPENDENT_EXPR, we cannot
7997 deduce any type information. */
7998 if (TREE_CODE (rhs) == NON_DEPENDENT_EXPR)
7999 {
8000 if (complain & tf_error)
8001 error ("not enough type information");
8002 return error_mark_node;
8003 }
8004
8005 /* If we instantiate a template, and it is a A ?: C expression 8114 /* If we instantiate a template, and it is a A ?: C expression
8006 with omitted B, look through the SAVE_EXPR. */ 8115 with omitted B, look through the SAVE_EXPR. */
8007 if (TREE_CODE (rhs) == SAVE_EXPR) 8116 if (TREE_CODE (rhs) == SAVE_EXPR)
8008 rhs = TREE_OPERAND (rhs, 0); 8117 rhs = TREE_OPERAND (rhs, 0);
8118
8119 if (BASELINK_P (rhs))
8120 {
8121 access_path = BASELINK_ACCESS_BINFO (rhs);
8122 rhs = BASELINK_FUNCTIONS (rhs);
8123 }
8124
8125 /* If we are in a template, and have a NON_DEPENDENT_EXPR, we cannot
8126 deduce any type information. */
8127 if (TREE_CODE (rhs) == NON_DEPENDENT_EXPR)
8128 {
8129 if (complain & tf_error)
8130 error ("not enough type information");
8131 return error_mark_node;
8132 }
8009 8133
8010 /* There are only a few kinds of expressions that may have a type 8134 /* There are only a few kinds of expressions that may have a type
8011 dependent on overload resolution. */ 8135 dependent on overload resolution. */
8012 gcc_assert (TREE_CODE (rhs) == ADDR_EXPR 8136 gcc_assert (TREE_CODE (rhs) == ADDR_EXPR
8013 || TREE_CODE (rhs) == COMPONENT_REF 8137 || TREE_CODE (rhs) == COMPONENT_REF
8109 + IDENTIFIER_LENGTH (ctor_name) + 2); 8233 + IDENTIFIER_LENGTH (ctor_name) + 2);
8110 sprintf (buf, VFIELD_NAME_FORMAT, IDENTIFIER_POINTER (ctor_name)); 8234 sprintf (buf, VFIELD_NAME_FORMAT, IDENTIFIER_POINTER (ctor_name));
8111 return get_identifier (buf); 8235 return get_identifier (buf);
8112 } 8236 }
8113 8237
8114 void
8115 print_class_statistics (void)
8116 {
8117 if (! GATHER_STATISTICS)
8118 return;
8119
8120 fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
8121 fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
8122 if (n_vtables)
8123 {
8124 fprintf (stderr, "vtables = %d; vtable searches = %d\n",
8125 n_vtables, n_vtable_searches);
8126 fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
8127 n_vtable_entries, n_vtable_elems);
8128 }
8129 }
8130
8131 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works, 8238 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
8132 according to [class]: 8239 according to [class]:
8133 The class-name is also inserted 8240 The class-name is also inserted
8134 into the scope of the class itself. For purposes of access checking, 8241 into the scope of the class itself. For purposes of access checking,
8135 the inserted class name is treated as if it were a public member name. */ 8242 the inserted class name is treated as if it were a public member name. */
8193 return false; 8300 return false;
8194 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) 8301 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
8195 if (TREE_CODE (field) == FIELD_DECL 8302 if (TREE_CODE (field) == FIELD_DECL
8196 && !DECL_ARTIFICIAL (field) 8303 && !DECL_ARTIFICIAL (field)
8197 /* An unnamed bit-field is not a data member. */ 8304 /* An unnamed bit-field is not a data member. */
8198 && (DECL_NAME (field) || !DECL_C_BIT_FIELD (field)) 8305 && !DECL_UNNAMED_BIT_FIELD (field)
8199 && !is_really_empty_class (TREE_TYPE (field))) 8306 && !is_really_empty_class (TREE_TYPE (field)))
8200 return false; 8307 return false;
8201 return true; 8308 return true;
8202 } 8309 }
8203 else if (TREE_CODE (type) == ARRAY_TYPE) 8310 else if (TREE_CODE (type) == ARRAY_TYPE)
8263 /* [basic.scope.class] 8370 /* [basic.scope.class]
8264 8371
8265 A name N used in a class S shall refer to the same declaration 8372 A name N used in a class S shall refer to the same declaration
8266 in its context and when re-evaluated in the completed scope of 8373 in its context and when re-evaluated in the completed scope of
8267 S. */ 8374 S. */
8268 permerror (input_location, "declaration of %q#D", decl); 8375 if (permerror (location_of (decl),
8269 permerror (location_of ((tree) n->value), 8376 "declaration of %q#D changes meaning of %qD",
8270 "changes meaning of %qD from %q#D", 8377 decl, OVL_NAME (decl)))
8271 OVL_NAME (decl), (tree) n->value); 8378 inform (location_of ((tree) n->value),
8379 "%qD declared here as %q#D",
8380 OVL_NAME (decl), (tree) n->value);
8272 } 8381 }
8273 } 8382 }
8274 8383
8275 /* Returns the VAR_DECL for the complete vtable associated with BINFO. 8384 /* Returns the VAR_DECL for the complete vtable associated with BINFO.
8276 Secondary vtables are merged with primary vtables; this function 8385 Secondary vtables are merged with primary vtables; this function
9229 { 9338 {
9230 tree delta; 9339 tree delta;
9231 tree vcall_index; 9340 tree vcall_index;
9232 tree fn, fn_original; 9341 tree fn, fn_original;
9233 tree init = NULL_TREE; 9342 tree init = NULL_TREE;
9343 tree idx = size_int (jx++);
9234 9344
9235 fn = BV_FN (v); 9345 fn = BV_FN (v);
9236 fn_original = fn; 9346 fn_original = fn;
9237 if (DECL_THUNK_P (fn)) 9347 if (DECL_THUNK_P (fn))
9238 { 9348 {
9332 if (TARGET_VTABLE_USES_DESCRIPTORS) 9442 if (TARGET_VTABLE_USES_DESCRIPTORS)
9333 { 9443 {
9334 int i; 9444 int i;
9335 if (init == size_zero_node) 9445 if (init == size_zero_node)
9336 for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i) 9446 for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
9337 CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init); 9447 CONSTRUCTOR_APPEND_ELT (*inits, idx, init);
9338 else 9448 else
9339 for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i) 9449 for (i = 0; i < TARGET_VTABLE_USES_DESCRIPTORS; ++i)
9340 { 9450 {
9341 tree fdesc = build2 (FDESC_EXPR, vfunc_ptr_type_node, 9451 tree fdesc = build2 (FDESC_EXPR, vfunc_ptr_type_node,
9342 fn, build_int_cst (NULL_TREE, i)); 9452 fn, build_int_cst (NULL_TREE, i));
9343 TREE_CONSTANT (fdesc) = 1; 9453 TREE_CONSTANT (fdesc) = 1;
9344 9454
9345 CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, fdesc); 9455 CONSTRUCTOR_APPEND_ELT (*inits, idx, fdesc);
9346 } 9456 }
9347 } 9457 }
9348 else 9458 else
9349 CONSTRUCTOR_APPEND_ELT (*inits, NULL_TREE, init); 9459 CONSTRUCTOR_APPEND_ELT (*inits, idx, init);
9350 } 9460 }
9351 } 9461 }
9352 9462
9353 /* Adds to vid->inits the initializers for the vbase and vcall 9463 /* Adds to vid->inits the initializers for the vbase and vcall
9354 offsets in BINFO, which is in the hierarchy dominated by T. */ 9464 offsets in BINFO, which is in the hierarchy dominated by T. */