[cfe-dev] Modules TS: various problems

Boris Kolpackov via cfe-dev cfe-dev at lists.llvm.org
Tue Jun 20 05:29:44 PDT 2017


Boris Kolpackov <boris at codesynthesis.com> writes:

> So, theoretically, I should be able to replace my '#include <string>'
> with something like 'import std.core' provided I build an appropriate
> .pcm?

Actually, nothing prevents me from defining my own modules-ts std.core
module, even if I am using libstdc++:

// file: std-core.mxx -*- C++ -*-
export module std.core;

#include <string>
#include <iostream> // For compatibility with VC.

I was then able to replace '#include <string>' with 'import std.core'
and everything works except for one little niggle: for some reason
Clang insists that I import in the module's purview:

// file: hello.mxx -*- C++ -*-
export module hello;

import std.core;

export namespace hello
{
  void
  say (const std::string& name);
}

If I move import before the exporting module declaration:

// file: hello.mxx -*- C++ -*-
import std.core;

export module hello;

export namespace hello
{
  void
  say (const std::string& name); // line 9
}

Then I get this error:

hello.mxx:9:14: error: declaration of 'std' must be imported from module 'std.core' before it is required say (const std::string& name);
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.2.0/../../../../include/c++/6.2.0/iostream:42:11: note: previous declaration is here namespace std _GLIBCXX_VISIBILITY(default)

VC is happy with either placement and my reading of the spec suggests
that it shouldn't matter (unlike #include). Or am I missing something
here?

Thanks,
Boris



More information about the cfe-dev mailing list