Skip to content

Commit 18e276e

Browse files
committed
[clang-tidy] Add QtEnabled option to modernize-use-integer-sign-comparison
- rename QtEnabled option to EnableQtSupport
1 parent fcd7768 commit 18e276e

File tree

5 files changed

+13
-12
lines changed

5 files changed

+13
-12
lines changed

clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ UseIntegerSignComparisonCheck::UseIntegerSignComparisonCheck(
8181
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
8282
utils::IncludeSorter::IS_LLVM),
8383
areDiagsSelfContained()),
84-
QtFrameworkEnabled(Options.get("QtEnabled", false)) {}
84+
EnableQtSupport(Options.get("EnableQtSupport", false)) {}
8585

8686
void UseIntegerSignComparisonCheck::storeOptions(
8787
ClangTidyOptions::OptionMap &Opts) {
8888
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
89-
Options.store(Opts, "QtEnabled", QtFrameworkEnabled);
89+
Options.store(Opts, "EnableQtSupport", EnableQtSupport);
9090
}
9191

9292
void UseIntegerSignComparisonCheck::registerMatchers(MatchFinder *Finder) {
@@ -157,15 +157,16 @@ void UseIntegerSignComparisonCheck::check(
157157
diag(BinaryOp->getBeginLoc(),
158158
"comparison between 'signed' and 'unsigned' integers");
159159
std::string CmpNamespace;
160-
std::string CmpHeader;
161-
if (getLangOpts().CPlusPlus17 && QtFrameworkEnabled) {
162-
CmpHeader = "<QtCore/q20utility.h>";
163-
CmpNamespace = llvm::Twine("q20::" + parseOpCode(OpCode)).str();
164-
}
160+
llvm::StringRef CmpHeader;
161+
165162
if (getLangOpts().CPlusPlus20) {
166163
CmpHeader = "<utility>";
167164
CmpNamespace = llvm::Twine("std::" + parseOpCode(OpCode)).str();
165+
} else if (getLangOpts().CPlusPlus17 && EnableQtSupport) {
166+
CmpHeader = "<QtCore/q20utility.h>";
167+
CmpNamespace = llvm::Twine("q20::" + parseOpCode(OpCode)).str();
168168
}
169+
169170
// Prefer modernize-use-integer-sign-comparison when C++20 is available!
170171
Diag << FixItHint::CreateReplacement(
171172
CharSourceRange(R1, SubExprLHS != nullptr),

clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class UseIntegerSignComparisonCheck : public ClangTidyCheck {
3030
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3131
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3232
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
33-
return LangOpts.CPlusPlus20 || (LangOpts.CPlusPlus17 && QtFrameworkEnabled);
33+
return LangOpts.CPlusPlus20 || (LangOpts.CPlusPlus17 && EnableQtSupport);
3434
}
3535

3636
private:
3737
utils::IncludeInserter IncludeInserter;
38-
const bool QtFrameworkEnabled;
38+
const bool EnableQtSupport;
3939
};
4040

4141
} // namespace clang::tidy::modernize

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Changes in existing checks
303303

304304
- Improved :doc:`modernize-use-integer-sign-comparison
305305
<clang-tidy/checks/modernize/use-integer-sign-comparison>` check to
306-
add an option ``QtEnabled``, that makes C++17 ``q20::cmp_*`` alternative
306+
add an option ``EnableQtSupport``, that makes C++17 ``q20::cmp_*`` alternative
307307
available for Qt-based applications.
308308

309309
- Improved :doc:`modernize-use-nullptr

clang-tools-extra/docs/clang-tidy/checks/modernize/use-integer-sign-comparison.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Options
3535
A string specifying which include-style is used, `llvm` or `google`.
3636
Default is `llvm`.
3737

38-
.. option:: QtEnabled
38+
.. option:: EnableQtSupport
3939

4040
Makes C++17 ``q20::cmp_*`` alternative available for Qt-based
4141
applications. Default is `false`.

clang-tools-extra/test/clang-tidy/checkers/modernize/use-integer-sign-comparison-qt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// CHECK-FIXES: #include <QtCore/q20utility.h>
22
// RUN: %check_clang_tidy -std=c++17 %s modernize-use-integer-sign-comparison %t -- \
3-
// RUN: -config="{CheckOptions: {modernize-use-integer-sign-comparison.QtEnabled: true}}"
3+
// RUN: -config="{CheckOptions: {modernize-use-integer-sign-comparison.EnableQtSupport: true}}"
44

55
// The code that triggers the check
66
#define MAX_MACRO(a, b) (a < b) ? b : a

0 commit comments

Comments
 (0)