Skip to content

Commit 472bf58

Browse files
committed
Drop the requirement that polymorphic_base types not have data members
See my Issue 395 comment here: #395 (comment)
1 parent 3b78cf1 commit 472bf58

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed

regression-tests/test-results/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
cppfront compiler v0.2.1 Build 8506:1834
2+
cppfront compiler v0.2.1 Build 8507:0751
33
Copyright(c) Herb Sutter All rights reserved
44

55
SPDX-License-Identifier: CC-BY-NC-ND-4.0

source/reflect.h

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#line 410 "reflect.h2"
1313
namespace cpp2 {
1414

15-
#line 718 "reflect.h2"
15+
#line 713 "reflect.h2"
1616
}
1717

1818

@@ -482,7 +482,7 @@ auto interface(meta::type_declaration& t) -> void;
482482
//
483483
auto polymorphic_base(meta::type_declaration& t) -> void;
484484

485-
#line 520 "reflect.h2"
485+
#line 515 "reflect.h2"
486486
//-----------------------------------------------------------------------
487487
//
488488
// "... A totally ordered type ... requires operator<=> that
@@ -508,27 +508,27 @@ auto ordered_impl(
508508
cpp2::in<std::string_view> ordering// must be "strong_ordering" etc.
509509
) -> void;
510510

511-
#line 565 "reflect.h2"
511+
#line 560 "reflect.h2"
512512
//-----------------------------------------------------------------------
513513
// ordered - a totally ordered type
514514
//
515515
// Note: the ordering that should be encouraged as default gets the nice name
516516
//
517517
auto ordered(meta::type_declaration& t) -> void;
518518

519-
#line 575 "reflect.h2"
519+
#line 570 "reflect.h2"
520520
//-----------------------------------------------------------------------
521521
// weakly_ordered - a weakly ordered type
522522
//
523523
auto weakly_ordered(meta::type_declaration& t) -> void;
524524

525-
#line 583 "reflect.h2"
525+
#line 578 "reflect.h2"
526526
//-----------------------------------------------------------------------
527527
// partially_ordered - a partially ordered type
528528
//
529529
auto partially_ordered(meta::type_declaration& t) -> void;
530530

531-
#line 592 "reflect.h2"
531+
#line 587 "reflect.h2"
532532
//-----------------------------------------------------------------------
533533
//
534534
// "A value is ... a regular type. It must have all public
@@ -548,7 +548,7 @@ auto partially_ordered(meta::type_declaration& t) -> void;
548548
//
549549
auto basic_value(meta::type_declaration& t) -> void;
550550

551-
#line 645 "reflect.h2"
551+
#line 640 "reflect.h2"
552552
//-----------------------------------------------------------------------
553553
//
554554
// "A 'value' is a totally ordered basic_value..."
@@ -560,13 +560,13 @@ auto basic_value(meta::type_declaration& t) -> void;
560560
//
561561
auto value(meta::type_declaration& t) -> void;
562562

563-
#line 660 "reflect.h2"
563+
#line 655 "reflect.h2"
564564
auto weakly_ordered_value(meta::type_declaration& t) -> void;
565565

566-
#line 666 "reflect.h2"
566+
#line 661 "reflect.h2"
567567
auto partially_ordered_value(meta::type_declaration& t) -> void;
568568

569-
#line 673 "reflect.h2"
569+
#line 668 "reflect.h2"
570570
//-----------------------------------------------------------------------
571571
//
572572
// "By definition, a `struct` is a `class` in which members
@@ -594,7 +594,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void;
594594
//
595595
auto cpp2_struct(meta::type_declaration& t) -> void;
596596

597-
#line 716 "reflect.h2"
597+
#line 711 "reflect.h2"
598598
//=======================================================================
599599
// Switch to Cpp1: Close namespace cpp2 and reopen it in Cpp1 code
600600
}
@@ -726,15 +726,9 @@ auto polymorphic_base(meta::type_declaration& t) -> void
726726
if (!(std::move(has_dtor))) {
727727
add_virtual_destructor(t);
728728
}
729-
730-
{ auto const& cpp2_range = CPP2_UFCS_0(get_member_objects, t); for ( auto const& mo : cpp2_range ) {
731-
CPP2_UFCS(require, mo, CPP2_UFCS(has_name, mo, "this"),
732-
"polymorphic base types may not contain data");
733-
}}
734-
#line 517 "reflect.h2"
735729
}
736730

737-
#line 540 "reflect.h2"
731+
#line 535 "reflect.h2"
738732
auto ordered_impl(
739733
meta::type_declaration& t,
740734
cpp2::in<std::string_view> ordering
@@ -754,32 +748,32 @@ auto ordered_impl(
754748
}
755749
}}
756750

757-
#line 559 "reflect.h2"
751+
#line 554 "reflect.h2"
758752
if (!(std::move(has_spaceship))) {
759753
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator<=>: (this, that) -> std::" + (cpp2::as_<std::string>(ordering)) + ";"),
760754
"could not add operator<=> with std::" + (cpp2::as_<std::string>(ordering)));
761755
}
762756
}
763757

764-
#line 570 "reflect.h2"
758+
#line 565 "reflect.h2"
765759
auto ordered(meta::type_declaration& t) -> void
766760
{
767761
ordered_impl(t, "strong_ordering");
768762
}
769763

770-
#line 578 "reflect.h2"
764+
#line 573 "reflect.h2"
771765
auto weakly_ordered(meta::type_declaration& t) -> void
772766
{
773767
ordered_impl(t, "weak_ordering");
774768
}
775769

776-
#line 586 "reflect.h2"
770+
#line 581 "reflect.h2"
777771
auto partially_ordered(meta::type_declaration& t) -> void
778772
{
779773
ordered_impl(t, "partial_ordering");
780774
}
781775

782-
#line 609 "reflect.h2"
776+
#line 604 "reflect.h2"
783777
auto basic_value(meta::type_declaration& t) -> void
784778
{
785779
// If the user explicitly wrote any of the copy/move functions,
@@ -810,14 +804,14 @@ auto basic_value(meta::type_declaration& t) -> void
810804
"a value type may not have a non-public destructor");
811805
}}
812806

813-
#line 639 "reflect.h2"
807+
#line 634 "reflect.h2"
814808
if (!(std::move(has_default_ctor))) {
815809
CPP2_UFCS(require, t, CPP2_UFCS(add_member, t, "operator=: (out this) = { }"),
816810
"could not add default constructor");
817811
}
818812
}
819813

820-
#line 654 "reflect.h2"
814+
#line 649 "reflect.h2"
821815
auto value(meta::type_declaration& t) -> void
822816
{
823817
ordered(t);
@@ -836,7 +830,7 @@ auto partially_ordered_value(meta::type_declaration& t) -> void
836830
basic_value(t);
837831
}
838832

839-
#line 698 "reflect.h2"
833+
#line 693 "reflect.h2"
840834
auto cpp2_struct(meta::type_declaration& t) -> void
841835
{
842836
{ auto&& cpp2_range = CPP2_UFCS_0(get_members, t); for ( auto& m : cpp2_range )
@@ -851,11 +845,11 @@ auto cpp2_struct(meta::type_declaration& t) -> void
851845
"a struct may not have a user-defined operator=");
852846
}
853847
}}
854-
#line 712 "reflect.h2"
848+
#line 707 "reflect.h2"
855849
basic_value(t); // a plain_struct is-a basic_value
856850
}
857851

858-
#line 718 "reflect.h2"
852+
#line 713 "reflect.h2"
859853
}
860854

861855
#endif

source/reflect.h2

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,6 @@ polymorphic_base: (inout t: meta::type_declaration) =
509509
if !has_dtor {
510510
add_virtual_destructor(t);
511511
}
512-
513-
for t.get_member_objects() do (mo) {
514-
mo.require( mo.has_name("this"),
515-
"polymorphic base types may not contain data");
516-
}
517512
}
518513

519514

x64/Debug/cppfront.exe

-13 KB
Binary file not shown.

0 commit comments

Comments
 (0)