YarikTH / ureact

Functional reactive programming library for c++
Boost Software License 1.0
155 stars 10 forks source link

Compile errors for Visual Studio #133

Closed jcoder58 closed 1 year ago

jcoder58 commented 1 year ago
Severity    Code    Description Project File    Line    Suppression State
Error   C4800   Implicit conversion from 'const size_t' to bool. Possible information loss  FRPTest C:\UnrealEngine\Projects\FRPTest\Plugins\FRP\Source\FRP\Public\ureact\detail\take_drop_base.hpp 52  
 Error  C4459   declaration of 'elements' hides global declaration  FRPTest C:\UnrealEngine\Projects\FRPTest\Plugins\FRP\Source\FRP\Public\ureact\detail\slot_map.hpp   261 
YarikTH commented 1 year ago

C4800 Implicit conversion from 'const size_t' to bool. Possible information loss ureact\detail\take_drop_base.hpp 52

    // checkable in boolean context
    explicit operator bool() const
    {
        return m_value;
    }

It is valid C++ code. Try to change it with either of the following variants:

return bool(m_value);
return static_cast<bool>(m_value);
return m_value != 0;
return !!m_value;

I need to know which of them don't trigger the error.

YarikTH commented 1 year ago

C4459 declaration of 'elements' hides global declaration

ureact\detail\slot_map.hpp 261

        void shake( const size_type elements )
        {
            const auto total_size = [&]() { return elements + m_size; };

            while( m_size > 0 && back_() == total_size() - 1 )
            {
                --m_size;
            }
        }

It seems that is is consequence of using namespace ureact and including <ureact/adaptor/elements.hpp>. Normally they are in different namespaces, so there is no any trace of shadowing. But once elements included in the global scope, it's become a reason for warning.

Try to rename elements arg to elements_amount or something. It was not so correct name in the first place.

YarikTH commented 1 year ago

I need to check my MSVC warnings list. Ureact is tested with github actions with lots of enabled warnings. Which warnings flags do you use? I use /W3. I heard that /W4 is kinda broken. It is full of false positives like you listed above. That's why /W3 is IDE default level, at least it is useful.

jcoder58 commented 1 year ago

I've made the changes you suggest and everything compiles.

I used return m_value != 0;

I'm compile it as part of Unreal Engine, so I assume it uses /W4.