Debian Codegraph @

clang/test/Modules/warn-duplicated-decls-in-module-units.cppm

raw
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
24 enum E { E1, E2 };
25
26 int a = 43;
27
28 class foo {
29 public:
30 void consume(E, int);
31 };
32
33 inline void func() {}
34
35 void fwd_decl();
36
37 #endif
38
39 //--- m1.cppm
40 module;
41 #include "foo.h"
42 export module m1;
43 export {
44 using ::foo;
45 using ::a;
46 using ::func;
47 using ::fwd_decl;
48 using ::E;
49 }
50
51 //--- m2.cppm
52 module;
53 #include "foo.h"
54 export module m2;
55 export {
56 using ::foo;
57 using ::a;
58 using ::func;
59 using ::fwd_decl;
60 using ::E;
61 }
62
63 //--- use.cc
64 import m1;
65 import m2;
66 void use();
67 void 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