MISRA.MEMB.NON_CONSTNon-const member function does not change any member variables. MISRA-C++ Rule 9-3-3 (required): If a member function can be made static then it shall be made static, otherwise if it can be made const then it shall be made const.This rule is also covered by MISRA.MEMB.NON_STATIC. RationaleDeclaring a member function static or const limits its access to the non-static data members. This helps to prevent unintentional modification of the data, and facilitates compliance with Rule 7—1—1. Exampleclass A { public: int16_t f1 ( ) // Non-compliant — can be const { return m_i; } int16_t f2 ( ) // Non-compliant — can be static { return m_s; } int16_t f3 ( ) // Compliant — cannot be const or static { return ++m_i; } private: int16_t m_i; static int16_t m_s; }; |