# cpp:S995 false positive with range based for loop

**URL:** <https://community.sonarsource.com/t/cpp-s995-false-positive-with-range-based-for-loop/78182>\
**Category:** Report False-positive / False-negative...\
**Tags:** cfamily\
**Created:** [November 30, 2022, 9:34pm UTC](https://community.sonarsource.com/t/cpp-s995-false-positive-with-range-based-for-loop/78182 "2022-11-30T21:34:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eroller](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/eroller/32/45991_2.png) [@eroller](https://community.sonarsource.com/u/eroller)\
**Post date:** [November 30, 2022, 9:34pm UTC](https://community.sonarsource.com/t/cpp-s995-false-positive-with-range-based-for-loop/78182/1 "2022-11-30T21:34:34Z")

</div>

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){}  
}

---

<div class="post-metadata">

**Author:** ![Abbas](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/abbas/32/5717_2.png) [@Abbas](https://community.sonarsource.com/u/Abbas)\
**Post date:** [December 1, 2022, 8:19am UTC](https://community.sonarsource.com/t/cpp-s995-false-positive-with-range-based-for-loop/78182/2 "2022-12-01T08:19:50Z")

</div>

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](https://sonarsource.atlassian.net/browse/CPP-3360)

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

Thanks,

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [December 8, 2022, 9:37am UTC](https://community.sonarsource.com/t/cpp-s995-false-positive-with-range-based-for-loop/78182/5 "2022-12-08T09:37:15Z")

</div>

Closed on December 8, 2022, 9:37am UTC

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