[cfe-dev] How do I try out C++ modules with clang?
Stephen Kelly
steveire at gmail.com
Sun Oct 5 13:49:11 PDT 2014
Richard Smith wrote:
> "At present, there is no C or C++ syntax for import declarations. Clang
> will track the modules proposal in the C++ committee. See the section
> Includes as imports to see how modules get imported today."
Yes, to be more-specific than I was before, this ^ is what I was missing
before this thread.
>> > in your own module maps for
>> > C++, I recommend focusing on making sure your headers are hygienic.
>>
>> My interest/curiosity is whether module maps can be created for
>> Qt/KDE/Boost. It seems that module maps for dependencies (such as the std
>> library) are a prerequisite before that kind of playing around anyway. Is
>> something floating around already for libc++/libstdc++? Even a trivial
>> one, not providing separate std.io etc, but just std?
>>
>
> libc++ already ships with a module map.
Ok, the version of libcxx on my system doesn't. Maybe I can point clang to
the version in the git repo...
>> [Aside: in the doc, the sentence "Module map files are typically named
>> module.modulemap", but elsewhere on the page it is specified to be a
>> naming requirement - 'typically' is wrong here]
>>
>
> 'typically' is correct; while only 'module.modulemap' is searched for in
> -I paths, additional module map files can be specified via
> -fmodule-map-file= and 'extern module' declarations, and these files do
> not need to be named module.modulemap.
I see. Perhaps "(each named module.modulemap)" could be rephrased in the
docs too then.
However, I tried this with the example from Sean after moving the
module.modulemap file to a foo subdirectory and renaming it.
It did not work:
$ ls $PWD/foo/module.modulemap
/home/stephen/dev/src/playground/modules/modulestry/foo/map
$ clang++-3.6 -E -fmodules -fmodule-map-file=$PWD/foo/map test.cpp
<snip>
static inline int foo() { return 1; }
# 5 "test.cpp" 2
int main(int, char **) {
return foo();
}
Instead of the expected @import declaration.
I also tried -fmodule-map-file=$PWD/foo/does_not_exist and no warning or
error was reported.
I then moved the map file out of the subdirectory, and ran
$ clang++-3.6 -E -fmodules -fmodule-map-file=map -Weverything test.cpp
and the first time I ran it (but not any subsequent time), I got the output:
<module-includes>:1:1: warning: header 'map' is included in module 'test'
but not listed in module map [-Wincomplete-module]
#include "/home/stephen/dev/src/playground/modules/modulestry/./test.h"
^
and the expected
@import test;
line.
So, I guess I can specify the name, but the file must still be with the
headers. I do have other things I wonder about along these lines, but I'll
experiment more later.
> One option would be for each library to provide its own module map file,
> which you specify on the clang command line with -fmodule-map-file=. I
> don't think we necessarily have the right answer for this case yet.
Right. At least in CMake, we can add an abstraction (eventually, when the
feature is stable) to specify the -fmodule-map-file as a usage requirement.
>> So, is this something that is proposed for standardization?
>
>
> No. Nothing about module maps is proposed for standardization, nor even
> guaranteed to be compatible across Clang revisions (yet).
I see. I remember hearsay that there are 3 different modules proposals in
the works currently. I found
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4047.pdf
Can you point me to other modules related N-documents?
> So be aware that
> if you go and write a bunch of module maps now, you may need to change
> them all to keep them working with future versions of Clang (or you may
> not; we don't know).
Understood, thanks.
Steve.
More information about the cfe-dev
mailing list