Mercurial > hg > CbC > CbC_gcc
comparison gcc/cp/friend.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
1 /* Help friends in C++. | 1 /* Help friends in C++. |
2 Copyright (C) 1997-2017 Free Software Foundation, Inc. | 2 Copyright (C) 1997-2018 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify | 6 GCC is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
170 tree name; | 170 tree name; |
171 tree ctx; | 171 tree ctx; |
172 | 172 |
173 if (decl == error_mark_node) | 173 if (decl == error_mark_node) |
174 return; | 174 return; |
175 | |
176 if (TREE_CODE (decl) == FUNCTION_DECL | |
177 && DECL_TEMPLATE_INSTANTIATION (decl)) | |
178 /* We'll have parsed this as a declaration, and therefore not | |
179 marked the lookup set for keeping. Do that now. */ | |
180 lookup_keep (DECL_TI_TEMPLATE (decl)); | |
175 | 181 |
176 typedecl = TYPE_MAIN_DECL (type); | 182 typedecl = TYPE_MAIN_DECL (type); |
177 list = DECL_FRIENDLIST (typedecl); | 183 list = DECL_FRIENDLIST (typedecl); |
178 name = DECL_NAME (decl); | 184 name = DECL_NAME (decl); |
179 type = TREE_TYPE (typedecl); | 185 type = TREE_TYPE (typedecl); |
281 | 287 |
282 if (check_for_bare_parameter_packs (friend_type)) | 288 if (check_for_bare_parameter_packs (friend_type)) |
283 return; | 289 return; |
284 | 290 |
285 if (friend_depth) | 291 if (friend_depth) |
286 /* If the TYPE is a template then it makes sense for it to be | 292 { |
287 friends with itself; this means that each instantiation is | 293 /* [temp.friend] Friend declarations shall not declare partial |
288 friends with all other instantiations. */ | 294 specializations. */ |
289 { | |
290 if (CLASS_TYPE_P (friend_type) | 295 if (CLASS_TYPE_P (friend_type) |
291 && CLASSTYPE_TEMPLATE_SPECIALIZATION (friend_type) | 296 && CLASSTYPE_TEMPLATE_SPECIALIZATION (friend_type) |
292 && uses_template_parms (friend_type)) | 297 && uses_template_parms (friend_type)) |
293 { | 298 { |
294 /* [temp.friend] | |
295 Friend declarations shall not declare partial | |
296 specializations. */ | |
297 error ("partial specialization %qT declared %<friend%>", | 299 error ("partial specialization %qT declared %<friend%>", |
298 friend_type); | 300 friend_type); |
299 return; | 301 return; |
300 } | 302 } |
303 | |
301 if (TYPE_TEMPLATE_INFO (friend_type) | 304 if (TYPE_TEMPLATE_INFO (friend_type) |
302 && !PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (friend_type))) | 305 && !PRIMARY_TEMPLATE_P (TYPE_TI_TEMPLATE (friend_type))) |
303 { | 306 { |
307 auto_diagnostic_group d; | |
304 error ("%qT is not a template", friend_type); | 308 error ("%qT is not a template", friend_type); |
305 inform (location_of (friend_type), "previous declaration here"); | 309 inform (location_of (friend_type), "previous declaration here"); |
306 if (TYPE_CLASS_SCOPE_P (friend_type) | 310 if (TYPE_CLASS_SCOPE_P (friend_type) |
307 && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (friend_type)) | 311 && CLASSTYPE_TEMPLATE_INFO (TYPE_CONTEXT (friend_type)) |
308 && currently_open_class (TYPE_CONTEXT (friend_type))) | 312 && currently_open_class (TYPE_CONTEXT (friend_type))) |
309 inform (input_location, "perhaps you need explicit template " | 313 inform (input_location, "perhaps you need explicit template " |
310 "arguments in your nested-name-specifier"); | 314 "arguments in your nested-name-specifier"); |
311 return; | 315 return; |
312 } | 316 } |
313 } | 317 } |
314 else if (same_type_p (type, friend_type)) | 318 |
319 /* It makes sense for a template class to be friends with itself, | |
320 that means the instantiations can be friendly. Other cases are | |
321 not so meaningful. */ | |
322 if (!friend_depth && same_type_p (type, friend_type)) | |
315 { | 323 { |
316 if (complain) | 324 if (complain) |
317 warning (0, "class %qT is implicitly friends with itself", | 325 warning (0, "class %qT is implicitly friends with itself", |
318 type); | 326 type); |
319 return; | 327 return; |
375 error ("%qT is not a member of %qT", name, ctype); | 383 error ("%qT is not a member of %qT", name, ctype); |
376 return; | 384 return; |
377 } | 385 } |
378 if (template_member_p && !DECL_CLASS_TEMPLATE_P (decl)) | 386 if (template_member_p && !DECL_CLASS_TEMPLATE_P (decl)) |
379 { | 387 { |
388 auto_diagnostic_group d; | |
380 error ("%qT is not a member class template of %qT", | 389 error ("%qT is not a member class template of %qT", |
381 name, ctype); | 390 name, ctype); |
382 inform (DECL_SOURCE_LOCATION (decl), | 391 inform (DECL_SOURCE_LOCATION (decl), |
383 "%qD declared here", decl); | 392 "%qD declared here", decl); |
384 return; | 393 return; |
385 } | 394 } |
386 if (!template_member_p && (TREE_CODE (decl) != TYPE_DECL | 395 if (!template_member_p && (TREE_CODE (decl) != TYPE_DECL |
387 || !CLASS_TYPE_P (TREE_TYPE (decl)))) | 396 || !CLASS_TYPE_P (TREE_TYPE (decl)))) |
388 { | 397 { |
398 auto_diagnostic_group d; | |
389 error ("%qT is not a nested class of %qT", | 399 error ("%qT is not a nested class of %qT", |
390 name, ctype); | 400 name, ctype); |
391 inform (DECL_SOURCE_LOCATION (decl), | 401 inform (DECL_SOURCE_LOCATION (decl), |
392 "%qD declared here", decl); | 402 "%qD declared here", decl); |
393 return; | 403 return; |
492 cplus_decl_attributes (&decl, attrlist, 0); | 502 cplus_decl_attributes (&decl, attrlist, 0); |
493 | 503 |
494 if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) | 504 if (TREE_CODE (declarator) == TEMPLATE_ID_EXPR) |
495 { | 505 { |
496 declarator = TREE_OPERAND (declarator, 0); | 506 declarator = TREE_OPERAND (declarator, 0); |
497 declarator = OVL_NAME (declarator); | 507 if (!identifier_p (declarator)) |
508 declarator = OVL_NAME (declarator); | |
498 } | 509 } |
499 | 510 |
500 if (ctype) | 511 if (ctype) |
501 { | 512 { |
502 /* CLASS_TEMPLATE_DEPTH counts the number of template headers for | 513 /* CLASS_TEMPLATE_DEPTH counts the number of template headers for |
626 if (warn) | 637 if (warn) |
627 { | 638 { |
628 static int explained; | 639 static int explained; |
629 bool warned; | 640 bool warned; |
630 | 641 |
642 auto_diagnostic_group d; | |
631 warned = warning (OPT_Wnon_template_friend, "friend declaration " | 643 warned = warning (OPT_Wnon_template_friend, "friend declaration " |
632 "%q#D declares a non-template function", decl); | 644 "%q#D declares a non-template function", decl); |
633 if (! explained && warned) | 645 if (! explained && warned) |
634 { | 646 { |
635 inform (input_location, "(if this is not what you intended, make sure " | 647 inform (input_location, "(if this is not what you intended, make sure " |