Skip to content

Commit

Permalink
Remove Qt4 compatibility mode and last remaining check
Browse files Browse the repository at this point in the history
By now, almost everyone should use Qt5 or Qt6. And even if there are old
projects, this one check will not be a must-have for them.

The Qt4 mode is also AFAIK untested and not actively maintained. Thus we
should focus on the relevant parts that have a consumer impact.
  • Loading branch information
alex1701c committed Feb 11, 2024
1 parent 41360d6 commit de6653f
Show file tree
Hide file tree
Showing 30 changed files with 19 additions and 590 deletions.
1 change: 0 additions & 1 deletion CheckSources.generated.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ set(CLAZY_CHECKS_SRCS ${CLAZY_CHECKS_SRCS}
${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qstring-varargs.cpp
${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qt-keyword-emit.cpp
${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qt-keywords.cpp
${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qt4-qstring-from-array.cpp
${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qt6-deprecated-api-fixes.cpp
${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qt6-fwd-fixes.cpp
${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qt6-header-fixes.cpp
Expand Down
1 change: 0 additions & 1 deletion ClazyTests.generated.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ add_clazy_test(qrequiredresult-candidates)
add_clazy_test(qstring-varargs)
add_clazy_test(qt-keyword-emit)
add_clazy_test(qt-keywords)
add_clazy_test(qt4-qstring-from-array)
add_clazy_test(qt6-deprecated-api-fixes)
add_clazy_test(qt6-fwd-fixes)
add_clazy_test(qt6-header-fixes)
Expand Down
1 change: 0 additions & 1 deletion HOWTO
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Tips for fixits
functionargsbyref.cpp
autounexpectedqstringbuilder.cpp
qstringref.cpp
qt4-qstring-from-array.cpp

--------------------------------------------------------------------------------
Running tests
Expand Down
12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Table of contents
* [clazy-standalone and JSON database support](#clazy-standalone-and-json-database-support)
* [Enabling Fixits](#enabling-fixits)
* [Troubleshooting](#troubleshooting)
* [Qt4 compatibility mode](#qt4-compatibility-mode)
* [Reducing warning noise](#reducing-warning-noise)
* [Reporting bugs and wishes](#reporting-bugs-and-wishes)
* [Authors](#authors)
Expand Down Expand Up @@ -230,7 +229,6 @@ clazy runs all checks from level1 by default.
- [qstring-varargs](docs/checks/README-qstring-varargs.md)
- [qt-keyword-emit](docs/checks/README-qt-keyword-emit.md) (fix-qt-keyword-emit)
- [qt-keywords](docs/checks/README-qt-keywords.md) (fix-qt-keywords)
- [qt4-qstring-from-array](docs/checks/README-qt4-qstring-from-array.md) (fix-qt4-qstring-from-array)
- [qt6-deprecated-api-fixes](docs/checks/README-qt6-deprecated-api-fixes.md) (fix-qt6-deprecated-api-fixes)
- [qt6-fwd-fixes](docs/checks/README-qt6-fwd-fixes.md) (fix-qt6-fwd-fixes)
- [qt6-header-fixes](docs/checks/README-qt6-header-fixes.md) (fix-qt6-header-fixes)
Expand Down Expand Up @@ -432,16 +430,6 @@ with each other modifying the same source lines.
If you're building in 32-bit, open clazy-cl.bat and insert a -m32 argument.
Should read: %~dp0\clang\clang.exe –driver-mode=cl -m32 (...)

# Qt4 compatibility mode

When running on codebases that must still compile with Qt4, you can pass `--qt4compat`
(a convenience option equivalent to passing `-Xclang -plugin-arg-clazy -Xclang qt4-compat`)
to disable checks that only make sense with Qt5.

For example, to build a CMake project with Qt4 compatibility use:
`CXX="clazy --qt4compat"; cmake .`
and rebuild.

# Reducing warning noise

If you think you found a false-positive, file a bug report. But do make sure to test first without icecc/distcc enabled.
Expand Down
14 changes: 1 addition & 13 deletions checks.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"available_categories" : ["readability", "qt4", "qt6", "containers", "qstring", "cpp", "bug", "performance", "deprecation", "qml"],
"available_categories" : ["readability", "qt6", "containers", "qstring", "cpp", "bug", "performance", "deprecation", "qml"],
"checks" : [
{
"name" : "qt-keywords",
Expand Down Expand Up @@ -66,18 +66,6 @@
"categories" : ["bug"],
"visits_stmts" : true
},
{
"name" : "qt4-qstring-from-array",
"class_name" : "Qt4QStringFromArray",
"level" : -1,
"categories" : ["qt4", "qstring"],
"fixits" : [
{
"name" : "qt4-qstring-from-array"
}
],
"visits_stmts" : true
},
{
"name" : "qt6-qlatin1stringchar-to-u",
"class_name" : "Qt6QLatin1StringCharToU",
Expand Down
7 changes: 0 additions & 7 deletions clazy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ HELP() {
echo "Any of the options above will print the requested information and then exit."
echo
echo "Convenience Options:"
echo " --qt4compat Qt4 compatibility mode. useful for source code that can build with Qt4"
echo " (this is the same as passing \"-Xclang -plugin-arg-clazy -Xclang qt4-compat\")"
echo " --qtdeveloper Special option for building Qt5 itself resulting in fewer false positives"
echo " (this is the same as passing \"-Xclang -plugin-arg-clazy -Xclang qt-developer\")"
echo
Expand Down Expand Up @@ -100,11 +98,6 @@ then
fi

ExtraClangOptions=""
if ( test $# -gt 0 -a "$1" = "--qt4compat" )
then
shift
ExtraClangOptions="-Xclang -plugin-arg-clazy -Xclang qt4-compat"
fi
if ( test $# -gt 0 -a "$1" = "--qtdeveloper" )
then
shift
Expand Down
17 changes: 5 additions & 12 deletions dev-scripts/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ def readme_name(self):
def readme_path(self):
return docs_path() + self.readme_name()


def supportsQt4(self):
return self.minimum_qt_version < 50000

def get_class_name(self):
if self.class_name:
return self.class_name
Expand Down Expand Up @@ -259,21 +255,18 @@ def generate_register_checks(checks):
"""

for c in checks:
qt4flag = "RegisteredCheck::Option_None"
if not c.supportsQt4():
qt4flag = "RegisteredCheck::Option_Qt4Incompatible"

qtflags = "RegisteredCheck::Option_None"
if c.visits_stmts:
qt4flag += " | RegisteredCheck::Option_VisitsStmts"
qtflags += " | RegisteredCheck::Option_VisitsStmts"
if c.visits_decls:
qt4flag += " | RegisteredCheck::Option_VisitsDecls"
qtflags += " | RegisteredCheck::Option_VisitsDecls"

qt4flag = qt4flag.replace("RegisteredCheck::Option_None |", "")
qtflags = qtflags.replace("RegisteredCheck::Option_None |", "")

if c.ifndef:
text += "#ifndef " + c.ifndef + "\n"

text += ' registerCheck(check<%s>("%s", %s, %s));\n' % (c.get_class_name(), c.name, level_num_to_enum(c.level), qt4flag)
text += ' registerCheck(check<%s>("%s", %s, %s));\n' % (c.get_class_name(), c.name, level_num_to_enum(c.level), qtflags)

fixitID = 1
for fixit in c.fixits:
Expand Down
4 changes: 0 additions & 4 deletions docs/checks/README-qt4-qstring-from-array.md

This file was deleted.

13 changes: 0 additions & 13 deletions docs/man/clazy.pod
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,6 @@ Any of the options above will print the requested information and then exit.

=over 4

=item B<--qt4compat>

This option runs clazy in Qt4 compatibility mode.
Use this when your source code can build with Qt4 and Qt5 in order to easily
suppress issues that cannot be fixed due to the requirement of the Qt4 API.

This is a convenience option which is identical to directly passing:
"-Xclang -plugin-arg-clazy -Xclang qt4-compat"

=back

=over 4

=item B<--qtdeveloper>

B<For Qt developers only.> This option is special for running clazy on Qt itself.
Expand Down
1 change: 0 additions & 1 deletion readmes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ SET(README_manuallevel_FILES
${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qstring-varargs.md
${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qt-keyword-emit.md
${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qt-keywords.md
${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qt4-qstring-from-array.md
${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qt6-deprecated-api-fixes.md
${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qt6-fwd-fixes.md
${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qt6-header-fixes.md
Expand Down
13 changes: 5 additions & 8 deletions src/Checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
#include "checks/manuallevel/qstring-varargs.h"
#include "checks/manuallevel/qt-keyword-emit.h"
#include "checks/manuallevel/qt-keywords.h"
#include "checks/manuallevel/qt4-qstring-from-array.h"
#include "checks/manuallevel/qt6-deprecated-api-fixes.h"
#include "checks/manuallevel/qt6-fwd-fixes.h"
#include "checks/manuallevel/qt6-header-fixes.h"
Expand Down Expand Up @@ -136,8 +135,6 @@ void CheckManager::registerChecks()
registerFixIt(1, "fix-qt-keyword-emit", "qt-keyword-emit");
registerCheck(check<QtKeywords>("qt-keywords", ManualCheckLevel, RegisteredCheck::Option_None));
registerFixIt(1, "fix-qt-keywords", "qt-keywords");
registerCheck(check<Qt4QStringFromArray>("qt4-qstring-from-array", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts));
registerFixIt(1, "fix-qt4-qstring-from-array", "qt4-qstring-from-array");
registerCheck(
check<Qt6DeprecatedAPIFixes>("qt6-deprecated-api-fixes", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts | RegisteredCheck::Option_VisitsDecls));
registerFixIt(1, "fix-qt6-deprecated-api-fixes", "qt6-deprecated-api-fixes");
Expand Down Expand Up @@ -165,7 +162,7 @@ void CheckManager::registerChecks()
registerCheck(check<UseArrowOperatorInsteadOfData>("use-arrow-operator-instead-of-data", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<UseChronoInQTimer>("use-chrono-in-qtimer", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<ConnectByName>("connect-by-name", CheckLevel0, RegisteredCheck::Option_VisitsDecls));
registerCheck(check<ConnectNonSignal>("connect-non-signal", CheckLevel0, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts));
registerCheck(check<ConnectNonSignal>("connect-non-signal", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<ConnectNotNormalized>("connect-not-normalized", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<ContainerAntiPattern>("container-anti-pattern", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerCheck(check<EmptyQStringliteral>("empty-qstringliteral", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
Expand All @@ -183,10 +180,10 @@ void CheckManager::registerChecks()
#endif
registerCheck(check<QDateTimeUtc>("qdatetime-utc", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerFixIt(1, "fix-qdatetime-utc", "qdatetime-utc");
registerCheck(check<QEnums>("qenums", CheckLevel0, RegisteredCheck::Option_Qt4Incompatible));
registerCheck(check<QEnums>("qenums", CheckLevel0, RegisteredCheck::Option_None));
registerCheck(check<QFileInfoExists>("qfileinfo-exists", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerFixIt(1, "fix-qfileinfo-exists", "qfileinfo-exists");
registerCheck(check<QGetEnv>("qgetenv", CheckLevel0, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts));
registerCheck(check<QGetEnv>("qgetenv", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
registerFixIt(1, "fix-qgetenv", "qgetenv");
registerCheck(check<QMapWithPointerKey>("qmap-with-pointer-key", CheckLevel0, RegisteredCheck::Option_VisitsDecls));
registerCheck(check<QStringArg>("qstring-arg", CheckLevel0, RegisteredCheck::Option_VisitsStmts));
Expand Down Expand Up @@ -240,9 +237,9 @@ void CheckManager::registerChecks()
registerCheck(check<MissingQObjectMacro>("missing-qobject-macro", CheckLevel2, RegisteredCheck::Option_VisitsDecls));
registerFixIt(1, "fix-missing-qobject-macro", "missing-qobject-macro");
registerCheck(check<MissingTypeInfo>("missing-typeinfo", CheckLevel2, RegisteredCheck::Option_VisitsDecls));
registerCheck(check<OldStyleConnect>("old-style-connect", CheckLevel2, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts));
registerCheck(check<OldStyleConnect>("old-style-connect", CheckLevel2, RegisteredCheck::Option_VisitsStmts));
registerFixIt(1, "fix-old-style-connect", "old-style-connect");
registerCheck(check<QStringAllocations>("qstring-allocations", CheckLevel2, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts));
registerCheck(check<QStringAllocations>("qstring-allocations", CheckLevel2, RegisteredCheck::Option_VisitsStmts));
registerFixIt(1, "fix-qlatin1string-allocations", "qstring-allocations");
registerFixIt(2, "fix-fromLatin1_fromUtf8-allocations", "qstring-allocations");
registerFixIt(4, "fix-fromCharPtrAllocations", "qstring-allocations");
Expand Down
9 changes: 2 additions & 7 deletions src/Clazy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ bool ClazyASTAction::ParseArgs(const CompilerInstance &ci, const std::vector<std
m_options |= ClazyContext::ClazyOption_ExportFixes;
}

if (parseArgument("qt4-compat", args)) {
m_options |= ClazyContext::ClazyOption_Qt4Compat;
}

if (parseArgument("only-qt", args)) {
m_options |= ClazyContext::ClazyOption_OnlyQt;
}
Expand Down Expand Up @@ -273,7 +269,7 @@ bool ClazyASTAction::ParseArgs(const CompilerInstance &ci, const std::vector<std

{
std::lock_guard<std::mutex> lock(CheckManager::lock());
m_checks = m_checkManager->requestedChecks(args, m_options & ClazyContext::ClazyOption_Qt4Compat);
m_checks = m_checkManager->requestedChecks(args);
}

if (args.size() > 1) {
Expand Down Expand Up @@ -397,8 +393,7 @@ std::unique_ptr<ASTConsumer> ClazyStandaloneASTAction::CreateASTConsumer(Compile

std::vector<std::string> checks;
checks.push_back(m_checkList);
const bool qt4Compat = m_options & ClazyContext::ClazyOption_Qt4Compat;
const RegisteredCheck::List requestedChecks = cm->requestedChecks(checks, qt4Compat);
const RegisteredCheck::List requestedChecks = cm->requestedChecks(checks);

if (requestedChecks.empty()) {
llvm::errs() << "No checks were requested!\n"
Expand Down
1 change: 0 additions & 1 deletion src/ClazyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class ClazyContext
enum ClazyOption {
ClazyOption_None = 0,
ClazyOption_ExportFixes = 1,
ClazyOption_Qt4Compat = 2,
ClazyOption_OnlyQt = 4, // Ignore non-Qt files. This is done by bailing out if QT_CORE_LIB is not set.
ClazyOption_QtDeveloper = 8, // For running clazy on Qt itself, optional, but honours specific guidelines
ClazyOption_VisitImplicitCode = 16, // Inspect compiler generated code aswell, useful for custom checks, if they need it
Expand Down
8 changes: 1 addition & 7 deletions src/ClazyStandaloneMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ static cl::opt<std::string>
cl::init(""),
cl::cat(s_clazyCategory));

static cl::opt<bool> s_qt4Compat("qt4-compat", cl::desc("Turns off checks not compatible with Qt 4"), cl::init(false), cl::cat(s_clazyCategory));

static cl::opt<bool> s_onlyQt("only-qt",
cl::desc("Won't emit warnings for non-Qt files, or in other words, if -DQT_CORE_LIB is missing."),
cl::init(false),
Expand Down Expand Up @@ -113,10 +111,6 @@ class ClazyToolActionFactory : public clang::tooling::FrontendActionFactory
options |= ClazyContext::ClazyOption_ExportFixes;
}

if (s_qt4Compat.getValue()) {
options |= ClazyContext::ClazyOption_Qt4Compat;
}

if (s_qtDeveloper.getValue()) {
options |= ClazyContext::ClazyOption_QtDeveloper;
}
Expand Down Expand Up @@ -188,7 +182,7 @@ int main(int argc, const char **argv)
if (s_listEnabledChecks.getValue()) {
std::string checksFromArgs = s_checks.getValue();
std::vector<std::string> checks = {checksFromArgs.empty() ? "level1" : checksFromArgs};
const RegisteredCheck::List enabledChecks = CheckManager::instance()->requestedChecks(checks, s_qt4Compat.getValue());
const RegisteredCheck::List enabledChecks = CheckManager::instance()->requestedChecks(checks);

if (!enabledChecks.empty()) {
llvm::outs() << "Enabled checks:";
Expand Down
12 changes: 1 addition & 11 deletions src/checkmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static bool takeArgument(const std::string &arg, std::vector<std::string> &args)
return false;
}

RegisteredCheck::List CheckManager::requestedChecks(std::vector<std::string> &args, bool qt4Compat)
RegisteredCheck::List CheckManager::requestedChecks(std::vector<std::string> &args)
{
RegisteredCheck::List result;

Expand Down Expand Up @@ -200,16 +200,6 @@ RegisteredCheck::List CheckManager::requestedChecks(std::vector<std::string> &ar
clazy::sort_and_remove_dups(result, checkLessThan);
CheckManager::removeChecksFromList(result, userDisabledChecks);

if (qt4Compat) {
// #5 Remove Qt4 incompatible checks
result.erase(remove_if(result.begin(),
result.end(),
[](const RegisteredCheck &c) {
return c.options & RegisteredCheck::Option_Qt4Incompatible;
}),
result.end());
}

return result;
}

Expand Down
4 changes: 2 additions & 2 deletions src/checkmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct RegisteredFixIt {
using FactoryFunction = std::function<CheckBase *(ClazyContext *context)>;

struct RegisteredCheck {
enum Option { Option_None = 0, Option_Qt4Incompatible = 1, Option_VisitsStmts = 2, Option_VisitsDecls = 4 };
enum Option { Option_None = 0, Option_VisitsStmts = 2, Option_VisitsDecls = 4 };

using List = std::vector<RegisteredCheck>;
using Options = int;
Expand Down Expand Up @@ -101,7 +101,7 @@ class CheckManager
* Returns all the requested checks.
* This is a union of the requested checks via env variable and via arguments passed to compiler
*/
RegisteredCheck::List requestedChecks(std::vector<std::string> &args, bool qt4Compat);
RegisteredCheck::List requestedChecks(std::vector<std::string> &args);
std::vector<std::pair<CheckBase *, RegisteredCheck>> createChecks(const RegisteredCheck::List &requestedChecks, ClazyContext *context);

static void removeChecksFromList(RegisteredCheck::List &list, std::vector<std::string> &checkNames);
Expand Down
Loading

0 comments on commit de6653f

Please sign in to comment.