xref: /llvm-project/clang/test/Modules/export-language-linkage.cppm (revision da00c60dae0040185dc45039c4397f6e746548e9)
1// RUN: rm -rf %t
2// RUN: split-file %s %t
3// RUN: cd %t
4//
5// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
6// RUN: %clang_cc1 -module-file-info %t/a.pcm | FileCheck %t/a.cppm
7// RUN: %clang_cc1 -std=c++20 %t/b.cpp -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
8// RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-module-interface -o %t/c.pcm
9// RUN: %clang_cc1 -std=c++20 %t/d.cpp -fsyntax-only -verify -fmodule-file=c=%t/c.pcm
10
11// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
12// RUN: %clang_cc1 -std=c++20 %t/b.cpp -fmodule-file=a=%t/a.pcm -fsyntax-only -verify
13// RUN: %clang_cc1 -std=c++20 %t/c.cppm -fsyntax-only -verify
14// RUN: %clang_cc1 -module-file-info %t/a.pcm | FileCheck %t/a.cppm
15
16//--- a.cppm
17export module a;
18export extern "C++" int foo() { return 43; }
19export extern "C++" {
20    int a();
21    int b();
22    int c();
23}
24
25export {
26    extern "C++" void f1();
27    extern "C++" void f2();
28    extern "C++" void f3();
29}
30
31extern "C++" void unexported();
32
33// CHECK: Sub Modules:
34// CHECK-NEXT: Implicit Module Fragment '<implicit global>'
35
36//--- b.cpp
37import a;
38int use() {
39    a();
40    b();
41    c();
42    f1();
43    f2();
44    f3();
45    unexported(); // expected-error {{declaration of 'unexported' must be imported from module 'a' before it is required}}
46                   // expected-note@a.cppm:15 {{declaration here is not visible}}
47    return foo();
48}
49
50//--- c.cppm
51// expected-no-diagnostics
52export module c;
53extern "C++" {
54    export int f();
55    int h();
56}
57
58extern "C++" export int g();
59
60//--- d.cpp
61import c;
62int use() {
63    return f() + g();
64}
65
66int use_of_nonexported() {
67    return h(); // expected-error {{declaration of 'h' must be imported from module 'c' before it is required}}
68                // expected-note@c.cppm:5 {{declaration here is not visible}}
69}
70