diff --git a/docs/checks/README-auto-unexpected-qstringbuilder.md b/docs/checks/README-auto-unexpected-qstringbuilder.md index 0c9e814..947535e 100644 --- a/docs/checks/README-auto-unexpected-qstringbuilder.md +++ b/docs/checks/README-auto-unexpected-qstringbuilder.md @@ -1,16 +1,16 @@ # auto-unexpected-qstringbuilder Finds places where auto is deduced to be `QStringBuilder` instead of `QString`, which introduces crashes. Also warns for lambdas returning `QStringBuilder`. #### Example #define QT_USE_QSTRINGBUILDER #include (...) const auto path = "hello " + QString::fromLatin1("world"); qDebug() << path; // CRASH #### Fixits - export CLAZY_FIXIT="fix-auto-unexpected-qstringbuilder" +This check supports a fixit to rewrite your code. See the README.md on how to enable it. diff --git a/docs/checks/README-function-args-by-ref.md b/docs/checks/README-function-args-by-ref.md index 8f78b38..55c2fb6 100644 --- a/docs/checks/README-function-args-by-ref.md +++ b/docs/checks/README-function-args-by-ref.md @@ -1,17 +1,16 @@ # function-args-by-ref Warns when you should be passing by const-ref. Types with sizeof > 16 bytes [1] or types which are not trivially-copyable [2] or not trivially-destructible [3] should be passed by ref. A rule of thumb is that if passing by value would trigger copy-ctor and/or dtor then pass by ref instead. This check will ignore shared pointers, you're on your own. Most of the times passing shared pointers by const-ref is the best thing to do, but occasionally that will lead to crashes if you're in a method that calls something else that makes the shared pointer ref count go down to zero. #### Fixits -This check supports adding missing `&` or `const-&` with: - export CLAZY_FIXIT="fix-function-args-by-ref" +This check supports adding missing `&` or `const-&`. See the README.md on how to enable it. - [1] - [2] - [3] diff --git a/docs/checks/README-old-style-connect.md b/docs/checks/README-old-style-connect.md index 2cad4e8..b1ec052 100644 --- a/docs/checks/README-old-style-connect.md +++ b/docs/checks/README-old-style-connect.md @@ -1,18 +1,18 @@ # old-style-connect Finds usages of old style connects. Connecting with old style syntax (`SIGNAL`/`SLOT`) is much slower than using pointer to member syntax (PMF). 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) - 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. +This check supports a fixit to rewrite your code to the new connect syntax. See the README.md on how to enable it. +Be careful, as PMF is not a 100% drop-in replacement and the fixit might introduce bugs. #### 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. diff --git a/docs/checks/README-qstring-allocations.md b/docs/checks/README-qstring-allocations.md index 22645b4..c156353 100644 --- a/docs/checks/README-qstring-allocations.md +++ b/docs/checks/README-qstring-allocations.md @@ -1,49 +1,44 @@ # qstring-unneeded-heap-allocations Finds places with unneeded memory allocations due to temporary `QString`s. Here's a summary of usages that allocate: 1. `QString s = "foo"; // Allocates, use QStringLiteral("foo") instead` 2. `QString s = QLatin1String("foo"); // Allocates, use QStringLiteral("foo") instead` 2.1 `QString s = QLatin1String(""); // No allocation. QString is optimized for this case, so it's safe for empty literals` 3. `QString s = QStringLiteral("foo"); // No allocation` 4. `QString s = QString::fromLatin1("foo"); // Allocates, use QStringLiteral` 5. `QString s = QString::fromUtf8("foo"); // Allocates, use QStringLiteral` 6. `s == "foo" // Allocates, use QLatin1String` 7. `s == QLatin1String("foo") // No allocation` 8. `s == QStringLiteral("foo") // No allocation` 9. `QString {"append", "compare", "endsWith", "startsWith", "indexOf", "insert",` ` "lastIndexOf", "prepend", "replace", "contains" } // They all have QLatin1String overloads, so passing a QLatin1String is ok.` 10. `QString::fromLatin1("foo %1").arg(bar) // Allocates twice, replacing with QStringLiteral makes it allocate only once.` #### Fixits - fix-qlatin1string-allocations // To replace QLatin1String with QStringLiteral only where it was allocating before - fix-fromLatin1_fromUtf8-allocations // To replace fromLatin1() and fromUtf8() so it doesn't allocate - fix-fromCharPtrAllocations // To replace raw string literals so it doesn't allocate - - Example: - export CLAZY_FIXIT="fix-fromCharPtrAllocations" +This check supports a fixit to rewrite your code. See the README.md on how to enable it. #### Pitfalls - `QStringLiteral` might make your app crash at exit if plugins are involved. See: and - Also note that MSVC crashes when `QStringLiteral` is used inside initializer lists. For that reason no warning or fixit is emitted for this case unless you set an env variable: export CLAZY_EXTRA_OPTIONS="qstring-allocations-no-msvc-compat" diff --git a/docs/checks/README-qstring-ref.md b/docs/checks/README-qstring-ref.md index 7dcf05e..98b77dd 100644 --- a/docs/checks/README-qstring-ref.md +++ b/docs/checks/README-qstring-ref.md @@ -1,17 +1,16 @@ # qstring-ref Finds places where `QString::fooRef()` should be used instead of `QString::foo()`, to avoid temporary heap allocations. #### Example str.mid(5).toInt(ok) // BAD str.midRef(5).toInt(ok) // GOOD Where `mid` can be any of: `mid`, `left`, `right`. And `toInt()` can be any of: `compare`, `contains`, `count`, `startsWith`, `endsWith`, `indexOf`, `isEmpty`, `isNull`, `lastIndexOf`, `length`, `size`, `to*`, `trimmed` #### FixIts -Fixing the above cases can be automated with: -`export CLAZY_FIXIT="fix-missing-qstringref"` +This check supports a fixit to rewrite your code. See the README.md on how to enable it.