cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

Don't set pure for const functions [refs #12696]

Open chrchr-github opened this issue 1 year ago • 1 comments

chrchr-github avatar May 04 '24 16:05 chrchr-github

FWIW here's a reduced example:

class QModelIndex;

struct ResultsTree {   
    void copy();
    QStandardItemModel mModel;
    QItemSelectionModel mSelectionModel{};
};

void ResultsTree::copy()
{
    QString text;
    for (QModelIndex index : mSelectionModel.selectedRows()) {
        QStandardItem* item = mModel.itemFromIndex(index);
        if (!item->parent()) {
            text += item->text() + '\n';
            continue;
        }
    }
}

Before this change, the valueflow was

Line 14
  ! always {!<=-1,!>=2}
  item always symbolic=(mModel.itemFromIndex(index))
Line 15
  item always symbolic=(mModel.itemFromIndex(index))
  '\n' always 10

Those symbolic values disappear without pure, affecting isAliasOf() and ultimaltely isVariableChanged().

chrchr-github avatar May 04 '24 21:05 chrchr-github