cpp:S995 false positive with range based for loop

SonarQube * Enterprise Edition

  • Version 8.9.9 (build 56886) says: Pointer and reference parameters should be “const” if the corresponding object is not modified

It appears that SonarQube cannot tell that the non-const begin() and end() are being called on the parameter passed by non-const reference. Simple example (assume MyFileReader only provides non-const begin() and end() functions):

void foo(MyFileReader& input){
for(const auto line : input){}
}

Hi @eroller,

Thanks for this report.

The issue is related to the range-for and non-const being/end.

We already fixed it: [CPP-3360] - Jira

Feel free to update to the latest SonarQube version to get the best analysis result.

Thanks,

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.