38 lines · plain
1.. title:: clang-tidy - llvmlibc-implementation-in-namespace2 3llvmlibc-implementation-in-namespace4====================================5 6Checks that all declarations in the llvm-libc implementation are within the7correct namespace.8 9.. code-block:: c++10 11 // Implementation inside the LIBC_NAMESPACE_DECL namespace.12 // Correct if:13 // - LIBC_NAMESPACE_DECL is a macro14 // - LIBC_NAMESPACE_DECL expansion starts with `[[gnu::visibility("hidden")]] __llvm_libc`15 namespace LIBC_NAMESPACE_DECL {16 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}17 // Namespaces within LIBC_NAMESPACE_DECL namespace are allowed.18 namespace inner {19 int localVar = 0;20 }21 // Functions with C linkage are allowed.22 extern "C" void str_fuzz() {}23 }24 25 // Incorrect: implementation not in the LIBC_NAMESPACE_DECL namespace.26 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}27 28 // Incorrect: outer most namespace is not the LIBC_NAMESPACE_DECL macro.29 namespace something_else {30 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}31 }32 33 // Incorrect: outer most namespace expansion does not start with `[[gnu::visibility("hidden")]] __llvm_libc`.34 #define LIBC_NAMESPACE_DECL custom_namespace35 namespace LIBC_NAMESPACE_DECL {36 void LLVM_LIBC_ENTRYPOINT(strcpy)(char *dest, const char *src) {}37 }38