diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 9a45788fc6..907fb58e57 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1704,7 +1704,7 @@ private: Base::FileInfo tmp(sourcename); if (!tmp.renameFile(targetname.c_str())) { throw Base::FileException( - "Cannot rename tmp save file to project file", targetname); + "Cannot rename tmp save file to project file", Base::FileInfo(targetname)); } } void applyTimeStamp(const std::string& sourcename, const std::string& targetname) { diff --git a/src/Base/Debugger.h b/src/Base/Debugger.h index 83096b228b..8df60871d9 100644 --- a/src/Base/Debugger.h +++ b/src/Base/Debugger.h @@ -59,7 +59,7 @@ class BaseExport Debugger: public QObject Q_OBJECT public: - Debugger(QObject* parent = nullptr); + explicit Debugger(QObject* parent = nullptr); ~Debugger() override; Debugger(const Debugger&) = delete; diff --git a/src/Base/Exception.h b/src/Base/Exception.h index 6430ec0990..9bb33b3db3 100644 --- a/src/Base/Exception.h +++ b/src/Base/Exception.h @@ -247,8 +247,8 @@ protected: * - a very technical message not intended to be translated or shown to the user in the UI * The preferred way of throwing an exception is using the macros above. * This way, the file, line, and function are automatically inserted. */ - Exception(const char* sMessage); - Exception(const std::string& sMessage); + explicit Exception(const char* sMessage); + explicit Exception(const std::string& sMessage); Exception(); Exception(const Exception& inst); Exception(Exception&& inst) noexcept; @@ -273,7 +273,7 @@ class BaseExport AbortException: public Exception public: /// Construction - AbortException(const char* sMessage); + explicit AbortException(const char* sMessage); /// Construction AbortException(); AbortException(const AbortException&) = default; @@ -299,8 +299,8 @@ class BaseExport XMLBaseException: public Exception public: /// Construction XMLBaseException(); - XMLBaseException(const char* sMessage); - XMLBaseException(const std::string& sMessage); + explicit XMLBaseException(const char* sMessage); + explicit XMLBaseException(const std::string& sMessage); XMLBaseException(const XMLBaseException&) = default; XMLBaseException(XMLBaseException&&) = default; @@ -320,9 +320,9 @@ class BaseExport XMLParseException: public XMLBaseException { public: /// Construction - XMLParseException(const char* sMessage); + explicit XMLParseException(const char* sMessage); /// Construction - XMLParseException(const std::string& sMessage); + explicit XMLParseException(const std::string& sMessage); /// Construction XMLParseException(); XMLParseException(const XMLParseException&) = default; @@ -346,9 +346,9 @@ class BaseExport XMLAttributeError: public XMLBaseException { public: /// Construction - XMLAttributeError(const char* sMessage); + explicit XMLAttributeError(const char* sMessage); /// Construction - XMLAttributeError(const std::string& sMessage); + explicit XMLAttributeError(const std::string& sMessage); /// Construction XMLAttributeError(); XMLAttributeError(const XMLAttributeError&) = default; @@ -372,7 +372,7 @@ class BaseExport FileException: public Exception { public: /// With massage and file name - FileException(const char* sMessage, const char* sFileName = nullptr); + explicit FileException(const char* sMessage, const char* sFileName = nullptr); /// With massage and file name FileException(const char* sMessage, const FileInfo& File); /// standard construction @@ -416,8 +416,8 @@ class BaseExport FileSystemError: public Exception public: /// Construction FileSystemError(); - FileSystemError(const char* sMessage); - FileSystemError(const std::string& sMessage); + explicit FileSystemError(const char* sMessage); + explicit FileSystemError(const std::string& sMessage); FileSystemError(const FileSystemError&) = default; FileSystemError(FileSystemError&&) = default; /// Destruction @@ -437,8 +437,8 @@ class BaseExport BadFormatError: public Exception public: /// Construction BadFormatError(); - BadFormatError(const char* sMessage); - BadFormatError(const std::string& sMessage); + explicit BadFormatError(const char* sMessage); + explicit BadFormatError(const std::string& sMessage); BadFormatError(const BadFormatError&) = default; BadFormatError(BadFormatError&&) = default; /// Destruction @@ -486,8 +486,8 @@ class BaseExport AccessViolation: public Exception public: /// Construction AccessViolation(); - AccessViolation(const char* sMessage); - AccessViolation(const std::string& sMessage); + explicit AccessViolation(const char* sMessage); + explicit AccessViolation(const std::string& sMessage); AccessViolation(const AccessViolation&) = default; AccessViolation(AccessViolation&&) = default; /// Destruction @@ -507,8 +507,8 @@ public: /// Construction AbnormalProgramTermination(); /// Construction - AbnormalProgramTermination(const char* sMessage); - AbnormalProgramTermination(const std::string& sMessage); + explicit AbnormalProgramTermination(const char* sMessage); + explicit AbnormalProgramTermination(const std::string& sMessage); AbnormalProgramTermination(const AbnormalProgramTermination&) = default; AbnormalProgramTermination(AbnormalProgramTermination&&) = default; /// Destruction @@ -527,8 +527,8 @@ class BaseExport UnknownProgramOption: public Exception public: /// Construction UnknownProgramOption(); - UnknownProgramOption(const char* sMessage); - UnknownProgramOption(const std::string& sMessage); + explicit UnknownProgramOption(const char* sMessage); + explicit UnknownProgramOption(const std::string& sMessage); UnknownProgramOption(const UnknownProgramOption&) = default; UnknownProgramOption(UnknownProgramOption&&) = default; /// Destruction @@ -547,8 +547,8 @@ class BaseExport ProgramInformation: public Exception public: /// Construction ProgramInformation(); - ProgramInformation(const char* sMessage); - ProgramInformation(const std::string& sMessage); + explicit ProgramInformation(const char* sMessage); + explicit ProgramInformation(const std::string& sMessage); ProgramInformation(const ProgramInformation&) = default; ProgramInformation(ProgramInformation&&) = default; @@ -567,8 +567,8 @@ class BaseExport TypeError: public Exception public: /// Construction TypeError(); - TypeError(const char* sMessage); - TypeError(const std::string& sMessage); + explicit TypeError(const char* sMessage); + explicit TypeError(const std::string& sMessage); TypeError(const TypeError&) = default; TypeError(TypeError&&) = default; /// Destruction @@ -587,8 +587,8 @@ class BaseExport ValueError: public Exception public: /// Construction ValueError(); - ValueError(const char* sMessage); - ValueError(const std::string& sMessage); + explicit ValueError(const char* sMessage); + explicit ValueError(const std::string& sMessage); ValueError(const ValueError&) = default; ValueError(ValueError&&) = default; /// Destruction @@ -607,8 +607,8 @@ class BaseExport IndexError: public Exception public: /// Construction IndexError(); - IndexError(const char* sMessage); - IndexError(const std::string& sMessage); + explicit IndexError(const char* sMessage); + explicit IndexError(const std::string& sMessage); IndexError(const IndexError&) = default; IndexError(IndexError&&) = default; /// Destruction @@ -623,8 +623,8 @@ class BaseExport NameError: public Exception public: /// Construction NameError(); - NameError(const char* sMessage); - NameError(const std::string& sMessage); + explicit NameError(const char* sMessage); + explicit NameError(const std::string& sMessage); NameError(const NameError&) = default; NameError(NameError&&) = default; /// Destruction @@ -639,8 +639,8 @@ class BaseExport ImportError: public Exception public: /// Construction ImportError(); - ImportError(const char* sMessage); - ImportError(const std::string& sMessage); + explicit ImportError(const char* sMessage); + explicit ImportError(const std::string& sMessage); ImportError(const ImportError&) = default; ImportError(ImportError&&) = default; /// Destruction @@ -659,8 +659,8 @@ class BaseExport AttributeError: public Exception public: /// Construction AttributeError(); - AttributeError(const char* sMessage); - AttributeError(const std::string& sMessage); + explicit AttributeError(const char* sMessage); + explicit AttributeError(const std::string& sMessage); AttributeError(const AttributeError&) = default; AttributeError(AttributeError&&) = default; /// Destruction @@ -679,8 +679,8 @@ class BaseExport RuntimeError: public Exception public: /// Construction RuntimeError(); - RuntimeError(const char* sMessage); - RuntimeError(const std::string& sMessage); + explicit RuntimeError(const char* sMessage); + explicit RuntimeError(const std::string& sMessage); RuntimeError(const RuntimeError&) = default; RuntimeError(RuntimeError&&) = default; /// Destruction @@ -699,8 +699,8 @@ class BaseExport BadGraphError: public RuntimeError public: /// Construction BadGraphError(); - BadGraphError(const char* sMessage); - BadGraphError(const std::string& sMessage); + explicit BadGraphError(const char* sMessage); + explicit BadGraphError(const std::string& sMessage); BadGraphError(const BadGraphError&) = default; BadGraphError(BadGraphError&&) = default; /// Destruction @@ -719,8 +719,8 @@ class BaseExport NotImplementedError: public Exception public: /// Construction NotImplementedError(); - NotImplementedError(const char* sMessage); - NotImplementedError(const std::string& sMessage); + explicit NotImplementedError(const char* sMessage); + explicit NotImplementedError(const std::string& sMessage); NotImplementedError(const NotImplementedError&) = default; NotImplementedError(NotImplementedError&&) = default; /// Destruction @@ -739,8 +739,8 @@ class BaseExport ZeroDivisionError: public Exception public: /// Construction ZeroDivisionError(); - ZeroDivisionError(const char* sMessage); - ZeroDivisionError(const std::string& sMessage); + explicit ZeroDivisionError(const char* sMessage); + explicit ZeroDivisionError(const std::string& sMessage); ZeroDivisionError(const ZeroDivisionError&) = default; ZeroDivisionError(ZeroDivisionError&&) = default; /// Destruction @@ -759,8 +759,8 @@ class BaseExport ReferenceError: public Exception public: /// Construction ReferenceError(); - ReferenceError(const char* sMessage); - ReferenceError(const std::string& sMessage); + explicit ReferenceError(const char* sMessage); + explicit ReferenceError(const std::string& sMessage); ReferenceError(const ReferenceError&) = default; ReferenceError(ReferenceError&&) = default; /// Destruction @@ -780,8 +780,8 @@ class BaseExport ExpressionError: public Exception public: /// Construction ExpressionError(); - ExpressionError(const char* sMessage); - ExpressionError(const std::string& sMessage); + explicit ExpressionError(const char* sMessage); + explicit ExpressionError(const std::string& sMessage); ExpressionError(const ExpressionError&) = default; ExpressionError(ExpressionError&&) = default; /// Destruction @@ -800,8 +800,8 @@ class BaseExport ParserError: public Exception public: /// Construction ParserError(); - ParserError(const char* sMessage); - ParserError(const std::string& sMessage); + explicit ParserError(const char* sMessage); + explicit ParserError(const std::string& sMessage); ParserError(const ParserError&) = default; ParserError(ParserError&&) = default; /// Destruction @@ -820,8 +820,8 @@ class BaseExport UnicodeError: public Exception public: /// Construction UnicodeError(); - UnicodeError(const char* sMessage); - UnicodeError(const std::string& sMessage); + explicit UnicodeError(const char* sMessage); + explicit UnicodeError(const std::string& sMessage); UnicodeError(const UnicodeError&) = default; UnicodeError(UnicodeError&&) = default; /// Destruction @@ -840,8 +840,8 @@ class BaseExport OverflowError: public Exception public: /// Construction OverflowError(); - OverflowError(const char* sMessage); - OverflowError(const std::string& sMessage); + explicit OverflowError(const char* sMessage); + explicit OverflowError(const std::string& sMessage); OverflowError(const OverflowError&) = default; OverflowError(OverflowError&&) = default; /// Destruction @@ -860,8 +860,8 @@ class BaseExport UnderflowError: public Exception public: /// Construction UnderflowError(); - UnderflowError(const char* sMessage); - UnderflowError(const std::string& sMessage); + explicit UnderflowError(const char* sMessage); + explicit UnderflowError(const std::string& sMessage); UnderflowError(const UnderflowError&) = default; UnderflowError(UnderflowError&&) = default; /// Destruction @@ -880,8 +880,8 @@ class BaseExport UnitsMismatchError: public Exception public: /// Construction UnitsMismatchError(); - UnitsMismatchError(const char* sMessage); - UnitsMismatchError(const std::string& sMessage); + explicit UnitsMismatchError(const char* sMessage); + explicit UnitsMismatchError(const std::string& sMessage); UnitsMismatchError(const UnitsMismatchError&) = default; UnitsMismatchError(UnitsMismatchError&&) = default; /// Destruction @@ -901,8 +901,8 @@ class BaseExport CADKernelError: public Exception public: /// Construction CADKernelError(); - CADKernelError(const char* sMessage); - CADKernelError(const std::string& sMessage); + explicit CADKernelError(const char* sMessage); + explicit CADKernelError(const std::string& sMessage); CADKernelError(const CADKernelError&) = default; CADKernelError(CADKernelError&&) = default; /// Destruction @@ -924,8 +924,8 @@ class BaseExport RestoreError: public Exception public: /// Construction RestoreError(); - RestoreError(const char* sMessage); - RestoreError(const std::string& sMessage); + explicit RestoreError(const char* sMessage); + explicit RestoreError(const std::string& sMessage); RestoreError(const RestoreError&) = default; RestoreError(RestoreError&&) = default; /// Destruction diff --git a/src/Base/FileInfo.h b/src/Base/FileInfo.h index 0f120386a6..502dec3f4a 100644 --- a/src/Base/FileInfo.h +++ b/src/Base/FileInfo.h @@ -59,8 +59,8 @@ public: }; /// Construction - FileInfo(const char* fileName = ""); - FileInfo(const std::string& fileName); + explicit FileInfo(const char* fileName = ""); + explicit FileInfo(const std::string& fileName); /// Set a new file name void setFile(const char* name); /// Set a new file name diff --git a/src/Base/InputSource.h b/src/Base/InputSource.h index a56d5bc507..de8dd61d3a 100644 --- a/src/Base/InputSource.h +++ b/src/Base/InputSource.h @@ -44,10 +44,12 @@ namespace Base class BaseExport StdInputStream: public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream { public: - StdInputStream(std::istream& Stream, + // clang-format off + explicit StdInputStream(std::istream& Stream, XERCES_CPP_NAMESPACE_QUALIFIER MemoryManager* const manager = - XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager); + XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::fgMemoryManager); ~StdInputStream() override; + // clang-format on // ----------------------------------------------------------------------- // Implementation of the input stream interface diff --git a/src/Base/Interpreter.h b/src/Base/Interpreter.h index 43b85ee0d7..e42305c8a2 100644 --- a/src/Base/Interpreter.h +++ b/src/Base/Interpreter.h @@ -95,7 +95,7 @@ class BaseExport PyException: public Exception public: /// constructor does the whole job PyException(); - PyException(const Py::Object& obj); + explicit PyException(const Py::Object& obj); PyException(const PyException&) = default; PyException(PyException&&) = default; ~PyException() noexcept override; diff --git a/src/Base/PythonTypeExt.h b/src/Base/PythonTypeExt.h index 31eb76c87b..905657f00c 100644 --- a/src/Base/PythonTypeExt.h +++ b/src/Base/PythonTypeExt.h @@ -41,7 +41,7 @@ namespace Base class BaseExport PythonTypeExt { public: - PythonTypeExt(Py::PythonType& type); + explicit PythonTypeExt(Py::PythonType& type); Py::PythonType& set_tp_descr_get(PyObject* (*tp_descr_get)(PyObject* self, PyObject* obj, PyObject* type)); diff --git a/src/Base/Stream.h b/src/Base/Stream.h index 3db89acedf..43eea806e2 100644 --- a/src/Base/Stream.h +++ b/src/Base/Stream.h @@ -79,7 +79,7 @@ private: class BaseExport OutputStream: public Stream { public: - OutputStream(std::ostream& rout); + explicit OutputStream(std::ostream& rout); ~OutputStream() override; OutputStream& operator<<(bool b); @@ -110,7 +110,7 @@ private: class BaseExport InputStream: public Stream { public: - InputStream(std::istream& rin); + explicit InputStream(std::istream& rin); ~InputStream() override; InputStream& operator>>(bool& b); @@ -125,7 +125,7 @@ public: InputStream& operator>>(float& f); InputStream& operator>>(double& d); - operator bool() const + explicit operator bool() const { // test if _Ipfx succeeded return !_in.eof(); @@ -213,7 +213,7 @@ private: class BaseExport IODeviceOStreambuf: public std::streambuf { public: - IODeviceOStreambuf(QIODevice* dev); + explicit IODeviceOStreambuf(QIODevice* dev); ~IODeviceOStreambuf() override; protected: @@ -243,7 +243,7 @@ private: class BaseExport IODeviceIStreambuf: public std::streambuf { public: - IODeviceIStreambuf(QIODevice* dev); + explicit IODeviceIStreambuf(QIODevice* dev); ~IODeviceIStreambuf() override; protected: @@ -287,7 +287,7 @@ public: Unknown }; - PyStreambuf(PyObject* o, std::size_t buf_size = 256, std::size_t put_back = 8); + explicit PyStreambuf(PyObject* o, std::size_t buf_size = 256, std::size_t put_back = 8); ~PyStreambuf() override; void setType(Type t) { @@ -364,7 +364,7 @@ public: ofstream() = default; ofstream(const ofstream&) = delete; ofstream(ofstream&&) = delete; - ofstream(const FileInfo& fi, ios_base::openmode mode = std::ios::out | std::ios::trunc) + explicit ofstream(const FileInfo& fi, ios_base::openmode mode = std::ios::out | std::ios::trunc) #ifdef _MSC_VER : std::ofstream(fi.toStdWString().c_str(), mode) {} #else @@ -397,7 +397,7 @@ public: ifstream() = default; ifstream(const ifstream&) = delete; ifstream(ifstream&&) = delete; - ifstream(const FileInfo& fi, ios_base::openmode mode = std::ios::in) + explicit ifstream(const FileInfo& fi, ios_base::openmode mode = std::ios::in) #ifdef _MSC_VER : std::ifstream(fi.toStdWString().c_str(), mode) {} #else diff --git a/src/Base/Tools.h b/src/Base/Tools.h index 194c92901b..ab7d566460 100644 --- a/src/Base/Tools.h +++ b/src/Base/Tools.h @@ -49,7 +49,7 @@ public: { return n++; } - iotaGen(T v) + explicit iotaGen(T v) : n(v) {} diff --git a/src/Base/ViewProj.h b/src/Base/ViewProj.h index 1788289714..b986447bc3 100644 --- a/src/Base/ViewProj.h +++ b/src/Base/ViewProj.h @@ -80,7 +80,7 @@ private: class BaseExport ViewProjMatrix: public ViewProjMethod { public: - ViewProjMatrix(const Matrix4D& rclMtx); + explicit ViewProjMatrix(const Matrix4D& rclMtx); Vector3f operator()(const Vector3f& inp) const override; Vector3d operator()(const Vector3d& inp) const override; @@ -103,7 +103,7 @@ private: class BaseExport ViewOrthoProjMatrix: public ViewProjMethod { public: - ViewOrthoProjMatrix(const Matrix4D& rclMtx); + explicit ViewOrthoProjMatrix(const Matrix4D& rclMtx); Vector3f operator()(const Vector3f& rclPt) const override; Vector3d operator()(const Vector3d& rclPt) const override; diff --git a/src/Base/Writer.h b/src/Base/Writer.h index 63bbdfcd37..b2926018ef 100644 --- a/src/Base/Writer.h +++ b/src/Base/Writer.h @@ -187,8 +187,8 @@ private: class BaseExport ZipWriter: public Writer { public: - ZipWriter(const char* FileName); - ZipWriter(std::ostream&); + explicit ZipWriter(const char* FileName); + explicit ZipWriter(std::ostream&); ~ZipWriter() override; void writeFiles() override; @@ -253,7 +253,7 @@ private: class BaseExport FileWriter: public Writer { public: - FileWriter(const char* DirName); + explicit FileWriter(const char* DirName); ~FileWriter() override; void putNextEntry(const char* file); diff --git a/src/Base/XMLTools.h b/src/Base/XMLTools.h index 80bbc975f0..7becb7e51a 100644 --- a/src/Base/XMLTools.h +++ b/src/Base/XMLTools.h @@ -59,7 +59,7 @@ private: class StrX { public: - StrX(const XMLCh* const toTranscode); + explicit StrX(const XMLCh* const toTranscode); ~StrX(); /// Getter method @@ -105,7 +105,7 @@ inline const char* StrX::c_str() const class StrXUTF8 { public: - StrXUTF8(const XMLCh* const toTranscode); + explicit StrXUTF8(const XMLCh* const toTranscode); /// Getter method const char* c_str() const; @@ -143,7 +143,7 @@ class XStr { public: /// Constructors and Destructor - XStr(const char* const toTranscode); + explicit XStr(const char* const toTranscode); ~XStr(); @@ -184,7 +184,7 @@ inline const XMLCh* XStr::unicodeForm() const class XUTF8Str { public: - XUTF8Str(const char* const fromTranscode); + explicit XUTF8Str(const char* const fromTranscode); ~XUTF8Str(); /// Getter method diff --git a/src/Gui/ViewProviderExtern.cpp b/src/Gui/ViewProviderExtern.cpp index 7e235453be..6ed09f8afc 100644 --- a/src/Gui/ViewProviderExtern.cpp +++ b/src/Gui/ViewProviderExtern.cpp @@ -58,7 +58,7 @@ void ViewProviderExtern::setModeByString(const char* name, const char* ivFragmen void ViewProviderExtern::setModeByFile(const char* name, const char* ivFileName) { SoInput in; - Base::ifstream file(ivFileName, std::ios::in | std::ios::binary); + Base::ifstream file(Base::FileInfo(ivFileName), std::ios::in | std::ios::binary); if (file){ std::streamoff size = 0; std::streambuf* buf = file.rdbuf(); diff --git a/src/Mod/Mesh/App/Exporter.cpp b/src/Mod/Mesh/App/Exporter.cpp index ca3f8062b2..a4a34616f2 100644 --- a/src/Mod/Mesh/App/Exporter.cpp +++ b/src/Mod/Mesh/App/Exporter.cpp @@ -155,7 +155,7 @@ void Exporter::throwIfNoPermission(const std::string& filename) Base::FileInfo fi(filename); Base::FileInfo di(fi.dirPath()); if ((fi.exists() && !fi.isWritable()) || !di.exists() || !di.isWritable()) { - throw Base::FileException("No write permission for file", filename); + throw Base::FileException("No write permission for file", fi); } } diff --git a/src/Mod/Points/App/Points.cpp b/src/Mod/Points/App/Points.cpp index 731dedb295..67e9d4bfef 100644 --- a/src/Mod/Points/App/Points.cpp +++ b/src/Mod/Points/App/Points.cpp @@ -214,7 +214,7 @@ void PointKernel::RestoreDocFile(Base::Reader& reader) void PointKernel::save(const char* file) const { - Base::ofstream out(file, std::ios::out); + Base::ofstream out(Base::FileInfo(file), std::ios::out); save(out); } diff --git a/src/Mod/Points/App/PointsAlgos.cpp b/src/Mod/Points/App/PointsAlgos.cpp index 4d42564668..491005e633 100644 --- a/src/Mod/Points/App/PointsAlgos.cpp +++ b/src/Mod/Points/App/PointsAlgos.cpp @@ -1981,7 +1981,7 @@ void PlyWriter::write(const std::string& filename) col += 1; } - Base::ofstream out(filename, std::ios::out); + Base::ofstream out(Base::FileInfo(filename), std::ios::out); out << "ply" << std::endl << "format ascii 1.0" << std::endl << "comment FreeCAD generated" << std::endl; @@ -2130,7 +2130,7 @@ void PcdWriter::write(const std::string& filename) } std::size_t numFields = fields.size(); - Base::ofstream out(filename, std::ios::out); + Base::ofstream out(Base::FileInfo(filename), std::ios::out); out << "# .PCD v0.7 - Point Cloud Data file format" << std::endl << "VERSION 0.7" << std::endl; // the fields