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_DECL' namespace 7 struct StructC {}; 8 // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace 9 const char *VarD = MACRO_A; 10 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace 11 typedef int typeE; 12 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace 13 void funcF() {} 14 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace 15 16 namespace outer_most { 17 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE_DECL' 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_DECL' namespace 24 class A {}; 25 } 26 27 namespace namespaceG { 28 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the outermost namespace should be the 'LIBC_NAMESPACE_DECL' macro 29 namespace __llvm_libc { 30 namespace namespaceH { 31 class ClassB; 32 } // namespace namespaceH 33 struct StructC {}; 34 } // namespace __llvm_libc 35 const 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_DECL [[gnu::visibility("hidden")]] custom_namespace 42 namespace LIBC_NAMESPACE_DECL { 43 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the 'LIBC_NAMESPACE_DECL' macro expansion should start with '__llvm_libc' 44 45 namespace namespaceH { 46 class ClassB; 47 } // namespace namespaceH 48 } // namespace LIBC_NAMESPACE_DECL 49 50 51 // Wrapped in macro namespace with a valid name, LIBC_NAMESPACE_DECL starts with '__llvm_libc' 52 #undef LIBC_NAMESPACE_DECL 53 #define LIBC_NAMESPACE_DECL [[gnu::visibility("hidden")]] __llvm_libc_xyz 54 namespace LIBC_NAMESPACE_DECL { 55 namespace namespaceI { 56 class ClassB; 57 } // namespace namespaceI 58 struct StructC {}; 59 const char *VarD = MACRO_A; 60 typedef int typeE; 61 void funcF() {} 62 extern "C" void extern_funcJ() {} 63 } // namespace LIBC_NAMESPACE_DECL 64