Cpp:1006 false-positive

  • Language: C++

  • Rule: cpp:S1006

  • Why do we believe it’s a false-positive?

    • C++ Qt project
    • We have a class that extends QAbstractTableModel
    • Our class overrides the rowCount() member function with the following:
      int rowCount(QModelIndex const &parent = QModelIndex()) const override;
      This is signalled by SonarQube as cpp:S1006: Make the default value for parameter “parent” constant
    • We agree that the parameter is not a constant, but the detail of the smell reports:
      • 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

    • The function we are overriding has the following signature:
      virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0;
    • The signature we are using is exactly the same as the one of the function we are overriding.
  • We are using: SonarQube Developer LTA 2025.4.3

Hello @lorenzo.buzzi,

We recently changed this rule to make it closer to the MISRA C++:2023 rule 13.3.2. In this context, it makes sense to ensure that the value of the default argument is always the same, in both the base class and the derived class, and therefore is a compile-time constant. Which is why you saw this message (the rule description should have been updated, but this was forgotten).

However, after careful review of your case, we decided that it is a very stringent condition, which is justified in safety-critical software, but not for general-purpose software. Consequently, we are going to revert to the previous behavior, which compared the default argument expressions, not their actual values, and did not require them to be constant.

Meanwhile, you can just mark this as false positive, or if you don’t directly use this function in your code, maybe removing the default argument in the derived class could work too.

1 Like

I don’t know what your timeline is for the revert, but I have no problem living with this smell for a while.

Thank @JolyLoic you for your prompt reply.

It’s not exactly a revert, more of a refinement :slight_smile: And it is now on our main branch, which means it should be part of our next release.

1 Like