Commit d503104
committed
c++: Implement C++20 'using enum'. [PR91367]
This feature allows the programmer to import enumerator names into the
current scope so later mentions don't need to use the fully-qualified name.
These usings are not subject to the usual restrictions on using-decls: in
particular, they can move between class and non-class scopes, and between
classes that are not related by inheritance. This last caused difficulty
for our normal approach to using-decls within a class hierarchy, as we
assume that the class where we looked up a used declaration is derived from
the class where it was first declared. So to simplify things, in that case
we make a clone of the CONST_DECL in the using class.
Thanks to Nathan for the start of this work: in particular, the
lookup_using_decl rewrite.
The changes to dwarf2out revealed an existing issue with the D front-end: we
were doing the wrong thing for importing a D CONST_DECL, because
dwarf2out_imported_module_or_decl_1 was looking through it to its type,
expecting it to be an enumerator, but in one case in thread.d, the constant
had type int. Adding the ability to import a C++ enumerator also fixed
that, but that led to a crash in force_decl_die, which didn't know what to
do with a CONST_DECL. So now it does.
Co-authored-by: Nathan Sidwell <nathan@acm.org>
gcc/cp/ChangeLog:
* cp-tree.h (USING_DECL_UNRELATED_P): New.
(CONST_DECL_USING_P): New.
* class.c (handle_using_decl): If USING_DECL_UNRELATED_P,
clone the CONST_DECL.
* name-lookup.c (supplement_binding_1): A clone hides its
using-declaration.
(lookup_using_decl): Rewrite to separate lookup and validation.
(do_class_using_decl): Adjust.
(finish_nonmember_using_decl): Adjust.
* parser.c (make_location): Add cp_token overload.
(finish_using_decl): Split out from...
(cp_parser_using_declaration): ...here. Don't look through enums.
(cp_parser_using_enum): New.
(cp_parser_block_declaration): Call it.
(cp_parser_member_declaration): Call it.
* semantics.c (finish_id_expression_1): Handle enumerator
used from class scope.
gcc/ChangeLog:
* dwarf2out.c (gen_enumeration_type_die): Call
equate_decl_number_to_die for enumerators.
(gen_member_die): Don't move enumerators to their
enclosing class.
(dwarf2out_imported_module_or_decl_1): Allow importing
individual enumerators.
(force_decl_die): Handle CONST_DECL.
gcc/testsuite/ChangeLog:
* g++.dg/cpp0x/inh-ctor28.C: Adjust expected diagnostic.
* g++.dg/cpp0x/inh-ctor33.C: Likewise.
* g++.dg/cpp0x/using-enum-1.C: Add comment.
* g++.dg/cpp0x/using-enum-2.C: Allowed in C++20.
* g++.dg/cpp0x/using-enum-3.C: Likewise.
* g++.dg/cpp1z/class-deduction69.C: Adjust diagnostic.
* g++.dg/inherit/using5.C: Likewise.
* g++.dg/cpp2a/using-enum-1.C: New test.
* g++.dg/cpp2a/using-enum-2.C: New test.
* g++.dg/cpp2a/using-enum-3.C: New test.
* g++.dg/cpp2a/using-enum-4.C: New test.
* g++.dg/cpp2a/using-enum-5.C: New test.
* g++.dg/cpp2a/using-enum-6.C: New test.
* g++.dg/debug/dwarf2/using-enum.C: New test.1 parent e3b3b59 commit d503104
File tree
20 files changed
+648
-135
lines changed- gcc
- cp
- testsuite/g++.dg
- cpp0x
- cpp1z
- cpp2a
- debug/dwarf2
- inherit
20 files changed
+648
-135
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1331 | 1331 | | |
1332 | 1332 | | |
1333 | 1333 | | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
1334 | 1351 | | |
1335 | 1352 | | |
1336 | 1353 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
529 | 529 | | |
530 | 530 | | |
531 | 531 | | |
| 532 | + | |
532 | 533 | | |
533 | 534 | | |
534 | 535 | | |
| |||
3409 | 3410 | | |
3410 | 3411 | | |
3411 | 3412 | | |
| 3413 | + | |
| 3414 | + | |
| 3415 | + | |
| 3416 | + | |
| 3417 | + | |
| 3418 | + | |
| 3419 | + | |
| 3420 | + | |
| 3421 | + | |
| 3422 | + | |
3412 | 3423 | | |
3413 | 3424 | | |
3414 | 3425 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2125 | 2125 | | |
2126 | 2126 | | |
2127 | 2127 | | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
2128 | 2132 | | |
2129 | 2133 | | |
2130 | 2134 | | |
| |||
4540 | 4544 | | |
4541 | 4545 | | |
4542 | 4546 | | |
4543 | | - | |
| 4547 | + | |
4544 | 4548 | | |
4545 | 4549 | | |
4546 | 4550 | | |
4547 | 4551 | | |
| 4552 | + | |
| 4553 | + | |
| 4554 | + | |
| 4555 | + | |
| 4556 | + | |
| 4557 | + | |
| 4558 | + | |
| 4559 | + | |
| 4560 | + | |
| 4561 | + | |
| 4562 | + | |
| 4563 | + | |
| 4564 | + | |
| 4565 | + | |
| 4566 | + | |
| 4567 | + | |
| 4568 | + | |
| 4569 | + | |
| 4570 | + | |
| 4571 | + | |
4548 | 4572 | | |
4549 | 4573 | | |
4550 | 4574 | | |
4551 | 4575 | | |
4552 | | - | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
| 4581 | + | |
| 4582 | + | |
4553 | 4583 | | |
4554 | 4584 | | |
4555 | | - | |
| 4585 | + | |
4556 | 4586 | | |
4557 | | - | |
4558 | | - | |
4559 | 4587 | | |
4560 | 4588 | | |
4561 | 4589 | | |
4562 | | - | |
4563 | | - | |
4564 | | - | |
| 4590 | + | |
| 4591 | + | |
| 4592 | + | |
| 4593 | + | |
| 4594 | + | |
| 4595 | + | |
4565 | 4596 | | |
4566 | 4597 | | |
4567 | 4598 | | |
4568 | | - | |
4569 | | - | |
4570 | | - | |
4571 | | - | |
4572 | | - | |
4573 | | - | |
| 4599 | + | |
| 4600 | + | |
4574 | 4601 | | |
4575 | | - | |
| 4602 | + | |
4576 | 4603 | | |
4577 | 4604 | | |
4578 | 4605 | | |
4579 | | - | |
| 4606 | + | |
4580 | 4607 | | |
4581 | 4608 | | |
4582 | 4609 | | |
4583 | 4610 | | |
4584 | 4611 | | |
4585 | 4612 | | |
4586 | 4613 | | |
| 4614 | + | |
| 4615 | + | |
| 4616 | + | |
| 4617 | + | |
| 4618 | + | |
4587 | 4619 | | |
4588 | 4620 | | |
4589 | 4621 | | |
4590 | 4622 | | |
4591 | 4623 | | |
4592 | | - | |
4593 | | - | |
| 4624 | + | |
| 4625 | + | |
| 4626 | + | |
4594 | 4627 | | |
4595 | | - | |
4596 | | - | |
4597 | | - | |
4598 | | - | |
4599 | | - | |
4600 | | - | |
4601 | | - | |
4602 | | - | |
4603 | | - | |
4604 | | - | |
4605 | | - | |
| 4628 | + | |
| 4629 | + | |
| 4630 | + | |
| 4631 | + | |
| 4632 | + | |
4606 | 4633 | | |
4607 | | - | |
4608 | | - | |
4609 | | - | |
4610 | | - | |
| 4634 | + | |
| 4635 | + | |
| 4636 | + | |
| 4637 | + | |
| 4638 | + | |
| 4639 | + | |
| 4640 | + | |
| 4641 | + | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
| 4652 | + | |
4611 | 4653 | | |
4612 | | - | |
4613 | 4654 | | |
4614 | 4655 | | |
4615 | | - | |
4616 | | - | |
4617 | | - | |
4618 | | - | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
4619 | 4663 | | |
4620 | | - | |
4621 | | - | |
4622 | | - | |
4623 | | - | |
| 4664 | + | |
| 4665 | + | |
4624 | 4666 | | |
4625 | | - | |
4626 | | - | |
| 4667 | + | |
| 4668 | + | |
| 4669 | + | |
| 4670 | + | |
| 4671 | + | |
| 4672 | + | |
| 4673 | + | |
| 4674 | + | |
4627 | 4675 | | |
4628 | | - | |
4629 | | - | |
| 4676 | + | |
| 4677 | + | |
4630 | 4678 | | |
4631 | | - | |
| 4679 | + | |
| 4680 | + | |
4632 | 4681 | | |
4633 | | - | |
4634 | | - | |
4635 | | - | |
| 4682 | + | |
| 4683 | + | |
| 4684 | + | |
| 4685 | + | |
| 4686 | + | |
| 4687 | + | |
| 4688 | + | |
| 4689 | + | |
| 4690 | + | |
| 4691 | + | |
| 4692 | + | |
| 4693 | + | |
| 4694 | + | |
| 4695 | + | |
| 4696 | + | |
| 4697 | + | |
| 4698 | + | |
| 4699 | + | |
| 4700 | + | |
| 4701 | + | |
| 4702 | + | |
| 4703 | + | |
| 4704 | + | |
| 4705 | + | |
4636 | 4706 | | |
4637 | | - | |
4638 | | - | |
4639 | | - | |
4640 | | - | |
4641 | | - | |
4642 | | - | |
4643 | 4707 | | |
4644 | 4708 | | |
4645 | 4709 | | |
4646 | | - | |
| 4710 | + | |
| 4711 | + | |
| 4712 | + | |
| 4713 | + | |
4647 | 4714 | | |
4648 | | - | |
4649 | | - | |
4650 | | - | |
4651 | | - | |
4652 | | - | |
| 4715 | + | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
| 4719 | + | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
| 4723 | + | |
| 4724 | + | |
| 4725 | + | |
| 4726 | + | |
| 4727 | + | |
| 4728 | + | |
| 4729 | + | |
| 4730 | + | |
| 4731 | + | |
4653 | 4732 | | |
4654 | | - | |
4655 | | - | |
4656 | | - | |
4657 | | - | |
4658 | | - | |
4659 | | - | |
4660 | | - | |
4661 | | - | |
4662 | | - | |
| 4733 | + | |
| 4734 | + | |
| 4735 | + | |
4663 | 4736 | | |
4664 | | - | |
| 4737 | + | |
| 4738 | + | |
4665 | 4739 | | |
4666 | | - | |
4667 | | - | |
| 4740 | + | |
| 4741 | + | |
| 4742 | + | |
4668 | 4743 | | |
| 4744 | + | |
| 4745 | + | |
| 4746 | + | |
| 4747 | + | |
4669 | 4748 | | |
4670 | 4749 | | |
4671 | | - | |
| 4750 | + | |
| 4751 | + | |
| 4752 | + | |
| 4753 | + | |
| 4754 | + | |
| 4755 | + | |
| 4756 | + | |
| 4757 | + | |
4672 | 4758 | | |
4673 | 4759 | | |
4674 | 4760 | | |
| |||
4682 | 4768 | | |
4683 | 4769 | | |
4684 | 4770 | | |
4685 | | - | |
4686 | | - | |
4687 | | - | |
4688 | | - | |
4689 | | - | |
4690 | | - | |
4691 | | - | |
4692 | | - | |
4693 | | - | |
4694 | | - | |
4695 | | - | |
4696 | | - | |
4697 | | - | |
4698 | | - | |
| 4771 | + | |
4699 | 4772 | | |
4700 | 4773 | | |
4701 | 4774 | | |
| |||
5076 | 5149 | | |
5077 | 5150 | | |
5078 | 5151 | | |
5079 | | - | |
| 5152 | + | |
| 5153 | + | |
5080 | 5154 | | |
5081 | 5155 | | |
5082 | 5156 | | |
| |||
5105 | 5179 | | |
5106 | 5180 | | |
5107 | 5181 | | |
5108 | | - | |
5109 | | - | |
5110 | 5182 | | |
5111 | 5183 | | |
5112 | 5184 | | |
| |||
0 commit comments