Programming language: c++ (cpp20)
Rule: cpp:S6231
IDE: Visual Studio (2022, 2026)
SonarQube version: 10.5.0.16999
This rule should not complain when both, address (data()) and length (size()) of a string_view object are provided to a called function.
Example:
std::string_view view{"some text"};
char const* comp_text{"some other text"};
if (0 == strncmp(comp_text, view.data(), view.size()))
do_something();
That code is totally valid and there is no risk of reading past the end of the memory area, described by the string_view object.
The reason to use string_view objects, i.e. when parsing text, is to explicitly prevent permanently copying parts into new string objects. Doing so only to produce “compliant” code would be bad. Disabling this hint/warning would also be bad for those cases, where the size() property is not taken into account.