Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entt fails to compile in C++20 when used inside a module interface file #1216

Open
KiviTK opened this issue Feb 1, 2025 · 8 comments
Open
Assignees
Labels
discussion it sounds interesting, let's discuss it invalid not a bug/not an issue/not whatever you want

Comments

@KiviTK
Copy link

KiviTK commented Feb 1, 2025

I tried to wrap some entt functionality for a project in C++20 modules, however when entt::registry is used in a module interface the compilation fails in this way:

[1/16] Scanning F:\Pawprint\source\ecs\world.cxxm for CXX dependencies
world.cxxm
[2/16] Generating CXX dyndep file CMakeFiles\Pawprint.dir\CXX.dd
[3/6] Building CXX object CMakeFiles\Pawprint.dir\source\ecs\world.cxxm.obj
FAILED: CMakeFiles/Pawprint.dir/source/ecs/world.cxxm.obj 
C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\cl.exe  /nologo /TP -DGRAPHICS_API_OPENGL_33 -DPLATFORM_DESKTOP -DSPDLOG_COMPILED_LIB -DTRACY_ENABLE -IF:\Pawprint\external -IF:\Pawprint\external\imgui -IF:\Pawprint\external\rlimgui -IF:\Pawprint\external\json\single_include\nlohmann -IF:\Pawprint\cmake-build-debug\_deps\raylib-src\src -IF:\Pawprint\cmake-build-debug\_deps\raylib-src\src\external\glfw\include -IF:\Pawprint\external\spdlog\include -external:IF:\Pawprint\external\tracy\public -external:W0 /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -std:c++latest -MDd -Zi /utf-8 /showIncludes @CMakeFiles\Pawprint.dir\source\ecs\world.cxxm.obj.modmap /FoCMakeFiles\Pawprint.dir\source\ecs\world.cxxm.obj /FdCMakeFiles\Pawprint.dir\Pawprint.pdb /FS -c F:\Pawprint\source\ecs\world.cxxm
world.cxxm
F:\Pawprint\external\entt.h(1435): error C2760: syntax error: '&&' was unexpected here; expected 'expression'
F:\Pawprint\external\entt.h(1435): note: the template instantiation context (the oldest one first) is
F:\Pawprint\source\ecs\world.ixx(9): note: see reference to class template instantiation 'entt::basic_registry<entt::entity,std::allocator<entt::entity>>' being compiled
F:\Pawprint\external\entt.h(38215): note: see reference to class template instantiation 'entt::dense_map<entt::id_type,std::shared_ptr<entt::basic_sparse_set<Entity,Allocator>>,entt::identity,std::equal_to<entt::id_type>,std::allocator<std::pair<const entt::id_type,std::shared_ptr<entt::basic_sparse_set<Entity,Allocator>>>>>' being compiled
        with
        [
            Entity=entt::entity,
            Allocator=std::allocator<entt::entity>
        ]
F:\Pawprint\external\entt.h(4053): note: see reference to class template instantiation 'entt::compressed_pair<std::vector<size_t,std::allocator<size_t>>,entt::identity>' being compiled
F:\Pawprint\external\entt.h(1435): error C2057: expected constant expression
F:\Pawprint\external\entt.h(1435): error C2059: syntax error: '&&'
F:\Pawprint\external\entt.h(3453): error C2760: syntax error: '&&' was unexpected here; expected 'expression'
F:\Pawprint\external\entt.h(3453): error C2057: expected constant expression
F:\Pawprint\external\entt.h(3453): error C2059: syntax error: '&&'
[4/6] Building CXX object CMakeFiles\PawprintExample.dir\example\main.cpp.obj
FAILED: CMakeFiles/PawprintExample.dir/example/main.cpp.obj 
C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\cl.exe  /nologo /TP -DGRAPHICS_API_OPENGL_33 -DPLATFORM_DESKTOP -DSPDLOG_COMPILED_LIB -DTRACY_ENABLE -IF:\Pawprint\external -IF:\Pawprint\external\imgui -IF:\Pawprint\external\rlimgui -IF:\Pawprint\external\json\single_include\nlohmann -IF:\Pawprint -IF:\Pawprint\cmake-build-debug\_deps\raylib-src\src -IF:\Pawprint\cmake-build-debug\_deps\raylib-src\src\external\glfw\include -IF:\Pawprint\external\spdlog\include -external:IF:\Pawprint\external\tracy\public -external:W0 /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -std:c++latest -MDd -Zi /utf-8 /showIncludes @CMakeFiles\PawprintExample.dir\example\main.cpp.obj.modmap /FoCMakeFiles\PawprintExample.dir\example\main.cpp.obj /FdCMakeFiles\PawprintExample.dir\ /FS -c F:\Pawprint\example\main.cpp
F:\Pawprint\external\entt.h(1435): error C2760: syntax error: '&&' was unexpected here; expected 'expression'
F:\Pawprint\external\entt.h(1435): note: the template instantiation context (the oldest one first) is
F:\Pawprint\source\ecs\world.ixx(9): note: see reference to class template instantiation 'entt::basic_registry<entt::entity,std::allocator<entt::entity>>' being compiled
F:\Pawprint\external\entt.h(38215): note: see reference to class template instantiation 'entt::dense_map<entt::id_type,std::shared_ptr<entt::basic_sparse_set<Entity,Allocator>>,entt::identity,std::equal_to<entt::id_type>,std::allocator<std::pair<const entt::id_type,std::shared_ptr<entt::basic_sparse_set<Entity,Allocator>>>>>' being compiled
        with
        [
            Entity=entt::entity,
            Allocator=std::allocator<entt::entity>
        ]
F:\Pawprint\external\entt.h(4053): note: see reference to class template instantiation 'entt::compressed_pair<std::vector<size_t,std::allocator<size_t>>,entt::identity>' being compiled
F:\Pawprint\external\entt.h(1435): error C2057: expected constant expression
F:\Pawprint\external\entt.h(1435): error C2059: syntax error: '&&'
F:\Pawprint\external\entt.h(3453): error C2760: syntax error: '&&' was unexpected here; expected 'expression'
F:\Pawprint\external\entt.h(3453): error C2057: expected constant expression
F:\Pawprint\external\entt.h(3453): error C2059: syntax error: '&&'
ninja: build stopped: subcommand failed.

This example error is produced by this code:

// world.ixx
module;

#include <entt.h>

export module world;

export class world {
public:
    entt::registry r;
};
// main.cpp
import world;

int main() {
    world w;
}

The code compiles perfectly fine when the exact same class is copied to a traditional C++ file, like on top of the main file as an example.

@skypjack skypjack self-assigned this Feb 4, 2025
@skypjack skypjack added the triage pending issue, PR or whatever label Feb 4, 2025
@skypjack
Copy link
Owner

skypjack commented Feb 4, 2025

It seems an issue with the module support of your compiler rather than a problem in EnTT. Am I wrong?

@KiviTK
Copy link
Author

KiviTK commented Feb 4, 2025

I am unsure, possibly.
I am using the currently latest MSVC compiler, 17.12.4 Visual Studio Community 2022.

Other libraries that are wrapped this way had no issues, this obviously does not mean that it's not a compiler issue.
Maybe if it's reproducible escalate this to a MSVC issue?

@skypjack
Copy link
Owner

skypjack commented Feb 4, 2025

Uhm, any chance that you can try the same with the clang compiler in VS? It's available out of the box already.

@KiviTK
Copy link
Author

KiviTK commented Feb 4, 2025

Right, I am just using the cl compiler and using external CMake to build the project, but I'll spin it up with clang-cl and report back soon.

@KiviTK
Copy link
Author

KiviTK commented Feb 4, 2025

Regular clang does build the project as expected. This may be an MSVC issue then. clang-cl does not build it, however.
Probably shaky module support on MSVC's end, I may file a report on there too, but I am unsure of what exactly the issue is so may not be trivial.

@skypjack
Copy link
Owner

skypjack commented Feb 5, 2025

The main problem is that I wouldn't even know how to fix it if the problem is a specific compiler on a feature that is still not widespread. I think that calling MSFT on the topic is the best move actually.
I'm open to suggestions to fix it temporarily if you know how to do that. I can't find an easy way to get around the problem yet.

@skypjack skypjack added invalid not a bug/not an issue/not whatever you want discussion it sounds interesting, let's discuss it and removed triage pending issue, PR or whatever labels Feb 5, 2025
@n0F4x
Copy link

n0F4x commented Feb 5, 2025

I happen to #include <entt/entt.hpp> within module interface units in my project with Clang 19 (I use MSYS2) that uses entt/3.14.0 and it works fine.

@KiviTK
Copy link
Author

KiviTK commented Feb 5, 2025

Regular Clang does build it. And the header itself was not causing issues. I was able to use entt::entity for example without issues, the registry was what broke.
For the time being I am able to continue prototyping on Clang, so this is an acceptable compromise for me.
I also have no suggestions on how it could be worked around on MSVC, so feel free to just close the issue.
I will also recreate the issue and submit it to Microsoft to see if they can figure out where the compilation goes wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion it sounds interesting, let's discuss it invalid not a bug/not an issue/not whatever you want
Projects
None yet
Development

No branches or pull requests

3 participants