Clarification for rule 9-3-3

Moderators: david ward, misra cpp

Post Reply
dg1980
Posts: 108
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Clarification for rule 9-3-3

Post by dg1980 » Wed Mar 22, 2017 8:59 am

Dear MISRA team,

to me the rule text sounds like an if/else instruction for a static analysis tool vendor, e.g.:

Code: Select all

if (static_possible[ast_cur_sym])
{
  print("[MISRA C++ 9-3-3] %s could be made static", ast_cur_sym);
}
else
{
  if (const_possible[ast_cur_sym])
  {
    print("[MISRA C++ 9-3-3] %s could be made const", ast_cur_sym);
  }
}


Can you confirm?
Thanks.

Background: in the sample code below i would expect to get "[MISRA C++ 9-3-3] nfoo::cfoo::get could be made static" while some static analyzers suggest const instead.

Code: Select all

namespace nfoo
{
  typedef int si32;
  class cfoo
  {
  public:
    si32 get(void){return x;}
  private:
    static si32 x;
  };

  si32 cfoo::x = 0;
}

misra cpp
Posts: 145
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Clarification for rule 9-3-3

Post by misra cpp » Mon Jul 10, 2017 11:39 am

You are correct - if your tool says it should be const - contact your tool vendor
Posted by and on behalf of
the MISRA C++ Working Group

dg1980
Posts: 108
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Clarification for rule 9-3-3

Post by dg1980 » Mon Sep 04, 2017 9:45 am

The scope for this rule shall be clarified in the next version in such a way that it is clear whether virtual member functions are included or excluded.
Our static analyzer has a different, non-MISRA related message for virtual members that could be const, because then all derived implementations would have to be const as well (which might not be possible/wanted).
Thanks.

misra cpp
Posts: 145
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Clarification for rule 9-3-3

Post by misra cpp » Fri Sep 22, 2017 4:30 pm

We'd agree that the current position is ambiguous. This is to be considered for the next version - the likely outcome being that this applies to all functions, including virtual members. However, for virtual functions the requirement only applies if all virtual functions in an override set can be made const
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.9 Classes (C++)”