From 53fcb3c827fe52e7858ebe6f6c5d0f485175cfef Mon Sep 17 00:00:00 2001 From: Steven Hahn <hahnse@ornl.gov> Date: Thu, 15 Feb 2018 17:56:07 -0500 Subject: [PATCH] Fixes suggested by cppcheck 1.82. --- Framework/DataObjects/src/EventList.cpp | 21 +++++++------------ Framework/HistogramData/CMakeLists.txt | 1 + Framework/Indexing/CMakeLists.txt | 1 + Framework/Kernel/inc/MantidKernel/VMD.h | 1 - Framework/Kernel/src/ConfigService.cpp | 14 ------------- Framework/Kernel/src/Matrix.cpp | 3 +-- Framework/Kernel/src/VMD.cpp | 13 ------------ Framework/MDAlgorithms/src/FindPeaksMD.cpp | 2 +- Framework/Nexus/src/NexusFileIO.cpp | 7 ++----- Framework/Parallel/CMakeLists.txt | 2 +- .../TestHelpers/src/FileComparisonHelper.cpp | 6 +++--- MantidPlot/src/ApplicationWindow.cpp | 4 ---- 12 files changed, 17 insertions(+), 58 deletions(-) diff --git a/Framework/DataObjects/src/EventList.cpp b/Framework/DataObjects/src/EventList.cpp index 7a58b4f70e9..ee8fb7c957b 100644 --- a/Framework/DataObjects/src/EventList.cpp +++ b/Framework/DataObjects/src/EventList.cpp @@ -540,21 +540,17 @@ void EventList::minusHelper(std::vector<T1> &events, const std::vector<T2> &more_events) { // Make the end vector big enough in one go (avoids repeated re-allocations). events.reserve(events.size() + more_events.size()); - typename std::vector<T2>::const_iterator itev; /* In the event of subtracting in place, calling the end() vector would make * it point * at the wrong place * Using it caused a segault, Ticket #2306. * So we cache the end (this speeds up too). */ - auto more_begin = more_events.cbegin(); - auto more_end = more_events.cend(); - - for (itev = more_begin; itev != more_end; itev++) { + for (const auto &ev : more_events) { // We call the constructor for T1. In the case of WeightedEventNoTime, the // pulse time will just be ignored. - events.emplace_back(itev->tof(), itev->pulseTime(), itev->weight() * (-1.0), - itev->errorSquared()); + events.emplace_back(ev.tof(), ev.pulseTime(), ev.weight() * (-1.0), + ev.errorSquared()); } } @@ -1608,7 +1604,7 @@ void EventList::compressEventsParallelHelper( events.begin() + (thread + 1) * numPerBlock; // cache for speed if (thread == numThreads - 1) it_end = events.end(); - for (; it != it_end; it++) { + for (; it != it_end; ++it) { if ((it->m_tof - lastTof) <= tolerance) { // Carry the error and weight weight += it->weight(); @@ -2479,8 +2475,7 @@ void EventList::integrateHelper(std::vector<T> &events, const double minX, } // Sum up all the weights - typename std::vector<T>::iterator it; - for (it = lowit; it != highit; it++) { + for (auto it = lowit; it != highit; ++it) { sum += it->weight(); error += it->errorSquared(); } @@ -2589,10 +2584,8 @@ template <class T> void EventList::convertTofHelper(std::vector<T> &events, std::function<double(double)> func) { // iterate through all events - typename std::vector<T>::iterator itev; - auto itev_end = events.end(); // cache for speed - for (itev = events.begin(); itev != itev_end; itev++) - itev->m_tof = func(itev->m_tof); + for (auto &ev : events) + ev.m_tof = func(ev.m_tof); } // -------------------------------------------------------------------------- diff --git a/Framework/HistogramData/CMakeLists.txt b/Framework/HistogramData/CMakeLists.txt index fdaf4a9d8f5..550dcd46bec 100644 --- a/Framework/HistogramData/CMakeLists.txt +++ b/Framework/HistogramData/CMakeLists.txt @@ -119,6 +119,7 @@ endif () # Add to the 'Framework' group in VS set_property ( TARGET HistogramData PROPERTY FOLDER "MantidFramework" ) +target_include_directories ( HistogramData PUBLIC ${Boost_INCLUDE_DIRS}) target_link_libraries ( HistogramData LINK_PRIVATE ${TCMALLOC_LIBRARIES_LINKTIME} ${GSL_LIBRARIES} ${MANTIDLIBS} ) diff --git a/Framework/Indexing/CMakeLists.txt b/Framework/Indexing/CMakeLists.txt index 33fc4cf478c..775465ecb4a 100644 --- a/Framework/Indexing/CMakeLists.txt +++ b/Framework/Indexing/CMakeLists.txt @@ -72,6 +72,7 @@ endif () # Add to the 'Framework' group in VS set_property ( TARGET Indexing PROPERTY FOLDER "MantidFramework" ) +target_include_directories ( Indexing PUBLIC ${Boost_INCLUDE_DIRS}) target_link_libraries ( Indexing LINK_PRIVATE ${TCMALLOC_LIBRARIES_LINKTIME} ${MANTIDLIBS} Parallel ) diff --git a/Framework/Kernel/inc/MantidKernel/VMD.h b/Framework/Kernel/inc/MantidKernel/VMD.h index ec5f594c445..4cfce09de7a 100644 --- a/Framework/Kernel/inc/MantidKernel/VMD.h +++ b/Framework/Kernel/inc/MantidKernel/VMD.h @@ -64,7 +64,6 @@ public: TYPE &operator[](const size_t index); const TYPE *getBareArray() const; std::string toString(const std::string &separator = " ") const; - template <class T> std::vector<T> toVector() const; bool operator==(const VMDBase &v) const; bool operator!=(const VMDBase &v) const; VMDBase operator+(const VMDBase &v) const; diff --git a/Framework/Kernel/src/ConfigService.cpp b/Framework/Kernel/src/ConfigService.cpp index 0a789fa2b41..53385cfa7e4 100644 --- a/Framework/Kernel/src/ConfigService.cpp +++ b/Framework/Kernel/src/ConfigService.cpp @@ -127,20 +127,6 @@ public: m_pPtr = static_cast<T *>(this); } - /// Copy constructor - WrappedObject(const WrappedObject<T> &A) : T(A) { - m_pPtr = static_cast<T *>(this); - } - - /// Overloaded = operator sets the pointer to the wrapped class - /// and copies over the contents - WrappedObject<T> &operator=(const WrappedObject<T> &rhs) { - if (this != &rhs) { - m_pPtr = static_cast<T *>(this); - *m_pPtr = rhs; - } - return *this; - } /// Overloaded * operator returns the wrapped object pointer const T &operator*() const { return *m_pPtr; } /// Overloaded * operator returns the wrapped object pointer diff --git a/Framework/Kernel/src/Matrix.cpp b/Framework/Kernel/src/Matrix.cpp index cdd07279dd5..acb51865083 100644 --- a/Framework/Kernel/src/Matrix.cpp +++ b/Framework/Kernel/src/Matrix.cpp @@ -1454,9 +1454,8 @@ std::vector<T> Matrix<T>::toRotation() } // step 2: get scales and rescsale the matrix std::vector<T> scale(this->m_numRows); - T currentScale; for (size_t i = 0; i < this->m_numColumns; ++i) { - currentScale = T(0.); + T currentScale{0}; for (size_t j = 0; j < this->m_numRows; ++j) currentScale += (m_rawData[j][i] * m_rawData[j][i]); currentScale = static_cast<T>(sqrt(static_cast<double>(currentScale))); diff --git a/Framework/Kernel/src/VMD.cpp b/Framework/Kernel/src/VMD.cpp index a3925ff1987..1cafd0aa503 100644 --- a/Framework/Kernel/src/VMD.cpp +++ b/Framework/Kernel/src/VMD.cpp @@ -288,19 +288,6 @@ std::string VMDBase<TYPE>::toString(const std::string &separator) const { return mess.str(); } -/** Get the vector as a vector - * @tparam T :: type to convert to (double/float) - * @return the vector as a std::vector - */ -template <typename TYPE> -template <class T> -std::vector<T> VMDBase<TYPE>::toVector() const { - typename std::vector<T> out; - for (size_t d = 0; d < nd; d++) - out.push_back(T(data[d])); - return out; -} - /** Equals operator with tolerance factor @param v :: VMDBase for comparison @return true if the items are equal diff --git a/Framework/MDAlgorithms/src/FindPeaksMD.cpp b/Framework/MDAlgorithms/src/FindPeaksMD.cpp index bfedf8b8390..a3f838e5938 100644 --- a/Framework/MDAlgorithms/src/FindPeaksMD.cpp +++ b/Framework/MDAlgorithms/src/FindPeaksMD.cpp @@ -439,7 +439,7 @@ void FindPeaksMD::findPeaks(typename MDEventWorkspace<MDE, nd>::sptr ws) { // e.g. from highest density down to lowest density. typename std::multimap<double, boxPtr>::reverse_iterator it2; auto it2_end = sortedBoxes.rend(); - for (it2 = sortedBoxes.rbegin(); it2 != it2_end; it2++) { + for (it2 = sortedBoxes.rbegin(); it2 != it2_end; ++it2) { signal_t density = it2->first; boxPtr box = it2->second; #ifndef MDBOX_TRACK_CENTROID diff --git a/Framework/Nexus/src/NexusFileIO.cpp b/Framework/Nexus/src/NexusFileIO.cpp index e373e252dbb..5c7f89e87b5 100644 --- a/Framework/Nexus/src/NexusFileIO.cpp +++ b/Framework/Nexus/src/NexusFileIO.cpp @@ -838,12 +838,9 @@ void NexusFileIO::writeEventListData(std::vector<T> events, bool writeTOF, auto errorSquareds = new double[num]; auto pulsetimes = new int64_t[num]; - typename std::vector<T>::const_iterator it; - typename std::vector<T>::const_iterator it_end = events.end(); size_t i = 0; - // Fill the C-arrays with the fields from all the events, as requested. - for (it = events.begin(); it != it_end; it++) { + for (auto it = events.cbegin(); it != events.cend(); ++it) { if (writeTOF) tofs[i] = it->tof(); if (writePulsetime) @@ -852,7 +849,7 @@ void NexusFileIO::writeEventListData(std::vector<T> events, bool writeTOF, weights[i] = it->weight(); if (writeError) errorSquareds[i] = it->errorSquared(); - i++; + ++i; } // Write out all the required arrays. diff --git a/Framework/Parallel/CMakeLists.txt b/Framework/Parallel/CMakeLists.txt index 24668373bbe..39e5fe6f954 100644 --- a/Framework/Parallel/CMakeLists.txt +++ b/Framework/Parallel/CMakeLists.txt @@ -63,7 +63,7 @@ endif () # Add to the 'Framework' group in VS set_property ( TARGET Parallel PROPERTY FOLDER "MantidFramework" ) -target_include_directories ( Parallel SYSTEM PRIVATE ${HDF5_INCLUDE_DIRS} ) +target_include_directories ( Parallel SYSTEM PRIVATE ${HDF5_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) target_link_libraries ( Parallel LINK_PRIVATE ${TCMALLOC_LIBRARIES_LINKTIME} ${GSL_LIBRARIES} ${MANTIDLIBS} ${HDF5_LIBRARIES} ) diff --git a/Framework/TestHelpers/src/FileComparisonHelper.cpp b/Framework/TestHelpers/src/FileComparisonHelper.cpp index ccf783e80f2..95e86c89afd 100644 --- a/Framework/TestHelpers/src/FileComparisonHelper.cpp +++ b/Framework/TestHelpers/src/FileComparisonHelper.cpp @@ -12,15 +12,15 @@ using streamCharIter = std::istreambuf_iterator<char>; // Returns if the difference was due to EOL and fixes the position of the // stream if it was due to EOL -bool isEolDifference(streamCharIter streamOne, streamCharIter streamTwo) { +bool isEolDifference(streamCharIter &streamOne, streamCharIter &streamTwo) { // Check which is the Windows file stream (CR in CRLF) // and advance it by a character so we are back to LF on both if (*streamOne == '\r' && *streamTwo == '\n') { - streamOne++; + ++streamOne; } else if (*streamOne == '\n' && *streamTwo == '\r') { - streamTwo++; + ++streamTwo; } else { // Was not a different EOL so indicate false to that return false; diff --git a/MantidPlot/src/ApplicationWindow.cpp b/MantidPlot/src/ApplicationWindow.cpp index 39391706737..daa9a930eb8 100644 --- a/MantidPlot/src/ApplicationWindow.cpp +++ b/MantidPlot/src/ApplicationWindow.cpp @@ -13535,14 +13535,12 @@ ApplicationWindow *ApplicationWindow::importOPJ(const QString &filename, app->recentProjects.push_front(filename); app->updateRecentProjectsList(); - // cppcheck-suppress unusedScopedObject ImportOPJ(app, filename); QApplication::restoreOverrideCursor(); return app; } else if (filename.endsWith(".ogm", Qt::CaseInsensitive) || filename.endsWith(".ogw", Qt::CaseInsensitive)) { - // cppcheck-suppress unusedScopedObject ImportOPJ(this, filename); recentProjects.removeAll(filename); recentProjects.push_front(filename); @@ -15272,7 +15270,6 @@ void ApplicationWindow::scriptsDirPathChanged(const QString &path) { } void ApplicationWindow::makeToolbarsMenu() { - // cppcheck-suppress publicAllocationError actionFileTools = new QAction(standardTools->windowTitle(), toolbarsMenu); actionFileTools->setCheckable(true); toolbarsMenu->addAction(actionFileTools); @@ -15581,7 +15578,6 @@ void ApplicationWindow::showUserDirectoryDialog() { ad->setAttribute(Qt::WA_DeleteOnClose); ad->show(); ad->setFocus(); - // cppcheck-suppress memleak } void ApplicationWindow::addCustomAction(QAction *action, -- GitLab