[llvm-branch-commits] [clang-tidy] Add FixIts for libc namespace macros (PR #99681)

Julian Schmidt via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Jul 20 10:00:23 PDT 2024


================
@@ -41,8 +50,26 @@ void ImplementationInNamespaceCheck::check(
 
   // Enforce that the namespace is the result of macro expansion
   if (Result.SourceManager->isMacroBodyExpansion(NS->getLocation()) == false) {
-    diag(NS->getLocation(), "the outermost namespace should be the '%0' macro")
-        << RequiredNamespaceDeclMacroName;
+    auto DB = diag(NS->getLocation(),
+                   "the outermost namespace should be the '%0' macro")
+              << RequiredNamespaceDeclMacroName;
+
+    // TODO: Determine how to split inline namespaces correctly in the FixItHint
+    //
+    // We can't easily replace LIBC_NAMEPACE::inner::namespace { with
+    //
+    // namespace LIBC_NAMEPACE_DECL {
+    //   namespace inner::namespace {
----------------
5chmidti wrote:

I think this is doable, but the `MACRO` in `namespace MACRO::foo::bar` could be a nested namespace as well (`#define MACRO my::namespace`).

You would likely have to go through the lexer and check if the next tokens are `::`, and take these locations (with offset 1) as the range to be removed/changed. Should the outer libc namespace be on its own like in this example, or is a replacement from `LIBC_NAMESPACE::inner::namespace` to `LIBC_NAMESPACE_DECL::inner::namespace` fine?

FYI: `LIBC_NAMEPACE_DECL` -> `LIBC_NAMESPACE_DECL` (missing `S` twice)

https://github.com/llvm/llvm-project/pull/99681


More information about the llvm-branch-commits mailing list