Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

clazy 1.2 released

presenting 5 new Qt compile-time checks


    // warning: Signature is not normalized. Use void mySlot(int) instead of void mySlot(const int) [-Wclazy-connect-not-normalized]
    o.connect(&o, SIGNAL(mySignal(int, int)),
              &o, SLOT(void mySlot(const int)));

QByteArray b = ...;
return b.data();

return funcReturningByteArray().data();

return funcReturningByteArray().constData();

const char * getFoo()
{
    QByteArray b = ...;
    return b; // QByteArray can implicitly cast to char*
}

const char *c1 = getByteArray();
const char *c2 = str.toUtf8().data();

QColor c("#000000"); // Use QColor c(0, 0, 0) instead
c.setNamedColor("#001122"); // Use c = QColor(0, 0x11, 0x22) instead

    QHash<int, int> wrong;
    if (wrong.find(1) == wrong.cend()) {
        qDebug() << "Not found";
    } else {
        // find() detached the container before cend() was called, so it prints "Found"
        qDebug() << "Found";
    }

    QHash<int, int> right;
    if (right.constFind(1) == right.cend()) {
        // Prints "Not Found". This is correct now !
        qDebug() << "Not found";
    } else {
        qDebug() << "Found";
    }
 clazy-standalone -checks=level1 -p compile_commands.json myfile.cpp 

6 Comments

27 - Jul - 2017

frederic

27 - Jul - 2017

Sérgio Martins

25 - Jan - 2018

zack

25 - Jan - 2018

Sérgio Martins

26 - Jan - 2018

zack

26 - Jan - 2018

Sérgio Martins

SérgioMartins

Sérgio Martins

Senior Software Engineer

Learn Modern C++

Learn more