GMX_TEST_CXXFLAG(CXXFLAGS_PRAGMA "-Wno-unknown-pragmas" GMXC_CXXFLAGS)
endif()
if (GMX_COMPILER_WARNINGS)
+ if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0") #LLVM BUG #21629
+ GMX_TEST_CXXFLAG(CXXFLAGS_WARN_NO_BRACES "-Wno-missing-braces" GMXC_CXXFLAGS)
+ endif()
GMX_TEST_CXXFLAG(CXXFLAGS_WARN "-Wall" GMXC_CXXFLAGS)
GMX_TEST_CXXFLAG(CXXFLAGS_WARN_EXTRA "-Wextra -Wno-missing-field-initializers -Wpointer-arith -Wmissing-prototypes" GMXC_CXXFLAGS)
GMX_TEST_CXXFLAG(CXXFLAGS_DEPRECATED "-Wdeprecated" GMXC_CXXFLAGS)
-cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions,
google-*,-google-build-using-namespace,-google-explicit-constructor,
-google-readability-function-size,-google-readability-todo,-google-runtime-int
-
+HeaderFilterRegex: .*
CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
--- /dev/null
+Checks: clang-diagnostic-*,clang-analyzer-*,
+ bugprone-*,misc-*,readability-*,performance-*,mpi-*,-misc-incorrect-roundings,
+ -readability-else-after-return,
+ modernize-use-nullptr,modernize-use-emplace,
+ modernize-make-unique,modernize-make-shared,
+ modernize-avoid-bind,
+ modernize-redundant-void-arg,modernize-use-bool-literals,
+ cppcoreguidelines-*,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-const-cast,
+ -cppcoreguidelines-pro-type-static-cast-downcast,
+ -cppcoreguidelines-special-member-functions,-cppcoreguidelines-pro-type-vararg,
+ -cppcoreguidelines-pro-bounds-constant-array-index,
+ -cppcoreguidelines-pro-bounds-array-to-pointer-decay,
+ -cppcoreguidelines-pro-bounds-pointer-arithmetic,
+ google-*,-google-build-using-namespace,-google-explicit-constructor,
+ -google-readability-todo,
+ -google-runtime-int
+HeaderFilterRegex: .*
+CheckOptions:
+ - key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
+ value: 1
+ - key: modernize-make-unique.MakeSmartPtrFunction
+ value: gmx::compat::make_unique
+ - key: modernize-make-unique.MakeSmartPtrFunctionHeader
+ value: gromacs/compat/make_unique.h
+ - key: modernize-make-unique.IncludeStyle
+ value: google
+ - key: modernize-make-shared.IncludeStyle
+ value: google
+ - key: readability-implicit-bool-conversion.AllowIntegerConditions
+ value: 1
+ - key: readability-implicit-bool-conversion.AllowPointerConditions
+ value: 1
(parent_id), \
parent_class::SetUpTestCase, \
parent_class::TearDownTestCase, \
- new ::testing::internal::TestFactoryImpl<\
- GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
-void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
+ new ::testing::internal::TestFactoryImpl<GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>); /*NOLINT(cppcoreguidelines-owning-memory)*/ \
+ void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
add_subdirectory(awh)
add_subdirectory(simd)
add_subdirectory(imd)
+add_subdirectory(compat)
if (NOT GMX_BUILD_MDRUN_ONLY)
add_subdirectory(gmxana)
add_subdirectory(gmxpreprocess)
if (GMX_CLANG_TIDY)
set_target_properties(libgromacs PROPERTIES CXX_CLANG_TIDY
- "${CLANG_TIDY_EXE};-warnings-as-errors=*;-header-filter=.*")
+ "${CLANG_TIDY_EXE};-warnings-as-errors=*")
endif()
gmx_write_installed_header_list()
install(FILES ${OPENCL_KERNELS} DESTINATION
${GMX_INSTALL_OCLDIR} COMPONENT libraries)
endif()
-
-if (BUILD_TESTING)
- add_subdirectory(compat/tests)
-endif()
--- /dev/null
+../../.clang-tidy.new.code
\ No newline at end of file
};
AnalysisDataModuleManager::Impl::Impl()
- : bAllowMissing_(true), bSerialModules_(false), bParallelModules_(false),
+ : bDataProperty_(), // This must be in sync with how AbstractAnalysisData
+ // is actually initialized.
+ bAllowMissing_(true), bSerialModules_(false), bParallelModules_(false),
state_(eNotStarted), currIndex_(0)
{
- // This must be in sync with how AbstractAnalysisData is actually
- // initialized.
- for (int i = 0; i < eDataPropertyNR; ++i)
- {
- bDataProperty_[i] = false;
- }
}
void
std::string xlabel_;
std::string ylabel_;
std::vector<std::string> legend_;
- char xformat_[15];
- char yformat_[15];
+ std::string xformat_;
+ std::string yformat_;
real xscale_;
};
AbstractPlotModule::Impl::Impl(const AnalysisDataPlotSettings &settings)
: settings_(settings), fp_(nullptr), bPlain_(false), bOmitX_(false),
- bErrorsAsSeparateColumn_(false), xscale_(1.0)
+ bErrorsAsSeparateColumn_(false),
+ xformat_("%11.3f"), yformat_(" %8.3f"), xscale_(1.0)
{
- strcpy(xformat_, "%11.3f");
- strcpy(yformat_, " %8.3f");
}
AbstractPlotModule::Impl::~Impl()
"Invalid width or precision");
GMX_RELEASE_ASSERT(strchr("eEfFgG", format) != nullptr,
"Invalid format specifier");
- sprintf(impl_->xformat_, "%%%d.%d%c", width, precision, format);
+ impl_->xformat_ = formatString("%%%d.%d%c", width, precision, format);
}
"Invalid width or precision");
GMX_RELEASE_ASSERT(strchr("eEfFgG", format) != nullptr,
"Invalid format specifier");
- sprintf(impl_->yformat_, " %%%d.%d%c", width, precision, format);
+ impl_->yformat_ = formatString(" %%%d.%d%c", width, precision, format);
}
void
-AbstractPlotModule::frameStarted(const AnalysisDataFrameHeader &frame)
+AbstractPlotModule::frameStarted(const AnalysisDataFrameHeader &header)
{
if (!isFileOpen())
{
}
if (!impl_->bOmitX_)
{
- std::fprintf(impl_->fp_, impl_->xformat_, frame.x() * impl_->xscale_);
+ std::fprintf(impl_->fp_, impl_->xformat_.c_str(), header.x() * impl_->xscale_);
}
}
{
GMX_ASSERT(isFileOpen(), "File not opened, but write attempted");
const real y = value.isSet() ? value.value() : 0.0;
- std::fprintf(impl_->fp_, impl_->yformat_, y);
+ std::fprintf(impl_->fp_, impl_->yformat_.c_str(), y);
if (impl_->bErrorsAsSeparateColumn_)
{
const real dy = value.isSet() ? value.error() : 0.0;
- std::fprintf(impl_->fp_, impl_->yformat_, dy);
+ std::fprintf(impl_->fp_, impl_->yformat_.c_str(), dy);
}
}
//! \endcond
*/
AnalysisDataVectorPlotModule::AnalysisDataVectorPlotModule()
+ : bWrite_ {true, true, true, false}
{
- for (int i = 0; i < DIM; ++i)
- {
- bWrite_[i] = true;
- }
- bWrite_[DIM] = false;
}
AnalysisDataVectorPlotModule::AnalysisDataVectorPlotModule(
const AnalysisDataPlotSettings &settings)
- : AbstractPlotModule(settings)
+ : AbstractPlotModule(settings),
+ bWrite_ {true, true, true, false}
{
- for (int i = 0; i < DIM; ++i)
- {
- bWrite_[i] = true;
- }
- bWrite_[DIM] = false;
}
--- /dev/null
+#
+# This file is part of the GROMACS molecular simulation package.
+#
+# Copyright (c) 2018, by the GROMACS development team, led by
+# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+# and including many others, as listed in the AUTHORS file in the
+# top-level source directory and at http://www.gromacs.org.
+#
+# GROMACS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 2.1
+# of the License, or (at your option) any later version.
+#
+# GROMACS is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with GROMACS; if not, see
+# http://www.gnu.org/licenses, or write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# If you want to redistribute modifications to GROMACS, please
+# consider that scientific software is very special. Version
+# control is crucial - bugs must be traceable. We will be happy to
+# consider code for inclusion in the official distribution, but
+# derived work must not be called official GROMACS. Details are found
+# in the README & COPYING files - if they are missing, get the
+# official version at http://www.gromacs.org.
+#
+# To help us fund GROMACS development, we humbly ask that you cite
+# the research papers on the package. Check out http://www.gromacs.org.
+
+gmx_install_headers(make_unique.h)
+if (BUILD_TESTING)
+ add_subdirectory(tests)
+endif()
* library implementations as appropriate.
*/
-/*! \libinternal
+/*!
* \file
* \brief Provides template gmx::compat::make_unique
*
--- /dev/null
+../../.clang-tidy.new.code
\ No newline at end of file
*
* Similar to AbstractOption::createStorage().
*/
- virtual IOptionSectionStorage *createStorage() const = 0;
+ virtual std::unique_ptr<IOptionSectionStorage> createStorage() const = 0;
//! \endcond
private:
createEnumOptionStorage(const AbstractOption &option,
const char *const *enumValues, int count,
int defaultValue, int defaultValueIfSet,
- IOptionValueStore<int> *store)
+ std::unique_ptr<IOptionValueStore<int> > store)
{
- std::unique_ptr<IOptionValueStore<int> > storePtr(store);
return new EnumOptionStorage(option, enumValues, count, defaultValue,
- defaultValueIfSet, move(storePtr));
+ defaultValueIfSet, move(store));
}
//! \endcond
#include <string>
#include <vector>
+#include "gromacs/compat/make_unique.h"
#include "gromacs/options/abstractoption.h"
#include "gromacs/options/ivaluestore.h"
#include "gromacs/utility/arrayref.h"
createEnumOptionStorage(const AbstractOption &option,
const char *const *enumValues, int count,
int defaultValue, int defaultValueIfSet,
- IOptionValueStore<int> *store);
+ std::unique_ptr<IOptionValueStore<int> > store);
//! \endcond
} // namespace internal
*this, enumValues_, enumValuesCount_,
convertToInt(MyBase::defaultValue()),
convertToInt(MyBase::defaultValueIfSet()),
- new internal::EnumIndexStore<EnumType>(
+ compat::make_unique<internal::EnumIndexStore<EnumType> >(
MyBase::store(), MyBase::storeVector()));
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "optionsection.h"
+#include "gromacs/compat/make_unique.h"
#include "gromacs/options/isectionstorage.h"
namespace gmx
} // namespace
-IOptionSectionStorage *OptionSection::createStorage() const
+std::unique_ptr<IOptionSectionStorage> OptionSection::createStorage() const
{
- return new OptionSectionStorage();
+ return compat::make_unique<OptionSectionStorage>();
}
} // namespace gmx
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
explicit OptionSection(const char *name) : AbstractOptionSection(name) {}
private:
- virtual IOptionSectionStorage *createStorage() const;
+ virtual std::unique_ptr<IOptionSectionStorage> createStorage() const;
};
/*! \brief
GMX_THROW(APIError("defaultValueIfSet() is not supported with allowMultiple()"));
}
setFlag(efOption_DefaultValueIfSetExists);
- defaultValueIfSet_.reset(new T(value));
+ defaultValueIfSet_ = compat::make_unique<T>(value);
}
} // namespace gmx
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <memory>
#include <vector>
+#include "gromacs/compat/make_unique.h"
#include "gromacs/options/abstractsection.h"
#include "gromacs/options/ioptionscontainerwithsections.h"
#include "gromacs/options/isectionstorage.h"
}
private:
- virtual IOptionSectionStorage *createStorage() const;
+ virtual std::unique_ptr<IOptionSectionStorage> createStorage() const;
std::vector<T> *values_;
};
template <class T>
-IOptionSectionStorage *RepeatingOptionSection<T>::createStorage() const
+std::unique_ptr<IOptionSectionStorage> RepeatingOptionSection<T>::createStorage() const
{
- return new RepeatingOptionSectionStorage<T>(*this);
+
+ return compat::make_unique<RepeatingOptionSectionStorage<T> >(*this);
}
/*! \brief
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016, by the GROMACS development team, led by
+ * Copyright (c) 2016,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
struct NestedSectionData
{
- int value;
+ int value {};
std::vector<SectionData> subsec;
};
}
TimeUnitManager::TimeUnitManager(TimeUnit unit)
+ : timeUnit_(unit)
{
- setTimeUnit(unit);
+ GMX_RELEASE_ASSERT(unit >= 0 && unit <= TimeUnit_s,
+ "Invalid time unit");
}
void TimeUnitManager::setTimeUnit(TimeUnit unit)
{
}
-void TimeUnitBehavior::setTimeUnit(TimeUnit timeUnit)
+void TimeUnitBehavior::setTimeUnit(TimeUnit unit)
{
- GMX_RELEASE_ASSERT(timeUnit >= 0 && timeUnit <= TimeUnit_s,
+ GMX_RELEASE_ASSERT(unit >= 0 && unit <= TimeUnit_s,
"Invalid time unit");
- timeUnit_ = timeUnit;
+ timeUnit_ = unit;
if (timeUnitStore_ != nullptr)
{
- *timeUnitStore_ = timeUnit;
+ *timeUnitStore_ = unit;
}
}
* \throws InternalError if the high bits needed to encode the number of counter
* bits are nonzero.
*/
+ //NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
ThreeFry2x64General(uint64_t key0 = 0, RandomDomain domain = RandomDomain::Other)
{
seed(key0, domain);
* \throws InternalError if the high bits needed to encode the number of counter
* bits are nonzero. To test arbitrary values, use 0 internal counter bits.
*/
+ //NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
ThreeFry2x64General(uint64_t key0, uint64_t key1)
{
seed(key0, key1);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
{
public:
//! Initializes an invalid pair.
- AnalysisNeighborhoodPair() : refIndex_(-1), testIndex_(0), distance2_(0.0)
+ AnalysisNeighborhoodPair() : refIndex_(-1), testIndex_(0), distance2_(0.0), dx_()
{
- clear_rvec(dx_);
}
//! Initializes a pair object with the given data.
AnalysisNeighborhoodPair(int refIndex, int testIndex, real distance2,
const rvec dx)
- : refIndex_(refIndex), testIndex_(testIndex), distance2_(distance2)
+ : refIndex_(refIndex), testIndex_(testIndex), distance2_(distance2), dx_()
{
copy_rvec(dx, dx_);
}
--- /dev/null
+../../.clang-tidy.new.code
\ No newline at end of file
#include "gromacs/analysisdata/modules/average.h"
#include "gromacs/analysisdata/modules/histogram.h"
#include "gromacs/analysisdata/modules/plot.h"
+#include "gromacs/compat/make_unique.h"
#include "gromacs/math/units.h"
#include "gromacs/math/vec.h"
#include "gromacs/options/basicoptions.h"
g1type_(Group1Type_Angle), g2type_(Group2Type_None),
binWidth_(1.0), natoms1_(0), natoms2_(0)
{
- averageModule_.reset(new AnalysisDataFrameAverageModule());
+ averageModule_ = compat::make_unique<AnalysisDataFrameAverageModule>();
angles_.addModule(averageModule_);
- histogramModule_.reset(new AnalysisDataSimpleHistogramModule());
+ histogramModule_ = compat::make_unique<AnalysisDataSimpleHistogramModule>();
angles_.addModule(histogramModule_);
registerAnalysisDataset(&angles_, "angle");
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "gromacs/analysisdata/modules/average.h"
#include "gromacs/analysisdata/modules/histogram.h"
#include "gromacs/analysisdata/modules/plot.h"
+#include "gromacs/compat/make_unique.h"
#include "gromacs/math/vec.h"
#include "gromacs/options/basicoptions.h"
#include "gromacs/options/filenameoption.h"
};
Distance::Distance()
- : meanLength_(0.1), lengthDev_(1.0), binWidth_(0.001)
+ : meanLength_(0.1), lengthDev_(1.0), binWidth_(0.001),
+ summaryStatsModule_(compat::make_unique<AnalysisDataAverageModule>()),
+ allStatsModule_(compat::make_unique<AnalysisDataAverageModule>()),
+ averageModule_(compat::make_unique<AnalysisDataFrameAverageModule>()),
+ histogramModule_(compat::make_unique<AnalysisDataSimpleHistogramModule>())
{
- summaryStatsModule_.reset(new AnalysisDataAverageModule());
summaryStatsModule_->setAverageDataSets(true);
distances_.addModule(summaryStatsModule_);
- allStatsModule_.reset(new AnalysisDataAverageModule());
distances_.addModule(allStatsModule_);
- averageModule_.reset(new AnalysisDataFrameAverageModule());
distances_.addModule(averageModule_);
- histogramModule_.reset(new AnalysisDataSimpleHistogramModule());
distances_.addModule(histogramModule_);
registerAnalysisDataset(&distances_, "dist");
std::string fnX_;
std::string fnV_;
std::string fnF_;
- bool dimMask_[4];
- bool maskSet_[4];
+ std::array<bool, 4> dimMask_;
+ std::array<bool, 4> maskSet_;
AnalysisData xdata_;
AnalysisData vdata_;
AnalysisData fdata_;
};
-Trajectory::Trajectory()
+Trajectory::Trajectory() :
+ dimMask_ {true, true, true, false}, maskSet_ {}
{
- std::fill(std::begin(dimMask_), std::end(dimMask_), true);
- dimMask_[DIM] = false;
- std::fill(std::begin(maskSet_), std::end(maskSet_), false);
registerAnalysisDataset(&xdata_, "x");
registerAnalysisDataset(&vdata_, "v");
registerAnalysisDataset(&fdata_, "f");
}
AnalysisDataVectorPlotModulePointer plot(
new AnalysisDataVectorPlotModule(settings.plotSettings()));
- plot->setWriteMask(dimMask_);
+ plot->setWriteMask(dimMask_.data());
plot->setFileName(fnX_);
plot->setTitle("Coordinates");
plot->setXAxisIsTime();
}
AnalysisDataVectorPlotModulePointer plot(
new AnalysisDataVectorPlotModule(settings.plotSettings()));
- plot->setWriteMask(dimMask_);
+ plot->setWriteMask(dimMask_.data());
plot->setFileName(fnV_);
plot->setTitle("Velocities");
plot->setXAxisIsTime();
}
AnalysisDataVectorPlotModulePointer plot(
new AnalysisDataVectorPlotModule(settings.plotSettings()));
- plot->setWriteMask(dimMask_);
+ plot->setWriteMask(dimMask_.data());
plot->setFileName(fnF_);
plot->setTitle("Forces");
plot->setXAxisIsTime();
{
public:
SurfaceAreaTest()
- : rng_(12345), area_(0.0), volume_(0.0),
+ : box_(), rng_(12345), area_(0.0), volume_(0.0),
atomArea_(nullptr), dotCount_(0), dots_(nullptr)
{
- clear_mat(box_);
}
~SurfaceAreaTest()
{
{
TopologyInformation::TopologyInformation()
- : mtop_(nullptr), top_(nullptr), bTop_(false), xtop_(nullptr), ePBC_(-1)
+ : mtop_(nullptr), top_(nullptr), bTop_(false), xtop_(nullptr), boxtop_(), ePBC_(-1)
{
- clear_mat(boxtop_);
}
#include <typeinfo>
#include <utility>
+#include "gromacs/compat/make_unique.h"
#include "gromacs/utility/gmxassert.h"
namespace gmx
*/
Variant &operator=(const Variant &other)
{
- content_.reset(other.cloneContent());
+ content_ = other.cloneContent();
return *this;
}
//! Move-assigns the variant.
public:
virtual ~IContent() {}
virtual const std::type_info &typeInfo() const = 0;
- virtual IContent *clone() const = 0;
+ virtual std::unique_ptr<IContent> clone() const = 0;
};
template <typename T>
explicit Content(T &&value) : value_(std::move(value)) {}
virtual const std::type_info &typeInfo() const { return typeid(T); }
- virtual IContent *clone() const { return new Content(value_); }
+ virtual std::unique_ptr<IContent> clone() const { return compat::make_unique<Content>(value_); }
T value_;
};
//! Creates a deep copy of the content.
- IContent *cloneContent() const
+ std::unique_ptr<IContent> cloneContent() const
{
return content_ != nullptr ? content_->clone() : nullptr;
}