================
@@ -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;
----------------
t-a-james wrote:

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

I think the current status is:
- MSVC supports all pragma comment types
- GCC doesn't support any
- Clang supports `lib` for Linux, and all types when targeting Windows
- I haven't checked other compilers

(You can see this in the test files :) )

In my situation the user was only using `lib`, which Clang accepts on both 
Windows and Linux.  I wanted to write a check to forbid `#pragma comment(lib, 
some_lib)`, and when reading up on pragma comment realised there were a bunch 
more types I should catch.

I've phrased this as "not widely supported outside of MSVC", because my guess 
is that Clang only supports the different comment types for Windows because 
it's trying to be compatible with MSVC.  Outside of this MSVC-like context, 
Clang only supports one of these comment types on Linux, and GNU doesn't 
support any.

I use this phrase in 
`clang-tools-extra/docs/clang-tidy/checks/portability/avoid-pragma-comment.md` 
- would you like me to rephrase that to make it clearer? :)

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