1 | // RUN: %check_clang_tidy %s llvmlibc-implementation-in-namespace %t |
2 | |
3 | #define MACRO_A "defining macros outside namespace is valid" |
4 | |
5 | class ClassB; |
6 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace |
7 | struct StructC {}; |
8 | // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace |
9 | char *VarD = MACRO_A; |
10 | // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace |
11 | typedef int typeE; |
12 | // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace |
13 | void funcF() {} |
14 | // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace |
15 | |
16 | namespace outer_most { |
17 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE' macro |
18 | class A {}; |
19 | } |
20 | |
21 | // Wrapped in anonymous namespace. |
22 | namespace { |
23 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: declaration must be enclosed within the 'LIBC_NAMESPACE' namespace |
24 | class A {}; |
25 | } |
26 | |
27 | namespace namespaceG { |
28 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE' macro |
29 | namespace __llvm_libc { |
30 | namespace namespaceH { |
31 | class ClassB; |
32 | } // namespace namespaceH |
33 | struct StructC {}; |
34 | } // namespace __llvm_libc |
35 | char *VarD = MACRO_A; |
36 | typedef int typeE; |
37 | void funcF() {} |
38 | } // namespace namespaceG |
39 | |
40 | // Wrapped in macro namespace but with an incorrect name |
41 | #define LIBC_NAMESPACE custom_namespace |
42 | namespace LIBC_NAMESPACE { |
43 | // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the 'LIBC_NAMESPACE' macro should start with '__llvm_libc' |
44 | namespace namespaceH { |
45 | class ClassB; |
46 | } // namespace namespaceH |
47 | } // namespace LIBC_NAMESPACE |
48 | |
49 | |
50 | // Wrapped in macro namespace with a valid name, LIBC_NAMESPACE starts with '__llvm_libc' |
51 | #undef LIBC_NAMESPACE |
52 | #define LIBC_NAMESPACE __llvm_libc_xyz |
53 | namespace LIBC_NAMESPACE { |
54 | namespace namespaceI { |
55 | class ClassB; |
56 | } // namespace namespaceI |
57 | struct StructC {}; |
58 | char *VarD = MACRO_A; |
59 | typedef int typeE; |
60 | void funcF() {} |
61 | extern "C" void extern_funcJ() {} |
62 | } // namespace LIBC_NAMESPACE |
63 | |