================
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_AVOIDPRAGMACOMMENTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_AVOIDPRAGMACOMMENTCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::portability {
+
+/// Finds uses of ``#pragma comment`` and for ``lib`` or ``linker`` comments
+/// suggests using the build system for improved portability.
+///
+/// Only the "lib" pragma comment type is implemented on Linux, the rest are
+/// Windows-only and should be caught by "-Wunknown-pragmas" on Linux.
+///
+/// For the user-facing documentation see:
+/// 
https://clang.llvm.org/extra/clang-tidy/checks/portability/avoid-pragma-comment.html
+class AvoidPragmaCommentCheck : public ClangTidyCheck {
+public:
+  AvoidPragmaCommentCheck(StringRef Name, ClangTidyContext *Context)
+      : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
+    return LangOpts.CPlusPlus;
----------------
zwuis wrote:

> Is the `-Wunknown-pragma` compiler warning enough?

You are right.

> `#pragma comment` is not widely supported outside of MSVC.

I was thinking about this. So this part of motivation doesn't make sense to me 
:)

---

> Regardless, I think `pragma comment` causes particular issues with 
> portability.  My project has quite complex dependency management tooling 
> (which tends to be tightly tied to the build system) and `pragma comment` 
> gives developers a way to sneak dependencies in through the back door.

Makes sense to me!

https://github.com/llvm/llvm-project/pull/215239
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to