[cfe-dev] Modules TS: various problems

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Mon Jun 19 13:42:16 PDT 2017


On 19 June 2017 at 06:45, Boris Kolpackov via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> I am trying to use the Modules TS implementation in Clang 5.0.0-svn305177.
> My module interface file:
>
> #include <string>
>
> export module hello;
>
> export namespace hello
> {
>   void say (const std::string& name);
> }
>
> Module implementation file:
>
> #include <string>
> #include <iostream>
>
> module hello;
>
> using namespace std;
>
> namespace hello
> {
>   void
>   say (const string& n)
>   {
>     cout << "Hello, " << n << '!' << endl;
>   }
> }
>
> The problems:
>
> 1. It seems the .pcm file compiled from the interface file references
>    said interface file. If I remove it after generating .pcm, then I get
>    an error like this when compiling the implementation file:
>
>    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
>    fatal error: malformed or corrupted AST file: 'could not find file
> '/home/boris/work/build2/hello/m/libmhello/libhello/hello.a.pcm.ii'
> referenced by AST file 'hello.a.pcm''
>
>    The .pcm is produced with this command line:
>
>    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
>

.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.

2. If I keep the source file, then I get errors along these lines (again,
>    when compiling the implementation file):
>
>    In file included from hello.cxx:3:
>

This line number doesn't match the above code.


>    In file included from /usr/bin/../lib/gcc/x86_64-
> linux-gnu/6.2.0/../../../../include/c++/6.2.0/string:39:
>    /usr/bin/../lib/gcc/x86_64-linux-gnu/6.2.0/../../../../
> include/c++/6.2.0/bits/stringfwd.h:69:48: error: template parameter
> redefines default argument
>      template<typename _CharT, typename _Traits = char_traits<_CharT>,
>    /usr/bin/../lib/gcc/x86_64-linux-gnu/6.2.0/../../../../
> include/c++/6.2.0/bits/stringfwd.h:69:48: note: previous default template
> argument defined here
>      template<typename _CharT, typename _Traits = char_traits<_CharT>,
>
>    The same code compiles fine with VC 15u3.
>
>    If I get rid of the <string> inclusion from the interface file (and
>    use const char* to pass the name), everything compiles fine.


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.

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).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170619/365240fc/attachment.html>


More information about the cfe-dev mailing list