Menu

FP: unsignedLessThanZero from known false constexpr if

2024-01-29
2024-01-29
  • Lionel Gimbert

    Lionel Gimbert - 2024-01-29

    Hello,

    I encounter a case where cppcheck complain about a unsignedLessThanZero in a bit of code that is (for this case) in the code block of a constexpr false if:

      uint32_t u32 = 4096u;
      if constexpr (std::numeric_limits<uint32_t>::is_signed) // same result with if constexpr (false)
      {
        if(u32 < 0) {} //FP: Checking if unsigned expression 'u32' is less than zero. [unsignedLessThanZero]
      }
    

    (real code is templated and the type can be signed).

    While it is true that, out of context, u32 < 0 should return this issue, I would expect if constexpr (false) {} to behave like #if 0 \ #endif and don't have this bit of code analyzed.

    I made this topic about unsignedLessThanZero but it is probably a wider issue of handling constexpr.
    I see this issue with both 2.10, 2.13.2 and current head of main (bef9e73e60a61a382f4341cfb70730ea67948132).

     
  • CHR

    CHR - 2024-01-29

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

     

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.