Skip to content

Commit

Permalink
Require that a member object before a 'this' base object must be priv…
Browse files Browse the repository at this point in the history
…ate, closes hsutter#336
  • Loading branch information
hsutter authored and zaucy committed Dec 5, 2023
1 parent 0c34c2b commit e2fc400
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4928,7 +4928,8 @@ class cppfront
decl->get_decl_if_type_scope_object_name_before_a_base_type(*decl->name())
|| decl->has_name("this")
;
if (emit_as_base) {
if (emit_as_base)
{
if (decl->has_name("this")) {
if (printer.get_phase() == printer.phase1_type_defs_func_decls) {
printer.print_cpp2(
Expand All @@ -4938,7 +4939,20 @@ class cppfront
separator = ",";
}
}
else {
else
{
if (
decl->access
&& *decl->access != "public"
)
{
errors.emplace_back(
decl->position(),
"a member object that appears before a 'this' base type object must be private (the default)"
);
return;
}

if (printer.get_phase() == printer.phase1_type_defs_func_decls) {
printer.print_cpp2(
separator + " private cpp2::store_as_base<\""
Expand All @@ -4952,7 +4966,8 @@ class cppfront
}
}
// Then we'll switch to start the body == other members
else {
else
{
if (printer.get_phase() == printer.phase1_type_defs_func_decls) {
if (!started_body) {
printer.print_cpp2(" {", compound_stmt->position());
Expand Down

0 comments on commit e2fc400

Please sign in to comment.