comparison gcc/cp/method.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 /* Handle the hair of processing (but not expanding) inline functions. 1 /* Handle the hair of processing (but not expanding) inline functions.
2 Also manage function and variable name overloading. 2 Also manage function and variable name overloading.
3 Copyright (C) 1987-2017 Free Software Foundation, Inc. 3 Copyright (C) 1987-2018 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com) 4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify 8 GCC is free software; you can redistribute it and/or modify
29 #include "stringpool.h" 29 #include "stringpool.h"
30 #include "cgraph.h" 30 #include "cgraph.h"
31 #include "varasm.h" 31 #include "varasm.h"
32 #include "toplev.h" 32 #include "toplev.h"
33 #include "common/common-target.h" 33 #include "common/common-target.h"
34
35 /* Various flags to control the mangling process. */
36
37 enum mangling_flags
38 {
39 /* No flags. */
40 mf_none = 0,
41 /* The thing we are presently mangling is part of a template type,
42 rather than a fully instantiated type. Therefore, we may see
43 complex expressions where we would normally expect to see a
44 simple integer constant. */
45 mf_maybe_uninstantiated = 1,
46 /* When mangling a numeric value, use the form `_XX_' (instead of
47 just `XX') if the value has more than one digit. */
48 mf_use_underscores_around_value = 2
49 };
50 34
51 static void do_build_copy_assign (tree); 35 static void do_build_copy_assign (tree);
52 static void do_build_copy_constructor (tree); 36 static void do_build_copy_constructor (tree);
53 static tree make_alias_for_thunk (tree); 37 static tree make_alias_for_thunk (tree);
54 38
204 { 188 {
205 tree alias = build_decl (DECL_SOURCE_LOCATION (target), 189 tree alias = build_decl (DECL_SOURCE_LOCATION (target),
206 TREE_CODE (target), newid, TREE_TYPE (target)); 190 TREE_CODE (target), newid, TREE_TYPE (target));
207 DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target); 191 DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
208 cxx_dup_lang_specific_decl (alias); 192 cxx_dup_lang_specific_decl (alias);
209 DECL_CONTEXT (alias) = NULL; 193 DECL_CONTEXT (alias) = DECL_CONTEXT (target);
210 TREE_READONLY (alias) = TREE_READONLY (target); 194 TREE_READONLY (alias) = TREE_READONLY (target);
211 TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target); 195 TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
212 TREE_PUBLIC (alias) = 0; 196 TREE_PUBLIC (alias) = 0;
213 DECL_INTERFACE_KNOWN (alias) = 1; 197 DECL_INTERFACE_KNOWN (alias) = 1;
214 if (DECL_LANG_SPECIFIC (alias)) 198 if (DECL_LANG_SPECIFIC (alias))
389 TREE_ASM_WRITTEN (thunk_fndecl) = 1; 373 TREE_ASM_WRITTEN (thunk_fndecl) = 1;
390 funcn = cgraph_node::get (function); 374 funcn = cgraph_node::get (function);
391 gcc_checking_assert (funcn); 375 gcc_checking_assert (funcn);
392 thunk_node = funcn->create_thunk (thunk_fndecl, function, 376 thunk_node = funcn->create_thunk (thunk_fndecl, function,
393 this_adjusting, fixed_offset, virtual_value, 377 this_adjusting, fixed_offset, virtual_value,
394 virtual_offset, alias); 378 0, virtual_offset, alias);
395 if (DECL_ONE_ONLY (function)) 379 if (DECL_ONE_ONLY (function))
396 thunk_node->add_to_same_comdat_group (funcn); 380 thunk_node->add_to_same_comdat_group (funcn);
397 381
398 pop_from_top_level (); 382 pop_from_top_level ();
399 } 383 }
482 { 466 {
483 tree exp = convert_from_reference (parm); 467 tree exp = convert_from_reference (parm);
484 tree type = TREE_TYPE (parm); 468 tree type = TREE_TYPE (parm);
485 if (DECL_PACK_P (parm)) 469 if (DECL_PACK_P (parm))
486 type = PACK_EXPANSION_PATTERN (type); 470 type = PACK_EXPANSION_PATTERN (type);
487 if (TREE_CODE (type) != REFERENCE_TYPE) 471 if (!TYPE_REF_P (type))
488 type = cp_build_reference_type (type, /*rval=*/true); 472 type = cp_build_reference_type (type, /*rval=*/true);
489 warning_sentinel w (warn_useless_cast); 473 warning_sentinel w (warn_useless_cast);
490 exp = build_static_cast (type, exp, tf_warning_or_error); 474 exp = build_static_cast (type, exp, tf_warning_or_error);
491 if (DECL_PACK_P (parm)) 475 if (DECL_PACK_P (parm))
492 exp = make_pack_expansion (exp); 476 exp = make_pack_expansion (exp);
745 /* Compute the type of "init->field". If the copy-constructor 729 /* Compute the type of "init->field". If the copy-constructor
746 parameter is, for example, "const S&", and the type of 730 parameter is, for example, "const S&", and the type of
747 the field is "T", then the type will usually be "const 731 the field is "T", then the type will usually be "const
748 T". (There are no cv-qualified variants of reference 732 T". (There are no cv-qualified variants of reference
749 types.) */ 733 types.) */
750 if (TREE_CODE (expr_type) != REFERENCE_TYPE) 734 if (!TYPE_REF_P (expr_type))
751 { 735 {
752 int quals = cvquals; 736 int quals = cvquals;
753 737
754 if (DECL_MUTABLE_P (field)) 738 if (DECL_MUTABLE_P (field))
755 quals &= ~TYPE_QUAL_CONST; 739 quals &= ~TYPE_QUAL_CONST;
756 quals |= cp_type_quals (expr_type); 740 quals |= cp_type_quals (expr_type);
757 expr_type = cp_build_qualified_type (expr_type, quals); 741 expr_type = cp_build_qualified_type (expr_type, quals);
758 } 742 }
759 743
760 init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE); 744 init = build3 (COMPONENT_REF, expr_type, parm, field, NULL_TREE);
761 if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE 745 if (move_p && !TYPE_REF_P (expr_type)
762 /* 'move' breaks bit-fields, and has no effect for scalars. */ 746 /* 'move' breaks bit-fields, and has no effect for scalars. */
763 && !scalarish_type_p (expr_type)) 747 && !scalarish_type_p (expr_type))
764 init = move (init); 748 init = move (init);
765 init = build_tree_list (NULL_TREE, init); 749 init = build_tree_list (NULL_TREE, init);
766 750
813 converted_parm = move (converted_parm); 797 converted_parm = move (converted_parm);
814 /* Call the base class assignment operator. */ 798 /* Call the base class assignment operator. */
815 parmvec = make_tree_vector_single (converted_parm); 799 parmvec = make_tree_vector_single (converted_parm);
816 finish_expr_stmt 800 finish_expr_stmt
817 (build_special_member_call (current_class_ref, 801 (build_special_member_call (current_class_ref,
818 cp_assignment_operator_id (NOP_EXPR), 802 assign_op_identifier,
819 &parmvec, 803 &parmvec,
820 base_binfo, 804 base_binfo,
821 flags, 805 flags,
822 tf_warning_or_error)); 806 tf_warning_or_error));
823 release_tree_vector (parmvec); 807 release_tree_vector (parmvec);
843 { 827 {
844 error ("non-static const member %q#D, can%'t use default " 828 error ("non-static const member %q#D, can%'t use default "
845 "assignment operator", field); 829 "assignment operator", field);
846 continue; 830 continue;
847 } 831 }
848 else if (TREE_CODE (expr_type) == REFERENCE_TYPE) 832 else if (TYPE_REF_P (expr_type))
849 { 833 {
850 error ("non-static reference member %q#D, can%'t use " 834 error ("non-static reference member %q#D, can%'t use "
851 "default assignment operator", field); 835 "default assignment operator", field);
852 continue; 836 continue;
853 } 837 }
872 if (DECL_MUTABLE_P (field)) 856 if (DECL_MUTABLE_P (field))
873 quals &= ~TYPE_QUAL_CONST; 857 quals &= ~TYPE_QUAL_CONST;
874 expr_type = cp_build_qualified_type (expr_type, quals); 858 expr_type = cp_build_qualified_type (expr_type, quals);
875 859
876 init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE); 860 init = build3 (COMPONENT_REF, expr_type, init, field, NULL_TREE);
877 if (move_p && TREE_CODE (expr_type) != REFERENCE_TYPE 861 if (move_p && !TYPE_REF_P (expr_type)
878 /* 'move' breaks bit-fields, and has no effect for scalars. */ 862 /* 'move' breaks bit-fields, and has no effect for scalars. */
879 && !scalarish_type_p (expr_type)) 863 && !scalarish_type_p (expr_type))
880 init = move (init); 864 init = move (init);
881 865
882 if (DECL_NAME (field)) 866 if (DECL_NAME (field))
927 input_location = DECL_SOURCE_LOCATION (fndecl); 911 input_location = DECL_SOURCE_LOCATION (fndecl);
928 912
929 start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED); 913 start_preparsed_function (fndecl, NULL_TREE, SF_DEFAULT | SF_PRE_PARSED);
930 stmt = begin_function_body (); 914 stmt = begin_function_body ();
931 915
932 if (DECL_OVERLOADED_OPERATOR_P (fndecl) == NOP_EXPR) 916 if (DECL_ASSIGNMENT_OPERATOR_P (fndecl)
917 && DECL_OVERLOADED_OPERATOR_IS (fndecl, NOP_EXPR))
933 { 918 {
934 do_build_copy_assign (fndecl); 919 do_build_copy_assign (fndecl);
935 need_body = false; 920 need_body = false;
936 } 921 }
937 else if (DECL_CONSTRUCTOR_P (fndecl)) 922 else if (DECL_CONSTRUCTOR_P (fndecl))
963 pop_function_context (); 948 pop_function_context ();
964 949
965 pop_deferring_access_checks (); 950 pop_deferring_access_checks ();
966 951
967 if (error_count != errorcount || warning_count != warningcount + werrorcount) 952 if (error_count != errorcount || warning_count != warningcount + werrorcount)
968 inform (input_location, "synthesized method %qD first required here ", 953 inform (input_location, "synthesized method %qD first required here",
969 fndecl); 954 fndecl);
970 } 955 }
971 956
972 /* Build a reference to type TYPE with cv-quals QUALS, which is an 957 /* Build a reference to type TYPE with cv-quals QUALS, which is an
973 rvalue if RVALUE is true. */ 958 rvalue if RVALUE is true. */
983 REFTYPE. */ 968 REFTYPE. */
984 969
985 static tree 970 static tree
986 build_stub_object (tree reftype) 971 build_stub_object (tree reftype)
987 { 972 {
988 if (TREE_CODE (reftype) != REFERENCE_TYPE) 973 if (!TYPE_REF_P (reftype))
989 reftype = cp_build_reference_type (reftype, /*rval*/true); 974 reftype = cp_build_reference_type (reftype, /*rval*/true);
990 tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node); 975 tree stub = build1 (CONVERT_EXPR, reftype, integer_one_node);
991 return convert_from_reference (stub); 976 return convert_from_reference (stub);
992 } 977 }
993 978
1106 get_copy_assign (tree type) 1091 get_copy_assign (tree type)
1107 { 1092 {
1108 int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type) 1093 int quals = (TYPE_HAS_CONST_COPY_ASSIGN (type)
1109 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED); 1094 ? TYPE_QUAL_CONST : TYPE_UNQUALIFIED);
1110 tree argtype = build_stub_type (type, quals, false); 1095 tree argtype = build_stub_type (type, quals, false);
1111 tree fn = locate_fn_flags (type, cp_assignment_operator_id (NOP_EXPR), argtype, 1096 tree fn = locate_fn_flags (type, assign_op_identifier, argtype,
1112 LOOKUP_NORMAL, tf_warning_or_error); 1097 LOOKUP_NORMAL, tf_warning_or_error);
1113 if (fn == error_mark_node) 1098 if (fn == error_mark_node)
1114 return NULL_TREE; 1099 return NULL_TREE;
1115 return fn; 1100 return fn;
1116 } 1101 }
1157 1142
1158 static tree 1143 static tree
1159 constructible_expr (tree to, tree from) 1144 constructible_expr (tree to, tree from)
1160 { 1145 {
1161 tree expr; 1146 tree expr;
1147 cp_unevaluated cp_uneval_guard;
1162 if (CLASS_TYPE_P (to)) 1148 if (CLASS_TYPE_P (to))
1163 { 1149 {
1164 tree ctype = to; 1150 tree ctype = to;
1165 vec<tree, va_gc> *args = NULL; 1151 vec<tree, va_gc> *args = NULL;
1166 cp_unevaluated cp_uneval_guard; 1152 if (!TYPE_REF_P (to))
1167 if (TREE_CODE (to) != REFERENCE_TYPE)
1168 to = cp_build_reference_type (to, /*rval*/false); 1153 to = cp_build_reference_type (to, /*rval*/false);
1169 tree ob = build_stub_object (to); 1154 tree ob = build_stub_object (to);
1170 for (; from; from = TREE_CHAIN (from)) 1155 for (; from; from = TREE_CHAIN (from))
1171 vec_safe_push (args, build_stub_object (TREE_VALUE (from))); 1156 vec_safe_push (args, build_stub_object (TREE_VALUE (from)));
1172 expr = build_special_member_call (ob, complete_ctor_identifier, &args, 1157 expr = build_special_member_call (ob, complete_ctor_identifier, &args,
1229 is_trivially_xible (enum tree_code code, tree to, tree from) 1214 is_trivially_xible (enum tree_code code, tree to, tree from)
1230 { 1215 {
1231 tree expr; 1216 tree expr;
1232 expr = is_xible_helper (code, to, from, /*trivial*/true); 1217 expr = is_xible_helper (code, to, from, /*trivial*/true);
1233 1218
1234 if (expr == error_mark_node) 1219 if (expr == NULL_TREE || expr == error_mark_node)
1235 return false; 1220 return false;
1236 tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL); 1221 tree nt = cp_walk_tree_without_duplicates (&expr, check_nontriv, NULL);
1237 return !nt; 1222 return !nt;
1238 } 1223 }
1239 1224
1290 { 1275 {
1291 *constexpr_p = false; 1276 *constexpr_p = false;
1292 if (diag) 1277 if (diag)
1293 { 1278 {
1294 inform (DECL_SOURCE_LOCATION (fn), 1279 inform (DECL_SOURCE_LOCATION (fn),
1295 "defaulted constructor calls non-constexpr %qD", fn); 1280 "defaulted constructor calls non-%<constexpr%> %qD", fn);
1296 explain_invalid_constexpr_fn (fn); 1281 explain_invalid_constexpr_fn (fn);
1297 } 1282 }
1298 } 1283 }
1299 } 1284 }
1300 1285
1318 1303
1319 if (TREE_CODE (field) != FIELD_DECL 1304 if (TREE_CODE (field) != FIELD_DECL
1320 || DECL_ARTIFICIAL (field)) 1305 || DECL_ARTIFICIAL (field))
1321 continue; 1306 continue;
1322 1307
1308 /* Variant members only affect deletedness. In particular, they don't
1309 affect the exception-specification of a user-provided destructor,
1310 which we're figuring out via get_defaulted_eh_spec. So if we aren't
1311 asking if this is deleted, don't even look up the function; we don't
1312 want an error about a deleted function we aren't actually calling. */
1313 if (sfk == sfk_destructor && deleted_p == NULL
1314 && TREE_CODE (DECL_CONTEXT (field)) == UNION_TYPE)
1315 break;
1316
1323 mem_type = strip_array_types (TREE_TYPE (field)); 1317 mem_type = strip_array_types (TREE_TYPE (field));
1324 if (assign_p) 1318 if (assign_p)
1325 { 1319 {
1326 bool bad = true; 1320 bool bad = true;
1327 if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type)) 1321 if (CP_TYPE_CONST_P (mem_type) && !CLASS_TYPE_P (mem_type))
1328 { 1322 {
1329 if (diag) 1323 if (diag)
1330 error ("non-static const member %q#D, can%'t use default " 1324 error ("non-static const member %q#D, can%'t use default "
1331 "assignment operator", field); 1325 "assignment operator", field);
1332 } 1326 }
1333 else if (TREE_CODE (mem_type) == REFERENCE_TYPE) 1327 else if (TYPE_REF_P (mem_type))
1334 { 1328 {
1335 if (diag) 1329 if (diag)
1336 error ("non-static reference member %q#D, can%'t use " 1330 error ("non-static reference member %q#D, can%'t use "
1337 "default assignment operator", field); 1331 "default assignment operator", field);
1338 } 1332 }
1376 inform (DECL_SOURCE_LOCATION (field), 1370 inform (DECL_SOURCE_LOCATION (field),
1377 "%q#D should be initialized", field); 1371 "%q#D should be initialized", field);
1378 } 1372 }
1379 bad = true; 1373 bad = true;
1380 } 1374 }
1381 else if (TREE_CODE (mem_type) == REFERENCE_TYPE) 1375 else if (TYPE_REF_P (mem_type))
1382 { 1376 {
1383 if (diag) 1377 if (diag)
1384 { 1378 {
1385 error ("uninitialized reference member in %q#T", 1379 error ("uninitialized reference member in %q#T",
1386 current_class_type); 1380 current_class_type);
1407 } 1401 }
1408 } 1402 }
1409 else if (sfk == sfk_copy_constructor) 1403 else if (sfk == sfk_copy_constructor)
1410 { 1404 {
1411 /* 12.8p11b5 */ 1405 /* 12.8p11b5 */
1412 if (TREE_CODE (mem_type) == REFERENCE_TYPE 1406 if (TYPE_REF_P (mem_type)
1413 && TYPE_REF_IS_RVALUE (mem_type)) 1407 && TYPE_REF_IS_RVALUE (mem_type))
1414 { 1408 {
1415 if (diag) 1409 if (diag)
1416 error ("copying non-static data member %q#D of rvalue " 1410 error ("copying non-static data member %q#D of rvalue "
1417 "reference type", field); 1411 "reference type", field);
1543 1537
1544 if (deleted_p) 1538 if (deleted_p)
1545 { 1539 {
1546 /* "The closure type associated with a lambda-expression has a deleted 1540 /* "The closure type associated with a lambda-expression has a deleted
1547 default constructor and a deleted copy assignment operator." 1541 default constructor and a deleted copy assignment operator."
1548 This is diagnosed in maybe_explain_implicit_delete. */ 1542 This is diagnosed in maybe_explain_implicit_delete.
1543 In C++2a, only lambda-expressions with lambda-captures have those
1544 deleted. */
1549 if (LAMBDA_TYPE_P (ctype) 1545 if (LAMBDA_TYPE_P (ctype)
1550 && (sfk == sfk_constructor 1546 && (sfk == sfk_constructor || sfk == sfk_copy_assignment)
1551 || sfk == sfk_copy_assignment)) 1547 && (cxx_dialect < cxx2a
1548 || LAMBDA_EXPR_CAPTURE_LIST (CLASSTYPE_LAMBDA_EXPR (ctype))
1549 || LAMBDA_EXPR_DEFAULT_CAPTURE_MODE
1550 (CLASSTYPE_LAMBDA_EXPR (ctype)) != CPLD_NONE))
1552 { 1551 {
1553 *deleted_p = true; 1552 *deleted_p = true;
1554 return; 1553 return;
1555 } 1554 }
1556 1555
1563 switch (sfk) 1562 switch (sfk)
1564 { 1563 {
1565 case sfk_move_assignment: 1564 case sfk_move_assignment:
1566 case sfk_copy_assignment: 1565 case sfk_copy_assignment:
1567 assign_p = true; 1566 assign_p = true;
1568 fnname = cp_assignment_operator_id (NOP_EXPR); 1567 fnname = assign_op_identifier;
1569 break; 1568 break;
1570 1569
1571 case sfk_destructor: 1570 case sfk_destructor:
1572 check_vdtor = true; 1571 check_vdtor = true;
1573 /* The synthesized method will call base dtors, but check complete 1572 /* The synthesized method will call base dtors, but check complete
1700 1699
1701 if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo))) 1700 if (check_vdtor && type_has_virtual_destructor (BINFO_TYPE (base_binfo)))
1702 { 1701 {
1703 /* Unlike for base ctor/op=/dtor, for operator delete it's fine 1702 /* Unlike for base ctor/op=/dtor, for operator delete it's fine
1704 to have a null fn (no class-specific op delete). */ 1703 to have a null fn (no class-specific op delete). */
1705 fn = locate_fn_flags (ctype, cp_operator_id (DELETE_EXPR), 1704 fn = locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
1706 ptr_type_node, flags, tf_none); 1705 ptr_type_node, flags, tf_none);
1707 if (fn && fn == error_mark_node) 1706 if (fn && fn == error_mark_node)
1708 { 1707 {
1709 if (complain & tf_error) 1708 if (complain & tf_error)
1710 locate_fn_flags (ctype, cp_operator_id (DELETE_EXPR), 1709 locate_fn_flags (ctype, ovl_op_identifier (false, DELETE_EXPR),
1711 ptr_type_node, flags, complain); 1710 ptr_type_node, flags, complain);
1712 if (deleted_p) 1711 if (deleted_p)
1713 *deleted_p = true; 1712 *deleted_p = true;
1714 } 1713 }
1715 check_vdtor = false; 1714 check_vdtor = false;
1863 { 1862 {
1864 inform (DECL_SOURCE_LOCATION (decl), 1863 inform (DECL_SOURCE_LOCATION (decl),
1865 "%q#D is implicitly deleted because the default " 1864 "%q#D is implicitly deleted because the default "
1866 "definition would be ill-formed:", decl); 1865 "definition would be ill-formed:", decl);
1867 synthesized_method_walk (ctype, sfk, const_p, 1866 synthesized_method_walk (ctype, sfk, const_p,
1868 NULL, NULL, NULL, NULL, true, 1867 NULL, NULL, &deleted_p, NULL, true,
1869 &inh, parms); 1868 &inh, parms);
1870 } 1869 }
1871 else if (!comp_except_specs 1870 else if (!comp_except_specs
1872 (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)), 1871 (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (decl)),
1873 raises, ce_normal)) 1872 raises, ce_normal))
2005 { 2004 {
2006 if (kind == sfk_copy_assignment 2005 if (kind == sfk_copy_assignment
2007 || kind == sfk_move_assignment) 2006 || kind == sfk_move_assignment)
2008 { 2007 {
2009 return_type = build_reference_type (type); 2008 return_type = build_reference_type (type);
2010 name = cp_assignment_operator_id (NOP_EXPR); 2009 name = assign_op_identifier;
2011 } 2010 }
2012 else 2011 else
2013 name = ctor_identifier; 2012 name = ctor_identifier;
2014 2013
2015 if (kind == sfk_inheriting_constructor) 2014 if (kind == sfk_inheriting_constructor)
2075 if (kind != sfk_inheriting_constructor) 2074 if (kind != sfk_inheriting_constructor)
2076 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type)); 2075 DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
2077 2076
2078 if (!IDENTIFIER_CDTOR_P (name)) 2077 if (!IDENTIFIER_CDTOR_P (name))
2079 /* Assignment operator. */ 2078 /* Assignment operator. */
2080 SET_OVERLOADED_OPERATOR_CODE (fn, NOP_EXPR); 2079 DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = OVL_OP_NOP_EXPR;
2081 else if (IDENTIFIER_CTOR_P (name)) 2080 else if (IDENTIFIER_CTOR_P (name))
2082 DECL_CXX_CONSTRUCTOR_P (fn) = true; 2081 DECL_CXX_CONSTRUCTOR_P (fn) = true;
2083 else 2082 else
2084 DECL_CXX_DESTRUCTOR_P (fn) = true; 2083 DECL_CXX_DESTRUCTOR_P (fn) = true;
2085 2084
2193 { 2192 {
2194 error ("defaulted declaration %q+D does not match the " 2193 error ("defaulted declaration %q+D does not match the "
2195 "expected signature", fn); 2194 "expected signature", fn);
2196 inform (DECL_SOURCE_LOCATION (fn), 2195 inform (DECL_SOURCE_LOCATION (fn),
2197 "expected signature: %qD", implicit_fn); 2196 "expected signature: %qD", implicit_fn);
2198 return;
2199 } 2197 }
2200 2198
2201 if (DECL_DELETED_FN (implicit_fn)) 2199 if (DECL_DELETED_FN (implicit_fn))
2202 { 2200 {
2203 DECL_DELETED_FN (fn) = 1; 2201 DECL_DELETED_FN (fn) = 1;
2254 && DECL_DECLARED_CONSTEXPR_P (fn)) 2252 && DECL_DECLARED_CONSTEXPR_P (fn))
2255 { 2253 {
2256 if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx)) 2254 if (!CLASSTYPE_TEMPLATE_INSTANTIATION (ctx))
2257 { 2255 {
2258 error ("explicitly defaulted function %q+D cannot be declared " 2256 error ("explicitly defaulted function %q+D cannot be declared "
2259 "as constexpr because the implicit declaration is not " 2257 "as %<constexpr%> because the implicit declaration is not "
2260 "constexpr:", fn); 2258 "%<constexpr%>:", fn);
2261 explain_implicit_non_constexpr (fn); 2259 explain_implicit_non_constexpr (fn);
2262 } 2260 }
2263 DECL_DECLARED_CONSTEXPR_P (fn) = false; 2261 DECL_DECLARED_CONSTEXPR_P (fn) = false;
2264 } 2262 }
2265 } 2263 }
2316 kind = sfk_move_constructor; 2314 kind = sfk_move_constructor;
2317 } 2315 }
2318 else if (DECL_DESTRUCTOR_P (fn)) 2316 else if (DECL_DESTRUCTOR_P (fn))
2319 kind = sfk_destructor; 2317 kind = sfk_destructor;
2320 else if (DECL_ASSIGNMENT_OPERATOR_P (fn) 2318 else if (DECL_ASSIGNMENT_OPERATOR_P (fn)
2321 && DECL_OVERLOADED_OPERATOR_P (fn) == NOP_EXPR) 2319 && DECL_OVERLOADED_OPERATOR_IS (fn, NOP_EXPR))
2322 { 2320 {
2323 if (copy_fn_p (fn)) 2321 if (copy_fn_p (fn))
2324 kind = sfk_copy_assignment; 2322 kind = sfk_copy_assignment;
2325 else if (move_fn_p (fn)) 2323 else if (move_fn_p (fn))
2326 kind = sfk_move_assignment; 2324 kind = sfk_move_assignment;
2399 2397
2400 /* [class.copy]/8 If the class definition declares a move constructor or 2398 /* [class.copy]/8 If the class definition declares a move constructor or
2401 move assignment operator, the implicitly declared copy constructor is 2399 move assignment operator, the implicitly declared copy constructor is
2402 defined as deleted.... */ 2400 defined as deleted.... */
2403 if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor) 2401 if ((sfk == sfk_copy_assignment || sfk == sfk_copy_constructor)
2404 && classtype_has_move_assign_or_move_ctor_p (type, true)) 2402 && cxx_dialect >= cxx11)
2405 DECL_DELETED_FN (fn) = true; 2403 {
2404 if (classtype_has_move_assign_or_move_ctor_p (type, true))
2405 DECL_DELETED_FN (fn) = true;
2406 else if (classtype_has_user_copy_or_dtor (type))
2407 /* The implicit definition of a copy constructor as defaulted is
2408 deprecated if the class has a user-declared copy assignment operator
2409 or a user-declared destructor. The implicit definition of a copy
2410 assignment operator as defaulted is deprecated if the class has a
2411 user-declared copy constructor or a user-declared destructor (15.4,
2412 15.8). */
2413 TREE_DEPRECATED (fn) = true;
2414 }
2406 2415
2407 /* Destructors and assignment operators may be virtual. */ 2416 /* Destructors and assignment operators may be virtual. */
2408 if (sfk == sfk_destructor 2417 if (sfk == sfk_destructor
2409 || sfk == sfk_move_assignment 2418 || sfk == sfk_move_assignment
2410 || sfk == sfk_copy_assignment) 2419 || sfk == sfk_copy_assignment)
2411 check_for_override (fn, type); 2420 check_for_override (fn, type);
2412 2421
2413 /* Add it to the class */ 2422 /* Add it to the class */
2414 bool added = add_method (type, fn, false); 2423 bool added = add_method (type, fn, false);
2415 gcc_assert (added); 2424 gcc_assert (added || errorcount);
2416 2425
2417 /* Add it to TYPE_FIELDS. */ 2426 /* Add it to TYPE_FIELDS. */
2418 if (sfk == sfk_destructor 2427 if (sfk == sfk_destructor
2419 && DECL_VIRTUAL_P (fn)) 2428 && DECL_VIRTUAL_P (fn))
2420 /* The ABI requires that a virtual destructor go at the end of the 2429 /* The ABI requires that a virtual destructor go at the end of the
2427 } 2436 }
2428 /* Propagate TYPE_FIELDS. */ 2437 /* Propagate TYPE_FIELDS. */
2429 fixup_type_variants (type); 2438 fixup_type_variants (type);
2430 2439
2431 maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0); 2440 maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
2432 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (fn) 2441 if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
2433 || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fn))
2434 /* Create appropriate clones. */ 2442 /* Create appropriate clones. */
2435 clone_function_decl (fn, /*update_methods=*/true); 2443 clone_function_decl (fn, /*update_methods=*/true);
2436 2444
2437 return fn; 2445 return fn;
2438 } 2446 }