Menu

False positive [incorrectStringBooleanError]

1 day ago
1 day ago
  • Simon Jantsch

    Simon Jantsch - 1 day ago

    Hi,

    cppcheck (version 2.19, on commit 633b4e45c7e036a73da18a4e0340896edfa92f35) gives an incorrectStringBooleanError for the following program, even though there is a string_view overload which is correctly chosen when I run this (https://godbolt.org/z/fjjGf4s7n).

    #include <string_view>
    #include <iostream>
    
    using namespace std::literals::string_view_literals;
    
    
    bool f(bool a) {
        return false;
    }
    
    bool f(const std::string_view a) {
        return true;
    }
    
    
    int main() {
      std::cout << f("01"sv);
    }
    

    I'm running:

    cppcheck --enable=all test.cpp
    

    and I'm getting:

    test.cpp:17:18: warning: Conversion of string literal "01" to bool always evaluates to true. [incorrectStringBooleanError]
      std::cout << f("01"sv);
    
     
  • CHR

    CHR - 1 day ago

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14058

     

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.