Skip to content

Commit f83ca9b

Browse files
committed
Require that a member object before a 'this' base object must be private, closes #336
1 parent a9f64ba commit f83ca9b

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

source/cppfront.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4928,7 +4928,8 @@ class cppfront
49284928
decl->get_decl_if_type_scope_object_name_before_a_base_type(*decl->name())
49294929
|| decl->has_name("this")
49304930
;
4931-
if (emit_as_base) {
4931+
if (emit_as_base)
4932+
{
49324933
if (decl->has_name("this")) {
49334934
if (printer.get_phase() == printer.phase1_type_defs_func_decls) {
49344935
printer.print_cpp2(
@@ -4938,7 +4939,20 @@ class cppfront
49384939
separator = ",";
49394940
}
49404941
}
4941-
else {
4942+
else
4943+
{
4944+
if (
4945+
decl->access
4946+
&& *decl->access != "public"
4947+
)
4948+
{
4949+
errors.emplace_back(
4950+
decl->position(),
4951+
"a member object that appears before a 'this' base type object must be private (the default)"
4952+
);
4953+
return;
4954+
}
4955+
49424956
if (printer.get_phase() == printer.phase1_type_defs_func_decls) {
49434957
printer.print_cpp2(
49444958
separator + " private cpp2::store_as_base<\""
@@ -4952,7 +4966,8 @@ class cppfront
49524966
}
49534967
}
49544968
// Then we'll switch to start the body == other members
4955-
else {
4969+
else
4970+
{
49564971
if (printer.get_phase() == printer.phase1_type_defs_func_decls) {
49574972
if (!started_body) {
49584973
printer.print_cpp2(" {", compound_stmt->position());

0 commit comments

Comments
 (0)