Skip to content

Fix #10682 Unused QString / #10686 unused std::array / #10005 unused variable with c++11 braced initializer not detected#3684

Merged
danmar merged 6 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix10682
Jan 10, 2022
Merged

Fix #10682 Unused QString / #10686 unused std::array / #10005 unused variable with c++11 braced initializer not detected#3684
danmar merged 6 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_Fix10682

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

@firewave

firewave commented Jan 7, 2022

Copy link
Copy Markdown
Collaborator

As mentioned in the ticket I assumed other containers might also be affected. And QMap, QSet, QMultiMap and QQueue are somehow not detected. QList and QVector are. There's probably more but I just looked at the STL counterparts.

#include <map>
#include <list>
#include <array>
#include <vector>
#include <set>
#include <queue>
#include <deque>
#include <forward_list>
#include <unordered_set>
#include <unordered_map>

#include <QMap>
#include <QList>
#include <QVector>
#include <QSet>
#include <QMultiMap>
#include <QQueue>

extern void f()
{
	std::map<int, int> m;
	QMap<int, int> qm;

	std::list<int> l;
	QList<int> ql;

	std::array<int, 1> a;

	std::vector<int> v;
	QVector<int> qv;

	std::set<int> s;
	QSet<int> qs;

	std::multimap<int, int> mm;
	QMultiMap<int, int> qmm;

	std::multiset<int> ms;

	std::queue<int> q;
	QQueue<int> qq;

	std::deque<int> d;

	std::forward_list<int> fl;

	std::unordered_set<int> us;

	std::unordered_map<int, int> um;
}
/mnt/s/clion/example_lite_2/test.cpp:21:21: style: Unused variable: m [unusedVariable]
 std::map<int, int> m;
                    ^
/mnt/s/clion/example_lite_2/test.cpp:24:17: style: Unused variable: l [unusedVariable]
 std::list<int> l;
                ^
/mnt/s/clion/example_lite_2/test.cpp:25:13: style: Unused variable: ql [unusedVariable]
 QList<int> ql;
            ^
/mnt/s/clion/example_lite_2/test.cpp:29:19: style: Unused variable: v [unusedVariable]
 std::vector<int> v;
                  ^
/mnt/s/clion/example_lite_2/test.cpp:30:15: style: Unused variable: qv [unusedVariable]
 QVector<int> qv;
              ^
/mnt/s/clion/example_lite_2/test.cpp:32:16: style: Unused variable: s [unusedVariable]
 std::set<int> s;
               ^
/mnt/s/clion/example_lite_2/test.cpp:35:26: style: Unused variable: mm [unusedVariable]
 std::multimap<int, int> mm;
                         ^
/mnt/s/clion/example_lite_2/test.cpp:38:21: style: Unused variable: ms [unusedVariable]
 std::multiset<int> ms;
                    ^
/mnt/s/clion/example_lite_2/test.cpp:40:18: style: Unused variable: q [unusedVariable]
 std::queue<int> q;
                 ^
/mnt/s/clion/example_lite_2/test.cpp:43:18: style: Unused variable: d [unusedVariable]
 std::deque<int> d;
                 ^
/mnt/s/clion/example_lite_2/test.cpp:45:25: style: Unused variable: fl [unusedVariable]
 std::forward_list<int> fl;
                        ^
/mnt/s/clion/example_lite_2/test.cpp:47:26: style: Unused variable: us [unusedVariable]
 std::unordered_set<int> us;
                         ^
/mnt/s/clion/example_lite_2/test.cpp:49:31: style: Unused variable: um [unusedVariable]
 std::unordered_map<int, int> um;
                              ^

std::array also isn't detected but I will add another ticket for that.

Comment thread gui/projectfile.cpp
for (const QString &tag: tags) {
xmlWriter.writeStartElement(CppcheckXml::TagWarningsElementName);
xmlWriter.writeAttribute(CppcheckXml::TagAttributeName, tag);
QStringList warnings;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Cool!

@chrchr-github

chrchr-github commented Jan 7, 2022

Copy link
Copy Markdown
Collaborator Author

It seems that those containers are missing from qt.cfg (QMap, QMultiMap, QSet, QQueue).

@firewave

firewave commented Jan 7, 2022

Copy link
Copy Markdown
Collaborator

It seems that those containers are missing from qt.cfg (QMap, QMultiMap, QSet, QQueue).

Ah - I didn't check that. I will add a ticket for that.

@firewave

firewave commented Jan 7, 2022

Copy link
Copy Markdown
Collaborator

Nice. 😀 Better change the title so we know there's two tickets in this PR.

@chrchr-github chrchr-github changed the title Fix #10682 False negative: Unused QString variable is not detected Fix #10682 False negative: Unused QString not detected / #10686 unused std::array not detected Jan 7, 2022
@firewave

firewave commented Jan 8, 2022

Copy link
Copy Markdown
Collaborator

https://trac.cppcheck.net/ticket/10005 is the ticket for the undetected unused braced initializer variables.

This is becoming a grand slam.🥳

@chrchr-github chrchr-github changed the title Fix #10682 False negative: Unused QString not detected / #10686 unused std::array not detected Fix #10682 Unused QString / #10686 unused std::array / #10005 unused variable with c++11 braced initializer not detected Jan 8, 2022
@firewave

firewave commented Jan 8, 2022

Copy link
Copy Markdown
Collaborator

Here's some similar tickets you might also want to have a look at after this:
https://trac.cppcheck.net/ticket/7732 - looks related to having a constructor being used
https://trac.cppcheck.net/ticket/10057 - looks related to missing varid

@chrchr-github

Copy link
Copy Markdown
Collaborator Author

Here's some similar tickets you might also want to have a look at after this: https://trac.cppcheck.net/ticket/7732 - looks related to having a constructor being used https://trac.cppcheck.net/ticket/10057 - looks related to missing varid

It never ends, does it? 🤪

@firewave

firewave commented Jan 8, 2022

Copy link
Copy Markdown
Collaborator

It never ends, does it? 🤪

With these changes we're a lot closer. 🐱‍👤 And this should probably end here.

There's also the side effect shortcomings 😏 But "might" and "after this"!

@danmar danmar merged commit df3da38 into cppcheck-opensource:main Jan 10, 2022
@orbitcowboy

orbitcowboy commented Jan 11, 2022

Copy link
Copy Markdown
Collaborator

Here's some similar tickets you might also want to have a look at after this: https://trac.cppcheck.net/ticket/7732 - looks related to having a constructor being used https://trac.cppcheck.net/ticket/10057 - looks related to missing varid

It never ends, does it? zany_face

It never ends, that's true, I found other cases:

void f(void)
{
	int();
	int(1);
	int{};
	int{1};
}
$ gcc -c test1.cpp && cppcheck --enable=all test1.cpp 
Checking test1.cpp ...
test1.cpp:4:0: style: The function 'f' is never used. [unusedFunction]

^
nofile:0:0: information: Cppcheck cannot find all the include files (use --check-config for details) [missingIncludeSystem]


@firewave

Copy link
Copy Markdown
Collaborator

It never ends, that's true, I found other cases:

That's https://trac.cppcheck.net/ticket/10057.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants