Menu

False positive Unusual pointer arithmetic

Robert
2020-06-24
2020-06-25
  • Robert

    Robert - 2020-06-24

    I'm getting a false positive (Unusual pointer arithmetic. A value of type 'char' is added to a string literal. [strPlusChar]) on the follwing code

    void function(void)
    { 
      std::string l_Test;
      l_Test = "FooBar"s + 'a';
    }
    

    Although “FooBar”s returns a std::string which has a valid operator+ for char

     
  • Daniel Marjamäki

    alright.. "FooBar"s is not understood by compilers by default.. I assume you have an operator for that?

     
  • Zufu Liu

    Zufu Liu - 2020-06-25

    it seems "s" suffix (along with others) is from the C++ standard library, see last section on https://en.cppreference.com/w/cpp/language/user_literal

     
  • Daniel Marjamäki

    yes I assume there must be an operator.

    Cppcheck does not handle this code well. I created a ticket: https://trac.cppcheck.net/ticket/9787

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.