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

source code of clang-tools-extra/test/clang-tidy/checkers/llvmlibc/implementation-in-namespace.cpp