Menu

False positive in throwInNoexceptFunction

Skult
2023-04-26
2023-04-27
  • Skult

    Skult - 2023-04-26
    template <bool IsNoThrow>
    static void* MyNew( size_t Size ) noexcept( IsNoThrow )
    {
        void* Memory = std::malloc( Size );
        if ( !Memory )
        {
            if constexpr ( !IsNoThrow )
            {
                throw std::bad_alloc();
            }
        }
        return Memory;
    }
    
    void* operator new( size_t Size, const std::no_throw_t& ) noexcept
    {
        return MyNew<true>( Size );
    }
    

    "error: Exception thrown in function declared not to throw exceptions. [throwInNoexceptFunction]" is produced on both the callsite and the line with throw.
    However, with template parameter == true it should be impossible for the function to throw

     
  • CHR

    CHR - 2023-04-27

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

     

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.