FP: cpp:S810 on std::string s{4, 'a'};

  • What language is this for? cpp
  • Which rule? Target type is a plain char and should not be used to store numeric values.sonarlint(cpp:S810)
  • Why do you believe it’s a false-positive/false-negative? We are using constructor (2) which clearly takes a number and a char. I see no violation of this rule.
  • Are you using
    • SonarLint - which IDE/version? VSCode / v4.1.0
      • in connected mode with SonarQube or SonarCloud? yes
  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
#include <string>

std::string s{4, 'a'};

My bad. I cannot use {} init here. Then it uses an {char, char, …} initalizer list. I need to call: std::string s(4, 'a');

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