0

FlexeLint/PC-lint is warning about that the return value of std::string::append is not considered on following reduced sample code:

#include <iostream>
#include <string>

int main() {

std::string s("Hell");
s.append(1,'o');

std::cout << s << std::endl;
return 0;

Calling FlexeLint gives the following warning:

Warning 534: Ignoring return value of function  'std::basic_string<char>::append(unsigned long, char)'

While that message is true, it does not make sense to catch the return value in this case because std::string::append simply returns *this.

In addition, any iterators, pointers and references related to this object may be invalidated. But this not the case, no iterators, pointers and references are used.

Question

Did i miss something important or is this simply a false positive of FlexeLint?

orbitcowboy
  • 1,438
  • 13
  • 25
  • *While that message is true* -- Well isn't that the job of a lint utility, and that is to find any and all issues (unless you suppress those warnings)? I wouldn't want to have a utility that decides on its own what it wanted to show me. – PaulMcKenzie May 19 '16 at 09:34
  • @PaulMcKenzie I still think the tool should me more clever, even on really simple cases like this. My understanding of a linter tool differs from yours - I would want to have a utility that is intelligent enough to decide whats relevant. – orbitcowboy May 19 '16 at 11:26
  • @orbitcowboy intelligelt analysis is a continuum and I can assure you that FlexeLint already filters away a lot of stupid false positives. It is non-trivial to get compete with skilled and motivated human analysis :) – Morten Jensen Dec 05 '17 at 12:57

1 Answers1

1

PC-Lint is quite flexible and most of the time it's possible to tweak it to your needs. There are several ways to disable this warning:

  • Using the global option -e534 (covers all functions)
  • Using the global option -esym(534,std::basic_string<char>::append(unsigned long, char))
  • Adding the comment //lint !e534 on the same line
Lars Ljung
  • 375
  • 2
  • 6
  • Thank you for this. I still think the checking of PC-Lint can be improved in this case, because it simply does not make sense to catch the return value here. Instead of suppressing errors, the tool should be improved! – orbitcowboy May 19 '16 at 19:35
  • 1
    Another way to disable the warning is to write (void)s.append(1,'o'); This solution does not clutter the code with lint comments and no external suppression list has to be maintained. – orbitcowboy May 20 '16 at 07:48
  • I couldn't get the explicit -esym suppression to work, but this did instead: `-esym(534,std::basic_string*::append)` – Andy Krouwel Nov 02 '16 at 12:28