CLAZY(1)

๐Ÿ’… CLAZY(1) โ€” the KDAB girlie's guide to clazy

okay so bestie, you know how I keep telling you static analysis is not a vibe-killer but actually the most self-care thing you can do for your C++? This is the page for clazy, manual section 1, and yes it's the glow-up your Qt5 codebase has been begging for. Grab a strawberry drink ๐Ÿ“, let's go.


โœจ NAME โœจ

clazy โ€” a static source code analyzer for Qt5-based C++.

Like, it reads your code and tells you about your choices. Lovingly. Mostly. ๐Ÿ’–


๐ŸŒธ SYNOPSIS ๐ŸŒธ

clazy [option] [clang++-options]

That's it. That's the whole mood. One command, options, then all your clang++ stuff. ๐ŸŽ€


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So clazy scans your C++/Qt source code looking for issues related to good coding practice with Qt5. Scans. Looks. Judges gently. And here's the fun part: in typical use, during code compilation with clazy, you'll see any such warnings printed to the output, normally, just like you'd find any compiler warnings. So it's not some whole separate flow โ€” it just shows up in your build output like "hey queen, this line is giving questionable". ๐Ÿ˜ญ

And clazy has the ability to "fix" the offending code in some cases. Yes, actual automatic fixing. icon behavior. See the CLAZY_FIXIT environment variable description below for more info. ๐Ÿ‘‘


โœจ OPTIONS โœจ

Let's do the roundup, bestie:

  • --help โ€” Prints the help message and then exits. Classic. ๐Ÿซถ
  • --version โ€” Prints version information and exits. Identity check. ๐Ÿ’…
  • --list โ€” Prints a list of all available checkers, arranged by level. This is the one you run first, no cap.
  • --explain โ€” Prints explanations for all checkers. All of them. The full syllabus. ๐Ÿ“š
  • --explain <regexp> โ€” Prints explanations for the checkers matching the specified regular expression. So you can be picky, and honestly? slay.
Heads up: any of the options above will print the requested information and then exit. Like, it's a one-and-done, it's not sticking around to compile anything.
  • --qtdeveloper โ€” For Qt developers only. Qt developers ONLY. This option is special for running clazy on Qt itself, and it will result in fewer false positives being reported in Qt code.

It's a convenience option which is identical to directly passing:

"-Xclang -plugin-arg-clazy -Xclang qt-developer"

So like, you could type all that, but why would you. ๐Ÿ™ˆ

All other options are passed directly to clang++ and handled from there. Every single one. Not our business, we hand it off. ๏ฟฝ๏ฟฝ

See the clang manual for a list of the very large set of options available โ€” and it is very large, like genuinely huge โ€” but in normal operation you "compile" your code with clazy just as you would with clang. Same energy, better feedback.


๐ŸŽ€ EXAMPLES ๐ŸŽ€

% 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
 ....

100% safe, no false-positives โ€” the level0 girlies are the trustworthy ones, that's the whole point. ๐Ÿ’œ

Compile your CMake project with clazy default checkers

% cmake -DCMAKE_CXX_COMPILER=clazy <other_cmake_options>
then make as normal

"then make as normal" โ€” like literally just carry on, that's the entire trick. ๐Ÿงš

Compile your CMake project with level2 checks only (non-Windows)

% export CLAZY_CHECKS="level2"
% cmake -DCMAKE_CXX_COMPILER=clazy <other_cmake_options>
then make as normal

Note the (non-Windows) bestie. That's not me being cute, that's the actual scope. ๐Ÿ’€

Compile your qmake project with clazy default checkers

% qmake -spec linux-clang QMAKE_CXX=clazy <other_qmake_options>
then make as normal

qmake girlies, we see you, we love you, same deal. ๐ŸŒธ


๐Ÿ”ฅ IN-CODE DIRECTIVES ๐Ÿ”ฅ

okay this is the part where you get to talk back to the tool. clazy supports the following list of in-code directives:

  • clazy:skip โ€” Exempt an entire file from all checks. No clazy tests will run on the file. Whole file, off the table, not today. ๐Ÿ’…
  • clazy:excludeall=<name1[,name2,...,nameN]> โ€” Exempt the entire file from the specified checks. The clazy checks name1, etc. will not be run on this file. So it's skip, but picky.
  • clazy:exclude=<name1[,name2,...,nameN]> โ€” Exclude individual lines from specific checks. The clazy checks tests name1, etc. will not be run on the line where this directive is found. Just that one line. Micro-exclusion. iconic.
  • clazy:exclude-next-line=<name1[,name2,...,nameN]> โ€” Excludes the given clazy checks from the next line. Future-line exemption, she's forward-thinking. ๐Ÿ”ฎ
The important bit: 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. So // yes, /* */ no โ€” she will simply not read it, fr fr. ๐Ÿ™ˆ


๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

  • CLAZY_CHECKS โ€” a comma-separated list of checkers or check-sets to run. By default, all checkers from the "level0" and "level1" check-sets will run. That's the default. No config needed, she's already working. โœจ

Examples:

  1. Enables the 2 checkers "unneeded-cast" and "virtual-call-ctor" only:
% export CLAZY_CHECKS="unneeded-cast,virtual-call-ctor"
  1. Enables all checks from the "level0" check-set, except for "qenums":
% export CLAZY_CHECKS="level0,no-qenums"
  1. Enables all checks from the "level0" check-set along with the "detaching-temporary" checker:
% export CLAZY_CHECKS="level0,detaching-temporary"

see how you can mix a whole level with one specific checker? that's the good stuff.

  • CLAZY_FIXIT โ€” 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.

Examples:

  1. Fix qlatin1string allocations:
% export CLAZY_FIXIT="fix-qlatin1string-allocations"
  1. Fix old-style (simple cases) connect statements:
% export CLAZY_FIXIT=fix-old-style-connect

More documentation is provided when running clazy with the --explain command line option. ๐Ÿ“–

Also note that only 1 fixit checker can be run at a time. ONE. Not two, not "just a couple", one. Choose wisely bestie. ๐Ÿ’€
  • CLAZY_EXTRA_OPTIONS โ€” some checkers can adapt their behavior depending on the value of this environment variable. More documentation is provided when running clazy with the --explain command line option. She's flexible, but she's not gonna explain herself here. ๐Ÿ˜Œ
  • CLAZY_NO_WERROR โ€” 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. So you get to be strict with everyone else and gentle with yourself. growth.
  • CLAZY_CHECKS_AS_ERRORS โ€” comma-separated list of checks that will be promoted to compiler errors. Note that this does not enable the checks specified here. Like, it promotes them, it does not summon them. Two different things. ๐Ÿ™
  • CLAZY_IGNORE_DIRS โ€” A regular expression for paths to exclude from processing. For example:
% export CLAZY_IGNORE_DIRS=".*my_qt_folder.*"

Bye bye my_qt_folder, we simply do not see her. ๐Ÿฆ‹


Copyright (C) 2015-2017 Klaralvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see <http://www.gnu.org/licenses/>.

(lowercase gnu dot org, no www, copy it exactly bestie โ€” licensing is not a place to freestyle ๐Ÿซถ)


๐Ÿงš SEE ALSO ๐Ÿงš

clang(1)
https://www.kdab.com/use-static-analysis-improve-performance

like, read the clang manual, and then read that KDAB article, that's the assignment. ๐Ÿ“Œ


๐Ÿ’– AUTHORS ๐Ÿ’–

The whole squad, respectfully:

Sergio Martins <sergio.martins@kdab.com>
Laurent Montel <laurent.montel@kdab.com>
Allen Winter <allen.winter@kdab.com>
Albert Astals Cid <aacid@kde.org>
Aurรฉlien Gรขteau <agateau@kde.org>
Kevin Funk <kevin.funk@kdab.com>
Hannah von Reth <hannah.vonreth@kdab.com>
Volker Krause <volker.krause@kdab.com>
Christian Ehrlicher <Ch.Ehrlicher@gmx.de>
Mathias Hasselmann <mathias.hasselmann@kdab.com>

and that's the page!! ๐ŸŒŸ go forth, compile with clazy, let her fix your connect statements, and remember: level0 will never lie to you.

cute little sign-off for the footer energy: this is version 1.17.1, dated 2026-04-08, section CLAZY(1) โ€” mwah, bye bestie ๐Ÿ’‹๐ŸŽ€

๐Ÿ“ฆ where this page comes from