xref: /llvm-project/clang/test/Modules/warn-duplicated-decls-in-module-units.cppm (revision 3cca522d21876da36145655bc14f334035b4265d)
1// RUN: rm -rf %t
2// RUN: mkdir %t
3// RUN: split-file %s %t
4//
5// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -emit-module-interface -o %t/m1.pcm
6// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -emit-module-interface -o %t/m2.pcm
7// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \
8// RUN:     -verify
9//
10// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -Wall -emit-module-interface -o %t/m1.pcm
11// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -Wall -emit-module-interface -o %t/m2.pcm
12// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \
13// RUN:     -verify -Wall
14//
15// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -Wdecls-in-multiple-modules -emit-module-interface -o %t/m1.pcm
16// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -Wdecls-in-multiple-modules -emit-module-interface -o %t/m2.pcm
17// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \
18// RUN:     -verify -Wdecls-in-multiple-modules -DWARNING
19
20//--- foo.h
21#ifndef FOO_H
22#define FOO_H
23
24enum E { E1, E2 };
25
26int a = 43;
27
28class foo {
29public:
30    void consume(E, int);
31};
32
33inline void func() {}
34
35void fwd_decl();
36
37#endif
38
39//--- m1.cppm
40module;
41#include "foo.h"
42export module m1;
43export {
44    using ::foo;
45    using ::a;
46    using ::func;
47    using ::fwd_decl;
48    using ::E;
49}
50
51//--- m2.cppm
52module;
53#include "foo.h"
54export module m2;
55export {
56    using ::foo;
57    using ::a;
58    using ::func;
59    using ::fwd_decl;
60    using ::E;
61}
62
63//--- use.cc
64import m1;
65import m2;
66void use();
67void use() {
68    E e = E1;
69    foo f;
70    f.consume(e, a);
71    func();
72    fwd_decl();
73}
74
75#ifndef WARNING
76// expected-no-diagnostics
77#else
78// expected-warning@* {{declaration 'E' is detected to be defined in multiple module units}}
79// expected-warning@* {{declaration 'foo' is detected to be defined in multiple module units}}
80// expected-warning@* {{declaration 'a' is detected to be defined in multiple module units}}
81// expected-warning@* {{declaration 'func' is detected to be defined in multiple module units}}
82// expected-note@* 1+ {{}}
83#endif
84