[clang-tools-extra] [clang-tidy] Create a check for signed and unsigned integers comparison (PR #113144)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 27 08:14:51 PDT 2024
================
@@ -0,0 +1,165 @@
+//===--- UseIntegerSignComparisonCheck.cpp - clang-tidy -------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "UseIntegerSignComparisonCheck.h"
+#include "clang/AST/Expr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::ast_matchers::internal;
+
+namespace clang::tidy::modernize {
+UseIntegerSignComparisonCheck::UseIntegerSignComparisonCheck(
+ StringRef Name, ClangTidyContext *Context)
+ : ClangTidyCheck(Name, Context),
+ IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+ utils::IncludeSorter::IS_LLVM),
+ areDiagsSelfContained()),
+ IsQtApplication(Options.get("IsQtApplication", false)),
+ StringsMatchHeader(Options.get("StringsMatchHeader", "<utility>")) {}
+
+void UseIntegerSignComparisonCheck::storeOptions(
+ ClangTidyOptions::OptionMap &Opts) {
+ Options.store(Opts, "IsQtApplication", IsQtApplication);
+ Options.store(Opts, "StringsMatchHeader", StringsMatchHeader);
----------------
5chmidti wrote:
If instead, you provide the header as an option and a namespace, then the check would be even more generic and the Qt module would not be needed (not saying a Qt module wouldn't make sense, just that this check may not require adding it). Though a quick look at boost, gsl and abseil did not show them having such functions.
(You could mention the settings for QT in the documentation as an example)
It would be best to check what others think, though. Thoughts?
https://github.com/llvm/llvm-project/pull/113144
More information about the cfe-commits
mailing list