Skip to content

Commit

Permalink
enabled and mitigated readability-container-size-empty clang-tidy w…
Browse files Browse the repository at this point in the history
…arnings (#5340)
  • Loading branch information
firewave committed Aug 17, 2023
1 parent 3cf9100 commit 5dbcea3
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Checks: >
-readability-braces-around-statements,
-readability-const-return-type,
-readability-container-data-pointer,
-readability-container-size-empty,
-readability-convert-member-functions-to-static,
-readability-function-cognitive-complexity,
-readability-function-size,
Expand Down
1 change: 0 additions & 1 deletion clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ Also reports a false positive about templates which deduce the array length: htt

We run this separately via `clang-include-cleaner` in the `iwyu.yml` workflow as the findings of the include checkers still need to be reviewed manually before applying them.

`readability-container-size-empty`<br/>
`bugprone-branch-clone`<br/>
`readability-const-return-type`<br/>
`modernize-return-braced-init-list`<br/>
Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ void MainWindow::analyzeFiles()

QStringList selected = selectFilesToAnalyze(QFileDialog::ExistingFiles);

const QString file0 = (selected.size() ? selected[0].toLower() : QString());
const QString file0 = (!selected.empty() ? selected[0].toLower() : QString());
if (file0.endsWith(".sln")
|| file0.endsWith(".vcxproj")
|| file0.endsWith(compile_commands_json)
Expand Down
2 changes: 1 addition & 1 deletion gui/test/cppchecklibrarydata/testcppchecklibrarydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ void TestCppcheckLibraryData::validateAllCfg()
{
const QDir dir(QString(SRCDIR) + "/../../../cfg/");
const QStringList files = dir.entryList(QStringList() << "*.cfg",QDir::Files);
QVERIFY(files.size() != 0);
QVERIFY(!files.empty());
bool error = false;
for (const QString& f : files) {
loadCfgFile(dir.absolutePath() + "/" + f, fileLibraryData, result);
Expand Down
4 changes: 2 additions & 2 deletions lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3529,8 +3529,8 @@ void CheckOther::funcArgOrderDifferent(const std::string & functionName,
const std::vector<const Token *> & definitions)
{
std::list<const Token *> tokens = {
declarations.size() ? declarations[0] ? declarations[0] : declaration : nullptr,
definitions.size() ? definitions[0] ? definitions[0] : definition : nullptr
!declarations.empty() ? declarations[0] ? declarations[0] : declaration : nullptr,
!definitions.empty() ? definitions[0] ? definitions[0] : definition : nullptr
};
std::string msg = "$symbol:" + functionName + "\nFunction '$symbol' argument order different: declaration '";
for (int i = 0; i < declarations.size(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3356,7 +3356,7 @@ void TemplateSimplifier::replaceTemplateUsage(
std::set<TemplateSimplifier::TokenAndName*>* pointers = nameTok->templateSimplifierPointers();

// check if instantiation matches token instantiation from pointer
if (pointers && pointers->size()) {
if (pointers && !pointers->empty()) {
// check full name
if (instantiation.fullName() != (*pointers->begin())->fullName()) {
// FIXME: fallback to just matching name
Expand Down
1 change: 1 addition & 0 deletions test/testsymboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,7 @@ class TestSymbolDatabase : public TestFixture {
ASSERT_EQUALS(10, db->variableList().size() - 1);
ASSERT_EQUALS(true, db->getVariableFromVarId(1) && db->getVariableFromVarId(1)->dimensions().size() == 1);
ASSERT_EQUALS(true, db->getVariableFromVarId(2) != nullptr);
// NOLINTNEXTLINE(readability-container-size-empty)
ASSERT_EQUALS(true, db->getVariableFromVarId(3) && db->getVariableFromVarId(3)->dimensions().size() == 0);
ASSERT_EQUALS(true, db->getVariableFromVarId(4) != nullptr);
ASSERT_EQUALS(true, db->getVariableFromVarId(5) != nullptr);
Expand Down
2 changes: 1 addition & 1 deletion test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6616,7 +6616,7 @@ class TestValueFlow : public TestFixture {
" if (a.empty() && b.empty()) {}\n"
" else if (a.empty() == false && b.empty() == false) {}\n"
"}\n";
ASSERT("" != isImpossibleContainerSizeValue(tokenValues(code, "a . empty ( ) == false"), 0));
ASSERT(!isImpossibleContainerSizeValue(tokenValues(code, "a . empty ( ) == false"), 0).empty());

code = "bool g(std::vector<int>& v) {\n"
" v.push_back(1);\n"
Expand Down

0 comments on commit 5dbcea3

Please sign in to comment.