diff --git a/CheckSources.cmake b/CheckSources.cmake index 69f0529..5f8d3d6 100644 --- a/CheckSources.cmake +++ b/CheckSources.cmake @@ -1,86 +1,86 @@ set(CLAZY_CHECKS_SRCS ${CLAZY_CHECKS_SRCS} ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/assert-with-side-effects.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/container-inside-loop.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/detaching-member.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/ifndef-define-typo.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/inefficient-qlist.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/isempty-vs-count.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qhash-with-char-pointer-key.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qrequiredresult-candidates.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/qstring-varargs.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/qvariant-template-instantiation.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/raw-environment-function.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/reserve-candidates.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/thread-with-slots.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/tr-non-literal.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/manuallevel/unneeded-cast.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/connect-by-name.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/connect-non-signal.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/connect-not-normalized.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/container-anti-pattern.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/empty-qstringliteral.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/fully-qualified-moc-types.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/lambda-in-connect.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/lambda-unique-connection.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/lowercase-qml-type-name.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/mutable-container-key.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qcolor-from-literal.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qdatetime-utc.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qenums.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qfileinfo-exists.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qgetenv.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qmap-with-pointer-key.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qstring-arg.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qstring-insensitive-allocation.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qstring-ref.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qt-macros.cpp - ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/qvariant-template-instantiation.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/strict-iterators.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/temporary-iterator.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/unused-non-trivial-variable.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/writing-to-temporary.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/wrong-qevent-cast.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level0/wrong-qglobalstatic.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/auto-unexpected-qstringbuilder.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/child-event-qobject-cast.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/connect-3arg-lambda.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/const-signal-or-slot.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/detaching-temporary.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/foreach.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/incorrect-emit.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/inefficient-qlist-soft.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/install-event-filter.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/non-pod-global-static.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/overridden-signal.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/post-event.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/qdeleteall.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/qhash-namespace.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/qlatin1string-non-ascii.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/qproperty-without-notify.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/qstring-left.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/range-loop.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/returning-data-from-temporary.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/rule-of-two-soft.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/skipped-base-method.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level1/virtual-signal.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/base-class-event.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/copyable-polymorphic.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/ctor-missing-parent-argument.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/function-args-by-ref.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/function-args-by-value.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/global-const-char-pointer.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/implicit-casts.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/missing-qobject-macro.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/missing-typeinfo.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/old-style-connect.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/qstring-allocations.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/returning-void-expression.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/rule-of-three.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/static-pmf.cpp ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/virtual-call-ctor.cpp ) if(HAS_STD_REGEX OR CLAZY_BUILD_WITH_CLANG) set(CLAZY_CHECKS_SRCS ${CLAZY_CHECKS_SRCS} ${CMAKE_CURRENT_LIST_DIR}/src/checks/level2/old-style-connect.cpp) endif() diff --git a/README.md b/README.md index 62e44e9..4c13b62 100644 --- a/README.md +++ b/README.md @@ -1,483 +1,483 @@ *WARNING:* master is the development branch. Please use the v1.5 branch. clazy v1.6 =========== clazy is a compiler plugin which allows clang to understand Qt semantics. You get more than 50 Qt related compiler warnings, ranging from unneeded memory allocations to misusage of API, including fix-its for automatic refactoring. Table of contents ================= * [Source Code](#source-code) * [Pre-built binaries](#pre-built-binaries) * [Build Instructions](#build-instructions) * [Linux](#linux) * [Install dependencies](#install-dependencies) * [Build and install clang](#build-and-install-clang) * [Build clazy](#build-clazy) * [Windows](#windows) * [Build and install clang](#build-and-install-clang-1) * [Build clazy](#build-clazy-1) * [macOS with MacPorts](#macos-with-macports) * [Install clang](#install-clang) * [Build clazy](#build-clazy-2) * [macOS with Homebrew](#macos-with-homebrew) * [Install clang](#install-clang-1) * [Build clazy](#build-clazy-3) * [Setting up your project to build with clazy](#setting-up-your-project-to-build-with-clazy) * [List of checks](#list-of-checks) * [Selecting which checks to enable](#selecting-which-checks-to-enable) * [Example via env variable](#example-via-env-variable) * [Example via compiler argument](#example-via-compiler-argument) * [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) * [Contributing patches](#contributing-patches) # Source Code You can get clazy from: - - git@git.kde.org:clazy - git://anongit.kde.org/clazy # Pre-built binaries Pre-built binaries are produced by KDAB, you can get them from https://downloads.kdab.com/clazy/. Currently MSVC2015, MSVC2017 (based on clang-7.0) and Linux AppImage packages (based on clang-8.0) are provided. # Build Instructions ## Linux ### Install dependencies - OpenSUSE tumbleweed: `zypper install cmake git-core llvm llvm-devel llvm-clang llvm-clang-devel` - Ubuntu: `apt install g++ cmake clang llvm-dev git-core libclang-dev` - Archlinux: `pacman -S make llvm clang python2 cmake git gcc` - Fedora: be sure to *remove* the llvm-static package and only install the one with dynamic libraries - Other distros: Check llvm/clang build docs. ### Build and install clang clang and LLVM >= 4.0 are required. Use clazy v1.1 if you need 3.7 support, or v1.3 for 3.8 support. If your distro provides clang then you can skip this step. ``` $ git clone https://github.com/llvm-mirror/llvm.git $ cd /tools/ && git clone https://github.com/llvm-mirror/clang.git $ cd /projects && git clone https://github.com/llvm-mirror/compiler-rt.git $ mkdir /build && cd /build $ cmake -DCMAKE_INSTALL_PREFIX= -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=Release .. $ make -jX && make install ``` ### Build clazy ``` $ cd clazy/ $ cmake -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=Release $ make && make install ``` See troubleshooting section if you have problems. ## Windows ### Build and install clang These instructions assume your terminal is suitable for development (msvc2015). jom, nmake, git, cmake and cl should be in your PATH. clang and LLVM >= 4.0 are required. Be sure to pass -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON to CMake when building LLVM, otherwise clazy won't work. ``` > git clone https://github.com/llvm-mirror/llvm.git > cd \tools\ && git clone https://github.com/llvm-mirror/clang.git > git checkout release_40 > cd clang > git checkout release_40 > mkdir \build && cd \build > cmake -DCMAKE_INSTALL_PREFIX=c:\my_install_folder\llvm\ -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles JOM" .. > jom > nmake install > Add c:\my_install_folder\llvm\bin\ to PATH ``` ### Build clazy Be sure to point CLANG_LIBRARY_IMPORT to clang.lib. It's probably inside your LLVM build dir since it doesn't get installed. ``` > cd clazy\ > cmake -DCMAKE_INSTALL_PREFIX=c:\my_install_folder\llvm\ -DCLANG_LIBRARY_IMPORT=C:\path\to\llvm-build\lib\clang.lib -DCMAKE_BUILD_TYPE=Release -G "NMake Makefiles JOM" > jom && nmake install ``` ## macOS with MacPorts ### Install clang ``` $ sudo port install clang-3.9 llvm-3.9 $ sudo ln -sf /opt/local/bin/llvm-config-mp-3.9 /opt/local/bin/llvm-config $ sudo port select --set clang mp-clang-3.9 ``` ### Build clazy ``` $ export CXX=clang++ $ cmake $ make $ make install ``` ## macOS with Homebrew The recommended way is to build clazy yourself, but alternatively you can try user recipes, such as: ``` $ brew install kde-mac/kde/clazy ``` for stable branch, or for master: ``` $ brew install kde-mac/kde/clazy --HEAD ``` As these are not verified or tested by the clazy developers please don't report bugs to us. For building yourself, read on. You'll have to install clang and build clazy from source. ### Install clang ``` $ brew install --with-clang llvm ``` ### Build clazy ``` $ export CXX=clang++ $ export LLVM_ROOT=/usr/local/opt/llvm $ cmake $ make $ make install ``` # Setting up your project to build with clazy Note: Wherever `clazy` is mentioned, replace with `clazy-cl.bat` if you're on Windows, or replace with `Clazy-x86_64.AppImage` if you're using AppImage. Note: If you prefer running clazy over a JSON compilation database instead of using it as a plugin, jump to [clazy-standalone](#clazy-standalone-and-json-database-support). You should now have the clazy command available to you, in `/bin/`. Compile your programs with it instead of clang++/g++. Note that this command is just a convenience wrapper which calls: `clang++ -Xclang -load -Xclang ClazyPlugin.so -Xclang -add-plugin -Xclang clazy` If you have multiple versions of clang installed (say clang++-3.8 and clang++-3.9) you can choose which one to use by setting the CLANGXX environment variable, like so: `export CLANGXX=clang++-3.8; clazy` To build a CMake project use: `cmake . -DCMAKE_CXX_COMPILER=clazy` and rebuild. To make it the compiler for qmake projects, just run qmake like: `qmake -spec linux-clang QMAKE_CXX="clazy"` On Windows with MSVC it's simply: `qmake QMAKE_CXX="clazy-cl.bat"` Alternatively, if you want to use clang directly, without the wrapper: `qmake -spec linux-clang QMAKE_CXXFLAGS="-Xclang -load -Xclang ClazyPlugin.so -Xclang -add-plugin -Xclang clazy"` On Windows it's similar, just inspect the contents of `clazy-cl.bat`. It's recommended that you disable pre-compiled headers and don't use ccache. You're all set, clazy will now run some checks on your project, but not all of them. Read on if you want to enable/disable which checks are run. # List of checks There are many checks and they are divided in levels: - level0: Very stable checks, 99.99% safe, mostly no false-positives, very desirable - level1: The default level. Very similar to level 0, slightly more false-positives but very few. - level2: Also very few false-positives, but contains noisy checks which not everyone agree should be default. - manual: Checks here need to be enabled explicitly, as they don't belong to any level. They can be very stable or very unstable. clazy runs all checks from level1 by default. - Checks from Manual Level: - [assert-with-side-effects](docs/checks/README-assert-with-side-effects.md) - [container-inside-loop](docs/checks/README-container-inside-loop.md) - [detaching-member](docs/checks/README-detaching-member.md) - [ifndef-define-typo](docs/checks/README-ifndef-define-typo.md) - [inefficient-qlist](docs/checks/README-inefficient-qlist.md) - [isempty-vs-count](docs/checks/README-isempty-vs-count.md) - [qhash-with-char-pointer-key](docs/checks/README-qhash-with-char-pointer-key.md) - [qrequiredresult-candidates](docs/checks/README-qrequiredresult-candidates.md) - [qstring-varargs](docs/checks/README-qstring-varargs.md) - [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) + - [qvariant-template-instantiation](docs/checks/README-qvariant-template-instantiation.md) - [raw-environment-function](docs/checks/README-raw-environment-function.md) - [reserve-candidates](docs/checks/README-reserve-candidates.md) - [thread-with-slots](docs/checks/README-thread-with-slots.md) - [tr-non-literal](docs/checks/README-tr-non-literal.md) - [unneeded-cast](docs/checks/README-unneeded-cast.md) - Checks from Level 0: - [connect-by-name](docs/checks/README-connect-by-name.md) - [connect-non-signal](docs/checks/README-connect-non-signal.md) - [connect-not-normalized](docs/checks/README-connect-not-normalized.md) - [container-anti-pattern](docs/checks/README-container-anti-pattern.md) - [empty-qstringliteral](docs/checks/README-empty-qstringliteral.md) - [fully-qualified-moc-types](docs/checks/README-fully-qualified-moc-types.md) - [lambda-in-connect](docs/checks/README-lambda-in-connect.md) - [lambda-unique-connection](docs/checks/README-lambda-unique-connection.md) - [lowercase-qml-type-name](docs/checks/README-lowercase-qml-type-name.md) - [mutable-container-key](docs/checks/README-mutable-container-key.md) - [qcolor-from-literal](docs/checks/README-qcolor-from-literal.md) - [qdatetime-utc](docs/checks/README-qdatetime-utc.md) (fix-qdatetime-utc) - [qenums](docs/checks/README-qenums.md) - [qfileinfo-exists](docs/checks/README-qfileinfo-exists.md) - [qgetenv](docs/checks/README-qgetenv.md) (fix-qgetenv) - [qmap-with-pointer-key](docs/checks/README-qmap-with-pointer-key.md) - [qstring-arg](docs/checks/README-qstring-arg.md) - [qstring-insensitive-allocation](docs/checks/README-qstring-insensitive-allocation.md) - [qstring-ref](docs/checks/README-qstring-ref.md) (fix-missing-qstringref) - [qt-macros](docs/checks/README-qt-macros.md) - - [qvariant-template-instantiation](docs/checks/README-qvariant-template-instantiation.md) - [strict-iterators](docs/checks/README-strict-iterators.md) - [temporary-iterator](docs/checks/README-temporary-iterator.md) - [unused-non-trivial-variable](docs/checks/README-unused-non-trivial-variable.md) - [writing-to-temporary](docs/checks/README-writing-to-temporary.md) - [wrong-qevent-cast](docs/checks/README-wrong-qevent-cast.md) - [wrong-qglobalstatic](docs/checks/README-wrong-qglobalstatic.md) - Checks from Level 1: - [auto-unexpected-qstringbuilder](docs/checks/README-auto-unexpected-qstringbuilder.md) (fix-auto-unexpected-qstringbuilder) - [child-event-qobject-cast](docs/checks/README-child-event-qobject-cast.md) - [connect-3arg-lambda](docs/checks/README-connect-3arg-lambda.md) - [const-signal-or-slot](docs/checks/README-const-signal-or-slot.md) - [detaching-temporary](docs/checks/README-detaching-temporary.md) - [foreach](docs/checks/README-foreach.md) - [incorrect-emit](docs/checks/README-incorrect-emit.md) - [inefficient-qlist-soft](docs/checks/README-inefficient-qlist-soft.md) - [install-event-filter](docs/checks/README-install-event-filter.md) - [non-pod-global-static](docs/checks/README-non-pod-global-static.md) - [overridden-signal](docs/checks/README-overridden-signal.md) - [post-event](docs/checks/README-post-event.md) - [qdeleteall](docs/checks/README-qdeleteall.md) - [qhash-namespace](docs/checks/README-qhash-namespace.md) - [qlatin1string-non-ascii](docs/checks/README-qlatin1string-non-ascii.md) - [qproperty-without-notify](docs/checks/README-qproperty-without-notify.md) - [qstring-left](docs/checks/README-qstring-left.md) - [range-loop](docs/checks/README-range-loop.md) (fix-range-loop-add-ref,fix-range-loop-add-qasconst) - [returning-data-from-temporary](docs/checks/README-returning-data-from-temporary.md) - [rule-of-two-soft](docs/checks/README-rule-of-two-soft.md) - [skipped-base-method](docs/checks/README-skipped-base-method.md) - [virtual-signal](docs/checks/README-virtual-signal.md) - Checks from Level 2: - [base-class-event](docs/checks/README-base-class-event.md) - [copyable-polymorphic](docs/checks/README-copyable-polymorphic.md) - [ctor-missing-parent-argument](docs/checks/README-ctor-missing-parent-argument.md) - [function-args-by-ref](docs/checks/README-function-args-by-ref.md) (fix-function-args-by-ref) - [function-args-by-value](docs/checks/README-function-args-by-value.md) - [global-const-char-pointer](docs/checks/README-global-const-char-pointer.md) - [implicit-casts](docs/checks/README-implicit-casts.md) - [missing-qobject-macro](docs/checks/README-missing-qobject-macro.md) - [missing-typeinfo](docs/checks/README-missing-typeinfo.md) - [old-style-connect](docs/checks/README-old-style-connect.md) (fix-old-style-connect) - [qstring-allocations](docs/checks/README-qstring-allocations.md) (fix-qlatin1string-allocations,fix-fromLatin1_fromUtf8-allocations,fix-fromCharPtrAllocations) - [returning-void-expression](docs/checks/README-returning-void-expression.md) - [rule-of-three](docs/checks/README-rule-of-three.md) - [static-pmf](docs/checks/README-static-pmf.md) - [virtual-call-ctor](docs/checks/README-virtual-call-ctor.md) # Selecting which checks to enable You may want to choose which checks to enable before starting to compile. If you don't specify anything then all checks from level0 and level1 will run. To specify a list of checks to run, or to choose a level, you can use the `CLAZY_CHECKS` env variable or pass arguments to the compiler. You can disable checks by prefixing with `no-`, in case you don't want all checks from a given level. ## Example via env variable ``` export CLAZY_CHECKS="unneeded-cast,qmap-with-key-pointer,virtual-call-ctor" # Enables only these 3 checks export CLAZY_CHECKS="level0,no-qenums" # Enables all checks from level0, except for qenums export CLAZY_CHECKS="level0,detaching-temporary" # Enables all from level0 and also detaching-temporary ``` ## Example via compiler argument `clazy -Xclang -plugin-arg-clazy -Xclang level0,detaching-temporary` Don't forget to re-run cmake/qmake/etc if you altered the c++ flags to specify flags. # clazy-standalone and JSON database support The `clazy-standalone` binary allows you to run clazy over a compilation database JSON file, in the same way you would use `clang-tidy` or other clang tooling. This way you don't need to build your application, only the static analysis is performed. Note: If you're using the AppImage, use `Clazy-x86_64.AppImage --standalone` instead of `clazy-standalone`. `clazy-standalone` supports the same env variables as the clazy plugin. You can also specify a list of checks via the `-checks` argument. Running on one cpp file: `clazy-standalone -checks=install-event-filter,qmap-with-pointer-key,level0 -p compile_commands.json my.file.cpp` Running on all cpp files: `find . -name "*cpp" | xargs clazy-standalone -checks=level2 -p default/compile_commands.json` See https://clang.llvm.org/docs/JSONCompilationDatabase.html for how to generate the compile_commands.json file. Basically it's generated by passing `-DCMAKE_EXPORT_COMPILE_COMMANDS` to CMake, or using [Bear](https://github.com/rizsotto/Bear) to intercept compiler commands, or, if you're using `qbs`: `qbs generate --generator clangdb` **Note:** Be sure the clazy-standalone binary is located in the same folder as the clang binary, otherwise it will have trouble finding builtin headers, like stddef.h. Alternatively, you can symlink to the folder containing the builtin headers: (Assuming clazy was built with `-DCMAKE_INSTALL_PREFIX=/myprefix/`) ``` $ touch foo.c && clang++ '-###' -c foo.c 2>&1 | tr ' ' '\n' | grep -A1 resource "-resource-dir" "/usr/bin/../lib/clang/4.0.1" # this is the interesting path (without the version) $ ln -sf /usr/bin/../lib/clang/ /myprefix/lib/clang $ ln -sf /usr/bin/../include/c++/ /myprefix/include/c++ # Required on macOS ``` If that doesn't work, run `clang -v` and check what's the InstalledDir. Move clazy-standalone to that folder. `clang-tidy` support will be added after is fixed. # Enabling Fixits Some checks support fixits, in which clazy will help re-write your source files whenever it can fix something. Simply pass `-Xclang -plugin-arg-clazy -Xclang export-fixes` to clang, or `-export-fixes=somefile.yaml` for `clazy-standalone`. Alternatively, set the `CLAZY_EXPORT_FIXES` env variable (works only with the plugin, not with standalone). Then run `clang-apply-replacements `, which will modify your code. When using fixits, prefer to run only a single check each time, so they don't conflict with each other modifying the same source lines. **WARNING**: Backup your code and make sure all changes done by clazy are correct. # Troubleshooting - clang: symbol lookup error: `/usr/lib/x86_64-linux-gnu/ClazyPlugin.so: undefined symbol: _ZNK5clang15DeclarationName11getAsStringEv`. This is due to mixing ABIs. Your clang/llvm was compiled with the [new gcc c++ ABI][1] but you compiled the clazy plugin with clang (which uses [the old ABI][2]). The solution is to build the clazy plugin with gcc or use a distro which hasn't migrated to gcc5 ABI yet, such as archlinux. [1]: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html [2]: https://llvm.org/bugs/show_bug.cgi?id=23529 - [Fedora] cmake can't find LLVM ? Try building llvm/clang yourself (There are reports that /usr/share/llvm/cmake/LLVM-Config.cmake is buggy). - [Fedora] CommandLine Error: `Option 'opt-bisect-limit' registered more than once!` Remove the llvm-static package and use the dynamically linked libraries instead. Alternatively, if you want to use llvm-static, see next item. - CommandLine Error: `Option 'foo' registered more than once!` Means you're building against a static version of LLVM (*.a files instead of *.so). Try passing to cmake -DLINK_CLAZY_TO_LLVM=OFF when building clazy, this was tested successfully against a static LLVM 7.0, and might work with other versions. - Some checks are mysteriously not producing warnings or not applying fixits ? Check if you have ccache interfering and turn it off. - fatal error: 'stddef.h' file not found, while using `clazy-standalone` Be sure the clazy-standalone binary is located in the same folder as the clang binary. - Be sure to disble pch. - macOS: Be sure you're not using Apple Clang - Windows: fatal error LNK1112: module machine type ‘X86’ conflicts with target machine type ‘x64’ 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. If you want to suppress warnings from headers of Qt or 3rd party code, include them with `-isystem` instead of `-I` (gcc/clang only). For MSVC use `/external`, which is available since VS 15.6. Alternatively you can set the CLAZY_HEADER_FILTER env variable to a regexp matching the path where you want warnings, for example `CLAZY_HEADER_FILTER=.*myapplication.*`. You can also exclude paths using a regexp by setting CLAZY_IGNORE_DIRS, for example `CLAZY_IGNORE_DIRS=.*my_qt_folder.*`. You can also suppress individual warnings by file or by line by inserting comments: - To disable clazy in a specific source file, insert this comment, anywhere in the file: `// clazy:skip` - To disable specific checks in a source file, insert a comment such as `// clazy:excludeall=check1,check2` - To disable specific checks in specific source lines, insert a comment in the same line as the warning: `(...) // clazy:exclude=check1,check2` Don't include the `clazy-` prefix. If, for example, you want to disable qstring-allocations you would write: `// clazy:exclude=qstring-allocations` not `clazy-qstring-allocations`. # Reporting bugs and wishes - bug tracker: - IRC: #kde-clazy (freenode) - E-mail: # Authors - Sérgio Martins with contributions from: - Allen Winter - Kevin Funk - Mathias Hasselmann - Laurent Montel - Albert Astals Cid - Aurélien Gâteau - Hannah von Reth - Volker Krause - Christian Ehrlicher - Christian Gagneraud and thanks to: - Klarälvdalens Datakonsult AB (), for letting me work on clazy as a research project # Contributing patches New features go to master and bug fixes go to the 1.5 branch. The prefered way to contributing is by using KDE's phabricator, see: - - If you rather just create a pull request in https://github.com/KDE/clazy for a drive-by change, it's also fine, but beware that the maintainer might forget to check on github and the KDE bot will close the PR. In that case just send a reminder to the maintainer (smartins at kde.org). diff --git a/checks.json b/checks.json index 310a306..66ebbe1 100644 --- a/checks.json +++ b/checks.json @@ -1,599 +1,598 @@ { "available_categories" : ["readability", "qt4", "containers", "qstring", "cpp", "bug", "performance", "deprecation", "qml"], "checks" : [ { "name" : "qt-keywords", "level" : -1, "fixits" : [ { "name" : "qt-keywords" } ] }, { "name" : "ifndef-define-typo", "level" : -1, "categories" : ["bug"] }, { "name" : "inefficient-qlist", "level" : -1, "categories" : ["containers", "performance"], "visits_decls" : true }, { "name" : "isempty-vs-count", "class_name" : "IsEmptyVSCount", "level" : -1, "categories" : ["readability"], "visits_stmts" : true }, { "name" : "qrequiredresult-candidates", "class_name" : "QRequiredResultCandidates", "level" : -1, "categories" : ["bug"], "visits_decls" : true }, { "name" : "qstring-varargs", "level" : -1, "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" : "tr-non-literal", "level" : -1, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "raw-environment-function", "level" : -1, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "container-inside-loop", "level" : -1, "categories" : ["containers", "performance"], "visits_stmts" : true }, { "name" : "qhash-with-char-pointer-key", "level" : -1, "categories" : ["cpp", "bug"], "visits_decls" : true }, { "name" : "connect-by-name", "level" : 0, "categories" : ["bug", "readability"], "visits_decls" : true }, { "name" : "connect-non-signal", "minimum_qt_version" : 50700, "level" : 0, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "wrong-qevent-cast", "level" : 0, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "lambda-in-connect", "level" : 0, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "lambda-unique-connection", "level" : 0, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "qdatetime-utc", "class_name" : "QDateTimeUtc", "level" : 0, "categories" : ["performance"], "fixits" : [ { "name" : "qdatetime-utc" } ], "visits_stmts" : true }, { "name" : "qgetenv", "class_name" : "QGetEnv", "level" : 0, "minimum_qt_version" : 50500, "categories" : ["performance"], "fixits" : [ { "name" : "qgetenv" } ], "visits_stmts" : true }, { "name" : "qstring-insensitive-allocation", "level" : 0, "categories" : ["performance", "qstring"], "visits_stmts" : true }, { "name" : "fully-qualified-moc-types", "class_name" : "FullyQualifiedMocTypes", "level" : 0, "categories" : ["bug", "qml"], "visits_decls" : true }, { "name" : "qvariant-template-instantiation", - "level" : 0, - "categories" : ["performance"], + "level" : -1, "visits_stmts" : true }, { "name" : "unused-non-trivial-variable", "level" : 0, "categories" : ["readability"], "visits_stmts" : true }, { "name" : "connect-not-normalized", "level" : 0, "categories" : ["performance"], "visits_stmts" : true }, { "name" : "mutable-container-key", "level" : 0, "categories" : ["containers", "bug"], "visits_decls" : true }, { "name" : "qenums", "level" : 0, "minimum_qt_version" : 50500, "categories" : ["deprecation"] }, { "name" : "qmap-with-pointer-key", "level" : 0, "categories" : ["containers", "performance"], "visits_decls" : true }, { "name" : "qstring-ref", "class_name" : "StringRefCandidates", "level" : 0, "categories" : ["performance", "qstring"], "fixits" : [ { "name" : "missing-qstringref" } ], "visits_stmts" : true }, { "name" : "strict-iterators", "level" : 0, "categories" : ["containers", "performance", "bug"], "visits_stmts" : true }, { "name" : "writing-to-temporary", "level" : 0, "categories" : ["bug"], "options" : [ { "name" : "widen-criteria" } ], "visits_stmts" : true }, { "name" : "container-anti-pattern", "level" : 0, "categories" : ["containers", "performance"], "visits_stmts" : true }, { "name" : "qcolor-from-literal", "level" : 0, "categories" : ["performance"], "visits_stmts" : true, "ifndef" : "CLAZY_DISABLE_AST_MATCHERS" }, { "name" : "qfileinfo-exists", "class_name" : "QFileInfoExists", "level" : 0, "categories" : ["performance"], "visits_stmts" : true }, { "name" : "qstring-arg", "level" : 0, "categories" : ["performance", "qstring"], "options" : [ { "name" : "fillChar-overloads" } ], "visits_stmts" : true }, { "name" : "empty-qstringliteral", "level" : 0, "categories" : ["performance"], "visits_stmts" : true }, { "name" : "qt-macros", "class_name" : "QtMacros", "level" : 0, "categories" : ["bug"] }, { "name" : "temporary-iterator", "level" : 0, "categories" : ["containers", "bug"], "visits_stmts" : true }, { "name" : "wrong-qglobalstatic", "class_name" : "WrongQGlobalStatic", "level" : 0, "categories" : ["performance"], "visits_stmts" : true }, { "name" : "lowercase-qml-type-name", "level" : 0, "categories" : ["qml", "bug"], "visits_stmts" : true }, { "name" : "auto-unexpected-qstringbuilder", "class_name" : "AutoUnexpectedQStringBuilder", "level" : 1, "categories" : ["bug", "qstring"], "visits_decls" : true, "visits_stmts" : true, "fixits" : [ { "name" : "auto-unexpected-qstringbuilder" } ] }, { "name" : "connect-3arg-lambda", "level" : 1, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "const-signal-or-slot", "level" : 1, "categories" : ["readability", "bug"], "visits_decls" : true, "visits_stmts" : true }, { "name" : "detaching-temporary", "level" : 1, "categories" : ["containers", "performance"], "visits_stmts" : true }, { "name" : "foreach", "level" : 1, "categories" : ["containers", "performance"], "visits_stmts" : true }, { "name" : "incorrect-emit", "level" : 1, "categories" : ["readability"], "visits_stmts" : true }, { "name" : "inefficient-qlist-soft", "level" : 1, "categories" : ["containers", "performance"], "visits_decls" : true }, { "name" : "install-event-filter", "level" : 1, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "non-pod-global-static", "level" : 1, "categories" : ["performance"], "visits_stmts" : true }, { "name" : "post-event", "level" : 1, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "qdeleteall", "class_name" : "QDeleteAll", "level" : 1, "categories" : ["containers", "performance"], "visits_stmts" : true }, { "name" : "qlatin1string-non-ascii", "level" : 1, "categories" : ["bug", "qstring"], "visits_stmts" : true }, { "name" : "qproperty-without-notify", "level" : 1, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "qstring-left", "level" : 1, "categories" : ["bug", "performance", "qstring"], "visits_stmts" : true }, { "name" : "range-loop", "level" : 1, "categories" : ["containers", "performance"], "visits_stmts" : true, "fixits" : [ { "name" : "range-loop-add-ref" }, { "name" : "range-loop-add-qasconst" } ] }, { "name" : "returning-data-from-temporary", "level" : 1, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "rule-of-two-soft", "level" : 1, "categories" : ["cpp", "bug"], "visits_stmts" : true }, { "name" : "child-event-qobject-cast", "level" : 1, "categories" : ["bug"], "visits_decls" : true }, { "name" : "virtual-signal", "level" : 1, "categories" : ["bug", "readability"], "visits_decls" : true }, { "name" : "overridden-signal", "level" : 1, "categories" : ["bug", "readability"], "visits_decls" : true }, { "name" : "qhash-namespace", "level" : 1, "categories" : ["bug"], "visits_decls" : true }, { "name" : "skipped-base-method", "level" : 1, "categories" : ["bug", "cpp"], "visits_stmts" : true }, { "name" : "unneeded-cast", "level" : -1, "categories" : ["cpp", "readability"], "options" : [ { "name" : "prefer-dynamic-cast-over-qobject" } ], "visits_stmts" : true }, { "name" : "ctor-missing-parent-argument", "level" : 2, "categories" : ["bug"], "visits_decls" : true }, { "name" : "base-class-event", "level" : 2, "categories" : ["bug"], "visits_decls" : true }, { "name" : "copyable-polymorphic", "level" : 2, "categories" : ["cpp", "bug"], "visits_decls" : true }, { "name" : "function-args-by-ref", "level" : 2, "categories" : ["cpp", "performance"], "options" : [ { "name" : "warn-for-overridden-methods" } ], "fixits" : [ { "name" : "function-args-by-ref" } ], "visits_decls" : true, "visits_stmts" : true }, { "name" : "function-args-by-value", "level" : 2, "categories" : ["cpp", "performance"], "options" : [ { "name" : "warn-for-overridden-methods" } ], "visits_decls" : true, "visits_stmts" : true }, { "name" : "global-const-char-pointer", "level" : 2, "categories" : ["cpp", "performance"], "visits_decls" : true }, { "name" : "implicit-casts", "level" : 2, "categories" : ["cpp", "bug"], "options" : [ { "name" : "bool-to-int" } ], "visits_stmts" : true }, { "name" : "missing-qobject-macro", "level" : 2, "categories" : ["bug"], "visits_decls" : true }, { "name" : "missing-typeinfo", "class_name" : "MissingTypeInfo", "level" : 2, "categories" : ["containers", "performance"], "visits_decls" : true }, { "name" : "old-style-connect", "level" : 2, "minimum_qt_version" : 50500, "ifndef" : "NO_STD_REGEX", "categories" : ["performance"], "fixits" : [ { "name" : "old-style-connect" } ], "visits_stmts" : true }, { "name" : "qstring-allocations", "level" : 2, "minimum_qt_version" : 50000, "categories" : ["performance", "qstring"], "fixits" : [ { "name" : "qlatin1string-allocations" }, { "name" : "fromLatin1_fromUtf8-allocations" }, { "name" : "fromCharPtrAllocations" } ], "options" : [ { "name" : "no-msvc-compat" } ], "visits_stmts" : true }, { "name" : "returning-void-expression", "level" : 2, "categories" : ["readability", "cpp"], "visits_stmts" : true }, { "name" : "rule-of-three", "level" : 2, "categories" : ["cpp", "bug"], "visits_decls" : true }, { "name" : "virtual-call-ctor", "level" : 2, "categories" : ["cpp", "bug"], "visits_decls" : true }, { "name" : "static-pmf", "level" : 2, "categories" : ["bug"], "visits_decls" : true }, { "name" : "assert-with-side-effects", "level" : -1, "categories" : ["bug"], "visits_stmts" : true }, { "name" : "detaching-member", "level" : -1, "categories" : ["containers", "performance"], "visits_stmts" : true }, { "name" : "thread-with-slots", "level" : -1, "categories" : ["bug"], "visits_decls" : true, "visits_stmts" : true }, { "name" : "reserve-candidates", "level" : -1, "categories" : ["containers"], "visits_stmts" : true } ] } diff --git a/docs/checks/README-qvariant-template-instantiation.md b/docs/checks/README-qvariant-template-instantiation.md index 9a8f5e9..4b8387e 100644 --- a/docs/checks/README-qvariant-template-instantiation.md +++ b/docs/checks/README-qvariant-template-instantiation.md @@ -1,5 +1,10 @@ # qvariant-template-instantiation Detects when you're using `QVariant::value()` instead of `QVariant::toFoo()`. -The former results in more code being generated. +The former results in more code being generated in theory. + +## False-Positives +Beware that this function doesn't work well when typedefs are involved, for example +it suggests that `v.toUlongLong()` should replace `v.value()`, which +isn't semantically correct. diff --git a/readmes.cmake b/readmes.cmake index 49a03fc..b0dd587 100644 --- a/readmes.cmake +++ b/readmes.cmake @@ -1,91 +1,91 @@ SET(README_manuallevel_FILES ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-assert-with-side-effects.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-container-inside-loop.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-detaching-member.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-ifndef-define-typo.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-inefficient-qlist.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-isempty-vs-count.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qhash-with-char-pointer-key.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qrequiredresult-candidates.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qstring-varargs.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-qvariant-template-instantiation.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-raw-environment-function.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-reserve-candidates.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-thread-with-slots.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-tr-non-literal.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-unneeded-cast.md ) SET(README_LEVEL0_FILES ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-connect-by-name.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-connect-non-signal.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-connect-not-normalized.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-container-anti-pattern.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-empty-qstringliteral.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-fully-qualified-moc-types.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-lambda-in-connect.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-lambda-unique-connection.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-lowercase-qml-type-name.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-mutable-container-key.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qcolor-from-literal.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qdatetime-utc.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qenums.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qfileinfo-exists.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qgetenv.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qmap-with-pointer-key.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qstring-arg.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qstring-insensitive-allocation.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qstring-ref.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qt-macros.md - ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qvariant-template-instantiation.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-strict-iterators.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-temporary-iterator.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-unused-non-trivial-variable.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-writing-to-temporary.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-wrong-qevent-cast.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-wrong-qglobalstatic.md ) SET(README_LEVEL1_FILES ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-auto-unexpected-qstringbuilder.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-child-event-qobject-cast.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-connect-3arg-lambda.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-const-signal-or-slot.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-detaching-temporary.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-foreach.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-incorrect-emit.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-inefficient-qlist-soft.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-install-event-filter.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-non-pod-global-static.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-overridden-signal.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-post-event.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qdeleteall.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qhash-namespace.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qlatin1string-non-ascii.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qproperty-without-notify.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qstring-left.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-range-loop.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-returning-data-from-temporary.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-rule-of-two-soft.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-skipped-base-method.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-virtual-signal.md ) SET(README_LEVEL2_FILES ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-base-class-event.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-copyable-polymorphic.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-ctor-missing-parent-argument.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-function-args-by-ref.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-function-args-by-value.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-global-const-char-pointer.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-implicit-casts.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-missing-qobject-macro.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-missing-typeinfo.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-old-style-connect.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-qstring-allocations.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-returning-void-expression.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-rule-of-three.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-static-pmf.md ${CMAKE_CURRENT_LIST_DIR}/docs/checks/README-virtual-call-ctor.md ) diff --git a/src/Checks.h b/src/Checks.h index 709d66c..1bb85ee 100644 --- a/src/Checks.h +++ b/src/Checks.h @@ -1,217 +1,217 @@ /* This file is part of the clazy static checker. Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com Author: Sérgio Martins This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /** * To add a new check you can either edit this file, or use the python script: * dev-scripts/generate.py > src/Checks.h */ #include "checkmanager.h" #include "checks/manuallevel/assert-with-side-effects.h" #include "checks/manuallevel/container-inside-loop.h" #include "checks/manuallevel/detaching-member.h" #include "checks/manuallevel/ifndef-define-typo.h" #include "checks/manuallevel/inefficient-qlist.h" #include "checks/manuallevel/isempty-vs-count.h" #include "checks/manuallevel/qhash-with-char-pointer-key.h" #include "checks/manuallevel/qrequiredresult-candidates.h" #include "checks/manuallevel/qstring-varargs.h" #include "checks/manuallevel/qt-keywords.h" #include "checks/manuallevel/qt4-qstring-from-array.h" +#include "checks/manuallevel/qvariant-template-instantiation.h" #include "checks/manuallevel/raw-environment-function.h" #include "checks/manuallevel/reserve-candidates.h" #include "checks/manuallevel/thread-with-slots.h" #include "checks/manuallevel/tr-non-literal.h" #include "checks/manuallevel/unneeded-cast.h" #include "checks/level0/connect-by-name.h" #include "checks/level0/connect-non-signal.h" #include "checks/level0/connect-not-normalized.h" #include "checks/level0/container-anti-pattern.h" #include "checks/level0/empty-qstringliteral.h" #include "checks/level0/fully-qualified-moc-types.h" #include "checks/level0/lambda-in-connect.h" #include "checks/level0/lambda-unique-connection.h" #include "checks/level0/lowercase-qml-type-name.h" #include "checks/level0/mutable-container-key.h" #include "checks/level0/qcolor-from-literal.h" #include "checks/level0/qdatetime-utc.h" #include "checks/level0/qenums.h" #include "checks/level0/qfileinfo-exists.h" #include "checks/level0/qgetenv.h" #include "checks/level0/qmap-with-pointer-key.h" #include "checks/level0/qstring-arg.h" #include "checks/level0/qstring-insensitive-allocation.h" #include "checks/level0/qstring-ref.h" #include "checks/level0/qt-macros.h" -#include "checks/level0/qvariant-template-instantiation.h" #include "checks/level0/strict-iterators.h" #include "checks/level0/temporary-iterator.h" #include "checks/level0/unused-non-trivial-variable.h" #include "checks/level0/writing-to-temporary.h" #include "checks/level0/wrong-qevent-cast.h" #include "checks/level0/wrong-qglobalstatic.h" #include "checks/level1/auto-unexpected-qstringbuilder.h" #include "checks/level1/child-event-qobject-cast.h" #include "checks/level1/connect-3arg-lambda.h" #include "checks/level1/const-signal-or-slot.h" #include "checks/level1/detaching-temporary.h" #include "checks/level1/foreach.h" #include "checks/level1/incorrect-emit.h" #include "checks/level1/inefficient-qlist-soft.h" #include "checks/level1/install-event-filter.h" #include "checks/level1/non-pod-global-static.h" #include "checks/level1/overridden-signal.h" #include "checks/level1/post-event.h" #include "checks/level1/qdeleteall.h" #include "checks/level1/qhash-namespace.h" #include "checks/level1/qlatin1string-non-ascii.h" #include "checks/level1/qproperty-without-notify.h" #include "checks/level1/qstring-left.h" #include "checks/level1/range-loop.h" #include "checks/level1/returning-data-from-temporary.h" #include "checks/level1/rule-of-two-soft.h" #include "checks/level1/skipped-base-method.h" #include "checks/level1/virtual-signal.h" #include "checks/level2/base-class-event.h" #include "checks/level2/copyable-polymorphic.h" #include "checks/level2/ctor-missing-parent-argument.h" #include "checks/level2/function-args-by-ref.h" #include "checks/level2/function-args-by-value.h" #include "checks/level2/global-const-char-pointer.h" #include "checks/level2/implicit-casts.h" #include "checks/level2/missing-qobject-macro.h" #include "checks/level2/missing-typeinfo.h" #include "checks/level2/old-style-connect.h" #include "checks/level2/qstring-allocations.h" #include "checks/level2/returning-void-expression.h" #include "checks/level2/rule-of-three.h" #include "checks/level2/static-pmf.h" #include "checks/level2/virtual-call-ctor.h" template RegisteredCheck check(const char *name, CheckLevel level, RegisteredCheck::Options options = RegisteredCheck::Option_None) { auto factoryFuntion = [name](ClazyContext *context){ return new T(name, context); }; return RegisteredCheck{name, level, factoryFuntion, options}; } void CheckManager::registerChecks() { registerCheck(check("assert-with-side-effects", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("container-inside-loop", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("detaching-member", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("ifndef-define-typo", ManualCheckLevel, RegisteredCheck::Option_None)); registerCheck(check("inefficient-qlist", ManualCheckLevel, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("isempty-vs-count", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qhash-with-char-pointer-key", ManualCheckLevel, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("qrequiredresult-candidates", ManualCheckLevel, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("qstring-varargs", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qt-keywords", ManualCheckLevel, RegisteredCheck::Option_None)); registerFixIt(1, "fix-qt-keywords", "qt-keywords"); registerCheck(check("qt4-qstring-from-array", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-qt4-qstring-from-array", "qt4-qstring-from-array"); + registerCheck(check("qvariant-template-instantiation", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("raw-environment-function", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("reserve-candidates", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("thread-with-slots", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts | RegisteredCheck::Option_VisitsDecls)); registerCheck(check("tr-non-literal", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("unneeded-cast", ManualCheckLevel, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("connect-by-name", CheckLevel0, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("connect-non-signal", CheckLevel0, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts)); registerCheck(check("connect-not-normalized", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("container-anti-pattern", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("empty-qstringliteral", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("fully-qualified-moc-types", CheckLevel0, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("lambda-in-connect", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("lambda-unique-connection", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("lowercase-qml-type-name", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("mutable-container-key", CheckLevel0, RegisteredCheck::Option_VisitsDecls)); #ifndef CLAZY_DISABLE_AST_MATCHERS registerCheck(check("qcolor-from-literal", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); #endif registerCheck(check("qdatetime-utc", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-qdatetime-utc", "qdatetime-utc"); registerCheck(check("qenums", CheckLevel0, RegisteredCheck::Option_Qt4Incompatible)); registerCheck(check("qfileinfo-exists", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qgetenv", CheckLevel0, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-qgetenv", "qgetenv"); registerCheck(check("qmap-with-pointer-key", CheckLevel0, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("qstring-arg", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qstring-insensitive-allocation", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qstring-ref", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-missing-qstringref", "qstring-ref"); registerCheck(check("qt-macros", CheckLevel0, RegisteredCheck::Option_None)); - registerCheck(check("qvariant-template-instantiation", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("strict-iterators", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("temporary-iterator", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("unused-non-trivial-variable", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("writing-to-temporary", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("wrong-qevent-cast", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("wrong-qglobalstatic", CheckLevel0, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("auto-unexpected-qstringbuilder", CheckLevel1, RegisteredCheck::Option_VisitsStmts | RegisteredCheck::Option_VisitsDecls)); registerFixIt(1, "fix-auto-unexpected-qstringbuilder", "auto-unexpected-qstringbuilder"); registerCheck(check("child-event-qobject-cast", CheckLevel1, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("connect-3arg-lambda", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("const-signal-or-slot", CheckLevel1, RegisteredCheck::Option_VisitsStmts | RegisteredCheck::Option_VisitsDecls)); registerCheck(check("detaching-temporary", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("foreach", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("incorrect-emit", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("inefficient-qlist-soft", CheckLevel1, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("install-event-filter", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("non-pod-global-static", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("overridden-signal", CheckLevel1, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("post-event", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qdeleteall", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qhash-namespace", CheckLevel1, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("qlatin1string-non-ascii", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qproperty-without-notify", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("qstring-left", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("range-loop", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-range-loop-add-ref", "range-loop"); registerFixIt(2, "fix-range-loop-add-qasconst", "range-loop"); registerCheck(check("returning-data-from-temporary", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("rule-of-two-soft", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("skipped-base-method", CheckLevel1, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("virtual-signal", CheckLevel1, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("base-class-event", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("copyable-polymorphic", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("ctor-missing-parent-argument", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("function-args-by-ref", CheckLevel2, RegisteredCheck::Option_VisitsStmts | RegisteredCheck::Option_VisitsDecls)); registerFixIt(1, "fix-function-args-by-ref", "function-args-by-ref"); registerCheck(check("function-args-by-value", CheckLevel2, RegisteredCheck::Option_VisitsStmts | RegisteredCheck::Option_VisitsDecls)); registerCheck(check("global-const-char-pointer", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("implicit-casts", CheckLevel2, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("missing-qobject-macro", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("missing-typeinfo", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); #ifndef NO_STD_REGEX registerCheck(check("old-style-connect", CheckLevel2, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-old-style-connect", "old-style-connect"); #endif registerCheck(check("qstring-allocations", CheckLevel2, RegisteredCheck::Option_Qt4Incompatible | RegisteredCheck::Option_VisitsStmts)); registerFixIt(1, "fix-qlatin1string-allocations", "qstring-allocations"); registerFixIt(2, "fix-fromLatin1_fromUtf8-allocations", "qstring-allocations"); registerFixIt(4, "fix-fromCharPtrAllocations", "qstring-allocations"); registerCheck(check("returning-void-expression", CheckLevel2, RegisteredCheck::Option_VisitsStmts)); registerCheck(check("rule-of-three", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("static-pmf", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); registerCheck(check("virtual-call-ctor", CheckLevel2, RegisteredCheck::Option_VisitsDecls)); } diff --git a/src/checks/level0/qvariant-template-instantiation.cpp b/src/checks/manuallevel/qvariant-template-instantiation.cpp similarity index 100% rename from src/checks/level0/qvariant-template-instantiation.cpp rename to src/checks/manuallevel/qvariant-template-instantiation.cpp diff --git a/src/checks/level0/qvariant-template-instantiation.h b/src/checks/manuallevel/qvariant-template-instantiation.h similarity index 100% rename from src/checks/level0/qvariant-template-instantiation.h rename to src/checks/manuallevel/qvariant-template-instantiation.h