diff --git a/.arcconfig b/.arcconfig index 6cdb5cd..377c7ec 100644 --- a/.arcconfig +++ b/.arcconfig @@ -1,4 +1,3 @@ { - "phabricator.uri" : "https://phabricator.kde.org/", - "history.immutable" : true + "phabricator.uri" : "https://phabricator.kde.org/" } diff --git a/clazy.cmake b/clazy.cmake index 1e4b6ff..150061d 100644 --- a/clazy.cmake +++ b/clazy.cmake @@ -1,93 +1,93 @@ #!/usr/bin/env sh libdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ sharedir=@CMAKE_INSTALL_PREFIX@/@SHARE_INSTALL_DIR@/clazy HELP() { echo "Usage: `basename $0` [options] [clang++-options]" echo echo "Static analyzer for C++/Qt code" echo echo "Options:" echo " --help print program help" echo " --version print the program version" echo " --list print a list of all available checkers, arranged by level" echo " --explain [regexp] print explanations for the checker matching a regexp" echo "or" echo " --explain print explanations for all checkers" echo echo "Any of the options above will print the requested information and then exit." echo "Otherwise, options are passed directly to clang++ and handled from there." echo echo "See the clang++ manual for a list of the very large set of options available" echo } VERSION() { echo "clazy version: @CLAZY_PRINT_VERSION@" ${CLANGXX:-clang++} --version | head -1 | awk '{printf("clang++ Version: %s\n",$3)}' } PRLIST() { echo "" echo "Checks from level$1. $2:" ls -1 $sharedir/doc/level$1/README* | awk -F/ '{printf(" %s\n", $NF)}' | sed s/README-// | sed s/\.md$// | sort } PRINFO() { lst=`ls -1 $sharedir/doc/level*/README*$1*` for f in $lst do l=`echo $f | awk -F/ '{foo=NF-1; printf(" %s:%s\n", $foo,$NF)}'` level=`echo $l | cut -d: -f1` checker=`echo $l | cut -d: -f2 | sed s/README-// | sed s/\.md$//` echo "== Explanation for checker $checker ($level) ==" cat $f echo done } if ( test $# -gt 0 -a "$1" = "--help" ) then HELP exit fi if ( test $# -gt 0 -a "$1" = "--version" ) then VERSION exit fi if ( test $# -gt 0 -a "$1" = "--list" ) then echo "List of available clazy checkers:" PRLIST 0 "Very stable checks, 100% safe, no false-positives" PRLIST 1 "Mostly stable and safe, rare false-positives" PRLIST 2 "Sometimes has false-positives (20-30%)" PRLIST 3 "Not always correct, high rate of false-positives" exit fi if ( test $# -gt 0 -a "$1" = "--explain" ) then shift PRINFO $@ exit fi ClangLazyLib=ClangLazy@CMAKE_SHARED_LIBRARY_SUFFIX@ if ( test -f "$libdir/$ClangLazyLib" ) then # find plugin libraries in install dir export LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH export DYLD_LIBRARY_PATH=$libdir:$DYLD_LIBRARY_PATH elif ( test -f "$(dirname $0)/lib/$ClangLazyLib" ) then # find plugin libraries in build dir export LD_LIBRARY_PATH=$(dirname $0)/lib:$LD_LIBRARY_PATH export DYLD_LIBRARY_PATH=$(dirname $0)/lib:$DYLD_LIBRARY_PATH fi -${CLANGXX:-clang++} -Qunused-arguments -Xclang -load -Xclang $ClangLazyLib -Xclang -add-plugin -Xclang clang-lazy $@ +${CLANGXX:-clang++} -Qunused-arguments -Xclang -load -Xclang $ClangLazyLib -Xclang -add-plugin -Xclang clang-lazy "$@" diff --git a/docs/man/clazy.pod b/docs/man/clazy.pod index 910c0ed..f177c4f 100644 --- a/docs/man/clazy.pod +++ b/docs/man/clazy.pod @@ -1,210 +1,214 @@ =encoding utf8 =head1 NAME clazy - a static source code analyzer for Qt5-based C++. =head1 SYNOPSIS clazy [option] [clang++-options] =head1 DESCRIPTION clazy scans C++/Qt source code looking for issues related to good coding practice with of Qt5. In typical use, during code compilation with clazy you will see any such warnings printed to the output normally as you would find any compiler warnings. clazy has the ability to "fix" the offending code in some cases. See the B environment variable description below for more information. =head1 OPTIONS =over 4 =item B<--help> Print help message and exit. =item B<--version> Print version information and exit. =item B<--list> Print a list of all available checkers, arranged by level. =item B<--explain> Print explanations for all checkers. =item B<--explain> Print explanations for the checkers matching the specified regular expression. =back Any of the options above will print the requested information and then exit. Otherwise, options are passed directly to clang++ and handled from there. See the clang manual for a list of the very large set of options available, but in normal operation you "compile" your code with clazy just as you would with clang. =head1 EXAMPLES =over 4 =item Print a list of all available checkers, arranged by check level: % clazy --list List of available clazy checkers: Checks from level0. Very stable checks, 100% safe, no false-positives: connect-non-signal container-anti-pattern lambda-in-connect mutable-container-key qdatetime-utc qenums qfileinfo-exists .... =item Compile your CMake project with clazy default checkers: % cmake -DCMAKE_CXX_COMPILER=clazy then make as normal =item Compile your CMake project with level2 checks only (non-Windows): % export CLAZY_CHECKS="level2" % cmake -DCMAKE_CXX_COMPILER=clazy then make as normal =item Compile your qmake project with clazy default checkers: % qmake -spec linux-clang QMAKE_CXX=clazy then make as normal =back =head1 IN-CODE DIRECTIVES clazy supports the following list of in-code directives: =over 4 =item clazy:skip Exempt an entire file from all checks. No clazy tests will run on the file. =item clazy:excludeall= Exempt the entire file from the specified checks. The clazy checks name1, etc will not be run on this file. =item clazy:exclude= Exclude individual lines from specific checks. The clazy checks tests name1, etc. will not be run on the line where this directive is found. =back Don't include the 'clazy-' prefix. For example, to disable the "qstring-allocations" check, you would write: // clazy:exclude=qstring-allocations and not // clazy:exclude=clazy-qstring-allocations Also note that these directives must be C++ style comments; C style comments are ignored. =head1 ENVIRONMENT B - a comma-separated list of checkers or check-sets to run. By default, all checkers from the "level0" and "level1" check-sets will run. B =over 4 =item 1. Enables the 2 checkers "bogus-dynamic-cast" and "virtual-call-ctor" only: % export CLAZY_CHECKS="bogus-dynamic-cast,virtual-call-ctor" =item 2. Enables all checks from the "level0" check-set, except for "qenums": % export CLAZY_CHECKS="level0,no-qenums" =item 3. Enables all checks from the "level0" check-set along with the "detaching-temporary" checker: % export CLAZY_CHECKS="level0,detaching-temporary" =back B - some checkers are able to automatically re-write your source code whenever it encounters code it can "fix". Enable this "fixit" feature by setting this variable to the name of the checker with a "fixit" capability. B =over 4 =item 1. Fix qlatin1string allocations: % export CLAZY_FIXIT="fix-qlatin1string-allocations" =item 2. Fix old-style (simple cases) connect statements: % export CLAZY_FIXIT=fix-old-style-connect More documentation is provided when running clazy with the B<--explain> command line option. Also note that only 1 fixit checker can be run at a time. =back B - some checkers can adapt their behavior depending on the value of this environment variable. More documentation is provided when running clazy with the B<--explain> command line option. +B - if this is variable is set, clazy will not treat warnings as errors, +even if the -Werror compiler option is specified. This is useful if you want to use -Werror +only for the regular gcc/clang warnings but not for clazy warnings. + =head1 COPYRIGHT AND LICENSE Copyright (C) 2010-2017 Klaralvdalens Datakonsult AB, a KDAB Group company, This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. =head1 SEE ALSO clang(1) - L + https://www.kdab.com/use-static-analysis-improve-performance =head1 AUTHORS Sergio Martins Laurent Montel Allen Winter Albert Astals Cid Aurélien Gâteau Kevin Funk Hannah von Reth Volker Krause Christian Ehrlicher Mathias Hasselmann =cut diff --git a/src/checks/level0/README-lambda-in-connect.md b/src/checks/level0/README-lambda-in-connect.md index e98b125..bfdefec 100644 --- a/src/checks/level0/README-lambda-in-connect.md +++ b/src/checks/level0/README-lambda-in-connect.md @@ -1,13 +1,13 @@ # lambda-in-connect Warns when a lambda inside a connect captures local variables by reference. -This usually results in a crash since the lambda might get called after the variable went out of scope. +This usually results in a crash since the lambda might get called after the captured variable went out of scope. #### Example: ```` int a; - connect(obj, &MyObj::mySignal, [&a](){ ... }); + connect(obj, &MyObj::mySignal, [&a]{ ... }); ```` Although it's dangerous to capture by reference in other situations too, this check only warns for connects, otherwise it would generate false-positives in legitimate situations where you only use the lambda before going out of scope. diff --git a/src/checks/level0/README-wrong-qglobalstatic.md b/src/checks/level0/README-wrong-qglobalstatic.md index 1a6590a..7073487 100644 --- a/src/checks/level0/README-wrong-qglobalstatic.md +++ b/src/checks/level0/README-wrong-qglobalstatic.md @@ -1,14 +1,14 @@ # wrong-qglobalstatic Finds `Q_GLOBAL_STATIC`s being used with trivial types. -This is unnecessary and creates more code bloat. +This is unnecessary and creates code bloat. #### Example: struct Trivial { int v; }; Q_GLOBAL_STATIC(Trivial, t); // Wrong static Trivial t; // Correct diff --git a/src/checks/level2/README-old-style-connect.md b/src/checks/level2/README-old-style-connect.md index bd643e4..2cad4e8 100644 --- a/src/checks/level2/README-old-style-connect.md +++ b/src/checks/level2/README-old-style-connect.md @@ -1,19 +1,18 @@ # old-style-connect Finds usages of old style connects. -Old style syntax (`SIGNAL`/`SLOT`) is much slower than using pointer to member syntax (PMF). +Connecting with old style syntax (`SIGNAL`/`SLOT`) is much slower than using pointer to member syntax (PMF). -Here's a non-exhaustive list of caveats of PMF connects: +Here's however a non-exhaustive list of caveats you should be aware of: - You can't disconnect with new-syntax if the connect was made with old-syntax (and vice-versa) -- You can't disconnect from a static slot with new-syntax (although connecting works!) +- You can't disconnect from a static slot with new-syntax (although connecting works) - Difference in behaviour when calling slots of partially destroyed objects () #### Fixits You can convert the most simple cases with `export CLAZY_FIXIT=fix-old-style-connect`. Be careful, as PMF is not a 100% drop-in replacement. #### Pitfalls -Although this check doesn't have false-positives it's a level2 check. -That's because some connects are tricky to convert to PMF syntax and might introduce bugs if you don't know what you're doing. +Although this check doesn't have false-positives it's a level2 check, that's because some connects are tricky to convert to PMF syntax and might introduce bugs if you don't know what you're doing.