Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC++2008-8-3-1 (C++ only)

In this section:
Synopsis

(Required) Parameters in an overriding virtual function shall either use the same default arguments as the function they override, or else shall not specify any default arguments.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Using different default vales might be confusing for the user of the class. Value must either be same constant, which must be specified in base class function, or not specified. This check is identical to MISRAC++2023-13.3.2.

Coding standards
MISRA C++ 2023 13.3.2

(Required) Parameters in an overriding virtual function shall not specify different default arguments

Code examples

The following code example fails the check and will give a warning:

class A
{
public:
  virtual void f(int a = 0);
};

class B : public A
{
public:
  void f(int a = 1) override; // Non-compliant
};

The following code example passes the check and will not give a warning about this issue:

class A
{
public:
  virtual void f( int a = 0  );
};

class B : public A
{
public:
  void f( int a  ) override; // Compliant
};