File: warn-duplicated-decls-in-module-units.cppm

package info (click to toggle)
llvm-toolchain-snapshot 1%3A22~%2B%2B20250731080150%2Bbe449d6b6587-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,250,472 kB
  • sloc: cpp: 7,641,756; ansic: 1,439,220; asm: 1,072,591; python: 253,178; f90: 95,173; objc: 70,722; lisp: 44,365; pascal: 18,720; sh: 10,051; ml: 5,111; perl: 4,720; awk: 3,523; makefile: 3,397; javascript: 2,272; xml: 892; fortran: 783
file content (83 lines) | stat: -rw-r--r-- 2,033 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// RUN: rm -rf %t
// RUN: mkdir %t
// RUN: split-file %s %t
//
// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -emit-module-interface -o %t/m1.pcm
// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -emit-module-interface -o %t/m2.pcm
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \
// RUN:     -verify
//
// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -Wall -emit-module-interface -o %t/m1.pcm
// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -Wall -emit-module-interface -o %t/m2.pcm
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \
// RUN:     -verify -Wall
//
// RUN: %clang_cc1 -std=c++20 %t/m1.cppm -Wdecls-in-multiple-modules -emit-module-interface -o %t/m1.pcm
// RUN: %clang_cc1 -std=c++20 %t/m2.cppm -Wdecls-in-multiple-modules -emit-module-interface -o %t/m2.pcm
// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/use.cc -fsyntax-only \
// RUN:     -verify -Wdecls-in-multiple-modules -DWARNING

//--- foo.h
#ifndef FOO_H
#define FOO_H

enum E { E1, E2 };

int a = 43;

class foo {
public:
    void consume(E, int);
};

inline void func() {}

void fwd_decl();

#endif 

//--- m1.cppm
module;
#include "foo.h"
export module m1;
export {
    using ::foo;
    using ::a;
    using ::func;
    using ::fwd_decl;
    using ::E;
}

//--- m2.cppm
module;
#include "foo.h"
export module m2;
export {
    using ::foo;
    using ::a;
    using ::func;
    using ::fwd_decl;
    using ::E;
}

//--- use.cc
import m1;
import m2;
void use();
void use() {
    E e = E1;
    foo f;
    f.consume(e, a);
    func();
    fwd_decl();
}

#ifndef WARNING
// expected-no-diagnostics
#else
// expected-warning@* {{declaration 'E' is detected to be defined in multiple module units}}
// expected-warning@* {{declaration 'foo' is detected to be defined in multiple module units}}
// expected-warning@* {{declaration 'a' is detected to be defined in multiple module units}}
// expected-warning@* {{declaration 'func' is detected to be defined in multiple module units}}
// expected-note@* 1+ {{}}
#endif