diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index 96e2ff406..7cf788305 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -54,48 +54,42 @@ public: /** * Return if user wanted to see program version. */ - bool GetShowVersion() const - { + bool GetShowVersion() const { return _showVersion; } /** * Return if user wanted to see list of error messages. */ - bool GetShowErrorMessages() const - { + bool GetShowErrorMessages() const { return _showErrorMessages; } /** * Return the path names user gave to command line. */ - const std::vector& GetPathNames() const - { + const std::vector& GetPathNames() const { return _pathnames; } /** * Return if help is shown to user. */ - bool GetShowHelp() const - { + bool GetShowHelp() const { return _showHelp; } /** * Return if we should exit after printing version, help etc. */ - bool ExitAfterPrinting() const - { + bool ExitAfterPrinting() const { return _exitAfterPrint; } /** * Return a list of paths user wants to ignore. */ - const std::vector& GetIgnoredPaths() const - { + const std::vector& GetIgnoredPaths() const { return _ignoredPaths; } diff --git a/cli/filelister.h b/cli/filelister.h index 0511466d4..ec37525d3 100644 --- a/cli/filelister.h +++ b/cli/filelister.h @@ -37,8 +37,7 @@ public: * @param files output map that associates the size of each file with its name * @param path root path */ - static void recursiveAddFiles(std::map &files, const std::string &path) - { + static void recursiveAddFiles(std::map &files, const std::string &path) { const std::set extra; recursiveAddFiles(files, path, extra); } diff --git a/cli/threadexecutor.h b/cli/threadexecutor.h index 402b39cc6..84b14ced2 100644 --- a/cli/threadexecutor.h +++ b/cli/threadexecutor.h @@ -98,8 +98,7 @@ public: /** * @return true if support for threads exist. */ - static bool isEnabled() - { + static bool isEnabled() { return true; } @@ -129,8 +128,7 @@ public: /** * @return true if support for threads exist. */ - static bool isEnabled() - { + static bool isEnabled() { return true; } #else @@ -138,8 +136,7 @@ public: /** * @return true if support for threads exist. */ - static bool isEnabled() - { + static bool isEnabled() { return false; } #endif diff --git a/democlient/democlient.cpp b/democlient/democlient.cpp index f8cb22e8f..c4844169c 100644 --- a/democlient/democlient.cpp +++ b/democlient/democlient.cpp @@ -33,28 +33,24 @@ public: CppcheckExecutor() : ErrorLogger() , stoptime(std::time(NULL)+2U) - , cppcheck(*this,false) - { + , cppcheck(*this,false) { cppcheck.settings().addEnabled("all"); cppcheck.settings().inconclusive = true; } - void run(const char code[]) - { + void run(const char code[]) { cppcheck.check("test.c", code); } void reportOut(const std::string &outmsg) { } - void reportErr(const ErrorLogger::ErrorMessage &msg) - { + void reportErr(const ErrorLogger::ErrorMessage &msg) { printf("%s\n", msg.toString(true).c_str()); } void reportProgress(const std::string &filename, const char stage[], - const unsigned int value) - { + const unsigned int value) { if (std::time(NULL) >= stoptime) { printf("time to analyse the " "code is more than 1 " diff --git a/gui/application.h b/gui/application.h index 17e7048db..1dd7e7419 100644 --- a/gui/application.h +++ b/gui/application.h @@ -49,8 +49,7 @@ public: * @brief Get application name. * @return Application name. */ - QString getName() const - { + QString getName() const { return mName; } @@ -58,8 +57,7 @@ public: * @brief Get application path. * @return Application path. */ - QString getPath() const - { + QString getPath() const { return mPath; } @@ -67,8 +65,7 @@ public: * @brief Get application command line parameters. * @return Application command line parameters. */ - QString getParameters() const - { + QString getParameters() const { return mParameters; } @@ -76,8 +73,7 @@ public: * @brief Set application name. * @param name Application name. */ - void setName(const QString &name) - { + void setName(const QString &name) { mName = name; } @@ -85,8 +81,7 @@ public: * @brief Set application path. * @param path Application path. */ - void setPath(const QString &path) - { + void setPath(const QString &path) { mPath = path; } @@ -94,8 +89,7 @@ public: * @brief Set application command line parameters. * @param parameters Application command line parameters. */ - void setParameters(const QString ¶meters) - { + void setParameters(const QString ¶meters) { mParameters = parameters; } diff --git a/gui/applicationlist.h b/gui/applicationlist.h index b73e67093..36d501773 100644 --- a/gui/applicationlist.h +++ b/gui/applicationlist.h @@ -69,8 +69,7 @@ public: * @brief Return the default application. * @return Index of the default application. */ - int GetDefaultApplication() const - { + int GetDefaultApplication() const { return mDefaultApplicationIndex; } diff --git a/gui/erroritem.h b/gui/erroritem.h index c0aca1a95..5192bc6e9 100644 --- a/gui/erroritem.h +++ b/gui/erroritem.h @@ -37,13 +37,11 @@ class ErrorLine; */ class GuiSeverity { public: - static QString toString(Severity::SeverityType severity) - { + static QString toString(Severity::SeverityType severity) { return QString(Severity::toString(severity).c_str()); } - static Severity::SeverityType fromString(const QString &severity) - { + static Severity::SeverityType fromString(const QString &severity) { return Severity::fromString(severity.toStdString()); } }; diff --git a/gui/filelist.cpp b/gui/filelist.cpp index a46be694c..94c640760 100644 --- a/gui/filelist.cpp +++ b/gui/filelist.cpp @@ -68,7 +68,7 @@ void FileList::AddDirectory(const QString &directory, bool recursive) dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); QFileInfoList list = dir.entryInfoList(); QFileInfo item; - foreach (item, list) { + foreach(item, list) { const QString path = item.canonicalFilePath(); AddDirectory(path, recursive); } @@ -78,7 +78,7 @@ void FileList::AddDirectory(const QString &directory, bool recursive) void FileList::AddPathList(const QStringList &paths) { QString path; - foreach (path, paths) { + foreach(path, paths) { QFileInfo inf(path); if (inf.isFile()) AddFile(path); @@ -91,7 +91,7 @@ QStringList FileList::GetFileList() const { if (mExcludedPaths.empty()) { QStringList names; - foreach (QFileInfo item, mFileList) { + foreach(QFileInfo item, mFileList) { QString name = QDir::fromNativeSeparators(item.canonicalFilePath()); names << name; } @@ -109,7 +109,7 @@ void FileList::AddExcludeList(const QStringList &paths) QStringList FileList::ApplyExcludeList() const { QStringList paths; - foreach (QFileInfo item, mFileList) { + foreach(QFileInfo item, mFileList) { QString name = QDir::fromNativeSeparators(item.canonicalFilePath()); if (!Match(name)) paths << name; diff --git a/gui/main.cpp b/gui/main.cpp index 84c194b08..dbb8644cc 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) QSettings* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app); // Set data dir.. - foreach (const QString arg, app.arguments()) { + foreach(const QString arg, app.arguments()) { if (arg.startsWith("--data-dir=")) { settings->setValue("DATADIR", arg.mid(11)); return 0; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index ead86acee..e6b293702 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -499,7 +499,7 @@ void MainWindow::CheckDirectory() void MainWindow::AddIncludeDirs(const QStringList &includeDirs, Settings &result) { QString dir; - foreach (dir, includeDirs) { + foreach(dir, includeDirs) { QString incdir; if (!QDir::isAbsolutePath(dir)) incdir = mCurrentDirectory + "/"; @@ -560,14 +560,14 @@ Settings MainWindow::GetCppcheckSettings() QStringList defines = pfile->GetDefines(); QString define; - foreach (define, defines) { + foreach(define, defines) { if (!result.userDefines.empty()) result.userDefines += ";"; result.userDefines += define.toStdString(); } QStringList libraries = pfile->GetLibraries(); - foreach (QString library, libraries) { + foreach(QString library, libraries) { const QString filename = library + ".cfg"; const Library::Error error = LoadLibrary(&result.library, filename); if (error.errorcode != Library::ErrorCode::OK) { @@ -604,7 +604,7 @@ Settings MainWindow::GetCppcheckSettings() } QStringList suppressions = pfile->GetSuppressions(); - foreach (QString suppression, suppressions) { + foreach(QString suppression, suppressions) { result.nomsg.addSuppressionLine(suppression.toStdString()); } diff --git a/gui/project.h b/gui/project.h index 2ebc0c4ff..804170ac8 100644 --- a/gui/project.h +++ b/gui/project.h @@ -79,8 +79,7 @@ public: * @brief Return current project file. * @return project file. */ - ProjectFile * GetProjectFile() const - { + ProjectFile * GetProjectFile() const { return mPFile; } diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index fe1231cff..bc57687ea 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -119,7 +119,7 @@ bool ProjectFile::Read(const QString &filename) insideProject = false; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: @@ -143,7 +143,7 @@ bool ProjectFile::Read(const QString &filename) QStringList ProjectFile::GetIncludeDirs() const { QStringList dirs; - foreach (QString path, mIncludeDirs) { + foreach(QString path, mIncludeDirs) { dirs << QDir::fromNativeSeparators(path); } return dirs; @@ -157,7 +157,7 @@ QStringList ProjectFile::GetDefines() const QStringList ProjectFile::GetCheckPaths() const { QStringList paths; - foreach (QString path, mPaths) { + foreach(QString path, mPaths) { paths << QDir::fromNativeSeparators(path); } return paths; @@ -166,7 +166,7 @@ QStringList ProjectFile::GetCheckPaths() const QStringList ProjectFile::GetExcludedPaths() const { QStringList paths; - foreach (QString path, mExcludedPaths) { + foreach(QString path, mExcludedPaths) { paths << QDir::fromNativeSeparators(path); } return paths; @@ -175,7 +175,7 @@ QStringList ProjectFile::GetExcludedPaths() const QStringList ProjectFile::GetLibraries() const { QStringList libraries; - foreach (QString library, mLibraries) { + foreach(QString library, mLibraries) { libraries << library; } return libraries; @@ -184,7 +184,7 @@ QStringList ProjectFile::GetLibraries() const QStringList ProjectFile::GetSuppressions() const { QStringList suppressions; - foreach (QString suppression, mSuppressions) { + foreach(QString suppression, mSuppressions) { suppressions << suppression; } return suppressions; @@ -221,7 +221,7 @@ void ProjectFile::ReadIncludeDirs(QXmlStreamReader &reader) allRead = true; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: @@ -258,7 +258,7 @@ void ProjectFile::ReadDefines(QXmlStreamReader &reader) allRead = true; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: @@ -296,7 +296,7 @@ void ProjectFile::ReadCheckPaths(QXmlStreamReader &reader) allRead = true; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: @@ -342,7 +342,7 @@ void ProjectFile::ReadExcludes(QXmlStreamReader &reader) allRead = true; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: @@ -381,7 +381,7 @@ void ProjectFile::ReadStringList(QStringList &stringlist, QXmlStreamReader &read allRead = true; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: @@ -449,7 +449,7 @@ bool ProjectFile::Write(const QString &filename) if (!mIncludeDirs.isEmpty()) { xmlWriter.writeStartElement(IncludeDirElementName); - foreach (QString incdir, mIncludeDirs) { + foreach(QString incdir, mIncludeDirs) { xmlWriter.writeStartElement(DirElementName); xmlWriter.writeAttribute(DirNameAttrib, incdir); xmlWriter.writeEndElement(); @@ -459,7 +459,7 @@ bool ProjectFile::Write(const QString &filename) if (!mDefines.isEmpty()) { xmlWriter.writeStartElement(DefinesElementName); - foreach (QString define, mDefines) { + foreach(QString define, mDefines) { xmlWriter.writeStartElement(DefineName); xmlWriter.writeAttribute(DefineNameAttrib, define); xmlWriter.writeEndElement(); @@ -469,7 +469,7 @@ bool ProjectFile::Write(const QString &filename) if (!mPaths.isEmpty()) { xmlWriter.writeStartElement(PathsElementName); - foreach (QString path, mPaths) { + foreach(QString path, mPaths) { xmlWriter.writeStartElement(PathName); xmlWriter.writeAttribute(PathNameAttrib, path); xmlWriter.writeEndElement(); @@ -479,7 +479,7 @@ bool ProjectFile::Write(const QString &filename) if (!mExcludedPaths.isEmpty()) { xmlWriter.writeStartElement(ExcludeElementName); - foreach (QString path, mExcludedPaths) { + foreach(QString path, mExcludedPaths) { xmlWriter.writeStartElement(ExcludePathName); xmlWriter.writeAttribute(ExcludePathNameAttrib, path); xmlWriter.writeEndElement(); @@ -508,7 +508,7 @@ void ProjectFile::WriteStringList(QXmlStreamWriter &xmlWriter, const QStringList return; xmlWriter.writeStartElement(startelementname); - foreach (QString str, stringlist) { + foreach(QString str, stringlist) { xmlWriter.writeStartElement(stringelementname); xmlWriter.writeCharacters(str); xmlWriter.writeEndElement(); diff --git a/gui/projectfile.h b/gui/projectfile.h index 84133fc17..5c7c8b272 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -50,8 +50,7 @@ public: * @brief Get project root path. * @return project root path. */ - QString GetRootPath() const - { + QString GetRootPath() const { return mRootPath; } @@ -95,8 +94,7 @@ public: * @brief Get filename for the project file. * @return file name. */ - QString GetFilename() const - { + QString GetFilename() const { return mFilename; } @@ -104,8 +102,7 @@ public: * @brief Set project root path. * @param rootpath new project root path. */ - void SetRootPath(const QString &rootpath) - { + void SetRootPath(const QString &rootpath) { mRootPath = rootpath; } @@ -164,8 +161,7 @@ public: * @brief Set filename for the project file. * @param filename Filename to use. */ - void SetFilename(const QString &filename) - { + void SetFilename(const QString &filename) { mFilename = filename; } diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp index f60cb57b8..755c7cdc1 100644 --- a/gui/projectfiledialog.cpp +++ b/gui/projectfiledialog.cpp @@ -53,12 +53,12 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent) if (!datadir.isEmpty()) searchPaths << datadir << datadir + "/cfg"; QStringList libs; - foreach (const QString sp, searchPaths) { + foreach(const QString sp, searchPaths) { QDir dir(sp); dir.setSorting(QDir::Name); dir.setNameFilters(QStringList("*.cfg")); dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); - foreach (QFileInfo item, dir.entryInfoList()) { + foreach(QFileInfo item, dir.entryInfoList()) { QString library = item.fileName(); { Library lib; @@ -75,7 +75,7 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent) } } qSort(libs); - foreach (const QString library, libs) { + foreach(const QString library, libs) { QCheckBox *checkbox = new QCheckBox(this); checkbox->setText(library); mUI.librariesLayout->addWidget(checkbox); @@ -208,7 +208,7 @@ QStringList ProjectFileDialog::GetExcludedPaths() const QStringList ProjectFileDialog::GetLibraries() const { QStringList libraries; - foreach (const QCheckBox *checkbox, mLibraryCheckboxes) { + foreach(const QCheckBox *checkbox, mLibraryCheckboxes) { if (checkbox->isChecked()) libraries << checkbox->text(); } @@ -234,7 +234,7 @@ void ProjectFileDialog::SetRootPath(const QString &root) void ProjectFileDialog::SetIncludepaths(const QStringList &includes) { - foreach (QString dir, includes) { + foreach(QString dir, includes) { AddIncludeDir(dir); } } @@ -243,7 +243,7 @@ void ProjectFileDialog::SetDefines(const QStringList &defines) { QString definestr; QString define; - foreach (define, defines) { + foreach(define, defines) { definestr += define; definestr += ";"; } @@ -255,14 +255,14 @@ void ProjectFileDialog::SetDefines(const QStringList &defines) void ProjectFileDialog::SetPaths(const QStringList &paths) { - foreach (QString path, paths) { + foreach(QString path, paths) { AddPath(path); } } void ProjectFileDialog::SetExcludedPaths(const QStringList &paths) { - foreach (QString path, paths) { + foreach(QString path, paths) { AddExcludePath(path); } } @@ -397,8 +397,7 @@ void ProjectFileDialog::AddSuppression() class QErrorLogger : public ErrorLogger { public: virtual void reportOut(const std::string &/*outmsg*/) {} - virtual void reportErr(const ErrorLogger::ErrorMessage &msg) - { + virtual void reportErr(const ErrorLogger::ErrorMessage &msg) { errorIds << QString::fromStdString(msg._id); } QStringList errorIds; diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 97dbd83ff..25e857d4a 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -756,7 +756,7 @@ void ResultsTree::HideResult() QModelIndexList selectedRows = mSelectionModel->selectedRows(); QModelIndex index; - foreach (index, selectedRows) { + foreach(index, selectedRows) { QStandardItem *item = mModel.itemFromIndex(index); //Set the "hide" flag for this item QVariantMap data = item->data().toMap(); diff --git a/gui/resultstree.h b/gui/resultstree.h index 5fc2f1ad8..63f68ef1e 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -147,8 +147,7 @@ public: /** * @brief Returns true if column "Id" is shown */ - bool ShowIdColumn() const - { + bool ShowIdColumn() const { return mShowErrorId; } diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index a79a0099e..f14b9e6bd 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -297,7 +297,7 @@ void ResultsView::ReadErrorsXml(const QString &filename) } ErrorItem item; - foreach (item, errors) { + foreach(item, errors) { mUI.mTree->AddErrorItem(item); } mUI.mTree->SetCheckDirectory(""); diff --git a/gui/resultsview.h b/gui/resultsview.h index 5b6e9cd37..260737453 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -151,8 +151,7 @@ public: * @brief Return checking statistics. * @return Pointer to checking statistics. */ - CheckStatistics *GetStatistics() const - { + CheckStatistics *GetStatistics() const { return mStatistics; } @@ -160,8 +159,7 @@ public: * @brief Return Showtypes. * @return Pointer to Showtypes. */ - ShowTypes * GetShowTypes() const - { + ShowTypes * GetShowTypes() const { return &mUI.mTree->mShowSeverities; } diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 6777835fa..2142fab5a 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -106,7 +106,7 @@ void SettingsDialog::InitIncludepathsList() QSettings settings; const QString allPaths = settings.value(SETTINGS_GLOBAL_INCLUDE_PATHS).toString(); const QStringList paths = allPaths.split(";", QString::SkipEmptyParts); - foreach (QString path, paths) { + foreach(QString path, paths) { AddIncludePath(path); } } @@ -115,7 +115,7 @@ void SettingsDialog::InitTranslationsList() { const QString current = mTranslator->GetCurrentLanguage(); QList translations = mTranslator->GetTranslations(); - foreach (TranslationInfo translation, translations) { + foreach(TranslationInfo translation, translations) { QListWidgetItem *item = new QListWidgetItem; item->setText(translation.mName); item->setData(LangCodeRole, QVariant(translation.mCode)); @@ -211,7 +211,7 @@ void SettingsDialog::AddApplication() void SettingsDialog::RemoveApplication() { QList selected = mUI.mListWidget->selectedItems(); - foreach (QListWidgetItem *item, selected) { + foreach(QListWidgetItem *item, selected) { const int removeIndex = mUI.mListWidget->row(item); const int currentDefault = mTempApplications->GetDefaultApplication(); mTempApplications->RemoveApplication(removeIndex); @@ -230,7 +230,7 @@ void SettingsDialog::EditApplication() { QList selected = mUI.mListWidget->selectedItems(); QListWidgetItem *item = 0; - foreach (item, selected) { + foreach(item, selected) { int row = mUI.mListWidget->row(item); Application& app = mTempApplications->GetApplication(row); ApplicationDialog dialog(tr("Modify an application"), app, this); diff --git a/gui/test/benchmark/simple/benchmarksimple.h b/gui/test/benchmark/simple/benchmarksimple.h index 587dba9be..0efa544e7 100644 --- a/gui/test/benchmark/simple/benchmarksimple.h +++ b/gui/test/benchmark/simple/benchmarksimple.h @@ -31,10 +31,8 @@ private slots: private: // Empty implementations of ErrorLogger methods. // We don't care about the output in the benchmark tests. - void reportOut(const std::string & outmsg) - { + void reportOut(const std::string & outmsg) { } - void reportErr(const ErrorLogger::ErrorMessage &msg) - { + void reportErr(const ErrorLogger::ErrorMessage &msg) { } }; diff --git a/gui/test/data/benchmark/simple.cpp b/gui/test/data/benchmark/simple.cpp index 685aac62a..8931eb3a2 100644 --- a/gui/test/data/benchmark/simple.cpp +++ b/gui/test/data/benchmark/simple.cpp @@ -988,8 +988,7 @@ public: ScopeInfo(const Token *token, ScopeInfo *parent_) : _token(token), _parent(parent_) { } ~ScopeInfo(); - ScopeInfo *parent() - { + ScopeInfo *parent() { return _parent; } ScopeInfo *addChild(const Token *token); @@ -1054,20 +1053,17 @@ public: _read(read), _write(write), _modified(modified), - _allocateMemory(allocateMemory) - { + _allocateMemory(allocateMemory) { } /** variable is used.. set both read+write */ - void use() - { + void use() { _read = true; _write = true; } /** is variable unused? */ - bool unused() const - { + bool unused() const { return (_read == false && _write == false); } @@ -1084,12 +1080,10 @@ public: typedef std::map VariableMap; - void clear() - { + void clear() { _varUsage.clear(); } - VariableMap &varUsage() - { + VariableMap &varUsage() { return _varUsage; } void addVar(const Token *name, VariableType type, ScopeInfo *scope, bool write_); @@ -1104,8 +1098,7 @@ public: void modified(unsigned int varid); VariableUsage *find(unsigned int varid); void alias(unsigned int varid1, unsigned int varid2, bool replace); - void erase(unsigned int varid) - { + void erase(unsigned int varid) { _varUsage.erase(varid); } void eraseAliases(unsigned int varid); diff --git a/gui/threadresult.cpp b/gui/threadresult.cpp index 6610cc7e4..ccffd0973 100644 --- a/gui/threadresult.cpp +++ b/gui/threadresult.cpp @@ -109,7 +109,7 @@ void ThreadResult::SetFiles(const QStringList &files) // Determine the total size of all of the files to check, so that we can // show an accurate progress estimate quint64 sizeOfFiles = 0; - foreach (const QString& file, files) { + foreach(const QString& file, files) { sizeOfFiles += QFile(file).size(); } mMaxProgress = sizeOfFiles; diff --git a/gui/translationhandler.cpp b/gui/translationhandler.cpp index c7d884936..97ed15067 100644 --- a/gui/translationhandler.cpp +++ b/gui/translationhandler.cpp @@ -63,7 +63,7 @@ TranslationHandler::~TranslationHandler() const QStringList TranslationHandler::GetNames() const { QStringList names; - foreach (TranslationInfo translation, mTranslations) { + foreach(TranslationInfo translation, mTranslations) { names.append(translation.mName); } return names; diff --git a/gui/translationhandler.h b/gui/translationhandler.h index 2f5d6add8..b2c629dc8 100644 --- a/gui/translationhandler.h +++ b/gui/translationhandler.h @@ -76,8 +76,7 @@ public: * @return List of available translations. * */ - QList GetTranslations() const - { + QList GetTranslations() const { return mTranslations; } diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index 2468c8d99..796184d84 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -75,7 +75,7 @@ int XmlReport::determineVersion(const QString &filename) } break; - // Not handled + // Not handled case QXmlStreamReader::EndElement: case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: diff --git a/gui/xmlreportv1.cpp b/gui/xmlreportv1.cpp index 4b45e4929..643806e1d 100644 --- a/gui/xmlreportv1.cpp +++ b/gui/xmlreportv1.cpp @@ -132,7 +132,7 @@ QList XmlReportV1::Read() insideResults = false; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: diff --git a/gui/xmlreportv2.cpp b/gui/xmlreportv2.cpp index ab7bba756..544b76ec2 100644 --- a/gui/xmlreportv2.cpp +++ b/gui/xmlreportv2.cpp @@ -157,7 +157,7 @@ QList XmlReportV2::Read() insideResults = false; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: @@ -220,7 +220,7 @@ ErrorItem XmlReportV2::ReadError(QXmlStreamReader *reader) errorRead = true; break; - // Not handled + // Not handled case QXmlStreamReader::NoToken: case QXmlStreamReader::Invalid: case QXmlStreamReader::StartDocument: diff --git a/lib/check.h b/lib/check.h index 6f3213657..6328b7dfc 100644 --- a/lib/check.h +++ b/lib/check.h @@ -44,26 +44,22 @@ public: /** This constructor is used when running checks. */ Check(const std::string &aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger), _name(aname) - { + : _tokenizer(tokenizer), _settings(settings), _errorLogger(errorLogger), _name(aname) { } - virtual ~Check() - { + virtual ~Check() { if (!_tokenizer) instances().remove(this); } /** List of registered check classes. This is used by Cppcheck to run checks and generate documentation */ - static std::list &instances() - { + static std::list &instances() { static std::list _instances; return _instances; } /** run checks, the token list is not simplified */ - virtual void runChecks(const Tokenizer *, const Settings *, ErrorLogger *) - { + virtual void runChecks(const Tokenizer *, const Settings *, ErrorLogger *) { } /** run checks, the token list is simplified */ @@ -73,8 +69,7 @@ public: virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const = 0; /** class name, used to generate documentation */ - const std::string& name() const - { + const std::string& name() const { return _name; } @@ -88,8 +83,7 @@ public: */ static void reportError(const ErrorLogger::ErrorMessage &errmsg); - bool inconclusiveFlag() const - { + bool inconclusiveFlag() const { return _settings && _settings->inconclusive; } @@ -100,15 +94,13 @@ public: virtual ~FileInfo() {} }; - virtual FileInfo * getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const - { + virtual FileInfo * getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const { (void)tokenizer; (void)settings; return nullptr; } - virtual void analyseWholeProgram(const std::list &fileInfo, ErrorLogger &errorLogger) - { + virtual void analyseWholeProgram(const std::list &fileInfo, ErrorLogger &errorLogger) { (void)fileInfo; (void)errorLogger; } @@ -120,16 +112,14 @@ protected: /** report an error */ template - void reportError(const Token *tok, const Severity::SeverityType severity, const T id, const U msg, bool inconclusive = false) - { + void reportError(const Token *tok, const Severity::SeverityType severity, const T id, const U msg, bool inconclusive = false) { std::list callstack(1, tok); reportError(callstack, severity, id, msg, inconclusive); } /** report an error */ template - void reportError(const std::list &callstack, Severity::SeverityType severity, const T id, const U msg, bool inconclusive = false) - { + void reportError(const std::list &callstack, Severity::SeverityType severity, const T id, const U msg, bool inconclusive = false) { ErrorLogger::ErrorMessage errmsg(callstack, _tokenizer?&_tokenizer->list:0, severity, id, msg, inconclusive); if (_errorLogger) _errorLogger->reportErr(errmsg); diff --git a/lib/check64bit.h b/lib/check64bit.h index 9706e2a52..ce3b849fc 100644 --- a/lib/check64bit.h +++ b/lib/check64bit.h @@ -36,26 +36,22 @@ class CPPCHECKLIB Check64BitPortability : public Check { public: /** This constructor is used when registering the Check64BitPortability */ - Check64BitPortability() : Check(myName()) - { + Check64BitPortability() : Check(myName()) { } /** This constructor is used when running checks. */ Check64BitPortability(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { Check64BitPortability check64BitPortability(tokenizer, settings, errorLogger); check64BitPortability.pointerassignment(); } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { (void)tokenizer; (void)settings; (void)errorLogger; @@ -71,8 +67,7 @@ private: void returnIntegerError(const Token *tok); void returnPointerError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { Check64BitPortability c(0, settings, errorLogger); c.assignmentAddressToIntegerError(0); c.assignmentIntegerToAddressError(0); @@ -80,13 +75,11 @@ private: c.returnPointerError(0); } - static std::string myName() - { + static std::string myName() { return "64-bit portability"; } - std::string classInfo() const - { + std::string classInfo() const { return "Check if there is 64-bit portability issues:\n" "- assign address to/from int/long\n" "- casting address from/to integer when returning from function\n"; diff --git a/lib/checkassert.h b/lib/checkassert.h index 4abe077ea..892b032fc 100644 --- a/lib/checkassert.h +++ b/lib/checkassert.h @@ -34,17 +34,14 @@ class CPPCHECKLIB CheckAssert : public Check { public: - CheckAssert() : Check(myName()) - { + CheckAssert() : Check(myName()) { } CheckAssert(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } - virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckAssert check(tokenizer, settings, errorLogger); check.assertWithSideEffects(); } @@ -59,20 +56,17 @@ private: void sideEffectInAssertError(const Token *tok, const std::string& functionName); void assignmentInAssertError(const Token *tok, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckAssert c(0, settings, errorLogger); c.sideEffectInAssertError(0, "function"); c.assignmentInAssertError(0, "var"); } - static std::string myName() - { + static std::string myName() { return "Assert"; } - std::string classInfo() const - { + std::string classInfo() const { return "Warn if there are side effects in assert statements (since this cause different behaviour in debug/release builds).\n"; } }; diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index 53d00505c..c554332f3 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -33,26 +33,22 @@ class CPPCHECKLIB CheckAutoVariables : public Check { public: /** This constructor is used when registering the CheckClass */ - CheckAutoVariables() : Check(myName()) - { + CheckAutoVariables() : Check(myName()) { } /** This constructor is used when running checks. */ CheckAutoVariables(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckAutoVariables checkAutoVariables(tokenizer, settings, errorLogger); checkAutoVariables.assignFunctionArg(); checkAutoVariables.returnReference(); } - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckAutoVariables checkAutoVariables(tokenizer, settings, errorLogger); checkAutoVariables.autoVariables(); checkAutoVariables.returnPointerToLocalArray(); @@ -94,8 +90,7 @@ private: void errorUselessAssignmentArg(const Token *tok); void errorUselessAssignmentPtrArg(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckAutoVariables c(0,settings,errorLogger); c.errorAutoVariableAssignment(0, false); c.errorReturnAddressToAutoVariable(0); @@ -108,13 +103,11 @@ private: c.errorUselessAssignmentPtrArg(0); } - static std::string myName() - { + static std::string myName() { return "Auto Variables"; } - std::string classInfo() const - { + std::string classInfo() const { return "A pointer to a variable is only valid as long as the variable is in scope.\n" "Check:\n" "- returning a pointer to auto or temporary variable\n" diff --git a/lib/checkbool.h b/lib/checkbool.h index aaa7320df..4d69d1602 100644 --- a/lib/checkbool.h +++ b/lib/checkbool.h @@ -37,19 +37,16 @@ class Variable; class CPPCHECKLIB CheckBool : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckBool() : Check(myName()) - { + CheckBool() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckBool(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckBool checkBool(tokenizer, settings, errorLogger); // Checks @@ -60,8 +57,7 @@ public: } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckBool checkBool(tokenizer, settings, errorLogger); // Checks @@ -114,8 +110,7 @@ private: void comparisonOfBoolExpressionWithIntError(const Token *tok, bool n0o1); void pointerArithBoolError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckBool c(0, settings, errorLogger); c.assignBoolToPointerError(0); @@ -129,13 +124,11 @@ private: c.pointerArithBoolError(0); } - static std::string myName() - { + static std::string myName() { return "Boolean"; } - std::string classInfo() const - { + std::string classInfo() const { return "Boolean type checks\n" "- using increment on boolean\n" "- comparison of a boolean with a non-zero integer\n" diff --git a/lib/checkboost.h b/lib/checkboost.h index 27cb296e4..aa5daf9a5 100644 --- a/lib/checkboost.h +++ b/lib/checkboost.h @@ -35,19 +35,16 @@ class Token; class CPPCHECKLIB CheckBoost : public Check { public: /** This constructor is used when registering the CheckClass */ - CheckBoost() : Check(myName()) - { + CheckBoost() : Check(myName()) { } /** This constructor is used when running checks. */ CheckBoost(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** Simplified checks. The token list is simplified. */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { if (!tokenizer->isCPP()) return; @@ -62,19 +59,16 @@ public: private: void boostForeachError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckBoost c(0, settings, errorLogger); c.boostForeachError(0); } - static std::string myName() - { + static std::string myName() { return "Boost usage"; } - std::string classInfo() const - { + std::string classInfo() const { return "Check for invalid usage of Boost:\n" "- container modification during BOOST_FOREACH\n"; } diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index d43226048..e64bdd65a 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -47,18 +47,15 @@ class CPPCHECKLIB CheckBufferOverrun : public Check { public: /** This constructor is used when registering the CheckClass */ - CheckBufferOverrun() : Check(myName()) - { + CheckBufferOverrun() : Check(myName()) { } /** This constructor is used when running checks. */ CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckBufferOverrun checkBufferOverrun(tokenizer, settings, errorLogger); checkBufferOverrun.bufferOverrun(); checkBufferOverrun.bufferOverrun2(); @@ -143,44 +140,36 @@ public: ArrayInfo limit(MathLib::bigint value) const; /** array sizes */ - const std::vector &num() const - { + const std::vector &num() const { return _num; } /** array size */ - MathLib::bigint num(std::size_t index) const - { + MathLib::bigint num(std::size_t index) const { return _num[index]; } - void num(std::size_t index, MathLib::bigint number) - { + void num(std::size_t index, MathLib::bigint number) { _num[index] = number; } /** size of each element */ - MathLib::bigint element_size() const - { + MathLib::bigint element_size() const { return _element_size; } /** Variable name */ - unsigned int declarationId() const - { + unsigned int declarationId() const { return _declarationId; } - void declarationId(unsigned int id) - { + void declarationId(unsigned int id) { _declarationId = id; } /** Variable name */ - const std::string &varname() const - { + const std::string &varname() const { return _varname; } - void varname(const std::string &name) - { + void varname(const std::string &name) { _varname = name; } }; @@ -261,8 +250,7 @@ private: void valueFlowCheckArrayIndex(const Token * const tok, const ArrayInfo &arrayInfo); public: - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckBufferOverrun c(0, settings, errorLogger); std::vector indexes; indexes.push_back(2); @@ -286,13 +274,11 @@ public: } private: - static std::string myName() - { + static std::string myName() { return "Bounds checking"; } - std::string classInfo() const - { + std::string classInfo() const { return "Out of bounds checking:\n" "- Array index out of bounds detection by value flow analysis\n" "- Dangerous usage of strncat()\n" diff --git a/lib/checkclass.h b/lib/checkclass.h index 451924daf..562773b23 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -35,16 +35,14 @@ class Function; class CPPCHECKLIB CheckClass : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckClass() : Check(myName()), symbolDatabase(NULL) - { + CheckClass() : Check(myName()), symbolDatabase(NULL) { } /** @brief This constructor is used when running checks. */ CheckClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger); /** @brief Run checks on the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { if (tokenizer->isC()) return; @@ -55,8 +53,7 @@ public: } /** @brief Run checks on the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { if (tokenizer->isC()) return; @@ -163,8 +160,7 @@ private: void callsPureVirtualFunctionError(const Function & scopeFunction, const std::list & tokStack, const std::string &purefuncname); void duplInheritedMembersError(const Token* tok1, const Token* tok2, const std::string &derivedname, const std::string &basename, const std::string &variablename, bool derivedIsStruct, bool baseIsStruct); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckClass c(0, settings, errorLogger); c.noConstructorError(0, "classname", false); //c.copyConstructorMallocError(0, 0, "var"); @@ -191,13 +187,11 @@ private: c.duplInheritedMembersError(0, 0, "class", "class", "variable", false, false); } - static std::string myName() - { + static std::string myName() { return "Class"; } - std::string classInfo() const - { + std::string classInfo() const { return "Check the code for each class.\n" "- Missing constructors and copy constructors\n" //"- Missing allocation of memory in copy constructor\n" diff --git a/lib/checkcondition.h b/lib/checkcondition.h index 1ac623150..681caf2ed 100644 --- a/lib/checkcondition.h +++ b/lib/checkcondition.h @@ -36,26 +36,22 @@ class CPPCHECKLIB CheckCondition : public Check { public: /** This constructor is used when registering the CheckAssignIf */ - CheckCondition() : Check(myName()) - { + CheckCondition() : Check(myName()) { } /** This constructor is used when running checks. */ CheckCondition(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckCondition checkCondition(tokenizer, settings, errorLogger); checkCondition.multiCondition(); checkCondition.clarifyCondition(); // not simplified because ifAssign } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckCondition checkCondition(tokenizer, settings, errorLogger); checkCondition.assignIf(); checkCondition.comparison(); @@ -114,8 +110,7 @@ private: void clarifyConditionError(const Token *tok, bool assign, bool boolop); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckCondition c(0, settings, errorLogger); c.assignIfError(0, 0, "", false); @@ -129,13 +124,11 @@ private: c.clarifyConditionError(0, true, false); } - static std::string myName() - { + static std::string myName() { return "Condition"; } - std::string classInfo() const - { + std::string classInfo() const { return "Match conditions with assignments and other conditions:\n" "- Mismatching assignment and comparison => comparison is always true/false\n" "- Mismatching lhs and rhs in comparison => comparison is always true/false\n" diff --git a/lib/checkexceptionsafety.h b/lib/checkexceptionsafety.h index 3986e093e..d370eb694 100644 --- a/lib/checkexceptionsafety.h +++ b/lib/checkexceptionsafety.h @@ -40,19 +40,16 @@ class CPPCHECKLIB CheckExceptionSafety : public Check { public: /** This constructor is used when registering the CheckClass */ - CheckExceptionSafety() : Check(myName()) - { + CheckExceptionSafety() : Check(myName()) { } /** This constructor is used when running checks. */ CheckExceptionSafety(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** Checks that uses the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { if (tokenizer->isC()) return; @@ -85,8 +82,7 @@ public: private: /** Don't throw exceptions in destructors */ - void destructorsError(const Token * const tok, const std::string &className) - { + void destructorsError(const Token * const tok, const std::string &className) { reportError(tok, Severity::warning, "exceptThrowInDestructor", "Class " + className + " is not safe, destructor throws exception\n" "The class " + className + " is not safe because its destructor " @@ -94,22 +90,19 @@ private: "is thrown that is caught in an outer scope the program will terminate."); } - void deallocThrowError(const Token * const tok, const std::string &varname) - { + void deallocThrowError(const Token * const tok, const std::string &varname) { reportError(tok, Severity::warning, "exceptDeallocThrow", "Exception thrown in invalid state, '" + varname + "' points at deallocated memory."); } - void rethrowCopyError(const Token * const tok, const std::string &varname) - { + void rethrowCopyError(const Token * const tok, const std::string &varname) { reportError(tok, Severity::style, "exceptRethrowCopy", "Throwing a copy of the caught exception instead of rethrowing the original exception.\n" "Rethrowing an exception with 'throw " + varname + ";' creates an unnecessary copy of '" + varname + "'. " "To rethrow the caught exception without unnecessary copying or slicing, use a bare 'throw;'."); } - void catchExceptionByValueError(const Token *tok) - { + void catchExceptionByValueError(const Token *tok) { reportError(tok, Severity::style, "catchExceptionByValue", "Exception should be caught by reference.\n" "The exception is caught by value. It could be caught " @@ -117,32 +110,27 @@ private: } /** Don't throw exceptions in noexcept functions */ - void noexceptThrowError(const Token * const tok) - { + void noexceptThrowError(const Token * const tok) { reportError(tok, Severity::error, "exceptThrowInNoexecptFunction", "Exception thrown in noexcept function."); } /** Don't throw exceptions in throw() functions */ - void nothrowThrowError(const Token * const tok) - { + void nothrowThrowError(const Token * const tok) { reportError(tok, Severity::error, "exceptThrowInNoThrowFunction", "Exception thrown in throw() function."); } /** Don't throw exceptions in __attribute__((nothrow)) functions */ - void nothrowAttributeThrowError(const Token * const tok) - { + void nothrowAttributeThrowError(const Token * const tok) { reportError(tok, Severity::error, "exceptThrowInAttributeNoThrowFunction", "Exception thrown in __attribute__((nothrow)) function."); } /** Don't throw exceptions in __declspec(nothrow) functions */ - void nothrowDeclspecThrowError(const Token * const tok) - { + void nothrowDeclspecThrowError(const Token * const tok) { reportError(tok, Severity::error, "exceptThrowInDeclspecNoThrowFunction", "Exception thrown in __declspec(nothrow) function."); } /** Missing exception specification */ - void unhandledExceptionSpecificationError(const Token * const tok1, const Token * const tok2, const std::string & funcname) - { + void unhandledExceptionSpecificationError(const Token * const tok1, const Token * const tok2, const std::string & funcname) { std::string str1(tok1 ? tok1->str() : "foo"); std::list locationList; locationList.push_back(tok1); @@ -154,8 +142,7 @@ private: } /** Generate all possible errors (for --errorlist) */ - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckExceptionSafety c(0, settings, errorLogger); c.destructorsError(0, "Class"); c.deallocThrowError(0, "p"); @@ -169,14 +156,12 @@ private: } /** Short description of class (for --doc) */ - static std::string myName() - { + static std::string myName() { return "Exception Safety"; } /** wiki formatted description of the class (for --doc) */ - std::string classInfo() const - { + std::string classInfo() const { return "Checking exception safety\n" "- Throwing exceptions in destructors\n" "- Throwing exception during invalid state\n" diff --git a/lib/checkinternal.h b/lib/checkinternal.h index 784950aa9..77372665d 100644 --- a/lib/checkinternal.h +++ b/lib/checkinternal.h @@ -33,19 +33,16 @@ class CPPCHECKLIB CheckInternal : public Check { public: /** This constructor is used when registering the CheckClass */ - CheckInternal() : Check(myName()) - { + CheckInternal() : Check(myName()) { } /** This constructor is used when running checks. */ CheckInternal(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** Simplified checks. The token list is simplified. */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { if (!settings->isEnabled("internal")) return; @@ -82,8 +79,7 @@ private: void redundantNextPreviousError(const Token* tok, const std::string& func1, const std::string& func2); void orInComplexPattern(const Token *tok, const std::string &pattern, const std::string &funcname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckInternal c(0, settings, errorLogger); c.multiComparePatternError(0, ";|%type%", "Match"); c.simplePatternError(0, "class {", "Match"); @@ -94,13 +90,11 @@ private: c.orInComplexPattern(0, "||", "Match"); } - static std::string myName() - { + static std::string myName() { return "cppcheck internal API usage"; } - std::string classInfo() const - { + std::string classInfo() const { // Don't include these checks on the WIKI where people can read what // checks there are. These checks are not intended for users. return ""; diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 39d4b279c..16ff14a44 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -89,8 +89,7 @@ struct Filepointer { enum AppendMode { UNKNOWN_AM, APPEND, APPEND_EX }; AppendMode append_mode; explicit Filepointer(OpenMode mode_ = UNKNOWN_OM) - : mode(mode_), mode_indent(0), lastOperation(NONE), op_indent(0), append_mode(UNKNOWN_AM) - { + : mode(mode_), mode_indent(0), lastOperation(NONE), op_indent(0), append_mode(UNKNOWN_AM) { } }; @@ -1005,7 +1004,7 @@ void CheckIO::checkWrongPrintfScanfArguments() case 'l': if (i+1 != formatString.end() && *(i+1) == *i) specifier += *i++; - // fallthrough + // fallthrough case 'j': case 'q': case 't': @@ -1307,7 +1306,7 @@ void CheckIO::checkWrongPrintfScanfArguments() specifier += *i++; specifier += *i++; } - // fallthrough + // fallthrough case 'j': // intmax_t or uintmax_t case 'z': // size_t case 't': // ptrdiff_t diff --git a/lib/checkio.h b/lib/checkio.h index c40ddbcda..12bf3cde6 100644 --- a/lib/checkio.h +++ b/lib/checkio.h @@ -31,27 +31,23 @@ class CPPCHECKLIB CheckIO : public Check { public: /** @brief This constructor is used when registering CheckIO */ - CheckIO() : Check(myName()) - { + CheckIO() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckIO(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks on the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckIO checkIO(tokenizer, settings, errorLogger); checkIO.checkWrongPrintfScanfArguments(); } /** @brief Run checks on the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckIO checkIO(tokenizer, settings, errorLogger); checkIO.checkCoutCerrMisusage(); @@ -126,8 +122,7 @@ private: void invalidScanfFormatWidthError(const Token* tok, unsigned int numFormat, int width, const Variable *var); static void argumentType(std::ostream & s, const ArgumentInfo * argInfo); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckIO c(0, settings, errorLogger); c.coutCerrMisusageError(0, "cout"); @@ -154,13 +149,11 @@ private: c.wrongPrintfScanfPosixParameterPositionError(0, "printf", 2, 1); } - static std::string myName() - { + static std::string myName() { return "IO using format string"; } - std::string classInfo() const - { + std::string classInfo() const { return "Check format string input/output operations.\n" "- Bad usage of the function 'sprintf' (overlapping data)\n" "- Missing or wrong width specifiers in 'scanf' format string\n" diff --git a/lib/checkleakautovar.h b/lib/checkleakautovar.h index 51a852f5b..4b6714a64 100644 --- a/lib/checkleakautovar.h +++ b/lib/checkleakautovar.h @@ -36,23 +36,20 @@ public: std::set conditionalAlloc; std::set referenced; - void clear() - { + void clear() { alloctype.clear(); possibleUsage.clear(); conditionalAlloc.clear(); referenced.clear(); } - void erase(unsigned int varid) - { + void erase(unsigned int varid) { alloctype.erase(varid); possibleUsage.erase(varid); conditionalAlloc.erase(varid); } - void swap(VarInfo &other) - { + void swap(VarInfo &other) { alloctype.swap(other.alloctype); possibleUsage.swap(other.possibleUsage); conditionalAlloc.swap(other.conditionalAlloc); @@ -76,19 +73,16 @@ public: class CPPCHECKLIB CheckLeakAutoVar : public Check { public: /** This constructor is used when registering the CheckLeakAutoVar */ - CheckLeakAutoVar() : Check(myName()) - { + CheckLeakAutoVar() : Check(myName()) { } /** This constructor is used when running checks. */ CheckLeakAutoVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckLeakAutoVar checkLeakAutoVar(tokenizer, settings, errorLogger); checkLeakAutoVar.check(); } @@ -120,20 +114,17 @@ private: /** message: user configuration is needed to complete analysis */ void configurationInfo(const Token* tok, const std::string &functionName); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckLeakAutoVar c(0, settings, errorLogger); c.deallocReturnError(0, "p"); c.configurationInfo(0, "f"); // user configuration is needed to complete analysis } - static std::string myName() - { + static std::string myName() { return "Leaks (auto variables)"; } - std::string classInfo() const - { + std::string classInfo() const { return "Detect when a auto variable is allocated but not deallocated.\n"; } }; diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index 564810993..bef7bfb4a 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -86,8 +86,7 @@ private: public: CheckMemoryLeak(const Tokenizer *t, ErrorLogger *e, const Settings *s) - : tokenizer(t), errorLogger(e), settings1(s) - { + : tokenizer(t), errorLogger(e), settings1(s) { } /** @brief What type of allocation are used.. the "Many" means that several types of allocation and deallocation are used */ @@ -182,14 +181,12 @@ public: class CPPCHECKLIB CheckMemoryLeakInFunction : private Check, public CheckMemoryLeak { public: /** @brief This constructor is used when registering this class */ - CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(0, 0, 0), symbolDatabase(NULL) - { + CheckMemoryLeakInFunction() : Check(myName()), CheckMemoryLeak(0, 0, 0), symbolDatabase(NULL) { } /** @brief This constructor is used when running checks */ CheckMemoryLeakInFunction(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) - : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) - { + : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) { // get the symbol database if (tokenizr) symbolDatabase = tokenizr->getSymbolDatabase(); @@ -198,8 +195,7 @@ public: } /** @brief run all simplified checks */ - void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) - { + void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) { CheckMemoryLeakInFunction checkMemoryLeak(tokenizr, settings, errLog); checkMemoryLeak.checkReallocUsage(); checkMemoryLeak.check(); @@ -302,8 +298,7 @@ public: private: /** Report all possible errors (for the --errorlist) */ - void getErrorMessages(ErrorLogger *e, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *e, const Settings *settings) const { CheckMemoryLeakInFunction c(0, settings, e); c.memleakError(0, "varname"); @@ -321,8 +316,7 @@ private: * Get name of class (--doc) * @return name of class */ - static std::string myName() - { + static std::string myName() { return "Memory leaks (function variables)"; } @@ -330,8 +324,7 @@ private: * Get class information (--doc) * @return Wiki formatted information about this class */ - std::string classInfo() const - { + std::string classInfo() const { return "Is there any allocated memory when a function goes out of scope\n"; } @@ -346,17 +339,14 @@ private: class CPPCHECKLIB CheckMemoryLeakInClass : private Check, private CheckMemoryLeak { public: - CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(0, 0, 0) - { + CheckMemoryLeakInClass() : Check(myName()), CheckMemoryLeak(0, 0, 0) { } CheckMemoryLeakInClass(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) - : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) - { + : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) { } - void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) - { + void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) { if (!tokenizr->isCPP()) return; @@ -375,20 +365,17 @@ private: void unsafeClassError(const Token *tok, const std::string &classname, const std::string &varname); - void getErrorMessages(ErrorLogger *e, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *e, const Settings *settings) const { CheckMemoryLeakInClass c(0, settings, e); c.publicAllocationError(0, "varname"); c.unsafeClassError(0, "class", "class::varname"); } - static std::string myName() - { + static std::string myName() { return "Memory leaks (class variables)"; } - std::string classInfo() const - { + std::string classInfo() const { return "If the constructor allocate memory then the destructor must deallocate it.\n"; } }; @@ -399,17 +386,14 @@ private: class CPPCHECKLIB CheckMemoryLeakStructMember : private Check, private CheckMemoryLeak { public: - CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(0, 0, 0) - { + CheckMemoryLeakStructMember() : Check(myName()), CheckMemoryLeak(0, 0, 0) { } CheckMemoryLeakStructMember(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) - : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) - { + : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) { } - void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) - { + void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) { CheckMemoryLeakStructMember checkMemoryLeak(tokenizr, settings, errLog); checkMemoryLeak.check(); } @@ -423,17 +407,14 @@ private: void checkStructVariable(const Variable * const variable); - void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const - { + void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/) const { } - static std::string myName() - { + static std::string myName() { return "Memory leaks (struct members)"; } - std::string classInfo() const - { + std::string classInfo() const { return "Don't forget to deallocate struct members\n"; } }; @@ -444,17 +425,14 @@ private: class CPPCHECKLIB CheckMemoryLeakNoVar : private Check, private CheckMemoryLeak { public: - CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(0, 0, 0) - { + CheckMemoryLeakNoVar() : Check(myName()), CheckMemoryLeak(0, 0, 0) { } CheckMemoryLeakNoVar(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) - : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) - { + : Check(myName(), tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog, settings) { } - void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) - { + void runSimplifiedChecks(const Tokenizer *tokenizr, const Settings *settings, ErrorLogger *errLog) { CheckMemoryLeakNoVar checkMemoryLeak(tokenizr, settings, errLog); checkMemoryLeak.check(); } @@ -471,21 +449,18 @@ private: void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall); void returnValueNotUsedError(const Token* tok, const std::string &alloc); - void getErrorMessages(ErrorLogger *e, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *e, const Settings *settings) const { CheckMemoryLeakNoVar c(0, settings, e); c.functionCallLeak(0, "funcName", "funcName"); c.returnValueNotUsedError(0, "funcName"); } - static std::string myName() - { + static std::string myName() { return "Memory leaks (address not taken)"; } - std::string classInfo() const - { + std::string classInfo() const { return "Not taking the address to allocated memory\n"; } }; diff --git a/lib/checknonreentrantfunctions.h b/lib/checknonreentrantfunctions.h index 3bfa2671a..8eb6fd6c2 100644 --- a/lib/checknonreentrantfunctions.h +++ b/lib/checknonreentrantfunctions.h @@ -37,20 +37,17 @@ class CPPCHECKLIB CheckNonReentrantFunctions : public Check { public: /** This constructor is used when registering the CheckNonReentrantFunctions */ - CheckNonReentrantFunctions() : Check(myName()) - { + CheckNonReentrantFunctions() : Check(myName()) { initNonReentrantFunctions(); } /** This constructor is used when running checks. */ CheckNonReentrantFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { initNonReentrantFunctions(); } - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckNonReentrantFunctions checkNonReentrantFunctions(tokenizer, settings, errorLogger); checkNonReentrantFunctions.nonReentrantFunctions(); } @@ -64,8 +61,7 @@ private: std::map _nonReentrantFunctions; /** init nonreentrant functions list ' */ - void initNonReentrantFunctions() - { + void initNonReentrantFunctions() { static const char * const non_reentrant_functions_list[] = { "localtime", "gmtime", "strtok", "gethostbyname", "gethostbyaddr", "getservbyname" , "getservbyport", "crypt", "ttyname", "gethostbyname2" @@ -86,8 +82,7 @@ private: } } - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckNonReentrantFunctions c(0, settings, errorLogger); std::map::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end()); @@ -96,13 +91,11 @@ private: } } - static std::string myName() - { + static std::string myName() { return "Non reentrant functions"; } - std::string classInfo() const - { + std::string classInfo() const { std::string info = "Warn if any of these non reentrant functions are used:\n"; std::map::const_iterator it(_nonReentrantFunctions.begin()), itend(_nonReentrantFunctions.end()); for (; it!=itend; ++it) { diff --git a/lib/checknullpointer.h b/lib/checknullpointer.h index 6785a2077..4d1af3f13 100644 --- a/lib/checknullpointer.h +++ b/lib/checknullpointer.h @@ -35,26 +35,22 @@ class CPPCHECKLIB CheckNullPointer : public Check { public: /** @brief This constructor is used when registering the CheckNullPointer */ - CheckNullPointer() : Check(myName()) - { + CheckNullPointer() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckNullPointer(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckNullPointer checkNullPointer(tokenizer, settings, errorLogger); checkNullPointer.nullPointer(); } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckNullPointer checkNullPointer(tokenizer, settings, errorLogger); checkNullPointer.nullConstantDereference(); } @@ -96,21 +92,18 @@ public: private: /** Get error messages. Used by --errorlist */ - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckNullPointer c(0, settings, errorLogger); c.nullPointerError(0, "pointer"); } /** Name of check */ - static std::string myName() - { + static std::string myName() { return "Null pointer"; } /** class info in WIKI format. Used by --doc */ - std::string classInfo() const - { + std::string classInfo() const { return "Null pointers\n" "- null pointer dereferencing\n"; } diff --git a/lib/checkobsolescentfunctions.h b/lib/checkobsolescentfunctions.h index 2e701d57b..84031ba58 100644 --- a/lib/checkobsolescentfunctions.h +++ b/lib/checkobsolescentfunctions.h @@ -38,20 +38,17 @@ class CPPCHECKLIB CheckObsoleteFunctions : public Check { public: /** This constructor is used when registering the CheckObsoleteFunctions */ - CheckObsoleteFunctions() : Check(myName()) - { + CheckObsoleteFunctions() : Check(myName()) { initObsoleteFunctions(); } /** This constructor is used when running checks. */ CheckObsoleteFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { initObsoleteFunctions(); } - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckObsoleteFunctions checkObsoleteFunctions(tokenizer, settings, errorLogger); checkObsoleteFunctions.obsoleteFunctions(); } @@ -66,8 +63,7 @@ private: std::map _obsoleteC99Functions; /** init obsolete functions list ' */ - void initObsoleteFunctions() - { + void initObsoleteFunctions() { // Obsolete posix functions, which messages suggest only one alternative and doesn't contain additional information. const struct { const char* bad; @@ -126,8 +122,7 @@ private: //_obsoleteC99Functions["ctime"] = "Obsolete function 'ctime' called. It is recommended to use the function 'strftime' instead."; } - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckObsoleteFunctions c(0, settings, errorLogger); std::map::const_iterator it(_obsoletePosixFunctions.begin()), itend(_obsoletePosixFunctions.end()); @@ -136,13 +131,11 @@ private: } } - static std::string myName() - { + static std::string myName() { return "Obsolete functions"; } - std::string classInfo() const - { + std::string classInfo() const { std::string info = "Warn if any of these obsolete functions are used:\n"; std::map::const_iterator it(_obsoletePosixFunctions.begin()), itend(_obsoletePosixFunctions.end()); for (; it!=itend; ++it) { diff --git a/lib/checkother.h b/lib/checkother.h index a56b3db3d..c4efb5140 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -44,19 +44,16 @@ bool astIsFloat(const Token *tok, bool unknown); class CPPCHECKLIB CheckOther : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckOther() : Check(myName()) - { + CheckOther() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckOther(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckOther checkOther(tokenizer, settings, errorLogger); // Checks @@ -80,8 +77,7 @@ public: } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckOther checkOther(tokenizer, settings, errorLogger); // Checks @@ -292,8 +288,7 @@ private: void commaSeparatedReturnError(const Token *tok); void ignoredReturnValueError(const Token* tok, const std::string& function); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckOther c(0, settings, errorLogger); // error @@ -350,13 +345,11 @@ private: c.ignoredReturnValueError(0, "malloc"); } - static std::string myName() - { + static std::string myName() { return "Other"; } - std::string classInfo() const - { + std::string classInfo() const { return "Other checks\n" // error diff --git a/lib/checkpostfixoperator.h b/lib/checkpostfixoperator.h index a1e6b5bc4..b65f50ba7 100644 --- a/lib/checkpostfixoperator.h +++ b/lib/checkpostfixoperator.h @@ -35,18 +35,15 @@ class CPPCHECKLIB CheckPostfixOperator : public Check { public: /** This constructor is used when registering the CheckPostfixOperator */ - CheckPostfixOperator() : Check(myName()) - { + CheckPostfixOperator() : Check(myName()) { } /** This constructor is used when running checks. */ CheckPostfixOperator(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { if (tokenizer->isC()) return; @@ -61,19 +58,16 @@ private: /** Report Error */ void postfixOperatorError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckPostfixOperator c(0, settings, errorLogger); c.postfixOperatorError(0); } - static std::string myName() - { + static std::string myName() { return "Using postfix operators"; } - std::string classInfo() const - { + std::string classInfo() const { return "Warn if using postfix operators ++ or -- rather than prefix operator\n"; } }; diff --git a/lib/checksizeof.h b/lib/checksizeof.h index 0a1596d15..15c8783bf 100644 --- a/lib/checksizeof.h +++ b/lib/checksizeof.h @@ -37,19 +37,16 @@ class Variable; class CPPCHECKLIB CheckSizeof : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckSizeof() : Check(myName()) - { + CheckSizeof() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckSizeof(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger) - { + void runChecks(const Tokenizer* tokenizer, const Settings* settings, ErrorLogger* errorLogger) { CheckSizeof checkSizeof(tokenizer, settings, errorLogger); // Checks @@ -63,8 +60,7 @@ public: } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer*, const Settings*, ErrorLogger*) - { + void runSimplifiedChecks(const Tokenizer*, const Settings*, ErrorLogger*) { } /** @brief %Check for 'sizeof sizeof ..' */ @@ -102,8 +98,7 @@ private: void sizeofDereferencedVoidPointerError(const Token *tok, const std::string &varname); void arithOperationsOnVoidPointerError(const Token* tok, const std::string &varname, const std::string &vartype); - void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const - { + void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const { CheckSizeof c(0, settings, errorLogger); c.sizeofForArrayParameterError(0); @@ -119,13 +114,11 @@ private: c.arithOperationsOnVoidPointerError(0, "varname", "vartype"); } - static std::string myName() - { + static std::string myName() { return "Sizeof"; } - std::string classInfo() const - { + std::string classInfo() const { return "sizeof() usage checks\n" "- sizeof for array given as function argument\n" "- sizeof for numeric given as function argument\n" diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 94d0fb541..77b09272e 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -363,8 +363,7 @@ void CheckStl::stlOutOfBoundsError(const Token *tok, const std::string &num, con */ class EraseCheckLoop : public ExecutionPath { public: - static void checkScope(CheckStl *checkStl, const Token *it) - { + static void checkScope(CheckStl *checkStl, const Token *it) { const Token *tok = it; // Search for the start of the loop body.. @@ -398,8 +397,7 @@ public: private: /** Startup constructor */ EraseCheckLoop(Check *o, unsigned int varid, const Token* usetoken) - : ExecutionPath(o, varid), eraseToken(0), useToken(usetoken) - { + : ExecutionPath(o, varid), eraseToken(0), useToken(usetoken) { } /** @brief token where iterator is erased (non-zero => the iterator is invalid) */ @@ -409,21 +407,18 @@ private: const Token* useToken; /** @brief Copy this check. Called from the ExecutionPath baseclass. */ - ExecutionPath *copy() - { + ExecutionPath *copy() { return new EraseCheckLoop(*this); } /** @brief is another execution path equal? */ - bool is_equal(const ExecutionPath *e) const - { + bool is_equal(const ExecutionPath *e) const { const EraseCheckLoop *c = static_cast(e); return (eraseToken == c->eraseToken); } /** @brief parse tokens */ - const Token *parse(const Token &tok, std::list &checks) const - { + const Token *parse(const Token &tok, std::list &checks) const { // bail out if there are assignments. We don't check the assignments properly. if (Token::Match(&tok, "[;{}] %var% =") || Token::Match(&tok, "= %var% ;")) { ExecutionPath::bailOutVar(checks, tok.next()->varId()); @@ -476,8 +471,7 @@ private: * @param checks The execution paths. All execution paths in the list are executed in the current scope * @return true => bail out all checking **/ - bool parseCondition(const Token &tok, std::list &checks) - { + bool parseCondition(const Token &tok, std::list &checks) { // no checking of conditions. (void)tok; (void)checks; @@ -485,8 +479,7 @@ private: } /** @brief going out of scope - all execution paths end */ - void end(const std::list &checks, const Token * /*tok*/) const - { + void end(const std::list &checks, const Token * /*tok*/) const { // check if there are any invalid iterators. If so there is an error. for (std::list::const_iterator it = checks.begin(); it != checks.end(); ++it) { EraseCheckLoop *c = dynamic_cast(*it); diff --git a/lib/checkstl.h b/lib/checkstl.h index c5d396f74..df2f5614a 100644 --- a/lib/checkstl.h +++ b/lib/checkstl.h @@ -34,19 +34,16 @@ class CPPCHECKLIB CheckStl : public Check { public: /** This constructor is used when registering the CheckClass */ - CheckStl() : Check(myName()) - { + CheckStl() : Check(myName()) { } /** This constructor is used when running checks. */ CheckStl(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** Simplified checks. The token list is simplified. */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { if (!tokenizer->isCPP()) return; @@ -192,8 +189,7 @@ private: void readingEmptyStlContainerError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckStl c(0, settings, errorLogger); c.invalidIteratorError(0, "iterator"); c.iteratorsError(0, "container1", "container2"); @@ -223,13 +219,11 @@ private: c.readingEmptyStlContainerError(0); } - static std::string myName() - { + static std::string myName() { return "STL usage"; } - std::string classInfo() const - { + std::string classInfo() const { return "Check for invalid usage of STL:\n" "- out of bounds errors\n" "- misuse of iterators when iterating through a container\n" diff --git a/lib/checkstring.h b/lib/checkstring.h index cd090abad..b809b73f7 100644 --- a/lib/checkstring.h +++ b/lib/checkstring.h @@ -34,19 +34,16 @@ class CPPCHECKLIB CheckString : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckString() : Check(myName()) - { + CheckString() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckString(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckString checkString(tokenizer, settings, errorLogger); // Checks @@ -55,8 +52,7 @@ public: } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckString checkString(tokenizer, settings, errorLogger); // Checks @@ -90,8 +86,7 @@ private: void suspiciousStringCompareError(const Token* tok, const std::string& var); void suspiciousStringCompareError_char(const Token* tok, const std::string& var); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckString c(0, settings, errorLogger); c.sprintfOverlappingDataError(0, "varname"); @@ -104,13 +99,11 @@ private: c.alwaysTrueStringVariableCompareError(0, "varname1", "varname2"); } - static std::string myName() - { + static std::string myName() { return "String"; } - std::string classInfo() const - { + std::string classInfo() const { return "Detect misusage of C-style strings:\n" "- overlapping buffers passed to sprintf as source and destination\n" "- incorrect length arguments for 'substr' and 'strncmp'\n" diff --git a/lib/checktype.h b/lib/checktype.h index ef5b788f4..392abed9e 100644 --- a/lib/checktype.h +++ b/lib/checktype.h @@ -34,19 +34,16 @@ class CPPCHECKLIB CheckType : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckType() : Check(myName()) - { + CheckType() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckType(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { // These are not "simplified" because casts can't be ignored CheckType checkType(tokenizer, settings, errorLogger); checkType.checkTooBigBitwiseShift(); @@ -55,8 +52,7 @@ public: } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { (void)tokenizer; (void)settings; (void)errorLogger; @@ -80,21 +76,18 @@ private: void integerOverflowError(const Token *tok, const ValueFlow::Value &value); void signConversionError(const Token *tok); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckType c(0, settings, errorLogger); c.tooBigBitwiseShiftError(0, 32, ValueFlow::Value(64)); c.integerOverflowError(0, ValueFlow::Value(1LL<<32)); c.signConversionError(0); } - static std::string myName() - { + static std::string myName() { return "Type"; } - std::string classInfo() const - { + std::string classInfo() const { return "Type checks\n" "- bitwise shift by too many bits (only enabled when --platform is used)\n" "- signed integer overflow (only enabled when --platform is used)\n" diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 92cac7038..7b8e29ceb 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -56,26 +56,22 @@ class UninitVar : public ExecutionPath { public: /** Startup constructor */ explicit UninitVar(Check *c, const SymbolDatabase* db, const Library *lib, bool isc) - : ExecutionPath(c, 0), symbolDatabase(db), library(lib), isC(isc), var(0), alloc(false), strncpy_(false), memset_nonzero(false) - { + : ExecutionPath(c, 0), symbolDatabase(db), library(lib), isC(isc), var(0), alloc(false), strncpy_(false), memset_nonzero(false) { } private: /** Create a copy of this check */ - ExecutionPath *copy() - { + ExecutionPath *copy() { return new UninitVar(*this); } /** internal constructor for creating extra checks */ UninitVar(Check *c, const Variable* v, const SymbolDatabase* db, const Library *lib, bool isc) - : ExecutionPath(c, v->declarationId()), symbolDatabase(db), library(lib), isC(isc), var(v), alloc(false), strncpy_(false), memset_nonzero(false) - { + : ExecutionPath(c, v->declarationId()), symbolDatabase(db), library(lib), isC(isc), var(v), alloc(false), strncpy_(false), memset_nonzero(false) { } /** is other execution path equal? */ - bool is_equal(const ExecutionPath *e) const - { + bool is_equal(const ExecutionPath *e) const { const UninitVar *c = static_cast(e); return (var == c->var && alloc == c->alloc && strncpy_ == c->strncpy_ && memset_nonzero == c->memset_nonzero); } @@ -101,8 +97,7 @@ private: bool memset_nonzero; /** allocating pointer. For example : p = malloc(10); */ - static void alloc_pointer(std::list &checks, unsigned int varid) - { + static void alloc_pointer(std::list &checks, unsigned int varid) { // loop through the checks and perform a allocation if the // variable id matches std::list::const_iterator it; @@ -119,8 +114,7 @@ private: } /** Initializing a pointer value. For example: *p = 0; */ - static void init_pointer(std::list &checks, const Token *tok) - { + static void init_pointer(std::list &checks, const Token *tok) { const unsigned int varid(tok->varId()); if (!varid) return; @@ -145,8 +139,7 @@ private: } /** Deallocate a pointer. For example: free(p); */ - static void dealloc_pointer(std::list &checks, const Token *tok) - { + static void dealloc_pointer(std::list &checks, const Token *tok) { const unsigned int varid(tok->varId()); if (!varid) return; @@ -177,8 +170,7 @@ private: * \param tok1 the "p" token * \param tok2 the "x" token */ - static void pointer_assignment(std::list &checks, const Token *tok1, const Token *tok2) - { + static void pointer_assignment(std::list &checks, const Token *tok1, const Token *tok2) { // Variable id for "left hand side" variable const unsigned int varid1(tok1->varId()); if (varid1 == 0) @@ -212,8 +204,7 @@ private: /** Initialize an array with strncpy. */ - static void init_strncpy(std::list &checks, const Token *tok) - { + static void init_strncpy(std::list &checks, const Token *tok) { const unsigned int varid(tok->varId()); if (!varid) return; @@ -228,8 +219,7 @@ private: } /** Initialize an array with memset (not zero). */ - static void init_memset_nonzero(std::list &checks, const Token *tok) - { + static void init_memset_nonzero(std::list &checks, const Token *tok) { const unsigned int varid(tok->varId()); if (!varid) return; @@ -252,8 +242,7 @@ private: * @param mode specific behaviour * @return if error is found, true is returned */ - static bool use(std::list &checks, const Token *tok, const int mode) - { + static bool use(std::list &checks, const Token *tok, const int mode) { const unsigned int varid(tok->varId()); if (varid == 0) return false; @@ -317,8 +306,7 @@ private: * @param tok variable token * @return if error is found, true is returned */ - static bool use(std::list &checks, const Token *tok) - { + static bool use(std::list &checks, const Token *tok) { return use(checks, tok, 0); } @@ -327,8 +315,7 @@ private: * @param checks all available checks * @param tok variable token */ - static void use_array(std::list &checks, const Token *tok) - { + static void use_array(std::list &checks, const Token *tok) { use(checks, tok, 1); } @@ -337,8 +324,7 @@ private: * @param checks all available checks * @param tok variable token */ - static void use_array_mem(std::list &checks, const Token *tok) - { + static void use_array_mem(std::list &checks, const Token *tok) { use(checks, tok, 2); } @@ -348,8 +334,7 @@ private: * @param tok variable token * @return if error is found, true is returned */ - static bool use_pointer(std::list &checks, const Token *tok) - { + static bool use_pointer(std::list &checks, const Token *tok) { return use(checks, tok, 3); } @@ -359,8 +344,7 @@ private: * @param tok variable token * @return if error is found, true is returned */ - static bool use_dead_pointer(std::list &checks, const Token *tok) - { + static bool use_dead_pointer(std::list &checks, const Token *tok) { return use(checks, tok, 4); } @@ -371,8 +355,7 @@ private: * @param tok variable token * @return if error is found, true is returned */ - static bool use_array_or_pointer_data(std::list &checks, const Token *tok) - { + static bool use_array_or_pointer_data(std::list &checks, const Token *tok) { return use(checks, tok, 5); } @@ -381,8 +364,7 @@ private: * @param tok2 start token of rhs * @param checks the execution paths */ - static void parserhs(const Token *tok2, std::list &checks) - { + static void parserhs(const Token *tok2, std::list &checks) { // check variable usages in rhs/index while (nullptr != (tok2 = tok2->next())) { if (Token::Match(tok2, "[;)=]")) @@ -425,8 +407,7 @@ private: } /** parse tokens. @sa ExecutionPath::parse */ - const Token *parse(const Token &tok, std::list &checks) const - { + const Token *parse(const Token &tok, std::list &checks) const { // Variable declaration.. if (tok.varId() && Token::Match(&tok, "%var% [[;]")) { const Variable* var2 = tok.variable(); @@ -892,8 +873,7 @@ private: return &tok; } - bool parseCondition(const Token &tok, std::list &checks) - { + bool parseCondition(const Token &tok, std::list &checks) { if (tok.varId() && Token::Match(&tok, "%var% <|<=|==|!=|)")) use(checks, &tok); @@ -921,8 +901,7 @@ private: return ExecutionPath::parseCondition(tok, checks); } - void parseLoopBody(const Token *tok, std::list &checks) const - { + void parseLoopBody(const Token *tok, std::list &checks) const { while (tok) { if (tok->str() == "{" || tok->str() == "}" || tok->str() == "for") return; @@ -941,8 +920,7 @@ private: public: - static void analyseFunctions(const Token * const tokens, std::set &func) - { + static void analyseFunctions(const Token * const tokens, std::set &func) { for (const Token *tok = tokens; tok; tok = tok->next()) { if (tok->str() == "{") { tok = tok->link(); diff --git a/lib/checkuninitvar.h b/lib/checkuninitvar.h index 22189b2c9..56434b80c 100644 --- a/lib/checkuninitvar.h +++ b/lib/checkuninitvar.h @@ -37,19 +37,16 @@ class Variable; class CPPCHECKLIB CheckUninitVar : public Check { public: /** @brief This constructor is used when registering the CheckUninitVar */ - CheckUninitVar() : Check(myName()), testrunner(false) - { + CheckUninitVar() : Check(myName()), testrunner(false) { } /** @brief This constructor is used when running checks. */ CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger), testrunner(false) - { + : Check(myName(), tokenizer, settings, errorLogger), testrunner(false) { } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckUninitVar checkUninitVar(tokenizer, settings, errorLogger); checkUninitVar.executionPaths(); checkUninitVar.check(); @@ -102,8 +99,7 @@ public: bool testrunner; private: - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckUninitVar c(0, settings, errorLogger); // error @@ -114,13 +110,11 @@ private: c.deadPointerError(0,0); } - static std::string myName() - { + static std::string myName() { return "Uninitialized variables"; } - std::string classInfo() const - { + std::string classInfo() const { return "Uninitialized variables\n" "- using uninitialized local variables\n" "- using allocated data before it has been initialized\n" diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 8133273f1..c4e09597f 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -32,14 +32,12 @@ class CPPCHECKLIB CheckUnusedFunctions : public Check { public: /** @brief This constructor is used when registering the CheckUnusedFunctions */ - CheckUnusedFunctions() : Check(myName()) - { + CheckUnusedFunctions() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckUnusedFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } // Parse current tokens and determine.. @@ -54,8 +52,7 @@ public: private: - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckUnusedFunctions c(0, settings, errorLogger); c.unusedFunctionError(errorLogger, "", 0, "funcName"); } @@ -72,20 +69,17 @@ private: */ void runSimplifiedChecks(const Tokenizer *, const Settings *, ErrorLogger *) {} - static std::string myName() - { + static std::string myName() { return "Unused functions"; } - std::string classInfo() const - { + std::string classInfo() const { return "Check for functions that are never called\n"; } class FunctionUsage { public: - FunctionUsage() : lineNumber(0), usedSameFile(false), usedOtherFile(false) - { + FunctionUsage() : lineNumber(0), usedSameFile(false), usedOtherFile(false) { } std::string filename; diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 7df457a34..23a71d071 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -52,21 +52,18 @@ public: _read(read), _write(write), _modified(modified), - _allocateMemory(allocateMemory) - { + _allocateMemory(allocateMemory) { } /** variable is used.. set both read+write */ - void use(std::list > & varReadInScope) - { + void use(std::list > & varReadInScope) { varReadInScope.back().insert(_var->declarationId()); _read = true; _write = true; } /** is variable unused? */ - bool unused() const - { + bool unused() const { return (_read == false && _write == false); } @@ -87,13 +84,11 @@ public: ScopeGuard(Variables & guarded, bool insideLoop) :_guarded(guarded), - _insideLoop(insideLoop) - { + _insideLoop(insideLoop) { _guarded.enterScope(); } - ~ScopeGuard() - { + ~ScopeGuard() { _guarded.leaveScope(_insideLoop); } @@ -102,12 +97,10 @@ public: bool _insideLoop; }; - void clear() - { + void clear() { _varUsage.clear(); } - const std::map &varUsage() const - { + const std::map &varUsage() const { return _varUsage; } void addVar(const Variable *var, VariableType type, bool write_); @@ -122,16 +115,14 @@ public: void modified(unsigned int varid, const Token* tok); VariableUsage *find(unsigned int varid); void alias(unsigned int varid1, unsigned int varid2, bool replace); - void erase(unsigned int varid) - { + void erase(unsigned int varid) { _varUsage.erase(varid); } void eraseAliases(unsigned int varid); void eraseAll(unsigned int varid); void clearAliases(unsigned int varid); - ScopeGuard newScope(bool insideLoop) - { + ScopeGuard newScope(bool insideLoop) { return ScopeGuard(*this, insideLoop); } diff --git a/lib/checkunusedvar.h b/lib/checkunusedvar.h index 9a66dc8f2..18f766849 100644 --- a/lib/checkunusedvar.h +++ b/lib/checkunusedvar.h @@ -39,19 +39,16 @@ class Variables; class CPPCHECKLIB CheckUnusedVar : public Check { public: /** @brief This constructor is used when registering the CheckClass */ - CheckUnusedVar() : Check(myName()) - { + CheckUnusedVar() : Check(myName()) { } /** @brief This constructor is used when running checks. */ CheckUnusedVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } /** @brief Run checks against the normal token list */ - void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckUnusedVar checkUnusedVar(tokenizer, settings, errorLogger); // Coding style checks @@ -60,8 +57,7 @@ public: } /** @brief Run checks against the simplified token list */ - void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { (void)tokenizer; (void)settings; (void)errorLogger; @@ -86,8 +82,7 @@ private: void unreadVariableError(const Token *tok, const std::string &varname); void unassignedVariableError(const Token *tok, const std::string &varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckUnusedVar c(0, settings, errorLogger); // style/warning @@ -98,13 +93,11 @@ private: c.unusedStructMemberError(0, "structname", "variable"); } - static std::string myName() - { + static std::string myName() { return "UnusedVar"; } - std::string classInfo() const - { + std::string classInfo() const { return "UnusedVar checks\n" // style diff --git a/lib/checkvaarg.h b/lib/checkvaarg.h index 00e458a15..660862063 100644 --- a/lib/checkvaarg.h +++ b/lib/checkvaarg.h @@ -34,17 +34,14 @@ class CPPCHECKLIB CheckVaarg : public Check { public: - CheckVaarg() : Check(myName()) - { + CheckVaarg() : Check(myName()) { } CheckVaarg(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - : Check(myName(), tokenizer, settings, errorLogger) - { + : Check(myName(), tokenizer, settings, errorLogger) { } - virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) - { + virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) { CheckVaarg check(tokenizer, settings, errorLogger); check.va_start_argument(); check.va_list_usage(); @@ -60,8 +57,7 @@ private: void va_list_usedBeforeStartedError(const Token *tok, const std::string& varname); void va_start_subsequentCallsError(const Token *tok, const std::string& varname); - void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const - { + void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckVaarg c(0, settings, errorLogger); c.wrongParameterTo_va_start_error(0, "arg1", "arg2"); c.referenceAs_va_start_error(0, "arg1"); @@ -70,13 +66,11 @@ private: c.va_start_subsequentCallsError(0, "vl"); } - static std::string myName() - { + static std::string myName() { return "Vaarg"; } - std::string classInfo() const - { + std::string classInfo() const { return "Check for misusage of variable argument lists:\n" "- Wrong parameter passed to va_start()\n" "- Reference passed to va_start()\n" diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 25fff8840..bfecb2c12 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -107,8 +107,7 @@ public: /** * @brief Terminate checking. The checking will be terminated as soon as possible. */ - void terminate() - { + void terminate() { _settings.terminate(); } @@ -126,8 +125,7 @@ public: void tooManyConfigsError(const std::string &file, const std::size_t numberOfConfigurations); void purgedConfigurationMessage(const std::string &file, const std::string& configuration); - void dontSimplify() - { + void dontSimplify() { _simplify = false; } diff --git a/lib/cxx11emu.h b/lib/cxx11emu.h index 743ea9aa1..945b24f7a 100644 --- a/lib/cxx11emu.h +++ b/lib/cxx11emu.h @@ -34,13 +34,11 @@ const // this is a const object... class { public: template // convertible to any type - operator T*() const // of null non-member - { + operator T*() const { // of null non-member return 0; // pointer... } template // or any type of null - operator T C::*() const // member pointer... - { + operator T C::*() const { // member pointer... return 0; } private: diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 90cccce1f..f7f3d7dd9 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -100,8 +100,7 @@ public: debug }; - static std::string toString(SeverityType severity) - { + static std::string toString(SeverityType severity) { switch (severity) { case none: return ""; @@ -122,8 +121,7 @@ public: }; throw InternalError(NULL, "Unknown severity"); } - static SeverityType fromString(const std::string &severity) - { + static SeverityType fromString(const std::string &severity) { if (severity.empty()) return none; if (severity == "none") @@ -166,13 +164,11 @@ public: class CPPCHECKLIB FileLocation { public: FileLocation() - : line(0) - { + : line(0) { } FileLocation(const std::string &file, unsigned int aline) - : line(aline), _file(file) - { + : line(aline), _file(file) { } FileLocation(const Token* tok, const TokenList* list); @@ -240,14 +236,12 @@ public: void setmsg(const std::string &msg); /** Short message (single line short message) */ - const std::string &shortMessage() const - { + const std::string &shortMessage() const { return _shortMessage; } /** Verbose message (may be the same as the short message) */ - const std::string &verboseMessage() const - { + const std::string &verboseMessage() const { return _verboseMessage; } @@ -293,8 +287,7 @@ public: * @param stage for example preprocess / tokenize / simplify / check * @param value progress value (0-100) */ - virtual void reportProgress(const std::string &filename, const char stage[], const std::size_t value) - { + virtual void reportProgress(const std::string &filename, const char stage[], const std::size_t value) { (void)filename; (void)stage; (void)value; @@ -304,8 +297,7 @@ public: * Output information messages. * @param msg Location and other information about the found error. */ - virtual void reportInfo(const ErrorLogger::ErrorMessage &msg) - { + virtual void reportInfo(const ErrorLogger::ErrorMessage &msg) { reportErr(msg); } diff --git a/lib/executionpath.h b/lib/executionpath.h index a2598f43e..e973431f7 100644 --- a/lib/executionpath.h +++ b/lib/executionpath.h @@ -44,12 +44,10 @@ protected: virtual bool is_equal(const ExecutionPath *) const = 0; public: - ExecutionPath(Check *c, unsigned int id) : owner(c), numberOfIf(0), varId(id) - { + ExecutionPath(Check *c, unsigned int id) : owner(c), numberOfIf(0), varId(id) { } - virtual ~ExecutionPath() - { + virtual ~ExecutionPath() { } /** Implement this in each derived class. This function must create a copy of the current instance */ @@ -67,8 +65,7 @@ public: * bail out all execution paths * @param checks the execution paths to bail out on **/ - static void bailOut(std::list &checks) - { + static void bailOut(std::list &checks) { while (!checks.empty()) { delete checks.back(); checks.pop_back(); @@ -80,8 +77,7 @@ public: * @param checks the execution paths to bail out on * @param varid the specific variable id **/ - static void bailOutVar(std::list &checks, const unsigned int varid) - { + static void bailOutVar(std::list &checks, const unsigned int varid) { if (varid == 0) return; @@ -117,19 +113,16 @@ public: * @param tok the first token in the loop body (the token after the {) * @param checks The execution paths */ - virtual void parseLoopBody(const Token *tok, std::list &checks) const - { + virtual void parseLoopBody(const Token *tok, std::list &checks) const { (void)tok; (void)checks; } /** going out of scope - all execution paths end */ - virtual void end(const std::list & /*checks*/, const Token * /*tok*/) const - { + virtual void end(const std::list & /*checks*/, const Token * /*tok*/) const { } - bool operator==(const ExecutionPath &e) const - { + bool operator==(const ExecutionPath &e) const { return bool(varId == e.varId && is_equal(&e)); } diff --git a/lib/library.h b/lib/library.h index e8bb58d89..16c2bfcd7 100644 --- a/lib/library.h +++ b/lib/library.h @@ -64,70 +64,58 @@ public: bool loadxmldata(const char xmldata[], std::size_t len); /** get allocation id for function by name */ - int alloc(const char name[]) const - { + int alloc(const char name[]) const { return getid(_alloc, name); } /** get allocation id for function */ - int alloc(const Token *tok) const - { + int alloc(const Token *tok) const { return tok->function() ? 0 : getid(_alloc, tok->str()); } /** get deallocation id for function */ - int dealloc(const Token *tok) const - { + int dealloc(const Token *tok) const { return tok->function() ? 0 : getid(_dealloc, tok->str()); } /** get deallocation id for function by name */ - int dealloc(const char name[]) const - { + int dealloc(const char name[]) const { return getid(_dealloc, name); } /** set allocation id for function */ - void setalloc(const std::string &functionname, int id) - { + void setalloc(const std::string &functionname, int id) { _alloc[functionname] = id; } - void setdealloc(const std::string &functionname, int id) - { + void setdealloc(const std::string &functionname, int id) { _dealloc[functionname] = id; } /** add noreturn function setting */ - void setnoreturn(const std::string& funcname, bool noreturn) - { + void setnoreturn(const std::string& funcname, bool noreturn) { _noreturn[funcname] = noreturn; } /** is allocation type memory? */ - static bool ismemory(int id) - { + static bool ismemory(int id) { return ((id > 0) && ((id & 1) == 0)); } /** is allocation type resource? */ - static bool isresource(int id) - { + static bool isresource(int id) { return ((id > 0) && ((id & 1) == 1)); } - bool formatstr_function(const std::string& funcname) const - { + bool formatstr_function(const std::string& funcname) const { return _formatstr.find(funcname) != _formatstr.end(); } - bool formatstr_scan(const std::string& funcname) const - { + bool formatstr_scan(const std::string& funcname) const { return _formatstr.at(funcname).first; } - bool formatstr_secure(const std::string& funcname) const - { + bool formatstr_secure(const std::string& funcname) const { return _formatstr.at(funcname).second; } @@ -137,14 +125,12 @@ public: std::set functionpure; std::set useretval; - bool isnoreturn(const std::string &name) const - { + bool isnoreturn(const std::string &name) const { std::map::const_iterator it = _noreturn.find(name); return (it != _noreturn.end() && it->second); } - bool isnotnoreturn(const std::string &name) const - { + bool isnotnoreturn(const std::string &name) const { std::map::const_iterator it = _noreturn.find(name); return (it != _noreturn.end() && !it->second); } @@ -158,8 +144,7 @@ public: notnull(false), notuninit(false), formatstr(false), - strz(false) - { + strz(false) { } bool notbool; @@ -183,46 +168,39 @@ public: // function name, argument nr => argument data std::map > argumentChecks; - bool isboolargbad(const std::string &functionName, int argnr) const - { + bool isboolargbad(const std::string &functionName, int argnr) const { const ArgumentChecks *arg = getarg(functionName, argnr); return arg && arg->notbool; } - bool isnullargbad(const std::string &functionName, int argnr) const - { + bool isnullargbad(const std::string &functionName, int argnr) const { const ArgumentChecks *arg = getarg(functionName, argnr); return arg && arg->notnull; } - bool isuninitargbad(const std::string &functionName, int argnr) const - { + bool isuninitargbad(const std::string &functionName, int argnr) const { const ArgumentChecks *arg = getarg(functionName, argnr); return arg && arg->notuninit; } - bool isargformatstr(const std::string &functionName, int argnr) const - { + bool isargformatstr(const std::string &functionName, int argnr) const { const ArgumentChecks *arg = getarg(functionName, argnr); return arg && arg->formatstr; } - bool isargstrz(const std::string &functionName, int argnr) const - { + bool isargstrz(const std::string &functionName, int argnr) const { const ArgumentChecks *arg = getarg(functionName, argnr); return arg && arg->strz; } bool isargvalid(const std::string &functionName, int argnr, const MathLib::bigint argvalue) const; - const std::string& validarg(const std::string &functionName, int argnr) const - { + const std::string& validarg(const std::string &functionName, int argnr) const { const ArgumentChecks *arg = getarg(functionName, argnr); return arg ? arg->valid : emptyString; } - bool hasminsize(const std::string &functionName) const - { + bool hasminsize(const std::string &functionName) const { std::map >::const_iterator it1; it1 = argumentChecks.find(functionName); if (it1 == argumentChecks.end()) @@ -235,47 +213,39 @@ public: return false; } - const std::list *argminsizes(const std::string &functionName, int argnr) const - { + const std::list *argminsizes(const std::string &functionName, int argnr) const { const ArgumentChecks *arg = getarg(functionName, argnr); return arg ? &arg->minsizes : nullptr; } - bool markupFile(const std::string &path) const - { + bool markupFile(const std::string &path) const { return _markupExtensions.find(Path::getFilenameExtensionInLowerCase(path)) != _markupExtensions.end(); } - bool processMarkupAfterCode(const std::string &path) const - { + bool processMarkupAfterCode(const std::string &path) const { const std::map::const_iterator it = _processAfterCode.find(Path::getFilenameExtensionInLowerCase(path)); return (it == _processAfterCode.end() || it->second); } - const std::set &markupExtensions() const - { + const std::set &markupExtensions() const { return _markupExtensions; } - bool reportErrors(const std::string &path) const - { + bool reportErrors(const std::string &path) const { const std::map::const_iterator it = _reporterrors.find(Path::getFilenameExtensionInLowerCase(path)); return (it == _reporterrors.end() || it->second); } - bool ignorefunction(const std::string &function) const - { + bool ignorefunction(const std::string &function) const { return (_ignorefunction.find(function) != _ignorefunction.end()); } - bool isexecutableblock(const std::string &file, const std::string &token) const - { + bool isexecutableblock(const std::string &file, const std::string &token) const { const std::map::const_iterator it = _executableblocks.find(Path::getFilenameExtensionInLowerCase(file)); return (it != _executableblocks.end() && it->second.isBlock(token)); } - int blockstartoffset(const std::string &file) const - { + int blockstartoffset(const std::string &file) const { int offset = -1; const std::map::const_iterator map_it = _executableblocks.find(Path::getFilenameExtensionInLowerCase(file)); @@ -286,8 +256,7 @@ public: return offset; } - const std::string& blockstart(const std::string &file) const - { + const std::string& blockstart(const std::string &file) const { const std::map::const_iterator map_it = _executableblocks.find(Path::getFilenameExtensionInLowerCase(file)); @@ -297,8 +266,7 @@ public: return emptyString; } - const std::string& blockend(const std::string &file) const - { + const std::string& blockend(const std::string &file) const { const std::map::const_iterator map_it = _executableblocks.find(Path::getFilenameExtensionInLowerCase(file)); @@ -308,46 +276,39 @@ public: return emptyString; } - bool iskeyword(const std::string &file, const std::string &keyword) const - { + bool iskeyword(const std::string &file, const std::string &keyword) const { const std::map >::const_iterator it = _keywords.find(Path::getFilenameExtensionInLowerCase(file)); return (it != _keywords.end() && it->second.count(keyword)); } - bool isexporter(const std::string &prefix) const - { + bool isexporter(const std::string &prefix) const { return _exporters.find(prefix) != _exporters.end(); } - bool isexportedprefix(const std::string &prefix, const std::string &token) const - { + bool isexportedprefix(const std::string &prefix, const std::string &token) const { const std::map::const_iterator it = _exporters.find(prefix); return (it != _exporters.end() && it->second.isPrefix(token)); } - bool isexportedsuffix(const std::string &prefix, const std::string &token) const - { + bool isexportedsuffix(const std::string &prefix, const std::string &token) const { const std::map::const_iterator it = _exporters.find(prefix); return (it != _exporters.end() && it->second.isSuffix(token)); } - bool isimporter(const std::string& file, const std::string &importer) const - { + bool isimporter(const std::string& file, const std::string &importer) const { const std::map >::const_iterator it = _importers.find(Path::getFilenameExtensionInLowerCase(file)); return (it != _importers.end() && it->second.count(importer) > 0); } - bool isreflection(const std::string &token) const - { + bool isreflection(const std::string &token) const { const std::map::const_iterator it = _reflection.find(token); return it != _reflection.end(); } - int reflectionArgument(const std::string &token) const - { + int reflectionArgument(const std::string &token) const { int argIndex = -1; const std::map::const_iterator it = _reflection.find(token); @@ -376,11 +337,9 @@ public: , _long(false) , _pointer(false) , _ptr_ptr(false) - , _const_ptr(false) - { + , _const_ptr(false) { } - bool operator == (const PlatformType & type) const - { + bool operator == (const PlatformType & type) const { return (_type == type._type && _signed == type._signed && _unsigned == type._unsigned && @@ -389,8 +348,7 @@ public: _ptr_ptr == type._ptr_ptr && _const_ptr == type._const_ptr); } - bool operator != (const PlatformType & type) const - { + bool operator != (const PlatformType & type) const { return !(*this == type); } std::string _type; @@ -403,16 +361,14 @@ public: }; struct Platform { - const PlatformType *platform_type(const std::string &name) const - { + const PlatformType *platform_type(const std::string &name) const { const std::map::const_iterator it = _platform_types.find(name); return (it != _platform_types.end()) ? &(it->second) : nullptr; } std::map _platform_types; }; - const PlatformType *platform_type(const std::string &name, const std::string & platform) const - { + const PlatformType *platform_type(const std::string &name, const std::string & platform) const { const std::map::const_iterator it = platforms.find(platform); if (it != platforms.end()) { @@ -430,20 +386,16 @@ public: private: class ExportedFunctions { public: - void addPrefix(const std::string& prefix) - { + void addPrefix(const std::string& prefix) { _prefixes.insert(prefix); } - void addSuffix(const std::string& suffix) - { + void addSuffix(const std::string& suffix) { _suffixes.insert(suffix); } - bool isPrefix(const std::string& prefix) const - { + bool isPrefix(const std::string& prefix) const { return (_prefixes.find(prefix) != _prefixes.end()); } - bool isSuffix(const std::string& suffix) const - { + bool isSuffix(const std::string& suffix) const { return (_suffixes.find(suffix) != _suffixes.end()); } @@ -455,36 +407,28 @@ private: public: CodeBlock() : _offset(0) {} - void setStart(const std::string& s) - { + void setStart(const std::string& s) { _start = s; } - void setEnd(const std::string& e) - { + void setEnd(const std::string& e) { _end = e; } - void setOffset(const int o) - { + void setOffset(const int o) { _offset = o; } - void addBlock(const std::string& blockName) - { + void addBlock(const std::string& blockName) { _blocks.insert(blockName); } - const std::string& start() const - { + const std::string& start() const { return _start; } - const std::string& end() const - { + const std::string& end() const { return _end; } - int offset() const - { + int offset() const { return _offset; } - bool isBlock(const std::string& blockName) const - { + bool isBlock(const std::string& blockName) const { return _blocks.find(blockName) != _blocks.end(); } @@ -515,8 +459,7 @@ private: const ArgumentChecks * getarg(const std::string &functionName, int argnr) const; - static int getid(const std::map &data, const std::string &name) - { + static int getid(const std::map &data, const std::string &name) { const std::map::const_iterator it = data.find(name); return (it == data.end()) ? 0 : it->second; } diff --git a/lib/mathlib.h b/lib/mathlib.h index 149f2af8c..740c94eb4 100644 --- a/lib/mathlib.h +++ b/lib/mathlib.h @@ -39,8 +39,7 @@ public: static bigint toLongNumber(const std::string & str); static biguint toULongNumber(const std::string & str); - template static std::string toString(T value) - { + template static std::string toString(T value) { std::ostringstream result; result << value; return result.str(); diff --git a/lib/path.h b/lib/path.h index ef4898b92..4da24cdcd 100644 --- a/lib/path.h +++ b/lib/path.h @@ -117,8 +117,7 @@ public: * @param filename filename to check. path info is optional * @return true if the file extension indicates it should be checked */ - static bool acceptFile(const std::string &filename) - { + static bool acceptFile(const std::string &filename) { const std::set extra; return acceptFile(filename, extra); } diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 891c37e98..903470159 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -2542,8 +2542,7 @@ private: /** @brief expand inner macro */ std::vector expandInnerMacros(const std::vector ¶ms1, - const std::map ¯os) const - { + const std::map ¯os) const { std::string innerMacroName; // Is there an inner macro.. @@ -2601,8 +2600,7 @@ public: * e.g. "A(x) foo(x);" */ explicit PreprocessorMacro(const std::string ¯o) - : _macro(macro), _prefix("__cppcheck__") - { + : _macro(macro), _prefix("__cppcheck__") { tokenizer.setSettings(&settings); // Tokenize the macro to make it easier to handle @@ -2643,32 +2641,27 @@ public: } /** return tokens of this macro */ - const Token *tokens() const - { + const Token *tokens() const { return tokenizer.tokens(); } /** read parameters of this macro */ - const std::vector ¶ms() const - { + const std::vector ¶ms() const { return _params; } /** check if this is macro has a variable number of parameters */ - bool variadic() const - { + bool variadic() const { return _variadic; } /** Check if this macro has parentheses but no parameters */ - bool nopar() const - { + bool nopar() const { return _nopar; } /** name of macro */ - const std::string &name() const - { + const std::string &name() const { return _name; } @@ -2679,8 +2672,7 @@ public: * @param macrocode output string * @return true if the expanding was successful */ - bool code(const std::vector ¶ms2, const std::map ¯os, std::string ¯ocode) const - { + bool code(const std::vector ¶ms2, const std::map ¯os, std::string ¯ocode) const { if (_nopar || (_params.empty() && _variadic)) { macrocode = _macro.substr(1 + _macro.find(")")); if (macrocode.empty()) diff --git a/lib/preprocessor.h b/lib/preprocessor.h index a87e6c9da..472f7c229 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -247,8 +247,7 @@ public: */ std::string handleIncludes(const std::string &code, const std::string &filePath, const std::list &includePaths, std::map &defs, std::set &pragmaOnce, std::list includes); - void setFile0(const std::string &f) - { + void setFile0(const std::string &f) { file0 = f; } diff --git a/lib/settings.h b/lib/settings.h index 4f3ef5f08..91de260e4 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -90,14 +90,12 @@ public: bool _verbose; /** @brief Request termination of checking */ - void terminate() - { + void terminate() { _terminate = true; } /** @brief termination requested? */ - bool terminated() const - { + bool terminated() const { return _terminate; } @@ -155,8 +153,7 @@ public: * @return true if the check is enabled. */ template - bool isEnabled(T&& str) const - { + bool isEnabled(T&& str) const { return bool(_enabled.find(str) != _enabled.end()); } @@ -171,8 +168,7 @@ public: /** * @brief Disables all severities, except from error. */ - void clearEnabled() - { + void clearEnabled() { _enabled.clear(); } @@ -214,8 +210,7 @@ public: Rule() : tokenlist("simple") // use simple tokenlist , id("rule") // default id - , severity("style") // default severity - { + , severity("style") { // default severity } std::string tokenlist; @@ -274,8 +269,7 @@ public: * @brief Returns true if platform type is Windows * @return true if Windows platform type. */ - bool isWindowsPlatform() const - { + bool isWindowsPlatform() const { return platformType == Win32A || platformType == Win32W || platformType == Win64; @@ -285,8 +279,7 @@ public: * @brief return true if a file is to be excluded from configuration checking * @return true for the file to be excluded. */ - bool configurationExcluded(const std::string &file) const - { + bool configurationExcluded(const std::string &file) const { for (std::set::const_iterator i=configExcludePaths.begin(); i!=configExcludePaths.end(); ++i) { if (file.length()>=i->length() && file.compare(0,i->length(),*i)==0) { return true; diff --git a/lib/suppressions.h b/lib/suppressions.h index aa718e82e..b356b6a06 100644 --- a/lib/suppressions.h +++ b/lib/suppressions.h @@ -121,8 +121,7 @@ public: struct SuppressionEntry { SuppressionEntry(const std::string &aid, const std::string &afile, unsigned int aline) - : id(aid), file(afile), line(aline) - { + : id(aid), file(afile), line(aline) { } std::string id; diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index af5752243..c04e66946 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -68,8 +68,7 @@ public: class BaseInfo { public: BaseInfo() : - type(NULL), nameTok(NULL), access(Public), isVirtual(false) - { + type(NULL), nameTok(NULL), access(Public), isVirtual(false) { } std::string name; @@ -78,16 +77,14 @@ public: AccessControl access; // public/protected/private bool isVirtual; // allow ordering within containers - bool operator<(const BaseInfo& rhs) const - { + bool operator<(const BaseInfo& rhs) const { return this->type < rhs.type; } }; struct FriendInfo { FriendInfo() : - nameStart(NULL), nameEnd(NULL), type(NULL) - { + nameStart(NULL), nameEnd(NULL), type(NULL) { } const Token* nameStart; @@ -103,12 +100,10 @@ public: classDef(classDef_), classScope(classScope_), enclosingScope(enclosingScope_), - needInitialization(Unknown) - { + needInitialization(Unknown) { } - const std::string& name() const - { + const std::string& name() const { const Token* next = classDef->next(); if (next->isName()) return next->str(); @@ -152,8 +147,7 @@ class CPPCHECKLIB Variable { * @param flag_ flag to get state of * @return true if flag set or false in flag not set */ - bool getFlag(int flag_) const - { + bool getFlag(int flag_) const { return bool((_flags & flag_) != 0); } @@ -162,8 +156,7 @@ class CPPCHECKLIB Variable { * @param flag_ flag to set state * @param state_ new state of flag */ - void setFlag(int flag_, bool state_) - { + void setFlag(int flag_, bool state_) { _flags = state_ ? _flags | flag_ : _flags & ~flag_; } @@ -186,8 +179,7 @@ public: _access(access_), _flags(0), _type(type_), - _scope(scope_) - { + _scope(scope_) { evaluate(); } @@ -195,8 +187,7 @@ public: * Get name token. * @return name token */ - const Token *nameToken() const - { + const Token *nameToken() const { return _name; } @@ -208,8 +199,7 @@ public: * type start token ^ * @return type start token */ - const Token *typeStartToken() const - { + const Token *typeStartToken() const { return _start; } @@ -221,8 +211,7 @@ public: * type end token ^ * @return type end token */ - const Token *typeEndToken() const - { + const Token *typeEndToken() const { return _end; } @@ -239,8 +228,7 @@ public: * Get name string. * @return name string */ - const std::string &name() const - { + const std::string &name() const { // name may not exist for function arguments if (_name) return _name->str(); @@ -252,8 +240,7 @@ public: * Get declaration ID (varId used for variable in its declaration). * @return declaration ID */ - unsigned int declarationId() const - { + unsigned int declarationId() const { // name may not exist for function arguments if (_name) return _name->varId(); @@ -265,8 +252,7 @@ public: * Get index of variable in declared order. * @return variable index */ - std::size_t index() const - { + std::size_t index() const { return _index; } @@ -274,8 +260,7 @@ public: * Is variable public. * @return true if public, false if not */ - bool isPublic() const - { + bool isPublic() const { return _access == Public; } @@ -283,8 +268,7 @@ public: * Is variable protected. * @return true if protected, false if not */ - bool isProtected() const - { + bool isProtected() const { return _access == Protected; } @@ -292,8 +276,7 @@ public: * Is variable private. * @return true if private, false if not */ - bool isPrivate() const - { + bool isPrivate() const { return _access == Private; } @@ -301,8 +284,7 @@ public: * Is variable global. * @return true if global, false if not */ - bool isGlobal() const - { + bool isGlobal() const { return _access == Global; } @@ -310,8 +292,7 @@ public: * Is variable in a namespace. * @return true if in a namespace, false if not */ - bool isNamespace() const - { + bool isNamespace() const { return _access == Namespace; } @@ -319,8 +300,7 @@ public: * Is variable a function argument. * @return true if a function argument, false if not */ - bool isArgument() const - { + bool isArgument() const { return _access == Argument; } @@ -328,8 +308,7 @@ public: * Is variable local. * @return true if local, false if not */ - bool isLocal() const - { + bool isLocal() const { return (_access == Local) && !isExtern(); } @@ -337,8 +316,7 @@ public: * Is variable mutable. * @return true if mutable, false if not */ - bool isMutable() const - { + bool isMutable() const { return getFlag(fIsMutable); } @@ -346,8 +324,7 @@ public: * Is variable static. * @return true if static, false if not */ - bool isStatic() const - { + bool isStatic() const { return getFlag(fIsStatic); } @@ -355,8 +332,7 @@ public: * Is variable extern. * @return true if extern, false if not */ - bool isExtern() const - { + bool isExtern() const { return getFlag(fIsExtern); } @@ -364,8 +340,7 @@ public: * Is variable const. * @return true if const, false if not */ - bool isConst() const - { + bool isConst() const { return getFlag(fIsConst); } @@ -373,8 +348,7 @@ public: * Is variable a throw type. * @return true if throw type, false if not */ - bool isThrow() const - { + bool isThrow() const { return _access == Throw; } @@ -382,8 +356,7 @@ public: * Is variable a user defined (or unknown) type. * @return true if user defined type, false if not */ - bool isClass() const - { + bool isClass() const { return getFlag(fIsClass); } @@ -391,8 +364,7 @@ public: * Is variable an array. * @return true if array, false if not */ - bool isArray() const - { + bool isArray() const { return getFlag(fIsArray); } @@ -400,8 +372,7 @@ public: * Is pointer variable. * @return true if pointer, false otherwise */ - bool isPointer() const - { + bool isPointer() const { return getFlag(fIsPointer); } @@ -409,8 +380,7 @@ public: * Is array or pointer variable. * @return true if pointer or array, false otherwise */ - bool isArrayOrPointer() const - { + bool isArrayOrPointer() const { return getFlag(fIsArray) || getFlag(fIsPointer); } @@ -418,8 +388,7 @@ public: * Is reference variable. * @return true if reference, false otherwise */ - bool isReference() const - { + bool isReference() const { return getFlag(fIsReference); } @@ -427,8 +396,7 @@ public: * Is reference variable. * @return true if reference, false otherwise */ - bool isRValueReference() const - { + bool isRValueReference() const { return getFlag(fIsRValueRef); } @@ -436,8 +404,7 @@ public: * Does variable have a default value. * @return true if has a default falue, false if not */ - bool hasDefault() const - { + bool hasDefault() const { return getFlag(fHasDefault); } @@ -445,8 +412,7 @@ public: * Get Type pointer of known type. * @return pointer to type if known, NULL if not known */ - const Type *type() const - { + const Type *type() const { return _type; } @@ -454,8 +420,7 @@ public: * Get Scope pointer of known type. * @return pointer to type scope if known, NULL if not known */ - const Scope *typeScope() const - { + const Scope *typeScope() const { return _type ? _type->classScope : 0; } @@ -463,8 +428,7 @@ public: * Get Scope pointer of enclosing scope. * @return pointer to enclosing scope */ - const Scope *scope() const - { + const Scope *scope() const { return _scope; } @@ -472,8 +436,7 @@ public: * Get array dimensions. * @return array dimensions vector */ - const std::vector &dimensions() const - { + const std::vector &dimensions() const { return _dimensions; } @@ -481,8 +444,7 @@ public: * Get array dimension length. * @return length of dimension */ - MathLib::bigint dimension(std::size_t index_) const - { + MathLib::bigint dimension(std::size_t index_) const { return _dimensions[index_].num; } @@ -490,8 +452,7 @@ public: * Get array dimension known. * @return length of dimension known */ - bool dimensionKnown(std::size_t index_) const - { + bool dimensionKnown(std::size_t index_) const { return _dimensions[index_].known; } @@ -503,8 +464,7 @@ public: * sVar->isStlType() == true * @return true if it is an stl type and its type matches any of the types in 'stlTypes' */ - bool isStlType() const - { + bool isStlType() const { return getFlag(fIsStlType); } @@ -516,8 +476,7 @@ public: * sVar->isStlType() == true * @return true if it is an stl type and its type matches any of the types in 'stlTypes' */ - bool isStlStringType() const - { + bool isStlStringType() const { return getFlag(fIsStlString); } @@ -532,8 +491,7 @@ public: * @return true if it is an stl type and its type matches any of the types in 'stlTypes' */ template - bool isStlType(const char* const(&stlTypes)[array_length]) const - { + bool isStlType(const char* const(&stlTypes)[array_length]) const { return isStlType() && std::binary_search(stlTypes, stlTypes + array_length, _start->strAt(2)); } @@ -541,8 +499,7 @@ public: * Determine whether it's a floating number type * @return true if the type is known and it's a floating type (float, double and long double) or a pointer/array to it */ - bool isFloatingType() const - { + bool isFloatingType() const { return getFlag(fIsFloatType); } @@ -550,8 +507,7 @@ public: * Determine whether it's an integral number type * @return true if the type is known and it's an integral type (bool, char, short, int, long long and their unsigned counter parts) or a pointer/array to it */ - bool isIntegralType() const - { + bool isIntegralType() const { return getFlag(fIsIntType); } @@ -564,8 +520,7 @@ private: * Set Type pointer to known type. * @param t type */ - void type(const Type * t) - { + void type(const Type * t) { _type = t; } @@ -630,65 +585,52 @@ public: isThrow(false), isOperator(false), noexceptArg(nullptr), - throwArg(nullptr) - { + throwArg(nullptr) { } - const std::string &name() const - { + const std::string &name() const { return tokenDef->str(); } - std::size_t argCount() const - { + std::size_t argCount() const { return argumentList.size(); } - std::size_t minArgCount() const - { + std::size_t minArgCount() const { return argumentList.size() - initArgCount; } const Variable* getArgumentVar(std::size_t num) const; - unsigned int initializedArgCount() const - { + unsigned int initializedArgCount() const { return initArgCount; } void addArguments(const SymbolDatabase *symbolDatabase, const Scope *scope); /** @brief check if this function is virtual in the base classes */ bool isImplicitlyVirtual(bool defaultVal = false) const; - bool isConstructor() const - { + bool isConstructor() const { return type==eConstructor || type==eCopyConstructor || type==eMoveConstructor; } - bool isDestructor() const - { + bool isDestructor() const { return type==eDestructor; } - bool isAttributeConstructor() const - { + bool isAttributeConstructor() const { return tokenDef->isAttributeConstructor(); } - bool isAttributeDestructor() const - { + bool isAttributeDestructor() const { return tokenDef->isAttributeDestructor(); } - bool isAttributePure() const - { + bool isAttributePure() const { return tokenDef->isAttributePure(); } - bool isAttributeConst() const - { + bool isAttributeConst() const { return tokenDef->isAttributeConst(); } - bool isAttributeNothrow() const - { + bool isAttributeNothrow() const { return tokenDef->isAttributeNothrow(); } - bool isDeclspecNothrow() const - { + bool isDeclspecNothrow() const { return tokenDef->isDeclspecNothrow(); } @@ -761,18 +703,15 @@ public: const Scope *functionOf; // scope this function belongs to Function *function; // function info for this function - bool isClassOrStruct() const - { + bool isClassOrStruct() const { return (type == eClass || type == eStruct); } - bool isExecutable() const - { + bool isExecutable() const { return type != eClass && type != eStruct && type != eUnion && type != eGlobal && type != eNamespace; } - bool isLocal() const - { + bool isLocal() const { return (type == eIf || type == eElse || type == eFor || type == eWhile || type == eDo || type == eSwitch || type == eUnconditional || @@ -793,14 +732,12 @@ public: Scope *findInNestedList(const std::string & name); const Scope *findRecordInNestedList(const std::string & name) const; - Scope *findRecordInNestedList(const std::string & name) - { + Scope *findRecordInNestedList(const std::string & name) { return const_cast(static_cast(this)->findRecordInNestedList(name)); } const Type* findType(const std::string& name) const; - Type* findType(const std::string& name) - { + Type* findType(const std::string& name) { return const_cast(static_cast(this)->findType(name)); } @@ -812,8 +749,7 @@ public: void addVariable(const Token *token_, const Token *start_, const Token *end_, AccessControl access_, const Type *type_, - const Scope *scope_) - { + const Scope *scope_) { varlist.push_back(Variable(token_, start_, end_, varlist.size(), access_, type_, scope_)); @@ -899,32 +835,27 @@ public: const Scope *findScopeByName(const std::string& name) const; const Type* findType(const Token *tok, const Scope *startScope) const; - Type* findType(const Token *tok, Scope *startScope) const - { + Type* findType(const Token *tok, Scope *startScope) const { return const_cast(this->findType(tok, static_cast(startScope))); } const Scope *findScope(const Token *tok, const Scope *startScope) const; - Scope *findScope(const Token *tok, Scope *startScope) const - { + Scope *findScope(const Token *tok, Scope *startScope) const { return const_cast(this->findScope(tok, static_cast(startScope))); } - bool isClassOrStruct(const std::string &type) const - { + bool isClassOrStruct(const std::string &type) const { for (std::list::const_iterator i = typeList.begin(); i != typeList.end(); ++i) if (i->name() == type) return true; return false; } - const Variable *getVariableFromVarId(std::size_t varId) const - { + const Variable *getVariableFromVarId(std::size_t varId) const { return _variableList[varId]; } - std::size_t getVariableListSize() const - { + std::size_t getVariableListSize() const { return _variableList.size(); } diff --git a/lib/timer.h b/lib/timer.h index 22d2fce92..b99d44571 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -45,12 +45,10 @@ struct TimerResultsData { TimerResultsData() : _clocks(0) - , _numberOfResults(0) - { + , _numberOfResults(0) { } - double seconds() const - { + double seconds() const { double ret = (double)((unsigned long)_clocks) / (double)CLOCKS_PER_SEC; return ret; } @@ -58,8 +56,7 @@ struct TimerResultsData { class CPPCHECKLIB TimerResults : public TimerResultsIntf { public: - TimerResults() - { + TimerResults() { } void ShowResults(SHOWTIME_MODES mode) const; diff --git a/lib/token.h b/lib/token.h index 53b6fe74b..010024267 100644 --- a/lib/token.h +++ b/lib/token.h @@ -70,8 +70,7 @@ public: ~Token(); template - void str(T&& s) - { + void str(T&& s) { _str = s; _varId = 0; @@ -84,8 +83,7 @@ public: */ void concatStr(std::string const& b); - const std::string &str() const - { + const std::string &str() const { return _str; } @@ -100,8 +98,7 @@ public: * would return next from that one. */ const Token *tokAt(int index) const; - Token *tokAt(int index) - { + Token *tokAt(int index) { return const_cast(static_cast(this)->tokAt(index)); } @@ -110,8 +107,7 @@ public: * For example index 1 would return the link to next token. */ const Token *linkAt(int index) const; - Token *linkAt(int index) - { + Token *linkAt(int index) { return const_cast(static_cast(this)->linkAt(index)); } @@ -220,193 +216,149 @@ public: **/ static std::string getCharAt(const Token *tok, std::size_t index); - Type type() const - { + Type type() const { return _type; } - void type(Type t) - { + void type(Type t) { _type = t; } - void isKeyword(bool kwd) - { + void isKeyword(bool kwd) { if (kwd) _type = eKeyword; else if (_type == eKeyword) _type = eName; } - bool isKeyword() const - { + bool isKeyword() const { return _type == eKeyword; } - bool isName() const - { + bool isName() const { return _type == eName || _type == eType || _type == eVariable || _type == eFunction || _type == eKeyword || _type == eBoolean; // TODO: "true"/"false" aren't really a name... } bool isUpperCaseName() const; - bool isLiteral() const - { + bool isLiteral() const { return _type == eNumber || _type == eString || _type == eChar || _type == eBoolean || _type == eLiteral; } - bool isNumber() const - { + bool isNumber() const { return _type == eNumber; } - bool isOp() const - { + bool isOp() const { return (isConstOp() || isAssignmentOp() || _type == eIncDecOp); } - bool isConstOp() const - { + bool isConstOp() const { return (isArithmeticalOp() || _type == eLogicalOp || _type == eComparisonOp || _type == eBitOp); } - bool isExtendedOp() const - { + bool isExtendedOp() const { return isConstOp() || _type == eExtendedOp; } - bool isArithmeticalOp() const - { + bool isArithmeticalOp() const { return _type == eArithmeticalOp; } - bool isComparisonOp() const - { + bool isComparisonOp() const { return _type == eComparisonOp; } - bool isAssignmentOp() const - { + bool isAssignmentOp() const { return _type == eAssignmentOp; } - bool isBoolean() const - { + bool isBoolean() const { return _type == eBoolean; } - unsigned int flags() const - { + unsigned int flags() const { return _flags; } - void flags(unsigned int flags_) - { + void flags(unsigned int flags_) { _flags = flags_; } - bool isUnsigned() const - { + bool isUnsigned() const { return getFlag(fIsUnsigned); } - void isUnsigned(bool sign) - { + void isUnsigned(bool sign) { setFlag(fIsUnsigned, sign); } - bool isSigned() const - { + bool isSigned() const { return getFlag(fIsSigned); } - void isSigned(bool sign) - { + void isSigned(bool sign) { setFlag(fIsSigned, sign); } - bool isPointerCompare() const - { + bool isPointerCompare() const { return getFlag(fIsPointerCompare); } - void isPointerCompare(bool b) - { + void isPointerCompare(bool b) { setFlag(fIsPointerCompare, b); } - bool isLong() const - { + bool isLong() const { return getFlag(fIsLong); } - void isLong(bool size) - { + void isLong(bool size) { setFlag(fIsLong, size); } - bool isStandardType() const - { + bool isStandardType() const { return getFlag(fIsStandardType); } - void isStandardType(bool b) - { + void isStandardType(bool b) { setFlag(fIsStandardType, b); } - bool isExpandedMacro() const - { + bool isExpandedMacro() const { return getFlag(fIsExpandedMacro); } - void isExpandedMacro(bool m) - { + void isExpandedMacro(bool m) { setFlag(fIsExpandedMacro, m); } - bool isAttributeConstructor() const - { + bool isAttributeConstructor() const { return getFlag(fIsAttributeConstructor); } - void isAttributeConstructor(bool ac) - { + void isAttributeConstructor(bool ac) { setFlag(fIsAttributeConstructor, ac); } - bool isAttributeDestructor() const - { + bool isAttributeDestructor() const { return getFlag(fIsAttributeDestructor); } - void isAttributeDestructor(bool value) - { + void isAttributeDestructor(bool value) { setFlag(fIsAttributeDestructor, value); } - bool isAttributeUnused() const - { + bool isAttributeUnused() const { return getFlag(fIsAttributeUnused); } - void isAttributeUnused(bool unused) - { + void isAttributeUnused(bool unused) { setFlag(fIsAttributeUnused, unused); } - bool isAttributeUsed() const - { + bool isAttributeUsed() const { return getFlag(fIsAttributeUsed); } - void isAttributeUsed(bool unused) - { + void isAttributeUsed(bool unused) { setFlag(fIsAttributeUsed, unused); } - bool isAttributePure() const - { + bool isAttributePure() const { return getFlag(fIsAttributePure); } - void isAttributePure(bool value) - { + void isAttributePure(bool value) { setFlag(fIsAttributePure, value); } - bool isAttributeConst() const - { + bool isAttributeConst() const { return getFlag(fIsAttributeConst); } - void isAttributeConst(bool value) - { + void isAttributeConst(bool value) { setFlag(fIsAttributeConst, value); } - bool isAttributeNothrow() const - { + bool isAttributeNothrow() const { return getFlag(fIsAttributeNothrow); } - void isAttributeNothrow(bool value) - { + void isAttributeNothrow(bool value) { setFlag(fIsAttributeNothrow, value); } - bool isDeclspecNothrow() const - { + bool isDeclspecNothrow() const { return getFlag(fIsDeclspecNothrow); } - void isDeclspecNothrow(bool value) - { + void isDeclspecNothrow(bool value) { setFlag(fIsDeclspecNothrow, value); } @@ -414,20 +366,16 @@ public: static const Token *findsimplematch(const Token *tok, const char pattern[], const Token *end); static const Token *findmatch(const Token *tok, const char pattern[], unsigned int varId = 0); static const Token *findmatch(const Token *tok, const char pattern[], const Token *end, unsigned int varId = 0); - static Token *findsimplematch(Token *tok, const char pattern[]) - { + static Token *findsimplematch(Token *tok, const char pattern[]) { return const_cast(findsimplematch(static_cast(tok), pattern)); } - static Token *findsimplematch(Token *tok, const char pattern[], const Token *end) - { + static Token *findsimplematch(Token *tok, const char pattern[], const Token *end) { return const_cast(findsimplematch(static_cast(tok), pattern, end)); } - static Token *findmatch(Token *tok, const char pattern[], unsigned int varId = 0) - { + static Token *findmatch(Token *tok, const char pattern[], unsigned int varId = 0) { return const_cast(findmatch(static_cast(tok), pattern, varId)); } - static Token *findmatch(Token *tok, const char pattern[], const Token *end, unsigned int varId = 0) - { + static Token *findmatch(Token *tok, const char pattern[], const Token *end, unsigned int varId = 0) { return const_cast(findmatch(static_cast(tok), pattern, end, varId)); } @@ -447,26 +395,21 @@ public: */ static int multiCompare(const Token *needle, const char *haystack, unsigned int varid); - unsigned int linenr() const - { + unsigned int linenr() const { return _linenr; } - void linenr(unsigned int lineNumber) - { + void linenr(unsigned int lineNumber) { _linenr = lineNumber; } - unsigned int fileIndex() const - { + unsigned int fileIndex() const { return _fileIndex; } - void fileIndex(unsigned int indexOfFile) - { + void fileIndex(unsigned int indexOfFile) { _fileIndex = indexOfFile; } - Token *next() const - { + Token *next() const { return _next; } @@ -491,18 +434,15 @@ public: void insertToken(const std::string &tokenStr, const std::string &originalNameStr, bool prepend=false); - Token *previous() const - { + Token *previous() const { return _previous; } - unsigned int varId() const - { + unsigned int varId() const { return _varId; } - void varId(unsigned int id) - { + void varId(unsigned int id) { _varId = id; if (id != 0) _type = eVariable; @@ -576,8 +516,7 @@ public: * @param linkToToken The token where this token should link * to. */ - void link(Token *linkToToken) - { + void link(Token *linkToToken) { _link = linkToToken; if (_str == "<" || _str == ">") update_property_info(); @@ -592,8 +531,7 @@ public: * * @return The token where this token links to. */ - Token *link() const - { + Token *link() const { return _link; } @@ -601,16 +539,14 @@ public: * Associate this token with given scope * @param s Scope to be associated */ - void scope(const Scope *s) - { + void scope(const Scope *s) { _scope = s; } /** * @return a pointer to the scope containing this token. */ - const Scope *scope() const - { + const Scope *scope() const { return _scope; } @@ -618,8 +554,7 @@ public: * Associate this token with given function * @param f Function to be associated */ - void function(const Function *f) - { + void function(const Function *f) { _function = f; if (f) _type = eFunction; @@ -630,8 +565,7 @@ public: /** * @return a pointer to the Function associated with this token. */ - const Function *function() const - { + const Function *function() const { return _type == eFunction ? _function : 0; } @@ -639,8 +573,7 @@ public: * Associate this token with given variable * @param v Variable to be associated */ - void variable(const Variable *v) - { + void variable(const Variable *v) { _variable = v; if (v || _varId) _type = eVariable; @@ -651,8 +584,7 @@ public: /** * @return a pointer to the variable associated with this token. */ - const Variable *variable() const - { + const Variable *variable() const { return _type == eVariable ? _variable : 0; } @@ -679,8 +611,7 @@ public: static void move(Token *srcStart, Token *srcEnd, Token *newLocation); /** Get progressValue */ - unsigned int progressValue() const - { + unsigned int progressValue() const { return _progressValue; } @@ -712,8 +643,7 @@ public: /** * @return the original name. */ - const std::string & originalName() const - { + const std::string & originalName() const { return _originalName ? *_originalName : emptyString; } @@ -721,8 +651,7 @@ public: * Sets the original name. */ template - void originalName(T&& name) - { + void originalName(T&& name) { if (!_originalName) _originalName = new std::string(name); else @@ -732,8 +661,7 @@ public: /** Values of token */ std::list values; - const ValueFlow::Value * getValue(const MathLib::bigint val) const - { + const ValueFlow::Value * getValue(const MathLib::bigint val) const { std::list::const_iterator it; for (it = values.begin(); it != values.end(); ++it) { if (it->intvalue == val && !it->tokvalue) @@ -742,8 +670,7 @@ public: return NULL; } - const ValueFlow::Value * getMaxValue(bool condition) const - { + const ValueFlow::Value * getMaxValue(bool condition) const { const ValueFlow::Value *ret = nullptr; std::list::const_iterator it; for (it = values.begin(); it != values.end(); ++it) { @@ -766,12 +693,10 @@ public: private: - void next(Token *nextToken) - { + void next(Token *nextToken) { _next = nextToken; } - void previous(Token *previousToken) - { + void previous(Token *previousToken) { _previous = previousToken; } @@ -845,8 +770,7 @@ private: * @param flag_ flag to get state of * @return true if flag set or false in flag not set */ - bool getFlag(unsigned int flag_) const - { + bool getFlag(unsigned int flag_) const { return bool((_flags & flag_) != 0); } @@ -855,8 +779,7 @@ private: * @param flag_ flag to set state * @param state_ new state of flag */ - void setFlag(unsigned int flag_, bool state_) - { + void setFlag(unsigned int flag_, bool state_) { _flags = state_ ? _flags | flag_ : _flags & ~flag_; } @@ -879,20 +802,16 @@ public: void astOperand1(Token *tok); void astOperand2(Token *tok); - const Token * astOperand1() const - { + const Token * astOperand1() const { return _astOperand1; } - const Token * astOperand2() const - { + const Token * astOperand2() const { return _astOperand2; } - const Token * astParent() const - { + const Token * astParent() const { return _astParent; } - const Token *astTop() const - { + const Token *astTop() const { const Token *ret = this; while (ret->_astParent) ret = ret->_astParent; @@ -908,13 +827,11 @@ public: */ bool isCalculation() const; - void clearAst() - { + void clearAst() { _astOperand1 = _astOperand2 = _astParent = NULL; } - std::string astString(const char *sep = "") const - { + std::string astString(const char *sep = "") const { std::string ret; if (_astOperand1) ret = _astOperand1->astString(sep); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index f4eb61a63..fee2f7d3a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7407,15 +7407,12 @@ public: name(nullptr), value(nullptr), start(nullptr), - end(nullptr) - { + end(nullptr) { } - EnumValue(const EnumValue &ev) - { + EnumValue(const EnumValue &ev) { *this = ev; } - EnumValue& operator=(const EnumValue& ev) - { + EnumValue& operator=(const EnumValue& ev) { name=ev.name; value=ev.value; start=ev.start; @@ -7426,12 +7423,10 @@ public: name(name_), value(value_), start(start_), - end(end_) - { + end(end_) { } - void simplify(const std::map &enumValues) - { + void simplify(const std::map &enumValues) { for (Token *tok = start; tok; tok = tok->next()) { std::map::const_iterator it = enumValues.find(tok->str()); if (it != enumValues.end()) { diff --git a/lib/tokenize.h b/lib/tokenize.h index d9b1d2c69..8300c3e36 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -44,20 +44,17 @@ public: Tokenizer(const Settings * settings, ErrorLogger *errorLogger); ~Tokenizer(); - void setTimerResults(TimerResults *tr) - { + void setTimerResults(TimerResults *tr) { m_timerResults = tr; } /** Is the code C. Used for bailouts */ - bool isC() const - { + bool isC() const { return list.isC(); } /** Is the code CPP. Used for bailouts */ - bool isCPP() const - { + bool isCPP() const { return list.isCPP(); } @@ -704,19 +701,16 @@ public: void unsupportedTypedef(const Token *tok) const; /** Was there templates in the code? */ - bool codeWithTemplates() const - { + bool codeWithTemplates() const { return _codeWithTemplates; } - void setSettings(const Settings *settings) - { + void setSettings(const Settings *settings) { _settings = settings; list.setSettings(settings); } - const SymbolDatabase *getSymbolDatabase() const - { + const SymbolDatabase *getSymbolDatabase() const { return _symbolDatabase; } void createSymbolDatabase(); @@ -732,8 +726,7 @@ public: * Get variable count. * @return number of variables */ - unsigned int varIdCount() const - { + unsigned int varIdCount() const { return _varId; } @@ -754,8 +747,7 @@ public: */ TokenList list; // Implement tokens() as a wrapper for convinience when using the TokenList - const Token* tokens() const - { + const Token* tokens() const { return list.front(); } @@ -806,8 +798,7 @@ private: Tokenizer &operator=(const Tokenizer &); static Token * startOfFunction(Token * tok); - static Token * startOfExecutableScope(Token * tok) - { + static Token * startOfExecutableScope(Token * tok) { return const_cast(startOfExecutableScope(const_cast(tok))); } diff --git a/lib/tokenlist.h b/lib/tokenlist.h index b4ae3fd01..944e5d586 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -36,8 +36,7 @@ public: TokenList(const Settings* settings); ~TokenList(); - void setSettings(const Settings *settings) - { + void setSettings(const Settings *settings) { _settings = settings; } @@ -45,14 +44,12 @@ public: const std::string& getSourceFilePath() const; /** Is the code C. Used for bailouts */ - bool isC() const - { + bool isC() const { return _isC; } /** Is the code CPP. Used for bailouts */ - bool isCPP() const - { + bool isCPP() const { return _isCPP; } @@ -85,22 +82,18 @@ public: unsigned int appendFileIfNew(const std::string &file); /** get first token of list */ - const Token *front() const - { + const Token *front() const { return _front; } - Token *front() - { + Token *front() { return _front; } /** get last token of list */ - const Token *back() const - { + const Token *back() const { return _back; } - Token *back() - { + Token *back() { return _back; } @@ -109,8 +102,7 @@ public: * The first filename is the filename for the sourcefile * @return vector with filenames */ - const std::vector& getFiles() const - { + const std::vector& getFiles() const { return _files; } diff --git a/test/redirect.h b/test/redirect.h index b282f1850..b7ee4f386 100644 --- a/test/redirect.h +++ b/test/redirect.h @@ -29,8 +29,7 @@ extern std::ostringstream output; class RedirectOutputError { public: /** Set up redirection, flushing anything in the pipes. */ - RedirectOutputError() - { + RedirectOutputError() { // flush all old output std::cout.flush(); std::cerr.flush(); @@ -43,8 +42,7 @@ public: } /** Revert cout and cerr behaviour */ - ~RedirectOutputError() - { + ~RedirectOutputError() { std::cout.rdbuf(_oldCout); // restore cout's original streambuf std::cerr.rdbuf(_oldCerr); // restore cerrs's original streambuf @@ -53,28 +51,24 @@ public: } /** Return what would be printed to cout. See also clearOutput() */ - std::string getOutput() const - { + std::string getOutput() const { return _out.str(); } /** Normally called after getOutput() to prevent same text to be returned twice. */ - void clearOutput() - { + void clearOutput() { _out.str(""); } /** Return what would be printed to cerr. See also clearErrout() */ - std::string getErrout() const - { + std::string getErrout() const { return _err.str(); } /** Normally called after getErrout() to prevent same text to be returned twice. */ - void clearErrout() - { + void clearErrout() { _err.str(""); } diff --git a/test/test64bit.cpp b/test/test64bit.cpp index 4d952d8b0..3913349fd 100644 --- a/test/test64bit.cpp +++ b/test/test64bit.cpp @@ -26,15 +26,13 @@ extern std::ostringstream errout; class Test64BitPortability : public TestFixture { public: - Test64BitPortability() : TestFixture("Test64BitPortability") - { + Test64BitPortability() : TestFixture("Test64BitPortability") { } private: - void run() - { + void run() { TEST_CASE(novardecl); TEST_CASE(functionpar); TEST_CASE(structmember); @@ -43,8 +41,7 @@ private: TEST_CASE(returnIssues); } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -61,8 +58,7 @@ private: check64BitPortability.pointerassignment(); } - void novardecl() - { + void novardecl() { // if the variable declarations can't be seen then skip the warning check("void foo()\n" "{\n" @@ -71,8 +67,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void functionpar() - { + void functionpar() { check("int foo(int *p)\n" "{\n" " int a = p;\n" @@ -107,8 +102,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember() - { + void structmember() { check("struct Foo { int *p; };\n" "void f(struct Foo *foo) {\n" " int i = foo->p;\n" @@ -116,8 +110,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (portability) Assigning a pointer to an integer is not portable.\n", errout.str()); } - void ptrcompare() - { + void ptrcompare() { // Ticket #2892 check("void foo(int *p) {\n" " int a = (p != NULL);\n" @@ -125,8 +118,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ptrarithmetic() - { + void ptrarithmetic() { // #3073 check("void foo(int *p) {\n" " int x = 10;\n" @@ -153,8 +145,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnIssues() - { + void returnIssues() { check("void* foo(int i) {\n" " return i;\n" "}"); diff --git a/test/testassert.cpp b/test/testassert.cpp index 79513eceb..a28733645 100644 --- a/test/testassert.cpp +++ b/test/testassert.cpp @@ -30,8 +30,7 @@ public: private: void check( const char code[], - const char *filename = NULL) - { + const char *filename = NULL) { // Clear the error buffer.. errout.str(""); @@ -48,8 +47,7 @@ private: checkAssert.runSimplifiedChecks(&tokenizer, &settings, this); } - void run() - { + void run() { TEST_CASE(assignmentInAssert); TEST_CASE(functionCallInAssert); TEST_CASE(memberFunctionCallInAssert); @@ -57,8 +55,7 @@ private: } - void safeFunctionCallInAssert() - { + void safeFunctionCallInAssert() { check( "int a;\n" "bool b = false;\n" @@ -80,8 +77,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void functionCallInAssert() - { + void functionCallInAssert() { check( "int a;\n" "int foo() {\n" @@ -138,8 +134,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void memberFunctionCallInAssert() - { + void memberFunctionCallInAssert() { check("struct SquarePack {\n" " void Foo();\n" "};\n" @@ -172,8 +167,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assignmentInAssert() - { + void assignmentInAssert() { check("void f() {\n" " int a; a = 0;\n" " assert(a = 2);\n" diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 70d029467..4263766bc 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -27,16 +27,14 @@ extern std::ostringstream errout; class TestAutoVariables : public TestFixture { public: - TestAutoVariables() : TestFixture("TestAutoVariables") - { + TestAutoVariables() : TestFixture("TestAutoVariables") { } private: - void check(const char code[], bool inconclusive=false, bool runSimpleChecks=true, const char* filename=nullptr) - { + void check(const char code[], bool inconclusive=false, bool runSimpleChecks=true, const char* filename=nullptr) { // Clear the error buffer.. errout.str(""); @@ -67,8 +65,7 @@ private: } } - void run() - { + void run() { TEST_CASE(testautovar1); TEST_CASE(testautovar2); TEST_CASE(testautovar3); // ticket #2925 @@ -121,8 +118,7 @@ private: - void testautovar1() - { + void testautovar1() { check("void func1(int **res)\n" "{\n" " int num = 2;\n" @@ -145,8 +141,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testautovar2() - { + void testautovar2() { check("class Fred {\n" " void func1(int **res);\n" "}\n" @@ -178,8 +173,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testautovar3() // ticket #2925 - { + void testautovar3() { // ticket #2925 check("void foo(int **p)\n" "{\n" " int x[100];\n" @@ -188,8 +182,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); } - void testautovar4() // ticket #2928 - { + void testautovar4() { // ticket #2928 check("void foo(int **p)\n" "{\n" " static int x[100];\n" @@ -198,8 +191,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testautovar5() // ticket #2926 - { + void testautovar5() { // ticket #2926 check("void foo(struct AB *ab)\n" "{\n" " char a;\n" @@ -215,8 +207,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str()); } - void testautovar6() // ticket #2931 - { + void testautovar6() { // ticket #2931 check("void foo(struct X *x)\n" "{\n" " char a[10];\n" @@ -232,8 +223,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Address of local auto-variable assigned to a function parameter.\n", errout.str()); } - void testautovar7() // ticket #3066 - { + void testautovar7() { // ticket #3066 check("struct txt_scrollpane_s * TXT_NewScrollPane(struct txt_widget_s * target)\n" "{\n" " struct txt_scrollpane_s * scrollpane;\n" @@ -243,8 +233,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testautovar8() - { + void testautovar8() { check("void foo(int*& p) {\n" " int i = 0;\n" " p = &i;\n" @@ -257,8 +246,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testautovar9() - { + void testautovar9() { check("struct FN {int i;};\n" "struct FP {FN* f};\n" "void foo(int*& p, FN* p_fp) {\n" @@ -271,8 +259,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); } - void testautovar10() // #2930 - assignment of function parameter - { + void testautovar10() { // #2930 - assignment of function parameter check("void foo(char* p) {\n" " p = 0;\n" "}"); @@ -340,8 +327,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (warning) Assignment of function parameter has no effect outside the function. Did you forget dereferencing it?\n", errout.str()); } - void testautovar11() // #4641 - fp, assign local struct member address to function parameter - { + void testautovar11() { // #4641 - fp, assign local struct member address to function parameter check("struct A {\n" " char *data[10];\n" "};\n" @@ -374,8 +360,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); } - void testautovar12() // Ticket #5024, #5050 - Crash on invalid input - { + void testautovar12() { // Ticket #5024, #5050 - Crash on invalid input check("void f(int* a) { a = }"); check("struct custom_type { custom_type(int) {} };\n" "void func(int) {}\n" @@ -384,8 +369,7 @@ private: "UNKNOWN_MACRO_EXPANDING_TO_SIGNATURE { custom_type a(var); }"); } - void testautovar13() // Ticket #5537 - { + void testautovar13() { // Ticket #5537 check("class FileManager {\n" " FileManager() : UniqueRealDirs(*new UniqueDirContainer())\n" " {}\n" @@ -395,8 +379,7 @@ private: "};\n"); } - void testautovar14() // Ticket #4776 - { + void testautovar14() { // Ticket #4776 check("void f(int x) {\n" "label:" " if (x>0) {\n" @@ -407,8 +390,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testautovar_array1() - { + void testautovar_array1() { check("void func1(int* arr[2])\n" "{\n" " int num=2;" @@ -417,8 +399,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); } - void testautovar_array2() - { + void testautovar_array2() { check("class Fred {\n" " void func1(int* arr[2]);\n" "}\n" @@ -430,8 +411,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Address of local auto-variable assigned to a function parameter.\n", errout.str()); } - void testautovar_return1() - { + void testautovar_return1() { check("int* func1()\n" "{\n" " int num=2;" @@ -440,8 +420,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Address of an auto-variable returned.\n", errout.str()); } - void testautovar_return2() - { + void testautovar_return2() { check("class Fred {\n" " int* func1()\n" "}\n" @@ -453,8 +432,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Address of an auto-variable returned.\n", errout.str()); } - void testautovar_return3() - { + void testautovar_return3() { // #2975 - FP check("void** f()\n" "{\n" @@ -464,8 +442,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testautovar_return4() - { + void testautovar_return4() { // #3030 check("char *foo()\n" "{\n" @@ -482,8 +459,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testautovar_extern() - { + void testautovar_extern() { check("struct foo *f()\n" "{\n" " extern struct foo f;\n" @@ -492,8 +468,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testinvaliddealloc() - { + void testinvaliddealloc() { check("void func1() {\n" " char tmp1[256];\n" " free(tmp1);\n" @@ -577,8 +552,7 @@ private: } - void testinvaliddealloc_C() - { + void testinvaliddealloc_C() { // #5691 check("void svn_repos_dir_delta2() {\n" " struct context c;\n" @@ -587,8 +561,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testassign1() // Ticket #1819 - { + void testassign1() { // Ticket #1819 check("void f(EventPtr *eventP, ActionPtr **actionsP) {\n" " EventPtr event = *eventP;\n" " *actionsP = &event->actions;\n" @@ -596,8 +569,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testassign2() // Ticket #2765 - { + void testassign2() { // Ticket #2765 check("static void function(unsigned long **datap) {\n" " struct my_s *mr = global_structure_pointer;\n" " *datap = &mr->value;\n" @@ -605,8 +577,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnLocalVariable1() - { + void returnLocalVariable1() { check("char *foo()\n" "{\n" " char str[100] = {0};\n" @@ -625,8 +596,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Pointer to local array variable returned.\n", errout.str()); } - void returnLocalVariable2() - { + void returnLocalVariable2() { check("std::string foo()\n" "{\n" " char str[100] = {0};\n" @@ -645,8 +615,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnReference1() - { + void returnReference1() { check("std::string &foo()\n" "{\n" " std::string s;\n" @@ -743,8 +712,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnReference2() - { + void returnReference2() { check("class Fred {\n" " std::string &foo();\n" "}\n" @@ -834,8 +802,7 @@ private: "}"); } - void returnReference3() - { + void returnReference3() { check("double & f(double & rd) {\n" " double ret = getValue();\n" " rd = ret;\n" @@ -845,8 +812,7 @@ private: } // Returning reference to global variable - void returnReference4() - { + void returnReference4() { check("double a;\n" "double & f() {\n" " return a;\n" @@ -854,8 +820,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnReference5() - { + void returnReference5() { check("struct A {\n" " int i;\n" "};\n" @@ -875,8 +840,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnReference6() - { + void returnReference6() { check("Fred & create() {\n" " Fred &fred(*new Fred);\n" " return fred;\n" @@ -884,8 +848,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnReference7() // 3791 - false positive for overloaded function - { + void returnReference7() { // 3791 - false positive for overloaded function check("std::string a();\n" "std::string &a(int);\n" "std::string &b() {\n" @@ -901,8 +864,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnReferenceLiteral() - { + void returnReferenceLiteral() { check("const std::string &a() {\n" " return \"foo\";\n" "}"); @@ -914,8 +876,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnReferenceCalculation() - { + void returnReferenceCalculation() { check("const std::string &a(const std::string& str) {\n" " return \"foo\" + str;\n" "}"); @@ -953,8 +914,7 @@ private: } - void testglobalnamespace() - { + void testglobalnamespace() { check("class SharedPtrHolder\n" "{\n" " ::std::tr1::shared_ptr pNum;\n" @@ -968,8 +928,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnParameterAddress() - { + void returnParameterAddress() { check("int* foo(int y)\n" "{\n" " return &y;\n" @@ -992,8 +951,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testconstructor() // Ticket #5478 - crash while checking a constructor - { + void testconstructor() { // Ticket #5478 - crash while checking a constructor check("class const_tree_iterator {\n" " const_tree_iterator(bool (*_incream)(node_type*&)) {}\n" " const_tree_iterator& parent() {\n" @@ -1002,8 +960,7 @@ private: "};"); } - void variableIsUsedInScope() - { + void variableIsUsedInScope() { check("void removed_cb (GList *uids) {\n" "for (; uids; uids = uids->next) {\n" "}\n" diff --git a/test/testbool.cpp b/test/testbool.cpp index d888fe53c..1f3be7600 100644 --- a/test/testbool.cpp +++ b/test/testbool.cpp @@ -26,15 +26,13 @@ extern std::ostringstream errout; class TestBool : public TestFixture { public: - TestBool() : TestFixture("TestBool") - { + TestBool() : TestFixture("TestBool") { } private: - void run() - { + void run() { TEST_CASE(bitwiseOnBoolean); // if (bool & bool) TEST_CASE(incrementBoolean); TEST_CASE(assignBoolToPointer); @@ -65,8 +63,7 @@ private: TEST_CASE(pointerArithBool1); } - void check(const char code[], bool experimental = false, const char filename[] = "test.cpp") - { + void check(const char code[], bool experimental = false, const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -89,8 +86,7 @@ private: } - void assignBoolToPointer() - { + void assignBoolToPointer() { check("void foo(bool *p) {\n" " p = false;\n" @@ -144,8 +140,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assignBoolToFloat() - { + void assignBoolToFloat() { check("void foo1() {\n" " double d = false;\n" "}"); @@ -168,8 +163,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void comparisonOfBoolExpressionWithInt1() - { + void comparisonOfBoolExpressionWithInt1() { check("void f(int x) {\n" " if ((x && 0x0f)==6)\n" " a++;\n" @@ -382,8 +376,7 @@ private: ASSERT_EQUALS("",errout.str()); } - void comparisonOfBoolExpressionWithInt2() - { + void comparisonOfBoolExpressionWithInt2() { check("void f(int x) {\n" " if (!x == 10) {\n" " printf(\"x not equal to 10\");\n" @@ -463,16 +456,14 @@ private: ASSERT_EQUALS("[test.cpp:1]: (warning) Comparison of a boolean expression with an integer other than 0 or 1.\n",errout.str()); } - void comparisonOfBoolExpressionWithInt3() - { + void comparisonOfBoolExpressionWithInt3() { check("int f(int x) {\n" " return t<0>() && x;\n" "}"); ASSERT_EQUALS("", errout.str()); } - void comparisonOfBoolExpressionWithInt4() - { + void comparisonOfBoolExpressionWithInt4() { // #5016 check("void f() {\n" " for(int i = 4; i > -1 < 5 ; --i) {}\n" @@ -508,8 +499,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkComparisonOfFuncReturningBool1() - { + void checkComparisonOfFuncReturningBool1() { check("void f(){\n" " int temp = 4;\n" " if(compare1(temp) > compare2(temp)){\n" @@ -533,8 +523,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } - void checkComparisonOfFuncReturningBool2() - { + void checkComparisonOfFuncReturningBool2() { check("void f(){\n" " int temp = 4;\n" " bool a = true;\n" @@ -552,8 +541,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } - void checkComparisonOfFuncReturningBool3() - { + void checkComparisonOfFuncReturningBool3() { check("void f(){\n" " int temp = 4;\n" " if(compare(temp) > temp){\n" @@ -570,8 +558,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } - void checkComparisonOfFuncReturningBool4() - { + void checkComparisonOfFuncReturningBool4() { check("void f(){\n" " int temp = 4;\n" " bool b = compare2(6);\n" @@ -596,8 +583,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Comparison of a function returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } - void checkComparisonOfFuncReturningBool5() - { + void checkComparisonOfFuncReturningBool5() { check("void f(){\n" " int temp = 4;\n" " if(compare1(temp) > !compare2(temp)){\n" @@ -621,8 +607,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Comparison of two functions returning boolean value using relational (<, >, <= or >=) operator.\n", errout.str()); } - void checkComparisonOfFuncReturningBool6() - { + void checkComparisonOfFuncReturningBool6() { check("int compare1(int temp);\n" "namespace Foo {\n" " bool compare1(int temp);\n" @@ -681,8 +666,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkComparisonOfBoolWithBool() - { + void checkComparisonOfBoolWithBool() { const char code[] = "void f(){\n" " int temp = 4;\n" " bool b = compare2(6);\n" @@ -711,8 +695,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void bitwiseOnBoolean() // 3062 - { + void bitwiseOnBoolean() { // 3062 check("void f(_Bool a, _Bool b) {\n" " if(a & b) {}\n" "}"); @@ -778,8 +761,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void incrementBoolean() - { + void incrementBoolean() { check("bool bValue = true;\n" "void f() { bValue++; }"); ASSERT_EQUALS("[test.cpp:2]: (style) Incrementing a variable of type 'bool' with postfix operator++ is deprecated by the C++ Standard. You should assign it the value 'true' instead.\n", errout.str()); @@ -795,8 +777,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void comparisonOfBoolWithInt1() - { + void comparisonOfBoolWithInt1() { check("void f(bool x) {\n" " if (x < 10) {\n" " printf(\"foo\");\n" @@ -849,8 +830,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void comparisonOfBoolWithInt2() - { + void comparisonOfBoolWithInt2() { check("void f(bool x, int y) {\n" " if (x == y) {\n" " printf(\"foo\");\n" @@ -880,8 +860,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void comparisonOfBoolWithInt3() - { + void comparisonOfBoolWithInt3() { check("void f(int y) {\n" " if (y > false) {\n" " printf(\"foo\");\n" @@ -911,16 +890,14 @@ private: ASSERT_EQUALS("[test.cpp:2]: (warning) Comparison of a boolean with an integer.\n", errout.str()); } - void comparisonOfBoolWithInt4() - { + void comparisonOfBoolWithInt4() { check("void f(int x) {\n" " if (!x == 1) { }\n" "}"); ASSERT_EQUALS("", errout.str()); } - void comparisonOfBoolWithInt5() - { + void comparisonOfBoolWithInt5() { check("void SetVisible(int index, bool visible) {\n" " bool (SciTEBase::*ischarforsel)(char ch);\n" " if (visible != GetVisible(index)) { }\n" @@ -928,24 +905,21 @@ private: ASSERT_EQUALS("", errout.str()); } - void comparisonOfBoolWithInt6() // #4224 - integer is casted to bool - { + void comparisonOfBoolWithInt6() { // #4224 - integer is casted to bool check("void SetVisible(bool b, int i) {\n" " if (b == (bool)i) { }\n" "}"); ASSERT_EQUALS("", errout.str()); } - void comparisonOfBoolWithInt7() // #4846 - (!x==true) - { + void comparisonOfBoolWithInt7() { // #4846 - (!x==true) check("void f(int x) {\n" " if (!x == true) { }\n" "}"); ASSERT_EQUALS("", errout.str()); } - void pointerArithBool1() // #5126 - { + void pointerArithBool1() { // #5126 check("void f(char *p) {\n" " if (p+1){}\n" "}"); diff --git a/test/testboost.cpp b/test/testboost.cpp index 31af86652..e7b1cbbbb 100644 --- a/test/testboost.cpp +++ b/test/testboost.cpp @@ -27,18 +27,15 @@ extern std::ostringstream errout; class TestBoost : public TestFixture { public: - TestBoost() : TestFixture("TestBoost") - { + TestBoost() : TestFixture("TestBoost") { } private: - void run() - { + void run() { TEST_CASE(BoostForeachContainerModification) } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -61,8 +58,7 @@ private: checkBoost.runSimplifiedChecks(&tokenizer, &settings, this); } - void BoostForeachContainerModification() - { + void BoostForeachContainerModification() { check("void f() {\n" " vector data;\n" " BOOST_FOREACH(int i, data) {\n" diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index e60213025..3c3ad8577 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -28,14 +28,12 @@ extern std::ostringstream errout; class TestBufferOverrun : public TestFixture { public: - TestBufferOverrun() : TestFixture("TestBufferOverrun") - { + TestBufferOverrun() : TestFixture("TestBufferOverrun") { } private: - void check(const char code[], bool experimental = true, const char filename[] = "test.cpp", bool verify = true) - { + void check(const char code[], bool experimental = true, const char filename[] = "test.cpp", bool verify = true) { // Clear the error buffer.. errout.str(""); @@ -72,8 +70,7 @@ private: checkBufferOverrun.writeOutsideBufferSize(); } - void checkstd(const char code[], const char filename[] = "test.cpp") - { + void checkstd(const char code[], const char filename[] = "test.cpp") { static bool init; static Settings settings; if (!init) { @@ -97,8 +94,7 @@ private: checkBufferOverrun.writeOutsideBufferSize(); } - void checkposix(const char code[], const char filename[] = "test.cpp") - { + void checkposix(const char code[], const char filename[] = "test.cpp") { static bool init; static Settings settings; if (!init) { @@ -123,8 +119,7 @@ private: } - void run() - { + void run() { TEST_CASE(noerr1); TEST_CASE(noerr2); TEST_CASE(noerr3); @@ -325,8 +320,7 @@ private: - void noerr1() - { + void noerr1() { check("extern int ab;\n" "void f()\n" "{\n" @@ -343,8 +337,7 @@ private: } - void noerr2() - { + void noerr2() { check("static char buf[2];\n" "void f1(char *str)\n" "{\n" @@ -366,8 +359,7 @@ private: } - void noerr3() - { + void noerr3() { check("struct { char data[10]; } abc;\n" "static char f()\n" "{\n" @@ -378,8 +370,7 @@ private: } - void noerr4() - { + void noerr4() { // The memory isn't read or written and therefore there is no error. check("static void f() {\n" " char data[100];\n" @@ -388,8 +379,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sizeof3() - { + void sizeof3() { check("struct group { int gr_gid; };\n" "void f()\n" "{\n" @@ -401,8 +391,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_1() - { + void array_index_1() { check("void f()\n" "{\n" " char str[0x10];\n" @@ -439,8 +428,7 @@ private: } - void array_index_2() - { + void array_index_2() { check("void f()\n" "{\n" " char *str = new char[0x10];\n" @@ -451,8 +439,7 @@ private: } - void array_index_3() - { + void array_index_3() { { check("void f()\n" "{\n" @@ -520,8 +507,7 @@ private: } } - void array_index_6() - { + void array_index_6() { check("struct ABC\n" "{\n" " char str[10];\n" @@ -677,8 +663,7 @@ private: } - void array_index_7() - { + void array_index_7() { check("struct ABC\n" "{\n" " char str[10];\n" @@ -691,8 +676,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) Array 'abc.str[10]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void array_index_9() - { + void array_index_9() { check("static void memclr( char *data )\n" "{\n" " data[10] = 0;\n" @@ -768,8 +752,7 @@ private: } - void array_index_11() - { + void array_index_11() { check("class ABC\n" "{\n" "public:\n" @@ -790,8 +773,7 @@ private: } - void array_index_12() - { + void array_index_12() { check("class Fred\n" "{\n" "private:\n" @@ -819,8 +801,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (error) Array 'str[10]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void array_index_13() - { + void array_index_13() { check("void f()\n" "{\n" " char buf[10];\n" @@ -833,8 +814,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_14() - { + void array_index_14() { check("void f()\n" "{\n" " int a[10];\n" @@ -844,8 +824,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout.str()); } - void array_index_15() - { + void array_index_15() { check("void f()\n" "{\n" " int a[10];\n" @@ -855,8 +834,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 19, which is out of bounds.\n", errout.str()); } - void array_index_16() - { + void array_index_16() { check("void f()\n" "{\n" " int a[10];\n" @@ -866,8 +844,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void array_index_17() - { + void array_index_17() { check("void f()\n" "{\n" " int a[10];\n" @@ -907,8 +884,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_18() - { + void array_index_18() { check("void f()\n" "{\n" " int a[5];\n" @@ -965,8 +941,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Buffer overrun\n", "", errout.str()); } - void array_index_19() - { + void array_index_19() { // "One Past the End" is legal, as long as pointer is not dereferenced. check("void f()\n" "{\n" @@ -984,8 +959,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[2]' accessed at index 3, which is out of bounds.\n", errout.str()); } - void array_index_20() - { + void array_index_20() { check("void f()\n" "{\n" " char a[8];\n" @@ -996,8 +970,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_21() - { + void array_index_21() { check("class A {\n" " int indices[2];\n" " void foo(int indices[3]);\n" @@ -1011,8 +984,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_22() - { + void array_index_22() { check("int main() {\n" " size_t indices[2];\n" " int b = indices[2];\n" @@ -1020,8 +992,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Array 'indices[2]' accessed at index 2, which is out of bounds.\n", errout.str()); } - void array_index_23() - { + void array_index_23() { check("void foo()\n" "{\n" " char c[10];\n" @@ -1030,8 +1001,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 'c[10]' accessed at index 8388608, which is out of bounds.\n", errout.str()); } - void array_index_24() - { + void array_index_24() { // ticket #1492 and #1539 // CHAR_MAX can be equal to SCHAR_MAX or UCHAR_MAX depending on the environment. // This test should work for both environments. @@ -1104,8 +1074,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Array index -1 is out of bounds.\n", errout.str()); } - void array_index_25() - { + void array_index_25() { // ticket #1536 check("void foo()\n" "{\n" @@ -1114,8 +1083,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_26() - { + void array_index_26() { check("void f()\n" "{\n" " int a[3];\n" @@ -1133,8 +1101,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_27() - { + void array_index_27() { check("void f()\n" "{\n" " int a[10];\n" @@ -1144,8 +1111,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Array index -1 is out of bounds.\n", errout.str()); } - void array_index_28() - { + void array_index_28() { // ticket #1418 check("void f()\n" "{\n" @@ -1156,8 +1122,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:5]: (error) Array ip[-10] out of bounds.\n", "", errout.str()); } - void array_index_29() - { + void array_index_29() { // ticket #1724 check("void f()\n" "{\n" @@ -1169,8 +1134,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Array ii[10] out of bounds.\n", "", errout.str()); } - void array_index_30() - { + void array_index_30() { // ticket #2086 - unknown type check("void f() {\n" " UINT8 x[2];\n" @@ -1179,8 +1143,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Array 'x[2]' accessed at index 5, which is out of bounds.\n", errout.str()); } - void array_index_31() - { + void array_index_31() { // ticket #2120 - sub function, unknown type check("struct s1 {\n" " unknown_type_t delay[3];\n" @@ -1220,8 +1183,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_32() - { + void array_index_32() { check("class X\n" "{\n" " public:\n" @@ -1235,16 +1197,14 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Array 'm_x[1]' accessed at index 1, which is out of bounds.\n", errout.str()); } - void array_index_33() - { + void array_index_33() { check("void foo(char bar[][4]) {\n" " baz(bar[5]);\n" "}"); ASSERT_EQUALS("", errout.str()); } - void array_index_34() // ticket #3063 - { + void array_index_34() { // ticket #3063 check("void foo() {\n" " int y[2][2][2];\n" " y[0][2][0] = 0;\n" @@ -1297,8 +1257,7 @@ private: "[test.cpp:13]: (error) Array 'ptest.a[10][5]' index ptest.a[0][50] out of bounds.\n", errout.str()); } - void array_index_35() // ticket #2889 - { + void array_index_35() { // ticket #2889 check("void f() {\n" " struct Struct { unsigned m_Var[1]; } s;\n" " s.m_Var[1] = 1;\n" @@ -1320,8 +1279,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_36() // ticket #2960 - { + void array_index_36() { // ticket #2960 check("class Fred {\n" " Fred(const Fred &);\n" "private:\n" @@ -1334,8 +1292,7 @@ private: "[test.cpp:7]: (error) Array 'rhs.m_b[2]' accessed at index 2, which is out of bounds.\n", errout.str()); } - void array_index_37() - { + void array_index_37() { check("class Fred {\n" " char x[X];\n" " Fred() {\n" @@ -1346,8 +1303,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_38() //ticket #3273 - { + void array_index_38() { //ticket #3273 check("void aFunction() {\n" " double aDoubleArray[ 10 ];\n" " unsigned int i; i = 0;\n" @@ -1366,8 +1322,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_39() // ticket 3387 - { + void array_index_39() { // ticket 3387 check("void aFunction()\n" "{\n" " char a[10];\n" @@ -1376,8 +1331,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void array_index_40() - { + void array_index_40() { check("void f() {\n" " char a[10];\n" " for (int i = 0; i < 10; ++i)\n" @@ -1386,8 +1340,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_41() - { + void array_index_41() { // Don't generate false positives when structs have the same name check("void a() {\n" " struct Fred { char data[6]; } fred;\n" @@ -1411,8 +1364,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) Array 'fred.data[3]' accessed at index 4, which is out of bounds.\n", errout.str()); } - void array_index_42() // ticket #3569 - { + void array_index_42() { // ticket #3569 check("void f()\n" "{\n" @@ -1465,8 +1417,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_43() // #3838 - { + void array_index_43() { // #3838 check("int f( )\n" "{\n" @@ -1565,8 +1516,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 'ab[1]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void array_index_44() // #3979 (false positive) - { + void array_index_44() { // #3979 (false positive) check("void f()\n" "{\n" @@ -1590,8 +1540,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_45() // #4207 - handling of function with variable number of parameters / unnamed arguments - { + void array_index_45() { // #4207 - handling of function with variable number of parameters / unnamed arguments // Variable number of arguments check("void f(const char *format, ...) {\n" " va_args args;\n" @@ -1615,8 +1564,7 @@ private: } // Two statement for-loop - void array_index_46() - { + void array_index_46() { // #4840 check("void bufferAccessOutOfBounds2() {\n" " char *buffer[]={\"a\",\"b\",\"c\"};\n" @@ -1645,8 +1593,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_47() - { + void array_index_47() { // #5849 check("int s[4];\n" "void f() {\n" @@ -1656,8 +1603,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_multidim() - { + void array_index_multidim() { check("void f()\n" "{\n" " char a[2][2];\n" @@ -1754,8 +1700,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_switch_in_for() - { + void array_index_switch_in_for() { check("void f()\n" "{\n" " int ar[10];\n" @@ -1793,8 +1738,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:12]: (error) Array index out of bounds.\n", "", errout.str()); } - void array_index_for_in_for() - { + void array_index_for_in_for() { check("void f() {\n" " int a[5];\n" " for (int i = 0; i < 10; ++i) {\n" @@ -1806,8 +1750,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_calculation() - { + void array_index_calculation() { // #1193 - false negative: array out of bounds in loop when there is calculation check("void f()\n" "{\n" @@ -1829,8 +1772,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Array 'arr[5]' accessed at index 11, which is out of bounds.\n", errout.str()); } - void array_index_negative1() - { + void array_index_negative1() { // #948 - array index out of bound not detected 'a[-1] = 0' check("void f()\n" "{\n" @@ -1869,8 +1811,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_negative2() // ticket #3063 - { + void array_index_negative2() { // ticket #3063 check("struct TEST { char a[10]; };\n" "void foo() {\n" " TEST test;\n" @@ -1879,8 +1820,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 'test.a[10]' accessed at index -1, which is out of bounds.\n", errout.str()); } - void array_index_for_decr() - { + void array_index_for_decr() { check("void f()\n" "{\n" " char data[8];\n" @@ -1911,8 +1851,7 @@ private: } - void array_index_varnames() - { + void array_index_varnames() { check("struct A {\n" " char data[4];\n" " struct B { char data[3]; };\n" @@ -1927,8 +1866,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_for_andand_oror() // #3907 - using && or || - { + void array_index_for_andand_oror() { // #3907 - using && or || check("void f() {\n" " char data[2];\n" " int x;\n" @@ -1966,8 +1904,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void array_index_for_continue() - { + void array_index_for_continue() { // #3913 check("void f() {\n" " int a[2];\n" @@ -1992,8 +1929,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Array index -1 is out of bounds.\n", errout.str()); } - void array_index_for() - { + void array_index_for() { // Ticket #2370 - No false negative when there is no "break" check("void f() {\n" " int a[10];\n" @@ -2027,8 +1963,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void array_index_for_neq() - { + void array_index_for_neq() { // Ticket #2211 - for loop using != in the condition check("void f() {\n" " int a[5];\n" @@ -2040,8 +1975,7 @@ private: errout.str()); } - void array_index_for_question() - { + void array_index_for_question() { // Ticket #2561 - using ?: inside for loop check("void f() {\n" " int a[10];\n" @@ -2069,8 +2003,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Array index -1 is out of bounds.\n", errout.str()); } - void array_index_for_varid0() // #4228: No varid for counter variable - { + void array_index_for_varid0() { // #4228: No varid for counter variable check("void f() {\n" " char a[10];\n" " for (i=0; i<10; i++);\n" @@ -2078,8 +2011,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_vla_for() - { + void array_index_vla_for() { // #3221 - access VLA inside for check("void f(int len) {\n" " char a[len];\n" @@ -2090,16 +2022,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_extern() - { + void array_index_extern() { // Ticket #1684. FP when using 'extern'. check("extern char arr[15];\n" "char arr[15] = \"abc\";"); ASSERT_EQUALS("", errout.str()); } - void array_index_cast() - { + void array_index_cast() { // Ticket #2841. FP when using cast. // Different types => no error @@ -2123,8 +2053,7 @@ private: ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:2]: (error) Array 'x[2]' accessed at index 4, which is out of bounds.\n", errout.str()); } - void array_index_string_literal() - { + void array_index_string_literal() { check("void f() {\n" " const char *str = \"abc\";\n" " bar(str[10]);\n" @@ -2154,8 +2083,7 @@ private: } - void array_index_same_struct_and_var_name() - { + void array_index_same_struct_and_var_name() { // don't throw internal error check("struct tt {\n" " char name[21];\n" @@ -2179,8 +2107,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Array 'tt.name[21]' accessed at index 22, which is out of bounds.\n", errout.str()); } - void array_index_valueflow() - { + void array_index_valueflow() { check("void f(int i) {\n" " char str[3];\n" " str[i] = 0;\n" @@ -2209,8 +2136,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_1_posix_functions() - { + void buffer_overrun_1_posix_functions() { checkposix("void f(int fd)\n" "{\n" " char str[3];\n" @@ -2275,8 +2201,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: str\n", errout.str()); } - void buffer_overrun_1_standard_functions() - { + void buffer_overrun_1_standard_functions() { check("void f()\n" "{\n" " char str[3];\n" @@ -2344,8 +2269,7 @@ private: } - void buffer_overrun_2_struct() - { + void buffer_overrun_2_struct() { check("struct ABC\n" "{\n" " char str[5];\n" @@ -2404,8 +2328,7 @@ private: } - void buffer_overrun_3() - { + void buffer_overrun_3() { check("int a[10];\n" "\n" "void foo()\n" @@ -2418,8 +2341,7 @@ private: } - void buffer_overrun_4() - { + void buffer_overrun_4() { check("void foo()\n" "{\n" " const char *p[2];\n" @@ -2461,8 +2383,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_5() - { + void buffer_overrun_5() { check("void f()\n" "{\n" " char n[5];\n" @@ -2472,8 +2393,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_6() - { + void buffer_overrun_6() { check("void f()\n" "{\n" " char n[5];\n" @@ -2483,8 +2403,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: n\n", errout.str()); } - void buffer_overrun_7() - { + void buffer_overrun_7() { // ticket #731 check("void f()\n" "{\n" @@ -2494,8 +2413,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_8() - { + void buffer_overrun_8() { // ticket #714 check("void f()\n" "{\n" @@ -2518,8 +2436,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_9() - { + void buffer_overrun_9() { // ticket #738 check("void f()\n" "{\n" @@ -2533,8 +2450,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_10() - { + void buffer_overrun_10() { // ticket #740 check("void f()\n" "{\n" @@ -2547,8 +2463,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_11() - { + void buffer_overrun_11() { check("void f()\n" "{\n" " char a[4];\n" @@ -2568,8 +2483,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_12() - { + void buffer_overrun_12() { // ticket #900 check("void f() {\n" " char *a = new char(30);\n" @@ -2579,8 +2493,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str()); } - void buffer_overrun_13() - { + void buffer_overrun_13() { // ticket #836 checkstd("void f() {\n" " char a[10];\n" @@ -2595,8 +2508,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds: a\n", errout.str()); } - void buffer_overrun_14() - { + void buffer_overrun_14() { checkstd("void f(char *a) {\n" " char *b = new char[strlen(a)];\n" " strcpy(b, a);\n" @@ -2672,8 +2584,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str()); } - void buffer_overrun_15() // ticket #1787 - { + void buffer_overrun_15() { // ticket #1787 check("class A : public B {\n" " char val[12];\n" " void f(int i, int ii);\n" @@ -2685,8 +2596,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Buffer is accessed out of bounds.\n", errout.str()); } - void buffer_overrun_16() - { + void buffer_overrun_16() { // unknown types check("void f() {\n" " struct Foo foo[5];\n" @@ -2708,8 +2618,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_17() // ticket #2548 - { + void buffer_overrun_17() { // ticket #2548 check("void f() {\n" " char t[8];\n" " sprintf(t, \"%s\", \"foo bar\");\n" @@ -2717,8 +2626,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str()); } - void buffer_overrun_18() // ticket #2576 - { + void buffer_overrun_18() { // ticket #2576 check("class A {\n" " void foo();\n" " bool b[7];\n" @@ -2744,8 +2652,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) Array 'b[7]' accessed at index 7, which is out of bounds.\n", errout.str()); } - void buffer_overrun_19() // #2597 - class member with unknown type - { + void buffer_overrun_19() { // #2597 - class member with unknown type check("class A {\n" "public:\n" " u8 buf[10];\n" @@ -2758,14 +2665,12 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_20() // #2986(segmentation fault) - { + void buffer_overrun_20() { // #2986(segmentation fault) check("x[y]\n"); ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_21() - { + void buffer_overrun_21() { check("void foo()\n" "{ { {\n" " char dst[4];\n" @@ -2776,8 +2681,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Array 'dst[4]' accessed at index 4, which is out of bounds.\n", errout.str()); } - void buffer_overrun_22() // ticket #3124 - { + void buffer_overrun_22() { // ticket #3124 checkstd("class A {\n" "public:\n" " char b[5][6];\n" @@ -2799,8 +2703,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Buffer is accessed out of bounds: a.b\n", errout.str()); } - void buffer_overrun_23() // ticket #3153 - { + void buffer_overrun_23() { // ticket #3153 checkstd("void foo() {\n" " double dest = 23.0;\n" " char* const source = (char*) malloc(sizeof(dest));\n" @@ -2817,8 +2720,7 @@ private: } - void buffer_overrun_24() // index variable is changed in for-loop - { + void buffer_overrun_24() { // index variable is changed in for-loop // ticket #4106 check("void main() {\n" " int array[] = {1,2};\n" @@ -2840,8 +2742,7 @@ private: TODO_ASSERT_EQUALS("error", "", errout.str()); } - void buffer_overrun_26() // ticket #4432 (segmentation fault) - { + void buffer_overrun_26() { // ticket #4432 (segmentation fault) check("extern int split();\n" "void regress() {\n" " char inbuf[1000];\n" @@ -2852,8 +2753,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_27() // ticket #4444 (segmentation fault) - { + void buffer_overrun_27() { // ticket #4444 (segmentation fault) check("void abc(struct foobar[5]);\n" "void main() {\n" "struct foobar x[5];\n" @@ -2863,14 +2763,12 @@ private: ASSERT_EQUALS("", errout.str()); } - void buffer_overrun_28() - { + void buffer_overrun_28() { check("char c = \"abc\"[4];"); ASSERT_EQUALS("[test.cpp:1]: (error) Buffer is accessed out of bounds: \"abc\"\n", errout.str()); } - void buffer_overrun_bailoutIfSwitch() - { + void buffer_overrun_bailoutIfSwitch() { // No false positive check("void f1(char *s) {\n" " if (x) s[100] = 0;\n" @@ -2907,8 +2805,7 @@ private: ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:3]: (error) Array 'a[10]' accessed at index 100, which is out of bounds.\n", errout.str()); } - void buffer_overrun_function_array_argument() - { + void buffer_overrun_function_array_argument() { check("void f(char a[10]);\n" "void g() {\n" " char a[2];\n" @@ -2949,8 +2846,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void possible_buffer_overrun_1() // #3035 - { + void possible_buffer_overrun_1() { // #3035 check("void foo() {\n" " char * data = alloca(50);\n" " char src[100];\n" @@ -3012,8 +2908,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void valueflow_string() // using ValueFlow string values in checking - { + void valueflow_string() { // using ValueFlow string values in checking checkstd("void f() {\n" " char buf[3];\n" " const char *x = s;\n" @@ -3037,8 +2932,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 'x[6]' accessed at index 20, which is out of bounds.\n", errout.str()); } - void pointer_out_of_bounds_1() - { + void pointer_out_of_bounds_1() { check("void f() {\n" " char a[10];\n" " char *p = a + 100;\n" @@ -3046,8 +2940,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (portability) Undefined behaviour: Pointer arithmetic result does not point into or just past the end of the array.\n", errout.str()); } - void pointer_out_of_bounds_2() - { + void pointer_out_of_bounds_2() { check("void f() {\n" " char *p = malloc(10);\n" " p += 100;\n" @@ -3082,8 +2975,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf1() - { + void sprintf1() { check("void f()\n" "{\n" " char str[3];\n" @@ -3100,8 +2992,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds.\n", errout.str()); } - void sprintf2() - { + void sprintf2() { check("int getnumber();\n" "void f()\n" "{\n" @@ -3111,8 +3002,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds.\n", errout.str()); } - void sprintf3() - { + void sprintf3() { check("void f()\n" "{\n" " char str[3];\n" @@ -3128,8 +3018,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf4() - { + void sprintf4() { // ticket #690 check("void f()\n" "{\n" @@ -3139,8 +3028,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf5() - { + void sprintf5() { // ticket #729 check("void f(int condition)\n" "{\n" @@ -3150,8 +3038,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf6() - { + void sprintf6() { check("void f(int condition)\n" "{\n" " char buf[3];\n" @@ -3160,8 +3047,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds.\n", "", errout.str()); } - void sprintf7() - { + void sprintf7() { check("struct Foo { char a[1]; };\n" "void f()\n" "{\n" @@ -3190,8 +3076,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf8() - { + void sprintf8() { check("struct Foo { char a[3]; };\n" "void f()\n" "{\n" @@ -3201,8 +3086,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf9() - { + void sprintf9() { check("void f()\n" "{\n" " gchar str[3];\n" @@ -3211,8 +3095,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf10() - { + void sprintf10() { check("void f()\n" "{\n" " TString str = \"\";\n" @@ -3221,8 +3104,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void snprintf1() - { + void snprintf1() { check("void f()\n" "{\n" " char str[5];\n" @@ -3231,8 +3113,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) snprintf size is out of bounds: Supplied size 10 is larger than actual size 5.\n", errout.str()); } - void snprintf2() - { + void snprintf2() { check("void f()\n" "{\n" " char str[5];\n" @@ -3241,8 +3122,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void snprintf4() - { + void snprintf4() { check("void f(int x)\n" "{\n" " char str[5];\n" @@ -3251,8 +3131,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void snprintf5() - { + void snprintf5() { check("struct Foo { char a[1]; };\n" "void f()\n" "{\n" @@ -3281,8 +3160,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void snprintf6() - { + void snprintf6() { check("struct Foo { char a[3]; };\n" "void f()\n" "{\n" @@ -3292,8 +3170,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void snprintf7() - { + void snprintf7() { check("void x() {\n" " sal_Char pString[1024];\n" " snprintf(pString, 1024, \"ab\");\n" @@ -3312,8 +3189,7 @@ private: } - void strncat1() - { + void strncat1() { checkstd("void f(char *a, char *b) {\n" " char str[16];\n" " strncpy(str, a, 10);\n" @@ -3322,8 +3198,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) Dangerous usage of strncat - 3rd parameter is the maximum number of characters to append.\n", errout.str()); } - void strncat2() - { + void strncat2() { checkstd("void f(char *a) {\n" " char str[5];\n" " strncat(str, a, 5);\n" @@ -3331,8 +3206,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning) Dangerous usage of strncat - 3rd parameter is the maximum number of characters to append.\n", errout.str()); } - void strncat3() - { + void strncat3() { checkstd("struct Foo { char a[4]; };\n" "void f(char *a) {\n" " struct Foo x;\n" @@ -3341,8 +3215,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: x.a\n", errout.str()); } - void strncat4() - { + void strncat4() { checkstd("void f(char *a) {\n" " char str[5];\n" " strncat(str, \"foobar\", 5);\n" @@ -3351,8 +3224,7 @@ private: } - void strcat1() - { + void strcat1() { checkstd("struct Foo { char a[4]; };\n" "void f() {\n" " struct Foo x;\n" @@ -3362,8 +3234,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds.\n", errout.str()); } - void strcat2() - { + void strcat2() { checkstd("struct Foo { char a[5]; };\n" "void f() {\n" " struct Foo x;\n" @@ -3373,8 +3244,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void strcat3() - { + void strcat3() { checkstd("void f() {\n" " INT str[10];\n" " strcat(str, \"aa\");\n" @@ -3384,8 +3254,7 @@ private: // memchr/memset/memcpy/etc - void memfunc1() - { + void memfunc1() { checkstd("struct S {\n" " char a[5];\n" "};\n" @@ -3423,8 +3292,7 @@ private: } // ticket #2121 - buffer access out of bounds when using uint32_t - void memfunc2() - { + void memfunc2() { checkstd("void f() {\n" " unknown_type_t buf[4];\n" " memset(buf, 0, 100);\n" @@ -3433,8 +3301,7 @@ private: } // ticket #1659 - overflowing variable when using memcpy - void memfunc3() - { + void memfunc3() { checkstd("void f() { \n" " char str1[]=\"Sample string\";\n" " char str2;\n" @@ -3463,8 +3330,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varid1() - { + void varid1() { check("void foo()\n" "{\n" " char str[10];\n" @@ -3478,8 +3344,7 @@ private: } - void varid2() - { + void varid2() { checkstd("void foo()\n" "{\n" " char str[10];\n" @@ -3492,8 +3357,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varid3() // #4764 - { + void varid3() { // #4764 check("struct foo {\n" " void bar() { return; }\n" " type<> member[1];\n" @@ -3501,8 +3365,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign1() - { + void assign1() { check("char str[3] = {'a', 'b', 'c'};\n" "\n" "void foo()\n" @@ -3512,8 +3375,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Array 'str[3]' accessed at index 3, which is out of bounds.\n", errout.str()); } - void alloc1() - { + void alloc1() { check("void foo()\n" "{\n" " char *s; s = new char[10];\n" @@ -3580,8 +3442,7 @@ private: } // data is allocated with malloc - void alloc2() - { + void alloc2() { check("void foo()\n" "{\n" " char *s; s = malloc(10);\n" @@ -3606,8 +3467,7 @@ private: } // statically allocated buffer - void alloc3() - { + void alloc3() { check("void foo()\n" "{\n" " const char *s = \"123\";\n" @@ -3631,8 +3491,7 @@ private: } // data is allocated with alloca - void alloc4() - { + void alloc4() { check("void foo()\n" "{\n" " char *s = alloca(10);\n" @@ -3641,8 +3500,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[10]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void malloc_memset() - { + void malloc_memset() { checkstd("void f() {\n" " char *p = malloc(10);\n" " memset(p,0,100);\n" @@ -3650,8 +3508,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Buffer is accessed out of bounds.\n", errout.str()); } - void memset1() - { + void memset1() { checkstd("void foo()\n" "{\n" " char s[10];\n" @@ -3667,8 +3524,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void memset2() - { + void memset2() { check("class X {\n" " char* array[2];\n" " X();\n" @@ -3679,8 +3535,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void counter_test() const - { + void counter_test() const { std::list unknownParameter; unknownParameter.push_back(0); @@ -3758,8 +3613,7 @@ private: } - void strncpy1() - { + void strncpy1() { checkstd("void f() {\n" " char c[7];\n" " strncpy(c, \"hello\", 7);\n" @@ -3791,8 +3645,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void unknownType() - { + void unknownType() { check("void f()\n" "{\n" " UnknownType *a = malloc(4);\n" @@ -3800,8 +3653,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void terminateStrncpy1() - { + void terminateStrncpy1() { check("void foo ( char *bar ) {\n" " char baz[100];\n" " strncpy(baz, bar, 100);\n" @@ -3827,8 +3679,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str()); } - void terminateStrncpy2() - { + void terminateStrncpy2() { check("char *foo ( char *bar ) {\n" " char baz[100];\n" " strncpy(baz, bar, 100);\n" @@ -3838,8 +3689,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'baz' may not be null-terminated after the call to strncpy().\n", errout.str()); } - void terminateStrncpy3() - { + void terminateStrncpy3() { // Ticket #2170 - false positive // The function bar is risky. But it might work that way intentionally. check("char str[100];\n" @@ -3854,8 +3704,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) The buffer 'str' may not be null-terminated after the call to strncpy().\n", errout.str()); } - void recursive_long_time() - { + void recursive_long_time() { // Just test that recursive check doesn't take long time check("char *f2 ( char *b )\n" "{\n" @@ -3885,8 +3734,7 @@ private: // Ticket #1587 - crash - void crash1() - { + void crash1() { check("struct struct A\n" "{\n" " int alloclen;\n" @@ -3900,8 +3748,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void crash2() - { + void crash2() { check("void a(char *p) {\n" " f( { if(finally_arg); } );\n" "}\n" @@ -3912,14 +3759,12 @@ private: "}"); } - void crash3() - { + void crash3() { check("struct b { unknown v[0]; };\n" "void d() { struct b *f; f = malloc(108); }"); } - void epcheck(const char code[], const char filename[] = "test.cpp") - { + void epcheck(const char code[], const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -3937,8 +3782,7 @@ private: } - void executionPaths1() - { + void executionPaths1() { epcheck("void f(int a)\n" "{\n" " int buf[10];\n" @@ -3960,8 +3804,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Array 'buf[10][5]' index buf[1000][0] out of bounds.\n", errout.str()); } - void executionPaths2() - { + void executionPaths2() { epcheck("void foo()\n" "{\n" " char a[64];\n" @@ -3972,8 +3815,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void executionPaths3() - { + void executionPaths3() { epcheck("void f(char *VLtext)\n" "{\n" " if ( x ) {\n" @@ -3986,8 +3828,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void executionPaths4() - { + void executionPaths4() { // Ticket #2386 - Segmentation fault upon strange syntax ASSERT_THROW(epcheck("void f() {\n" " switch ( x ) {\n" @@ -3996,8 +3837,7 @@ private: "}"), InternalError); } - void executionPaths5() - { + void executionPaths5() { // No false positive epcheck("class A {\n" " void foo() {\n" @@ -4010,8 +3850,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void executionPaths6() // handling unknown type - { + void executionPaths6() { // handling unknown type const char code[] = "void f() {\n" " u32 a[10];" " u32 i = 0;\n" @@ -4022,8 +3861,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Array 'a[10]' accessed at index 1000, which is out of bounds.\n", errout.str()); } - void cmdLineArgs1() - { + void cmdLineArgs1() { check("int main(int argc, char* argv[])\n" "{\n" " char prog[10];\n" @@ -4141,8 +3979,7 @@ private: "[test.cpp:4]: (error) Buffer overrun possible for long command line arguments.\n", errout.str()); } - void scope() - { + void scope() { check("class A {\n" "private:\n" " struct X { char buf[10]; };\n" @@ -4168,15 +4005,13 @@ private: ASSERT_EQUALS("[test.cpp:9]: (error) Array 'x.buf[10]' accessed at index 10, which is out of bounds.\n", errout.str()); } - void getErrorMessages() - { + void getErrorMessages() { // Ticket #2292: segmentation fault when using --errorlist CheckBufferOverrun c; c.getErrorMessages(this, 0); } - void unknownMacroNoDecl() - { + void unknownMacroNoDecl() { check("void f() {\n" " int a[10];\n" " AAA a[0] = 0;\n" // <- not a valid array declaration @@ -4185,8 +4020,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void arrayIndexThenCheck() - { + void arrayIndexThenCheck() { check("void f(const char s[]) {\n" " if (s[i] == 'x' && i < y) {\n" " }" @@ -4231,8 +4065,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Array index 'i' is used before limits check.\n", "", errout.str()); } - void bufferNotZeroTerminated() - { + void bufferNotZeroTerminated() { check("void f() {\n" " char c[6];\n" " strncpy(c,\"hello!\",6);\n" @@ -4252,8 +4085,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning, inconclusive) The buffer 'c' is not null-terminated after the call to memmove().\n", errout.str()); } - void readlink() - { + void readlink() { check("void f() {\n" " char buf[255];\n" " ssize_t len = readlink(path, buf, 254);\n" @@ -4308,8 +4140,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void readlinkat() - { + void readlinkat() { check("void f() {\n" " char buf[255];\n" " ssize_t len = readlinkat(42, path, buf, 254);\n" @@ -4349,8 +4180,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void writeOutsideBufferSize() - { + void writeOutsideBufferSize() { check("void f(void){\n" "write(1, \"Dump string \\n\", 100);\n" "}"); // ^ number of bytes too big @@ -4399,8 +4229,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Writing 1 bytes outside buffer size.\n", "", errout.str()); } - void negativeMemoryAllocationSizeError() // #389 - { + void negativeMemoryAllocationSizeError() { // #389 check("void f()\n" "{\n" " int *a;\n" diff --git a/test/testcharvar.cpp b/test/testcharvar.cpp index 9ed5ba255..4e983ddd3 100644 --- a/test/testcharvar.cpp +++ b/test/testcharvar.cpp @@ -26,15 +26,13 @@ extern std::ostringstream errout; class TestCharVar : public TestFixture { public: - TestCharVar() : TestFixture("TestCharVar") - { + TestCharVar() : TestFixture("TestCharVar") { } private: - void run() - { + void run() { TEST_CASE(array_index_1); TEST_CASE(array_index_2); TEST_CASE(array_index_3); @@ -48,8 +46,7 @@ private: TEST_CASE(pointer); } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -66,8 +63,7 @@ private: checkOther.checkCharVariable(); } - void array_index_1() - { + void array_index_1() { check("int buf[256];\n" "void foo()\n" "{\n" @@ -106,8 +102,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_2() - { + void array_index_2() { // #3282 - False positive check("void foo(char i);\n" "void bar(int i) {\n" @@ -117,8 +112,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void array_index_3() - { + void array_index_3() { // only write error message when array is more than // 0x80 elements in size. Otherwise the full valid // range is accessible with a char. @@ -141,8 +135,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void bitop1() - { + void bitop1() { check("void foo()\n" "{\n" " int result = 0;\n" @@ -152,8 +145,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); } - void bitop2() - { + void bitop2() { check("void foo()\n" "{\n" " char ch;\n" @@ -162,16 +154,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void bitop3() - { + void bitop3() { check("void f(int& i, char& c) {\n" " i &= c;\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) When using 'char' variables in bit operations, sign extension can generate unexpected results.\n", errout.str()); } - void bitop4() - { + void bitop4() { check("long f(char c) {\n" " long a;\n" " a = (long)&c;\n" @@ -180,8 +170,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void return1() - { + void return1() { check("void foo()\n" "{\n" " char c;\n" @@ -191,8 +180,7 @@ private: } - void assignChar() - { + void assignChar() { check("void foo()\n" "{\n" " char c;\n" @@ -201,8 +189,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void and03() - { + void and03() { check("void foo()\n" "{\n" " char c;\n" @@ -211,8 +198,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void pointer() - { + void pointer() { // ticket #2866 check("void f(char *p) {\n" " int ret = 0;\n" diff --git a/test/testclass.cpp b/test/testclass.cpp index ab0c780c5..a38cbd4c8 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -27,14 +27,12 @@ extern std::ostringstream errout; class TestClass : public TestFixture { public: - TestClass() : TestFixture("TestClass") - { + TestClass() : TestFixture("TestClass") { } private: - void run() - { + void run() { TEST_CASE(virtualDestructor1); // Base class not found => no error TEST_CASE(virtualDestructor2); // Base class doesn't have a destructor TEST_CASE(virtualDestructor3); // Base class has a destructor, but it's not virtual @@ -182,8 +180,7 @@ private: TEST_CASE(duplInheritedMembers); } - void checkDuplInheritedMembers(const char code[]) - { + void checkDuplInheritedMembers(const char code[]) { // Clear the error log errout.str(""); Settings settings; @@ -200,8 +197,7 @@ private: checkClass.checkDuplInheritedMembers(); } - void duplInheritedMembers() - { + void duplInheritedMembers() { checkDuplInheritedMembers("class Base {\n" " int x;\n" "};\n" @@ -296,8 +292,7 @@ private: } - void checkCopyConstructor(const char code[]) - { + void checkCopyConstructor(const char code[]) { // Clear the error log errout.str(""); Settings settings; @@ -314,8 +309,7 @@ private: checkClass.copyconstructors(); } - void copyConstructor1() - { + void copyConstructor1() { checkCopyConstructor("class F\n" "{\n" " public:\n" @@ -517,8 +511,7 @@ private: } - void copyConstructor2() // ticket #4458 - { + void copyConstructor2() { // ticket #4458 checkCopyConstructor("template \n" "class Vector\n" "{\n" @@ -535,8 +528,7 @@ private: // Check the operator Equal - void checkOpertorEq(const char code[]) - { + void checkOpertorEq(const char code[]) { // Clear the error log errout.str(""); @@ -555,8 +547,7 @@ private: checkClass.operatorEq(); } - void operatorEq1() - { + void operatorEq1() { checkOpertorEq("class A\n" "{\n" "public:\n" @@ -607,8 +598,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); } - void operatorEq2() - { + void operatorEq2() { checkOpertorEq("class A\n" "{\n" "public:\n" @@ -638,8 +628,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) 'A::operator=' should return 'A &'.\n", errout.str()); } - void operatorEq3() // ticket #3051 - { + void operatorEq3() { // ticket #3051 checkOpertorEq("class A\n" "{\n" "public:\n" @@ -648,8 +637,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEq4() // ticket #3114 (infinite loop) - { + void operatorEq4() { // ticket #3114 (infinite loop) checkOpertorEq("struct A {\n" " A& operator=(A const& a) { return operator=(&a); }\n" " A& operator=(const A*) { return *this; }\n" @@ -657,8 +645,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEq5() // ticket #3296 (virtual operator) - { + void operatorEq5() { // ticket #3296 (virtual operator) checkOpertorEq( "class A {\n" " virtual A& operator=(const A &a) {return *this};\n" @@ -667,8 +654,7 @@ private: } // Check that operator Equal returns reference to this - void checkOpertorEqRetRefThis(const char code[]) - { + void checkOpertorEqRetRefThis(const char code[]) { // Clear the error log errout.str(""); @@ -686,8 +672,7 @@ private: checkClass.operatorEqRetRefThis(); } - void operatorEqRetRefThis1() - { + void operatorEqRetRefThis1() { checkOpertorEqRetRefThis( "class A\n" "{\n" @@ -791,8 +776,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); } - void operatorEqRetRefThis2() - { + void operatorEqRetRefThis2() { // ticket # 1323 checkOpertorEqRetRefThis( "class szp\n" @@ -810,8 +794,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); } - void operatorEqRetRefThis3() - { + void operatorEqRetRefThis3() { // ticket # 1405 checkOpertorEqRetRefThis( "class A {\n" @@ -860,8 +843,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEqRetRefThis4() - { + void operatorEqRetRefThis4() { // ticket # 1451 checkOpertorEqRetRefThis( "P& P::operator = (const P& pc)\n" @@ -871,8 +853,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEqRetRefThis5() - { + void operatorEqRetRefThis5() { // ticket # 1550 checkOpertorEqRetRefThis( "class A {\n" @@ -890,8 +871,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style) 'operator=' should return reference to 'this' instance.\n", errout.str()); } - void operatorEqRetRefThis6() // ticket #2478 (segmentation fault) - { + void operatorEqRetRefThis6() { // ticket #2478 (segmentation fault) checkOpertorEqRetRefThis( "class UString {\n" "public:\n" @@ -907,8 +887,7 @@ private: "}"); } - void operatorEqRetRefThis7() // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis() - { + void operatorEqRetRefThis7() { // ticket #5782 Endless recursion in CheckClass::checkReturnPtrThis() checkOpertorEqRetRefThis( "class basic_fbstring {\n" " basic_fbstring& operator=(int il) {\n" @@ -928,8 +907,7 @@ private: } // Check that operator Equal checks for assignment to self - void checkOpertorEqToSelf(const char code[]) - { + void checkOpertorEqToSelf(const char code[]) { // Clear the error log errout.str(""); @@ -947,8 +925,7 @@ private: checkClass.operatorEqToSelf(); } - void operatorEqToSelf1() - { + void operatorEqToSelf1() { // this test has an assignment test but it is not needed checkOpertorEqToSelf( "class A\n" @@ -1075,8 +1052,7 @@ private: } - void operatorEqToSelf2() - { + void operatorEqToSelf2() { // this test has an assignment test but doesn't need it checkOpertorEqToSelf( "class A\n" @@ -1214,8 +1190,7 @@ private: ASSERT_EQUALS("[test.cpp:11]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); } - void operatorEqToSelf3() - { + void operatorEqToSelf3() { // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it checkOpertorEqToSelf( "class A : public B, public C\n" @@ -1267,8 +1242,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEqToSelf4() - { + void operatorEqToSelf4() { // this test has multiple inheritance so there is no trivial way to test for self assignment but doesn't need it checkOpertorEqToSelf( "class A\n" @@ -1336,8 +1310,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEqToSelf5() - { + void operatorEqToSelf5() { // ticket # 1233 checkOpertorEqToSelf( "class A\n" @@ -1632,8 +1605,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEqToSelf6() - { + void operatorEqToSelf6() { // ticket # 1550 checkOpertorEqToSelf( "class A\n" @@ -1702,8 +1674,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (warning) 'operator=' should check for assignment to self to avoid problems with dynamic memory.\n", errout.str()); } - void operatorEqToSelf7() - { + void operatorEqToSelf7() { checkOpertorEqToSelf( "class A\n" "{\n" @@ -1720,8 +1691,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEqToSelf8() - { + void operatorEqToSelf8() { checkOpertorEqToSelf( "class FMat\n" "{\n" @@ -1740,8 +1710,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEqToSelf9() - { + void operatorEqToSelf9() { checkOpertorEqToSelf( "class Foo\n" "{\n" @@ -1761,8 +1730,7 @@ private: } // Check that base classes have virtual destructors - void checkVirtualDestructor(const char code[], bool inconclusive = false) - { + void checkVirtualDestructor(const char code[], bool inconclusive = false) { // Clear the error log errout.str(""); @@ -1780,8 +1748,7 @@ private: checkClass.virtualDestructor(); } - void virtualDestructor1() - { + void virtualDestructor1() { // Base class not found checkVirtualDestructor("class Derived : public Base { };\n" @@ -1795,8 +1762,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void virtualDestructor2() - { + void virtualDestructor2() { // Base class doesn't have a destructor checkVirtualDestructor("class Base { };\n" @@ -1824,8 +1790,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void virtualDestructor3() - { + void virtualDestructor3() { // Base class has a destructor, but it's not virtual checkVirtualDestructor("class Base { public: ~Base(); };\n" @@ -1847,8 +1812,7 @@ private: ASSERT_EQUALS("[test.cpp:1]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); } - void virtualDestructor4() - { + void virtualDestructor4() { // Derived class doesn't have a destructor => no error checkVirtualDestructor("class Base { public: ~Base(); };\n" @@ -1864,8 +1828,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void virtualDestructor5() - { + void virtualDestructor5() { // Derived class has empty destructor => no error checkVirtualDestructor("class Base { public: ~Base(); };\n" @@ -1881,8 +1844,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void virtualDestructor6() - { + void virtualDestructor6() { // Only report error if base class pointer is deleted that // points at derived class @@ -1891,8 +1853,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void virtualDestructorProtected() - { + void virtualDestructorProtected() { // Base class has protected destructor, it makes Base *p = new Derived(); fail // during compilation time, so error is not possible. => no error checkVirtualDestructor("class A\n" @@ -1909,8 +1870,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void virtualDestructorInherited() - { + void virtualDestructorInherited() { // class A inherits virtual destructor from class Base -> no error checkVirtualDestructor("class Base\n" "{\n" @@ -2004,8 +1964,7 @@ private: "", errout.str()); } - void virtualDestructorTemplate() - { + void virtualDestructorTemplate() { checkVirtualDestructor("template class A\n" "{\n" " public:\n" @@ -2026,8 +1985,7 @@ private: ASSERT_EQUALS("[test.cpp:9]: (error) Class 'AA' which is inherited by class 'B' does not have a virtual destructor.\n", errout.str()); } - void virtualDestructorInconclusive() - { + void virtualDestructorInconclusive() { checkVirtualDestructor("class Base {\n" "public:\n" " ~Base(){}\n" @@ -2051,8 +2009,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str()); } - void checkNoMemset(const char code[], bool load_std_cfg = false, bool portability = false) - { + void checkNoMemset(const char code[], bool load_std_cfg = false, bool portability = false) { // Clear the error log errout.str(""); @@ -2074,8 +2031,7 @@ private: checkClass.checkMemset(); } - void memsetOnClass() - { + void memsetOnClass() { checkNoMemset("class Fred\n" "{\n" "};\n" @@ -2290,8 +2246,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Using 'memset' on class that contains a reference.\n", errout.str()); } - void memsetOnInvalid() // Ticket #5425 - { + void memsetOnInvalid() { // Ticket #5425 checkNoMemset("union ASFStreamHeader {\n" " struct AVMPACKED {\n" " union {\n" @@ -2307,8 +2262,7 @@ private: "}"); } - void memsetOnStruct() - { + void memsetOnStruct() { checkNoMemset("struct A\n" "{\n" "};\n" @@ -2384,8 +2338,7 @@ private: ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str()); } - void memsetVector() - { + void memsetVector() { checkNoMemset("class A\n" "{ std::vector ints; };\n" "\n" @@ -2507,8 +2460,7 @@ private: ASSERT_EQUALS("", errout.str()); // std::array is POD (#5481) } - void memsetOnStdPodType() // Ticket #5901 - { + void memsetOnStdPodType() { // Ticket #5901 checkNoMemset("struct st {\n" " std::uint8_t a;\n" " std::uint8_t b;\n" @@ -2522,8 +2474,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void memsetOnFloat() - { + void memsetOnFloat() { checkNoMemset("struct A {\n" " float f;\n" "};\n" @@ -2570,8 +2521,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mallocOnClass() - { + void mallocOnClass() { checkNoMemset("class C { C() {} };\n" "void foo(C*& p) {\n" " p = malloc(sizeof(C));\n" @@ -2622,8 +2572,7 @@ private: } - void checkThisSubtraction(const char code[]) - { + void checkThisSubtraction(const char code[]) { // Clear the error log errout.str(""); @@ -2641,8 +2590,7 @@ private: checkClass.thisSubtraction(); } - void this_subtraction() - { + void this_subtraction() { checkThisSubtraction("; this-x ;"); ASSERT_EQUALS("[test.cpp:1]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str()); @@ -2660,8 +2608,7 @@ private: "[test.cpp:3]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?\n", errout.str()); } - void checkConst(const char code[], const Settings *s = 0, bool inconclusive = true, bool verify = true) - { + void checkConst(const char code[], const Settings *s = 0, bool inconclusive = true, bool verify = true) { // Clear the error log errout.str(""); @@ -2688,8 +2635,7 @@ private: checkClass.checkConst(); } - void const1() - { + void const1() { checkConst("class Fred {\n" " int a;\n" " int getA() { return a; }\n" @@ -2761,8 +2707,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Fred::foo' can be static.\n", errout.str()); } - void const2() - { + void const2() { // ticket 1344 // assignment to variable can't be const checkConst("class Fred {\n" @@ -2814,8 +2759,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const3() - { + void const3() { // assignment to function argument pointer can be const checkConst("class Fred {\n" " int s;\n" @@ -2859,8 +2803,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const4() - { + void const4() { checkConst("class Fred {\n" " int a;\n" " int getA();\n" @@ -3121,8 +3064,7 @@ private: } // operator< can often be const - void constoperator1() - { + void constoperator1() { checkConst("struct Fred {\n" " int a;\n" " bool operator<(const Fred &f) { return a < f.a; }\n" @@ -3131,8 +3073,7 @@ private: } // operator<< - void constoperator2() - { + void constoperator2() { checkConst("struct Foo {\n" " void operator<<(int);\n" "};\n" @@ -3158,8 +3099,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'Fred::x' can be const.\n", errout.str()); } - void constoperator3() - { + void constoperator3() { checkConst("struct Fred {\n" " int array[10];\n" " int const & operator [] (unsigned int index) const { return array[index]; }\n" @@ -3174,8 +3114,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'Fred::operator[]' can be const.\n", errout.str()); } - void constoperator4() - { + void constoperator4() { checkConst("struct Fred {\n" " int array[10];\n" " typedef int* (Fred::*UnspecifiedBoolType);\n" @@ -3191,8 +3130,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void constoperator5() // ticket #3252 - { + void constoperator5() { // ticket #3252 checkConst("class A {\n" " int c;\n" "public:\n" @@ -3216,8 +3154,7 @@ private: } - void const5() - { + void const5() { // ticket #1482 checkConst("class A {\n" " int a;\n" @@ -3231,8 +3168,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::foo' can be const.\n", errout.str()); } - void const6() - { + void const6() { // ticket #1491 checkConst("class foo {\n" "public:\n" @@ -3262,8 +3198,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const7() - { + void const7() { checkConst("class foo {\n" " int a;\n" "public:\n" @@ -3274,8 +3209,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const8() - { + void const8() { // ticket #1517 checkConst("class A {\n" "public:\n" @@ -3287,8 +3221,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetString' can be const.\n", errout.str()); } - void const9() - { + void const9() { // ticket #1515 checkConst("class wxThreadInternal {\n" "public:\n" @@ -3299,8 +3232,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const10() - { + void const10() { // ticket #1522 checkConst("class A {\n" "public:\n" @@ -3327,8 +3259,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const11() - { + void const11() { // ticket #1529 checkConst("class A {\n" "public:\n" @@ -3339,8 +3270,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const12() - { + void const12() { // ticket #1525 checkConst("class A {\n" "public:\n" @@ -3351,8 +3281,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::foo' can be const.\n", errout.str()); } - void const13() - { + void const13() { // ticket #1519 checkConst("class A {\n" "public:\n" @@ -3379,8 +3308,7 @@ private: "[test.cpp:5]: (style, inconclusive) Technically the member function 'A::GetPair' can be const.\n", errout.str()); } - void const14() - { + void const14() { // extends ticket 1519 checkConst("class A {\n" "public:\n" @@ -3632,8 +3560,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::foo' can be const.\n", errout.str()); } - void const15() - { + void const15() { checkConst("class Fred {\n" " unsigned long long int a;\n" " unsigned long long int getA() { return a; }\n" @@ -3665,8 +3592,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const16() - { + void const16() { // ticket #1551 checkConst("class Fred {\n" " int a;\n" @@ -3675,8 +3601,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const17() - { + void const17() { // ticket #1552 checkConst("class Fred {\n" "public:\n" @@ -3687,8 +3612,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const18() - { + void const18() { checkConst("class Fred {\n" "static int x;\n" "public:\n" @@ -3697,8 +3621,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (performance, inconclusive) Technically the member function 'Fred::set' can be static.\n", errout.str()); } - void const19() - { + void const19() { // ticket #1612 checkConst("using namespace std;\n" "class Fred {\n" @@ -3710,8 +3633,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const20() - { + void const20() { // ticket #1602 checkConst("class Fred {\n" " int x : 3;\n" @@ -3749,8 +3671,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'Fred::get' can be const.\n", errout.str()); } - void const21() - { + void const21() { // ticket #1683 checkConst("class A\n" "{\n" @@ -3766,8 +3687,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const22() - { + void const22() { checkConst("class A\n" "{\n" "private:\n" @@ -3787,8 +3707,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const23() - { + void const23() { checkConst("class Class {\n" "public:\n" " typedef Template Type;\n" @@ -3800,8 +3719,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const24() - { + void const24() { checkConst("class Class {\n" "public:\n" "void Settings::SetSetting(QString strSetting, QString strNewVal)\n" @@ -3815,8 +3733,7 @@ private: } - void const25() // ticket #1724 - { + void const25() { // ticket #1724 checkConst("class A{\n" "public:\n" "A(){m_strVal=\"\";}\n" @@ -3875,8 +3792,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style, inconclusive) Technically the member function 'A::strGetEmpty' can be const.\n", errout.str()); } - void const26() // ticket #1847 - { + void const26() { // ticket #1847 checkConst("class DelayBase {\n" "public:\n" "void swapSpecificDelays(int index1, int index2) {\n" @@ -3896,8 +3812,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style, inconclusive) Technically the member function 'DelayBase::swapSpecificDelays' can be const.\n", errout.str()); } - void const27() // ticket #1882 - { + void const27() { // ticket #1882 checkConst("class A {\n" "public:\n" " A(){m_d=1.0; m_iRealVal=2.0;}\n" @@ -3916,8 +3831,7 @@ private: ASSERT_EQUALS("[test.cpp:9] -> [test.cpp:4]: (style, inconclusive) Technically the member function 'A::dGetValue' can be const.\n", errout.str()); } - void const28() // ticket #1883 - { + void const28() { // ticket #1883 checkConst("class P {\n" "public:\n" " P() { x=0.0; y=0.0; }\n" @@ -3956,8 +3870,7 @@ private: } - void const29() // ticket #1922 - { + void const29() { // ticket #1922 checkConst("class test {\n" " public:\n" " test();\n" @@ -3981,8 +3894,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const30() - { + void const30() { // check for false negatives checkConst("class Base {\n" "public:\n" @@ -4105,8 +4017,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const31() - { + void const31() { checkConst("namespace std { }\n" "class Fred {\n" "public:\n" @@ -4116,8 +4027,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style, inconclusive) Technically the member function 'Fred::get' can be const.\n", errout.str()); } - void const32() - { + void const32() { checkConst("class Fred {\n" "public:\n" " std::string a[10];\n" @@ -4126,8 +4036,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const33() - { + void const33() { checkConst("class derived : public base {\n" "public:\n" " void f(){}\n" @@ -4135,8 +4044,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const34() // ticket #1964 - { + void const34() { // ticket #1964 checkConst("class Bar {\n" " void init(Foo * foo) {\n" " foo.bar = this;\n" @@ -4145,8 +4053,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const35() // ticket #2001 - { + void const35() { // ticket #2001 checkConst("namespace N\n" "{\n" " class Base\n" @@ -4205,8 +4112,7 @@ private: ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:6]: (style, inconclusive) Technically the member function 'N::Base::getResourceName' can be const.\n", errout.str()); } - void const36() // ticket #2003 - { + void const36() { // ticket #2003 checkConst("class Foo {\n" "public:\n" " Blue::Utility::Size m_MaxQueueSize;\n" @@ -4218,8 +4124,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const37() // ticket #2081 and #2085 - { + void const37() { // ticket #2081 and #2085 checkConst("class A\n" "{\n" "public:\n" @@ -4248,8 +4153,7 @@ private: ASSERT_EQUALS("[test.cpp:9]: (style, inconclusive) Technically the member function 'Fred::isValid' can be const.\n", errout.str()); } - void const38() // ticket #2135 - { + void const38() { // ticket #2135 checkConst("class Foo {\n" "public:\n" " ~Foo() { delete oArq; }\n" @@ -4265,8 +4169,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const39() - { + void const39() { checkConst("class Foo\n" "{\n" " int * p;\n" @@ -4287,8 +4190,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const40() // ticket #2228 - { + void const40() { // ticket #2228 checkConst("class SharedPtrHolder\n" "{\n" " private:\n" @@ -4305,8 +4207,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const41() // ticket #2255 - { + void const41() { // ticket #2255 checkConst("class Fred\n" "{\n" " ::std::string m_name;\n" @@ -4382,8 +4283,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const42() // ticket #2282 - { + void const42() { // ticket #2282 checkConst("class Fred\n" "{\n" "public:\n" @@ -4459,8 +4359,7 @@ private: ASSERT_EQUALS("[test.cpp:11] -> [test.cpp:8]: (performance, inconclusive) Technically the member function 'Foo::Fred::f' can be static.\n", errout.str()); } - void const43() // ticket 2377 - { + void const43() { // ticket 2377 checkConst("class A\n" "{\n" "public:\n" @@ -4518,8 +4417,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const44() // ticket 2595 - { + void const44() { // ticket 2595 checkConst("class A\n" "{\n" "public:\n" @@ -4533,8 +4431,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const45() // ticket 2664 - { + void const45() { // ticket 2664 checkConst("namespace wraps {\n" " class BaseLayout {};\n" "}\n" @@ -4551,8 +4448,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (performance, inconclusive) Technically the member function 'tools::WorkspaceControl::toGrid' can be static.\n", errout.str()); } - void const46() // ticket 2663 - { + void const46() { // ticket 2663 checkConst("class Altren {\n" "public:\n" " int fun1() {\n" @@ -4568,8 +4464,7 @@ private: "[test.cpp:7]: (performance, inconclusive) Technically the member function 'Altren::fun2' can be static.\n", errout.str()); } - void const47() // ticket 2670 - { + void const47() { // ticket 2670 checkConst("class Altren {\n" "public:\n" " void foo() { delete this; }\n" @@ -4590,8 +4485,7 @@ private: "[test.cpp:5]: (style, inconclusive) Technically the member function 'Altren::bar' can be const.\n", errout.str()); } - void const48() // ticket 2672 - { + void const48() { // ticket 2672 checkConst("class S0 {\n" " class S1 {\n" " class S2 {\n" @@ -4613,8 +4507,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const49() // ticket 2795 - { + void const49() { // ticket 2795 checkConst("class A {\n" " private:\n" " std::map _hash;\n" @@ -4628,8 +4521,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const50() // ticket 2943 - { + void const50() { // ticket 2943 checkConst("class Altren\n" "{\n" " class SubClass : public std::vector\n" @@ -4645,8 +4537,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const51() // ticket 3040 - { + void const51() { // ticket 3040 checkConst("class PSIPTable {\n" "public:\n" " PSIPTable() : _pesdata(0) { }\n" @@ -4674,8 +4565,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const52() // ticket 3048 - { + void const52() { // ticket 3048 checkConst("class foo {\n" " void DoSomething(int &a) const { a = 1; }\n" " void DoSomethingElse() { DoSomething(bar); }\n" @@ -4685,8 +4575,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'foo::DoSomething' can be static.\n", errout.str()); } - void const53() // ticket 3049 - { + void const53() { // ticket 3049 checkConst("class A {\n" " public:\n" " A() : foo(false) {};\n" @@ -4702,8 +4591,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const54() // ticket 3052 - { + void const54() { // ticket 3052 checkConst("class Example {\n" " public:\n" " void Clear(void) { Example tmp; (*this) = tmp; }\n" @@ -4711,8 +4599,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const55() - { + void const55() { checkConst("class MyObject {\n" " int tmp;\n" " MyObject() : tmp(0) {}\n" @@ -4722,8 +4609,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const56() // ticket #3149 - { + void const56() { // ticket #3149 checkConst("class MyObject {\n" "public:\n" " void foo(int x) {\n" @@ -4781,8 +4667,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'MyObject::foo' can be static.\n", errout.str()); } - void const57() // tickets #2669 and #2477 - { + void const57() { // tickets #2669 and #2477 checkConst("namespace MyGUI\n" "{\n" " namespace types\n" @@ -4840,8 +4725,7 @@ private: "[test.cpp:6]: (style, inconclusive) Technically the member function 'Foo::foo' can be const.\n", errout.str()); } - void const58() - { + void const58() { checkConst("struct MyObject {\n" " void foo(Foo f) {\n" " f.clear();\n" @@ -4873,8 +4757,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'MyObject::foo' can be const.\n", errout.str()); } - void const59() // ticket #4646 - { + void const59() { // ticket #4646 checkConst("class C {\n" "public:\n" " inline void operator += (const int &x ) { re += x; }\n" @@ -4886,8 +4769,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const60() // ticket #3322 - { + void const60() { // ticket #3322 checkConst("class MyString {\n" "public:\n" " MyString() : m_ptr(0){}\n" @@ -4911,8 +4793,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const61() // ticket #5606 - don't crash - { + void const61() { // ticket #5606 - don't crash checkConst("class MixerParticipant : public MixerParticipant {\n" " int GetAudioFrame();\n" "};\n" @@ -4948,8 +4829,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const62() - { + void const62() { checkConst("class A {\n" " private:\n" " std::unordered_map _hash;\n" @@ -4963,8 +4843,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void const63() - { + void const63() { checkConst("struct A {\n" " std::string s;\n" " void clear() {\n" @@ -5011,8 +4890,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style, inconclusive) Technically the member function 'A::clear' can be const.\n", errout.str()); } - void const_handleDefaultParameters() - { + void const_handleDefaultParameters() { checkConst("struct Foo {\n" " void foo1(int i, int j = 0) {\n" " return func(this);\n" @@ -5046,8 +4924,7 @@ private: "[test.cpp:14]: (performance, inconclusive) Technically the member function 'Foo::bar4' can be static.\n", errout.str()); } - void const_passThisToMemberOfOtherClass() - { + void const_passThisToMemberOfOtherClass() { checkConst("struct Foo {\n" " void foo() {\n" " Bar b;\n" @@ -5065,8 +4942,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (performance, inconclusive) Technically the member function 'Foo::foo' can be static.\n", errout.str()); } - void assigningPointerToPointerIsNotAConstOperation() - { + void assigningPointerToPointerIsNotAConstOperation() { checkConst("struct s\n" "{\n" " int** v;\n" @@ -5079,8 +4955,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assigningArrayElementIsNotAConstOperation() - { + void assigningArrayElementIsNotAConstOperation() { checkConst("struct s\n" "{\n" " ::std::string v[3];\n" @@ -5094,8 +4969,7 @@ private: } // increment/decrement => not const - void constincdec() - { + void constincdec() { checkConst("class Fred {\n" " int a;\n" " void nextA() { return ++a; }\n" @@ -5145,8 +5019,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static.\n", errout.str()); } - void constassign1() - { + void constassign1() { checkConst("class Fred {\n" " int a;\n" " void nextA() { return a=1; }\n" @@ -5208,8 +5081,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static.\n", errout.str()); } - void constassign2() - { + void constassign2() { checkConst("class Fred {\n" " struct A { int a; } s;\n" " void nextA() { return s.a=1; }\n" @@ -5301,8 +5173,7 @@ private: } // increment/decrement array element => not const - void constincdecarray() - { + void constincdecarray() { checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return ++a[0]; }\n" @@ -5352,8 +5223,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (performance, inconclusive) Technically the member function 'Fred::nextA' can be static.\n", errout.str()); } - void constassignarray() - { + void constassignarray() { checkConst("class Fred {\n" " int a[2];\n" " void nextA() { return a[0]=1; }\n" @@ -5416,8 +5286,7 @@ private: } // return pointer/reference => not const - void constReturnReference() - { + void constReturnReference() { checkConst("class Fred {\n" " int a;\n" " int &getR() { return a; }\n" @@ -5427,8 +5296,7 @@ private: } // delete member variable => not const (but technically it can, it compiles without errors) - void constDelete() - { + void constDelete() { checkConst("class Fred {\n" " int *a;\n" " void clean() { delete a; }\n" @@ -5437,8 +5305,7 @@ private: } // A function that returns unknown types can't be const (#1579) - void constLPVOID() - { + void constLPVOID() { checkConst("class Fred {\n" " UNKNOWN a() { return 0; };\n" "};"); @@ -5453,8 +5320,7 @@ private: } // a function that calls const functions can be const - void constFunc() - { + void constFunc() { checkConst("class Fred {\n" " void f() const { };\n" " void a() { f(); };\n" @@ -5482,8 +5348,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (style, inconclusive) Technically the member function 'A::GetVecEmpty' can be const.\n", errout.str()); } - void constVirtualFunc() - { + void constVirtualFunc() { // base class has no virtual function checkConst("class A { };\n" "class B : public A {\n" @@ -5710,8 +5575,7 @@ private: "[test.cpp:21] -> [test.cpp:19]: (style, inconclusive) Technically the member function 'Z::getZ' can be const.\n", errout.str()); } - void constIfCfg() - { + void constIfCfg() { const char code[] = "struct foo {\n" " int i;\n" " void f() {\n" @@ -5731,8 +5595,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void constFriend() // ticket #1921 - { + void constFriend() { // ticket #1921 const char code[] = "class foo {\n" " friend void f() { }\n" "};"; @@ -5740,8 +5603,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void constUnion() // ticket #2111 - { + void constUnion() { // ticket #2111 checkConst("class foo {\n" "public:\n" " union {\n" @@ -5755,8 +5617,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void constArrayOperator() - { + void constArrayOperator() { checkConst("struct foo {\n" " int x;\n" " int y[5][724];\n" @@ -5773,8 +5634,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (style, inconclusive) Technically the member function 'foo::c' can be const.\n", errout.str()); } - void checkInitializerListOrder(const char code[]) - { + void checkInitializerListOrder(const char code[]) { // Clear the error log errout.str(""); @@ -5793,8 +5653,7 @@ private: checkClass.initializerListOrder(); } - void initializerListOrder() - { + void initializerListOrder() { checkInitializerListOrder("class Fred {\n" " int a, b, c;\n" "public:\n" @@ -5812,8 +5671,7 @@ private: "[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Member variable 'Fred::a' is in the wrong place in the initializer list.\n", errout.str()); } - void checkInitializationListUsage(const char code[]) - { + void checkInitializationListUsage(const char code[]) { // Clear the error log errout.str(""); @@ -5831,8 +5689,7 @@ private: checkClass.initializationListUsage(); } - void initializerListUsage() - { + void initializerListUsage() { checkInitializationListUsage("class Fred {\n" " int a;\n" // No message for builtin types: No performance gain " int* b;\n" // No message for pointers: No performance gain @@ -5959,8 +5816,7 @@ private: } - void checkSelfInitialization(const char code []) - { + void checkSelfInitialization(const char code []) { // Clear the error log errout.str(""); @@ -5977,8 +5833,7 @@ private: checkClass.checkSelfInitialization(); } - void selfInitialization() - { + void selfInitialization() { checkSelfInitialization("class Fred {\n" " int i;\n" " Fred() : i(i) {\n" @@ -6037,8 +5892,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkPureVirtualFunctionCall(const char code[], const Settings *s = 0, bool inconclusive = true) - { + void checkPureVirtualFunctionCall(const char code[], const Settings *s = 0, bool inconclusive = true) { // Clear the error log errout.str(""); @@ -6060,8 +5914,7 @@ private: checkClass.checkPureVirtualFunctionCall(); } - void pureVirtualFunctionCall() - { + void pureVirtualFunctionCall() { checkPureVirtualFunctionCall("class A\n" "{\n" " virtual void pure()=0;\n" @@ -6155,8 +6008,7 @@ private: } - void pureVirtualFunctionCallOtherClass() - { + void pureVirtualFunctionCallOtherClass() { checkPureVirtualFunctionCall("class A\n" "{\n" " virtual void pure()=0;\n" @@ -6180,8 +6032,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void pureVirtualFunctionCallWithBody() - { + void pureVirtualFunctionCallWithBody() { checkPureVirtualFunctionCall("class A\n" "{\n" " virtual void pureWithBody()=0;\n" @@ -6208,8 +6059,7 @@ private: } - void pureVirtualFunctionCallPrevented() - { + void pureVirtualFunctionCallPrevented() { checkPureVirtualFunctionCall("class A\n" " {\n" " virtual void pure()=0;\n" diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 190de972f..850658db1 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -26,16 +26,14 @@ class TestCmdlineParser : public TestFixture { public: TestCmdlineParser() : TestFixture("TestCmdlineParser") - , defParser(&settings) - { + , defParser(&settings) { } private: Settings settings; CmdLineParser defParser; - void run() - { + void run() { TEST_CASE(nooptions); TEST_CASE(helpshort); TEST_CASE(helplong); @@ -144,8 +142,7 @@ private: } - void nooptions() - { + void nooptions() { REDIRECT; const char *argv[] = {"cppcheck"}; CmdLineParser parser(&settings); @@ -153,8 +150,7 @@ private: ASSERT_EQUALS(true, parser.GetShowHelp()); } - void helpshort() - { + void helpshort() { REDIRECT; const char *argv[] = {"cppcheck", "-h"}; CmdLineParser parser(&settings); @@ -162,8 +158,7 @@ private: ASSERT_EQUALS(true, parser.GetShowHelp()); } - void helplong() - { + void helplong() { REDIRECT; const char *argv[] = {"cppcheck", "--help"}; CmdLineParser parser(&settings); @@ -171,8 +166,7 @@ private: ASSERT_EQUALS(true, parser.GetShowHelp()); } - void showversion() - { + void showversion() { REDIRECT; const char *argv[] = {"cppcheck", "--version"}; CmdLineParser parser(&settings); @@ -180,8 +174,7 @@ private: ASSERT_EQUALS(true, parser.GetShowVersion()); } - void onefile() - { + void onefile() { REDIRECT; const char *argv[] = {"cppcheck", "file.cpp"}; CmdLineParser parser(&settings); @@ -190,8 +183,7 @@ private: ASSERT_EQUALS("file.cpp", parser.GetPathNames().at(0)); } - void onepath() - { + void onepath() { REDIRECT; const char *argv[] = {"cppcheck", "src"}; CmdLineParser parser(&settings); @@ -200,8 +192,7 @@ private: ASSERT_EQUALS("src", parser.GetPathNames().at(0)); } - void optionwithoutfile() - { + void optionwithoutfile() { REDIRECT; const char *argv[] = {"cppcheck", "-v"}; CmdLineParser parser(&settings); @@ -209,8 +200,7 @@ private: ASSERT_EQUALS(0, (int)parser.GetPathNames().size()); } - void verboseshort() - { + void verboseshort() { REDIRECT; const char *argv[] = {"cppcheck", "-v", "file.cpp"}; settings._verbose = false; @@ -218,8 +208,7 @@ private: ASSERT_EQUALS(true, settings._verbose); } - void verboselong() - { + void verboselong() { REDIRECT; const char *argv[] = {"cppcheck", "--verbose", "file.cpp"}; settings._verbose = false; @@ -227,8 +216,7 @@ private: ASSERT_EQUALS(true, settings._verbose); } - void debug() - { + void debug() { REDIRECT; const char *argv[] = {"cppcheck", "--debug", "file.cpp"}; settings.debug = false; @@ -236,8 +224,7 @@ private: ASSERT_EQUALS(true, settings.debug); } - void debugwarnings() - { + void debugwarnings() { REDIRECT; const char *argv[] = {"cppcheck", "--debug-warnings", "file.cpp"}; settings.debugwarnings = false; @@ -245,8 +232,7 @@ private: ASSERT_EQUALS(true, settings.debugwarnings); } - void forceshort() - { + void forceshort() { REDIRECT; const char *argv[] = {"cppcheck", "-f", "file.cpp"}; settings._force = false; @@ -254,8 +240,7 @@ private: ASSERT_EQUALS(true, settings._force); } - void forcelong() - { + void forcelong() { REDIRECT; const char *argv[] = {"cppcheck", "--force", "file.cpp"}; settings._force = false; @@ -263,8 +248,7 @@ private: ASSERT_EQUALS(true, settings._force); } - void relativePaths() - { + void relativePaths() { REDIRECT; settings._relativePaths = false; @@ -299,8 +283,7 @@ private: ASSERT_EQUALS("C:/bar", settings._basePaths[1]); } - void quietshort() - { + void quietshort() { REDIRECT; const char *argv[] = {"cppcheck", "-q", "file.cpp"}; settings._errorsOnly = false; @@ -308,8 +291,7 @@ private: ASSERT_EQUALS(true, settings._errorsOnly); } - void quietlong() - { + void quietlong() { REDIRECT; const char *argv[] = {"cppcheck", "--quiet", "file.cpp"}; settings._errorsOnly = false; @@ -317,32 +299,28 @@ private: ASSERT_EQUALS(true, settings._errorsOnly); } - void defines_noarg() - { + void defines_noarg() { REDIRECT; const char *argv[] = {"cppcheck", "-D"}; // Fails since -D has no param ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv)); } - void defines_noarg2() - { + void defines_noarg2() { REDIRECT; const char *argv[] = {"cppcheck", "-D", "-v", "file.cpp"}; // Fails since -D has no param ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); } - void defines_noarg3() - { + void defines_noarg3() { REDIRECT; const char *argv[] = {"cppcheck", "-D", "--quiet", "file.cpp"}; // Fails since -D has no param ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); } - void defines() - { + void defines() { REDIRECT; const char *argv[] = {"cppcheck", "-D_WIN32", "file.cpp"}; settings.userDefines.clear(); @@ -350,8 +328,7 @@ private: ASSERT_EQUALS("_WIN32=1", settings.userDefines); } - void defines2() - { + void defines2() { REDIRECT; const char *argv[] = {"cppcheck", "-D_WIN32", "-DNODEBUG", "file.cpp"}; settings.userDefines.clear();; @@ -359,8 +336,7 @@ private: ASSERT_EQUALS("_WIN32=1;NODEBUG=1", settings.userDefines); } - void defines3() - { + void defines3() { REDIRECT; const char *argv[] = {"cppcheck", "-D", "DEBUG", "file.cpp"}; settings.userDefines.clear(); @@ -368,8 +344,7 @@ private: ASSERT_EQUALS("DEBUG=1", settings.userDefines); } - void defines4() - { + void defines4() { REDIRECT; const char *argv[] = {"cppcheck", "-DDEBUG=", "file.cpp"}; // #5137 - defining empty macro settings.userDefines.clear(); @@ -377,8 +352,7 @@ private: ASSERT_EQUALS("DEBUG=", settings.userDefines); } - void enforceLanguage() - { + void enforceLanguage() { REDIRECT; { const char *argv[] = {"cppcheck", "file.cpp"}; @@ -418,16 +392,14 @@ private: } } - void includesnopath() - { + void includesnopath() { REDIRECT; const char *argv[] = {"cppcheck", "-I"}; // Fails since -I has no param ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv)); } - void includes() - { + void includes() { REDIRECT; const char *argv[] = {"cppcheck", "-I", "include", "file.cpp"}; settings._includePaths.clear(); @@ -435,8 +407,7 @@ private: ASSERT_EQUALS("include/", settings._includePaths.front()); } - void includesslash() - { + void includesslash() { REDIRECT; const char *argv[] = {"cppcheck", "-I", "include/", "file.cpp"}; settings._includePaths.clear(); @@ -444,8 +415,7 @@ private: ASSERT_EQUALS("include/", settings._includePaths.front()); } - void includesbackslash() - { + void includesbackslash() { REDIRECT; const char *argv[] = {"cppcheck", "-I", "include\\", "file.cpp"}; settings._includePaths.clear(); @@ -453,8 +423,7 @@ private: ASSERT_EQUALS("include/", settings._includePaths.front()); } - void includesnospace() - { + void includesnospace() { REDIRECT; const char *argv[] = {"cppcheck", "-Iinclude", "file.cpp"}; settings._includePaths.clear(); @@ -462,8 +431,7 @@ private: ASSERT_EQUALS("include/", settings._includePaths.front()); } - void includes2() - { + void includes2() { REDIRECT; const char *argv[] = {"cppcheck", "-I", "include/", "-I", "framework/", "file.cpp"}; settings._includePaths.clear(); @@ -473,8 +441,7 @@ private: ASSERT_EQUALS("framework/", settings._includePaths.front()); } - void includesFile() - { + void includesFile() { // TODO: Fails since cannot open the file REDIRECT; const char *argv[] = {"cppcheck", "--includes-file=inclpaths.txt", "file.cpp"}; @@ -482,8 +449,7 @@ private: ASSERT_EQUALS(true, defParser.ParseFromArgs(3, argv)); } - void enabledAll() - { + void enabledAll() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=all", "file.cpp"}; settings = Settings(); @@ -495,8 +461,7 @@ private: ASSERT(!settings.isEnabled("internal")); } - void enabledStyle() - { + void enabledStyle() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=style", "file.cpp"}; settings = Settings(); @@ -509,8 +474,7 @@ private: ASSERT(!settings.isEnabled("missingInclude")); } - void enabledPerformance() - { + void enabledPerformance() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=performance", "file.cpp"}; settings = Settings(); @@ -523,8 +487,7 @@ private: ASSERT(!settings.isEnabled("missingInclude")); } - void enabledPortability() - { + void enabledPortability() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=portability", "file.cpp"}; settings = Settings(); @@ -537,8 +500,7 @@ private: ASSERT(!settings.isEnabled("missingInclude")); } - void enabledUnusedFunction() - { + void enabledUnusedFunction() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=unusedFunction", "file.cpp"}; settings = Settings(); @@ -546,8 +508,7 @@ private: ASSERT(settings.isEnabled("unusedFunction")); } - void enabledMissingInclude() - { + void enabledMissingInclude() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=missingInclude", "file.cpp"}; settings = Settings(); @@ -556,8 +517,7 @@ private: } #ifdef CHECK_INTERNAL - void enabledInternal() - { + void enabledInternal() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"}; settings = Settings(); @@ -566,8 +526,7 @@ private: } #endif - void enabledMultiple() - { + void enabledMultiple() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=missingInclude,portability,warning", "file.cpp"}; settings = Settings(); @@ -580,8 +539,7 @@ private: ASSERT(settings.isEnabled("missingInclude")); } - void inconclusive() - { + void inconclusive() { REDIRECT; const char *argv[] = {"cppcheck", "--inconclusive"}; settings.inconclusive = false; @@ -589,8 +547,7 @@ private: ASSERT_EQUALS(true, settings.inconclusive); } - void errorExitcode() - { + void errorExitcode() { REDIRECT; const char *argv[] = {"cppcheck", "--error-exitcode=5", "file.cpp"}; settings._exitCode = 0; @@ -598,8 +555,7 @@ private: ASSERT_EQUALS(5, settings._exitCode); } - void errorExitcodeMissing() - { + void errorExitcodeMissing() { REDIRECT; const char *argv[] = {"cppcheck", "--error-exitcode=", "file.cpp"}; settings._exitCode = 0; @@ -607,8 +563,7 @@ private: ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); } - void errorExitcodeStr() - { + void errorExitcodeStr() { REDIRECT; const char *argv[] = {"cppcheck", "--error-exitcode=foo", "file.cpp"}; settings._exitCode = 0; @@ -616,8 +571,7 @@ private: ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); } - void exitcodeSuppressionsOld() - { + void exitcodeSuppressionsOld() { // TODO: Fails since cannot open the file REDIRECT; const char *argv[] = {"cppcheck", "--exitcode-suppressions", "suppr.txt", "file.cpp"}; @@ -625,8 +579,7 @@ private: TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(4, argv)); } - void exitcodeSuppressions() - { + void exitcodeSuppressions() { // TODO: Fails since cannot open the file REDIRECT; const char *argv[] = {"cppcheck", "--exitcode-suppressions=suppr.txt", "file.cpp"}; @@ -634,8 +587,7 @@ private: TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); } - void exitcodeSuppressionsNoFile() - { + void exitcodeSuppressionsNoFile() { // TODO: Fails since cannot open the file REDIRECT; const char *argv[] = {"cppcheck", "--exitcode-suppressions", "file.cpp"}; @@ -643,8 +595,7 @@ private: TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); } - void fileList() - { + void fileList() { // TODO: Fails since cannot open the file REDIRECT; const char *argv[] = {"cppcheck", "--file-list", "files.txt", "file.cpp"}; @@ -659,15 +610,13 @@ private: TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); } */ - void inlineSuppr() - { + void inlineSuppr() { REDIRECT; const char *argv[] = {"cppcheck", "--inline-suppr", "file.cpp"}; ASSERT(defParser.ParseFromArgs(3, argv)); } - void jobs() - { + void jobs() { REDIRECT; const char *argv[] = {"cppcheck", "-j", "3", "file.cpp"}; settings._jobs = 0; @@ -675,8 +624,7 @@ private: ASSERT_EQUALS(3, settings._jobs); } - void jobsMissingCount() - { + void jobsMissingCount() { REDIRECT; const char *argv[] = {"cppcheck", "-j", "file.cpp"}; settings._jobs = 0; @@ -684,8 +632,7 @@ private: ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); } - void jobsInvalid() - { + void jobsInvalid() { REDIRECT; const char *argv[] = {"cppcheck", "-j", "e", "file.cpp"}; settings._jobs = 0; @@ -693,8 +640,7 @@ private: ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); } - void maxConfigs() - { + void maxConfigs() { REDIRECT; const char *argv[] = {"cppcheck", "-f", "--max-configs=12", "file.cpp"}; settings._force = false; @@ -704,32 +650,28 @@ private: ASSERT_EQUALS(false, settings._force); } - void maxConfigsMissingCount() - { + void maxConfigsMissingCount() { REDIRECT; const char *argv[] = {"cppcheck", "--max-configs=", "file.cpp"}; // Fails since --max-configs= is missing limit ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); } - void maxConfigsInvalid() - { + void maxConfigsInvalid() { REDIRECT; const char *argv[] = {"cppcheck", "--max-configs=e", "file.cpp"}; // Fails since invalid count given for --max-configs= ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); } - void maxConfigsTooSmall() - { + void maxConfigsTooSmall() { REDIRECT; const char *argv[] = {"cppcheck", "--max-configs=0", "file.cpp"}; // Fails since limit must be greater than 0 ASSERT_EQUALS(false, defParser.ParseFromArgs(3, argv)); } - void reportProgressTest() - { + void reportProgressTest() { REDIRECT; const char *argv[] = {"cppcheck", "--report-progress", "file.cpp"}; settings.reportProgress = false; @@ -737,8 +679,7 @@ private: ASSERT(settings.reportProgress); } - void stdposix() - { + void stdposix() { REDIRECT; const char *argv[] = {"cppcheck", "--std=posix", "file.cpp"}; settings.standards.posix = false; @@ -746,8 +687,7 @@ private: ASSERT(settings.standards.posix); } - void stdc99() - { + void stdc99() { REDIRECT; const char *argv[] = {"cppcheck", "--std=c99", "file.cpp"}; settings.standards.c = Standards::C89; @@ -755,8 +695,7 @@ private: ASSERT(settings.standards.c == Standards::C99); } - void stdcpp11() - { + void stdcpp11() { REDIRECT; const char *argv[] = {"cppcheck", "--std=c++11", "file.cpp"}; settings.standards.cpp = Standards::CPP03; @@ -764,8 +703,7 @@ private: ASSERT(settings.standards.cpp == Standards::CPP11); } - void platform() - { + void platform() { REDIRECT; const char *argv[] = {"cppcheck", "--platform=win64", "file.cpp"}; settings.platform(Settings::Unspecified); @@ -773,24 +711,21 @@ private: ASSERT(settings.platformType == Settings::Win64); } - void suppressionsOld() - { + void suppressionsOld() { // TODO: Fails because there is no suppr.txt file! REDIRECT; const char *argv[] = {"cppcheck", "--suppressions", "suppr.txt", "file.cpp"}; ASSERT(!defParser.ParseFromArgs(4, argv)); } - void suppressions() - { + void suppressions() { // TODO: Fails because there is no suppr.txt file! REDIRECT; const char *argv[] = {"cppcheck", "--suppressions-list=suppr.txt", "file.cpp"}; TODO_ASSERT_EQUALS(true, false, defParser.ParseFromArgs(3, argv)); } - void suppressionsNoFile() - { + void suppressionsNoFile() { REDIRECT; { CLEAR_REDIRECT_OUTPUT; @@ -814,8 +749,7 @@ private: } } - void suppressionSingle() - { + void suppressionSingle() { REDIRECT; const char *argv[] = {"cppcheck", "--suppress=uninitvar", "file.cpp"}; settings = Settings(); @@ -823,8 +757,7 @@ private: ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U)); } - void suppressionSingleFile() - { + void suppressionSingleFile() { REDIRECT; const char *argv[] = {"cppcheck", "--suppress=uninitvar:file.cpp", "file.cpp"}; settings = Settings(); @@ -832,8 +765,7 @@ private: ASSERT_EQUALS(true, settings.nomsg.isSuppressed("uninitvar", "file.cpp", 1U)); } - void suppressionTwo() - { + void suppressionTwo() { REDIRECT; const char *argv[] = {"cppcheck", "--suppress=uninitvar,unnecessaryQualification", "file.cpp"}; settings = Settings(); @@ -842,8 +774,7 @@ private: TODO_ASSERT_EQUALS(true, false, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U)); } - void suppressionTwoSeparate() - { + void suppressionTwoSeparate() { REDIRECT; const char *argv[] = {"cppcheck", "--suppress=uninitvar", "--suppress=unnecessaryQualification", "file.cpp"}; settings = Settings(); @@ -852,8 +783,7 @@ private: ASSERT_EQUALS(true, settings.nomsg.isSuppressed("unnecessaryQualification", "file.cpp", 1U)); } - void templates() - { + void templates() { REDIRECT; const char *argv[] = {"cppcheck", "--template", "{file}:{line},{severity},{id},{message}", "file.cpp"}; settings._outputFormat.clear(); @@ -861,8 +791,7 @@ private: ASSERT_EQUALS("{file}:{line},{severity},{id},{message}", settings._outputFormat); } - void templatesGcc() - { + void templatesGcc() { REDIRECT; const char *argv[] = {"cppcheck", "--template", "gcc", "file.cpp"}; settings._outputFormat.clear(); @@ -870,8 +799,7 @@ private: ASSERT_EQUALS("{file}:{line}: {severity}: {message}", settings._outputFormat); } - void templatesVs() - { + void templatesVs() { REDIRECT; const char *argv[] = {"cppcheck", "--template", "vs", "file.cpp"}; settings._outputFormat.clear(); @@ -879,8 +807,7 @@ private: ASSERT_EQUALS("{file}({line}): {severity}: {message}", settings._outputFormat); } - void templatesEdit() - { + void templatesEdit() { REDIRECT; const char *argv[] = {"cppcheck", "--template", "edit", "file.cpp"}; settings._outputFormat.clear(); @@ -888,8 +815,7 @@ private: ASSERT_EQUALS("{file} +{line}: {severity}: {message}", settings._outputFormat); } - void xml() - { + void xml() { REDIRECT; const char *argv[] = {"cppcheck", "--xml", "file.cpp"}; settings._xml_version = 1; @@ -899,8 +825,7 @@ private: ASSERT_EQUALS(1, settings._xml_version); } - void xmlver1() - { + void xmlver1() { REDIRECT; const char *argv[] = {"cppcheck", "--xml-version=1", "file.cpp"}; settings._xml_version = 1; @@ -910,8 +835,7 @@ private: ASSERT_EQUALS(1, settings._xml_version); } - void xmlver2() - { + void xmlver2() { REDIRECT; const char *argv[] = {"cppcheck", "--xml-version=2", "file.cpp"}; settings._xml_version = 1; @@ -921,8 +845,7 @@ private: ASSERT_EQUALS(2, settings._xml_version); } - void xmlver2both() - { + void xmlver2both() { REDIRECT; const char *argv[] = {"cppcheck", "--xml", "--xml-version=2", "file.cpp"}; settings._xml_version = 1; @@ -932,8 +855,7 @@ private: ASSERT_EQUALS(2, settings._xml_version); } - void xmlver2both2() - { + void xmlver2both2() { REDIRECT; const char *argv[] = {"cppcheck", "--xml-version=2", "--xml", "file.cpp"}; settings._xml_version = 1; @@ -943,32 +865,28 @@ private: ASSERT_EQUALS(2, settings._xml_version); } - void xmlverunknown() - { + void xmlverunknown() { REDIRECT; const char *argv[] = {"cppcheck", "--xml", "--xml-version=3", "file.cpp"}; // FAils since unknown XML format version ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); } - void xmlverinvalid() - { + void xmlverinvalid() { REDIRECT; const char *argv[] = {"cppcheck", "--xml", "--xml-version=a", "file.cpp"}; // FAils since unknown XML format version ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); } - void doc() - { + void doc() { REDIRECT; const char *argv[] = {"cppcheck", "--doc"}; ASSERT(defParser.ParseFromArgs(2, argv)); ASSERT(defParser.ExitAfterPrinting()); } - void showtime() - { + void showtime() { REDIRECT; const char *argv[] = {"cppcheck", "--showtime=summary"}; settings._showtime = SHOWTIME_NONE; @@ -976,16 +894,14 @@ private: ASSERT(settings._showtime == SHOWTIME_SUMMARY); } - void errorlist1() - { + void errorlist1() { REDIRECT; const char *argv[] = {"cppcheck", "--errorlist"}; ASSERT(defParser.ParseFromArgs(2, argv)); ASSERT(defParser.GetShowErrorMessages()); } - void errorlistverbose1() - { + void errorlistverbose1() { REDIRECT; const char *argv[] = {"cppcheck", "--verbose", "--errorlist"}; settings._verbose = false; @@ -993,8 +909,7 @@ private: ASSERT(settings._verbose); } - void errorlistverbose2() - { + void errorlistverbose2() { REDIRECT; const char *argv[] = {"cppcheck", "--errorlist", "--verbose"}; settings._verbose = false; @@ -1002,8 +917,7 @@ private: ASSERT(settings._verbose); } - void ignorepathsnopath() - { + void ignorepathsnopath() { REDIRECT; const char *argv[] = {"cppcheck", "-i"}; CmdLineParser parser(&settings); @@ -1012,8 +926,7 @@ private: ASSERT_EQUALS(0, parser.GetIgnoredPaths().size()); } - void ignorepaths1() - { + void ignorepaths1() { REDIRECT; const char *argv[] = {"cppcheck", "-isrc", "file.cpp"}; CmdLineParser parser(&settings); @@ -1022,8 +935,7 @@ private: ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]); } - void ignorepaths2() - { + void ignorepaths2() { REDIRECT; const char *argv[] = {"cppcheck", "-i", "src", "file.cpp"}; CmdLineParser parser(&settings); @@ -1032,8 +944,7 @@ private: ASSERT_EQUALS("src/", parser.GetIgnoredPaths()[0]); } - void ignorepaths3() - { + void ignorepaths3() { REDIRECT; const char *argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"}; CmdLineParser parser(&settings); @@ -1043,8 +954,7 @@ private: ASSERT_EQUALS("module/", parser.GetIgnoredPaths()[1]); } - void ignorepaths4() - { + void ignorepaths4() { REDIRECT; const char *argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"}; CmdLineParser parser(&settings); @@ -1054,8 +964,7 @@ private: ASSERT_EQUALS("module/", parser.GetIgnoredPaths()[1]); } - void ignorefilepaths1() - { + void ignorefilepaths1() { REDIRECT; const char *argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"}; CmdLineParser parser(&settings); @@ -1064,8 +973,7 @@ private: ASSERT_EQUALS("foo.cpp", parser.GetIgnoredPaths()[0]); } - void ignorefilepaths2() - { + void ignorefilepaths2() { REDIRECT; const char *argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"}; CmdLineParser parser(&settings); @@ -1074,8 +982,7 @@ private: ASSERT_EQUALS("src/foo.cpp", parser.GetIgnoredPaths()[0]); } - void checkconfig() - { + void checkconfig() { REDIRECT; const char *argv[] = {"cppcheck", "--check-config", "file.cpp"}; settings.checkConfiguration = false; @@ -1083,15 +990,13 @@ private: ASSERT_EQUALS(true, settings.checkConfiguration); } - void unknownParam() - { + void unknownParam() { REDIRECT; const char *argv[] = {"cppcheck", "--foo", "file.cpp"}; ASSERT(!defParser.ParseFromArgs(3, argv)); } - void undefs() - { + void undefs() { REDIRECT; const char *argv[] = {"cppcheck", "-U_WIN32", "file.cpp"}; settings = Settings(); @@ -1100,8 +1005,7 @@ private: ASSERT(settings.userUndefs.find("_WIN32") != settings.userUndefs.end()); } - void undefs2() - { + void undefs2() { REDIRECT; const char *argv[] = {"cppcheck", "-U_WIN32", "-UNODEBUG", "file.cpp"}; settings = Settings(); @@ -1111,24 +1015,21 @@ private: ASSERT(settings.userUndefs.find("NODEBUG") != settings.userUndefs.end()); } - void undefs_noarg() - { + void undefs_noarg() { REDIRECT; const char *argv[] = {"cppcheck", "-U"}; // Fails since -U has no param ASSERT_EQUALS(false, defParser.ParseFromArgs(2, argv)); } - void undefs_noarg2() - { + void undefs_noarg2() { REDIRECT; const char *argv[] = {"cppcheck", "-U", "-v", "file.cpp"}; // Fails since -U has no param ASSERT_EQUALS(false, defParser.ParseFromArgs(4, argv)); } - void undefs_noarg3() - { + void undefs_noarg3() { REDIRECT; const char *argv[] = {"cppcheck", "-U", "--quiet", "file.cpp"}; // Fails since -U has no param diff --git a/test/testcondition.cpp b/test/testcondition.cpp index f9948ee42..bee2374fd 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -26,15 +26,13 @@ extern std::ostringstream errout; class TestCondition : public TestFixture { public: - TestCondition() : TestFixture("TestCondition") - { + TestCondition() : TestFixture("TestCondition") { } private: - void run() - { + void run() { TEST_CASE(assignAndCompare); // assignment and comparison don't match TEST_CASE(mismatchingBitAnd); // overlapping bitmasks TEST_CASE(compare); // mismatching LHS/RHS in comparison @@ -64,8 +62,7 @@ private: TEST_CASE(clarifyCondition6); // #3818 } - void check(const char code[], bool validate=true, const char* filename = "test.cpp") - { + void check(const char code[], bool validate=true, const char* filename = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -91,8 +88,7 @@ private: } } - void assignAndCompare() - { + void assignAndCompare() { // & check("void foo(int x)\n" "{\n" @@ -260,8 +256,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mismatchingBitAnd() - { + void mismatchingBitAnd() { check("void f(int a) {\n" " int b = a & 0xf0;\n" " b &= 1;\n" @@ -284,8 +279,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void compare() - { + void compare() { check("void foo(int x)\n" "{\n" " if ((x & 4) == 3);\n" @@ -311,8 +305,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Expression '(X & 0x4) == 0x3' is always false.\n", errout.str()); } - void multicompare() - { + void multicompare() { check("void foo(int x)\n" "{\n" " if (x & 7);\n" @@ -328,8 +321,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Expression is always false because 'else if' condition matches previous condition at line 3.\n", errout.str()); } - void duplicateIf() - { + void duplicateIf() { check("void f(int a, int &b) {\n" " if (a) { b = 1; }\n" " else { if (a) { b = 2; } }\n" @@ -411,8 +403,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void invalidMissingSemicolon() - { + void invalidMissingSemicolon() { // simply survive - a syntax error would be even better check("void f(int x) {\n" " x = 42\n" @@ -421,8 +412,7 @@ private: } - void incorrectLogicOperator1() - { + void incorrectLogicOperator1() { check("void f(int x) {\n" " if ((x != 1) || (x != 3))\n" " a++;\n" @@ -517,8 +507,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void incorrectLogicOperator2() - { + void incorrectLogicOperator2() { check("void f(float x) {\n" " if ((x == 1) && (x == 1.0))\n" " a++;\n" @@ -738,8 +727,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void incorrectLogicOperator3() - { + void incorrectLogicOperator3() { check("void f(int x, bool& b) {\n" " b = x > 5 && x == 1;\n" " c = x < 1 && x == 3;\n" @@ -752,24 +740,21 @@ private: "[test.cpp:5]: (warning) Logical conjunction always evaluates to false: x <= 1 && x == 3.\n", errout.str()); } - void incorrectLogicOperator4() - { + void incorrectLogicOperator4() { check("void f(int x) {\n" " if (x && x != $0) {}\n" "}"); ASSERT_EQUALS("", errout.str()); } - void incorrectLogicOperator5() // complex expressions - { + void incorrectLogicOperator5() { // complex expressions check("void f(int x) {\n" " if (x+3 > 2 || x+3 < 10) {}\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: EXPR > 2 || EXPR < 10.\n", errout.str()); } - void incorrectLogicOperator6() // char literals - { + void incorrectLogicOperator6() { // char literals check("void f(char x) {\n" " if (x == '1' || x == '2') {}\n" "}"); @@ -781,16 +766,14 @@ private: TODO_ASSERT_EQUALS("error", "", errout.str()); } - void incorrectLogicOperator7() // opposite expressions - { + void incorrectLogicOperator7() { // opposite expressions check("void f(int i) {\n" " if (i || !i) {}\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (warning) Logical disjunction always evaluates to true: i||!i.\n", errout.str()); } - void secondAlwaysTrueFalseWhenFirstTrueError() - { + void secondAlwaysTrueFalseWhenFirstTrueError() { check("void f(int x) {\n" " if (x > 5 && x != 1)\n" " a++;\n" @@ -853,8 +836,7 @@ private: "[test.cpp:5]: (style) Redundant condition: If x < 5, the comparison x < 6 is always true.\n", errout.str()); } - void incorrectLogicOp_condSwapping() - { + void incorrectLogicOp_condSwapping() { check("void f(int x) {\n" " if (x < 1 && x > 3)\n" " a++;\n" @@ -904,8 +886,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (warning) Logical conjunction always evaluates to false: x > 3 && x < 1.\n", errout.str()); } - void modulo() - { + void modulo() { check("bool f(bool& b1, bool& b2, bool& b3) {\n" " b1 = a % 5 == 4;\n" " b2 = a % c == 100000;\n" @@ -945,8 +926,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void oppositeInnerCondition() - { + void oppositeInnerCondition() { check("void foo(int a, int b) {\n" " if(a==b)\n" " if(a!=b)\n" @@ -1112,8 +1092,7 @@ private: } // clarify conditions with = and comparison - void clarifyCondition1() - { + void clarifyCondition1() { check("void f() {\n" " if (x = b() < 0) {}\n" // don't simplify and verify this code "}", false); @@ -1132,8 +1111,7 @@ private: } // clarify conditions with bitwise operator and comparison - void clarifyCondition2() - { + void clarifyCondition2() { check("void f() {\n" " if (x & 3 == 2) {}\n" "}"); @@ -1146,8 +1124,7 @@ private: } // clarify condition that uses ! operator and then bitwise operator - void clarifyCondition3() - { + void clarifyCondition3() { check("void f(int w) {\n" " if(!w & 0x8000) {}\n" "}"); @@ -1176,8 +1153,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void clarifyCondition4() // ticket #3110 - { + void clarifyCondition4() { // ticket #3110 check("typedef double SomeType;\n" "typedef std::pair PairType;\n" "struct S\n" @@ -1192,14 +1168,12 @@ private: ASSERT_EQUALS("", errout.str()); } - void clarifyCondition5() // ticket #3609 (using | in template instantiation) - { + void clarifyCondition5() { // ticket #3609 (using | in template instantiation) check("CWinTraits::GetWndStyle(0);"); ASSERT_EQUALS("", errout.str()); } - void clarifyCondition6() - { + void clarifyCondition6() { check("template\n" "SharedPtr& operator=( SharedPtr const & r ) {\n" " px = r.px;\n" diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 95ed1fc0e..eb08d9c02 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -27,15 +27,13 @@ extern std::ostringstream errout; class TestConstructors : public TestFixture { public: - TestConstructors() : TestFixture("TestConstructors") - { + TestConstructors() : TestFixture("TestConstructors") { } private: - void check(const char code[], bool showAll = false) - { + void check(const char code[], bool showAll = false) { // Clear the error buffer.. errout.str(""); @@ -55,8 +53,7 @@ private: checkClass.constructors(); } - void run() - { + void run() { TEST_CASE(simple1); TEST_CASE(simple2); TEST_CASE(simple3); @@ -184,8 +181,7 @@ private: } - void simple1() - { + void simple1() { check("class Fred\n" "{\n" "public:\n" @@ -209,8 +205,7 @@ private: } - void simple2() - { + void simple2() { check("class Fred\n" "{\n" "public:\n" @@ -256,8 +251,7 @@ private: } - void simple3() - { + void simple3() { check("struct Fred\n" "{\n" " Fred();\n" @@ -287,8 +281,7 @@ private: } - void simple4() - { + void simple4() { check("struct Fred\n" "{\n" " Fred();\n" @@ -305,8 +298,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (warning, inconclusive) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str()); } - void simple5() // ticket #2560 - { + void simple5() { // ticket #2560 check("namespace Nsp\n" "{\n" " class B { };\n" @@ -323,8 +315,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simple6() // ticket #4085 - uninstantiated template class - { + void simple6() { // ticket #4085 - uninstantiated template class check("template struct A {\n" " A() { x = 0; }\n" " A(const T & t) { x = t.x; }\n" @@ -352,8 +343,7 @@ private: "[test.cpp:3]: (warning) Member variable 'A::y' is not initialized in the constructor.\n", errout.str()); } - void simple7() // ticket #4531 - { + void simple7() { // ticket #4531 check("class Fred;\n" "struct Fred {\n" " int x;\n" @@ -361,8 +351,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simple8() - { + void simple8() { check("struct Fred { int x; };\n" "class Barney { Fred fred; };\n" "class Wilma { struct Betty { int x; } betty; };"); @@ -370,8 +359,7 @@ private: "[test.cpp:3]: (style) The class 'Wilma' does not have a constructor.\n", errout.str()); } - void simple9() // ticket #4574 - { + void simple9() { // ticket #4574 check("class Unknown::Fred {\n" "public:\n" " Fred() : x(0) { }\n" @@ -381,8 +369,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simple10() // ticket #4388 - { + void simple10() { // ticket #4388 check("class Fred {\n" "public:\n" " Fred() = default;\n" @@ -392,8 +379,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simple11() // ticket #4536, #6214 - { + void simple11() { // ticket #4536, #6214 check("class Fred {\n" "public:\n" " Fred() {}\n" @@ -411,8 +397,7 @@ private: "[test.cpp:3]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str()); } - void simple12() // ticket #4620 - { + void simple12() { // ticket #4620 check("class Fred {\n" " int x;\n" "public:\n" @@ -433,8 +418,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simple13() // #5498 - { + void simple13() { // #5498 check("class Fred {\n" " int x=1;\n" " int *y=0;\n" @@ -442,8 +426,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void noConstructor1() - { + void noConstructor1() { // There are nonstatic member variables - constructor is needed check("class Fred\n" "{\n" @@ -452,8 +435,7 @@ private: ASSERT_EQUALS("[test.cpp:1]: (style) The class 'Fred' does not have a constructor.\n", errout.str()); } - void noConstructor2() - { + void noConstructor2() { check("class Fred\n" "{\n" "public:\n" @@ -465,8 +447,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void noConstructor3() - { + void noConstructor3() { check("class Fred\n" "{\n" "private:\n" @@ -475,8 +456,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void noConstructor4() - { + void noConstructor4() { check("class Fred\n" "{\n" "public:\n" @@ -485,8 +465,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void noConstructor5() - { + void noConstructor5() { check("namespace Foo\n" "{\n" " int i;\n" @@ -494,8 +473,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void noConstructor6() - { + void noConstructor6() { // ticket #4386 check("class Ccpucycles {\n" " friend class foo::bar;\n" @@ -509,16 +487,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void noConstructor7() - { + void noConstructor7() { // ticket #4391 check("short bar;\n" "class foo;\n"); ASSERT_EQUALS("", errout.str()); } - void noConstructor8() - { + void noConstructor8() { // ticket #4404 check("class LineSegment;\n" "class PointArray { };\n" @@ -526,8 +502,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void noConstructor9() - { + void noConstructor9() { // ticket #4419 check("class CGreeting : public CGreetingBase {\n" "public:\n" @@ -540,8 +515,7 @@ private: // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor." // ticket #3190 "SymbolDatabase: Parse of sub class constructor fails" - void forwardDeclaration() - { + void forwardDeclaration() { check("class foo;\n" "int bar;\n"); ASSERT_EQUALS("", errout.str()); @@ -555,8 +529,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_with_this() - { + void initvar_with_this() { check("struct Fred\n" "{\n" " Fred()\n" @@ -566,8 +539,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_if() - { + void initvar_if() { check("struct Fred\n" "{\n" " Fred()\n" @@ -582,8 +554,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_operator_eq1() - { + void initvar_operator_eq1() { // Bug 2190376 and #3820 - False positive, Uninitialized member variable with operator= check("struct Fred\n" @@ -629,8 +600,7 @@ private: } - void initvar_operator_eq2() - { + void initvar_operator_eq2() { check("struct Fred\n" "{\n" " Fred() { i = 0; }\n" @@ -640,8 +610,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::i' is not assigned a value in 'Fred::operator='.\n", errout.str()); } - void initvar_operator_eq3() - { + void initvar_operator_eq3() { check("struct Fred\n" "{\n" " Fred() { Init(); }\n" @@ -653,8 +622,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_operator_eq4() - { + void initvar_operator_eq4() { check("class Fred\n" "{\n" " int i;\n" @@ -716,8 +684,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_operator_eq5() // #4119 - false positive when using swap to assign variables - { + void initvar_operator_eq5() { // #4119 - false positive when using swap to assign variables check("class Fred {\n" " int i;\n" "public:\n" @@ -732,8 +699,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_same_classname() - { + void initvar_same_classname() { // Bug 2208157 - False positive: Uninitialized variable, same class name check("void func1()\n" @@ -842,8 +808,7 @@ private: "[test.cpp:16]: (warning) Member variable 'Fred::b' is not initialized in the constructor.\n", errout.str()); } - void initvar_chained_assign() - { + void initvar_chained_assign() { // Bug 2270433 - Uninitialized variable false positive on chained assigns check("struct c\n" @@ -863,8 +828,7 @@ private: } - void initvar_2constructors() - { + void initvar_2constructors() { check("struct c\n" "{\n" " c();\n" @@ -897,8 +861,7 @@ private: } - void initvar_constvar() - { + void initvar_constvar() { check("struct Fred\n" "{\n" " const char *s;\n" @@ -928,8 +891,7 @@ private: } - void initvar_staticvar() - { + void initvar_staticvar() { check("class Fred\n" "{\n" "public:\n" @@ -940,8 +902,7 @@ private: } - void initvar_union() - { + void initvar_union() { check("class Fred\n" "{\n" " union\n" @@ -973,8 +934,7 @@ private: } - void initvar_delegate() - { + void initvar_delegate() { check("class A {\n" " int number;\n" "public:\n" @@ -1045,8 +1005,7 @@ private: } - void initvar_private_constructor() - { + void initvar_private_constructor() { check("class Fred\n" "{\n" "private:\n" @@ -1058,8 +1017,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_copy_constructor() // ticket #1611 - { + void initvar_copy_constructor() { // ticket #1611 check("class Fred\n" "{\n" "private:\n" @@ -1093,8 +1051,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (warning, inconclusive) Member variable 'Fred::var' is not initialized in the constructor.\n", errout.str()); } - void initvar_nested_constructor() // ticket #1375 - { + void initvar_nested_constructor() { // ticket #1375 check("class A {\n" "public:\n" " A();\n" @@ -1187,8 +1144,7 @@ private: "[test.cpp:24]: (warning) Member variable 'D::d' is not initialized in the constructor.\n", errout.str()); } - void initvar_nocopy1() // ticket #2474 - { + void initvar_nocopy1() { // ticket #2474 check("class B\n" "{\n" " B (const B & Var);\n" @@ -1300,8 +1256,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_nocopy2() // ticket #2484 - { + void initvar_nocopy2() { // ticket #2484 check("class B\n" "{\n" " B (B & Var);\n" @@ -1335,8 +1290,7 @@ private: "[test.cpp:13]: (warning) Member variable 'A::m_SemVar' is not assigned a value in 'A::operator='.\n", errout.str()); } - void initvar_nocopy3() // #3611 - unknown type is non-copyable - { + void initvar_nocopy3() { // #3611 - unknown type is non-copyable check("struct A {\n" " B b;\n" " A() {}\n" @@ -1352,8 +1306,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning, inconclusive) Member variable 'A::b' is not initialized in the constructor.\n", errout.str()); } - void initvar_with_member_function_this() - { + void initvar_with_member_function_this() { check("struct Foo {\n" " Foo(int m) { this->setMember(m); }\n" " void setMember(int m) { member = m; }\n" @@ -1362,8 +1315,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_destructor() - { + void initvar_destructor() { check("class Fred\n" "{\n" "private:\n" @@ -1375,8 +1327,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initvar_func_ret_func_ptr() // ticket #4449 (segmentation fault) - { + void initvar_func_ret_func_ptr() { // ticket #4449 (segmentation fault) check("class something {\n" " int * ( something :: * process()) () { return 0; }\n" " something() { process(); }\n" @@ -1384,8 +1335,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void operatorEqSTL() - { + void operatorEqSTL() { check("class Fred\n" "{\n" "private:\n" @@ -1403,8 +1353,7 @@ private: ASSERT_EQUALS("[test.cpp:13]: (warning, inconclusive) Member variable 'Fred::ints' is not assigned a value in 'Fred::operator='.\n", errout.str()); } - void uninitVar1() - { + void uninitVar1() { check("enum ECODES\n" "{\n" " CODE_1 = 0,\n" @@ -1448,8 +1397,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar2() - { + void uninitVar2() { check("class John\n" "{\n" "public:\n" @@ -1460,8 +1408,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar3() - { + void uninitVar3() { // No FP when struct has constructor check("class Foo\n" "{\n" @@ -1489,8 +1436,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Foo::bars' is not initialized in the constructor.\n", errout.str()); } - void uninitVar4() - { + void uninitVar4() { check("class Foo\n" "{\n" "public:\n" @@ -1504,8 +1450,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar5() - { + void uninitVar5() { check("class Foo\n" "{\n" "public:\n" @@ -1517,8 +1462,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar6() - { + void uninitVar6() { check("class Foo : public Bar\n" "{\n" "public:\n" @@ -1538,8 +1482,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar7() - { + void uninitVar7() { check("class Foo {\n" " int a;\n" "public:\n" @@ -1560,8 +1503,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar8() - { + void uninitVar8() { check("class Foo {\n" " int a;\n" "public:\n" @@ -1578,8 +1520,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'Foo::a' is not assigned a value in 'Foo::operator='.\n", errout.str()); } - void uninitVar9() // ticket #1730 - { + void uninitVar9() { // ticket #1730 check("class Prefs {\n" "private:\n" " int xasd;\n" @@ -1593,8 +1534,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Prefs::xasd' is not initialized in the constructor.\n", errout.str()); } - void uninitVar10() // ticket #1993 - { + void uninitVar10() { // ticket #1993 check("class A {\n" "public:\n" " A();\n" @@ -1606,8 +1546,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (warning) Member variable 'A::var2' is not initialized in the constructor.\n", errout.str()); } - void uninitVar11() - { + void uninitVar11() { check("class A {\n" "public:\n" " explicit A(int a = 0);\n" @@ -1618,8 +1557,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'A::var' is not initialized in the constructor.\n", errout.str()); } - void uninitVar12() // ticket #2078 - { + void uninitVar12() { // ticket #2078 check("class Point\n" "{\n" "public:\n" @@ -1636,8 +1574,7 @@ private: "[test.cpp:4]: (warning) Member variable 'Point::y' is not initialized in the constructor.\n", errout.str()); } - void uninitVar13() // ticket #1195 - { + void uninitVar13() { // ticket #1195 check("class A {\n" "private:\n" " std::vector *ints;\n" @@ -1648,8 +1585,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'A::ints' is not initialized in the constructor.\n", errout.str()); } - void uninitVar14() // ticket #2149 - { + void uninitVar14() { // ticket #2149 // no namespace check("class Foo\n" "{\n" @@ -1835,8 +1771,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar15() - { + void uninitVar15() { check("class Fred\n" "{\n" " int a;\n" @@ -1850,8 +1785,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar16() - { + void uninitVar16() { check("struct Foo\n" "{\n" " int a;\n" @@ -1884,8 +1818,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (warning) Member variable 'Bar::foo' is not initialized in the constructor.\n", errout.str()); } - void uninitVar17() - { + void uninitVar17() { check("struct Foo\n" "{\n" " int a;\n" @@ -1916,8 +1849,7 @@ private: ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Bar::foo' is not initialized in the constructor.\n", errout.str()); } - void uninitVar18() // ticket #2465 - { + void uninitVar18() { // ticket #2465 check("struct Altren\n" "{\n" " explicit Altren(int _a = 0) : value(0) { }\n" @@ -1933,8 +1865,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar19() // ticket #2792 - { + void uninitVar19() { // ticket #2792 check("class mystring\n" "{\n" " char* m_str;\n" @@ -1958,8 +1889,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar20() // ticket #2867 - { + void uninitVar20() { // ticket #2867 check("Object::MemFunc() {\n" " class LocalClass {\n" " public:\n" @@ -1991,8 +1921,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'LocalClass::bitsInData_' is not initialized in the constructor.\n", errout.str()); } - void uninitVar21() // ticket #2947 - { + void uninitVar21() { // ticket #2947 check("class Fred {\n" "private:\n" " int a[23];\n" @@ -2005,8 +1934,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar22() // ticket #3043 - { + void uninitVar22() { // ticket #3043 check("class Fred {\n" " public:\n" " Fred & operator=(const Fred &);\n" @@ -2037,8 +1965,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'Fred::x' is not assigned a value in 'Fred::operator='.\n", errout.str()); } - void uninitVar23() // ticket #3702 - { + void uninitVar23() { // ticket #3702 check("class Fred {\n" " int x;\n" "public:\n" @@ -2061,8 +1988,7 @@ private: "[test.cpp:14]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n", errout.str()); } - void uninitVar24() // ticket #3190 - { + void uninitVar24() { // ticket #3190 check("class Foo;\n" "class Bar;\n" "class Sub;\n" @@ -2092,8 +2018,7 @@ private: "[test.cpp:20]: (warning) Member variable 'Sub::f' is not initialized in the constructor.\n", errout.str()); } - void uninitVar25() // ticket #4789 - { + void uninitVar25() { // ticket #4789 check("struct A {\n" " int a;\n" " int b;\n" @@ -2156,8 +2081,7 @@ private: "[test.cpp:42]: (warning) Member variable 'F::c' is not initialized in the constructor.\n", errout.str()); } - void uninitVar26() - { + void uninitVar26() { check("class A {\n" " int * v;\n" " int sz;\n" @@ -2169,8 +2093,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar27() - { + void uninitVar27() { check("class A {\n" " double d;\n" "public:\n" @@ -2189,8 +2112,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar28() - { + void uninitVar28() { check("class Fred {\n" " int i;\n" " float f;\n" @@ -2205,8 +2127,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVar29() - { + void uninitVar29() { check("class A {\n" " int i;\n" "public:\n" @@ -2239,8 +2160,7 @@ private: "[test.cpp:25]: (warning) Member variable 'D::i' is not initialized in the constructor.\n", errout.str()); } - void uninitVarArray1() - { + void uninitVarArray1() { check("class John\n" "{\n" "public:\n" @@ -2299,8 +2219,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'John::a' is not initialized in the constructor.\n", errout.str()); } - void uninitVarArray2() - { + void uninitVarArray2() { check("class John\n" "{\n" "public:\n" @@ -2323,8 +2242,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarArray3() - { + void uninitVarArray3() { check("class John\n" "{\n" "private:\n" @@ -2341,8 +2259,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarArray4() - { + void uninitVarArray4() { check("class John\n" "{\n" "private:\n" @@ -2359,8 +2276,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarArray5() - { + void uninitVarArray5() { check("class Foo\n" "{\n" "private:\n" @@ -2372,8 +2288,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarArray6() - { + void uninitVarArray6() { check("class Foo\n" "{\n" "public:\n" @@ -2385,8 +2300,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarArray7() - { + void uninitVarArray7() { check("class Foo\n" "{\n" " int array[10];\n" @@ -2412,8 +2326,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarArray8() - { + void uninitVarArray8() { check("class Foo {\n" " char a[10];\n" "public:\n" @@ -2422,8 +2335,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarArray2D() - { + void uninitVarArray2D() { check("class John\n" "{\n" "public:\n" @@ -2435,8 +2347,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarArray3D() - { + void uninitVarArray3D() { check("class John\n" "{\n" "private:\n" @@ -2447,8 +2358,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarCpp11Init1() - { + void uninitVarCpp11Init1() { check("class Foo {\n" " std::vector bar;\n" "public:\n" @@ -2459,8 +2369,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarCpp11Init2() - { + void uninitVarCpp11Init2() { check("class Fred {\n" " struct Foo {\n" " int a;\n" @@ -2476,8 +2385,7 @@ private: ASSERT_EQUALS("[test.cpp:9]: (warning) Member variable 'Fred::g' is not initialized in the constructor.\n", errout.str()); } - void uninitVarStruct1() // ticket #2172 - { + void uninitVarStruct1() { // ticket #2172 check("class A\n" "{\n" "private:\n" @@ -2522,8 +2430,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarStruct2() // ticket #838 - { + void uninitVarStruct2() { // ticket #838 check("struct POINT\n" "{\n" " int x;\n" @@ -2588,8 +2495,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarUnion1() // ticket #3196 - { + void uninitVarUnion1() { // ticket #3196 check("class Fred\n" "{\n" "private:\n" @@ -2601,8 +2507,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarUnion2() - { + void uninitVarUnion2() { // If the "data_type" is 0 it means union member "data" is invalid. // So it's ok to not initialize "data". // related forum: http://sourceforge.net/apps/phpbb/cppcheck/viewtopic.php?f=3&p=1806 @@ -2619,8 +2524,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitMissingFuncDef() - { + void uninitMissingFuncDef() { // Unknown member function check("class Fred\n" "{\n" @@ -2676,8 +2580,7 @@ private: } - void uninitVarEnum() - { + void uninitVarEnum() { check("class Fred\n" "{\n" "public:\n" @@ -2690,8 +2593,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str()); } - void uninitVarStream() - { + void uninitVarStream() { check("class Foo\n" "{\n" "private:\n" @@ -2707,8 +2609,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarTypedef() - { + void uninitVarTypedef() { check("class Foo\n" "{\n" "public:\n" @@ -2720,8 +2621,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarMemset() - { + void uninitVarMemset() { check("class Foo\n" "{\n" "public:\n" @@ -2741,8 +2641,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void privateCtor1() - { + void privateCtor1() { check("class Foo {\n" " int foo;\n" " Foo() { }\n" @@ -2750,8 +2649,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void privateCtor2() - { + void privateCtor2() { check("class Foo\n" "{\n" "private:\n" @@ -2765,8 +2663,7 @@ private: } - void function() - { + void function() { check("class A\n" "{\n" "public:\n" @@ -2787,8 +2684,7 @@ private: } - void uninitVarHeader1() - { + void uninitVarHeader1() { check("#file \"fred.h\"\n" "class Fred\n" "{\n" @@ -2801,8 +2697,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitVarHeader2() - { + void uninitVarHeader2() { check("#file \"fred.h\"\n" "class Fred\n" "{\n" @@ -2815,8 +2710,7 @@ private: ASSERT_EQUALS("[fred.h:6]: (warning) Member variable 'Fred::i' is not initialized in the constructor.\n", errout.str()); } - void uninitVarHeader3() - { + void uninitVarHeader3() { check("#file \"fred.h\"\n" "class Fred\n" "{\n" @@ -2830,8 +2724,7 @@ private: } // Borland C++: No FP for published pointers - they are automatically initialized - void uninitVarPublished() - { + void uninitVarPublished() { check("class Fred\n" "{\n" "__published:\n" @@ -2842,8 +2735,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitOperator() - { + void uninitOperator() { check("class Fred\n" "{\n" "public:\n" @@ -2853,8 +2745,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitFunction1() - { + void uninitFunction1() { check("class Fred\n" "{\n" "public:\n" @@ -2880,8 +2771,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", "", errout.str()); } - void uninitFunction2() - { + void uninitFunction2() { check("class Fred\n" "{\n" "public:\n" @@ -2907,8 +2797,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", "", errout.str()); } - void uninitFunction3() - { + void uninitFunction3() { check("class Fred\n" "{\n" "public:\n" @@ -2934,8 +2823,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", errout.str()); } - void uninitFunction4() - { + void uninitFunction4() { check("class Fred\n" "{\n" "public:\n" @@ -2961,8 +2849,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'Fred::d' is not initialized in the constructor.\n", "", errout.str()); } - void uninitFunction5() // #4072 - FP about struct that is initialized in function - { + void uninitFunction5() { // #4072 - FP about struct that is initialized in function check("struct Structure {\n" " int C;\n" "};\n" @@ -2976,8 +2863,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitSameClassName() - { + void uninitSameClassName() { check("class B\n" "{\n" "public:\n" @@ -3093,8 +2979,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitFunctionOverload() - { + void uninitFunctionOverload() { // Ticket #1783 - overloaded "init" functions check("class A\n" "{\n" @@ -3133,8 +3018,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'A::i' is not initialized in the constructor.\n", errout.str()); } - void uninitVarOperatorEqual() // ticket #2415 - { + void uninitVarOperatorEqual() { // ticket #2415 check("struct A {\n" " int a;\n" " A() { a=0; }\n" @@ -3165,8 +3049,7 @@ private: "[test.cpp:5]: (warning) Member variable 'A::a' is not assigned a value in 'A::operator='.\n", errout.str()); } - void uninitVarPointer() // #3801 - { + void uninitVarPointer() { // #3801 check("struct A {\n" " int a;\n" "};\n" @@ -3198,8 +3081,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout.str()); } - void uninitConstVar() - { + void uninitConstVar() { check("struct A;\n" "struct B {\n" " A* const a;\n" @@ -3232,8 +3114,7 @@ private: } // Ticket #5641 "Regression. Crash for 'C() _STLP_NOTHROW {}'" - void constructors_crash1() - { + void constructors_crash1() { check("class C {\n" "public:\n" " C() _STLP_NOTHROW {}\n" @@ -3242,8 +3123,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void invalidInitializerList() - { + void invalidInitializerList() { // 5702 ASSERT_THROW(check("struct R1 {\n" " int a;\n" diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index ced9b6b09..f74a83532 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -32,8 +32,7 @@ extern std::ostringstream output; class TestCppcheck : public TestFixture { public: - TestCppcheck() : TestFixture("TestCppcheck") - { + TestCppcheck() : TestFixture("TestCppcheck") { } private: @@ -42,25 +41,21 @@ private: public: std::list id; - void reportOut(const std::string & /*outmsg*/) - { + void reportOut(const std::string & /*outmsg*/) { } - void reportErr(const ErrorLogger::ErrorMessage &msg) - { + void reportErr(const ErrorLogger::ErrorMessage &msg) { id.push_back(msg._id); } }; - void run() - { + void run() { TEST_CASE(instancesSorted); TEST_CASE(classInfoFormat); TEST_CASE(getErrorMessages); } - void instancesSorted() const - { + void instancesSorted() const { for (std::list::const_iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) { std::list::const_iterator j = i; ++j; @@ -70,8 +65,7 @@ private: } } - void classInfoFormat() const - { + void classInfoFormat() const { for (std::list::const_iterator i = Check::instances().begin(); i != Check::instances().end(); ++i) { const std::string info = (*i)->classInfo(); if (!info.empty()) { @@ -83,8 +77,7 @@ private: } } - void getErrorMessages() const - { + void getErrorMessages() const { ErrorLogger2 errorLogger; CppCheck cppCheck(errorLogger, true); cppCheck.getErrorMessages(); diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index c603ba66c..0b275466a 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -23,16 +23,14 @@ class TestErrorLogger : public TestFixture { public: - TestErrorLogger() : TestFixture("TestErrorLogger"), fooCpp5("foo.cpp", 5), barCpp8("bar.cpp", 8) - { + TestErrorLogger() : TestFixture("TestErrorLogger"), fooCpp5("foo.cpp", 5), barCpp8("bar.cpp", 8) { } private: const ErrorLogger::ErrorMessage::FileLocation fooCpp5; const ErrorLogger::ErrorMessage::FileLocation barCpp8; - void run() - { + void run() { TEST_CASE(FileLocationDefaults); TEST_CASE(FileLocationSetFile); TEST_CASE(ErrorMessageConstruct); @@ -59,23 +57,20 @@ private: TEST_CASE(suppressUnmatchedSuppressions); } - void FileLocationDefaults() const - { + void FileLocationDefaults() const { ErrorLogger::ErrorMessage::FileLocation loc; ASSERT_EQUALS("", loc.getfile()); ASSERT_EQUALS(0, loc.line); } - void FileLocationSetFile() const - { + void FileLocationSetFile() const { ErrorLogger::ErrorMessage::FileLocation loc; loc.setfile("foo.cpp"); ASSERT_EQUALS("foo.cpp", loc.getfile()); ASSERT_EQUALS(0, loc.line); } - void ErrorMessageConstruct() const - { + void ErrorMessageConstruct() const { std::list locs(1, fooCpp5); ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); @@ -85,8 +80,7 @@ private: ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(true)); } - void ErrorMessageConstructLocations() const - { + void ErrorMessageConstructLocations() const { std::list locs; locs.push_back(fooCpp5); locs.push_back(barCpp8); @@ -98,8 +92,7 @@ private: ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Programming error.", msg.toString(true)); } - void ErrorMessageVerbose() const - { + void ErrorMessageVerbose() const { std::list locs(1, fooCpp5); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); @@ -109,8 +102,7 @@ private: ASSERT_EQUALS("[foo.cpp:5]: (error) Verbose error", msg.toString(true)); } - void ErrorMessageVerboseLocations() const - { + void ErrorMessageVerboseLocations() const { std::list locs; locs.push_back(fooCpp5); locs.push_back(barCpp8); @@ -122,8 +114,7 @@ private: ASSERT_EQUALS("[foo.cpp:5] -> [bar.cpp:8]: (error) Verbose error", msg.toString(true)); } - void CustomFormat() const - { + void CustomFormat() const { std::list locs(1, fooCpp5); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); @@ -133,8 +124,7 @@ private: ASSERT_EQUALS("foo.cpp:5,error,errorId,Verbose error", msg.toString(true, "{file}:{line},{severity},{id},{message}")); } - void CustomFormat2() const - { + void CustomFormat2() const { std::list locs(1, fooCpp5); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); @@ -144,8 +134,7 @@ private: ASSERT_EQUALS("Verbose error - foo.cpp(5):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})")); } - void CustomFormatLocations() const - { + void CustomFormatLocations() const { // Check that first location from location stack is used in template std::list locs; locs.push_back(fooCpp5); @@ -158,8 +147,7 @@ private: ASSERT_EQUALS("Verbose error - bar.cpp(8):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})")); } - void ToXml() const - { + void ToXml() const { std::list locs(1, fooCpp5); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); @@ -167,8 +155,7 @@ private: ASSERT_EQUALS(" ", msg.toXML(false,1)); } - void ToXmlLocations() const - { + void ToXmlLocations() const { std::list locs; locs.push_back(fooCpp5); locs.push_back(barCpp8); @@ -178,8 +165,7 @@ private: ASSERT_EQUALS(" ", msg.toXML(false,1)); } - void ToVerboseXml() const - { + void ToVerboseXml() const { std::list locs(1, fooCpp5); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS("\n", ErrorLogger::ErrorMessage::getXMLHeader(1)); @@ -187,8 +173,7 @@ private: ASSERT_EQUALS(" ", msg.toXML(true,1)); } - void ToVerboseXmlLocations() const - { + void ToVerboseXmlLocations() const { std::list locs; locs.push_back(fooCpp5); locs.push_back(barCpp8); @@ -198,8 +183,7 @@ private: ASSERT_EQUALS(" ", msg.toXML(true,1)); } - void ToXmlV2() const - { + void ToXmlV2() const { std::list locs(1, fooCpp5); ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false); std::string header("\n\n"); @@ -214,8 +198,7 @@ private: ASSERT_EQUALS(message, msg.toXML(false, 2)); } - void ToXmlV2Locations() const - { + void ToXmlV2Locations() const { std::list locs; locs.push_back(fooCpp5); locs.push_back(barCpp8); @@ -233,16 +216,14 @@ private: ASSERT_EQUALS(message, msg.toXML(false, 2)); } - void ToXmlV2Encoding() const - { + void ToXmlV2Encoding() const { std::list locs; ErrorMessage msg(locs, Severity::error, "Programming error.\nComparing \"\203\" with \"\003\"", "errorId", false); const std::string message(" "); ASSERT_EQUALS(message, msg.toXML(false, 2)); } - void InconclusiveXml() const - { + void InconclusiveXml() const { // Location std::list locs(1, fooCpp5); @@ -259,8 +240,7 @@ private: msg.toXML(false, 2)); } - void SerializeInconclusiveMessage() const - { + void SerializeInconclusiveMessage() const { // Inconclusive error message std::list locs; ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true); @@ -280,8 +260,7 @@ private: ASSERT_EQUALS("Programming error", msg2.verboseMessage()); } - void suppressUnmatchedSuppressions() - { + void suppressUnmatchedSuppressions() { std::list suppressions; // No unmatched suppression diff --git a/test/testexceptionsafety.cpp b/test/testexceptionsafety.cpp index b2fa32941..b4f09d59f 100644 --- a/test/testexceptionsafety.cpp +++ b/test/testexceptionsafety.cpp @@ -26,14 +26,12 @@ extern std::ostringstream errout; class TestExceptionSafety : public TestFixture { public: - TestExceptionSafety() : TestFixture("TestExceptionSafety") - { + TestExceptionSafety() : TestFixture("TestExceptionSafety") { } private: - void run() - { + void run() { TEST_CASE(destructors); TEST_CASE(deallocThrow1); TEST_CASE(deallocThrow2); @@ -53,8 +51,7 @@ private: TEST_CASE(nothrowDeclspecThrow); } - void check(const char code[], bool inconclusive = false) - { + void check(const char code[], bool inconclusive = false) { // Clear the error buffer.. errout.str(""); @@ -72,8 +69,7 @@ private: checkExceptionSafety.runSimplifiedChecks(&tokenizer, &settings, this); } - void destructors() - { + void destructors() { check("class x {\n" " ~x() {\n" " throw e;\n" @@ -115,8 +111,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void deallocThrow1() - { + void deallocThrow1() { check("int * p;\n" "void f(int x) {\n" " delete p;\n" @@ -136,8 +131,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory.\n", errout.str()); } - void deallocThrow2() - { + void deallocThrow2() { check("void f() {\n" " int* p = 0;\n" " delete p;\n" @@ -156,8 +150,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void deallocThrow3() - { + void deallocThrow3() { check("void f() {\n" " static int* p = 0;\n" " delete p;\n" @@ -173,8 +166,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) Exception thrown in invalid state, 'p' points at deallocated memory.\n", errout.str()); } - void rethrowCopy1() - { + void rethrowCopy1() { check("void f() {\n" " try\n" " {\n" @@ -188,8 +180,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); } - void rethrowCopy2() - { + void rethrowCopy2() { check("void f() {\n" " try\n" " {\n" @@ -203,8 +194,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); } - void rethrowCopy3() - { + void rethrowCopy3() { check("void f() {\n" " try {\n" " foo();\n" @@ -216,8 +206,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (style) Throwing a copy of the caught exception instead of rethrowing the original exception.\n", errout.str()); } - void rethrowCopy4() - { + void rethrowCopy4() { check("void f() {\n" " try\n" " {\n" @@ -232,8 +221,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void rethrowCopy5() - { + void rethrowCopy5() { check("void f() {\n" " try {\n" " foo();\n" @@ -265,8 +253,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void catchExceptionByValue() - { + void catchExceptionByValue() { check("void f() {\n" " try {\n" " bar();\n" @@ -338,8 +325,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void noexceptThrow() - { + void noexceptThrow() { check("void func1() noexcept(false) { throw 1; }\n" "void func2() noexcept { throw 1; }\n" "void func3() noexcept(true) { throw 1; }\n" @@ -355,8 +341,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nothrowThrow() - { + void nothrowThrow() { check("void func1() throw(int) { throw 1; }\n" "void func2() throw() { throw 1; }\n" "void func3() throw(int) { throw 1; }\n" @@ -370,8 +355,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void unhandledExceptionSpecification1() // #4800 - { + void unhandledExceptionSpecification1() { // #4800 check("void myThrowingFoo() throw(MyException) {\n" " throw MyException();\n" "}\n" @@ -386,8 +370,7 @@ private: ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:1]: (style, inconclusive) Unhandled exception specification when calling function myThrowingFoo().\n", errout.str()); } - void unhandledExceptionSpecification2() - { + void unhandledExceptionSpecification2() { check("void f() const throw (std::runtime_error);\n" "int main()\n" "{\n" @@ -396,8 +379,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nothrowAttributeThrow() - { + void nothrowAttributeThrow() { check("void func1() throw(int) { throw 1; }\n" "void func2() __attribute((nothrow)); void func2() { throw 1; }\n" "void func3() __attribute((nothrow)); void func3() { func1(); }\n"); @@ -409,8 +391,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nothrowAttributeThrow2() - { + void nothrowAttributeThrow2() { check("class foo {\n" " void copyMemberValues() throw () {\n" " copyMemberValues();\n" @@ -419,8 +400,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nothrowDeclspecThrow() - { + void nothrowDeclspecThrow() { check("void func1() throw(int) { throw 1; }\n" "void __declspec(nothrow) func2() { throw 1; }\n" "void __declspec(nothrow) func3() { func1(); }\n"); diff --git a/test/testfilelister.cpp b/test/testfilelister.cpp index be6c2636b..21a24cdcb 100644 --- a/test/testfilelister.cpp +++ b/test/testfilelister.cpp @@ -32,13 +32,11 @@ class TestFileLister: public TestFixture { public: TestFileLister() - :TestFixture("TestFileLister") - { + :TestFixture("TestFileLister") { } private: - void run() - { + void run() { // bail out if the tests are not executed from the base folder { std::ifstream fin("test/testfilelister.cpp"); @@ -53,15 +51,13 @@ private: TEST_CASE(recursiveAddFiles); } - void isDirectory() const - { + void isDirectory() const { ASSERT_EQUALS(false, FileLister::isDirectory("readme.txt")); ASSERT_EQUALS(true, FileLister::isDirectory("lib")); } #ifndef _WIN32 - void absolutePath() const - { + void absolutePath() const { std::vector current_dir; #ifdef PATH_MAX current_dir.resize(PATH_MAX); @@ -77,8 +73,7 @@ private: } #endif - void recursiveAddFiles() const - { + void recursiveAddFiles() const { // Recursively add add files.. std::map files; std::set extra; diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 48b19e52d..ce7c67a6e 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -27,14 +27,12 @@ extern std::ostringstream errout; class TestGarbage : public TestFixture { public: - TestGarbage() : TestFixture("TestGarbage") - { + TestGarbage() : TestFixture("TestGarbage") { } private: - void run() - { + void run() { // don't freak out when the syntax is wrong TEST_CASE(wrong_syntax1); TEST_CASE(wrong_syntax2); @@ -72,8 +70,7 @@ private: TEST_CASE(garbageAST); } - std::string checkCode(const char code[], const char filename[] = "test.cpp") - { + std::string checkCode(const char code[], const char filename[] = "test.cpp") { errout.str(""); Settings settings; @@ -104,8 +101,7 @@ private: return tokenizer.tokens()->stringifyList(false, false, false, true, false, 0, 0); } - void wrong_syntax1() - { + void wrong_syntax1() { { const char code[] ="TR(kvmpio, PROTO(int rw), ARGS(rw), TP_(aa->rw;))"; ASSERT_EQUALS("TR ( kvmpio , PROTO ( int rw ) , ARGS ( rw ) , TP_ ( aa . rw ; ) )", checkCode(code)); @@ -130,8 +126,7 @@ private: } } - void wrong_syntax2() // #3504 - { + void wrong_syntax2() { // #3504 const char code[] = "void f() {\n" " X x;\n" " Y y;\n" @@ -143,8 +138,7 @@ private: checkCode(code); } - void wrong_syntax3() // #3544 - { + void wrong_syntax3() { // #3544 const char code[] = "X #define\n" "{\n" " (\n" @@ -166,15 +160,13 @@ private: } } - void wrong_syntax4() // #3618 - { + void wrong_syntax4() { // #3618 const char code[] = "typedef void (x) (int); return x&"; ASSERT_THROW(checkCode(code), InternalError); } - void wrong_syntax_if_macro() - { + void wrong_syntax_if_macro() { // #2518 #4171 ASSERT_THROW(checkCode("void f() { if MACRO(); }"), InternalError); @@ -185,8 +177,7 @@ private: ASSERT_THROW(checkCode("void f() { if (x) MACRO() else ; }"), InternalError); } - void wrong_syntax_class_x_y() - { + void wrong_syntax_class_x_y() { // #3585 const char code[] = "class x y { };"; @@ -202,8 +193,7 @@ private: ASSERT_EQUALS("[test.c:1]: (information) The code 'class x y {' is not handled. You can use -I or --include to add handling of this code.\n", errout.str()); } - void syntax_case_default() - { + void syntax_case_default() { ASSERT_THROW(checkCode("void f() {switch (n) { case: z(); break;}}"), InternalError); ASSERT_THROW(checkCode("void f() {switch (n) { case;: z(); break;}}"), InternalError); @@ -223,45 +213,37 @@ private: ASSERT_THROW(checkCode("f ( ) { switch break; { switch ( x ) { case } case break; -6: ( ) ; } }"), InternalError); } - void garbageCode1() - { + void garbageCode1() { checkCode("struct x foo_t; foo_t typedef y;"); } - void garbageCode2() //#4300 (segmentation fault) - { + void garbageCode2() { //#4300 (segmentation fault) ASSERT_THROW(checkCode("enum { D = 1 struct { } ; } s.b = D;"), InternalError); } - void garbageCode3() //#4849 (segmentation fault in Tokenizer::simplifyStructDecl (invalid code)) - { + void garbageCode3() { //#4849 (segmentation fault in Tokenizer::simplifyStructDecl (invalid code)) ASSERT_THROW(checkCode("enum { D = 2 s ; struct y { x } ; } { s.a = C ; s.b = D ; }"), InternalError); } - void garbageCode4() // #4887 - { + void garbageCode4() { // #4887 ASSERT_THROW(checkCode("void f ( ) { = a ; if ( 1 ) if = ( 0 ) ; }"), InternalError); } - void garbageCode5() // #5168 - { + void garbageCode5() { // #5168 checkCode("( asm : ; void : );"); } - void garbageCode6() // #5214 - { + void garbageCode6() { // #5214 checkCode("int b = ( 0 ? ? ) 1 : 0 ;"); checkCode("int a = int b = ( 0 ? ? ) 1 : 0 ;"); } - void garbageCode7() - { + void garbageCode7() { ASSERT_THROW(checkCode("1 (int j) { return return (c) * sizeof } y[1];"), InternalError); checkCode("foo(Args&&...) fn void = { } auto template { { e = T::error }; };\n" "ScopedEnum1 se1; { enum class E : T { e = 0 = e ScopedEnum2 struct UnscopedEnum3 { T{ e = 4 }; };\n" @@ -273,72 +255,59 @@ private: "E::e; } int test2 = g(); }"), InternalError); } - void garbageCode9() - { + void garbageCode9() { ASSERT_THROW(checkCode("enum { e = { } } ( ) { { enum { } } } { e } "), InternalError); } - void garbageCode10() // #6127 - { + void garbageCode10() { // #6127 checkCode("for( rl=reslist; rl!=NULL; rl=rl->next )"); } - void garbageCode11() // do not crash - { + void garbageCode11() { // do not crash checkCode("( ) &"); } - void garbageCode12() // do not crash - { + void garbageCode12() { // do not crash checkCode("{ g; S (void) { struct } { } int &g; }"); } - void garbageCode13() - { + void garbageCode13() { checkCode("struct C {} {} x"); } - void garbageCode14() - { + void garbageCode14() { checkCode("static f() { int i; int source[1] = { 1 }; for (i = 0; i < 4; i++) (u, if (y u.x e)) }"); // Garbage code } - void garbageCode15() // Ticket #5203 - { + void garbageCode15() { // Ticket #5203 checkCode("int f ( int* r ) { { int s[2] ; f ( s ) ; if ( ) } }"); } - void garbageCode16() - { + void garbageCode16() { checkCode("{ } A() { delete }"); // #6080 } - void garbageCode17() - { + void garbageCode17() { ASSERT_THROW(checkCode("void h(int l) {\n" " while\n" // Don't crash (#3870) "}"), InternalError); } - void garbageCode18() - { + void garbageCode18() { ASSERT_THROW(checkCode("switch(){case}"), InternalError); } - void garbageCode19() - { + void garbageCode19() { // ticket #3512 - Don't crash on garbage code ASSERT_EQUALS("p = const", checkCode("1 *p = const")); } - void garbageCode20() - { + void garbageCode20() { // #3953 (valgrind errors on garbage code) ASSERT_EQUALS("void f ( 0 * ) ;", checkCode("void f ( 0 * ) ;")); } - void garbageCode21() - { + void garbageCode21() { // Ticket #3486 - Don't crash garbage code checkCode("void f()\n" "{\n" @@ -349,8 +318,7 @@ private: "}"); } - void garbageCode22() - { + void garbageCode22() { // Ticket #3480 - Don't crash garbage code ASSERT_THROW(checkCode("int f()\n" "{\n" @@ -358,8 +326,7 @@ private: "}"), InternalError); } - void garbageCode23() - { + void garbageCode23() { //garbage code : don't crash (#3481) checkCode("{\n" " if (1) = x\n" @@ -368,8 +335,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void garbageValueFlow() - { + void garbageValueFlow() { // #6089 const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n" "{\n" @@ -386,8 +352,7 @@ private: checkCode(code); } - void garbageSymbolDatabase() - { + void garbageSymbolDatabase() { checkCode("void f( { u = 1 ; } ) { }"); checkCode("{ }; void namespace A::f; { g() { int } }"); @@ -401,8 +366,7 @@ private: "} }"), InternalError); // #5663 } - void garbageAST() - { + void garbageAST() { checkCode("--"); // don't crash checkCode("N 1024 float a[N], b[N + 3], c[N]; void N; (void) i;\n" diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index bf4779d64..d15b281d3 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -31,13 +31,11 @@ extern std::ostringstream errout; class TestIncompleteStatement : public TestFixture { public: - TestIncompleteStatement() : TestFixture("TestIncompleteStatement") - { + TestIncompleteStatement() : TestFixture("TestIncompleteStatement") { } private: - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -55,8 +53,7 @@ private: checkOther.checkIncompleteStatement(); } - void run() - { + void run() { TEST_CASE(test1); TEST_CASE(test2); TEST_CASE(test3); @@ -76,8 +73,7 @@ private: TEST_CASE(block); // ({ do_something(); 0; }) } - void test1() - { + void test1() { check("void foo()\n" "{\n" " const char def[] =\n" @@ -87,8 +83,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void test2() - { + void test2() { check("void foo()\n" "{\n" " \"abc\";\n" @@ -97,8 +92,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with string constant.\n", errout.str()); } - void test3() - { + void test3() { check("void foo()\n" "{\n" " const char *str[] = { \"abc\" };\n" @@ -107,8 +101,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void test4() - { + void test4() { check("void foo()\n" "{\n" "const char *a =\n" @@ -122,8 +115,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void test5() - { + void test5() { check("void foo()\n" "{\n" " 50;\n" @@ -132,8 +124,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant code: Found a statement that begins with numeric constant.\n", errout.str()); } - void test6() - { + void test6() { // dont crash check("void f() {\n" " 1 == (two + three);\n" @@ -142,8 +133,7 @@ private: "}"); } - void test_numeric() - { + void test_numeric() { check("struct P\n" "{\n" "double a;\n" @@ -160,14 +150,12 @@ private: ASSERT_EQUALS("", errout.str()); } - void intarray() - { + void intarray() { check("int arr[] = { 100/2, 1*100 };"); ASSERT_EQUALS("", errout.str()); } - void structarraynull() - { + void structarraynull() { check("struct st arr[] = {\n" " { 100/2, 1*100 }\n" " { 90, 70 }\n" @@ -175,8 +163,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structarray() - { + void structarray() { check("struct st arr[] = {\n" " { 100/2, 1*100 }\n" " { 90, 70 }\n" @@ -184,16 +171,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void conditionalcall() - { + void conditionalcall() { check("void f() {\n" " 0==x ? X() : Y();\n" "}"); ASSERT_EQUALS("", errout.str()); } - void structinit() - { + void structinit() { // #2462 - C++11 struct initialization check("void f() {\n" " ABC abc{1,2,3};\n" @@ -225,8 +210,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void returnstruct() - { + void returnstruct() { check("struct s foo() {\n" " return (struct s){0,0};\n" "}"); @@ -242,16 +226,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void cast() - { + void cast() { check("void f() {\n" " ((struct foo *)(0x1234))->xy = 1;\n" "}"); ASSERT_EQUALS("", errout.str()); } - void increment() - { + void increment() { check("void f() {\n" " int x = 1;\n" " x++, x++;\n" @@ -259,16 +241,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void cpp11init() - { + void cpp11init() { check("void f() {\n" " int x{1};\n" "}"); ASSERT_EQUALS("", errout.str()); } - void block() - { + void block() { check("void f() {\n" " ({ do_something(); 0; });\n" "}"); diff --git a/test/testinternal.cpp b/test/testinternal.cpp index 6a600b86d..07161beea 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -27,13 +27,11 @@ extern std::ostringstream errout; class TestInternal : public TestFixture { public: - TestInternal() : TestFixture("TestInternal") - { + TestInternal() : TestFixture("TestInternal") { } private: - void run() - { + void run() { TEST_CASE(simplePatternInTokenMatch) TEST_CASE(complexPatternInTokenSimpleMatch) TEST_CASE(simplePatternSquareBrackets) @@ -46,8 +44,7 @@ private: TEST_CASE(orInComplexPattern); } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -65,8 +62,7 @@ private: checkInternal.runSimplifiedChecks(&tokenizer, &settings, this); } - void simplePatternInTokenMatch() - { + void simplePatternInTokenMatch() { check("void f() {\n" " const Token *tok;\n" " Token::Match(tok, \";\");\n" @@ -86,8 +82,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning) Found simple pattern inside Token::findmatch() call: \";\"\n", errout.str()); } - void complexPatternInTokenSimpleMatch() - { + void complexPatternInTokenSimpleMatch() { check("void f() {\n" " const Token *tok;\n" " Token::simpleMatch(tok, \"%type%\");\n" @@ -119,8 +114,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplePatternSquareBrackets() - { + void simplePatternSquareBrackets() { check("void f() {\n" " const Token *tok;\n" " Token::simpleMatch(tok, \"[\");\n" @@ -158,8 +152,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Found complex pattern inside Token::simpleMatch() call: \"[.,;]\"\n", errout.str()); } - void simplePatternAlternatives() - { + void simplePatternAlternatives() { check("void f() {\n" " const Token *tok;\n" " Token::simpleMatch(tok, \"||\");\n" @@ -191,8 +184,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void missingPercentCharacter() - { + void missingPercentCharacter() { check("void f() {\n" " const Token *tok;\n" " Token::Match(tok, \"%type%\");\n" @@ -250,8 +242,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void unknownPattern() - { + void unknownPattern() { check("void f() {\n" " Token::Match(tok, \"%typ%\");\n" "}"); @@ -264,8 +255,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void redundantNextPrevious() - { + void redundantNextPrevious() { check("void f() {\n" " return tok->next()->previous();\n" "}"); @@ -317,8 +307,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style) Call to 'Token::next()' followed by 'Token::str()' can be simplified.\n", errout.str()); } - void internalError() - { + void internalError() { // Make sure cppcheck does not raise an internal error of Token::Match ( Ticket #3727 ) check("class DELPHICLASS X;\n" "class Y {\n" @@ -334,8 +323,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void invalidMultiCompare() - { + void invalidMultiCompare() { // #5310 check("void f() {\n" " const Token *tok;\n" @@ -356,8 +344,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void orInComplexPattern() - { + void orInComplexPattern() { check("void f() {\n" " Token::Match(tok, \"||\");\n" "}"); diff --git a/test/testio.cpp b/test/testio.cpp index 2cb703bb1..1b2b767bb 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -25,15 +25,13 @@ extern std::ostringstream errout; class TestIO : public TestFixture { public: - TestIO() : TestFixture("TestIO") - { + TestIO() : TestFixture("TestIO") { } private: Settings settings; - void run() - { + void run() { LOAD_LIB_2(settings.library, "std.cfg"); LOAD_LIB_2(settings.library, "windows.cfg"); @@ -64,8 +62,7 @@ private: TEST_CASE(testTernary); // ticket #6182 } - void check(const char code[], bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified) - { + void check(const char code[], bool inconclusive = false, bool portability = false, Settings::PlatformType platform = Settings::Unspecified) { // Clear the error buffer.. errout.str(""); @@ -96,8 +93,7 @@ private: - void coutCerrMisusage() - { + void coutCerrMisusage() { check( "void foo() {\n" " std::cout << std::cout;\n" @@ -150,8 +146,7 @@ private: - void wrongMode_simple() - { + void wrongMode_simple() { // Read mode check("void foo(FILE*& f) {\n" " f = fopen(name, \"r\");\n" @@ -352,8 +347,7 @@ private: check("void fopen(std::string const &filepath, std::string const &mode);"); // #3832 } - void wrongMode_complex() - { + void wrongMode_complex() { check("void foo(FILE* f) {\n" " if(a) f = fopen(name, \"w\");\n" " else f = fopen(name, \"r\");\n" @@ -379,8 +373,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Read operation on a file that was opened only for writing.\n", errout.str()); } - void useClosedFile() - { + void useClosedFile() { check("void foo(FILE*& f) {\n" " fclose(f);\n" " fwrite(buffer, 5, 6, f);\n" @@ -505,8 +498,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Used file that is not opened.\n", errout.str()); } - void fileIOwithoutPositioning() - { + void fileIOwithoutPositioning() { check("void foo(FILE* f) {\n" " fwrite(buffer, 5, 6, f);\n" " fread(buffer, 5, 6, f);\n" @@ -563,8 +555,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour.\n", errout.str()); } - void seekOnAppendedFile() - { + void seekOnAppendedFile() { check("void foo() {\n" " FILE* f = fopen(\"\", \"a+\");\n" " fseek(f, 0, SEEK_SET);\n" @@ -590,8 +581,7 @@ private: ASSERT_EQUALS("", errout.str()); // #5578 } - void fflushOnInputStream() - { + void fflushOnInputStream() { check("void foo()\n" "{\n" " fflush(stdin);\n" @@ -625,8 +615,7 @@ private: - void testScanf1() - { + void testScanf1() { check("void foo() {\n" " int a, b;\n" " FILE *file = fopen(\"test\", \"r\");\n" @@ -644,8 +633,7 @@ private: "[test.cpp:8]: (warning) scanf without field width limits can crash with huge input data.\n", errout.str()); } - void testScanf2() - { + void testScanf2() { check("void foo() {\n" " scanf(\"%5s\", bar);\n" // Width specifier given " scanf(\"%5[^~]\", bar);\n" // Width specifier given @@ -657,8 +645,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (warning) scanf format string requires 0 parameters but 1 is given.\n", errout.str()); } - void testScanf3() - { + void testScanf3() { check("void foo() {\n" " scanf(\"%d\", &a);\n" " scanf(\"%n\", &a);\n" // No warning on %n, since it doesn't expect user input @@ -672,8 +659,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testScanf4() // ticket #2553 - { + void testScanf4() { // ticket #2553 check("void f()\n" "{\n" " char str [8];\n" @@ -685,8 +671,7 @@ private: - void testScanfArgument() - { + void testScanfArgument() { check("void foo() {\n" " scanf(\"%1d\", &foo);\n" " sscanf(bar, \"%1d\", &foo);\n" @@ -2286,8 +2271,7 @@ private: } - void testPrintfArgument() - { + void testPrintfArgument() { check("void foo() {\n" " printf(\"%u\");\n" " printf(\"%u%s\", 123);\n" @@ -3131,8 +3115,7 @@ private: } - void testPosixPrintfScanfParameterPosition() // #4900 - No support for parameters in format strings - { + void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings check("void foo() {" " int bar;" " printf(\"%1$d\", 1);" @@ -3156,8 +3139,7 @@ private: } - void testMicrosoftPrintfArgument() - { + void testMicrosoftPrintfArgument() { check("void foo() {\n" " size_t s;\n" " ptrdiff_t p;\n" @@ -3258,8 +3240,7 @@ private: } - void testMicrosoftScanfArgument() - { + void testMicrosoftScanfArgument() { check("void foo() {\n" " size_t s;\n" " ptrdiff_t p;\n" @@ -3336,8 +3317,7 @@ private: "[test.cpp:17]: (warning) 'I64' in format string (no. 1) is a length modifier and cannot be used without a conversion specifier.\n", errout.str()); } - void testMicrosoftCStringFormatArguments() // ticket #4920 - { + void testMicrosoftCStringFormatArguments() { // ticket #4920 check("void foo() {\n" " unsigned __int32 u32;\n" " String string;\n" @@ -3364,8 +3344,7 @@ private: "[test.cpp:5]: (warning) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'.\n", errout.str()); } - void testMicrosoftSecurePrintfArgument() - { + void testMicrosoftSecurePrintfArgument() { check("void foo() {\n" " int i;\n" " unsigned int u;\n" @@ -3555,8 +3534,7 @@ private: } - void testMicrosoftSecureScanfArgument() - { + void testMicrosoftSecureScanfArgument() { check("void foo() {\n" " int i;\n" " unsigned int u;\n" @@ -3688,8 +3666,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testTernary() // ticket #6182 - { + void testTernary() { // ticket #6182 check("void test(const std::string &val) {\n" " printf(\"%s\n\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n" "}\n"); diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index 893b3ecdf..cdc5a7612 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -26,14 +26,12 @@ extern std::ostringstream errout; class TestLeakAutoVar : public TestFixture { public: - TestLeakAutoVar() : TestFixture("TestLeakAutoVar") - { + TestLeakAutoVar() : TestFixture("TestLeakAutoVar") { } private: - void run() - { + void run() { // Assign TEST_CASE(assign1); TEST_CASE(assign2); @@ -115,8 +113,7 @@ private: TEST_CASE(nestedAllocation); } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -141,8 +138,7 @@ private: c.runSimplifiedChecks(&tokenizer, &settings, this); } - void checkcpp(const char code[]) - { + void checkcpp(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -167,8 +163,7 @@ private: c.runSimplifiedChecks(&tokenizer, &settings, this); } - void assign1() - { + void assign1() { check("void f() {\n" " char *p = malloc(10);\n" " p = NULL;\n" @@ -177,8 +172,7 @@ private: ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout.str()); } - void assign2() - { + void assign2() { check("void f() {\n" " char *p = malloc(10);\n" " char *q = p;\n" @@ -187,8 +181,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign3() - { + void assign3() { check("void f() {\n" " char *p = malloc(10);\n" " char *q = p + 1;\n" @@ -197,8 +190,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign4() - { + void assign4() { check("void f() {\n" " char *a = malloc(10);\n" " a += 10;\n" @@ -207,8 +199,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign5() - { + void assign5() { check("void foo()\n" "{\n" " char *p = new char[100];\n" @@ -217,8 +208,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign6() // #2806 - FP when there is redundant assignment - { + void assign6() { // #2806 - FP when there is redundant assignment check("void foo() {\n" " char *p = malloc(10);\n" " p = strcpy(p,q);\n" @@ -227,8 +217,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign7() - { + void assign7() { check("void foo(struct str *d) {\n" " struct str *p = malloc(10);\n" " d->p = p;\n" @@ -236,8 +225,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign8() // linux list - { + void assign8() { // linux list check("void foo(struct str *d) {\n" " struct str *p = malloc(10);\n" " d->p = &p->x;\n" @@ -245,8 +233,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign9() - { + void assign9() { check("void foo() {\n" " char *p = x();\n" " free(p);\n" @@ -255,8 +242,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign10() - { + void assign10() { check("void foo() {\n" " char *p;\n" " if (x) { p = malloc(10); }\n" @@ -266,8 +252,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign11() // #3942 - FP for x = a(b(p)); - { + void assign11() { // #3942 - FP for x = a(b(p)); check("void f() {\n" " char *p = malloc(10);\n" " x = a(b(p));\n" @@ -275,8 +260,7 @@ private: ASSERT_EQUALS("[test.c:4]: (information) --check-library: Function b() should have / configuration\n", errout.str()); } - void assign12() // #4236: FP. bar(&x) - { + void assign12() { // #4236: FP. bar(&x) check("void f() {\n" " char *p = malloc(10);\n" " free(p);\n" @@ -286,8 +270,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign13() // #4237: FP. char *&ref=p; p=malloc(10); free(ref); - { + void assign13() { // #4237: FP. char *&ref=p; p=malloc(10); free(ref); check("void f() {\n" " char *p;\n" " char * &ref = p;\n" @@ -297,8 +280,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void deallocuse1() - { + void deallocuse1() { check("void f(char *p) {\n" " free(p);\n" " *p = 0;\n" @@ -312,8 +294,7 @@ private: ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout.str()); } - void deallocuse2() - { + void deallocuse2() { check("void f(char *p) {\n" " free(p);\n" " strcpy(a, p);\n" @@ -327,8 +308,7 @@ private: TODO_ASSERT_EQUALS("", "[test.c:3]: (information) --check-library: Function strcpy() should have configuration\n", errout.str()); } - void deallocuse3() - { + void deallocuse3() { check("void f(struct str *p) {\n" " free(p);\n" " p = p->next;\n" @@ -336,8 +316,7 @@ private: ASSERT_EQUALS("[test.c:3]: (error) Dereferencing 'p' after it is deallocated / released\n", errout.str()); } - void deallocuse4() - { + void deallocuse4() { check("void f(char *p) {\n" " free(p);\n" " return p;\n" @@ -345,8 +324,7 @@ private: ASSERT_EQUALS("[test.c:3]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout.str()); } - void deallocuse5() // #4018 - { + void deallocuse5() { // #4018 check("void f(char *p) {\n" " free(p), p = 0;\n" " *p = 0;\n" // <- Make sure pointer info is reset. It is NOT a freed pointer dereference @@ -354,8 +332,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void deallocuse6() // #4034 - { + void deallocuse6() { // #4034 check("void f(char *p) {\n" " free(p);\n" " x = p = foo();\n" // <- p is not dereferenced @@ -363,8 +340,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void doublefree1() // #3895 - { + void doublefree1() { // #3895 check("void f(char *p) {\n" " if (x)\n" " free(p);\n" @@ -375,8 +351,7 @@ private: ASSERT_EQUALS("[test.c:6]: (error) Memory pointed to by 'p' is freed twice.\n", errout.str()); } - void doublefree2() // #3891 - { + void doublefree2() { // #3891 check("void *f(int a) {\n" " char *p = malloc(10);\n" " if (a == 2) { free(p); return ((void*)1); }\n" @@ -386,8 +361,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void doublefree3() // #4914 - { + void doublefree3() { // #4914 check("void foo() {\n" " bool done = false;\n" " do {\n" @@ -405,8 +379,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void doublefree4() // #5451 - exit - { + void doublefree4() { // #5451 - exit check("void f(char *p) {\n" " if (x) {\n" " free(p);\n" @@ -417,8 +390,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void exit1() - { + void exit1() { check("void f() {\n" " char *p = malloc(10);\n" " exit(0);\n" @@ -426,8 +398,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void exit2() - { + void exit2() { check("void f() {\n" " char *p = malloc(10);\n" " fatal_error();\n" @@ -437,8 +408,7 @@ private: errout.str()); } - void goto1() - { + void goto1() { check("static void f() {\n" " int err = -ENOMEM;\n" " char *reg = malloc(100);\n" @@ -449,8 +419,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void goto2() // #4231 - { + void goto2() { // #4231 check("static char * f() {\n" "x:\n" " char *p = malloc(100);\n" @@ -463,8 +432,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ifelse1() - { + void ifelse1() { check("int f() {\n" " char *p = NULL;\n" " if (x) { p = malloc(10); }\n" @@ -474,8 +442,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ifelse2() - { + void ifelse2() { check("int f() {\n" " char *p = NULL;\n" " if (x) { p = malloc(10); }\n" @@ -484,8 +451,7 @@ private: ASSERT_EQUALS("[test.c:5]: (error) Memory leak: p\n", errout.str()); } - void ifelse3() - { + void ifelse3() { check("void f() {\n" " char *p = malloc(10);\n" " if (!p) { return; }\n" @@ -509,8 +475,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ifelse4() - { + void ifelse4() { check("void f(int x) {\n" " char *p;\n" " if (x) { p = malloc(10); }\n" @@ -527,8 +492,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ifelse5() - { + void ifelse5() { check("void f() {\n" " char *p = malloc(10);\n" " if (!p && x) { p = malloc(10); }\n" @@ -537,8 +501,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ifelse6() // #3370 - { + void ifelse6() { // #3370 check("void f(int x) {\n" " int *a = malloc(20);\n" " if (x)\n" @@ -549,8 +512,7 @@ private: ASSERT_EQUALS("[test.c:6]: (error) Memory leak: a\n", errout.str()); } - void ifelse7() // #5576 - { + void ifelse7() { // #5576 check("void f() {\n" " int x = malloc(20);\n" " if (x < 0)\n" // assume negative value indicates its unallocated @@ -560,8 +522,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ifelse8() // #5747 - { + void ifelse8() { // #5747 check("void f() {\n" " int fd = socket(AF_INET, SOCK_PACKET, 0 );\n" " if (fd == -1)\n" @@ -570,8 +531,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void switch1() - { + void switch1() { check("void f() {\n" " char *p = 0;\n" " switch (x) {\n" @@ -583,8 +543,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void loop1() - { + void loop1() { // test the handling of { } check("void f() {\n" " char *p;\n" @@ -595,8 +554,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mismatch_fopen_free() - { + void mismatch_fopen_free() { check("void f() {\n" " FILE*f=fopen(fname,a);\n" " free(f);\n" @@ -604,8 +562,7 @@ private: ASSERT_EQUALS("[test.c:3]: (error) Mismatching allocation and deallocation: f\n", errout.str()); } - void return1() - { + void return1() { check("int f() {\n" " char *p = malloc(100);\n" " return 123;\n" @@ -613,8 +570,7 @@ private: ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout.str()); } - void return2() - { + void return2() { check("char *f() {\n" " char *p = malloc(100);\n" " return p;\n" @@ -622,8 +578,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void return3() - { + void return3() { check("struct dev * f() {\n" " struct ABC *abc = malloc(100);\n" " return &abc->dev;\n" @@ -631,8 +586,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void return4() // ticket #3862 - { + void return4() { // ticket #3862 // avoid false positives check("void f(char *p, int x) {\n" " if (x==12) {\n" @@ -662,16 +616,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void test1() // 3809 - { + void test1() { // 3809 check("void f(double*&p) {\n" " p = malloc(0x100);\n" "}"); ASSERT_EQUALS("", errout.str()); } - void test2() // 3899 - { + void test2() { // 3899 check("struct Fred {\n" " char *p;\n" " void f1() { free(p); }\n" @@ -679,8 +631,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void test3() // 3954 - reference pointer - { + void test3() { // 3954 - reference pointer check("void f() {\n" " char *&p = x();\n" " p = malloc(10);\n" @@ -688,8 +639,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void test4() // 5923 - static pointer - { + void test4() { // 5923 - static pointer check("void f() {\n" " static char *p;\n" " if (!p) p = malloc(10);\n" @@ -698,8 +648,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void test5() // unknown type - { + void test5() { // unknown type checkcpp("void f() { Fred *p = malloc(10); }"); ASSERT_EQUALS("", errout.str()); @@ -707,8 +656,7 @@ private: ASSERT_EQUALS("[test.c:1]: (error) Memory leak: p\n", errout.str()); } - void throw1() // 3987 - Execution reach a 'throw' - { + void throw1() { // 3987 - Execution reach a 'throw' check("void f() {\n" " char *p = malloc(10);\n" " throw 123;\n" @@ -726,8 +674,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void configuration1() - { + void configuration1() { // Possible leak => configuration is required for complete analysis // The user should be able to "white list" and "black list" functions. @@ -742,8 +689,7 @@ private: errout.str()); } - void configuration2() - { + void configuration2() { // possible leak. If the function 'x' deallocates the pointer or // takes the address, there is no leak. check("void f() {\n" @@ -755,8 +701,7 @@ private: errout.str()); } - void configuration3() - { + void configuration3() { check("void f() {\n" " char *p = malloc(10);\n" " if (set_data(p)) { }\n" @@ -772,8 +717,7 @@ private: , errout.str()); } - void configuration4() - { + void configuration4() { check("void f() {\n" " char *p = malloc(10);\n" " int ret = set_data(p);\n" @@ -782,16 +726,14 @@ private: ASSERT_EQUALS("[test.c:4]: (information) --check-library: Function set_data() should have / configuration\n", errout.str()); } - void ptrptr() - { + void ptrptr() { check("void f() {\n" " char **p = malloc(10);\n" "}"); ASSERT_EQUALS("[test.c:3]: (error) Memory leak: p\n", errout.str()); } - void nestedAllocation() - { + void nestedAllocation() { check("void QueueDSMCCPacket(unsigned char *data, int length) {\n" " unsigned char *dataCopy = malloc(length * sizeof(unsigned char));\n" " m_dsmccQueue.enqueue(new DSMCCPacket(dataCopy));\n" diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index ec573e35e..88336984d 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -28,8 +28,7 @@ public: private: - void run() - { + void run() { TEST_CASE(empty); TEST_CASE(function); TEST_CASE(function_arg); @@ -43,8 +42,7 @@ private: TEST_CASE(version); } - void empty() const - { + void empty() const { const char xmldata[] = "\n"; tinyxml2::XMLDocument doc; doc.Parse(xmldata, sizeof(xmldata)); @@ -56,8 +54,7 @@ private: ASSERT(library.argumentChecks.empty()); } - void function() const - { + void function() const { const char xmldata[] = "\n" "\n" " \n" @@ -75,8 +72,7 @@ private: ASSERT(library.isnotnoreturn("foo")); } - void function_arg() const - { + void function_arg() const { const char xmldata[] = "\n" "\n" " \n" @@ -99,8 +95,7 @@ private: ASSERT_EQUALS(true, library.argumentChecks["foo"][5].notbool); } - void function_arg_any() const - { + void function_arg_any() const { const char xmldata[] = "\n" "\n" "\n" @@ -115,8 +110,7 @@ private: ASSERT_EQUALS(true, library.argumentChecks["foo"][-1].notuninit); } - void function_arg_valid() const - { + void function_arg_valid() const { const char xmldata[] = "\n" "\n" " \n" @@ -166,8 +160,7 @@ private: ASSERT_EQUALS(false, library.isargvalid("foo", 5, 2)); } - void function_arg_minsize() const - { + void function_arg_minsize() const { const char xmldata[] = "\n" "\n" " \n" @@ -202,8 +195,7 @@ private: } } - void memory() const - { + void memory() const { const char xmldata[] = "\n" "\n" " \n" @@ -223,8 +215,7 @@ private: ASSERT(Library::ismemory(library.alloc("CreateX"))); ASSERT_EQUALS(library.alloc("CreateX"), library.dealloc("DeleteX")); } - void memory2() const - { + void memory2() const { const char xmldata1[] = "\n" "\n" " \n" @@ -248,8 +239,7 @@ private: ASSERT_EQUALS(library.dealloc("free"), library.alloc("foo")); } - void resource() const - { + void resource() const { const char xmldata[] = "\n" "\n" " \n" @@ -270,8 +260,7 @@ private: ASSERT_EQUALS(library.alloc("CreateX"), library.dealloc("DeleteX")); } - void podtype() const - { + void podtype() const { const char xmldata[] = "\n" "\n" " \n" @@ -287,8 +276,7 @@ private: ASSERT_EQUALS(0, type ? type->sign : '?'); } - void version() const - { + void version() const { { const char xmldata [] = "\n" "\n" diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index fc1360ca0..5fd5b782d 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -23,14 +23,12 @@ class TestMathLib : public TestFixture { public: - TestMathLib() : TestFixture("TestMathLib") - { + TestMathLib() : TestFixture("TestMathLib") { } private: - void run() - { + void run() { TEST_CASE(isint); TEST_CASE(isbin); TEST_CASE(isdec); @@ -58,49 +56,42 @@ private: TEST_CASE(abs); } - void isGreater() const - { + void isGreater() const { ASSERT_EQUALS(true , MathLib::isGreater("1.0", "0.001")); ASSERT_EQUALS(false, MathLib::isGreater("-1.0", "0.001")); } - void isGreaterEqual() const - { + void isGreaterEqual() const { ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.00", "1.0")); ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.001", "1.0")); ASSERT_EQUALS(true , MathLib::isGreaterEqual("1.0", "0.001")); ASSERT_EQUALS(false, MathLib::isGreaterEqual("-1.0", "0.001")); } - void isEqual() const - { + void isEqual() const { ASSERT_EQUALS(true , MathLib::isEqual("1.0", "1.0")); ASSERT_EQUALS(false , MathLib::isEqual("1.", "1.01")); ASSERT_EQUALS(true , MathLib::isEqual("0.1","1.0E-1")); } - void isNotEqual() const - { + void isNotEqual() const { ASSERT_EQUALS(false , MathLib::isNotEqual("1.0", "1.0")); ASSERT_EQUALS(true , MathLib::isNotEqual("1.", "1.01")); } - void isLess() const - { + void isLess() const { ASSERT_EQUALS(false , MathLib::isLess("1.0", "0.001")); ASSERT_EQUALS(true , MathLib::isLess("-1.0", "0.001")); } - void isLessEqual() const - { + void isLessEqual() const { ASSERT_EQUALS(true , MathLib::isLessEqual("1.00", "1.0")); ASSERT_EQUALS(false , MathLib::isLessEqual("1.001", "1.0")); ASSERT_EQUALS(false , MathLib::isLessEqual("1.0", "0.001")); ASSERT_EQUALS(true , MathLib::isLessEqual("-1.0", "0.001")); } - void calculate() const - { + void calculate() const { // addition ASSERT_EQUALS("256", MathLib::add("0xff", "1")); ASSERT_EQUALS("249", MathLib::add("250", "-1")); @@ -153,8 +144,7 @@ private: ASSERT_THROW(MathLib::calculate("1","2",'j'),InternalError); } - void calculate1() const - { + void calculate1() const { ASSERT_EQUALS("0" , MathLib::calculate("2" , "1" , '%')); ASSERT_EQUALS("0.0" , MathLib::calculate("2.0" , "1.0" , '%')); ASSERT_EQUALS("2" , MathLib::calculate("12" , "5" , '%')); @@ -169,8 +159,7 @@ private: ASSERT_EQUALS("3" , MathLib::calculate("2" , "1" , '^')); } - void convert() const - { + void convert() const { // ------------------ // tolong conversion: // ------------------ @@ -260,8 +249,7 @@ private: ASSERT_EQUALS("0.0" , MathLib::toString(MathLib::toDoubleNumber("+0.0"))); } - void isint() const - { + void isint() const { // zero tests ASSERT_EQUALS(true , MathLib::isInt("0")); ASSERT_EQUALS(false, MathLib::isInt("0.")); @@ -350,8 +338,7 @@ private: ASSERT_EQUALS(false, MathLib::isInt("")); } - void isbin() const - { + void isbin() const { // positive testing ASSERT_EQUALS(true, MathLib::isBin("0b0")); ASSERT_EQUALS(true, MathLib::isBin("0b1")); @@ -391,8 +378,7 @@ private: ASSERT_EQUALS(false, MathLib::isBin("")); } - void isnegative() const - { + void isnegative() const { ASSERT_EQUALS(true , MathLib::isNegative("-1")); ASSERT_EQUALS(true , MathLib::isNegative("-1.")); ASSERT_EQUALS(true , MathLib::isNegative("-1.0")); @@ -408,8 +394,7 @@ private: ASSERT_EQUALS(false, MathLib::isNegative("")); } - void isoct() const - { + void isoct() const { // octal number format: [+|-]0[0-7][suffix] // positive testing ASSERT_EQUALS(true, MathLib::isOct("010")); @@ -471,8 +456,7 @@ private: ASSERT_EQUALS(false, MathLib::isOct("+042LUL+0")); } - void ishex() const - { + void ishex() const { // hex number syntax: [sign]0x[hexnumbers][suffix] // positive testing @@ -534,8 +518,7 @@ private: ASSERT_EQUALS(false, MathLib::isHex("")); } - void isValidSuffix(void) - { + void isValidSuffix(void) { // negative testing std::string value = "ux"; ASSERT_EQUALS(false, MathLib::isValidSuffix(value.begin(), value.end())); @@ -605,8 +588,7 @@ private: ASSERT_EQUALS(true, MathLib::isValidSuffix(value.begin(), value.end())); } - void ispositive() const - { + void ispositive() const { ASSERT_EQUALS(false, MathLib::isPositive("-1")); ASSERT_EQUALS(false, MathLib::isPositive("-1.")); ASSERT_EQUALS(false, MathLib::isPositive("-1.0")); @@ -623,8 +605,7 @@ private: ASSERT_EQUALS(true, MathLib::isPositive("")); // because it has opposite result to MathLib::isNegative } - void isfloat() const - { + void isfloat() const { ASSERT_EQUALS(false, MathLib::isFloat("")); ASSERT_EQUALS(false, MathLib::isFloat(".")); ASSERT_EQUALS(false, MathLib::isFloat("...")); @@ -718,8 +699,7 @@ private: ASSERT_EQUALS(true , MathLib::isFloat("-1.0E+1")); } - void naninf() const - { + void naninf() const { ASSERT_EQUALS("nan.0", MathLib::divide("0.0", "0.0")); // nan ASSERT_EQUALS("nan.0", MathLib::divide("0.0", "0.f")); // nan (#5875) ASSERT_EQUALS("nan.0", MathLib::divide("-0.0", "0.f")); // nan (#5875) @@ -735,8 +715,7 @@ private: ASSERT_EQUALS("inf.0", MathLib::divide("-3.0", "-0.0f")); // inf (#5142) } - void isdec(void) - { + void isdec(void) { // positive testing ASSERT_EQUALS(true, MathLib::isDec("1")); ASSERT_EQUALS(true, MathLib::isDec("+1")); @@ -753,8 +732,7 @@ private: ASSERT_EQUALS(false, MathLib::isDec("x")); } - void isNullValue() const - { + void isNullValue() const { // inter zero value ASSERT_EQUALS(true, MathLib::isNullValue("0")); ASSERT_EQUALS(true, MathLib::isNullValue("+0")); @@ -923,8 +901,7 @@ private: ASSERT_EQUALS(false, MathLib::isNullValue("UL")); } - void incdec() - { + void incdec() { // increment { MathLib::biguint num = ~10U; @@ -945,20 +922,16 @@ private: ASSERT_THROW(MathLib::incdec("1", "x"), InternalError); // throw } - void sin() - { + void sin() { ASSERT_EQUALS("0.0" , MathLib::sin("0")); } - void cos() - { + void cos() { ASSERT_EQUALS("1.0" , MathLib::cos("0")); } - void tan() - { + void tan() { ASSERT_EQUALS("0.0" , MathLib::tan("0")); } - void abs() - { + void abs() { ASSERT_EQUALS("0.0" , MathLib::abs("0")); ASSERT_EQUALS("0.0" , MathLib::abs("+0")); ASSERT_EQUALS("0.0" , MathLib::abs("-0")); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 5213bd113..da221dfe5 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -31,19 +31,16 @@ extern std::ostringstream errout; class TestMemleak : private TestFixture { public: - TestMemleak() : TestFixture("TestMemleak") - { + TestMemleak() : TestFixture("TestMemleak") { } private: - void run() - { + void run() { TEST_CASE(testFunctionReturnType); TEST_CASE(open); } - CheckMemoryLeak::AllocType functionReturnType(const char code[]) - { + CheckMemoryLeak::AllocType functionReturnType(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -59,8 +56,7 @@ private: return c.functionReturnType(&tokenizer.getSymbolDatabase()->scopeList.front().functionList.front()); } - void testFunctionReturnType() - { + void testFunctionReturnType() { { const char code[] = "const char *foo()\n" "{ return 0; }"; @@ -89,8 +85,7 @@ private: } } - void open() - { + void open() { const char code[] = "class A {\n" " static int open() {\n" " return 1;\n" @@ -126,16 +121,14 @@ static TestMemleak testMemleak; class TestMemleakInFunction : public TestFixture { public: - TestMemleakInFunction() : TestFixture("TestMemleakInFunction") - { + TestMemleakInFunction() : TestFixture("TestMemleakInFunction") { } private: Settings settings1; Settings settings2; - void check(const char code[], const Settings *settings = nullptr) - { + void check(const char code[], const Settings *settings = nullptr) { // Clear the error buffer.. errout.str(""); @@ -155,8 +148,7 @@ private: } - void run() - { + void run() { LOAD_LIB_2(settings1.library, "std.cfg"); LOAD_LIB_2(settings1.library, "gtk.cfg"); LOAD_LIB_2(settings2.library, "std.cfg"); @@ -376,8 +368,7 @@ private: TEST_CASE(posixcfg); } - std::string getcode(const char code[], const char varname[], bool classfunc=false) - { + std::string getcode(const char code[], const char varname[], bool classfunc=false) { // Clear the error buffer.. errout.str(""); @@ -413,8 +404,7 @@ private: - void testgetcode() - { + void testgetcode() { // alloc; ASSERT_EQUALS(";;alloc;", getcode("int *a = malloc(100);", "a")); TODO_ASSERT_EQUALS(";;alloc;", ";;alloccallfunc;", getcode("int *a = ::malloc(100);", "a")); @@ -596,8 +586,7 @@ private: } - void call_func() const - { + void call_func() const { // whitelist.. ASSERT_EQUALS(true, CheckMemoryLeakInFunction::test_white_list("qsort")); ASSERT_EQUALS(true, CheckMemoryLeakInFunction::test_white_list("scanf")); @@ -652,8 +641,7 @@ private: } - std::string simplifycode(const char code[]) - { + std::string simplifycode(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -686,8 +674,7 @@ private: // Test that the CheckMemoryLeaksInFunction::simplifycode works - void simplifycode() - { + void simplifycode() { ASSERT_EQUALS(";", simplifycode("; ; ; ;")); ASSERT_EQUALS(";", simplifycode("; if ;")); ASSERT_EQUALS("alloc ;", simplifycode("alloc ; if ; if(var) ; ifv ; if(!var) ;")); @@ -823,8 +810,7 @@ private: // is there a leak in given code? if so, return the linenr - static unsigned int dofindleak(const char code[]) - { + static unsigned int dofindleak(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -858,8 +844,7 @@ private: return (tok ? tok->linenr() : (unsigned int)(-1)); } - void findleak() const - { + void findleak() const { static const unsigned int notfound = (unsigned int)(-1); ASSERT_EQUALS(1, dofindleak("alloc;")); @@ -910,8 +895,7 @@ private: } - void simple5() - { + void simple5() { check("static char *f()\n" "{\n" " struct *str = new strlist;\n" @@ -921,8 +905,7 @@ private: } - void simple7() - { + void simple7() { // A garbage collector may delete f automatically check("class Fred;\n" "void foo()\n" @@ -933,8 +916,7 @@ private: } - void simple9() - { + void simple9() { check("void foo()\n" "{\n" " MyClass *c = new MyClass();\n" @@ -944,8 +926,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simple11() - { + void simple11() { check("void Fred::aaa()\n" "{ }\n" "\n" @@ -986,8 +967,7 @@ private: - void new_nothrow() - { + void new_nothrow() { check("void f()\n" "{\n" " int *p = new(std::nothrow) int;\n" @@ -1057,8 +1037,7 @@ private: } - void staticvar() - { + void staticvar() { check("int f()\n" "{\n" " static char *s = 0;\n" @@ -1077,8 +1056,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void externvar() - { + void externvar() { check("void f()\n" "{\n" " extern char *s;\n" @@ -1087,8 +1065,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void referencevar() // 3954 - false positive for reference pointer - { + void referencevar() { // 3954 - false positive for reference pointer check("void f() {\n" " char *&x = get();\n" " x = malloc(100);\n" @@ -1097,8 +1074,7 @@ private: } - void alloc_alloc_1() - { + void alloc_alloc_1() { check("void foo()\n" "{\n" " char *str;\n" @@ -1109,8 +1085,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str()); } - void ifelse6() - { + void ifelse6() { check("static char *f()\n" "{\n" " char *s = new char[100];\n" @@ -1124,8 +1099,7 @@ private: } - void ifelse7() - { + void ifelse7() { check("static char *f()\n" "{\n" " char *s;\n" @@ -1139,8 +1113,7 @@ private: } - void ifelse8() - { + void ifelse8() { check("static char *f()\n" "{\n" " char *s = new char[10];\n" @@ -1153,8 +1126,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ifelse10() - { + void ifelse10() { Settings settings; settings.experimental = true; check("static char *f()\n" @@ -1174,8 +1146,7 @@ private: - void if4() - { + void if4() { check("void f()\n" "{\n" " char *s;\n" @@ -1198,8 +1169,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void if7() - { + void if7() { check("void f( bool b )\n" "{\n" " int *a=0;\n" @@ -1215,8 +1185,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void if8() - { + void if8() { check("static void f(int i)\n" "{\n" " char *c = malloc(50);\n" @@ -1249,8 +1218,7 @@ private: ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: c\n", errout.str()); } - void if9() - { + void if9() { check("static void f()\n" "{\n" " char *buf = NULL, *tmp;\n" @@ -1265,8 +1233,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void if10() - { + void if10() { check("static void f()\n" "{\n" " char *buf = malloc(10);\n" @@ -1279,8 +1246,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Common realloc mistake: \'buf\' nulled but not freed upon failure\n", errout.str()); } - void if11() - { + void if11() { Settings settings; settings.experimental = true; check("void foo()\n" @@ -1297,8 +1263,7 @@ private: } - void forwhile5() - { + void forwhile5() { check("void f(const char **a)\n" "{\n" " char *str = 0;\n" @@ -1312,8 +1277,7 @@ private: } - void forwhile6() - { + void forwhile6() { check("void f(const char **a)\n" "{\n" " char *str = 0;\n" @@ -1326,8 +1290,7 @@ private: } - void forwhile8() - { + void forwhile8() { check("char *f()\n" "{\n" " char *a = 0;\n" @@ -1352,8 +1315,7 @@ private: } - void forwhile9() - { + void forwhile9() { Settings settings; settings.experimental = true; check("char *f()\n" @@ -1375,8 +1337,7 @@ private: } - void forwhile10() - { + void forwhile10() { Settings settings; settings.experimental = true; check("char *f()\n" @@ -1399,8 +1360,7 @@ private: } - void forwhile11() - { + void forwhile11() { check("int main()\n" "{\n" " FILE *stream=NULL;\n" @@ -1414,8 +1374,7 @@ private: - void switch2() - { + void switch2() { check("void f()\n" "{\n" " char *str = new char[10];\n" @@ -1431,8 +1390,7 @@ private: ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: str\n", errout.str()); } - void switch3() - { + void switch3() { check("void f()\n" "{\n" " char *str = new char[10];\n" @@ -1449,8 +1407,7 @@ private: ASSERT_EQUALS("[test.cpp:9]: (error) Memory leak: str\n", errout.str()); } - void switch4() - { + void switch4() { // See tickets #2518 #2555 #4171 ASSERT_THROW(check("void f() {\n" " switch MAKEWORD(1)\n" @@ -1461,8 +1418,7 @@ private: "}"), InternalError); } - void ret5() - { + void ret5() { check("static char * f()\n" "{\n" " char *c = new char[50];\n" @@ -1471,8 +1427,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ret6() - { + void ret6() { check("void foo()\n" "{\n" " char *c = new char[50];\n" @@ -1481,8 +1436,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ret7() - { + void ret7() { check("void foo()\n" "{\n" " char *c = new char[50];\n" @@ -1491,8 +1445,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ret8() - { + void ret8() { check("char *foo()\n" "{\n" " char *c = new char[50];\n" @@ -1502,8 +1455,7 @@ private: } - void mismatch1() - { + void mismatch1() { Settings settings; settings.experimental = true; @@ -1530,8 +1482,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: a\n", errout.str()); } - void mismatch2() - { + void mismatch2() { check("void f()\n" "{\n" " FILE *fp;\n" @@ -1545,8 +1496,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mismatch3() - { + void mismatch3() { check("void f()\n" "{\n" " FILE *fp;\n" @@ -1560,8 +1510,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mismatch4() - { + void mismatch4() { check("void f()\n" "{\n" " char *p = 0;\n" @@ -1575,8 +1524,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Mismatching allocation and deallocation: p\n", errout.str()); } - void mismatch5() - { + void mismatch5() { check("void f() {\n" " C *c = new C;\n" " delete c;\n" @@ -1586,8 +1534,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mismatch6() // #4599 - { + void mismatch6() { // #4599 check("void test ( int do_gzip , const char * fn ) {\n" " FILE * f ;\n" " if ( do_gzip ) {\n" @@ -1603,8 +1550,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mismatchSize() - { + void mismatchSize() { check("void f(char *buf)\n" "{\n" " int i;\n" @@ -1629,8 +1575,7 @@ private: //////////////////////////////////////////////// - void func3() - { + void func3() { check("static void foo(const char *str)\n" "{ }\n" "\n" @@ -1643,8 +1588,7 @@ private: } - void func4() - { + void func4() { check("static void foo(char *str)\n" "{\n" " delete [] str;\n" @@ -1659,8 +1603,7 @@ private: } - void func5() - { + void func5() { Settings settings; settings.experimental = true; @@ -1679,8 +1622,7 @@ private: } - void func6() - { + void func6() { check("static void foo(char *str)\n" "{\n" " goto abc;\n" @@ -1695,8 +1637,7 @@ private: } - void func7() - { + void func7() { check("static void foo(char *str)\n" "{\n" " if (abc)\n" @@ -1714,8 +1655,7 @@ private: } - void func9() - { + void func9() { check("int b()\n" "{\n" " return 0;\n" @@ -1731,8 +1671,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func10() - { + void func10() { check("static void f(void (*fnc)(char*))\n" "{\n" " char *c = malloc(50);\n" @@ -1741,8 +1680,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func11() - { + void func11() { check("static void f(struct1 *s1)\n" "{\n" " char *c = malloc(50);\n" @@ -1751,8 +1689,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func12() - { + void func12() { check("void add_list(struct mmtimer *n)\n" "{\n" " rb_link_node(&n->list, parent, link);\n" @@ -1771,8 +1708,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func13() - { + void func13() { check("static void f()\n" "{\n" " char *p = malloc(100);\n" @@ -1781,8 +1717,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func14() - { + void func14() { // It is not known what the "foo" that only takes one parameter does.. check("static void foo(char *a, char *b)\n" "{\n" @@ -1810,8 +1745,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func15() - { + void func15() { check("static void a()\n" "{ return true; }\n" "\n" @@ -1834,8 +1768,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: p\n", errout.str()); } - void func16() - { + void func16() { check("static void a( bo_t *p_bo)\n" "{\n" " p_bo->buffer = realloc( p_bo->buffer, 100 );\n" @@ -1855,8 +1788,7 @@ private: } - void func17() - { + void func17() { // The "bar" function must be reduced to "use" check("bool bar(char **parent, char *res, bool a)\n" @@ -1881,8 +1813,7 @@ private: } - void func18() - { + void func18() { // No false positive // The "free_pointers" will deallocate all pointers check("static void free_pointers(int arg_count, ...)\n" @@ -1931,8 +1862,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func19() - { + void func19() { // Ticket #2056 check("bool a(int *p) {\n" " return p;\n" @@ -1956,8 +1886,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func20() - { + void func20() { // Ticket #2182 - false positive when there is unused class. // If the unused class is removed the false positive goes away. // [test.cpp:12]: (error) Deallocating a deallocated pointer: p @@ -1994,8 +1923,7 @@ private: } //# Ticket 2569 - void func21() - { + void func21() { // checking for lstat function: // ---------------------------- check("void foo ()\n" @@ -2288,8 +2216,7 @@ private: } // # 2668 - void func22() - { + void func22() { check("void foo()\n" "{\n" " char * cpFile;\n" @@ -2335,8 +2262,7 @@ private: } // # 2667 - void func23() - { + void func23() { // check open() function // ---------------------- @@ -2431,8 +2357,7 @@ private: } // #2705 - void func24() - { + void func24() { check("void f(void)\n" "{\n" " std::string *x = new std::string;\n" @@ -2447,8 +2372,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func25() // ticket #2904 - { + void func25() { // ticket #2904 check("class Fred { };\n" "void f(void)\n" "{\n" @@ -2480,8 +2404,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: f\n", errout.str()); } - void func26() // ticket #3444 - { + void func26() { // ticket #3444 // technically there is a leak here. However warning is not wanted check("void f() {\n" " char *p = strdup(\"A=B\");\n" @@ -2490,8 +2413,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void func27() // ticket #2773 - { + void func27() { // ticket #2773 check("void f(FRED *pData)\n" "{\n" " pData =(FRED*)malloc( 100 );\n" @@ -2505,8 +2427,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: pData\n", errout.str()); } - void func28() // ticket #3236 - { + void func28() { // ticket #3236 check("void f()\n" "{\n" " my_struct *p = malloc(42);\n" @@ -2515,8 +2436,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); } - void allocfunc1() - { + void allocfunc1() { check("static char *a()\n" "{\n" " return new char[100];\n" @@ -2548,8 +2468,7 @@ private: ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str()); } - void allocfunc2() - { + void allocfunc2() { check("static char *a(int size)\n" "{\n" " return new char[size];\n" @@ -2599,8 +2518,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void allocfunc3() - { + void allocfunc3() { check("static char *a()\n" "{\n" " char *data = malloc(10);;" @@ -2613,8 +2531,7 @@ private: ASSERT_EQUALS(std::string("[test.cpp:8]: (error) Memory leak: p\n"), errout.str()); } - void allocfunc4() - { + void allocfunc4() { check("char* foo()\n" "{\n" " char *str = NULL;\n" @@ -2643,8 +2560,7 @@ private: ASSERT_EQUALS(std::string("[test.cpp:11]: (error) Mismatching allocation and deallocation: p\n"), errout.str()); } - void allocfunc5() - { + void allocfunc5() { check("void foo(char **str)\n" "{\n" " *str = malloc(20);\n" @@ -2746,8 +2662,7 @@ private: } - void allocfunc6() - { + void allocfunc6() { check("static FILE* data()\n" "{\n" " return fopen(\"data.txt\",\"rt\");\n" @@ -2783,8 +2698,7 @@ private: } - void allocfunc7() - { + void allocfunc7() { // Ticket #2374 - no false positive check("char *data()\n" "{\n" @@ -2800,8 +2714,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void allocfunc8() - { + void allocfunc8() { // Ticket #2213 - calling alloc function twice check("FILE *foo() {\n" " return fopen(a,b);\n" @@ -2815,8 +2728,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Resource leak: f\n", errout.str()); } - void allocfunc9() - { + void allocfunc9() { // Ticket #2673 - address is taken in alloc func check("char *addstring(const char *s) {\n" " char *ret = strdup(s);\n" @@ -2830,8 +2742,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void allocfunc10() - { + void allocfunc10() { // Ticket #2921 - static pointer check("char *getstr() {\n" " static char *ret = malloc(100);\n" @@ -2844,16 +2755,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void allocfunc11() // ticket #3809 - false positive - { + void allocfunc11() { // ticket #3809 - false positive check("void f (double * & data_val) {\n" " data_val = malloc(0x100);\n" "}"); ASSERT_EQUALS("", errout.str()); } - void allocfunc12() // #3660: allocating and returning non-local pointer => not allocfunc - { + void allocfunc12() { // #3660: allocating and returning non-local pointer => not allocfunc check("char *p;\n" // global pointer "char *a() {\n" " if (!p) p = malloc(10);\n" @@ -2865,8 +2774,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void allocfunc13() // #4494: class function - { + void allocfunc13() { // #4494: class function check("namespace n {\n" " char *a() { return malloc(100); }\n" "}\n" @@ -2898,8 +2806,7 @@ private: ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: a\n", errout.str()); } - void throw1() - { + void throw1() { check("void foo()\n" "{\n" " char *str = new char[10];\n" @@ -2911,8 +2818,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str()); } - void throw2() - { + void throw2() { check("void foo()\n" "{\n" " char *str = 0;\n" @@ -2935,8 +2841,7 @@ private: - void linux_list_1() - { + void linux_list_1() { check("struct AB\n" "{\n" " int a;\n" @@ -2951,8 +2856,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void linux_list_2() // #5993 - { + void linux_list_2() { // #5993 check("void foo() {\n" " struct AB *ab = malloc(sizeof(struct AB));\n" " list_add_tail(&(ab->list));\n" @@ -2962,8 +2866,7 @@ private: - void sizeof1() - { + void sizeof1() { check("void f()\n" "{\n" " struct s_t s1;\n" @@ -3005,8 +2908,7 @@ private: } - void realloc1() - { + void realloc1() { check("void foo()\n" "{\n" " char *a = (char *)malloc(10);\n" @@ -3016,8 +2918,7 @@ private: "[test.cpp:5]: (error) Memory leak: a\n", errout.str()); } - void realloc2() - { + void realloc2() { check("void foo()\n" "{\n" " char *a = (char *)malloc(10);\n" @@ -3028,8 +2929,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Common realloc mistake: \'a\' nulled but not freed upon failure\n", errout.str()); } - void realloc3() - { + void realloc3() { check("void foo()\n" "{\n" " char *a = 0;\n" @@ -3041,8 +2941,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc4() - { + void realloc4() { check("void foo()\n" "{\n" " static char *a = 0;\n" @@ -3057,8 +2956,7 @@ private: errout.str()); } - void realloc5() - { + void realloc5() { check("void foo()\n" "{\n" " char *buf;\n" @@ -3073,14 +2971,12 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc6() - { + void realloc6() { ASSERT_EQUALS(";;realloc;;", getcode("char *buf; buf=realloc(buf,100);", "buf")); ASSERT_EQUALS(";;alloc;", getcode("char *buf; buf=realloc(0,100);", "buf")); } - void realloc7() - { + void realloc7() { check("bool foo(size_t nLen, char* pData)\n" "{\n" " pData = (char*) realloc(pData, sizeof(char) + (nLen + 1)*sizeof(char));\n" @@ -3094,8 +2990,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc8() - { + void realloc8() { check("void foo()\n" "{\n" " char *origBuf = m_buf;\n" @@ -3107,8 +3002,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc9() - { + void realloc9() { check("void foo()\n" "{\n" " x = realloc(x,100);\n" @@ -3116,8 +3010,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc10() - { + void realloc10() { check("void foo() {\n" " char *pa, *pb;\n" " pa = pb = malloc(10);\n" @@ -3127,8 +3020,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc11() - { + void realloc11() { check("void foo() {\n" " char *p;\n" " p = realloc(p, size);\n" @@ -3139,8 +3031,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc12() - { + void realloc12() { check("void foo(int x)\n" "{\n" " char *a = 0;\n" @@ -3151,8 +3042,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc13() - { + void realloc13() { check("void foo()\n" "{\n" " char **str;\n" @@ -3162,8 +3052,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Common realloc mistake: \'str\' nulled but not freed upon failure\n", errout.str()); } - void realloc14() - { + void realloc14() { check("void foo() {\n" " char *p;\n" " p = realloc(p, size + 1);\n" @@ -3174,8 +3063,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void realloc15() - { + void realloc15() { check("bool foo() {\n" " char ** m_options;\n" " m_options = (char**)realloc( m_options, 2 * sizeof(char*));\n" @@ -3187,8 +3075,7 @@ private: "[test.cpp:6]: (error) Memory leak: m_options\n", errout.str()); } - void realloc16() - { + void realloc16() { check("void f(char *zLine) {\n" " zLine = realloc(zLine, 42);\n" " if (zLine) {\n" @@ -3198,8 +3085,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign1() - { + void assign1() { check("void foo()\n" "{\n" " char *a = (char *)malloc(10);\n" @@ -3294,8 +3180,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign2() - { + void assign2() { // #2806 - FP when there is redundant assignment check("void foo() {\n" " gchar *bar;\n" @@ -3306,8 +3191,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varid() - { + void varid() { check("void foo()\n" "{\n" " char *p = malloc(100);\n" @@ -3330,8 +3214,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void cast1() - { + void cast1() { check("void foo()\n" "{\n" " char *a = reinterpret_cast(malloc(10));\n" @@ -3348,8 +3231,7 @@ private: - void dealloc_use() - { + void dealloc_use() { // It is ok to take the address.. check("void f()\n" "{\n" @@ -3483,8 +3365,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void dealloc_use_2() - { + void dealloc_use_2() { // #3041 - assigning pointer when it's used check("void f(char *s) {\n" " free(s);\n" @@ -3498,8 +3379,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void dealloc_use_3() - { + void dealloc_use_3() { check("void foo()\n" "{\n" " char *str = malloc(10);\n" @@ -3517,8 +3397,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Dereferencing 'str' after it is deallocated / released\n", errout.str()); } - void freefree1() - { + void freefree1() { check("void foo()\n" "{\n" " char *str = malloc(100);\n" @@ -3535,8 +3414,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Deallocating a deallocated pointer: str\n", errout.str()); } - void freefree2() - { + void freefree2() { check("void foo()\n" "{\n" " FILE *fd = fopen(\"test.txt\", \"wb\");\n" @@ -3546,8 +3424,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void freefree3() - { + void freefree3() { check("void foo()\n" "{\n" " char *p = malloc(10);\n" @@ -3566,8 +3443,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void strcpy_result_assignment() - { + void strcpy_result_assignment() { check("void foo()\n" "{\n" " char *p1 = malloc(10);\n" @@ -3582,8 +3458,7 @@ private: TODO_ASSERT_EQUALS("", "[test.cpp:5]: (error) Memory leak: p1\n", errout.str()); } - void strcat_result_assignment() - { + void strcat_result_assignment() { check("void foo()\n" "{\n" " char *p = malloc(10);\n" @@ -3606,8 +3481,7 @@ private: - void all1() - { + void all1() { check("void foo()\n" "{\n" " Fred *f = new Fred;\n" @@ -3617,8 +3491,7 @@ private: - void malloc_constant_1() - { + void malloc_constant_1() { check("void foo()\n" "{\n" " int *p = malloc(3);\n" @@ -3636,8 +3509,7 @@ private: - void unknownFunction1() - { + void unknownFunction1() { check("void foo()\n" "{\n" " int *p = new int[100];\n" @@ -3651,8 +3523,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void unknownFunction2() - { + void unknownFunction2() { check("void foo()\n" "{\n" " int *p = new int[100];\n" @@ -3673,8 +3544,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str()); } - void unknownFunction4() - { + void unknownFunction4() { check("void foo()\n" "{\n" " int *p = new int[100];\n" @@ -3685,8 +3555,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); } - void unknownFunction5() - { + void unknownFunction5() { check("static void foo()\n" "{\n" " char *p = NULL;\n" @@ -3718,8 +3587,7 @@ private: } - void class1() - { + void class1() { check("class Fred\n" "{\n" "public:\n" @@ -3731,8 +3599,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Memory leak: p\n", errout.str()); } - void class2() - { + void class2() { check("class Fred {\n" "public:\n" " Fred() : rootNode(0) {}\n" @@ -3763,8 +3630,7 @@ private: } - void autoptr1() - { + void autoptr1() { check("std::auto_ptr foo()\n" "{\n" " int *i = new int;\n" @@ -3773,8 +3639,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void if_with_and() - { + void if_with_and() { Settings settings; settings.experimental = true; @@ -3799,8 +3664,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign_pclose() - { + void assign_pclose() { Settings settings; settings.standards.posix = true; @@ -3812,8 +3676,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void exit2() - { + void exit2() { check("void f()\n" "{\n" " char *out = new char[100];\n" @@ -3830,8 +3693,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void exit4() - { + void exit4() { check("void f()\n" "{\n" " char *p = malloc(100);\n" @@ -3843,8 +3705,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n", errout.str()); } - void exit5() - { + void exit5() { check("void f()\n" "{\n" " char *p = malloc(100);\n" @@ -3857,8 +3718,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void exit6() - { + void exit6() { check("int main(int argc, char *argv[]) {\n" " FILE *sfile;\n" " unsigned long line;\n" @@ -3876,8 +3736,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void exit7() - { + void exit7() { check("int a(int x) {\n" " if (x == 0) {\n" " exit(0);\n" @@ -3892,8 +3751,7 @@ private: ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: p\n", errout.str()); } - void noreturn() - { + void noreturn() { check("void fatal_error()\n" "{ exit(1); }\n" "\n" @@ -3917,8 +3775,7 @@ private: - void stdstring() - { + void stdstring() { check("void f(std::string foo)\n" "{\n" " char *out = new char[11];\n" @@ -3928,8 +3785,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: out\n", errout.str()); } - void strndup_function() - { + void strndup_function() { check("void f()\n" "{\n" " char *out = strndup(\"text\", 3);\n" @@ -3937,8 +3793,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: out\n", errout.str()); } - void tmpfile_function() - { + void tmpfile_function() { check("void f()\n" "{\n" " FILE *f = tmpfile();\n" @@ -3976,8 +3831,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void fcloseall_function() - { + void fcloseall_function() { check("void f()\n" "{\n" " FILE *f = fopen(fname, str);\n" @@ -3993,8 +3847,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void open_function() - { + void open_function() { Settings settings; settings.experimental = true; settings.standards.posix = true; @@ -4033,8 +3886,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void creat_function() - { + void creat_function() { Settings settings; settings.standards.posix = true; check("void f(const char *path)\n" @@ -4044,8 +3896,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Resource leak: fd\n", errout.str()); } - void close_function() - { + void close_function() { Settings settings; settings.standards.posix = true; check("void f(const char *path)\n" @@ -4107,8 +3958,7 @@ private: ASSERT_EQUALS("[test.cpp:11]: (error) Resource leak: handle\n", errout.str()); } - void fd_functions() - { + void fd_functions() { Settings settings; settings.standards.posix = true; check("void f(const char *path)\n" @@ -4138,8 +3988,7 @@ private: ASSERT_EQUALS("[test.cpp:24]: (error) Resource leak: fd\n", errout.str()); } - void file_functions() - { + void file_functions() { check("void f()\n" "{\n" "FILE *f = fopen(fname, str);\n" @@ -4165,8 +4014,7 @@ private: ASSERT_EQUALS("[test.cpp:22]: (error) Resource leak: f\n", errout.str()); } - void getc_function() - { + void getc_function() { { check("void f()\n" "{" @@ -4189,8 +4037,7 @@ private: } } - void pointer_to_pointer() - { + void pointer_to_pointer() { check("void f(char **data)\n" "{\n" " char *c = new char[12];\n" @@ -4200,8 +4047,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void dealloc_and_alloc_in_func() - { + void dealloc_and_alloc_in_func() { check("char *f( const char *x )\n" "{\n" " delete [] x;\n" @@ -4220,8 +4066,7 @@ private: } - void unknownSyntax1() - { + void unknownSyntax1() { // I don't know what this syntax means so cppcheck should bail out check("void foo()\n" "{\n" @@ -4251,8 +4096,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void knownFunctions() - { + void knownFunctions() { check("void foo()\n" "{\n" " int *p = new int[100];\n" @@ -4261,8 +4105,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str()); } - void same_function_name() - { + void same_function_name() { check("void a(char *p)\n" "{ }\n" "void b()\n" @@ -4273,8 +4116,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void functionParameter() - { + void functionParameter() { check("void a(char *p)\n" "{\n" " p = malloc(100);\n" @@ -4283,8 +4125,7 @@ private: } // Ticket #2014 - setjmp / longjmp - void jmp() - { + void jmp() { check("int main()\n" "{\n" " jmp_buf env;\n" @@ -4306,8 +4147,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void trac1949() - { + void trac1949() { check("int fn()\n" "{\n" " char * buff = new char[100];\n" @@ -4318,8 +4158,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: buff\n", errout.str()); } - void trac2540() - { + void trac2540() { check("void f()\n" "{\n" " char* str = strdup(\"abc def\");\n" @@ -4335,8 +4174,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: str\n", errout.str()); } - void trac2662() - { + void trac2662() { // segfault because of endless recursion // call_func -> getAllocationType -> functionReturnType -> call_func .. @@ -4372,8 +4210,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void trac1879() - { + void trac1879() { // #1879 non regression test case check("void test() {\n" "int *a = new int[10];\n" @@ -4383,8 +4220,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: a\n", errout.str()); } - void ptrptr() - { + void ptrptr() { check("void f() {\n" " char *p;\n" " char **pp = &p;\n" @@ -4395,8 +4231,7 @@ private: // Test that posix.cfg is configured correctly - void posixcfg() - { + void posixcfg() { Settings settings; settings.standards.posix = true; LOAD_LIB_2(settings.library, "posix.cfg"); @@ -4468,8 +4303,7 @@ static TestMemleakInFunction testMemleakInFunction; class TestMemleakInClass : public TestFixture { public: - TestMemleakInClass() : TestFixture("TestMemleakInClass") - { + TestMemleakInClass() : TestFixture("TestMemleakInClass") { } private: @@ -4477,8 +4311,7 @@ private: * Tokenize and execute leak check for given code * @param code Source code */ - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -4497,8 +4330,7 @@ private: checkMemoryLeak.check(); } - void run() - { + void run() { TEST_CASE(class1); TEST_CASE(class2); TEST_CASE(class3); @@ -4537,8 +4369,7 @@ private: } - void class1() - { + void class1() { check("class Fred\n" "{\n" "private:\n" @@ -4580,8 +4411,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); } - void class2() - { + void class2() { check("class Fred\n" "{\n" "private:\n" @@ -4653,8 +4483,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:12]: (error) Mismatching allocation and deallocation: Fred::str1\n", "", errout.str()); } - void class3() - { + void class3() { check("class Token;\n" "\n" "class Tokenizer\n" @@ -4720,8 +4549,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class4() - { + void class4() { check("struct ABC;\n" "class Fred\n" "{\n" @@ -4761,8 +4589,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class6() - { + void class6() { check("class Fred\n" "{\n" "public:\n" @@ -4790,8 +4617,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class7() - { + void class7() { check("class Fred\n" "{\n" "public:\n" @@ -4826,8 +4652,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class8() - { + void class8() { check("class A\n" "{\n" "public:\n" @@ -4857,8 +4682,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class9() - { + void class9() { check("class A\n" "{\n" "public:\n" @@ -4886,8 +4710,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class10() - { + void class10() { check("class A\n" "{\n" "public:\n" @@ -4907,8 +4730,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); } - void class11() - { + void class11() { check("class A\n" "{\n" "public:\n" @@ -4929,8 +4751,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); } - void class12() - { + void class12() { check("class A\n" "{\n" "private:\n" @@ -4966,8 +4787,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); } - void class13() - { + void class13() { check("class A\n" "{\n" "private:\n" @@ -5003,8 +4823,7 @@ private: ASSERT_EQUALS("[test.cpp:11]: (warning) Possible leak in public function. The pointer 'p' is not deallocated before it is allocated.\n", errout.str()); } - void class14() - { + void class14() { check("class A\n" "{\n" " int *p;\n" @@ -5074,8 +4893,7 @@ private: "[test.cpp:3]: (style) Class 'A' is unsafe, 'A::p' can leak by wrong usage.\n", errout.str()); } - void class15() - { + void class15() { check("class A\n" "{\n" " int *p;\n" @@ -5161,8 +4979,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class16() - { + void class16() { // Ticket #1510 check("class A\n" "{\n" @@ -5175,8 +4992,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class17() - { + void class17() { // Ticket #1557 check("class A {\n" "private:\n" @@ -5219,8 +5035,7 @@ private: ASSERT_EQUALS("[test.cpp:9]: (warning) Possible leak in public function. The pointer 'pd' is not deallocated before it is allocated.\n", errout.str()); } - void class18() - { + void class18() { // Ticket #853 check("class A : public x\n" "{\n" @@ -5250,8 +5065,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class19() - { + void class19() { // Ticket #2219 check("class Foo\n" "{\n" @@ -5308,8 +5122,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class20() - { + void class20() { check("namespace ns1 {\n" " class Fred\n" " {\n" @@ -5430,8 +5243,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (style) Class 'Fred' is unsafe, 'Fred::str1' can leak by wrong usage.\n", errout.str()); } - void class21() // ticket #2517 - { + void class21() { // ticket #2517 check("struct B { };\n" "struct C\n" "{\n" @@ -5469,8 +5281,7 @@ private: "[test.cpp:10]: (style) Class 'A' is unsafe, 'A::c' can leak by wrong usage.\n", errout.str()); } - void class22() // ticket #3012 - false positive - { + void class22() { // ticket #3012 - false positive check("class Fred {\n" "private:\n" " int * a;\n" @@ -5481,8 +5292,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class23() // ticket #3303 - false positive - { + void class23() { // ticket #3303 - false positive check("class CDataImpl {\n" "public:\n" " CDataImpl() { m_refcount = 1; }\n" @@ -5501,8 +5311,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class24() // ticket #3806 - false positive in copy constructor - { + void class24() { // ticket #3806 - false positive in copy constructor check("class Fred {\n" "private:\n" " int * a;\n" @@ -5513,8 +5322,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void class25() // ticket #4367 - false positive when implementation for destructor is not seen - { + void class25() { // ticket #4367 - false positive when implementation for destructor is not seen check("class Fred {\n" "private:\n" " int * a;\n" @@ -5525,8 +5333,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void staticvar() - { + void staticvar() { check("class A\n" "{\n" "private:\n" @@ -5542,8 +5349,7 @@ private: } - void free_member_in_sub_func() - { + void free_member_in_sub_func() { // Member function check("class Tokenizer\n" "{\n" @@ -5601,8 +5407,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mismatch1() - { + void mismatch1() { check("class A\n" "{\n" "public:\n" @@ -5627,8 +5432,7 @@ private: ASSERT_EQUALS("[test.cpp:14]: (error) Mismatching allocation and deallocation: A::pkt_buffer\n", errout.str()); } - void mismatch2() // #5659 - { + void mismatch2() { // #5659 check("namespace NS\n" "{\n" "class Foo\n" @@ -5676,8 +5480,7 @@ private: "[test.cpp:18]: (error) Mismatching allocation and deallocation: Foo::data_\n", errout.str()); } - void func1() - { + void func1() { check("class Fred\n" "{\n" "private:\n" @@ -5725,8 +5528,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:7]: (warning) Possible leak in public function. The pointer 's' is not deallocated before it is allocated.\n", "", errout.str()); } - void func2() - { + void func2() { check("class Fred\n" "{\n" "private:\n" @@ -5762,13 +5564,11 @@ static TestMemleakInClass testMemleakInClass; class TestMemleakStructMember : public TestFixture { public: - TestMemleakStructMember() : TestFixture("TestMemleakStructMember") - { + TestMemleakStructMember() : TestFixture("TestMemleakStructMember") { } private: - void check(const char code[], const char fname[] = 0, bool isCPP = true) - { + void check(const char code[], const char fname[] = 0, bool isCPP = true) { // Clear the error buffer.. errout.str(""); @@ -5785,8 +5585,7 @@ private: checkMemoryLeakStructMember.check(); } - void run() - { + void run() { // testing that errors are detected TEST_CASE(err); @@ -5829,8 +5628,7 @@ private: TEST_CASE(varid_2); // #5315: Analysis confused by ((variable).attribute) notation } - void err() - { + void err() { check("static void foo()\n" "{\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" @@ -5908,8 +5706,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: abc.a\n", "", errout.str()); } - void goto_() - { + void goto_() { check("static void foo()\n" "{\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" @@ -5938,8 +5735,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ret1() - { + void ret1() { check("static ABC * foo()\n" "{\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" @@ -5967,8 +5763,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ret2() - { + void ret2() { check("static ABC * foo()\n" "{\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" @@ -5985,8 +5780,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign1() - { + void assign1() { check("static void foo()\n" "{\n" " struct ABC *abc = abc1;\n" @@ -6035,8 +5829,7 @@ private: } - void assign2() - { + void assign2() { check("static void foo() {\n" " struct ABC *abc = malloc(123);\n" " abc->a = abc->b = malloc(10);\n" @@ -6049,8 +5842,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void assign3() - { + void assign3() { check("void f(struct s *f1) {\n" " struct s f2;\n" " f2.a = malloc(100);\n" @@ -6065,8 +5857,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void failedAllocation() - { + void failedAllocation() { check("static struct ABC * foo()\n" "{\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" @@ -6093,8 +5884,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void function1() - { + void function1() { // Not found function => assume that the function may deallocate check("static void foo()\n" "{\n" @@ -6128,8 +5918,7 @@ private: } // #2848: Taking address in function 'assign' - void function2() - { + void function2() { check("void f() {\n" " A a = { 0 };\n" " a.foo = (char *) malloc(10);\n" @@ -6145,8 +5934,7 @@ private: } // #3024: kernel list - void function3() - { + void function3() { check("void f() {\n" " struct ABC *abc = kmalloc(100);\n" " abc.a = (char *) kmalloc(10);\n" @@ -6156,8 +5944,7 @@ private: } // #3038: deallocating in function - void function4() - { + void function4() { check("void a(char *p) { char *x = p; free(x); }\n" "void b() {\n" " struct ABC abc;\n" @@ -6174,8 +5961,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ifelse() - { + void ifelse() { check("static void foo()\n" "{\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" @@ -6210,8 +5996,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void linkedlist() - { + void linkedlist() { // #3904 - false positive when linked list is used check("static void foo() {\n" " struct ABC *abc = malloc(sizeof(struct ABC));\n" @@ -6239,8 +6024,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void globalvar() - { + void globalvar() { check("struct ABC *abc;\n" "\n" "static void foo()\n" @@ -6262,8 +6046,7 @@ private: } // Ticket #933 Leaks with struct members not detected - void localvars() - { + void localvars() { // Test error case const char code_err[] = "struct A {\n" " FILE* f;\n" @@ -6350,8 +6133,7 @@ private: } // don't crash - void trac5030() - { + void trac5030() { check("bool bob( char const **column_ptrs ) {\n" "unique_ptrotherbuffer{new char[otherbufsize+1]};\n" "char *const oldbuffer = otherbuffer.get();\n" @@ -6360,8 +6142,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varid() // #5201 - { + void varid() { // #5201 check("struct S {\n" " void *state_check_buff;\n" "};\n" @@ -6384,8 +6165,7 @@ private: TODO_ASSERT_EQUALS("[test.c:9]: (error) Memory leak: s.state_check_buff\n", "", errout.str()); } - void varid_2() // #5315 - { + void varid_2() { // #5315 check("typedef struct foo { char *realm; } foo;\n" "void build_principal() {\n" " foo f;\n" @@ -6405,15 +6185,13 @@ static TestMemleakStructMember testMemleakStructMember; class TestMemleakNoVar : public TestFixture { public: - TestMemleakNoVar() : TestFixture("TestMemleakNoVar") - { + TestMemleakNoVar() : TestFixture("TestMemleakNoVar") { } private: Settings settings; - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -6428,8 +6206,7 @@ private: checkMemoryLeakNoVar.check(); } - void run() - { + void run() { settings.standards.posix = true; LOAD_LIB_2(settings.library, "gtk.cfg"); @@ -6451,8 +6228,7 @@ private: TEST_CASE(missingAssignment); } - void functionParameter() - { + void functionParameter() { // standard function.. check("void x() {\n" " strcpy(a, strdup(p));\n" @@ -6541,8 +6317,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with g_strdup, g_strcmp0 doesn't release it.\n", errout.str()); } - void missingAssignment() - { + void missingAssignment() { check("void x()\n" "{\n" " malloc(10);\n" @@ -6606,15 +6381,13 @@ REGISTER_TEST(TestMemleakNoVar) class TestMemleakGLib : public TestFixture { public: - TestMemleakGLib() : TestFixture("TestMemleakGLib") - { + TestMemleakGLib() : TestFixture("TestMemleakGLib") { } private: Settings settings; - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -6636,15 +6409,13 @@ private: checkMemoryLeak.check(); } - void run() - { + void run() { LOAD_LIB_2(settings.library, "gtk.cfg"); TEST_CASE(glib1); } - void glib1() - { + void glib1() { check("void f(gchar *_a, gchar *_b) {" " g_return_if_fail(_a);" " gchar *a = g_strdup(_a);" @@ -6664,15 +6435,13 @@ static TestMemleakGLib testMemleakGLib; class TestMemleakWindows : public TestFixture { public: - TestMemleakWindows() : TestFixture("TestMemleakWindows") - { + TestMemleakWindows() : TestFixture("TestMemleakWindows") { } private: Settings settings; - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -6694,15 +6463,13 @@ private: checkMemoryLeak.check(); } - void run() - { + void run() { LOAD_LIB_2(settings.library, "windows.cfg"); TEST_CASE(openfileNoLeak); } - void openfileNoLeak() - { + void openfileNoLeak() { check("void f() {" " OFSTRUCT OfStr;" " int hFile = OpenFile(\"file\", &OfStr, 0);" diff --git a/test/testnonreentrantfunctions.cpp b/test/testnonreentrantfunctions.cpp index 16016c488..17d5cd306 100644 --- a/test/testnonreentrantfunctions.cpp +++ b/test/testnonreentrantfunctions.cpp @@ -27,20 +27,17 @@ extern std::ostringstream errout; class TestNonReentrantFunctions : public TestFixture { public: - TestNonReentrantFunctions() : TestFixture("TestNonReentrantFunctions") - { + TestNonReentrantFunctions() : TestFixture("TestNonReentrantFunctions") { } private: - void run() - { + void run() { TEST_CASE(test_crypt); TEST_CASE(test_namespace_handling); } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -59,8 +56,7 @@ private: checkNonReentrantFunctions.nonReentrantFunctions(); } - void test_crypt() - { + void test_crypt() { check("void f(char *pwd)\n" "{\n" " char *cpwd;" @@ -84,8 +80,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void test_namespace_handling() - { + void test_namespace_handling() { check("int f()\n" "{\n" " time_t t = 0;" diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 46858dec2..05b059a50 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -25,15 +25,13 @@ extern std::ostringstream errout; class TestNullPointer : public TestFixture { public: - TestNullPointer() : TestFixture("TestNullPointer") - { + TestNullPointer() : TestFixture("TestNullPointer") { } private: Settings settings; - void run() - { + void run() { LOAD_LIB_2(settings.library, "std.cfg"); TEST_CASE(nullpointerAfterLoop); @@ -96,8 +94,7 @@ private: TEST_CASE(posixcfg); } - void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp", bool verify=true) - { + void check(const char code[], bool inconclusive = false, const char filename[] = "test.cpp", bool verify=true) { // Clear the error buffer.. errout.str(""); @@ -124,8 +121,7 @@ private: } - void nullpointerAfterLoop() - { + void nullpointerAfterLoop() { check("int foo(const Token *tok)\n" "{\n" " while (tok);\n" @@ -230,8 +226,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer1() - { + void nullpointer1() { // ticket #1923 - no false positive when using else if check("void f(A *a)\n" "{\n" @@ -264,8 +259,7 @@ private: } - void nullpointer2() - { + void nullpointer2() { // Null pointer dereference can only happen with pointers check("void foo()\n" "{\n" @@ -279,8 +273,7 @@ private: // Dereferencing a struct and then checking if it is null // This is checked by this function: // CheckOther::nullPointerStructByDeRefAndChec - void structDerefAndCheck() - { + void structDerefAndCheck() { // errors.. check("void foo(struct ABC *abc)\n" "{\n" @@ -522,8 +515,7 @@ private: } // Dereferencing a pointer and then checking if it is null - void pointerDerefAndCheck() - { + void pointerDerefAndCheck() { // errors.. check("void foo(int *p)\n" "{\n" @@ -853,8 +845,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer5() - { + void nullpointer5() { // errors.. check("void foo(A &a)\n" "{\n" @@ -866,8 +857,7 @@ private: } // Execution paths.. - void nullpointerExecutionPaths() - { + void nullpointerExecutionPaths() { // errors.. check("static void foo()\n" "{\n" @@ -1064,8 +1054,7 @@ private: } // Ticket #2350 - void nullpointerExecutionPathsLoop() - { + void nullpointerExecutionPathsLoop() { // No false positive: check("void foo() {\n" " int n;\n" @@ -1113,8 +1102,7 @@ private: ASSERT_EQUALS("[test.cpp:11]: (error) Possible null pointer dereference: p\n", errout.str()); } - void nullpointer7() - { + void nullpointer7() { check("void foo()\n" "{\n" " wxLongLong x = 0;\n" @@ -1123,8 +1111,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer9() //#ticket 1778 - { + void nullpointer9() { //#ticket 1778 check("void foo()\n" "{\n" " std::string * x = 0;\n" @@ -1134,8 +1121,7 @@ private: "[test.cpp:4]: (error) Null pointer dereference\n", errout.str()); } - void nullpointer10() - { + void nullpointer10() { check("void foo()\n" "{\n" " struct my_type* p = 0;\n" @@ -1144,8 +1130,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str()); } - void nullpointer11() // ticket #2812 - { + void nullpointer11() { // ticket #2812 check("int foo()\n" "{\n" " struct my_type* p;\n" @@ -1155,8 +1140,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Possible null pointer dereference: p\n", errout.str()); } - void nullpointer12() // ticket #2470, #4035 - { + void nullpointer12() { // ticket #2470, #4035 const char code[] = "int foo()\n" "{\n" " int* i = nullptr;\n" @@ -1171,8 +1155,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer14() - { + void nullpointer14() { check("void foo()\n" "{\n" " strcpy(bar, 0);\n" @@ -1195,8 +1178,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Possible null pointer dereference: q\n", errout.str()); } - void nullpointer15() // #3560 - { + void nullpointer15() { // #3560 check("void f() {\n" " char *p = 0;\n" " if (x) p = \"abcd\";\n" @@ -1205,8 +1187,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer16() // #3591 - { + void nullpointer16() { // #3591 check("void foo() {\n" " int *p = 0;\n" " bar(&p);\n" @@ -1215,8 +1196,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer17() // #3567 - { + void nullpointer17() { // #3567 check("int foo() {\n" " int *p = 0;\n" " if (x) { return 0; }\n" @@ -1232,8 +1212,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer18() // #1927 - { + void nullpointer18() { // #1927 check("void f ()\n" "{\n" " int i=0;\n" @@ -1247,16 +1226,14 @@ private: "[test.cpp:5]: (error) Null pointer dereference\n", errout.str()); } - void nullpointer19() // #3811 - { + void nullpointer19() { // #3811 check("int foo() {\n" " perror(0);\n" "}", true); ASSERT_EQUALS("", errout.str()); } - void nullpointer20() // #3807 - { + void nullpointer20() { // #3807 check("void f(int x) {\n" " struct xy *p = 0;\n" " if (x) p = q;\n" @@ -1272,8 +1249,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str()); } - void nullpointer21() // #4038 - fp: if (x) p=q; else return; - { + void nullpointer21() { // #4038 - fp: if (x) p=q; else return; check("void f(int x) {\n" " int *p = 0;\n" " if (x) p = q;\n" @@ -1283,8 +1259,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer23() // #4665 - { + void nullpointer23() { // #4665 check("void f(){\n" " char *c = NULL;\n" " char cBuf[10];\n" @@ -1293,8 +1268,7 @@ private: ASSERT_EQUALS("",errout.str()); } - void nullpointer24() // #5083 - fp: chained assignment - { + void nullpointer24() { // #5083 - fp: chained assignment check("void f(){\n" " char *c = NULL;\n" " x = c = new char[10];\n" @@ -1303,8 +1277,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer25() // #5061 - { + void nullpointer25() { // #5061 check("void f(int *data, int i)\n" "{\n" " int *array = NULL;\n" @@ -1314,8 +1287,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: array\n", errout.str()); } - void nullpointer26() // #3589 - { + void nullpointer26() { // #3589 check("double foo() {\n" " sk *t1 = foo();\n" " sk *t2 = foo();\n" @@ -1332,8 +1304,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointerSwitch() // #2626 - { + void nullpointerSwitch() { // #2626 check("char *f(int x) {\n" " char *p = do_something();\n" " switch (x) {\n" @@ -1349,8 +1320,7 @@ private: "[test.cpp:7]: (error) Null pointer dereference\n", errout.str()); } - void nullpointer_cast() // #4692 - { + void nullpointer_cast() { // #4692 check("char *nasm_skip_spaces(const char *p) {\n" " if (p)\n" " while (*p && nasm_isspace(*p))\n" @@ -1360,8 +1330,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer_castToVoid() // #3771 - { + void nullpointer_castToVoid() { // #3771 check("void f () {\n" " int *buf; buf = NULL;\n" " buf;\n" @@ -1370,8 +1339,7 @@ private: } // Check if pointer is null and the dereference it - void pointerCheckAndDeRef() - { + void pointerCheckAndDeRef() { check("void foo(char *p) {\n" " if (!p) {\n" " }\n" @@ -1766,8 +1734,7 @@ private: } // Test CheckNullPointer::nullConstantDereference - void nullConstantDereference() - { + void nullConstantDereference() { // Ticket #2090 check("void foo() {\n" " strcpy(0, \"abcd\");\n" @@ -1814,8 +1781,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void gcc_statement_expression() - { + void gcc_statement_expression() { // Ticket #2621 check("void f(struct ABC *abc) {\n" " ({ if (abc) dbg(); })\n" @@ -1823,8 +1789,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void snprintf_with_zero_size() - { + void snprintf_with_zero_size() { // Ticket #2840 check("void f() {\n" " int bytes = snprintf(0, 0, \"%u\", 1);\n" @@ -1832,8 +1797,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void snprintf_with_non_zero_size() - { + void snprintf_with_non_zero_size() { // Ticket #2840 check("void f() {\n" " int bytes = snprintf(0, 10, \"%u\", 1);\n" @@ -1841,8 +1805,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str()); } - void printf_with_invalid_va_argument() - { + void printf_with_invalid_va_argument() { check("void f() {\n" " printf(\"%s\", 0);\n" "}"); @@ -1918,8 +1881,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void scanf_with_invalid_va_argument() - { + void scanf_with_invalid_va_argument() { check("void f(char* s) {\n" " sscanf(s, \"%s\", 0);\n" "}"); @@ -1967,8 +1929,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str()); } - void nullpointer_in_return() - { + void nullpointer_in_return() { check("int foo() {\n" " int* iVal = 0;\n" " if(g()) iVal = g();\n" @@ -1982,8 +1943,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointer_in_typeid() - { + void nullpointer_in_typeid() { // Should throw std::bad_typeid check("struct PolymorphicA { virtual ~A() {} };\n" "bool foo() {\n" @@ -2007,8 +1967,7 @@ private: } - void nullpointer_in_for_loop() - { + void nullpointer_in_for_loop() { // Ticket #3278 check("void f(int* ptr, int cnt){\n" " if (!ptr)\n" @@ -2019,8 +1978,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointerDelete() - { + void nullpointerDelete() { check("void f() {\n" " K *k = getK();\n" " if (k)\n" @@ -2039,8 +1997,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointerExit() - { + void nullpointerExit() { check("void f() {\n" " K *k = getK();\n" " if (!k)\n" @@ -2050,8 +2007,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointerStdString() - { + void nullpointerStdString() { check("void f(std::string s1) {\n" " void* p = 0;\n" " s1 = 0;\n" @@ -2114,8 +2070,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nullpointerStdStream() - { + void nullpointerStdStream() { check("void f(std::ifstream& is) {\n" " char* p = 0;\n" " is >> p;\n" @@ -2191,8 +2146,7 @@ private: } - void functioncall() // #3443 - function calls - { + void functioncall() { // #3443 - function calls // dereference pointer and then check if it's null { // function not seen @@ -2282,8 +2236,7 @@ private: } } - void functioncalllibrary() - { + void functioncalllibrary() { Settings settings1; Tokenizer tokenizer(&settings1,this); std::istringstream code("void f() { int a,b; x(a,b); }"); @@ -2337,8 +2290,7 @@ private: } } - void functioncallDefaultArguments() - { + void functioncallDefaultArguments() { check("void f(int *p = 0) {\n" " *p = 0;\n" @@ -2507,15 +2459,13 @@ private: } - void crash1() - { + void crash1() { ASSERT_THROW(check("int f() {\n" " return if\n" "}"), InternalError); } - void nullpointer_internal_error() // ticket #5080 - { + void nullpointer_internal_error() { // ticket #5080 check("struct A { unsigned int size; };\n" "struct B { struct A *a; };\n" "void f(struct B *b) {\n" @@ -2527,8 +2477,7 @@ private: } // Test that std.cfg is configured correctly - void stdcfg() - { + void stdcfg() { const char errp[] = "[test.cpp:1] -> [test.cpp:1]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n"; const char errpq[] = "[test.cpp:1] -> [test.cpp:1]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n" "[test.cpp:1] -> [test.cpp:1]: (warning) Possible null pointer dereference: q - otherwise it is redundant to check it against null.\n"; @@ -2628,8 +2577,7 @@ private: ASSERT_EQUALS("",errout.str()); } - void nullpointerFputc() - { + void nullpointerFputc() { check("int main () {\n" "FILE *fp = fopen(\"file.txt\", \"w+\");\n" "fputc(000, fp); \n" @@ -2648,8 +2596,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: nullstring\n", errout.str()); } - void nullpointerMemchr() - { + void nullpointerMemchr() { check("void f (char *p, char *s) {\n" " p = memchr (s, 'p', strlen(s));\n" "}\n"); @@ -2667,8 +2614,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: s\n", errout.str()); } - void nullpointerPutchar() - { + void nullpointerPutchar() { check("void f (char *c) {\n" " putchar(c);\n" "}\n"); @@ -2685,8 +2631,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (error) Null pointer dereference\n", errout.str()); } - void posixcfg() - { + void posixcfg() { const char errp[] = "[test.cpp:1] -> [test.cpp:1]: (warning) Possible null pointer dereference: p - otherwise it is redundant to check it against null.\n"; check("void f(FILE *p){ isatty (*p);if(!p){}}"); diff --git a/test/testobsolescentfunctions.cpp b/test/testobsolescentfunctions.cpp index c1e15bba7..2fdd8cec9 100644 --- a/test/testobsolescentfunctions.cpp +++ b/test/testobsolescentfunctions.cpp @@ -27,14 +27,12 @@ extern std::ostringstream errout; class TestObsoleteFunctions : public TestFixture { public: - TestObsoleteFunctions() : TestFixture("TestObsoleteFunctions") - { + TestObsoleteFunctions() : TestFixture("TestObsoleteFunctions") { } private: - void run() - { + void run() { TEST_CASE(testbsd_signal); TEST_CASE(testgethostbyname); TEST_CASE(testgethostbyaddr); @@ -70,8 +68,7 @@ private: TEST_CASE(ticket3238); } - void check(const char code[], const char filename[]="test.cpp") - { + void check(const char code[], const char filename[]="test.cpp") { // Clear the error buffer.. errout.str(""); @@ -91,8 +88,7 @@ private: checkObsoleteFunctions.obsoleteFunctions(); } - void testbsd_signal() - { + void testbsd_signal() { check("void f()\n" "{\n" " bsd_signal(SIGABRT, SIG_IGN);\n" @@ -108,8 +104,7 @@ private: } - void testgethostbyname() - { + void testgethostbyname() { check("void f()\n" "{\n" " struct hostent *hp;\n" @@ -120,8 +115,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'gethostbyname' called. It is recommended to use the function 'getaddrinfo' instead.\n", errout.str()); } - void testgethostbyaddr() - { + void testgethostbyaddr() { check("void f()\n" "{\n" " long addr;\n" @@ -133,8 +127,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style) Obsolete function 'gethostbyaddr' called. It is recommended to use the function 'getnameinfo' instead.\n", errout.str()); } - void testusleep() - { + void testusleep() { check("void f()\n" "{\n" " usleep( 1000 );\n" @@ -142,8 +135,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.\n", errout.str()); } - void testindex() - { + void testindex() { check("namespace n1 {\n" " int index(){};\n" @@ -184,16 +176,14 @@ private: errout.str()); } - void test_qt_index() - { + void test_qt_index() { check("void TDataModel::forceRowRefresh(int row) {\n" " emit dataChanged(index(row, 0), index(row, columnCount() - 1));\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Obsolete function 'index' called. It is recommended to use the function 'strchr' instead.\n", errout.str()); } - void testrindex() - { + void testrindex() { check("void f()\n" "{\n" " int rindex( 0 );\n" @@ -209,8 +199,7 @@ private: } - void testvar() - { + void testvar() { check("class Fred {\n" "public:\n" " Fred() : index(0) { }\n" @@ -219,8 +208,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testgets() - { + void testgets() { check("void f()\n" "{\n" " char *x = gets();\n" @@ -234,8 +222,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Obsolete function 'gets' called. It is recommended to use the function 'fgets' instead.\n", errout.str()); } - void testalloca() - { + void testalloca() { check("void f()\n" "{\n" " char *x = alloca(10);\n" @@ -250,8 +237,7 @@ private: } // ticket #3121 - void test_declared_function() - { + void test_declared_function() { check("int ftime ( int a )\n" "{\n" " return a;\n" @@ -265,8 +251,7 @@ private: } // test std::gets - void test_std_gets() - { + void test_std_gets() { check("void f(char * str)\n" "{\n" " char *x = std::gets(str);\n" @@ -275,8 +260,7 @@ private: } // multiple use - void test_multiple() - { + void test_multiple() { check("void f(char * str)\n" "{\n" " char *x = std::gets(str);\n" @@ -286,8 +270,7 @@ private: "[test.cpp:4]: (style) Obsolete function 'usleep' called. It is recommended to use the 'nanosleep' or 'setitimer' function instead.\n", errout.str()); } - void test_c_declaration() - { + void test_c_declaration() { check("char * gets ( char * c ) ;\n" "int main ()\n" "{\n" @@ -304,8 +287,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Obsolete function 'getcontext' called. Due to portability issues, applications are recommended to be rewritten to use POSIX threads.\n", errout.str()); } - void test_function_with_body() - { + void test_function_with_body() { check("char * gets ( char * c ) { return c; }\n" "int main ()\n" "{\n" @@ -315,8 +297,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ticket3238() - { + void ticket3238() { check("__FBSDID(\"...\");\n"); ASSERT_EQUALS("", errout.str()); } diff --git a/test/testoptions.cpp b/test/testoptions.cpp index 29d9d1100..23c821975 100644 --- a/test/testoptions.cpp +++ b/test/testoptions.cpp @@ -23,14 +23,12 @@ extern std::ostringstream errout; class TestOptions: public TestFixture { public: TestOptions() - :TestFixture("TestOptions") - { + :TestFixture("TestOptions") { } private: - void run() - { + void run() { TEST_CASE(which_test); TEST_CASE(which_test_method); TEST_CASE(no_test_method); @@ -42,64 +40,56 @@ private: } - void which_test() const - { + void which_test() const { const char* argv[] = {"./test_runner", "TestClass"}; options args(sizeof argv / sizeof argv[0], argv); ASSERT_EQUALS("TestClass", args.which_test()); } - void which_test_method() const - { + void which_test_method() const { const char* argv[] = {"./test_runner", "TestClass::TestMethod"}; options args(sizeof argv / sizeof argv[0], argv); ASSERT_EQUALS("TestClass::TestMethod", args.which_test()); } - void no_test_method() const - { + void no_test_method() const { const char* argv[] = {"./test_runner"}; options args(sizeof argv / sizeof argv[0], argv); ASSERT_EQUALS("", args.which_test()); } - void not_quiet() const - { + void not_quiet() const { const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-v"}; options args(sizeof argv / sizeof argv[0], argv); ASSERT_EQUALS(false, args.quiet()); } - void quiet() const - { + void quiet() const { const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-q"}; options args(sizeof argv / sizeof argv[0], argv); ASSERT_EQUALS(true, args.quiet()); } - void gcc_errors() const - { + void gcc_errors() const { const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-g"}; options args(sizeof argv / sizeof argv[0], argv); ASSERT_EQUALS(true, args.gcc_style_errors()); } - void multiple_testcases() const - { + void multiple_testcases() const { const char* argv[] = {"./test_runner", "TestClass::TestMethod", "Ignore::ThisOne"}; options args(sizeof argv / sizeof argv[0], argv); ASSERT_EQUALS("TestClass::TestMethod", args.which_test()); } - void invalid_switches() const - { + void invalid_switches() const { const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-a", "-v", "-q", "-g"}; options args(sizeof argv / sizeof argv[0], argv); ASSERT_EQUALS("TestClass::TestMethod", args.which_test()); diff --git a/test/testother.cpp b/test/testother.cpp index b775d8e19..72631d0b3 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -29,15 +29,13 @@ extern std::ostringstream errout; class TestOther : public TestFixture { public: - TestOther() : TestFixture("TestOther") - { + TestOther() : TestFixture("TestOther") { } private: Settings settings_std; - void run() - { + void run() { LOAD_LIB_2(settings_std.library, "std.cfg"); TEST_CASE(emptyBrackets); @@ -176,8 +174,7 @@ private: TEST_CASE(testReturnIgnoredReturnValue); } - void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool posix = false, bool runSimpleChecks=true, Settings* settings = 0) - { + void check(const char code[], const char *filename = nullptr, bool experimental = false, bool inconclusive = true, bool posix = false, bool runSimpleChecks=true, Settings* settings = 0) { // Clear the error buffer.. errout.str(""); @@ -222,8 +219,7 @@ private: } } - void check_preprocess_suppress(const char precode[], const char *filename = nullptr) - { + void check_preprocess_suppress(const char precode[], const char *filename = nullptr) { // Clear the error buffer.. errout.str(""); @@ -258,24 +254,21 @@ private: } - void emptyBrackets() - { + void emptyBrackets() { check("{\n" "}"); ASSERT_EQUALS("", errout.str()); } - void zeroDiv1() - { + void zeroDiv1() { check("void foo() {\n" " cout << 1. / 0;\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Division by zero.\n", errout.str()); } - void zeroDiv2() - { + void zeroDiv2() { check("void foo()\n" "{\n" " int sum = 0;\n" @@ -288,8 +281,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void zeroDiv3() - { + void zeroDiv3() { check("void f()\n" "{\n" " div_t divresult = div (1,0);\n" @@ -304,8 +296,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void zeroDiv4() - { + void zeroDiv4() { check("void f()\n" "{\n" " long a = b / 0x6;\n" @@ -370,8 +361,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void zeroDiv5() - { + void zeroDiv5() { check("void f()\n" "{ { {\n" " long a = b / 0;\n" @@ -379,8 +369,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); } - void zeroDiv6() - { + void zeroDiv6() { check("void f()\n" "{ { {\n" " int a = b % 0;\n" @@ -388,8 +377,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Division by zero.\n", errout.str()); } - void zeroDiv7() - { + void zeroDiv7() { check("void f() {\n" " int a = x/2*3/0;\n" " int b = y/2*3%0;\n" @@ -398,8 +386,7 @@ private: "[test.cpp:3]: (error) Division by zero.\n", errout.str()); } - void zeroDiv8() - { + void zeroDiv8() { // #5584 - FP when function is unknown check("void f() {\n" " int a = 0;\n" @@ -409,8 +396,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error, inconclusive) Division by zero.\n", errout.str()); } - void zeroDivCond() - { + void zeroDivCond() { check("void f(unsigned int x) {\n" " int y = 17 / x;\n" " if (x > 0) {}\n" @@ -524,8 +510,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void nanInArithmeticExpression() - { + void nanInArithmeticExpression() { check("void f()\n" "{\n" " double x = 3.0 / 0.0 + 1.0\n" @@ -567,8 +552,7 @@ private: } - void invalidFunctionUsage(const char code[]) - { + void invalidFunctionUsage(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -593,8 +577,7 @@ private: checkOther.invalidFunctionUsage(); } - void invalidFunctionUsage1() - { + void invalidFunctionUsage1() { invalidFunctionUsage("int f() { memset(a,b,sizeof(a)!=12); }"); ASSERT_EQUALS("[test.cpp:1]: (error) Invalid memset() argument nr 3. A non-boolean value is required.\n", errout.str()); @@ -611,8 +594,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope(const char code[]) - { + void varScope(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -629,8 +611,7 @@ private: checkOther.checkVariableScope(); } - void varScope1() - { + void varScope1() { varScope("unsigned short foo()\n" "{\n" " test_client CClient;\n" @@ -660,8 +641,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope2() - { + void varScope2() { varScope("int foo()\n" "{\n" " Error e;\n" @@ -671,8 +651,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope3() - { + void varScope3() { varScope("void foo()\n" "{\n" " int i;\n" @@ -686,8 +665,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope4() - { + void varScope4() { varScope("void foo()\n" "{\n" " int i;\n" @@ -695,8 +673,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope5() - { + void varScope5() { varScope("void f(int x)\n" "{\n" " int i = 0;\n" @@ -725,8 +702,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) The scope of the variable 'i' can be reduced.\n", errout.str()); } - void varScope6() - { + void varScope6() { varScope("void f(int x)\n" "{\n" " int i = x;\n" @@ -766,8 +742,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope7() - { + void varScope7() { varScope("void f(int x)\n" "{\n" " int y = 0;\n" @@ -779,8 +754,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope8() - { + void varScope8() { varScope("void test() {\n" " float edgeResistance=1;\n" " std::vector edges;\n" @@ -791,8 +765,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'edgeResistance' can be reduced.\n", errout.str()); } - void varScope9() - { + void varScope9() { // classes may have extra side effects varScope("class fred {\n" "public:\n" @@ -807,8 +780,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope10() - { + void varScope10() { varScope("int f()\n" "{\n" " int x = 0;\n" @@ -819,8 +791,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope11() - { + void varScope11() { varScope("int f() {\n" " int x = 0;\n" " AB ab = { x, 0 };\n" @@ -842,8 +813,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope12() - { + void varScope12() { varScope("void f(int x) {\n" " int i[5];\n" " int* j = y;\n" @@ -879,8 +849,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope13() - { + void varScope13() { // #2770 varScope("void f() {\n" " int i = 0;\n" @@ -891,8 +860,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope14() - { + void varScope14() { // #3941 varScope("void f() {\n" " const int i( foo());\n" @@ -903,8 +871,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope15() - { + void varScope15() { // #4573 varScope("void f() {\n" " int a,b,c;\n" @@ -916,8 +883,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope16() - { + void varScope16() { varScope("void f() {\n" " int a = 0;\n" " while((++a) < 56) {\n" @@ -953,8 +919,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'a' can be reduced.\n", errout.str()); } - void varScope17() - { + void varScope17() { varScope("void f() {\n" " int x;\n" " if (a) {\n" @@ -975,8 +940,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'x' can be reduced.\n", errout.str()); } - void varScope18() - { + void varScope18() { varScope("void f() {\n" " short x;\n" "\n" @@ -1047,8 +1011,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope19() // Ticket #4994 - { + void varScope19() { // Ticket #4994 varScope("long f () {\n" " return a >> extern\n" "}\n" @@ -1057,8 +1020,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope20() // Ticket #5103 - constant variable only used in inner scope - { + void varScope20() { // Ticket #5103 - constant variable only used in inner scope varScope("int f(int a) {\n" " const int x = 234;\n" " int b = a;\n" @@ -1068,8 +1030,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope21() // Ticket #5382 - initializing two-dimensional array - { + void varScope21() { // Ticket #5382 - initializing two-dimensional array varScope("int test() {\n" " int test_value = 3;\n" " int test_array[1][1] = { { test_value } };\n" @@ -1078,8 +1039,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varScope22() // Ticket #5684 - "The scope of the variable 'p' can be reduced" - But it can not. - { + void varScope22() { // Ticket #5684 - "The scope of the variable 'p' can be reduced" - But it can not. varScope("void foo() {\n" " int* p( 42 );\n" " int i = 0;\n" @@ -1105,8 +1065,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style) The scope of the variable 'p' can be reduced.\n", errout.str()); } - void varScope23() // #6154: Don't suggest to reduce scope if inner scope is a lambda - { + void varScope23() { // #6154: Don't suggest to reduce scope if inner scope is a lambda varScope("int main() {\n" " size_t myCounter = 0;\n" " Test myTest([&](size_t aX){\n" @@ -1116,8 +1075,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkOldStylePointerCast(const char code[]) - { + void checkOldStylePointerCast(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -1141,8 +1099,7 @@ private: checkOtherC.warningOldStylePointerCast(); } - void oldStylePointerCast() - { + void oldStylePointerCast() { checkOldStylePointerCast("class Base;\n" "void foo()\n" "{\n" @@ -1266,8 +1223,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style) C-style pointer casting\n", errout.str()); } - void checkInvalidPointerCast(const char code[], bool portability = true, bool inconclusive = false) - { + void checkInvalidPointerCast(const char code[], bool portability = true, bool inconclusive = false) { // Clear the error buffer.. errout.str(""); @@ -1287,8 +1243,7 @@ private: } - void invalidPointerCast() - { + void invalidPointerCast() { checkInvalidPointerCast("void test() {\n" " float *f = new float[10];\n" " delete [] (double*)f;\n" @@ -1360,8 +1315,7 @@ private: checkInvalidPointerCast("Q_DECLARE_METATYPE(int*)"); // #4135 - don't crash } - void testPassedByValue(const char code[]) - { + void testPassedByValue(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -1376,8 +1330,7 @@ private: checkOther.checkConstantFunctionParameter(); } - void passedByValue() - { + void passedByValue() { testPassedByValue("void f(const std::string str) {}"); ASSERT_EQUALS("[test.cpp:1]: (performance) Function parameter 'str' should be passed by reference.\n", errout.str()); @@ -1435,8 +1388,7 @@ private: } - void mathfunctionCall_sqrt() - { + void mathfunctionCall_sqrt() { // sqrt, sqrtf, sqrtl check("void foo()\n" "{\n" @@ -1466,8 +1418,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mathfunctionCall_log() - { + void mathfunctionCall_log() { // log,log10,logf,logl,log10f,log10l check("void foo()\n" "{\n" @@ -1551,8 +1502,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mathfunctionCall_acos() - { + void mathfunctionCall_acos() { // acos, acosf, acosl check("void foo()\n" "{\n" @@ -1610,8 +1560,7 @@ private: "[test.cpp:5]: (warning) Passing value -1.1 to acosl() leads to implementation-defined result.\n", errout.str()); } - void mathfunctionCall_asin() - { + void mathfunctionCall_asin() { // asin, asinf, asinl check("void foo()\n" "{\n" @@ -1672,8 +1621,7 @@ private: "[test.cpp:5]: (warning) Passing value -1.1 to asinl() leads to implementation-defined result.\n", errout.str()); } - void mathfunctionCall_pow() - { + void mathfunctionCall_pow() { // pow, powf, powl check("void foo()\n" "{\n" @@ -1694,8 +1642,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mathfunctionCall_atan2() - { + void mathfunctionCall_atan2() { // atan2 check("void foo()\n" "{\n" @@ -1746,8 +1693,7 @@ private: "[test.cpp:5]: (warning) Passing values 0 and 0 to atan2l() leads to implementation-defined result.\n", errout.str()); } - void mathfunctionCall_fmod() - { + void mathfunctionCall_fmod() { // fmod, fmodl, fmodf check("void foo()\n" "{\n" @@ -1768,8 +1714,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void mathfunctionCall_precision() - { + void mathfunctionCall_precision() { check("void foo() {\n" " print(exp(x) - 1);\n" " print(log(1 + x));\n" @@ -1804,8 +1749,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void switchRedundantAssignmentTest() - { + void switchRedundantAssignmentTest() { check("void foo()\n" "{\n" @@ -2074,8 +2018,7 @@ private: } - void switchRedundantOperationTest() - { + void switchRedundantOperationTest() { check("void foo()\n" "{\n" " int y = 1;\n" @@ -2415,8 +2358,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void switchRedundantBitwiseOperationTest() - { + void switchRedundantBitwiseOperationTest() { check("void foo(int a)\n" "{\n" " int y = 1;\n" @@ -2591,8 +2533,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void switchFallThroughCase() - { + void switchFallThroughCase() { check_preprocess_suppress( "void foo() {\n" " switch (a) {\n" @@ -2893,8 +2834,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void unreachableCode() - { + void unreachableCode() { check("void foo(int a) {\n" " while(1) {\n" " if (a++ >= 100) {\n" @@ -3176,8 +3116,7 @@ private: } - void suspiciousCase() - { + void suspiciousCase() { check("void foo() {\n" " switch(a) {\n" " case A&&B:\n" @@ -3209,8 +3148,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void suspiciousEqualityComparison() - { + void suspiciousEqualityComparison() { check("void foo(int c) {\n" " if (c == 1) c == 0;\n" "}"); @@ -3313,8 +3251,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void selfAssignment() - { + void selfAssignment() { check("void foo()\n" "{\n" " int x = 1;\n" @@ -3421,8 +3358,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void trac1132() - { + void trac1132() { check("class Lock\n" "{\n" "public:\n" @@ -3445,8 +3381,7 @@ private: ASSERT_EQUALS("[test.cpp:15]: (error) Instance of 'Lock' object is destroyed immediately.\n", errout.str()); } - void trac3693() - { + void trac3693() { check("struct A{\n" " enum {\n" " b = 300\n" @@ -3456,8 +3391,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testMisusedScopeObjectDoesNotPickFunction1() - { + void testMisusedScopeObjectDoesNotPickFunction1() { check("int main ( )\n" "{\n" " CouldBeFunction ( 123 ) ;\n" @@ -3467,8 +3401,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testMisusedScopeObjectDoesNotPickFunction2() - { + void testMisusedScopeObjectDoesNotPickFunction2() { check("struct error {\n" " error() {}\n" "};\n" @@ -3486,8 +3419,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testMisusedScopeObjectPicksClass() - { + void testMisusedScopeObjectPicksClass() { check("class NotAFunction ;\n" "int function ( )\n" "{\n" @@ -3498,8 +3430,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Instance of 'NotAFunction' object is destroyed immediately.\n", errout.str()); } - void testMisusedScopeObjectPicksStruct() - { + void testMisusedScopeObjectPicksStruct() { check("struct NotAClass;\n" "bool func ( )\n" "{\n" @@ -3510,8 +3441,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Instance of 'NotAClass' object is destroyed immediately.\n", errout.str()); } - void testMisusedScopeObjectDoesNotPickIf() - { + void testMisusedScopeObjectDoesNotPickIf() { check("bool func( int a , int b , int c )\n" "{\n" " if ( a > b ) return c == a ;\n" @@ -3521,8 +3451,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testMisusedScopeObjectDoesNotPickConstructorDeclaration() - { + void testMisusedScopeObjectDoesNotPickConstructorDeclaration() { check("class Something : public SomethingElse\n" "{\n" "public:\n" @@ -3533,8 +3462,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testMisusedScopeObjectDoesNotPickFunctor() - { + void testMisusedScopeObjectDoesNotPickFunctor() { check("class IncrementFunctor\n" "{\n" "public:\n" @@ -3554,8 +3482,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testMisusedScopeObjectDoesNotPickLocalClassConstructors() - { + void testMisusedScopeObjectDoesNotPickLocalClassConstructors() { check("void f() {\n" " class Foo {\n" " Foo() { }\n" @@ -3569,8 +3496,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Instance of 'Foo' object is destroyed immediately.\n", errout.str()); } - void testMisusedScopeObjectDoesNotPickUsedObject() - { + void testMisusedScopeObjectDoesNotPickUsedObject() { check("struct Foo {\n" " void bar() {\n" " }\n" @@ -3583,8 +3509,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testMisusedScopeObjectDoesNotPickPureC() - { + void testMisusedScopeObjectDoesNotPickPureC() { // Ticket #2352 const char code[] = "struct cb_watch_bool {\n" " int a;\n" @@ -3613,8 +3538,7 @@ private: ASSERT_EQUALS("",errout.str()); } - void testMisusedScopeObjectDoesNotPickNestedClass() - { + void testMisusedScopeObjectDoesNotPickNestedClass() { const char code[] = "class ios_base {\n" "public:\n" " class Init {\n" @@ -3635,8 +3559,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testMisusedScopeObjectInConstructor() - { + void testMisusedScopeObjectInConstructor() { const char code[] = "class Foo {\n" "public:\n" " Foo(char x) {\n" @@ -3649,8 +3572,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Instance of 'Foo' object is destroyed immediately.\n", errout.str()); } - void testMisusedScopeObjectNoCodeAfter() - { + void testMisusedScopeObjectNoCodeAfter() { check("class Foo {};\n" "void f() {\n" " Foo();\n" // No code after class => don't warn @@ -3658,8 +3580,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void trac2084() - { + void trac2084() { check("void f()\n" "{\n" " struct sigaction sa;\n" @@ -3671,8 +3592,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void trac2071() - { + void trac2071() { check("void f() {\n" " struct AB {\n" " AB(int a) { }\n" @@ -3684,8 +3604,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void memsetZeroBytes() - { + void memsetZeroBytes() { check("void f() {\n" " memset(p, 10, 0x0);\n" "}\n"); @@ -3702,8 +3621,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void memsetInvalid2ndParam() - { + void memsetInvalid2ndParam() { check("void f() {\n" " int* is = new int[10];\n" " memset(is, 1.0f, 40);\n" @@ -3763,8 +3681,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (portability) The 2nd memset() argument '1.0f+i' is a float, its representation is implementation defined.\n", errout.str()); } - void redundantGetAndSetUserId() - { + void redundantGetAndSetUserId() { check("void foo() { seteuid(geteuid()); }", nullptr, false , false, true); ASSERT_EQUALS("[test.cpp:1]: (warning) Redundant get and set of user id.\n", errout.str()); check("void foo() { setuid(getuid()); }", nullptr, false , false, true); @@ -3782,8 +3699,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void clarifyCalculation() - { + void clarifyCalculation() { check("int f(char c) {\n" " return 10 * (c == 0) ? 1 : 2;\n" "}"); @@ -3835,8 +3751,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void clarifyStatement() - { + void clarifyStatement() { check("char* f(char* c) {\n" " *c++;\n" " return c;\n" @@ -3903,8 +3818,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateBranch() - { + void duplicateBranch() { check("void f(int a, int &b) {\n" " if (a)\n" " b = 1;\n" @@ -3963,8 +3877,7 @@ private: ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:2]: (style, inconclusive) Found duplicate branches for 'if' and 'else'.\n", errout.str()); } - void duplicateBranch1() - { + void duplicateBranch1() { // tests inspired by http://www.viva64.com/en/b/0149/ ( Comparison between PVS-Studio and cppcheck ) // Errors detected in Quake 3: Arena by PVS-Studio: Fragement 2 @@ -3997,8 +3910,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateBranch2() - { + void duplicateBranch2() { Preprocessor::macroChar = '$'; check("void f(int x) {\n" // #4329 @@ -4010,8 +3922,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateExpression1() - { + void duplicateExpression1() { check("void foo(int a) {\n" " if (a == a) { }\n" "}"); @@ -4225,8 +4136,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateExpression2() // check if float is NaN or Inf - { + void duplicateExpression2() { // check if float is NaN or Inf check("int f(long double ldbl, double dbl, float flt) {\n" // ticket #2730 " if (ldbl != ldbl) have_nan = 1;\n" " if (!(dbl == dbl)) have_nan = 1;\n" @@ -4254,8 +4164,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateExpression3() - { + void duplicateExpression3() { check("void foo() {\n" " if (x() || x()) {}\n" "}"); @@ -4360,8 +4269,7 @@ private: } - void duplicateExpression4() - { + void duplicateExpression4() { check("void foo() {\n" " if (*a++ != b || *a++ != b) {}\n" "}"); @@ -4379,8 +4287,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateExpression5() // #3749 - macros with same values - { + void duplicateExpression5() { // #3749 - macros with same values Preprocessor::macroChar = '$'; check("void f() {\n" " if ($a == $a) { }\n" @@ -4388,16 +4295,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void duplicateExpression6() // #4639 - { + void duplicateExpression6() { // #4639 check("float IsNan(float value) { return !(value == value); }\n" "double IsNan(double value) { return !(value == value); }\n" "long double IsNan(long double value) { return !(value == value); }"); ASSERT_EQUALS("", errout.str()); } - void check_signOfUnsignedVariable(const char code[], bool inconclusive=false) - { + void check_signOfUnsignedVariable(const char code[], bool inconclusive=false) { // Clear the error buffer.. errout.str(""); @@ -4415,8 +4320,7 @@ private: checkOther.checkSignOfUnsignedVariable(); } - void checkSignOfUnsignedVariable() - { + void checkSignOfUnsignedVariable() { check_signOfUnsignedVariable( "void foo() {\n" " for(unsigned char i = 10; i >= 0; i--)" @@ -4640,8 +4544,7 @@ private: } } - void checkSignOfPointer() - { + void checkSignOfPointer() { check_signOfUnsignedVariable( "bool foo(int* x) {\n" " if (x >= 0)" @@ -4799,8 +4702,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkForSuspiciousSemicolon1() - { + void checkForSuspiciousSemicolon1() { check( "void foo() {\n" " for(int i = 0; i < 10; ++i);\n" @@ -4824,8 +4726,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Suspicious use of ; at the end of 'while' statement.\n", errout.str()); } - void checkForSuspiciousSemicolon2() - { + void checkForSuspiciousSemicolon2() { check( "void foo() {\n" " if (i == 1); {\n" @@ -4871,8 +4772,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkDoubleFree() - { + void checkDoubleFree() { check( "void foo(char *p) {\n" " free(p);\n" @@ -5296,8 +5196,7 @@ private: } - void checkInvalidFree() - { + void checkInvalidFree() { check( "void foo(char *p) {\n" " char *a; a = malloc(1024);\n" @@ -5387,8 +5286,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void check_redundant_copy(const char code[], bool inconclusive = true) - { + void check_redundant_copy(const char code[], bool inconclusive = true) { // Clear the error buffer.. errout.str(""); @@ -5406,8 +5304,7 @@ private: tokenizer.simplifyTokenList2(); checkOther.checkRedundantCopy(); } - void checkRedundantCopy() - { + void checkRedundantCopy() { check_redundant_copy("const std::string& getA(){static std::string a;return a;}\n" "void foo() {\n" " const std::string a = getA();\n" @@ -5515,8 +5412,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkNegativeShift() - { + void checkNegativeShift() { check("void foo()\n" "{\n" " int a; a = 123;\n" @@ -5558,8 +5454,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void incompleteArrayFill() - { + void incompleteArrayFill() { check("void f() {\n" " int a[5];\n" " memset(a, 123, 5);\n" @@ -5609,8 +5504,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (portability, inconclusive) Array 'a' might be filled incompletely. Did you forget to multiply the size given to 'memset()' with 'sizeof(*a)'?\n", errout.str()); } - void redundantVarAssignment() - { + void redundantVarAssignment() { // Simple tests check("void f(int i) {\n" " i = 1;\n" @@ -5917,8 +5811,7 @@ private: "}"); } - void redundantMemWrite() - { + void redundantMemWrite() { // Simple tests check("void f(void* a) {\n" " memcpy(a, foo, bar);\n" @@ -6027,8 +5920,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void varFuncNullUB() // #4482 - { + void varFuncNullUB() { // #4482 check("void a(...);\n" "void b() { a(NULL); }"); ASSERT_EQUALS("[test.cpp:2]: (portability) Passing NULL after the last typed argument to a variadic function leads to undefined behaviour.\n", errout.str()); @@ -6038,8 +5930,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkPipeParameterSize() // #3521 - { + void checkPipeParameterSize() { // #3521 check("void f(){\n" "int pipefd[1];\n" // <-- array of two integers is needed "if (pipe(pipefd) == -1) {\n" @@ -6132,8 +6023,7 @@ private: } - void checkCastIntToCharAndBack() // #160 - { + void checkCastIntToCharAndBack() { // #160 // check getchar check("void f() {\n" @@ -6299,8 +6189,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkSleepTimeIntervall() - { + void checkSleepTimeIntervall() { // check usleep(), which is allowed to be called with in a range of [0,999999] check("void f(){\n" "usleep(10000);\n" @@ -6323,8 +6212,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (error) Invalid usleep() argument nr 1. The value is 1000001 but the valid values are '0:999999'.\n", errout.str()); } - void checkCommaSeparatedReturn() - { + void checkCommaSeparatedReturn() { check("int fun(int a) {\n" " if (a < 0)\n" " return a++,\n" @@ -6375,8 +6263,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkComparisonFunctionIsAlwaysTrueOrFalse() - { + void checkComparisonFunctionIsAlwaysTrueOrFalse() { // positive test check("bool f(int x){\n" " return isless(x,x);\n" @@ -6410,8 +6297,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void integerOverflow() // 5895 - { + void integerOverflow() { // 5895 // no signed integer overflow should happen check("void f(unsigned long long ull) {\n" " if (ull == 0x89504e470d0a1a0a || ull == 0x8a4d4e470d0a1a0a) ;\n" @@ -6419,8 +6305,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testReturnIgnoredReturnValue() - { + void testReturnIgnoredReturnValue() { check("void foo() {\n" " strcmp(a, b);\n" "}", "test.cpp", false, false, false, true, &settings_std); diff --git a/test/testpath.cpp b/test/testpath.cpp index 15c1b3c84..dd2859e58 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -22,14 +22,12 @@ class TestPath : public TestFixture { public: - TestPath() : TestFixture("TestPath") - { + TestPath() : TestFixture("TestPath") { } private: - void run() - { + void run() { TEST_CASE(simplify_path); TEST_CASE(accept_file); TEST_CASE(getRelative); @@ -38,8 +36,7 @@ private: TEST_CASE(get_path_from_filename); } - void simplify_path() const - { + void simplify_path() const { // Path::simplifyPath() ASSERT_EQUALS("index.h", Path::simplifyPath("index.h")); ASSERT_EQUALS("index.h", Path::simplifyPath("./index.h")); @@ -67,8 +64,7 @@ private: ASSERT_EQUALS("the/path to/index.cpp", Path::removeQuotationMarks("\"the/path to/index.cpp\"")); } - void accept_file() const - { + void accept_file() const { ASSERT(Path::acceptFile("index.cpp")); ASSERT(Path::acceptFile("index.invalid.cpp")); ASSERT(Path::acceptFile("index.invalid.Cpp")); @@ -84,8 +80,7 @@ private: ASSERT_EQUALS(false, Path::acceptFile("index.hpp")); } - void getRelative() const - { + void getRelative() const { std::vector basePaths; basePaths.push_back(""); // Don't crash with empty paths basePaths.push_back("C:/foo"); @@ -99,8 +94,7 @@ private: ASSERT_EQUALS("C:/foobar/test.cpp", Path::getRelativePath("C:/foobar/test.cpp", basePaths)); } - void is_c() const - { + void is_c() const { ASSERT(Path::isC("index.cpp")==false); ASSERT(Path::isC("")==false); ASSERT(Path::isC("c")==false); @@ -115,8 +109,7 @@ private: #endif } - void is_cpp() const - { + void is_cpp() const { ASSERT(Path::isCPP("index.c")==false); // In unix .C is considered C++ @@ -130,8 +123,7 @@ private: ASSERT(Path::isCPP("C:\\foo\\index.Cpp")); } - void get_path_from_filename() const - { + void get_path_from_filename() const { ASSERT_EQUALS("", Path::getPathFromFilename("index.h")); ASSERT_EQUALS("/tmp/", Path::getPathFromFilename("/tmp/index.h")); ASSERT_EQUALS("a/b/c/", Path::getPathFromFilename("a/b/c/index.h")); diff --git a/test/testpathmatch.cpp b/test/testpathmatch.cpp index 2d50f7f8e..d28df4e8b 100644 --- a/test/testpathmatch.cpp +++ b/test/testpathmatch.cpp @@ -28,8 +28,7 @@ public: , emptyMatcher(std::vector()) , srcMatcher(std::vector(1, "src/")) , fooCppMatcher(std::vector(1, "foo.cpp")) - , srcFooCppMatcher(std::vector(1, "src/foo.cpp")) - { + , srcFooCppMatcher(std::vector(1, "src/foo.cpp")) { } private: @@ -38,8 +37,7 @@ private: const PathMatch fooCppMatcher; const PathMatch srcFooCppMatcher; - void run() - { + void run() { TEST_CASE(emptymaskemptyfile); TEST_CASE(emptymaskpath1); TEST_CASE(emptymaskpath2); @@ -70,86 +68,70 @@ private: } // Test empty PathMatch - void emptymaskemptyfile() const - { + void emptymaskemptyfile() const { ASSERT(!emptyMatcher.Match("")); } - void emptymaskpath1() const - { + void emptymaskpath1() const { ASSERT(!emptyMatcher.Match("src/")); } - void emptymaskpath2() const - { + void emptymaskpath2() const { ASSERT(!emptyMatcher.Match("../src/")); } - void emptymaskpath3() const - { + void emptymaskpath3() const { ASSERT(!emptyMatcher.Match("/home/user/code/src/")); } // Test PathMatch containing "src/" - void onemaskemptypath() const - { + void onemaskemptypath() const { ASSERT(!srcMatcher.Match("")); } - void onemasksamepath() const - { + void onemasksamepath() const { ASSERT(srcMatcher.Match("src/")); } - void onemasksamepathdifferentcase() const - { + void onemasksamepathdifferentcase() const { std::vector masks(1, "sRc/"); PathMatch match(masks, false); ASSERT(match.Match("srC/")); } - void onemasksamepathwithfile() const - { + void onemasksamepathwithfile() const { ASSERT(srcMatcher.Match("src/file.txt")); } - void onemaskdifferentdir1() const - { + void onemaskdifferentdir1() const { ASSERT(!srcMatcher.Match("srcfiles/file.txt")); } - void onemaskdifferentdir2() const - { + void onemaskdifferentdir2() const { ASSERT(!srcMatcher.Match("proj/srcfiles/file.txt")); } - void onemaskdifferentdir3() const - { + void onemaskdifferentdir3() const { ASSERT(!srcMatcher.Match("proj/mysrc/file.txt")); } - void onemaskdifferentdir4() const - { + void onemaskdifferentdir4() const { ASSERT(!srcMatcher.Match("proj/mysrcfiles/file.txt")); } - void onemasklongerpath1() const - { + void onemasklongerpath1() const { ASSERT(srcMatcher.Match("/tmp/src/")); } - void onemasklongerpath2() const - { + void onemasklongerpath2() const { ASSERT(srcMatcher.Match("src/module/")); } - void onemasklongerpath3() const - { + void onemasklongerpath3() const { ASSERT(srcMatcher.Match("project/src/module/")); } - void twomasklongerpath1() const - { + void twomasklongerpath1() const { std::vector masks; masks.push_back("src/"); masks.push_back("module/"); @@ -157,8 +139,7 @@ private: ASSERT(!match.Match("project/")); } - void twomasklongerpath2() const - { + void twomasklongerpath2() const { std::vector masks; masks.push_back("src/"); masks.push_back("module/"); @@ -166,8 +147,7 @@ private: ASSERT(match.Match("project/src/")); } - void twomasklongerpath3() const - { + void twomasklongerpath3() const { std::vector masks; masks.push_back("src/"); masks.push_back("module/"); @@ -175,8 +155,7 @@ private: ASSERT(match.Match("project/module/")); } - void twomasklongerpath4() const - { + void twomasklongerpath4() const { std::vector masks; masks.push_back("src/"); masks.push_back("module/"); @@ -185,46 +164,38 @@ private: } // Test PathMatch containing "foo.cpp" - void filemask1() const - { + void filemask1() const { ASSERT(fooCppMatcher.Match("foo.cpp")); } - void filemaskdifferentcase() const - { + void filemaskdifferentcase() const { std::vector masks(1, "foo.cPp"); PathMatch match(masks, false); ASSERT(match.Match("fOo.cpp")); } - void filemask2() const - { + void filemask2() const { ASSERT(fooCppMatcher.Match("../foo.cpp")); } - void filemask3() const - { + void filemask3() const { ASSERT(fooCppMatcher.Match("src/foo.cpp")); } // Test PathMatch containing "src/foo.cpp" - void filemaskpath1() const - { + void filemaskpath1() const { ASSERT(srcFooCppMatcher.Match("src/foo.cpp")); } - void filemaskpath2() const - { + void filemaskpath2() const { ASSERT(srcFooCppMatcher.Match("proj/src/foo.cpp")); } - void filemaskpath3() const - { + void filemaskpath3() const { ASSERT(!srcFooCppMatcher.Match("foo.cpp")); } - void filemaskpath4() const - { + void filemaskpath4() const { ASSERT(!srcFooCppMatcher.Match("bar/foo.cpp")); } }; diff --git a/test/testpostfixoperator.cpp b/test/testpostfixoperator.cpp index d3f8cf367..07fd7af34 100644 --- a/test/testpostfixoperator.cpp +++ b/test/testpostfixoperator.cpp @@ -27,16 +27,14 @@ extern std::ostringstream errout; class TestPostfixOperator : public TestFixture { public: - TestPostfixOperator() : TestFixture("TestPostfixOperator") - { + TestPostfixOperator() : TestFixture("TestPostfixOperator") { } private: - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -55,8 +53,7 @@ private: checkPostfixOperator.postfixOperator(); } - void run() - { + void run() { TEST_CASE(testsimple); TEST_CASE(testfor); TEST_CASE(testvolatile); @@ -69,14 +66,12 @@ private: TEST_CASE(testcomma); } - void testHangWithInvalidCode() - { + void testHangWithInvalidCode() { check("a,b--\n"); ASSERT_EQUALS("", errout.str()); } - void testsimple() - { + void testsimple() { check("int main()\n" "{\n" " unsigned int k(0);\n" @@ -190,8 +185,7 @@ private: } - void testfor() - { + void testfor() { check("int main()\n" "{\n" " for ( unsigned int i=0; i <= 10; i++) {\n" @@ -244,8 +238,7 @@ private: } - void testvolatile() - { + void testvolatile() { check("class K {};\n" "int main()\n" "{\n" @@ -259,8 +252,7 @@ private: "[test.cpp:6]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); } - void testiterator() - { + void testiterator() { check("class Base {};\n" "int main() {\n" " std::vector v;\n" @@ -317,23 +309,20 @@ private: } - void test2168() - { + void test2168() { check("--> declare allocator lock here\n" "int main(){}"); ASSERT_EQUALS("", errout.str()); } - void pointer() - { + void pointer() { check("static struct class * ab;\n" "int * p;\n" "p++;\n"); ASSERT_EQUALS("", errout.str()); } - void testtemplate() - { + void testtemplate() { check("bool foo() {\n" " std::vector::iterator aIter(aImport.begin());\n" " aIter++;\n" @@ -341,8 +330,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (performance) Prefer prefix ++/-- operators for non-primitive types.\n", errout.str()); } - void testmember() - { + void testmember() { check("bool foo() {\n" " class A {}; class B {A a;};\n" " B b;\n" @@ -358,8 +346,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testcomma() - { + void testcomma() { check("bool foo(int i) {\n" " class A {};\n" " A a;\n" diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 1c72d1111..faa04baef 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -43,34 +43,29 @@ extern std::ostringstream output; class TestPreprocessor : public TestFixture { public: - TestPreprocessor() : TestFixture("TestPreprocessor") - { + TestPreprocessor() : TestFixture("TestPreprocessor") { Preprocessor::macroChar = '$'; } class OurPreprocessor : public Preprocessor { public: - static std::string replaceIfDefined(const std::string &str) - { + static std::string replaceIfDefined(const std::string &str) { Preprocessor p; return p.replaceIfDefined(str); } - static std::string expandMacros(const std::string& code, ErrorLogger *errorLogger = 0) - { + static std::string expandMacros(const std::string& code, ErrorLogger *errorLogger = 0) { return Preprocessor::expandMacros(code, "file.cpp", "", errorLogger); } - static int getHeaderFileName(std::string &str) - { + static int getHeaderFileName(std::string &str) { return Preprocessor::getHeaderFileName(str); } }; private: - void run() - { + void run() { // Just read the code into a string. Perform simple cleanup of the code TEST_CASE(readCode1); TEST_CASE(readCode2); // #4308 - convert C++11 raw string to plain old C string @@ -309,8 +304,7 @@ private: } - void readCode1() - { + void readCode1() { const char code[] = " \t a //\n" " #aa\t /* remove this */\tb \r\n"; Settings settings; @@ -320,8 +314,7 @@ private: ASSERT_EQUALS("a\n#aa b\n", codestr); } - void readCode2() - { + void readCode2() { const char code[] = "R\"( \" /* abc */ \n)\";"; Settings settings; Preprocessor preprocessor(&settings, this); @@ -330,8 +323,7 @@ private: ASSERT_EQUALS("\" \\\" /* abc */ \\n\"\n;", codestr); } - void readCode3() - { + void readCode3() { const char code[] = "func(#errorname)"; Settings settings; Preprocessor preprocessor(&settings, this); @@ -340,8 +332,7 @@ private: ASSERT_EQUALS("func(#errorname)", codestr); } - void readCode4() - { + void readCode4() { const char code[] = "char c = '\\ ';"; Settings settings; errout.str(""); @@ -352,8 +343,7 @@ private: } - void utf16() - { + void utf16() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -406,8 +396,7 @@ private: } - void removeComments() - { + void removeComments() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -433,8 +422,7 @@ private: } - void Bug2190219() - { + void Bug2190219() { const char filedata[] = "int main()\n" "{\n" "#ifdef __cplusplus\n" @@ -496,8 +484,7 @@ private: } - void test1() - { + void test1() { const char filedata[] = "#ifdef WIN32 \n" " abcdef\n" "#else \n" @@ -517,8 +504,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void test2() - { + void test2() { const char filedata[] = "# ifndef WIN32\n" " \" # ifdef WIN32\" // a comment\n" " # else \n" @@ -538,8 +524,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void test3() - { + void test3() { const char filedata[] = "#ifdef ABC\n" "a\n" "#ifdef DEF\n" @@ -562,8 +547,7 @@ private: ASSERT_EQUALS(3, static_cast(actual.size())); } - void test4() - { + void test4() { const char filedata[] = "#ifdef ABC\n" "A\n" "#endif\t\n" @@ -584,8 +568,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void test5() - { + void test5() { const char filedata[] = "#ifdef ABC\n" "A\n" "#else\n" @@ -609,8 +592,7 @@ private: ASSERT_EQUALS(3, static_cast(actual.size())); } - void test6() - { + void test6() { const char filedata[] = "#if(A)\n" "#if ( A ) \n" "#if A\n" @@ -626,8 +608,7 @@ private: ASSERT_EQUALS("#if A\n#if A\n#if A\n#if defined(A)\n#elif defined(A)\n", actual); } - void test7() - { + void test7() { const char filedata[] = "#ifdef ABC\n" "A\n" "#ifdef ABC\n" @@ -659,8 +640,7 @@ private: test7d(); } - void test7a() - { + void test7a() { const char filedata[] = "#ifndef ABC\n" "A\n" "#ifndef ABC\n" @@ -684,8 +664,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void test7b() - { + void test7b() { const char filedata[] = "#ifndef ABC\n" "A\n" "#ifdef ABC\n" @@ -709,8 +688,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void test7c() - { + void test7c() { const char filedata[] = "#ifdef ABC\n" "A\n" "#ifndef ABC\n" @@ -735,8 +713,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void test7d() - { + void test7d() { const char filedata[] = "#if defined(ABC)\n" "A\n" "#if defined(ABC)\n" @@ -761,8 +738,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void test7e() - { + void test7e() { const char filedata[] = "#ifdef ABC\n" "#file \"test.h\"\n" "#ifndef test_h\n" @@ -789,8 +765,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void test8() - { + void test8() { const char filedata[] = "#if A == 1\n" "1\n" "#endif\n"; @@ -812,8 +787,7 @@ private: ASSERT_EQUALS("\n1\n\n", actual["A=1"]); } - void test9() - { + void test9() { const char filedata[] = "#if\n" "#else\n" "#endif\n"; @@ -828,8 +802,7 @@ private: preprocessor.preprocess(istr, actual, "file.c"); // <- don't crash } - void test10() // Ticket #5139 - { + void test10() { // Ticket #5139 const char filedata[] = "#define foo a.foo\n" "#define bar foo\n" "#define baz bar+0\n" @@ -844,8 +817,7 @@ private: preprocessor.preprocess(istr, actual, "file.c"); } - void error1() - { + void error1() { const char filedata[] = "#ifdef A\n" ";\n" "#else\n" @@ -868,8 +840,7 @@ private: } - void error2() - { + void error2() { errout.str(""); const char filedata[] = "#error \xAB\n" @@ -884,8 +855,7 @@ private: } - void error3() - { + void error3() { errout.str(""); Settings settings; settings.userDefines = "__cplusplus"; @@ -896,8 +866,7 @@ private: } // Ticket #2919 - wrong filename reported for #error - void error4() - { + void error4() { // In included file { errout.str(""); @@ -921,8 +890,7 @@ private: } } - void error5() - { + void error5() { errout.str(""); Settings settings; settings.userDefines = "FOO"; @@ -933,8 +901,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void if0_exclude() - { + void if0_exclude() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -951,8 +918,7 @@ private: ASSERT_EQUALS("#if 0\n\n#endif\nB\n", preprocessor.read(code2,"")); } - void if0_whitespace() - { + void if0_whitespace() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -963,8 +929,7 @@ private: ASSERT_EQUALS("#if 0\n\n#endif\nB\n", preprocessor.read(code,"")); } - void if0_else() - { + void if0_else() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -986,8 +951,7 @@ private: "#if 1\nA\n#else\nB\n#endif\nC\n", preprocessor.read(code2,"")); } - void if0_elif() - { + void if0_elif() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -1000,8 +964,7 @@ private: ASSERT_EQUALS("#if 0\n\n#elif 1\nB\n#endif\nC\n", preprocessor.read(code,"")); } - void if0_include_1() - { + void if0_include_1() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -1012,8 +975,7 @@ private: ASSERT_EQUALS("#if 0\n\n#endif\nAB\n", preprocessor.read(code,"")); } - void if0_include_2() - { + void if0_include_2() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -1027,8 +989,7 @@ private: ASSERT_EQUALS("#if 0\n\n#ifdef WIN32\n#else\n#endif\n#endif\nAB\n", preprocessor.read(code,"")); } - void includeguard1() - { + void includeguard1() { // Handling include guards.. const char filedata[] = "#file \"abc.h\"\n" "#ifndef abcH\n" @@ -1049,8 +1010,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void includeguard2() - { + void includeguard2() { // Handling include guards.. const char filedata[] = "#file \"abc.h\"\n" "foo\n" @@ -1073,8 +1033,7 @@ private: } - void ifdefwithfile() - { + void ifdefwithfile() { // Handling include guards.. const char filedata[] = "#ifdef ABC\n" "#file \"abc.h\"\n" @@ -1096,8 +1055,7 @@ private: ASSERT_EQUALS("\n#file \"abc.h\"\nclass A{};\n\n\n\n\n\n\n\n#endfile\n\nint main() {}\n", actual["ABC"]); } - void newlines() - { + void newlines() { const char filedata[] = "\r\r\n\n"; // Preprocess @@ -1109,8 +1067,7 @@ private: - void comments1() - { + void comments1() { { const char filedata[] = "/*\n" "#ifdef WIN32\n" @@ -1168,8 +1125,7 @@ private: - void if0() - { + void if0() { const char filedata[] = " # if /* comment */ 0 // comment\n" "#ifdef WIN32\n" "#endif\n" @@ -1187,8 +1143,7 @@ private: ASSERT_EQUALS(1, static_cast(actual.size())); } - void if1() - { + void if1() { const char filedata[] = " # if /* comment */ 1 // comment\n" "ABC\n" " # endif \n"; @@ -1206,8 +1161,7 @@ private: } - void elif() - { + void elif() { { const char filedata[] = "#if DEF1\n" "ABC\n" @@ -1255,8 +1209,7 @@ private: - void match_cfg_def() - { + void match_cfg_def() { Preprocessor preprocessor(nullptr, this); { @@ -1297,8 +1250,7 @@ private: } - void if_cond1() - { + void if_cond1() { const char filedata[] = "#if LIBVER>100\n" " A\n" "#else\n" @@ -1319,8 +1271,7 @@ private: "", actual["LIBVER=101"]); } - void if_cond2() - { + void if_cond2() { const char filedata[] = "#ifdef A\n" "a\n" "#endif\n" @@ -1346,8 +1297,7 @@ private: if_cond2e(); } - void if_cond2b() - { + void if_cond2b() { const char filedata[] = "#ifndef A\n" "!a\n" "#ifdef B\n" @@ -1371,8 +1321,7 @@ private: ASSERT_EQUALS("\n!a\n\nb\n\n\n\n\n", actual["B"]); } - void if_cond2c() - { + void if_cond2c() { const char filedata[] = "#ifndef A\n" "!a\n" "#ifdef B\n" @@ -1398,8 +1347,7 @@ private: ASSERT_EQUALS("\n!a\n\nb\n\n\n\n\n\n\n", actual["B"]); } - void if_cond2d() - { + void if_cond2d() { const char filedata[] = "#ifndef A\n" "!a\n" "#ifdef B\n" @@ -1431,8 +1379,7 @@ private: ASSERT_EQUALS("\n!a\n\nb\n\n\n\n\n\n\n\n\n\n\n\n", actual["B"]); } - void if_cond2e() - { + void if_cond2e() { const char filedata[] = "#if !defined(A)\n" "!a\n" "#elif !defined(B)\n" @@ -1456,8 +1403,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void if_cond3() - { + void if_cond3() { const char filedata[] = "#ifdef A\n" "a\n" "#if defined(B) && defined(C)\n" @@ -1479,8 +1425,7 @@ private: ASSERT_EQUALS("\na\n\nabc\n\n\n", actual["A;B;C"]); } - void if_cond4() - { + void if_cond4() { { const char filedata[] = "#define A\n" "#define B\n" @@ -1578,8 +1523,7 @@ private: } } - void if_cond5() - { + void if_cond5() { const char filedata[] = "#if defined(A) && defined(B)\n" "ab\n" "#endif\n" @@ -1601,8 +1545,7 @@ private: ASSERT_EQUALS("\nab\n\ncd\n\nef\n\n", actual["A;B"]); } - void if_cond6() - { + void if_cond6() { const char filedata[] = "\n" "#if defined(A) && defined(B))\n" "#endif\n"; @@ -1620,8 +1563,7 @@ private: ASSERT_EQUALS("[file.c:2]: (error) mismatching number of '(' and ')' in this line: defined(A)&&defined(B))\n", errout.str()); } - void if_cond8() - { + void if_cond8() { const char filedata[] = "#if defined(A) + defined(B) + defined(C) != 1\n" "#endif\n"; @@ -1638,8 +1580,7 @@ private: } - void if_cond9() - { + void if_cond9() { const char filedata[] = "#if !defined _A\n" "abc\n" "#endif\n"; @@ -1656,8 +1597,7 @@ private: ASSERT_EQUALS("\nabc\n\n", actual[""]); } - void if_cond10() - { + void if_cond10() { const char filedata[] = "#if !defined(a) && !defined(b)\n" "#if defined(and)\n" "#endif\n" @@ -1671,8 +1611,7 @@ private: preprocessor.preprocess(istr, actual, "file.c"); } - void if_cond11() - { + void if_cond11() { errout.str(""); const char filedata[] = "#if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE\n" "#if LIBGCC2_HAS_DF_MODE\n" @@ -1687,8 +1626,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void if_cond12() - { + void if_cond12() { const char filedata[] = "#define A (1)\n" "#if A == 1\n" ";\n" @@ -1697,8 +1635,7 @@ private: ASSERT_EQUALS("\n\n;\n\n", preprocessor.getcode(filedata,"","")); } - void if_cond13() - { + void if_cond13() { const char filedata[] = "#if ('A' == 0x41)\n" "123\n" "#endif\n"; @@ -1706,8 +1643,7 @@ private: ASSERT_EQUALS("\n123\n\n", preprocessor.getcode(filedata,"","")); } - void if_cond14() - { + void if_cond14() { const char filedata[] = "#if !(A)\n" "123\n" "#endif\n"; @@ -1715,8 +1651,7 @@ private: ASSERT_EQUALS("\n123\n\n", preprocessor.getcode(filedata,"","")); } - void if_cond15() // #4456 - segmentation fault - { + void if_cond15() { // #4456 - segmentation fault const char filedata[] = "#if ((A >= B) && (C != D))\n" "#if (E < F(1))\n" "#endif\n" @@ -1732,8 +1667,7 @@ private: - void if_or_1() - { + void if_or_1() { const char filedata[] = "#if defined(DEF_10) || defined(DEF_11)\n" "a1;\n" "#endif\n"; @@ -1762,8 +1696,7 @@ private: } - void if_or_2() - { + void if_or_2() { const std::string code("#if X || Y\n" "a1;\n" "#endif\n"); @@ -1772,8 +1705,7 @@ private: ASSERT_EQUALS("\na1;\n\n", preprocessor.getcode(code, "Y", "test.c")); } - void if_macro_eq_macro() - { + void if_macro_eq_macro() { const std::string code("#define A B\n" "#define B 1\n" "#define C 1\n" @@ -1791,8 +1723,7 @@ private: ASSERT_EQUALS("\n\n\n\nWilma\n\n\n\n", actual[""]); } - void ticket_3675() - { + void ticket_3675() { const std::string code("#ifdef YYSTACKSIZE\n" "#define YYMAXDEPTH YYSTACKSIZE\n" "#else\n" @@ -1809,8 +1740,7 @@ private: // There's nothing to assert. It just needs to not hang. } - void ticket_3699() - { + void ticket_3699() { const std::string code("#define INLINE __forceinline\n" "#define inline __forceinline\n" "#define __forceinline inline\n" @@ -1828,8 +1758,7 @@ private: ASSERT_EQUALS("\n\n\n\n\n$$$__forceinline $$inline $$__forceinline\n", actual[""]); } - void ticket_4922() // #4922 - { + void ticket_4922() { // #4922 const std::string code("__asm__ \n" "{ int extern __value) 0; (double return (\"\" } extern\n" "__typeof __finite (__finite) __finite __inline \"__GI___finite\");"); @@ -1840,8 +1769,7 @@ private: preprocessor.preprocess(istr, actual, "file.cpp"); } - void multiline1() - { + void multiline1() { const char filedata[] = "#define str \"abc\" \\\n" " \"def\" \n" "abcdef = str;\n"; @@ -1852,8 +1780,7 @@ private: ASSERT_EQUALS("#define str \"abc\" \"def\"\n\nabcdef = str;\n", preprocessor.read(istr, "test.c")); } - void multiline2() - { + void multiline2() { const char filedata[] = "#define sqr(aa) aa * \\\n" " aa\n" "sqr(5);\n"; @@ -1864,8 +1791,7 @@ private: ASSERT_EQUALS("#define sqr(aa) aa * aa\n\nsqr(5);\n", preprocessor.read(istr, "test.c")); } - void multiline3() - { + void multiline3() { const char filedata[] = "const char *str = \"abc\\\n" "def\\\n" "ghi\"\n"; @@ -1876,8 +1802,7 @@ private: ASSERT_EQUALS("const char *str = \"abcdefghi\"\n\n\n", preprocessor.read(istr, "test.c")); } - void multiline4() - { + void multiline4() { errout.str(""); const char filedata[] = "#define A int a = 4;\\ \n" " int b = 5;\n" @@ -1900,8 +1825,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void multiline5() - { + void multiline5() { errout.str(""); const char filedata[] = "#define ABC int a /*\n" "*/= 4;\n" @@ -1922,8 +1846,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void remove_asm() - { + void remove_asm() { std::string str1("#asm\nmov ax,bx\n#endasm"); Preprocessor::removeAsm(str1); ASSERT_EQUALS("asm(\nmov ax,bx\n);", str1); @@ -1933,8 +1856,7 @@ private: ASSERT_EQUALS("\nasm(\nmov ax,bx\n);\n", str2); } - void if_defined() - { + void if_defined() { { const char filedata[] = "#if defined(AAA)\n" "#endif\n"; @@ -1946,16 +1868,14 @@ private: } } - void if_not_defined() - { + void if_not_defined() { const char filedata[] = "#if !defined(AAA)\n" "#endif\n"; ASSERT_EQUALS("#ifndef AAA\n#endif\n", OurPreprocessor::replaceIfDefined(filedata)); } - void macro_simple1() - { + void macro_simple1() { { const char filedata[] = "#define AAA(aa) f(aa)\n" "AAA(5);\n"; @@ -1969,29 +1889,25 @@ private: } } - void macro_simple2() - { + void macro_simple2() { const char filedata[] = "#define min(x,y) x $0 ) $return $1;\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple5() - { + void macro_simple5() { const char filedata[] = "#define ABC if( temp > 0 ) return 1;\n" "\n" "void foo()\n" @@ -2002,87 +1918,75 @@ private: ASSERT_EQUALS("\n\nvoid foo()\n{\n int temp = 0;\n $if( $temp > $0 ) $return $1;\n}\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple6() - { + void macro_simple6() { const char filedata[] = "#define ABC (a+b+c)\n" "ABC\n"; ASSERT_EQUALS("\n$($a+$b+$c)\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple7() - { + void macro_simple7() { const char filedata[] = "#define ABC(str) str\n" "ABC(\"(\")\n"; ASSERT_EQUALS("\n$\"(\"\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple8() - { + void macro_simple8() { const char filedata[] = "#define ABC 123\n" "#define ABCD 1234\n" "ABC ABCD\n"; ASSERT_EQUALS("\n\n$123 $1234\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple9() - { + void macro_simple9() { const char filedata[] = "#define ABC(a) f(a)\n" "ABC( \"\\\"\" );\n" "ABC( \"g\" );\n"; ASSERT_EQUALS("\n$f(\"\\\"\");\n$f(\"g\");\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple10() - { + void macro_simple10() { const char filedata[] = "#define ABC(t) t x\n" "ABC(unsigned long);\n"; ASSERT_EQUALS("\n$unsigned $long $x;\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple11() - { + void macro_simple11() { const char filedata[] = "#define ABC(x) delete x\n" "ABC(a);\n"; ASSERT_EQUALS("\n$delete $a;\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple12() - { + void macro_simple12() { const char filedata[] = "#define AB ab.AB\n" "AB.CD\n"; ASSERT_EQUALS("\n$ab.$AB.CD\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple13() - { + void macro_simple13() { const char filedata[] = "#define TRACE(x)\n" "TRACE(;if(a))\n"; ASSERT_EQUALS("\n$\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple14() - { + void macro_simple14() { const char filedata[] = "#define A \" a \"\n" "printf(A);\n"; ASSERT_EQUALS("\nprintf($\" a \");\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple15() - { + void macro_simple15() { const char filedata[] = "#define FOO\"foo\"\n" "FOO\n"; ASSERT_EQUALS("\n$\"foo\"\n", OurPreprocessor::expandMacros(filedata)); } - void macro_simple16() // # 4703 - { + void macro_simple16() { // # 4703 const char filedata[] = "#define MACRO( A, B, C ) class A##B##C##Creator {};\n" "MACRO( B\t, U , G )"; ASSERT_EQUALS("\n$class $BUGCreator{};", OurPreprocessor::expandMacros(filedata)); } - void macro_simple17() // # 5074 - the Token::isExpandedMacro() doesn't always indicate properly if token comes from macro - { + void macro_simple17() { // # 5074 - the Token::isExpandedMacro() doesn't always indicate properly if token comes from macro // It would probably be OK if the generated code was // "\n123+$123" since the first 123 comes from the source code const char filedata[] = "#define MACRO(A) A+123\n" @@ -2090,8 +1994,7 @@ private: ASSERT_EQUALS("\n$123+$123", OurPreprocessor::expandMacros(filedata)); } - void macro_simple18() // (1e-7) - { + void macro_simple18() { // (1e-7) const char filedata1[] = "#define A (1e-7)\n" "a=A;"; ASSERT_EQUALS("\na=$($1e-7);", OurPreprocessor::expandMacros(filedata1)); @@ -2125,8 +2028,7 @@ private: ASSERT_EQUALS("\na=$($8.0E+007);", OurPreprocessor::expandMacros(filedata8)); } - void macroInMacro1() - { + void macroInMacro1() { { const char filedata[] = "#define A(m) long n = m; n++;\n" "#define B(n) A(n)\n" @@ -2226,23 +2128,20 @@ private: } } - void macroInMacro2() - { + void macroInMacro2() { const char filedata[] = "#define A(x) a##x\n" "#define B 0\n" "A(B)\n"; ASSERT_EQUALS("\n\n$aB\n", OurPreprocessor::expandMacros(filedata)); } - void macro_mismatch() - { + void macro_mismatch() { const char filedata[] = "#define AAA(aa,bb) f(aa)\n" "AAA(5);\n"; ASSERT_EQUALS("\nAAA(5);\n", OurPreprocessor::expandMacros(filedata)); } - void macro_linenumbers() - { + void macro_linenumbers() { const char filedata[] = "#define AAA(a)\n" "AAA(5\n" "\n" @@ -2256,15 +2155,13 @@ private: OurPreprocessor::expandMacros(filedata)); } - void macro_nopar() - { + void macro_nopar() { const char filedata[] = "#define AAA( ) { NULL }\n" "AAA()\n"; ASSERT_EQUALS("\n${ $NULL }\n", OurPreprocessor::expandMacros(filedata)); } - void macro_switchCase() - { + void macro_switchCase() { { // Make sure "case 2" doesn't become "case2" const char filedata[] = "#define A( b ) " @@ -2310,16 +2207,14 @@ private: } } - void macro_NULL() - { + void macro_NULL() { // Let the tokenizer handle NULL. // See ticket #4482 - UB when passing NULL to variadic function ASSERT_EQUALS("\n$0", OurPreprocessor::expandMacros("#define null 0\nnull")); ASSERT_EQUALS("\nNULL", OurPreprocessor::expandMacros("#define NULL 0\nNULL")); } - void string1() - { + void string1() { const char filedata[] = "int main()" "{" " const char *a = \"#define A\n\";" @@ -2337,8 +2232,7 @@ private: ASSERT_EQUALS("int main(){ const char *a = \"#define A\n\";}\n", actual[""]); } - void string2() - { + void string2() { const char filedata[] = "#define AAA 123\n" "str = \"AAA\"\n"; @@ -2346,8 +2240,7 @@ private: ASSERT_EQUALS("\nstr = \"AAA\"\n", OurPreprocessor::expandMacros(filedata)); } - void string3() - { + void string3() { const char filedata[] = "str(\";\");\n"; // Compare results.. @@ -2355,8 +2248,7 @@ private: } - void preprocessor_undef() - { + void preprocessor_undef() { { const char filedata[] = "#define AAA int a;\n" "#undef AAA\n" @@ -2379,8 +2271,7 @@ private: } } - void defdef() - { + void defdef() { const char filedata[] = "#define AAA 123\n" "#define AAA 456\n" "#define AAA 789\n" @@ -2390,8 +2281,7 @@ private: ASSERT_EQUALS("\n\n\n$789\n", OurPreprocessor::expandMacros(filedata)); } - void preprocessor_doublesharp() - { + void preprocessor_doublesharp() { // simple testcase without ## const char filedata1[] = "#define TEST(var,val) var = val\n" "TEST(foo,20);\n"; @@ -2431,8 +2321,7 @@ private: - void preprocessor_include_in_str() - { + void preprocessor_include_in_str() { const char filedata[] = "int main()\n" "{\n" "const char *a = \"#include \n\";\n" @@ -2454,8 +2343,7 @@ private: - void va_args_1() - { + void va_args_1() { const char filedata[] = "#define DBG(fmt...) printf(fmt)\n" "DBG(\"[0x%lx-0x%lx)\", pstart, pend);\n"; @@ -2465,8 +2353,7 @@ private: ASSERT_EQUALS("\n$printf(\"[0x%lx-0x%lx)\",$pstart,$pend);\n", actual); } - void va_args_2() - { + void va_args_2() { const char filedata[] = "#define DBG(fmt, args...) printf(fmt, ## args)\n" "DBG(\"hello\");\n"; @@ -2476,15 +2363,13 @@ private: ASSERT_EQUALS("\n$printf(\"hello\");\n", actual); } - void va_args_3() - { + void va_args_3() { const char filedata[] = "#define FRED(...) { fred(__VA_ARGS__); }\n" "FRED(123)\n"; ASSERT_EQUALS("\n${ $fred($123); }\n", OurPreprocessor::expandMacros(filedata)); } - void va_args_4() - { + void va_args_4() { const char filedata[] = "#define FRED(name, ...) name (__VA_ARGS__)\n" "FRED(abc, 123)\n"; ASSERT_EQUALS("\n$abc($123)\n", OurPreprocessor::expandMacros(filedata)); @@ -2492,8 +2377,7 @@ private: - void multi_character_character() - { + void multi_character_character() { const char filedata[] = "#define FOO 'ABCD'\n" "int main()\n" "{\n" @@ -2514,8 +2398,7 @@ private: } - void stringify() - { + void stringify() { const char filedata[] = "#define STRINGIFY(x) #x\n" "STRINGIFY(abc)\n"; @@ -2525,8 +2408,7 @@ private: ASSERT_EQUALS("\n$\"abc\"\n", actual); } - void stringify2() - { + void stringify2() { const char filedata[] = "#define A(x) g(#x)\n" "A(abc);\n"; @@ -2536,8 +2418,7 @@ private: ASSERT_EQUALS("\n$g(\"abc\");\n", actual); } - void stringify3() - { + void stringify3() { const char filedata[] = "#define A(x) g(#x)\n" "A( abc);\n"; @@ -2547,8 +2428,7 @@ private: ASSERT_EQUALS("\n$g(\"abc\");\n", actual); } - void stringify4() - { + void stringify4() { const char filedata[] = "#define A(x) #x\n" "1 A(\n" "abc\n" @@ -2560,15 +2440,13 @@ private: ASSERT_EQUALS("\n1 $\n\n\"abc\" 2\n", actual); } - void stringify5() - { + void stringify5() { const char filedata[] = "#define A(x) a(#x,x)\n" "A(foo(\"\\\"\"))\n"; ASSERT_EQUALS("\n$a(\"foo(\\\"\\\\\\\"\\\")\",$foo(\"\\\"\"))\n", OurPreprocessor::expandMacros(filedata)); } - void pragma() - { + void pragma() { const char filedata[] = "#pragma once\n" "void f()\n" "{\n" @@ -2586,8 +2464,7 @@ private: ASSERT_EQUALS("\nvoid f()\n{\n}\n", actual[""]); } - void pragma_asm_1() - { + void pragma_asm_1() { const char filedata[] = "#pragma asm\n" " mov r1, 11\n" "#pragma endasm\n" @@ -2609,8 +2486,7 @@ private: ASSERT_EQUALS("\n\n\naaa\n\n\n\nbbb\n", actual[""]); } - void pragma_asm_2() - { + void pragma_asm_2() { const char filedata[] = "#pragma asm\n" " mov @w1, 11\n" "#pragma endasm ( temp=@w1 )\n" @@ -2628,8 +2504,7 @@ private: ASSERT_EQUALS("\n\nasm(temp);\nbbb\n", actual[""]); } - void pragma_once() - { + void pragma_once() { const char code[] = "#pragma once\n" "int x"; @@ -2642,8 +2517,7 @@ private: ASSERT_EQUALS("123.h", *(pragmaOnce.begin())); } - void endifsemicolon() - { + void endifsemicolon() { const char filedata[] = "void f() {\n" "#ifdef A\n" "#endif;\n" @@ -2663,8 +2537,7 @@ private: ASSERT_EQUALS(expected, actual["A"]); } - void handle_error() - { + void handle_error() { { const char filedata[] = "#define A \n" "#define B don't want to \\\n" @@ -2693,8 +2566,7 @@ private: } } - void missing_doublequote() - { + void missing_doublequote() { { const char filedata[] = "#define a\n" "#ifdef 1\n" @@ -2768,8 +2640,7 @@ private: } } - void unicodeInCode() - { + void unicodeInCode() { const std::string filedata("a\xC8"); std::istringstream istr(filedata); errout.str(""); @@ -2779,8 +2650,7 @@ private: ASSERT_EQUALS("[test.cpp:1]: (error) The code contains unhandled characters (character code = 0xc8). Checking continues, but do not expect valid results.\n", errout.str()); } - void unicodeInComment() - { + void unicodeInComment() { const std::string filedata("//\xC8"); std::istringstream istr(filedata); Settings settings; @@ -2788,8 +2658,7 @@ private: ASSERT_EQUALS("", preprocessor.read(istr, "test.cpp")); } - void unicodeInString() - { + void unicodeInString() { const std::string filedata("\"\xC8\""); std::istringstream istr(filedata); Settings settings; @@ -2798,8 +2667,7 @@ private: } - void define_part_of_func() - { + void define_part_of_func() { errout.str(""); const char filedata[] = "#define A g(\n" "void f() {\n" @@ -2819,8 +2687,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void conditionalDefine() - { + void conditionalDefine() { const char filedata[] = "#ifdef A\n" "#define N 10\n" "#else\n" @@ -2843,8 +2710,7 @@ private: } - void multiline_comment() - { + void multiline_comment() { errout.str(""); const char filedata[] = "#define ABC {// \\\n" "}\n" @@ -2863,8 +2729,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void macro_parameters() - { + void macro_parameters() { errout.str(""); const char filedata[] = "#define BC(a, b, c, arg...) \\\n" "AB(a, b, c, ## arg)\n" @@ -2887,8 +2752,7 @@ private: ASSERT_EQUALS("[file.c:6]: (error) Syntax error. Not enough parameters for macro 'BC'.\n", errout.str()); } - void newline_in_macro() - { + void newline_in_macro() { errout.str(""); const char filedata[] = "#define ABC(str) printf( str )\n" "void f()\n" @@ -2909,8 +2773,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void includes() - { + void includes() { { std::string src = "#include a.h"; ASSERT_EQUALS(OurPreprocessor::NoHeader, OurPreprocessor::getHeaderFileName(src)); @@ -2942,8 +2805,7 @@ private: } } - void ifdef_ifdefined() - { + void ifdef_ifdefined() { const char filedata[] = "#ifdef ABC\n" "A\n" "#endif\t\n" @@ -2964,8 +2826,7 @@ private: ASSERT_EQUALS(2, static_cast(actual.size())); } - void define_if1() - { + void define_if1() { Preprocessor preprocessor(nullptr, this); { @@ -2984,8 +2845,7 @@ private: } } - void define_if2() - { + void define_if2() { const char filedata[] = "#define A 22\n" "#define B A\n" "#if (B==A) || (B==C)\n" @@ -2995,8 +2855,7 @@ private: ASSERT_EQUALS("\n\n\nFOO\n\n", preprocessor.getcode(filedata,"","")); } - void define_if3() - { + void define_if3() { const char filedata[] = "#define A 0\n" "#if (A==0)\n" "FOO\n" @@ -3005,8 +2864,7 @@ private: ASSERT_EQUALS("\n\nFOO\n\n", preprocessor.getcode(filedata,"","")); } - void define_if4() - { + void define_if4() { const char filedata[] = "#define X +123\n" "#if X==123\n" "FOO\n" @@ -3015,8 +2873,7 @@ private: ASSERT_EQUALS("\n\nFOO\n\n", preprocessor.getcode(filedata,"","")); } - void define_if5() // #4516 - #define B (A & 0x00f0) - { + void define_if5() { // #4516 - #define B (A & 0x00f0) { const char filedata[] = "#define A 0x0010\n" "#define B (A & 0x00f0)\n" @@ -3046,8 +2903,7 @@ private: } } - void define_if6() // #4516 - #define B (A?1:-1) - { + void define_if6() { // #4516 - #define B (A?1:-1) const char filedata[] = "#ifdef A\n" "#define B (A?1:-1)\n" "#endif\n" @@ -3068,8 +2924,7 @@ private: ASSERT_EQUALS(true, actualA1.find("456") != std::string::npos); } - void define_ifdef() - { + void define_ifdef() { { const char filedata[] = "#define ABC\n" "#ifndef ABC\n" @@ -3164,8 +3019,7 @@ private: } } - void define_ifndef1() - { + void define_ifndef1() { const char filedata[] = "#define A(x) (x)\n" "#ifndef A\n" ";\n" @@ -3183,8 +3037,7 @@ private: ASSERT_EQUALS(1U, actual.size()); } - void define_ifndef2() - { + void define_ifndef2() { const char filedata[] = "#ifdef A\n" "#define B char\n" "#endif\n" @@ -3199,8 +3052,7 @@ private: ASSERT_EQUALS("\n\n\n\n\n\n$char me;\n", preprocessor.getcode(filedata, "A", "a.cpp")); } - void ifndef_define() - { + void ifndef_define() { const char filedata[] = "#ifndef A\n" "#define A(x) x\n" "#endif\n" @@ -3217,8 +3069,7 @@ private: ASSERT_EQUALS("\n\n\n$123;\n", actual[""]); } - void undef_ifdef() - { + void undef_ifdef() { const char filedata[] = "#undef A\n" "#ifdef A\n" "123\n" @@ -3230,8 +3081,7 @@ private: ASSERT_EQUALS("\n\n\n\n", preprocessor.getcode(filedata, "A", "a.cpp")); } - void redundant_config() - { + void redundant_config() { const char filedata[] = "int main() {\n" "#ifdef FOO\n" "#ifdef BAR\n" @@ -3263,8 +3113,7 @@ private: } - void endfile() - { + void endfile() { const char filedata[] = "char a[] = \"#endfile\";\n" "char b[] = \"#endfile\";\n" "#include \"notfound.h\"\n"; @@ -3281,8 +3130,7 @@ private: ASSERT_EQUALS(1, (int)actual.size()); } - void dup_defines() - { + void dup_defines() { const char filedata[] = "#ifdef A\n" "#define B\n" "#if defined(B) && defined(A)\n" @@ -3317,8 +3165,7 @@ private: } } - void testPreprocessorRead1() - { + void testPreprocessorRead1() { const std::string filedata("/*\n*/ # /*\n*/ defi\\\nne FO\\\nO 10\\\n20"); std::istringstream istr(filedata); Settings settings; @@ -3326,8 +3173,7 @@ private: ASSERT_EQUALS("#define FOO 1020", preprocessor.read(istr, "test.cpp")); } - void testPreprocessorRead2() - { + void testPreprocessorRead2() { const std::string filedata("\"foo\\\\\nbar\""); std::istringstream istr(filedata); Settings settings; @@ -3335,8 +3181,7 @@ private: ASSERT_EQUALS("\"foo\\bar\"", preprocessor.read(istr, "test.cpp")); } - void testPreprocessorRead3() - { + void testPreprocessorRead3() { const std::string filedata("#define A \" a \"\n\" b\""); std::istringstream istr(filedata); Settings settings; @@ -3344,8 +3189,7 @@ private: ASSERT_EQUALS(filedata, preprocessor.read(istr, "test.cpp")); } - void testPreprocessorRead4() - { + void testPreprocessorRead4() { { // test < \\> < > (unescaped) const std::string filedata("#define A \" \\\\\"/*space*/ \" \""); @@ -3374,8 +3218,7 @@ private: } } - void invalid_define_1() - { + void invalid_define_1() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -3386,8 +3229,7 @@ private: preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang } - void invalid_define_2() // #4036 - hang - { + void invalid_define_2() { // #4036 - hang Settings settings; Preprocessor preprocessor(&settings, this); @@ -3398,8 +3240,7 @@ private: preprocessor.preprocess(src, processedFile, cfg, "", paths); // don't hang } - void missingInclude() - { + void missingInclude() { Settings settings; Preprocessor preprocessor(&settings, this); Preprocessor::missingIncludeFlag = false; @@ -3413,8 +3254,7 @@ private: ASSERT_EQUALS(true, Preprocessor::missingIncludeFlag); } - void inline_suppression_for_missing_include() - { + void inline_suppression_for_missing_include() { Preprocessor::missingIncludeFlag = false; Settings settings; settings._inlineSuppressions = true; @@ -3435,8 +3275,7 @@ private: ASSERT_EQUALS(false, Preprocessor::missingIncludeFlag); } - void predefine1() - { + void predefine1() { const std::string src("#if defined X || Y\n" "Fred & Wilma\n" "#endif\n"); @@ -3447,8 +3286,7 @@ private: ASSERT_EQUALS("\nFred & Wilma\n\n", actual); } - void predefine2() - { + void predefine2() { const std::string src("#if defined(X) && Y\n" "Fred & Wilma\n" "#endif\n"); @@ -3465,8 +3303,7 @@ private: } } - void predefine3() - { + void predefine3() { // #2871 - define in source is not used if -D is used const char code[] = "#define X 1\n" "#define Y X\n" @@ -3478,8 +3315,7 @@ private: ASSERT_EQUALS("\n\n\nFred & Wilma\n\n", actual); } - void predefine4() - { + void predefine4() { // #3577 const char code[] = "char buf[X];\n"; Preprocessor preprocessor(nullptr,this); @@ -3487,8 +3323,7 @@ private: ASSERT_EQUALS("char buf[$123];\n", actual); } - void predefine5() // #3737, #5119 - automatically define __cplusplus - { + void predefine5() { // #3737, #5119 - automatically define __cplusplus // #3737... const char code[] = "#ifdef __cplusplus\n123\n#endif"; Preprocessor preprocessor(nullptr,this); @@ -3505,8 +3340,7 @@ private: ASSERT_EQUALS(false, Preprocessor::cplusplus(&settings,"test.cpp")); } - void predefine6() // #3737 - using -D and -f => check all matching configurations - { + void predefine6() { // #3737 - using -D and -f => check all matching configurations const char filedata[] = "#ifdef A\n" "1\n" "#else\n" @@ -3532,8 +3366,7 @@ private: } - void simplifyCondition() - { + void simplifyCondition() { // Ticket #2794 std::map cfg; cfg["C"] = ""; @@ -3543,8 +3376,7 @@ private: ASSERT_EQUALS("1", condition); } - void invalidElIf() - { + void invalidElIf() { // #2942 - segfault const char code[] = "#elif (){\n"; Preprocessor preprocessor(nullptr,this); @@ -3552,8 +3384,7 @@ private: ASSERT_EQUALS("\n", actual); } - void def_handleIncludes() - { + void def_handleIncludes() { const std::string filePath("test.c"); const std::list includePaths; std::map defs; @@ -3693,8 +3524,7 @@ private: } } - void def_missingInclude() - { + void def_missingInclude() { const std::list includePaths; std::map defs; defs["AA"] = ""; @@ -3773,8 +3603,7 @@ private: } } - void def_handleIncludes_ifelse1() - { + void def_handleIncludes_ifelse1() { const std::string filePath("test.c"); const std::list includePaths; std::map defs; @@ -3831,8 +3660,7 @@ private: } } - void def_handleIncludes_ifelse2() // #3651 - { + void def_handleIncludes_ifelse2() { // #3651 const char code[] = "#if defined(A)\n" "\n" "#if defined(B)\n" @@ -3856,8 +3684,7 @@ private: preprocessor.handleIncludes(code, "test.c", includePaths, defs, pragmaOnce,std::list()).find("123")); } - void def_handleIncludes_ifelse3() // #4865 - { + void def_handleIncludes_ifelse3() { // #4865 const char code[] = "#ifdef A\n" "#if defined(SOMETHING_NOT_DEFINED)\n" "#else\n" @@ -3877,8 +3704,7 @@ private: preprocessor.handleIncludes(code, "test.c", includePaths, defs, pragmaOnce, std::list()); // don't crash } - void def_valueWithParentheses() - { + void def_valueWithParentheses() { // #define should introduce a new symbol regardless of parentheses in the value // and regardless of white space in weird places (people do this for some reason). const char code[] = "#define A (Fred)\n" @@ -3909,8 +3735,7 @@ private: ASSERT_EQUALS("(Rubble)", defs["D"]); } - void undef1() - { + void undef1() { Settings settings; const char filedata[] = "#ifdef X\n" @@ -3930,8 +3755,7 @@ private: ASSERT_EQUALS("\n\n\n", actual[""]); } - void undef2() - { + void undef2() { Settings settings; const char filedata[] = "#ifndef X\n" @@ -3951,8 +3775,7 @@ private: ASSERT_EQUALS("\nFred & Wilma\n\n", actual[""]); } - void undef3() - { + void undef3() { Settings settings; const char filedata[] = "#define X\n" @@ -3973,8 +3796,7 @@ private: ASSERT_EQUALS("\n\n\n\n", actual[""]); } - void undef4() - { + void undef4() { Settings settings; const char filedata[] = "#define X Y\n" @@ -3995,8 +3817,7 @@ private: ASSERT_EQUALS("\n\n\n\n", actual[""]); } - void undef5() - { + void undef5() { Settings settings; const char filedata[] = "#define X() Y\n" @@ -4017,8 +3838,7 @@ private: ASSERT_EQUALS("\n\n\n\n", actual[""]); } - void undef6() - { + void undef6() { Settings settings; const char filedata[] = "#define X Y\n" @@ -4041,8 +3861,7 @@ private: ASSERT_EQUALS("\n\n\n\nBarney & Betty\n\n", actual[""]); } - void undef7() - { + void undef7() { Settings settings; const char filedata[] = "#define X XDefined\n" @@ -4061,8 +3880,7 @@ private: TODO_ASSERT_EQUALS("\n;\n","\n$XDefined;\n", actual[""]); } - void undef8() - { + void undef8() { Settings settings; const char filedata[] = "#ifdef HAVE_CONFIG_H\n" @@ -4086,8 +3904,7 @@ private: ASSERT_EQUALS("\n\n\n\n\n", actual[""]); } - void undef9() - { + void undef9() { Settings settings; const char filedata[] = "#define X Y\n" @@ -4110,8 +3927,7 @@ private: ASSERT_EQUALS("\n\nFred & Wilma\n\n\n\n", actual[""]); } - void undef10() - { + void undef10() { Settings settings; const char filedata[] = "#ifndef X\n" @@ -4137,8 +3953,7 @@ private: ASSERT_EQUALS("Y", resultConfigurations.back()); } - void handleUndef() - { + void handleUndef() { Settings settings; settings.userUndefs.insert("X"); const Preprocessor preprocessor(&settings, this); @@ -4164,8 +3979,7 @@ private: ASSERT_EQUALS(0U, configurations.size()); } - void macroChar() - { + void macroChar() { const char filedata[] = "#define X 1\nX\n"; ASSERT_EQUALS("\n$1\n", OurPreprocessor::expandMacros(filedata,nullptr)); OurPreprocessor::macroChar = char(1); @@ -4173,8 +3987,7 @@ private: OurPreprocessor::macroChar = '$'; } - void validateCfg() - { + void validateCfg() { Settings settings; Preprocessor preprocessor(&settings, this); @@ -4211,8 +4024,7 @@ private: ASSERT_EQUALS("[test.c:1]: (information) Skipping configuration 'A' since the value of 'A' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.\n", errout.str()); } - void if_sizeof() // #4071 - { + void if_sizeof() { // #4071 static const char* code = "#if sizeof(unsigned short) == 2\n" "Fred & Wilma\n" "#elif sizeof(unsigned short) == 4\n" @@ -4228,8 +4040,7 @@ private: ASSERT_EQUALS("\nFred & Wilma\n\n\n\n\n", actual[""]); } - void double_include() - { + void double_include() { const char code[] = "int x"; Preprocessor preprocessor(nullptr, this); @@ -4241,8 +4052,7 @@ private: preprocessor.handleIncludes(code, "123.h", includePaths, defs, pragmaOnce, std::list()); } - void invalid_ifs() - { + void invalid_ifs() { const char filedata[] = "#ifdef\n" "#endif\n" "#ifdef !\n" diff --git a/test/testsamples.cpp b/test/testsamples.cpp index de7bbd72e..63f404b5e 100644 --- a/test/testsamples.cpp +++ b/test/testsamples.cpp @@ -27,19 +27,16 @@ class TestSamples : public TestFixture { public: - TestSamples() : TestFixture("TestSamples") - { + TestSamples() : TestFixture("TestSamples") { } private: - void run() - { + void run() { TEST_CASE(runSamples); } - void runSamples() const - { + void runSamples() const { REDIRECT; std::map files; diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 50792ada2..dcd21fa94 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -29,14 +29,12 @@ extern std::ostringstream errout; class TestSimplifyTemplate : public TestFixture { public: - TestSimplifyTemplate() : TestFixture("TestSimplifyTemplate") - { + TestSimplifyTemplate() : TestFixture("TestSimplifyTemplate") { } private: - void run() - { + void run() { TEST_CASE(template1); TEST_CASE(template2); TEST_CASE(template3); @@ -98,8 +96,7 @@ private: TEST_CASE(templateParameters1); // #4169 - segmentation fault } - std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) - { + std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { errout.str(""); Settings settings; @@ -116,8 +113,7 @@ private: return tokenizer.tokens()->stringifyList(0, !simplify); } - std::string tok(const char code[], const char filename[]) - { + std::string tok(const char code[], const char filename[]) { errout.str(""); Settings settings; @@ -130,8 +126,7 @@ private: return tokenizer.tokens()->stringifyList(0, false); } - void template1() - { + void template1() { const char code[] = "template void f(T val) { T a; }\n" "f(10);"; @@ -141,8 +136,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template2() - { + void template2() { const char code[] = "template class Fred { T a; };\n" "Fred fred;"; @@ -152,8 +146,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template3() - { + void template3() { const char code[] = "template class Fred { T data[sz]; };\n" "Fred fred;"; @@ -163,8 +156,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template4() - { + void template4() { const char code[] = "template class Fred { Fred(); };\n" "Fred fred;"; @@ -174,8 +166,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template5() - { + void template5() { const char code[] = "template class Fred { };\n" "template Fred::Fred() { }\n" "Fred fred;"; @@ -188,8 +179,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template6() - { + void template6() { const char code[] = "template class Fred { };\n" "Fred fred1;\n" "Fred fred2;"; @@ -201,8 +191,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template7() - { + void template7() { // A template class that is not used => no simplification { const char code[] = "template \n" @@ -268,8 +257,7 @@ private: } // Template definitions but no usage => no expansion - void template8() - { + void template8() { const char code[] = "template class A;\n" "template class B;\n" "\n" @@ -295,8 +283,7 @@ private: ASSERT_EQUALS("class A { template < typename T > int foo ( T d ) ; } ;", tok("class A{ template int foo(T d);};")); } - void template9() - { + void template9() { const char code[] = "template < typename T > class A { } ;\n" "\n" "void f ( ) {\n" @@ -318,8 +305,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template10() - { + void template10() { const char code[] = "template T * foo()\n" "{ return new T[ui]; }\n" "\n" @@ -337,8 +323,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template11() - { + void template11() { const char code[] = "template T * foo()\n" "{ return new T[ui]; }\n" "\n" @@ -356,8 +341,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template12() - { + void template12() { const char code[] = "template \n" "class A : public B\n" "{ };\n" @@ -377,8 +361,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template13() - { + void template13() { const char code[] = "class BB {};\n" "\n" "template \n" @@ -407,8 +390,7 @@ private: tok(code); } - void template14() - { + void template14() { const char code[] = "template <> void foo()\n" "{ x(); }\n" "\n" @@ -426,8 +408,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template15() - { + void template15() { const char code[] = "template void a()\n" "{\n" " a();\n" @@ -452,8 +433,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template16() - { + void template16() { const char code[] = "template void a()\n" "{ }\n" "\n" @@ -474,8 +454,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template17() - { + void template17() { const char code[] = "template\n" "class Fred\n" "{\n" @@ -491,8 +470,7 @@ private: tok(code); } - void template18() - { + void template18() { const char code[] = "template class foo { T a; };\n" "foo *f;"; @@ -502,8 +480,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template19() - { + void template19() { const char code[] = "template T & foo()\n" "{ static T temp; return temp; }\n" "\n" @@ -521,8 +498,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template20() - { + void template20() { // Ticket #1788 - the destructor implementation is lost const char code[] = "template class A\n" "{\n" @@ -544,8 +520,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template21() - { + void template21() { { const char code[] = "template struct Fred { T a; };\n" "Fred fred;"; @@ -589,8 +564,7 @@ private: } } - void template22() - { + void template22() { const char code[] = "template struct Fred { T a; };\n" "Fred fred;"; @@ -600,8 +574,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template23() - { + void template23() { const char code[] = "template void foo() { }\n" "void bar() {\n" " std::cout << (foo());\n" @@ -615,8 +588,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template24() - { + void template24() { // #2648 const char code[] = "template struct B\n" "{\n" @@ -633,8 +605,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template25() - { + void template25() { const char code[] = "template struct B\n" "{\n" " int a[n];\n" @@ -657,8 +628,7 @@ private: } - void template26() - { + void template26() { // #2721 const char code[] = "template\n" "class A { public: T x; };\n" @@ -671,23 +641,20 @@ private: ASSERT_EQUALS("template < class T > class A { public: T x ; } ; C<2> a ; class C<2> : public A < char [ 2 ] > { } ;", tok(code)); } - void template27() - { + void template27() { // #3350 - template inside macro call const char code[] = "X(template class Fred);"; ASSERT_EQUALS("X ( template < class T > class Fred ) ;", tok(code)); } - void template28() - { + void template28() { // #3226 - inner template const char code[] = "template class Fred {};\n" "Fred > x;\n"; ASSERT_EQUALS("Fred> x ; class Fred { } ; class Fred> { } ;", tok(code)); } - void template29() - { + void template29() { // #3449 - garbage code (don't segfault) const char code[] = "template struct A;\n" "struct B { template struct C };\n" @@ -695,22 +662,19 @@ private: ASSERT_EQUALS("template < typename T > struct A ; struct B { template < typename T > struct C } ; { } ;", tok(code)); } - void template30() - { + void template30() { // #3529 - template < template < .. const char code[] = "template class A, class B> void f(){}"; ASSERT_EQUALS("template < template < class > class A , class B > void f ( ) { }", tok(code)); } - void template31() - { + void template31() { // #4010 - template reference type const char code[] = "template struct A{}; A a;"; ASSERT_EQUALS("A a ; struct A { } ;", tok(code)); } - void template32() - { + void template32() { // #3818 - mismatching template not handled well const char code[] = "template struct A { };\n" "\n" @@ -727,8 +691,7 @@ private: "struct B { public: A < int , Pair < int , int > , int > a ; } ;", tok(code)); } - void template33() - { + void template33() { { // #3818 - inner templates in template instantiation not handled well const char code[] = "template struct A { };\n" @@ -755,8 +718,7 @@ private: } } - void template34() - { + void template34() { // #3706 - namespace => hang const char code[] = "namespace abc {\n" "template struct X { void f(X &x) {} };\n" @@ -768,15 +730,13 @@ private: "template < > int X < int > :: Y ( 0 ) ;", tok(code)); } - void template35() // #4074 - "A<'x'> a;" is not recognized as template instantiation - { + void template35() { // #4074 - "A<'x'> a;" is not recognized as template instantiation const char code[] = "template class A {};\n" "A<'x'> a;"; ASSERT_EQUALS("A<'x'> a ; class A<'x'> { } ;", tok(code)); } - void template36() // #4310 - Passing unknown template instantiation as template argument - { + void template36() { // #4310 - Passing unknown template instantiation as template argument const char code[] = "template struct X { T t; };\n" "template struct Y { Foo < X< Bar > > _foo; };\n" // <- Bar is unknown "Y bar;"; @@ -786,8 +746,7 @@ private: tok(code)); } - void template37() // #4544 - A a; - { + void template37() { // #4544 - A a; const char code[] = "class A { };\n" "template class B {};\n" "B b1;\n" @@ -796,14 +755,12 @@ private: tok(code)); } - void template_unhandled() - { + void template_unhandled() { // An unhandled template usage should be simplified.. ASSERT_EQUALS("x ( ) ;", tok("x();")); } - void template38() // #4832 - Crash on C++11 right angle brackets - { + void template38() { // #4832 - Crash on C++11 right angle brackets const char code[] = "template class A {\n" " T mT;\n" "public:\n" @@ -817,8 +774,7 @@ private: tok(code); // Don't crash or freeze } - void template39() // #4742 - Used to freeze in 1.60 - { + void template39() { // #4742 - Used to freeze in 1.60 const char code[] = "template struct vector {" " operator T() const;" "};" @@ -829,8 +785,7 @@ private: tok(code); } - void template40() // #5055 - false negatives when there is template specialization outside struct - { + void template40() { // #5055 - false negatives when there is template specialization outside struct const char code[] = "struct A {" " template struct X { T t; };" "};" @@ -838,8 +793,7 @@ private: ASSERT_EQUALS("struct A { template < typename T > struct X { T t ; } ; } ;", tok(code)); } - void template41() // #4710 - const in template instantiation not handled perfectly - { + void template41() { // #4710 - const in template instantiation not handled perfectly const char code1[] = "template struct X { };\n" "void f(const X x) { }"; ASSERT_EQUALS("void f ( const X x ) { } struct X { } ;", tok(code1)); @@ -849,8 +803,7 @@ private: ASSERT_EQUALS("int x ( ) { return f ( 123 ) ; } int f ( int t ) { return t ; }", tok(code2)); } - void template42() // #4878 cpcheck aborts in ext-blocks.cpp (clang testcode) - { + void template42() { // #4878 cpcheck aborts in ext-blocks.cpp (clang testcode) const char code[] = "template\n" "int f0(Args ...args) {\n" " return ^ {\n" @@ -862,8 +815,7 @@ private: ASSERT_THROW(tok(code), InternalError); } - void template43() // #5097 - Assert due to '>>' in 'B>' not being treated as end of template instantation - { + void template43() { // #5097 - Assert due to '>>' in 'B>' not being treated as end of template instantation const char code[] = "template struct C { };" "template struct D { static int f() { return C::f(); } };" "template inline int f2() { return D::f(); }" @@ -876,8 +828,7 @@ private: tok(code); // Don't assert } - void template44() // #5297 - { + void template44() { // #5297 tok("template struct StackContainer {" " void foo(int i) {" " if (0 >= 1 && i<0) {}" @@ -888,8 +839,7 @@ private: "class FoldedZContainer : public ZContainer {};"); } - void template45() // #5814 - { + void template45() { // #5814 tok("namespace Constants { const int fourtytwo = 42; } " "template struct TypeMath { " " static const int mult = sizeof(T) * U; " @@ -900,8 +850,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void template46() // #5816 - { + void template46() { // #5816 tok("template struct A { static const int value = 0; }; " "template struct B { " " enum { value = A::value }; " @@ -919,22 +868,19 @@ private: ASSERT_EQUALS("", errout.str()); } - void template47() // #6023 - { + void template47() { // #6023 tok("template > class C1 {}; " "class C2 : public C1 {};"); ASSERT_EQUALS("", errout.str()); } - void template48() // #6134 - { + void template48() { // #6134 tok("template int f( { } ); " "int foo = f<1>(0);"); ASSERT_EQUALS("", errout.str()); } - void template49() // #6237 - { + void template49() { // #6237 const char code[] = "template class Fred { void f(); void g(); };\n" "template void Fred::f() { }\n" "template void Fred::g() { }\n" @@ -954,8 +900,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void template50() // #4272 - { + void template50() { // #4272 const char code[] = "template class Fred { void f(); };\n" "template void Fred::f() { }\n" "template<> void Fred::f() { }\n" @@ -974,8 +919,7 @@ private: - void template_default_parameter() - { + void template_default_parameter() { { const char code[] = "template \n" "class A\n" @@ -1064,8 +1008,7 @@ private: } } - void template_default_type() - { + void template_default_type() { const char code[] = "template \n" "class A\n" "{\n" @@ -1094,8 +1037,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void template_typename() - { + void template_typename() { { const char code[] = "template \n" "void foo(typename T::t *)\n" @@ -1116,8 +1058,7 @@ private: } } - void template_constructor() - { + void template_constructor() { // #3152 - if template constructor is removed then there might be // "no constructor" false positives const char code[] = "class Fred {\n" @@ -1132,8 +1073,7 @@ private: ASSERT_EQUALS("class Fred { template < class T > Fred ( T t ) { } }", tok(code2)); } - unsigned int templateParameters(const char code[]) - { + unsigned int templateParameters(const char code[]) { Settings settings; Tokenizer tokenizer(&settings, this); @@ -1143,8 +1083,7 @@ private: return TemplateSimplifier::templateParameters(tokenizer.tokens()); } - void templateParameters() - { + void templateParameters() { // Test that the function TemplateSimplifier::templateParameters works ASSERT_EQUALS(1U, templateParameters(" x;")); ASSERT_EQUALS(1U, templateParameters(" x;")); @@ -1153,8 +1092,7 @@ private: ASSERT_EQUALS(1U, templateParameters(" x;")); } - void templateParameters1() - { + void templateParameters1() { // #4169 - segmentation fault (invalid code) const char code[] = "volatile true , test < test < #ifdef __ppc__ true ,"; // do not crash on invalid code diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 0d3554d63..4f9544db1 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -28,8 +28,7 @@ extern std::ostringstream errout; class TestSimplifyTokens : public TestFixture { public: - TestSimplifyTokens() : TestFixture("TestSimplifyTokens") - { + TestSimplifyTokens() : TestFixture("TestSimplifyTokens") { } @@ -37,8 +36,7 @@ private: Settings settings_std; Settings settings_windows; - void run() - { + void run() { LOAD_LIB_2(settings_std.library, "std.cfg"); LOAD_LIB_2(settings_windows.library, "windows.cfg"); @@ -285,8 +283,7 @@ private: TEST_CASE(simplifyOverride); // ticket #5069 } - std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) - { + std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { errout.str(""); Settings settings; @@ -303,8 +300,7 @@ private: return tokenizer.tokens()->stringifyList(0, !simplify); } - std::string tokWithWindows(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) - { + std::string tokWithWindows(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { errout.str(""); settings_windows.addEnabled("portability"); @@ -320,8 +316,7 @@ private: return tokenizer.tokens()->stringifyList(0, !simplify); } - std::string tok(const char code[], const char filename[]) - { + std::string tok(const char code[], const char filename[]) { errout.str(""); Settings settings; @@ -334,8 +329,7 @@ private: return tokenizer.tokens()->stringifyList(0, false); } - std::string tokWithStdLib(const char code[]) - { + std::string tokWithStdLib(const char code[]) { errout.str(""); Tokenizer tokenizer(&settings_std, this); @@ -347,8 +341,7 @@ private: return tokenizer.tokens()->stringifyList(0, false); } - std::string tokenizeDebugListing(const char code[], bool simplify = false, const char filename[] = "test.cpp") - { + std::string tokenizeDebugListing(const char code[], bool simplify = false, const char filename[] = "test.cpp") { errout.str(""); Settings settings; @@ -364,16 +357,14 @@ private: return tokenizer.tokens()->stringifyList(true); } - void simplifyTokenList1() - { + void simplifyTokenList1() { // #1717 : The simplifyErrNoInWhile needs to be used before simplifyIfAndWhileAssign.. ASSERT_EQUALS("; x = f ( ) ; while ( x == -1 ) { x = f ( ) ; }", tok(";while((x=f())==-1 && errno==EINTR){}",true)); } - void cast() - { + void cast() { ASSERT_EQUALS("if ( ! p ) { ; }", tok("if (p == (char *)0);")); ASSERT_EQUALS("return str ;", tok("return (char *)str;")); @@ -393,8 +384,7 @@ private: } - void iftruefalse() - { + void iftruefalse() { { const char code1[] = " void f() { int a; bool use = false; if( use ) { a=0; } else {a=1;} }"; const char code2[] = " void f() { int a; bool use = false; {a=1;} }"; @@ -467,8 +457,7 @@ private: } } - void combine_strings() - { + void combine_strings() { const char code1[] = "void foo()\n" "{\n" "const char *a =\n" @@ -488,8 +477,7 @@ private: ASSERT_EQUALS(tok(code2), tok(code1)); } - void combine_wstrings() - { + void combine_wstrings() { const char code1[] = "void foo()\n" "{\n" "const wchar_t *a =\n" @@ -517,8 +505,7 @@ private: ASSERT_EQUALS(true, tokenizer.tokens()->tokAt(13) && tokenizer.tokens()->tokAt(13)->isLong()); } - void double_plus() - { + void double_plus() { { const char code1[] = "void foo( int a )\n" "{\n" @@ -580,8 +567,7 @@ private: } } - void redundant_plus() - { + void redundant_plus() { { const char code1[] = "void foo( int a, int b )\n" "{\n" @@ -633,8 +619,7 @@ private: } } - void redundant_plus_numbers() - { + void redundant_plus_numbers() { { const char code1[] = "void foo( int a )\n" "{\n" @@ -687,14 +672,12 @@ private: } - void parentheses1() - { + void parentheses1() { ASSERT_EQUALS("a <= 110 ;", tok("a <= (10+100);")); ASSERT_EQUALS("while ( x ( ) == -1 ) { }", tok("while((x()) == -1){ }")); } - void parenthesesVar() - { + void parenthesesVar() { // remove parentheses.. ASSERT_EQUALS("a = p ;", tok("a = (p);")); ASSERT_EQUALS("if ( a < p ) { }", tok("if(a<(p)){}")); @@ -719,14 +702,12 @@ private: ASSERT_EQUALS("void foo ( int p ) { if ( p >= 0 ) { ; } }", tok("void foo(int p){if((p)>=0);}")); } - void declareVar() - { + void declareVar() { const char code[] = "void f ( ) { char str [ 100 ] = \"100\" ; }"; ASSERT_EQUALS(code, tok(code)); } - void declareArray() - { + void declareArray() { const char code1[] = "void f ( ) { char str [ ] = \"100\" ; }"; const char expected1[] = "void f ( ) { char str [ 4 ] = \"100\" ; }"; ASSERT_EQUALS(expected1, tok(code1)); @@ -740,8 +721,7 @@ private: ASSERT_EQUALS(expected3, tok(code3)); } - void dontRemoveIncrement() - { + void dontRemoveIncrement() { { const char code[] = "void f(int a)\n" "{\n" @@ -767,8 +747,7 @@ private: } } - void removePostIncrement() - { + void removePostIncrement() { const char code[] = "void f(int &c)\n" "{\n" " c = 0;\n" @@ -781,8 +760,7 @@ private: } - void removePreIncrement() - { + void removePreIncrement() { { const char code[] = "void f(int &c)\n" "{\n" @@ -806,8 +784,7 @@ private: } - std::string elseif(const char code[]) - { + std::string elseif(const char code[]) { errout.str(""); Settings settings; @@ -819,8 +796,7 @@ private: return tokenizer.tokens()->stringifyList(false); } - void elseif1() - { + void elseif1() { const char code[] = "else if(ab) { cd } else { ef }gh"; ASSERT_EQUALS("\n\n##file 0\n1: else { if ( ab ) { cd } else { ef } } gh\n", elseif(code)); @@ -859,8 +835,7 @@ private: } - void ifa_ifa() - { + void ifa_ifa() { ASSERT_EQUALS("int a ; if ( a ) { { ab } cd }", tok("int a ; if (a) { if (a) { ab } cd }", true)); ASSERT_EQUALS("int a ; if ( a ) { { ab } cd }", tok("int a ; if (unlikely(a)) { if (a) { ab } cd }", true)); } @@ -868,8 +843,7 @@ private: - unsigned int sizeofFromTokenizer(const char type[]) - { + unsigned int sizeofFromTokenizer(const char type[]) { errout.str(""); Settings settings; @@ -884,8 +858,7 @@ private: - void sizeof_array() - { + void sizeof_array() { const char *code; code = "void foo()\n" @@ -918,8 +891,7 @@ private: ASSERT_EQUALS("char i [ 2 ] [ 20 ] ; 20 ;", tok(code)); } - void sizeof5() - { + void sizeof5() { const char code[] = "const char * names[2];" "for (int i = 0; i != sizeof(names[0]); i++)" @@ -929,8 +901,7 @@ private: ASSERT_EQUALS(expected.str(), tok(code)); } - void sizeof6() - { + void sizeof6() { const char code[] = ";int i;\n" "sizeof(i);\n"; @@ -940,16 +911,14 @@ private: ASSERT_EQUALS(expected.str(), tok(code)); } - void sizeof7() - { + void sizeof7() { const char code[] = ";INT32 i[10];\n" "sizeof(i[0]);\n"; ASSERT_EQUALS("; INT32 i [ 10 ] ; sizeof ( i [ 0 ] ) ;", tok(code, true, Settings::Unspecified)); ASSERT_EQUALS("; int i [ 10 ] ; 4 ;", tokWithWindows(code, true, Settings::Win32A)); } - void sizeof8() - { + void sizeof8() { { const char code[] = "void f()\n" "{\n" @@ -985,8 +954,7 @@ private: } } - void sizeof9() - { + void sizeof9() { // ticket #487 { const char code[] = "; const char *str = \"1\"; sizeof(str);"; @@ -1107,8 +1075,7 @@ private: } } - void sizeof10() - { + void sizeof10() { // ticket #809 const char code[] = "int m ; " "compat_ulong_t um ; " @@ -1117,8 +1084,7 @@ private: ASSERT_EQUALS(code, tok(code, true, Settings::Win32A)); } - void sizeof11() - { + void sizeof11() { // ticket #827 const char code[] = "void f()\n" "{\n" @@ -1149,8 +1115,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void sizeof12() - { + void sizeof12() { // ticket #827 const char code[] = "void f()\n" "{\n" @@ -1167,8 +1132,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void sizeof13() - { + void sizeof13() { // ticket #851 const char code[] = "int main()\n" "{\n" @@ -1192,8 +1156,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void sizeof14() - { + void sizeof14() { // ticket #954 const char code[] = "void f()\n" "{\n" @@ -1211,8 +1174,7 @@ private: ASSERT_EQUALS("sizeof ( ! ! ( a == 1 ) ) ;", tok("sizeof !!(a==1);")); } - void sizeof15() - { + void sizeof15() { // ticket #1020 tok("void f()\n" "{\n" @@ -1222,8 +1184,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sizeof16() - { + void sizeof16() { // ticket #1027 const char code[] = "void f()\n" "{\n" @@ -1234,8 +1195,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sizeof17() - { + void sizeof17() { // ticket #1050 const char code[] = "void f()\n" "{\n" @@ -1246,8 +1206,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sizeof18() - { + void sizeof18() { { std::ostringstream expected; expected << sizeof(short int); @@ -1389,8 +1348,7 @@ private: } } - void sizeof19() - { + void sizeof19() { // ticket #1891 - sizeof 'x' { const char code[] = "void f()\n" @@ -1415,8 +1373,7 @@ private: } } - void sizeof20() - { + void sizeof20() { // ticket #2024 - sizeof a) const char code[] = "struct struct_a {\n" " char a[20];\n" @@ -1433,8 +1390,7 @@ private: "}", tok(code)); } - void sizeof21() - { + void sizeof21() { // ticket #2232 - sizeof...(Args) const char code[] = "struct Internal {\n" " int operator()(const Args&... args) const {\n" @@ -1453,8 +1409,7 @@ private: tok(code); } - void sizeof22() - { + void sizeof22() { // ticket #2599 segmentation fault const char code[] = "sizeof\n"; @@ -1462,8 +1417,7 @@ private: tok(code); } - void sizeof23() - { + void sizeof23() { // ticket #2604 segmentation fault const char code[] = "sizeof <= A\n"; @@ -1472,8 +1426,7 @@ private: } - void sizeofsizeof() - { + void sizeofsizeof() { // ticket #1682 const char code[] = "void f()\n" "{\n" @@ -1483,8 +1436,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void casting() - { + void casting() { { const char code[] = "void f()\n" "{\n" @@ -1520,8 +1472,7 @@ private: } - void strlen1() - { + void strlen1() { ASSERT_EQUALS("4", tok("strlen(\"abcd\")")); { @@ -1555,16 +1506,14 @@ private: } - void strlen2() - { + void strlen2() { // #4530 - make sure calculation with strlen is simplified ASSERT_EQUALS("i = -4 ;", tok("i = (strlen(\"abcd\") - 8);")); } - void namespaces() - { + void namespaces() { { const char code[] = "namespace std { }"; @@ -1603,8 +1552,7 @@ private: } - std::string simplifyIfAndWhileAssign(const char code[]) - { + std::string simplifyIfAndWhileAssign(const char code[]) { errout.str(""); Settings settings; // tokenize.. @@ -1617,8 +1565,7 @@ private: return tokenizer.tokens()->stringifyList(0, false); } - void ifassign1() - { + void ifassign1() { ASSERT_EQUALS("; a = b ; if ( a ) { ; }", simplifyIfAndWhileAssign(";if(a=b);")); ASSERT_EQUALS("; a = b ( ) ; if ( a ) { ; }", simplifyIfAndWhileAssign(";if((a=b()));")); ASSERT_EQUALS("; a = b ( ) ; if ( ! ( a ) ) { ; }", simplifyIfAndWhileAssign(";if(!(a=b()));")); @@ -1630,8 +1577,7 @@ private: tok("void foo(A a) {if((a.c=b())>=0);}")); } - void ifAssignWithCast() - { + void ifAssignWithCast() { const char *code = "void foo()\n" "{\n" "FILE *f;\n" @@ -1652,8 +1598,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void whileAssign1() - { + void whileAssign1() { ASSERT_EQUALS("; a = b ; while ( a ) { b = 0 ; a = b ; }", simplifyIfAndWhileAssign(";while(a=b) { b = 0; }")); ASSERT_EQUALS("; a . b = c ; while ( a . b ) { c = 0 ; a . b = c ; }", simplifyIfAndWhileAssign(";while(a.b=c) { c=0; }")); ASSERT_EQUALS("struct hfs_bnode * node ; " @@ -1667,8 +1612,7 @@ private: tok("char *s; while (0 == (s=new char[10])) { }")); } - void whileAssign2() - { + void whileAssign2() { // #1909 - Internal error tok("void f()\n" "{\n" @@ -1681,8 +1625,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void whileAssign3() - { + void whileAssign3() { // #4254 - Variable id const char code[] = "void f() {\n" " int a;\n" @@ -1695,8 +1638,7 @@ private: "4: }\n", tokenizeDebugListing(code, true, "test.c")); } - void whileAssign4() - { + void whileAssign4() { errout.str(""); Settings settings; @@ -1713,8 +1655,7 @@ private: } } - void doWhileAssign() - { + void doWhileAssign() { ASSERT_EQUALS("; do { a = b ; } while ( a ) ;", simplifyIfAndWhileAssign(";do { } while(a=b);")); ASSERT_EQUALS("; do { a . a = 0 ; a . b = c ; } while ( a . b ) ;", simplifyIfAndWhileAssign(";do { a.a = 0; } while(a.b=c);")); ASSERT_EQUALS("struct hfs_bnode * node ; " @@ -1729,8 +1670,7 @@ private: ASSERT_EQUALS("; do { current = f ( ) ; } while ( current ) ;", simplifyIfAndWhileAssign(";do { } while((current=f()) != NULL);")); } - void ifnot() - { + void ifnot() { ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(0==x);", false)); ASSERT_EQUALS("if ( ! x ) { ; }", tok("if(x==0);", false)); ASSERT_EQUALS("if ( ! ( a = b ) ) { ; }", tok("if(0==(a=b));", false)); @@ -1743,8 +1683,7 @@ private: ASSERT_EQUALS("if ( ! ( ! fclose ( fd ) ) ) { ; }", tok("if(!(fclose(fd) == 0));", false)); } - void not1() - { + void not1() { ASSERT_EQUALS("void f ( ) { if ( ! p ) { ; } }", tok("void f() { if (not p); }", false)); ASSERT_EQUALS("void f ( ) { if ( p && ! q ) { ; } }", tok("void f() { if (p && not q); }", false)); ASSERT_EQUALS("void f ( ) { a = ! ( p && q ) ; }", tok("void f() { a = not(p && q); }", false)); @@ -1756,8 +1695,7 @@ private: ASSERT_EQUALS("int foo ( not i ) { return g ( i ) ; }", tok("int foo(not i) { return g(i); }", false)); } - void and1() - { + void and1() { ASSERT_EQUALS("void f ( ) { if ( p && q ) { ; } }", tok("void f() { if (p and q) ; }", false)); @@ -1780,8 +1718,7 @@ private: tok("void f() { r = (a || b) and (c || d); }", false)); } - void or1() - { + void or1() { ASSERT_EQUALS("void f ( ) { if ( p || q ) { ; } }", tok("void f() { if (p or q) ; }", false)); @@ -1804,8 +1741,7 @@ private: tok("void f() { r = (a && b) or (c && d); }", false)); } - void cAlternativeTokens() - { + void cAlternativeTokens() { ASSERT_EQUALS("void f ( ) { err = err | ( ( r & s ) && ! t ) ; }", tok("void f() { err or_eq ((r bitand s) and not t); }", false)); ASSERT_EQUALS("void f ( ) const { r = f ( a [ 4 ] | 15 , ~ c , ! d ) ; }", @@ -1813,8 +1749,7 @@ private: } - void comma_keyword() - { + void comma_keyword() { { const char code[] = "void foo()\n" "{\n" @@ -1918,8 +1853,7 @@ private: } } - void remove_comma() - { + void remove_comma() { { const char code[] = "void f()\n" "{\n" @@ -2006,8 +1940,7 @@ private: } } - void simplifyConditionOperator() - { + void simplifyConditionOperator() { { const char code[] = "(0?(false?1:2):3)"; ASSERT_EQUALS("( 3 )", tok(code)); @@ -2096,8 +2029,7 @@ private: } } - void calculations() - { + void calculations() { { const char code[] = "a[i+8+2]"; ASSERT_EQUALS("a [ i + 10 ]", tok(code)); @@ -2162,8 +2094,7 @@ private: ASSERT_EQUALS("new ( auto ) ( 4 ) ;", tok("new (auto)(4);")); } - void comparisons() - { + void comparisons() { ASSERT_EQUALS("( 1 )", tok("( 1 < 2 )")); ASSERT_EQUALS("( x )", tok("( x && 1 < 2 )")); ASSERT_EQUALS("( 5 )", tok("( 1 < 2 && 3 < 4 ? 5 : 6 )")); @@ -2171,8 +2102,7 @@ private: } - void simplifyFlowControl() - { + void simplifyFlowControl() { const char code1[] = "void f() {\n" " return;\n" " y();\n" @@ -2192,8 +2122,7 @@ private: ASSERT_EQUALS("void f ( ) { x . abort ( ) ; y ( ) ; }", tokWithStdLib(code3)); } - void flowControl() - { + void flowControl() { { ASSERT_EQUALS("void f ( ) { exit ( 0 ) ; }", tokWithStdLib("void f() { exit(0); foo(); }")); ASSERT_EQUALS("void f ( ) { exit ( 0 ) ; }", tokWithStdLib("void f() { exit(0); if (m) foo(); }")); @@ -2488,8 +2417,7 @@ private: "}"); } - void strcat1() - { + void strcat1() { const char code[] = "; strcat(strcat(strcat(strcat(strcat(strcat(dst, \"this \"), \"\"), \"is \"), \"a \"), \"test\"), \".\");"; const char expect[] = "; " "strcat ( dst , \"this \" ) ; " @@ -2501,8 +2429,7 @@ private: ASSERT_EQUALS(expect, tok(code)); } - void strcat2() - { + void strcat2() { const char code[] = "; strcat(strcat(dst, foo[0]), \" \");"; const char expect[] = "; " "strcat ( dst , foo [ 0 ] ) ; " @@ -2511,16 +2438,14 @@ private: ASSERT_EQUALS(expect, tok(code)); } - void simplifyAtol() - { + void simplifyAtol() { ASSERT_EQUALS("a = std :: atol ( x ) ;", tok("a = std::atol(x);")); ASSERT_EQUALS("a = atol ( \"text\" ) ;", tok("a = atol(\"text\");")); ASSERT_EQUALS("a = 0 ;", tok("a = std::atol(\"0\");")); ASSERT_EQUALS("a = 10 ;", tok("a = atol(\"0xa\");")); } - void simplifyOperator1() - { + void simplifyOperator1() { // #3237 - error merging namespaces with operators const char code[] = "class c {\n" "public:\n" @@ -2535,13 +2460,11 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void reverseArraySyntax() - { + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]")); } - void simplify_numeric_condition() - { + void simplify_numeric_condition() { { const char code[] = "void f()\n" @@ -2631,8 +2554,7 @@ private: } } - void simplify_condition() - { + void simplify_condition() { { const char code[] = "void f(int a)\n" @@ -2707,8 +2629,7 @@ private: } - void pointeralias1() - { + void pointeralias1() { { const char code[] = "void f()\n" "{\n" @@ -2793,8 +2714,7 @@ private: } } - void pointeralias2() - { + void pointeralias2() { const char code[] = "void f()\n" "{\n" " int i;\n" @@ -2804,8 +2724,7 @@ private: ASSERT_EQUALS("void f ( ) { int i ; return i ; }", tok(code)); } - void pointeralias3() - { + void pointeralias3() { const char code[] = "void f()\n" "{\n" " int i, j, *p;\n" @@ -2823,8 +2742,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void pointeralias4() - { + void pointeralias4() { const char code[] = "void f()\n" "{\n" " int a[10];\n" @@ -2839,8 +2757,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void pointeralias5() - { + void pointeralias5() { const char code[] = "int f()\n" "{\n" " int i;\n" @@ -2855,13 +2772,11 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void reduceConstness() - { + void reduceConstness() { ASSERT_EQUALS("char * p ;", tok("char * const p;")); } - void while0() - { + void while0() { ASSERT_EQUALS("; x = 1 ;", tok("; do { x = 1 ; } while (0);")); ASSERT_EQUALS("; return 0 ;", tok("; do { return 0; } while (0);")); ASSERT_EQUALS("void foo ( ) { goto label ; }", tok("void foo() { do { goto label; } while (0); }")); @@ -2871,8 +2786,7 @@ private: ASSERT_EQUALS(";", tok("; while (false) { switch (n) { case 0: return; default: break; } n*=1; }")); } - void while0for() - { + void while0for() { // for (condition is always false) ASSERT_EQUALS("void f ( ) { }", tok("void f() { int i; for (i = 0; i < 0; i++) { a; } }")); //ticket #3140 @@ -2885,40 +2799,35 @@ private: ASSERT_EQUALS("void f ( ) { }", tok("void f() { int n = 0; for (signed long long i = 0; i < n; i++) { a; } }")); } - void while1() - { + void while1() { // ticket #1197 const char code[] = "void do {} while (0) { }"; const char expected[] = "void { }"; ASSERT_EQUALS(expected, tok(code)); } - void enum1() - { + void enum1() { const char code[] = "enum A { a, b, c }; A c1 = c;"; const char expected[] = "int c1 ; c1 = 2 ;"; ASSERT_EQUALS(expected, tok(code, false)); } - void enum2() - { + void enum2() { const char code[] = "enum A { a, }; int array[a];"; const char expected[] = "int array [ 0 ] ;"; ASSERT_EQUALS(expected, tok(code, false)); } - void enum3() - { + void enum3() { const char code[] = "enum { a, }; int array[a];"; const char expected[] = "int array [ 0 ] ;"; ASSERT_EQUALS(expected, tok(code, false)); } - void enum4() - { + void enum4() { { const char code[] = "class A {\n" "public:\n" @@ -2968,8 +2877,7 @@ private: } } - void enum5() - { + void enum5() { const char code[] = "enum ABC {\n" " a = sizeof(int),\n" " b = 1 + a,\n" @@ -2992,15 +2900,13 @@ private: ASSERT_EQUALS("int sum ; sum = 508 ;", tok(code, true)); } - void enum6() - { + void enum6() { const char code[] = "enum { a = MAC(A, B, C) }; void f(a) { }"; const char expected[] = "void f ( a ) { }"; ASSERT_EQUALS(expected, tok(code, false)); } - void enum7() - { + void enum7() { { // ticket 1388 const char code[] = "enum FOO {A,B,C};\n" @@ -3026,8 +2932,7 @@ private: } // Check simplifyEnum - std::string checkSimplifyEnum(const char code[], bool cpp = true) - { + std::string checkSimplifyEnum(const char code[], bool cpp = true) { errout.str(""); // Tokenize.. Settings settings; @@ -3038,8 +2943,7 @@ private: return tokenizer.tokens()->stringifyList(0, true); } - void enum8() - { + void enum8() { // ticket 1388 checkSimplifyEnum("enum Direction {N=100,E,S,W,ALL};\n" "template class EF_Vector{\n" @@ -3080,8 +2984,7 @@ private: "[test.cpp:23] -> [test.cpp:1]: (style) Template parameter 'S' hides enumerator with same name\n", errout.str()); } - void enum9() - { + void enum9() { // ticket 1404 checkSimplifyEnum("class XX {\n" "public:\n" @@ -3096,8 +2999,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void enum10() - { + void enum10() { // ticket 1445 const char code[] = "enum {\n" "SHELL_SIZE = sizeof(union { int i; char *cp; double d; }) - 1,\n" @@ -3108,8 +3010,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void enum11() - { + void enum11() { const char code[] = "int main()\n" "{\n" " enum { u, v };\n" @@ -3126,8 +3027,7 @@ private: "[test.cpp:4] -> [test.cpp:3]: (style) Variable 'v' hides enumerator with same name\n", errout.str()); } - void enum12() - { + void enum12() { const char code[] = "enum fred { a, b };\n" "void foo()\n" "{\n" @@ -3137,8 +3037,7 @@ private: ASSERT_EQUALS(expected, checkSimplifyEnum(code)); } - void enum13() - { + void enum13() { const char code[] = "enum ab { ENTRY(1, a = 0), ENTRY(2, b) };\n" "void foo()\n" "{\n" @@ -3148,16 +3047,14 @@ private: ASSERT_EQUALS(expected, checkSimplifyEnum(code)); } - void enum14() - { + void enum14() { const char code[] = "enum ab { a };\n" "ab"; const char expected[] = "ab"; ASSERT_EQUALS(expected, checkSimplifyEnum(code)); } - void enum15() // C++0x features - { + void enum15() { // C++0x features { const char code[] = "enum : char { a = 99 };\n" "char c1 = a;"; @@ -3216,14 +3113,12 @@ private: } } - void enum16() // ticket #1988 - { + void enum16() { // ticket #1988 const char code[] = "enum D : auto * { FF = 0 };"; ASSERT_THROW(checkSimplifyEnum(code), InternalError); } - void enum17() // ticket #2381 - { + void enum17() { // ticket #2381 // if header is included twice its enums will be duplicated const char code[] = "enum ab { a=0, b };" "enum ab { a=0, b };\n"; @@ -3231,35 +3126,30 @@ private: ASSERT_EQUALS("", errout.str()); } - void enum18() // ticket #2466 - array with same name as enum constant - { + void enum18() { // ticket #2466 - array with same name as enum constant const char code[] = "enum ab { a=0, b };\n" "void f() { a[0]; }\n"; ASSERT_EQUALS("void f ( ) { a [ 0 ] ; }", checkSimplifyEnum(code)); } - void enum19() // ticket #2536 - { + void enum19() { // ticket #2536 const char code[] = "enum class E1;\n" "enum class E2 : int;\n"; ASSERT_EQUALS(";", checkSimplifyEnum(code)); } - void enum20() // ticket #2600 segmentation fault - { + void enum20() { // ticket #2600 segmentation fault const char code[] = "enum { const }\n"; ASSERT_EQUALS("", checkSimplifyEnum(code)); } - void enum21() // ticket #2720 syntax error - { + void enum21() { // ticket #2720 syntax error const char code[] = "enum E2 : signed const short { };\n"; ASSERT_EQUALS(";", checkSimplifyEnum(code)); ASSERT_EQUALS("", errout.str()); } - void enum22() // ticket #2745 - { + void enum22() { // ticket #2745 const char code[] = "enum en { x = 0 };\n" "void f() {\n" " int x = 0;\n" @@ -3286,8 +3176,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void enum23() // ticket #2804 - { + void enum23() { // ticket #2804 const char code[] = "enum Enumerator : std::uint8_t { ITEM1, ITEM2, ITEM3 };\n" "Enumerator e = ITEM3;\n"; const char expected[] = "std :: uint8_t e ; e = 2 ;"; @@ -3295,8 +3184,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void enum24() // ticket #2828 - { + void enum24() { // ticket #2828 const char code[] = "enum EnumName { STYLE = 0x0001 };\n" "void f(long style) {\n" " if (style & STYLE) { }\n" @@ -3306,27 +3194,23 @@ private: ASSERT_EQUALS("", errout.str()); } - void enum25() // ticket #2966 (segmentation fault) - { + void enum25() { // ticket #2966 (segmentation fault) const char code[] = "enum x :\n"; ASSERT_THROW(checkSimplifyEnum(code), InternalError); } - void enum26() // ticket #2975 (segmentation fault) - { + void enum26() { // ticket #2975 (segmentation fault) const char code[] = "enum E {} e enum\n"; checkSimplifyEnum(code); ASSERT_EQUALS("", errout.str()); } - void enum27() // ticket #3005 (segmentation fault) - { + void enum27() { // ticket #3005 (segmentation fault) const char code[] = "enum : x\n"; ASSERT_THROW(checkSimplifyEnum(code), InternalError); } - void enum28() - { + void enum28() { const char code[] = "enum { x=0 };\n" "void f() { char x[4]; memset(x, 0, 4);\n" "{ x } };\n" @@ -3334,14 +3218,12 @@ private: ASSERT_EQUALS("void f ( ) { char x [ 4 ] ; memset ( x , 0 , 4 ) ; { x } } ; void g ( ) { 0 ; }", checkSimplifyEnum(code)); } - void enum29() // #3747 - bitwise or value - { + void enum29() { // #3747 - bitwise or value const char code[] = "enum { x=1, y=x|2 }; i = (3==y);"; ASSERT_EQUALS("i = 3 == 3 ;", checkSimplifyEnum(code)); } - void enum30() // #3852 - false positive - { + void enum30() { // #3852 - false positive const char code [] = "class TestIf\n" "{\n" "public:\n" @@ -3363,44 +3245,37 @@ private: ASSERT_EQUALS("", errout.str()); } - void enum31() // #3934 - calculation in first item - { + void enum31() { // #3934 - calculation in first item const char code[] = "enum { x=2*32, y }; i = y;"; ASSERT_EQUALS("i = 65 ;", checkSimplifyEnum(code)); } - void enum32() // #3998 - wrong enum simplification => access violation - { + void enum32() { // #3998 - wrong enum simplification => access violation const char code[] = "enum { x=(32), y=x, z }; { a, z }"; ASSERT_EQUALS("{ a , ( 33 ) }", checkSimplifyEnum(code)); } - void enum33() // #4015 - segmentation fault - { + void enum33() { // #4015 - segmentation fault const char code[] = "enum { A=SOME_VALUE, B=A };"; ASSERT_EQUALS(";", checkSimplifyEnum(code)); } - void enum34() // #4141 - division by zero - { + void enum34() { // #4141 - division by zero const char code[] = "enum { A=1/0 };"; ASSERT_EQUALS(";", checkSimplifyEnum(code)); } - void enum35() // #3953 - avoid simplification of type - { + void enum35() { // #3953 - avoid simplification of type ASSERT_EQUALS("void f ( A * a ) ;", checkSimplifyEnum("enum { A }; void f(A * a) ;")); ASSERT_EQUALS("void f ( A * a ) { }", checkSimplifyEnum("enum { A }; void f(A * a) { }")); } - void enum36() // #4378 - { + void enum36() { // #4378 const char code[] = "struct X { enum Y { a, b }; X(Y) { Y y = (Y)1; } };"; ASSERT_EQUALS("struct X { X ( int ) { int y ; y = ( int ) 1 ; } } ;", checkSimplifyEnum(code)); } - void enum37() // #4280 - shadow variables - { + void enum37() { // #4280 - shadow variables const char code1[] = "enum { a, b }; void f(int a) { return a + 1; }"; ASSERT_EQUALS("void f ( int a ) { return a + 1 ; }", checkSimplifyEnum(code1)); @@ -3418,28 +3293,24 @@ private: ASSERT_EQUALS("", errout.str()); } - void enum38() // #4463 - { + void enum38() { // #4463 const char code[] = "enum { a,b }; void f() { throw a; }"; checkSimplifyEnum(code); ASSERT_EQUALS("", errout.str()); } - void enum39() // #5145 - fp variable hides enum - { + void enum39() { // #5145 - fp variable hides enum const char code[] = "enum { A }; void f() { int a = 1 * A; }"; checkSimplifyEnum(code); ASSERT_EQUALS("", errout.str()); } - void enum40() - { + void enum40() { const char code[] = "enum { A=(1<<0)|(1<<1) }; void f() { x = y + A; }"; ASSERT_EQUALS("void f ( ) { x = y + ( 3 ) ; }", checkSimplifyEnum(code)); } - void enum41() // ticket #5212 (valgrind errors during enum simplification) - { + void enum41() { // ticket #5212 (valgrind errors during enum simplification) const char code[] = "namespace Foo {\n" " enum BarConfig {\n" " eBitOne = (1 << 0),\n" @@ -3451,29 +3322,25 @@ private: ASSERT_EQUALS("int x ; x = ( 1 ) | 2 ;", checkSimplifyEnum(code)); } - void enum42() // ticket #5182 (template function call in template value) - { + void enum42() { // ticket #5182 (template function call in template value) const char code[] = "enum { A = f() };\n" "a = A;"; ASSERT_EQUALS("a = f < int , 2 > ( ) ;", checkSimplifyEnum(code)); } - void enum43() // lhs in assignment - { + void enum43() { // lhs in assignment const char code[] = "enum { A, B };\n" "A = 1;"; ASSERT_EQUALS("A = 1 ;", checkSimplifyEnum(code)); } - void enumscope1() // #3949 - don't simplify enum from one function in another function - { + void enumscope1() { // #3949 - don't simplify enum from one function in another function const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n" "void bar() { int a = A; }"; ASSERT_EQUALS("void foo ( ) { } void bar ( ) { int a ; a = A ; }", checkSimplifyEnum(code)); } - void duplicateDefinition() // #3565 - wrongly detects duplicate definition - { + void duplicateDefinition() { // #3565 - wrongly detects duplicate definition const Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr("x ; return a not_eq x;"); @@ -3482,8 +3349,7 @@ private: ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&x_token, tokenizer.tokens())); } - void invalid_enum() // #5600: missing include causes invalid enum - { + void invalid_enum() { // #5600: missing include causes invalid enum const char code [] = "enum {\n" " NUM_OPCODES = \n" // #include "definition" @@ -3494,8 +3360,7 @@ private: ASSERT_THROW(checkSimplifyEnum(code), InternalError); } - void removestd() - { + void removestd() { ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);")); ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);")); ASSERT_EQUALS("; strncpy ( a , b , 10 ) ;", tok("; std::strncpy(a,b,10);")); @@ -3504,8 +3369,7 @@ private: ASSERT_EQUALS("; malloc ( 10 ) ;", tok("; std::malloc(10);")); } - void simplifyInitVar() - { + void simplifyInitVar() { // ticket #1005 - int *p(0); => int *p = 0; { const char code[] = "void foo() { int *p(0); }"; @@ -3523,8 +3387,7 @@ private: } } - void simplifyReference() - { + void simplifyReference() { ASSERT_EQUALS("void f ( ) { int a ; a ++ ; }", tok("void f() { int a; int &b(a); b++; }")); ASSERT_EQUALS("void f ( ) { int a ; a ++ ; }", @@ -3534,8 +3397,7 @@ private: tok("void test() { c.f(7); T3 &t3 = c; }")); // #6133 } - void simplifyRealloc() - { + void simplifyRealloc() { ASSERT_EQUALS("; free ( p ) ; p = 0 ;", tok("; p = realloc(p, 0);")); ASSERT_EQUALS("; p = malloc ( 100 ) ;", tok("; p = realloc(0, 100);")); ASSERT_EQUALS("; p = malloc ( 0 ) ;", tok("; p = realloc(0, 0);")); @@ -3546,16 +3408,14 @@ private: ASSERT_EQUALS("; p = malloc ( f ( 1 ) ) ;", tok("; p = realloc(0, f(1));")); } - void simplifyErrNoInWhile() - { + void simplifyErrNoInWhile() { ASSERT_EQUALS("; while ( f ( ) ) { }", tok("; while (f() && errno == EINTR) { }")); ASSERT_EQUALS("; while ( f ( ) ) { }", tok("; while (f() && (errno == EINTR)) { }")); } - void simplifyFuncInWhile() - { + void simplifyFuncInWhile() { ASSERT_EQUALS("int cppcheck:r1 = fclose ( f ) ; " "while ( cppcheck:r1 ) " "{ " @@ -3584,8 +3444,7 @@ private: tok("while(fclose(f)); while(fclose(g));")); } - void initstruct() - { + void initstruct() { ASSERT_EQUALS("; struct A a ; a . buf = 3 ;", tok("; struct A a ; a = { .buf = 3 };")); ASSERT_EQUALS("; struct A a ; a . buf = x ;", tok("; struct A a ; a = { .buf = x };")); ASSERT_EQUALS("; struct A a ; a . buf = & key ;", tok("; struct A a ; a = { .buf = &key };")); @@ -3595,8 +3454,7 @@ private: tok("; struct A a = { .buf = {0} };")); } - void simplifyStructDecl1() - { + void simplifyStructDecl1() { { const char code[] = "struct ABC { } abc;"; const char expected[] = "struct ABC { } ; struct ABC abc ;"; @@ -3738,15 +3596,13 @@ private: } } - void simplifyStructDecl2() // ticket #2479 (segmentation fault) - { + void simplifyStructDecl2() { // ticket #2479 (segmentation fault) const char code[] = "struct { char c; }"; const char expected[] = "struct { char c ; }"; ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyStructDecl3() - { + void simplifyStructDecl3() { { const char code[] = "class ABC { } abc;"; const char expected[] = "class ABC { } ; ABC abc ;"; @@ -3868,8 +3724,7 @@ private: } } - void simplifyStructDecl4() - { + void simplifyStructDecl4() { const char code[] = "class ABC {\n" " void foo() {\n" " union {\n" @@ -3897,8 +3752,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyStructDecl5() - { + void simplifyStructDecl5() { const char code[] = "\n" "{\n" " struct {\n" @@ -3909,8 +3763,7 @@ private: tok(code, false); } - void simplifyStructDecl6() - { + void simplifyStructDecl6() { ASSERT_EQUALS("struct A { " "char integers [ X ] ; " "} ; struct A arrays ; arrays = { { 0 } } ;", @@ -3919,16 +3772,14 @@ private: "} arrays = {{0}};", false)); } - void simplifyStructDecl7() - { + void simplifyStructDecl7() { ASSERT_EQUALS("struct Anonymous0 { char x ; } ; struct Anonymous0 a [ 2 ] ;", tok("struct { char x; } a[2];", false)); ASSERT_EQUALS("struct Anonymous0 { char x ; } ; static struct Anonymous0 a [ 2 ] ;", tok("static struct { char x; } a[2];", false)); } - void removeUnwantedKeywords() - { + void removeUnwantedKeywords() { ASSERT_EQUALS("int var ;", tok("register int var ;", true)); ASSERT_EQUALS("short var ;", tok("register short int var ;", true)); ASSERT_EQUALS("int foo ( ) { }", tok("inline int foo ( ) { }", true)); @@ -3955,8 +3806,7 @@ private: ASSERT_EQUALS("auto i ; i = 0 ;", tok("auto i = 0;", "test.cpp")); } - void simplifyCallingConvention() - { + void simplifyCallingConvention() { ASSERT_EQUALS("int f ( ) ;", tok("int __cdecl f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int __stdcall f();", true)); ASSERT_EQUALS("int f ( ) ;", tok("int __fastcall f();", true)); @@ -3978,25 +3828,21 @@ private: ASSERT_EQUALS("int f ( ) ;", tok("int CALLBACK f();", true)); } - void simplifyFunctorCall() - { + void simplifyFunctorCall() { ASSERT_EQUALS("IncrementFunctor ( ) ( a ) ;", tok("IncrementFunctor()(a);", true)); } // #ticket #5339 (simplify function pointer after comma) - void simplifyFunctionPointer() - { + void simplifyFunctionPointer() { ASSERT_EQUALS("f ( double x , double * y ) ;", tok("f (double x, double (*y) ());", true)); } - void redundant_semicolon() - { + void redundant_semicolon() { ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { ; }", false)); ASSERT_EQUALS("void f ( ) { ; }", tok("void f() { do { ; } while (0); }", true)); } - void simplifyFunctionReturn() - { + void simplifyFunctionReturn() { { const char code[] = "typedef void (*testfp)();\n" "struct Fred\n" @@ -4030,21 +3876,18 @@ private: } } - void removeVoidFromFunction() - { + void removeVoidFromFunction() { ASSERT_EQUALS("void foo ( ) ;", tok("void foo(void);")); } - void removeUnnecessaryQualification1() - { + void removeUnnecessaryQualification1() { const char code[] = "class Fred { Fred::Fred() {} };"; const char expected[] = "class Fred { Fred ( ) { } } ;"; ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS("[test.cpp:1]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str()); } - void removeUnnecessaryQualification2() - { + void removeUnnecessaryQualification2() { const char code[] = "template\n" "struct grammar : qi::grammar {\n" " grammar() : grammar::base_type(start) { }\n" @@ -4053,8 +3896,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void removeUnnecessaryQualification3() - { + void removeUnnecessaryQualification3() { const char code[] = "namespace one {\n" " class c {\n" " public:\n" @@ -4073,8 +3915,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void removeUnnecessaryQualification4() - { + void removeUnnecessaryQualification4() { const char code[] = "namespace one {\n" " class c {\n" " public:\n" @@ -4091,8 +3932,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void removeUnnecessaryQualification5() - { + void removeUnnecessaryQualification5() { const char code[] = "namespace one {\n" " class c {\n" " public:\n" @@ -4111,8 +3951,7 @@ private: ASSERT_EQUALS("[test.cpp:11]: (portability) The extra qualification 'two::c::' is unnecessary and is considered an error by many compilers.\n", errout.str()); } - void removeUnnecessaryQualification6() - { + void removeUnnecessaryQualification6() { const char code[] = "namespace NS {\n" " int HRDF_bit() { return 1; }\n" " void HRDF_bit_set() { }\n" @@ -4127,8 +3966,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void removeUnnecessaryQualification7() // ticket #2970 - { + void removeUnnecessaryQualification7() { // ticket #2970 const char code[] = "class TProcedure {\n" "public:\n" " TProcedure::TProcedure(long endAddress) : m_lEndAddr(endAddress){}\n" @@ -4139,8 +3977,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (portability) The extra qualification 'TProcedure::' is unnecessary and is considered an error by many compilers.\n", errout.str()); } - void removeUnnecessaryQualification8() - { + void removeUnnecessaryQualification8() { const char code[] = "class Fred {\n" "public:\n" " Fred & Fred::operator = (const Fred &);\n" @@ -4153,8 +3990,7 @@ private: "[test.cpp:5]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str()); } - void removeUnnecessaryQualification9() - { + void removeUnnecessaryQualification9() { const char code[] = "class Fred {\n" "public:\n" " Fred::~Fred();\n" @@ -4163,8 +3999,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (portability) The extra qualification 'Fred::' is unnecessary and is considered an error by many compilers.\n", errout.str()); } - void removeUnnecessaryQualification10() - { + void removeUnnecessaryQualification10() { const char code[] = "template class A\n" "{\n" " operator T();\n" @@ -4174,8 +4009,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyIfNotNull() - { + void simplifyIfNotNull() { { // ticket # 2601 segmentation fault const char code[] = "|| #if #define <="; @@ -4191,22 +4025,19 @@ private: } } - void simplifyVarDecl1() // ticket # 2682 segmentation fault - { + void simplifyVarDecl1() { // ticket # 2682 segmentation fault const char code[] = "x a[0] ="; tok(code, false); ASSERT_EQUALS("", errout.str()); } - void simplifyVarDecl2() // ticket # 2834 segmentation fault - { + void simplifyVarDecl2() { // ticket # 2834 segmentation fault const char code[] = "std::vector::iterator"; tok(code, false); ASSERT_EQUALS("", errout.str()); } - void return_strncat() - { + void return_strncat() { { const char code[] = "char *f()\n" "{\n" @@ -4258,8 +4089,7 @@ private: } } - void removeRedundantFor() // ticket #3069 - { + void removeRedundantFor() { // ticket #3069 { const char code[] = "void f() {" " for(x=0;x<1;x++) {" @@ -4289,16 +4119,14 @@ private: } } - void consecutiveBraces() - { + void consecutiveBraces() { ASSERT_EQUALS("void f ( ) { }", tok("void f(){{}}", true)); ASSERT_EQUALS("void f ( ) { }", tok("void f(){{{}}}", true)); ASSERT_EQUALS("void f ( ) { for ( ; ; ) { } }", tok("void f () { for(;;){} }", true)); ASSERT_EQUALS("void f ( ) { { scope_lock lock ; foo ( ) ; } { scope_lock lock ; bar ( ) ; } }", tok("void f () { {scope_lock lock; foo();} {scope_lock lock; bar();} }", true)); } - void undefinedSizeArray() - { + void undefinedSizeArray() { ASSERT_EQUALS("int * x ;", tok("int x [];")); ASSERT_EQUALS("int * * x ;", tok("int x [][];")); ASSERT_EQUALS("int * * x ;", tok("int * x [];")); @@ -4307,8 +4135,7 @@ private: ASSERT_EQUALS("void f ( int x [ ] , double y [ ] ) { }", tok("void f(int x[], double y[]) { }")); } - void simplifyArrayAddress() // ticket #3304 - { + void simplifyArrayAddress() { // ticket #3304 const char code[] = "void foo() {\n" " int a[10];\n" " memset(&a[4], 0, 20*sizeof(int));\n" @@ -4322,8 +4149,7 @@ private: tok("int", true); } - void simplifyCharAt() // ticket #4481 - { + void simplifyCharAt() { // ticket #4481 ASSERT_EQUALS("'h' ;", tok("\"hello\"[0] ;")); ASSERT_EQUALS("'\n' ;", tok("\"\n\"[0] ;")); ASSERT_EQUALS("'\\0' ;", tok("\"hello\"[5] ;")); @@ -4335,8 +4161,7 @@ private: ASSERT_EQUALS("\"hello\" [ -1 ] ;", tok("\"hello\"[-1] ;")); } - void test_4881() - { + void test_4881() { const char code[] = "int evallex() {\n" " int c, t;\n" "again:\n" @@ -4349,8 +4174,7 @@ private: tok(code, true)); } - void simplifyOverride() // ticket #5069 - { + void simplifyOverride() { // ticket #5069 const char code[] = "void fun() {\n" " unsigned char override[] = {0x01, 0x02};\n" " doSomething(override, sizeof(override));\n" diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 34d2ae7a2..a0a7c080e 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -28,15 +28,13 @@ extern std::ostringstream errout; class TestSimplifyTypedef : public TestFixture { public: - TestSimplifyTypedef() : TestFixture("TestSimplifyTypedef") - { + TestSimplifyTypedef() : TestFixture("TestSimplifyTypedef") { } private: - void run() - { + void run() { TEST_CASE(simplifyTypedef1) TEST_CASE(simplifyTypedef2) TEST_CASE(simplifyTypedef3) @@ -159,8 +157,7 @@ private: TEST_CASE(simplifyTypedefShadow); // #4445 - shadow variable } - std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) - { + std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Unspecified) { errout.str(""); Settings settings; @@ -177,8 +174,7 @@ private: return tokenizer.tokens()->stringifyList(0, !simplify); } - std::string simplifyTypedef(const char code[]) - { + std::string simplifyTypedef(const char code[]) { errout.str(""); Settings settings; @@ -194,8 +190,7 @@ private: - void simplifyTypedef1() - { + void simplifyTypedef1() { const char code[] = "class A\n" "{\n" "public:\n" @@ -226,8 +221,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef2() - { + void simplifyTypedef2() { const char code[] = "class A;\n" "typedef A duplicate;\n" "class A\n" @@ -248,8 +242,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef3() - { + void simplifyTypedef3() { const char code[] = "class A {};\n" "typedef A duplicate;\n" "wchar_t foo()\n" @@ -278,8 +271,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef4() - { + void simplifyTypedef4() { const char code[] = "typedef int s32;\n" "typedef unsigned int u32;\n" "void f()\n" @@ -299,8 +291,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef5() - { + void simplifyTypedef5() { // ticket #780 const char code[] = "typedef struct yy_buffer_state *YY_BUFFER_STATE;\n" @@ -318,8 +309,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef6() - { + void simplifyTypedef6() { // ticket #983 const char code[] = "namespace VL {\n" @@ -336,16 +326,14 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef7() - { + void simplifyTypedef7() { const char code[] = "typedef int abc ; " "Fred :: abc f ;"; const char expected[] = "Fred :: abc f ;"; ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef8() - { + void simplifyTypedef8() { const char code[] = "typedef int INT;\n" "typedef unsigned int UINT;\n" "typedef int * PINT;\n" @@ -376,8 +364,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef9() - { + void simplifyTypedef9() { const char code[] = "typedef struct s S, * PS;\n" "typedef struct t { int a; } T, *TP;\n" "typedef struct { int a; } U;\n" @@ -403,8 +390,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef10() - { + void simplifyTypedef10() { const char code[] = "typedef union s S, * PS;\n" "typedef union t { int a; float b ; } T, *TP;\n" "typedef union { int a; float b; } U;\n" @@ -430,8 +416,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef11() - { + void simplifyTypedef11() { const char code[] = "typedef enum { a = 0 , b = 1 , c = 2 } abc;\n" "typedef enum xyz { x = 0 , y = 1 , z = 2 } XYZ;\n" "abc e1;\n" @@ -443,8 +428,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef12() - { + void simplifyTypedef12() { const char code[] = "typedef vector V1;\n" "typedef std::vector V2;\n" "typedef std::vector > V3;\n" @@ -463,8 +447,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef13() - { + void simplifyTypedef13() { // ticket # 1167 const char code[] = "typedef std::pair Func;" "typedef std::vector CallQueue;" @@ -475,8 +458,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef14() - { + void simplifyTypedef14() { // ticket # 1232 const char code[] = "template struct E" "{" @@ -495,8 +477,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef15() - { + void simplifyTypedef15() { { const char code[] = "typedef char frame[10];\n" "frame f;"; @@ -516,8 +497,7 @@ private: } } - void simplifyTypedef16() - { + void simplifyTypedef16() { // ticket # 1252 const char code[] = "typedef char MOT8;\n" "typedef MOT8 CHFOO[4096];\n" @@ -530,8 +510,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef17() - { + void simplifyTypedef17() { const char code[] = "typedef char * PCHAR, CHAR;\n" "PCHAR pc;\n" "CHAR c;"; @@ -543,8 +522,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef18() - { + void simplifyTypedef18() { const char code[] = "typedef vector a;\n" "a b;\n"; @@ -561,8 +539,7 @@ private: tokenizer.validate(); } - void simplifyTypedef19() - { + void simplifyTypedef19() { { // ticket #1275 const char code[] = "typedef struct {} A, *B, **C;\n" @@ -608,8 +585,7 @@ private: } } - void simplifyTypedef20() - { + void simplifyTypedef20() { // ticket #1284 const char code[] = "typedef jobject invoke_t (jobject, Proxy *, Method *, JArray< jobject > *);"; @@ -626,8 +602,7 @@ private: tokenizer.validate(); } - void simplifyTypedef21() - { + void simplifyTypedef21() { const char code[] = "typedef void (* PF)();\n" "typedef void * (* PFV)(void *);\n" "PF pf;\n" @@ -642,8 +617,7 @@ private: ASSERT_EQUALS(expected, simplifyTypedef(code)); } - void simplifyTypedef22() - { + void simplifyTypedef22() { { const char code[] = "class Fred {\n" " typedef void (*testfp)();\n" @@ -731,8 +705,7 @@ private: } } - void simplifyTypedef23() - { + void simplifyTypedef23() { const char code[] = "typedef bool (*Callback) (int i);\n" "void addCallback(Callback callback) { }\n" "void addCallback1(Callback callback, int j) { }"; @@ -744,8 +717,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef24() - { + void simplifyTypedef24() { { const char code[] = "typedef int (*fp)();\n" "void g( fp f )\n" @@ -779,8 +751,7 @@ private: } } - void simplifyTypedef25() - { + void simplifyTypedef25() { { // ticket #1298 const char code[] = "typedef void (*fill_names_f) (const char *);\n" @@ -811,8 +782,7 @@ private: } } - void simplifyTypedef26() - { + void simplifyTypedef26() { { const char code[] = "typedef void (*Callback) ();\n" "void addCallback(Callback (*callback)());"; @@ -835,8 +805,7 @@ private: } } - void simplifyTypedef27() - { + void simplifyTypedef27() { // ticket #1316 const char code[] = "int main()\n" "{\n" @@ -854,8 +823,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef28() - { + void simplifyTypedef28() { const char code[] = "typedef std::pair (*F)(double);\n" "F f;"; @@ -864,8 +832,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef29() - { + void simplifyTypedef29() { const char code[] = "typedef int array [ice_or::value, is_int::value>::value ? 1 : -1];\n" "typedef int array1 [N];\n" "typedef int array2 [N][M];\n" @@ -886,8 +853,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef30() - { + void simplifyTypedef30() { const char code[] = "typedef ::std::list int_list;\n" "typedef ::std::list::iterator int_list_iterator;\n" "typedef ::std::list int_list_array[10];\n" @@ -903,8 +869,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef31() - { + void simplifyTypedef31() { { const char code[] = "class A {\n" "public:\n" @@ -952,8 +917,7 @@ private: } } - void simplifyTypedef32() - { + void simplifyTypedef32() { const char code[] = "typedef char CHAR;\n" "typedef CHAR * LPSTR;\n" "typedef const CHAR * LPCSTR;\n" @@ -969,8 +933,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef33() - { + void simplifyTypedef33() { const char code[] = "class A {\n" "public:\n" " typedef char CHAR_A;\n" @@ -1031,8 +994,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef34() - { + void simplifyTypedef34() { // ticket #1411 const char code[] = "class X { };\n" "typedef X (*foofunc)(const X&);\n" @@ -1051,8 +1013,7 @@ private: } // Check simplifyTypedef - void checkSimplifyTypedef(const char code[]) - { + void checkSimplifyTypedef(const char code[]) { errout.str(""); // Tokenize.. Settings settings; @@ -1064,8 +1025,7 @@ private: tokenizer.tokenize(istr, "test.cpp"); } - void simplifyTypedef35() - { + void simplifyTypedef35() { const char code[] = "typedef int A;\n" "class S\n" "{\n" @@ -1143,8 +1103,7 @@ private: "[test.cpp:24]: (debug) ValueFlow bailout: parameter a, at '{'\n", errout.str()); } - void simplifyTypedef36() - { + void simplifyTypedef36() { // ticket #1434 const char code[] = "typedef void (*TIFFFaxFillFunc)();\n" "void f(va_list ap)\n" @@ -1158,8 +1117,7 @@ private: ASSERT_EQUALS(expected, tok(code, false)); } - void simplifyTypedef37() - { + void simplifyTypedef37() { { // ticket #1449 const char code[] = "template class V {};\n" @@ -1187,8 +1145,7 @@ private: } } - void simplifyTypedef38() - { + void simplifyTypedef38() { const char code[] = "typedef C A;\n" "struct AB : public A, public B { };"; const char expected[] = "struct AB : public C , public B { } ;"; @@ -1198,8 +1155,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef39() - { + void simplifyTypedef39() { const char code[] = "typedef int A;\n" "template ::value;"; const char expected[] = "template < const int , int > :: value ;"; @@ -1209,8 +1165,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef40() - { + void simplifyTypedef40() { const char code[] = "typedef int A;\n" "typedef int B;\n" "template class C { };"; @@ -1265,8 +1220,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef41() - { + void simplifyTypedef41() { // ticket #1488 checkSimplifyTypedef("class Y;\n" "class X\n" @@ -1277,8 +1231,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef42() - { + void simplifyTypedef42() { // ticket #1506 checkSimplifyTypedef("typedef struct A { } A;\n" "struct A;"); @@ -1295,8 +1248,7 @@ private: TODO_ASSERT_EQUALS("class A ;", "class std :: map < std :: string , int > ;", tok(code)); } - void simplifyTypedef43() - { + void simplifyTypedef43() { // ticket #1588 { const char code[] = "typedef struct foo A;\n" @@ -1353,8 +1305,7 @@ private: } } - void simplifyTypedef44() - { + void simplifyTypedef44() { { const char code[] = "typedef std::map Map;\n" "class MyMap : public Map\n" @@ -1438,8 +1389,7 @@ private: } } - void simplifyTypedef45() - { + void simplifyTypedef45() { // ticket # 1613 const char code[] = "void fn() {\n" " typedef foo<> bar;\n" @@ -1450,8 +1400,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef46() - { + void simplifyTypedef46() { const char code[] = "typedef const struct A { int a; } * AP;\n" "AP ap;\n"; @@ -1461,8 +1410,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef47() - { + void simplifyTypedef47() { { const char code[] = "typedef std::pair const I;\n" "I i;"; @@ -1482,8 +1430,7 @@ private: } } - void simplifyTypedef48() // ticket #1673 - { + void simplifyTypedef48() { // ticket #1673 const char code[] = "typedef struct string { } string;\n" "void foo (LIST *module_name)\n" "{\n" @@ -1499,8 +1446,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef49() // ticket #1691 - { + void simplifyTypedef49() { // ticket #1691 const char code[] = "class Class2 {\n" "typedef const Class & Const_Reference;\n" "void some_method (Const_Reference x) const {}\n" @@ -1516,8 +1462,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef50() - { + void simplifyTypedef50() { const char code[] = "typedef char (* type1)[10];\n" "typedef char (& type2)[10];\n" "typedef char (& type3)[x];\n" @@ -1537,8 +1482,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef51() - { + void simplifyTypedef51() { const char code[] = "class A { public: int i; };\n" "typedef const char (A :: * type1);\n" "type1 t1 = &A::i;"; @@ -1549,8 +1493,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef52() // ticket #1782 - { + void simplifyTypedef52() { // ticket #1782 { const char code[] = "typedef char (* type1)[10];\n" "type1 foo() { }"; @@ -1573,8 +1516,7 @@ private: } } - void simplifyTypedef53() // ticket #1801 - { + void simplifyTypedef53() { // ticket #1801 { const char code[] = "typedef int ( * int ( * ) ( ) ) ( ) ;"; @@ -1599,8 +1541,7 @@ private: } } - void simplifyTypedef54() // ticket #1814 - { + void simplifyTypedef54() { // ticket #1814 const char code[] = "void foo()\n" "{\n" " typedef std::basic_string string_type;\n" @@ -1618,8 +1559,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef55() - { + void simplifyTypedef55() { const char code[] = "typedef volatile unsigned long * const hwreg_t ;\n" "typedef void *const t1[2];\n" "typedef int*const *_Iterator;\n" @@ -1638,8 +1578,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef56() // ticket #1829 - { + void simplifyTypedef56() { // ticket #1829 const char code[] = "struct C {\n" " typedef void (*fptr)();\n" " const fptr pr;\n" @@ -1659,8 +1598,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef57() // ticket #1846 - { + void simplifyTypedef57() { // ticket #1846 const char code[] = "void foo() {\n" " typedef int A;\n" " A a = A(1) * A(2);\n" @@ -1678,8 +1616,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef58() // ticket #1963 - { + void simplifyTypedef58() { // ticket #1963 { const char code[] = "typedef int vec2_t[2];\n" "vec2_t coords[4] = {1,2,3,4,5,6,7,8};\n"; @@ -1707,8 +1644,7 @@ private: } } - void simplifyTypedef59() // ticket #2011 - { + void simplifyTypedef59() { // ticket #2011 const char code[] = "template class SomeTemplateClass {\n" " typedef void (SomeTemplateClass::*MessageDispatcherFunc)(SerialInputMessage&);\n" "};\n"; @@ -1721,8 +1657,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef60() // ticket #2035 - { + void simplifyTypedef60() { // ticket #2035 const char code[] = "typedef enum {qfalse, qtrue} qboolean;\n" "typedef qboolean (*localEntitiyAddFunc_t) (struct le_s * le, entity_t * ent);\n" "void f()\n" @@ -1739,8 +1674,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef61() // ticket #2074 and 2075 - { + void simplifyTypedef61() { // ticket #2074 and 2075 const char code1[] = "typedef unsigned char (*Mf_GetIndexByte_Func) (void);\n" "typedef const unsigned char * (*Mf_GetPointerToCurrentPos_Func)(void);\n"; @@ -1756,8 +1690,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef62() // ticket #2082 - { + void simplifyTypedef62() { // ticket #2082 const char code1[] = "typedef char TString[256];\n" "void f()\n" "{\n" @@ -1815,8 +1748,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef63() // ticket #2175 'typedef float x[3];' - { + void simplifyTypedef63() { // ticket #2175 'typedef float x[3];' const char code[] = "typedef float x[3];\n" "x a,b,c;\n"; const std::string actual(tok(code)); @@ -1824,8 +1756,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef64() - { + void simplifyTypedef64() { const char code[] = "typedef __typeof__(__type1() + __type2()) __type;" "__type t;\n"; const std::string actual(tok(code)); @@ -1833,8 +1764,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef65() // ticket #2314 - { + void simplifyTypedef65() { // ticket #2314 const char code[] = "typedef BAR Foo;\n" "int main() {\n" " Foo b(0);\n" @@ -1845,16 +1775,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef66() // ticket #2341 - { + void simplifyTypedef66() { // ticket #2341 const char code[] = "typedef long* GEN;\n" "extern GEN (*foo)(long);"; tok(code); ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef67() // ticket #2354 - { + void simplifyTypedef67() { // ticket #2354 const char code[] = "typedef int ( * Function ) ( ) ;\n" "void f ( ) {\n" " ((Function * (*) (char *, char *, int, int)) global[6]) ( \"assoc\", \"eggdrop\", 106, 0);\n" @@ -1866,8 +1794,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef68() // ticket #2355 - { + void simplifyTypedef68() { // ticket #2355 const char code[] = "typedef FMAC1 void (* a) ();\n" "void *(*b) ();\n"; const std::string actual(tok(code)); @@ -1875,8 +1802,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef69() // ticket #2348 - { + void simplifyTypedef69() { // ticket #2348 const char code[] = "typedef int (*CompilerHook)();\n" "typedef struct VirtualMachine\n" "{\n" @@ -1890,8 +1816,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef70() // ticket #2348 - { + void simplifyTypedef70() { // ticket #2348 const char code[] = "typedef int pread_f ( int ) ;\n" "pread_f *(*test_func)(char *filename);\n"; const std::string expected = "int ( * ( * test_func ) ( char * filename ) ) ( int ) ;"; @@ -1899,8 +1824,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef71() // ticket #2348 - { + void simplifyTypedef71() { // ticket #2348 { const char code[] = "typedef int RexxFunctionHandler();\n" "RexxFunctionHandler *(efuncs[1]);\n"; @@ -1917,8 +1841,7 @@ private: } } - void simplifyTypedef72() // ticket #2374 - { + void simplifyTypedef72() { // ticket #2374 // inline operator { const char code[] = "class Fred {\n" @@ -1977,8 +1900,7 @@ private: } } - void simplifyTypedef73() // ticket #2412 - { + void simplifyTypedef73() { // ticket #2412 const char code[] = "struct B {};\n" "typedef struct A : public B {\n" " void f();\n" @@ -1991,8 +1913,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef74() // ticket #2414 - { + void simplifyTypedef74() { // ticket #2414 const char code[] = "typedef long (*state_func_t)(void);\n" "typedef state_func_t (*state_t)(void);\n" "state_t current_state = death;\n" @@ -2003,30 +1924,26 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef75() // ticket #2426 - { + void simplifyTypedef75() { // ticket #2426 const char code[] = "typedef _Packed struct S { long l; };\n"; ASSERT_EQUALS("", tok(code)); ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef76() // ticket #2453 segmentation fault - { + void simplifyTypedef76() { // ticket #2453 segmentation fault const char code[] = "void f1(typedef int x) {}\n"; const std::string expected = "void f1 ( typedef int x ) { }"; ASSERT_EQUALS(expected, tok(code)); ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef77() // ticket #2554 - { + void simplifyTypedef77() { // ticket #2554 const char code[] = "typedef char Str[10]; int x = sizeof(Str);\n"; const std::string expected = "int x ; x = 10 ;"; ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef78() // ticket #2568 - { + void simplifyTypedef78() { // ticket #2568 const char code[] = "typedef struct A A_t;\n" "A_t a;\n" "typedef struct A { } A_t;\n" @@ -2035,8 +1952,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef79() // ticket #2348 - { + void simplifyTypedef79() { // ticket #2348 const char code[] = "typedef int (Tcl_ObjCmdProc) (int x);\n" "typedef struct LangVtab\n" "{\n" @@ -2049,8 +1965,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef80() // ticket #2587 - { + void simplifyTypedef80() { // ticket #2587 const char code[] = "typedef struct s { };\n" "void f() {\n" " sizeof(struct s);\n" @@ -2066,16 +1981,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef81() // ticket #2603 segmentation fault - { + void simplifyTypedef81() { // ticket #2603 segmentation fault ASSERT_THROW(checkSimplifyTypedef("typedef\n"), InternalError); checkSimplifyTypedef("typedef constexpr\n"); ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef82() // ticket #2403 - { + void simplifyTypedef82() { // ticket #2403 checkSimplifyTypedef("class A {\n" "public:\n" " typedef int F(int idx);\n" @@ -2092,8 +2005,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef83() // ticket #2620 - { + void simplifyTypedef83() { // ticket #2620 const char code[] = "typedef char Str[10];\n" "void f(Str &cl) { }\n"; @@ -2103,8 +2015,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef84() // ticket #2630 (segmentation fault) - { + void simplifyTypedef84() { // ticket #2630 (segmentation fault) const char code1[] = "typedef y x () x\n"; ASSERT_THROW(checkSimplifyTypedef(code1), InternalError); @@ -2115,8 +2026,7 @@ private: ASSERT_THROW(checkSimplifyTypedef(code3), InternalError); } - void simplifyTypedef85() // ticket #2651 - { + void simplifyTypedef85() { // ticket #2651 const char code[] = "typedef FOO ((BAR)(void, int, const int, int*));\n"; const char expected[] = ";"; checkSimplifyTypedef(code); @@ -2124,8 +2034,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef86() // ticket #2581 - { + void simplifyTypedef86() { // ticket #2581 const char code[] = "class relational {\n" " typedef void (safe_bool_helper::*safe_bool)();\n" "public:\n" @@ -2143,8 +2052,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef87() // ticket #2651 - { + void simplifyTypedef87() { // ticket #2651 const char code[] = "typedef FOO (*(*BAR)(void, int, const int, int*));\n"; const char expected[] = ";"; checkSimplifyTypedef(code); @@ -2152,8 +2060,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef88() // ticket #2675 - { + void simplifyTypedef88() { // ticket #2675 const char code[] = "typedef short int (*x)(...);\n"; const char expected[] = ";"; checkSimplifyTypedef(code); @@ -2161,8 +2068,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef89() // ticket #2717 - { + void simplifyTypedef89() { // ticket #2717 const char code[] = "class Fred {\n" " typedef void f(int) const;\n" " f func;\n" @@ -2173,8 +2079,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef90() // ticket #2718 - { + void simplifyTypedef90() { // ticket #2718 const char code[] = "typedef int IA[2];\n" "void f(const IA&) {};\n"; const char expected[] = "void f ( const int ( & ) [ 2 ] ) { } ;"; @@ -2183,8 +2088,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef91() // ticket #2716 - { + void simplifyTypedef91() { // ticket #2716 const char code1[] = "namespace NS {\n" " typedef int (*T)();\n" " class A {\n" @@ -2282,8 +2186,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef92() // ticket #2736 (segmentation fault) - { + void simplifyTypedef92() { // ticket #2736 (segmentation fault) const char code[] = "typedef long Long;\n" "namespace NS {\n" "}\n"; @@ -2293,8 +2196,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef93() // ticket #2738 (syntax error) - { + void simplifyTypedef93() { // ticket #2738 (syntax error) const char code[] = "struct s { double x; };\n" "typedef struct s (*binop) (struct s, struct s);\n"; const char expected[] = "struct s { double x ; } ;"; @@ -2304,8 +2206,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef94() // ticket #1982 - { + void simplifyTypedef94() { // ticket #1982 const char code1[] = "class A {\n" "public:\n" " typedef struct {\n" @@ -2364,8 +2265,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef95() // ticket #2844 - { + void simplifyTypedef95() { // ticket #2844 const char code[] = "class symbol_table {\n" "public:\n" " typedef expression_error::error_code (*valid_func)(void *cbparam, const char *name, expression_space space);\n" @@ -2381,22 +2281,19 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef96() // ticket #2886 (segmentation fault) - { + void simplifyTypedef96() { // ticket #2886 (segmentation fault) const char code[] = "typedef struct x { }\n"; ASSERT_THROW(tok(code), InternalError); } - void simplifyTypedef97() // ticket #2983 (segmentation fault) - { + void simplifyTypedef97() { // ticket #2983 (segmentation fault) const char code[] = "typedef x y\n" "(A); y\n"; tok(code); ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef98() // ticket #2963 - { + void simplifyTypedef98() { // ticket #2963 const char code[] = "typedef int type ## __LINE__;\n" "typedef int type ## __LINE__;\n" "type1 x;\n" @@ -2404,8 +2301,7 @@ private: ASSERT_EQUALS("int x ; int y ;", tok(code)); } - void simplifyTypedef99() // ticket #2999 - { + void simplifyTypedef99() { // ticket #2999 const char code[] = "typedef struct Fred Fred;\n" "struct Fred { };\n"; tok(code); @@ -2417,8 +2313,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef100() // ticket #3000 - { + void simplifyTypedef100() { // ticket #3000 const char code[] = "typedef struct Fred { } Fred;\n" "Fred * foo() {\n" " Fred *fred;\n" @@ -2429,15 +2324,13 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef101() // ticket #3003 (segmentation fault) - { + void simplifyTypedef101() { // ticket #3003 (segmentation fault) const char code[] = "typedef a x[];\n" "y = x\n"; ASSERT_THROW(tok(code), InternalError); } - void simplifyTypedef102() // ticket #3004 - { + void simplifyTypedef102() { // ticket #3004 const char code[] = "typedef struct { } Fred;\n" "void foo()\n" "{\n" @@ -2447,8 +2340,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef103() // ticket #3007 - { + void simplifyTypedef103() { // ticket #3007 const char code[] = "typedef struct { } Fred;\n" "void foo()\n" "{\n" @@ -2458,35 +2350,30 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef104() // ticket #3070 - { + void simplifyTypedef104() { // ticket #3070 const char code[] = "typedef int (*in_func) (void FAR *, unsigned char FAR * FAR *);\n"; ASSERT_EQUALS(";", tok(code)); ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef105() // ticket #3616 (segmentation fault) - { + void simplifyTypedef105() { // ticket #3616 (segmentation fault) const char code[] = "( int typedef char x; ){}\n"; tok(code); ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef106() // ticket #3619 (segmentation fault) - { + void simplifyTypedef106() { // ticket #3619 (segmentation fault) const char code[] = "typedef void f ();\ntypedef { f }"; tok(code); ASSERT_EQUALS("", errout.str()); } - void simplifyTypedef107() // ticket #3963 (bad code => segmentation fault) - { + void simplifyTypedef107() { // ticket #3963 (bad code => segmentation fault) const char code[] = "typedef int x[]; int main() { return x }"; ASSERT_THROW(tok(code), InternalError); } - void simplifyTypedef108() // ticket #4777 - { + void simplifyTypedef108() { // ticket #4777 const char code[] = "typedef long* GEN;\n" "void sort_factor(GEN *y, long n) {\n" " GEN a, b;\n" @@ -2501,8 +2388,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedef109() - { + void simplifyTypedef109() { const char code[] = "typedef int&& rref;\n" "rref var;"; const char expected[] = "int & & var ;"; @@ -2512,8 +2398,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedefFunction1() - { + void simplifyTypedefFunction1() { { const char code[] = "typedef void (*my_func)();\n" "std::queue func_queue;"; @@ -2779,8 +2664,7 @@ private: } } - void simplifyTypedefFunction2() // ticket #1685 - { + void simplifyTypedefFunction2() { // ticket #1685 const char code[] = "typedef void voidfn (int);\n" "voidfn xxx;"; @@ -2789,8 +2673,7 @@ private: ASSERT_EQUALS(expected, tok(code)); } - void simplifyTypedefFunction3() - { + void simplifyTypedefFunction3() { { const char code[] = "typedef C func1();\n" "typedef C (* func2)();\n" @@ -2974,8 +2857,7 @@ private: } } - void simplifyTypedefFunction4() - { + void simplifyTypedefFunction4() { const char code[] = "typedef int ( * ( * type1 ) ( bool ) ) ( int , int ) ;\n" "typedef int ( * ( type2 ) ( bool ) ) ( int , int ) ;\n" "typedef int ( * type3 ( bool ) ) ( int , int ) ;\n" @@ -2993,8 +2875,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedefFunction5() - { + void simplifyTypedefFunction5() { const char code[] = "typedef int ( * type1 ) ( float ) ;\n" "typedef int ( * const type2 ) ( float ) ;\n" "typedef int ( * volatile type3 ) ( float ) ;\n" @@ -3039,8 +2920,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedefFunction6() - { + void simplifyTypedefFunction6() { const char code[] = "typedef void (*testfp)();\n" "struct Fred\n" "{\n" @@ -3069,8 +2949,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedefFunction7() - { + void simplifyTypedefFunction7() { const char code[] = "typedef void ( __gnu_cxx :: _SGIAssignableConcept < _Tp > :: * _func_Tp_SGIAssignableConcept ) () ;" "_func_Tp_SGIAssignableConcept X;\n"; @@ -3083,8 +2962,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyTypedefFunction8() - { + void simplifyTypedefFunction8() { // #2376 - internal error const char code[] = "typedef int f_expand(const nrv_byte *);\n" "void f(f_expand *(*get_fexp(int))){}\n"; @@ -3092,8 +2970,7 @@ private: TODO_ASSERT_EQUALS("", "[test.cpp:2]: (debug) Function::addArguments found argument 'int' with varid 0.\n", errout.str()); // make sure that there is no internal error } - void simplifyTypedefShadow() // shadow variable (#4445) - { + void simplifyTypedefShadow() { // shadow variable (#4445) const char code[] = "typedef struct { int x; } xyz;;\n" "void f(){\n" " int abc, xyz;\n" // <- shadow variable diff --git a/test/testsizeof.cpp b/test/testsizeof.cpp index 9d4cd554a..c6b83ba55 100644 --- a/test/testsizeof.cpp +++ b/test/testsizeof.cpp @@ -26,15 +26,13 @@ extern std::ostringstream errout; class TestSizeof : public TestFixture { public: - TestSizeof() : TestFixture("TestSizeof") - { + TestSizeof() : TestFixture("TestSizeof") { } private: - void run() - { + void run() { TEST_CASE(sizeofsizeof); TEST_CASE(sizeofCalculation); TEST_CASE(checkPointerSizeof); @@ -46,8 +44,7 @@ private: TEST_CASE(customStrncat); } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -66,8 +63,7 @@ private: checkSizeof.runChecks(&tokenizer, &settings, this); } - void sizeofsizeof() - { + void sizeofsizeof() { check("void foo()\n" "{\n" " int i = sizeof sizeof char;\n" @@ -87,8 +83,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (warning) Calling 'sizeof' on 'sizeof'.\n", errout.str()); } - void sizeofCalculation() - { + void sizeofCalculation() { check("int a, b; int a,sizeof(a+b)"); ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); @@ -117,8 +112,7 @@ private: ASSERT_EQUALS("[test.cpp:1]: (warning) Found calculation inside sizeof().\n", errout.str()); } - void sizeofForArrayParameter() - { + void sizeofForArrayParameter() { check("void f() {\n" " int a[10];\n" " std::cout << sizeof(a) / sizeof(int) << std::endl;\n" @@ -250,8 +244,7 @@ private: } - void sizeofForNumericParameter() - { + void sizeofForNumericParameter() { check("void f() {\n" " std::cout << sizeof(10) << std::endl;\n" "}\n"); @@ -273,8 +266,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (warning) Suspicious usage of 'sizeof' with a numeric constant as parameter.\n", errout.str()); } - void suspiciousSizeofCalculation() - { + void suspiciousSizeofCalculation() { check("int* p;\n" "return sizeof(p)/5;"); ASSERT_EQUALS("[test.cpp:2]: (warning, inconclusive) Division of result of sizeof() on pointer type.\n", errout.str()); @@ -308,8 +300,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkPointerSizeof() - { + void checkPointerSizeof() { check("void f() {\n" " char *x = malloc(10);\n" " free(x);\n" @@ -511,8 +502,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sizeofDivisionMemset() - { + void sizeofDivisionMemset() { check("void foo(memoryMapEntry_t* entry, memoryMapEntry_t* memoryMapEnd) {\n" " memmove(entry, entry + 1, (memoryMapEnd - entry) / sizeof(entry));\n" "}"); @@ -524,8 +514,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (warning) Division by result of sizeof(). malloc() expects a size in bytes, did you intend to multiply instead?\n", errout.str()); } - void sizeofVoid() - { + void sizeofVoid() { check("void f() {\n" " int size = sizeof(void);\n" "}"); @@ -665,8 +654,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void customStrncat() - { + void customStrncat() { // Ensure we don't crash on custom-defined strncat, ticket #5875 check("char strncat ();\n" "int main () {\n" diff --git a/test/teststl.cpp b/test/teststl.cpp index c498aa4d1..c3d5c30c7 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -27,13 +27,11 @@ extern std::ostringstream errout; class TestStl : public TestFixture { public: - TestStl() : TestFixture("TestStl") - { + TestStl() : TestFixture("TestStl") { } private: - void run() - { + void run() { TEST_CASE(iterator1); TEST_CASE(iterator2); TEST_CASE(iterator3); @@ -132,8 +130,7 @@ private: TEST_CASE(readingEmptyStlContainer); } - void check(const char code[], const bool inconclusive=false) - { + void check(const char code[], const bool inconclusive=false) { // Clear the error buffer.. errout.str(""); @@ -153,14 +150,12 @@ private: CheckStl checkStl; checkStl.runSimplifiedChecks(&tokenizer, &settings, this); } - void check(const std::string &code, const bool inconclusive=false) - { + void check(const std::string &code, const bool inconclusive=false) { check(code.c_str(), inconclusive); } - void iterator1() - { + void iterator1() { check("void f()\n" "{\n" " list l1;\n" @@ -181,8 +176,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str()); } - void iterator2() - { + void iterator2() { check("void foo()\n" "{\n" " list l1;\n" @@ -196,8 +190,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str()); } - void iterator3() - { + void iterator3() { check("void foo()\n" "{\n" " list l1;\n" @@ -208,8 +201,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Same iterator is used with different containers 'l1' and 'l2'.\n", errout.str()); } - void iterator4() - { + void iterator4() { check("void foo(std::vector &test)\n" "{\n" " std::set result;\n" @@ -223,8 +215,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void iterator5() - { + void iterator5() { check("void foo()\n" "{\n" " std::vector ints1;\n" @@ -234,8 +225,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Iterators of different containers are used together.\n", errout.str()); } - void iterator6() - { + void iterator6() { // Ticket #1357 check("void foo(const std::set &ints1)\n" "{\n" @@ -256,8 +246,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Iterators of different containers are used together.\n", "", errout.str()); } - void iterator7() - { + void iterator7() { check("void foo()\n" "{\n" " std::vector ints1;\n" @@ -275,8 +264,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void iterator8() - { + void iterator8() { check("void foo()\n" "{\n" " std::vector ints1;\n" @@ -310,8 +298,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void iterator9() - { + void iterator9() { // Ticket #1600 check("void foo(std::vector &r)\n" "{\n" @@ -364,8 +351,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:14] (error) After insert(), the iterator 'aI' may be invalid.", "", errout.str()); } - void iterator10() - { + void iterator10() { // Ticket #1679 check("void foo()\n" "{\n" @@ -380,8 +366,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) Same iterator is used with different containers 's1' and 's2'.\n", errout.str()); } - void iterator11() - { + void iterator11() { // Ticket #3433 check("int main() {\n" " map myMap;\n" @@ -392,8 +377,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void iterator12() - { + void iterator12() { // Ticket #3201 check("void f() {\n" " std::map map1;\n" @@ -411,8 +395,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void iterator13() - { + void iterator13() { check("void f() {\n" " std::vector a;\n" " std::vector t;\n" @@ -456,15 +439,13 @@ private: ASSERT_EQUALS("", errout.str()); } - void iterator14() - { + void iterator14() { check(" { { void foo() { struct }; template struct S { Used x; void bar() } auto f = [this] { }; } };"); ASSERT_EQUALS("", errout.str()); } // Dereferencing invalid pointer - void dereference() - { + void dereference() { check("void f()\n" "{\n" " std::vector ints;\n" @@ -476,8 +457,7 @@ private: ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n", errout.str()); } - void dereference_break() // #3644 - { + void dereference_break() { // #3644 check("void f(std::vector &ints) {\n" " std::vector::iterator iter;\n" " for (iter=ints.begin();iter!=ints.end();++iter) {\n" @@ -494,8 +474,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void dereference_member() - { + void dereference_member() { check("void f()\n" "{\n" " std::map ints;\n" @@ -518,8 +497,7 @@ private: ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:6]: (error) Iterator 'iter' used after element has been erased.\n", errout.str()); } - void dereference_auto() - { + void dereference_auto() { check("void f()\n" "{\n" " std::vector ints;\n" @@ -537,8 +515,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void STLSize() - { + void STLSize() { check("void foo()\n" "{\n" " std::vector foo;\n" @@ -599,8 +576,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void STLSizeNoErr() - { + void STLSizeNoErr() { { check("void foo()\n" "{\n" @@ -656,8 +632,7 @@ private: - void erase1() - { + void erase1() { check("void f()\n" "{\n" " for (it = foo.begin(); it != foo.end(); ++it) {\n" @@ -690,8 +665,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void erase2() - { + void erase2() { check("static void f()\n" "{\n" " for (iterator it = foo.begin(); it != foo.end(); it = next)\n" @@ -704,8 +678,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void erase3() - { + void erase3() { check("static void f(std::list &foo)\n" "{\n" " std::list::iterator it = foo.begin();\n" @@ -715,8 +688,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void erase4() - { + void erase4() { check("void f()\n" "{\n" " std::list::iterator it, it2;\n" @@ -758,8 +730,7 @@ private: ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); } - void erase5() - { + void erase5() { check("void f()\n" "{\n" " std::list foo;\n" @@ -773,8 +744,7 @@ private: ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:8]: (error) Iterator 'it' used after element has been erased.\n", errout.str()); } - void erase6() - { + void erase6() { check("void f() {\n" " std::vector vec(3);\n" " std::vector::iterator it;\n" @@ -787,8 +757,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseBreak() - { + void eraseBreak() { check("void f()\n" "{\n" " for (iterator it = foo.begin(); it != foo.end(); ++it)\n" @@ -825,8 +794,7 @@ private: } - void eraseContinue() - { + void eraseContinue() { check("void f(std::vector &ints)\n" "{\n" " std::vector::iterator it;\n" @@ -842,8 +810,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseReturn1() - { + void eraseReturn1() { check("void f()\n" "{\n" " std::vector foo;\n" @@ -857,8 +824,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseReturn2() - { + void eraseReturn2() { check("void f()\n" "{\n" " std::vector foo;\n" @@ -878,8 +844,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseReturn3() - { + void eraseReturn3() { check("void f()\n" "{\n" " std::vector foo;\n" @@ -914,8 +879,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:9]: (error) Dangerous iterator usage after erase()-method.\n", "", errout.str()); } - void eraseGoto() - { + void eraseGoto() { check("void f()\n" "{\n" " for (iterator it = foo.begin(); it != foo.end(); ++it)\n" @@ -928,8 +892,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseAssign1() - { + void eraseAssign1() { check("void f()\n" "{\n" " for (iterator it = foo.begin(); it != foo.end(); ++it)\n" @@ -941,8 +904,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseAssign2() - { + void eraseAssign2() { check("void f(list &ints)\n" "{\n" " for (list::iterator it = ints.begin(); it != ints.end();) {\n" @@ -960,8 +922,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseAssign3() - { + void eraseAssign3() { check("void f(std::list >& l) {\n" " std::list >::const_iterator i = l.begin();\n" " std::list::const_iterator j = (*i).begin();\n" @@ -970,8 +931,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseAssign4() - { + void eraseAssign4() { check("void f(std::list data) {\n" " std::list::const_iterator it = data.begin();\n" " it = data.erase(it);\n" @@ -987,8 +947,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseAssignByFunctionCall() - { + void eraseAssignByFunctionCall() { check("void f(std::list >& l) {\n" " std::list::const_iterator i;\n" " bar(i);\n" @@ -997,8 +956,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void eraseErase() - { + void eraseErase() { check("void f(std::vector &ints)\n" "{\n" " std::vector::iterator iter;\n" @@ -1009,8 +967,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (error) Invalid iterator: iter\n", errout.str()); } - void eraseByValue() - { + void eraseByValue() { check("void f()\n" "{\n" " std::set foo;\n" @@ -1061,8 +1018,7 @@ private: } - void eraseOnVector() - { + void eraseOnVector() { check("void f(const std::vector& m_ImplementationMap) {\n" " std::vector::iterator aIt = m_ImplementationMap.find( xEle );\n" " m_ImplementationMap.erase(something(unknown));\n" // All iterators become invalidated when erasing from std::vector @@ -1086,8 +1042,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) After erase(), the iterator 'aIt' may be invalid.\n", errout.str()); } - void pushback1() - { + void pushback1() { check("void f(const std::vector &foo)\n" "{\n" " std::vector::const_iterator it = foo.begin();\n" @@ -1097,8 +1052,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); } - void pushback2() - { + void pushback2() { check("void f()\n" "{\n" " std::vector::const_iterator it = foo.begin();\n" @@ -1111,8 +1065,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void pushback3() - { + void pushback3() { check("void f()\n" "{\n" " std::vector foo;\n" @@ -1126,8 +1079,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); } - void pushback4() - { + void pushback4() { check("void f()\n" "{\n" " std::vector ints;\n" @@ -1139,8 +1091,7 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Invalid pointer 'first' after push_back().\n", errout.str()); } - void pushback5() - { + void pushback5() { check("void f()\n" "{\n" " std::vector::const_iterator i;\n" @@ -1157,8 +1108,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void pushback6() - { + void pushback6() { // ticket #735 check("void f()\n" "{\n" @@ -1187,8 +1137,7 @@ private: ASSERT_EQUALS("[test.cpp:9]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); } - void pushback7() - { + void pushback7() { check("void f()\n" "{\n" " std::vector foo;\n" @@ -1202,8 +1151,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) After push_back(), the iterator 'it' may be invalid.\n", errout.str()); } - void pushback8() - { + void pushback8() { check("void f()\n" "{\n" " std::vector ints;\n" @@ -1219,8 +1167,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) After push_back(), the iterator 'end' may be invalid.\n", errout.str()); } - void pushback9() - { + void pushback9() { check("struct A {\n" " std::vector ints;\n" "};\n" @@ -1240,8 +1187,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void pushback10() - { + void pushback10() { check("void f(std::vector &foo)\n" "{\n" " std::vector::const_iterator it = foo.begin();\n" @@ -1264,8 +1210,7 @@ private: ASSERT_EQUALS("[test.cpp:8]: (error) After reserve(), the iterator 'it' may be invalid.\n", errout.str()); } - void pushback11() - { + void pushback11() { // #2798 check("void f() {\n" " std::vector ints;\n" @@ -1279,8 +1224,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void pushback12() - { + void pushback12() { // #4197 check("void foo(double s)\n" "{\n" @@ -1297,8 +1241,7 @@ private: "[test.cpp:9]: (error) After insert(), the iterator 'it' may be invalid.\n", errout.str()); } - void insert1() - { + void insert1() { check("void f(std::vector &ints)\n" "{\n" " std::vector::iterator iter = ints.begin() + 5;\n" @@ -1365,8 +1308,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) After insert(), the iterator 'i' may be invalid.\n", errout.str()); } - void insert2() - { + void insert2() { // Ticket: #2169 check("void f(std::vector &vec) {\n" " for(std::vector::iterator iter = vec.begin(); iter != vec.end(); ++iter)\n" @@ -1390,13 +1332,11 @@ private: } template - size_t getArraylength(const T(&)[n]) - { + size_t getArraylength(const T(&)[n]) { return n; } - void stlBoundaries1() - { + void stlBoundaries1() { const std::string stlCont[] = { "list", "set", "multiset", "map", "multimap", "hash_map", "hash_multimap", "hash_set" @@ -1427,8 +1367,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void stlBoundaries2() - { + void stlBoundaries2() { check("void f()\n" "{\n" " std::vector files;\n" @@ -1440,8 +1379,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void stlBoundaries3() - { + void stlBoundaries3() { check("void f()\n" "{\n" " set files;\n" @@ -1461,8 +1399,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Invalid iterator 'current' used.\n", errout.str()); } - void stlBoundaries4() - { + void stlBoundaries4() { check("void f() {\n" " std::forward_list>>::iterator it;\n" @@ -1485,8 +1422,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous iterator comparison using operator< on 'std::forward_list'.\n", errout.str()); } - void stlBoundaries5() - { + void stlBoundaries5() { check("class iterator { int foo(); };\n" "int foo() {\n" " iterator i;\n" @@ -1507,8 +1443,7 @@ private: } - void if_find() - { + void if_find() { // --------------------------- // set::find // --------------------------- @@ -1628,8 +1563,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void if_str_find() - { + void if_str_find() { // error (simple) check("void f(const std::string &s)\n" "{\n" @@ -1671,8 +1605,7 @@ private: } - void size1() - { + void size1() { check("struct Fred {\n" " void foo();\n" " std::list x;\n" @@ -1814,8 +1747,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void size2() - { + void size2() { check("struct Fred {\n" " std::list x;\n" "};\n" @@ -1830,8 +1762,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); } - void size3() - { + void size3() { check("namespace N {\n" " class Zzz {\n" " public:\n" @@ -1859,8 +1790,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str()); } - void size4() // #2652 - don't warn about vector/deque - { + void size4() { // #2652 - don't warn about vector/deque check("void f(std::vector &v) {\n" " if (v.size() > 0U) {}\n" "}"); @@ -1872,8 +1802,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void redundantCondition1() - { + void redundantCondition1() { check("void f(string haystack)\n" "{\n" " if (haystack.find(needle) != haystack.end())\n" @@ -1882,8 +1811,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Redundant checking of STL container element existence before removing it.\n", errout.str()); } - void missingInnerComparison1() - { + void missingInnerComparison1() { check("void f(std::set &ints) {\n" " for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\n" " if (a) {\n" @@ -1901,8 +1829,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void missingInnerComparison2() - { + void missingInnerComparison2() { check("void f(std::set &ints) {\n" " for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\n" " if (a) {\n" @@ -1915,8 +1842,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void missingInnerComparison3() - { + void missingInnerComparison3() { check("void f(std::set &ints) {\n" " for (std::set::iterator it = ints.begin(); it != ints.end(); ++it) {\n" " for (std::set::iterator it = ints2.begin(); it != ints2.end(); ++it)\n" @@ -1926,8 +1852,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void missingInnerComparison4() - { + void missingInnerComparison4() { check("function f1(std::list &l1) {\n" " for(std::list::iterator i = l1.begin(); i != l1.end(); i++) {\n" " if (*i == 44) {\n" @@ -1949,8 +1874,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void missingInnerComparison5() - { + void missingInnerComparison5() { check("void f() {\n" " for(it = map1.begin(); it != map1.end(); it++) {\n" " str[i++] = (*it).first;\n" @@ -1959,8 +1883,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void missingInnerComparison6() - { + void missingInnerComparison6() { check("void f(std::string &s) {\n" " for(string::iterator it = s.begin(); it != s.end(); it++) {\n" " it = s.insert(++it, 0);\n" @@ -1969,8 +1892,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void cstr() - { + void cstr() { check("void f() {\n" " std::string errmsg;\n" " throw errmsg.c_str();\n" @@ -2176,8 +2098,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void autoPointer() - { + void autoPointer() { // ticket 2846 check("void f()\n" @@ -2334,8 +2255,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uselessCalls() - { + void uselessCalls() { check("void f()\n" "{\n" " string s1, s2;\n" @@ -2428,8 +2348,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void stabilityOfChecks() - { + void stabilityOfChecks() { // Stability test: 4684 cppcheck crash in template function call. check("template\n" "class EffectivityRangeData {};\n" @@ -2444,8 +2363,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void dereferenceInvalidIterator() - { + void dereferenceInvalidIterator() { // Test simplest "if" with && case check("void foo(std::string::iterator& i) {\n" " if (std::isalpha(*i) && i != str.end()) {\n" @@ -2567,8 +2485,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void readingEmptyStlContainer() - { + void readingEmptyStlContainer() { check("void f() {\n" " std::map CMap;\n" " std::string strValue = CMap[1]; \n" diff --git a/test/teststring.cpp b/test/teststring.cpp index 39badd1b3..0e1b1ad7b 100644 --- a/test/teststring.cpp +++ b/test/teststring.cpp @@ -28,14 +28,12 @@ extern std::ostringstream errout; class TestString : public TestFixture { public: - TestString() : TestFixture("TestString") - { + TestString() : TestFixture("TestString") { } private: - void run() - { + void run() { TEST_CASE(alwaysTrueFalseStringCompare); TEST_CASE(suspiciousStringCompare); TEST_CASE(suspiciousStringCompare_char); @@ -53,8 +51,7 @@ private: TEST_CASE(incorrectStringCompare); } - void check(const char code[], const char filename[] = "test.cpp") - { + void check(const char code[], const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -75,8 +72,7 @@ private: checkString.runSimplifiedChecks(&tokenizer, &settings, this); } - void check_preprocess_suppress(const char precode[]) - { + void check_preprocess_suppress(const char precode[]) { // Clear the error buffer.. errout.str(""); @@ -101,8 +97,7 @@ private: checkString.checkAlwaysTrueOrFalseStringCompare(); } - void alwaysTrueFalseStringCompare() - { + void alwaysTrueFalseStringCompare() { check_preprocess_suppress( "#define MACRO \"00FF00\"\n" "int main()\n" @@ -200,8 +195,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void suspiciousStringCompare() - { + void suspiciousStringCompare() { check("bool foo(char* c) {\n" " return c == \"x\";\n" "}"); @@ -308,8 +302,7 @@ private: ASSERT_EQUALS("[test.c:6]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead?\n", errout.str()); } - void suspiciousStringCompare_char() - { + void suspiciousStringCompare_char() { check("bool foo(char* c) {\n" " return c == '\\0';\n" "}"); @@ -364,8 +357,7 @@ private: } - void sprintf1() - { + void sprintf1() { check("void foo()\n" "{\n" " char buf[100];\n" @@ -374,8 +366,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Undefined behavior: Variable 'buf' is used as parameter and destination in s[n]printf().\n", errout.str()); } - void sprintf2() - { + void sprintf2() { check("void foo()\n" "{\n" " char buf[100];\n" @@ -384,8 +375,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf3() - { + void sprintf3() { check("void foo()\n" "{\n" " char buf[100];\n" @@ -395,8 +385,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void sprintf4() - { + void sprintf4() { check("struct A\n" "{\n" " char filename[128];\n" @@ -411,8 +400,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void strPlusChar1() - { + void strPlusChar1() { // Strange looking pointer arithmetic.. check("void foo()\n" "{\n" @@ -421,8 +409,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Unusual pointer arithmetic. A value of type 'char' is added to a string literal.\n", errout.str()); } - void strPlusChar2() - { + void strPlusChar2() { // Strange looking pointer arithmetic.. check("void foo()\n" "{\n" @@ -441,8 +428,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void strPlusChar3() - { + void strPlusChar3() { // Strange looking pointer arithmetic.. check("void foo()\n" "{\n" @@ -452,15 +438,13 @@ private: ASSERT_EQUALS("", errout.str()); } - void strPlusChar4() - { + void strPlusChar4() { // don't crash check("int test() { int +; }"); } - void incorrectStringCompare() - { + void incorrectStringCompare() { check("int f() {\n" " return test.substr( 0 , 4 ) == \"Hello\" ? : 0 : 1 ;\n" "}"); diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 748a00752..0d61da5cf 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -36,19 +36,16 @@ private: std::list _tests; public: - static TestRegistry &theInstance() - { + static TestRegistry &theInstance() { static TestRegistry testreg; return testreg; } - void addTest(TestFixture *t) - { + void addTest(TestFixture *t) { _tests.push_back(t); } - const std::list &tests() const - { + const std::list &tests() const { return _tests; } }; diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index e15b12450..ed54ed2f9 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -28,14 +28,12 @@ extern std::ostringstream errout; class TestSuppressions : public TestFixture { public: - TestSuppressions() : TestFixture("TestSuppressions") - { + TestSuppressions() : TestFixture("TestSuppressions") { } private: - void run() - { + void run() { TEST_CASE(suppressionsBadId1); TEST_CASE(suppressionsDosFormat); // Ticket #1836 TEST_CASE(suppressionsFileNameWithColon); // Ticket #1919 - filename includes colon @@ -50,8 +48,7 @@ private: TEST_CASE(suppressionWithRelativePaths); // #4733 } - void suppressionsBadId1() const - { + void suppressionsBadId1() const { Suppressions suppressions; std::istringstream s1("123"); ASSERT_EQUALS("Failed to add suppression. Invalid id \"123\"", suppressions.parseFile(s1)); @@ -60,8 +57,7 @@ private: ASSERT_EQUALS("", suppressions.parseFile(s2)); } - void suppressionsDosFormat() const - { + void suppressionsDosFormat() const { Suppressions suppressions; std::istringstream s("abc\r\ndef\r\n"); ASSERT_EQUALS("", suppressions.parseFile(s)); @@ -69,8 +65,7 @@ private: ASSERT_EQUALS(true, suppressions.isSuppressed("def", "test.cpp", 1)); } - void suppressionsFileNameWithColon() const - { + void suppressionsFileNameWithColon() const { Suppressions suppressions; std::istringstream s("errorid:c:\\foo.cpp\nerrorid:c:\\bar.cpp:12"); ASSERT_EQUALS("", suppressions.parseFile(s)); @@ -79,8 +74,7 @@ private: ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "c:/bar.cpp", 12)); } - void suppressionsGlob() const - { + void suppressionsGlob() const { // Check for syntax errors in glob { Suppressions suppressions; @@ -114,8 +108,7 @@ private: } } - void suppressionsFileNameWithExtraPath() const - { + void suppressionsFileNameWithExtraPath() const { // Ticket #2797 Suppressions suppressions; suppressions.addSuppression("errorid", "./a.c", 123); @@ -123,8 +116,7 @@ private: } // Check the suppression - void checkSuppression(const char code[], const std::string &suppression = emptyString) - { + void checkSuppression(const char code[], const std::string &suppression = emptyString) { // Clear the error log errout.str(""); @@ -142,8 +134,7 @@ private: reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(true)); } - void checkSuppressionThreads(const char code[], const std::string &suppression = emptyString) - { + void checkSuppressionThreads(const char code[], const std::string &suppression = emptyString) { errout.str(""); output.str(""); @@ -167,8 +158,7 @@ private: } // Check the suppression for multiple files - void checkSuppression(const char *names[], const char *codes[], const std::string &suppression = emptyString) - { + void checkSuppression(const char *names[], const char *codes[], const std::string &suppression = emptyString) { // Clear the error log errout.str(""); @@ -185,8 +175,7 @@ private: reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions(true)); } - void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) - { + void runChecks(void (TestSuppressions::*check)(const char[], const std::string &)) { // check to make sure the appropriate error is present (this->*check)("void f() {\n" " int a;\n" @@ -307,15 +296,13 @@ private: ASSERT_EQUALS("[test.cpp:4]: (information) Unmatched suppression: uninitvar\n", errout.str()); } - void suppressionsSettings() - { + void suppressionsSettings() { runChecks(&TestSuppressions::checkSuppression); if (ThreadExecutor::isEnabled()) runChecks(&TestSuppressions::checkSuppressionThreads); } - void suppressionsMultiFile() - { + void suppressionsMultiFile() { const char *names[] = {"abc.cpp", "xyz.cpp", NULL}; const char *codes[] = { "void f() {\n" @@ -331,15 +318,13 @@ private: ASSERT_EQUALS("", errout.str()); } - void suppressionsPathSeparator() const - { + void suppressionsPathSeparator() const { Suppressions suppressions; suppressions.addSuppressionLine("*:test\\*"); ASSERT_EQUALS(true, suppressions.isSuppressed("someid", "test/foo/bar.cpp", 142)); } - void inlinesuppress_unusedFunction() const // #4210, #4946 - wrong report of "unmatchedSuppression" for "unusedFunction" - { + void inlinesuppress_unusedFunction() const { // #4210, #4946 - wrong report of "unmatchedSuppression" for "unusedFunction" Suppressions suppressions; suppressions.addSuppression("unusedFunction", "test.c", 3U); ASSERT_EQUALS(true, !suppressions.getUnmatchedLocalSuppressions("test.c", true).empty()); @@ -348,8 +333,7 @@ private: ASSERT_EQUALS(false, !suppressions.getUnmatchedGlobalSuppressions(false).empty()); } - void globalsuppress_unusedFunction() const // #4946 - wrong report of "unmatchedSuppression" for "unusedFunction" - { + void globalsuppress_unusedFunction() const { // #4946 - wrong report of "unmatchedSuppression" for "unusedFunction" Suppressions suppressions; suppressions.addSuppressionLine("unusedFunction:*"); ASSERT_EQUALS(false, !suppressions.getUnmatchedLocalSuppressions("test.c", true).empty()); @@ -358,8 +342,7 @@ private: ASSERT_EQUALS(false, !suppressions.getUnmatchedGlobalSuppressions(false).empty()); } - void suppressionWithRelativePaths() - { + void suppressionWithRelativePaths() { // Clear the error log errout.str(""); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index bf853a18f..4a0210a98 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -45,8 +45,7 @@ public: ,vartok(nullptr) ,typetok(nullptr) ,t(nullptr) - ,found(false) - { + ,found(false) { } private: @@ -56,16 +55,14 @@ private: const Token* t; bool found; - void reset() - { + void reset() { vartok = nullptr; typetok = nullptr; t = nullptr; found = false; } - static const Scope *findFunctionScopeByToken(const SymbolDatabase * db, const Token *tok) - { + static const Scope *findFunctionScopeByToken(const SymbolDatabase * db, const Token *tok) { std::list::const_iterator scope; for (scope = db->scopeList.begin(); scope != db->scopeList.end(); ++scope) { @@ -77,8 +74,7 @@ private: return 0; } - static const Function *findFunctionByName(const char str[], const Scope* startScope) - { + static const Function *findFunctionByName(const char str[], const Scope* startScope) { const Scope* currScope = startScope; while (currScope && currScope->isExecutable()) { if (currScope->functionOf) @@ -96,8 +92,7 @@ private: return 0; } - void run() - { + void run() { TEST_CASE(array); TEST_CASE(test_isVariableDeclarationCanHandleNull); @@ -256,8 +251,7 @@ private: TEST_CASE(lambda); // ticket #5867 } - void array() const - { + void array() const { std::istringstream code("int a[10+2];"); TokenList list(nullptr); list.createTokens(code, "test.c"); @@ -268,8 +262,7 @@ private: ASSERT_EQUALS(0U, v.dimension(0)); } - void test_isVariableDeclarationCanHandleNull() - { + void test_isVariableDeclarationCanHandleNull() { reset(); bool result = si.isVariableDeclaration(nullptr, vartok, typetok); ASSERT_EQUALS(false, result); @@ -278,8 +271,7 @@ private: Variable v(nullptr, nullptr, nullptr, 0, Public, 0, 0); } - void test_isVariableDeclarationIdentifiesSimpleDeclaration() - { + void test_isVariableDeclarationIdentifiesSimpleDeclaration() { reset(); givenACodeSampleToTokenize simpleDeclaration("int x;"); bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok); @@ -292,8 +284,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesInitialization() - { + void test_isVariableDeclarationIdentifiesInitialization() { reset(); givenACodeSampleToTokenize simpleDeclaration("int x (1);"); bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok); @@ -307,8 +298,7 @@ private: ASSERT(true == v.isIntegralType()); } - void test_isVariableDeclarationIdentifiesCpp11Initialization() - { + void test_isVariableDeclarationIdentifiesCpp11Initialization() { reset(); givenACodeSampleToTokenize simpleDeclaration("int x {1};"); bool result = si.isVariableDeclaration(simpleDeclaration.tokens(), vartok, typetok); @@ -322,8 +312,7 @@ private: ASSERT(true == v.isIntegralType()); } - void test_isVariableDeclarationIdentifiesScopedDeclaration() - { + void test_isVariableDeclarationIdentifiesScopedDeclaration() { reset(); givenACodeSampleToTokenize ScopedDeclaration("::int x;"); bool result = si.isVariableDeclaration(ScopedDeclaration.tokens(), vartok, typetok); @@ -336,8 +325,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesStdDeclaration() - { + void test_isVariableDeclarationIdentifiesStdDeclaration() { reset(); givenACodeSampleToTokenize StdDeclaration("std::string x;"); bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok); @@ -350,8 +338,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesScopedStdDeclaration() - { + void test_isVariableDeclarationIdentifiesScopedStdDeclaration() { reset(); givenACodeSampleToTokenize StdDeclaration("::std::string x;"); bool result = si.isVariableDeclaration(StdDeclaration.tokens(), vartok, typetok); @@ -364,8 +351,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesManyScopes() - { + void test_isVariableDeclarationIdentifiesManyScopes() { reset(); givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE x;"); bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok); @@ -378,8 +364,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesPointers() - { + void test_isVariableDeclarationIdentifiesPointers() { reset(); givenACodeSampleToTokenize pointer("int* p;"); bool result1 = si.isVariableDeclaration(pointer.tokens(), vartok, typetok); @@ -412,8 +397,7 @@ private: ASSERT(false == v3.isReference()); } - void test_isVariableDeclarationDoesNotIdentifyConstness() - { + void test_isVariableDeclarationDoesNotIdentifyConstness() { reset(); givenACodeSampleToTokenize constness("const int* cp;"); bool result = si.isVariableDeclaration(constness.tokens(), vartok, typetok); @@ -422,8 +406,7 @@ private: ASSERT(nullptr == typetok); } - void test_isVariableDeclarationIdentifiesFirstOfManyVariables() - { + void test_isVariableDeclarationIdentifiesFirstOfManyVariables() { reset(); givenACodeSampleToTokenize multipleDeclaration("int first, second;"); bool result = si.isVariableDeclaration(multipleDeclaration.tokens(), vartok, typetok); @@ -436,8 +419,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesScopedPointerDeclaration() - { + void test_isVariableDeclarationIdentifiesScopedPointerDeclaration() { reset(); givenACodeSampleToTokenize manyScopes("AA::BB::CC::DD::EE* p;"); bool result = si.isVariableDeclaration(manyScopes.tokens(), vartok, typetok); @@ -450,8 +432,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesDeclarationWithIndirection() - { + void test_isVariableDeclarationIdentifiesDeclarationWithIndirection() { reset(); givenACodeSampleToTokenize pointerToPointer("int** pp;"); bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok); @@ -464,8 +445,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesDeclarationWithMultipleIndirection() - { + void test_isVariableDeclarationIdentifiesDeclarationWithMultipleIndirection() { reset(); givenACodeSampleToTokenize pointerToPointer("int***** p;"); bool result = si.isVariableDeclaration(pointerToPointer.tokens(), vartok, typetok); @@ -478,8 +458,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesArray() - { + void test_isVariableDeclarationIdentifiesArray() { reset(); givenACodeSampleToTokenize arr("::std::string v[3];"); bool result = si.isVariableDeclaration(arr.tokens(), vartok, typetok); @@ -492,8 +471,7 @@ private: ASSERT(false == v.isReference()); } - void test_isVariableDeclarationIdentifiesOfArrayPointers() - { + void test_isVariableDeclarationIdentifiesOfArrayPointers() { reset(); givenACodeSampleToTokenize arr("A *a[5];"); bool result = si.isVariableDeclaration(arr.tokens(), vartok, typetok); @@ -506,8 +484,7 @@ private: ASSERT(false == v.isReference()); } - void isVariableDeclarationIdentifiesTemplatedPointerVariable() - { + void isVariableDeclarationIdentifiesTemplatedPointerVariable() { reset(); givenACodeSampleToTokenize var("std::set* chars;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); @@ -520,8 +497,7 @@ private: ASSERT(false == v.isReference()); } - void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() - { + void isVariableDeclarationIdentifiesTemplatedPointerToPointerVariable() { reset(); givenACodeSampleToTokenize var("std::deque*** ints;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); @@ -534,8 +510,7 @@ private: ASSERT(false == v.isReference()); } - void isVariableDeclarationIdentifiesTemplatedArrayVariable() - { + void isVariableDeclarationIdentifiesTemplatedArrayVariable() { reset(); givenACodeSampleToTokenize var("std::deque ints[3];"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); @@ -548,8 +523,7 @@ private: ASSERT(false == v.isReference()); } - void isVariableDeclarationIdentifiesTemplatedVariable() - { + void isVariableDeclarationIdentifiesTemplatedVariable() { reset(); givenACodeSampleToTokenize var("std::vector ints;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); @@ -562,8 +536,7 @@ private: ASSERT(false == v.isReference()); } - void isVariableDeclarationIdentifiesTemplatedVariableIterator() - { + void isVariableDeclarationIdentifiesTemplatedVariableIterator() { reset(); givenACodeSampleToTokenize var("std::list::const_iterator floats;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); @@ -576,8 +549,7 @@ private: ASSERT(false == v.isReference()); } - void isVariableDeclarationIdentifiesNestedTemplateVariable() - { + void isVariableDeclarationIdentifiesNestedTemplateVariable() { reset(); givenACodeSampleToTokenize var("std::deque > intsets;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); @@ -590,8 +562,7 @@ private: ASSERT(false == v.isReference()); } - void isVariableDeclarationIdentifiesReference() - { + void isVariableDeclarationIdentifiesReference() { reset(); givenACodeSampleToTokenize var1("int& foo;"); bool result1 = si.isVariableDeclaration(var1.tokens(), vartok, typetok); @@ -620,24 +591,21 @@ private: ASSERT(true == v3.isReference()); } - void isVariableDeclarationDoesNotIdentifyTemplateClass() - { + void isVariableDeclarationDoesNotIdentifyTemplateClass() { reset(); givenACodeSampleToTokenize var("template class SomeClass{};"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); ASSERT_EQUALS(false, result); } - void isVariableDeclarationDoesNotIdentifyCppCast() - { + void isVariableDeclarationDoesNotIdentifyCppCast() { reset(); givenACodeSampleToTokenize var("reinterpret_cast (code)[0] = 0;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); ASSERT_EQUALS(false, result); } - void isVariableDeclarationPointerConst() - { + void isVariableDeclarationPointerConst() { reset(); givenACodeSampleToTokenize var("std::string const* s;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); @@ -648,8 +616,7 @@ private: ASSERT(false == v.isReference()); } - void isVariableDeclarationRValueRef() - { + void isVariableDeclarationRValueRef() { reset(); givenACodeSampleToTokenize var("int&& i;"); bool result = si.isVariableDeclaration(var.tokens(), vartok, typetok); @@ -662,8 +629,7 @@ private: ASSERT(var.tokens()->tokAt(2)->scope() != 0); } - void isVariableStlType() - { + void isVariableStlType() { { reset(); std::istringstream code("std::string s;"); @@ -710,8 +676,7 @@ private: } } - void arrayMemberVar1() - { + void arrayMemberVar1() { const char code[] = "struct Foo {\n" " int x;\n" "};\n" @@ -731,8 +696,7 @@ private: ASSERT(tok && tok->varId() == 0U); // It's possible to set a varId } - void arrayMemberVar2() - { + void arrayMemberVar2() { const char code[] = "struct Foo {\n" " int x;\n" "};\n" @@ -752,8 +716,7 @@ private: ASSERT(tok && tok->varId() == 0U); // It's possible to set a varId } - void arrayMemberVar3() - { + void arrayMemberVar3() { const char code[] = "struct Foo {\n" " int x;\n" "};\n" @@ -773,8 +736,7 @@ private: ASSERT(tok && tok->varId() == 0U); // It's possible to set a varId } - void staticMemberVar() - { + void staticMemberVar() { GET_SYMBOL_DB("class Foo {\n" " static const double d;\n" "};\n" @@ -785,8 +747,7 @@ private: ASSERT(v && v->isStatic() && v->isConst() && v->isPrivate()); } - void hasRegularFunction() - { + void hasRegularFunction() { GET_SYMBOL_DB("void func() { }\n") // 2 scopes: Global and Function @@ -808,8 +769,7 @@ private: } } - void hasInlineClassFunction() - { + void hasInlineClassFunction() { GET_SYMBOL_DB("class Fred { void func() { } };\n") // 3 scopes: Global, Class, and Function @@ -835,8 +795,7 @@ private: } } - void hasMissingInlineClassFunction() - { + void hasMissingInlineClassFunction() { GET_SYMBOL_DB("class Fred { void func(); };\n") // 2 scopes: Global and Class (no Function scope because there is no function implementation) @@ -857,8 +816,7 @@ private: } } - void hasClassFunction() - { + void hasClassFunction() { GET_SYMBOL_DB("class Fred { void func(); }; void Fred::func() { }\n") // 3 scopes: Global, Class, and Function @@ -881,8 +839,7 @@ private: } } - void hasRegularFunctionReturningFunctionPointer() - { + void hasRegularFunctionReturningFunctionPointer() { GET_SYMBOL_DB("void (*func(int f))(char) { }\n") // 2 scopes: Global and Function @@ -903,8 +860,7 @@ private: } } - void hasInlineClassFunctionReturningFunctionPointer() - { + void hasInlineClassFunctionReturningFunctionPointer() { GET_SYMBOL_DB("class Fred { void (*func(int f))(char) { } };\n") // 3 scopes: Global, Class, and Function @@ -925,8 +881,7 @@ private: } } - void hasMissingInlineClassFunctionReturningFunctionPointer() - { + void hasMissingInlineClassFunctionReturningFunctionPointer() { GET_SYMBOL_DB("class Fred { void (*func(int f))(char); };\n") // 2 scopes: Global and Class (no Function scope because there is no function implementation) @@ -947,8 +902,7 @@ private: } } - void hasClassFunctionReturningFunctionPointer() - { + void hasClassFunctionReturningFunctionPointer() { GET_SYMBOL_DB("class Fred { void (*func(int f))(char); }; void (*Fred::func(int f))(char) { }\n") // 3 scopes: Global, Class, and Function @@ -969,8 +923,7 @@ private: } } - void complexFunctionArrayPtr() - { + void complexFunctionArrayPtr() { GET_SYMBOL_DB("int(*p1)[10]; \n" // pointer to array 10 of int "void(*p2)(char); \n" // pointer to function (char) returning void "int(*(*p3)(char))[10];\n" // pointer to function (char) returning pointer to array 10 of int @@ -1000,8 +953,7 @@ private: } } - void pointerToMemberFunction() - { + void pointerToMemberFunction() { GET_SYMBOL_DB("bool (A::*pFun)();"); // Pointer to member function of A, returning bool and taking no parameters ASSERT(db != nullptr); @@ -1015,8 +967,7 @@ private: } } - void hasSubClassConstructor() - { + void hasSubClassConstructor() { GET_SYMBOL_DB("class Foo { class Sub; }; class Foo::Sub { Sub() {} };"); ASSERT(db != nullptr); @@ -1034,8 +985,7 @@ private: } } - void testConstructors() - { + void testConstructors() { { GET_SYMBOL_DB("class Foo { Foo(Foo f); };"); const Function* ctor = tokenizer.tokens()->tokAt(3)->function(); @@ -1062,8 +1012,7 @@ private: } } - void functionDeclarationTemplate() - { + void functionDeclarationTemplate() { GET_SYMBOL_DB("std::map foo() {}") // 2 scopes: Global and Function @@ -1081,8 +1030,7 @@ private: } } - void functionDeclarations() - { + void functionDeclarations() { GET_SYMBOL_DB("void foo();\nvoid foo();\nint foo(int i);\nvoid foo() {}") // 2 scopes: Global and Function @@ -1109,8 +1057,7 @@ private: } } - void constructorInitialization() - { + void constructorInitialization() { GET_SYMBOL_DB("std::string logfile;\n" "std::ofstream log(logfile.c_str(), std::ios::out);"); @@ -1123,8 +1070,7 @@ private: } } - void memberFunctionOfUnknownClassMacro1() - { + void memberFunctionOfUnknownClassMacro1() { GET_SYMBOL_DB("class ScVbaFormatCondition { OUString getServiceImplName() SAL_OVERRIDE; };\n" "void ScVbaValidation::getFormula1() {\n" " sal_uInt16 nFlags = 0;\n" @@ -1140,8 +1086,7 @@ private: } } - void memberFunctionOfUnknownClassMacro2() - { + void memberFunctionOfUnknownClassMacro2() { GET_SYMBOL_DB("class ScVbaFormatCondition { OUString getServiceImplName() SAL_OVERRIDE {} };\n" "void getFormula1() {\n" " sal_uInt16 nFlags = 0;\n" @@ -1161,8 +1106,7 @@ private: } } - void memberFunctionOfUnknownClassMacro3() - { + void memberFunctionOfUnknownClassMacro3() { GET_SYMBOL_DB("class ScVbaFormatCondition { OUString getServiceImplName() THROW(whatever); };\n" "void ScVbaValidation::getFormula1() {\n" " sal_uInt16 nFlags = 0;\n" @@ -1178,8 +1122,7 @@ private: } } - void classWithFriend() - { + void classWithFriend() { GET_SYMBOL_DB("class Foo {}; class Bar1 { friend class Foo; }; class Bar2 { friend Foo; };") // 3 scopes: Global, 3 classes ASSERT(db && db->scopeList.size() == 4); @@ -1198,8 +1141,7 @@ private: } } - void parseFunctionCorrect() - { + void parseFunctionCorrect() { // ticket 3188 - "if" statement parsed as function GET_SYMBOL_DB("void func(i) int i; { if (i == 1) return; }\n") ASSERT(db != nullptr); @@ -1211,16 +1153,14 @@ private: ASSERT(findFunctionByName("if", &db->scopeList.back()) == nullptr); } - void parseFunctionDeclarationCorrect() - { + void parseFunctionDeclarationCorrect() { GET_SYMBOL_DB("void func();\n" "int bar() {}\n" "void func() {}") ASSERT_EQUALS(3, db->findScopeByName("func")->classStart->linenr()); } - void Cpp11InitInInitList() - { + void Cpp11InitInInitList() { GET_SYMBOL_DB("class Foo {\n" " std::vector bar;\n" " Foo() : bar({\"a\", \"b\"})\n" @@ -1229,8 +1169,7 @@ private: ASSERT_EQUALS(4, db->scopeList.front().nestedList.front()->nestedList.front()->classStart->linenr()); } - void hasGlobalVariables1() - { + void hasGlobalVariables1() { GET_SYMBOL_DB("int i;\n") ASSERT(db && db->scopeList.size() == 1); @@ -1245,8 +1184,7 @@ private: } } - void hasGlobalVariables2() - { + void hasGlobalVariables2() { GET_SYMBOL_DB("int array[2][2];\n") ASSERT(db && db->scopeList.size() == 1); @@ -1261,8 +1199,7 @@ private: } } - void hasGlobalVariables3() - { + void hasGlobalVariables3() { GET_SYMBOL_DB("int array[2][2] = { { 0, 0 }, { 0, 0 } };\n") ASSERT(db && db->scopeList.size() == 1); @@ -1277,8 +1214,7 @@ private: } } - void checkTypeStartEndToken1() - { + void checkTypeStartEndToken1() { GET_SYMBOL_DB("static std::string i;\n" "static const std::string j;\n" "const std::string* k;\n" @@ -1301,8 +1237,7 @@ private: } } - void checkTypeStartEndToken2() - { + void checkTypeStartEndToken2() { GET_SYMBOL_DB("class CodeGenerator {\n" " DiagnosticsEngine Diags;\n" "public:\n" @@ -1318,8 +1253,7 @@ private: ASSERT_EQUALS("DiagnosticsEngine", db->getVariableFromVarId(1)->typeStartToken()->str()); } - void check(const char code[], bool debug = true) - { + void check(const char code[], bool debug = true) { // Clear the error log errout.str(""); @@ -1337,8 +1271,7 @@ private: tokenizer.getSymbolDatabase(); } - void functionArgs1() - { + void functionArgs1() { { GET_SYMBOL_DB("void f(std::vector, const std::vector & v) { }"); ASSERT_EQUALS(1+1, db->getVariableListSize()); @@ -1379,8 +1312,7 @@ private: } } - void functionArgs2() - { + void functionArgs2() { GET_SYMBOL_DB("void f(int a[][4]) { }"); const Variable *a = db->getVariableFromVarId(1); ASSERT_EQUALS("a", a->nameToken()->str()); @@ -1391,15 +1323,13 @@ private: ASSERT_EQUALS(true, a->dimensions()[1].known); } - void functionArgs3() - { + void functionArgs3() { GET_SYMBOL_DB("void f(int i,) { }"); // Don't crash const Variable *a = db->getVariableFromVarId(1); ASSERT_EQUALS("i", a->nameToken()->str()); } - void functionArgs4() - { + void functionArgs4() { GET_SYMBOL_DB("void f1(char [10], struct foo [10]);"); ASSERT_EQUALS(true, db->scopeList.front().functionList.size() == 1UL); const Function *func = &db->scopeList.front().functionList.front(); @@ -1416,8 +1346,7 @@ private: } } - void namespaces1() - { + void namespaces1() { GET_SYMBOL_DB("namespace fred {\n" " namespace barney {\n" " class X { X(int); };\n" @@ -1447,8 +1376,7 @@ private: } // based on namespaces1 but here the namespaces match - void namespaces2() - { + void namespaces2() { GET_SYMBOL_DB("namespace fred {\n" " namespace barney {\n" " class X { X(int); };\n" @@ -1482,8 +1410,7 @@ private: ASSERT_EQUALS(true, function->hasBody); } - void namespaces3() // #3854 - namespace with unknown macro - { + void namespaces3() { // #3854 - namespace with unknown macro GET_SYMBOL_DB("namespace fred UNKNOWN_MACRO(default) {\n" "}"); ASSERT_EQUALS(2U, db->scopeList.size()); @@ -1491,8 +1418,7 @@ private: ASSERT_EQUALS(Scope::eNamespace, db->scopeList.back().type); } - void tryCatch1() - { + void tryCatch1() { const char str[] = "void foo() {\n" " try { }\n" " catch (const Error1 & x) { }\n" @@ -1508,8 +1434,7 @@ private: } - void symboldatabase1() - { + void symboldatabase1() { check("namespace foo {\n" " class bar;\n" "};"); @@ -1520,8 +1445,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase2() - { + void symboldatabase2() { check("class foo {\n" "public slots :\n" "foo() { }\n" @@ -1535,8 +1459,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase3() - { + void symboldatabase3() { check("typedef void (func_type)();\n" "struct A {\n" " friend func_type f : 2;\n" @@ -1544,8 +1467,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase4() - { + void symboldatabase4() { check("static void function_declaration_before(void) __attribute__((__used__));\n" "static void function_declaration_before(void) {}\n" "static void function_declaration_after(void) {}\n" @@ -1577,8 +1499,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase5() - { + void symboldatabase5() { // ticket #2178 - segmentation fault check("int CL_INLINE_DECL(integer_decode_float) (int x) {\n" " return (sign ? cl_I() : 0);\n" @@ -1586,8 +1507,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase6() - { + void symboldatabase6() { // ticket #2221 - segmentation fault check("template class X { };\n" "X< 1>2 > x1;\n" @@ -1599,8 +1519,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase7() - { + void symboldatabase7() { // ticket #2230 - segmentation fault check("template class E,class D> class C : E\n" "{\n" @@ -1615,8 +1534,7 @@ private: ASSERT_EQUALS("[test.cpp:1]: (debug) simplifyTemplates: bailing out\n", errout.str()); } - void symboldatabase8() - { + void symboldatabase8() { // ticket #2252 - segmentation fault check("struct PaletteColorSpaceHolder: public rtl::StaticWithInit,\n" " PaletteColorSpaceHolder>\n" @@ -1630,8 +1548,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase9() - { + void symboldatabase9() { // ticket #2425 - segmentation fault check("class CHyperlink : public CString\n" "{\n" @@ -1645,8 +1562,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase10() - { + void symboldatabase10() { // ticket #2537 - segmentation fault check("class A {\n" "private:\n" @@ -1659,8 +1575,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase11() - { + void symboldatabase11() { // ticket #2539 - segmentation fault check("int g ();\n" "struct S {\n" @@ -1670,8 +1585,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase12() - { + void symboldatabase12() { // ticket #2547 - segmentation fault check("class foo {\n" " void bar2 () = __null;\n" @@ -1680,8 +1594,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase13() - { + void symboldatabase13() { // ticket #2577 - segmentation fault check("class foo {\n" " void bar2 () = A::f;\n" @@ -1690,58 +1603,50 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase14() - { + void symboldatabase14() { // ticket #2589 - segmentation fault ASSERT_THROW(check("struct B : A\n"), InternalError); } - void symboldatabase15() - { + void symboldatabase15() { // ticket #2591 - segmentation fault ASSERT_THROW(check("struct A :\n"), InternalError); } - void symboldatabase16() - { + void symboldatabase16() { // ticket #2637 - segmentation fault check("{} const const\n"); ASSERT_EQUALS("", errout.str()); } - void symboldatabase17() - { + void symboldatabase17() { // ticket #2657 - segmentation fault check("return f(){}"); ASSERT_EQUALS("", errout.str()); } - void symboldatabase18() - { + void symboldatabase18() { // ticket #2865 - segmentation fault check("char a[1]\n"); ASSERT_EQUALS("", errout.str()); } - void symboldatabase19() - { + void symboldatabase19() { // ticket #2991 - segmentation fault check("::y(){x}"); ASSERT_EQUALS("", errout.str()); } - void symboldatabase20() - { + void symboldatabase20() { // ticket #3013 - segmentation fault ASSERT_THROW(check("struct x : virtual y\n"), InternalError); } - void symboldatabase21() - { + void symboldatabase21() { check("class Fred {\n" " class Foo { };\n" " void func() const;\n" @@ -1754,16 +1659,14 @@ private: } // #ticket 3437 (segmentation fault) - void symboldatabase22() - { + void symboldatabase22() { check("template struct A {};\n" "A a;\n"); ASSERT_EQUALS("", errout.str()); } // #ticket 3435 (std::vector) - void symboldatabase23() - { + void symboldatabase23() { GET_SYMBOL_DB("class A { std::vector ints; };"); ASSERT_EQUALS(2U, db->scopeList.size()); const Scope &scope = db->scopeList.back(); @@ -1774,8 +1677,7 @@ private: } // #ticket 3508 (constructor, destructor) - void symboldatabase24() - { + void symboldatabase24() { GET_SYMBOL_DB("struct Fred {\n" " ~Fred();\n" " Fred();\n" @@ -1817,8 +1719,7 @@ private: } // #ticket #3561 (throw C++) - void symboldatabase25() - { + void symboldatabase25() { const char str[] = "int main() {\n" " foo bar;\n" " throw bar;\n" @@ -1830,8 +1731,7 @@ private: } // #ticket #3561 (throw C) - void symboldatabase26() - { + void symboldatabase26() { const char str[] = "int main() {\n" " throw bar;\n" "}"; @@ -1842,8 +1742,7 @@ private: } // #ticket #3543 (segmentation fault) - void symboldatabase27() - { + void symboldatabase27() { check("class C : public B1\n" "{\n" " B1()\n" @@ -1852,31 +1751,27 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase28() - { + void symboldatabase28() { GET_SYMBOL_DB("struct S {};\n" "void foo(struct S s) {}"); ASSERT(db && db->getVariableFromVarId(1) && db->getVariableFromVarId(1)->typeScope() && db->getVariableFromVarId(1)->typeScope()->className == "S"); } // #ticket #4442 (segmentation fault) - void symboldatabase29() - { + void symboldatabase29() { check("struct B : A {\n" " B() : A {}\n" "};"); ASSERT_EQUALS("", errout.str()); } - void symboldatabase30() - { + void symboldatabase30() { GET_SYMBOL_DB("struct A { void foo(const int a); };\n" "void A::foo(int a) { }"); ASSERT(db && db->functionScopes.size() == 1 && db->functionScopes[0]->functionOf); } - void symboldatabase31() - { + void symboldatabase31() { GET_SYMBOL_DB("class Foo;\n" "class Bar;\n" "class Sub;\n" @@ -1921,8 +1816,7 @@ private: ASSERT(Bar_Sub && Bar_Sub->classScope && Bar_Sub->classScope->numConstructors == 2 && Bar_Sub->classScope->className == "Sub"); } - void symboldatabase32() - { + void symboldatabase32() { GET_SYMBOL_DB("struct Base {\n" " void foo() {}\n" "};\n" @@ -1931,8 +1825,7 @@ private: ASSERT(db && db->findScopeByName("Deri") && db->findScopeByName("Deri")->definedType->getFunction("foo")); } - void symboldatabase33() // ticket #4682 - { + void symboldatabase33() { // ticket #4682 GET_SYMBOL_DB("static struct A::B s;\n" "static struct A::B t = { 0 };\n" "static struct A::B u(0);\n" @@ -1942,8 +1835,7 @@ private: ASSERT(db && db->functionScopes.size() == 1); } - void symboldatabase34() // ticket #4694 - { + void symboldatabase34() { // ticket #4694 check("typedef _Atomic(int(A::*)) atomic_mem_ptr_to_int;\n" "typedef _Atomic(int)&atomic_int_ref;\n" "struct S {\n" @@ -1952,21 +1844,18 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase35() // ticket #4806 and #4841 - { + void symboldatabase35() { // ticket #4806 and #4841 check("class FragmentQueue : public CL_NS(util)::PriorityQueue >\n" "{};"); ASSERT_EQUALS("", errout.str()); } - void symboldatabase36() // ticket #4892 - { + void symboldatabase36() { // ticket #4892 check("void struct ( ) { if ( 1 ) } int main ( ) { }"); ASSERT_EQUALS("", errout.str()); } - void symboldatabase37() - { + void symboldatabase37() { GET_SYMBOL_DB("class Fred {\n" "public:\n" " struct Wilma { };\n" @@ -1999,8 +1888,7 @@ private: ASSERT(db->getVariableFromVarId(3) && db->getVariableFromVarId(3)->type() && db->getVariableFromVarId(3)->type()->name() == "Barney"); } - void symboldatabase38() // ticket #5125 - { + void symboldatabase38() { // ticket #5125 check("template struct scoped_service;\n" "struct service {};\n" "template <> struct scoped_service {};\n" @@ -2012,13 +1900,11 @@ private: "};"); } - void symboldatabase39() // ticket #5120 - { + void symboldatabase39() { // ticket #5120 check("struct V : { public case {} ; struct U : U void { V *f (int x) (x) } }"); } - void symboldatabase40() // ticket #5153 - { + void symboldatabase40() { // ticket #5153 check("void f() {\n" " try { }\n" " catch (std::bad_alloc) { }\n" @@ -2026,14 +1912,12 @@ private: ASSERT_EQUALS("", errout.str()); } - void symboldatabase41() // ticket #5197 (unknown macro) - { + void symboldatabase41() { // ticket #5197 (unknown macro) GET_SYMBOL_DB("struct X1 { MACRO1 f(int spd) MACRO2; };\n"); ASSERT(db && db->findScopeByName("X1") && db->findScopeByName("X1")->functionList.size() == 1 && !db->findScopeByName("X1")->functionList.front().hasBody); } - void symboldatabase42() // only put variables in variable list - { + void symboldatabase42() { // only put variables in variable list GET_SYMBOL_DB("void f() { extern int x(); }\n"); ASSERT(!!db); const Scope * const fscope = db ? db->findScopeByName("f") : nullptr; @@ -2041,16 +1925,14 @@ private: ASSERT_EQUALS(0U, fscope ? fscope->varlist.size() : ~0U); // "x" is not a variable } - void symboldatabase43() // ticket #4738 - { + void symboldatabase43() { // ticket #4738 check("void f() {\n" " new int;\n" "}\n"); ASSERT_EQUALS("", errout.str()); } - void symboldatabase44() - { + void symboldatabase44() { GET_SYMBOL_DB("int i { 1 };\n" "int j ( i );\n" "void foo() {\n" @@ -2064,8 +1946,7 @@ private: ASSERT(db->getVariableFromVarId(i) != nullptr); } - void symboldatabase45() - { + void symboldatabase45() { GET_SYMBOL_DB("typedef struct {\n" " unsigned long bits;\n" "} S;\n" @@ -2096,8 +1977,7 @@ private: ASSERT_EQUALS(Scope::eFunction, scope->type); } - void symboldatabase46() // #6171 (anonymous namespace) - { + void symboldatabase46() { // #6171 (anonymous namespace) GET_SYMBOL_DB("struct S { };\n" "namespace {\n" " struct S { };\n" @@ -2118,8 +1998,7 @@ private: ASSERT_EQUALS(scope->className, "S"); } - void isImplicitlyVirtual() - { + void isImplicitlyVirtual() { { GET_SYMBOL_DB("class Base {\n" " virtual void foo() {}\n" @@ -2233,8 +2112,7 @@ private: } } - void isFunction() // #5602 - UNKNOWN_MACRO(a,b) { .. } - { + void isFunction() { // #5602 - UNKNOWN_MACRO(a,b) { .. } GET_SYMBOL_DB("TEST(a,b) {\n" " std::vector messages;\n" " foo(messages[2].size());\n" @@ -2247,8 +2125,7 @@ private: var->typeStartToken()->str() == "std"); } - void findFunction1() - { + void findFunction1() { GET_SYMBOL_DB("int foo(int x);\n" /* 1 */ "void foo();\n" /* 2 */ "void bar() {\n" /* 3 */ @@ -2280,8 +2157,7 @@ private: } } - void findFunction2() - { + void findFunction2() { // The function does not match the function call. GET_SYMBOL_DB("void func(const int x, const Fred &fred);\n" "void otherfunc() {\n" @@ -2295,8 +2171,7 @@ private: ASSERT_EQUALS(false, (callfunc && callfunc->function())); // callfunc->function() should be null } - void findFunction3() - { + void findFunction3() { GET_SYMBOL_DB("struct base { void foo() { } };\n" "struct derived : public base { void foo() { } };\n" "void foo() {\n" @@ -2311,8 +2186,7 @@ private: ASSERT_EQUALS(true, callfunc && callfunc->tokAt(2)->function() && callfunc->tokAt(2)->function()->tokenDef->linenr() == 2); // should find function on line 2 } - void findFunction4() - { + void findFunction4() { GET_SYMBOL_DB("void foo(UNKNOWN) { }\n" "void foo(int a) { }\n" "void foo(unsigned int a) { }\n" @@ -2460,8 +2334,7 @@ private: ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 8); } - void findFunction5() - { + void findFunction5() { GET_SYMBOL_DB("struct Fred {\n" " void Sync(dsmp_t& type, int& len, int limit = 123);\n" " void Sync(int& syncpos, dsmp_t& type, int& len, int limit = 123);\n" @@ -2480,8 +2353,7 @@ private: ASSERT_EQUALS(true, db && f && f->function() && f->function()->tokenDef->linenr() == 2); } - void findFunction6() // avoid null pointer access - { + void findFunction6() { // avoid null pointer access GET_SYMBOL_DB("void addtoken(Token** rettail, const Token *tok);\n" "void CheckMemoryLeakInFunction::getcode(const Token *tok ) {\n" " addtoken(&rettail, tok);\n" @@ -2495,8 +2367,7 @@ private: ASSERT_EQUALS(true, x != nullptr); \ if (x) ASSERT_EQUALS(true, x->isNoExcept); - void noexceptFunction1() - { + void noexceptFunction1() { GET_SYMBOL_DB("void func1() noexcept;\n" "void func2() noexcept { }\n" "void func3() noexcept(true);\n" @@ -2512,8 +2383,7 @@ private: } } - void noexceptFunction2() - { + void noexceptFunction2() { GET_SYMBOL_DB("template void self_assign(T& t) noexcept(noexcept(t = t)) {t = t; }\n"); ASSERT_EQUALS("", errout.str()); @@ -2528,8 +2398,7 @@ private: ASSERT_EQUALS(true, x != nullptr); \ if (x) ASSERT_EQUALS(true, x->isNoExcept); - void noexceptFunction3() - { + void noexceptFunction3() { GET_SYMBOL_DB("struct Fred {\n" " void func1() noexcept;\n" " void func2() noexcept { }\n" @@ -2567,8 +2436,7 @@ private: } } - void noexceptFunction4() - { + void noexceptFunction4() { GET_SYMBOL_DB("class A {\n" "public:\n" " A(A&& a) {\n" @@ -2596,8 +2464,7 @@ private: ASSERT_EQUALS(true, x != nullptr); \ if (x) ASSERT_EQUALS(true, x->isThrow); - void throwFunction1() - { + void throwFunction1() { GET_SYMBOL_DB("void func1() throw();\n" "void func2() throw() { }\n" "void func3() throw(int);\n" @@ -2616,8 +2483,7 @@ private: #define CLASS_FUNC_THROW(x, y) const Function *x = findFunctionByName(#x, y); \ ASSERT_EQUALS(true, x != nullptr); \ if (x) ASSERT_EQUALS(true, x->isThrow); - void throwFunction2() - { + void throwFunction2() { GET_SYMBOL_DB("struct Fred {\n" " void func1() throw();\n" " void func2() throw() { }\n" @@ -2655,8 +2521,7 @@ private: } } - void nothrowAttributeFunction() - { + void nothrowAttributeFunction() { GET_SYMBOL_DB("void func() __attribute__((nothrow));\n" "void func() { }\n"); ASSERT_EQUALS("", errout.str()); @@ -2670,8 +2535,7 @@ private: } } - void nothrowDeclspecFunction() - { + void nothrowDeclspecFunction() { GET_SYMBOL_DB("void __declspec(nothrow) func() { }\n"); ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS(true, db != nullptr); // not null @@ -2684,8 +2548,7 @@ private: } } - void varTypesIntegral() - { + void varTypesIntegral() { GET_SYMBOL_DB("void f() { bool b; char c; unsigned char uc; short s; unsigned short us; int i; unsigned u; unsigned int ui; long l; unsigned long ul; long long ll; }"); const Variable *b = db->getVariableFromVarId(1); ASSERT(b != nullptr); @@ -2766,8 +2629,7 @@ private: } } - void varTypesFloating() - { + void varTypesFloating() { { GET_SYMBOL_DB("void f() { float f; double d; long double ld; }"); const Variable *f = db->getVariableFromVarId(1); @@ -2824,8 +2686,7 @@ private: } } - void varTypesOther() - { + void varTypesOther() { GET_SYMBOL_DB("void f() { class A {} a; void *b; }"); const Variable *a = db->getVariableFromVarId(1); ASSERT(a != nullptr); @@ -2843,8 +2704,7 @@ private: } } - void functionPrototype() - { + void functionPrototype() { check("int foo(int x) {\n" " extern int func1();\n" " extern int func2(int);\n" @@ -2855,8 +2715,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void lambda() - { + void lambda() { GET_SYMBOL_DB("void func() {\n" " float y = 0.0f;\n" " auto lambda = [&]()\n" diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 23d7bb29b..0f0963d1d 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -30,8 +30,7 @@ extern std::ostringstream output; class TestThreadExecutor : public TestFixture { public: - TestThreadExecutor() : TestFixture("TestThreadExecutor") - { + TestThreadExecutor() : TestFixture("TestThreadExecutor") { } private: @@ -40,8 +39,7 @@ private: * Execute check using n jobs for y files which are have * identical data, given within data. */ - void check(unsigned int jobs, int files, int result, const std::string &data) - { + void check(unsigned int jobs, int files, int result, const std::string &data) { errout.str(""); output.str(""); if (!ThreadExecutor::isEnabled()) { @@ -65,8 +63,7 @@ private: ASSERT_EQUALS(result, executor.check()); } - void run() - { + void run() { TEST_CASE(deadlock_with_many_errors); TEST_CASE(many_threads); TEST_CASE(no_errors_more_files); @@ -76,8 +73,7 @@ private: TEST_CASE(one_error_several_files); } - void deadlock_with_many_errors() - { + void deadlock_with_many_errors() { std::ostringstream oss; oss << "int main()\n" << "{\n"; @@ -89,8 +85,7 @@ private: check(2, 3, 3, oss.str()); } - void many_threads() - { + void many_threads() { std::ostringstream oss; oss << "int main()\n" << "{\n"; @@ -100,8 +95,7 @@ private: check(20, 100, 100, oss.str()); } - void no_errors_more_files() - { + void no_errors_more_files() { std::ostringstream oss; oss << "int main()\n" << "{\n" @@ -110,8 +104,7 @@ private: check(2, 3, 0, oss.str()); } - void no_errors_less_files() - { + void no_errors_less_files() { std::ostringstream oss; oss << "int main()\n" << "{\n" @@ -120,8 +113,7 @@ private: check(2, 1, 0, oss.str()); } - void no_errors_equal_amount_files() - { + void no_errors_equal_amount_files() { std::ostringstream oss; oss << "int main()\n" << "{\n" @@ -130,8 +122,7 @@ private: check(2, 2, 0, oss.str()); } - void one_error_less_files() - { + void one_error_less_files() { std::ostringstream oss; oss << "int main()\n" << "{\n" @@ -141,8 +132,7 @@ private: check(2, 1, 1, oss.str()); } - void one_error_several_files() - { + void one_error_several_files() { std::ostringstream oss; oss << "int main()\n" << "{\n" diff --git a/test/testtimer.cpp b/test/testtimer.cpp index 9cc769497..1db64beb6 100644 --- a/test/testtimer.cpp +++ b/test/testtimer.cpp @@ -24,19 +24,16 @@ class TestTimer : public TestFixture { public: - TestTimer() : TestFixture("TestTimer") - { + TestTimer() : TestFixture("TestTimer") { } private: - void run() - { + void run() { TEST_CASE(result); } - void result() const - { + void result() const { TimerResultsData t1; t1._clocks = ~(std::clock_t)0; ASSERT(t1.seconds() > 100.0); diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 02e890857..8398a8ea3 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -27,8 +27,7 @@ extern std::ostringstream errout; class TestToken : public TestFixture { public: - TestToken() : TestFixture("TestToken") - { + TestToken() : TestFixture("TestToken") { } private: @@ -39,8 +38,7 @@ private: std::vector extendedOps; std::vector assignmentOps; - void run() - { + void run() { initOps(); TEST_CASE(nextprevious); @@ -95,8 +93,7 @@ private: TEST_CASE(canFindMatchingBracketsWithTooManyOpening); } - void nextprevious() const - { + void nextprevious() const { Token *token = new Token(0); token->str("1"); token->insertToken("2"); @@ -117,8 +114,7 @@ private: TokenList::deleteTokens(token); } - bool Match(const std::string &code, const std::string &pattern, unsigned int varid=0) - { + bool Match(const std::string &code, const std::string &pattern, unsigned int varid=0) { static const Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); @@ -128,8 +124,7 @@ private: return Token::Match(tokenizer.tokens(), pattern.c_str(), varid); } - void multiCompare() const - { + void multiCompare() const { // Test for found Token one(0); one.str("one"); @@ -181,15 +176,13 @@ private: ASSERT_EQUALS(-1, Token::multiCompare(&x, "%op%|two", 0)); } - void multiCompare2() const // #3294 - { + void multiCompare2() const { // #3294 // Original pattern that failed: [[,(=<>+-*|&^] %num% [+-*/] %num% ]|,|)|;|=|%op% givenACodeSampleToTokenize toks("a == 1", true); ASSERT_EQUALS(true, Token::Match(toks.tokens(), "a =|%op%")); } - void multiCompare3() const - { + void multiCompare3() const { // Original pattern that failed: "return|(|&&|%oror% %var% &&|%oror%|==|!=|<=|>=|<|>|-|%or% %var% )|&&|%oror%|;" // Code snippet that failed: "return lv@86 |= rv@87 ;" @@ -241,8 +234,7 @@ private: ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %bool%|%var%| )|")); } - void multiCompare4() const - { + void multiCompare4() const { givenACodeSampleToTokenize var("std :: queue < int > foo ;"); ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->type()); @@ -253,15 +245,13 @@ private: ASSERT_EQUALS(false, Token::Match(var.tokens(), "std :: queue %op%|x")); } - void multiCompare5() const - { + void multiCompare5() const { Token tok(0); tok.str("||"); ASSERT_EQUALS(true, Token::multiCompare(&tok, "+|%or%|%oror%", 0) >= 0); } - void getStrLength() const - { + void getStrLength() const { Token tok(0); tok.str("\"\""); @@ -277,8 +267,7 @@ private: ASSERT_EQUALS(1, (int)Token::getStrLength(&tok)); } - void getStrSize() const - { + void getStrSize() const { Token tok(0); tok.str("\"abc\""); @@ -291,8 +280,7 @@ private: ASSERT_EQUALS(sizeof("\\"), Token::getStrSize(&tok)); } - void strValue() const - { + void strValue() const { Token tok(0); tok.str("\"\""); ASSERT_EQUALS("", tok.strValue()); @@ -302,8 +290,7 @@ private: } - void deleteLast() const - { + void deleteLast() const { Token *tokensBack = 0; Token tok(&tokensBack); tok.insertToken("aba"); @@ -312,8 +299,7 @@ private: ASSERT_EQUALS(true, tokensBack == &tok); } - void nextArgument() const - { + void nextArgument() const { givenACodeSampleToTokenize example1("foo(1, 2, 3, 4);"); ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(2)->nextArgument(), "2 , 3")); ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(4)->nextArgument(), "3 , 4")); @@ -328,16 +314,14 @@ private: ASSERT_EQUALS(true, Token::simpleMatch(example4.tokens()->tokAt(2)->nextArgument(), "\"\" , 3")); } - void eraseTokens() const - { + void eraseTokens() const { givenACodeSampleToTokenize code("begin ; { this code will be removed } end", true); Token::eraseTokens(code.tokens()->next(), code.tokens()->tokAt(9)); ASSERT_EQUALS("begin ; end", code.tokens()->stringifyList(0, false)); } - void matchAny() const - { + void matchAny() const { givenACodeSampleToTokenize varBitOrVar("abc|def", true); ASSERT_EQUALS(true, Token::Match(varBitOrVar.tokens(), "%var% %or% %var%")); @@ -345,8 +329,7 @@ private: ASSERT_EQUALS(true, Token::Match(varLogOrVar.tokens(), "%var% %oror% %var%")); } - void matchSingleChar() const - { + void matchSingleChar() const { givenACodeSampleToTokenize singleChar("a", true); ASSERT_EQUALS(true, Token::Match(singleChar.tokens(), "[a|bc]")); ASSERT_EQUALS(false, Token::Match(singleChar.tokens(), "[d|ef]")); @@ -356,8 +339,7 @@ private: ASSERT_EQUALS(false, Token::Match(&multiChar, "[ab|def]")); } - void matchNothingOrAnyNotElse() const - { + void matchNothingOrAnyNotElse() const { givenACodeSampleToTokenize empty_String("", true); ASSERT_EQUALS(true, Token::Match(empty_String.tokens(), "!!else")); ASSERT_EQUALS(false, Token::Match(empty_String.tokens(), "!!else something")); @@ -375,8 +357,7 @@ private: ASSERT_EQUALS(false, Token::Match(ifSemicolonElse.tokens(), "if ; !!else")); } - void matchType() const - { + void matchType() const { givenACodeSampleToTokenize type("abc", true); ASSERT_EQUALS(true, Token::Match(type.tokens(), "%type%")); @@ -395,8 +376,7 @@ private: ASSERT_EQUALS(false, Token::Match(noType2.tokens(), "!!foo %type%")); } - void matchChar() const - { + void matchChar() const { givenACodeSampleToTokenize chr1("'a'", true); ASSERT_EQUALS(true, Token::Match(chr1.tokens(), "%char%")); @@ -407,8 +387,7 @@ private: ASSERT_EQUALS(false, Token::Match(noChr.tokens(), "%char%")); } - void matchCompOp() const - { + void matchCompOp() const { givenACodeSampleToTokenize comp1("<=", true); ASSERT_EQUALS(true, Token::Match(comp1.tokens(), "%comp%")); @@ -419,8 +398,7 @@ private: ASSERT_EQUALS(false, Token::Match(noComp.tokens(), "%comp%")); } - void matchStr() const - { + void matchStr() const { givenACodeSampleToTokenize noStr1("abc", true); ASSERT_EQUALS(false, Token::Match(noStr1.tokens(), "%str%")); @@ -435,8 +413,7 @@ private: ASSERT_EQUALS(true, Token::Match(emptyStr.tokens(), "%str%")); } - void matchVarid() const - { + void matchVarid() const { givenACodeSampleToTokenize var("int a ; int b ;"); // Varid == 0 should throw exception @@ -449,8 +426,7 @@ private: ASSERT_EQUALS(false, Token::Match(var.tokens(), "%type% %varid% ; %type% %varid%", 2)); } - void matchNumeric() const - { + void matchNumeric() const { givenACodeSampleToTokenize nonNumeric("abc", true); ASSERT_EQUALS(false, Token::Match(nonNumeric.tokens(), "%num%")); @@ -504,8 +480,7 @@ private: } - void matchBoolean() const - { + void matchBoolean() const { givenACodeSampleToTokenize yes("YES", true); ASSERT_EQUALS(false, Token::Match(yes.tokens(), "%bool%")); @@ -516,8 +491,7 @@ private: ASSERT_EQUALS(true, Token::Match(negative.tokens(), "%bool%")); } - void matchOr() const - { + void matchOr() const { givenACodeSampleToTokenize bitwiseOr("|", true); ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%or%")); ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "%op%")); @@ -541,13 +515,11 @@ private: ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "%oror%|&&")); } - static void append_vector(std::vector &dest, const std::vector &src) - { + static void append_vector(std::vector &dest, const std::vector &src) { dest.insert(dest.end(), src.begin(), src.end()); } - void initOps() - { + void initOps() { arithmeticalOps.push_back("+"); arithmeticalOps.push_back("-"); arithmeticalOps.push_back("*"); @@ -591,8 +563,7 @@ private: assignmentOps.push_back(">>="); } - void matchOp() - { + void matchOp() { std::vector test_ops; append_vector(test_ops, arithmeticalOps); append_vector(test_ops, bitOps); @@ -615,8 +586,7 @@ private: } } - void matchConstOp() - { + void matchConstOp() { std::vector test_ops; append_vector(test_ops, arithmeticalOps); append_vector(test_ops, bitOps); @@ -640,8 +610,7 @@ private: } - void isArithmeticalOp() const - { + void isArithmeticalOp() const { std::vector::const_iterator test_op, test_ops_end = arithmeticalOps.end(); for (test_op = arithmeticalOps.begin(); test_op != test_ops_end; ++test_op) { Token tok(nullptr); @@ -665,8 +634,7 @@ private: } } - void isOp() const - { + void isOp() const { std::vector test_ops; append_vector(test_ops, arithmeticalOps); append_vector(test_ops, bitOps); @@ -693,8 +661,7 @@ private: } } - void isConstOp() const - { + void isConstOp() const { std::vector test_ops; append_vector(test_ops, arithmeticalOps); append_vector(test_ops, bitOps); @@ -721,8 +688,7 @@ private: } } - void isExtendedOp() const - { + void isExtendedOp() const { std::vector test_ops; append_vector(test_ops, arithmeticalOps); append_vector(test_ops, bitOps); @@ -746,8 +712,7 @@ private: } } - void isAssignmentOp() const - { + void isAssignmentOp() const { std::vector::const_iterator test_op, test_ops_end = assignmentOps.end(); for (test_op = assignmentOps.begin(); test_op != test_ops_end; ++test_op) { Token tok(nullptr); @@ -771,8 +736,7 @@ private: } } - void operators() const - { + void operators() const { std::vector::const_iterator test_op; for (test_op = extendedOps.begin(); test_op != extendedOps.end(); ++test_op) { Token tok(nullptr); @@ -801,8 +765,7 @@ private: ASSERT_EQUALS(Token::eIncDecOp, tok.type()); } - void literals() const - { + void literals() const { Token tok(nullptr); tok.str("\"foo\""); @@ -821,8 +784,7 @@ private: ASSERT(tok.type() == Token::eBoolean); } - void isStandardType() const - { + void isStandardType() const { std::vector standard_types; standard_types.push_back("bool"); standard_types.push_back("char"); @@ -850,8 +812,7 @@ private: ASSERT_EQUALS(true, tok.isStandardType()); } - void updateProperties() const - { + void updateProperties() const { Token tok(nullptr); tok.str("foobar"); @@ -864,8 +825,7 @@ private: ASSERT_EQUALS(true, tok.isNumber()); } - void updatePropertiesConcatStr() const - { + void updatePropertiesConcatStr() const { Token tok(nullptr); tok.str("true"); @@ -877,37 +837,32 @@ private: ASSERT_EQUALS("tru23", tok.str()); } - void isNameGuarantees1() const - { + void isNameGuarantees1() const { Token tok(nullptr); tok.str("Name"); ASSERT_EQUALS(true, tok.isName()); } - void isNameGuarantees2() const - { + void isNameGuarantees2() const { Token tok(nullptr); tok.str("_name"); ASSERT_EQUALS(true, tok.isName()); } - void isNameGuarantees3() const - { + void isNameGuarantees3() const { Token tok(nullptr); tok.str("_123"); ASSERT_EQUALS(true, tok.isName()); } - void isNameGuarantees4() const - { + void isNameGuarantees4() const { Token tok(nullptr); tok.str("123456"); ASSERT_EQUALS(false, tok.isName()); ASSERT_EQUALS(true, tok.isNumber()); } - void isNameGuarantees5() const - { + void isNameGuarantees5() const { Token tok(nullptr); tok.str("a123456"); ASSERT_EQUALS(true, tok.isName()); @@ -915,16 +870,14 @@ private: } - void canFindMatchingBracketsNeedsOpen() const - { + void canFindMatchingBracketsNeedsOpen() const { givenACodeSampleToTokenize var("std::deque > intsets;"); const Token* t = var.tokens()->findClosingBracket(); ASSERT(t == nullptr); } - void canFindMatchingBracketsInnerPair() const - { + void canFindMatchingBracketsInnerPair() const { givenACodeSampleToTokenize var("std::deque > intsets;"); Token* t = const_cast(var.tokens()->tokAt(7))->findClosingBracket(); @@ -932,8 +885,7 @@ private: ASSERT(var.tokens()->tokAt(9) == t); } - void canFindMatchingBracketsOuterPair() const - { + void canFindMatchingBracketsOuterPair() const { givenACodeSampleToTokenize var("std::deque > intsets;"); const Token* t = var.tokens()->tokAt(3)->findClosingBracket(); @@ -941,8 +893,7 @@ private: ASSERT(var.tokens()->tokAt(10) == t); } - void canFindMatchingBracketsWithTooManyClosing() const - { + void canFindMatchingBracketsWithTooManyClosing() const { givenACodeSampleToTokenize var("X< 1>2 > x1;\n"); const Token* t = var.tokens()->next()->findClosingBracket(); @@ -950,8 +901,7 @@ private: ASSERT(var.tokens()->tokAt(3) == t); } - void canFindMatchingBracketsWithTooManyOpening() const - { + void canFindMatchingBracketsWithTooManyOpening() const { givenACodeSampleToTokenize var("X < (2 < 1) > x1;\n"); const Token* t = var.tokens()->next()->findClosingBracket(); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 38e8da62c..fe16099c6 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -29,15 +29,13 @@ extern std::ostringstream errout; class TestTokenizer : public TestFixture { public: - TestTokenizer() : TestFixture("TestTokenizer") - { + TestTokenizer() : TestFixture("TestTokenizer") { } private: Settings settings_windows; - void run() - { + void run() { LOAD_LIB_2(settings_windows.library, "windows.cfg"); TEST_CASE(tokenize1); @@ -475,8 +473,7 @@ private: TEST_CASE(startOfExecutableScope); } - std::string tokenizeAndStringify(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Unspecified, const char* filename = "test.cpp", bool cpp11 = true) - { + std::string tokenizeAndStringify(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Unspecified, const char* filename = "test.cpp", bool cpp11 = true) { errout.str(""); Settings settings; @@ -507,8 +504,7 @@ private: return ""; } - std::string tokenizeAndStringifyWindows(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Unspecified, const char* filename = "test.cpp", bool cpp11 = true) - { + std::string tokenizeAndStringifyWindows(const char code[], bool simplify = false, bool expand = true, Settings::PlatformType platform = Settings::Unspecified, const char* filename = "test.cpp", bool cpp11 = true) { errout.str(""); settings_windows.debugwarnings = true; @@ -539,21 +535,18 @@ private: } - void tokenize1() - { + void tokenize1() { const char code[] = "void f ( )\n" "{ if ( p . y ( ) > yof ) { } }"; ASSERT_EQUALS(code, tokenizeAndStringify(code)); } - void tokenize2() - { + void tokenize2() { const char code[] = "{ sizeof a, sizeof b }"; ASSERT_EQUALS("{ sizeof ( a ) , sizeof ( b ) }", tokenizeAndStringify(code)); } - void tokenize3() - { + void tokenize3() { const char code[] = "void foo()\n" "{\n" " int i;\n" @@ -567,8 +560,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void tokenize4() - { + void tokenize4() { const char code[] = "class foo\n" "{\n" "public:\n" @@ -582,15 +574,13 @@ private: ASSERT_EQUALS("", errout.str()); } - void tokenize5() - { + void tokenize5() { // Tokenize values ASSERT_EQUALS("; + 1E3 ;", tokenizeAndStringify("; +1E3 ;")); ASSERT_EQUALS("; 1E-2 ;", tokenizeAndStringify("; 1E-2 ;")); } - void tokenize6() - { + void tokenize6() { // "&p[1]" => "p+1" /* ASSERT_EQUALS("; x = p + n ;", tokenizeAndStringify("; x = & p [ n ] ;", true)); @@ -633,8 +623,7 @@ private: ASSERT_EQUALS("; z = foo ( ) * ( x + y ) ;", tokenizeAndStringify("; z = foo() * (x + y);", true)); } - void tokenize7() - { + void tokenize7() { const char code[] = "void f() {\n" " int x1 = 1;\n" " int x2(x1);\n" @@ -643,8 +632,7 @@ private: tokenizeAndStringify(code, false)); } - void tokenize8() - { + void tokenize8() { const char code[] = "void f() {\n" " int x1(g());\n" " int x2(x1);\n" @@ -657,8 +645,7 @@ private: tokenizeDebugListing(code, false)); } - void tokenize9() - { + void tokenize9() { const char code[] = "typedef void (*fp)();\n" "typedef fp (*fpp)();\n" "void f() {\n" @@ -668,22 +655,19 @@ private: ASSERT_EQUALS("", errout.str()); } - void tokenize10() - { + void tokenize10() { ASSERT_EQUALS("private:", tokenizeAndStringify("private:", false)); ASSERT_EQUALS("protected:", tokenizeAndStringify("protected:", false)); ASSERT_EQUALS("public:", tokenizeAndStringify("public:", false)); ASSERT_EQUALS("__published:", tokenizeAndStringify("__published:", false)); } - void tokenize11() - { + void tokenize11() { ASSERT_EQUALS("X * sizeof ( Y ( ) ) ;", tokenizeAndStringify("X * sizeof(Y());", false)); } // ticket #2118 - invalid syntax error - void tokenize12() - { + void tokenize12() { const char code[] = "Q_GLOBAL_STATIC_WITH_INITIALIZER(Qt4NodeStaticData, qt4NodeStaticData, {\n" " for (unsigned i = 0 ; i < count; i++) {\n" " }\n" @@ -692,8 +676,7 @@ private: } // bailout if there is "@" - it is not handled well - void tokenize13() - { + void tokenize13() { const char code[] = "@implementation\n" "-(Foo *)foo: (Bar *)bar\n" "{ }\n" @@ -702,38 +685,32 @@ private: } // Ticket #2361: 0X10 => 16 - void tokenize14() - { + void tokenize14() { ASSERT_EQUALS("; 16 ;", tokenizeAndStringify(";0x10;")); ASSERT_EQUALS("; 16 ;", tokenizeAndStringify(";0X10;")); ASSERT_EQUALS("; 292 ;", tokenizeAndStringify(";0444;")); } // Ticket #2429: 0.125 - void tokenize15() - { + void tokenize15() { ASSERT_EQUALS("0.125", tokenizeAndStringify(".125")); ASSERT_EQUALS("005.125", tokenizeAndStringify("005.125")); // Don't confuse with octal values } // #2612 - segfault for "<><<" - void tokenize16() - { + void tokenize16() { tokenizeAndStringify("<><<"); } - void tokenize17() // #2759 - { + void tokenize17() { // #2759 ASSERT_EQUALS("class B : private :: A { } ;", tokenizeAndStringify("class B : private ::A { };")); } - void tokenize18() // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )" - { + void tokenize18() { // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )" ASSERT_EQUALS("( X && Y )", tokenizeAndStringify("(X&&Y)")); } - void tokenize19() - { + void tokenize19() { // #3006 - added hasComplicatedSyntaxErrorsInTemplates to avoid segmentation fault ASSERT_THROW(tokenizeAndStringify("x < () <"), InternalError); @@ -758,18 +735,15 @@ private: "};")); } - void tokenize20() // replace C99 _Bool => bool - { + void tokenize20() { // replace C99 _Bool => bool ASSERT_EQUALS("bool a ; a = true ;", tokenizeAndStringify("_Bool a = true;")); } - void tokenize21() // tokenize 0x0E-7 - { + void tokenize21() { // tokenize 0x0E-7 ASSERT_EQUALS("14 - 7", tokenizeAndStringify("0x0E-7")); } - void tokenize22() // tokenize special marker $ from preprocessor - { + void tokenize22() { // tokenize special marker $ from preprocessor ASSERT_EQUALS("a $b", tokenizeAndStringify("a$b")); ASSERT_EQUALS("a $b\nc", tokenizeAndStringify("a $b\nc")); ASSERT_EQUALS("a = $0 ;", tokenizeAndStringify("a = $0;")); @@ -778,25 +752,21 @@ private: } // #4195 - segfault for "enum { int f ( ) { return = } r = f ( ) ; }" - void tokenize24() - { + void tokenize24() { ASSERT_THROW(tokenizeAndStringify("enum { int f ( ) { return = } r = f ( ) ; }"), InternalError); } // #4239 - segfault for "f ( struct { int typedef T x ; } ) { }" - void tokenize25() - { + void tokenize25() { tokenizeAndStringify("f ( struct { int typedef T x ; } ) { }"); } // #4245 - segfault - void tokenize26() - { + void tokenize26() { tokenizeAndStringify("class x { protected : template < int y = } ;"); } - void tokenize27() - { + void tokenize27() { // #4525 - segfault tokenizeAndStringify("struct except_spec_d_good : except_spec_a, except_spec_b {\n" "~except_spec_d_good();\n" @@ -810,28 +780,24 @@ private: } // #4725 - ^{} - void tokenize28() - { + void tokenize28() { ASSERT_EQUALS("void f ( ) { asm ( \"^{}\" ) ; }", tokenizeAndStringify("void f() { ^{} }")); ASSERT_EQUALS("void f ( ) { asm ( \"x(^{})\" ) ; }", tokenizeAndStringify("void f() { x(^{}); }")); ASSERT_EQUALS("; asm ( \"voidf^{return}intmain\" ) ; ( ) { }", tokenizeAndStringify("; void f ^ { return } int main ( ) { }")); } // #5506 - segmentation fault upon invalid code - void tokenize29() - { + void tokenize29() { tokenizeAndStringify("A template < int { int = -1 ; } template < int N > struct B { int [ A < N > :: zero ] ; } ; B < 0 > b ;"); } // #5356 - segmentation fault upon invalid code - void tokenize30() - { + void tokenize30() { tokenizeAndStringify("struct template struct B { }; B < 0 > b;"); } // #3503 - don't "simplify" SetFunction member function to a variable - void tokenize31() - { + void tokenize31() { ASSERT_EQUALS("struct TTestClass { TTestClass ( ) { }\n" "void SetFunction ( Other * m_f ) { }\n" "} ;", @@ -848,16 +814,14 @@ private: } // #5884 - Avoid left shift of negative integer value. - void tokenize32() - { + void tokenize32() { // Do not simplify negative integer left shifts. const char * code = "void f ( ) { int max_x ; max_x = -10000 << 16 ; }"; ASSERT_EQUALS(code, tokenizeAndStringify(code)); } // #5780 Various crashes on valid template code in Tokenizer::setVarId() - void tokenize33() - { + void tokenize33() { const char * code = "template> struct vector {};\n" "void z() {\n" " vector VI;\n" @@ -865,15 +829,13 @@ private: ASSERT_THROW(tokenizeAndStringify(code, true), InternalError); } - void tokenize34() // #6121 - { + void tokenize34() { // #6121 const char code[] = "enum E { f = {} };\n" "int a = f;"; ASSERT_THROW(tokenizeAndStringify(code, true), InternalError); } - void syntax_case_default() // correct syntax - { + void syntax_case_default() { // correct syntax tokenizeAndStringify("void f() {switch (n) { case 0: z(); break;}}"); ASSERT_EQUALS("", errout.str()); @@ -911,21 +873,18 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifyFileAndLineMacro() // tokenize 'return - __LINE__' correctly - { + void simplifyFileAndLineMacro() { // tokenize 'return - __LINE__' correctly ASSERT_EQUALS("\"test.cpp\"", tokenizeAndStringify("__FILE__")); ASSERT_EQUALS("return -1 ;", tokenizeAndStringify("return - __LINE__;")); } - void foreach () - { + void foreach() { // #3690,#5154 const char code[] ="void f() { for each ( char c in MyString ) { Console::Write(c); } }"; ASSERT_EQUALS("void f ( ) { asm ( \"char c in MyString\" ) { Console :: Write ( c ) ; } }" ,tokenizeAndStringify(code)); } - void concatenateNegativeNumber() - { + void concatenateNegativeNumber() { ASSERT_EQUALS("i = -12", tokenizeAndStringify("i = -12")); ASSERT_EQUALS("1 - 2", tokenizeAndStringify("1-2")); ASSERT_EQUALS("foo ( -1 ) - 2", tokenizeAndStringify("foo(-1)-2")); @@ -937,8 +896,7 @@ private: - void longtok() - { + void longtok() { const std::string filedata(10000, 'a'); errout.str(""); @@ -957,8 +915,7 @@ private: // Don’t remove "(int *)".. - void removeCast1() - { + void removeCast1() { const char code[] = "int *f(int *);"; errout.str(""); @@ -976,8 +933,7 @@ private: } // remove static_cast.. - void removeCast2() - { + void removeCast2() { const char code[] = "t = (static_cast *>(&p));\n"; errout.str(""); @@ -994,69 +950,58 @@ private: ASSERT_EQUALS("t = ( & p ) ;", tokenizer.tokens()->stringifyList(0, false)); } - void removeCast3() - { + void removeCast3() { // ticket #961 const char code[] = "assert (iplen >= (unsigned) ipv4->ip_hl * 4 + 20);"; const char expected[] = "assert ( iplen >= ipv4 . ip_hl * 4 + 20 ) ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void removeCast4() - { + void removeCast4() { // ticket #970 const char code[] = "if (a >= (unsigned)(b)) {}"; const char expected[] = "if ( a >= ( unsigned int ) b ) { }"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void removeCast5() - { + void removeCast5() { // ticket #1817 ASSERT_EQUALS("a . data = f ;", tokenizeAndStringify("a->data = reinterpret_cast(static_cast(f));", true)); } - void removeCast6() - { + void removeCast6() { // ticket #2103 ASSERT_EQUALS("if ( ! x ) { ; }", tokenizeAndStringify("if (x == (char *) ((void *)0)) ;", true)); } - void removeCast7() - { + void removeCast7() { ASSERT_EQUALS("str = malloc ( 3 )", tokenizeAndStringify("str=(char **)malloc(3)", true)); } - void removeCast8() - { + void removeCast8() { ASSERT_EQUALS("ptr1 = ptr2", tokenizeAndStringify("ptr1=(int * **)ptr2", true)); } - void removeCast9() - { + void removeCast9() { ASSERT_EQUALS("f ( ( double ) ( v1 ) * v2 )", tokenizeAndStringify("f((double)(v1)*v2)", true)); ASSERT_EQUALS("int v1 ; f ( ( double ) v1 * v2 )", tokenizeAndStringify("int v1; f((double)(v1)*v2)", true)); ASSERT_EQUALS("f ( ( A ) ( B ) & x )", tokenizeAndStringify("f((A)(B)&x)", true)); // #4439 } - void removeCast10() - { + void removeCast10() { ASSERT_EQUALS("; ( * f ) ( p ) ;", tokenizeAndStringify("; (*(void (*)(char *))f)(p);", true)); } - void removeCast11() - { + void removeCast11() { ASSERT_EQUALS("; x = 0 ;", tokenizeAndStringify("; *(int *)&x = 0;", true)); } - void removeCast12() - { + void removeCast12() { // #3935 - don't remove this cast ASSERT_EQUALS("; ( ( short * ) data ) [ 5 ] = 0 ;", tokenizeAndStringify("; ((short*)data)[5] = 0;", true)); } - void removeCast13() - { + void removeCast13() { // casting deref / address of ASSERT_EQUALS("; int x ; x = * y ;", tokenizeAndStringify(";int x=(int)*y;",true)); ASSERT_EQUALS("; int x ; x = & y ;", tokenizeAndStringify(";int x=(int)&y;",true)); @@ -1077,28 +1022,24 @@ private: tokenizeAndStringify("; float angle = (float) +tilt;", true)); } - void removeCast14() // const - { + void removeCast14() { // const // #5081 ASSERT_EQUALS("( ! ( & s ) . a )", tokenizeAndStringify("(! ( (struct S const *) &s)->a)", true)); // #5244 ASSERT_EQUALS("bar ( & ptr ) ;", tokenizeAndStringify("bar((const X**)&ptr);",true)); } - void removeCast15() // #5996 - don't remove cast in 'a+static_cast(b?60:0)' - { + void removeCast15() { // #5996 - don't remove cast in 'a+static_cast(b?60:0)' ASSERT_EQUALS("a + ( b ? 60 : 0 ) ;", tokenizeAndStringify("a + static_cast(b ? 60 : 0);", true)); } - void removeCast16() // #6278 - { + void removeCast16() { // #6278 ASSERT_EQUALS("Get ( pArray ) ;", tokenizeAndStringify("Get((CObject*&)pArray);", true)); } - void simplifyFloatCasts() // float casting integers - { + void simplifyFloatCasts() { // float casting integers // C-style casts ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = (float)1;")); ASSERT_EQUALS("a = 1.0f ;", tokenizeAndStringify("a = ((float)1);")); @@ -1113,8 +1054,7 @@ private: ASSERT_EQUALS("a = 291.0 ;", tokenizeAndStringify("a = ((long double)0x123);")); } - void inlineasm() - { + void inlineasm() { ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("asm { mov ax,bx };")); ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm { mov ax,bx };")); ASSERT_EQUALS("asm ( \"mov ax , bx\" ) ;", tokenizeAndStringify("_asm mov ax,bx")); @@ -1133,8 +1073,7 @@ private: } - void pointers_condition() - { + void pointers_condition() { ASSERT_EQUALS("( p )", tokenizeAndStringify("( p != NULL )", true)); ASSERT_EQUALS("( p )", tokenizeAndStringify("( NULL != p )", true)); ASSERT_EQUALS("( this . p )", tokenizeAndStringify("( this->p != NULL )", true)); @@ -1174,8 +1113,7 @@ private: } - void ifAddBraces1() - { + void ifAddBraces1() { const char code[] = "void f()\n" "{\n" " if (a);\n" @@ -1188,8 +1126,7 @@ private: "}", tokenizeAndStringify(code, true)); } - void ifAddBraces2() - { + void ifAddBraces2() { const char code[] = "void f()\n" "{\n" " if (a) if (b) { }\n" @@ -1200,8 +1137,7 @@ private: "}", tokenizeAndStringify(code, true)); } - void ifAddBraces3() - { + void ifAddBraces3() { const char code[] = "void f()\n" "{\n" " if (a) for (;;) { }\n" @@ -1212,8 +1148,7 @@ private: "}", tokenizeAndStringify(code, true)); } - void ifAddBraces4() - { + void ifAddBraces4() { const char code[] = "char * foo ()\n" "{\n" " char *str = malloc(10);\n" @@ -1232,8 +1167,7 @@ private: "}", tokenizeAndStringify(code, true)); } - void ifAddBraces5() - { + void ifAddBraces5() { const char code[] = "void f()\n" "{\n" "for(int i = 0; i < 2; i++)\n" @@ -1252,14 +1186,12 @@ private: "}", tokenizeAndStringify(code, true)); } - void ifAddBraces6() - { + void ifAddBraces6() { const char code[] = "if()"; ASSERT_EQUALS("if ( )", tokenizeAndStringify(code, true)); } - void ifAddBraces7() - { + void ifAddBraces7() { const char code[] = "void f()\n" "{\n" "int a;\n" @@ -1274,8 +1206,7 @@ private: "}", tokenizeAndStringify(code, true)); } - void ifAddBraces9() - { + void ifAddBraces9() { // ticket #990 const char code[] = "void f() {" @@ -1290,31 +1221,27 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void ifAddBraces10() - { + void ifAddBraces10() { // ticket #1361 const char code[] = "{ DEBUG(if (x) y; else z); }"; const char expected[] = "{ DEBUG ( if ( x ) { y ; } else z ) ; }"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void ifAddBraces11() - { + void ifAddBraces11() { const char code[] = "{ if (x) if (y) ; else ; }"; const char expected[] = "{ if ( x ) { if ( y ) { ; } else { ; } } }"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void ifAddBraces12() - { + void ifAddBraces12() { // ticket #1424 const char code[] = "{ if (x) do { } while(x); }"; const char expected[] = "{ if ( x ) { do { } while ( x ) ; } }"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void ifAddBraces13() - { + void ifAddBraces13() { // ticket #1809 const char code[] = "{ if (x) if (y) { } else { } else { } }"; const char expected[] = "{ if ( x ) { if ( y ) { } else { } } else { } }"; @@ -1326,20 +1253,17 @@ private: ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, true)); } - void ifAddBraces14() - { + void ifAddBraces14() { // ticket #2610 (segfault) tokenizeAndStringify("if()<{}", false); } - void ifAddBraces15() - { + void ifAddBraces15() { // ticket #2616 - unknown macro before if ASSERT_EQUALS("{ A if ( x ) { y ( ) ; } }", tokenizeAndStringify("{A if(x)y();}", false)); } - void ifAddBraces16() // ticket # 2739 (segmentation fault) - { + void ifAddBraces16() { // ticket # 2739 (segmentation fault) tokenizeAndStringify("if()x"); ASSERT_EQUALS("", errout.str()); @@ -1353,8 +1277,7 @@ private: } } - void ifAddBraces17() - { + void ifAddBraces17() { const char code[] = "void f()\n" "{\n" " if (a)\n" @@ -1373,8 +1296,7 @@ private: "}", tokenizeAndStringify(code, true)); } - void ifAddBraces18() - { + void ifAddBraces18() { // ticket #3424 - if if { } else else ASSERT_EQUALS("{ if ( x ) { if ( y ) { } else { ; } } else { ; } }", tokenizeAndStringify("{ if(x) if(y){}else;else;}", false)); @@ -1383,8 +1305,7 @@ private: tokenizeAndStringify("{ if(x) if(y) if(z){}else;else;else;}", false)); } - void ifAddBraces19() - { + void ifAddBraces19() { // #3928 - if for if else const char code[] = "void f()\n" "{\n" @@ -1406,20 +1327,17 @@ private: "}", tokenizeAndStringify(code, true)); } - void ifAddBraces20() // #5012 - syntax error 'else }' - { + void ifAddBraces20() { // #5012 - syntax error 'else }' const char code[] = "void f() { if(x) {} else }"; ASSERT_THROW(tokenizeAndStringify(code, true), InternalError); } - void whileAddBraces() - { + void whileAddBraces() { const char code[] = ";while(a);"; ASSERT_EQUALS("; while ( a ) { ; }", tokenizeAndStringify(code, true)); } - void doWhileAddBraces() - { + void doWhileAddBraces() { { const char code[] = "do ; while (0);"; const char result[] = "do { ; } while ( 0 ) ;"; @@ -1478,8 +1396,7 @@ private: } } - void forAddBraces1() - { + void forAddBraces1() { { const char code[] = "void f() {\n" " for(;;)\n" @@ -1511,8 +1428,7 @@ private: } } - void forAddBraces2() // #5088 - { + void forAddBraces2() { // #5088 const char code[] = "void f() {\n" " for(;;) try { } catch (...) { }\n" "}"; @@ -1522,8 +1438,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - std::string simplifyKnownVariables(const char code[]) - { + std::string simplifyKnownVariables(const char code[]) { errout.str(""); Settings settings; @@ -1537,8 +1452,7 @@ private: return tokenizer.tokens()->stringifyList(0, false); } - void simplifyKnownVariables1() - { + void simplifyKnownVariables1() { { const char code[] = "void f()\n" "{\n" @@ -1564,8 +1478,7 @@ private: } } - void simplifyKnownVariables2() - { + void simplifyKnownVariables2() { const char code[] = "void f()\n" "{\n" " int a = 10;\n" @@ -1578,8 +1491,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables3() - { + void simplifyKnownVariables3() { const char code[] = "void f()\n" "{\n" " int a = 4;\n" @@ -1595,8 +1507,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables4() - { + void simplifyKnownVariables4() { const char code[] = "void f()\n" "{\n" " int a = 4;\n" @@ -1609,8 +1520,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables5() - { + void simplifyKnownVariables5() { const char code[] = "void f()\n" "{\n" " int a = 4;\n" @@ -1622,8 +1532,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables6() - { + void simplifyKnownVariables6() { const char code[] = "void f()\n" "{\n" " char str[2];" @@ -1636,8 +1545,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables7() - { + void simplifyKnownVariables7() { const char code[] = "void foo()\n" "{\n" " int i = 22;\n" @@ -1650,8 +1558,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables8() - { + void simplifyKnownVariables8() { const char code[] = "void foo()\n" "{\n" " int i = 22;\n" @@ -1664,8 +1571,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables9() - { + void simplifyKnownVariables9() { const char code[] = "void foo()\n" "{\n" " int a = 1, b = 2;\n" @@ -1678,8 +1584,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables10() - { + void simplifyKnownVariables10() { { const char code[] = "void f()\n" "{\n" @@ -1745,8 +1650,7 @@ private: } } - void simplifyKnownVariables11() - { + void simplifyKnownVariables11() { const char code[] = "const int foo = 0;\n" "int main()\n" "{\n" @@ -1758,8 +1662,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables12() - { + void simplifyKnownVariables12() { const char code[] = "ENTER_NAMESPACE(project_namespace)\n" "const double pi = 3.14;\n" "int main(){}\n"; @@ -1768,8 +1671,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables13() - { + void simplifyKnownVariables13() { const char code[] = "void f()\n" "{\n" " int i = 10;\n" @@ -1781,15 +1683,13 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables14() - { + void simplifyKnownVariables14() { // ticket #753 const char code[] = "void f ( ) { int n ; n = 1 ; do { ++ n ; } while ( n < 10 ) ; }"; ASSERT_EQUALS(code, simplifyKnownVariables(code)); } - void simplifyKnownVariables15() - { + void simplifyKnownVariables15() { { const char code[] = "int main()\n" "{\n" @@ -1815,15 +1715,13 @@ private: } } - void simplifyKnownVariables16() - { + void simplifyKnownVariables16() { // ticket #807 - segmentation fault when macro isn't found const char code[] = "void f ( ) { int n = 1; DISPATCH(while); }"; ASSERT_THROW(simplifyKnownVariables(code), InternalError); } - void simplifyKnownVariables17() - { + void simplifyKnownVariables17() { // ticket #807 - segmentation fault when macro isn't found const char code[] = "void f ( ) { char *s = malloc(100);mp_ptr p = s; p++; }"; ASSERT_EQUALS( @@ -1831,24 +1729,21 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables18() - { + void simplifyKnownVariables18() { const char code[] = "void f ( ) { char *s = malloc(100);mp_ptr p = s; ++p; }"; ASSERT_EQUALS( "void f ( ) { char * s ; s = malloc ( 100 ) ; mp_ptr p ; p = s ; ++ p ; }", simplifyKnownVariables(code)); } - void simplifyKnownVariables19() - { + void simplifyKnownVariables19() { const char code[] = "void f ( ) { int i=0; do { if (i>0) { a(); } i=b(); } while (i != 12); }"; ASSERT_EQUALS( "void f ( ) { int i ; i = 0 ; do { if ( i > 0 ) { a ( ) ; } i = b ( ) ; } while ( i != 12 ) ; }", simplifyKnownVariables(code)); } - void simplifyKnownVariables20() - { + void simplifyKnownVariables20() { const char code[] = "void f()\n" "{\n" " int i = 0;\n" @@ -1862,8 +1757,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables21() - { + void simplifyKnownVariables21() { const char code[] = "void foo() { int n = 10; for (int i = 0; i < n; ++i) { } }"; ASSERT_EQUALS( @@ -1871,8 +1765,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables22() - { + void simplifyKnownVariables22() { // This testcase is related to ticket #1169 { const char code[] = "void foo()\n" @@ -1920,8 +1813,7 @@ private: } } - void simplifyKnownVariables23() - { + void simplifyKnownVariables23() { // This testcase is related to ticket #1596 const char code[] = "void foo(int x)\n" "{\n" @@ -1952,8 +1844,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables25() - { + void simplifyKnownVariables25() { { // This testcase is related to ticket #1646 const char code[] = "void foo(char *str)\n" @@ -2005,8 +1896,7 @@ private: } } - void simplifyKnownVariables27() - { + void simplifyKnownVariables27() { // This testcase is related to ticket #1633 const char code[] = "void foo()\n" "{\n" @@ -2024,8 +1914,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables28() - { + void simplifyKnownVariables28() { const char code[] = "void foo(int g)\n" "{\n" " int i = 2;\n" @@ -2044,8 +1933,7 @@ private: simplifyKnownVariables(code)); } - void simplifyKnownVariables29() // ticket #1811 - { + void simplifyKnownVariables29() { // ticket #1811 { const char code[] = "int foo(int u, int v)\n" "{\n" @@ -2355,8 +2243,7 @@ private: } } - void simplifyKnownVariables30() - { + void simplifyKnownVariables30() { const char code[] = "int foo() {\n" " iterator it1 = ints.begin();\n" " iterator it2 = it1;\n" @@ -2370,8 +2257,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables31() - { + void simplifyKnownVariables31() { const char code[] = "void foo(const char str[]) {\n" " const char *p = str;\n" " if (p[0] == 0) {\n" @@ -2385,8 +2271,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables32() - { + void simplifyKnownVariables32() { { const char code[] = "void foo() {\n" " const int x = 0;\n" @@ -2402,8 +2287,7 @@ private: } } - void simplifyKnownVariables33() - { + void simplifyKnownVariables33() { const char code[] = "static void foo(struct Foo *foo) {\n" " foo->a = 23;\n" " x[foo->a] = 0;\n" @@ -2415,8 +2299,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables34() - { + void simplifyKnownVariables34() { const char code[] = "void f() {\n" " int x = 10;\n" " do { cin >> x; } while (x > 5);\n" @@ -2430,8 +2313,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables35() - { + void simplifyKnownVariables35() { // Ticket #2353 const char code[] = "int f() {" " int x = 0;" @@ -2444,8 +2326,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables36() - { + void simplifyKnownVariables36() { // Ticket #2304 const char code[] = "void f() {" " const char *q = \"hello\";" @@ -2463,8 +2344,7 @@ private: ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, true)); } - void simplifyKnownVariables37() - { + void simplifyKnownVariables37() { // Ticket #2398 - no simplification in for loop const char code[] = "void f() {\n" " double x = 0;\n" @@ -2485,8 +2365,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables38() - { + void simplifyKnownVariables38() { // Ticket #2399 - simplify conditions const char code[] = "void f() {\n" " int x = 0;\n" @@ -2501,8 +2380,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables39() - { + void simplifyKnownVariables39() { // Ticket #2296 - simplify pointer alias 'delete p;' { const char code[] = "void f() {\n" @@ -2523,8 +2401,7 @@ private: } - void simplifyKnownVariables40() - { + void simplifyKnownVariables40() { const char code[] = "void f() {\n" " char c1 = 'a';\n" " char c2 = { c1 };\n" @@ -2532,8 +2409,7 @@ private: ASSERT_EQUALS("void f ( ) {\n\nchar c2 ; c2 = { 'a' } ;\n}", tokenizeAndStringify(code, true)); } - void simplifyKnownVariables41() - { + void simplifyKnownVariables41() { const char code[] = "void f() {\n" " int x = 0;\n" " const int *p; p = &x;\n" @@ -2542,8 +2418,7 @@ private: ASSERT_EQUALS("void f ( ) {\nint x ; x = 0 ;\nconst int * p ; p = & x ;\nif ( & x ) { return 0 ; }\n}", tokenizeAndStringify(code, true)); } - void simplifyKnownVariables42() - { + void simplifyKnownVariables42() { { const char code[] = "void f() {\n" " char str1[10], str2[10];\n" @@ -2600,8 +2475,7 @@ private: } } - void simplifyKnownVariables43() - { + void simplifyKnownVariables43() { { const char code[] = "void f() {\n" " int a, *p; p = &a;\n" @@ -2627,8 +2501,7 @@ private: } } - void simplifyKnownVariables44() - { + void simplifyKnownVariables44() { const char code[] = "void a() {\n" " static int i = 10;\n" " b(i++);\n" @@ -2640,8 +2513,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables45() - { + void simplifyKnownVariables45() { const char code[] = "class Fred {\n" "private:\n" " const static int NUM = 2;\n" @@ -2655,8 +2527,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariables46() - { + void simplifyKnownVariables46() { const char code[] = "void f() {\n" " int x = 0;\n" " cin >> x;\n" @@ -2682,8 +2553,7 @@ private: } } - void simplifyKnownVariables47() - { + void simplifyKnownVariables47() { // #3621 const char code[] = "void f() {\n" " int x = 0;\n" @@ -2696,8 +2566,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.cpp")); } - void simplifyKnownVariables48() - { + void simplifyKnownVariables48() { // #3754 const char code[] = "void f(int sz) {\n" " int i;\n" @@ -2710,8 +2579,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.c")); } - void simplifyKnownVariables49() // #3691 - { + void simplifyKnownVariables49() { // #3691 const char code[] = "void f(int sz) {\n" " switch (x) {\n" " case 1: sz = 2; continue;\n" @@ -2727,8 +2595,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.c")); } - void simplifyKnownVariables50() // #4066 - { + void simplifyKnownVariables50() { // #4066 { const char code[] = "void f() {\n" " char str1[10], str2[10];\n" @@ -2790,8 +2657,7 @@ private: } } - void simplifyKnownVariables51() // #4409 hang - { + void simplifyKnownVariables51() { // #4409 hang const char code[] = "void mhz_M(int enough) {\n" " TYPE *x=&x, **p=x, **q = NULL;\n" " BENCH1(q = _mhz_M(n); n = 1;)\n" @@ -2800,8 +2666,7 @@ private: tokenizeAndStringify(code, true); // don't hang } - void simplifyKnownVariables52() // #4728 "= x %op%" - { + void simplifyKnownVariables52() { // #4728 "= x %op%" ASSERT_EQUALS("void f ( ) { int y ; y = 34 + z ; }", tokenizeAndStringify("void f() { int x=34; int y=x+z; }", true)); ASSERT_EQUALS("void f ( ) { int y ; y = 34 - z ; }", tokenizeAndStringify("void f() { int x=34; int y=x-z; }", true)); ASSERT_EQUALS("void f ( ) { int y ; y = 34 * z ; }", tokenizeAndStringify("void f() { int x=34; int y=x*z; }", true)); @@ -2826,38 +2691,32 @@ private: ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { Foo *p = 0; bool b = (p && (p->type() == 1)); }", true)); } - void simplifyKnownVariables53() // references - { + void simplifyKnownVariables53() { // references ASSERT_EQUALS("void f ( ) { int x ; x = abc ( ) ; }", tokenizeAndStringify("void f() { int x; int &ref=x; ref=abc(); }", true)); ASSERT_EQUALS("void f ( ) { int * p ; p = abc ( ) ; }", tokenizeAndStringify("void f() { int *p; int *&ref=p; ref=abc(); }", true)); } - void simplifyKnownVariables54() // #4913 - { + void simplifyKnownVariables54() { // #4913 ASSERT_EQUALS("void f ( int * p ) { * -- p = 0 ; * p = 0 ; }", tokenizeAndStringify("void f(int*p) { *--p=0; *p=0; }", true)); } - void simplifyKnownVariables55() // pointer alias - { + void simplifyKnownVariables55() { // pointer alias ASSERT_EQUALS("void f ( ) { int a ; if ( a > 0 ) { } }", tokenizeAndStringify("void f() { int a; int *p=&a; if (*p>0) {} }", true)); ASSERT_EQUALS("void f ( ) { int a ; struct AB ab ; ab . a = & a ; if ( a > 0 ) { } }", tokenizeAndStringify("void f() { int a; struct AB ab; ab.a = &a; if (*ab.a>0) {} }", true)); ASSERT_EQUALS("void f ( ) { int a ; if ( x > a ) { } }", tokenizeAndStringify("void f() { int a; int *p=&a; if (x>*p) {} }", true)); } - void simplifyKnownVariables56() // ticket #5301 - >> - { + void simplifyKnownVariables56() { // ticket #5301 - >> ASSERT_EQUALS("void f ( ) { int a ; a = 0 ; int b ; b = 0 ; * p >> a >> b ; return a / b ; }", tokenizeAndStringify("void f() { int a=0,b=0; *p>>a>>b; return a/b; }", true)); } - void simplifyKnownVariables57() // #4724 - { + void simplifyKnownVariables57() { // #4724 ASSERT_EQUALS("unsigned long long x ; x = 9223372036854775808 ;", tokenizeAndStringify("unsigned long long x = 1UL << 63 ;", true)); ASSERT_EQUALS("long long x ; x = -9223372036854775808 ;", tokenizeAndStringify("long long x = 1L << 63 ;", true)); } - void simplifyKnownVariables58() // #5268 - { + void simplifyKnownVariables58() { // #5268 const char code[] = "enum e { VAL1 = 1, VAL2 }; " "typedef char arr_t[VAL2]; " "int foo(int) ; " @@ -2872,8 +2731,7 @@ private: "int baz ( ) { return 2 ; }", tokenizeAndStringify(code, true)); } - void simplifyKnownVariables59() // #5062 - for head - { + void simplifyKnownVariables59() { // #5062 - for head const char code[] = "void f() {\n" " int a[3], i, j;\n" " for(i = 0, j = 1; i < 3, j < 12; i++,j++) {\n" @@ -2888,8 +2746,7 @@ private: "}", tokenizeAndStringify(code, true)); } - void simplifyKnownVariablesIfEq1() - { + void simplifyKnownVariablesIfEq1() { const char code[] = "void f(int x) {\n" " if (x==5) {\n" " return x;\n" @@ -2903,8 +2760,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.c")); } - void simplifyKnownVariablesIfEq2() - { + void simplifyKnownVariablesIfEq2() { const char code[] = "void f(int x) {\n" " if (x==5) {\n" " buf[x++] = 0;\n" @@ -2921,8 +2777,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.c")); } - void simplifyKnownVariablesIfEq3() - { + void simplifyKnownVariablesIfEq3() { const char code[] = "void f(int x) {\n" " if (x==5) {\n" " buf[++x] = 0;\n" @@ -2941,8 +2796,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unspecified, "test.c")); } - void simplifyKnownVariablesBailOutAssign1() - { + void simplifyKnownVariablesBailOutAssign1() { const char code[] = "int foo() {\n" " int i; i = 0;\n" " if (x) { i = 10; }\n" @@ -2956,8 +2810,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariablesBailOutAssign2() - { + void simplifyKnownVariablesBailOutAssign2() { // ticket #3032 - assignment in condition const char code[] = "void f(struct ABC *list) {\n" " struct ABC *last = NULL;\n" @@ -2970,8 +2823,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariablesBailOutAssign3() // #4395 - nested assignments - { + void simplifyKnownVariablesBailOutAssign3() { // #4395 - nested assignments const char code[] = "void f() {\n" " int *p = 0;\n" " a = p = (VdbeCursor*)pMem->z;\n" @@ -2985,8 +2837,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariablesBailOutFor1() - { + void simplifyKnownVariablesBailOutFor1() { const char code[] = "void foo() {\n" " for (int i = 0; i < 10; ++i) { }\n" "}\n"; @@ -2997,8 +2848,7 @@ private: ASSERT_EQUALS("", errout.str()); // debug warnings } - void simplifyKnownVariablesBailOutFor2() - { + void simplifyKnownVariablesBailOutFor2() { const char code[] = "void foo() {\n" " int i = 0;\n" " while (i < 10) { ++i; }\n" @@ -3011,8 +2861,7 @@ private: ASSERT_EQUALS("", errout.str()); // debug warnings } - void simplifyKnownVariablesBailOutFor3() - { + void simplifyKnownVariablesBailOutFor3() { const char code[] = "void foo() {\n" " for (std::string::size_type pos = 0; pos < 10; ++pos)\n" " { }\n" @@ -3025,8 +2874,7 @@ private: ASSERT_EQUALS("", errout.str()); // debug warnings } - void simplifyKnownVariablesBailOutMemberFunction() - { + void simplifyKnownVariablesBailOutMemberFunction() { const char code[] = "void foo(obj a) {\n" " obj b = a;\n" " b.f();\n" @@ -3038,8 +2886,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true)); } - void simplifyKnownVariablesBailOutConditionalIncrement() - { + void simplifyKnownVariablesBailOutConditionalIncrement() { const char code[] = "int f() {\n" " int a = 0;\n" " if (x) {\n" @@ -3051,8 +2898,7 @@ private: ASSERT_EQUALS("", errout.str()); // no debug warnings } - void simplifyKnownVariablesBailOutSwitchBreak() - { + void simplifyKnownVariablesBailOutSwitchBreak() { // Ticket #2324 const char code[] = "int f(char *x) {\n" " char *p;\n" @@ -3091,8 +2937,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code,true)); } - void simplifyKnownVariablesFloat() - { + void simplifyKnownVariablesFloat() { // Ticket #2454 const char code[] = "void f() {\n" " float a = 40;\n" @@ -3124,8 +2969,7 @@ private: ASSERT_EQUALS("void f ( ) {\nstd :: cout << 1.0 ;\n}", tokenizeAndStringify(code4,true)); } - void simplifyKnownVariablesFunctionCalls() - { + void simplifyKnownVariablesFunctionCalls() { { const char code[] = "void a(int x);" // <- x is passed by value "void b() {" @@ -3147,8 +2991,7 @@ private: } } - void simplifyKnownVariablesReturn() - { + void simplifyKnownVariablesReturn() { const char code[] = "int a() {" " int x = 123;" " return (x);" @@ -3156,8 +2999,7 @@ private: ASSERT_EQUALS("int a ( ) { return 123 ; }", tokenizeAndStringify(code,true)); } - void simplifyKnownVariablesClassMember() - { + void simplifyKnownVariablesClassMember() { // Ticket #2815 { const char code[] = "char *a;\n" @@ -3184,15 +3026,13 @@ private: } } - void simplifyExternC() - { + void simplifyExternC() { ASSERT_EQUALS("int foo ( ) ;", tokenizeAndStringify("extern \"C\" int foo();")); ASSERT_EQUALS("int foo ( ) ;", tokenizeAndStringify("extern \"C\" { int foo(); }")); } - std::string tokenizeDebugListing(const char code[], bool simplify = false, const char filename[] = "test.cpp") - { + std::string tokenizeDebugListing(const char code[], bool simplify = false, const char filename[] = "test.cpp") { errout.str(""); Settings settings; @@ -3210,8 +3050,7 @@ private: return tokenizer.tokens()->stringifyList(true); } - void file1() - { + void file1() { const char code[] = "a1\n" "#file \"b\"\n" "b1\n" @@ -3236,8 +3075,7 @@ private: } - void file2() - { + void file2() { const char code[] = "a1\n" "#file \"b\"\n" "b1\n" @@ -3272,8 +3110,7 @@ private: - void file3() - { + void file3() { const char code[] = "#file \"c:\\a.h\"\n" "123\n" "#endfile\n"; @@ -3291,8 +3128,7 @@ private: } - void line1() const - { + void line1() const { // Test for Ticket #4408 const char code[] = "#file \"c:\\a.h\"\n" "first\n" @@ -3328,8 +3164,7 @@ private: } } - void line2() - { + void line2() { const char code[] = "#line 8 \"c:\\a.h\"\n" "123\n"; @@ -3347,8 +3182,7 @@ private: - void doublesharp() - { + void doublesharp() { const char code[] = "a##_##b TEST(var,val) var##_##val = val\n"; errout.str(""); @@ -3363,8 +3197,7 @@ private: ASSERT_EQUALS("a_b TEST ( var , val ) var_val = val", tokenizer.tokens()->stringifyList(0, false)); } - void macrodoublesharp() - { + void macrodoublesharp() { const char code[] = "DBG(fmt,args...) printf(fmt, ## args)\n"; errout.str(""); @@ -3379,8 +3212,7 @@ private: ASSERT_EQUALS("DBG ( fmt , args . . . ) printf ( fmt , ## args )", tokenizer.tokens()->stringifyList(0, false)); } - void simplifyFunctionParameters() - { + void simplifyFunctionParameters() { { const char code[] = "char a [ ABC ( DEF ) ] ;"; ASSERT_EQUALS(code, tokenizeAndStringify(code)); @@ -3424,8 +3256,7 @@ private: } } - void simplifyFunctionParameters1() // ticket #3721 - { + void simplifyFunctionParameters1() { // ticket #3721 const char code[] = "typedef float ufloat;\n" "typedef short ftnlen;\n" @@ -3437,8 +3268,7 @@ private: "}", tokenizeAndStringify(code)); } - void simplifyFunctionParameters2() // #4430 - { + void simplifyFunctionParameters2() { // #4430 const char code[] = "class Item { " "int i ; " "public: " @@ -3448,8 +3278,7 @@ private: ASSERT_EQUALS(code, tokenizeAndStringify(code)); } - void simplifyFunctionParameters3() // #4436 - { + void simplifyFunctionParameters3() { // #4436 const char code[] = "class Item { " "int i ; " "int j ; " @@ -3460,8 +3289,7 @@ private: ASSERT_EQUALS(code, tokenizeAndStringify(code)); } - void simplifyFunctionParametersErrors() - { + void simplifyFunctionParametersErrors() { //same parameters... ASSERT_THROW(tokenizeAndStringify("void foo(x, x)\n" " int x;\n" @@ -3489,8 +3317,7 @@ private: } // Simplify "((..))" into "(..)" - void removeParentheses1() - { + void removeParentheses1() { const char code[] = "void foo()" "{" " free(((void*)p));" @@ -3499,8 +3326,7 @@ private: ASSERT_EQUALS("void foo ( ) { free ( p ) ; }", tokenizeAndStringify(code, true)); } - void removeParentheses2() - { + void removeParentheses2() { const char code[] = "void foo()" "{" " if (__builtin_expect((s == NULL), 0))" @@ -3510,8 +3336,7 @@ private: ASSERT_EQUALS("void foo ( ) { if ( ! s ) { return ; } }", tokenizeAndStringify(code)); } - void removeParentheses3() - { + void removeParentheses3() { { const char code[] = "void foo()" "{" @@ -3538,8 +3363,7 @@ private: } // Simplify "( function (..))" into "function (..)" - void removeParentheses4() - { + void removeParentheses4() { const char code[] = "void foo()" "{" " (free(p));" @@ -3547,8 +3371,7 @@ private: ASSERT_EQUALS("void foo ( ) { free ( p ) ; }", tokenizeAndStringify(code)); } - void removeParentheses5() - { + void removeParentheses5() { // Simplify "( delete x )" into "delete x" { const char code[] = "void foo()" @@ -3569,8 +3392,7 @@ private: } // "!(abc.a)" => "!abc.a" - void removeParentheses6() - { + void removeParentheses6() { { const char code[] = "(!(abc.a))"; ASSERT_EQUALS("( ! abc . a )", tokenizeAndStringify(code)); @@ -3582,14 +3404,12 @@ private: } } - void removeParentheses7() - { + void removeParentheses7() { const char code[] = ";char *p; (delete(p), (p)=0);"; ASSERT_EQUALS("; char * p ; delete p ; p = 0 ;", tokenizeAndStringify(code,true)); } - void removeParentheses8() - { + void removeParentheses8() { const char code[] = "struct foo {\n" " void operator delete(void *obj, size_t sz);\n" "}\n"; @@ -3602,41 +3422,34 @@ private: ASSERT_EQUALS(expected, actual); } - void removeParentheses9() - { + void removeParentheses9() { ASSERT_EQUALS("void delete ( double num ) ;", tokenizeAndStringify("void delete(double num);", false)); } - void removeParentheses10() - { + void removeParentheses10() { ASSERT_EQUALS("p = buf + 8 ;", tokenizeAndStringify("p = (buf + 8);", false)); } - void removeParentheses11() - { + void removeParentheses11() { // #2502 ASSERT_EQUALS("{ } x ( ) ;", tokenizeAndStringify("{}(x());", false)); } - void removeParentheses12() - { + void removeParentheses12() { // #2760 ASSERT_EQUALS(", x = 0 ;", tokenizeAndStringify(",(x)=0;", false)); } - void removeParentheses13() - { + void removeParentheses13() { ASSERT_EQUALS("; f ( a + b , c ) ;", tokenizeAndStringify(";f((a+b),c);", false)); ASSERT_EQUALS("; x = y [ a + b ] ;", tokenizeAndStringify(";x=y[(a+b)];", false)); } - void removeParentheses14() - { + void removeParentheses14() { ASSERT_EQUALS("; if ( ! ( i & 1 ) ) { ; } ;", tokenizeAndStringify("; if ( (i & 1) == 0 ); ;", false)); } - void removeParentheses15() - { + void removeParentheses15() { ASSERT_EQUALS("a = b ? c : 123 ;", tokenizeAndStringify("a = b ? c : (123);", false)); ASSERT_EQUALS("a = b ? c : ( 579 ) ;", tokenizeAndStringify("a = b ? c : ((123)+(456));", false)); ASSERT_EQUALS("a = b ? 123 : c ;", tokenizeAndStringify("a = b ? (123) : c;", false)); @@ -3645,40 +3458,33 @@ private: ASSERT_EQUALS("a = b ? c : ( d = 1 , 0 ) ;", tokenizeAndStringify("a = b ? c : (d=1,0);", false)); } - void removeParentheses16() // *(x.y)= - { + void removeParentheses16() { // *(x.y)= // #4423 ASSERT_EQUALS("* x = 0 ;", tokenizeAndStringify("*(x)=0;", false)); ASSERT_EQUALS("* x . y = 0 ;", tokenizeAndStringify("*(x.y)=0;", false)); } - void removeParentheses17() // a ? b : (c > 0 ? d : e) - { + void removeParentheses17() { // a ? b : (c > 0 ? d : e) ASSERT_EQUALS("a ? b : ( c > 0 ? d : e ) ;", tokenizeAndStringify("a?b:(c>0?d:e);", false)); } - void removeParentheses18() - { + void removeParentheses18() { ASSERT_EQUALS("float * a [ 2 ] ;", tokenizeAndStringify("float(*a)[2];", false)); } - void removeParentheses19() - { + void removeParentheses19() { ASSERT_EQUALS("( ( ( typeof ( X ) ) * ) 0 )", tokenizeAndStringify("(((typeof(X))*)0)", false)); } - void removeParentheses20() - { + void removeParentheses20() { ASSERT_EQUALS("a < b < int > > ( 2 ) ;", tokenizeAndStringify("a>(2);", false)); } - void removeParentheses21() - { + void removeParentheses21() { ASSERT_EQUALS("a = ( int ) - b ;", tokenizeAndStringify("a = ((int)-b);", false)); } - void removeParentheses22() - { + void removeParentheses22() { static char code[] = "struct S { " "char *(a); " "char &(b); " @@ -3692,8 +3498,7 @@ private: ASSERT_EQUALS(exp, tokenizeAndStringify(code)); } - void removeParentheses23() // Ticket #6103 - { + void removeParentheses23() { // Ticket #6103 // Reported case { static char code[] = "* * p f ( ) int = { new int ( * [ 2 ] ) ; void }"; @@ -3724,8 +3529,7 @@ private: } } - void tokenize_double() - { + void tokenize_double() { const char code[] = "void f()\n" "{\n" " double a = 4.2;\n" @@ -3747,8 +3551,7 @@ private: ASSERT_EQUALS("void f ( ) { double a ; a = 4.2 ; float b ; b = 4.2f ; double c ; c = 4.2e+10 ; double d ; d = 4.2e-10 ; int e ; e = 6 ; }", tokenizer.tokens()->stringifyList(0, false)); } - void tokenize_strings() - { + void tokenize_strings() { const char code[] = "void f()\n" "{\n" "const char *a =\n" @@ -3772,8 +3575,7 @@ private: ASSERT_EQUALS("void f ( ) { const char * a ; a = { \"hello more world\" } ; }", tokenizer.tokens()->stringifyList(0, false)); } - void simplify_constants() - { + void simplify_constants() { const char code[] = "void f()\n" "{\n" @@ -3800,8 +3602,7 @@ private: ASSERT_EQUALS("void f ( ) { } void g ( ) { }", tokenizer.tokens()->stringifyList(0, false)); } - void simplify_constants2() - { + void simplify_constants2() { const char code[] = "void f( Foo &foo, Foo *foo2 )\n" "{\n" @@ -3824,8 +3625,7 @@ private: ASSERT_EQUALS("void f ( Foo & foo , Foo * foo2 ) { foo . a = 90 ; foo2 . a = 45 ; }", tokenizer.tokens()->stringifyList(0, false)); } - void simplify_constants3() - { + void simplify_constants3() { const char code[] = "static const char str[] = \"abcd\";\n" "static const unsigned int SZ = sizeof(str);\n" @@ -3837,8 +3637,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code,true)); } - void simplify_constants4() - { + void simplify_constants4() { const char code[] = "static const int bSize = 4;\n" "static const int aSize = 50;\n" "x = bSize;\n" @@ -3846,8 +3645,7 @@ private: ASSERT_EQUALS("x = 4 ;\ny = 50 ;", tokenizeAndStringify(code,true)); } - void simplify_constants5() - { + void simplify_constants5() { const char code[] = "int buffer[10];\n" "static const int NELEMS = sizeof(buffer)/sizeof(int);\n" "static const int NELEMS2(sizeof(buffer)/sizeof(int));\n" @@ -3856,8 +3654,7 @@ private: ASSERT_EQUALS("int buffer [ 10 ] ;\n\n\nx = 10 ;\ny = 10 ;", tokenizeAndStringify(code,true)); } - void simplify_constants6() // Ticket #5625 - { + void simplify_constants6() { // Ticket #5625 { const char code[] = "template < class T > struct foo ;\n" "void bar ( ) {\n" @@ -3878,8 +3675,7 @@ private: } } - void simplify_null() - { + void simplify_null() { { const char code[] = "int * p = NULL;\n" @@ -3893,8 +3689,7 @@ private: ASSERT_EQUALS("( ! a )", tokenizeAndStringify("(a==nullptr)", false, false, Settings::Unspecified, "test.cpp")); } - void simplifyMulAndParens() - { + void simplifyMulAndParens() { // (error) Resource leak const char code[] = "void f() {" " *&n1=open();" @@ -3933,14 +3728,12 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } - void simplifyStructDecl() - { + void simplifyStructDecl() { const char code[] = "const struct A { int a; int b; } a;"; ASSERT_EQUALS("struct A { int a ; int b ; } ; const struct A a ;", tokenizeAndStringify(code)); } - void vardecl1() - { + void vardecl1() { const char code[] = "unsigned int a, b;"; const std::string actual(tokenizeAndStringify(code)); @@ -3948,8 +3741,7 @@ private: ASSERT_EQUALS("unsigned int a ; unsigned int b ;", actual); } - void vardecl2() - { + void vardecl2() { const char code[] = "void foo(a,b) unsigned int a, b; { }"; const std::string actual(tokenizeAndStringify(code)); @@ -3957,15 +3749,13 @@ private: ASSERT_EQUALS("void foo ( unsigned int a , unsigned int b ) { }", actual); } - void vardecl3() - { + void vardecl3() { const char code[] = "void f() { char * p = foo<10,char>(); }"; const std::string actual(tokenizeAndStringify(code)); ASSERT_EQUALS("void f ( ) { char * p ; p = foo < 10 , char > ( ) ; }", actual); } - void vardecl4() - { + void vardecl4() { // ticket #346 const char code1[] = "void *p = NULL;"; @@ -3985,8 +3775,7 @@ private: ASSERT_EQUALS(res4, tokenizeAndStringify(code4)); } - void vardecl_stl_1() - { + void vardecl_stl_1() { // ticket #520 const char code1[] = "std::vectora, b;"; @@ -4002,8 +3791,7 @@ private: ASSERT_EQUALS(res3, tokenizeAndStringify(code3)); } - void vardecl_stl_2() - { + void vardecl_stl_2() { const char code1[] = "{ std::string x = \"abc\"; }"; ASSERT_EQUALS("{ std :: string x ; x = \"abc\" ; }", tokenizeAndStringify(code1)); @@ -4011,8 +3799,7 @@ private: ASSERT_EQUALS("{ std :: vector < int > x ; x = y ; }", tokenizeAndStringify(code2)); } - void vardecl_template_1() - { + void vardecl_template_1() { // ticket #1046 const char code1[] = "b<(1<<24),10,24> u, v;"; const char res1[] = "b < 16777216 , 10 , 24 > u ; b < 16777216 , 10 , 24 > v ;"; @@ -4021,16 +3808,14 @@ private: tokenizeAndStringify("template 4) > class X4 {};"); } - void vardecl_template_2() - { + void vardecl_template_2() { // ticket #3650 const char code[] = "const string str = x<8,int>();"; const char expected[] = "const string str = x < 8 , int > ( ) ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } - void vardecl_union() - { + void vardecl_union() { // ticket #1976 const char code1[] = "class Fred { public: union { int a ; int b ; } ; } ;"; ASSERT_EQUALS(code1, tokenizeAndStringify(code1)); @@ -4049,8 +3834,7 @@ private: ASSERT_EQUALS("union xy * p ; p = 0 ;", tokenizeAndStringify(code3)); } - void vardecl_par() - { + void vardecl_par() { // ticket #2743 - set links if variable type contains parentheses const char code[] = "Fred fred1=a, fred2=b;"; @@ -4061,8 +3845,7 @@ private: tokenizer.validate(); } - void vardecl_par2() - { + void vardecl_par2() { // ticket #3912 - set correct links const char code[] = "function)> v;"; @@ -4073,8 +3856,7 @@ private: tokenizer.validate(); } - void vardec_static() - { + void vardec_static() { { // don't simplify declarations of static variables // "static int i = 0;" is not the same as "static int i; i = 0;" @@ -4149,8 +3931,7 @@ private: } } - void vardecl6() - { + void vardecl6() { // ticket #565 const char code1[] = "int z = x >> 16;"; @@ -4158,8 +3939,7 @@ private: ASSERT_EQUALS(res1, tokenizeAndStringify(code1)); } - void vardecl7() - { + void vardecl7() { // ticket #603 const char code[] = "void f() {\n" " for (int c = 0; c < 0; ++c) {}\n" @@ -4175,8 +3955,7 @@ private: ASSERT_EQUALS(res, tokenizeAndStringify(code)); } - void vardecl8() - { + void vardecl8() { // ticket #696 const char code[] = "char a[10]={'\\0'}, b[10]={'\\0'};"; const char res[] = "char a [ 10 ] = { 0 } ; char b [ 10 ] = { 0 } ;"; @@ -4184,56 +3963,48 @@ private: ASSERT_EQUALS(res, tokenizeAndStringify(code)); } - void vardecl9() - { + void vardecl9() { const char code[] = "char a[2] = {'A', '\\0'}, b[2] = {'B', '\\0'};"; const char res[] = "char a [ 2 ] = { 'A' , 0 } ; char b [ 2 ] = { 'B' , 0 } ;"; ASSERT_EQUALS(res, tokenizeAndStringify(code)); } - void vardecl10() - { + void vardecl10() { // ticket #732 const char code[] = "char a [ 2 ] = { '-' } ; memset ( a , '-' , sizeof ( a ) ) ;"; ASSERT_EQUALS(code, tokenizeAndStringify(code)); } - void vardecl11() - { + void vardecl11() { // ticket #1684 const char code[] = "char a[5][8], b[5][8];"; ASSERT_EQUALS("char a [ 5 ] [ 8 ] ; char b [ 5 ] [ 8 ] ;", tokenizeAndStringify(code)); } - void vardecl12() - { + void vardecl12() { const char code[] = "struct A { public: B a, b, c, d; };"; ASSERT_EQUALS("struct A { public: B a ; B b ; B c ; B d ; } ;", tokenizeAndStringify(code)); } - void vardecl13() - { + void vardecl13() { const char code[] = "void f() {\n" " int a = (x < y) ? 1 : 0;\n" "}"; ASSERT_EQUALS("void f ( ) {\nint a ; a = ( x < y ) ? 1 : 0 ;\n}", tokenizeAndStringify(code)); } - void vardecl14() - { + void vardecl14() { const char code[] = "::std::tr1::shared_ptr pNum1, pNum2;\n"; ASSERT_EQUALS(":: std :: tr1 :: shared_ptr < int > pNum1 ; :: std :: tr1 :: shared_ptr < int > pNum2 ;", tokenizeAndStringify(code, false, false, Settings::Unspecified, "test.cpp", false)); } - void vardecl15() - { + void vardecl15() { const char code[] = "const char x[] = \"foo\", y[] = \"bar\";\n"; ASSERT_EQUALS("const char x [ 4 ] = \"foo\" ; const char y [ 4 ] = \"bar\" ;", tokenizeAndStringify(code)); } - void vardecl16() - { + void vardecl16() { { const char code[] = "const a::b::g::h::l *x [] = foo(),y [][] = bar();\n"; ASSERT_EQUALS("const a :: b < c , d ( e ) , f > :: g :: h < i > :: l * x [ ] = foo ( ) ; " @@ -4247,15 +4018,13 @@ private: } } - void vardecl17() - { + void vardecl17() { const char code[] = "a < b > :: c :: d :: e < f > x = foo(), y = bar();\n"; ASSERT_EQUALS("a < b > :: c :: d :: e < f > x ; x = foo ( ) ; " "a < b > :: c :: d :: e < f > y ; y = bar ( ) ;", tokenizeAndStringify(code)); } - void vardecl18() - { + void vardecl18() { const char code[] = "void f() {\n" " g((double)v1*v2, v3, v4);\n" "}\n"; @@ -4265,8 +4034,7 @@ private: "}", tokenizeAndStringify(code)); } - void vardecl19() - { + void vardecl19() { { const char code[] = "void func(in, r, m)\n" "int in;" @@ -4355,8 +4123,7 @@ private: } } - void vardecl20() - { + void vardecl20() { // #3700 const char code[] = "void a::b() const\n" "{\n" @@ -4368,8 +4135,7 @@ private: "}", tokenizeAndStringify(code)); } - void vardecl21() // type in namespace - { + void vardecl21() { // type in namespace // #4042 - a::b const *p = 0; const char code1[] = "void f() {\n" " a::b const *p = 0;\n" @@ -4389,18 +4155,15 @@ private: , tokenizeAndStringify(code2)); } - void vardecl22() // #4211 - segmentation fault - { + void vardecl22() { // #4211 - segmentation fault tokenizeAndStringify("A> >* p = 0;"); } - void vardecl23() // #4276 - segmentation fault - { + void vardecl23() { // #4276 - segmentation fault tokenizeAndStringify("class a { protected : template < class int x = 1 ; public : int f ( ) ; }"); } - void vardecl24() // #4187 - variable declaration within lambda function - { + void vardecl24() { // #4187 - variable declaration within lambda function const char code1[] = "void f() {\n" " std::for_each(ints.begin(), ints.end(), [](int val)\n" " {\n" @@ -4428,24 +4191,21 @@ private: ASSERT_EQUALS(expected2, tokenizeAndStringify(code2)); } - void vardecl25() // #4799 - segmentation fault - { + void vardecl25() { // #4799 - segmentation fault tokenizeAndStringify("void A::func(P g) const {}\n" "void A::a() {\n" " b = new d( [this]( const P & p) -> double { return this->func(p);} );\n" "}"); } - void vardecl26() // #5907 - { + void vardecl26() { // #5907 const char code[] = "extern int *new, obj, player;"; const char expected[] = "extern int * new ; extern int obj ; extern int player ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code, false, true, Settings::Unspecified, "test.c")); ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } - void volatile_variables() - { + void volatile_variables() { const char code[] = "volatile int a=0;\n" "volatile int b=0;\n" "volatile int c=0;\n"; @@ -4455,8 +4215,7 @@ private: ASSERT_EQUALS("int a ; a = 0 ;\nint b ; b = 0 ;\nint c ; c = 0 ;", actual); } - void syntax_error() - { + void syntax_error() { { errout.str(""); const char code[] = "void f() {}"; @@ -4555,8 +4314,7 @@ private: } - void syntax_error_templates_1() - { + void syntax_error_templates_1() { // ok code.. using ">" for a comparison { errout.str(""); @@ -4651,16 +4409,14 @@ private: } } - void syntax_error_templates_2() - { + void syntax_error_templates_2() { std::istringstream istr("template<>\n"); Settings settings; Tokenizer tokenizer(&settings, this); tokenizer.tokenize(istr, "test.cpp"); // shouldn't segfault } - void syntax_error_templates_3() // Ticket #5605, #5759, #5762, #5774, #5823, #6059 - { + void syntax_error_templates_3() { // Ticket #5605, #5759, #5762, #5774, #5823, #6059 tokenizeAndStringify("foo() template struct tuple Args> tuple { } main() { foo(); }"); tokenizeAndStringify("( ) template < T1 = typename = unused> struct Args { } main ( ) { foo < int > ( ) ; }"); tokenizeAndStringify("() template < T = typename = x > struct a {} { f () }"); @@ -4688,8 +4444,7 @@ private: "void f() { A::i = 0; }"); } - void template_member_ptr() // Ticket #5786 - { + void template_member_ptr() { // Ticket #5786 tokenizeAndStringify("struct A {}; " "struct B { " "template struct BB {}; " @@ -4716,8 +4471,7 @@ private: "};"); } - void removeKeywords() - { + void removeKeywords() { const char code[] = "if (__builtin_expect(!!(x), 1));"; const std::string actual(tokenizeAndStringify(code, true)); @@ -4725,8 +4479,7 @@ private: ASSERT_EQUALS("if ( ! ! x ) { ; }", actual); } - void simplifyKeyword() - { + void simplifyKeyword() { const char code[] = "void f (int a [ static 5] );"; const std::string actual(tokenizeAndStringify(code, true)); @@ -4737,8 +4490,7 @@ private: /** * tokenize "signed i" => "signed int i" */ - void signed1() - { + void signed1() { { const char code1[] = "void foo ( signed int , float ) ;"; ASSERT_EQUALS(code1, tokenizeAndStringify(code1)); @@ -4772,8 +4524,7 @@ private: * tokenize "unsigned i" => "unsigned int i" * tokenize "unsigned" => "unsigned int" */ - void unsigned1() - { + void unsigned1() { // No changes.. { const char code[] = "void foo ( unsigned int , float ) ;"; @@ -4808,16 +4559,14 @@ private: } } - void unsigned2() - { + void unsigned2() { const char code[] = "i = (unsigned)j;"; const char expected[] = "i = ( unsigned int ) j ;"; ASSERT_EQUALS(expected, tokenizeAndStringify(code)); } // simplify "unsigned" when using templates.. - void unsigned3() - { + void unsigned3() { { const char code[] = "; foo();"; const char expected[] = "; foo ( ) ;"; @@ -4831,8 +4580,7 @@ private: } } - void simplifyStdType() // #4947, #4950, #4951 - { + void simplifyStdType() { // #4947, #4950, #4951 // usigned long long { const char code[] = "long long unsigned int x;"; @@ -4959,8 +4707,7 @@ private: } } - void createLinks() - { + void createLinks() { { const char code[] = "class A{\n" " void f() {}\n" @@ -5180,8 +4927,7 @@ private: } } - void simplifyString() - { + void simplifyString() { errout.str(""); Settings settings; Tokenizer tokenizer(&settings, this); @@ -5209,8 +4955,7 @@ private: ASSERT_EQUALS(std::string("\"a") + '\0' + "\"", tokenizer.simplifyString("\"a\\0\"")); } - void simplifyConst() - { + void simplifyConst() { ASSERT_EQUALS("void foo ( ) { const int x ; }", tokenizeAndStringify("void foo(){ int const x;}")); @@ -5235,8 +4980,7 @@ private: ASSERT_EQUALS("const struct X x ;", tokenizeAndStringify("struct X const x;")); } - void switchCase() - { + void switchCase() { ASSERT_EQUALS("void foo ( int i ) { switch ( i ) { case -1 : ; break ; } }", tokenizeAndStringify("void foo (int i) { switch(i) { case -1: break; } }")); //ticket #3227 @@ -5244,8 +4988,7 @@ private: tokenizeAndStringify("void foo(){ switch (n){ label: case 1: label1: label2: break; }}")); } - void simplifyPointerToStandardType() - { + void simplifyPointerToStandardType() { // Pointer to standard type ASSERT_EQUALS("char buf [ 100 ] ; readlink ( path , buf , 99 ) ;", tokenizeAndStringify("char buf[100] ; readlink(path, &buf[0], 99);", @@ -5260,8 +5003,7 @@ private: tokenizeAndStringify("foo data[100]; something(&foo[0]);")); } - std::string simplifyFunctionPointers(const char code[]) - { + std::string simplifyFunctionPointers(const char code[]) { errout.str(""); Settings settings; Tokenizer tokenizer(&settings, this); @@ -5271,16 +5013,14 @@ private: return tokenizer.tokens()->stringifyList(0, true); } - void functionpointer1() - { + void functionpointer1() { ASSERT_EQUALS("void * f ;", simplifyFunctionPointers("void (*f)();")); ASSERT_EQUALS("void * * f ;", simplifyFunctionPointers("void *(*f)();")); ASSERT_EQUALS("unsigned int * f ;", simplifyFunctionPointers("unsigned int (*f)();")); ASSERT_EQUALS("unsigned int * * f ;", simplifyFunctionPointers("unsigned int * (*f)();")); } - void functionpointer2() - { + void functionpointer2() { const char code[] = "typedef void (* PF)();" "void f1 ( ) { }" "PF pf = &f1;" @@ -5291,8 +5031,7 @@ private: ASSERT_EQUALS(expected, simplifyFunctionPointers(code)); } - void functionpointer3() - { + void functionpointer3() { // Related with ticket #2873 const char code[] = "void f() {\n" "(void)(xy(*p)(0);)" @@ -5303,8 +5042,7 @@ private: ASSERT_EQUALS(expected, simplifyFunctionPointers(code)); } - void functionpointer4() - { + void functionpointer4() { const char code[] = "struct S\n" "{\n" " typedef void (*FP)();\n" @@ -5327,16 +5065,14 @@ private: ASSERT_EQUALS(expected, tokenizeDebugListing(code, false)); } - void functionpointer5() - { + void functionpointer5() { const char code[] = ";void (*fp[])(int a) = {0,0,0};"; const char expected[] = "\n\n##file 0\n" "1: ; void * fp@1 [ ] = { 0 , 0 , 0 } ;\n"; ASSERT_EQUALS(expected, tokenizeDebugListing(code, false)); } - void functionpointer6() - { + void functionpointer6() { const char code1[] = ";void (*fp(f))(int);"; const char expected1[] = "\n\n##file 0\n" "1: ; void * fp ( f ) ;\n"; // No varId - it could be a function @@ -5348,23 +5084,20 @@ private: ASSERT_EQUALS(expected2, tokenizeDebugListing(code2, false)); } - void functionpointer7() - { + void functionpointer7() { const char code1[] = "void (X::*y)();"; const char expected1[] = "\n\n##file 0\n" "1: void * y@1 ;\n"; ASSERT_EQUALS(expected1, tokenizeDebugListing(code1, false)); } - void removeRedundantAssignment() - { + void removeRedundantAssignment() { ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { int *p, *q; p = q; }", true)); ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() { int *p = 0, *q; p = q; }", true)); ASSERT_EQUALS("int f ( int * x ) { return * x ; }", tokenizeAndStringify("int f(int *x) { return *x; }", true)); } - void removedeclspec() - { + void removedeclspec() { ASSERT_EQUALS("a b", tokenizeAndStringify("a __declspec ( dllexport ) b")); ASSERT_EQUALS("int a ;", tokenizeAndStringify("__declspec(thread) __declspec(align(32)) int a;")); ASSERT_EQUALS("int i ;", tokenizeAndStringify("__declspec(allocate(\"mycode\")) int i;")); @@ -5372,8 +5105,7 @@ private: ASSERT_EQUALS("__property int x [ ] ;", tokenizeAndStringify("__declspec(property(get=GetX, put=PutX)) int x[];")); } - void removeattribute() - { + void removeattribute() { ASSERT_EQUALS("short array [ 3 ] ;", tokenizeAndStringify("short array[3] __attribute__ ((aligned));")); ASSERT_EQUALS("int x [ 2 ] ;", tokenizeAndStringify("int x[2] __attribute__ ((packed));")); ASSERT_EQUALS("int vecint ;", tokenizeAndStringify("int __attribute__((mode(SI))) __attribute__((vector_size (16))) vecint;")); @@ -5384,8 +5116,7 @@ private: ASSERT_EQUALS("int vecint ;", tokenizeAndStringify("int __attribute((mode(SI))) __attribute((vector_size (16))) vecint;")); } - void functionAttributeBefore() - { + void functionAttributeBefore() { const char code[] = "void __attribute__((pure)) __attribute__((nothrow)) __attribute__((const)) func1();\n" "void __attribute__((__pure__)) __attribute__((__nothrow__)) __attribute__((__const__)) func2();\n" "void __attribute__((nothrow)) __attribute__((pure)) __attribute__((const)) func3();\n" @@ -5415,8 +5146,7 @@ private: ASSERT(func4 && func4->isAttributePure() && func4->isAttributeNothrow() && func4->isAttributeConst()); } - void functionAttributeAfter() - { + void functionAttributeAfter() { const char code[] = "void func1() __attribute__((pure)) __attribute__((nothrow)) __attribute__((const));\n" "void func2() __attribute__((__pure__)) __attribute__((__nothrow__)) __attribute__((__const__));\n" "void func3() __attribute__((nothrow)) __attribute__((pure)) __attribute__((const));\n" @@ -5446,8 +5176,7 @@ private: ASSERT(func4 && func4->isAttributePure() && func4->isAttributeNothrow() && func4->isAttributeConst()); } - void cpp0xtemplate1() - { + void cpp0xtemplate1() { const char *code = "template \n" "void fn2 (T t = []{return 1;}())\n" "{}\n" @@ -5458,15 +5187,13 @@ private: ASSERT_EQUALS("int main ( )\n{\nfn2 ( ) ;\n} void fn2 ( int t = [ ] { return 1 ; } ( ) )\n{ }", tokenizeAndStringify(code)); } - void cpp0xtemplate2() - { + void cpp0xtemplate2() { // tokenize ">>" into "> >" const char *code = "list> ints;\n"; ASSERT_EQUALS("list < list < int > > ints ;", tokenizeAndStringify(code)); } - void cpp0xtemplate3() - { + void cpp0xtemplate3() { // #2549 const char *code = "template\n" "struct S\n" @@ -5480,8 +5207,7 @@ private: tokenizeAndStringify(code)); } - std::string arraySize_(const std::string &code) - { + std::string arraySize_(const std::string &code) { errout.str(""); Settings settings; // tokenize.. @@ -5499,8 +5225,7 @@ private: return ostr.str(); } - void arraySize() - { + void arraySize() { ASSERT_EQUALS("; int a[3]={1,2,3};", arraySize_(";int a[]={1,2,3};")); ASSERT_EQUALS("; int a[3]={1,2,3};", arraySize_(";int a[]={1,2,3,};")); ASSERT_EQUALS("; foo a[3]={{1,2},{3,4},{5,6}};", arraySize_(";foo a[]={{1,2},{3,4},{5,6}};")); @@ -5510,14 +5235,12 @@ private: ASSERT_EQUALS("; int a[3]={ ABC,2,3};", arraySize_(";int a[]={ABC,2,3};")); } - std::string labels_(const std::string &code) - { + std::string labels_(const std::string &code) { // the arraySize_ does what we want currently.. return arraySize_(code); } - void labels() - { + void labels() { ASSERT_EQUALS("void f(){ ab:; a=0;}", labels_("void f() { ab: a=0; }")); //ticket #3176 ASSERT_EQUALS("void f(){ ab:;(* func)();}", labels_("void f() { ab: (*func)(); }")); @@ -5541,8 +5264,7 @@ private: ASSERT_EQUALS("void f(){ MACRO( bar, ab:{&(* b. x)=0;})}", labels_("void f() { MACRO(bar, ab: {&(*b.x)=0;})}")); } - void simplifyInitVar() - { + void simplifyInitVar() { { const char code[] = "int i ; int p(0);"; ASSERT_EQUALS("int i ; int p ; p = 0 ;", tokenizeAndStringify(code)); @@ -5726,8 +5448,7 @@ private: } } - void simplifyInitVar2() - { + void simplifyInitVar2() { // ticket #5131 - unsigned const char code[] = "void f() {\n" " unsigned int a(0),b(0);\n" @@ -5737,8 +5458,7 @@ private: "}", tokenizeAndStringify(code)); } - void simplifyInitVar3() - { + void simplifyInitVar3() { const char code[] = "void f() {\n" " int *a(0),b(0);\n" "}"; @@ -5747,8 +5467,7 @@ private: "}", tokenizeAndStringify(code)); } - void bitfields1() - { + void bitfields1() { const char code1[] = "struct A { bool x : 1; };"; ASSERT_EQUALS("struct A { bool x ; } ;", tokenizeAndStringify(code1,false)); @@ -5825,8 +5544,7 @@ private: ASSERT_EQUALS("struct A { signed long long x ; } ;", tokenizeAndStringifyWindows(code25,false, true, Settings::Win32A)); } - void bitfields2() - { + void bitfields2() { const char code1[] = "struct A { public: int x : 3; };"; ASSERT_EQUALS("struct A { public: int x ; } ;", tokenizeAndStringify(code1,false)); @@ -5846,8 +5564,7 @@ private: ASSERT_EQUALS("struct A { private: unsigned long x ; } ;", tokenizeAndStringify(code6,false)); } - void bitfields3() - { + void bitfields3() { const char code1[] = "struct A { const int x : 3; };"; ASSERT_EQUALS("struct A { const int x ; } ;", tokenizeAndStringify(code1,false)); @@ -5861,8 +5578,7 @@ private: ASSERT_EQUALS("struct A { public: const unsigned long x ; } ;", tokenizeAndStringify(code4,false)); } - void bitfields4() // ticket #1956 - { + void bitfields4() { // ticket #1956 const char code1[] = "struct A { CHAR x : 3; };"; ASSERT_EQUALS("struct A { CHAR x ; } ;", tokenizeAndStringify(code1,false)); @@ -5894,8 +5610,7 @@ private: ASSERT_EQUALS("struct A { UINT64 x ; } ;", tokenizeAndStringify(code10,false)); } - void bitfields5() // ticket #1956 - { + void bitfields5() { // ticket #1956 const char code1[] = "struct RGB { unsigned int r : 3, g : 3, b : 2; };"; ASSERT_EQUALS("struct RGB { unsigned int r ; unsigned int g ; unsigned int b ; } ;", tokenizeAndStringify(code1,false)); @@ -5906,8 +5621,7 @@ private: ASSERT_EQUALS("struct A { virtual void f ( ) { } int f1 ; } ;", tokenizeAndStringify(code3,false)); } - void bitfields6() // ticket #2595 - { + void bitfields6() { // ticket #2595 const char code1[] = "struct A { bool b : true; };"; ASSERT_EQUALS("struct A { bool b ; } ;", tokenizeAndStringify(code1,false)); @@ -5924,8 +5638,7 @@ private: ASSERT_EQUALS("void f ( int a ) { switch ( a ) { default : ; break ; } }", tokenizeAndStringify(code5,true)); } - void bitfields7() // ticket #1987 - { + void bitfields7() { // ticket #1987 const char code[] = "typedef struct Descriptor {" " unsigned element_size: 8* sizeof( unsigned );" "} Descriptor;"; @@ -5936,8 +5649,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void bitfields8() - { + void bitfields8() { const char code[] = "struct A;" "class B : virtual public C" "{" @@ -5952,8 +5664,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void bitfields9() // ticket #2706 - { + void bitfields9() { // ticket #2706 const char code[] = "void f() {\n" " goto half;\n" "half:\n" @@ -5965,8 +5676,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void bitfields10() // ticket #2737 - { + void bitfields10() { // ticket #2737 const char code[] = "{}" "MACRO " "default: { }" @@ -5974,33 +5684,28 @@ private: ASSERT_EQUALS("{ } MACRO default : { } ;", tokenizeAndStringify(code,false)); } - void bitfields11() // ticket #2845 (segmentation fault) - { + void bitfields11() { // ticket #2845 (segmentation fault) const char code[] = "#if b&&a\n" "#ifdef y z:\n"; tokenizeAndStringify(code,false); ASSERT_EQUALS("", errout.str()); } - void bitfields12() // ticket #3485 (segmentation fault) - { + void bitfields12() { // ticket #3485 (segmentation fault) const char code[] = "{a:1;};\n"; ASSERT_EQUALS("{ } ;", tokenizeAndStringify(code,false)); } - void bitfields13() // ticket #3502 (segmentation fault) - { + void bitfields13() { // ticket #3502 (segmentation fault) ASSERT_EQUALS("x y ;", tokenizeAndStringify("struct{x y:};\n",false)); } - void bitfields14() // #4561 - crash for 'signals:' - { + void bitfields14() { // #4561 - crash for 'signals:' ASSERT_EQUALS("class x { signals : } ;", tokenizeAndStringify("class x { signals: };\n",false)); } - void simplifyNamespaceStd() - { + void simplifyNamespaceStd() { static const char code1[] = "map m;"; // namespace std is not used ASSERT_EQUALS("map < foo , bar > m ;", tokenizeAndStringify(code1, false)); @@ -6079,8 +5784,7 @@ private: ASSERT_EQUALS(expected14, tokenizeAndStringify(code14, false)); } - void microsoftMFC() - { + void microsoftMFC() { const char code1[] = "class MyDialog : public CDialog { DECLARE_MESSAGE_MAP() private: CString text; };"; ASSERT_EQUALS("class MyDialog : public CDialog { private: CString text ; } ;", tokenizeAndStringify(code1,false,true,Settings::Win32A)); @@ -6094,8 +5798,7 @@ private: ASSERT_EQUALS("class MyDialog : public CDialog { private: CString text ; } ;", tokenizeAndStringify(code4,false,true,Settings::Win32A)); } - void microsoftMemory() - { + void microsoftMemory() { const char code1a[] = "void foo() { int a[10], b[10]; CopyMemory(a, b, sizeof(a)); }"; ASSERT_EQUALS("void foo ( ) { int a [ 10 ] ; int b [ 10 ] ; memcpy ( a , b , sizeof ( a ) ) ; }", tokenizeAndStringify(code1a,false,true,Settings::Win32A)); @@ -6136,8 +5839,7 @@ private: ASSERT_EQUALS("void foo ( ) { memset ( f ( 1 , g ( a , b ) ) , 255 , h ( i , j ( 0 , 1 ) ) ) ; }", tokenizeAndStringify(code7,false,true,Settings::Win32A)); } - void borland() - { + void borland() { // __closure ASSERT_EQUALS("int * a ;", tokenizeAndStringify("int (__closure *a)();", false)); @@ -6147,8 +5849,7 @@ private: tokenizeAndStringify("class Fred { __property int x = { } };", false)); } - void Qt() - { + void Qt() { const char code1[] = "class Counter : public QObject " "{ " " Q_OBJECT " @@ -6254,8 +5955,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void simplifySQL() - { + void simplifySQL() { // Oracle PRO*C extensions for inline SQL. Just replace the SQL with "asm()" to fix wrong error messages // ticket: #1959 ASSERT_EQUALS("asm ( \"\"EXEC SQL SELECT A FROM B\"\" ) ;", tokenizeAndStringify("EXEC SQL SELECT A FROM B;",false)); @@ -6263,8 +5963,7 @@ private: } - void simplifyCAlternativeTokens() - { + void simplifyCAlternativeTokens() { ASSERT_EQUALS("void f ( ) { if ( a && b ) { ; } }", tokenizeAndStringify("void f() { if (a and b); }")); ASSERT_EQUALS("void f ( ) { if ( a || b ) { ; } }", tokenizeAndStringify("void f() { if (a or b); }")); ASSERT_EQUALS("void f ( ) { if ( a & b ) { ; } }", tokenizeAndStringify("void f() { if (a bitand b); }")); @@ -6283,8 +5982,7 @@ private: tokenizeDebugListing("void f(bool b) { if (not b); }")); } - void simplifyCalculations() - { + void simplifyCalculations() { ASSERT_EQUALS("void foo ( char str [ ] ) { char x ; x = * str ; }", tokenizeAndStringify("void foo ( char str [ ] ) { char x = 0 | ( * str ) ; }", true)); ASSERT_EQUALS("void foo ( ) { if ( b ) { } }", @@ -6321,8 +6019,7 @@ private: ASSERT_EQUALS("char a [ 10 ] ;", tokenizeAndStringify("char a[9+1];")); } - void simplifyCompoundAssignment() - { + void simplifyCompoundAssignment() { ASSERT_EQUALS("; x = x + y ;", tokenizeAndStringify("; x += y;")); ASSERT_EQUALS("; x = x - y ;", tokenizeAndStringify("; x -= y;")); ASSERT_EQUALS("; x = x * y ;", tokenizeAndStringify("; x *= y;")); @@ -6383,19 +6080,16 @@ private: ASSERT_EQUALS("; a = a + ( b = 1 ) ;", tokenizeAndStringify("; a += b = 1;")); } - void simplifyAssignmentInFunctionCall() - { + void simplifyAssignmentInFunctionCall() { ASSERT_EQUALS("; x = g ( ) ; f ( x ) ;", tokenizeAndStringify(";f(x=g());")); } - void simplifyRoundCurlyParentheses() - { + void simplifyRoundCurlyParentheses() { ASSERT_EQUALS("; x = 123 ;", tokenizeAndStringify(";x=({123;});")); ASSERT_EQUALS("; x = y ;", tokenizeAndStringify(";x=({y;});")); } - void simplifyOperatorName1() - { + void simplifyOperatorName1() { // make sure C code doesn't get changed const char code[] = "void operator () {}" "int main()" @@ -6412,8 +6106,7 @@ private: ASSERT_EQUALS(result, tokenizeAndStringify(code,false)); } - void simplifyOperatorName2() - { + void simplifyOperatorName2() { const char code[] = "class Fred" "{" " Fred(const Fred & f) { operator = (f); }" @@ -6429,8 +6122,7 @@ private: ASSERT_EQUALS(result, tokenizeAndStringify(code,false)); } - void simplifyOperatorName3() - { + void simplifyOperatorName3() { // #2615 const char code[] = "void f() {" "static_cast(xResult.operator->())->GetMatrix();" @@ -6439,15 +6131,13 @@ private: ASSERT_EQUALS(result, tokenizeAndStringify(code,false)); } - void simplifyOperatorName4() - { + void simplifyOperatorName4() { const char code[] = "void operator==() { }"; const char result[] = "void operator== ( ) { }"; ASSERT_EQUALS(result, tokenizeAndStringify(code,false)); } - void simplifyOperatorName5() - { + void simplifyOperatorName5() { const char code1[] = "std::istream & operator >> (std::istream & s, Fred &f);"; const char result1[] = "std :: istream & operator>> ( std :: istream & s , Fred & f ) ;"; ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false)); @@ -6457,8 +6147,7 @@ private: ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false)); } - void simplifyOperatorName6() // ticket #3195 - { + void simplifyOperatorName6() { // ticket #3195 const char code1[] = "value_type * operator ++ (int);"; const char result1[] = "value_type * operator++ ( int ) ;"; ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false)); @@ -6468,15 +6157,13 @@ private: ASSERT_EQUALS(result2, tokenizeAndStringify(code2,false)); } - void simplifyOperatorName7() // ticket #4619 - { + void simplifyOperatorName7() { // ticket #4619 const char code1[] = "value_type * operator += (int);"; const char result1[] = "value_type * operator+= ( int ) ;"; ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false)); } - void simplifyOperatorName8() // ticket #5706 - { + void simplifyOperatorName8() { // ticket #5706 const char code1[] = "value_type * operator += (int) noexcept ;"; const char result1[] = "value_type * operator+= ( int ) noexcept ;"; ASSERT_EQUALS(result1, tokenizeAndStringify(code1,false)); @@ -6502,26 +6189,22 @@ private: ASSERT_EQUALS(result6, tokenizeAndStringify(code6,false)); } - void simplifyOperatorName9() // Ticket #5709 - { + void simplifyOperatorName9() { // Ticket #5709 const char code[] = "struct R { R operator, ( R b ) ; } ;"; ASSERT_EQUALS(code, tokenizeAndStringify(code)); } - void simplifyNull() - { + void simplifyNull() { ASSERT_EQUALS("if ( ! p )", tokenizeAndStringify("if (p==NULL)")); ASSERT_EQUALS("f ( NULL ) ;", tokenizeAndStringify("f(NULL);")); ASSERT_EQUALS("char * i ; i = 0 ;", tokenizeAndStringify("char* i = (NULL);")); } - void simplifyNullArray() - { + void simplifyNullArray() { ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;")); } - void removeMacrosInGlobalScope() - { + void removeMacrosInGlobalScope() { // remove some unhandled macros in the global scope. ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() NOTHROW { }")); ASSERT_EQUALS("struct Foo { } ;", tokenizeAndStringify("struct __declspec(dllexport) Foo {};")); @@ -6541,8 +6224,7 @@ private: tokenizeAndStringify("; CONST struct ABC abc ;")); } - void removeMacroInVarDecl() // #4304 - { + void removeMacroInVarDecl() { // #4304 // only remove macros with parentheses (those hurt most) ASSERT_EQUALS("void f ( ) { PROGMEM int x ; }", tokenizeAndStringify("void f() { PROGMEM int x ; }")); ASSERT_EQUALS("void f ( ) { int x ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") int x ; }")); @@ -6555,13 +6237,11 @@ private: ASSERT_EQUALS("void f ( ) { CONST struct ABC abc ; }", tokenizeAndStringify("void f() { SECTION(\".data.ro\") CONST struct ABC abc; }")); } - void multipleAssignment() - { + void multipleAssignment() { ASSERT_EQUALS("a = b = 0 ;", tokenizeAndStringify("a=b=0;")); } - void platformWin() - { + void platformWin() { const char code[] = "BOOL f;" "BOOLEAN g;" "BYTE h;" @@ -6709,8 +6389,7 @@ private: ASSERT_EQUALS(win32A, tokenizeAndStringifyWindows(code, true, true, Settings::Win64)); } - void platformWin32() - { + void platformWin32() { const char code[] = "unsigned int sizeof_short = sizeof(short);" "unsigned int sizeof_unsigned_short = sizeof(unsigned short);" "unsigned int sizeof_int = sizeof(int);" @@ -6783,8 +6462,7 @@ private: ASSERT_EQUALS(win32A, tokenizeAndStringifyWindows(code, true, true, Settings::Win32W)); } - void platformWin32A() - { + void platformWin32A() { const char code[] = "wchar_t wc;" "TCHAR c;" "PTSTR ptstr;" @@ -6830,8 +6508,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, false, true, Settings::Win32A)); } - void platformWin32W() - { + void platformWin32W() { const char code[] = "wchar_t wc;" "TCHAR c;" "PTSTR ptstr;" @@ -6877,8 +6554,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, false, true, Settings::Win32W)); } - void platformWin64() - { + void platformWin64() { const char code[] = "unsigned int sizeof_short = sizeof(short);" "unsigned int sizeof_unsigned_short = sizeof(unsigned short);" "unsigned int sizeof_int = sizeof(int);" @@ -6948,8 +6624,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, true, Settings::Win64)); } - void platformUnix32() - { + void platformUnix32() { const char code[] = "unsigned int sizeof_short = sizeof(short);" "unsigned int sizeof_unsigned_short = sizeof(unsigned short);" "unsigned int sizeof_int = sizeof(int);" @@ -6995,8 +6670,7 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unix32)); } - void platformUnix64() - { + void platformUnix64() { const char code[] = "unsigned int sizeof_short = sizeof(short);" "unsigned int sizeof_unsigned_short = sizeof(unsigned short);" "unsigned int sizeof_int = sizeof(int);" @@ -7042,22 +6716,19 @@ private: ASSERT_EQUALS(expected, tokenizeAndStringify(code, true, true, Settings::Unix64)); } - void platformWin32AStringCat() //#5150 - { + void platformWin32AStringCat() { //#5150 const char code[] = "TCHAR text[] = _T(\"123\") _T(\"456\") _T(\"789\");"; const char expected[] = "char text [ 10 ] = \"123456789\" ;"; ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, true, Settings::Win32A)); } - void platformWin32WStringCat() //#5150 - { + void platformWin32WStringCat() { //#5150 const char code[] = "TCHAR text[] = _T(\"123\") _T(\"456\") _T(\"789\");"; const char expected[] = "wchar_t text [ 10 ] = L\"123456789\" ;"; ASSERT_EQUALS(expected, tokenizeAndStringifyWindows(code, true, true, Settings::Win32W)); } - void platformWinWithNamespace() - { + void platformWinWithNamespace() { const char code1[] = "UINT32 a; ::UINT32 b; foo::UINT32 c;"; const char expected1[] = "unsigned int a ; unsigned int b ; foo :: UINT32 c ;"; ASSERT_EQUALS(expected1, tokenizeAndStringifyWindows(code1, true, true, Settings::Win32A)); @@ -7067,8 +6738,7 @@ private: ASSERT_EQUALS(expected2, tokenizeAndStringifyWindows(code2, true, true, Settings::Win32A)); } - void isZeroNumber() const - { + void isZeroNumber() const { ASSERT_EQUALS(true, Tokenizer::isZeroNumber("0.0")); ASSERT_EQUALS(true, Tokenizer::isZeroNumber("+0.0")); ASSERT_EQUALS(true, Tokenizer::isZeroNumber("-0.0")); @@ -7086,8 +6756,7 @@ private: ASSERT_EQUALS(false, Tokenizer::isZeroNumber("2e")); } - void isOneNumber() const - { + void isOneNumber() const { ASSERT_EQUALS(true, Tokenizer::isOneNumber("1.0")); ASSERT_EQUALS(true, Tokenizer::isOneNumber("+1.0")); ASSERT_EQUALS(true, Tokenizer::isOneNumber("1.0e+0")); @@ -7103,8 +6772,7 @@ private: ASSERT_EQUALS(false, Tokenizer::isOneNumber("garbage")); } - void isTwoNumber() const - { + void isTwoNumber() const { ASSERT_EQUALS(true, Tokenizer::isTwoNumber("2.0")); ASSERT_EQUALS(true, Tokenizer::isTwoNumber("+2.0")); ASSERT_EQUALS(true, Tokenizer::isTwoNumber("2.0e+0")); @@ -7120,8 +6788,7 @@ private: ASSERT_EQUALS(false, Tokenizer::isTwoNumber("garbage")); } - void simplifyMathFunctions_erfc() - { + void simplifyMathFunctions_erfc() { // verify erfc(), erfcf(), erfcl() - simplifcation const char code_erfc[] ="void f(int x) {\n" " std::cout << erfc(x);\n" // do not simplify @@ -7154,8 +6821,7 @@ private: ASSERT_EQUALS(expected_erfcl, tokenizeAndStringify(code_erfcl)); } - void simplifyMathFunctions_cos() - { + void simplifyMathFunctions_cos() { // verify cos(), cosf(), cosl() - simplifcation const char code_cos[] ="void f(int x) {\n" " std::cout << cos(x);\n" // do not simplify @@ -7188,8 +6854,7 @@ private: ASSERT_EQUALS(expected_cosl, tokenizeAndStringify(code_cosl)); } - void simplifyMathFunctions_cosh() - { + void simplifyMathFunctions_cosh() { // verify cosh(), coshf(), coshl() - simplifcation const char code_cosh[] ="void f(int x) {\n" " std::cout << cosh(x);\n" // do not simplify @@ -7222,8 +6887,7 @@ private: ASSERT_EQUALS(expected_coshl, tokenizeAndStringify(code_coshl)); } - void simplifyMathFunctions_acos() - { + void simplifyMathFunctions_acos() { // verify acos(), acosf(), acosl() - simplifcation const char code_acos[] ="void f(int x) {\n" " std::cout << acos(x);\n" // do not simplify @@ -7256,8 +6920,7 @@ private: ASSERT_EQUALS(expected_acosl, tokenizeAndStringify(code_acosl)); } - void simplifyMathFunctions_acosh() - { + void simplifyMathFunctions_acosh() { // verify acosh(), acoshf(), acoshl() - simplifcation const char code_acosh[] ="void f(int x) {\n" " std::cout << acosh(x);\n" // do not simplify @@ -7290,8 +6953,7 @@ private: ASSERT_EQUALS(expected_acoshl, tokenizeAndStringify(code_acoshl)); } - void simplifyMathFunctions_sqrt() - { + void simplifyMathFunctions_sqrt() { // verify sqrt(), sqrtf(), sqrtl() - simplifcation const char code_sqrt[] ="void f(int x) {\n" " std::cout << sqrt(x);\n" // do not simplify @@ -7336,8 +6998,7 @@ private: ASSERT_EQUALS(expected_sqrtl, tokenizeAndStringify(code_sqrtl)); } - void simplifyMathFunctions_cbrt() - { + void simplifyMathFunctions_cbrt() { // verify cbrt(), cbrtf(), cbrtl() - simplifcation const char code_cbrt[] ="void f(int x) {\n" " std::cout << cbrt(x);\n" // do not simplify @@ -7382,8 +7043,7 @@ private: ASSERT_EQUALS(expected_cbrtl, tokenizeAndStringify(code_cbrtl)); } - void simplifyMathFunctions_exp2() - { + void simplifyMathFunctions_exp2() { // verify exp2(), exp2f(), exp2l() - simplifcation const char code_exp2[] ="void f(int x) {\n" " std::cout << exp2(x);\n" // do not simplify @@ -7428,8 +7088,7 @@ private: ASSERT_EQUALS(expected_exp2l, tokenizeAndStringify(code_exp2l)); } - void simplifyMathFunctions_exp() - { + void simplifyMathFunctions_exp() { // verify exp(), expf(), expl() - simplifcation const char code_exp[] ="void f(int x) {\n" " std::cout << exp(x);\n" // do not simplify @@ -7474,8 +7133,7 @@ private: ASSERT_EQUALS(expected_expl, tokenizeAndStringify(code_expl)); } - void simplifyMathFunctions_erf() - { + void simplifyMathFunctions_erf() { // verify erf(), erff(), erfl() - simplifcation const char code_erf[] ="void f(int x) {\n" " std::cout << erf(x);\n" // do not simplify @@ -7514,8 +7172,7 @@ private: ASSERT_EQUALS(expected_erfl, tokenizeAndStringify(code_erfl)); } - void simplifyMathFunctions_atanh() - { + void simplifyMathFunctions_atanh() { // verify atanh(), atanhf(), atanhl() - simplifcation const char code_atanh[] ="void f(int x) {\n" " std::cout << atanh(x);\n" // do not simplify @@ -7556,8 +7213,7 @@ private: ASSERT_EQUALS(expected_atanhl, tokenizeAndStringify(code_atanhl)); } - void simplifyMathFunctions_atan() - { + void simplifyMathFunctions_atan() { // verify atan(), atanf(), atanl() - simplifcation const char code_atan[] ="void f(int x) {\n" " std::cout << atan(x);\n" // do not simplify @@ -7596,8 +7252,7 @@ private: ASSERT_EQUALS(expected_atanl, tokenizeAndStringify(code_atanl)); } - void simplifyMathFunctions_fma() - { + void simplifyMathFunctions_fma() { // verify fma(), fmal(), fmaf() - simplifcation const char code_fma[] ="int f(int a, int b, int c) { return fma(a,b,c); }"; const char expected_fma[] = "int f ( int a , int b , int c ) { return ( a ) * ( b ) + ( c ) ; }"; @@ -7631,8 +7286,7 @@ private: TODO_ASSERT_EQUALS(expected_fma1, current_fma1,tokenizeAndStringify(code_fma1)); } - void simplifyMathFunctions_tanh() - { + void simplifyMathFunctions_tanh() { // verify tanh(), tanhf(), tanhl() - simplifcation const char code_tanh[] ="void f(int x) {\n" " std::cout << tanh(x);\n" // do not simplify @@ -7671,8 +7325,7 @@ private: ASSERT_EQUALS(expected_tanhl, tokenizeAndStringify(code_tanhl)); } - void simplifyMathFunctions_tan() - { + void simplifyMathFunctions_tan() { // verify tan(), tanf(), tanl() - simplifcation const char code_tan[] ="void f(int x) {\n" " std::cout << tan(x);\n" // do not simplify @@ -7711,8 +7364,7 @@ private: ASSERT_EQUALS(expected_tanl, tokenizeAndStringify(code_tanl)); } - void simplifyMathFunctions_expm1() - { + void simplifyMathFunctions_expm1() { // verify expm1(), expm1f(), expm1l() - simplifcation const char code_expm1[] ="void f(int x) {\n" " std::cout << expm1(x);\n" // do not simplify @@ -7751,8 +7403,7 @@ private: ASSERT_EQUALS(expected_expm1l, tokenizeAndStringify(code_expm1l)); } - void simplifyMathFunctions_asinh() - { + void simplifyMathFunctions_asinh() { // verify asinh(), asinhf(), asinhl() - simplifcation const char code_asinh[] ="void f(int x) {\n" " std::cout << asinh(x);\n" // do not simplify @@ -7791,8 +7442,7 @@ private: ASSERT_EQUALS(expected_asinhl, tokenizeAndStringify(code_asinhl)); } - void simplifyMathFunctions_asin() - { + void simplifyMathFunctions_asin() { // verify asin(), asinf(), asinl() - simplifcation const char code_asin[] ="void f(int x) {\n" " std::cout << asin(x);\n" // do not simplify @@ -7831,8 +7481,7 @@ private: ASSERT_EQUALS(expected_asinl, tokenizeAndStringify(code_asinl)); } - void simplifyMathFunctions_sinh() - { + void simplifyMathFunctions_sinh() { // verify sinh(), sinhf(), sinhl() - simplifcation const char code_sinh[] ="void f(int x) {\n" " std::cout << sinh(x);\n" // do not simplify @@ -7871,8 +7520,7 @@ private: ASSERT_EQUALS(expected_sinhl, tokenizeAndStringify(code_sinhl)); } - void simplifyMathFunctions_sin() - { + void simplifyMathFunctions_sin() { // verify sin(), sinf(), sinl() - simplifcation const char code_sin[] ="void f(int x) {\n" " std::cout << sin(x);\n" // do not simplify @@ -7911,8 +7559,7 @@ private: ASSERT_EQUALS(expected_sinl, tokenizeAndStringify(code_sinl)); } - void simplifyMathFunctions_ilogb() - { + void simplifyMathFunctions_ilogb() { // verify ilogb(), ilogbf(), ilogbl() - simplifcation const char code_ilogb[] ="void f(int x) {\n" " std::cout << ilogb(x);\n" // do not simplify @@ -7951,8 +7598,7 @@ private: ASSERT_EQUALS(expected_ilogbl, tokenizeAndStringify(code_ilogbl)); } - void simplifyMathFunctions_logb() - { + void simplifyMathFunctions_logb() { // verify logb(), logbf(), logbl() - simplifcation const char code_logb[] ="void f(int x) {\n" " std::cout << logb(x);\n" // do not simplify @@ -7991,8 +7637,7 @@ private: ASSERT_EQUALS(expected_logbl, tokenizeAndStringify(code_logbl)); } - void simplifyMathFunctions_log1p() - { + void simplifyMathFunctions_log1p() { // verify log1p(), log1pf(), log1pl() - simplifcation const char code_log1p[] ="void f(int x) {\n" " std::cout << log1p(x);\n" // do not simplify @@ -8031,8 +7676,7 @@ private: ASSERT_EQUALS(expected_log1pl, tokenizeAndStringify(code_log1pl)); } - void simplifyMathFunctions_log10() - { + void simplifyMathFunctions_log10() { // verify log10(), log10f(), log10l() - simplifcation const char code_log10[] ="void f(int x) {\n" " std::cout << log10(x);\n" // do not simplify @@ -8071,8 +7715,7 @@ private: ASSERT_EQUALS(expected_log10l, tokenizeAndStringify(code_log10l)); } - void simplifyMathFunctions_log() - { + void simplifyMathFunctions_log() { // verify log(), logf(), logl() - simplifcation const char code_log[] ="void f(int x) {\n" " std::cout << log(x);\n" // do not simplify @@ -8111,8 +7754,7 @@ private: ASSERT_EQUALS(expected_logl, tokenizeAndStringify(code_logl)); } - void simplifyMathFunctions_log2() - { + void simplifyMathFunctions_log2() { // verify log2(), log2f(), log2l() - simplifcation const char code_log2[] ="void f(int x) {\n" " std::cout << log2(x);\n" // do not simplify @@ -8151,8 +7793,7 @@ private: ASSERT_EQUALS(expected_log2l, tokenizeAndStringify(code_log2l)); } - void simplifyMathFunctions_div() - { + void simplifyMathFunctions_div() { // verify div(), ldiv(), lldiv() - simplifcation const char code_div[] ="void f(int x) {\n" " std::cout << div(x,1);\n" //simplify @@ -8188,8 +7829,7 @@ private: ASSERT_EQUALS(expected_div3, tokenizeAndStringify(code_div3)); } - void simplifyMathFunctions_pow() - { + void simplifyMathFunctions_pow() { // verify pow(),pow(),powl() - simplifcation const char code_pow[] ="void f() {\n" " std::cout << pow(-1.0,1);\n" @@ -8241,8 +7881,7 @@ private: ASSERT_EQUALS(expected_pow4, tokenizeAndStringify(code_pow4)); } - void simplifyMathFunctions_islessgreater() - { + void simplifyMathFunctions_islessgreater() { // verify islessgreater() simplification const char code_islessgreater[] = "bool f(){\n" "return islessgreater(1,0);\n" // (1 < 0) or (1 > 0) --> true @@ -8269,8 +7908,7 @@ private: ASSERT_EQUALS(expected_islessgreater3, tokenizeAndStringify(code_islessgreater3)); } - void simplifyMathFunctions_islessequal() - { + void simplifyMathFunctions_islessequal() { // verify islessequal() simplification const char code_islessequal[] = "bool f(){\n" "return islessequal(1,0);\n" // (1 <= 0) --> false @@ -8297,8 +7935,7 @@ private: ASSERT_EQUALS(expected_islessequal3, tokenizeAndStringify(code_islessequal3)); } - void simplifyMathFunctions_isless() - { + void simplifyMathFunctions_isless() { // verify isless() simplification const char code_isless[] = "bool f(){\n" "return isless(1,0);\n" // (1 < 0) --> false @@ -8325,8 +7962,7 @@ private: ASSERT_EQUALS(expected_isless3, tokenizeAndStringify(code_isless3)); } - void simplifyMathFunctions_isgreaterequal() - { + void simplifyMathFunctions_isgreaterequal() { // verify isgreaterequal() simplification const char code_isgreaterequal[] = "bool f(){\n" "return isgreaterequal(1,0);\n" // (1 >= 0) --> true @@ -8353,8 +7989,7 @@ private: ASSERT_EQUALS(expected_isgreaterequal3, tokenizeAndStringify(code_isgreaterequal3)); } - void simplifyMathFunctions_isgreater() - { + void simplifyMathFunctions_isgreater() { // verify isgreater() simplification const char code_isgreater[] = "bool f(){\n" "return isgreater(1,0);\n" // (1 > 0) --> true @@ -8381,8 +8016,7 @@ private: ASSERT_EQUALS(expected_isgreater3, tokenizeAndStringify(code_isgreater3)); } - void simplifyMathFunctions_fmin() - { + void simplifyMathFunctions_fmin() { // verify fmin,fminl,fminl simplifcation const char code_fmin[] ="void f() {\n" " std::cout << fmin(-1.0,0);\n" @@ -8415,8 +8049,7 @@ private: ASSERT_EQUALS(expected_fmin1, tokenizeAndStringify(code_fmin1)); } - void simplifyMathFunctions_fmax() - { + void simplifyMathFunctions_fmax() { // verify fmax(),fmax(),fmaxl() simplifcation const char code_fmax[] ="void f() {\n" " std::cout << fmax(-1.0,0);\n" @@ -8449,8 +8082,7 @@ private: ASSERT_EQUALS(expected_fmax1, tokenizeAndStringify(code_fmax1)); } - void simplifyMathFunctions() //#5031 - { + void simplifyMathFunctions() { //#5031 // verify abs,fabs,labs,llabs,atol simplifcation const char code1[] = "void foo() {\n" " std::cout<::epsilon();")); // #6195 } - void astbrackets() const // [] - { + void astbrackets() const { // [] ASSERT_EQUALS("a23+[4+", testAst("a[2+3]+4")); ASSERT_EQUALS("a1[0[", testAst("a[1][0]")); ASSERT_EQUALS("ab0[=", testAst("a=(b)[0];")); @@ -8944,8 +8569,7 @@ private: ASSERT_EQUALS("ab0[1[=", testAst("a=b[0][1];")); } - void astunaryop() const // unary operators - { + void astunaryop() const { // unary operators ASSERT_EQUALS("1a--+", testAst("1 + --a")); ASSERT_EQUALS("1a--+", testAst("1 + a--")); ASSERT_EQUALS("ab+!", testAst("!(a+b)")); @@ -8964,8 +8588,7 @@ private: ASSERT_EQUALS("ai[i= i--", testAst("a[i]=i; --i;")); } - void astfunction() const // function calls - { + void astfunction() const { // function calls ASSERT_EQUALS("1f(+2+", testAst("1+f()+2")); ASSERT_EQUALS("1f2(+3+", testAst("1+f(2)+3")); ASSERT_EQUALS("1f23,(+4+", testAst("1+f(2,3)+4")); @@ -8978,8 +8601,7 @@ private: ASSERT_EQUALS("xsizeofvoid(=", testAst("x=sizeof(void*)")); } - void asttemplate() const // uninstantiated templates will have <,>,etc.. - { + void asttemplate() const { // uninstantiated templates will have <,>,etc.. ASSERT_EQUALS("a(3==", testAst("a()==3")); ASSERT_EQUALS("ab(== f(", testAst("a == b(); f();")); ASSERT_EQUALS("static_casta(i[", testAst("; static_cast(a)[i];")); // #6203 @@ -8989,8 +8611,7 @@ private: ASSERT_EQUALS("AB: f( abc+=", testAst("struct A : public B { void f() { a=b+c; } };")); } - void astcast() const - { + void astcast() const { ASSERT_EQUALS("ac&(=", testAst("a = (long)&c;")); ASSERT_EQUALS("ac*(=", testAst("a = (Foo*)*c;")); ASSERT_EQUALS("ac-(=", testAst("a = (long)-c;")); @@ -9001,8 +8622,7 @@ private: ASSERT_EQUALS("xdouble123(i*(=", testAst("x = (int)(double(123)*i);")); } - void astlambda() const - { + void astlambda() const { ASSERT_EQUALS("([(return 0return", testAst("return [](){ return 0; }();")); ASSERT_EQUALS("([(return 0return", testAst("return []() -> int { return 0; }();")); ASSERT_EQUALS("([(return 0return", testAst("return [something]() -> int { return 0; }();")); @@ -9011,8 +8631,7 @@ private: ASSERT_EQUALS("x([= 0return", testAst("x = [](){return 0; };")); } - void compileLimits() - { + void compileLimits() { const char raw_code[] = "#define PTR1 (* (* (* (* (* (* (* (* (* (*\n" "#define PTR2 PTR1 PTR1 PTR1 PTR1 PTR1 PTR1 PTR1 PTR1 PTR1 PTR1\n" "#define PTR3 PTR2 PTR2 PTR2 PTR2 PTR2 PTR2 PTR2 PTR2 PTR2 PTR2\n" @@ -9041,8 +8660,7 @@ private: tokenizeAndStringify(code.c_str()); // just survive... } - bool isStartOfExecutableScope(int offset, const char code[]) - { + bool isStartOfExecutableScope(int offset, const char code[]) { const Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); @@ -9051,8 +8669,7 @@ private: return Tokenizer::startOfExecutableScope(tokenizer.tokens()->tokAt(offset)) != nullptr; } - void startOfExecutableScope() - { + void startOfExecutableScope() { ASSERT(isStartOfExecutableScope(3, "void foo() { }")); ASSERT(isStartOfExecutableScope(3, "void foo() const { }")); ASSERT(isStartOfExecutableScope(3, "void foo() volatile { }")); diff --git a/test/testtype.cpp b/test/testtype.cpp index 1f464a9f2..78c2ead0a 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -29,22 +29,19 @@ extern std::ostringstream errout; class TestType : public TestFixture { public: - TestType() : TestFixture("TestType") - { + TestType() : TestFixture("TestType") { } private: - void run() - { + void run() { TEST_CASE(checkTooBigShift); TEST_CASE(checkIntegerOverflow); TEST_CASE(signConversion); } - void check(const char code[], Settings* settings = 0) - { + void check(const char code[], Settings* settings = 0) { // Clear the error buffer.. errout.str(""); @@ -64,8 +61,7 @@ private: checkType.runChecks(&tokenizer, settings, this); } - void checkTooBigShift() - { + void checkTooBigShift() { Settings settings; settings.platform(Settings::Unix32); @@ -91,8 +87,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void checkIntegerOverflow() - { + void checkIntegerOverflow() { Settings settings; settings.platform(Settings::Unix32); @@ -115,8 +110,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void signConversion() - { + void signConversion() { check("unsigned int f1(signed int x, unsigned int y) {" // x is signed " return x * y;\n" "}\n" diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 310875b76..a17917e8b 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -25,15 +25,13 @@ extern std::ostringstream errout; class TestUninitVar : public TestFixture { public: - TestUninitVar() : TestFixture("TestUninitVar") - { + TestUninitVar() : TestFixture("TestUninitVar") { } private: Settings settings; - void run() - { + void run() { LOAD_LIB_2(settings.library, "std.cfg"); TEST_CASE(uninitvar1); @@ -81,8 +79,7 @@ private: TEST_CASE(deadPointer); } - void checkUninitVar(const char code[], const char filename[] = "test.cpp") - { + void checkUninitVar(const char code[], const char filename[] = "test.cpp") { // Clear the error buffer.. errout.str(""); @@ -97,8 +94,7 @@ private: check.executionPaths(); } - void uninitvar1() - { + void uninitvar1() { // Ticket #2207 - False negative checkUninitVar("void foo() {\n" " int a;\n" @@ -624,8 +620,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitvar3() // #3844 - { + void uninitvar3() { // #3844 // avoid false positive checkUninitVar("namespace std _GLIBCXX_VISIBILITY(default)\n" "{\n" @@ -642,8 +637,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitvar_bitop() - { + void uninitvar_bitop() { checkUninitVar("void foo() {\n" " int b;\n" " c = a | b;\n" @@ -658,8 +652,7 @@ private: } // if.. - void uninitvar_if() - { + void uninitvar_if() { checkUninitVar("static void foo()\n" "{\n" " Foo *p;\n" @@ -930,8 +923,7 @@ private: // handling for/while loops.. - void uninitvar_loops() - { + void uninitvar_loops() { // for.. checkUninitVar("void f()\n" "{\n" @@ -1063,8 +1055,7 @@ private: } // switch.. - void uninitvar_switch() - { + void uninitvar_switch() { checkUninitVar("void f(int x)\n" "{\n" " short c;\n" @@ -1156,8 +1147,7 @@ private: } // arrays.. - void uninitvar_arrays() - { + void uninitvar_arrays() { checkUninitVar("int f()\n" "{\n" " char a[10];\n" @@ -1352,8 +1342,7 @@ private: } // alloc.. - void uninitvar_alloc() - { + void uninitvar_alloc() { checkUninitVar("void f()\n" "{\n" " char *s = malloc(100);\n" @@ -1494,8 +1483,7 @@ private: } // class / struct.. - void uninitvar_class() - { + void uninitvar_class() { checkUninitVar("class Fred\n" "{\n" " int i;\n" @@ -1544,8 +1532,7 @@ private: } // enum.. - void uninitvar_enum() - { + void uninitvar_enum() { checkUninitVar("void f()\n" "{\n" " enum AB { a, b };\n" @@ -1556,8 +1543,7 @@ private: } // references.. - void uninitvar_references() - { + void uninitvar_references() { checkUninitVar("void f()\n" "{\n" " int a;\n" @@ -1583,8 +1569,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitvar_return() - { + void uninitvar_return() { checkUninitVar("static int foo()\n" "{\n" @@ -1653,8 +1638,7 @@ private: } // strncpy doesn't always null-terminate.. - void uninitvar_strncpy() - { + void uninitvar_strncpy() { checkUninitVar("void f()\n" "{\n" " char a[100];\n" @@ -1714,8 +1698,7 @@ private: } // initialization with memset (not 0-terminating string).. - void uninitvar_memset() - { + void uninitvar_memset() { checkUninitVar("void f() {\n" " char a[20];\n" " memset(a, 'a', 20);\n" @@ -1724,8 +1707,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of 'a' (not null-terminated).\n", errout.str()); } - void uninitvar_memset_nonchar() - { + void uninitvar_memset_nonchar() { checkUninitVar("void f() {\n" " int a[20];\n" " memset(a, 1, 20);\n" @@ -1734,8 +1716,7 @@ private: ASSERT_EQUALS(errout.str(), ""); } - void uninitvar_memset_char_access() - { + void uninitvar_memset_char_access() { checkUninitVar("void f() {\n" " unsigned char c[10];\n" " memset(c, 32, 10);\n" @@ -1744,8 +1725,7 @@ private: ASSERT_EQUALS(errout.str(), ""); } - std::string analyseFunctions(const char code[]) - { + std::string analyseFunctions(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -1764,8 +1744,7 @@ private: return ret; } - void uninitvar_func() - { + void uninitvar_func() { // function analysis.. ASSERT_EQUALS("foo", analyseFunctions("void foo(int x) { }")); ASSERT_EQUALS("foo", analyseFunctions("void foo(int x);")); @@ -2012,8 +1991,7 @@ private: } // valid and invalid use of 'int a(int x) { return x + x; }' - void func_uninit_var() - { + void func_uninit_var() { const std::string funca("int a(int x) { return x + x; }"); checkUninitVar((funca + @@ -2040,8 +2018,7 @@ private: // valid and invalid use of 'void a(int *p) { *p = 0; }' - void func_uninit_pointer() - { + void func_uninit_pointer() { const std::string funca("void a(int *p) { *p = 0; }"); // ok - initialized pointer @@ -2067,8 +2044,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n", errout.str()); } - void uninitvar_typeof() - { + void uninitvar_typeof() { checkUninitVar("void f() {\n" " struct Fred *fred;\n" " typeof(fred->x);\n" @@ -2097,8 +2073,7 @@ private: /** New checking that doesn't rely on ExecutionPath */ - void checkUninitVar2(const char code[], const char fname[] = "test.cpp", bool verify=true, bool debugwarnings=false) - { + void checkUninitVar2(const char code[], const char fname[] = "test.cpp", bool verify=true, bool debugwarnings=false) { // Clear the error buffer.. errout.str(""); @@ -2121,8 +2096,7 @@ private: checkuninitvar.check(); } - void uninitvar2() - { + void uninitvar2() { // using uninit var checkUninitVar2("void f() {\n" " int x;\n" @@ -2604,8 +2578,7 @@ private: } // #3869 - reference variable - void uninitvar4() - { + void uninitvar4() { checkUninitVar2("void f() {\n" " int buf[10];\n" " int &x = buf[0];\n" @@ -2616,8 +2589,7 @@ private: } // #3861 - void uninitvar5() - { + void uninitvar5() { // ensure there is no false positive checkUninitVar2("void f() {\n" " x c;\n" @@ -2641,8 +2613,7 @@ private: } // Handling of unknown types. Assume they are POD in C. - void uninitvar6() - { + void uninitvar6() { const char code[] = "void f() {\n" " dfs a;\n" " return a;\n" @@ -2667,8 +2638,7 @@ private: ASSERT_EQUALS("[test.c:4]: (error) Uninitialized variable: ab\n", errout.str()); } - void uninitvar7() - { + void uninitvar7() { const char code[] = "void eDBauth_user() {\n" " char *blid_cert;\n" " if( ) {\n" @@ -2680,8 +2650,7 @@ private: checkUninitVar2(code, "test.cpp"); } - void uninitvar8() - { + void uninitvar8() { const char code[] = "struct Fred {\n" " void Sync(dsmp_t& type, int& len, int limit = 123);\n" " void Sync(int& syncpos, dsmp_t& type, int& len, int limit = 123);\n" @@ -2697,8 +2666,7 @@ private: } // Handling of function calls - void uninitvar2_func() - { + void uninitvar2_func() { // non-pointer variable checkUninitVar2("void a(char);\n" // value => error "void b() {\n" @@ -2818,8 +2786,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitvar2_value() - { + void uninitvar2_value() { checkUninitVar2("void f() {\n" " int i;\n" " if (x) {\n" @@ -2934,8 +2901,7 @@ private: TODO_ASSERT_EQUALS("error", "", errout.str()); } - void uninitvar2_structmembers() // struct members - { + void uninitvar2_structmembers() { // struct members checkUninitVar2("struct AB { int a; int b; };\n" "void f(void) {\n" " struct AB ab;\n" @@ -3271,8 +3237,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized struct member: ab.b\n", errout.str()); } - void uninitvar2_while() - { + void uninitvar2_while() { // for, while checkUninitVar2("void f() {\n" " int x;\n" @@ -3451,8 +3416,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void uninitvar2_4494() - { + void uninitvar2_4494() { checkUninitVar2("namespace N1 {\n" " class Fred {\n" " public:\n" @@ -3515,8 +3479,7 @@ private: ASSERT_EQUALS("[test.cpp:20]: (error) Uninitialized variable: p\n", errout.str()); } - void uninitvar2_malloc() - { + void uninitvar2_malloc() { checkUninitVar2("int f() {\n" " int *p = malloc(40);\n" " return *p;\n" @@ -3602,8 +3565,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void syntax_error() // Ticket #5073 - { + void syntax_error() { // Ticket #5073 // Nominal mode => No output checkUninitVar2("struct flex_array {};\n" "struct cgroup_taskset {};\n" @@ -3626,8 +3588,7 @@ private: } // Test that std.cfg is configured correctly - void stdcfg() - { + void stdcfg() { // clearerr checkUninitVar("void f() {\n" " FILE * pFile;\n" @@ -3869,8 +3830,7 @@ private: TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: ptr\n", "", errout.str()); } - void checkDeadPointer(const char code[]) - { + void checkDeadPointer(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -3885,8 +3845,7 @@ private: check.deadPointer(); } - void deadPointer() - { + void deadPointer() { checkDeadPointer("void f() {\n" " int *p = p1;\n" " if (cond) {\n" diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index a6a35ae34..895a037a8 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -26,15 +26,13 @@ extern std::ostringstream errout; class TestUnusedFunctions : public TestFixture { public: - TestUnusedFunctions() : TestFixture("TestUnusedFunctions") - { + TestUnusedFunctions() : TestFixture("TestUnusedFunctions") { } private: - void run() - { + void run() { TEST_CASE(incondition); TEST_CASE(return1); TEST_CASE(return2); @@ -62,8 +60,7 @@ private: TEST_CASE(ignore_declaration); // ignore declaration } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -83,8 +80,7 @@ private: delete fileInfo.back(); } - void incondition() - { + void incondition() { check("int f1()\n" "{\n" " if (f1())\n" @@ -93,8 +89,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void return1() - { + void return1() { check("int f1()\n" "{\n" " return f1();\n" @@ -102,8 +97,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void return2() - { + void return2() { check("char * foo()\n" "{\n" " return *foo();\n" @@ -111,8 +105,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void callback1() - { + void callback1() { check("void f1()\n" "{\n" " void (*f)() = cond ? f1 : NULL;\n" @@ -120,8 +113,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void else1() - { + void else1() { check("void f1()\n" "{\n" " if (cond) ;\n" @@ -130,8 +122,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void functionpointer() - { + void functionpointer() { check("namespace abc {\n" "void foo() { }\n" "};\n" @@ -166,8 +157,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void template1() - { + void template1() { check("template void foo() { }\n" "\n" "int main()\n" @@ -178,8 +168,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void template2() - { + void template2() { check("void f() { }\n" "\n" "template void g()\n" @@ -189,8 +178,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void template3() // #4701 - { + void template3() { // #4701 check("class X {\n" "public:\n" " void bar() { foo(0); }\n" @@ -201,14 +189,12 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) The function 'bar' is never used.\n", errout.str()); } - void throwIsNotAFunction() - { + void throwIsNotAFunction() { check("struct A {void f() const throw () {}}; int main() {A a; a.f();}"); ASSERT_EQUALS("", errout.str()); } - void unusedError() - { + void unusedError() { check("void foo() {}\n" "int main()\n"); ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); @@ -226,8 +212,7 @@ private: ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); } - void unusedMain() - { + void unusedMain() { check("int main() { }"); ASSERT_EQUALS("", errout.str()); @@ -238,28 +223,24 @@ private: ASSERT_EQUALS("", errout.str()); } - void initializationIsNotAFunction() - { + void initializationIsNotAFunction() { check("struct B: N::A {\n" " B(): N::A() {};\n" "};"); ASSERT_EQUALS("", errout.str()); } - void operator1() - { + void operator1() { check("struct Foo { void operator()(int a) {} };"); ASSERT_EQUALS("", errout.str()); } - void returnRef() - { + void returnRef() { check("int& foo() {return x;}"); ASSERT_EQUALS("[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); } - void attribute() // #3471 - FP __attribute__((constructor)) - { + void attribute() { // #3471 - FP __attribute__((constructor)) check("void __attribute__((constructor)) f() {}"); ASSERT_EQUALS("", errout.str()); @@ -308,8 +289,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void initializer_list() - { + void initializer_list() { check("int foo() { return 0; }\n" "struct A {\n" " A() : m_i(foo())\n" @@ -319,8 +299,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void member_function_ternary() - { + void member_function_ternary() { check("struct Foo {\n" " void F1() {}\n" " void F2() {}\n" @@ -334,16 +313,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void boost() - { + void boost() { check("static void _xy(const char *b, const char *e)\n" "{}\n" "parse(line, blanks_p >> ident[&_xy] >> blanks_p >> eol_p).full"); ASSERT_EQUALS("", errout.str()); } - void multipleFiles() - { + void multipleFiles() { CheckUnusedFunctions c; // Clear the error buffer.. @@ -380,8 +357,7 @@ private: ASSERT_EQUALS("[test1.cpp:1]: (style) The function 'f' is never used.\n", errout.str()); } - void lineNumber() - { + void lineNumber() { check("void foo() {}\n" "void bar() {}\n" "int main()\n"); @@ -389,8 +365,7 @@ private: "[test.cpp:1]: (style) The function 'foo' is never used.\n", errout.str()); } - void ignore_declaration() - { + void ignore_declaration() { check("void f();\n" "void f() {}"); ASSERT_EQUALS("[test.cpp:2]: (style) The function 'f' is never used.\n", errout.str()); diff --git a/test/testunusedprivfunc.cpp b/test/testunusedprivfunc.cpp index 9e36e12b0..511f29044 100644 --- a/test/testunusedprivfunc.cpp +++ b/test/testunusedprivfunc.cpp @@ -27,13 +27,11 @@ extern std::ostringstream errout; class TestUnusedPrivateFunction : public TestFixture { public: - TestUnusedPrivateFunction() : TestFixture("TestUnusedPrivateFunction") - { + TestUnusedPrivateFunction() : TestFixture("TestUnusedPrivateFunction") { } private: - void run() - { + void run() { TEST_CASE(test1); TEST_CASE(test2); TEST_CASE(test3); @@ -80,8 +78,7 @@ private: } - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -101,8 +98,7 @@ private: - void test1() - { + void test1() { check("class Fred\n" "{\n" "private:\n" @@ -170,8 +166,7 @@ private: } - void test2() - { + void test2() { check("class A {\n" "public:\n" " A();\n" @@ -189,8 +184,7 @@ private: } - void test3() - { + void test3() { check("class A {\n" "public:\n" " A() { }\n" @@ -205,8 +199,7 @@ private: } - void test4() - { + void test4() { check("class A {\n" "public:\n" " A();\n" @@ -221,8 +214,7 @@ private: } - void test5() - { + void test5() { check("class A {\n" "private:\n" " A() : lock(new Lock())\n" @@ -232,8 +224,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void test6() // ticket #2602 segmentation fault - { + void test6() { // ticket #2602 segmentation fault check("class A {\n" " A& operator=(const A&);\n" "};"); @@ -244,8 +235,7 @@ private: - void func_pointer1() - { + void func_pointer1() { check("class Fred\n" "{\n" "private:\n" @@ -271,8 +261,7 @@ private: - void func_pointer2() - { + void func_pointer2() { check("class UnusedPrivateFunctionMemberPointer\n" "{\n" "public:\n" @@ -289,8 +278,7 @@ private: } - void func_pointer3() - { + void func_pointer3() { check("class c1\n" "{\n" "public:\n" @@ -304,8 +292,7 @@ private: } - void func_pointer4() // ticket #2807 - { + void func_pointer4() { // ticket #2807 check("class myclass {\n" "public:\n" " myclass();\n" @@ -319,8 +306,7 @@ private: } - void func_pointer5() - { + void func_pointer5() { check("class A {\n" "public:\n" " A() { f = A::func; }\n" @@ -332,8 +318,7 @@ private: } - void func_pointer6() // #4787 - { + void func_pointer6() { // #4787 check("class Test {\n" "private:\n" " static void a(const char* p) { }\n" @@ -346,8 +331,7 @@ private: } - void ctor() - { + void ctor() { check("class PrivateCtor\n" "{\n" "private:\n" @@ -362,8 +346,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void ctor2() - { + void ctor2() { check("struct State {\n" " State(double const totalWeighting= TotalWeighting()) :\n" " totalWeighting_(totalWeighting) {}\n" @@ -376,8 +359,7 @@ private: } - void classInClass() - { + void classInClass() { check("class A\n" "{\n" "public:\n" @@ -413,8 +395,7 @@ private: } - void sameFunctionNames() - { + void sameFunctionNames() { check("class A\n" "{\n" "public:\n" @@ -430,8 +411,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void incompleteImplementation() - { + void incompleteImplementation() { // The implementation for "A::a" is missing - so don't check if // "A::b" is used or not check("#file \"test.h\"\n" @@ -449,8 +429,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void derivedClass() - { + void derivedClass() { // skip warning in derived classes in case the base class is invisible check("class derived : public base\n" "{\n" @@ -493,8 +472,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void friendClass() - { + void friendClass() { // ticket #2459 - friend class check("class Foo {\n" "private:\n" @@ -532,8 +510,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style) Unused private function: 'Foo::f'\n", errout.str()); } - void borland1() - { + void borland1() { // ticket #2034 - Borland C++ __property check("class Foo {\n" "private:\n" @@ -547,8 +524,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void borland2() - { + void borland2() { // ticket #3661 - Borland C++ __published check("class Foo {\n" "__published:\n" @@ -561,8 +537,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void template1() - { + void template1() { // ticket #2067 - Template methods do not "use" private ones check("class A {\n" "public:\n" @@ -580,8 +555,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void fp_operator() - { + void fp_operator() { // #2407 - FP when function is called from operator() check("class Fred\n" "{\n" @@ -622,8 +596,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testDoesNotIdentifyMethodAsFirstFunctionArgument() - { + void testDoesNotIdentifyMethodAsFirstFunctionArgument() { check("void callback(void (*func)(int), int arg)" "{" " (*func)(arg);" @@ -650,8 +623,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testDoesNotIdentifyMethodAsMiddleFunctionArgument() - { + void testDoesNotIdentifyMethodAsMiddleFunctionArgument() { check("void callback(char, void (*func)(int), int arg)" "{" " (*func)(arg);" @@ -678,8 +650,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void testDoesNotIdentifyMethodAsLastFunctionArgument() - { + void testDoesNotIdentifyMethodAsLastFunctionArgument() { check("void callback(int arg, void (*func)(int))" "{" " (*func)(arg);" @@ -706,8 +677,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void multiFile() // ticket #2567 - { + void multiFile() { // ticket #2567 check("#file \"test.h\"\n" "struct Fred\n" "{\n" @@ -726,8 +696,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void unknownBaseTemplate() // ticket #2580 - { + void unknownBaseTemplate() { // ticket #2580 check("class Bla : public Base2 {\n" "public:\n" " Bla() {}\n" @@ -739,8 +708,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void hierarchie_loop() - { + void hierarchie_loop() { check("class InfiniteB : InfiniteA {\n" " class D {\n" " };\n" @@ -759,8 +727,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (style) Unused private function: 'InfiniteA::foo'\n", errout.str()); } - void staticVariable() - { + void staticVariable() { check("class Foo {\n" " static int i;\n" " static int F() const { return 1; }\n" diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index a8e4b4f10..2b8ee0a7a 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -29,13 +29,11 @@ extern std::ostringstream errout; class TestUnusedVar : public TestFixture { public: - TestUnusedVar() : TestFixture("TestUnusedVar") - { + TestUnusedVar() : TestFixture("TestUnusedVar") { } private: - void run() - { + void run() { TEST_CASE(emptyclass); // #5355 - False positive: Variable is not assigned a value. TEST_CASE(emptystruct); // #5355 - False positive: Variable is not assigned a value. @@ -166,8 +164,7 @@ private: TEST_CASE(usingNamespace); // #4585 } - void checkStructMemberUsage(const char code[]) - { + void checkStructMemberUsage(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -185,8 +182,7 @@ private: } // #5355 - False positive: Variable is not assigned a value. - void emptyclass() - { + void emptyclass() { functionVariableUsage("class Carla {\n" "};\n" "class Fred : Carla {\n" @@ -199,8 +195,7 @@ private: } // #5355 - False positive: Variable is not assigned a value. - void emptystruct() - { + void emptystruct() { functionVariableUsage("struct Fred {\n" "};\n" "void foo() {\n" @@ -210,8 +205,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember1() - { + void structmember1() { checkStructMemberUsage("struct abc\n" "{\n" " int a;\n" @@ -223,8 +217,7 @@ private: "[test.cpp:5]: (style) struct or union member 'abc::c' is never used.\n", errout.str()); } - void structmember2() - { + void structmember2() { checkStructMemberUsage("struct ABC\n" "{\n" " int a;\n" @@ -242,8 +235,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember3() - { + void structmember3() { checkStructMemberUsage("struct ABC\n" "{\n" " int a;\n" @@ -262,8 +254,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember4() - { + void structmember4() { checkStructMemberUsage("struct ABC\n" "{\n" " const int a;\n" @@ -277,8 +268,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember5() - { + void structmember5() { checkStructMemberUsage("struct AB\n" "{\n" " int a;\n" @@ -298,8 +288,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember6() - { + void structmember6() { checkStructMemberUsage("struct AB\n" "{\n" " int a;\n" @@ -325,8 +314,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember7() - { + void structmember7() { checkStructMemberUsage("struct AB\n" "{\n" " int a;\n" @@ -352,8 +340,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember8() - { + void structmember8() { checkStructMemberUsage("struct AB\n" "{\n" " int a;\n" @@ -367,8 +354,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember9() - { + void structmember9() { checkStructMemberUsage("struct base {\n" " int a;\n" "};\n" @@ -378,8 +364,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember10() - { + void structmember10() { // Fred may have some useful side-effects checkStructMemberUsage("struct abc {\n" " Fred fred;\n" @@ -387,8 +372,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void structmember11() // #4168 - { + void structmember11() { // #4168 checkStructMemberUsage("struct abc { int x; };\n" "struct abc s = {0};\n" "void f() { do_something(&s); }"); @@ -400,8 +384,7 @@ private: TODO_ASSERT_EQUALS("abc::x is not used", "", errout.str()); } - void structmember_extern() - { + void structmember_extern() { // extern struct => no false positive checkStructMemberUsage("extern struct AB\n" "{\n" @@ -442,8 +425,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) struct or union member 'AB::a' is never used.\n", errout.str()); } - void functionVariableUsage(const char code[], const char filename[]="test.cpp") - { + void functionVariableUsage(const char code[], const char filename[]="test.cpp") { // Clear the error buffer.. errout.str(""); @@ -461,8 +443,7 @@ private: checkUnusedVar.checkFunctionVariableUsage(); } - void localvar1() - { + void localvar1() { functionVariableUsage("void foo()\n" "{\n" " int i = 0;\n" @@ -892,8 +873,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); } - void localvar2() - { + void localvar2() { functionVariableUsage("int foo()\n" "{\n" " int i;\n" @@ -1021,8 +1001,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar3() - { + void localvar3() { functionVariableUsage("void foo()\n" "{\n" " int i;\n" @@ -1033,8 +1012,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'i' is assigned a value that is never used.\n", errout.str()); } - void localvar4() - { + void localvar4() { functionVariableUsage("void foo()\n" "{\n" " int i = 0;\n" @@ -1050,8 +1028,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar5() - { + void localvar5() { functionVariableUsage("void foo()\n" "{\n" " int a = 0;\n" @@ -1060,8 +1037,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar6() - { + void localvar6() { functionVariableUsage("void foo()\n" "{\n" " int b[10];\n" @@ -1080,8 +1056,7 @@ private: ASSERT_EQUALS("[test.cpp:6]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); } - void localvar7() // ticket 1253 - { + void localvar7() { // ticket 1253 functionVariableUsage("void foo()\n" "{\n" " int i;\n" @@ -1106,8 +1081,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'i' is not assigned a value.\n", errout.str()); } - void localvar8() - { + void localvar8() { functionVariableUsage("void foo()\n" "{\n" " int i;\n" @@ -1308,8 +1282,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar9() - { + void localvar9() { // ticket #1605 functionVariableUsage("void foo()\n" "{\n" @@ -1320,8 +1293,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'a' is assigned a value that is never used.\n", errout.str()); } - void localvar10() - { + void localvar10() { functionVariableUsage("void foo(int x)\n" "{\n" " int i;\n" @@ -1375,8 +1347,7 @@ private: "[test.cpp:7]: (style) Unused variable: i\n", errout.str()); } - void localvar11() - { + void localvar11() { functionVariableUsage("void foo(int x)\n" "{\n" " int a = 0;\n" @@ -1405,8 +1376,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar12() - { + void localvar12() { // ticket #1574 functionVariableUsage("void foo()\n" "{\n" @@ -1440,8 +1410,7 @@ private: errout.str()); } - void localvar13() // ticket #1640 - { + void localvar13() { // ticket #1640 functionVariableUsage("void foo( OBJECT *obj )\n" "{\n" " int x;\n" @@ -1450,8 +1419,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); } - void localvar14() - { + void localvar14() { // ticket #5 functionVariableUsage("void foo()\n" "{\n" @@ -1460,8 +1428,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Unused variable: a\n", errout.str()); } - void localvar15() - { + void localvar15() { functionVariableUsage("int foo()\n" "{\n" " int a = 5;\n" @@ -1508,8 +1475,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar16() // ticket #1709 - { + void localvar16() { // ticket #1709 functionVariableUsage("int foo()\n" "{\n" " char buf[5];\n" @@ -1546,8 +1512,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar17() // ticket #1720 - { + void localvar17() { // ticket #1720 // Don't crash when checking the code below! functionVariableUsage("void foo()\n" "{\n" @@ -1563,8 +1528,7 @@ private: ASSERT_EQUALS("[test.cpp:10]: (style) Variable 'line_start' is assigned a value that is never used.\n", errout.str()); } - void localvar18() // ticket #1723 - { + void localvar18() { // ticket #1723 functionVariableUsage("A::A(int iValue) {\n" " UserDefinedException* pe = new UserDefinedException();\n" " throw pe;\n" @@ -1572,8 +1536,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar19() // ticket #1776 - { + void localvar19() { // ticket #1776 functionVariableUsage("void foo() {\n" " int a[10];\n" " int c;\n" @@ -1583,8 +1546,7 @@ private: "[test.cpp:4]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str()); } - void localvar20() // ticket #1799 - { + void localvar20() { // ticket #1799 functionVariableUsage("void foo()\n" "{\n" " char c1 = 'c';\n" @@ -1594,8 +1556,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar21() // ticket #1807 - { + void localvar21() { // ticket #1807 functionVariableUsage("void foo()\n" "{\n" " char buffer[1024];\n" @@ -1604,8 +1565,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar22() // ticket #1811 - { + void localvar22() { // ticket #1811 functionVariableUsage("int foo(int u, int v)\n" "{\n" " int h, i;\n" @@ -1616,8 +1576,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar23() // ticket #1808 - { + void localvar23() { // ticket #1808 functionVariableUsage("int foo(int c)\n" "{\n" " int a;\n" @@ -1628,8 +1587,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); } - void localvar24() // ticket #1803 - { + void localvar24() { // ticket #1803 functionVariableUsage("class MyException\n" "{\n" " virtual void raise() const\n" @@ -1640,8 +1598,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar25() // ticket #1729 - { + void localvar25() { // ticket #1729 functionVariableUsage("int main() {\n" " int ppos = 1;\n" " int pneg = 0;\n" @@ -1652,8 +1609,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar26() // ticket #1894 - { + void localvar26() { // ticket #1894 functionVariableUsage("int main() {\n" " const Fred &fred = getfred();\n" " int *p = fred.x();\n" @@ -1662,8 +1618,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar27() // ticket #2160 - { + void localvar27() { // ticket #2160 functionVariableUsage("void f(struct s *ptr) {\n" " int param = 1;\n" " ptr->param = param++;\n" @@ -1671,8 +1626,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar28() // ticket #2205 - { + void localvar28() { // ticket #2205 functionVariableUsage("void f(char* buffer, int value) {\n" " char* pos = buffer;\n" " int size = value;\n" @@ -1681,8 +1635,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar29() // ticket #2206 - { + void localvar29() { // ticket #2206 functionVariableUsage("void f() {\n" " float s_ranges[] = { 0, 256 };\n" " float* ranges[] = { s_ranges };\n" @@ -1691,8 +1644,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar30() // ticket #2264 - { + void localvar30() { // ticket #2264 functionVariableUsage("void f() {\n" " Engine *engine = e;\n" " x->engine = engine->clone();\n" @@ -1700,8 +1652,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar31() // ticket #2286 - { + void localvar31() { // ticket #2286 functionVariableUsage("void f() {\n" " int x = 0;\n" " a.x = x - b;\n" @@ -1709,8 +1660,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar32() - { + void localvar32() { // ticket #2330 - fstream >> x functionVariableUsage("void f() {\n" " int x;\n" @@ -1756,8 +1706,7 @@ private: "[test.cpp:2]: (style) Variable 'y' is not assigned a value.\n", errout.str()); } - void localvar33() // ticket #2345 - { + void localvar33() { // ticket #2345 functionVariableUsage("void f() {\n" " Abc* abc = getabc();\n" " while (0 != (abc = abc->next())) {\n" @@ -1767,8 +1716,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar34() // ticket #2368 - { + void localvar34() { // ticket #2368 functionVariableUsage("void f() {\n" " int i = 0;\n" " if (false) {\n" @@ -1779,8 +1727,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar35() // ticket #2535 - { + void localvar35() { // ticket #2535 functionVariableUsage("void f() {\n" " int a, b;\n" " x(1,a,b);\n" @@ -1788,8 +1735,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar36() // ticket #2805 - { + void localvar36() { // ticket #2805 functionVariableUsage("int f() {\n" " int a, b;\n" " a = 2 * (b = 3);\n" @@ -1804,8 +1750,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar37() // ticket #3078 - { + void localvar37() { // ticket #3078 functionVariableUsage("void f() {\n" " int a = 2;\n" " ints.at(a) = 0;\n" @@ -1813,8 +1758,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar38() - { + void localvar38() { functionVariableUsage("std::string f() {\n" " const char code[] = \"foo\";\n" " const std::string s1(sizeof_(code));\n" @@ -1824,8 +1768,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar39() - { + void localvar39() { functionVariableUsage("void f() {\n" " int a = 1;\n" " foo(x*a);\n" @@ -1833,8 +1776,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar40() - { + void localvar40() { functionVariableUsage("int f() {\n" " int a = 1;\n" " return x & a;\n" @@ -1842,8 +1784,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar41() - { + void localvar41() { // #3603 - false positive 'x is assigned a value that is never used' functionVariableUsage("int f() {\n" " int x = 1;\n" @@ -1853,8 +1794,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar42() // #3742 - { + void localvar42() { // #3742 functionVariableUsage("float g_float = 1;\n" "extern void SomeTestFunc(float);\n" "void MyFuncError()\n" @@ -1886,8 +1826,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar43() // ticket #3602 (false positive) - { + void localvar43() { // ticket #3602 (false positive) functionVariableUsage("void bar()\n" "{\n" " int * piArray = NULL;\n" @@ -1913,8 +1852,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar44() // #4020 - FP - { + void localvar44() { // #4020 - FP functionVariableUsage("void func() {\n" " int *sp_mem[2] = { 0x00, 0x00 };\n" " int src = 1, dst = 2;\n" @@ -1923,8 +1861,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar45() // #4899 - FP - { + void localvar45() { // #4899 - FP functionVariableUsage("int func() {\n" " int a = 123;\n" " int b = (short)-a;;\n" @@ -1933,8 +1870,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvar46() // #5491/#5494 - { + void localvar46() { // #5491/#5494 functionVariableUsage("int func() {\n" " int i = 0;\n" " int j{i};\n" @@ -1950,8 +1886,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias1() - { + void localvaralias1() { functionVariableUsage("void foo()\n" "{\n" " int a;\n" @@ -2415,8 +2350,7 @@ private: "[test.cpp:9]: (style) Variable 'c' is assigned a value that is never used.\n", errout.str()); } - void localvaralias2() // ticket 1637 - { + void localvaralias2() { // ticket 1637 functionVariableUsage("void foo()\n" "{\n" " int * a;\n" @@ -2425,8 +2359,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias3() // ticket 1639 - { + void localvaralias3() { // ticket 1639 functionVariableUsage("void foo()\n" "{\n" " BROWSEINFO info;\n" @@ -2437,8 +2370,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias4() // ticket 1643 - { + void localvaralias4() { // ticket 1643 functionVariableUsage("struct AB { int a; int b; } ab;\n" "void foo()\n" "{\n" @@ -2473,8 +2405,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias5() // ticket 1647 - { + void localvaralias5() { // ticket 1647 functionVariableUsage("char foo()\n" "{\n" " char buf[8];\n" @@ -2512,8 +2443,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias6() // ticket 1729 - { + void localvaralias6() { // ticket 1729 functionVariableUsage("void foo()\n" "{\n" " char buf[8];\n" @@ -2648,8 +2578,7 @@ private: ASSERT_EQUALS("[test.cpp:5]: (style) Unused variable: vdata\n", errout.str()); } - void localvaralias7() // ticket 1732 - { + void localvaralias7() { // ticket 1732 functionVariableUsage("void foo()\n" "{\n" " char *c[10];\n" @@ -2660,8 +2589,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias8() - { + void localvaralias8() { functionVariableUsage("void foo()\n" "{\n" " char b1[8];\n" @@ -2846,8 +2774,7 @@ private: "[test.cpp:5]: (style) Unused variable: b3\n", errout.str()); } - void localvaralias9() // ticket 1996 - { + void localvaralias9() { // ticket 1996 functionVariableUsage("void foo()\n" "{\n" " Foo foo;\n" @@ -2866,8 +2793,7 @@ private: ASSERT_EQUALS("[test.c:5]: (style) Variable 'foo' is assigned a value that is never used.\n", errout.str()); } - void localvaralias10() // ticket 2004 - { + void localvaralias10() { // ticket 2004 functionVariableUsage("void foo(Foo &foo)\n" "{\n" " Foo &ref = foo;\n" @@ -2886,8 +2812,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias11() // #4423 - iterator - { + void localvaralias11() { // #4423 - iterator functionVariableUsage("void f(Foo &foo) {\n" " std::set::iterator x = foo.dostuff();\n" " *(x) = 0;\n" @@ -2895,8 +2820,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias12() // #4394 - { + void localvaralias12() { // #4394 functionVariableUsage("void f(void) {\n" " int a[4];\n" " int *b = (int*)((int*)a+1);\n" @@ -2912,8 +2836,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvaralias13() // #4487 - { + void localvaralias13() { // #4487 functionVariableUsage("void f(char *p) {\n" " char a[4];\n" " p = a;\n" @@ -2929,8 +2852,7 @@ private: TODO_ASSERT_EQUALS("a is assigned value that is never used", "", errout.str()); } - void localvarasm() - { + void localvarasm() { functionVariableUsage("void foo(int &b)\n" "{\n" " int a;\n" @@ -2940,8 +2862,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarStruct1() - { + void localvarStruct1() { functionVariableUsage("void foo()\n" "{\n" " static const struct{ int x, y, w, h; } bounds = {1,2,3,4};\n" @@ -2950,8 +2871,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarStruct2() - { + void localvarStruct2() { functionVariableUsage("void foo()\n" "{\n" " struct ABC { int a, b, c; };\n" @@ -2960,8 +2880,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Variable 'abc' is assigned a value that is never used.\n", errout.str()); } - void localvarStruct3() - { + void localvarStruct3() { functionVariableUsage("void foo()\n" "{\n" " int a = 10;\n" @@ -2974,8 +2893,7 @@ private: "[test.cpp:4]: (style) Unused variable: z\n", "", errout.str()); } - void localvarStruct5() - { + void localvarStruct5() { functionVariableUsage("int foo() {\n" " A a;\n" " return a.i;\n" @@ -3090,8 +3008,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (style) Unused variable: a\n", errout.str()); } - void localvarStruct6() - { + void localvarStruct6() { functionVariableUsage("class Type { };\n" "class A {\n" "public:\n" @@ -3102,8 +3019,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarStructArray() - { + void localvarStructArray() { // #3633 - detect that struct array is assigned a value functionVariableUsage("void f() {\n" " struct X x[10];\n" @@ -3112,8 +3028,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); } - void localvarOp() - { + void localvarOp() { const char op[] = "+-*/%&|^"; for (const char *p = op; *p; ++p) { std::string code("int main()\n" @@ -3126,8 +3041,7 @@ private: } } - void localvarInvert() - { + void localvarInvert() { functionVariableUsage("int main()\n" "{\n" " int tmp = 10;\n" @@ -3136,8 +3050,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarIf() - { + void localvarIf() { functionVariableUsage("int main()\n" "{\n" " int tmp = 10;\n" @@ -3148,8 +3061,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarIfElse() - { + void localvarIfElse() { functionVariableUsage("int foo()\n" "{\n" " int tmp1 = 1;\n" @@ -3160,8 +3072,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarOpAssign() - { + void localvarOpAssign() { functionVariableUsage("void foo()\n" "{\n" " int a = 1;\n" @@ -3177,8 +3088,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarFor() - { + void localvarFor() { functionVariableUsage("void foo()\n" "{\n" " int a = 1;\n" @@ -3193,8 +3103,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarForEach() // #4155 - foreach - { + void localvarForEach() { // #4155 - foreach functionVariableUsage("void foo() {\n" " int i = -1;\n" " int a[] = {1,2,3};\n" @@ -3246,8 +3155,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarShift1() - { + void localvarShift1() { functionVariableUsage("int foo()\n" "{\n" " int var = 1;\n" @@ -3256,8 +3164,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarShift2() - { + void localvarShift2() { functionVariableUsage("int foo()\n" "{\n" " int var = 1;\n" @@ -3266,8 +3173,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarShift3() // #3509 - { + void localvarShift3() { // #3509 functionVariableUsage("int foo()\n" "{\n" " QList ints;\n" @@ -3283,8 +3189,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarCast() - { + void localvarCast() { functionVariableUsage("int foo()\n" "{\n" " int a = 1;\n" @@ -3294,8 +3199,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarClass() - { + void localvarClass() { functionVariableUsage("int foo()\n" "{\n" " class B : public A {\n" @@ -3306,8 +3210,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarUnused() - { + void localvarUnused() { functionVariableUsage("int foo()\n" "{\n" " bool test __attribute__((unused));\n" @@ -3345,8 +3248,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarFunction() - { + void localvarFunction() { functionVariableUsage("void check_dlsym(void*& h)\n" "{\n" " typedef void (*function_type) (void);\n" @@ -3357,8 +3259,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarstatic() - { + void localvarstatic() { functionVariableUsage("void foo()\n" "{\n" " static int i;\n" @@ -3403,8 +3304,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarextern() - { + void localvarextern() { functionVariableUsage("void foo() {\n" " extern int i;\n" " i = 0;\n" @@ -3412,8 +3312,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvardynamic1() - { + void localvardynamic1() { functionVariableUsage("void foo()\n" "{\n" " void* ptr = malloc(16);\n" @@ -3530,8 +3429,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvardynamic2() - { + void localvardynamic2() { functionVariableUsage("struct Fred { int i; };\n" "void foo()\n" "{\n" @@ -3651,8 +3549,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvardynamic3() - { + void localvardynamic3() { // Ticket #3477 - False positive that 'data' is not assigned a value functionVariableUsage("void foo() {\n" " int* data = new int[100];\n" @@ -3663,8 +3560,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvararray1() - { + void localvararray1() { functionVariableUsage("void foo() {\n" " int p[5];\n" " *p = 0;\n" @@ -3672,8 +3568,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvararray2() - { + void localvararray2() { functionVariableUsage("int foo() {\n" " int p[5][5];\n" " p[0][0] = 0;\n" @@ -3682,8 +3577,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvararray3() - { + void localvararray3() { functionVariableUsage("int foo() {\n" " int p[5][5];\n" " *((int*)p[0]) = 0;\n" @@ -3692,8 +3586,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarstring1() // ticket #1597 - { + void localvarstring1() { // ticket #1597 functionVariableUsage("void foo() {\n" " std::string s;\n" "}"); @@ -3723,8 +3616,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarstring2() // ticket #2929 - { + void localvarstring2() { // ticket #2929 functionVariableUsage("void foo() {\n" " std::string s;\n" " int i;\n" @@ -3733,16 +3625,14 @@ private: "[test.cpp:3]: (style) Unused variable: i\n", errout.str()); } - void localvarconst1() - { + void localvarconst1() { functionVariableUsage("void foo() {\n" " const bool b = true;\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'b' is assigned a value that is never used.\n", errout.str()); } - void localvarconst2() - { + void localvarconst2() { functionVariableUsage("void foo() {\n" " const int N = 10;\n" " struct X { int x[N]; };\n" @@ -3750,8 +3640,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarthrow() // ticket #3687 - { + void localvarthrow() { // ticket #3687 functionVariableUsage("void foo() {\n" " try {}" " catch(Foo& bar) {}\n" @@ -3759,8 +3648,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localVarStd() - { + void localVarStd() { functionVariableUsage("void f() {\n" " std::string x = foo();\n" "}"); @@ -3804,8 +3692,7 @@ private: } // ticket #3104 - false positive when variable is read with "if (NOT var)" - void localvarIfNOT() - { + void localvarIfNOT() { functionVariableUsage("void f() {\n" " bool x = foo();\n" " if (NOT x) { }\n" @@ -3813,8 +3700,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarAnd() // #3672 - { + void localvarAnd() { // #3672 functionVariableUsage("int main() {\n" " unsigned flag = 0x1 << i;\n" " if (m_errorflags & flag) {\n" @@ -3824,8 +3710,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarSwitch() // #3744 - false positive when used in switch - { + void localvarSwitch() { // #3744 - false positive when used in switch functionVariableUsage("const char *f(int x) {\n" " const char a[] = \"abc\";\n" " const char def[] = \"def\";\n" @@ -3841,8 +3726,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarNULL() // #4203 - Setting NULL value is not redundant - it is safe - { + void localvarNULL() { // #4203 - Setting NULL value is not redundant - it is safe functionVariableUsage("void f() {\n" " char *p = malloc(100);\n" " foo(p);\n" @@ -3852,8 +3736,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarUnusedGoto() - { + void localvarUnusedGoto() { // #4447 functionVariableUsage("bool f(const int &i) {\n" " int X = i;\n" @@ -3884,8 +3767,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void localvarCpp11Initialization() - { + void localvarCpp11Initialization() { // #6160 functionVariableUsage("void foo() {\n" " int myNewValue{ 3u };\n" @@ -3894,8 +3776,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void chainedAssignment() - { + void chainedAssignment() { // #5466 functionVariableUsage("void NotUsed(double* pdD, int n) {\n" " double sum = 0.0;\n" @@ -3905,16 +3786,14 @@ private: ASSERT_EQUALS("", errout.str()); } - void crash1() - { + void crash1() { functionVariableUsage("SAL_WNODEPRECATED_DECLARATIONS_PUSH\n" "void convertToTokenArray() {\n" "}\n" "SAL_WNODEPRECATED_DECLARATIONS_POP"); // #4033 } - void crash2() - { + void crash2() { functionVariableUsage("template\n" "struct Y: Y { };\n" "template<>\n" @@ -3924,8 +3803,7 @@ private: "}"); // #4695 } - void usingNamespace() - { + void usingNamespace() { functionVariableUsage("int foo() {\n" " using namespace ::com::sun::star::i18n;\n" " bool b = false;\n" diff --git a/test/testutils.h b/test/testutils.h index 1cd21032e..01b2cece6 100644 --- a/test/testutils.h +++ b/test/testutils.h @@ -31,8 +31,7 @@ private: public: explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true) - : _tokenizer(&_settings, 0) - { + : _tokenizer(&_settings, 0) { std::istringstream iss(sample); if (createOnly) _tokenizer.list.createTokens(iss, cpp ? "test.cpp" : "test.c"); @@ -40,8 +39,7 @@ public: _tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c"); } - const Token* tokens() const - { + const Token* tokens() const { return _tokenizer.tokens(); } }; @@ -50,15 +48,12 @@ public: class SimpleSuppressor : public ErrorLogger { public: SimpleSuppressor(Settings &settings, ErrorLogger *next) - : _settings(settings), _next(next) - { + : _settings(settings), _next(next) { } - virtual void reportOut(const std::string &outmsg) - { + virtual void reportOut(const std::string &outmsg) { _next->reportOut(outmsg); } - virtual void reportErr(const ErrorLogger::ErrorMessage &msg) - { + virtual void reportErr(const ErrorLogger::ErrorMessage &msg) { if (!msg._callStack.empty() && !_settings.nomsg.isSuppressed(msg._id, msg._callStack.begin()->getfile(), msg._callStack.begin()->line)) _next->reportErr(msg); } diff --git a/test/testvaarg.cpp b/test/testvaarg.cpp index b05c35570..8d152f39b 100644 --- a/test/testvaarg.cpp +++ b/test/testvaarg.cpp @@ -28,8 +28,7 @@ public: TestVaarg() : TestFixture("TestVaarg") {} private: - void check(const char code[]) - { + void check(const char code[]) { // Clear the error buffer.. errout.str(""); @@ -46,8 +45,7 @@ private: checkVaarg.runSimplifiedChecks(&tokenizer, &settings, this); } - void run() - { + void run() { TEST_CASE(wrongParameterTo_va_start); TEST_CASE(referenceAs_va_start); TEST_CASE(va_end_missing); @@ -55,8 +53,7 @@ private: TEST_CASE(va_start_subsequentCalls); } - void wrongParameterTo_va_start() - { + void wrongParameterTo_va_start() { check("void Format(char* szFormat, char* szBuffer, size_t nSize, ...) {\n" " va_list arg_ptr;\n" " va_start(arg_ptr, szFormat);\n" @@ -95,8 +92,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void referenceAs_va_start() - { + void referenceAs_va_start() { check("void Format(char* szFormat, char (&szBuffer)[_Size], ...) {\n" " va_list arg_ptr;\n" " va_start(arg_ptr, szBuffer);\n" @@ -112,8 +108,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void va_end_missing() - { + void va_end_missing() { check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n" " va_list arg_ptr;\n" " va_start(arg_ptr, szBuffer);\n" @@ -148,8 +143,7 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) va_list 'arg_ptr' was opened but not closed by va_end().\n", errout.str()); } - void va_list_usedBeforeStarted() - { + void va_list_usedBeforeStarted() { check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n" " va_list arg_ptr;\n" " return va_arg(arg_ptr, float);\n" @@ -196,8 +190,7 @@ private: ASSERT_EQUALS("", errout.str()); } - void va_start_subsequentCalls() - { + void va_start_subsequentCalls() { check("void Format(char* szFormat, char (*szBuffer)[_Size], ...) {\n" " va_list arg_ptr;\n" " va_start(arg_ptr, szBuffer);\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index bb0966a95..d105bf7fe 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -28,14 +28,12 @@ extern std::ostringstream errout; class TestValueFlow : public TestFixture { public: - TestValueFlow() : TestFixture("TestValueFlow") - { + TestValueFlow() : TestFixture("TestValueFlow") { } private: - void run() - { + void run() { TEST_CASE(valueFlowNumber); TEST_CASE(valueFlowString); TEST_CASE(valueFlowPointerAlias); @@ -66,8 +64,7 @@ private: TEST_CASE(valueFlowFunctionReturn); } - bool testValueOfX(const char code[], unsigned int linenr, int value) - { + bool testValueOfX(const char code[], unsigned int linenr, int value) { Settings settings; // strcpy cfg @@ -96,8 +93,7 @@ private: } - bool testValueOfX(const char code[], unsigned int linenr, const char value[]) - { + bool testValueOfX(const char code[], unsigned int linenr, const char value[]) { Settings settings; // strcpy cfg @@ -125,8 +121,7 @@ private: return false; } - void bailout(const char code[]) - { + void bailout(const char code[]) { Settings settings; settings.debugwarnings = true; @@ -137,8 +132,7 @@ private: tokenizer.tokenize(istr, "test.cpp"); } - std::list tokenValues(const char code[], const char tokstr[]) - { + std::list tokenValues(const char code[], const char tokstr[]) { const Settings settings; Tokenizer tokenizer(&settings, this); std::istringstream istr(code); @@ -148,14 +142,12 @@ private: return tok ? tok->values : std::list(); } - ValueFlow::Value valueOfTok(const char code[], const char tokstr[]) - { + ValueFlow::Value valueOfTok(const char code[], const char tokstr[]) { std::list values = tokenValues(code, tokstr); return values.size() == 1U && !values.front().tokvalue ? values.front() : ValueFlow::Value(); } - void valueFlowNumber() - { + void valueFlowNumber() { const char *code; code = "void f() {\n" @@ -164,8 +156,7 @@ private: ASSERT_EQUALS(123, valueOfTok(code, "123").intvalue); } - void valueFlowString() - { + void valueFlowString() { const char *code; // valueFlowAfterAssign @@ -185,8 +176,7 @@ private: ASSERT_EQUALS(true, testValueOfX(code, 2, "\"abc\"")); } - void valueFlowPointerAlias() - { + void valueFlowPointerAlias() { const char *code; code = "const char * f() {\n" @@ -206,8 +196,7 @@ private: ASSERT_EQUALS(true, testValueOfX(code, 4, "& i")); } - void valueFlowCalculations() - { + void valueFlowCalculations() { const char *code; /* code = "void f() {\n" @@ -269,8 +258,7 @@ private: } } - void valueFlowBeforeCondition() - { + void valueFlowBeforeCondition() { const char *code; code = "void f(int x) {\n" @@ -318,8 +306,7 @@ private: ASSERT_EQUALS(true, testValueOfX(code, 3U, 123)); } - void valueFlowBeforeConditionAssignIncDec() // assignment / increment - { + void valueFlowBeforeConditionAssignIncDec() { // assignment / increment const char *code; code = "void f(int x) {\n" @@ -355,8 +342,7 @@ private: ASSERT_EQUALS("[test.cpp:2]: (debug) ValueFlow bailout: assignment of x\n", errout.str()); } - void valueFlowBeforeConditionAndAndOrOrGuard() // guarding by && - { + void valueFlowBeforeConditionAndAndOrOrGuard() { // guarding by && const char *code; code = "void f(int x) {\n" @@ -375,8 +361,7 @@ private: ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); } - void valueFlowBeforeConditionFunctionCall() // function calls - { + void valueFlowBeforeConditionFunctionCall() { // function calls const char *code; code = "void f(int x) {\n" @@ -403,8 +388,7 @@ private: ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); } - void valueFlowBeforeConditionLoop() // while, for, do-while - { + void valueFlowBeforeConditionLoop() { // while, for, do-while const char *code; code = "void f(int x) {\n" // loop condition, x is not assigned inside loop => use condition @@ -451,8 +435,7 @@ private: ASSERT_EQUALS(false, testValueOfX(code, 2U, 0)); } - void valueFlowBeforeConditionTernaryOp() // bailout: ?: - { + void valueFlowBeforeConditionTernaryOp() { // bailout: ?: const char *code; bailout("void f(int x) {\n" @@ -481,8 +464,7 @@ private: ASSERT_EQUALS(true, testValueOfX(code, 2U, 123)); } - void valueFlowBeforeConditionSizeof() // skip sizeof - { + void valueFlowBeforeConditionSizeof() { // skip sizeof const char *code; code = "void f(int *x) {\n" @@ -498,8 +480,7 @@ private: ASSERT_EQUALS(false, testValueOfX(code, 2U, 0)); } - void valueFlowBeforeConditionIfElse() // bailout: if/else/etc - { + void valueFlowBeforeConditionIfElse() { // bailout: if/else/etc const char *code; code = "void f(X * x) {\n" @@ -528,8 +509,7 @@ private: ASSERT_EQUALS(true, testValueOfX(code, 2U, 7)); } - void valueFlowBeforeConditionGlobalVariables() - { + void valueFlowBeforeConditionGlobalVariables() { // bailout: global variables bailout("int x;\n" "void f() {\n" @@ -549,8 +529,7 @@ private: ASSERT_EQUALS(false, testValueOfX(code,3,234)); } - void valueFlowBeforeConditionSwitch() - { + void valueFlowBeforeConditionSwitch() { // bailout: switch // TODO : handle switch/goto more intelligently bailout("void f(int x, int y) {\n" @@ -570,8 +549,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x stopping on return\n", errout.str()); } - void valueFlowBeforeConditionMacro() - { + void valueFlowBeforeConditionMacro() { // bailout: condition is a expanded macro bailout("void f(int x) {\n" " a = x;\n" @@ -580,8 +558,7 @@ private: ASSERT_EQUALS("[test.cpp:3]: (debug) ValueFlow bailout: variable x, condition is defined in macro\n", errout.str()); } - void valueFlowBeforeConditionGoto() - { + void valueFlowBeforeConditionGoto() { // bailout: goto label (TODO: handle gotos more intelligently) bailout("void f(int x) {\n" " if (x == 123) { goto out; }\n" @@ -610,8 +587,7 @@ private: errout.str()); } - void valueFlowAfterAssign() - { + void valueFlowAfterAssign() { const char *code; code = "void f() {\n" @@ -961,8 +937,7 @@ private: ASSERT_EQUALS(true, testValueOfX(code, 9U, 0)); // x can be 0 at line 9 } - void valueFlowAfterCondition() - { + void valueFlowAfterCondition() { const char *code; // if @@ -1139,8 +1114,7 @@ private: ASSERT_EQUALS(false, testValueOfX(code, 3U, 0)); } - void valueFlowBitAnd() - { + void valueFlowBitAnd() { const char *code; code = "int f(int a) {\n" @@ -1151,8 +1125,7 @@ private: ASSERT_EQUALS(true, testValueOfX(code,3U,0x80)); } - void valueFlowForLoop() - { + void valueFlowForLoop() { const char *code; code = "void f() {\n" @@ -1292,8 +1265,7 @@ private: testValueOfX(code,0,0); // <- dont hang } - void valueFlowSubFunction() - { + void valueFlowSubFunction() { const char *code; code = "void f1(int x) { return x; }\n" @@ -1362,8 +1334,7 @@ private: ASSERT_EQUALS(true, testValueOfX(code, 2U, 2)); } - void valueFlowFunctionReturn() - { + void valueFlowFunctionReturn() { const char *code; code = "void f1(int x) {\n" diff --git a/test/testvarid.cpp b/test/testvarid.cpp index d4f1ed170..ffb490a95 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -28,14 +28,12 @@ extern std::ostringstream errout; class TestVarID : public TestFixture { public: - TestVarID() : TestFixture("TestVarID") - { + TestVarID() : TestFixture("TestVarID") { } private: - void run() - { + void run() { TEST_CASE(varid1); TEST_CASE(varid2); TEST_CASE(varid3); @@ -162,8 +160,7 @@ private: TEST_CASE(varidnamespace1); } - std::string tokenize(const char code[], bool simplify = false, const char filename[] = "test.cpp") - { + std::string tokenize(const char code[], bool simplify = false, const char filename[] = "test.cpp") { errout.str(""); Settings settings; @@ -181,8 +178,7 @@ private: return tokenizer.tokens()->stringifyList(true); } - void varid1() - { + void varid1() { { const std::string actual = tokenize( "static int i = 1;\n" @@ -236,8 +232,7 @@ private: } } - void varid2() - { + void varid2() { const std::string actual = tokenize( "void f()\n" "{\n" @@ -257,8 +252,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid3() - { + void varid3() { const std::string actual = tokenize( "static char str[4];\n" "void f()\n" @@ -278,8 +272,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid4() - { + void varid4() { const std::string actual = tokenize( "void f(const unsigned int a[])\n" "{\n" @@ -295,8 +288,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid5() - { + void varid5() { const std::string actual = tokenize( "void f()\n" "{\n" @@ -313,8 +305,7 @@ private: } - void varid6() - { + void varid6() { const std::string actual = tokenize( "int f(int a, int b)\n" "{\n" @@ -331,8 +322,7 @@ private: } - void varid7() - { + void varid7() { const std::string actual = tokenize( "void func() {\n" " char a[256] = \"test\";\n" @@ -352,8 +342,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varidReturn1() - { + void varidReturn1() { const std::string actual = tokenize( "int f()\n" "{\n" @@ -371,8 +360,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varidReturn2() - { + void varidReturn2() { const std::string actual = tokenize( "void foo()\n" "{\n" @@ -390,8 +378,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid8() - { + void varid8() { const std::string actual = tokenize( "void func()\n" "{\n" @@ -409,8 +396,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid9() - { + void varid9() { const std::string actual = tokenize( "typedef int INT32;\n", false, "test.c"); @@ -420,8 +406,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid10() - { + void varid10() { const std::string actual = tokenize( "void foo()\n" "{\n" @@ -439,8 +424,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid11() - { + void varid11() { const std::string actual = tokenize( "class Foo;\n"); @@ -450,8 +434,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid12() - { + void varid12() { const std::string actual = tokenize( "static void a()\n" "{\n" @@ -467,8 +450,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid13() - { + void varid13() { const std::string actual = tokenize( "void f()\n" "{\n" @@ -486,8 +468,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid14() - { + void varid14() { // Overloaded operator* const std::string actual = tokenize( "void foo()\n" @@ -508,8 +489,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid15() - { + void varid15() { { const std::string actual = tokenize( "struct S {\n" @@ -543,8 +523,7 @@ private: } } - void varid16() - { + void varid16() { const char code[] ="void foo()\n" "{\n" " int x = 1;\n" @@ -561,8 +540,7 @@ private: ASSERT_EQUALS(expected, tokenize(code, false, "test.c")); } - void varid17() // ticket #1810 - { + void varid17() { // ticket #1810 const char code[] ="char foo()\n" "{\n" " char c('c');\n" @@ -579,8 +557,7 @@ private: ASSERT_EQUALS(expected, tokenize(code, false, "test.c")); } - void varid18() - { + void varid18() { const char code[] ="char foo(char c)\n" "{\n" " bar::c = c;\n" @@ -595,8 +572,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid19() - { + void varid19() { const char code[] ="void foo()\n" "{\n" " std::pair, int> x;\n" @@ -611,8 +587,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid20() - { + void varid20() { const char code[] ="void foo()\n" "{\n" " pair, vector > x;\n" @@ -627,8 +602,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid24() - { + void varid24() { const char code[] ="class foo()\n" "{\n" "public:\n" @@ -649,8 +623,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid25() - { + void varid25() { const char code[] ="class foo()\n" "{\n" "public:\n" @@ -671,16 +644,14 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid26() - { + void varid26() { const char code[] ="list functions;\n"; const std::string expected("\n\n##file 0\n" "1: list < int ( * ) ( ) > functions@1 ;\n"); ASSERT_EQUALS(expected, tokenize(code)); } - void varid27() - { + void varid27() { const char code[] ="int fooled_ya;\n" "fooled_ya::iterator iter;\n"; const std::string expected("\n\n##file 0\n" @@ -689,14 +660,12 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid28() // ticket #2630 (segmentation fault) - { + void varid28() { // ticket #2630 (segmentation fault) tokenize("template \n"); ASSERT_EQUALS("", errout.str()); } - void varid29() - { + void varid29() { const char code[] ="class A {\n" " B,1> b;\n" "};\n"; @@ -707,8 +676,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid30() // ticket #2614 - { + void varid30() { // ticket #2614 const char code1[] = "void f(EventPtr *eventP, ActionPtr **actionsP)\n" "{\n" " EventPtr event = *eventP;\n" @@ -749,29 +717,25 @@ private: ASSERT_EQUALS(expected3, tokenize(code3)); } - void varid31() // ticket #2831 (segmentation fault) - { + void varid31() { // ticket #2831 (segmentation fault) const char code[] ="z"; tokenize(code); ASSERT_EQUALS("", errout.str()); } - void varid32() // ticket #2835 (segmentation fault) - { + void varid32() { // ticket #2835 (segmentation fault) const char code[] ="><,f) - { + void varid49() { // #3799 - void f(std::vector) const char code[] ="void f(std::vector)"; ASSERT_EQUALS("\n\n##file 0\n" "1: void f ( std :: vector < int > )\n", tokenize(code, false, "test.cpp")); } - void varid50() // #3760 - explicit - { + void varid50() { // #3760 - explicit const char code[] ="class A { explicit A(const A&); };"; ASSERT_EQUALS("\n\n##file 0\n" "1: class A { explicit A ( const A & ) ; } ;\n", tokenize(code, false, "test.cpp")); } - void varid51() // don't set varid on template function - { + void varid51() { // don't set varid on template function const char code[] ="T t; t.x<0>();"; ASSERT_EQUALS("\n\n##file 0\n" "1: T t@1 ; t@1 . x < 0 > ( ) ;\n", tokenize(code, false, "test.cpp")); } - void varid52() - { + void varid52() { const char code[] ="A::D> e;\n" "B< C<> > b[10];\n" "B> c[10];"; @@ -994,21 +940,18 @@ private: tokenize(code, false, "test.cpp")); } - void varid53() // #4172 - Template instantiation: T<&functionName> list[4]; - { + void varid53() { // #4172 - Template instantiation: T<&functionName> list[4]; ASSERT_EQUALS("\n\n##file 0\n" "1: A < & f > list@1 [ 4 ] ;\n", tokenize("A<&f> list[4];", false, "test.cpp")); } - void varid54() // hang - { + void varid54() { // hang // Original source code: libgc tokenize("STATIC ptr_t GC_approx_sp(void) { word sp; sp = (word)&sp; return((ptr_t)sp); }",true); } - void varid55() // Ticket #5868 - { + void varid55() { // Ticket #5868 const char code[] = "typedef struct foo {} foo; " "void bar1(struct foo foo) {} " "void baz1(foo foo) {} " @@ -1026,8 +969,7 @@ private: ASSERT_EQUALS(expected, tokenize(code, false, "test.cpp")); } - void varid_cpp_keywords_in_c_code() - { + void varid_cpp_keywords_in_c_code() { const char code[] = "void f() {\n" " delete d;\n" " throw t;\n" @@ -1042,8 +984,7 @@ private: ASSERT_EQUALS(expected, tokenize(code,false,"test.c")); } - void varid_cpp_keywords_in_c_code2() // #5373 - { + void varid_cpp_keywords_in_c_code2() { // #5373 const char code[] = "int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, " "unsigned long bits, int wake, int delete, struct extent_state **cached_state, " "gfp_t mask) {\n" @@ -1056,8 +997,7 @@ private: tokenize(code, false, "test.c"); } - void varidFunctionCall1() - { + void varidFunctionCall1() { const char code[] ="void f() {\n" " int x;\n" " x = a(y*x,10);\n" @@ -1070,8 +1010,7 @@ private: ASSERT_EQUALS(expected, tokenize(code, false, "test.c")); } - void varidFunctionCall2() - { + void varidFunctionCall2() { // #2491 const char code[] ="void f(int b) {\n" " x(a*b,10);\n" @@ -1084,8 +1023,7 @@ private: ASSERT_EQUALS(expected1+"@1"+expected2, tokenize(code,false,"test.c")); } - void varidFunctionCall3() - { + void varidFunctionCall3() { // Ticket #2339 const char code[] ="void f() {\n" " int a = 0;\n" @@ -1101,8 +1039,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidFunctionCall4() - { + void varidFunctionCall4() { // Ticket #3280 const char code1[] = "void f() { int x; fun(a,b*x); }"; ASSERT_EQUALS("\n\n##file 0\n" @@ -1115,8 +1052,7 @@ private: } - void varidStl() - { + void varidStl() { const std::string actual = tokenize( "list ints;\n" "list::iterator it;\n" @@ -1144,15 +1080,13 @@ private: ASSERT_EQUALS(expected, actual); } - void varid_newauto() - { + void varid_newauto() { ASSERT_EQUALS("\n\n##file 0\n" "1: void f ( ) { const new auto ( 0 ) ; }\n", tokenize("void f(){new const auto(0);}")); } - void varid_delete() - { + void varid_delete() { const std::string actual = tokenize( "void f()\n" "{\n" @@ -1170,8 +1104,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid_functions() - { + void varid_functions() { { const std::string actual = tokenize( "void f();\n" @@ -1247,16 +1180,14 @@ private: } } - void varid_sizeof() - { + void varid_sizeof() { const char code[] = "x = sizeof(a*b);"; const char expected[] = "\n\n##file 0\n" "1: x = sizeof ( a * b ) ;\n"; ASSERT_EQUALS(expected, tokenize(code,false,"test.c")); } - void varid_reference_to_containers() - { + void varid_reference_to_containers() { const std::string actual = tokenize( "void f()\n" "{\n" @@ -1276,8 +1207,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid_in_class1() - { + void varid_in_class1() { { const std::string actual = tokenize( "class Foo\n" @@ -1333,8 +1263,7 @@ private: } } - void varid_in_class2() - { + void varid_in_class2() { const std::string actual = tokenize( "struct Foo {\n" " int x;\n" @@ -1368,8 +1297,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid_in_class3() - { + void varid_in_class3() { const char code[] = "class Foo {\n" " void blah() {\n" " Bar x(*this);\n" // <- .. @@ -1385,8 +1313,7 @@ private: "6: } ;\n", tokenize(code)); } - void varid_in_class4() - { + void varid_in_class4() { const char code[] = "class Foo {\n" "public: class C;\n" "};"; @@ -1397,8 +1324,7 @@ private: tokenize(code)); } - void varid_in_class5() - { + void varid_in_class5() { const char code[] = "struct Foo {\n" " std::vector<::X> v;\n" "}"; @@ -1409,8 +1335,7 @@ private: tokenize(code)); } - void varid_in_class6() - { + void varid_in_class6() { const char code[] = "class A {\n" " void f(const char *str) const {\n" " std::stringstream sst;\n" @@ -1427,8 +1352,7 @@ private: tokenize(code)); } - void varid_in_class7() - { + void varid_in_class7() { const char code[] = "class A {\n" " void f() {\n" " abc.a = 0;\n" @@ -1445,8 +1369,7 @@ private: tokenize(code)); } - void varid_in_class8() // #3776 - unknown macro - { + void varid_in_class8() { // #3776 - unknown macro const char code[] = "class A {\n" " UNKNOWN_MACRO(A)\n" "private:\n" @@ -1461,8 +1384,7 @@ private: tokenize(code)); } - void varid_in_class9() // #4291 - id for variables accessed through 'this' - { + void varid_in_class9() { // #4291 - id for variables accessed through 'this' const char code1[] = "class A {\n" " int var;\n" "public:\n" @@ -1500,8 +1422,7 @@ private: tokenize(code2)); // #4311 } - void varid_in_class10() - { + void varid_in_class10() { const char code[] = "class Foo : public FooBase {\n" " void Clone(FooBase& g);\n" " short m_bar;\n" @@ -1528,8 +1449,7 @@ private: tokenize(code)); } - void varid_in_class11() // #4277 - anonymous union - { + void varid_in_class11() { // #4277 - anonymous union const char code1[] = "class Foo {\n" " union { float a; int b; };\n" " void f() { a=0; }\n" @@ -1553,8 +1473,7 @@ private: tokenize(code2)); } - void varid_in_class12() // #4637 - method - { + void varid_in_class12() { // #4637 - method const char code[] = "class Foo {\n" "private:\n" " void f(void);\n" @@ -1567,8 +1486,7 @@ private: tokenize(code)); } - void varid_in_class13() - { + void varid_in_class13() { const char code1[] = "struct a { char typename; };"; ASSERT_EQUALS("\n\n##file 0\n" "1: struct a { char typename@1 ; } ;\n", @@ -1586,8 +1504,7 @@ private: tokenize(code2, false, "test.cpp")); } - void varid_in_class14() - { + void varid_in_class14() { const char code[] = "class Tokenizer { TokenList list; };\n" "\n" "void Tokenizer::f() {\n" @@ -1605,8 +1522,7 @@ private: "7: }\n", tokenize(code, false, "test.cpp")); } - void varid_in_class15() // #5533 - functions - { + void varid_in_class15() { // #5533 - functions const char code[] = "class Fred {\n" " void x(int a) const;\n" " void y() { a=0; }\n" // <- unknown variable @@ -1618,8 +1534,7 @@ private: "4: }\n", tokenize(code, false, "test.cpp")); } - void varid_in_class16() // Set varId for inline member functions - { + void varid_in_class16() { // Set varId for inline member functions const char code[] = "class Fred {\n" " int x;\n" " void foo(int x) { this->x = x; }\n" @@ -1631,8 +1546,7 @@ private: "4: } ;\n", tokenize(code, false, "test.cpp")); } - void varid_in_class17() // #6056 - Set no varid for member functions - { + void varid_in_class17() { // #6056 - Set no varid for member functions const char code1[] = "class Fred {\n" " int method_with_internal(X&);\n" " int method_with_internal(X*);\n" @@ -1672,8 +1586,7 @@ private: "5: SomeType someVar4@4 ( new bar ) ;\n", tokenize(code2, false, "test.cpp")); } - void varid_initList() - { + void varid_initList() { const char code1[] = "class A {\n" " A() : x(0) {}\n" " int x;\n" @@ -1721,8 +1634,7 @@ private: tokenize(code4)); } - void varid_operator() - { + void varid_operator() { { const std::string actual = tokenize( "class Foo\n" @@ -1754,8 +1666,7 @@ private: } } - void varid_throw() // ticket #1723 - { + void varid_throw() { // ticket #1723 const std::string actual = tokenize( "UserDefinedException* pe = new UserDefinedException();\n" "throw pe;\n"); @@ -1767,8 +1678,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varid_unknown_macro() - { + void varid_unknown_macro() { // #2638 - unknown macro const char code[] = "void f() {\n" " int a[10];\n" @@ -1784,8 +1694,7 @@ private: ASSERT_EQUALS(expected, tokenize(code, false, "test.c")); } - void varid_using() - { + void varid_using() { // #3648 const char code[] = "using std::size_t;"; const char expected[] = "\n\n##file 0\n" @@ -1793,8 +1702,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid_catch() - { + void varid_catch() { const char code[] = "void f() {\n" " try { dostuff(); }\n" " catch (exception &e) { }\n" @@ -1807,33 +1715,28 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid_functionPrototypeTemplate() - { + void varid_functionPrototypeTemplate() { ASSERT_EQUALS("\n\n##file 0\n" "1: function < void ( ) > fptr@1 ;\n", tokenize("function fptr;")); } - void varid_templatePtr() - { + void varid_templatePtr() { ASSERT_EQUALS("\n\n##file 0\n" "1: std :: map < int , FooTemplate < int > * > dummy_member@1 [ 1 ] ;\n", tokenize("std::map*> dummy_member[1];")); } - void varid_templateNamespaceFuncPtr() - { + void varid_templateNamespaceFuncPtr() { ASSERT_EQUALS("\n\n##file 0\n" "1: KeyListT < float , & NIFFile :: getFloat > mKeyList@1 [ 4 ] ;\n", tokenize("KeyListT mKeyList[4];")); } - void varid_templateArray() - { + void varid_templateArray() { ASSERT_EQUALS("\n\n##file 0\n" "1: VertexArrayIterator < float [ 2 ] > attrPos@1 ; attrPos@1 = m_AttributePos . GetIterator < float [ 2 ] > ( ) ;\n", tokenize("VertexArrayIterator attrPos = m_AttributePos.GetIterator();")); } - void varid_cppcast() - { + void varid_cppcast() { ASSERT_EQUALS("\n\n##file 0\n1: const_cast < int * > ( code ) [ 0 ] = 0 ;\n", tokenize("const_cast(code)[0] = 0;")); @@ -1847,14 +1750,12 @@ private: tokenize("static_cast(code)[0] = 0;")); } - void varid_variadicFunc() - { + void varid_variadicFunc() { ASSERT_EQUALS("\n\n##file 0\n" "1: int foo ( . . . ) ;\n", tokenize("int foo(...);")); } - void varid_typename() - { + void varid_typename() { ASSERT_EQUALS("\n\n##file 0\n" "1: template < int d , class A , class B >\n", tokenize("template")); @@ -1865,8 +1766,7 @@ private: "1: typename A a@1 ;\n", tokenize("typename A a;")); } - void varid_rvalueref() - { + void varid_rvalueref() { ASSERT_EQUALS("\n\n##file 0\n" "1: int & & a@1 ;\n", tokenize("int&& a;")); @@ -1885,14 +1785,12 @@ private: "1: void foo ( int & & ) ;\n", tokenize("void foo(int&&);")); } - void varid_arrayFuncPar() - { + void varid_arrayFuncPar() { ASSERT_EQUALS("\n\n##file 0\n" "1: void check ( const char fname@1 [ ] = 0 ) { }\n", tokenize("void check( const char fname[] = 0) { }")); } - void varid_sizeofPassed() - { + void varid_sizeofPassed() { ASSERT_EQUALS("\n\n##file 0\n" "1: void which_test ( ) {\n" "2: const char * argv@1 [ 2 ] = { \"./test_runner\" , \"TestClass\" } ;\n" @@ -1906,8 +1804,7 @@ private: "}")); } - void varid_classInFunction() - { + void varid_classInFunction() { ASSERT_EQUALS("\n\n##file 0\n" "1: void AddSuppression ( ) {\n" "2: class QErrorLogger {\n" @@ -1923,8 +1820,7 @@ private: "}")); } - void varid_pointerToArray() - { + void varid_pointerToArray() { ASSERT_EQUALS("\n\n##file 0\n" "1: int * a1@1 [ 10 ] ;\n" "2: void f1 ( ) {\n" @@ -1950,8 +1846,7 @@ private: "int f4(int(&a6)[10], int i) { return a6[i]; }")); } - void varid_cpp11initialization() - { + void varid_cpp11initialization() { ASSERT_EQUALS("\n\n##file 0\n" "1: int i@1 { 1 } ;\n" "2: std :: vector < int > vec@2 { 1 , 2 , 3 } ;\n" @@ -1990,8 +1885,7 @@ private: "};")); } - void varid_inheritedMembers() - { + void varid_inheritedMembers() { ASSERT_EQUALS("\n\n##file 0\n" "1: class A {\n" "2: int a@1 ;\n" @@ -2071,8 +1965,7 @@ private: "};")); } - void varidclass1() - { + void varidclass1() { const std::string actual = tokenize( "class Fred\n" "{\n" @@ -2113,8 +2006,7 @@ private: } - void varidclass2() - { + void varidclass2() { const std::string actual = tokenize( "class Fred\n" "{ void f(); };\n" @@ -2147,8 +2039,7 @@ private: } - void varidclass3() - { + void varidclass3() { const std::string actual = tokenize( "class Fred\n" "{ int i; void f(); };\n" @@ -2181,8 +2072,7 @@ private: } - void varidclass4() - { + void varidclass4() { const std::string actual = tokenize( "class Fred\n" "{ int i; void f(); };\n" @@ -2206,8 +2096,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varidclass5() - { + void varidclass5() { const std::string actual = tokenize( "class A { };\n" "class B\n" @@ -2229,8 +2118,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varidclass6() - { + void varidclass6() { const std::string actual = tokenize( "class A\n" "{\n" @@ -2260,8 +2148,7 @@ private: ASSERT_EQUALS(wanted, actual); } - void varidclass7() - { + void varidclass7() { const std::string actual = tokenize( "int main()\n" "{\n" @@ -2279,8 +2166,7 @@ private: ASSERT_EQUALS(expected, actual); } - void varidclass8() - { + void varidclass8() { const char code[] ="class Fred {\n" "public:\n" " void foo(int d) {\n" @@ -2301,8 +2187,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidclass9() - { + void varidclass9() { const char code[] ="typedef char Str[10];" "class A {\n" "public:\n" @@ -2327,8 +2212,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidclass10() - { + void varidclass10() { const char code[] ="class A {\n" " void f() {\n" " a = 3;\n" @@ -2346,8 +2230,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidclass11() - { + void varidclass11() { const char code[] ="class Fred {\n" " int a;\n" " void f();\n" @@ -2374,8 +2257,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidclass12() - { + void varidclass12() { const char code[] ="class Fred {\n" " int a;\n" " void f() { Fred::a = 0; }\n" @@ -2390,8 +2272,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidclass13() - { + void varidclass13() { const char code[] ="class Fred {\n" " int a;\n" " void f() { Foo::Fred::a = 0; }\n" @@ -2406,8 +2287,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidclass14() - { + void varidclass14() { // don't give friend classes varid { const char code[] ="class A {\n" @@ -2436,8 +2316,7 @@ private: } } - void varidclass15() - { + void varidclass15() { const char code[] = "class A {\n" " int a;\n" " int b;\n" @@ -2454,8 +2333,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidclass16() - { + void varidclass16() { const char code[] = "struct A;\n" "typedef bool (A::* FuncPtr)();\n" "struct A {\n" @@ -2480,8 +2358,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varidclass17() - { + void varidclass17() { const char code[] = "class A: public B, public C::D {\n" " int i;\n" " A(int i): B(i), C::D(i), i(i) {\n" @@ -2498,8 +2375,7 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } - void varid_classnameshaddowsvariablename() - { + void varid_classnameshaddowsvariablename() { const char code[] = "class Data;\n" "void strange_declarated(const Data& Data);\n" "void handleData(const Data& data) {\n" @@ -2515,8 +2391,7 @@ private: } - void varidnamespace1() - { + void varidnamespace1() { const char code[] = "namespace A {\n" " char buf[20];\n" "}\n" diff --git a/tools/reduce.cpp b/tools/reduce.cpp index 870338861..25246aa3f 100644 --- a/tools/reduce.cpp +++ b/tools/reduce.cpp @@ -48,8 +48,7 @@ public: : ErrorLogger() , cppcheck(*this,false) , foundLine(false) - , stopTime(0) - { + , stopTime(0) { if (!settings.hang) pattern = ":" + MathLib::toString(settings.linenr) + "]"; @@ -57,8 +56,7 @@ public: cppcheck.settings() = settings; } - bool run(const char filename[], unsigned int maxtime) - { + bool run(const char filename[], unsigned int maxtime) { foundLine = false; stopTime = std::time(0) + maxtime; cppcheck.check(filename); @@ -66,15 +64,13 @@ public: } void reportOut(const std::string &/*outmsg*/) { } - void reportErr(const ErrorLogger::ErrorMessage &msg) - { + void reportErr(const ErrorLogger::ErrorMessage &msg) { if (!pattern.empty() && msg.toString(false).find(pattern) != std::string::npos) { foundLine = true; cppcheck.terminate(); } } - void reportProgress(const std::string &/*filename*/, const char /*stage*/[], const std::size_t /*value*/) - { + void reportProgress(const std::string &/*filename*/, const char /*stage*/[], const std::size_t /*value*/) { if (std::time(0) > stopTime) { if (pattern.empty()) foundLine = true;