Skip to content

Commit

Permalink
clang-cl C++20 modules compile test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharadh Rajaraman committed Jul 16, 2024
1 parent 865a8e5 commit 8f9c90b
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions clang/test/Driver/cl-cxx20-modules.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// REQUIRES: system-windows

// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t

// RUN: %clang_cl /std:c++20 --precompile "%/t/Hello.cppm" "/Fo%/t/Hello.pcm"
// RUN: %clang_cl /std:c++20 %/t/use.cpp -fmodule-file=Hello=%/t/Hello.pcm %/t/Hello.pcm /Fo%/t/SimpleHelloWorld.exe 2>&1

// RUN: %/t/SimpleHelloWorld.exe
// CHECK: Simple Hello World!

//--- Hello.cppm
module;
#include <iostream>
export module Hello;
export void hello() {
std::cout << "Simple Hello World!\n";
}

//--- use.cpp
import Hello;
int main() {
hello();
return 0;
}

//--- M.cppm
export module M;
export import :interface_part;
import :impl_part;
export void Hello();

//--- interface_part.cpp
export module M:interface_part;
export void World();

//--- impl_part.cppm
module;
#include <iostream>
#include <string>
module M:impl_part;
import :interface_part;

std::string W = "World!";
void World() {
std::cout << W << std::endl;
}

//--- Impl.cpp
module;
#include <iostream>
module M;
void Hello() {
std::cout << "Complex Hello ";
}

//--- User.cpp
import M;
int main() {
Hello();
World();
return 0;
}

0 comments on commit 8f9c90b

Please sign in to comment.