<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 19 June 2017 at 06:45, Boris Kolpackov via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I am trying to use the Modules TS implementation in Clang 5.0.0-svn305177.<br>
My module interface file:<br>
<br>
#include <string><br>
<br>
export module hello;<br>
<br>
export namespace hello<br>
{<br>
  void say (const std::string& name);<br>
}<br>
<br>
Module implementation file:<br>
<br>
#include <string><br>
#include <iostream><br>
<br>
module hello;<br>
<br>
using namespace std;<br>
<br>
namespace hello<br>
{<br>
  void<br>
  say (const string& n)<br>
  {<br>
    cout << "Hello, " << n << '!' << endl;<br>
  }<br>
}<br>
<br>
The problems:<br>
<br>
1. It seems the .pcm file compiled from the interface file references<br>
   said interface file. If I remove it after generating .pcm, then I get<br>
   an error like this when compiling the implementation file:<br>
<br>
   clang++-5.0 -std=c++1z -D__cpp_modules=201704 -fmodules-ts -fmodule-file=hello.a.pcm -o hello.a.o -c -x c++ hello.a.o.ii<br>
   fatal error: malformed or corrupted AST file: 'could not find file '/home/boris/work/build2/<wbr>hello/m/libmhello/libhello/<wbr>hello.a.pcm.ii' referenced by AST file 'hello.a.pcm''<br>
<br>
   The .pcm is produced with this command line:<br>
<br>
   clang++-5.0 -std=c++1z -D__cpp_modules=201704 -fmodules-ts -o hello.a.pcm --precompile -Xclang -fmodules-codegen -Xclang -fmodules-debuginfo -x c++-module hello.a.pcm.ii<br></blockquote><div><br></div><div>.pcm files are not a distribution format. You still need the module interface to be available at the point of use (Clang will use them to emit text snippets in diagnostics, as well as for some internal purposes where we avoid making copies of data that's present in a source file). As David notes, you can use -fmodules-embed-all-files to cause the input files to be embedded in the .pcm file.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2. If I keep the source file, then I get errors along these lines (again,<br>
   when compiling the implementation file):<br>
<br>
   In file included from hello.cxx:3:<br></blockquote><div><br></div><div>This line number doesn't match the above code.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   In file included from /usr/bin/../lib/gcc/x86_64-<wbr>linux-gnu/6.2.0/../../../../<wbr>include/c++/6.2.0/string:39:<br>
   /usr/bin/../lib/gcc/x86_64-<wbr>linux-gnu/6.2.0/../../../../<wbr>include/c++/6.2.0/bits/<wbr>stringfwd.h:69:48: error: template parameter redefines default argument<br>
     template<typename _CharT, typename _Traits = char_traits<_CharT>,<br>
   /usr/bin/../lib/gcc/x86_64-<wbr>linux-gnu/6.2.0/../../../../<wbr>include/c++/6.2.0/bits/<wbr>stringfwd.h:69:48: note: previous default template argument defined here<br>
     template<typename _CharT, typename _Traits = char_traits<_CharT>,<br>
<br>
   The same code compiles fine with VC 15u3.<br>
<br>
   If I get rid of the <string> inclusion from the interface file (and<br>
   use const char* to pass the name), everything compiles fine.</blockquote><div><br></div><div>I'm not surprised. Clang does not claim to fully implement the Modules TS yet; the implementation is incomplete. In particular, there is no support for the semantics of export declarations -- instead, we export everything declared within the module interface unit. As a result, you're importing the contents of <string> but not its include guards, so you will see redefinition errors for all definitions in that header.</div><div><br></div><div>If you want to experiment with Modules TS code using the standard library anyway, the easiest way to get the above code working would be to use a standard library implementation that provides a module map (for instance, build with -stdlib=libc++ -fmodules).</div></div></div></div>