Entt: EnTT really work on windows ?

Created on 8 Jun 2018  路  14Comments  路  Source: skypjack/entt

Hey using vcpkg + entt 2.6.1

```cpp
entity_registry_.each(this {
this->entity_registry_.destroy(entity);
});
````

this snippet doesn't compile with the following error
ecs-test.cpp

c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(567): warning C4003: not enough actual parameters for macro 'min' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(625): warning C4003: not enough actual parameters for macro 'min' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(633): warning C4003: not enough actual parameters for macro 'max' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(756): warning C4003: not enough actual parameters for macro 'min' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(552): error C2589: '(': illegal token on right side of '::' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(901): note: see reference to class template instantiation 'entt::View c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(567): error C2589: '(': illegal token on right side of '::' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(625): error C2589: '(': illegal token on right side of '::' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(633): error C2589: '(': illegal token on right side of '::' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(756): error C2589: '(': illegal token on right side of '::' [C:\projects\shiva\buildtests\ecs-test\ecs-test.vcxproj]

invalid

Most helpful comment

So, Windows has a flag that makes our code more portable by rejecting valid code? :-D
Love it, really.

All 14 comments

Fortunately yes, or at least appveyor says so.
If you can provide a minimal example to reproduce the error and all the details of your toolchain, we can try to solve the problem.
Otherwise I must tag the issue as invalid and close it. I'm sorry.

for my ci -> https://ci.appveyor.com/project/Milerius/shiva

cmake part of entt:
```cmake
include(CMakeSources.cmake)
set(MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

find_path(ENTT_INCLUDE_DIR entt/entt.hpp)
MSG_YELLOW_BOLD(STATUS "ENTT_INCLUDE_DIR: " "${ENTT_INCLUDE_DIR}" "")

CREATE_MODULE(shiva::entt "${MODULE_SOURCES}" ${MODULE_PATH})
target_include_directories(shiva-entt INTERFACE ${ENTT_INCLUDE_DIR})
````

```cpp
namespace shiva::error
{
class general_handler
{
public:
void receive(const shiva::event::fatal_error_occured &evt)
{
entity_registry_.each(this {
this->entity_registry_.destroy(entity);
}); // doesn't compile on windows
dispatcher_.trigger(evt.ec_.value());
}

    general_handler(entt::dispatcher &dispatcher, entt::entity_registry &entity_registry) noexcept :
        dispatcher_(dispatcher),
        entity_registry_(entity_registry)
    {
        this->dispatcher_.sink<shiva::event::fatal_error_occured>().connect(this);
        if (shiva::fs::exists("stacktrace/backtrace.dump")) {
            // there is a backtrace
            std::ifstream ifs("stacktrace/backtrace.dump");

            shiva::bs::stacktrace st = shiva::bs::stacktrace::from_dump(ifs);
            std::cerr << "Previous run crashed:\n" << st << std::endl;

            // cleaning up
            ifs.close();
            shiva::fs::remove("stacktrace/backtrace.dump");
        }
    }

private:
    entt::dispatcher &dispatcher_;
    entt::entity_registry &entity_registry_;
};

````
as you can see it's compile on Linux on my ci, but not on windows :/

I found the problem I'm compiling with flags / permissive- https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance
on windows, it's a very important flag. (It seems that EnTT does not compile with / permissive- we could look at this. problem together if you want and try to solve it via another issue?

permissive-:
Use this option to help you identify and fix conformance issues in your code, to make it both more correct and more portable.)

my program now compiles without /permissive-

So, Windows has a flag that makes our code more portable by rejecting valid code? :-D
Love it, really.

i dont know but may be we can look together if you want, or report an error to MSVC team

I was already looking at the error, but I don't know how to solve it.
It looks like it considers malformed expressions like this one:

return std::min({ pool<Component>().size()... });

Not sure about a workaround that doesn't affect everything.
Any idea?

If i reminder, std::min on windows is a macro, may be it's the problem, we can try to do our own min function and try with /permissive- to compile entt

i will ask in #msvc channel in cpplang.sh slack

A macro? Why that? The language is mandatory about std::min, it's defined as a function template.
I've used std::min all around in the codebase, this will break things a bit actually.

Btw, if it's a macro, why it doesn't complain without permissive flag?

It's does with /W4 msvc flags
c:\tools\vcpkg\installed\x64-windows\include\entt\entity\view.hpp(567): warning C4003: not enough actual parameters for macro 'min' [C:\projects\shiva\build\tests\ecs-test\ecs-test.vcxproj]

Combined with /permissive- it's turn this warning into an illegal error

I think the solution it's to use own min function for windows, since they didn't plan to remove this macro i think

It seems you can solve the problem your side by defining a macro that disable those macros (it makes me cry).
Probably, if it solves, it's worth adding the macro in the configuration file for EnTT.
Can you try it?

This:

#ifndef NOMINMAX
#define NOMINMAX
#endif

Should be put before any other include.
I don't think it will work as expected if set by the configuration file of EnTT.

If it solves your problem, well, it would confirm that it's in charge to users to turn off such annoying macros on Windows.

i will put in my cmake a compile definition that define NOMINMAX, ty

(use boost/stacktrace.hpp in my project that include windows.h) and windows.h have a macro min/max... sorry

Don't worry, it's not a problem of my fault or your fault.
I want to help you to solve your issue somehow. ;-)

thanks ! i close the issue !

Was this page helpful?
0 / 5 - 0 ratings