Clazy 1.5 released
Clazy 1.5 is now available. This is a small release, mainly focused on bug fixing.
Clazy is a clang compiler plugin which emits warnings related to Qt best practices. We’ll be showing Clazy at Embedded World, Nuremberg, Febr 26-28, where we are a main Qt partner. You can read more about it in our previous blog posts:
- How to use static analysis to improve performance
- Uncovering 32 Qt Best Practices
- Nailing 13 signal and slot mistakes with clazy
As usual, MSVC and AppImage binaries are available at http://downloads.kdab.com/clazy.
The interesting part of the ChangeLog is as follows:
Tries to find cases where a
#define following an
#ifndef defines a different but similar name.
#ifndef GL_FRAMEBUFFER_SRG // Oops, typo. # define GL_FRAMEBUFFER_SRGB 0x8DB9 #endif
It uses a Levenshtein Distance algorithm so it will only warn if the names are similar. This check is disabled by default as it can report many false-positives. Nevertheless you should give it a go, it even found a bug in Qt: https://codereview.qt-project.org/#/c/242090/.
Warns when QML types registered with
qmlRegisterUncreatableType() don’t start with uppercase. It’s required by the QML engine that they do.
Suggests methods that could be marked as [[nodiscard]] (via
Functions annotated with this attribute will trigger a compiler warning if their value is unused.
Clazy’s criteria for making such suggestion is: const methods, returning the same type as their class and ending with ‘ed’
For example, the signature for
QRect::intersected() should be written as:
Q_REQUIRED_RESULT QRect intersected(const QRect &other) const so that user code will get a warning when discarding the result.
To help you automatically rewrite your code, a few new fixits were implemented:
- range-loop now supports adding missing refs or const-refs
- range-loop now supports adding
- function-args-by-ref now supports adding missing refs or const-refs (experimental)
- Renamed the clazy plugin from ClangLazy.so to ClazyPlugin.so
- fully-qualified-moc-types now warns for slot/invokable return values too. They need to be fully qualified for QML
- Many bug fixes, including crashes