Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ void ResultsTree::copy()
return;

QString text;
for (QModelIndex index : mSelectionModel->selectedRows()) {
for (const QModelIndex& index : mSelectionModel->selectedRows()) {
QStandardItem *item = mModel.itemFromIndex(index);
if (!item->parent()) {
text += item->text() + '\n';
Expand Down Expand Up @@ -929,7 +929,7 @@ void ResultsTree::hideResult()
if (!mSelectionModel)
return;

for (QModelIndex index : mSelectionModel->selectedRows()) {
for (const QModelIndex& index : mSelectionModel->selectedRows()) {
QStandardItem *item = mModel.itemFromIndex(index);
//Set the "hide" flag for this item
QVariantMap data = item->data().toMap();
Expand All @@ -947,7 +947,7 @@ void ResultsTree::recheckSelectedFiles()
return;

QStringList selectedItems;
for (QModelIndex index : mSelectionModel->selectedRows()) {
for (const QModelIndex& index : mSelectionModel->selectedRows()) {
QStandardItem *item = mModel.itemFromIndex(index);
while (item->parent())
item = item->parent();
Expand Down Expand Up @@ -1029,7 +1029,7 @@ void ResultsTree::suppressSelectedIds()
return;

QSet<QString> selectedIds;
for (QModelIndex index : mSelectionModel->selectedRows()) {
for (const QModelIndex& index : mSelectionModel->selectedRows()) {
QStandardItem *item = mModel.itemFromIndex(index);
if (!item->parent())
continue;
Expand Down Expand Up @@ -1068,7 +1068,7 @@ void ResultsTree::suppressHash()

// Extract selected warnings
QSet<QStandardItem *> selectedWarnings;
for (QModelIndex index : mSelectionModel->selectedRows()) {
for (const QModelIndex& index : mSelectionModel->selectedRows()) {
QStandardItem *item = mModel.itemFromIndex(index);
if (!item->parent())
continue;
Expand Down Expand Up @@ -1115,7 +1115,7 @@ void ResultsTree::tagSelectedItems(const QString &tag)
return;
bool isTagged = false;
ProjectFile *currentProject = ProjectFile::getActiveProject();
for (QModelIndex index : mSelectionModel->selectedRows()) {
for (const QModelIndex& index : mSelectionModel->selectedRows()) {
QStandardItem *item = mModel.itemFromIndex(index);
QVariantMap data = item->data().toMap();
if (data.contains("tags")) {
Expand Down
3 changes: 1 addition & 2 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
} else if (functionnodename == "pure")
func.ispure = true;
else if (functionnodename == "const") {
func.ispure = true;
func.isconst = true; // a constant function is pure
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I understand a const function is always pure. does valueflow assume that the function reads from global memory if it's pure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how ValueFlow uses these attributes.
We also need to figure out what const is supposed to mean in the library, see #6385

func.isconst = true;
} else if (functionnodename == "leak-ignore")
func.leakignore = true;
else if (functionnodename == "not-overlapping-data") {
Expand Down