Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Add IWYU export pragma annotations for improved clangd and clang-tidy diagnostics

Closed / Fixedc7dc599e73a7094298594c4383ad3524f009e6f8Created 1 year agoUpdated 1 year ago
Descriptionplain2025-10-24 16:16:13
Someone including the toplevel "tcl.h" header might get misc-include-cleaner warnings from the clangd language server and clang-tidy in their projects for some symbols that are only provided by the "tclDecls.h" or "tclPlatDecls.h" headers as they are not _directly_ included.
 
The annotation with IWYU pragmas fixes that and tells the tools that it should consider that these includes indeed should be considered as exporting the symbols and thus as if they directly provided the symbol

Documentation clangd and clang-tidy
https://clang.llvm.org/extra/clang-tidy/checks/misc/include-cleaner.html points to https://clangd.llvm.org/design/include-cleaner#iwyu-pragmas

This has been first implemented and docuemnted in the include-what-you-use project https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUPragmas.md#iwyu-pragma-begin_exportsend_exports

=== 8< === Patch ====

--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -2343,7 +2343,7 @@ EXTERN const char *TclZipfs_AppHook(int *argc, char ***argv);
  * table.
  */
 
-#include "tclDecls.h"
+#include "tclDecls.h"  /* IWYU pragma: export */
 
 /*
  * Include platform specific public function declarations that are accessible
@@ -2356,7 +2356,7 @@ EXTERN const char *TclZipfs_AppHook(int *argc, char ***argv);
 #   define TCLAPI MODULE_SCOPE
 #endif
 
-#include "tclPlatDecls.h"
+#include "tclPlatDecls.h"  /* IWYU pragma: export */
 
 /*
  *----------------------------------------------------------------------------
Referenced by3
  • f70d9ef874[c7dc599e73] follow-up: for tclOO and internal headers too check-in2025-10-26 21:05:23
  • 0aa8b5e70d[c7dc599e73]: Add IWYU export pragma annotations for improved clangd and clang-tidy diagnostics check-in2025-10-25 22:19:11
  • 6fde69d19f[c7dc599e73]: Add IWYU export pragma annotations for improved clangd and clang-tidy diagnostics check-in2025-10-25 12:45:12
jan.nijtmanswiki2025-10-28 10:50:02

Added now for all *Decls.h inclusions. Also done for itcl and tdbc.

Log in (anonymous is fine) to add a comment.