diff --git a/src/cpp/cpp_typecheck_bases.cpp b/src/cpp/cpp_typecheck_bases.cpp index ff3c953f0bd..2aebed61ddd 100644 --- a/src/cpp/cpp_typecheck_bases.cpp +++ b/src/cpp/cpp_typecheck_bases.cpp @@ -18,8 +18,7 @@ void cpp_typecheckt::typecheck_compound_bases(struct_typet &type) std::set bases; std::set vbases; - irep_idt default_class_access= - type.get_bool(ID_C_class)?ID_private:ID_public; + irep_idt default_class_access = type.default_access(); irept::subt &bases_irep=type.add(ID_bases).get_sub(); diff --git a/src/cpp/cpp_typecheck_compound_type.cpp b/src/cpp/cpp_typecheck_compound_type.cpp index ce0324892e6..3d81ea5a847 100644 --- a/src/cpp/cpp_typecheck_compound_type.cpp +++ b/src/cpp/cpp_typecheck_compound_type.cpp @@ -977,8 +977,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol) symbol.type.set(ID_name, symbol.name); // default access - irep_idt access= - type.get_bool(ID_C_class)?ID_private:ID_public; + irep_idt access = type.default_access(); bool found_ctor=false; bool found_dtor=false; @@ -1119,8 +1118,7 @@ void cpp_typecheckt::typecheck_compound_body(symbolt &symbol) } // Reset the access type - access= - type.get_bool(ID_C_class)?ID_private:ID_public; + access = type.default_access(); // All the data members are now known. // We now deal with the constructors that we are given. diff --git a/src/util/std_types.h b/src/util/std_types.h index 487fde2e51b..4e3b2c4e1d3 100644 --- a/src/util/std_types.h +++ b/src/util/std_types.h @@ -216,6 +216,19 @@ class struct_union_typet:public typet irep_idt get_tag() const { return get(ID_tag); } void set_tag(const irep_idt &tag) { set(ID_tag, tag); } + + /// A struct may be a class, where members may have access restrictions. + bool is_class() const + { + return id() == ID_struct && get_bool(ID_C_class); + } + + /// Return the access specification for members where access has not been + /// modified. + irep_idt default_access() const + { + return is_class() ? ID_private : ID_public; + } }; /// Check whether a reference to a typet is a \ref struct_union_typet. @@ -313,16 +326,6 @@ class class_typet:public struct_typet return (methodst &)(add(ID_methods).get_sub()); } - bool is_class() const - { - return get_bool(ID_C_class); - } - - irep_idt default_access() const - { - return is_class()?ID_private:ID_public; - } - class baset:public exprt { public: