xref: /llvm-project/clang/test/Modules/named-modules-adl-3.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 -std=c++20 %t/b.cppm -fmodule-file=a=%t/a.pcm  -emit-module-interface \
7// RUN:     -o %t/b.pcm
8// RUN: %clang_cc1 -std=c++20 %t/c.cppm -fmodule-file=a=%t/a.pcm -fmodule-file=b=%t/b.pcm \
9// RUN:     -fsyntax-only -verify
10//
11// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/a.cppm -emit-module-interface -o %t/a.pcm
12// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/b.cppm -fmodule-file=a=%t/a.pcm  \
13// RUN:     -emit-module-interface -o %t/b.pcm
14// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/c.cppm -fmodule-file=a=%t/a.pcm \
15// RUN:     -fmodule-file=b=%t/b.pcm -fsyntax-only -verify
16
17// Test again with reduced BMI.
18//
19// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
20// RUN: %clang_cc1 -std=c++20 %t/b.cppm -fmodule-file=a=%t/a.pcm  -emit-reduced-module-interface \
21// RUN:     -o %t/b.pcm
22// RUN: %clang_cc1 -std=c++20 %t/c.cppm -fmodule-file=a=%t/a.pcm -fmodule-file=b=%t/b.pcm \
23// RUN:     -fsyntax-only -verify
24//
25// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
26// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/b.cppm -fmodule-file=a=%t/a.pcm  \
27// RUN:     -emit-reduced-module-interface -o %t/b.pcm
28// RUN: %clang_cc1 -std=c++20 -DEXPORT_OPERATOR %t/c.cppm -fmodule-file=a=%t/a.pcm \
29// RUN:     -fmodule-file=b=%t/b.pcm -fsyntax-only -verify
30
31//--- foo.h
32namespace n {
33
34struct s { };
35
36void operator+(s, int) {}
37
38} // namespace n
39
40//--- a.cppm
41module;
42#include "foo.h"
43export module a;
44export namespace n {
45    using n::s;
46#ifdef EXPORT_OPERATOR
47    using n::operator+;
48#endif
49}
50
51//--- b.cppm
52export module b;
53export import a;
54
55export template<typename T>
56void b(T x) {
57	n::s() + x;
58}
59
60//--- c.cppm
61#ifdef EXPORT_OPERATOR
62// expected-no-diagnostics
63#endif
64export module c;
65import b;
66
67void c(int x) {
68#ifndef EXPORT_OPERATOR
69	// expected-error@b.cppm:6 {{invalid operands to binary expression ('n::s' and 'int')}}
70    // expected-note@+2 {{in instantiation of function template specialization 'b<int>' requested here}}
71#endif
72    b(0);
73
74#ifndef EXPORT_OPERATOR
75    // expected-error@+2 {{invalid operands to binary expression ('n::s' and 'int')}}
76#endif
77    n::s() + x;
78}
79