[llvm-branch-commits] [libcxx] [libc++][modules] Fixes clang-tidy exports. (PR #76288)

Mark de Wever via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Dec 23 06:31:47 PST 2023


https://github.com/mordante created https://github.com/llvm/llvm-project/pull/76288

As suggested in #71438 we should use
  export import std;
in the std.compat module.

Using this exports some named declarations from functions and records, adding them to the global namespace. Clang correctly, does not export these it's and issue in the declaration filtering. Declarations in function or record context are not considered a global named declaration.

>From dd147d317c4a1d0f9f98113106c630a1feec4320 Mon Sep 17 00:00:00 2001
From: Mark de Wever <koraq at xs4all.nl>
Date: Sat, 23 Dec 2023 15:27:43 +0100
Subject: [PATCH] [libc++][modules] Fixes clang-tidy exports.

As suggested in #71438 we should use
  export import std;
in the std.compat module.

Using this exports some named declarations from functions and records,
adding them to the global namespace. Clang correctly, does not export
these it's and issue in the declaration filtering. Declarations in
function or record context are not considered a global named
declaration.
---
 .../clang_tidy_checks/header_exportable_declarations.cpp    | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
index 35f020da45c435..15d2e6839ad5e3 100644
--- a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
+++ b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp
@@ -252,9 +252,13 @@ static bool is_global_name_exported_by_std_module(std::string_view name) {
 
 static bool is_valid_declaration_context(
     const clang::NamedDecl& decl, std::string_view name, header_exportable_declarations::FileType file_type) {
-  if (decl.getDeclContext()->isNamespace())
+  const clang::DeclContext& context = *decl.getDeclContext();
+  if (context.isNamespace())
     return true;
 
+  if (context.isFunctionOrMethod() || context.isRecord())
+    return false;
+
   if (is_global_name_exported_by_std_module(name))
     return true;
 



More information about the llvm-branch-commits mailing list