Miscellaneous-NoPublicDataMembers

Do not declare non-const data members public

Required inputs: IR

Public data members could be modified by other types in a way that violates the invariants of the class. Data members should be encapsulated: they should be declared as private, and accessor functions should be declared to allow other classes access to the data members.
Example
class C
{
private:
    std::string m_member;

public:
    const std::string& member()
    {
        return m_member;
    }
    void member(const std::string& new_value)
    {
        assert(new_value.size() > 0);
        m_member = new_value;
    }
};
See Also
Rule Miscellaneous-NoReferenceToPrivateDataMember

Possible Messages

Key

Text

Severity

Disabled

protected_field

Protected non-const data member.

None

False

public_field

Public non-const data member.

None

False

Options

allow_protected_members

allow_protected_members : bool = True

Whether protected fields should be ignored.
 

allowed

allowed

Type: list[typing.Tuple[typing.Union[typing.Pattern[str], typing.Callable[[bauhaus.ir.Node], bool]], typing.Union[typing.Pattern[str], typing.Callable[[bauhaus.ir.Node], bool]]]]

Default: []

Specifies allowed fields as pairs (class name pattern, field name pattern).Example: (re.compile('.*'), re.compile('x')) to allow x in all classes.
 

ignore_const_members

ignore_const_members : bool = True

Whether public const fields should be ignored.
 

ignore_pod

ignore_pod : bool = True

Whether public fields in POD classes should be ignored.
 

ignore_structs

ignore_structs : bool = True

Whether public fields in structs should be ignored.
 

ignore_templates

ignore_templates : bool = False

Whether public fields in generic templates should be ignored.