comparison gcc/cp/decl.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Process declarations and variables for C++ compiler. 1 /* Process declarations and variables for -*- C++ -*- compiler.
2 Copyright (C) 1988-2018 Free Software Foundation, Inc. 2 Copyright (C) 1988-2020 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
51 #include "builtins.h" 51 #include "builtins.h"
52 #include "gimplify.h" 52 #include "gimplify.h"
53 #include "asan.h" 53 #include "asan.h"
54 #include "gcc-rich-location.h" 54 #include "gcc-rich-location.h"
55 #include "langhooks.h" 55 #include "langhooks.h"
56 #include "omp-general.h"
56 57
57 /* Possible cases of bad specifiers type used by bad_specifiers. */ 58 /* Possible cases of bad specifiers type used by bad_specifiers. */
58 enum bad_spec_place { 59 enum bad_spec_place {
59 BSP_VAR, /* variable */ 60 BSP_VAR, /* variable */
60 BSP_PARM, /* parameter */ 61 BSP_PARM, /* parameter */
64 65
65 static const char *redeclaration_error_message (tree, tree); 66 static const char *redeclaration_error_message (tree, tree);
66 67
67 static int decl_jump_unsafe (tree); 68 static int decl_jump_unsafe (tree);
68 static void require_complete_types_for_parms (tree); 69 static void require_complete_types_for_parms (tree);
69 static void push_local_name (tree);
70 static tree grok_reference_init (tree, tree, tree, int); 70 static tree grok_reference_init (tree, tree, tree, int);
71 static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *, 71 static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
72 int, int, int, bool, int, tree); 72 int, int, int, bool, int, tree, location_t);
73 static void check_static_variable_definition (tree, tree); 73 static void check_static_variable_definition (tree, tree);
74 static void record_unknown_type (tree, const char *); 74 static void record_unknown_type (tree, const char *);
75 static tree builtin_function_1 (tree, tree, bool);
76 static int member_function_or_else (tree, tree, enum overload_flags); 75 static int member_function_or_else (tree, tree, enum overload_flags);
77 static tree local_variable_p_walkfn (tree *, int *, void *); 76 static tree local_variable_p_walkfn (tree *, int *, void *);
78 static const char *tag_name (enum tag_types); 77 static const char *tag_name (enum tag_types);
79 static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool); 78 static tree lookup_and_check_tag (enum tag_types, tree, tag_scope, bool);
80 static void maybe_deduce_size_from_array_init (tree, tree); 79 static void maybe_deduce_size_from_array_init (tree, tree);
81 static void layout_var_decl (tree); 80 static void layout_var_decl (tree);
82 static tree check_initializer (tree, tree, int, vec<tree, va_gc> **); 81 static tree check_initializer (tree, tree, int, vec<tree, va_gc> **);
83 static void make_rtl_for_nonlocal_decl (tree, tree, const char *); 82 static void make_rtl_for_nonlocal_decl (tree, tree, const char *);
84 static void save_function_data (tree);
85 static void copy_type_enum (tree , tree); 83 static void copy_type_enum (tree , tree);
86 static void check_function_type (tree, tree); 84 static void check_function_type (tree, tree);
87 static void finish_constructor_body (void); 85 static void finish_constructor_body (void);
88 static void begin_destructor_body (void); 86 static void begin_destructor_body (void);
89 static void finish_destructor_body (void); 87 static void finish_destructor_body (void);
90 static void record_key_method_defined (tree); 88 static void record_key_method_defined (tree);
91 static tree create_array_type_for_decl (tree, tree, tree); 89 static tree create_array_type_for_decl (tree, tree, tree, location_t);
92 static tree get_atexit_node (void); 90 static tree get_atexit_node (void);
93 static tree get_dso_handle_node (void); 91 static tree get_dso_handle_node (void);
94 static tree start_cleanup_fn (void); 92 static tree start_cleanup_fn (void);
95 static void end_cleanup_fn (void); 93 static void end_cleanup_fn (void);
96 static tree cp_make_fname_decl (location_t, tree, int); 94 static tree cp_make_fname_decl (location_t, tree, int);
100 static tree push_cp_library_fn (enum tree_code, tree, int); 98 static tree push_cp_library_fn (enum tree_code, tree, int);
101 static tree build_cp_library_fn (tree, enum tree_code, tree, int); 99 static tree build_cp_library_fn (tree, enum tree_code, tree, int);
102 static void store_parm_decls (tree); 100 static void store_parm_decls (tree);
103 static void initialize_local_var (tree, tree); 101 static void initialize_local_var (tree, tree);
104 static void expand_static_init (tree, tree); 102 static void expand_static_init (tree, tree);
103 static location_t smallest_type_location (const cp_decl_specifier_seq*);
105 104
106 /* The following symbols are subsumed in the cp_global_trees array, and 105 /* The following symbols are subsumed in the cp_global_trees array, and
107 listed here individually for documentation purposes. 106 listed here individually for documentation purposes.
108 107
109 C++ extensions 108 C++ extensions
135 Used by RTTI 134 Used by RTTI
136 tree type_info_type_node, tinfo_decl_id, tinfo_decl_type; 135 tree type_info_type_node, tinfo_decl_id, tinfo_decl_type;
137 tree tinfo_var_id; */ 136 tree tinfo_var_id; */
138 137
139 tree cp_global_trees[CPTI_MAX]; 138 tree cp_global_trees[CPTI_MAX];
140
141 #define local_names cp_function_chain->x_local_names
142 139
143 /* A list of objects which have constructors or destructors 140 /* A list of objects which have constructors or destructors
144 which reside in the global scope. The decl is stored in 141 which reside in the global scope. The decl is stored in
145 the TREE_VALUE slot and the initializer is stored 142 the TREE_VALUE slot and the initializer is stored
146 in the TREE_PURPOSE slot. */ 143 in the TREE_PURPOSE slot. */
869 TYPE_STUB_DECL (type) = decl; 866 TYPE_STUB_DECL (type) = decl;
870 867
871 return decl; 868 return decl;
872 } 869 }
873 870
874 /* Remember a local name for name-mangling purposes. */ 871 /* Function-scope local entities that need discriminators. Each entry
875 872 is a {decl,name} pair. VAR_DECLs for anon unions get their name
876 static void 873 smashed, so we cannot rely on DECL_NAME. */
877 push_local_name (tree decl) 874
878 { 875 static GTY((deletable)) vec<tree, va_gc> *local_entities;
879 size_t i, nelts; 876
880 tree t, name; 877 /* Determine the mangling discriminator of local DECL. There are
881 878 generally very few of these in any particular function. */
882 timevar_start (TV_NAME_LOOKUP); 879
883 880 void
884 name = DECL_NAME (decl); 881 determine_local_discriminator (tree decl)
885 882 {
886 nelts = vec_safe_length (local_names); 883 bool subtime = timevar_cond_start (TV_NAME_LOOKUP);
887 for (i = 0; i < nelts; i++) 884 retrofit_lang_decl (decl);
888 { 885 tree ctx = DECL_CONTEXT (decl);
889 t = (*local_names)[i]; 886 tree name = (TREE_CODE (decl) == TYPE_DECL
890 if (DECL_NAME (t) == name) 887 && TYPE_UNNAMED_P (TREE_TYPE (decl))
891 { 888 ? NULL_TREE : DECL_NAME (decl));
892 retrofit_lang_decl (decl); 889 size_t nelts = vec_safe_length (local_entities);
893 DECL_LANG_SPECIFIC (decl)->u.base.u2sel = 1; 890 for (size_t i = 0; i < nelts; i += 2)
894 if (DECL_DISCRIMINATOR_SET_P (t)) 891 {
895 DECL_DISCRIMINATOR (decl) = DECL_DISCRIMINATOR (t) + 1; 892 tree *pair = &(*local_entities)[i];
896 else 893 tree d = pair[0];
897 DECL_DISCRIMINATOR (decl) = 1; 894 tree n = pair[1];
898 895 gcc_checking_assert (d != decl);
899 (*local_names)[i] = decl; 896 if (name == n
900 timevar_stop (TV_NAME_LOOKUP); 897 && TREE_CODE (decl) == TREE_CODE (d)
901 return; 898 && ctx == DECL_CONTEXT (d))
902 } 899 {
903 } 900 tree disc = integer_one_node;
904 901 if (DECL_DISCRIMINATOR (d))
905 vec_safe_push (local_names, decl); 902 disc = build_int_cst (TREE_TYPE (disc),
906 timevar_stop (TV_NAME_LOOKUP); 903 TREE_INT_CST_LOW (DECL_DISCRIMINATOR (d)) + 1);
907 } 904 DECL_DISCRIMINATOR (decl) = disc;
905 /* Replace the saved decl. */
906 pair[0] = decl;
907 decl = NULL_TREE;
908 break;
909 }
910 }
911
912 if (decl)
913 {
914 vec_safe_reserve (local_entities, 2);
915 local_entities->quick_push (decl);
916 local_entities->quick_push (name);
917 }
918
919 timevar_cond_stop (TV_NAME_LOOKUP, subtime);
920 }
921
908 922
923
924 /* Returns true if functions FN1 and FN2 have equivalent trailing
925 requires clauses. */
926
927 static bool
928 function_requirements_equivalent_p (tree newfn, tree oldfn)
929 {
930 /* In the concepts TS, the combined constraints are compared. */
931 if (cxx_dialect < cxx2a)
932 {
933 tree ci1 = get_constraints (oldfn);
934 tree ci2 = get_constraints (newfn);
935 tree req1 = ci1 ? CI_ASSOCIATED_CONSTRAINTS (ci1) : NULL_TREE;
936 tree req2 = ci2 ? CI_ASSOCIATED_CONSTRAINTS (ci2) : NULL_TREE;
937 return cp_tree_equal (req1, req2);
938 }
939
940 /* Compare only trailing requirements. */
941 tree reqs1 = get_trailing_function_requirements (newfn);
942 tree reqs2 = get_trailing_function_requirements (oldfn);
943 if ((reqs1 != NULL_TREE) != (reqs2 != NULL_TREE))
944 return false;
945 reqs1 = maybe_substitute_reqs_for (reqs1, newfn);
946 reqs2 = maybe_substitute_reqs_for (reqs2, oldfn);
947 return cp_tree_equal (reqs1, reqs2);
948 }
949
909 /* Subroutine of duplicate_decls: return truthvalue of whether 950 /* Subroutine of duplicate_decls: return truthvalue of whether
910 or not types of these decls match. 951 or not types of these decls match.
911 952
912 For C++, we must compare the parameter list so that `int' can match 953 For C++, we must compare the parameter list so that `int' can match
913 `int&' in a parameter position, but `int&' is not confused with 954 `int&' in a parameter position, but `int&' is not confused with
983 TREE_TYPE (olddecl)) != 0); 1024 TREE_TYPE (olddecl)) != 0);
984 } 1025 }
985 else 1026 else
986 types_match = 0; 1027 types_match = 0;
987 1028
1029 /* Two function declarations match if either has a requires-clause
1030 then both have a requires-clause and their constraints-expressions
1031 are equivalent. */
1032 if (types_match && flag_concepts)
1033 types_match = function_requirements_equivalent_p (newdecl, olddecl);
1034
988 /* The decls dont match if they correspond to two different versions 1035 /* The decls dont match if they correspond to two different versions
989 of the same function. Disallow extern "C" functions to be 1036 of the same function. Disallow extern "C" functions to be
990 versions for now. */ 1037 versions for now. */
991 if (types_match 1038 if (types_match
992 && !DECL_EXTERN_C_P (newdecl) 1039 && !DECL_EXTERN_C_P (newdecl)
997 || !DECL_FUNCTION_VERSIONED (olddecl)))) 1044 || !DECL_FUNCTION_VERSIONED (olddecl))))
998 return 0; 1045 return 0;
999 } 1046 }
1000 else if (TREE_CODE (newdecl) == TEMPLATE_DECL) 1047 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1001 { 1048 {
1049 if (!template_heads_equivalent_p (newdecl, olddecl))
1050 return 0;
1051
1002 tree oldres = DECL_TEMPLATE_RESULT (olddecl); 1052 tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1003 tree newres = DECL_TEMPLATE_RESULT (newdecl); 1053 tree newres = DECL_TEMPLATE_RESULT (newdecl);
1004 1054
1005 if (TREE_CODE (newres) != TREE_CODE (oldres)) 1055 if (TREE_CODE (newres) != TREE_CODE (oldres))
1006 return 0; 1056 return 0;
1007 1057
1008 if (!comp_template_parms (DECL_TEMPLATE_PARMS (newdecl), 1058 /* Two template types match if they are the same. Otherwise, compare
1009 DECL_TEMPLATE_PARMS (olddecl))) 1059 the underlying declarations. */
1010 return 0; 1060 if (TREE_CODE (newres) == TYPE_DECL)
1011 1061 types_match = same_type_p (TREE_TYPE (newres), TREE_TYPE (oldres));
1012 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL)
1013 types_match = (same_type_p (TREE_TYPE (oldres), TREE_TYPE (newres))
1014 && equivalently_constrained (olddecl, newdecl));
1015 else 1062 else
1016 // We don't need to check equivalently_constrained for variable and 1063 types_match = decls_match (newres, oldres);
1017 // function templates because we check it on the results.
1018 types_match = decls_match (oldres, newres);
1019 } 1064 }
1020 else 1065 else
1021 { 1066 {
1022 /* Need to check scope for variable declaration (VAR_DECL). 1067 /* Need to check scope for variable declaration (VAR_DECL).
1023 For typedef (TYPE_DECL), scope is ignored. */ 1068 For typedef (TYPE_DECL), scope is ignored. */
1040 else 1085 else
1041 types_match = comptypes (TREE_TYPE (newdecl), 1086 types_match = comptypes (TREE_TYPE (newdecl),
1042 TREE_TYPE (olddecl), 1087 TREE_TYPE (olddecl),
1043 COMPARE_REDECLARATION); 1088 COMPARE_REDECLARATION);
1044 } 1089 }
1045
1046 // Normal functions can be constrained, as can variable partial
1047 // specializations.
1048 if (types_match && VAR_OR_FUNCTION_DECL_P (newdecl))
1049 types_match = equivalently_constrained (newdecl, olddecl);
1050 1090
1051 return types_match; 1091 return types_match;
1052 } 1092 }
1053 1093
1054 /* NEWDECL and OLDDECL have identical signatures. If they are 1094 /* NEWDECL and OLDDECL have identical signatures. If they are
1185 if (!VAR_OR_FUNCTION_DECL_P (old_decl) 1225 if (!VAR_OR_FUNCTION_DECL_P (old_decl)
1186 || !VAR_OR_FUNCTION_DECL_P (new_decl)) 1226 || !VAR_OR_FUNCTION_DECL_P (new_decl))
1187 return true; 1227 return true;
1188 if (DECL_DECLARED_CONSTEXPR_P (old_decl) 1228 if (DECL_DECLARED_CONSTEXPR_P (old_decl)
1189 == DECL_DECLARED_CONSTEXPR_P (new_decl)) 1229 == DECL_DECLARED_CONSTEXPR_P (new_decl))
1190 return true; 1230 {
1231 if (TREE_CODE (old_decl) != FUNCTION_DECL)
1232 return true;
1233 if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1234 == DECL_IMMEDIATE_FUNCTION_P (new_decl))
1235 return true;
1236 }
1191 if (TREE_CODE (old_decl) == FUNCTION_DECL) 1237 if (TREE_CODE (old_decl) == FUNCTION_DECL)
1192 { 1238 {
1193 if (fndecl_built_in_p (old_decl)) 1239 if (fndecl_built_in_p (old_decl))
1194 { 1240 {
1195 /* Hide a built-in declaration. */ 1241 /* Hide a built-in declaration. */
1196 DECL_DECLARED_CONSTEXPR_P (old_decl) 1242 DECL_DECLARED_CONSTEXPR_P (old_decl)
1197 = DECL_DECLARED_CONSTEXPR_P (new_decl); 1243 = DECL_DECLARED_CONSTEXPR_P (new_decl);
1244 if (DECL_IMMEDIATE_FUNCTION_P (new_decl))
1245 SET_DECL_IMMEDIATE_FUNCTION_P (old_decl);
1198 return true; 1246 return true;
1199 } 1247 }
1200 /* 7.1.5 [dcl.constexpr] 1248 /* 7.1.5 [dcl.constexpr]
1201 Note: An explicit specialization can differ from the template 1249 Note: An explicit specialization can differ from the template
1202 declaration with respect to the constexpr specifier. */ 1250 declaration with respect to the constexpr specifier. */
1203 if (! DECL_TEMPLATE_SPECIALIZATION (old_decl) 1251 if (! DECL_TEMPLATE_SPECIALIZATION (old_decl)
1204 && DECL_TEMPLATE_SPECIALIZATION (new_decl)) 1252 && DECL_TEMPLATE_SPECIALIZATION (new_decl))
1205 return true; 1253 return true;
1206 1254
1255 const char *kind = "constexpr";
1256 if (DECL_IMMEDIATE_FUNCTION_P (old_decl)
1257 || DECL_IMMEDIATE_FUNCTION_P (new_decl))
1258 kind = "consteval";
1207 error_at (DECL_SOURCE_LOCATION (new_decl), 1259 error_at (DECL_SOURCE_LOCATION (new_decl),
1208 "redeclaration %qD differs in %<constexpr%> " 1260 "redeclaration %qD differs in %qs "
1209 "from previous declaration", new_decl); 1261 "from previous declaration", new_decl,
1262 kind);
1210 inform (DECL_SOURCE_LOCATION (old_decl), 1263 inform (DECL_SOURCE_LOCATION (old_decl),
1211 "previous declaration %qD", old_decl); 1264 "previous declaration %qD", old_decl);
1212 return false; 1265 return false;
1213 } 1266 }
1214 return true; 1267 return true;
1289 || (DECL_FRIEND_P (newdecl) && TREE_PURPOSE (t2))) 1342 || (DECL_FRIEND_P (newdecl) && TREE_PURPOSE (t2)))
1290 { 1343 {
1291 auto_diagnostic_group d; 1344 auto_diagnostic_group d;
1292 if (permerror (DECL_SOURCE_LOCATION (newdecl), 1345 if (permerror (DECL_SOURCE_LOCATION (newdecl),
1293 "friend declaration of %q#D specifies default " 1346 "friend declaration of %q#D specifies default "
1294 "arguments and isn't the only declaration", newdecl)) 1347 "arguments and isn%'t the only declaration", newdecl))
1295 inform (DECL_SOURCE_LOCATION (olddecl), 1348 inform (DECL_SOURCE_LOCATION (olddecl),
1296 "previous declaration of %q#D", olddecl); 1349 "previous declaration of %q#D", olddecl);
1297 return; 1350 return;
1298 } 1351 }
1299 } 1352 }
1320 1373
1321 #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn) \ 1374 #define GNU_INLINE_P(fn) (DECL_DECLARED_INLINE_P (fn) \
1322 && lookup_attribute ("gnu_inline", \ 1375 && lookup_attribute ("gnu_inline", \
1323 DECL_ATTRIBUTES (fn))) 1376 DECL_ATTRIBUTES (fn)))
1324 1377
1378 /* A subroutine of duplicate_decls. Emits a diagnostic when newdecl
1379 ambiguates olddecl. Returns true if an error occurs. */
1380
1381 static bool
1382 duplicate_function_template_decls (tree newdecl, tree olddecl)
1383 {
1384
1385 tree newres = DECL_TEMPLATE_RESULT (newdecl);
1386 tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1387 /* Function template declarations can be differentiated by parameter
1388 and return type. */
1389 if (compparms (TYPE_ARG_TYPES (TREE_TYPE (oldres)),
1390 TYPE_ARG_TYPES (TREE_TYPE (newres)))
1391 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
1392 TREE_TYPE (TREE_TYPE (olddecl))))
1393 {
1394 /* ... and also by their template-heads and requires-clauses. */
1395 if (template_heads_equivalent_p (newdecl, olddecl)
1396 && function_requirements_equivalent_p (newres, oldres))
1397 {
1398 error ("ambiguating new declaration %q+#D", newdecl);
1399 inform (DECL_SOURCE_LOCATION (olddecl),
1400 "old declaration %q#D", olddecl);
1401 return true;
1402 }
1403
1404 /* FIXME: The types are the same but the are differences
1405 in either the template heads or function requirements.
1406 We should be able to diagnose a set of common errors
1407 stemming from these declarations. For example:
1408
1409 template<typename T> requires C void f(...);
1410 template<typename T> void f(...) requires C;
1411
1412 These are functionally equivalent but not equivalent. */
1413 }
1414
1415 return false;
1416 }
1417
1325 /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations. 1418 /* If NEWDECL is a redeclaration of OLDDECL, merge the declarations.
1326 If the redeclaration is invalid, a diagnostic is issued, and the 1419 If the redeclaration is invalid, a diagnostic is issued, and the
1327 error_mark_node is returned. Otherwise, OLDDECL is returned. 1420 error_mark_node is returned. Otherwise, OLDDECL is returned.
1328 1421
1329 If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is 1422 If NEWDECL is not a redeclaration of OLDDECL, NULL_TREE is
1353 it is rather pointless to harass the user with yet more error message 1446 it is rather pointless to harass the user with yet more error message
1354 about the same declaration, so just pretend the types match here. */ 1447 about the same declaration, so just pretend the types match here. */
1355 if (TREE_TYPE (newdecl) == error_mark_node 1448 if (TREE_TYPE (newdecl) == error_mark_node
1356 || TREE_TYPE (olddecl) == error_mark_node) 1449 || TREE_TYPE (olddecl) == error_mark_node)
1357 return error_mark_node; 1450 return error_mark_node;
1358
1359 if (DECL_NAME (newdecl)
1360 && DECL_NAME (olddecl)
1361 && UDLIT_OPER_P (DECL_NAME (newdecl))
1362 && UDLIT_OPER_P (DECL_NAME (olddecl)))
1363 {
1364 if (TREE_CODE (newdecl) == TEMPLATE_DECL
1365 && TREE_CODE (olddecl) != TEMPLATE_DECL
1366 && check_raw_literal_operator (olddecl))
1367 error_at (newdecl_loc,
1368 "literal operator template %qD conflicts with"
1369 " raw literal operator %qD", newdecl, olddecl);
1370 else if (TREE_CODE (newdecl) != TEMPLATE_DECL
1371 && TREE_CODE (olddecl) == TEMPLATE_DECL
1372 && check_raw_literal_operator (newdecl))
1373 error_at (newdecl_loc,
1374 "raw literal operator %qD conflicts with"
1375 " literal operator template %qD", newdecl, olddecl);
1376 }
1377
1378 /* True to merge attributes between the declarations, false to
1379 set OLDDECL's attributes to those of NEWDECL (for template
1380 explicit specializations that specify their own attributes
1381 independent of those specified for the primary template). */
1382 const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
1383 || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
1384 || DECL_TEMPLATE_SPECIALIZATION (olddecl));
1385
1386 if (DECL_P (olddecl)
1387 && TREE_CODE (newdecl) == FUNCTION_DECL
1388 && TREE_CODE (olddecl) == FUNCTION_DECL
1389 && merge_attr
1390 && diagnose_mismatched_attributes (olddecl, newdecl))
1391 {
1392 if (DECL_INITIAL (olddecl))
1393 inform (olddecl_loc,
1394 "previous definition of %qD was here", olddecl);
1395 else
1396 inform (olddecl_loc,
1397 "previous declaration of %qD was here", olddecl);
1398 }
1399 1451
1400 /* Check for redeclaration and other discrepancies. */ 1452 /* Check for redeclaration and other discrepancies. */
1401 if (TREE_CODE (olddecl) == FUNCTION_DECL 1453 if (TREE_CODE (olddecl) == FUNCTION_DECL
1402 && DECL_ARTIFICIAL (olddecl)) 1454 && DECL_ARTIFICIAL (olddecl))
1403 { 1455 {
1501 goto next_arg; 1553 goto next_arg;
1502 } 1554 }
1503 1555
1504 if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2))) 1556 if (! same_type_p (TREE_VALUE (t1), TREE_VALUE (t2)))
1505 break; 1557 break;
1506 next_arg:; 1558 next_arg:;
1507 } 1559 }
1508 1560
1509 warning_at (newdecl_loc, 1561 warning_at (newdecl_loc,
1510 OPT_Wbuiltin_declaration_mismatch, 1562 OPT_Wbuiltin_declaration_mismatch,
1511 "declaration of %q#D conflicts with built-in " 1563 "declaration of %q#D conflicts with built-in "
1618 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) 1670 else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
1619 { 1671 {
1620 /* C++ Standard, 3.3, clause 4: 1672 /* C++ Standard, 3.3, clause 4:
1621 "[Note: a namespace name or a class template name must be unique 1673 "[Note: a namespace name or a class template name must be unique
1622 in its declarative region (7.3.2, clause 14). ]" */ 1674 in its declarative region (7.3.2, clause 14). ]" */
1623 if (TREE_CODE (olddecl) != NAMESPACE_DECL 1675 if (TREE_CODE (olddecl) == NAMESPACE_DECL
1624 && TREE_CODE (newdecl) != NAMESPACE_DECL 1676 || TREE_CODE (newdecl) == NAMESPACE_DECL)
1625 && (TREE_CODE (olddecl) != TEMPLATE_DECL 1677 /* Namespace conflicts with not namespace. */;
1626 || TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) != TYPE_DECL) 1678 else if (DECL_TYPE_TEMPLATE_P (olddecl)
1627 && (TREE_CODE (newdecl) != TEMPLATE_DECL 1679 || DECL_TYPE_TEMPLATE_P (newdecl))
1628 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != TYPE_DECL)) 1680 /* Class template conflicts. */;
1629 { 1681 else if ((TREE_CODE (newdecl) == FUNCTION_DECL
1630 if ((TREE_CODE (olddecl) == TYPE_DECL && DECL_ARTIFICIAL (olddecl) 1682 && DECL_FUNCTION_TEMPLATE_P (olddecl))
1631 && TREE_CODE (newdecl) != TYPE_DECL) 1683 || (TREE_CODE (olddecl) == FUNCTION_DECL
1632 || (TREE_CODE (newdecl) == TYPE_DECL && DECL_ARTIFICIAL (newdecl) 1684 && DECL_FUNCTION_TEMPLATE_P (newdecl)))
1633 && TREE_CODE (olddecl) != TYPE_DECL)) 1685 {
1634 { 1686 /* One is a function and the other is a template
1635 /* We do nothing special here, because C++ does such nasty 1687 function. */
1636 things with TYPE_DECLs. Instead, just let the TYPE_DECL 1688 if (!UDLIT_OPER_P (DECL_NAME (newdecl)))
1637 get shadowed, and know that if we need to find a TYPE_DECL 1689 return NULL_TREE;
1638 for a given name, we can look in the IDENTIFIER_TYPE_VALUE 1690
1639 slot of the identifier. */ 1691 /* There can only be one! */
1640 return NULL_TREE; 1692 if (TREE_CODE (newdecl) == TEMPLATE_DECL
1641 } 1693 && check_raw_literal_operator (olddecl))
1642 1694 error_at (newdecl_loc,
1643 if ((TREE_CODE (newdecl) == FUNCTION_DECL 1695 "literal operator %q#D conflicts with"
1644 && DECL_FUNCTION_TEMPLATE_P (olddecl)) 1696 " raw literal operator", newdecl);
1645 || (TREE_CODE (olddecl) == FUNCTION_DECL 1697 else if (check_raw_literal_operator (newdecl))
1646 && DECL_FUNCTION_TEMPLATE_P (newdecl))) 1698 error_at (newdecl_loc,
1647 return NULL_TREE; 1699 "raw literal operator %q#D conflicts with"
1648 } 1700 " literal operator template", newdecl);
1649 1701 else
1650 error ("%q#D redeclared as different kind of symbol", newdecl); 1702 return NULL_TREE;
1651 if (TREE_CODE (olddecl) == TREE_LIST) 1703
1652 olddecl = TREE_VALUE (olddecl); 1704 inform (olddecl_loc, "previous declaration %q#D", olddecl);
1653 inform (olddecl_loc, 1705 return error_mark_node;
1654 "previous declaration %q#D", olddecl); 1706 }
1707 else if (DECL_IMPLICIT_TYPEDEF_P (olddecl)
1708 || DECL_IMPLICIT_TYPEDEF_P (newdecl))
1709 /* One is an implicit typedef, that's ok. */
1710 return NULL_TREE;
1711
1712 error ("%q#D redeclared as different kind of entity", newdecl);
1713 inform (olddecl_loc, "previous declaration %q#D", olddecl);
1655 1714
1656 return error_mark_node; 1715 return error_mark_node;
1657 } 1716 }
1658 else if (!types_match) 1717 else if (!types_match)
1659 { 1718 {
1662 from different scopes. */ 1721 from different scopes. */
1663 return NULL_TREE; 1722 return NULL_TREE;
1664 1723
1665 if (TREE_CODE (newdecl) == TEMPLATE_DECL) 1724 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
1666 { 1725 {
1726 tree oldres = DECL_TEMPLATE_RESULT (olddecl);
1727 tree newres = DECL_TEMPLATE_RESULT (newdecl);
1728
1667 /* The name of a class template may not be declared to refer to 1729 /* The name of a class template may not be declared to refer to
1668 any other template, class, function, object, namespace, value, 1730 any other template, class, function, object, namespace, value,
1669 or type in the same scope. */ 1731 or type in the same scope. */
1670 if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == TYPE_DECL 1732 if (TREE_CODE (oldres) == TYPE_DECL
1671 || TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) 1733 || TREE_CODE (newres) == TYPE_DECL)
1672 { 1734 {
1673 error_at (newdecl_loc, 1735 error_at (newdecl_loc,
1674 "conflicting declaration of template %q#D", newdecl); 1736 "conflicting declaration of template %q#D", newdecl);
1675 inform (olddecl_loc, 1737 inform (olddecl_loc,
1676 "previous declaration %q#D", olddecl); 1738 "previous declaration %q#D", olddecl);
1677 return error_mark_node; 1739 return error_mark_node;
1678 } 1740 }
1679 else if (TREE_CODE (DECL_TEMPLATE_RESULT (olddecl)) == FUNCTION_DECL 1741
1680 && TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == FUNCTION_DECL 1742 else if (TREE_CODE (oldres) == FUNCTION_DECL
1681 && compparms (TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (olddecl))), 1743 && TREE_CODE (newres) == FUNCTION_DECL)
1682 TYPE_ARG_TYPES (TREE_TYPE (DECL_TEMPLATE_RESULT (newdecl))))
1683 && comp_template_parms (DECL_TEMPLATE_PARMS (newdecl),
1684 DECL_TEMPLATE_PARMS (olddecl))
1685 /* Template functions can be disambiguated by
1686 return type. */
1687 && same_type_p (TREE_TYPE (TREE_TYPE (newdecl)),
1688 TREE_TYPE (TREE_TYPE (olddecl)))
1689 // Template functions can also be disambiguated by
1690 // constraints.
1691 && equivalently_constrained (olddecl, newdecl))
1692 { 1744 {
1693 error_at (newdecl_loc, "ambiguating new declaration %q#D", 1745 if (duplicate_function_template_decls (newdecl, olddecl))
1694 newdecl); 1746 return error_mark_node;
1695 inform (olddecl_loc, 1747 return NULL_TREE;
1696 "old declaration %q#D", olddecl);
1697 } 1748 }
1698 else if (check_concept_refinement (olddecl, newdecl)) 1749 else if (check_concept_refinement (olddecl, newdecl))
1699 return error_mark_node; 1750 return error_mark_node;
1700 return NULL_TREE; 1751 return NULL_TREE;
1701 } 1752 }
1922 if (TREE_CODE (olddecl) == TYPE_DECL 1973 if (TREE_CODE (olddecl) == TYPE_DECL
1923 && (DECL_IMPLICIT_TYPEDEF_P (olddecl) 1974 && (DECL_IMPLICIT_TYPEDEF_P (olddecl)
1924 || DECL_IMPLICIT_TYPEDEF_P (newdecl))) 1975 || DECL_IMPLICIT_TYPEDEF_P (newdecl)))
1925 return NULL_TREE; 1976 return NULL_TREE;
1926 1977
1978 if (!validate_constexpr_redeclaration (olddecl, newdecl))
1979 return error_mark_node;
1980
1981 /* We have committed to returning OLDDECL at this point. */
1982
1927 /* If new decl is `static' and an `extern' was seen previously, 1983 /* If new decl is `static' and an `extern' was seen previously,
1928 warn about it. */ 1984 warn about it. */
1929 warn_extern_redeclared_static (newdecl, olddecl); 1985 warn_extern_redeclared_static (newdecl, olddecl);
1930 1986
1931 if (!validate_constexpr_redeclaration (olddecl, newdecl)) 1987 /* True to merge attributes between the declarations, false to
1932 return error_mark_node; 1988 set OLDDECL's attributes to those of NEWDECL (for template
1933 1989 explicit specializations that specify their own attributes
1934 /* We have committed to returning 1 at this point. */ 1990 independent of those specified for the primary template). */
1991 const bool merge_attr = (TREE_CODE (newdecl) != FUNCTION_DECL
1992 || !DECL_TEMPLATE_SPECIALIZATION (newdecl)
1993 || DECL_TEMPLATE_SPECIALIZATION (olddecl));
1994
1935 if (TREE_CODE (newdecl) == FUNCTION_DECL) 1995 if (TREE_CODE (newdecl) == FUNCTION_DECL)
1936 { 1996 {
1997 if (merge_attr)
1998 {
1999 if (diagnose_mismatched_attributes (olddecl, newdecl))
2000 inform (olddecl_loc, DECL_INITIAL (olddecl)
2001 ? G_("previous definition of %qD here")
2002 : G_("previous declaration of %qD here"), olddecl);
2003
2004 /* [dcl.attr.noreturn]: The first declaration of a function shall
2005 specify the noreturn attribute if any declaration of that function
2006 specifies the noreturn attribute. */
2007 tree a;
2008 if (TREE_THIS_VOLATILE (newdecl)
2009 && !TREE_THIS_VOLATILE (olddecl)
2010 /* This applies to [[noreturn]] only, not its GNU variants. */
2011 && (a = lookup_attribute ("noreturn", DECL_ATTRIBUTES (newdecl)))
2012 && cxx11_attribute_p (a)
2013 && get_attribute_namespace (a) == NULL_TREE)
2014 {
2015 error_at (newdecl_loc, "function %qD declared %<[[noreturn]]%> "
2016 "but its first declaration was not", newdecl);
2017 inform (olddecl_loc, "previous declaration of %qD", olddecl);
2018 }
2019 }
2020
1937 /* Now that functions must hold information normally held 2021 /* Now that functions must hold information normally held
1938 by field decls, there is extra work to do so that 2022 by field decls, there is extra work to do so that
1939 declaration information does not get destroyed during 2023 declaration information does not get destroyed during
1940 definition. */ 2024 definition. */
1941 if (DECL_VINDEX (olddecl)) 2025 if (DECL_VINDEX (olddecl))
2011 DECL_ATTRIBUTES (newdecl) 2095 DECL_ATTRIBUTES (newdecl)
2012 = (*targetm.merge_decl_attributes) (olddecl, newdecl); 2096 = (*targetm.merge_decl_attributes) (olddecl, newdecl);
2013 else 2097 else
2014 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl); 2098 DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
2015 2099
2016 if (DECL_DECLARES_FUNCTION_P (olddecl) && DECL_DECLARES_FUNCTION_P (newdecl)) 2100 if (DECL_DECLARES_FUNCTION_P (olddecl))
2017 { 2101 {
2018 olddecl_friend = DECL_FRIEND_P (olddecl); 2102 olddecl_friend = DECL_FRIEND_P (olddecl);
2019 olddecl_hidden_friend = DECL_HIDDEN_FRIEND_P (olddecl); 2103 olddecl_hidden_friend = DECL_HIDDEN_FRIEND_P (olddecl);
2020 hidden_friend = (DECL_ANTICIPATED (olddecl) 2104 hidden_friend = (DECL_ANTICIPATED (olddecl)
2021 && DECL_HIDDEN_FRIEND_P (olddecl) 2105 && DECL_HIDDEN_FRIEND_P (olddecl)
2030 if (TREE_CODE (newdecl) == TEMPLATE_DECL) 2114 if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2031 { 2115 {
2032 tree old_result = DECL_TEMPLATE_RESULT (olddecl); 2116 tree old_result = DECL_TEMPLATE_RESULT (olddecl);
2033 tree new_result = DECL_TEMPLATE_RESULT (newdecl); 2117 tree new_result = DECL_TEMPLATE_RESULT (newdecl);
2034 TREE_TYPE (olddecl) = TREE_TYPE (old_result); 2118 TREE_TYPE (olddecl) = TREE_TYPE (old_result);
2035 DECL_TEMPLATE_SPECIALIZATIONS (olddecl) 2119
2036 = chainon (DECL_TEMPLATE_SPECIALIZATIONS (olddecl), 2120 /* The new decl should not already have gathered any
2037 DECL_TEMPLATE_SPECIALIZATIONS (newdecl)); 2121 specializations. */
2122 gcc_assert (!DECL_TEMPLATE_SPECIALIZATIONS (newdecl));
2038 2123
2039 DECL_ATTRIBUTES (old_result) 2124 DECL_ATTRIBUTES (old_result)
2040 = (*targetm.merge_decl_attributes) (old_result, new_result); 2125 = (*targetm.merge_decl_attributes) (old_result, new_result);
2041 2126
2042 if (DECL_FUNCTION_TEMPLATE_P (newdecl)) 2127 if (DECL_FUNCTION_TEMPLATE_P (newdecl))
2136 2221
2137 /* And remove the new type from the variants list. */ 2222 /* And remove the new type from the variants list. */
2138 if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl) 2223 if (TYPE_NAME (TREE_TYPE (newdecl)) == newdecl)
2139 { 2224 {
2140 tree remove = TREE_TYPE (newdecl); 2225 tree remove = TREE_TYPE (newdecl);
2141 for (tree t = TYPE_MAIN_VARIANT (remove); ; 2226 if (TYPE_MAIN_VARIANT (remove) == remove)
2142 t = TYPE_NEXT_VARIANT (t)) 2227 {
2143 if (TYPE_NEXT_VARIANT (t) == remove) 2228 gcc_assert (TYPE_NEXT_VARIANT (remove) == NULL_TREE);
2144 { 2229 /* If remove is the main variant, no need to remove that
2145 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove); 2230 from the list. One of the DECL_ORIGINAL_TYPE
2146 break; 2231 variants, e.g. created for aligned attribute, might still
2147 } 2232 refer to the newdecl TYPE_DECL though, so remove that one
2233 in that case. */
2234 if (tree orig = DECL_ORIGINAL_TYPE (newdecl))
2235 if (orig != remove)
2236 for (tree t = TYPE_MAIN_VARIANT (orig); t;
2237 t = TYPE_MAIN_VARIANT (t))
2238 if (TYPE_NAME (TYPE_NEXT_VARIANT (t)) == newdecl)
2239 {
2240 TYPE_NEXT_VARIANT (t)
2241 = TYPE_NEXT_VARIANT (TYPE_NEXT_VARIANT (t));
2242 break;
2243 }
2244 }
2245 else
2246 for (tree t = TYPE_MAIN_VARIANT (remove); ;
2247 t = TYPE_NEXT_VARIANT (t))
2248 if (TYPE_NEXT_VARIANT (t) == remove)
2249 {
2250 TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (remove);
2251 break;
2252 }
2148 } 2253 }
2149 } 2254 }
2150 else if (merge_attr) 2255 else if (merge_attr)
2151 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl)); 2256 newtype = merge_types (TREE_TYPE (newdecl), TREE_TYPE (olddecl));
2152 else 2257 else
2168 |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl); 2273 |= DECL_NONTRIVIALLY_INITIALIZED_P (olddecl);
2169 if (DECL_DEPENDENT_INIT_P (olddecl)) 2274 if (DECL_DEPENDENT_INIT_P (olddecl))
2170 SET_DECL_DEPENDENT_INIT_P (newdecl, true); 2275 SET_DECL_DEPENDENT_INIT_P (newdecl, true);
2171 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl) 2276 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
2172 |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl); 2277 |= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
2173 if (DECL_CLASS_SCOPE_P (olddecl)) 2278 DECL_DECLARED_CONSTEXPR_P (newdecl)
2174 DECL_DECLARED_CONSTEXPR_P (newdecl) 2279 |= DECL_DECLARED_CONSTEXPR_P (olddecl);
2175 |= DECL_DECLARED_CONSTEXPR_P (olddecl);
2176 2280
2177 /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */ 2281 /* Merge the threadprivate attribute from OLDDECL into NEWDECL. */
2178 if (DECL_LANG_SPECIFIC (olddecl) 2282 if (DECL_LANG_SPECIFIC (olddecl)
2179 && CP_DECL_THREADPRIVATE_P (olddecl)) 2283 && CP_DECL_THREADPRIVATE_P (olddecl))
2180 { 2284 {
2257 if (TREE_CODE (newdecl) == FUNCTION_DECL) 2361 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2258 { 2362 {
2259 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl) 2363 DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
2260 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl); 2364 |= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
2261 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl); 2365 DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
2262 DECL_IS_OPERATOR_NEW (newdecl) |= DECL_IS_OPERATOR_NEW (olddecl); 2366 if (DECL_IS_OPERATOR_NEW_P (olddecl))
2367 DECL_SET_IS_OPERATOR_NEW (newdecl, true);
2263 DECL_LOOPING_CONST_OR_PURE_P (newdecl) 2368 DECL_LOOPING_CONST_OR_PURE_P (newdecl)
2264 |= DECL_LOOPING_CONST_OR_PURE_P (olddecl); 2369 |= DECL_LOOPING_CONST_OR_PURE_P (olddecl);
2265 2370
2266 if (merge_attr) 2371 if (merge_attr)
2267 merge_attribute_bits (newdecl, olddecl); 2372 merge_attribute_bits (newdecl, olddecl);
2352 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl); 2457 DECL_USE_TEMPLATE (newdecl) = DECL_USE_TEMPLATE (olddecl);
2353 2458
2354 /* Don't really know how much of the language-specific 2459 /* Don't really know how much of the language-specific
2355 values we should copy from old to new. */ 2460 values we should copy from old to new. */
2356 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl); 2461 DECL_IN_AGGR_P (newdecl) = DECL_IN_AGGR_P (olddecl);
2357 DECL_REPO_AVAILABLE_P (newdecl) = DECL_REPO_AVAILABLE_P (olddecl);
2358 DECL_INITIALIZED_IN_CLASS_P (newdecl) 2462 DECL_INITIALIZED_IN_CLASS_P (newdecl)
2359 |= DECL_INITIALIZED_IN_CLASS_P (olddecl); 2463 |= DECL_INITIALIZED_IN_CLASS_P (olddecl);
2360 2464
2361 if (LANG_DECL_HAS_MIN (newdecl)) 2465 if (LANG_DECL_HAS_MIN (newdecl))
2362 { 2466 {
2363 DECL_LANG_SPECIFIC (newdecl)->u.min.u2 = 2467 DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl);
2364 DECL_LANG_SPECIFIC (olddecl)->u.min.u2;
2365 if (DECL_TEMPLATE_INFO (newdecl)) 2468 if (DECL_TEMPLATE_INFO (newdecl))
2366 { 2469 {
2367 new_template_info = DECL_TEMPLATE_INFO (newdecl); 2470 new_template_info = DECL_TEMPLATE_INFO (newdecl);
2368 if (DECL_TEMPLATE_INSTANTIATION (olddecl) 2471 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
2369 && DECL_TEMPLATE_SPECIALIZATION (newdecl)) 2472 && DECL_TEMPLATE_SPECIALIZATION (newdecl))
2371 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl)) 2474 TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl))
2372 = TINFO_USED_TEMPLATE_ID (new_template_info); 2475 = TINFO_USED_TEMPLATE_ID (new_template_info);
2373 } 2476 }
2374 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); 2477 DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl);
2375 } 2478 }
2376 /* Only functions have these fields. */ 2479
2377 if (DECL_DECLARES_FUNCTION_P (newdecl)) 2480 if (DECL_DECLARES_FUNCTION_P (newdecl))
2378 { 2481 {
2482 /* Only functions have these fields. */
2379 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl); 2483 DECL_NONCONVERTING_P (newdecl) = DECL_NONCONVERTING_P (olddecl);
2380 DECL_BEFRIENDING_CLASSES (newdecl) 2484 DECL_BEFRIENDING_CLASSES (newdecl)
2381 = chainon (DECL_BEFRIENDING_CLASSES (newdecl), 2485 = chainon (DECL_BEFRIENDING_CLASSES (newdecl),
2382 DECL_BEFRIENDING_CLASSES (olddecl)); 2486 DECL_BEFRIENDING_CLASSES (olddecl));
2383 /* DECL_THUNKS is only valid for virtual functions, 2487 /* DECL_THUNKS is only valid for virtual functions,
2384 otherwise it is a DECL_FRIEND_CONTEXT. */ 2488 otherwise it is a DECL_FRIEND_CONTEXT. */
2385 if (DECL_VIRTUAL_P (newdecl)) 2489 if (DECL_VIRTUAL_P (newdecl))
2386 SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl)); 2490 SET_DECL_THUNKS (newdecl, DECL_THUNKS (olddecl));
2387 } 2491 }
2388 /* Only variables have this field. */ 2492 else if (VAR_P (newdecl))
2389 else if (VAR_P (newdecl) 2493 {
2390 && VAR_HAD_UNKNOWN_BOUND (olddecl)) 2494 /* Only variables have this field. */
2391 SET_VAR_HAD_UNKNOWN_BOUND (newdecl); 2495 if (VAR_HAD_UNKNOWN_BOUND (olddecl))
2496 SET_VAR_HAD_UNKNOWN_BOUND (newdecl);
2497 }
2392 } 2498 }
2393 2499
2394 if (TREE_CODE (newdecl) == FUNCTION_DECL) 2500 if (TREE_CODE (newdecl) == FUNCTION_DECL)
2395 { 2501 {
2396 tree parm; 2502 tree parm;
2397 2503
2398 /* Merge parameter attributes. */ 2504 /* Merge parameter attributes. */
2399 tree oldarg, newarg; 2505 tree oldarg, newarg;
2400 for (oldarg = DECL_ARGUMENTS(olddecl), 2506 for (oldarg = DECL_ARGUMENTS(olddecl), newarg = DECL_ARGUMENTS(newdecl);
2401 newarg = DECL_ARGUMENTS(newdecl);
2402 oldarg && newarg; 2507 oldarg && newarg;
2403 oldarg = DECL_CHAIN(oldarg), newarg = DECL_CHAIN(newarg)) { 2508 oldarg = DECL_CHAIN(oldarg), newarg = DECL_CHAIN(newarg))
2509 {
2404 DECL_ATTRIBUTES (newarg) 2510 DECL_ATTRIBUTES (newarg)
2405 = (*targetm.merge_decl_attributes) (oldarg, newarg); 2511 = (*targetm.merge_decl_attributes) (oldarg, newarg);
2406 DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg); 2512 DECL_ATTRIBUTES (oldarg) = DECL_ATTRIBUTES (newarg);
2407 } 2513 }
2408 2514
2409 if (DECL_TEMPLATE_INSTANTIATION (olddecl) 2515 if (DECL_TEMPLATE_INSTANTIATION (olddecl)
2410 && !DECL_TEMPLATE_INSTANTIATION (newdecl)) 2516 && !DECL_TEMPLATE_INSTANTIATION (newdecl))
2411 { 2517 {
2412 /* If newdecl is not a specialization, then it is not a 2518 /* If newdecl is not a specialization, then it is not a
2413 template-related function at all. And that means that we 2519 template-related function at all. And that means that we
2462 DECL_PENDING_INLINE_INFO (newdecl) 2568 DECL_PENDING_INLINE_INFO (newdecl)
2463 = DECL_PENDING_INLINE_INFO (olddecl); 2569 = DECL_PENDING_INLINE_INFO (olddecl);
2464 } 2570 }
2465 else if (DECL_PENDING_INLINE_P (newdecl)) 2571 else if (DECL_PENDING_INLINE_P (newdecl))
2466 ; 2572 ;
2467 else if (DECL_SAVED_FUNCTION_DATA (newdecl) == NULL) 2573 else if (DECL_SAVED_AUTO_RETURN_TYPE (newdecl) == NULL)
2468 DECL_SAVED_FUNCTION_DATA (newdecl) 2574 DECL_SAVED_AUTO_RETURN_TYPE (newdecl)
2469 = DECL_SAVED_FUNCTION_DATA (olddecl); 2575 = DECL_SAVED_AUTO_RETURN_TYPE (olddecl);
2470 2576
2471 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl); 2577 DECL_DECLARED_INLINE_P (newdecl) |= DECL_DECLARED_INLINE_P (olddecl);
2472 2578
2473 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl) 2579 DECL_UNINLINABLE (newdecl) = DECL_UNINLINABLE (olddecl)
2474 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl)); 2580 = (DECL_UNINLINABLE (newdecl) || DECL_UNINLINABLE (olddecl));
2505 if newdecl is a gnu_inline definition, or if newdecl is just 2611 if newdecl is a gnu_inline definition, or if newdecl is just
2506 a declaration. */ 2612 a declaration. */
2507 if (fndecl_built_in_p (olddecl) 2613 if (fndecl_built_in_p (olddecl)
2508 && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match)) 2614 && (new_defines_function ? GNU_INLINE_P (newdecl) : types_match))
2509 { 2615 {
2510 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); 2616 copy_decl_built_in_function (newdecl, olddecl);
2511 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl);
2512 /* If we're keeping the built-in definition, keep the rtl, 2617 /* If we're keeping the built-in definition, keep the rtl,
2513 regardless of declaration matches. */ 2618 regardless of declaration matches. */
2514 COPY_DECL_RTL (olddecl, newdecl); 2619 COPY_DECL_RTL (olddecl, newdecl);
2515 if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL) 2620 if (DECL_BUILT_IN_CLASS (newdecl) == BUILT_IN_NORMAL)
2516 { 2621 {
2527 default: 2632 default:
2528 if (builtin_decl_explicit_p (fncode)) 2633 if (builtin_decl_explicit_p (fncode))
2529 set_builtin_decl_declared_p (fncode, true); 2634 set_builtin_decl_declared_p (fncode, true);
2530 break; 2635 break;
2531 } 2636 }
2637
2638 copy_attributes_to_builtin (newdecl);
2532 } 2639 }
2533
2534 copy_attributes_to_builtin (newdecl);
2535 } 2640 }
2536 if (new_defines_function) 2641 if (new_defines_function)
2537 /* If defining a function declared with other language 2642 /* If defining a function declared with other language
2538 linkage, use the previously declared language linkage. */ 2643 linkage, use the previously declared language linkage. */
2539 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl)); 2644 SET_DECL_LANGUAGE (newdecl, DECL_LANGUAGE (olddecl));
2872 } 2977 }
2873 else if (TREE_CODE (newdecl) == TEMPLATE_DECL) 2978 else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
2874 { 2979 {
2875 tree nt, ot; 2980 tree nt, ot;
2876 2981
2877 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == TYPE_DECL) 2982 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) == CONCEPT_DECL)
2878 { 2983 return G_("redefinition of %q#D");
2879 if (COMPLETE_TYPE_P (TREE_TYPE (newdecl)) 2984
2880 && COMPLETE_TYPE_P (TREE_TYPE (olddecl))) 2985 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL)
2881 return G_("redefinition of %q#D"); 2986 return redeclaration_error_message (DECL_TEMPLATE_RESULT (newdecl),
2882 return NULL; 2987 DECL_TEMPLATE_RESULT (olddecl));
2883 } 2988
2884 2989 if (DECL_TEMPLATE_RESULT (newdecl) == DECL_TEMPLATE_RESULT (olddecl))
2885 if (TREE_CODE (DECL_TEMPLATE_RESULT (newdecl)) != FUNCTION_DECL
2886 || (DECL_TEMPLATE_RESULT (newdecl)
2887 == DECL_TEMPLATE_RESULT (olddecl)))
2888 return NULL; 2990 return NULL;
2889 2991
2890 nt = DECL_TEMPLATE_RESULT (newdecl); 2992 nt = DECL_TEMPLATE_RESULT (newdecl);
2891 if (DECL_TEMPLATE_INFO (nt)) 2993 if (DECL_TEMPLATE_INFO (nt))
2892 nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt)); 2994 nt = DECL_TEMPLATE_RESULT (template_for_substitution (nt));
3211 location_t loc = input_location; 3313 location_t loc = input_location;
3212 switch (b->kind) 3314 switch (b->kind)
3213 { 3315 {
3214 case sk_try: 3316 case sk_try:
3215 if (!saw_eh) 3317 if (!saw_eh)
3216 inf = N_("enters try block"); 3318 inf = G_(" enters %<try%> block");
3217 saw_eh = true; 3319 saw_eh = true;
3218 break; 3320 break;
3219 3321
3220 case sk_catch: 3322 case sk_catch:
3221 if (!saw_eh) 3323 if (!saw_eh)
3222 inf = N_("enters catch block"); 3324 inf = G_(" enters %<catch%> block");
3223 saw_eh = true; 3325 saw_eh = true;
3224 break; 3326 break;
3225 3327
3226 case sk_omp: 3328 case sk_omp:
3227 if (!saw_omp) 3329 if (!saw_omp)
3228 inf = N_("enters OpenMP structured block"); 3330 inf = G_(" enters OpenMP structured block");
3229 saw_omp = true; 3331 saw_omp = true;
3230 break; 3332 break;
3231 3333
3232 case sk_transaction: 3334 case sk_transaction:
3233 if (!saw_tm) 3335 if (!saw_tm)
3234 inf = N_("enters synchronized or atomic statement"); 3336 inf = G_(" enters synchronized or atomic statement");
3235 saw_tm = true; 3337 saw_tm = true;
3236 break; 3338 break;
3237 3339
3238 case sk_block: 3340 case sk_block:
3239 if (!saw_cxif && level_for_constexpr_if (b->level_chain)) 3341 if (!saw_cxif && level_for_constexpr_if (b->level_chain))
3240 { 3342 {
3241 inf = N_("enters constexpr if statement"); 3343 inf = G_(" enters %<constexpr if%> statement");
3242 loc = EXPR_LOCATION (b->level_chain->this_entity); 3344 loc = EXPR_LOCATION (b->level_chain->this_entity);
3243 saw_cxif = true; 3345 saw_cxif = true;
3244 } 3346 }
3245 break; 3347 break;
3246 3348
3252 { 3354 {
3253 if (identified < 2) 3355 if (identified < 2)
3254 complained = identify_goto (decl, input_location, locus, DK_ERROR); 3356 complained = identify_goto (decl, input_location, locus, DK_ERROR);
3255 identified = 2; 3357 identified = 2;
3256 if (complained) 3358 if (complained)
3257 inform (loc, " %s", inf); 3359 inform (loc, inf);
3258 } 3360 }
3259 } 3361 }
3260 3362
3261 return !identified; 3363 return !identified;
3262 } 3364 }
3347 complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl), 3449 complained = identify_goto (decl, DECL_SOURCE_LOCATION (decl),
3348 &input_location, DK_ERROR); 3450 &input_location, DK_ERROR);
3349 identified = 2; 3451 identified = 2;
3350 } 3452 }
3351 if (complained) 3453 if (complained)
3352 inform (DECL_SOURCE_LOCATION (bad), " enters catch block"); 3454 inform (DECL_SOURCE_LOCATION (bad), " enters %<catch%> block");
3353 saw_catch = true; 3455 saw_catch = true;
3354 } 3456 }
3355 else if (complained) 3457 else if (complained)
3356 { 3458 {
3357 if (u > 1) 3459 if (u > 1)
3365 } 3467 }
3366 3468
3367 if (complained) 3469 if (complained)
3368 { 3470 {
3369 if (ent->in_try_scope) 3471 if (ent->in_try_scope)
3370 inform (input_location, " enters try block"); 3472 inform (input_location, " enters %<try%> block");
3371 else if (ent->in_catch_scope && !saw_catch) 3473 else if (ent->in_catch_scope && !saw_catch)
3372 inform (input_location, " enters catch block"); 3474 inform (input_location, " enters %<catch%> block");
3373 else if (ent->in_transaction_scope) 3475 else if (ent->in_transaction_scope)
3374 inform (input_location, " enters synchronized or atomic statement"); 3476 inform (input_location, " enters synchronized or atomic statement");
3375 else if (ent->in_constexpr_if) 3477 else if (ent->in_constexpr_if)
3376 inform (input_location, " enters %<constexpr%> if statement"); 3478 inform (input_location, " enters %<constexpr if%> statement");
3377 } 3479 }
3378 3480
3379 if (ent->in_omp_scope) 3481 if (ent->in_omp_scope)
3380 { 3482 {
3381 if (complained) 3483 if (complained)
3480 element, or NULL_TREE if there is no high element. Used to 3582 element, or NULL_TREE if there is no high element. Used to
3481 determine whether or not a new case label duplicates an old case 3583 determine whether or not a new case label duplicates an old case
3482 label. We need a tree, rather than simply a hash table, because 3584 label. We need a tree, rather than simply a hash table, because
3483 of the GNU case range extension. */ 3585 of the GNU case range extension. */
3484 splay_tree cases; 3586 splay_tree cases;
3485 /* Remember whether there was a case value that is outside the
3486 range of the original type of the controlling expression. */
3487 bool outside_range_p;
3488 /* Remember whether a default: case label has been seen. */ 3587 /* Remember whether a default: case label has been seen. */
3489 bool has_default_p; 3588 bool has_default_p;
3490 /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT. */ 3589 /* Remember whether a BREAK_STMT has been seen in this SWITCH_STMT. */
3491 bool break_stmt_seen_p; 3590 bool break_stmt_seen_p;
3492 /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch, 3591 /* Set if inside of {FOR,DO,WHILE}_BODY nested inside of a switch,
3511 struct cp_switch *p = XNEW (struct cp_switch); 3610 struct cp_switch *p = XNEW (struct cp_switch);
3512 p->level = current_binding_level; 3611 p->level = current_binding_level;
3513 p->next = switch_stack; 3612 p->next = switch_stack;
3514 p->switch_stmt = switch_stmt; 3613 p->switch_stmt = switch_stmt;
3515 p->cases = splay_tree_new (case_compare, NULL, NULL); 3614 p->cases = splay_tree_new (case_compare, NULL, NULL);
3516 p->outside_range_p = false;
3517 p->has_default_p = false; 3615 p->has_default_p = false;
3518 p->break_stmt_seen_p = false; 3616 p->break_stmt_seen_p = false;
3519 p->in_loop_body_p = false; 3617 p->in_loop_body_p = false;
3520 switch_stack = p; 3618 switch_stack = p;
3521 } 3619 }
3525 { 3623 {
3526 struct cp_switch *cs = switch_stack; 3624 struct cp_switch *cs = switch_stack;
3527 location_t switch_location; 3625 location_t switch_location;
3528 3626
3529 /* Emit warnings as needed. */ 3627 /* Emit warnings as needed. */
3530 switch_location = cp_expr_loc_or_loc (cs->switch_stmt, input_location); 3628 switch_location = cp_expr_loc_or_input_loc (cs->switch_stmt);
3531 const bool bool_cond_p 3629 const bool bool_cond_p
3532 = (SWITCH_STMT_TYPE (cs->switch_stmt) 3630 = (SWITCH_STMT_TYPE (cs->switch_stmt)
3533 && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE); 3631 && TREE_CODE (SWITCH_STMT_TYPE (cs->switch_stmt)) == BOOLEAN_TYPE);
3534 if (!processing_template_decl) 3632 if (!processing_template_decl)
3535 c_do_switch_warnings (cs->cases, switch_location, 3633 c_do_switch_warnings (cs->cases, switch_location,
3536 SWITCH_STMT_TYPE (cs->switch_stmt), 3634 SWITCH_STMT_TYPE (cs->switch_stmt),
3537 SWITCH_STMT_COND (cs->switch_stmt), 3635 SWITCH_STMT_COND (cs->switch_stmt), bool_cond_p);
3538 bool_cond_p, cs->outside_range_p);
3539 3636
3540 /* For the benefit of block_may_fallthru remember if the switch body 3637 /* For the benefit of block_may_fallthru remember if the switch body
3541 case labels cover all possible values and if there are break; stmts. */ 3638 case labels cover all possible values and if there are break; stmts. */
3542 if (cs->has_default_p 3639 if (cs->has_default_p
3543 || (!processing_template_decl 3640 || (!processing_template_decl
3597 if (value == NULL_TREE) 3694 if (value == NULL_TREE)
3598 return value; 3695 return value;
3599 3696
3600 value = mark_rvalue_use (value); 3697 value = mark_rvalue_use (value);
3601 3698
3699 if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
3700 type = type_promotes_to (type);
3701
3702 tree ovalue = value;
3703 /* The constant-expression VALUE shall be a converted constant expression
3704 of the adjusted type of the switch condition, which doesn't allow
3705 narrowing conversions. */
3706 value = build_converted_constant_expr (type, value, tf_warning_or_error);
3707
3602 if (cxx_dialect >= cxx11 3708 if (cxx_dialect >= cxx11
3603 && (SCOPED_ENUM_P (type) 3709 && (SCOPED_ENUM_P (type)
3604 || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (value)))) 3710 || !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (ovalue))))
3605 { 3711 /* Use the converted value. */;
3606 if (INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type)) 3712 else
3607 type = type_promotes_to (type); 3713 /* The already integral case. */
3608 value = (perform_implicit_conversion_flags 3714 value = ovalue;
3609 (type, value, tf_warning_or_error, 3715
3610 LOOKUP_IMPLICIT | LOOKUP_NO_NON_INTEGRAL));
3611 }
3612 return cxx_constant_value (value); 3716 return cxx_constant_value (value);
3613 } 3717 }
3614 3718
3615 /* Note that we've seen a definition of a case label, and complain if this 3719 /* Note that we've seen a definition of a case label, and complain if this
3616 is a bad place for one. */ 3720 is a bad place for one. */
3629 { 3733 {
3630 tree label; 3734 tree label;
3631 3735
3632 /* For templates, just add the case label; we'll do semantic 3736 /* For templates, just add the case label; we'll do semantic
3633 analysis at instantiation-time. */ 3737 analysis at instantiation-time. */
3634 label = build_decl (loc, LABEL_DECL, NULL_TREE, NULL_TREE); 3738 label = build_decl (loc, LABEL_DECL, NULL_TREE, void_type_node);
3635 return add_stmt (build_case_label (low_value, high_value, label)); 3739 return add_stmt (build_case_label (low_value, high_value, label));
3636 } 3740 }
3637 3741
3638 /* Find the condition on which this switch statement depends. */ 3742 /* Find the condition on which this switch statement depends. */
3639 cond = SWITCH_STMT_COND (switch_stack->switch_stmt); 3743 cond = SWITCH_STMT_COND (switch_stack->switch_stmt);
3648 return error_mark_node; 3752 return error_mark_node;
3649 3753
3650 low_value = case_conversion (type, low_value); 3754 low_value = case_conversion (type, low_value);
3651 high_value = case_conversion (type, high_value); 3755 high_value = case_conversion (type, high_value);
3652 3756
3653 r = c_add_case_label (loc, switch_stack->cases, cond, type, 3757 r = c_add_case_label (loc, switch_stack->cases, cond, low_value, high_value);
3654 low_value, high_value,
3655 &switch_stack->outside_range_p);
3656 3758
3657 /* After labels, make any new cleanups in the function go into their 3759 /* After labels, make any new cleanups in the function go into their
3658 own new (temporary) binding contour. */ 3760 own new (temporary) binding contour. */
3659 for (p = current_binding_level; 3761 for (p = current_binding_level;
3660 p->kind != sk_function_parms; 3762 p->kind != sk_function_parms;
3821 return error_mark_node; 3923 return error_mark_node;
3822 } 3924 }
3823 gcc_assert (identifier_p (name)); 3925 gcc_assert (identifier_p (name));
3824 gcc_assert (TYPE_P (context)); 3926 gcc_assert (TYPE_P (context));
3825 3927
3826 if (!MAYBE_CLASS_TYPE_P (context)) 3928 if (TREE_CODE (context) == TYPE_PACK_EXPANSION)
3929 /* This can happen for C++17 variadic using (c++/88986). */;
3930 else if (!MAYBE_CLASS_TYPE_P (context))
3827 { 3931 {
3828 if (complain & tf_error) 3932 if (complain & tf_error)
3829 error ("%q#T is not a class", context); 3933 error ("%q#T is not a class", context);
3830 return error_mark_node; 3934 return error_mark_node;
3831 } 3935 }
4082 {"__delta", &delta_identifier, cik_normal}, 4186 {"__delta", &delta_identifier, cik_normal},
4083 {"__pfn", &pfn_identifier, cik_normal}, 4187 {"__pfn", &pfn_identifier, cik_normal},
4084 {"_vptr", &vptr_identifier, cik_normal}, 4188 {"_vptr", &vptr_identifier, cik_normal},
4085 {"__vtt_parm", &vtt_parm_identifier, cik_normal}, 4189 {"__vtt_parm", &vtt_parm_identifier, cik_normal},
4086 {"::", &global_identifier, cik_normal}, 4190 {"::", &global_identifier, cik_normal},
4087 {"std", &std_identifier, cik_normal},
4088 /* The demangler expects anonymous namespaces to be called 4191 /* The demangler expects anonymous namespaces to be called
4089 something starting with '_GLOBAL__N_'. It no longer needs 4192 something starting with '_GLOBAL__N_'. It no longer needs
4090 to be unique to the TU. */ 4193 to be unique to the TU. */
4091 {"_GLOBAL__N_1", &anon_identifier, cik_normal}, 4194 {"_GLOBAL__N_1", &anon_identifier, cik_normal},
4092 {"auto", &auto_identifier, cik_normal}, 4195 {"auto", &auto_identifier, cik_normal},
4108 {"tuple_size", &tuple_size_identifier, cik_normal}, 4211 {"tuple_size", &tuple_size_identifier, cik_normal},
4109 {"type", &type_identifier, cik_normal}, 4212 {"type", &type_identifier, cik_normal},
4110 {"value", &value_identifier, cik_normal}, 4213 {"value", &value_identifier, cik_normal},
4111 {"_FUN", &fun_identifier, cik_normal}, 4214 {"_FUN", &fun_identifier, cik_normal},
4112 {"__closure", &closure_identifier, cik_normal}, 4215 {"__closure", &closure_identifier, cik_normal},
4216 {"heap uninit", &heap_uninit_identifier, cik_normal},
4217 {"heap ", &heap_identifier, cik_normal},
4218 {"heap deleted", &heap_deleted_identifier, cik_normal},
4113 {NULL, NULL, cik_normal} 4219 {NULL, NULL, cik_normal}
4114 }; 4220 };
4115 4221
4116 for (const predefined_identifier *pid = predefined_identifiers; 4222 for (const predefined_identifier *pid = predefined_identifiers;
4117 pid->name; ++pid) 4223 pid->name; ++pid)
4163 4269
4164 /* Initially, C. */ 4270 /* Initially, C. */
4165 current_lang_name = lang_name_c; 4271 current_lang_name = lang_name_c;
4166 4272
4167 /* Create the `std' namespace. */ 4273 /* Create the `std' namespace. */
4168 push_namespace (std_identifier); 4274 push_namespace (get_identifier ("std"));
4169 std_node = current_namespace; 4275 std_node = current_namespace;
4170 pop_namespace (); 4276 pop_namespace ();
4171 4277
4172 flag_noexcept_type = (cxx_dialect >= cxx17); 4278 flag_noexcept_type = (cxx_dialect >= cxx17);
4173 4279
4176 tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE); 4282 tree bool_ftype = build_function_type_list (boolean_type_node, NULL_TREE);
4177 tree decl 4283 tree decl
4178 = add_builtin_function ("__builtin_is_constant_evaluated", 4284 = add_builtin_function ("__builtin_is_constant_evaluated",
4179 bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED, 4285 bool_ftype, CP_BUILT_IN_IS_CONSTANT_EVALUATED,
4180 BUILT_IN_FRONTEND, NULL, NULL_TREE); 4286 BUILT_IN_FRONTEND, NULL, NULL_TREE);
4287 set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
4288
4289 tree cptr_ftype = build_function_type_list (const_ptr_type_node, NULL_TREE);
4290 decl = add_builtin_function ("__builtin_source_location",
4291 cptr_ftype, CP_BUILT_IN_SOURCE_LOCATION,
4292 BUILT_IN_FRONTEND, NULL, NULL_TREE);
4181 set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF); 4293 set_call_expr_flags (decl, ECF_CONST | ECF_NOTHROW | ECF_LEAF);
4182 4294
4183 integer_two_node = build_int_cst (NULL_TREE, 2); 4295 integer_two_node = build_int_cst (NULL_TREE, 2);
4184 4296
4185 /* Guess at the initial static decls size. */ 4297 /* Guess at the initial static decls size. */
4270 current_lang_name = lang_name_cplusplus; 4382 current_lang_name = lang_name_cplusplus;
4271 4383
4272 if (aligned_new_threshold > 1 4384 if (aligned_new_threshold > 1
4273 && !pow2p_hwi (aligned_new_threshold)) 4385 && !pow2p_hwi (aligned_new_threshold))
4274 { 4386 {
4275 error ("-faligned-new=%d is not a power of two", aligned_new_threshold); 4387 error ("%<-faligned-new=%d%> is not a power of two",
4388 aligned_new_threshold);
4276 aligned_new_threshold = 1; 4389 aligned_new_threshold = 1;
4277 } 4390 }
4278 if (aligned_new_threshold == -1) 4391 if (aligned_new_threshold == -1)
4279 aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0; 4392 aligned_new_threshold = (cxx_dialect >= cxx17) ? 1 : 0;
4280 if (aligned_new_threshold == 1) 4393 if (aligned_new_threshold == 1)
4292 { 4405 {
4293 tree bad_alloc_id; 4406 tree bad_alloc_id;
4294 tree bad_alloc_type_node; 4407 tree bad_alloc_type_node;
4295 tree bad_alloc_decl; 4408 tree bad_alloc_decl;
4296 4409
4297 push_namespace (std_identifier); 4410 push_nested_namespace (std_node);
4298 bad_alloc_id = get_identifier ("bad_alloc"); 4411 bad_alloc_id = get_identifier ("bad_alloc");
4299 bad_alloc_type_node = make_class_type (RECORD_TYPE); 4412 bad_alloc_type_node = make_class_type (RECORD_TYPE);
4300 TYPE_CONTEXT (bad_alloc_type_node) = current_namespace; 4413 TYPE_CONTEXT (bad_alloc_type_node) = current_namespace;
4301 bad_alloc_decl 4414 bad_alloc_decl
4302 = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node); 4415 = create_implicit_typedef (bad_alloc_id, bad_alloc_type_node);
4303 DECL_CONTEXT (bad_alloc_decl) = current_namespace; 4416 DECL_CONTEXT (bad_alloc_decl) = current_namespace;
4304 pop_namespace (); 4417 pop_nested_namespace (std_node);
4305 4418
4306 new_eh_spec 4419 new_eh_spec
4307 = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1); 4420 = add_exception_specifier (NULL_TREE, bad_alloc_type_node, -1);
4308 } 4421 }
4309 else 4422 else
4310 new_eh_spec = noexcept_false_spec; 4423 new_eh_spec = noexcept_false_spec;
4311 4424
4312 /* Ensure attribs.c is initialized. */ 4425 /* Ensure attribs.c is initialized. */
4313 init_attributes (); 4426 init_attributes ();
4314
4315 /* Ensure constraint.cc is initialized. */
4316 init_constraint_processing ();
4317 4427
4318 extvisattr = build_tree_list (get_identifier ("externally_visible"), 4428 extvisattr = build_tree_list (get_identifier ("externally_visible"),
4319 NULL_TREE); 4429 NULL_TREE);
4320 newattrs = tree_cons (get_identifier ("alloc_size"), 4430 newattrs = tree_cons (get_identifier ("alloc_size"),
4321 build_tree_list (NULL_TREE, integer_one_node), 4431 build_tree_list (NULL_TREE, integer_one_node),
4324 newtype = build_exception_variant (newtype, new_eh_spec); 4434 newtype = build_exception_variant (newtype, new_eh_spec);
4325 deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr); 4435 deltype = cp_build_type_attribute_variant (void_ftype_ptr, extvisattr);
4326 deltype = build_exception_variant (deltype, empty_except_spec); 4436 deltype = build_exception_variant (deltype, empty_except_spec);
4327 tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0); 4437 tree opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
4328 DECL_IS_MALLOC (opnew) = 1; 4438 DECL_IS_MALLOC (opnew) = 1;
4329 DECL_IS_OPERATOR_NEW (opnew) = 1; 4439 DECL_SET_IS_OPERATOR_NEW (opnew, true);
4330 opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0); 4440 opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
4331 DECL_IS_MALLOC (opnew) = 1; 4441 DECL_IS_MALLOC (opnew) = 1;
4332 DECL_IS_OPERATOR_NEW (opnew) = 1; 4442 DECL_SET_IS_OPERATOR_NEW (opnew, true);
4333 push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW); 4443 tree opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
4334 push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW); 4444 DECL_SET_IS_OPERATOR_DELETE (opdel, true);
4445 opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
4446 DECL_SET_IS_OPERATOR_DELETE (opdel, true);
4335 if (flag_sized_deallocation) 4447 if (flag_sized_deallocation)
4336 { 4448 {
4337 /* Also push the sized deallocation variants: 4449 /* Also push the sized deallocation variants:
4338 void operator delete(void*, std::size_t) throw(); 4450 void operator delete(void*, std::size_t) throw();
4339 void operator delete[](void*, std::size_t) throw(); */ 4451 void operator delete[](void*, std::size_t) throw(); */
4341 = build_function_type_list (void_type_node, ptr_type_node, 4453 = build_function_type_list (void_type_node, ptr_type_node,
4342 size_type_node, NULL_TREE); 4454 size_type_node, NULL_TREE);
4343 deltype = cp_build_type_attribute_variant (void_ftype_ptr_size, 4455 deltype = cp_build_type_attribute_variant (void_ftype_ptr_size,
4344 extvisattr); 4456 extvisattr);
4345 deltype = build_exception_variant (deltype, empty_except_spec); 4457 deltype = build_exception_variant (deltype, empty_except_spec);
4346 push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW); 4458 opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
4347 push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW); 4459 DECL_SET_IS_OPERATOR_DELETE (opdel, true);
4460 opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
4461 DECL_SET_IS_OPERATOR_DELETE (opdel, true);
4348 } 4462 }
4349 4463
4350 if (aligned_new_threshold) 4464 if (aligned_new_threshold)
4351 { 4465 {
4352 push_namespace (std_identifier); 4466 push_nested_namespace (std_node);
4353 tree align_id = get_identifier ("align_val_t"); 4467 tree align_id = get_identifier ("align_val_t");
4354 align_type_node = start_enum (align_id, NULL_TREE, size_type_node, 4468 align_type_node = start_enum (align_id, NULL_TREE, size_type_node,
4355 NULL_TREE, /*scoped*/true, NULL); 4469 NULL_TREE, /*scoped*/true, NULL);
4356 pop_namespace (); 4470 pop_nested_namespace (std_node);
4357 4471
4358 /* operator new (size_t, align_val_t); */ 4472 /* operator new (size_t, align_val_t); */
4359 newtype = build_function_type_list (ptr_type_node, size_type_node, 4473 newtype = build_function_type_list (ptr_type_node, size_type_node,
4360 align_type_node, NULL_TREE); 4474 align_type_node, NULL_TREE);
4361 newtype = cp_build_type_attribute_variant (newtype, newattrs); 4475 newtype = cp_build_type_attribute_variant (newtype, newattrs);
4362 newtype = build_exception_variant (newtype, new_eh_spec); 4476 newtype = build_exception_variant (newtype, new_eh_spec);
4363 opnew = push_cp_library_fn (NEW_EXPR, newtype, 0); 4477 opnew = push_cp_library_fn (NEW_EXPR, newtype, 0);
4364 DECL_IS_MALLOC (opnew) = 1; 4478 DECL_IS_MALLOC (opnew) = 1;
4365 DECL_IS_OPERATOR_NEW (opnew) = 1; 4479 DECL_SET_IS_OPERATOR_NEW (opnew, true);
4366 opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0); 4480 opnew = push_cp_library_fn (VEC_NEW_EXPR, newtype, 0);
4367 DECL_IS_MALLOC (opnew) = 1; 4481 DECL_IS_MALLOC (opnew) = 1;
4368 DECL_IS_OPERATOR_NEW (opnew) = 1; 4482 DECL_SET_IS_OPERATOR_NEW (opnew, true);
4369 4483
4370 /* operator delete (void *, align_val_t); */ 4484 /* operator delete (void *, align_val_t); */
4371 deltype = build_function_type_list (void_type_node, ptr_type_node, 4485 deltype = build_function_type_list (void_type_node, ptr_type_node,
4372 align_type_node, NULL_TREE); 4486 align_type_node, NULL_TREE);
4373 deltype = cp_build_type_attribute_variant (deltype, extvisattr); 4487 deltype = cp_build_type_attribute_variant (deltype, extvisattr);
4374 deltype = build_exception_variant (deltype, empty_except_spec); 4488 deltype = build_exception_variant (deltype, empty_except_spec);
4375 push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW); 4489 opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
4376 push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW); 4490 DECL_SET_IS_OPERATOR_DELETE (opdel, true);
4491 opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
4492 DECL_SET_IS_OPERATOR_DELETE (opdel, true);
4377 4493
4378 if (flag_sized_deallocation) 4494 if (flag_sized_deallocation)
4379 { 4495 {
4380 /* operator delete (void *, size_t, align_val_t); */ 4496 /* operator delete (void *, size_t, align_val_t); */
4381 deltype = build_function_type_list (void_type_node, ptr_type_node, 4497 deltype = build_function_type_list (void_type_node, ptr_type_node,
4382 size_type_node, align_type_node, 4498 size_type_node, align_type_node,
4383 NULL_TREE); 4499 NULL_TREE);
4384 deltype = cp_build_type_attribute_variant (deltype, extvisattr); 4500 deltype = cp_build_type_attribute_variant (deltype, extvisattr);
4385 deltype = build_exception_variant (deltype, empty_except_spec); 4501 deltype = build_exception_variant (deltype, empty_except_spec);
4386 push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW); 4502 opdel = push_cp_library_fn (DELETE_EXPR, deltype, ECF_NOTHROW);
4387 push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW); 4503 DECL_SET_IS_OPERATOR_DELETE (opdel, true);
4504 opdel = push_cp_library_fn (VEC_DELETE_EXPR, deltype, ECF_NOTHROW);
4505 DECL_SET_IS_OPERATOR_DELETE (opdel, true);
4388 } 4506 }
4389 } 4507 }
4390 4508
4391 nullptr_type_node = make_node (NULLPTR_TYPE); 4509 nullptr_type_node = make_node (NULLPTR_TYPE);
4392 TYPE_SIZE (nullptr_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode)); 4510 TYPE_SIZE (nullptr_type_node) = bitsize_int (GET_MODE_BITSIZE (ptr_mode));
4463 at the point of first use, so we mustn't push the decl now. */ 4581 at the point of first use, so we mustn't push the decl now. */
4464 4582
4465 static tree 4583 static tree
4466 cp_make_fname_decl (location_t loc, tree id, int type_dep) 4584 cp_make_fname_decl (location_t loc, tree id, int type_dep)
4467 { 4585 {
4468 const char *const name = (type_dep && processing_template_decl 4586 const char * name = NULL;
4469 ? NULL : fname_as_string (type_dep)); 4587 bool release_name = false;
4588 if (!(type_dep && in_template_function ()))
4589 {
4590 if (current_function_decl == NULL_TREE)
4591 name = "top level";
4592 else if (type_dep == 1) /* __PRETTY_FUNCTION__ */
4593 name = cxx_printable_name (current_function_decl, 2);
4594 else if (type_dep == 0) /* __FUNCTION__ */
4595 {
4596 name = fname_as_string (type_dep);
4597 release_name = true;
4598 }
4599 else
4600 gcc_unreachable ();
4601 }
4470 tree type; 4602 tree type;
4471 tree init = cp_fname_init (name, &type); 4603 tree init = cp_fname_init (name, &type);
4472 tree decl = build_decl (loc, VAR_DECL, id, type); 4604 tree decl = build_decl (loc, VAR_DECL, id, type);
4473 4605
4474 if (name) 4606 if (release_name)
4475 free (CONST_CAST (char *, name)); 4607 free (CONST_CAST (char *, name));
4476 4608
4477 TREE_STATIC (decl) = 1; 4609 /* As we're using pushdecl_with_scope, we must set the context. */
4610 DECL_CONTEXT (decl) = current_function_decl;
4611
4478 TREE_READONLY (decl) = 1; 4612 TREE_READONLY (decl) = 1;
4479 DECL_ARTIFICIAL (decl) = 1; 4613 DECL_ARTIFICIAL (decl) = 1;
4614 DECL_DECLARED_CONSTEXPR_P (decl) = 1;
4615 TREE_STATIC (decl) = 1;
4480 4616
4481 TREE_USED (decl) = 1; 4617 TREE_USED (decl) = 1;
4618
4619 if (init)
4620 {
4621 SET_DECL_VALUE_EXPR (decl, init);
4622 DECL_HAS_VALUE_EXPR_P (decl) = 1;
4623 /* For decl_constant_var_p. */
4624 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1;
4625 }
4482 4626
4483 if (current_function_decl) 4627 if (current_function_decl)
4484 { 4628 {
4485 DECL_CONTEXT (decl) = current_function_decl; 4629 DECL_CONTEXT (decl) = current_function_decl;
4486 decl = pushdecl_outermost_localscope (decl); 4630 decl = pushdecl_outermost_localscope (decl);
4487 cp_finish_decl (decl, init, /*init_const_expr_p=*/false, NULL_TREE, 4631 if (decl != error_mark_node)
4488 LOOKUP_ONLYCONVERTING); 4632 add_decl_expr (decl);
4489 } 4633 }
4490 else 4634 else
4491 { 4635 {
4492 DECL_THIS_STATIC (decl) = true; 4636 DECL_THIS_STATIC (decl) = true;
4493 pushdecl_top_level_and_finish (decl, init); 4637 pushdecl_top_level_and_finish (decl, NULL_TREE);
4494 } 4638 }
4495 4639
4496 return decl; 4640 return decl;
4497 } 4641 }
4498 4642
4499 static tree 4643 /* Install DECL as a builtin function at current (global) scope.
4500 builtin_function_1 (tree decl, tree context, bool is_global) 4644 Return the new decl (if we found an existing version). Also
4501 { 4645 installs it into ::std, if it's not '_*'. */
4502 tree id = DECL_NAME (decl); 4646
4503 const char *name = IDENTIFIER_POINTER (id); 4647 tree
4504 4648 cxx_builtin_function (tree decl)
4649 {
4505 retrofit_lang_decl (decl); 4650 retrofit_lang_decl (decl);
4506 4651
4507 DECL_ARTIFICIAL (decl) = 1; 4652 DECL_ARTIFICIAL (decl) = 1;
4508 SET_DECL_LANGUAGE (decl, lang_c); 4653 SET_DECL_LANGUAGE (decl, lang_c);
4509 /* Runtime library routines are, by definition, available in an 4654 /* Runtime library routines are, by definition, available in an
4510 external shared object. */ 4655 external shared object. */
4511 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; 4656 DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
4512 DECL_VISIBILITY_SPECIFIED (decl) = 1; 4657 DECL_VISIBILITY_SPECIFIED (decl) = 1;
4513 4658
4514 DECL_CONTEXT (decl) = context; 4659 tree id = DECL_NAME (decl);
4515 4660 const char *name = IDENTIFIER_POINTER (id);
4516 /* A function in the user's namespace should have an explicit
4517 declaration before it is used. Mark the built-in function as
4518 anticipated but not actually declared. */
4519 if (name[0] != '_' || name[1] != '_') 4661 if (name[0] != '_' || name[1] != '_')
4662 /* In the user's namespace, it must be declared before use. */
4520 DECL_ANTICIPATED (decl) = 1; 4663 DECL_ANTICIPATED (decl) = 1;
4521 else if (strncmp (name + 2, "builtin_", strlen ("builtin_")) != 0) 4664 else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
4522 { 4665 && 0 != strncmp (name + 2, "builtin_", strlen ("builtin_"))
4523 size_t len = strlen (name); 4666 && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
4524 4667 "_chk", strlen ("_chk") + 1))
4525 /* Treat __*_chk fortification functions as anticipated as well, 4668 /* Treat __*_chk fortification functions as anticipated as well,
4526 unless they are __builtin_*. */ 4669 unless they are __builtin_*_chk. */
4527 if (len > strlen ("___chk") 4670 DECL_ANTICIPATED (decl) = 1;
4528 && memcmp (name + len - strlen ("_chk"), 4671
4529 "_chk", strlen ("_chk") + 1) == 0)
4530 DECL_ANTICIPATED (decl) = 1;
4531 }
4532
4533 if (is_global)
4534 pushdecl_top_level (decl);
4535 else
4536 pushdecl (decl);
4537
4538 return decl;
4539 }
4540
4541 tree
4542 cxx_builtin_function (tree decl)
4543 {
4544 tree id = DECL_NAME (decl);
4545 const char *name = IDENTIFIER_POINTER (id);
4546 /* All builtins that don't begin with an '_' should additionally 4672 /* All builtins that don't begin with an '_' should additionally
4547 go in the 'std' namespace. */ 4673 go in the 'std' namespace. */
4548 if (name[0] != '_') 4674 if (name[0] != '_')
4549 { 4675 {
4550 tree decl2 = copy_node(decl); 4676 tree std_decl = copy_decl (decl);
4551 push_namespace (std_identifier); 4677
4552 builtin_function_1 (decl2, std_node, false); 4678 push_nested_namespace (std_node);
4553 pop_namespace (); 4679 DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
4554 } 4680 pushdecl (std_decl);
4555 4681 pop_nested_namespace (std_node);
4556 return builtin_function_1 (decl, NULL_TREE, false); 4682 }
4683
4684 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
4685 decl = pushdecl (decl);
4686
4687 return decl;
4557 } 4688 }
4558 4689
4559 /* Like cxx_builtin_function, but guarantee the function is added to the global 4690 /* Like cxx_builtin_function, but guarantee the function is added to the global
4560 scope. This is to allow function specific options to add new machine 4691 scope. This is to allow function specific options to add new machine
4561 dependent builtins when the target ISA changes via attribute((target(...))) 4692 dependent builtins when the target ISA changes via attribute((target(...)))
4563 ISAs. */ 4694 ISAs. */
4564 4695
4565 tree 4696 tree
4566 cxx_builtin_function_ext_scope (tree decl) 4697 cxx_builtin_function_ext_scope (tree decl)
4567 { 4698 {
4568 4699 push_nested_namespace (global_namespace);
4569 tree id = DECL_NAME (decl); 4700 decl = cxx_builtin_function (decl);
4570 const char *name = IDENTIFIER_POINTER (id); 4701 pop_nested_namespace (global_namespace);
4571 /* All builtins that don't begin with an '_' should additionally 4702
4572 go in the 'std' namespace. */ 4703 return decl;
4573 if (name[0] != '_') 4704 }
4574 { 4705
4575 tree decl2 = copy_node(decl); 4706 /* Implement LANG_HOOKS_SIMULATE_BUILTIN_FUNCTION_DECL. */
4576 push_namespace (std_identifier); 4707
4577 builtin_function_1 (decl2, std_node, true); 4708 tree
4578 pop_namespace (); 4709 cxx_simulate_builtin_function_decl (tree decl)
4579 } 4710 {
4580 4711 retrofit_lang_decl (decl);
4581 return builtin_function_1 (decl, NULL_TREE, true); 4712
4713 DECL_ARTIFICIAL (decl) = 1;
4714 SET_DECL_LANGUAGE (decl, lang_cplusplus);
4715 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
4716 return pushdecl (decl);
4582 } 4717 }
4583 4718
4584 /* Generate a FUNCTION_DECL with the typical flags for a runtime library 4719 /* Generate a FUNCTION_DECL with the typical flags for a runtime library
4585 function. Not called directly. */ 4720 function. Not called directly. */
4586 4721
4745 /* Warn for an attribute located at LOCATION that appertains to the 4880 /* Warn for an attribute located at LOCATION that appertains to the
4746 class type CLASS_TYPE that has not been properly placed after its 4881 class type CLASS_TYPE that has not been properly placed after its
4747 class-key, in it class-specifier. */ 4882 class-key, in it class-specifier. */
4748 4883
4749 void 4884 void
4750 warn_misplaced_attr_for_class_type (source_location location, 4885 warn_misplaced_attr_for_class_type (location_t location,
4751 tree class_type) 4886 tree class_type)
4752 { 4887 {
4753 gcc_assert (OVERLOAD_TYPE_P (class_type)); 4888 gcc_assert (OVERLOAD_TYPE_P (class_type));
4754 4889
4755 auto_diagnostic_group d; 4890 auto_diagnostic_group d;
4757 "attribute ignored in declaration " 4892 "attribute ignored in declaration "
4758 "of %q#T", class_type)) 4893 "of %q#T", class_type))
4759 inform (location, 4894 inform (location,
4760 "attribute for %q#T must follow the %qs keyword", 4895 "attribute for %q#T must follow the %qs keyword",
4761 class_type, class_key_or_enum_as_string (class_type)); 4896 class_type, class_key_or_enum_as_string (class_type));
4897 }
4898
4899 /* Returns the cv-qualifiers that apply to the type specified
4900 by the DECLSPECS. */
4901
4902 static int
4903 get_type_quals (const cp_decl_specifier_seq *declspecs)
4904 {
4905 int type_quals = TYPE_UNQUALIFIED;
4906
4907 if (decl_spec_seq_has_spec_p (declspecs, ds_const))
4908 type_quals |= TYPE_QUAL_CONST;
4909 if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
4910 type_quals |= TYPE_QUAL_VOLATILE;
4911 if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
4912 type_quals |= TYPE_QUAL_RESTRICT;
4913
4914 return type_quals;
4762 } 4915 }
4763 4916
4764 /* Make sure that a declaration with no declarator is well-formed, i.e. 4917 /* Make sure that a declaration with no declarator is well-formed, i.e.
4765 just declares a tagged type or anonymous union. 4918 just declares a tagged type or anonymous union.
4766 4919
4778 DECLARED_TYPE is set to the corresponding type. */ 4931 DECLARED_TYPE is set to the corresponding type. */
4779 tree declared_type = NULL_TREE; 4932 tree declared_type = NULL_TREE;
4780 bool error_p = false; 4933 bool error_p = false;
4781 4934
4782 if (declspecs->multiple_types_p) 4935 if (declspecs->multiple_types_p)
4783 error ("multiple types in one declaration"); 4936 error_at (smallest_type_location (declspecs),
4937 "multiple types in one declaration");
4784 else if (declspecs->redefined_builtin_type) 4938 else if (declspecs->redefined_builtin_type)
4785 { 4939 {
4786 if (!in_system_header_at (input_location)) 4940 location_t loc = declspecs->locations[ds_redefined_builtin_type_spec];
4787 permerror (declspecs->locations[ds_redefined_builtin_type_spec], 4941 if (!in_system_header_at (loc))
4788 "redeclaration of C++ built-in type %qT", 4942 permerror (loc, "redeclaration of C++ built-in type %qT",
4789 declspecs->redefined_builtin_type); 4943 declspecs->redefined_builtin_type);
4790 return NULL_TREE; 4944 return NULL_TREE;
4791 } 4945 }
4792 4946
4793 if (declspecs->type 4947 if (declspecs->type
4796 && MAYBE_CLASS_TYPE_P (declspecs->type)) 4950 && MAYBE_CLASS_TYPE_P (declspecs->type))
4797 || TREE_CODE (declspecs->type) == ENUMERAL_TYPE)) 4951 || TREE_CODE (declspecs->type) == ENUMERAL_TYPE))
4798 declared_type = declspecs->type; 4952 declared_type = declspecs->type;
4799 else if (declspecs->type == error_mark_node) 4953 else if (declspecs->type == error_mark_node)
4800 error_p = true; 4954 error_p = true;
4801 if (declared_type == NULL_TREE && ! saw_friend && !error_p) 4955
4802 permerror (input_location, "declaration does not declare anything"); 4956 if (type_uses_auto (declared_type))
4803 else if (declared_type != NULL_TREE && type_uses_auto (declared_type))
4804 { 4957 {
4805 error_at (declspecs->locations[ds_type_spec], 4958 error_at (declspecs->locations[ds_type_spec],
4806 "%<auto%> can only be specified for variables " 4959 "%<auto%> can only be specified for variables "
4807 "or function declarations"); 4960 "or function declarations");
4808 return error_mark_node; 4961 return error_mark_node;
4809 } 4962 }
4963
4964 if (declared_type && !OVERLOAD_TYPE_P (declared_type))
4965 declared_type = NULL_TREE;
4966
4967 if (!declared_type && !saw_friend && !error_p)
4968 permerror (input_location, "declaration does not declare anything");
4810 /* Check for an anonymous union. */ 4969 /* Check for an anonymous union. */
4811 else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type)) 4970 else if (declared_type && RECORD_OR_UNION_CODE_P (TREE_CODE (declared_type))
4812 && TYPE_UNNAMED_P (declared_type)) 4971 && TYPE_UNNAMED_P (declared_type))
4813 { 4972 {
4814 /* 7/3 In a simple-declaration, the optional init-declarator-list 4973 /* 7/3 In a simple-declaration, the optional init-declarator-list
4827 enum { }; // ill-formed 4986 enum { }; // ill-formed
4828 typedef class { }; // ill-formed 4987 typedef class { }; // ill-formed
4829 --end example] */ 4988 --end example] */
4830 if (saw_typedef) 4989 if (saw_typedef)
4831 { 4990 {
4832 error ("missing type-name in typedef-declaration"); 4991 error_at (declspecs->locations[ds_typedef],
4992 "missing type-name in typedef-declaration");
4833 return NULL_TREE; 4993 return NULL_TREE;
4834 } 4994 }
4835 /* Anonymous unions are objects, so they can have specifiers. */; 4995 /* Anonymous unions are objects, so they can have specifiers. */;
4836 SET_ANON_AGGR_TYPE_P (declared_type); 4996 SET_ANON_AGGR_TYPE_P (declared_type);
4837 4997
4838 if (TREE_CODE (declared_type) != UNION_TYPE 4998 if (TREE_CODE (declared_type) != UNION_TYPE)
4839 && !in_system_header_at (input_location)) 4999 pedwarn (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (declared_type)),
4840 pedwarn (input_location, OPT_Wpedantic, "ISO C++ prohibits anonymous structs"); 5000 OPT_Wpedantic, "ISO C++ prohibits anonymous structs");
4841 } 5001 }
4842 5002
4843 else 5003 else
4844 { 5004 {
4845 if (decl_spec_seq_has_spec_p (declspecs, ds_inline)) 5005 if (decl_spec_seq_has_spec_p (declspecs, ds_inline))
4877 "%<__thread%> can only be specified for objects " 5037 "%<__thread%> can only be specified for objects "
4878 "and functions"); 5038 "and functions");
4879 else if (saw_typedef) 5039 else if (saw_typedef)
4880 warning_at (declspecs->locations[ds_typedef], 0, 5040 warning_at (declspecs->locations[ds_typedef], 0,
4881 "%<typedef%> was ignored in this declaration"); 5041 "%<typedef%> was ignored in this declaration");
4882 else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr)) 5042 else if (decl_spec_seq_has_spec_p (declspecs, ds_constexpr))
4883 error_at (declspecs->locations[ds_constexpr], 5043 error_at (declspecs->locations[ds_constexpr],
4884 "%<constexpr%> cannot be used for type declarations"); 5044 "%qs cannot be used for type declarations", "constexpr");
5045 else if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
5046 error_at (declspecs->locations[ds_constinit],
5047 "%qs cannot be used for type declarations", "constinit");
5048 else if (decl_spec_seq_has_spec_p (declspecs, ds_consteval))
5049 error_at (declspecs->locations[ds_consteval],
5050 "%qs cannot be used for type declarations", "consteval");
4885 } 5051 }
4886 5052
4887 if (declspecs->attributes && warn_attributes && declared_type) 5053 if (declspecs->attributes && warn_attributes && declared_type)
4888 { 5054 {
4889 location_t loc; 5055 location_t loc;
5049 If not, set INITIALIZED to zero, which will indirectly 5215 If not, set INITIALIZED to zero, which will indirectly
5050 tell `cp_finish_decl' to ignore the initializer once it is parsed. */ 5216 tell `cp_finish_decl' to ignore the initializer once it is parsed. */
5051 if (initialized 5217 if (initialized
5052 && TREE_CODE (decl) == TYPE_DECL) 5218 && TREE_CODE (decl) == TYPE_DECL)
5053 { 5219 {
5054 error ("typedef %qD is initialized (use decltype instead)", decl); 5220 error_at (DECL_SOURCE_LOCATION (decl),
5221 "typedef %qD is initialized (use %qs instead)",
5222 decl, "decltype");
5055 return error_mark_node; 5223 return error_mark_node;
5056 } 5224 }
5057 5225
5058 if (initialized) 5226 if (initialized)
5059 { 5227 {
5086 can be initialized in-class and dllimported) go through grokfield, 5254 can be initialized in-class and dllimported) go through grokfield,
5087 not here, so we don't need to exclude those decls when checking for 5255 not here, so we don't need to exclude those decls when checking for
5088 a definition. */ 5256 a definition. */
5089 if (initialized && DECL_DLLIMPORT_P (decl)) 5257 if (initialized && DECL_DLLIMPORT_P (decl))
5090 { 5258 {
5091 error ("definition of %q#D is marked %<dllimport%>", decl); 5259 error_at (DECL_SOURCE_LOCATION (decl),
5260 "definition of %q#D is marked %<dllimport%>", decl);
5092 DECL_DLLIMPORT_P (decl) = 0; 5261 DECL_DLLIMPORT_P (decl) = 0;
5093 } 5262 }
5094 5263
5095 /* If #pragma weak was used, mark the decl weak now. */ 5264 /* If #pragma weak was used, mark the decl weak now. */
5096 if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl)) 5265 if (!processing_template_decl && !DECL_DECOMPOSITION_P (decl))
5099 if (TREE_CODE (decl) == FUNCTION_DECL 5268 if (TREE_CODE (decl) == FUNCTION_DECL
5100 && DECL_DECLARED_INLINE_P (decl) 5269 && DECL_DECLARED_INLINE_P (decl)
5101 && DECL_UNINLINABLE (decl) 5270 && DECL_UNINLINABLE (decl)
5102 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl))) 5271 && lookup_attribute ("noinline", DECL_ATTRIBUTES (decl)))
5103 warning_at (DECL_SOURCE_LOCATION (decl), 0, 5272 warning_at (DECL_SOURCE_LOCATION (decl), 0,
5104 "inline function %qD given attribute noinline", decl); 5273 "inline function %qD given attribute %qs", decl, "noinline");
5105 5274
5106 if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context))) 5275 if (TYPE_P (context) && COMPLETE_TYPE_P (complete_type (context)))
5107 { 5276 {
5108 bool this_tmpl = (processing_template_decl 5277 bool this_tmpl = (processing_template_decl
5109 > template_class_depth (context)); 5278 > template_class_depth (context));
5192 } 5361 }
5193 5362
5194 if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl) 5363 if (DECL_EXTERNAL (decl) && ! DECL_TEMPLATE_SPECIALIZATION (decl)
5195 /* Aliases are definitions. */ 5364 /* Aliases are definitions. */
5196 && !alias) 5365 && !alias)
5197 permerror (input_location, "declaration of %q#D outside of class is not definition", 5366 permerror (declarator->id_loc,
5367 "declaration of %q#D outside of class is not definition",
5198 decl); 5368 decl);
5199 } 5369 }
5200 5370
5201 was_public = TREE_PUBLIC (decl); 5371 was_public = TREE_PUBLIC (decl);
5202 5372
5205 if (!template_parm_scope_p () 5375 if (!template_parm_scope_p ()
5206 || !VAR_P (decl)) 5376 || !VAR_P (decl))
5207 decl = maybe_push_decl (decl); 5377 decl = maybe_push_decl (decl);
5208 5378
5209 if (processing_template_decl) 5379 if (processing_template_decl)
5210 decl = push_template_decl (decl); 5380 {
5381 /* Make sure that for a `constinit' decl push_template_decl creates
5382 a DECL_TEMPLATE_INFO info for us, so that cp_finish_decl can then set
5383 TINFO_VAR_DECLARED_CONSTINIT. */
5384 if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
5385 retrofit_lang_decl (decl);
5386 decl = push_template_decl (decl);
5387 }
5211 if (decl == error_mark_node) 5388 if (decl == error_mark_node)
5212 return error_mark_node; 5389 return error_mark_node;
5213 5390
5214 if (VAR_P (decl) 5391 if (VAR_P (decl)
5215 && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public 5392 && DECL_NAMESPACE_SCOPE_P (decl) && !TREE_PUBLIC (decl) && !was_public
5225 if (current_function_decl && VAR_P (decl) 5402 if (current_function_decl && VAR_P (decl)
5226 && DECL_DECLARED_CONSTEXPR_P (current_function_decl)) 5403 && DECL_DECLARED_CONSTEXPR_P (current_function_decl))
5227 { 5404 {
5228 bool ok = false; 5405 bool ok = false;
5229 if (CP_DECL_THREAD_LOCAL_P (decl)) 5406 if (CP_DECL_THREAD_LOCAL_P (decl))
5230 error ("%qD declared %<thread_local%> in %<constexpr%> function", 5407 error_at (DECL_SOURCE_LOCATION (decl),
5231 decl); 5408 "%qD declared %<thread_local%> in %qs function", decl,
5409 DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
5410 ? "consteval" : "constexpr");
5232 else if (TREE_STATIC (decl)) 5411 else if (TREE_STATIC (decl))
5233 error ("%qD declared %<static%> in %<constexpr%> function", decl); 5412 error_at (DECL_SOURCE_LOCATION (decl),
5413 "%qD declared %<static%> in %qs function", decl,
5414 DECL_IMMEDIATE_FUNCTION_P (current_function_decl)
5415 ? "consteval" : "constexpr");
5234 else 5416 else
5235 ok = true; 5417 ok = true;
5236 if (!ok) 5418 if (!ok)
5237 cp_function_chain->invalid_constexpr = true; 5419 cp_function_chain->invalid_constexpr = true;
5238 } 5420 }
5282 was "const", but incomplete, before this point. But, now, we 5464 was "const", but incomplete, before this point. But, now, we
5283 have a complete type, so we can try again. */ 5465 have a complete type, so we can try again. */
5284 cp_apply_type_quals_to_decl (cp_type_quals (type), decl); 5466 cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
5285 } 5467 }
5286 5468
5469 if (is_global_var (decl))
5470 {
5471 type_context_kind context = (DECL_THREAD_LOCAL_P (decl)
5472 ? TCTX_THREAD_STORAGE
5473 : TCTX_STATIC_STORAGE);
5474 verify_type_context (input_location, context, TREE_TYPE (decl));
5475 }
5287 if (initialized) 5476 if (initialized)
5288 /* Is it valid for this decl to have an initializer at all? */ 5477 /* Is it valid for this decl to have an initializer at all? */
5289 { 5478 {
5290 /* Don't allow initializations for incomplete types except for 5479 /* Don't allow initializations for incomplete types except for
5291 arrays which might be completed by the initialization. */ 5480 arrays which might be completed by the initialization. */
5344 if (init == NULL_TREE) 5533 if (init == NULL_TREE)
5345 { 5534 {
5346 if ((DECL_LANG_SPECIFIC (decl) == 0 5535 if ((DECL_LANG_SPECIFIC (decl) == 0
5347 || DECL_IN_AGGR_P (decl) == 0) 5536 || DECL_IN_AGGR_P (decl) == 0)
5348 && ! DECL_THIS_EXTERN (decl)) 5537 && ! DECL_THIS_EXTERN (decl))
5349 error ("%qD declared as reference but not initialized", decl); 5538 error_at (DECL_SOURCE_LOCATION (decl),
5539 "%qD declared as reference but not initialized", decl);
5350 return NULL_TREE; 5540 return NULL_TREE;
5351 } 5541 }
5352 5542
5543 tree ttype = TREE_TYPE (type);
5353 if (TREE_CODE (init) == TREE_LIST) 5544 if (TREE_CODE (init) == TREE_LIST)
5354 init = build_x_compound_expr_from_list (init, ELK_INIT, 5545 {
5355 tf_warning_or_error); 5546 /* This handles (C++20 only) code like
5356 5547
5357 tree ttype = TREE_TYPE (type); 5548 const A& r(1, 2, 3);
5549
5550 where we treat the parenthesized list as a CONSTRUCTOR. */
5551 if (TREE_TYPE (init) == NULL_TREE
5552 && CP_AGGREGATE_TYPE_P (ttype)
5553 && !DECL_DECOMPOSITION_P (decl)
5554 && (cxx_dialect >= cxx2a))
5555 {
5556 init = build_constructor_from_list (init_list_type_node, init);
5557 CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
5558 CONSTRUCTOR_IS_PAREN_INIT (init) = true;
5559 }
5560 else
5561 init = build_x_compound_expr_from_list (init, ELK_INIT,
5562 tf_warning_or_error);
5563 }
5564
5358 if (TREE_CODE (ttype) != ARRAY_TYPE 5565 if (TREE_CODE (ttype) != ARRAY_TYPE
5359 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE) 5566 && TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
5360 /* Note: default conversion is only called in very special cases. */ 5567 /* Note: default conversion is only called in very special cases. */
5361 init = decay_conversion (init, tf_warning_or_error); 5568 init = decay_conversion (init, tf_warning_or_error);
5362 5569
5429 } 5636 }
5430 else 5637 else
5431 sorry ("non-trivial designated initializers not supported"); 5638 sorry ("non-trivial designated initializers not supported");
5432 } 5639 }
5433 else 5640 else
5434 error ("C99 designator %qE is not an integral constant-expression", 5641 error_at (cp_expr_loc_or_input_loc (ce->index),
5435 ce->index); 5642 "C99 designator %qE is not an integral constant-expression",
5643 ce->index);
5436 5644
5437 return false; 5645 return false;
5438 } 5646 }
5439 5647
5440 return true; 5648 return true;
5616 /* While for initialized variables, we must use internal 5824 /* While for initialized variables, we must use internal
5617 linkage -- which means that multiple copies will not 5825 linkage -- which means that multiple copies will not
5618 be merged. */ 5826 be merged. */
5619 TREE_PUBLIC (decl) = 0; 5827 TREE_PUBLIC (decl) = 0;
5620 DECL_COMMON (decl) = 0; 5828 DECL_COMMON (decl) = 0;
5829 DECL_INTERFACE_KNOWN (decl) = 1;
5621 const char *msg; 5830 const char *msg;
5622 if (DECL_INLINE_VAR_P (decl)) 5831 if (DECL_INLINE_VAR_P (decl))
5623 msg = G_("sorry: semantics of inline variable " 5832 msg = G_("sorry: semantics of inline variable "
5624 "%q#D are wrong (you%'ll wind up with " 5833 "%q#D are wrong (you%'ll wind up with "
5625 "multiple copies)"); 5834 "multiple copies)");
5650 /* ``Unless explicitly declared extern, a const object does not have 5859 /* ``Unless explicitly declared extern, a const object does not have
5651 external linkage and must be initialized. ($8.4; $12.1)'' ARM 5860 external linkage and must be initialized. ($8.4; $12.1)'' ARM
5652 7.1.6 */ 5861 7.1.6 */
5653 if (VAR_P (decl) 5862 if (VAR_P (decl)
5654 && !TYPE_REF_P (type) 5863 && !TYPE_REF_P (type)
5655 && (constexpr_context_p 5864 && (CP_TYPE_CONST_P (type)
5656 || CP_TYPE_CONST_P (type) || var_in_constexpr_fn (decl)) 5865 /* C++20 permits trivial default initialization in constexpr
5866 context (P1331R2). */
5867 || (cxx_dialect < cxx2a
5868 && (constexpr_context_p
5869 || var_in_constexpr_fn (decl))))
5657 && !DECL_NONTRIVIALLY_INITIALIZED_P (decl)) 5870 && !DECL_NONTRIVIALLY_INITIALIZED_P (decl))
5658 { 5871 {
5659 tree field = default_init_uninitialized_part (type); 5872 tree field = default_init_uninitialized_part (type);
5660 if (!field) 5873 if (!field)
5661 return true; 5874 return true;
5662 5875
5663 if (!constexpr_context_p) 5876 bool show_notes = true;
5877
5878 if (!constexpr_context_p || cxx_dialect >= cxx2a)
5664 { 5879 {
5665 if (CP_TYPE_CONST_P (type)) 5880 if (CP_TYPE_CONST_P (type))
5666 { 5881 {
5667 if (complain & tf_error) 5882 if (complain & tf_error)
5668 permerror (DECL_SOURCE_LOCATION (decl), 5883 show_notes = permerror (DECL_SOURCE_LOCATION (decl),
5669 "uninitialized const %qD", decl); 5884 "uninitialized %<const %D%>", decl);
5670 } 5885 }
5671 else 5886 else
5672 { 5887 {
5673 if (!is_instantiation_of_constexpr (current_function_decl) 5888 if (!is_instantiation_of_constexpr (current_function_decl)
5674 && (complain & tf_error)) 5889 && (complain & tf_error))
5675 error_at (DECL_SOURCE_LOCATION (decl), 5890 error_at (DECL_SOURCE_LOCATION (decl),
5676 "uninitialized variable %qD in %<constexpr%> " 5891 "uninitialized variable %qD in %<constexpr%> "
5677 "function", decl); 5892 "function", decl);
5893 else
5894 show_notes = false;
5678 cp_function_chain->invalid_constexpr = true; 5895 cp_function_chain->invalid_constexpr = true;
5679 } 5896 }
5680 } 5897 }
5681 else if (complain & tf_error) 5898 else if (complain & tf_error)
5682 error_at (DECL_SOURCE_LOCATION (decl), 5899 error_at (DECL_SOURCE_LOCATION (decl),
5683 "uninitialized variable %qD in %<constexpr%> context", 5900 "uninitialized variable %qD in %<constexpr%> context",
5684 decl); 5901 decl);
5685 5902
5686 if (CLASS_TYPE_P (type) && (complain & tf_error)) 5903 if (show_notes && CLASS_TYPE_P (type) && (complain & tf_error))
5687 { 5904 {
5688 tree defaulted_ctor; 5905 tree defaulted_ctor;
5689 5906
5690 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)), 5907 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type)),
5691 "%q#T has no user-provided default constructor", type); 5908 "%q#T has no user-provided default constructor", type);
5712 { 5929 {
5713 constructor_elt *cur; 5930 constructor_elt *cur;
5714 constructor_elt *end; 5931 constructor_elt *end;
5715 }; 5932 };
5716 5933
5717 static tree reshape_init_r (tree, reshape_iter *, bool, tsubst_flags_t); 5934 static tree reshape_init_r (tree, reshape_iter *, tree, tsubst_flags_t);
5718 5935
5719 /* FIELD is a FIELD_DECL or NULL. In the former case, the value 5936 /* FIELD is a FIELD_DECL or NULL. In the former case, the value
5720 returned is the next FIELD_DECL (possibly FIELD itself) that can be 5937 returned is the next FIELD_DECL (possibly FIELD itself) that can be
5721 initialized. If there are no more such fields, the return value 5938 initialized. If there are no more such fields, the return value
5722 will be NULL. */ 5939 will be NULL. */
5726 { 5943 {
5727 while (field 5944 while (field
5728 && (TREE_CODE (field) != FIELD_DECL 5945 && (TREE_CODE (field) != FIELD_DECL
5729 || DECL_UNNAMED_BIT_FIELD (field) 5946 || DECL_UNNAMED_BIT_FIELD (field)
5730 || (DECL_ARTIFICIAL (field) 5947 || (DECL_ARTIFICIAL (field)
5731 && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field))))) 5948 /* In C++17, don't skip base class fields. */
5949 && !(cxx_dialect >= cxx17 && DECL_FIELD_IS_BASE (field))
5950 /* Don't skip vptr fields. We might see them when we're
5951 called from reduced_constant_expression_p. */
5952 && !DECL_VIRTUAL_P (field))))
5732 field = DECL_CHAIN (field); 5953 field = DECL_CHAIN (field);
5733 5954
5734 return field; 5955 return field;
5735 } 5956 }
5736 5957
5756 or NULL_TREE if the array was declared without specifying the size. D is 5977 or NULL_TREE if the array was declared without specifying the size. D is
5757 the iterator within the constructor. */ 5978 the iterator within the constructor. */
5758 5979
5759 static tree 5980 static tree
5760 reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d, 5981 reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d,
5761 tsubst_flags_t complain) 5982 tree first_initializer_p, tsubst_flags_t complain)
5762 { 5983 {
5763 tree new_init; 5984 tree new_init;
5764 bool sized_array_p = (max_index && TREE_CONSTANT (max_index)); 5985 bool sized_array_p = (max_index && TREE_CONSTANT (max_index));
5765 unsigned HOST_WIDE_INT max_index_cst = 0; 5986 unsigned HOST_WIDE_INT max_index_cst = 0;
5766 unsigned HOST_WIDE_INT index; 5987 unsigned HOST_WIDE_INT index;
5767 5988
5768 /* The initializer for an array is always a CONSTRUCTOR. */ 5989 /* The initializer for an array is always a CONSTRUCTOR. If this is the
5769 new_init = build_constructor (init_list_type_node, NULL); 5990 outermost CONSTRUCTOR and the element type is non-aggregate, we don't need
5991 to build a new one. */
5992 bool reuse = (first_initializer_p
5993 && !CP_AGGREGATE_TYPE_P (elt_type)
5994 && !TREE_SIDE_EFFECTS (first_initializer_p));
5995 if (reuse)
5996 new_init = first_initializer_p;
5997 else
5998 new_init = build_constructor (init_list_type_node, NULL);
5770 5999
5771 if (sized_array_p) 6000 if (sized_array_p)
5772 { 6001 {
5773 /* Minus 1 is used for zero sized arrays. */ 6002 /* Minus 1 is used for zero sized arrays. */
5774 if (integer_all_onesp (max_index)) 6003 if (integer_all_onesp (max_index))
5779 /* sizetype is sign extended, not zero extended. */ 6008 /* sizetype is sign extended, not zero extended. */
5780 else 6009 else
5781 max_index_cst = tree_to_uhwi (fold_convert (size_type_node, max_index)); 6010 max_index_cst = tree_to_uhwi (fold_convert (size_type_node, max_index));
5782 } 6011 }
5783 6012
6013 /* Set to the index of the last element with a non-zero initializer.
6014 Zero initializers for elements past this one can be dropped. */
6015 unsigned HOST_WIDE_INT last_nonzero = -1;
5784 /* Loop until there are no more initializers. */ 6016 /* Loop until there are no more initializers. */
5785 for (index = 0; 6017 for (index = 0;
5786 d->cur != d->end && (!sized_array_p || index <= max_index_cst); 6018 d->cur != d->end && (!sized_array_p || index <= max_index_cst);
5787 ++index) 6019 ++index)
5788 { 6020 {
5789 tree elt_init; 6021 tree elt_init;
5790 constructor_elt *old_cur = d->cur; 6022 constructor_elt *old_cur = d->cur;
5791 6023
5792 check_array_designated_initializer (d->cur, index); 6024 check_array_designated_initializer (d->cur, index);
5793 elt_init = reshape_init_r (elt_type, d, /*first_initializer_p=*/false, 6025 elt_init = reshape_init_r (elt_type, d,
6026 /*first_initializer_p=*/NULL_TREE,
5794 complain); 6027 complain);
5795 if (elt_init == error_mark_node) 6028 if (elt_init == error_mark_node)
5796 return error_mark_node; 6029 return error_mark_node;
5797 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), 6030 tree idx = size_int (index);
5798 size_int (index), elt_init); 6031 if (reuse)
6032 {
6033 old_cur->index = idx;
6034 old_cur->value = elt_init;
6035 }
6036 else
6037 CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init),
6038 idx, elt_init);
5799 if (!TREE_CONSTANT (elt_init)) 6039 if (!TREE_CONSTANT (elt_init))
5800 TREE_CONSTANT (new_init) = false; 6040 TREE_CONSTANT (new_init) = false;
6041
6042 /* Pointers initialized to strings must be treated as non-zero
6043 even if the string is empty. */
6044 tree init_type = TREE_TYPE (elt_init);
6045 if (POINTER_TYPE_P (elt_type) != POINTER_TYPE_P (init_type)
6046 || !type_initializer_zero_p (elt_type, elt_init))
6047 last_nonzero = index;
5801 6048
5802 /* This can happen with an invalid initializer (c++/54501). */ 6049 /* This can happen with an invalid initializer (c++/54501). */
5803 if (d->cur == old_cur && !sized_array_p) 6050 if (d->cur == old_cur && !sized_array_p)
5804 break; 6051 break;
5805 } 6052 }
5806 6053
6054 if (sized_array_p && trivial_type_p (elt_type))
6055 {
6056 /* Strip trailing zero-initializers from an array of a trivial
6057 type of known size. They are redundant and get in the way
6058 of telling them apart from those with implicit zero value. */
6059 unsigned HOST_WIDE_INT nelts = CONSTRUCTOR_NELTS (new_init);
6060 if (last_nonzero > nelts)
6061 nelts = 0;
6062 else if (last_nonzero < nelts - 1)
6063 nelts = last_nonzero + 1;
6064
6065 vec_safe_truncate (CONSTRUCTOR_ELTS (new_init), nelts);
6066 }
6067
5807 return new_init; 6068 return new_init;
5808 } 6069 }
5809 6070
5810 /* Subroutine of reshape_init_r, processes the initializers for arrays. 6071 /* Subroutine of reshape_init_r, processes the initializers for arrays.
5811 Parameters are the same of reshape_init_r. */ 6072 Parameters are the same of reshape_init_r. */
5812 6073
5813 static tree 6074 static tree
5814 reshape_init_array (tree type, reshape_iter *d, tsubst_flags_t complain) 6075 reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
6076 tsubst_flags_t complain)
5815 { 6077 {
5816 tree max_index = NULL_TREE; 6078 tree max_index = NULL_TREE;
5817 6079
5818 gcc_assert (TREE_CODE (type) == ARRAY_TYPE); 6080 gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
5819 6081
5820 if (TYPE_DOMAIN (type)) 6082 if (TYPE_DOMAIN (type))
5821 max_index = array_type_nelts (type); 6083 max_index = array_type_nelts (type);
5822 6084
5823 return reshape_init_array_1 (TREE_TYPE (type), max_index, d, complain); 6085 return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
6086 first_initializer_p, complain);
5824 } 6087 }
5825 6088
5826 /* Subroutine of reshape_init_r, processes the initializers for vectors. 6089 /* Subroutine of reshape_init_r, processes the initializers for vectors.
5827 Parameters are the same of reshape_init_r. */ 6090 Parameters are the same of reshape_init_r. */
5828 6091
5849 6112
5850 /* For a vector, we initialize it as an array of the appropriate size. */ 6113 /* For a vector, we initialize it as an array of the appropriate size. */
5851 if (VECTOR_TYPE_P (type)) 6114 if (VECTOR_TYPE_P (type))
5852 max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1); 6115 max_index = size_int (TYPE_VECTOR_SUBPARTS (type) - 1);
5853 6116
5854 return reshape_init_array_1 (TREE_TYPE (type), max_index, d, complain); 6117 return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
6118 NULL_TREE, complain);
5855 } 6119 }
5856 6120
5857 /* Subroutine of reshape_init_r, processes the initializers for classes 6121 /* Subroutine of reshape_init_r, processes the initializers for classes
5858 or union. Parameters are the same of reshape_init_r. */ 6122 or union. Parameters are the same of reshape_init_r. */
5859 6123
5904 if (field != d->cur->index) 6168 if (field != d->cur->index)
5905 { 6169 {
5906 tree id = DECL_NAME (d->cur->index); 6170 tree id = DECL_NAME (d->cur->index);
5907 gcc_assert (id); 6171 gcc_assert (id);
5908 gcc_checking_assert (d->cur->index 6172 gcc_checking_assert (d->cur->index
5909 == get_class_binding (type, id, false)); 6173 == get_class_binding (type, id));
5910 field = d->cur->index; 6174 field = d->cur->index;
5911 } 6175 }
5912 } 6176 }
5913 else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE) 6177 else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
5914 field = get_class_binding (type, d->cur->index, false); 6178 field = get_class_binding (type, d->cur->index);
5915 else 6179 else
5916 { 6180 {
5917 if (complain & tf_error) 6181 if (complain & tf_error)
5918 error ("%<[%E] =%> used in a GNU-style designated initializer" 6182 error ("%<[%E] =%> used in a GNU-style designated initializer"
5919 " for class %qT", d->cur->index, type); 6183 " for class %qT", d->cur->index, type);
5932 /* If we processed all the member of the class, we are done. */ 6196 /* If we processed all the member of the class, we are done. */
5933 if (!field) 6197 if (!field)
5934 break; 6198 break;
5935 6199
5936 field_init = reshape_init_r (TREE_TYPE (field), d, 6200 field_init = reshape_init_r (TREE_TYPE (field), d,
5937 /*first_initializer_p=*/false, complain); 6201 /*first_initializer_p=*/NULL_TREE,
6202 complain);
5938 if (field_init == error_mark_node) 6203 if (field_init == error_mark_node)
5939 return error_mark_node; 6204 return error_mark_node;
5940 6205
5941 if (d->cur == old_cur && d->cur->index) 6206 if (d->cur == old_cur && d->cur->index)
5942 { 6207 {
5971 has_designator_problem (reshape_iter *d, tsubst_flags_t complain) 6236 has_designator_problem (reshape_iter *d, tsubst_flags_t complain)
5972 { 6237 {
5973 if (d->cur->index) 6238 if (d->cur->index)
5974 { 6239 {
5975 if (complain & tf_error) 6240 if (complain & tf_error)
5976 error ("C99 designator %qE outside aggregate initializer", 6241 error_at (cp_expr_loc_or_input_loc (d->cur->index),
5977 d->cur->index); 6242 "C99 designator %qE outside aggregate initializer",
6243 d->cur->index);
5978 else 6244 else
5979 return true; 6245 return true;
5980 } 6246 }
5981 return false; 6247 return false;
5982 } 6248 }
5983 6249
5984 /* Subroutine of reshape_init, which processes a single initializer (part of 6250 /* Subroutine of reshape_init, which processes a single initializer (part of
5985 a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the 6251 a CONSTRUCTOR). TYPE is the type of the variable being initialized, D is the
5986 iterator within the CONSTRUCTOR which points to the initializer to process. 6252 iterator within the CONSTRUCTOR which points to the initializer to process.
5987 FIRST_INITIALIZER_P is true if this is the first initializer of the 6253 If this is the first initializer of the outermost CONSTRUCTOR node,
5988 outermost CONSTRUCTOR node. */ 6254 FIRST_INITIALIZER_P is that CONSTRUCTOR; otherwise, it is NULL_TREE. */
5989 6255
5990 static tree 6256 static tree
5991 reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p, 6257 reshape_init_r (tree type, reshape_iter *d, tree first_initializer_p,
5992 tsubst_flags_t complain) 6258 tsubst_flags_t complain)
5993 { 6259 {
5994 tree init = d->cur->value; 6260 tree init = d->cur->value;
5995 6261
5996 if (error_operand_p (init)) 6262 if (error_operand_p (init))
5998 6264
5999 if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type) 6265 if (first_initializer_p && !CP_AGGREGATE_TYPE_P (type)
6000 && has_designator_problem (d, complain)) 6266 && has_designator_problem (d, complain))
6001 return error_mark_node; 6267 return error_mark_node;
6002 6268
6269 tree stripped_init = tree_strip_any_location_wrapper (init);
6270
6003 if (TREE_CODE (type) == COMPLEX_TYPE) 6271 if (TREE_CODE (type) == COMPLEX_TYPE)
6004 { 6272 {
6005 /* A complex type can be initialized from one or two initializers, 6273 /* A complex type can be initialized from one or two initializers,
6006 but braces are not elided. */ 6274 but braces are not elided. */
6007 d->cur++; 6275 d->cur++;
6008 if (BRACE_ENCLOSED_INITIALIZER_P (init)) 6276 if (BRACE_ENCLOSED_INITIALIZER_P (stripped_init))
6009 { 6277 {
6010 if (CONSTRUCTOR_NELTS (init) > 2) 6278 if (CONSTRUCTOR_NELTS (stripped_init) > 2)
6011 { 6279 {
6012 if (complain & tf_error) 6280 if (complain & tf_error)
6013 error ("too many initializers for %qT", type); 6281 error ("too many initializers for %qT", type);
6014 else 6282 else
6015 return error_mark_node; 6283 return error_mark_node;
6035 /* It is invalid to initialize a non-aggregate type with a 6303 /* It is invalid to initialize a non-aggregate type with a
6036 brace-enclosed initializer before C++0x. 6304 brace-enclosed initializer before C++0x.
6037 We need to check for BRACE_ENCLOSED_INITIALIZER_P here because 6305 We need to check for BRACE_ENCLOSED_INITIALIZER_P here because
6038 of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is 6306 of g++.old-deja/g++.mike/p7626.C: a pointer-to-member constant is
6039 a CONSTRUCTOR (with a record type). */ 6307 a CONSTRUCTOR (with a record type). */
6040 if (TREE_CODE (init) == CONSTRUCTOR 6308 if (TREE_CODE (stripped_init) == CONSTRUCTOR
6041 /* Don't complain about a capture-init. */ 6309 /* Don't complain about a capture-init. */
6042 && !CONSTRUCTOR_IS_DIRECT_INIT (init) 6310 && !CONSTRUCTOR_IS_DIRECT_INIT (stripped_init)
6043 && BRACE_ENCLOSED_INITIALIZER_P (init)) /* p7626.C */ 6311 && BRACE_ENCLOSED_INITIALIZER_P (stripped_init)) /* p7626.C */
6044 { 6312 {
6045 if (SCALAR_TYPE_P (type)) 6313 if (SCALAR_TYPE_P (type))
6046 { 6314 {
6047 if (cxx_dialect < cxx11 6315 if (cxx_dialect < cxx11)
6048 /* Isn't value-initialization. */
6049 || CONSTRUCTOR_NELTS (init) > 0)
6050 { 6316 {
6051 if (complain & tf_error) 6317 if (complain & tf_error)
6052 error ("braces around scalar initializer for type %qT", 6318 error ("braces around scalar initializer for type %qT",
6053 type); 6319 type);
6320 init = error_mark_node;
6321 }
6322 else if (first_initializer_p
6323 || (CONSTRUCTOR_NELTS (stripped_init) > 0
6324 && (BRACE_ENCLOSED_INITIALIZER_P
6325 (CONSTRUCTOR_ELT (stripped_init,0)->value))))
6326 {
6327 if (complain & tf_error)
6328 error ("too many braces around scalar initializer "
6329 "for type %qT", type);
6054 init = error_mark_node; 6330 init = error_mark_node;
6055 } 6331 }
6056 } 6332 }
6057 else 6333 else
6058 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS); 6334 maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
6104 string-literal (optionally enclosed in braces). */ 6380 string-literal (optionally enclosed in braces). */
6105 if (TREE_CODE (type) == ARRAY_TYPE 6381 if (TREE_CODE (type) == ARRAY_TYPE
6106 && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))) 6382 && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type))))
6107 { 6383 {
6108 tree str_init = init; 6384 tree str_init = init;
6385 tree stripped_str_init = stripped_init;
6109 6386
6110 /* Strip one level of braces if and only if they enclose a single 6387 /* Strip one level of braces if and only if they enclose a single
6111 element (as allowed by [dcl.init.string]). */ 6388 element (as allowed by [dcl.init.string]). */
6112 if (!first_initializer_p 6389 if (!first_initializer_p
6113 && TREE_CODE (str_init) == CONSTRUCTOR 6390 && TREE_CODE (stripped_str_init) == CONSTRUCTOR
6114 && CONSTRUCTOR_NELTS (str_init) == 1) 6391 && CONSTRUCTOR_NELTS (stripped_str_init) == 1)
6115 { 6392 {
6116 str_init = (*CONSTRUCTOR_ELTS (str_init))[0].value; 6393 str_init = (*CONSTRUCTOR_ELTS (stripped_str_init))[0].value;
6394 stripped_str_init = tree_strip_any_location_wrapper (str_init);
6117 } 6395 }
6118 6396
6119 /* If it's a string literal, then it's the initializer for the array 6397 /* If it's a string literal, then it's the initializer for the array
6120 as a whole. Otherwise, continue with normal initialization for 6398 as a whole. Otherwise, continue with normal initialization for
6121 array types (one value per array element). */ 6399 array types (one value per array element). */
6122 if (TREE_CODE (str_init) == STRING_CST) 6400 if (TREE_CODE (stripped_str_init) == STRING_CST)
6123 { 6401 {
6124 if (has_designator_problem (d, complain)) 6402 if (has_designator_problem (d, complain))
6125 return error_mark_node; 6403 return error_mark_node;
6126 d->cur++; 6404 d->cur++;
6127 return str_init; 6405 return str_init;
6132 initializer already, and there is not a CONSTRUCTOR, it means that there 6410 initializer already, and there is not a CONSTRUCTOR, it means that there
6133 is a missing set of braces (that is, we are processing the case for 6411 is a missing set of braces (that is, we are processing the case for
6134 which reshape_init exists). */ 6412 which reshape_init exists). */
6135 if (!first_initializer_p) 6413 if (!first_initializer_p)
6136 { 6414 {
6137 if (TREE_CODE (init) == CONSTRUCTOR) 6415 if (TREE_CODE (stripped_init) == CONSTRUCTOR)
6138 { 6416 {
6139 if (TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init))) 6417 tree init_type = TREE_TYPE (init);
6140 /* There is no need to reshape pointer-to-member function 6418 if (init_type && TYPE_PTRMEMFUNC_P (init_type))
6141 initializers, as they are always constructed correctly 6419 /* There is no need to call reshape_init for pointer-to-member
6142 by the front end. */ 6420 function initializers, as they are always constructed correctly
6143 ; 6421 by the front end. Here we have e.g. {.__pfn=0B, .__delta=0},
6144 else if (COMPOUND_LITERAL_P (init)) 6422 which is missing outermost braces. We should warn below, and
6145 /* For a nested compound literal, there is no need to reshape since 6423 one of the routines below will wrap it in additional { }. */;
6146 brace elision is not allowed. Even if we decided to allow it, 6424 /* For a nested compound literal, proceed to specialized routines,
6147 we should add a call to reshape_init in finish_compound_literal, 6425 to handle initialization of arrays and similar. */
6148 before calling digest_init, so changing this code would still 6426 else if (COMPOUND_LITERAL_P (stripped_init))
6149 not be necessary. */ 6427 gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
6150 gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (init)); 6428 /* A CONSTRUCTOR of the target's type is a previously
6429 digested initializer. */
6430 else if (same_type_ignoring_top_level_qualifiers_p (type, init_type))
6431 {
6432 ++d->cur;
6433 return init;
6434 }
6151 else 6435 else
6152 { 6436 {
6437 /* Something that hasn't been reshaped yet. */
6153 ++d->cur; 6438 ++d->cur;
6154 gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init)); 6439 gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (stripped_init));
6155 return reshape_init (type, init, complain); 6440 return reshape_init (type, init, complain);
6156 } 6441 }
6157 } 6442 }
6158 6443
6159 if (complain & tf_warning) 6444 if (complain & tf_warning)
6164 6449
6165 /* Dispatch to specialized routines. */ 6450 /* Dispatch to specialized routines. */
6166 if (CLASS_TYPE_P (type)) 6451 if (CLASS_TYPE_P (type))
6167 return reshape_init_class (type, d, first_initializer_p, complain); 6452 return reshape_init_class (type, d, first_initializer_p, complain);
6168 else if (TREE_CODE (type) == ARRAY_TYPE) 6453 else if (TREE_CODE (type) == ARRAY_TYPE)
6169 return reshape_init_array (type, d, complain); 6454 return reshape_init_array (type, d, first_initializer_p, complain);
6170 else if (VECTOR_TYPE_P (type)) 6455 else if (VECTOR_TYPE_P (type))
6171 return reshape_init_vector (type, d, complain); 6456 return reshape_init_vector (type, d, complain);
6172 else 6457 else
6173 gcc_unreachable(); 6458 gcc_unreachable();
6174 } 6459 }
6202 /* An empty constructor does not need reshaping, and it is always a valid 6487 /* An empty constructor does not need reshaping, and it is always a valid
6203 initializer. */ 6488 initializer. */
6204 if (vec_safe_is_empty (v)) 6489 if (vec_safe_is_empty (v))
6205 return init; 6490 return init;
6206 6491
6492 /* Brace elision is not performed for a CONSTRUCTOR representing
6493 parenthesized aggregate initialization. */
6494 if (CONSTRUCTOR_IS_PAREN_INIT (init))
6495 return init;
6496
6207 /* Handle [dcl.init.list] direct-list-initialization from 6497 /* Handle [dcl.init.list] direct-list-initialization from
6208 single element of enumeration with a fixed underlying type. */ 6498 single element of enumeration with a fixed underlying type. */
6209 if (is_direct_enum_init (type, init)) 6499 if (is_direct_enum_init (type, init))
6210 { 6500 {
6211 tree elt = CONSTRUCTOR_ELT (init, 0)->value; 6501 tree elt = CONSTRUCTOR_ELT (init, 0)->value;
6212 type = cv_unqualified (type); 6502 type = cv_unqualified (type);
6213 if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain)) 6503 if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
6214 { 6504 {
6215 warning_sentinel w (warn_useless_cast); 6505 warning_sentinel w (warn_useless_cast);
6216 warning_sentinel w2 (warn_ignored_qualifiers); 6506 warning_sentinel w2 (warn_ignored_qualifiers);
6217 return cp_build_c_cast (type, elt, tf_warning_or_error); 6507 return cp_build_c_cast (input_location, type, elt,
6508 tf_warning_or_error);
6218 } 6509 }
6219 else 6510 else
6220 return error_mark_node; 6511 return error_mark_node;
6221 } 6512 }
6222 6513
6223 /* Recurse on this CONSTRUCTOR. */ 6514 /* Recurse on this CONSTRUCTOR. */
6224 d.cur = &(*v)[0]; 6515 d.cur = &(*v)[0];
6225 d.end = d.cur + v->length (); 6516 d.end = d.cur + v->length ();
6226 6517
6227 new_init = reshape_init_r (type, &d, true, complain); 6518 new_init = reshape_init_r (type, &d, init, complain);
6228 if (new_init == error_mark_node) 6519 if (new_init == error_mark_node)
6229 return error_mark_node; 6520 return error_mark_node;
6230 6521
6231 /* Make sure all the element of the constructor were used. Otherwise, 6522 /* Make sure all the element of the constructor were used. Otherwise,
6232 issue an error about exceeding initializers. */ 6523 issue an error about exceeding initializers. */
6238 } 6529 }
6239 6530
6240 if (CONSTRUCTOR_IS_DIRECT_INIT (init) 6531 if (CONSTRUCTOR_IS_DIRECT_INIT (init)
6241 && BRACE_ENCLOSED_INITIALIZER_P (new_init)) 6532 && BRACE_ENCLOSED_INITIALIZER_P (new_init))
6242 CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true; 6533 CONSTRUCTOR_IS_DIRECT_INIT (new_init) = true;
6534 if (CONSTRUCTOR_IS_DESIGNATED_INIT (init)
6535 && BRACE_ENCLOSED_INITIALIZER_P (new_init))
6536 CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
6243 6537
6244 return new_init; 6538 return new_init;
6245 } 6539 }
6246 6540
6247 /* Verify array initializer. Returns true if errors have been reported. */ 6541 /* Verify array initializer. Returns true if errors have been reported. */
6261 "elements of array %q#D have incomplete type", decl); 6555 "elements of array %q#D have incomplete type", decl);
6262 else 6556 else
6263 error ("elements of array %q#T have incomplete type", type); 6557 error ("elements of array %q#T have incomplete type", type);
6264 return true; 6558 return true;
6265 } 6559 }
6560
6561 location_t loc = (decl ? location_of (decl) : input_location);
6562 if (!verify_type_context (loc, TCTX_ARRAY_ELEMENT, element_type))
6563 return true;
6564
6266 /* A compound literal can't have variable size. */ 6565 /* A compound literal can't have variable size. */
6267 if (init && !decl 6566 if (init && !decl
6268 && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type))) 6567 && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
6269 || !TREE_CONSTANT (TYPE_SIZE (element_type)))) 6568 || !TREE_CONSTANT (TYPE_SIZE (element_type))))
6270 { 6569 {
6293 evaluated dynamically to initialize DECL. */ 6592 evaluated dynamically to initialize DECL. */
6294 6593
6295 static tree 6594 static tree
6296 check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups) 6595 check_initializer (tree decl, tree init, int flags, vec<tree, va_gc> **cleanups)
6297 { 6596 {
6298 tree type = TREE_TYPE (decl); 6597 tree type;
6299 tree init_code = NULL; 6598 tree init_code = NULL;
6300 tree core_type; 6599 tree core_type;
6301 6600
6302 /* Things that are going to be initialized need to have complete 6601 /* Things that are going to be initialized need to have complete
6303 type. */ 6602 type. */
6402 { 6701 {
6403 init = reshape_init (type, init, tf_warning_or_error); 6702 init = reshape_init (type, init, tf_warning_or_error);
6404 flags |= LOOKUP_NO_NARROWING; 6703 flags |= LOOKUP_NO_NARROWING;
6405 } 6704 }
6406 } 6705 }
6706 /* [dcl.init] "Otherwise, if the destination type is an array, the object
6707 is initialized as follows..." So handle things like
6708
6709 int a[](1, 2, 3);
6710
6711 which is permitted in C++20 by P0960. */
6712 else if (TREE_CODE (init) == TREE_LIST
6713 && TREE_TYPE (init) == NULL_TREE
6714 && TREE_CODE (type) == ARRAY_TYPE
6715 && !DECL_DECOMPOSITION_P (decl)
6716 && (cxx_dialect >= cxx2a))
6717 {
6718 /* [dcl.init.string] "An array of ordinary character type [...]
6719 can be initialized by an ordinary string literal [...] by an
6720 appropriately-typed string literal enclosed in braces" only
6721 talks about braces, but GCC has always accepted
6722
6723 char a[]("foobar");
6724
6725 so we continue to do so. */
6726 tree val = TREE_VALUE (init);
6727 if (TREE_CHAIN (init) == NULL_TREE
6728 && char_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (type)))
6729 && TREE_CODE (tree_strip_any_location_wrapper (val))
6730 == STRING_CST)
6731 /* If the list has a single element and it's a string literal,
6732 then it's the initializer for the array as a whole. */
6733 init = val;
6734 else
6735 {
6736 init = build_constructor_from_list (init_list_type_node, init);
6737 CONSTRUCTOR_IS_DIRECT_INIT (init) = true;
6738 CONSTRUCTOR_IS_PAREN_INIT (init) = true;
6739 }
6740 }
6407 else if (TREE_CODE (init) == TREE_LIST 6741 else if (TREE_CODE (init) == TREE_LIST
6408 && TREE_TYPE (init) != unknown_type_node 6742 && TREE_TYPE (init) != unknown_type_node
6409 && !MAYBE_CLASS_TYPE_P (type)) 6743 && !MAYBE_CLASS_TYPE_P (type))
6410 { 6744 {
6411 gcc_assert (TREE_CODE (decl) != RESULT_DECL); 6745 gcc_assert (TREE_CODE (decl) != RESULT_DECL);
6445 while (TREE_CODE (init_code) == EXPR_STMT 6779 while (TREE_CODE (init_code) == EXPR_STMT
6446 || TREE_CODE (init_code) == CONVERT_EXPR) 6780 || TREE_CODE (init_code) == CONVERT_EXPR)
6447 init_code = TREE_OPERAND (init_code, 0); 6781 init_code = TREE_OPERAND (init_code, 0);
6448 if (TREE_CODE (init_code) == INIT_EXPR) 6782 if (TREE_CODE (init_code) == INIT_EXPR)
6449 { 6783 {
6784 /* In C++20, the call to build_aggr_init could have created
6785 an INIT_EXPR with a CONSTRUCTOR as the RHS to handle
6786 A(1, 2). */
6450 init = TREE_OPERAND (init_code, 1); 6787 init = TREE_OPERAND (init_code, 1);
6451 init_code = NULL_TREE; 6788 init_code = NULL_TREE;
6452 /* Don't call digest_init; it's unnecessary and will complain 6789 /* Don't call digest_init; it's unnecessary and will complain
6453 about aggregate initialization of non-aggregate classes. */ 6790 about aggregate initialization of non-aggregate classes. */
6454 flags |= LOOKUP_ALREADY_DIGESTED; 6791 flags |= LOOKUP_ALREADY_DIGESTED;
6455 } 6792 }
6456 else if (DECL_DECLARED_CONSTEXPR_P (decl)) 6793 else if (DECL_DECLARED_CONSTEXPR_P (decl)
6794 || (flags & LOOKUP_CONSTINIT))
6457 { 6795 {
6458 /* Declared constexpr, but no suitable initializer; massage 6796 /* Declared constexpr or constinit, but no suitable initializer;
6459 init appropriately so we can pass it into store_init_value 6797 massage init appropriately so we can pass it into
6460 for the error. */ 6798 store_init_value for the error. */
6461 if (CLASS_TYPE_P (type) 6799 if (CLASS_TYPE_P (type)
6462 && (!init || TREE_CODE (init) == TREE_LIST)) 6800 && (!init || TREE_CODE (init) == TREE_LIST))
6463 { 6801 {
6464 init = build_functional_cast (type, init, tf_none); 6802 init = build_functional_cast (input_location, type,
6803 init, tf_none);
6465 if (TREE_CODE (init) == TARGET_EXPR) 6804 if (TREE_CODE (init) == TARGET_EXPR)
6466 TARGET_EXPR_DIRECT_INIT_P (init) = true; 6805 TARGET_EXPR_DIRECT_INIT_P (init) = true;
6467 } 6806 }
6468 init_code = NULL_TREE; 6807 init_code = NULL_TREE;
6469 } 6808 }
6497 warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl), 6836 warning_at (cp_expr_loc_or_loc (DECL_INITIAL (decl),
6498 DECL_SOURCE_LOCATION (decl)), 6837 DECL_SOURCE_LOCATION (decl)),
6499 0, "array %qD initialized by parenthesized " 6838 0, "array %qD initialized by parenthesized "
6500 "string literal %qE", 6839 "string literal %qE",
6501 decl, DECL_INITIAL (decl)); 6840 decl, DECL_INITIAL (decl));
6502 init = NULL; 6841 init = NULL_TREE;
6503 } 6842 }
6504 } 6843 }
6505 else 6844 else
6506 { 6845 {
6507 if (CLASS_TYPE_P (core_type = strip_array_types (type)) 6846 if (CLASS_TYPE_P (core_type = strip_array_types (type))
6523 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false; 6862 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = false;
6524 TREE_CONSTANT (decl) = false; 6863 TREE_CONSTANT (decl) = false;
6525 } 6864 }
6526 6865
6527 if (init_code 6866 if (init_code
6528 && (DECL_IN_AGGR_P (decl) 6867 && DECL_IN_AGGR_P (decl)
6529 && DECL_INITIALIZED_IN_CLASS_P (decl) 6868 && DECL_INITIALIZED_IN_CLASS_P (decl))
6530 && !DECL_VAR_DECLARED_INLINE_P (decl)))
6531 { 6869 {
6532 static int explained = 0; 6870 static int explained = 0;
6533 6871
6534 if (cxx_dialect < cxx11) 6872 if (cxx_dialect < cxx11)
6535 error ("initializer invalid for static member with constructor"); 6873 error ("initializer invalid for static member with constructor");
6593 gcc_assert (TREE_STATIC (decl)); 6931 gcc_assert (TREE_STATIC (decl));
6594 /* An in-class declaration of a static data member should be 6932 /* An in-class declaration of a static data member should be
6595 external; it is only a declaration, and not a definition. */ 6933 external; it is only a declaration, and not a definition. */
6596 if (init == NULL_TREE) 6934 if (init == NULL_TREE)
6597 gcc_assert (DECL_EXTERNAL (decl) 6935 gcc_assert (DECL_EXTERNAL (decl)
6598 || !TREE_PUBLIC (decl) 6936 || !TREE_PUBLIC (decl));
6599 || DECL_INLINE_VAR_P (decl));
6600 } 6937 }
6601 6938
6602 /* We don't create any RTL for local variables. */ 6939 /* We don't create any RTL for local variables. */
6603 if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl)) 6940 if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
6604 return; 6941 return;
6839 if (TREE_CODE (*tp) == LABEL_DECL) 7176 if (TREE_CODE (*tp) == LABEL_DECL)
6840 cfun->has_forced_label_in_static = 1; 7177 cfun->has_forced_label_in_static = 1;
6841 return NULL_TREE; 7178 return NULL_TREE;
6842 } 7179 }
6843 7180
7181 /* Return true if DECL has either a trivial destructor, or for C++2A
7182 is constexpr and has a constexpr destructor. */
7183
7184 static bool
7185 decl_maybe_constant_destruction (tree decl, tree type)
7186 {
7187 return (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)
7188 || (cxx_dialect >= cxx2a
7189 && VAR_P (decl)
7190 && DECL_DECLARED_CONSTEXPR_P (decl)
7191 && type_has_constexpr_destructor (strip_array_types (type))));
7192 }
7193
7194 static tree declare_simd_adjust_this (tree *, int *, void *);
7195
7196 /* Helper function of omp_declare_variant_finalize. Finalize one
7197 "omp declare variant base" attribute. Return true if it should be
7198 removed. */
7199
7200 static bool
7201 omp_declare_variant_finalize_one (tree decl, tree attr)
7202 {
7203 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
7204 {
7205 walk_tree (&TREE_VALUE (TREE_VALUE (attr)), declare_simd_adjust_this,
7206 DECL_ARGUMENTS (decl), NULL);
7207 walk_tree (&TREE_PURPOSE (TREE_VALUE (attr)), declare_simd_adjust_this,
7208 DECL_ARGUMENTS (decl), NULL);
7209 }
7210
7211 tree ctx = TREE_VALUE (TREE_VALUE (attr));
7212 tree simd = omp_get_context_selector (ctx, "construct", "simd");
7213 if (simd)
7214 {
7215 TREE_VALUE (simd)
7216 = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl),
7217 TREE_VALUE (simd));
7218 /* FIXME, adjusting simd args unimplemented. */
7219 return true;
7220 }
7221
7222 tree chain = TREE_CHAIN (TREE_VALUE (attr));
7223 location_t varid_loc
7224 = cp_expr_loc_or_input_loc (TREE_PURPOSE (TREE_CHAIN (chain)));
7225 location_t match_loc = cp_expr_loc_or_input_loc (TREE_PURPOSE (chain));
7226 cp_id_kind idk = (cp_id_kind) tree_to_uhwi (TREE_VALUE (chain));
7227 tree variant = TREE_PURPOSE (TREE_VALUE (attr));
7228
7229 location_t save_loc = input_location;
7230 input_location = varid_loc;
7231
7232 releasing_vec args;
7233 tree parm = DECL_ARGUMENTS (decl);
7234 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
7235 parm = DECL_CHAIN (parm);
7236 for (; parm; parm = DECL_CHAIN (parm))
7237 if (type_dependent_expression_p (parm))
7238 vec_safe_push (args, build_constructor (TREE_TYPE (parm), NULL));
7239 else if (MAYBE_CLASS_TYPE_P (TREE_TYPE (parm)))
7240 vec_safe_push (args, build_local_temp (TREE_TYPE (parm)));
7241 else
7242 vec_safe_push (args, build_zero_cst (TREE_TYPE (parm)));
7243
7244 bool koenig_p = false;
7245 if (idk == CP_ID_KIND_UNQUALIFIED || idk == CP_ID_KIND_TEMPLATE_ID)
7246 {
7247 if (identifier_p (variant)
7248 /* In C++2A, we may need to perform ADL for a template
7249 name. */
7250 || (TREE_CODE (variant) == TEMPLATE_ID_EXPR
7251 && identifier_p (TREE_OPERAND (variant, 0))))
7252 {
7253 if (!args->is_empty ())
7254 {
7255 koenig_p = true;
7256 if (!any_type_dependent_arguments_p (args))
7257 variant = perform_koenig_lookup (variant, args,
7258 tf_warning_or_error);
7259 }
7260 else
7261 variant = unqualified_fn_lookup_error (variant);
7262 }
7263 else if (!args->is_empty () && is_overloaded_fn (variant))
7264 {
7265 tree fn = get_first_fn (variant);
7266 fn = STRIP_TEMPLATE (fn);
7267 if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
7268 || DECL_FUNCTION_MEMBER_P (fn)
7269 || DECL_LOCAL_FUNCTION_P (fn)))
7270 {
7271 koenig_p = true;
7272 if (!any_type_dependent_arguments_p (args))
7273 variant = perform_koenig_lookup (variant, args,
7274 tf_warning_or_error);
7275 }
7276 }
7277 }
7278
7279 if (idk == CP_ID_KIND_QUALIFIED)
7280 variant = finish_call_expr (variant, &args, /*disallow_virtual=*/true,
7281 koenig_p, tf_warning_or_error);
7282 else
7283 variant = finish_call_expr (variant, &args, /*disallow_virtual=*/false,
7284 koenig_p, tf_warning_or_error);
7285 if (variant == error_mark_node && !processing_template_decl)
7286 return true;
7287
7288 variant = cp_get_callee (variant);
7289 if (variant)
7290 {
7291 if (TREE_CODE (variant) == FUNCTION_DECL)
7292 ;
7293 else if (TREE_TYPE (variant) && INDIRECT_TYPE_P (TREE_TYPE (variant)))
7294 variant = cp_get_fndecl_from_callee (variant, false);
7295 else
7296 variant = NULL_TREE;
7297 }
7298
7299 input_location = save_loc;
7300
7301 if (variant)
7302 {
7303 const char *varname = IDENTIFIER_POINTER (DECL_NAME (variant));
7304 if (!comptypes (TREE_TYPE (decl), TREE_TYPE (variant), 0))
7305 {
7306 error_at (varid_loc, "variant %qD and base %qD have incompatible "
7307 "types", variant, decl);
7308 return true;
7309 }
7310 if (fndecl_built_in_p (variant)
7311 && (strncmp (varname, "__builtin_", strlen ("__builtin_")) == 0
7312 || strncmp (varname, "__sync_", strlen ("__sync_")) == 0
7313 || strncmp (varname, "__atomic_", strlen ("__atomic_")) == 0))
7314 {
7315 error_at (varid_loc, "variant %qD is a built-in", variant);
7316 return true;
7317 }
7318 else
7319 {
7320 tree construct = omp_get_context_selector (ctx, "construct", NULL);
7321 c_omp_mark_declare_variant (match_loc, variant, construct);
7322 if (!omp_context_selector_matches (ctx))
7323 return true;
7324 TREE_PURPOSE (TREE_VALUE (attr)) = variant;
7325 }
7326 }
7327 else if (!processing_template_decl)
7328 {
7329 error_at (varid_loc, "could not find variant declaration");
7330 return true;
7331 }
7332
7333 return false;
7334 }
7335
7336 /* Helper function, finish up "omp declare variant base" attribute
7337 now that there is a DECL. ATTR is the first "omp declare variant base"
7338 attribute. */
7339
7340 void
7341 omp_declare_variant_finalize (tree decl, tree attr)
7342 {
7343 size_t attr_len = strlen ("omp declare variant base");
7344 tree *list = &DECL_ATTRIBUTES (decl);
7345 bool remove_all = false;
7346 location_t match_loc = DECL_SOURCE_LOCATION (decl);
7347 if (TREE_CHAIN (TREE_VALUE (attr))
7348 && TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))
7349 && EXPR_HAS_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr)))))
7350 match_loc = EXPR_LOCATION (TREE_PURPOSE (TREE_CHAIN (TREE_VALUE (attr))));
7351 if (DECL_CONSTRUCTOR_P (decl))
7352 {
7353 error_at (match_loc, "%<declare variant%> on constructor %qD", decl);
7354 remove_all = true;
7355 }
7356 else if (DECL_DESTRUCTOR_P (decl))
7357 {
7358 error_at (match_loc, "%<declare variant%> on destructor %qD", decl);
7359 remove_all = true;
7360 }
7361 else if (DECL_DEFAULTED_FN (decl))
7362 {
7363 error_at (match_loc, "%<declare variant%> on defaulted %qD", decl);
7364 remove_all = true;
7365 }
7366 else if (DECL_DELETED_FN (decl))
7367 {
7368 error_at (match_loc, "%<declare variant%> on deleted %qD", decl);
7369 remove_all = true;
7370 }
7371 else if (DECL_VIRTUAL_P (decl))
7372 {
7373 error_at (match_loc, "%<declare variant%> on virtual %qD", decl);
7374 remove_all = true;
7375 }
7376 /* This loop is like private_lookup_attribute, except that it works
7377 with tree * rather than tree, as we might want to remove the
7378 attributes that are diagnosed as errorneous. */
7379 while (*list)
7380 {
7381 tree attr = get_attribute_name (*list);
7382 size_t ident_len = IDENTIFIER_LENGTH (attr);
7383 if (cmp_attribs ("omp declare variant base", attr_len,
7384 IDENTIFIER_POINTER (attr), ident_len))
7385 {
7386 if (remove_all || omp_declare_variant_finalize_one (decl, *list))
7387 {
7388 *list = TREE_CHAIN (*list);
7389 continue;
7390 }
7391 }
7392 list = &TREE_CHAIN (*list);
7393 }
7394 }
7395
6844 /* Finish processing of a declaration; 7396 /* Finish processing of a declaration;
6845 install its line number and initial value. 7397 install its line number and initial value.
6846 If the length of an array type is not known before, 7398 If the length of an array type is not known before,
6847 it must be determined now, from the initial value, or it is an error. 7399 it must be determined now, from the initial value, or it is an error.
6848 7400
6935 NULL_TREE, flags); 7487 NULL_TREE, flags);
6936 if (type == error_mark_node) 7488 if (type == error_mark_node)
6937 return; 7489 return;
6938 if (TREE_CODE (type) == FUNCTION_TYPE) 7490 if (TREE_CODE (type) == FUNCTION_TYPE)
6939 { 7491 {
6940 error ("initializer for %<decltype(auto) %D%> has function type " 7492 error ("initializer for %<decltype(auto) %D%> has function type; "
6941 "(did you forget the %<()%> ?)", decl); 7493 "did you forget the %<()%>?", decl);
6942 TREE_TYPE (decl) = error_mark_node; 7494 TREE_TYPE (decl) = error_mark_node;
6943 return; 7495 return;
6944 } 7496 }
6945 cp_apply_type_quals_to_decl (cp_type_quals (type), decl); 7497 cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
6946 } 7498 }
6955 } 7507 }
6956 } 7508 }
6957 7509
6958 if (VAR_P (decl) 7510 if (VAR_P (decl)
6959 && DECL_CLASS_SCOPE_P (decl) 7511 && DECL_CLASS_SCOPE_P (decl)
7512 && verify_type_context (DECL_SOURCE_LOCATION (decl),
7513 TCTX_STATIC_STORAGE, type)
6960 && DECL_INITIALIZED_IN_CLASS_P (decl)) 7514 && DECL_INITIALIZED_IN_CLASS_P (decl))
6961 check_static_variable_definition (decl, type); 7515 check_static_variable_definition (decl, type);
6962 7516
6963 if (init && TREE_CODE (decl) == FUNCTION_DECL) 7517 if (init && TREE_CODE (decl) == FUNCTION_DECL)
6964 { 7518 {
7004 && !TYPE_REF_P (type)) 7558 && !TYPE_REF_P (type))
7005 TREE_CONSTANT (decl) = 1; 7559 TREE_CONSTANT (decl) = 1;
7006 } 7560 }
7007 } 7561 }
7008 7562
7563 if (flag_openmp
7564 && TREE_CODE (decl) == FUNCTION_DECL
7565 /* #pragma omp declare variant on methods handled in finish_struct
7566 instead. */
7567 && (!DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
7568 || COMPLETE_TYPE_P (DECL_CONTEXT (decl))))
7569 if (tree attr = lookup_attribute ("omp declare variant base",
7570 DECL_ATTRIBUTES (decl)))
7571 omp_declare_variant_finalize (decl, attr);
7572
7009 if (processing_template_decl) 7573 if (processing_template_decl)
7010 { 7574 {
7011 bool type_dependent_p; 7575 bool type_dependent_p;
7012 7576
7013 /* Add this declaration to the statement-tree. */ 7577 /* Add this declaration to the statement-tree. */
7019 if (check_for_bare_parameter_packs (init)) 7583 if (check_for_bare_parameter_packs (init))
7020 { 7584 {
7021 init = NULL_TREE; 7585 init = NULL_TREE;
7022 DECL_INITIAL (decl) = NULL_TREE; 7586 DECL_INITIAL (decl) = NULL_TREE;
7023 } 7587 }
7588
7589 /* Handle `constinit' on variable templates. */
7590 if (flags & LOOKUP_CONSTINIT)
7591 TINFO_VAR_DECLARED_CONSTINIT (DECL_TEMPLATE_INFO (decl)) = true;
7024 7592
7025 /* Generally, initializers in templates are expanded when the 7593 /* Generally, initializers in templates are expanded when the
7026 template is instantiated. But, if DECL is a variable constant 7594 template is instantiated. But, if DECL is a variable constant
7027 then it can be used in future constant expressions, so its value 7595 then it can be used in future constant expressions, so its value
7028 must be available. */ 7596 must be available. */
7050 init_code = check_initializer (decl, init, flags, &cleanups); 7618 init_code = check_initializer (decl, init, flags, &cleanups);
7051 if (init_code == NULL_TREE) 7619 if (init_code == NULL_TREE)
7052 init = NULL_TREE; 7620 init = NULL_TREE;
7053 release_tree_vector (cleanups); 7621 release_tree_vector (cleanups);
7054 } 7622 }
7055 else if (!DECL_PRETTY_FUNCTION_P (decl)) 7623 else
7056 { 7624 {
7625 gcc_assert (!DECL_PRETTY_FUNCTION_P (decl));
7057 /* Deduce array size even if the initializer is dependent. */ 7626 /* Deduce array size even if the initializer is dependent. */
7058 maybe_deduce_size_from_array_init (decl, init); 7627 maybe_deduce_size_from_array_init (decl, init);
7059 /* And complain about multiple initializers. */ 7628 /* And complain about multiple initializers. */
7060 if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init) 7629 if (init && TREE_CODE (init) == TREE_LIST && TREE_CHAIN (init)
7061 && !MAYBE_CLASS_TYPE_P (type)) 7630 && !MAYBE_CLASS_TYPE_P (type))
7108 { 7677 {
7109 was_readonly = 1; 7678 was_readonly = 1;
7110 TREE_READONLY (decl) = 0; 7679 TREE_READONLY (decl) = 0;
7111 } 7680 }
7112 7681
7682 /* This needs to happen before extend_ref_init_temps. */
7683 if (VAR_OR_FUNCTION_DECL_P (decl))
7684 {
7685 if (VAR_P (decl))
7686 maybe_commonize_var (decl);
7687 determine_visibility (decl);
7688 }
7689
7113 if (VAR_P (decl)) 7690 if (VAR_P (decl))
7114 { 7691 {
7692 duration_kind dk = decl_storage_duration (decl);
7693 /* [dcl.constinit]/1 "The constinit specifier shall be applied
7694 only to a declaration of a variable with static or thread storage
7695 duration." */
7696 if ((flags & LOOKUP_CONSTINIT)
7697 && !(dk == dk_thread || dk == dk_static))
7698 {
7699 error_at (DECL_SOURCE_LOCATION (decl),
7700 "%<constinit%> can only be applied to a variable with "
7701 "static or thread storage duration");
7702 return;
7703 }
7704
7115 /* If this is a local variable that will need a mangled name, 7705 /* If this is a local variable that will need a mangled name,
7116 register it now. We must do this before processing the 7706 register it now. We must do this before processing the
7117 initializer for the variable, since the initialization might 7707 initializer for the variable, since the initialization might
7118 require a guard variable, and since the mangled name of the 7708 require a guard variable, and since the mangled name of the
7119 guard variable will depend on the mangled name of this 7709 guard variable will depend on the mangled name of this
7120 variable. */ 7710 variable. */
7121 if (DECL_FUNCTION_SCOPE_P (decl) 7711 if (DECL_FUNCTION_SCOPE_P (decl)
7122 && TREE_STATIC (decl) 7712 && TREE_STATIC (decl)
7123 && !DECL_ARTIFICIAL (decl)) 7713 && !DECL_ARTIFICIAL (decl))
7124 { 7714 {
7125 push_local_name (decl); 7715 /* The variable holding an anonymous union will have had its
7716 discriminator set in finish_anon_union, after which it's
7717 NAME will have been cleared. */
7718 if (DECL_NAME (decl))
7719 determine_local_discriminator (decl);
7126 /* Normally has_forced_label_in_static is set during GIMPLE 7720 /* Normally has_forced_label_in_static is set during GIMPLE
7127 lowering, but [cd]tors are never actually compiled directly. 7721 lowering, but [cd]tors are never actually compiled directly.
7128 We need to set this early so we can deal with the label 7722 We need to set this early so we can deal with the label
7129 address extension. */ 7723 address extension. */
7130 if ((DECL_CONSTRUCTOR_P (current_function_decl) 7724 if ((DECL_CONSTRUCTOR_P (current_function_decl)
7220 if (VAR_OR_FUNCTION_DECL_P (decl)) 7814 if (VAR_OR_FUNCTION_DECL_P (decl))
7221 { 7815 {
7222 if (VAR_P (decl)) 7816 if (VAR_P (decl))
7223 { 7817 {
7224 layout_var_decl (decl); 7818 layout_var_decl (decl);
7225 maybe_commonize_var (decl); 7819 if (!flag_weak)
7226 } 7820 /* Check again now that we have an initializer. */
7227 7821 maybe_commonize_var (decl);
7228 /* This needs to happen after the linkage is set. */ 7822 }
7229 determine_visibility (decl);
7230 7823
7231 if (var_definition_p && TREE_STATIC (decl)) 7824 if (var_definition_p && TREE_STATIC (decl))
7232 { 7825 {
7233 /* If a TREE_READONLY variable needs initialization 7826 /* If a TREE_READONLY variable needs initialization
7234 at runtime, it is no longer readonly and we need to 7827 at runtime, it is no longer readonly and we need to
7241 } 7834 }
7242 else if (was_readonly) 7835 else if (was_readonly)
7243 TREE_READONLY (decl) = 1; 7836 TREE_READONLY (decl) = 1;
7244 7837
7245 /* Likewise if it needs destruction. */ 7838 /* Likewise if it needs destruction. */
7246 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)) 7839 if (!decl_maybe_constant_destruction (decl, type))
7247 TREE_READONLY (decl) = 0; 7840 TREE_READONLY (decl) = 0;
7248 } 7841 }
7249 7842
7250 make_rtl_for_nonlocal_decl (decl, init, asmspec); 7843 make_rtl_for_nonlocal_decl (decl, init, asmspec);
7251 7844
7269 maybe_explain_implicit_delete (decl); 7862 maybe_explain_implicit_delete (decl);
7270 else if (DECL_INITIAL (decl) == error_mark_node) 7863 else if (DECL_INITIAL (decl) == error_mark_node)
7271 synthesize_method (decl); 7864 synthesize_method (decl);
7272 } 7865 }
7273 else 7866 else
7274 error ("function %q#D is initialized like a variable", decl); 7867 error_at (cp_expr_loc_or_loc (init,
7868 DECL_SOURCE_LOCATION (decl)),
7869 "function %q#D is initialized like a variable",
7870 decl);
7275 } 7871 }
7276 /* else no initialization required. */ 7872 /* else no initialization required. */
7277 } 7873 }
7278 else if (DECL_EXTERNAL (decl) 7874 else if (DECL_EXTERNAL (decl)
7279 && ! (DECL_LANG_SPECIFIC (decl) 7875 && ! (DECL_LANG_SPECIFIC (decl)
7280 && DECL_NOT_REALLY_EXTERN (decl))) 7876 && DECL_NOT_REALLY_EXTERN (decl)))
7281 { 7877 {
7282 if (init) 7878 /* check_initializer will have done any constant initialization. */
7283 DECL_INITIAL (decl) = init;
7284 } 7879 }
7285 /* A variable definition. */ 7880 /* A variable definition. */
7286 else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl)) 7881 else if (DECL_FUNCTION_SCOPE_P (decl) && !TREE_STATIC (decl))
7287 /* Initialize the local variable. */ 7882 /* Initialize the local variable. */
7288 initialize_local_var (decl, init); 7883 initialize_local_var (decl, init);
7320 DECL_ATTRIBUTES (decl) 7915 DECL_ATTRIBUTES (decl)
7321 = remove_attribute ("omp declare target implicit", 7916 = remove_attribute ("omp declare target implicit",
7322 DECL_ATTRIBUTES (decl)); 7917 DECL_ATTRIBUTES (decl));
7323 complete_type (TREE_TYPE (decl)); 7918 complete_type (TREE_TYPE (decl));
7324 if (!cp_omp_mappable_type (TREE_TYPE (decl))) 7919 if (!cp_omp_mappable_type (TREE_TYPE (decl)))
7325 error ("%q+D in declare target directive does not have mappable type", 7920 {
7326 decl); 7921 error ("%q+D in declare target directive does not have mappable"
7922 " type", decl);
7923 cp_omp_emit_unmappable_type_notes (TREE_TYPE (decl));
7924 }
7327 else if (!lookup_attribute ("omp declare target", 7925 else if (!lookup_attribute ("omp declare target",
7328 DECL_ATTRIBUTES (decl)) 7926 DECL_ATTRIBUTES (decl))
7329 && !lookup_attribute ("omp declare target link", 7927 && !lookup_attribute ("omp declare target link",
7330 DECL_ATTRIBUTES (decl))) 7928 DECL_ATTRIBUTES (decl)))
7331 DECL_ATTRIBUTES (decl) 7929 DECL_ATTRIBUTES (decl)
7498 /*path*/NULL_TREE, LOOKUP_NORMAL, 8096 /*path*/NULL_TREE, LOOKUP_NORMAL,
7499 /*fn_p*/NULL, tf_warning_or_error); 8097 /*fn_p*/NULL, tf_warning_or_error);
7500 } 8098 }
7501 else 8099 else
7502 { 8100 {
7503 vec<tree,va_gc> *args = make_tree_vector_single (e); 8101 releasing_vec args (make_tree_vector_single (e));
7504 fns = lookup_template_function (get__identifier, targs); 8102 fns = lookup_template_function (get__identifier, targs);
7505 fns = perform_koenig_lookup (fns, args, tf_warning_or_error); 8103 fns = perform_koenig_lookup (fns, args, tf_warning_or_error);
7506 return finish_call_expr (fns, &args, /*novirt*/false, 8104 return finish_call_expr (fns, &args, /*novirt*/false,
7507 /*koenig*/true, tf_warning_or_error); 8105 /*koenig*/true, tf_warning_or_error);
7508 } 8106 }
7509 } 8107 }
7510 8108
7511 /* It's impossible to recover the decltype of a tuple decomposition variable 8109 /* It's impossible to recover the decltype of a tuple decomposition variable
7512 based on the actual type of the variable, so store it in a hash table. */ 8110 based on the actual type of the variable, so store it in a hash table. */
7513 8111
7514 static GTY((cache)) tree_cache_map *decomp_type_table; 8112 static GTY((cache)) decl_tree_cache_map *decomp_type_table;
7515 static void
7516 store_decomp_type (tree v, tree t)
7517 {
7518 if (!decomp_type_table)
7519 decomp_type_table = tree_cache_map::create_ggc (13);
7520 decomp_type_table->put (v, t);
7521 }
7522 8113
7523 tree 8114 tree
7524 lookup_decomp_type (tree v) 8115 lookup_decomp_type (tree v)
7525 { 8116 {
7526 return *decomp_type_table->get (v); 8117 return *decomp_type_table->get (v);
7532 void 8123 void
7533 cp_maybe_mangle_decomp (tree decl, tree first, unsigned int count) 8124 cp_maybe_mangle_decomp (tree decl, tree first, unsigned int count)
7534 { 8125 {
7535 if (!processing_template_decl 8126 if (!processing_template_decl
7536 && !error_operand_p (decl) 8127 && !error_operand_p (decl)
7537 && DECL_NAMESPACE_SCOPE_P (decl)) 8128 && TREE_STATIC (decl))
7538 { 8129 {
7539 auto_vec<tree, 16> v; 8130 auto_vec<tree, 16> v;
7540 v.safe_grow (count); 8131 v.safe_grow (count);
7541 tree d = first; 8132 tree d = first;
7542 for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d)) 8133 for (unsigned int i = 0; i < count; i++, d = DECL_CHAIN (d))
7752 inform (dloc, "in initialization of structured binding " 8343 inform (dloc, "in initialization of structured binding "
7753 "variable %qD", v[i]); 8344 "variable %qD", v[i]);
7754 goto error_out; 8345 goto error_out;
7755 } 8346 }
7756 /* Save the decltype away before reference collapse. */ 8347 /* Save the decltype away before reference collapse. */
7757 store_decomp_type (v[i], eltype); 8348 hash_map_safe_put<hm_ggc> (decomp_type_table, v[i], eltype);
7758 eltype = cp_build_reference_type (eltype, !lvalue_p (init)); 8349 eltype = cp_build_reference_type (eltype, !lvalue_p (init));
7759 TREE_TYPE (v[i]) = eltype; 8350 TREE_TYPE (v[i]) = eltype;
7760 layout_decl (v[i], 0); 8351 layout_decl (v[i], 0);
7761 if (DECL_HAS_VALUE_EXPR_P (v[i])) 8352 if (DECL_HAS_VALUE_EXPR_P (v[i]))
7762 { 8353 {
7763 /* In this case the names are variables, not just proxies. */ 8354 /* In this case the names are variables, not just proxies. */
7764 SET_DECL_VALUE_EXPR (v[i], NULL_TREE); 8355 SET_DECL_VALUE_EXPR (v[i], NULL_TREE);
7765 DECL_HAS_VALUE_EXPR_P (v[i]) = 0; 8356 DECL_HAS_VALUE_EXPR_P (v[i]) = 0;
7766 } 8357 }
7767 if (!processing_template_decl) 8358 if (!processing_template_decl)
7768 cp_finish_decl (v[i], init, /*constexpr*/false, 8359 {
7769 /*asm*/NULL_TREE, LOOKUP_NORMAL); 8360 copy_linkage (v[i], decl);
8361 cp_finish_decl (v[i], init, /*constexpr*/false,
8362 /*asm*/NULL_TREE, LOOKUP_NORMAL);
8363 }
7770 } 8364 }
7771 /* Ignore reads from the underlying decl performed during initialization 8365 /* Ignore reads from the underlying decl performed during initialization
7772 of the individual variables. If those will be read, we'll mark 8366 of the individual variables. If those will be read, we'll mark
7773 the underlying decl as read at that point. */ 8367 the underlying decl as read at that point. */
7774 DECL_READ_P (decl) = save_read; 8368 DECL_READ_P (decl) = save_read;
8106 8700
8107 type = TREE_TYPE (decl); 8701 type = TREE_TYPE (decl);
8108 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)) 8702 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
8109 return void_node; 8703 return void_node;
8110 8704
8705 if (decl_maybe_constant_destruction (decl, type)
8706 && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
8707 {
8708 cxx_maybe_build_cleanup (decl, tf_warning_or_error);
8709 return void_node;
8710 }
8711
8111 /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or 8712 /* If we're using "__cxa_atexit" (or "__cxa_thread_atexit" or
8112 "__aeabi_atexit"), and DECL is a class object, we can just pass the 8713 "__aeabi_atexit"), and DECL is a class object, we can just pass the
8113 destructor to "__cxa_atexit"; we don't have to build a temporary 8714 destructor to "__cxa_atexit"; we don't have to build a temporary
8114 function to do the cleanup. */ 8715 function to do the cleanup. */
8115 dso_parm = (flag_use_cxa_atexit 8716 dso_parm = (flag_use_cxa_atexit
8223 { 8824 {
8224 gcc_assert (VAR_P (decl)); 8825 gcc_assert (VAR_P (decl));
8225 gcc_assert (TREE_STATIC (decl)); 8826 gcc_assert (TREE_STATIC (decl));
8226 8827
8227 /* Some variables require no dynamic initialization. */ 8828 /* Some variables require no dynamic initialization. */
8228 if (TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl))) 8829 if (decl_maybe_constant_destruction (decl, TREE_TYPE (decl)))
8229 { 8830 {
8230 /* Make sure the destructor is callable. */ 8831 /* Make sure the destructor is callable. */
8231 cxx_maybe_build_cleanup (decl, tf_warning_or_error); 8832 cxx_maybe_build_cleanup (decl, tf_warning_or_error);
8232 if (!init) 8833 if (!init)
8233 return; 8834 return;
8234 } 8835 }
8235 8836
8236 if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl) 8837 if (CP_DECL_THREAD_LOCAL_P (decl) && DECL_GNU_TLS_P (decl)
8237 && !DECL_FUNCTION_SCOPE_P (decl)) 8838 && !DECL_FUNCTION_SCOPE_P (decl))
8238 { 8839 {
8840 location_t dloc = DECL_SOURCE_LOCATION (decl);
8239 if (init) 8841 if (init)
8240 error ("non-local variable %qD declared %<__thread%> " 8842 error_at (dloc, "non-local variable %qD declared %<__thread%> "
8241 "needs dynamic initialization", decl); 8843 "needs dynamic initialization", decl);
8242 else 8844 else
8243 error ("non-local variable %qD declared %<__thread%> " 8845 error_at (dloc, "non-local variable %qD declared %<__thread%> "
8244 "has a non-trivial destructor", decl); 8846 "has a non-trivial destructor", decl);
8245 static bool informed; 8847 static bool informed;
8246 if (!informed) 8848 if (!informed)
8247 { 8849 {
8248 inform (DECL_SOURCE_LOCATION (decl), 8850 inform (dloc, "C++11 %<thread_local%> allows dynamic "
8249 "C++11 %<thread_local%> allows dynamic initialization " 8851 "initialization and destruction");
8250 "and destruction");
8251 informed = true; 8852 informed = true;
8252 } 8853 }
8253 return; 8854 return;
8254 } 8855 }
8255 8856
8321 if (!acquire_fn) 8922 if (!acquire_fn)
8322 acquire_fn = push_library_fn 8923 acquire_fn = push_library_fn
8323 (acquire_name, build_function_type_list (integer_type_node, 8924 (acquire_name, build_function_type_list (integer_type_node,
8324 TREE_TYPE (guard_addr), 8925 TREE_TYPE (guard_addr),
8325 NULL_TREE), 8926 NULL_TREE),
8326 NULL_TREE, ECF_NOTHROW | ECF_LEAF); 8927 NULL_TREE, ECF_NOTHROW);
8327 if (!release_fn || !abort_fn) 8928 if (!release_fn || !abort_fn)
8328 vfntype = build_function_type_list (void_type_node, 8929 vfntype = build_function_type_list (void_type_node,
8329 TREE_TYPE (guard_addr), 8930 TREE_TYPE (guard_addr),
8330 NULL_TREE); 8931 NULL_TREE);
8331 if (!release_fn) 8932 if (!release_fn)
8332 release_fn = push_library_fn (release_name, vfntype, NULL_TREE, 8933 release_fn = push_library_fn (release_name, vfntype, NULL_TREE,
8333 ECF_NOTHROW | ECF_LEAF); 8934 ECF_NOTHROW);
8334 if (!abort_fn) 8935 if (!abort_fn)
8335 abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE, 8936 abort_fn = push_library_fn (abort_name, vfntype, NULL_TREE,
8336 ECF_NOTHROW | ECF_LEAF); 8937 ECF_NOTHROW | ECF_LEAF);
8337 8938
8338 inner_if_stmt = begin_if_stmt (); 8939 inner_if_stmt = begin_if_stmt ();
8414 && TREE_CODE (initial_value) == CONSTRUCTOR 9015 && TREE_CODE (initial_value) == CONSTRUCTOR
8415 && !vec_safe_is_empty (CONSTRUCTOR_ELTS (initial_value))) 9016 && !vec_safe_is_empty (CONSTRUCTOR_ELTS (initial_value)))
8416 { 9017 {
8417 vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value); 9018 vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (initial_value);
8418 tree value = (*v)[0].value; 9019 tree value = (*v)[0].value;
9020 STRIP_ANY_LOCATION_WRAPPER (value);
8419 9021
8420 if (TREE_CODE (value) == STRING_CST 9022 if (TREE_CODE (value) == STRING_CST
8421 && v->length () == 1) 9023 && v->length () == 1)
8422 initial_value = value; 9024 initial_value = value;
8423 } 9025 }
8735 tree t; 9337 tree t;
8736 9338
8737 if (location == UNKNOWN_LOCATION) 9339 if (location == UNKNOWN_LOCATION)
8738 location = input_location; 9340 location = input_location;
8739 9341
8740 // Was the concept specifier present? 9342 /* Was the concept specifier present? */
8741 bool concept_p = inlinep & 4; 9343 bool concept_p = inlinep & 4;
8742 9344
8743 // Concept declarations must have a corresponding definition. 9345 /* Concept declarations must have a corresponding definition. */
8744 if (concept_p && !funcdef_flag) 9346 if (concept_p && !funcdef_flag)
8745 { 9347 {
8746 error_at (location, "concept %qD has no definition", declarator); 9348 error_at (location, "concept %qD has no definition", declarator);
8747 return NULL_TREE; 9349 return NULL_TREE;
8748 } 9350 }
8753 9355
8754 /* Set the constraints on the declaration. */ 9356 /* Set the constraints on the declaration. */
8755 if (flag_concepts) 9357 if (flag_concepts)
8756 { 9358 {
8757 tree tmpl_reqs = NULL_TREE; 9359 tree tmpl_reqs = NULL_TREE;
8758 if (processing_template_decl > template_class_depth (ctype)) 9360 tree ctx = friendp ? current_class_type : ctype;
9361 bool memtmpl = (processing_template_decl > template_class_depth (ctx));
9362 if (memtmpl)
8759 tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms); 9363 tmpl_reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
8760
8761 /* Adjust the required expression into a constraint. */
8762 if (decl_reqs)
8763 decl_reqs = normalize_expression (decl_reqs);
8764
8765 tree ci = build_constraints (tmpl_reqs, decl_reqs); 9364 tree ci = build_constraints (tmpl_reqs, decl_reqs);
9365 if (concept_p && ci)
9366 {
9367 error_at (location, "a function concept cannot be constrained");
9368 ci = NULL_TREE;
9369 }
9370 /* C++20 CA378: Remove non-templated constrained functions. */
9371 if (ci && !flag_concepts_ts
9372 && (!processing_template_decl
9373 || (friendp && !memtmpl && !funcdef_flag)))
9374 {
9375 error_at (location, "constraints on a non-templated function");
9376 ci = NULL_TREE;
9377 }
8766 set_constraints (decl, ci); 9378 set_constraints (decl, ci);
8767 } 9379 }
8768 9380
8769 if (TREE_CODE (type) == METHOD_TYPE) 9381 if (TREE_CODE (type) == METHOD_TYPE)
8770 { 9382 {
8825 9437
8826 /* A friend declaration of the form friend void f<>(). Record 9438 /* A friend declaration of the form friend void f<>(). Record
8827 the information in the TEMPLATE_ID_EXPR. */ 9439 the information in the TEMPLATE_ID_EXPR. */
8828 SET_DECL_IMPLICIT_INSTANTIATION (decl); 9440 SET_DECL_IMPLICIT_INSTANTIATION (decl);
8829 9441
8830 gcc_assert (identifier_p (fns) || TREE_CODE (fns) == OVERLOAD); 9442 gcc_assert (identifier_p (fns) || OVL_P (fns));
8831 DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args); 9443 DECL_TEMPLATE_INFO (decl) = build_template_info (fns, args);
8832 9444
8833 for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t)) 9445 for (t = TYPE_ARG_TYPES (TREE_TYPE (decl)); t; t = TREE_CHAIN (t))
8834 if (TREE_PURPOSE (t) 9446 if (TREE_PURPOSE (t)
8835 && TREE_CODE (TREE_PURPOSE (t)) == DEFAULT_ARG) 9447 && TREE_CODE (TREE_PURPOSE (t)) == DEFERRED_PARSE)
8836 { 9448 {
8837 error_at (defarg_location (TREE_PURPOSE (t)), 9449 error_at (defparse_location (TREE_PURPOSE (t)),
8838 "default arguments are not allowed in declaration " 9450 "default arguments are not allowed in declaration "
8839 "of friend template specialization %qD", 9451 "of friend template specialization %qD",
8840 decl); 9452 decl);
8841 return NULL_TREE; 9453 return NULL_TREE;
8842 } 9454 }
8860 t && t != void_list_node; t = TREE_CHAIN (t)) 9472 t && t != void_list_node; t = TREE_CHAIN (t))
8861 if (TREE_PURPOSE (t)) 9473 if (TREE_PURPOSE (t))
8862 { 9474 {
8863 permerror (DECL_SOURCE_LOCATION (decl), 9475 permerror (DECL_SOURCE_LOCATION (decl),
8864 "friend declaration of %qD specifies default " 9476 "friend declaration of %qD specifies default "
8865 "arguments and isn't a definition", decl); 9477 "arguments and isn%'t a definition", decl);
8866 break; 9478 break;
8867 } 9479 }
9480 }
9481
9482 /* FIXME: For now. */
9483 if (virtualp && (inlinep & 8) != 0)
9484 {
9485 sorry_at (DECL_SOURCE_LOCATION (decl),
9486 "%<virtual%> %<consteval%> method %qD not supported yet",
9487 decl);
9488 inlinep &= ~8;
8868 } 9489 }
8869 9490
8870 /* If this decl has namespace scope, set that up. */ 9491 /* If this decl has namespace scope, set that up. */
8871 if (in_namespace) 9492 if (in_namespace)
8872 set_decl_namespace (decl, in_namespace, friendp); 9493 set_decl_namespace (decl, in_namespace, friendp);
8912 if (inlinep & 1) 9533 if (inlinep & 1)
8913 error_at (declspecs->locations[ds_inline], 9534 error_at (declspecs->locations[ds_inline],
8914 "cannot declare %<::main%> to be inline"); 9535 "cannot declare %<::main%> to be inline");
8915 if (inlinep & 2) 9536 if (inlinep & 2)
8916 error_at (declspecs->locations[ds_constexpr], 9537 error_at (declspecs->locations[ds_constexpr],
8917 "cannot declare %<::main%> to be %<constexpr%>"); 9538 "cannot declare %<::main%> to be %qs", "constexpr");
9539 if (inlinep & 8)
9540 error_at (declspecs->locations[ds_consteval],
9541 "cannot declare %<::main%> to be %qs", "consteval");
8918 if (!publicp) 9542 if (!publicp)
8919 error_at (location, "cannot declare %<::main%> to be static"); 9543 error_at (location, "cannot declare %<::main%> to be static");
8920 inlinep = 0; 9544 inlinep = 0;
8921 publicp = 1; 9545 publicp = 1;
8922 } 9546 }
8951 if (publicp) 9575 if (publicp)
8952 DECL_COMDAT (decl) = 1; 9576 DECL_COMDAT (decl) = 1;
8953 } 9577 }
8954 if (inlinep & 2) 9578 if (inlinep & 2)
8955 DECL_DECLARED_CONSTEXPR_P (decl) = true; 9579 DECL_DECLARED_CONSTEXPR_P (decl) = true;
9580 else if (inlinep & 8)
9581 {
9582 DECL_DECLARED_CONSTEXPR_P (decl) = true;
9583 SET_DECL_IMMEDIATE_FUNCTION_P (decl);
9584 }
8956 9585
8957 // If the concept declaration specifier was found, check 9586 // If the concept declaration specifier was found, check
8958 // that the declaration satisfies the necessary requirements. 9587 // that the declaration satisfies the necessary requirements.
8959 if (concept_p) 9588 if (concept_p)
8960 { 9589 {
9034 " shadowed by implementation", suffix); 9663 " shadowed by implementation", suffix);
9035 } 9664 }
9036 else if (long_double_p) 9665 else if (long_double_p)
9037 { 9666 {
9038 if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix))) 9667 if (cpp_interpret_float_suffix (parse_in, suffix, strlen (suffix)))
9039 warning_at (location, 0, "floating point suffix %qs" 9668 warning_at (location, 0, "floating-point suffix %qs"
9040 " shadowed by implementation", suffix); 9669 " shadowed by implementation", suffix);
9041 } 9670 }
9042 /* 17.6.3.3.5 */ 9671 /* 17.6.3.3.5 */
9043 if (suffix[0] != '_' 9672 if (suffix[0] != '_'
9044 && !in_system_header_at (location)
9045 && !current_function_decl && !(friendp && !funcdef_flag)) 9673 && !current_function_decl && !(friendp && !funcdef_flag))
9046 warning_at (location, OPT_Wliteral_suffix, 9674 warning_at (location, OPT_Wliteral_suffix,
9047 "literal operator suffixes not preceded by %<_%>" 9675 "literal operator suffixes not preceded by %<_%>"
9048 " are reserved for future standardization"); 9676 " are reserved for future standardization");
9049 } 9677 }
9268 int initialized, 9896 int initialized,
9269 int type_quals, 9897 int type_quals,
9270 int inlinep, 9898 int inlinep,
9271 bool conceptp, 9899 bool conceptp,
9272 int template_count, 9900 int template_count,
9273 tree scope) 9901 tree scope,
9902 location_t location)
9274 { 9903 {
9275 tree decl; 9904 tree decl;
9276 tree explicit_scope; 9905 tree explicit_scope;
9277 9906
9278 gcc_assert (!name || identifier_p (name)); 9907 gcc_assert (!name || identifier_p (name));
9304 /* Similarly for static data members. */ 9933 /* Similarly for static data members. */
9305 || TYPE_P (scope) 9934 || TYPE_P (scope)
9306 /* Similarly for explicit specializations. */ 9935 /* Similarly for explicit specializations. */
9307 || (orig_declarator 9936 || (orig_declarator
9308 && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR))) 9937 && TREE_CODE (orig_declarator) == TEMPLATE_ID_EXPR)))
9309 decl = build_lang_decl (VAR_DECL, name, type); 9938 decl = build_lang_decl_loc (location, VAR_DECL, name, type);
9310 else 9939 else
9311 decl = build_decl (input_location, VAR_DECL, name, type); 9940 decl = build_decl (location, VAR_DECL, name, type);
9312 9941
9313 if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL) 9942 if (explicit_scope && TREE_CODE (explicit_scope) == NAMESPACE_DECL)
9314 set_decl_namespace (decl, explicit_scope, 0); 9943 set_decl_namespace (decl, explicit_scope, 0);
9315 else 9944 else
9316 DECL_CONTEXT (decl) = FROB_CONTEXT (scope); 9945 DECL_CONTEXT (decl) = FROB_CONTEXT (scope);
9381 DECL_INTERFACE_KNOWN (decl) = 1; 10010 DECL_INTERFACE_KNOWN (decl) = 1;
9382 10011
9383 if (DECL_NAME (decl) 10012 if (DECL_NAME (decl)
9384 && MAIN_NAME_P (DECL_NAME (decl)) 10013 && MAIN_NAME_P (DECL_NAME (decl))
9385 && scope == global_namespace) 10014 && scope == global_namespace)
9386 error ("cannot declare %<::main%> to be a global variable"); 10015 error_at (DECL_SOURCE_LOCATION (decl),
10016 "cannot declare %<::main%> to be a global variable");
9387 10017
9388 /* Check that the variable can be safely declared as a concept. 10018 /* Check that the variable can be safely declared as a concept.
9389 Note that this also forbids explicit specializations. */ 10019 Note that this also forbids explicit specializations. */
9390 if (conceptp) 10020 if (conceptp)
9391 { 10021 {
9398 else 10028 else
9399 DECL_DECLARED_CONCEPT_P (decl) = true; 10029 DECL_DECLARED_CONCEPT_P (decl) = true;
9400 if (!same_type_ignoring_top_level_qualifiers_p (type, boolean_type_node)) 10030 if (!same_type_ignoring_top_level_qualifiers_p (type, boolean_type_node))
9401 error_at (declspecs->locations[ds_type_spec], 10031 error_at (declspecs->locations[ds_type_spec],
9402 "concept must have type %<bool%>"); 10032 "concept must have type %<bool%>");
10033 if (TEMPLATE_PARMS_CONSTRAINTS (current_template_parms))
10034 {
10035 error_at (location, "a variable concept cannot be constrained");
10036 TEMPLATE_PARMS_CONSTRAINTS (current_template_parms) = NULL_TREE;
10037 }
9403 } 10038 }
9404 else if (flag_concepts 10039 else if (flag_concepts
9405 && processing_template_decl > template_class_depth (scope)) 10040 && processing_template_decl > template_class_depth (scope))
9406 { 10041 {
9407 tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms); 10042 tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
9408 tree ci = build_constraints (reqs, NULL_TREE); 10043 tree ci = build_constraints (reqs, NULL_TREE);
10044
9409 set_constraints (decl, ci); 10045 set_constraints (decl, ci);
9410 } 10046 }
9411 10047
9412 // Handle explicit specializations and instantiations of variable templates. 10048 // Handle explicit specializations and instantiations of variable templates.
9413 if (orig_declarator) 10049 if (orig_declarator)
9449 10085
9450 /* Let the front end know this is a pointer to member function. */ 10086 /* Let the front end know this is a pointer to member function. */
9451 TYPE_PTRMEMFUNC_FLAG (t) = 1; 10087 TYPE_PTRMEMFUNC_FLAG (t) = 1;
9452 10088
9453 field = build_decl (input_location, FIELD_DECL, pfn_identifier, type); 10089 field = build_decl (input_location, FIELD_DECL, pfn_identifier, type);
10090 DECL_NONADDRESSABLE_P (field) = 1;
9454 fields = field; 10091 fields = field;
9455 10092
9456 field = build_decl (input_location, FIELD_DECL, delta_identifier, 10093 field = build_decl (input_location, FIELD_DECL, delta_identifier,
9457 delta_type_node); 10094 delta_type_node);
10095 DECL_NONADDRESSABLE_P (field) = 1;
9458 DECL_CHAIN (field) = fields; 10096 DECL_CHAIN (field) = fields;
9459 fields = field; 10097 fields = field;
9460 10098
9461 finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node); 10099 finish_builtin_struct (t, "__ptrmemfunc_type", fields, ptr_type_node);
9462 10100
9590 tree 10228 tree
9591 fold_sizeof_expr (tree t) 10229 fold_sizeof_expr (tree t)
9592 { 10230 {
9593 tree r; 10231 tree r;
9594 if (SIZEOF_EXPR_TYPE_P (t)) 10232 if (SIZEOF_EXPR_TYPE_P (t))
9595 r = cxx_sizeof_or_alignof_type (TREE_TYPE (TREE_OPERAND (t, 0)), 10233 r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
10234 TREE_TYPE (TREE_OPERAND (t, 0)),
9596 SIZEOF_EXPR, false, false); 10235 SIZEOF_EXPR, false, false);
9597 else if (TYPE_P (TREE_OPERAND (t, 0))) 10236 else if (TYPE_P (TREE_OPERAND (t, 0)))
9598 r = cxx_sizeof_or_alignof_type (TREE_OPERAND (t, 0), SIZEOF_EXPR, 10237 r = cxx_sizeof_or_alignof_type (EXPR_LOCATION (t),
10238 TREE_OPERAND (t, 0), SIZEOF_EXPR,
9599 false, false); 10239 false, false);
9600 else 10240 else
9601 r = cxx_sizeof_or_alignof_expr (TREE_OPERAND (t, 0), SIZEOF_EXPR, 10241 r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
10242 TREE_OPERAND (t, 0), SIZEOF_EXPR,
9602 false); 10243 false);
9603 if (r == error_mark_node) 10244 if (r == error_mark_node)
9604 r = size_one_node; 10245 r = size_one_node;
9605 return r; 10246 return r;
9606 } 10247 }
9607 10248
9608 /* Given the SIZE (i.e., number of elements) in an array, compute 10249 /* Given the SIZE (i.e., number of elements) in an array, compute
9609 an appropriate index type for the array. If non-NULL, NAME is 10250 an appropriate index type for the array. If non-NULL, NAME is
9610 the name of the entity being declared. */ 10251 the name of the entity being declared. */
9611 10252
9612 tree 10253 static tree
9613 compute_array_index_type (tree name, tree size, tsubst_flags_t complain) 10254 compute_array_index_type_loc (location_t name_loc, tree name, tree size,
9614 { 10255 tsubst_flags_t complain)
9615 tree itype; 10256 {
9616 tree osize = size;
9617
9618 if (error_operand_p (size)) 10257 if (error_operand_p (size))
9619 return error_mark_node; 10258 return error_mark_node;
9620 10259
10260 /* The type of the index being computed. */
10261 tree itype;
10262
10263 /* The original numeric size as seen in the source code before
10264 conversion to size_t. */
10265 tree origsize = size;
10266
10267 location_t loc = cp_expr_loc_or_loc (size, name ? name_loc : input_location);
10268
9621 if (!type_dependent_expression_p (size)) 10269 if (!type_dependent_expression_p (size))
9622 { 10270 {
9623 osize = size = mark_rvalue_use (size); 10271 origsize = size = mark_rvalue_use (size);
9624 10272
9625 if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR 10273 if (cxx_dialect < cxx11 && TREE_CODE (size) == NOP_EXPR
9626 && TREE_SIDE_EFFECTS (size)) 10274 && TREE_SIDE_EFFECTS (size))
9627 /* In C++98, we mark a non-constant array bound with a magic 10275 /* In C++98, we mark a non-constant array bound with a magic
9628 NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case. */; 10276 NOP_EXPR with TREE_SIDE_EFFECTS; don't fold in that case. */;
9629 else 10277 else
9630 { 10278 {
9631 size = instantiate_non_dependent_expr_sfinae (size, complain); 10279 size = instantiate_non_dependent_expr_sfinae (size, complain);
9632 size = build_converted_constant_expr (size_type_node, size, complain); 10280 size = build_converted_constant_expr (size_type_node, size, complain);
9633 size = maybe_constant_value (size); 10281 /* Pedantically a constant expression is required here and so
10282 __builtin_is_constant_evaluated () should fold to true if it
10283 is successfully folded into a constant. */
10284 size = maybe_constant_value (size, NULL_TREE,
10285 /*manifestly_const_eval=*/true);
9634 10286
9635 if (!TREE_CONSTANT (size)) 10287 if (!TREE_CONSTANT (size))
9636 size = osize; 10288 size = origsize;
9637 } 10289 }
9638 10290
9639 if (error_operand_p (size)) 10291 if (error_operand_p (size))
9640 return error_mark_node; 10292 return error_mark_node;
9641 10293
9644 if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type)) 10296 if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (type))
9645 { 10297 {
9646 if (!(complain & tf_error)) 10298 if (!(complain & tf_error))
9647 return error_mark_node; 10299 return error_mark_node;
9648 if (name) 10300 if (name)
9649 error ("size of array %qD has non-integral type %qT", name, type); 10301 error_at (loc, "size of array %qD has non-integral type %qT",
10302 name, type);
9650 else 10303 else
9651 error ("size of array has non-integral type %qT", type); 10304 error_at (loc, "size of array has non-integral type %qT", type);
9652 size = integer_one_node; 10305 size = integer_one_node;
9653 } 10306 }
9654 } 10307 }
9655 10308
9656 /* A type is dependent if it is...an array type constructed from any 10309 /* A type is dependent if it is...an array type constructed from any
9675 10328
9676 if (TREE_CODE (size) != INTEGER_CST) 10329 if (TREE_CODE (size) != INTEGER_CST)
9677 { 10330 {
9678 tree folded = cp_fully_fold (size); 10331 tree folded = cp_fully_fold (size);
9679 if (TREE_CODE (folded) == INTEGER_CST) 10332 if (TREE_CODE (folded) == INTEGER_CST)
9680 pedwarn (input_location, OPT_Wpedantic, 10333 {
9681 "size of array is not an integral constant-expression"); 10334 if (name)
10335 pedwarn (loc, OPT_Wpedantic, "size of array %qD is not an "
10336 "integral constant-expression", name);
10337 else
10338 pedwarn (loc, OPT_Wpedantic,
10339 "size of array is not an integral constant-expression");
10340 }
9682 /* Use the folded result for VLAs, too; it will have resolved 10341 /* Use the folded result for VLAs, too; it will have resolved
9683 SIZEOF_EXPR. */ 10342 SIZEOF_EXPR. */
9684 size = folded; 10343 size = folded;
9685 } 10344 }
9686 10345
9687 /* Normally, the array-bound will be a constant. */ 10346 /* Normally, the array-bound will be a constant. */
9688 if (TREE_CODE (size) == INTEGER_CST) 10347 if (TREE_CODE (size) == INTEGER_CST)
9689 { 10348 {
9690 /* An array must have a positive number of elements. */ 10349 /* The size to use in diagnostics that reflects the constant
9691 if (!valid_constant_size_p (size)) 10350 size used in the source, rather than SIZE massaged above. */
10351 tree diagsize = size;
10352
10353 /* If the original size before conversion to size_t was signed
10354 and negative, convert it to ssizetype to restore the sign. */
10355 if (!TYPE_UNSIGNED (TREE_TYPE (origsize))
10356 && TREE_CODE (size) == INTEGER_CST
10357 && tree_int_cst_sign_bit (size))
10358 {
10359 diagsize = fold_convert (ssizetype, size);
10360
10361 /* Clear the overflow bit that may have been set as a result
10362 of the conversion from the sizetype of the new size to
10363 ssizetype. */
10364 TREE_OVERFLOW (diagsize) = false;
10365 }
10366
10367 /* Verify that the array has a positive number of elements
10368 and issue the appropriate diagnostic if it doesn't. */
10369 if (!valid_array_size_p (loc, diagsize, name, (complain & tf_error)))
9692 { 10370 {
9693 if (!(complain & tf_error)) 10371 if (!(complain & tf_error))
9694 return error_mark_node; 10372 return error_mark_node;
9695
9696 if (name)
9697 error ("size of array %qD is negative", name);
9698 else
9699 error ("size of array is negative");
9700 size = integer_one_node; 10373 size = integer_one_node;
9701 } 10374 }
9702 /* As an extension we allow zero-sized arrays. */ 10375 /* As an extension we allow zero-sized arrays. */
9703 else if (integer_zerop (size)) 10376 else if (integer_zerop (size))
9704 { 10377 {
9705 if (!(complain & tf_error)) 10378 if (!(complain & tf_error))
9706 /* We must fail if performing argument deduction (as 10379 /* We must fail if performing argument deduction (as
9707 indicated by the state of complain), so that 10380 indicated by the state of complain), so that
9708 another substitution can be found. */ 10381 another substitution can be found. */
9709 return error_mark_node; 10382 return error_mark_node;
9710 else if (in_system_header_at (input_location))
9711 /* Allow them in system headers because glibc uses them. */;
9712 else if (name) 10383 else if (name)
9713 pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids zero-size array %qD", name); 10384 pedwarn (loc, OPT_Wpedantic,
10385 "ISO C++ forbids zero-size array %qD", name);
9714 else 10386 else
9715 pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids zero-size array"); 10387 pedwarn (loc, OPT_Wpedantic,
10388 "ISO C++ forbids zero-size array");
9716 } 10389 }
9717 } 10390 }
9718 else if (TREE_CONSTANT (size) 10391 else if (TREE_CONSTANT (size)
9719 /* We don't allow VLAs at non-function scopes, or during 10392 /* We don't allow VLAs at non-function scopes, or during
9720 tentative template substitution. */ 10393 tentative template substitution. */
9723 { 10396 {
9724 if (!(complain & tf_error)) 10397 if (!(complain & tf_error))
9725 return error_mark_node; 10398 return error_mark_node;
9726 /* `(int) &fn' is not a valid array bound. */ 10399 /* `(int) &fn' is not a valid array bound. */
9727 if (name) 10400 if (name)
9728 error ("size of array %qD is not an integral constant-expression", 10401 error_at (loc,
9729 name); 10402 "size of array %qD is not an integral constant-expression",
10403 name);
9730 else 10404 else
9731 error ("size of array is not an integral constant-expression"); 10405 error_at (loc, "size of array is not an integral constant-expression");
9732 size = integer_one_node; 10406 size = integer_one_node;
9733 } 10407 }
9734 else if (pedantic && warn_vla != 0) 10408 else if (pedantic && warn_vla != 0)
9735 { 10409 {
9736 if (name) 10410 if (name)
9737 pedwarn (input_location, OPT_Wvla, "ISO C++ forbids variable length array %qD", name); 10411 pedwarn (name_loc, OPT_Wvla,
10412 "ISO C++ forbids variable length array %qD", name);
9738 else 10413 else
9739 pedwarn (input_location, OPT_Wvla, "ISO C++ forbids variable length array"); 10414 pedwarn (input_location, OPT_Wvla,
10415 "ISO C++ forbids variable length array");
9740 } 10416 }
9741 else if (warn_vla > 0) 10417 else if (warn_vla > 0)
9742 { 10418 {
9743 if (name) 10419 if (name)
9744 warning (OPT_Wvla, 10420 warning_at (name_loc, OPT_Wvla,
9745 "variable length array %qD is used", name); 10421 "variable length array %qD is used", name);
9746 else 10422 else
9747 warning (OPT_Wvla, 10423 warning (OPT_Wvla,
9748 "variable length array is used"); 10424 "variable length array is used");
9749 } 10425 }
9750 10426
9807 TYPE_DEPENDENT_P (itype) = 0; 10483 TYPE_DEPENDENT_P (itype) = 0;
9808 TYPE_DEPENDENT_P_VALID (itype) = 1; 10484 TYPE_DEPENDENT_P_VALID (itype) = 1;
9809 return itype; 10485 return itype;
9810 } 10486 }
9811 10487
10488 tree
10489 compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
10490 {
10491 return compute_array_index_type_loc (input_location, name, size, complain);
10492 }
10493
9812 /* Returns the scope (if any) in which the entity declared by 10494 /* Returns the scope (if any) in which the entity declared by
9813 DECLARATOR will be located. If the entity was declared with an 10495 DECLARATOR will be located. If the entity was declared with an
9814 unqualified name, NULL_TREE is returned. */ 10496 unqualified name, NULL_TREE is returned. */
9815 10497
9816 tree 10498 tree
9833 /* Returns an ARRAY_TYPE for an array with SIZE elements of the 10515 /* Returns an ARRAY_TYPE for an array with SIZE elements of the
9834 indicated TYPE. If non-NULL, NAME is the NAME of the declaration 10516 indicated TYPE. If non-NULL, NAME is the NAME of the declaration
9835 with this type. */ 10517 with this type. */
9836 10518
9837 static tree 10519 static tree
9838 create_array_type_for_decl (tree name, tree type, tree size) 10520 create_array_type_for_decl (tree name, tree type, tree size, location_t loc)
9839 { 10521 {
9840 tree itype = NULL_TREE; 10522 tree itype = NULL_TREE;
9841 10523
9842 /* If things have already gone awry, bail now. */ 10524 /* If things have already gone awry, bail now. */
9843 if (type == error_mark_node || size == error_mark_node) 10525 if (type == error_mark_node || size == error_mark_node)
9846 /* 8.3.4/1: If the type of the identifier of D contains the auto 10528 /* 8.3.4/1: If the type of the identifier of D contains the auto
9847 type-specifier, the program is ill-formed. */ 10529 type-specifier, the program is ill-formed. */
9848 if (type_uses_auto (type)) 10530 if (type_uses_auto (type))
9849 { 10531 {
9850 if (name) 10532 if (name)
9851 error ("%qD declared as array of %qT", name, type); 10533 error_at (loc, "%qD declared as array of %qT", name, type);
9852 else 10534 else
9853 error ("creating array of %qT", type); 10535 error ("creating array of %qT", type);
9854 return error_mark_node; 10536 return error_mark_node;
9855 } 10537 }
9856 10538
9857 /* If there are some types which cannot be array elements, 10539 /* If there are some types which cannot be array elements,
9858 issue an error-message and return. */ 10540 issue an error-message and return. */
9859 switch (TREE_CODE (type)) 10541 switch (TREE_CODE (type))
9860 { 10542 {
9861 case VOID_TYPE: 10543 case VOID_TYPE:
9862 if (name) 10544 if (name)
9863 error ("declaration of %qD as array of void", name); 10545 error_at (loc, "declaration of %qD as array of void", name);
9864 else 10546 else
9865 error ("creating array of void"); 10547 error ("creating array of void");
9866 return error_mark_node; 10548 return error_mark_node;
9867 10549
9868 case FUNCTION_TYPE: 10550 case FUNCTION_TYPE:
9869 if (name) 10551 if (name)
9870 error ("declaration of %qD as array of functions", name); 10552 error_at (loc, "declaration of %qD as array of functions", name);
9871 else 10553 else
9872 error ("creating array of functions"); 10554 error ("creating array of functions");
9873 return error_mark_node; 10555 return error_mark_node;
9874 10556
9875 case REFERENCE_TYPE: 10557 case REFERENCE_TYPE:
9876 if (name) 10558 if (name)
9877 error ("declaration of %qD as array of references", name); 10559 error_at (loc, "declaration of %qD as array of references", name);
9878 else 10560 else
9879 error ("creating array of references"); 10561 error ("creating array of references");
9880 return error_mark_node; 10562 return error_mark_node;
9881 10563
9882 case METHOD_TYPE: 10564 case METHOD_TYPE:
9883 if (name) 10565 if (name)
9884 error ("declaration of %qD as array of function members", name); 10566 error_at (loc, "declaration of %qD as array of function members",
10567 name);
9885 else 10568 else
9886 error ("creating array of function members"); 10569 error ("creating array of function members");
9887 return error_mark_node; 10570 return error_mark_node;
9888 10571
9889 default: 10572 default:
9890 break; 10573 break;
9891 } 10574 }
9892 10575
10576 if (!verify_type_context (name ? loc : input_location,
10577 TCTX_ARRAY_ELEMENT, type))
10578 return error_mark_node;
10579
9893 /* [dcl.array] 10580 /* [dcl.array]
9894 10581
9895 The constant expressions that specify the bounds of the arrays 10582 The constant expressions that specify the bounds of the arrays
9896 can be omitted only for the first member of the sequence. */ 10583 can be omitted only for the first member of the sequence. */
9897 if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)) 10584 if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type))
9898 { 10585 {
9899 if (name) 10586 if (name)
9900 error ("declaration of %qD as multidimensional array must " 10587 error_at (loc, "declaration of %qD as multidimensional array must "
9901 "have bounds for all dimensions except the first", 10588 "have bounds for all dimensions except the first",
9902 name); 10589 name);
9903 else 10590 else
9904 error ("multidimensional array must have bounds for all " 10591 error ("multidimensional array must have bounds for all "
9905 "dimensions except the first"); 10592 "dimensions except the first");
9906 10593
9907 return error_mark_node; 10594 return error_mark_node;
9908 } 10595 }
9909 10596
9910 /* Figure out the index type for the array. */ 10597 /* Figure out the index type for the array. */
9911 if (size) 10598 if (size)
9912 itype = compute_array_index_type (name, size, tf_warning_or_error); 10599 itype = compute_array_index_type_loc (loc, name, size,
10600 tf_warning_or_error);
9913 10601
9914 /* [dcl.array] 10602 /* [dcl.array]
9915 T is called the array element type; this type shall not be [...] an 10603 T is called the array element type; this type shall not be [...] an
9916 abstract class type. */ 10604 abstract class type. */
9917 abstract_virtuals_error (name, type); 10605 abstract_virtuals_error (name, type);
9948 10636
9949 if (type_quals & TYPE_QUAL_RESTRICT) 10637 if (type_quals & TYPE_QUAL_RESTRICT)
9950 loc = min_location (loc, locations[ds_restrict]); 10638 loc = min_location (loc, locations[ds_restrict]);
9951 10639
9952 return loc; 10640 return loc;
10641 }
10642
10643 /* Returns the smallest among the latter and locations[ds_type_spec]. */
10644
10645 static location_t
10646 smallest_type_location (int type_quals, const location_t* locations)
10647 {
10648 location_t loc = smallest_type_quals_location (type_quals, locations);
10649 return min_location (loc, locations[ds_type_spec]);
10650 }
10651
10652 static location_t
10653 smallest_type_location (const cp_decl_specifier_seq *declspecs)
10654 {
10655 int type_quals = get_type_quals (declspecs);
10656 return smallest_type_location (type_quals, declspecs->locations);
9953 } 10657 }
9954 10658
9955 /* Check that it's OK to declare a function with the indicated TYPE 10659 /* Check that it's OK to declare a function with the indicated TYPE
9956 and TYPE_QUALS. SFK indicates the kind of special function (if any) 10660 and TYPE_QUALS. SFK indicates the kind of special function (if any)
9957 that this function is. OPTYPE is the type given in a conversion 10661 that this function is. OPTYPE is the type given in a conversion
9968 { 10672 {
9969 switch (sfk) 10673 switch (sfk)
9970 { 10674 {
9971 case sfk_constructor: 10675 case sfk_constructor:
9972 if (type) 10676 if (type)
9973 error ("return type specification for constructor invalid"); 10677 error_at (smallest_type_location (type_quals, locations),
10678 "return type specification for constructor invalid");
9974 else if (type_quals != TYPE_UNQUALIFIED) 10679 else if (type_quals != TYPE_UNQUALIFIED)
9975 error_at (smallest_type_quals_location (type_quals, locations), 10680 error_at (smallest_type_quals_location (type_quals, locations),
9976 "qualifiers are not allowed on constructor declaration"); 10681 "qualifiers are not allowed on constructor declaration");
9977 10682
9978 if (targetm.cxx.cdtor_returns_this ()) 10683 if (targetm.cxx.cdtor_returns_this ())
9981 type = void_type_node; 10686 type = void_type_node;
9982 break; 10687 break;
9983 10688
9984 case sfk_destructor: 10689 case sfk_destructor:
9985 if (type) 10690 if (type)
9986 error ("return type specification for destructor invalid"); 10691 error_at (smallest_type_location (type_quals, locations),
10692 "return type specification for destructor invalid");
9987 else if (type_quals != TYPE_UNQUALIFIED) 10693 else if (type_quals != TYPE_UNQUALIFIED)
9988 error_at (smallest_type_quals_location (type_quals, locations), 10694 error_at (smallest_type_quals_location (type_quals, locations),
9989 "qualifiers are not allowed on destructor declaration"); 10695 "qualifiers are not allowed on destructor declaration");
9990 10696
9991 /* We can't use the proper return type here because we run into 10697 /* We can't use the proper return type here because we run into
9996 type = void_type_node; 10702 type = void_type_node;
9997 break; 10703 break;
9998 10704
9999 case sfk_conversion: 10705 case sfk_conversion:
10000 if (type) 10706 if (type)
10001 error ("return type specified for %<operator %T%>", optype); 10707 error_at (smallest_type_location (type_quals, locations),
10708 "return type specified for %<operator %T%>", optype);
10002 else if (type_quals != TYPE_UNQUALIFIED) 10709 else if (type_quals != TYPE_UNQUALIFIED)
10003 error_at (smallest_type_quals_location (type_quals, locations), 10710 error_at (smallest_type_quals_location (type_quals, locations),
10004 "qualifiers are not allowed on declaration of " 10711 "qualifiers are not allowed on declaration of "
10005 "%<operator %T%>", optype); 10712 "%<operator %T%>", optype);
10006 10713
10007 type = optype; 10714 type = optype;
10008 break; 10715 break;
10009 10716
10010 case sfk_deduction_guide: 10717 case sfk_deduction_guide:
10011 if (type) 10718 if (type)
10012 error ("return type specified for deduction guide"); 10719 error_at (smallest_type_location (type_quals, locations),
10720 "return type specified for deduction guide");
10013 else if (type_quals != TYPE_UNQUALIFIED) 10721 else if (type_quals != TYPE_UNQUALIFIED)
10014 error_at (smallest_type_quals_location (type_quals, locations), 10722 error_at (smallest_type_quals_location (type_quals, locations),
10015 "qualifiers are not allowed on declaration of " 10723 "qualifiers are not allowed on declaration of "
10016 "deduction guide"); 10724 "deduction guide");
10017 if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM) 10725 if (TREE_CODE (optype) == TEMPLATE_TEMPLATE_PARM)
10023 else 10731 else
10024 type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype)); 10732 type = make_template_placeholder (CLASSTYPE_TI_TEMPLATE (optype));
10025 for (int i = 0; i < ds_last; ++i) 10733 for (int i = 0; i < ds_last; ++i)
10026 if (i != ds_explicit && locations[i]) 10734 if (i != ds_explicit && locations[i])
10027 error_at (locations[i], 10735 error_at (locations[i],
10028 "decl-specifier in declaration of deduction guide"); 10736 "%<decl-specifier%> in declaration of deduction guide");
10029 break; 10737 break;
10030 10738
10031 default: 10739 default:
10032 gcc_unreachable (); 10740 gcc_unreachable ();
10033 } 10741 }
10039 has been declared with the indicated TYPE. If the TYPE is not 10747 has been declared with the indicated TYPE. If the TYPE is not
10040 acceptable, issue an error message and return a type to use for 10748 acceptable, issue an error message and return a type to use for
10041 error-recovery purposes. */ 10749 error-recovery purposes. */
10042 10750
10043 tree 10751 tree
10044 check_var_type (tree identifier, tree type) 10752 check_var_type (tree identifier, tree type, location_t loc)
10045 { 10753 {
10046 if (VOID_TYPE_P (type)) 10754 if (VOID_TYPE_P (type))
10047 { 10755 {
10048 if (!identifier) 10756 if (!identifier)
10049 error ("unnamed variable or field declared void"); 10757 error_at (loc, "unnamed variable or field declared void");
10050 else if (identifier_p (identifier)) 10758 else if (identifier_p (identifier))
10051 { 10759 {
10052 gcc_assert (!IDENTIFIER_ANY_OP_P (identifier)); 10760 gcc_assert (!IDENTIFIER_ANY_OP_P (identifier));
10053 error ("variable or field %qE declared void", identifier); 10761 error_at (loc, "variable or field %qE declared void",
10762 identifier);
10054 } 10763 }
10055 else 10764 else
10056 error ("variable or field declared void"); 10765 error_at (loc, "variable or field declared void");
10057 type = error_mark_node; 10766 type = error_mark_node;
10058 } 10767 }
10059 10768
10060 return type; 10769 return type;
10061 } 10770 }
10072 "%qD declared at block scope", decl); 10781 "%qD declared at block scope", decl);
10073 inlinep = false; 10782 inlinep = false;
10074 } 10783 }
10075 else if (cxx_dialect < cxx17) 10784 else if (cxx_dialect < cxx17)
10076 pedwarn (loc, 0, "inline variables are only available " 10785 pedwarn (loc, 0, "inline variables are only available "
10077 "with -std=c++17 or -std=gnu++17"); 10786 "with %<-std=c++17%> or %<-std=gnu++17%>");
10078 if (inlinep) 10787 if (inlinep)
10079 { 10788 {
10080 retrofit_lang_decl (decl); 10789 retrofit_lang_decl (decl);
10081 SET_DECL_VAR_DECLARED_INLINE_P (decl); 10790 SET_DECL_VAR_DECLARED_INLINE_P (decl);
10082 } 10791 }
10092 { 10801 {
10093 gcc_assert (TYPE_UNNAMED_P (type)); 10802 gcc_assert (TYPE_UNNAMED_P (type));
10094 10803
10095 /* Replace the anonymous name with the real name everywhere. */ 10804 /* Replace the anonymous name with the real name everywhere. */
10096 for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) 10805 for (tree t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t))
10097 { 10806 if (IDENTIFIER_ANON_P (TYPE_IDENTIFIER (t)))
10098 if (anon_aggrname_p (TYPE_IDENTIFIER (t))) 10807 /* We do not rename the debug info representing the unnamed
10099 /* We do not rename the debug info representing the 10808 tagged type because the standard says in [dcl.typedef] that
10100 unnamed tagged type because the standard says in 10809 the naming applies only for linkage purposes. */
10101 [dcl.typedef] that the naming applies only for 10810 /*debug_hooks->set_name (t, decl);*/
10102 linkage purposes. */ 10811 TYPE_NAME (t) = decl;
10103 /*debug_hooks->set_name (t, decl);*/
10104 TYPE_NAME (t) = decl;
10105 }
10106
10107 if (TYPE_LANG_SPECIFIC (type))
10108 TYPE_WAS_UNNAMED (type) = 1;
10109 10812
10110 /* If this is a typedef within a template class, the nested 10813 /* If this is a typedef within a template class, the nested
10111 type is a (non-primary) template. The name for the 10814 type is a (non-primary) template. The name for the
10112 template needs updating as well. */ 10815 template needs updating as well. */
10113 if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type)) 10816 if (TYPE_LANG_SPECIFIC (type) && CLASSTYPE_TEMPLATE_INFO (type))
10178 tree* attrlist) 10881 tree* attrlist)
10179 { 10882 {
10180 tree type = NULL_TREE; 10883 tree type = NULL_TREE;
10181 int longlong = 0; 10884 int longlong = 0;
10182 int explicit_intN = 0; 10885 int explicit_intN = 0;
10886 int int_n_alt = 0;
10183 int virtualp, explicitp, friendp, inlinep, staticp; 10887 int virtualp, explicitp, friendp, inlinep, staticp;
10184 int explicit_int = 0; 10888 int explicit_int = 0;
10185 int explicit_char = 0; 10889 int explicit_char = 0;
10186 int defaulted_int = 0; 10890 int defaulted_int = 0;
10187 10891
10213 cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED; 10917 cp_virt_specifiers virt_specifiers = VIRT_SPEC_UNSPECIFIED;
10214 /* ref-qualifier that applies to the declarator, for a declaration of 10918 /* ref-qualifier that applies to the declarator, for a declaration of
10215 a member function. */ 10919 a member function. */
10216 cp_ref_qualifier rqual = REF_QUAL_NONE; 10920 cp_ref_qualifier rqual = REF_QUAL_NONE;
10217 /* cv-qualifiers that apply to the type specified by the DECLSPECS. */ 10921 /* cv-qualifiers that apply to the type specified by the DECLSPECS. */
10218 int type_quals = TYPE_UNQUALIFIED; 10922 int type_quals = get_type_quals (declspecs);
10219 tree raises = NULL_TREE; 10923 tree raises = NULL_TREE;
10220 int template_count = 0; 10924 int template_count = 0;
10221 tree returned_attrs = NULL_TREE; 10925 tree returned_attrs = NULL_TREE;
10222 tree parms = NULL_TREE; 10926 tree parms = NULL_TREE;
10223 const cp_declarator *id_declarator; 10927 const cp_declarator *id_declarator;
10240 bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false; 10944 bool parameter_pack_p = declarator ? declarator->parameter_pack_p : false;
10241 bool template_type_arg = false; 10945 bool template_type_arg = false;
10242 bool template_parm_flag = false; 10946 bool template_parm_flag = false;
10243 bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef); 10947 bool typedef_p = decl_spec_seq_has_spec_p (declspecs, ds_typedef);
10244 bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr); 10948 bool constexpr_p = decl_spec_seq_has_spec_p (declspecs, ds_constexpr);
10949 bool constinit_p = decl_spec_seq_has_spec_p (declspecs, ds_constinit);
10950 bool consteval_p = decl_spec_seq_has_spec_p (declspecs, ds_consteval);
10245 bool late_return_type_p = false; 10951 bool late_return_type_p = false;
10246 bool array_parameter_p = false; 10952 bool array_parameter_p = false;
10247 source_location saved_loc = input_location;
10248 tree reqs = NULL_TREE; 10953 tree reqs = NULL_TREE;
10249 10954
10250 signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed); 10955 signed_p = decl_spec_seq_has_spec_p (declspecs, ds_signed);
10251 unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned); 10956 unsigned_p = decl_spec_seq_has_spec_p (declspecs, ds_unsigned);
10252 short_p = decl_spec_seq_has_spec_p (declspecs, ds_short); 10957 short_p = decl_spec_seq_has_spec_p (declspecs, ds_short);
10253 long_p = decl_spec_seq_has_spec_p (declspecs, ds_long); 10958 long_p = decl_spec_seq_has_spec_p (declspecs, ds_long);
10254 longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long); 10959 longlong = decl_spec_seq_has_spec_p (declspecs, ds_long_long);
10255 explicit_intN = declspecs->explicit_intN_p; 10960 explicit_intN = declspecs->explicit_intN_p;
10961 int_n_alt = declspecs->int_n_alt;
10256 thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread); 10962 thread_p = decl_spec_seq_has_spec_p (declspecs, ds_thread);
10257 10963
10258 // Was concept_p specified? Note that ds_concept 10964 // Was concept_p specified? Note that ds_concept
10259 // implies ds_constexpr! 10965 // implies ds_constexpr!
10260 bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept); 10966 bool concept_p = decl_spec_seq_has_spec_p (declspecs, ds_concept);
10261 if (concept_p) 10967 if (concept_p)
10262 constexpr_p = true; 10968 constexpr_p = true;
10263
10264 if (decl_spec_seq_has_spec_p (declspecs, ds_const))
10265 type_quals |= TYPE_QUAL_CONST;
10266 if (decl_spec_seq_has_spec_p (declspecs, ds_volatile))
10267 type_quals |= TYPE_QUAL_VOLATILE;
10268 if (decl_spec_seq_has_spec_p (declspecs, ds_restrict))
10269 type_quals |= TYPE_QUAL_RESTRICT;
10270 10969
10271 if (decl_context == FUNCDEF) 10970 if (decl_context == FUNCDEF)
10272 funcdef_flag = true, decl_context = NORMAL; 10971 funcdef_flag = true, decl_context = NORMAL;
10273 else if (decl_context == MEMFUNCDEF) 10972 else if (decl_context == MEMFUNCDEF)
10274 funcdef_flag = true, decl_context = FIELD; 10973 funcdef_flag = true, decl_context = FIELD;
10280 template_parm_flag = true, decl_context = PARM; 10979 template_parm_flag = true, decl_context = PARM;
10281 10980
10282 if (initialized > 1) 10981 if (initialized > 1)
10283 funcdef_flag = true; 10982 funcdef_flag = true;
10284 10983
10285 location_t typespec_loc = smallest_type_quals_location (type_quals, 10984 location_t typespec_loc = smallest_type_location (type_quals,
10286 declspecs->locations); 10985 declspecs->locations);
10287 if (typespec_loc == UNKNOWN_LOCATION)
10288 typespec_loc = declspecs->locations[ds_type_spec];
10289 if (typespec_loc == UNKNOWN_LOCATION) 10986 if (typespec_loc == UNKNOWN_LOCATION)
10290 typespec_loc = input_location; 10987 typespec_loc = input_location;
10988
10989 location_t id_loc = declarator ? declarator->id_loc : input_location;
10990 if (id_loc == UNKNOWN_LOCATION)
10991 id_loc = input_location;
10291 10992
10292 /* Look inside a declarator for the name being declared 10993 /* Look inside a declarator for the name being declared
10293 and get it as a string, for an error message. */ 10994 and get it as a string, for an error message. */
10294 for (id_declarator = declarator; 10995 for (id_declarator = declarator;
10295 id_declarator; 10996 id_declarator;
10344 else if (TYPE_P (qualifying_scope)) 11045 else if (TYPE_P (qualifying_scope))
10345 { 11046 {
10346 ctype = qualifying_scope; 11047 ctype = qualifying_scope;
10347 if (!MAYBE_CLASS_TYPE_P (ctype)) 11048 if (!MAYBE_CLASS_TYPE_P (ctype))
10348 { 11049 {
10349 error ("%q#T is not a class or a namespace", ctype); 11050 error_at (id_declarator->id_loc,
11051 "%q#T is not a class or namespace", ctype);
10350 ctype = NULL_TREE; 11052 ctype = NULL_TREE;
10351 } 11053 }
10352 else if (innermost_code != cdk_function 11054 else if (innermost_code != cdk_function
10353 && current_class_type 11055 && current_class_type
10354 && !uniquely_derived_from_p (ctype, 11056 && !uniquely_derived_from_p (ctype,
10355 current_class_type)) 11057 current_class_type))
10356 { 11058 {
10357 error ("invalid use of qualified-name %<%T::%D%>", 11059 error_at (id_declarator->id_loc,
10358 qualifying_scope, decl); 11060 "invalid use of qualified-name %<%T::%D%>",
11061 qualifying_scope, decl);
10359 return error_mark_node; 11062 return error_mark_node;
10360 } 11063 }
10361 } 11064 }
10362 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL) 11065 else if (TREE_CODE (qualifying_scope) == NAMESPACE_DECL)
10363 in_namespace = qualifying_scope; 11066 in_namespace = qualifying_scope;
10366 { 11069 {
10367 case BIT_NOT_EXPR: 11070 case BIT_NOT_EXPR:
10368 { 11071 {
10369 if (innermost_code != cdk_function) 11072 if (innermost_code != cdk_function)
10370 { 11073 {
10371 error ("declaration of %qD as non-function", decl); 11074 error_at (EXPR_LOCATION (decl),
11075 "declaration of %qE as non-function", decl);
10372 return error_mark_node; 11076 return error_mark_node;
10373 } 11077 }
10374 else if (!qualifying_scope 11078 else if (!qualifying_scope
10375 && !(current_class_type && at_class_scope_p ())) 11079 && !(current_class_type && at_class_scope_p ()))
10376 { 11080 {
10377 error ("declaration of %qD as non-member", decl); 11081 error_at (EXPR_LOCATION (decl),
11082 "declaration of %qE as non-member", decl);
10378 return error_mark_node; 11083 return error_mark_node;
10379 } 11084 }
10380 11085
10381 tree type = TREE_OPERAND (decl, 0); 11086 tree type = TREE_OPERAND (decl, 0);
10382 if (TYPE_P (type)) 11087 if (TYPE_P (type))
10451 11156
10452 The declarator in a function-definition shall have the form 11157 The declarator in a function-definition shall have the form
10453 D1 ( parameter-declaration-clause) ... */ 11158 D1 ( parameter-declaration-clause) ... */
10454 if (funcdef_flag && innermost_code != cdk_function) 11159 if (funcdef_flag && innermost_code != cdk_function)
10455 { 11160 {
10456 error ("function definition does not declare parameters"); 11161 error_at (id_loc, "function definition does not declare parameters");
10457 return error_mark_node; 11162 return error_mark_node;
10458 } 11163 }
10459 11164
10460 if (flags == TYPENAME_FLAG 11165 if (flags == TYPENAME_FLAG
10461 && innermost_code != cdk_function 11166 && innermost_code != cdk_function
10462 && ! (ctype && !declspecs->any_specifiers_p)) 11167 && ! (ctype && !declspecs->any_specifiers_p))
10463 { 11168 {
10464 error ("declaration of %qD as non-function", dname); 11169 error_at (id_loc, "declaration of %qD as non-function", dname);
10465 return error_mark_node; 11170 return error_mark_node;
10466 } 11171 }
10467 11172
10468 if (dname && identifier_p (dname)) 11173 if (dname && identifier_p (dname))
10469 { 11174 {
10470 if (UDLIT_OPER_P (dname) 11175 if (UDLIT_OPER_P (dname)
10471 && innermost_code != cdk_function) 11176 && innermost_code != cdk_function)
10472 { 11177 {
10473 error ("declaration of %qD as non-function", dname); 11178 error_at (id_loc, "declaration of %qD as non-function", dname);
10474 return error_mark_node; 11179 return error_mark_node;
10475 } 11180 }
10476 11181
10477 if (IDENTIFIER_ANY_OP_P (dname)) 11182 if (IDENTIFIER_ANY_OP_P (dname))
10478 { 11183 {
10479 if (typedef_p) 11184 if (typedef_p)
10480 { 11185 {
10481 error ("declaration of %qD as %<typedef%>", dname); 11186 error_at (id_loc, "declaration of %qD as %<typedef%>", dname);
10482 return error_mark_node; 11187 return error_mark_node;
10483 } 11188 }
10484 else if (decl_context == PARM || decl_context == CATCHPARM) 11189 else if (decl_context == PARM || decl_context == CATCHPARM)
10485 { 11190 {
10486 error ("declaration of %qD as parameter", dname); 11191 error_at (id_loc, "declaration of %qD as parameter", dname);
10487 return error_mark_node; 11192 return error_mark_node;
10488 } 11193 }
10489 } 11194 }
10490 } 11195 }
10491 11196
10513 } 11218 }
10514 11219
10515 if (name == NULL) 11220 if (name == NULL)
10516 name = decl_context == PARM ? "parameter" : "type name"; 11221 name = decl_context == PARM ? "parameter" : "type name";
10517 11222
11223 if (consteval_p && constexpr_p)
11224 {
11225 error_at (declspecs->locations[ds_consteval],
11226 "both %qs and %qs specified", "constexpr", "consteval");
11227 return error_mark_node;
11228 }
11229
10518 if (concept_p && typedef_p) 11230 if (concept_p && typedef_p)
10519 { 11231 {
10520 error_at (declspecs->locations[ds_concept], 11232 error_at (declspecs->locations[ds_concept],
10521 "%<concept%> cannot appear in a typedef declaration"); 11233 "%qs cannot appear in a typedef declaration", "concept");
10522 return error_mark_node; 11234 return error_mark_node;
10523 } 11235 }
10524 11236
10525 if (constexpr_p && typedef_p) 11237 if (constexpr_p && typedef_p)
10526 { 11238 {
10527 error_at (declspecs->locations[ds_constexpr], 11239 error_at (declspecs->locations[ds_constexpr],
10528 "%<constexpr%> cannot appear in a typedef declaration"); 11240 "%qs cannot appear in a typedef declaration", "constexpr");
11241 return error_mark_node;
11242 }
11243
11244 if (consteval_p && typedef_p)
11245 {
11246 error_at (declspecs->locations[ds_consteval],
11247 "%qs cannot appear in a typedef declaration", "consteval");
11248 return error_mark_node;
11249 }
11250
11251 if (constinit_p && typedef_p)
11252 {
11253 error_at (declspecs->locations[ds_constinit],
11254 "%<constinit%> cannot appear in a typedef declaration");
11255 return error_mark_node;
11256 }
11257
11258 /* [dcl.spec]/2 "At most one of the constexpr, consteval, and constinit
11259 keywords shall appear in a decl-specifier-seq." */
11260 if (constinit_p && constexpr_p)
11261 {
11262 gcc_rich_location richloc (declspecs->locations[ds_constinit]);
11263 richloc.add_range (declspecs->locations[ds_constexpr]);
11264 error_at (&richloc,
11265 "can use at most one of the %<constinit%> and %<constexpr%> "
11266 "specifiers");
10529 return error_mark_node; 11267 return error_mark_node;
10530 } 11268 }
10531 11269
10532 /* If there were multiple types specified in the decl-specifier-seq, 11270 /* If there were multiple types specified in the decl-specifier-seq,
10533 issue an error message. */ 11271 issue an error message. */
10534 if (declspecs->multiple_types_p) 11272 if (declspecs->multiple_types_p)
10535 { 11273 {
10536 error ("two or more data types in declaration of %qs", name); 11274 error_at (typespec_loc,
11275 "two or more data types in declaration of %qs", name);
10537 return error_mark_node; 11276 return error_mark_node;
10538 } 11277 }
10539 11278
10540 if (declspecs->conflicting_specifiers_p) 11279 if (declspecs->conflicting_specifiers_p)
10541 { 11280 {
10542 error ("conflicting specifiers in declaration of %qs", name); 11281 error_at (min_location (declspecs->locations[ds_typedef],
11282 declspecs->locations[ds_storage_class]),
11283 "conflicting specifiers in declaration of %qs", name);
10543 return error_mark_node; 11284 return error_mark_node;
10544 } 11285 }
10545 11286
10546 /* Extract the basic type from the decl-specifier-seq. */ 11287 /* Extract the basic type from the decl-specifier-seq. */
10547 type = declspecs->type; 11288 type = declspecs->type;
10551 type_was_error_mark_node = true; 11292 type_was_error_mark_node = true;
10552 } 11293 }
10553 cp_warn_deprecated_use (type); 11294 cp_warn_deprecated_use (type);
10554 if (type && TREE_CODE (type) == TYPE_DECL) 11295 if (type && TREE_CODE (type) == TYPE_DECL)
10555 { 11296 {
11297 cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (type));
10556 typedef_decl = type; 11298 typedef_decl = type;
10557 type = TREE_TYPE (typedef_decl); 11299 type = TREE_TYPE (typedef_decl);
10558 if (DECL_ARTIFICIAL (typedef_decl)) 11300 if (DECL_ARTIFICIAL (typedef_decl))
10559 cp_warn_deprecated_use (type); 11301 cp_warn_deprecated_use (type);
10560 } 11302 }
10618 && in_namespace == NULL_TREE 11360 && in_namespace == NULL_TREE
10619 && current_namespace == global_namespace); 11361 && current_namespace == global_namespace);
10620 11362
10621 if (type_was_error_mark_node) 11363 if (type_was_error_mark_node)
10622 /* We've already issued an error, don't complain more. */; 11364 /* We've already issued an error, don't complain more. */;
10623 else if (in_system_header_at (input_location) || flag_ms_extensions) 11365 else if (in_system_header_at (id_loc) || flag_ms_extensions)
10624 /* Allow it, sigh. */; 11366 /* Allow it, sigh. */;
10625 else if (! is_main) 11367 else if (! is_main)
10626 permerror (input_location, "ISO C++ forbids declaration of %qs with no type", name); 11368 permerror (id_loc, "ISO C++ forbids declaration of %qs with no type",
11369 name);
10627 else if (pedantic) 11370 else if (pedantic)
10628 pedwarn (input_location, OPT_Wpedantic, 11371 pedwarn (id_loc, OPT_Wpedantic,
10629 "ISO C++ forbids declaration of %qs with no type", name); 11372 "ISO C++ forbids declaration of %qs with no type", name);
10630 else 11373 else
10631 warning (OPT_Wreturn_type, 11374 warning_at (id_loc, OPT_Wreturn_type,
10632 "ISO C++ forbids declaration of %qs with no type", name); 11375 "ISO C++ forbids declaration of %qs with no type", name);
10633 11376
10634 if (type_was_error_mark_node && template_parm_flag) 11377 if (type_was_error_mark_node && template_parm_flag)
10635 /* FIXME we should be able to propagate the error_mark_node as is 11378 /* FIXME we should be able to propagate the error_mark_node as is
10636 for other contexts too. */ 11379 for other contexts too. */
10637 type = error_mark_node; 11380 type = error_mark_node;
10643 11386
10644 if (explicit_intN) 11387 if (explicit_intN)
10645 { 11388 {
10646 if (! int_n_enabled_p[declspecs->int_n_idx]) 11389 if (! int_n_enabled_p[declspecs->int_n_idx])
10647 { 11390 {
10648 error ("%<__int%d%> is not supported by this target", 11391 error_at (declspecs->locations[ds_type_spec],
10649 int_n_data[declspecs->int_n_idx].bitsize); 11392 "%<__int%d%> is not supported by this target",
11393 int_n_data[declspecs->int_n_idx].bitsize);
10650 explicit_intN = false; 11394 explicit_intN = false;
10651 } 11395 }
10652 else if (pedantic && ! in_system_header_at (input_location)) 11396 /* Don't pedwarn if the alternate "__intN__" form has been used instead
10653 pedwarn (input_location, OPT_Wpedantic, 11397 of "__intN". */
11398 else if (!int_n_alt && pedantic)
11399 pedwarn (declspecs->locations[ds_type_spec], OPT_Wpedantic,
10654 "ISO C++ does not support %<__int%d%> for %qs", 11400 "ISO C++ does not support %<__int%d%> for %qs",
10655 int_n_data[declspecs->int_n_idx].bitsize, name); 11401 int_n_data[declspecs->int_n_idx].bitsize, name);
10656 } 11402 }
10657 11403
10658 /* Now process the modifiers that were specified 11404 /* Now process the modifiers that were specified
10712 gcc_rich_location richloc (declspecs->locations[ds_long]); 11458 gcc_rich_location richloc (declspecs->locations[ds_long]);
10713 richloc.add_range (declspecs->locations[ds_short]); 11459 richloc.add_range (declspecs->locations[ds_short]);
10714 error_at (&richloc, "%<long%> and %<short%> specified together"); 11460 error_at (&richloc, "%<long%> and %<short%> specified together");
10715 } 11461 }
10716 else if (TREE_CODE (type) != INTEGER_TYPE 11462 else if (TREE_CODE (type) != INTEGER_TYPE
10717 || type == char16_type_node || type == char32_type_node 11463 || type == char8_type_node
11464 || type == char16_type_node
11465 || type == char32_type_node
10718 || ((long_p || short_p) 11466 || ((long_p || short_p)
10719 && (explicit_char || explicit_intN))) 11467 && (explicit_char || explicit_intN)))
10720 error_at (loc, "%qs specified with %qT", key, type); 11468 error_at (loc, "%qs specified with %qT", key, type);
10721 else if (!explicit_int && !defaulted_int 11469 else if (!explicit_int && !defaulted_int
10722 && !explicit_char && !explicit_intN) 11470 && !explicit_char && !explicit_intN)
10794 type = short_integer_type_node; 11542 type = short_integer_type_node;
10795 11543
10796 if (decl_spec_seq_has_spec_p (declspecs, ds_complex)) 11544 if (decl_spec_seq_has_spec_p (declspecs, ds_complex))
10797 { 11545 {
10798 if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE) 11546 if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != REAL_TYPE)
10799 error ("complex invalid for %qs", name); 11547 error_at (declspecs->locations[ds_complex],
11548 "complex invalid for %qs", name);
10800 /* If a modifier is specified, the resulting complex is the complex 11549 /* If a modifier is specified, the resulting complex is the complex
10801 form of TYPE. E.g, "complex short" is "complex short int". */ 11550 form of TYPE. E.g, "complex short" is "complex short int". */
10802 else if (type == integer_type_node) 11551 else if (type == integer_type_node)
10803 type = complex_integer_type_node; 11552 type = complex_integer_type_node;
10804 else if (type == float_type_node) 11553 else if (type == float_type_node)
10836 if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type)) 11585 if (tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (type))
10837 { 11586 {
10838 error_at (typespec_loc, "template placeholder type %qT must be followed " 11587 error_at (typespec_loc, "template placeholder type %qT must be followed "
10839 "by a simple declarator-id", type); 11588 "by a simple declarator-id", type);
10840 inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl); 11589 inform (DECL_SOURCE_LOCATION (tmpl), "%qD declared here", tmpl);
11590 type = error_mark_node;
10841 } 11591 }
10842 11592
10843 staticp = 0; 11593 staticp = 0;
10844 inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline); 11594 inlinep = decl_spec_seq_has_spec_p (declspecs, ds_inline);
10845 virtualp = decl_spec_seq_has_spec_p (declspecs, ds_virtual); 11595 virtualp = decl_spec_seq_has_spec_p (declspecs, ds_virtual);
10863 if (constexpr_p && cxx_dialect < cxx2a) 11613 if (constexpr_p && cxx_dialect < cxx2a)
10864 { 11614 {
10865 gcc_rich_location richloc (declspecs->locations[ds_virtual]); 11615 gcc_rich_location richloc (declspecs->locations[ds_virtual]);
10866 richloc.add_range (declspecs->locations[ds_constexpr]); 11616 richloc.add_range (declspecs->locations[ds_constexpr]);
10867 pedwarn (&richloc, OPT_Wpedantic, "member %qD can be declared both " 11617 pedwarn (&richloc, OPT_Wpedantic, "member %qD can be declared both "
10868 "%<virtual%> and %<constexpr%> only in -std=c++2a or " 11618 "%<virtual%> and %<constexpr%> only in %<-std=c++2a%> or "
10869 "-std=gnu++2a", dname); 11619 "%<-std=gnu++2a%>", dname);
10870 } 11620 }
10871 } 11621 }
10872 friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend); 11622 friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
10873 11623
10874 /* Issue errors about use of storage classes for parameters. */ 11624 /* Issue errors about use of storage classes for parameters. */
10898 return error_mark_node; 11648 return error_mark_node;
10899 } 11649 }
10900 11650
10901 /* Function parameters cannot be concept. */ 11651 /* Function parameters cannot be concept. */
10902 if (concept_p) 11652 if (concept_p)
10903 error_at (declspecs->locations[ds_concept], 11653 {
10904 "a parameter cannot be declared %<concept%>"); 11654 error_at (declspecs->locations[ds_concept],
11655 "a parameter cannot be declared %qs", "concept");
11656 concept_p = 0;
11657 constexpr_p = 0;
11658 }
10905 /* Function parameters cannot be constexpr. If we saw one, moan 11659 /* Function parameters cannot be constexpr. If we saw one, moan
10906 and pretend it wasn't there. */ 11660 and pretend it wasn't there. */
10907 else if (constexpr_p) 11661 else if (constexpr_p)
10908 { 11662 {
10909 error_at (declspecs->locations[ds_constexpr], 11663 error_at (declspecs->locations[ds_constexpr],
10910 "a parameter cannot be declared %<constexpr%>"); 11664 "a parameter cannot be declared %qs", "constexpr");
10911 constexpr_p = 0; 11665 constexpr_p = 0;
10912 } 11666 }
11667 if (constinit_p)
11668 {
11669 error_at (declspecs->locations[ds_constinit],
11670 "a parameter cannot be declared %qs", "constinit");
11671 constinit_p = 0;
11672 }
11673 if (consteval_p)
11674 {
11675 error_at (declspecs->locations[ds_consteval],
11676 "a parameter cannot be declared %qs", "consteval");
11677 consteval_p = 0;
11678 }
10913 } 11679 }
10914 11680
10915 /* Give error if `virtual' is used outside of class declaration. */ 11681 /* Give error if `virtual' is used outside of class declaration. */
10916 if (virtualp 11682 if (virtualp
10917 && (current_class_name == NULL_TREE || decl_context != FIELD)) 11683 && (current_class_name == NULL_TREE || decl_context != FIELD))
10925 { 11691 {
10926 location_t loc = (declarator->kind == cdk_reference 11692 location_t loc = (declarator->kind == cdk_reference
10927 ? declarator->declarator->id_loc : declarator->id_loc); 11693 ? declarator->declarator->id_loc : declarator->id_loc);
10928 if (inlinep) 11694 if (inlinep)
10929 error_at (declspecs->locations[ds_inline], 11695 error_at (declspecs->locations[ds_inline],
10930 "structured binding declaration cannot be %<inline%>"); 11696 "structured binding declaration cannot be %qs", "inline");
10931 if (typedef_p) 11697 if (typedef_p)
10932 error_at (declspecs->locations[ds_typedef], 11698 error_at (declspecs->locations[ds_typedef],
10933 "structured binding declaration cannot be %<typedef%>"); 11699 "structured binding declaration cannot be %qs", "typedef");
10934 if (constexpr_p) 11700 if (constexpr_p && !concept_p)
10935 error_at (declspecs->locations[ds_constexpr], "structured " 11701 error_at (declspecs->locations[ds_constexpr], "structured "
10936 "binding declaration cannot be %<constexpr%>"); 11702 "binding declaration cannot be %qs", "constexpr");
10937 if (thread_p) 11703 if (consteval_p)
10938 error_at (declspecs->locations[ds_thread], 11704 error_at (declspecs->locations[ds_consteval], "structured "
10939 "structured binding declaration cannot be %qs", 11705 "binding declaration cannot be %qs", "consteval");
10940 declspecs->gnu_thread_keyword_p 11706 if (thread_p && cxx_dialect < cxx2a)
10941 ? "__thread" : "thread_local"); 11707 pedwarn (declspecs->locations[ds_thread], 0,
11708 "structured binding declaration can be %qs only in "
11709 "%<-std=c++2a%> or %<-std=gnu++2a%>",
11710 declspecs->gnu_thread_keyword_p
11711 ? "__thread" : "thread_local");
10942 if (concept_p) 11712 if (concept_p)
10943 error_at (declspecs->locations[ds_concept], 11713 error_at (declspecs->locations[ds_concept],
10944 "structured binding declaration cannot be %<concept%>"); 11714 "structured binding declaration cannot be %qs", "concept");
11715 /* [dcl.struct.bind] "A cv that includes volatile is deprecated." */
11716 if (type_quals & TYPE_QUAL_VOLATILE)
11717 warning_at (declspecs->locations[ds_volatile], OPT_Wvolatile,
11718 "%<volatile%>-qualified structured binding is deprecated");
10945 switch (storage_class) 11719 switch (storage_class)
10946 { 11720 {
10947 case sc_none: 11721 case sc_none:
10948 break; 11722 break;
10949 case sc_register: 11723 case sc_register:
10950 error_at (loc, "structured binding declaration cannot be " 11724 error_at (loc, "structured binding declaration cannot be %qs",
10951 "%<register%>"); 11725 "register");
10952 break; 11726 break;
10953 case sc_static: 11727 case sc_static:
10954 error_at (loc, "structured binding declaration cannot be " 11728 if (cxx_dialect < cxx2a)
10955 "%<static%>"); 11729 pedwarn (loc, 0,
11730 "structured binding declaration can be %qs only in "
11731 "%<-std=c++2a%> or %<-std=gnu++2a%>", "static");
10956 break; 11732 break;
10957 case sc_extern: 11733 case sc_extern:
10958 error_at (loc, "structured binding declaration cannot be " 11734 error_at (loc, "structured binding declaration cannot be %qs",
10959 "%<extern%>"); 11735 "extern");
10960 break; 11736 break;
10961 case sc_mutable: 11737 case sc_mutable:
10962 error_at (loc, "structured binding declaration cannot be " 11738 error_at (loc, "structured binding declaration cannot be %qs",
10963 "%<mutable%>"); 11739 "mutable");
10964 break; 11740 break;
10965 case sc_auto: 11741 case sc_auto:
10966 error_at (loc, "structured binding declaration cannot be " 11742 error_at (loc, "structured binding declaration cannot be "
10967 "C++98 %<auto%>"); 11743 "C++98 %<auto%>");
10968 break; 11744 break;
10984 declspecs->type = type; 11760 declspecs->type = type;
10985 } 11761 }
10986 inlinep = 0; 11762 inlinep = 0;
10987 typedef_p = 0; 11763 typedef_p = 0;
10988 constexpr_p = 0; 11764 constexpr_p = 0;
10989 thread_p = 0; 11765 consteval_p = 0;
10990 concept_p = 0; 11766 concept_p = 0;
10991 storage_class = sc_none; 11767 if (storage_class != sc_static)
10992 staticp = 0; 11768 {
10993 declspecs->storage_class = sc_none; 11769 storage_class = sc_none;
10994 declspecs->locations[ds_thread] = UNKNOWN_LOCATION; 11770 declspecs->storage_class = sc_none;
11771 }
10995 } 11772 }
10996 11773
10997 /* Static anonymous unions are dealt with here. */ 11774 /* Static anonymous unions are dealt with here. */
10998 if (staticp && decl_context == TYPENAME 11775 if (staticp && decl_context == TYPENAME
10999 && declspecs->type 11776 && declspecs->type
11006 && ((storage_class 11783 && ((storage_class
11007 && storage_class != sc_extern 11784 && storage_class != sc_extern
11008 && storage_class != sc_static) 11785 && storage_class != sc_static)
11009 || typedef_p)) 11786 || typedef_p))
11010 { 11787 {
11011 error ("multiple storage classes in declaration of %qs", name); 11788 location_t loc
11789 = min_location (declspecs->locations[ds_thread],
11790 declspecs->locations[ds_storage_class]);
11791 error_at (loc, "multiple storage classes in declaration of %qs", name);
11012 thread_p = false; 11792 thread_p = false;
11013 } 11793 }
11014 if (decl_context != NORMAL 11794 if (decl_context != NORMAL
11015 && ((storage_class != sc_none 11795 && ((storage_class != sc_none
11016 && storage_class != sc_mutable) 11796 && storage_class != sc_mutable)
11050 && ! toplevel_bindings_p ()) 11830 && ! toplevel_bindings_p ())
11051 error ("nested function %qs declared %<extern%>", name); 11831 error ("nested function %qs declared %<extern%>", name);
11052 else if (toplevel_bindings_p ()) 11832 else if (toplevel_bindings_p ())
11053 { 11833 {
11054 if (storage_class == sc_auto) 11834 if (storage_class == sc_auto)
11055 error ("top-level declaration of %qs specifies %<auto%>", name); 11835 error_at (declspecs->locations[ds_storage_class],
11836 "top-level declaration of %qs specifies %<auto%>", name);
11056 } 11837 }
11057 else if (thread_p 11838 else if (thread_p
11058 && storage_class != sc_extern 11839 && storage_class != sc_extern
11059 && storage_class != sc_static) 11840 && storage_class != sc_static)
11060 { 11841 {
11162 11943
11163 switch (declarator->kind) 11944 switch (declarator->kind)
11164 { 11945 {
11165 case cdk_array: 11946 case cdk_array:
11166 type = create_array_type_for_decl (dname, type, 11947 type = create_array_type_for_decl (dname, type,
11167 declarator->u.array.bounds); 11948 declarator->u.array.bounds,
11168 if (!valid_array_size_p (input_location, type, dname)) 11949 declarator->id_loc);
11950 if (!valid_array_size_p (dname
11951 ? declarator->id_loc : input_location,
11952 type, dname))
11169 type = error_mark_node; 11953 type = error_mark_node;
11170 11954
11171 if (declarator->std_attributes) 11955 if (declarator->std_attributes)
11172 /* [dcl.array]/1: 11956 /* [dcl.array]/1:
11173 11957
11182 tree arg_types; 11966 tree arg_types;
11183 int funcdecl_p; 11967 int funcdecl_p;
11184 11968
11185 /* Declaring a function type. */ 11969 /* Declaring a function type. */
11186 11970
11187 input_location = declspecs->locations[ds_type_spec]; 11971 {
11188 abstract_virtuals_error (ACU_RETURN, type); 11972 iloc_sentinel ils (declspecs->locations[ds_type_spec]);
11189 input_location = saved_loc; 11973 abstract_virtuals_error (ACU_RETURN, type);
11974 }
11190 11975
11191 /* Pick up type qualifiers which should be applied to `this'. */ 11976 /* Pick up type qualifiers which should be applied to `this'. */
11192 memfn_quals = declarator->u.function.qualifiers; 11977 memfn_quals = declarator->u.function.qualifiers;
11193 /* Pick up virt-specifiers. */ 11978 /* Pick up virt-specifiers. */
11194 virt_specifiers = declarator->u.function.virt_specifiers; 11979 virt_specifiers = declarator->u.function.virt_specifiers;
11225 if (current_class_type 12010 if (current_class_type
11226 && LAMBDA_TYPE_P (current_class_type)) 12011 && LAMBDA_TYPE_P (current_class_type))
11227 /* OK for C++11 lambdas. */; 12012 /* OK for C++11 lambdas. */;
11228 else if (cxx_dialect < cxx14) 12013 else if (cxx_dialect < cxx14)
11229 { 12014 {
11230 error ("%qs function uses " 12015 error_at (typespec_loc, "%qs function uses "
11231 "%<auto%> type specifier without trailing " 12016 "%<auto%> type specifier without "
11232 "return type", name); 12017 "trailing return type", name);
11233 inform (input_location, "deduced return type " 12018 inform (typespec_loc,
11234 "only available with -std=c++14 or " 12019 "deduced return type only available "
11235 "-std=gnu++14"); 12020 "with %<-std=c++14%> or %<-std=gnu++14%>");
11236 } 12021 }
11237 else if (virtualp) 12022 else if (virtualp)
11238 { 12023 {
11239 error ("virtual function cannot " 12024 error_at (typespec_loc, "virtual function "
11240 "have deduced return type"); 12025 "cannot have deduced return type");
11241 virtualp = false; 12026 virtualp = false;
11242 } 12027 }
11243 } 12028 }
11244 else if (!is_auto (type) && sfk != sfk_conversion) 12029 else if (!is_auto (type) && sfk != sfk_conversion)
11245 { 12030 {
11246 error ("%qs function with trailing return type has" 12031 error_at (typespec_loc, "%qs function with trailing "
11247 " %qT as its type rather than plain %<auto%>", 12032 "return type has %qT as its type rather "
11248 name, type); 12033 "than plain %<auto%>", name, type);
11249 return error_mark_node; 12034 return error_mark_node;
11250 } 12035 }
11251 else if (is_auto (type) && AUTO_IS_DECLTYPE (type)) 12036 else if (is_auto (type) && AUTO_IS_DECLTYPE (type))
11252 { 12037 {
11253 if (funcdecl_p) 12038 if (funcdecl_p)
11254 error ("%qs function with trailing return type has " 12039 error_at (typespec_loc,
11255 "%<decltype(auto)%> as its type rather than " 12040 "%qs function with trailing return type "
11256 "plain %<auto%>", name); 12041 "has %<decltype(auto)%> as its type "
12042 "rather than plain %<auto%>", name);
11257 else 12043 else
11258 error ("invalid use of %<decltype(auto)%>"); 12044 error_at (typespec_loc,
12045 "invalid use of %<decltype(auto)%>");
11259 return error_mark_node; 12046 return error_mark_node;
11260 } 12047 }
11261 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node); 12048 tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node);
11262 if (!tmpl) 12049 if (!tmpl)
11263 if (tree late_auto = type_uses_auto (late_return_type)) 12050 if (tree late_auto = type_uses_auto (late_return_type))
11264 tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto); 12051 tmpl = CLASS_PLACEHOLDER_TEMPLATE (late_auto);
11265 if (tmpl) 12052 if (tmpl && funcdecl_p)
11266 { 12053 {
11267 if (!dguide_name_p (unqualified_id)) 12054 if (!dguide_name_p (unqualified_id))
11268 { 12055 {
11269 error_at (declarator->id_loc, "deduced class " 12056 error_at (declarator->id_loc, "deduced class "
11270 "type %qD in function return type", 12057 "type %qD in function return type",
11294 } 12081 }
11295 } 12082 }
11296 else if (late_return_type 12083 else if (late_return_type
11297 && sfk != sfk_conversion) 12084 && sfk != sfk_conversion)
11298 { 12085 {
12086 if (late_return_type == error_mark_node)
12087 return error_mark_node;
11299 if (cxx_dialect < cxx11) 12088 if (cxx_dialect < cxx11)
11300 /* Not using maybe_warn_cpp0x because this should 12089 /* Not using maybe_warn_cpp0x because this should
11301 always be an error. */ 12090 always be an error. */
11302 error ("trailing return type only available with " 12091 error_at (typespec_loc,
11303 "-std=c++11 or -std=gnu++11"); 12092 "trailing return type only available "
12093 "with %<-std=c++11%> or %<-std=gnu++11%>");
11304 else 12094 else
11305 error ("%qs function with trailing return type not " 12095 error_at (typespec_loc, "%qs function with trailing "
11306 "declared with %<auto%> type specifier", name); 12096 "return type not declared with %<auto%> "
12097 "type specifier", name);
11307 return error_mark_node; 12098 return error_mark_node;
11308 } 12099 }
11309 } 12100 }
11310 type = splice_late_return_type (type, late_return_type); 12101 type = splice_late_return_type (type, late_return_type);
11311 if (type == error_mark_node) 12102 if (type == error_mark_node)
11320 if (type_quals != TYPE_UNQUALIFIED) 12111 if (type_quals != TYPE_UNQUALIFIED)
11321 { 12112 {
11322 if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type)) 12113 if (SCALAR_TYPE_P (type) || VOID_TYPE_P (type))
11323 warning_at (typespec_loc, OPT_Wignored_qualifiers, "type " 12114 warning_at (typespec_loc, OPT_Wignored_qualifiers, "type "
11324 "qualifiers ignored on function return type"); 12115 "qualifiers ignored on function return type");
12116 /* [dcl.fct] "A volatile-qualified return type is
12117 deprecated." */
12118 if (type_quals & TYPE_QUAL_VOLATILE)
12119 warning_at (typespec_loc, OPT_Wvolatile,
12120 "%<volatile%>-qualified return type is "
12121 "deprecated");
12122
11325 /* We now know that the TYPE_QUALS don't apply to the 12123 /* We now know that the TYPE_QUALS don't apply to the
11326 decl, but to its return type. */ 12124 decl, but to its return type. */
11327 type_quals = TYPE_UNQUALIFIED; 12125 type_quals = TYPE_UNQUALIFIED;
11328 } 12126 }
11329 12127
11339 { 12137 {
11340 error_at (typespec_loc, "%qs declared as function returning " 12138 error_at (typespec_loc, "%qs declared as function returning "
11341 "an array", name); 12139 "an array", name);
11342 return error_mark_node; 12140 return error_mark_node;
11343 } 12141 }
12142 if (constinit_p)
12143 {
12144 error_at (declspecs->locations[ds_constinit],
12145 "%<constinit%> on function return type is not "
12146 "allowed");
12147 return error_mark_node;
12148 }
12149 /* Only plain decltype(auto) is allowed. */
12150 if (tree a = type_uses_auto (type))
12151 {
12152 if (AUTO_IS_DECLTYPE (a) && a != type)
12153 {
12154 error_at (typespec_loc, "%qT as type rather than "
12155 "plain %<decltype(auto)%>", type);
12156 return error_mark_node;
12157 }
12158 }
11344 12159
11345 if (ctype == NULL_TREE 12160 if (ctype == NULL_TREE
11346 && decl_context == FIELD 12161 && decl_context == FIELD
11347 && funcdecl_p 12162 && funcdecl_p
11348 && friendp == 0) 12163 && friendp == 0)
11363 ISO C++ 12.1. A constructor may not be declared 12178 ISO C++ 12.1. A constructor may not be declared
11364 const or volatile. A constructor may not be 12179 const or volatile. A constructor may not be
11365 virtual. A constructor may not be static. 12180 virtual. A constructor may not be static.
11366 A constructor may not be declared with ref-qualifier. */ 12181 A constructor may not be declared with ref-qualifier. */
11367 if (staticp == 2) 12182 if (staticp == 2)
11368 error ((flags == DTOR_FLAG) 12183 error_at (declspecs->locations[ds_storage_class],
11369 ? G_("destructor cannot be static member function") 12184 (flags == DTOR_FLAG)
11370 : G_("constructor cannot be static member function")); 12185 ? G_("destructor cannot be static member "
12186 "function")
12187 : G_("constructor cannot be static member "
12188 "function"));
11371 if (memfn_quals) 12189 if (memfn_quals)
11372 { 12190 {
11373 error ((flags == DTOR_FLAG) 12191 error ((flags == DTOR_FLAG)
11374 ? G_("destructors may not be cv-qualified") 12192 ? G_("destructors may not be cv-qualified")
11375 : G_("constructors may not be cv-qualified")); 12193 : G_("constructors may not be cv-qualified"));
11418 richloc.add_range (declspecs->locations[ds_friend]); 12236 richloc.add_range (declspecs->locations[ds_friend]);
11419 error_at (&richloc, "virtual functions cannot be friends"); 12237 error_at (&richloc, "virtual functions cannot be friends");
11420 friendp = 0; 12238 friendp = 0;
11421 } 12239 }
11422 if (decl_context == NORMAL) 12240 if (decl_context == NORMAL)
11423 error ("friend declaration not in class definition"); 12241 error_at (declarator->id_loc,
12242 "friend declaration not in class definition");
11424 if (current_function_decl && funcdef_flag) 12243 if (current_function_decl && funcdef_flag)
11425 { 12244 {
11426 error ("can%'t define friend function %qs in a local " 12245 error_at (declarator->id_loc,
11427 "class definition", name); 12246 "cannot define friend function %qs in a local "
12247 "class definition", name);
11428 friendp = 0; 12248 friendp = 0;
12249 }
12250 /* [class.friend]/6: A function can be defined in a friend
12251 declaration if the function name is unqualified. */
12252 if (funcdef_flag && in_namespace)
12253 {
12254 if (in_namespace == global_namespace)
12255 error_at (declarator->id_loc,
12256 "friend function definition %qs cannot have "
12257 "a name qualified with %<::%>", name);
12258 else
12259 error_at (declarator->id_loc,
12260 "friend function definition %qs cannot have "
12261 "a name qualified with %<%D::%>", name,
12262 in_namespace);
11429 } 12263 }
11430 } 12264 }
11431 else if (ctype && sfk == sfk_conversion) 12265 else if (ctype && sfk == sfk_conversion)
11432 { 12266 {
11433 if (explicitp == 1) 12267 if (explicitp == 1)
11460 if (inner_declarator 12294 if (inner_declarator
11461 && inner_declarator->kind == cdk_id 12295 && inner_declarator->kind == cdk_id
11462 && inner_declarator->u.id.sfk == sfk_destructor 12296 && inner_declarator->u.id.sfk == sfk_destructor
11463 && arg_types != void_list_node) 12297 && arg_types != void_list_node)
11464 { 12298 {
11465 error ("destructors may not have parameters"); 12299 error_at (declarator->id_loc,
12300 "destructors may not have parameters");
11466 arg_types = void_list_node; 12301 arg_types = void_list_node;
11467 parms = NULL_TREE; 12302 parms = NULL_TREE;
11468 } 12303 }
11469 12304
11470 type = build_function_type (type, arg_types); 12305 type = build_function_type (type, arg_types);
11483 if (attrs) 12318 if (attrs)
11484 /* [dcl.fct]/2: 12319 /* [dcl.fct]/2:
11485 12320
11486 The optional attribute-specifier-seq appertains to 12321 The optional attribute-specifier-seq appertains to
11487 the function type. */ 12322 the function type. */
11488 decl_attributes (&type, attrs, 0); 12323 cplus_decl_attributes (&type, attrs, 0);
11489 12324
11490 if (raises) 12325 if (raises)
11491 type = build_exception_variant (type, raises); 12326 type = build_exception_variant (type, raises);
11492 } 12327 }
11493 break; 12328 break;
11676 default: 12511 default:
11677 gcc_unreachable (); 12512 gcc_unreachable ();
11678 } 12513 }
11679 } 12514 }
11680 12515
12516 id_loc = declarator ? declarator->id_loc : input_location;
12517
11681 /* A `constexpr' specifier used in an object declaration declares 12518 /* A `constexpr' specifier used in an object declaration declares
11682 the object as `const'. */ 12519 the object as `const'. */
11683 if (constexpr_p && innermost_code != cdk_function) 12520 if (constexpr_p && innermost_code != cdk_function)
11684 { 12521 {
11685 /* DR1688 says that a `constexpr' specifier in combination with 12522 /* DR1688 says that a `constexpr' specifier in combination with
11691 type = cp_build_qualified_type (type, type_quals); 12528 type = cp_build_qualified_type (type, type_quals);
11692 } 12529 }
11693 } 12530 }
11694 12531
11695 if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR 12532 if (unqualified_id && TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR
11696 && TREE_CODE (type) != FUNCTION_TYPE 12533 && !FUNC_OR_METHOD_TYPE_P (type)
11697 && TREE_CODE (type) != METHOD_TYPE
11698 && !variable_template_p (TREE_OPERAND (unqualified_id, 0))) 12534 && !variable_template_p (TREE_OPERAND (unqualified_id, 0)))
11699 { 12535 {
11700 error ("template-id %qD used as a declarator", 12536 error ("template-id %qD used as a declarator",
11701 unqualified_id); 12537 unqualified_id);
11702 unqualified_id = dname; 12538 unqualified_id = dname;
11720 12556
11721 if (ctype == current_class_type) 12557 if (ctype == current_class_type)
11722 { 12558 {
11723 if (friendp) 12559 if (friendp)
11724 { 12560 {
11725 permerror (input_location, "member functions are implicitly " 12561 permerror (declspecs->locations[ds_friend],
11726 "friends of their class"); 12562 "member functions are implicitly "
12563 "friends of their class");
11727 friendp = 0; 12564 friendp = 0;
11728 } 12565 }
11729 else 12566 else
11730 permerror (declarator->id_loc, 12567 permerror (id_loc, "extra qualification %<%T::%> on member %qs",
11731 "extra qualification %<%T::%> on member %qs",
11732 ctype, name); 12568 ctype, name);
11733 } 12569 }
11734 else if (/* If the qualifying type is already complete, then we 12570 else if (/* If the qualifying type is already complete, then we
11735 can skip the following checks. */ 12571 can skip the following checks. */
11736 !COMPLETE_TYPE_P (ctype) 12572 !COMPLETE_TYPE_P (ctype)
11755 else if (TREE_CODE (type) == FUNCTION_TYPE) 12591 else if (TREE_CODE (type) == FUNCTION_TYPE)
11756 { 12592 {
11757 if (current_class_type 12593 if (current_class_type
11758 && (!friendp || funcdef_flag || initialized)) 12594 && (!friendp || funcdef_flag || initialized))
11759 { 12595 {
11760 error (funcdef_flag || initialized 12596 error_at (id_loc, funcdef_flag || initialized
11761 ? G_("cannot define member function %<%T::%s%> " 12597 ? G_("cannot define member function %<%T::%s%> "
11762 "within %qT") 12598 "within %qT")
11763 : G_("cannot declare member function %<%T::%s%> " 12599 : G_("cannot declare member function %<%T::%s%> "
11764 "within %qT"), 12600 "within %qT"),
11765 ctype, name, current_class_type); 12601 ctype, name, current_class_type);
11766 return error_mark_node; 12602 return error_mark_node;
11767 } 12603 }
11768 } 12604 }
11769 else if (typedef_p && current_class_type) 12605 else if (typedef_p && current_class_type)
11770 { 12606 {
11771 error ("cannot declare member %<%T::%s%> within %qT", 12607 error_at (id_loc, "cannot declare member %<%T::%s%> within %qT",
11772 ctype, name, current_class_type); 12608 ctype, name, current_class_type);
11773 return error_mark_node; 12609 return error_mark_node;
11774 } 12610 }
11775 } 12611 }
11776 12612
11777 if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0) 12613 if (ctype == NULL_TREE && decl_context == FIELD && friendp == 0)
11814 if ((decl_context == FIELD || decl_context == PARM) 12650 if ((decl_context == FIELD || decl_context == PARM)
11815 && !processing_template_decl 12651 && !processing_template_decl
11816 && variably_modified_type_p (type, NULL_TREE)) 12652 && variably_modified_type_p (type, NULL_TREE))
11817 { 12653 {
11818 if (decl_context == FIELD) 12654 if (decl_context == FIELD)
11819 error ("data member may not have variably modified type %qT", type); 12655 error_at (id_loc,
12656 "data member may not have variably modified type %qT", type);
11820 else 12657 else
11821 error ("parameter may not have variably modified type %qT", type); 12658 error_at (id_loc,
12659 "parameter may not have variably modified type %qT", type);
11822 type = error_mark_node; 12660 type = error_mark_node;
11823 } 12661 }
11824 12662
11825 if (explicitp == 1 || (explicitp && friendp)) 12663 if (explicitp == 1 || (explicitp && friendp))
11826 { 12664 {
11840 explicitp = 0; 12678 explicitp = 0;
11841 } 12679 }
11842 12680
11843 if (storage_class == sc_mutable) 12681 if (storage_class == sc_mutable)
11844 { 12682 {
12683 location_t sloc = declspecs->locations[ds_storage_class];
11845 if (decl_context != FIELD || friendp) 12684 if (decl_context != FIELD || friendp)
11846 { 12685 {
11847 error ("non-member %qs cannot be declared %<mutable%>", name); 12686 error_at (sloc, "non-member %qs cannot be declared %<mutable%>",
12687 name);
11848 storage_class = sc_none; 12688 storage_class = sc_none;
11849 } 12689 }
11850 else if (decl_context == TYPENAME || typedef_p) 12690 else if (decl_context == TYPENAME || typedef_p)
11851 { 12691 {
11852 error ("non-object member %qs cannot be declared %<mutable%>", name); 12692 error_at (sloc,
12693 "non-object member %qs cannot be declared %<mutable%>",
12694 name);
11853 storage_class = sc_none; 12695 storage_class = sc_none;
11854 } 12696 }
11855 else if (TREE_CODE (type) == FUNCTION_TYPE 12697 else if (FUNC_OR_METHOD_TYPE_P (type))
11856 || TREE_CODE (type) == METHOD_TYPE) 12698 {
11857 { 12699 error_at (sloc, "function %qs cannot be declared %<mutable%>",
11858 error ("function %qs cannot be declared %<mutable%>", name); 12700 name);
11859 storage_class = sc_none; 12701 storage_class = sc_none;
11860 } 12702 }
11861 else if (staticp) 12703 else if (staticp)
11862 { 12704 {
11863 error ("static %qs cannot be declared %<mutable%>", name); 12705 error_at (sloc, "%<static%> %qs cannot be declared %<mutable%>",
12706 name);
11864 storage_class = sc_none; 12707 storage_class = sc_none;
11865 } 12708 }
11866 else if (type_quals & TYPE_QUAL_CONST) 12709 else if (type_quals & TYPE_QUAL_CONST)
11867 { 12710 {
11868 error ("const %qs cannot be declared %<mutable%>", name); 12711 error_at (sloc, "%<const%> %qs cannot be declared %<mutable%>",
12712 name);
11869 storage_class = sc_none; 12713 storage_class = sc_none;
11870 } 12714 }
11871 else if (TYPE_REF_P (type)) 12715 else if (TYPE_REF_P (type))
11872 { 12716 {
11873 permerror (input_location, "reference %qs cannot be declared " 12717 permerror (sloc, "reference %qs cannot be declared %<mutable%>",
11874 "%<mutable%>", name); 12718 name);
11875 storage_class = sc_none; 12719 storage_class = sc_none;
11876 } 12720 }
11877 } 12721 }
11878 12722
11879 /* If this is declaring a typedef name, return a TYPE_DECL. */ 12723 /* If this is declaring a typedef name, return a TYPE_DECL. */
11880 if (typedef_p && decl_context != TYPENAME) 12724 if (typedef_p && decl_context != TYPENAME)
11881 { 12725 {
11882 bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias); 12726 bool alias_p = decl_spec_seq_has_spec_p (declspecs, ds_alias);
11883 tree decl; 12727 tree decl;
12728
12729 if (funcdef_flag)
12730 {
12731 if (decl_context == NORMAL)
12732 error_at (id_loc,
12733 "typedef may not be a function definition");
12734 else
12735 error_at (id_loc,
12736 "typedef may not be a member function definition");
12737 return error_mark_node;
12738 }
11884 12739
11885 /* This declaration: 12740 /* This declaration:
11886 12741
11887 typedef void f(int) const; 12742 typedef void f(int) const;
11888 12743
11914 if (reqs) 12769 if (reqs)
11915 error_at (location_of (reqs), "requires-clause on typedef"); 12770 error_at (location_of (reqs), "requires-clause on typedef");
11916 12771
11917 if (id_declarator && declarator->u.id.qualifying_scope) 12772 if (id_declarator && declarator->u.id.qualifying_scope)
11918 { 12773 {
11919 error ("typedef name may not be a nested-name-specifier"); 12774 error_at (id_loc, "typedef name may not be a nested-name-specifier");
11920 type = error_mark_node; 12775 type = error_mark_node;
11921 } 12776 }
11922 12777
11923 if (decl_context == FIELD) 12778 if (decl_context == FIELD)
11924 decl = build_lang_decl (TYPE_DECL, unqualified_id, type); 12779 decl = build_lang_decl_loc (id_loc, TYPE_DECL, unqualified_id, type);
11925 else 12780 else
11926 decl = build_decl (input_location, TYPE_DECL, unqualified_id, type); 12781 decl = build_decl (id_loc, TYPE_DECL, unqualified_id, type);
11927 12782
11928 if (decl_context != FIELD) 12783 if (decl_context != FIELD)
11929 { 12784 {
11930 if (!current_function_decl) 12785 if (!current_function_decl)
11931 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace); 12786 DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
11938 the clones should share a common implementation. */ 12793 the clones should share a common implementation. */
11939 DECL_ABSTRACT_P (decl) = true; 12794 DECL_ABSTRACT_P (decl) = true;
11940 } 12795 }
11941 else if (current_class_type 12796 else if (current_class_type
11942 && constructor_name_p (unqualified_id, current_class_type)) 12797 && constructor_name_p (unqualified_id, current_class_type))
11943 permerror (input_location, "ISO C++ forbids nested type %qD with same name " 12798 permerror (id_loc, "ISO C++ forbids nested type %qD with same name "
11944 "as enclosing class", 12799 "as enclosing class",
11945 unqualified_id); 12800 unqualified_id);
11946 12801
11947 /* If the user declares "typedef struct {...} foo" then the 12802 /* If the user declares "typedef struct {...} foo" then the
11948 struct will have an anonymous name. Fill that name in now. 12803 struct will have an anonymous name. Fill that name in now.
12011 /* The qualifiers on the function type become the qualifiers on 12866 /* The qualifiers on the function type become the qualifiers on
12012 the non-static member function. */ 12867 the non-static member function. */
12013 memfn_quals |= type_memfn_quals (type); 12868 memfn_quals |= type_memfn_quals (type);
12014 rqual = type_memfn_rqual (type); 12869 rqual = type_memfn_rqual (type);
12015 type_quals = TYPE_UNQUALIFIED; 12870 type_quals = TYPE_UNQUALIFIED;
12871 raises = TYPE_RAISES_EXCEPTIONS (type);
12016 } 12872 }
12017 } 12873 }
12018 12874
12019 /* If this is a type name (such as, in a cast or sizeof), 12875 /* If this is a type name (such as, in a cast or sizeof),
12020 compute the type and return it now. */ 12876 compute the type and return it now. */
12096 if (!FUNC_OR_METHOD_TYPE_P (type)) 12952 if (!FUNC_OR_METHOD_TYPE_P (type))
12097 { 12953 {
12098 /* Only functions may be declared using an operator-function-id. */ 12954 /* Only functions may be declared using an operator-function-id. */
12099 if (dname && IDENTIFIER_ANY_OP_P (dname)) 12955 if (dname && IDENTIFIER_ANY_OP_P (dname))
12100 { 12956 {
12101 error ("declaration of %qD as non-function", dname); 12957 error_at (id_loc, "declaration of %qD as non-function", dname);
12102 return error_mark_node; 12958 return error_mark_node;
12103 } 12959 }
12104 12960
12105 if (reqs) 12961 if (reqs)
12106 error_at (location_of (reqs), 12962 error_at (location_of (reqs),
12110 12966
12111 /* We don't check parameter types here because we can emit a better 12967 /* We don't check parameter types here because we can emit a better
12112 error message later. */ 12968 error message later. */
12113 if (decl_context != PARM) 12969 if (decl_context != PARM)
12114 { 12970 {
12115 type = check_var_type (unqualified_id, type); 12971 type = check_var_type (unqualified_id, type, id_loc);
12116 if (type == error_mark_node) 12972 if (type == error_mark_node)
12117 return error_mark_node; 12973 return error_mark_node;
12118 } 12974 }
12119 12975
12120 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL 12976 /* Now create the decl, which may be a VAR_DECL, a PARM_DECL
12123 if (decl_context == PARM || decl_context == CATCHPARM) 12979 if (decl_context == PARM || decl_context == CATCHPARM)
12124 { 12980 {
12125 if (ctype || in_namespace) 12981 if (ctype || in_namespace)
12126 error ("cannot use %<::%> in parameter declaration"); 12982 error ("cannot use %<::%> in parameter declaration");
12127 12983
12128 if (type_uses_auto (type) 12984 tree auto_node = type_uses_auto (type);
12129 && !(cxx_dialect >= cxx17 && template_parm_flag)) 12985 if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
12130 { 12986 {
12131 if (cxx_dialect >= cxx14) 12987 if (cxx_dialect >= cxx14)
12132 error ("%<auto%> parameter not permitted in this context"); 12988 {
12989 if (decl_context == PARM && AUTO_IS_DECLTYPE (auto_node))
12990 error_at (typespec_loc,
12991 "cannot declare a parameter with %<decltype(auto)%>");
12992 else
12993 error_at (typespec_loc,
12994 "%<auto%> parameter not permitted in this context");
12995 }
12133 else 12996 else
12134 error ("parameter declared %<auto%>"); 12997 error_at (typespec_loc, "parameter declared %<auto%>");
12135 type = error_mark_node; 12998 type = error_mark_node;
12136 } 12999 }
12137 13000
12138 /* A parameter declared as an array of T is really a pointer to T. 13001 /* A parameter declared as an array of T is really a pointer to T.
12139 One declared as a function is really a pointer to a function. 13002 One declared as a function is really a pointer to a function.
12149 else if (TREE_CODE (type) == FUNCTION_TYPE) 13012 else if (TREE_CODE (type) == FUNCTION_TYPE)
12150 type = build_pointer_type (type); 13013 type = build_pointer_type (type);
12151 } 13014 }
12152 13015
12153 if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2 13016 if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2
12154 && !(identifier_p (unqualified_id) 13017 && !(unqualified_id
13018 && identifier_p (unqualified_id)
12155 && IDENTIFIER_NEWDEL_OP_P (unqualified_id))) 13019 && IDENTIFIER_NEWDEL_OP_P (unqualified_id)))
12156 { 13020 {
12157 cp_cv_quals real_quals = memfn_quals; 13021 cp_cv_quals real_quals = memfn_quals;
12158 if (cxx_dialect < cxx14 && constexpr_p 13022 if (cxx_dialect < cxx14 && constexpr_p
12159 && sfk != sfk_constructor && sfk != sfk_destructor) 13023 && sfk != sfk_constructor && sfk != sfk_destructor)
12177 else if (decl_context == FIELD) 13041 else if (decl_context == FIELD)
12178 { 13042 {
12179 if (!staticp && !friendp && TREE_CODE (type) != METHOD_TYPE) 13043 if (!staticp && !friendp && TREE_CODE (type) != METHOD_TYPE)
12180 if (tree auto_node = type_uses_auto (type)) 13044 if (tree auto_node = type_uses_auto (type))
12181 { 13045 {
12182 location_t loc = declspecs->locations[ds_type_spec]; 13046 location_t tloc = declspecs->locations[ds_type_spec];
12183 if (CLASS_PLACEHOLDER_TEMPLATE (auto_node)) 13047 if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
12184 error_at (loc, "invalid use of template-name %qE without an " 13048 error_at (tloc, "invalid use of template-name %qE without an "
12185 "argument list", 13049 "argument list",
12186 CLASS_PLACEHOLDER_TEMPLATE (auto_node)); 13050 CLASS_PLACEHOLDER_TEMPLATE (auto_node));
12187 else 13051 else
12188 error_at (loc, "non-static data member declared with " 13052 error_at (tloc, "non-static data member declared with "
12189 "placeholder %qT", auto_node); 13053 "placeholder %qT", auto_node);
12190 type = error_mark_node; 13054 type = error_mark_node;
12191 } 13055 }
12192 13056
12193 /* The C99 flexible array extension. */ 13057 /* The C99 flexible array extension. */
12196 { 13060 {
12197 if (ctype 13061 if (ctype
12198 && (TREE_CODE (ctype) == UNION_TYPE 13062 && (TREE_CODE (ctype) == UNION_TYPE
12199 || TREE_CODE (ctype) == QUAL_UNION_TYPE)) 13063 || TREE_CODE (ctype) == QUAL_UNION_TYPE))
12200 { 13064 {
12201 error ("flexible array member in union"); 13065 error_at (id_loc, "flexible array member in union");
12202 type = error_mark_node; 13066 type = error_mark_node;
12203 } 13067 }
12204 else 13068 else
12205 { 13069 {
12206 /* Array is a flexible member. */ 13070 /* Array is a flexible member. */
12207 if (in_system_header_at (input_location)) 13071 if (name)
12208 /* Do not warn on flexible array members in system 13072 pedwarn (id_loc, OPT_Wpedantic,
12209 headers because glibc uses them. */;
12210 else if (name)
12211 pedwarn (input_location, OPT_Wpedantic,
12212 "ISO C++ forbids flexible array member %qs", name); 13073 "ISO C++ forbids flexible array member %qs", name);
12213 else 13074 else
12214 pedwarn (input_location, OPT_Wpedantic, 13075 pedwarn (input_location, OPT_Wpedantic,
12215 "ISO C++ forbids flexible array members"); 13076 "ISO C++ forbids flexible array members");
12216 13077
12226 decl = NULL_TREE; 13087 decl = NULL_TREE;
12227 } 13088 }
12228 else if (in_namespace && !friendp) 13089 else if (in_namespace && !friendp)
12229 { 13090 {
12230 /* Something like struct S { int N::j; }; */ 13091 /* Something like struct S { int N::j; }; */
12231 error ("invalid use of %<::%>"); 13092 error_at (id_loc, "invalid use of %<::%>");
12232 return error_mark_node; 13093 return error_mark_node;
12233 } 13094 }
12234 else if (TREE_CODE (type) == FUNCTION_TYPE 13095 else if (FUNC_OR_METHOD_TYPE_P (type) && unqualified_id)
12235 || TREE_CODE (type) == METHOD_TYPE)
12236 { 13096 {
12237 int publicp = 0; 13097 int publicp = 0;
12238 tree function_context; 13098 tree function_context;
12239 13099
12240 if (friendp == 0) 13100 if (friendp == 0)
12282 tree uqname = id_declarator->u.id.unqualified_name; 13142 tree uqname = id_declarator->u.id.unqualified_name;
12283 13143
12284 if (!ctype) 13144 if (!ctype)
12285 { 13145 {
12286 gcc_assert (friendp); 13146 gcc_assert (friendp);
12287 error ("expected qualified name in friend declaration " 13147 error_at (id_loc, "expected qualified name in friend "
12288 "for destructor %qD", uqname); 13148 "declaration for destructor %qD", uqname);
12289 return error_mark_node; 13149 return error_mark_node;
12290 } 13150 }
12291 13151
12292 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0))) 13152 if (!check_dtor_name (ctype, TREE_OPERAND (uqname, 0)))
12293 { 13153 {
12294 error ("declaration of %qD as member of %qT", 13154 error_at (id_loc, "declaration of %qD as member of %qT",
12295 uqname, ctype); 13155 uqname, ctype);
12296 return error_mark_node; 13156 return error_mark_node;
12297 } 13157 }
12298 if (concept_p) 13158 if (concept_p)
12299 { 13159 {
12300 error_at (declspecs->locations[ds_concept], 13160 error_at (declspecs->locations[ds_concept],
12301 "a destructor cannot be %<concept%>"); 13161 "a destructor cannot be %qs", "concept");
12302 return error_mark_node; 13162 return error_mark_node;
12303 } 13163 }
12304 if (constexpr_p) 13164 if (constexpr_p && cxx_dialect < cxx2a)
12305 { 13165 {
12306 error_at (declspecs->locations[ds_constexpr], 13166 error_at (declspecs->locations[ds_constexpr],
12307 "a destructor cannot be %<constexpr%>"); 13167 "%<constexpr%> destructors only available"
12308 return error_mark_node; 13168 " with %<-std=c++2a%> or %<-std=gnu++2a%>");
12309 } 13169 return error_mark_node;
13170 }
13171 if (consteval_p)
13172 {
13173 error_at (declspecs->locations[ds_consteval],
13174 "a destructor cannot be %qs", "consteval");
13175 return error_mark_node;
13176 }
12310 } 13177 }
12311 else if (sfk == sfk_constructor && friendp && !ctype) 13178 else if (sfk == sfk_constructor && friendp && !ctype)
12312 { 13179 {
12313 error ("expected qualified name in friend declaration " 13180 error ("expected qualified name in friend declaration "
12314 "for constructor %qD", 13181 "for constructor %qD",
12326 { 13193 {
12327 error_at (declspecs->locations[ds_concept], 13194 error_at (declspecs->locations[ds_concept],
12328 "a concept cannot be a member function"); 13195 "a concept cannot be a member function");
12329 concept_p = false; 13196 concept_p = false;
12330 } 13197 }
13198 else if (consteval_p
13199 && identifier_p (unqualified_id)
13200 && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
13201 {
13202 error_at (declspecs->locations[ds_consteval],
13203 "%qD cannot be %qs", unqualified_id, "consteval");
13204 consteval_p = false;
13205 }
12331 13206
12332 if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR) 13207 if (TREE_CODE (unqualified_id) == TEMPLATE_ID_EXPR)
12333 { 13208 {
12334 tree tmpl = TREE_OPERAND (unqualified_id, 0); 13209 tree tmpl = TREE_OPERAND (unqualified_id, 0);
12335 if (variable_template_p (tmpl)) 13210 if (variable_template_p (tmpl))
12336 { 13211 {
12337 error ("specialization of variable template %qD " 13212 error_at (id_loc, "specialization of variable template "
12338 "declared as function", tmpl); 13213 "%qD declared as function", tmpl);
12339 inform (DECL_SOURCE_LOCATION (tmpl), 13214 inform (DECL_SOURCE_LOCATION (tmpl),
12340 "variable template declared here"); 13215 "variable template declared here");
12341 return error_mark_node; 13216 return error_mark_node;
12342 } 13217 }
12343 } 13218 }
12344 13219
12345 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */ 13220 /* Tell grokfndecl if it needs to set TREE_PUBLIC on the node. */
12346 function_context = (ctype != NULL_TREE) ? 13221 function_context
12347 decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE; 13222 = (ctype != NULL_TREE
12348 publicp = (! friendp || ! staticp) 13223 ? decl_function_context (TYPE_MAIN_DECL (ctype)) : NULL_TREE);
12349 && function_context == NULL_TREE; 13224 publicp = ((! friendp || ! staticp)
13225 && function_context == NULL_TREE);
12350 13226
12351 decl = grokfndecl (ctype, type, 13227 decl = grokfndecl (ctype, type,
12352 TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR 13228 TREE_CODE (unqualified_id) != TEMPLATE_ID_EXPR
12353 ? unqualified_id : dname, 13229 ? unqualified_id : dname,
12354 parms, 13230 parms,
12355 unqualified_id, 13231 unqualified_id,
12356 declspecs, 13232 declspecs,
12357 reqs, 13233 reqs,
12358 virtualp, flags, memfn_quals, rqual, raises, 13234 virtualp, flags, memfn_quals, rqual, raises,
12359 friendp ? -1 : 0, friendp, publicp, 13235 friendp ? -1 : 0, friendp, publicp,
12360 inlinep | (2 * constexpr_p) | (4 * concept_p), 13236 inlinep | (2 * constexpr_p) | (4 * concept_p)
13237 | (8 * consteval_p),
12361 initialized == SD_DELETED, sfk, 13238 initialized == SD_DELETED, sfk,
12362 funcdef_flag, late_return_type_p, 13239 funcdef_flag, late_return_type_p,
12363 template_count, in_namespace, 13240 template_count, in_namespace,
12364 attrlist, declarator->id_loc); 13241 attrlist, id_loc);
12365 decl = set_virt_specifiers (decl, virt_specifiers); 13242 decl = set_virt_specifiers (decl, virt_specifiers);
12366 if (decl == NULL_TREE) 13243 if (decl == NULL_TREE)
12367 return error_mark_node; 13244 return error_mark_node;
12368 #if 0 13245 #if 0
12369 /* This clobbers the attrs stored in `decl' from `attrlist'. */ 13246 /* This clobbers the attrs stored in `decl' from `attrlist'. */
12378 specifies a conversion from the type of its first 13255 specifies a conversion from the type of its first
12379 parameter to the type of its class. Such a constructor 13256 parameter to the type of its class. Such a constructor
12380 is called a converting constructor. */ 13257 is called a converting constructor. */
12381 if (explicitp == 2) 13258 if (explicitp == 2)
12382 DECL_NONCONVERTING_P (decl) = 1; 13259 DECL_NONCONVERTING_P (decl) = 1;
13260
13261 if (declspecs->explicit_specifier)
13262 store_explicit_specifier (decl, declspecs->explicit_specifier);
12383 } 13263 }
12384 else if (!staticp && !dependent_type_p (type) 13264 else if (!staticp
12385 && !COMPLETE_TYPE_P (complete_type (type)) 13265 && ((current_class_type
12386 && (!complete_or_array_type_p (type) 13266 && same_type_p (type, current_class_type))
12387 || initialized == 0)) 13267 || (!dependent_type_p (type)
13268 && !COMPLETE_TYPE_P (complete_type (type))
13269 && (!complete_or_array_type_p (type)
13270 || initialized == 0))))
12388 { 13271 {
12389 if (TREE_CODE (type) != ARRAY_TYPE 13272 if (TREE_CODE (type) != ARRAY_TYPE
12390 || !COMPLETE_TYPE_P (TREE_TYPE (type))) 13273 || !COMPLETE_TYPE_P (TREE_TYPE (type)))
12391 { 13274 {
12392 if (unqualified_id) 13275 if (unqualified_id)
12393 { 13276 {
12394 error ("field %qD has incomplete type %qT", 13277 error_at (id_loc, "field %qD has incomplete type %qT",
12395 unqualified_id, type); 13278 unqualified_id, type);
12396 cxx_incomplete_type_inform (strip_array_types (type)); 13279 cxx_incomplete_type_inform (strip_array_types (type));
12397 } 13280 }
12398 else 13281 else
12399 error ("name %qT has incomplete type", type); 13282 error ("name %qT has incomplete type", type);
12400 13283
12401 type = error_mark_node; 13284 type = error_mark_node;
12402 decl = NULL_TREE; 13285 decl = NULL_TREE;
12403 } 13286 }
13287 }
13288 else if (!verify_type_context (input_location,
13289 staticp
13290 ? TCTX_STATIC_STORAGE
13291 : TCTX_FIELD, type))
13292 {
13293 type = error_mark_node;
13294 decl = NULL_TREE;
12404 } 13295 }
12405 else 13296 else
12406 { 13297 {
12407 if (friendp) 13298 if (friendp)
12408 { 13299 {
12409 error ("%qE is neither function nor member function; " 13300 if (unqualified_id)
12410 "cannot be declared friend", unqualified_id); 13301 error_at (id_loc,
13302 "%qE is neither function nor member function; "
13303 "cannot be declared friend", unqualified_id);
13304 else
13305 error ("unnamed field is neither function nor member "
13306 "function; cannot be declared friend");
12411 return error_mark_node; 13307 return error_mark_node;
12412 } 13308 }
12413 decl = NULL_TREE; 13309 decl = NULL_TREE;
12414 } 13310 }
12415 13311
12418 /* Friends are treated specially. */ 13314 /* Friends are treated specially. */
12419 if (ctype == current_class_type) 13315 if (ctype == current_class_type)
12420 ; /* We already issued a permerror. */ 13316 ; /* We already issued a permerror. */
12421 else if (decl && DECL_NAME (decl)) 13317 else if (decl && DECL_NAME (decl))
12422 { 13318 {
13319 if (initialized)
13320 /* Kludge: We need funcdef_flag to be true in do_friend for
13321 in-class defaulted functions, but that breaks grokfndecl.
13322 So set it here. */
13323 funcdef_flag = true;
12423 if (template_class_depth (current_class_type) == 0) 13324 if (template_class_depth (current_class_type) == 0)
12424 { 13325 {
12425 decl = check_explicit_specialization 13326 decl = check_explicit_specialization
12426 (unqualified_id, decl, template_count, 13327 (unqualified_id, decl, template_count,
12427 2 * funcdef_flag + 4); 13328 2 * funcdef_flag + 4);
12444 { 13345 {
12445 if (staticp) 13346 if (staticp)
12446 { 13347 {
12447 /* C++ allows static class members. All other work 13348 /* C++ allows static class members. All other work
12448 for this is done by grokfield. */ 13349 for this is done by grokfield. */
12449 decl = build_lang_decl_loc (declarator 13350 decl = build_lang_decl_loc (id_loc, VAR_DECL,
12450 ? declarator->id_loc 13351 unqualified_id, type);
12451 : input_location,
12452 VAR_DECL, unqualified_id, type);
12453 set_linkage_for_static_data_member (decl); 13352 set_linkage_for_static_data_member (decl);
12454 if (concept_p) 13353 if (concept_p)
12455 error_at (declspecs->locations[ds_concept], 13354 error_at (declspecs->locations[ds_concept],
12456 "static data member %qE declared %<concept%>", 13355 "static data member %qE declared %qs",
12457 unqualified_id); 13356 unqualified_id, "concept");
12458 else if (constexpr_p && !initialized) 13357 else if (constexpr_p && !initialized)
12459 { 13358 {
12460 error ("%<constexpr%> static data member %qD must have an " 13359 error_at (DECL_SOURCE_LOCATION (decl),
12461 "initializer", decl); 13360 "%<constexpr%> static data member %qD must "
13361 "have an initializer", decl);
12462 constexpr_p = false; 13362 constexpr_p = false;
12463 } 13363 }
13364 if (consteval_p)
13365 error_at (declspecs->locations[ds_consteval],
13366 "static data member %qE declared %qs",
13367 unqualified_id, "consteval");
12464 13368
12465 if (inlinep) 13369 if (inlinep)
12466 mark_inline_variable (decl, declspecs->locations[ds_inline]); 13370 mark_inline_variable (decl, declspecs->locations[ds_inline]);
12467 13371
12468 if (!DECL_VAR_DECLARED_INLINE_P (decl) 13372 if (!DECL_VAR_DECLARED_INLINE_P (decl)
12483 } 13387 }
12484 } 13388 }
12485 else 13389 else
12486 { 13390 {
12487 if (concept_p) 13391 if (concept_p)
12488 error_at (declspecs->locations[ds_concept], 13392 {
12489 "non-static data member %qE declared %<concept%>", 13393 error_at (declspecs->locations[ds_concept],
12490 unqualified_id); 13394 "non-static data member %qE declared %qs",
12491 else if (constexpr_p) 13395 unqualified_id, "concept");
13396 concept_p = false;
13397 constexpr_p = false;
13398 }
13399 else if (constexpr_p)
12492 { 13400 {
12493 error_at (declspecs->locations[ds_constexpr], 13401 error_at (declspecs->locations[ds_constexpr],
12494 "non-static data member %qE declared %<constexpr%>", 13402 "non-static data member %qE declared %qs",
12495 unqualified_id); 13403 unqualified_id, "constexpr");
12496 constexpr_p = false; 13404 constexpr_p = false;
12497 } 13405 }
12498 decl = build_decl (input_location, 13406 if (constinit_p)
12499 FIELD_DECL, unqualified_id, type); 13407 {
13408 error_at (declspecs->locations[ds_constinit],
13409 "non-static data member %qE declared %qs",
13410 unqualified_id, "constinit");
13411 constinit_p = false;
13412 }
13413 if (consteval_p)
13414 {
13415 error_at (declspecs->locations[ds_consteval],
13416 "non-static data member %qE declared %qs",
13417 unqualified_id, "consteval");
13418 consteval_p = false;
13419 }
13420 decl = build_decl (id_loc, FIELD_DECL, unqualified_id, type);
12500 DECL_NONADDRESSABLE_P (decl) = bitfield; 13421 DECL_NONADDRESSABLE_P (decl) = bitfield;
12501 if (bitfield && !unqualified_id) 13422 if (bitfield && !unqualified_id)
12502 { 13423 {
12503 TREE_NO_WARNING (decl) = 1; 13424 TREE_NO_WARNING (decl) = 1;
12504 DECL_PADDING_P (decl) = 1; 13425 DECL_PADDING_P (decl) = 1;
12529 staticp ? false : inlinep, friendp, 13450 staticp ? false : inlinep, friendp,
12530 raises != NULL_TREE, 13451 raises != NULL_TREE,
12531 declspecs->locations); 13452 declspecs->locations);
12532 } 13453 }
12533 } 13454 }
12534 else if (TREE_CODE (type) == FUNCTION_TYPE 13455 else if (FUNC_OR_METHOD_TYPE_P (type))
12535 || TREE_CODE (type) == METHOD_TYPE)
12536 { 13456 {
12537 tree original_name; 13457 tree original_name;
12538 int publicp = 0; 13458 int publicp = 0;
12539 13459
12540 if (!unqualified_id) 13460 if (!unqualified_id)
12545 else 13465 else
12546 original_name = unqualified_id; 13466 original_name = unqualified_id;
12547 // FIXME:gcc_assert (original_name == dname); 13467 // FIXME:gcc_assert (original_name == dname);
12548 13468
12549 if (storage_class == sc_auto) 13469 if (storage_class == sc_auto)
12550 error ("storage class %<auto%> invalid for function %qs", name); 13470 error_at (declspecs->locations[ds_storage_class],
13471 "storage class %<auto%> invalid for function %qs", name);
12551 else if (storage_class == sc_register) 13472 else if (storage_class == sc_register)
12552 error ("storage class %<register%> invalid for function %qs", name); 13473 error_at (declspecs->locations[ds_storage_class],
13474 "storage class %<register%> invalid for function %qs",
13475 name);
12553 else if (thread_p) 13476 else if (thread_p)
12554 { 13477 {
12555 if (declspecs->gnu_thread_keyword_p) 13478 if (declspecs->gnu_thread_keyword_p)
12556 error_at (declspecs->locations[ds_thread], 13479 error_at (declspecs->locations[ds_thread],
12557 "storage class %<__thread%> invalid for function %qs", 13480 "storage class %<__thread%> invalid for function %qs",
12597 ? G_("%qs defined in a non-class scope") 13520 ? G_("%qs defined in a non-class scope")
12598 : G_("%qs declared in a non-class scope"), name); 13521 : G_("%qs declared in a non-class scope"), name);
12599 sfk = sfk_none; 13522 sfk = sfk_none;
12600 } 13523 }
12601 } 13524 }
13525 if (consteval_p
13526 && identifier_p (unqualified_id)
13527 && IDENTIFIER_NEWDEL_OP_P (unqualified_id))
13528 {
13529 error_at (declspecs->locations[ds_consteval],
13530 "%qD cannot be %qs", unqualified_id, "consteval");
13531 consteval_p = false;
13532 }
12602 13533
12603 /* Record whether the function is public. */ 13534 /* Record whether the function is public. */
12604 publicp = (ctype != NULL_TREE 13535 publicp = (ctype != NULL_TREE
12605 || storage_class != sc_static); 13536 || storage_class != sc_static);
12606 13537
12607 decl = grokfndecl (ctype, type, original_name, parms, unqualified_id, 13538 decl = grokfndecl (ctype, type, original_name, parms, unqualified_id,
12608 declspecs, 13539 declspecs,
12609 reqs, virtualp, flags, memfn_quals, rqual, raises, 13540 reqs, virtualp, flags, memfn_quals, rqual, raises,
12610 1, friendp, 13541 1, friendp,
12611 publicp, 13542 publicp,
12612 inlinep | (2 * constexpr_p) | (4 * concept_p), 13543 inlinep | (2 * constexpr_p) | (4 * concept_p)
13544 | (8 * consteval_p),
12613 initialized == SD_DELETED, 13545 initialized == SD_DELETED,
12614 sfk, 13546 sfk,
12615 funcdef_flag, 13547 funcdef_flag,
12616 late_return_type_p, 13548 late_return_type_p,
12617 template_count, in_namespace, attrlist, 13549 template_count, in_namespace, attrlist,
12618 declarator->id_loc); 13550 id_loc);
12619 if (decl == NULL_TREE) 13551 if (decl == NULL_TREE)
12620 return error_mark_node; 13552 return error_mark_node;
12621 13553
12622 if (explicitp == 2) 13554 if (explicitp == 2)
12623 DECL_NONCONVERTING_P (decl) = 1; 13555 DECL_NONCONVERTING_P (decl) = 1;
12659 initialized, 13591 initialized,
12660 type_quals, 13592 type_quals,
12661 inlinep, 13593 inlinep,
12662 concept_p, 13594 concept_p,
12663 template_count, 13595 template_count,
12664 ctype ? ctype : in_namespace); 13596 ctype ? ctype : in_namespace,
13597 id_loc);
12665 if (decl == NULL_TREE) 13598 if (decl == NULL_TREE)
12666 return error_mark_node; 13599 return error_mark_node;
12667 13600
12668 bad_specifiers (decl, BSP_VAR, virtualp, 13601 bad_specifiers (decl, BSP_VAR, virtualp,
12669 memfn_quals != TYPE_UNQUALIFIED, 13602 memfn_quals != TYPE_UNQUALIFIED,
12673 if (ctype) 13606 if (ctype)
12674 { 13607 {
12675 DECL_CONTEXT (decl) = ctype; 13608 DECL_CONTEXT (decl) = ctype;
12676 if (staticp == 1) 13609 if (staticp == 1)
12677 { 13610 {
12678 permerror (input_location, "%<static%> may not be used when defining " 13611 permerror (declspecs->locations[ds_storage_class],
13612 "%<static%> may not be used when defining "
12679 "(as opposed to declaring) a static data member"); 13613 "(as opposed to declaring) a static data member");
12680 staticp = 0; 13614 staticp = 0;
12681 storage_class = sc_none; 13615 storage_class = sc_none;
12682 } 13616 }
12683 if (storage_class == sc_register && TREE_STATIC (decl)) 13617 if (storage_class == sc_register && TREE_STATIC (decl))
12693 storage_class = sc_none; 13627 storage_class = sc_none;
12694 } 13628 }
12695 } 13629 }
12696 else if (constexpr_p && DECL_EXTERNAL (decl)) 13630 else if (constexpr_p && DECL_EXTERNAL (decl))
12697 { 13631 {
12698 error ("declaration of %<constexpr%> variable %qD " 13632 error_at (DECL_SOURCE_LOCATION (decl),
12699 "is not a definition", decl); 13633 "declaration of %<constexpr%> variable %qD "
13634 "is not a definition", decl);
12700 constexpr_p = false; 13635 constexpr_p = false;
13636 }
13637 if (consteval_p)
13638 {
13639 error_at (DECL_SOURCE_LOCATION (decl),
13640 "a variable cannot be declared %<consteval%>");
13641 consteval_p = false;
12701 } 13642 }
12702 13643
12703 if (inlinep) 13644 if (inlinep)
12704 mark_inline_variable (decl, declspecs->locations[ds_inline]); 13645 mark_inline_variable (decl, declspecs->locations[ds_inline]);
12705 if (innermost_code == cdk_decomp) 13646 if (innermost_code == cdk_decomp)
12706 { 13647 {
12707 gcc_assert (declarator && declarator->kind == cdk_decomp); 13648 gcc_assert (declarator && declarator->kind == cdk_decomp);
12708 DECL_SOURCE_LOCATION (decl) = declarator->id_loc; 13649 DECL_SOURCE_LOCATION (decl) = id_loc;
12709 DECL_ARTIFICIAL (decl) = 1; 13650 DECL_ARTIFICIAL (decl) = 1;
12710 fit_decomposition_lang_decl (decl, NULL_TREE); 13651 fit_decomposition_lang_decl (decl, NULL_TREE);
12711 } 13652 }
12712 } 13653 }
12713 13654
12725 if (toplevel_bindings_p ()) 13666 if (toplevel_bindings_p ())
12726 { 13667 {
12727 /* It's common practice (and completely valid) to have a const 13668 /* It's common practice (and completely valid) to have a const
12728 be initialized and declared extern. */ 13669 be initialized and declared extern. */
12729 if (!(type_quals & TYPE_QUAL_CONST)) 13670 if (!(type_quals & TYPE_QUAL_CONST))
12730 warning (0, "%qs initialized and declared %<extern%>", name); 13671 warning_at (DECL_SOURCE_LOCATION (decl), 0,
13672 "%qs initialized and declared %<extern%>", name);
12731 } 13673 }
12732 else 13674 else
12733 { 13675 {
12734 error ("%qs has both %<extern%> and initializer", name); 13676 error_at (DECL_SOURCE_LOCATION (decl),
13677 "%qs has both %<extern%> and initializer", name);
12735 return error_mark_node; 13678 return error_mark_node;
12736 } 13679 }
12737 } 13680 }
12738 13681
12739 /* Record `register' declaration for warnings on & 13682 /* Record `register' declaration for warnings on &
12842 check_default_argument (tree decl, tree arg, tsubst_flags_t complain) 13785 check_default_argument (tree decl, tree arg, tsubst_flags_t complain)
12843 { 13786 {
12844 tree var; 13787 tree var;
12845 tree decl_type; 13788 tree decl_type;
12846 13789
12847 if (TREE_CODE (arg) == DEFAULT_ARG) 13790 if (TREE_CODE (arg) == DEFERRED_PARSE)
12848 /* We get a DEFAULT_ARG when looking at an in-class declaration 13791 /* We get a DEFERRED_PARSE when looking at an in-class declaration
12849 with a default argument. Ignore the argument for now; we'll 13792 with a default argument. Ignore the argument for now; we'll
12850 deal with it after the class is complete. */ 13793 deal with it after the class is complete. */
12851 return arg; 13794 return arg;
12852 13795
12853 if (TYPE_P (decl)) 13796 if (TYPE_P (decl))
12878 --cp_unevaluated_operand; 13821 --cp_unevaluated_operand;
12879 13822
12880 /* Avoid redundant -Wzero-as-null-pointer-constant warnings at 13823 /* Avoid redundant -Wzero-as-null-pointer-constant warnings at
12881 the call sites. */ 13824 the call sites. */
12882 if (TYPE_PTR_OR_PTRMEM_P (decl_type) 13825 if (TYPE_PTR_OR_PTRMEM_P (decl_type)
12883 && null_ptr_cst_p (arg)) 13826 && null_ptr_cst_p (arg)
13827 /* Don't lose side-effects as in PR90473. */
13828 && !TREE_SIDE_EFFECTS (arg))
12884 return nullptr_node; 13829 return nullptr_node;
12885 13830
12886 /* [dcl.fct.default] 13831 /* [dcl.fct.default]
12887 13832
12888 Local variables shall not be used in default argument 13833 Local variables shall not be used in default argument
12919 if (TYPE_NAME (type)) 13864 if (TYPE_NAME (type))
12920 { 13865 {
12921 if (TREE_DEPRECATED (TYPE_NAME (type))) 13866 if (TREE_DEPRECATED (TYPE_NAME (type)))
12922 return type; 13867 return type;
12923 else 13868 else
12924 return NULL_TREE; 13869 {
13870 cp_warn_deprecated_use_scopes (CP_DECL_CONTEXT (TYPE_NAME (type)));
13871 return NULL_TREE;
13872 }
12925 } 13873 }
12926 13874
12927 /* Do warn about using typedefs to a deprecated class. */ 13875 /* Do warn about using typedefs to a deprecated class. */
12928 if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type)) 13876 if (OVERLOAD_TYPE_P (type) && type != TYPE_MAIN_VARIANT (type))
12929 return type_is_deprecated (TYPE_MAIN_VARIANT (type)); 13877 return type_is_deprecated (TYPE_MAIN_VARIANT (type));
13003 tree deptype = type_is_deprecated (type); 13951 tree deptype = type_is_deprecated (type);
13004 if (deptype) 13952 if (deptype)
13005 cp_warn_deprecated_use (deptype); 13953 cp_warn_deprecated_use (deptype);
13006 } 13954 }
13007 13955
13956 /* [dcl.fct] "A parameter with volatile-qualified type is
13957 deprecated." */
13958 if (CP_TYPE_VOLATILE_P (type))
13959 warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wvolatile,
13960 "%<volatile%>-qualified parameter is "
13961 "deprecated");
13962
13008 /* Top-level qualifiers on the parameters are 13963 /* Top-level qualifiers on the parameters are
13009 ignored for function types. */ 13964 ignored for function types. */
13010 type = cp_build_qualified_type (type, 0); 13965 type = cp_build_qualified_type (type, 0);
13011 if (TREE_CODE (type) == METHOD_TYPE) 13966 if (TREE_CODE (type) == METHOD_TYPE)
13012 { 13967 {
13201 void 14156 void
13202 grok_special_member_properties (tree decl) 14157 grok_special_member_properties (tree decl)
13203 { 14158 {
13204 tree class_type; 14159 tree class_type;
13205 14160
13206 if (!DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)) 14161 if (TREE_CODE (decl) == USING_DECL
14162 || !DECL_NONSTATIC_MEMBER_FUNCTION_P (decl))
13207 return; 14163 return;
13208 14164
13209 class_type = DECL_CONTEXT (decl); 14165 class_type = DECL_CONTEXT (decl);
13210 if (IDENTIFIER_CTOR_P (DECL_NAME (decl))) 14166 if (IDENTIFIER_CTOR_P (DECL_NAME (decl)))
13211 { 14167 {
13222 constructor if its first parameter is of type X&, const 14178 constructor if its first parameter is of type X&, const
13223 X&, volatile X& or const volatile X&, and either there 14179 X&, volatile X& or const volatile X&, and either there
13224 are no other parameters or else all other parameters have 14180 are no other parameters or else all other parameters have
13225 default arguments. */ 14181 default arguments. */
13226 TYPE_HAS_COPY_CTOR (class_type) = 1; 14182 TYPE_HAS_COPY_CTOR (class_type) = 1;
13227 if (user_provided_p (decl))
13228 TYPE_HAS_COMPLEX_COPY_CTOR (class_type) = 1;
13229 if (ctor > 1) 14183 if (ctor > 1)
13230 TYPE_HAS_CONST_COPY_CTOR (class_type) = 1; 14184 TYPE_HAS_CONST_COPY_CTOR (class_type) = 1;
13231 } 14185 }
13232 else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl))) 14186 else if (sufficient_parms_p (FUNCTION_FIRST_USER_PARMTYPE (decl)))
13233 TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1; 14187 TYPE_HAS_DEFAULT_CONSTRUCTOR (class_type) = 1;
13234 else if (move_fn_p (decl) && user_provided_p (decl))
13235 TYPE_HAS_COMPLEX_MOVE_CTOR (class_type) = 1;
13236 else if (is_list_ctor (decl)) 14188 else if (is_list_ctor (decl))
13237 TYPE_HAS_LIST_CTOR (class_type) = 1; 14189 TYPE_HAS_LIST_CTOR (class_type) = 1;
13238 14190
13239 if (DECL_DECLARED_CONSTEXPR_P (decl) 14191 if (DECL_DECLARED_CONSTEXPR_P (decl)
13240 && !ctor && !move_fn_p (decl)) 14192 && !ctor && !move_fn_p (decl))
13251 int assop = copy_fn_p (decl); 14203 int assop = copy_fn_p (decl);
13252 14204
13253 if (assop) 14205 if (assop)
13254 { 14206 {
13255 TYPE_HAS_COPY_ASSIGN (class_type) = 1; 14207 TYPE_HAS_COPY_ASSIGN (class_type) = 1;
13256 if (user_provided_p (decl))
13257 TYPE_HAS_COMPLEX_COPY_ASSIGN (class_type) = 1;
13258 if (assop != 1) 14208 if (assop != 1)
13259 TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1; 14209 TYPE_HAS_CONST_COPY_ASSIGN (class_type) = 1;
13260 } 14210 }
13261 else if (move_fn_p (decl) && user_provided_p (decl))
13262 TYPE_HAS_COMPLEX_MOVE_ASSIGN (class_type) = 1;
13263 } 14211 }
13264 else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl))) 14212 else if (IDENTIFIER_CONV_OP_P (DECL_NAME (decl)))
13265 TYPE_HAS_CONVERSION (class_type) = true; 14213 TYPE_HAS_CONVERSION (class_type) = true;
13266 14214
13267 /* Destructors are handled in check_methods. */ 14215 /* Destructors are handled in check_methods. */
13290 overload resolution will never prefer such a constructor to 14238 overload resolution will never prefer such a constructor to
13291 the non-template copy constructor (which is either explicitly 14239 the non-template copy constructor (which is either explicitly
13292 or implicitly defined), there's no need to worry about their 14240 or implicitly defined), there's no need to worry about their
13293 existence. Theoretically, they should never even be 14241 existence. Theoretically, they should never even be
13294 instantiated, but that's hard to forestall. */ 14242 instantiated, but that's hard to forestall. */
13295 error ("invalid constructor; you probably meant %<%T (const %T&)%>", 14243 error_at (DECL_SOURCE_LOCATION (decl),
14244 "invalid constructor; you probably meant %<%T (const %T&)%>",
13296 ctype, ctype); 14245 ctype, ctype);
13297 return false; 14246 return false;
13298 } 14247 }
13299 14248
13300 return true; 14249 return true;
13382 return false; 14331 return false;
13383 } 14332 }
13384 } 14333 }
13385 14334
13386 if (op_flags & OVL_OP_FLAG_DELETE) 14335 if (op_flags & OVL_OP_FLAG_DELETE)
13387 TREE_TYPE (decl) = coerce_delete_type (TREE_TYPE (decl), loc); 14336 {
14337 DECL_SET_IS_OPERATOR_DELETE (decl, true);
14338 coerce_delete_type (decl, loc);
14339 }
13388 else 14340 else
13389 { 14341 {
13390 DECL_IS_OPERATOR_NEW (decl) = 1; 14342 DECL_SET_IS_OPERATOR_NEW (decl, true);
13391 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc); 14343 TREE_TYPE (decl) = coerce_new_type (TREE_TYPE (decl), loc);
13392 } 14344 }
13393 14345
13394 return true; 14346 return true;
13395 } 14347 }
13445 return true; 14397 return true;
13446 14398
13447 if (operator_code == COND_EXPR) 14399 if (operator_code == COND_EXPR)
13448 { 14400 {
13449 /* 13.4.0.3 */ 14401 /* 13.4.0.3 */
13450 error_at (loc, "ISO C++ prohibits overloading operator ?:"); 14402 error_at (loc, "ISO C++ prohibits overloading %<operator ?:%>");
13451 return false; 14403 return false;
13452 } 14404 }
13453 14405
13454 /* Count the number of arguments and check for ellipsis. */ 14406 /* Count the number of arguments and check for ellipsis. */
13455 int arity = 0; 14407 int arity = 0;
13708 the type is declared. */ 14660 the type is declared. */
13709 else if (!DECL_IMPLICIT_TYPEDEF_P (decl) 14661 else if (!DECL_IMPLICIT_TYPEDEF_P (decl)
13710 && !DECL_SELF_REFERENCE_P (decl) 14662 && !DECL_SELF_REFERENCE_P (decl)
13711 && tag_code != typename_type) 14663 && tag_code != typename_type)
13712 { 14664 {
13713 if (alias_template_specialization_p (type)) 14665 if (alias_template_specialization_p (type, nt_opaque))
13714 error ("using alias template specialization %qT after %qs", 14666 error ("using alias template specialization %qT after %qs",
13715 type, tag_name (tag_code)); 14667 type, tag_name (tag_code));
13716 else 14668 else
13717 error ("using typedef-name %qD after %qs", decl, tag_name (tag_code)); 14669 error ("using typedef-name %qD after %qs", decl, tag_name (tag_code));
13718 inform (DECL_SOURCE_LOCATION (decl), 14670 inform (DECL_SOURCE_LOCATION (decl),
13893 } 14845 }
13894 14846
13895 /* In case of anonymous name, xref_tag is only called to 14847 /* In case of anonymous name, xref_tag is only called to
13896 make type node and push name. Name lookup is not required. */ 14848 make type node and push name. Name lookup is not required. */
13897 tree t = NULL_TREE; 14849 tree t = NULL_TREE;
13898 if (scope != ts_lambda && !anon_aggrname_p (name)) 14850 if (scope != ts_lambda && !IDENTIFIER_ANON_P (name))
13899 t = lookup_and_check_tag (tag_code, name, scope, template_header_p); 14851 t = lookup_and_check_tag (tag_code, name, scope, template_header_p);
13900 14852
13901 if (t == error_mark_node) 14853 if (t == error_mark_node)
13902 return error_mark_node; 14854 return error_mark_node;
13903 14855
14555 /* If the precision of the type was specified with an attribute and it 15507 /* If the precision of the type was specified with an attribute and it
14556 was too small, give an error. Otherwise, use it. */ 15508 was too small, give an error. Otherwise, use it. */
14557 if (TYPE_PRECISION (enumtype)) 15509 if (TYPE_PRECISION (enumtype))
14558 { 15510 {
14559 if (precision > TYPE_PRECISION (enumtype)) 15511 if (precision > TYPE_PRECISION (enumtype))
14560 error ("specified mode too small for enumeral values"); 15512 error ("specified mode too small for enumerated values");
14561 else 15513 else
14562 { 15514 {
14563 use_short_enum = true; 15515 use_short_enum = true;
14564 precision = TYPE_PRECISION (enumtype); 15516 precision = TYPE_PRECISION (enumtype);
14565 } 15517 }
14630 15582
14631 /* Convert each of the enumerators to the type of the underlying 15583 /* Convert each of the enumerators to the type of the underlying
14632 type of the enumeration. */ 15584 type of the enumeration. */
14633 for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values)) 15585 for (values = TYPE_VALUES (enumtype); values; values = TREE_CHAIN (values))
14634 { 15586 {
14635 location_t saved_location;
14636
14637 decl = TREE_VALUE (values); 15587 decl = TREE_VALUE (values);
14638 saved_location = input_location; 15588 iloc_sentinel ils (DECL_SOURCE_LOCATION (decl));
14639 input_location = DECL_SOURCE_LOCATION (decl);
14640 if (fixed_underlying_type_p) 15589 if (fixed_underlying_type_p)
14641 /* If the enumeration type has a fixed underlying type, we 15590 /* If the enumeration type has a fixed underlying type, we
14642 already checked all of the enumerator values. */ 15591 already checked all of the enumerator values. */
14643 value = DECL_INITIAL (decl); 15592 value = DECL_INITIAL (decl);
14644 else 15593 else
14645 value = perform_implicit_conversion (underlying_type, 15594 value = perform_implicit_conversion (underlying_type,
14646 DECL_INITIAL (decl), 15595 DECL_INITIAL (decl),
14647 tf_warning_or_error); 15596 tf_warning_or_error);
14648 input_location = saved_location;
14649
14650 /* Do not clobber shared ints. */ 15597 /* Do not clobber shared ints. */
14651 if (value != error_mark_node) 15598 if (value != error_mark_node)
14652 { 15599 {
14653 value = copy_node (value); 15600 value = copy_node (value);
14654 15601
14751 if (value != NULL_TREE) 15698 if (value != NULL_TREE)
14752 { 15699 {
14753 if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P 15700 if (! INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P
14754 (TREE_TYPE (value))) 15701 (TREE_TYPE (value)))
14755 { 15702 {
14756 error ("enumerator value for %qD must have integral or " 15703 error_at (cp_expr_loc_or_input_loc (value),
14757 "unscoped enumeration type", name); 15704 "enumerator value for %qD must have integral or "
15705 "unscoped enumeration type", name);
14758 value = NULL_TREE; 15706 value = NULL_TREE;
14759 } 15707 }
14760 else 15708 else
14761 { 15709 {
14762 value = cxx_constant_value (value); 15710 value = cxx_constant_value (value);
14934 15882
14935 e = purpose_member (name, TYPE_VALUES (enumtype)); 15883 e = purpose_member (name, TYPE_VALUES (enumtype));
14936 return e? TREE_VALUE (e) : NULL_TREE; 15884 return e? TREE_VALUE (e) : NULL_TREE;
14937 } 15885 }
14938 15886
15887 /* Implement LANG_HOOKS_SIMULATE_ENUM_DECL. */
15888
15889 tree
15890 cxx_simulate_enum_decl (location_t loc, const char *name,
15891 vec<string_int_pair> values)
15892 {
15893 location_t saved_loc = input_location;
15894 input_location = loc;
15895
15896 tree enumtype = start_enum (get_identifier (name), NULL_TREE, NULL_TREE,
15897 NULL_TREE, false, NULL);
15898 if (!OPAQUE_ENUM_P (enumtype))
15899 {
15900 error_at (loc, "multiple definition of %q#T", enumtype);
15901 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (enumtype)),
15902 "previous definition here");
15903 return enumtype;
15904 }
15905 SET_OPAQUE_ENUM_P (enumtype, false);
15906 DECL_SOURCE_LOCATION (TYPE_NAME (enumtype)) = loc;
15907
15908 string_int_pair *value;
15909 unsigned int i;
15910 FOR_EACH_VEC_ELT (values, i, value)
15911 build_enumerator (get_identifier (value->first),
15912 build_int_cst (integer_type_node, value->second),
15913 enumtype, NULL_TREE, loc);
15914
15915 finish_enum_value_list (enumtype);
15916 finish_enum (enumtype);
15917
15918 input_location = saved_loc;
15919 return enumtype;
15920 }
14939 15921
14940 /* We're defining DECL. Make sure that its type is OK. */ 15922 /* We're defining DECL. Make sure that its type is OK. */
14941 15923
14942 static void 15924 static void
14943 check_function_type (tree decl, tree current_function_parms) 15925 check_function_type (tree decl, tree current_function_parms)
15084 } 16066 }
15085 16067
15086 if (DECL_DECLARED_INLINE_P (decl1) 16068 if (DECL_DECLARED_INLINE_P (decl1)
15087 && lookup_attribute ("noinline", attrs)) 16069 && lookup_attribute ("noinline", attrs))
15088 warning_at (DECL_SOURCE_LOCATION (decl1), 0, 16070 warning_at (DECL_SOURCE_LOCATION (decl1), 0,
15089 "inline function %qD given attribute noinline", decl1); 16071 "inline function %qD given attribute %qs", decl1, "noinline");
15090 16072
15091 /* Handle gnu_inline attribute. */ 16073 /* Handle gnu_inline attribute. */
15092 if (GNU_INLINE_P (decl1)) 16074 if (GNU_INLINE_P (decl1))
15093 { 16075 {
15094 DECL_EXTERNAL (decl1) = 1; 16076 DECL_EXTERNAL (decl1) = 1;
15277 a new function, we destroy temporaries in the usual way. */ 16259 a new function, we destroy temporaries in the usual way. */
15278 cfun->language = ggc_cleared_alloc<language_function> (); 16260 cfun->language = ggc_cleared_alloc<language_function> ();
15279 current_stmt_tree ()->stmts_are_full_exprs_p = 1; 16261 current_stmt_tree ()->stmts_are_full_exprs_p = 1;
15280 current_binding_level = bl; 16262 current_binding_level = bl;
15281 16263
16264 /* If we are (erroneously) defining a function that we have already
16265 defined before, wipe out what we knew before. */
16266 gcc_checking_assert (!DECL_PENDING_INLINE_P (decl1));
16267 FNDECL_USED_AUTO (decl1) = false;
16268 DECL_SAVED_AUTO_RETURN_TYPE (decl1) = NULL;
16269
15282 if (!processing_template_decl && type_uses_auto (restype)) 16270 if (!processing_template_decl && type_uses_auto (restype))
15283 { 16271 {
15284 FNDECL_USED_AUTO (decl1) = true; 16272 FNDECL_USED_AUTO (decl1) = true;
15285 current_function_auto_return_pattern = restype; 16273 DECL_SAVED_AUTO_RETURN_TYPE (decl1) = restype;
15286 } 16274 }
15287 16275
15288 /* Start the statement-tree, start the tree now. */ 16276 /* Start the statement-tree, start the tree now. */
15289 DECL_SAVED_TREE (decl1) = push_stmt_list (); 16277 DECL_SAVED_TREE (decl1) = push_stmt_list ();
15290
15291 /* If we are (erroneously) defining a function that we have already
15292 defined before, wipe out what we knew before. */
15293 if (!DECL_PENDING_INLINE_P (decl1))
15294 DECL_SAVED_FUNCTION_DATA (decl1) = NULL;
15295 16278
15296 if (ctype && !doing_friend && !DECL_STATIC_FUNCTION_P (decl1)) 16279 if (ctype && !doing_friend && !DECL_STATIC_FUNCTION_P (decl1))
15297 { 16280 {
15298 /* We know that this was set up by `grokclassfn'. We do not 16281 /* We know that this was set up by `grokclassfn'. We do not
15299 wait until `store_parm_decls', since evil parse errors may 16282 wait until `store_parm_decls', since evil parse errors may
15425 } 16408 }
15426 16409
15427 start_fname_decls (); 16410 start_fname_decls ();
15428 16411
15429 store_parm_decls (current_function_parms); 16412 store_parm_decls (current_function_parms);
16413
16414 push_operator_bindings ();
15430 16415
15431 if (!processing_template_decl 16416 if (!processing_template_decl
15432 && (flag_lifetime_dse > 1) 16417 && (flag_lifetime_dse > 1)
15433 && DECL_CONSTRUCTOR_P (decl1) 16418 && DECL_CONSTRUCTOR_P (decl1)
15434 && !DECL_CLONED_FUNCTION_P (decl1) 16419 && !DECL_CLONED_FUNCTION_P (decl1)
15445 && sanitize_flags_p (SANITIZE_VPTR) 16430 && sanitize_flags_p (SANITIZE_VPTR)
15446 && !DECL_CLONED_FUNCTION_P (decl1) 16431 && !DECL_CLONED_FUNCTION_P (decl1)
15447 && !implicit_default_ctor_p (decl1)) 16432 && !implicit_default_ctor_p (decl1))
15448 cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr); 16433 cp_ubsan_maybe_initialize_vtbl_ptrs (current_class_ptr);
15449 16434
15450 start_lambda_scope (decl1); 16435 if (!DECL_OMP_DECLARE_REDUCTION_P (decl1))
16436 start_lambda_scope (decl1);
15451 16437
15452 return true; 16438 return true;
15453 } 16439 }
15454 16440
15455 16441
15469 16455
15470 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs); 16456 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
15471 invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1); 16457 invoke_plugin_callbacks (PLUGIN_START_PARSE_FUNCTION, decl1);
15472 if (decl1 == error_mark_node) 16458 if (decl1 == error_mark_node)
15473 return false; 16459 return false;
15474 /* If the declarator is not suitable for a function definition,
15475 cause a syntax error. */
15476 if (decl1 == NULL_TREE || TREE_CODE (decl1) != FUNCTION_DECL)
15477 {
15478 error ("invalid function declaration");
15479 return false;
15480 }
15481 16460
15482 if (DECL_MAIN_P (decl1)) 16461 if (DECL_MAIN_P (decl1))
15483 /* main must return int. grokfndecl should have corrected it 16462 /* main must return int. grokfndecl should have corrected it
15484 (and issued a diagnostic) if the user got it wrong. */ 16463 (and issued a diagnostic) if the user got it wrong. */
15485 gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)), 16464 gcc_assert (same_type_p (TREE_TYPE (TREE_TYPE (decl1)),
15510 and we avoid spurious warnings about unreachable 16489 and we avoid spurious warnings about unreachable
15511 code. */ 16490 code. */
15512 && !DECL_DEFAULTED_FN (fn)); 16491 && !DECL_DEFAULTED_FN (fn));
15513 } 16492 }
15514 16493
16494 /* Helper function to push ARGS into the current lexical scope. DECL
16495 is the function declaration. NONPARMS is used to handle enum
16496 constants. */
16497
16498 void
16499 do_push_parm_decls (tree decl, tree args, tree *nonparms)
16500 {
16501 /* If we're doing semantic analysis, then we'll call pushdecl
16502 for each of these. We must do them in reverse order so that
16503 they end in the correct forward order. */
16504 args = nreverse (args);
16505
16506 tree next;
16507 for (tree parm = args; parm; parm = next)
16508 {
16509 next = DECL_CHAIN (parm);
16510 if (TREE_CODE (parm) == PARM_DECL)
16511 pushdecl (parm);
16512 else if (nonparms)
16513 {
16514 /* If we find an enum constant or a type tag, put it aside for
16515 the moment. */
16516 TREE_CHAIN (parm) = NULL_TREE;
16517 *nonparms = chainon (*nonparms, parm);
16518 }
16519 }
16520
16521 /* Get the decls in their original chain order and record in the
16522 function. This is all and only the PARM_DECLs that were
16523 pushed into scope by the loop above. */
16524 DECL_ARGUMENTS (decl) = get_local_decls ();
16525 }
16526
15515 /* Store the parameter declarations into the current function declaration. 16527 /* Store the parameter declarations into the current function declaration.
15516 This is called after parsing the parameter declarations, before 16528 This is called after parsing the parameter declarations, before
15517 digesting the body of the function. 16529 digesting the body of the function.
15518 16530
15519 Also install to binding contour return value identifier, if any. */ 16531 Also install to binding contour return value identifier, if any. */
15520 16532
15521 static void 16533 static void
15522 store_parm_decls (tree current_function_parms) 16534 store_parm_decls (tree current_function_parms)
15523 { 16535 {
15524 tree fndecl = current_function_decl; 16536 tree fndecl = current_function_decl;
15525 tree parm;
15526 16537
15527 /* This is a chain of any other decls that came in among the parm 16538 /* This is a chain of any other decls that came in among the parm
15528 declarations. If a parm is declared with enum {foo, bar} x; 16539 declarations. If a parm is declared with enum {foo, bar} x;
15529 then CONST_DECLs for foo and bar are put here. */ 16540 then CONST_DECLs for foo and bar are put here. */
15530 tree nonparms = NULL_TREE; 16541 tree nonparms = NULL_TREE;
15535 The parms already have decls, so we need not do anything here 16546 The parms already have decls, so we need not do anything here
15536 except record them as in effect 16547 except record them as in effect
15537 and complain if any redundant old-style parm decls were written. */ 16548 and complain if any redundant old-style parm decls were written. */
15538 16549
15539 tree specparms = current_function_parms; 16550 tree specparms = current_function_parms;
15540 tree next;
15541 16551
15542 /* Must clear this because it might contain TYPE_DECLs declared 16552 /* Must clear this because it might contain TYPE_DECLs declared
15543 at class level. */ 16553 at class level. */
15544 current_binding_level->names = NULL; 16554 current_binding_level->names = NULL;
15545 16555
15546 /* If we're doing semantic analysis, then we'll call pushdecl 16556 do_push_parm_decls (fndecl, specparms, &nonparms);
15547 for each of these. We must do them in reverse order so that
15548 they end in the correct forward order. */
15549 specparms = nreverse (specparms);
15550
15551 for (parm = specparms; parm; parm = next)
15552 {
15553 next = DECL_CHAIN (parm);
15554 if (TREE_CODE (parm) == PARM_DECL)
15555 pushdecl (parm);
15556 else
15557 {
15558 /* If we find an enum constant or a type tag,
15559 put it aside for the moment. */
15560 TREE_CHAIN (parm) = NULL_TREE;
15561 nonparms = chainon (nonparms, parm);
15562 }
15563 }
15564
15565 /* Get the decls in their original chain order and record in the
15566 function. This is all and only the PARM_DECLs that were
15567 pushed into scope by the loop above. */
15568 DECL_ARGUMENTS (fndecl) = get_local_decls ();
15569 } 16557 }
15570 else 16558 else
15571 DECL_ARGUMENTS (fndecl) = NULL_TREE; 16559 DECL_ARGUMENTS (fndecl) = NULL_TREE;
15572 16560
15573 /* Now store the final chain of decls for the arguments 16561 /* Now store the final chain of decls for the arguments
15579 if (use_eh_spec_block (current_function_decl)) 16567 if (use_eh_spec_block (current_function_decl))
15580 current_eh_spec_block = begin_eh_spec_block (); 16568 current_eh_spec_block = begin_eh_spec_block ();
15581 } 16569 }
15582 16570
15583 16571
15584 /* We have finished doing semantic analysis on DECL, but have not yet
15585 generated RTL for its body. Save away our current state, so that
15586 when we want to generate RTL later we know what to do. */
15587
15588 static void
15589 save_function_data (tree decl)
15590 {
15591 struct language_function *f;
15592
15593 /* Save the language-specific per-function data so that we can
15594 get it back when we really expand this function. */
15595 gcc_assert (!DECL_PENDING_INLINE_P (decl));
15596
15597 /* Make a copy. */
15598 f = ggc_alloc<language_function> ();
15599 memcpy (f, cp_function_chain, sizeof (struct language_function));
15600 DECL_SAVED_FUNCTION_DATA (decl) = f;
15601
15602 /* Clear out the bits we don't need. */
15603 f->base.x_stmt_tree.x_cur_stmt_list = NULL;
15604 f->bindings = NULL;
15605 f->x_local_names = NULL;
15606 f->base.local_typedefs = NULL;
15607 }
15608
15609
15610 /* Set the return value of the constructor (if present). */ 16572 /* Set the return value of the constructor (if present). */
15611 16573
15612 static void 16574 static void
15613 finish_constructor_body (void) 16575 finish_constructor_body (void)
15614 { 16576 {
15836 richloc->add_fixit_insert_formatted ("return *this;", 16798 richloc->add_fixit_insert_formatted ("return *this;",
15837 richloc->get_loc (), 16799 richloc->get_loc (),
15838 indent); 16800 indent);
15839 } 16801 }
15840 16802
16803 /* This function carries out the subset of finish_function operations needed
16804 to emit the compiler-generated outlined helper functions used by the
16805 coroutines implementation. */
16806
16807 static void
16808 emit_coro_helper (tree helper)
16809 {
16810 /* This is a partial set of the operations done by finish_function()
16811 plus emitting the result. */
16812 set_cfun (NULL);
16813 current_function_decl = helper;
16814 begin_scope (sk_function_parms, NULL);
16815 store_parm_decls (DECL_ARGUMENTS (helper));
16816 announce_function (helper);
16817 allocate_struct_function (helper, false);
16818 cfun->language = ggc_cleared_alloc<language_function> ();
16819 poplevel (1, 0, 1);
16820 maybe_save_function_definition (helper);
16821 /* We must start each function with a clear fold cache. */
16822 clear_fold_cache ();
16823 cp_fold_function (helper);
16824 DECL_CONTEXT (DECL_RESULT (helper)) = helper;
16825 BLOCK_SUPERCONTEXT (DECL_INITIAL (helper)) = helper;
16826 /* This function has coroutine IFNs that we should handle in middle
16827 end lowering. */
16828 cfun->coroutine_component = true;
16829 cp_genericize (helper);
16830 expand_or_defer_fn (helper);
16831 }
16832
15841 /* Finish up a function declaration and compile that function 16833 /* Finish up a function declaration and compile that function
15842 all the way to assembler language output. The free the storage 16834 all the way to assembler language output. The free the storage
15843 for the function definition. INLINE_P is TRUE if we just 16835 for the function definition. INLINE_P is TRUE if we just
15844 finished processing the body of an in-class inline function 16836 finished processing the body of an in-class inline function
15845 definition. (This processing will have taken place after the 16837 definition. (This processing will have taken place after the
15848 tree 16840 tree
15849 finish_function (bool inline_p) 16841 finish_function (bool inline_p)
15850 { 16842 {
15851 tree fndecl = current_function_decl; 16843 tree fndecl = current_function_decl;
15852 tree fntype, ctype = NULL_TREE; 16844 tree fntype, ctype = NULL_TREE;
16845 tree resumer = NULL_TREE, destroyer = NULL_TREE;
16846 bool coro_p = flag_coroutines
16847 && !processing_template_decl
16848 && DECL_COROUTINE_P (fndecl);
15853 16849
15854 /* When we get some parse errors, we can end up without a 16850 /* When we get some parse errors, we can end up without a
15855 current_function_decl, so cope. */ 16851 current_function_decl, so cope. */
15856 if (fndecl == NULL_TREE) 16852 if (fndecl == NULL_TREE)
15857 return error_mark_node; 16853 return error_mark_node;
15858 16854
15859 finish_lambda_scope (); 16855 if (!DECL_OMP_DECLARE_REDUCTION_P (fndecl))
16856 finish_lambda_scope ();
15860 16857
15861 if (c_dialect_objc ()) 16858 if (c_dialect_objc ())
15862 objc_finish_function (); 16859 objc_finish_function ();
15863 16860
15864 record_key_method_defined (fndecl); 16861 record_key_method_defined (fndecl);
15873 /* The current function is being defined, so its DECL_INITIAL should 16870 /* The current function is being defined, so its DECL_INITIAL should
15874 be set, and unless there's a multiple definition, it should be 16871 be set, and unless there's a multiple definition, it should be
15875 error_mark_node. */ 16872 error_mark_node. */
15876 gcc_assert (DECL_INITIAL (fndecl) == error_mark_node); 16873 gcc_assert (DECL_INITIAL (fndecl) == error_mark_node);
15877 16874
16875 if (coro_p)
16876 {
16877 if (!morph_fn_to_coro (fndecl, &resumer, &destroyer))
16878 {
16879 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl));
16880 poplevel (1, 0, 1);
16881 DECL_SAVED_TREE (fndecl) = error_mark_node;
16882 return fndecl;
16883 }
16884
16885 /* We should handle coroutine IFNs in middle end lowering. */
16886 cfun->coroutine_component = true;
16887
16888 if (use_eh_spec_block (fndecl))
16889 finish_eh_spec_block (TYPE_RAISES_EXCEPTIONS
16890 (TREE_TYPE (fndecl)),
16891 current_eh_spec_block);
16892 }
16893 else
15878 /* For a cloned function, we've already got all the code we need; 16894 /* For a cloned function, we've already got all the code we need;
15879 there's no need to add any extra bits. */ 16895 there's no need to add any extra bits. */
15880 if (!DECL_CLONED_FUNCTION_P (fndecl)) 16896 if (!DECL_CLONED_FUNCTION_P (fndecl))
15881 { 16897 {
15882 /* Make it so that `main' always returns 0 by default. */ 16898 /* Make it so that `main' always returns 0 by default. */
15933 16949
15934 /* If there are no return statements in a function with auto return type, 16950 /* If there are no return statements in a function with auto return type,
15935 the return type is void. But if the declared type is something like 16951 the return type is void. But if the declared type is something like
15936 auto*, this is an error. */ 16952 auto*, this is an error. */
15937 if (!processing_template_decl && FNDECL_USED_AUTO (fndecl) 16953 if (!processing_template_decl && FNDECL_USED_AUTO (fndecl)
15938 && TREE_TYPE (fntype) == current_function_auto_return_pattern) 16954 && TREE_TYPE (fntype) == DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
15939 { 16955 {
15940 if (is_auto (current_function_auto_return_pattern)) 16956 if (is_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl))
15941 { 16957 && !current_function_returns_value
16958 && !current_function_returns_null)
16959 {
16960 /* We haven't applied return type deduction because we haven't
16961 seen any return statements. Do that now. */
16962 tree node = type_uses_auto (DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
16963 do_auto_deduction (DECL_SAVED_AUTO_RETURN_TYPE (fndecl),
16964 void_node, node, tf_warning_or_error,
16965 adc_return_type);
16966
15942 apply_deduced_return_type (fndecl, void_type_node); 16967 apply_deduced_return_type (fndecl, void_type_node);
15943 fntype = TREE_TYPE (fndecl); 16968 fntype = TREE_TYPE (fndecl);
15944 } 16969 }
15945 else if (!current_function_returns_value 16970 else if (!current_function_returns_value
15946 && !current_function_returns_null) 16971 && !current_function_returns_null)
15947 { 16972 {
15948 error ("no return statements in function returning %qT", 16973 error ("no return statements in function returning %qT",
15949 current_function_auto_return_pattern); 16974 DECL_SAVED_AUTO_RETURN_TYPE (fndecl));
15950 inform (input_location, "only plain %<auto%> return type can be " 16975 inform (input_location, "only plain %<auto%> return type can be "
15951 "deduced to %<void%>"); 16976 "deduced to %<void%>");
15952 } 16977 }
16978 }
16979
16980 /* Remember that we were in class scope. */
16981 if (current_class_name)
16982 ctype = current_class_type;
16983
16984 if (DECL_DELETED_FN (fndecl))
16985 {
16986 DECL_INITIAL (fndecl) = error_mark_node;
16987 DECL_SAVED_TREE (fndecl) = NULL_TREE;
16988 goto cleanup;
15953 } 16989 }
15954 16990
15955 // If this is a concept, check that the definition is reasonable. 16991 // If this is a concept, check that the definition is reasonable.
15956 if (DECL_DECLARED_CONCEPT_P (fndecl)) 16992 if (DECL_DECLARED_CONCEPT_P (fndecl))
15957 check_function_concept (fndecl); 16993 check_function_concept (fndecl);
16994
16995 if (flag_openmp)
16996 if (tree attr = lookup_attribute ("omp declare variant base",
16997 DECL_ATTRIBUTES (fndecl)))
16998 omp_declare_variant_finalize (fndecl, attr);
15958 16999
15959 /* Lambda closure members are implicitly constexpr if possible. */ 17000 /* Lambda closure members are implicitly constexpr if possible. */
15960 if (cxx_dialect >= cxx17 17001 if (cxx_dialect >= cxx17
15961 && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl))) 17002 && LAMBDA_TYPE_P (CP_DECL_CONTEXT (fndecl)))
15962 DECL_DECLARED_CONSTEXPR_P (fndecl) 17003 DECL_DECLARED_CONSTEXPR_P (fndecl)
15971 /* Invoke the pre-genericize plugin before we start munging things. */ 17012 /* Invoke the pre-genericize plugin before we start munging things. */
15972 if (!processing_template_decl) 17013 if (!processing_template_decl)
15973 invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl); 17014 invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl);
15974 17015
15975 /* Perform delayed folding before NRV transformation. */ 17016 /* Perform delayed folding before NRV transformation. */
15976 if (!processing_template_decl) 17017 if (!processing_template_decl
17018 && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
17019 && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
15977 cp_fold_function (fndecl); 17020 cp_fold_function (fndecl);
15978 17021
15979 /* Set up the named return value optimization, if we can. Candidate 17022 /* Set up the named return value optimization, if we can. Candidate
15980 variables are selected in check_return_expr. */ 17023 variables are selected in check_return_expr. */
15981 if (current_function_return_value) 17024 if (current_function_return_value)
15996 finalize_nrv (&DECL_SAVED_TREE (fndecl), r, DECL_RESULT (fndecl)); 17039 finalize_nrv (&DECL_SAVED_TREE (fndecl), r, DECL_RESULT (fndecl));
15997 17040
15998 current_function_return_value = NULL_TREE; 17041 current_function_return_value = NULL_TREE;
15999 } 17042 }
16000 17043
16001 /* Remember that we were in class scope. */
16002 if (current_class_name)
16003 ctype = current_class_type;
16004
16005 /* Must mark the RESULT_DECL as being in this function. */ 17044 /* Must mark the RESULT_DECL as being in this function. */
16006 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl; 17045 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
16007 17046
16008 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point 17047 /* Set the BLOCK_SUPERCONTEXT of the outermost function scope to point
16009 to the FUNCTION_DECL node itself. */ 17048 to the FUNCTION_DECL node itself. */
16010 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; 17049 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
16011
16012 /* Save away current state, if appropriate. */
16013 if (!processing_template_decl)
16014 save_function_data (fndecl);
16015 17050
16016 /* Complain if there's just no return statement. */ 17051 /* Complain if there's just no return statement. */
16017 if (warn_return_type 17052 if (warn_return_type
16018 && !VOID_TYPE_P (TREE_TYPE (fntype)) 17053 && !VOID_TYPE_P (TREE_TYPE (fntype))
16019 && !dependent_type_p (TREE_TYPE (fntype)) 17054 && !dependent_type_p (TREE_TYPE (fntype))
16036 assignment operators. */ 17071 assignment operators. */
16037 if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl))) 17072 if (IDENTIFIER_ASSIGN_OP_P (DECL_NAME (fndecl)))
16038 { 17073 {
16039 tree valtype = TREE_TYPE (DECL_RESULT (fndecl)); 17074 tree valtype = TREE_TYPE (DECL_RESULT (fndecl));
16040 if (TREE_CODE (valtype) == REFERENCE_TYPE 17075 if (TREE_CODE (valtype) == REFERENCE_TYPE
17076 && current_class_ref
16041 && same_type_ignoring_top_level_qualifiers_p 17077 && same_type_ignoring_top_level_qualifiers_p
16042 (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))) 17078 (TREE_TYPE (valtype), TREE_TYPE (current_class_ref))
16043 if (global_dc->option_enabled (OPT_Wreturn_type, 17079 && global_dc->option_enabled (OPT_Wreturn_type,
16044 global_dc->option_state)) 17080 global_dc->lang_mask,
16045 add_return_star_this_fixit (&richloc, fndecl); 17081 global_dc->option_state))
16046 } 17082 add_return_star_this_fixit (&richloc, fndecl);
16047 warning_at (&richloc, OPT_Wreturn_type, 17083 }
16048 "no return statement in function returning non-void"); 17084 if (warning_at (&richloc, OPT_Wreturn_type,
16049 TREE_NO_WARNING (fndecl) = 1; 17085 "no return statement in function returning non-void"))
17086 TREE_NO_WARNING (fndecl) = 1;
16050 } 17087 }
16051 17088
16052 /* Store the end of the function, so that we get good line number 17089 /* Store the end of the function, so that we get good line number
16053 info for the epilogue. */ 17090 info for the epilogue. */
16054 cfun->function_end_locus = input_location; 17091 cfun->function_end_locus = input_location;
16090 && !processing_template_decl 17127 && !processing_template_decl
16091 && !DECL_CLONED_FUNCTION_P (fndecl)) 17128 && !DECL_CLONED_FUNCTION_P (fndecl))
16092 do_warn_unused_parameter (fndecl); 17129 do_warn_unused_parameter (fndecl);
16093 17130
16094 /* Genericize before inlining. */ 17131 /* Genericize before inlining. */
16095 if (!processing_template_decl) 17132 if (!processing_template_decl
16096 { 17133 && !DECL_IMMEDIATE_FUNCTION_P (fndecl)
16097 struct language_function *f = DECL_SAVED_FUNCTION_DATA (fndecl); 17134 && !DECL_OMP_DECLARE_REDUCTION_P (fndecl))
16098 cp_genericize (fndecl); 17135 cp_genericize (fndecl);
16099 /* Clear out the bits we don't need. */ 17136
16100 f->x_current_class_ptr = NULL; 17137 /* Emit the resumer and destroyer functions now. */
16101 f->x_current_class_ref = NULL; 17138 if (coro_p)
16102 f->x_eh_spec_block = NULL; 17139 {
16103 f->x_in_charge_parm = NULL; 17140 emit_coro_helper (resumer);
16104 f->x_vtt_parm = NULL; 17141 emit_coro_helper (destroyer);
16105 f->x_return_value = NULL; 17142 }
16106 f->bindings = NULL; 17143
16107 f->extern_decl_map = NULL; 17144 cleanup:
16108 f->infinite_loops = NULL;
16109 }
16110 /* Clear out the bits we don't need. */
16111 local_names = NULL;
16112
16113 /* We're leaving the context of this function, so zap cfun. It's still in 17145 /* We're leaving the context of this function, so zap cfun. It's still in
16114 DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation. */ 17146 DECL_STRUCT_FUNCTION, and we'll restore it in tree_rest_of_compilation. */
16115 set_cfun (NULL); 17147 set_cfun (NULL);
16116 current_function_decl = NULL; 17148 current_function_decl = NULL;
16117 17149
16163 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0, 17195 tree fndecl = grokdeclarator (declarator, declspecs, MEMFUNCDEF, 0,
16164 &attrlist); 17196 &attrlist);
16165 17197
16166 if (fndecl == error_mark_node) 17198 if (fndecl == error_mark_node)
16167 return error_mark_node; 17199 return error_mark_node;
16168
16169 if (fndecl == NULL || TREE_CODE (fndecl) != FUNCTION_DECL)
16170 {
16171 error ("invalid member function declaration");
16172 return error_mark_node;
16173 }
16174 17200
16175 if (attrlist) 17201 if (attrlist)
16176 cplus_decl_attributes (&fndecl, attrlist, 0); 17202 cplus_decl_attributes (&fndecl, attrlist, 0);
16177 17203
16178 /* Pass friends other than inline friend functions back. */ 17204 /* Pass friends other than inline friend functions back. */
16358 if (TREE_CODE (type) == ARRAY_TYPE) 17384 if (TREE_CODE (type) == ARRAY_TYPE)
16359 addr = decl; 17385 addr = decl;
16360 else 17386 else
16361 addr = build_address (decl); 17387 addr = build_address (decl);
16362 17388
16363 call = build_delete (TREE_TYPE (addr), addr, 17389 call = build_delete (input_location, TREE_TYPE (addr), addr,
16364 sfk_complete_destructor, flags, 0, complain); 17390 sfk_complete_destructor, flags, 0, complain);
16365 if (call == error_mark_node) 17391 if (call == error_mark_node)
16366 cleanup = error_mark_node; 17392 cleanup = error_mark_node;
16367 else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type)) 17393 else if (TYPE_HAS_TRIVIAL_DESTRUCTOR (type))
16368 /* Discard the call. */; 17394 /* Discard the call. */;
17395 else if (decl_maybe_constant_destruction (decl, type)
17396 && DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
17397 cxx_constant_dtor (call, decl);
16369 else if (cleanup) 17398 else if (cleanup)
16370 cleanup = cp_build_compound_expr (cleanup, call, complain); 17399 cleanup = cp_build_compound_expr (cleanup, call, complain);
16371 else 17400 else
16372 cleanup = call; 17401 cleanup = call;
16373 } 17402 }
16377 called later, at the end of the current scope. This can lead to 17406 called later, at the end of the current scope. This can lead to
16378 a "jumpy" behavior for users of debuggers when they step around 17407 a "jumpy" behavior for users of debuggers when they step around
16379 the end of the block. So let's unset the location of the 17408 the end of the block. So let's unset the location of the
16380 destructor call instead. */ 17409 destructor call instead. */
16381 protected_set_expr_location (cleanup, UNKNOWN_LOCATION); 17410 protected_set_expr_location (cleanup, UNKNOWN_LOCATION);
17411 if (cleanup && CONVERT_EXPR_P (cleanup))
17412 protected_set_expr_location (TREE_OPERAND (cleanup, 0), UNKNOWN_LOCATION);
16382 17413
16383 if (cleanup 17414 if (cleanup
16384 && DECL_P (decl) 17415 && DECL_P (decl)
16385 && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl))) 17416 && !lookup_attribute ("warn_unused", TYPE_ATTRIBUTES (TREE_TYPE (decl)))
16386 /* Treat objects with destructors as used; the destructor may do 17417 /* Treat objects with destructors as used; the destructor may do
16387 something substantive. */ 17418 something substantive. */
16388 && !mark_used (decl, complain) && !(complain & tf_error)) 17419 && !mark_used (decl, complain) && !(complain & tf_error))
16389 return error_mark_node; 17420 return error_mark_node;
17421
17422 if (cleanup && cfun && !processing_template_decl
17423 && !expr_noexcept_p (cleanup, tf_none))
17424 cp_function_chain->throwing_cleanup = true;
16390 17425
16391 return cleanup; 17426 return cleanup;
16392 } 17427 }
16393 17428
16394 17429
16445 enum cp_tree_node_structure_enum 17480 enum cp_tree_node_structure_enum
16446 cp_tree_node_structure (union lang_tree_node * t) 17481 cp_tree_node_structure (union lang_tree_node * t)
16447 { 17482 {
16448 switch (TREE_CODE (&t->generic)) 17483 switch (TREE_CODE (&t->generic))
16449 { 17484 {
16450 case DEFAULT_ARG: return TS_CP_DEFAULT_ARG; 17485 case ARGUMENT_PACK_SELECT: return TS_CP_ARGUMENT_PACK_SELECT;
17486 case BASELINK: return TS_CP_BASELINK;
17487 case CONSTRAINT_INFO: return TS_CP_CONSTRAINT_INFO;
16451 case DEFERRED_NOEXCEPT: return TS_CP_DEFERRED_NOEXCEPT; 17488 case DEFERRED_NOEXCEPT: return TS_CP_DEFERRED_NOEXCEPT;
17489 case DEFERRED_PARSE: return TS_CP_DEFERRED_PARSE;
16452 case IDENTIFIER_NODE: return TS_CP_IDENTIFIER; 17490 case IDENTIFIER_NODE: return TS_CP_IDENTIFIER;
17491 case LAMBDA_EXPR: return TS_CP_LAMBDA_EXPR;
16453 case OVERLOAD: return TS_CP_OVERLOAD; 17492 case OVERLOAD: return TS_CP_OVERLOAD;
17493 case PTRMEM_CST: return TS_CP_PTRMEM;
17494 case STATIC_ASSERT: return TS_CP_STATIC_ASSERT;
17495 case TEMPLATE_DECL: return TS_CP_TEMPLATE_DECL;
17496 case TEMPLATE_INFO: return TS_CP_TEMPLATE_INFO;
16454 case TEMPLATE_PARM_INDEX: return TS_CP_TPI; 17497 case TEMPLATE_PARM_INDEX: return TS_CP_TPI;
16455 case PTRMEM_CST: return TS_CP_PTRMEM;
16456 case BASELINK: return TS_CP_BASELINK;
16457 case TEMPLATE_DECL: return TS_CP_TEMPLATE_DECL;
16458 case STATIC_ASSERT: return TS_CP_STATIC_ASSERT;
16459 case ARGUMENT_PACK_SELECT: return TS_CP_ARGUMENT_PACK_SELECT;
16460 case TRAIT_EXPR: return TS_CP_TRAIT_EXPR; 17498 case TRAIT_EXPR: return TS_CP_TRAIT_EXPR;
16461 case LAMBDA_EXPR: return TS_CP_LAMBDA_EXPR;
16462 case TEMPLATE_INFO: return TS_CP_TEMPLATE_INFO;
16463 case CONSTRAINT_INFO: return TS_CP_CONSTRAINT_INFO;
16464 case USERDEF_LITERAL: return TS_CP_USERDEF_LITERAL; 17499 case USERDEF_LITERAL: return TS_CP_USERDEF_LITERAL;
16465 default: return TS_CP_GENERIC; 17500 default: return TS_CP_GENERIC;
16466 } 17501 }
16467 } 17502 }
16468 17503
16520 tree 17555 tree
16521 fndecl_declared_return_type (tree fn) 17556 fndecl_declared_return_type (tree fn)
16522 { 17557 {
16523 fn = STRIP_TEMPLATE (fn); 17558 fn = STRIP_TEMPLATE (fn);
16524 if (FNDECL_USED_AUTO (fn)) 17559 if (FNDECL_USED_AUTO (fn))
16525 { 17560 return DECL_SAVED_AUTO_RETURN_TYPE (fn);
16526 struct language_function *f = NULL; 17561
16527 if (DECL_STRUCT_FUNCTION (fn))
16528 f = DECL_STRUCT_FUNCTION (fn)->language;
16529 if (f == NULL)
16530 f = DECL_SAVED_FUNCTION_DATA (fn);
16531 return f->x_auto_return_pattern;
16532 }
16533 return TREE_TYPE (TREE_TYPE (fn)); 17562 return TREE_TYPE (TREE_TYPE (fn));
16534 } 17563 }
16535 17564
16536 /* Returns true iff DECL is a variable or function declared with an auto type 17565 /* Returns true iff DECL is a variable or function declared with an auto type
16537 that has not yet been deduced to a real type. */ 17566 that has not yet been deduced to a real type. */
16539 bool 17568 bool
16540 undeduced_auto_decl (tree decl) 17569 undeduced_auto_decl (tree decl)
16541 { 17570 {
16542 if (cxx_dialect < cxx11) 17571 if (cxx_dialect < cxx11)
16543 return false; 17572 return false;
17573 STRIP_ANY_LOCATION_WRAPPER (decl);
16544 return ((VAR_OR_FUNCTION_DECL_P (decl) 17574 return ((VAR_OR_FUNCTION_DECL_P (decl)
16545 || TREE_CODE (decl) == TEMPLATE_DECL) 17575 || TREE_CODE (decl) == TEMPLATE_DECL)
16546 && type_uses_auto (TREE_TYPE (decl))); 17576 && type_uses_auto (TREE_TYPE (decl)));
16547 } 17577 }
16548 17578
16551 bool 17581 bool
16552 require_deduced_type (tree decl, tsubst_flags_t complain) 17582 require_deduced_type (tree decl, tsubst_flags_t complain)
16553 { 17583 {
16554 if (undeduced_auto_decl (decl)) 17584 if (undeduced_auto_decl (decl))
16555 { 17585 {
16556 if (complain & tf_error) 17586 if (TREE_NO_WARNING (decl) && seen_error ())
17587 /* We probably already complained about deduction failure. */;
17588 else if (complain & tf_error)
16557 error ("use of %qD before deduction of %<auto%>", decl); 17589 error ("use of %qD before deduction of %<auto%>", decl);
16558 return false; 17590 return false;
16559 } 17591 }
16560 return true; 17592 return true;
16561 } 17593 }
16562 17594
17595 /* Create a representation of the explicit-specifier with
17596 constant-expression of EXPR. COMPLAIN is as for tsubst. */
17597
17598 tree
17599 build_explicit_specifier (tree expr, tsubst_flags_t complain)
17600 {
17601 if (instantiation_dependent_expression_p (expr))
17602 /* Wait for instantiation, tsubst_function_decl will handle it. */
17603 return expr;
17604
17605 expr = instantiate_non_dependent_expr_sfinae (expr, complain);
17606 /* Don't let convert_like_real create more template codes. */
17607 processing_template_decl_sentinel s;
17608 expr = build_converted_constant_bool_expr (expr, complain);
17609 expr = cxx_constant_value (expr);
17610 return expr;
17611 }
17612
16563 #include "gt-cp-decl.h" 17613 #include "gt-cp-decl.h"