Menu

False positive unusedFunction

2024-04-03
2024-04-08
  • Rob Deckers

    Rob Deckers - 2024-04-03

    We seem to be having a false positive unusedFunction.
    style: The function 'byteSwap' is never used. [unusedFunction]

    I simplified the code somewhat:

    namespace Details {
    
    template <typename T>
    constexpr T byteSwap(T value) noexcept
    {
        return value;
    }
    
    template <std::uint16_t Size>
    struct Converter<String<Size>, Endian::BIG> {
        static void fromRegisters(const std::array<std::uint16_t, 10>& buffer)
        {
            std::ranges::transform(buffer, buffer.begin(), byteSwap<std::uint16_t>);
        }
    };
    }
    

    If byteSwap is NOT a template function, Cppcheck seems to understand it and we don't have the false positive.
    If byteswap is a template, but we don't use std::ranges::transform (so, just call it directly). It also works.

     
  • Daniel Marjamäki

     

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.