From b52c6552c44fcb997b0db9f5e9f17b4674dd5359 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 30 Apr 2019 12:07:07 +0200 Subject: Add 'explicit' to most single argument constructors This prevents implicit conversions that we do not want, such as having a FileFd* being converted to a debListParser. Two cases are not yet handled because they require changes in code using them: 1. The classes in hashes.h 2. The URI class - this one is used quite a lot --- apt-private/private-cacheset.h | 2 ++ apt-private/private-json-hooks.cc | 2 +- apt-private/private-sources.cc | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) (limited to 'apt-private') diff --git a/apt-private/private-cacheset.h b/apt-private/private-cacheset.h index 3370bd03a..c52df36d7 100644 --- a/apt-private/private-cacheset.h +++ b/apt-private/private-cacheset.h @@ -18,6 +18,8 @@ class VerIteratorWithCaching const pkgCache::VerIterator iter; const pkgCache::DescFile * descFile; public: + + // cppcheck-suppress noExplicitConstructor VerIteratorWithCaching(const pkgCache::VerIterator& iter) : iter(iter), descFile(iter->DescriptionList != 0 diff --git a/apt-private/private-json-hooks.cc b/apt-private/private-json-hooks.cc index 65ff87924..3e0d8c93b 100644 --- a/apt-private/private-json-hooks.cc +++ b/apt-private/private-json-hooks.cc @@ -79,7 +79,7 @@ class APT_HIDDEN JsonWriter } public: - JsonWriter(std::ostream &os) : os(os) { old_locale = os.imbue(std::locale::classic()); } + explicit JsonWriter(std::ostream &os) : os(os) { old_locale = os.imbue(std::locale::classic()); } ~JsonWriter() { os.imbue(old_locale); } JsonWriter &beginArray() { diff --git a/apt-private/private-sources.cc b/apt-private/private-sources.cc index 713327f02..4cfb87938 100644 --- a/apt-private/private-sources.cc +++ b/apt-private/private-sources.cc @@ -31,7 +31,7 @@ class APT_HIDDEN ScopedGetLock { public: int fd; - ScopedGetLock(std::string const &filename) : fd(GetLock(filename)) {} + explicit ScopedGetLock(std::string const &filename) : fd(GetLock(filename)) {} ~ScopedGetLock() { close(fd); } }; bool EditSources(CommandLine &CmdL) -- cgit v1.2.3