I am trying to use the material of an experimental Visual Studio 2017 module with templates in a module. Here's a simplified example of a module I'm trying to make
// MyModule.ixx module MyModule; export { template<typename T> struct Struct_1 { T value; } template<typename T> struct Struct_2 { union { T data[1]; Struct_1<T> x; }; } }
And this is how I try to use the module and template structures
// main.cpp import std.core; import MyModule; int main(int argc, char* argv[]) { Struct_2<float> s; std::cout << s.data[0]; return 0; }
Compilation gives the following: error C2079: 'Struct_2::x' uses undefined struct 'Struct_1<T>
I understand that modules are an experimental function, however, when modules are not used, the definition of such structures works fine. He says that Struct_1<T> is undefined, so does this mean that I need to somehow create templates explicitly?
My compiler command line looks like this:
cl /utf-8 /experimental:module MyModule.ixx /std:c++latest /W3 /Zi /MDd /EHsc main.cpp /link /OUT:test.exe /INCREMENTAL:NO
Any help is appreciated.
UPDATE
I think this is a kind of MSVC compiler error. I compiled the same code with Clang and it works great. The Clang module file looks the same as above, except for the .cppm file extension and above, instead it has:
export module MyModule;
My compiler command line looks like this:
clang++ -fmodules-ts --precompile MyModule.cppm -o MyModule.pcm clang++ -fmodules-ts -fprebuilt-module-path=. main.cpp
It's probably a good idea to just wait for the MSVC compiler to ripen a bit before using the modules, but if someone knows a way around this for now, I would be interested to see it.
thanks