Fix some issues found with clang-tidy (#4353)

* directoryiterator: Fix missing inline

Add missing inline to inline function.

This was found with clang-tidy check:  misc-definitions-in-headers

* Convert deprecated throw() to noexcept

throw() has been deprecated in standar in C++17. It has been removed in
C++20. Code still compiles but let's just define these at those should
be.

These where found with clang-tidy check: modernize-use-noexcept

* Fix unnecessary copy initializations

Clang-tidy did find these with check:

  performance-unnecessary-copy-initialization

* Fix some strings not references

Looks like these are just missing reference marks.

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
Kari Argillander 2023-12-17 17:55:30 +02:00 committed by GitHub
parent 111fe90dd9
commit bf3c519183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 29 additions and 30 deletions

View File

@ -33,11 +33,11 @@ public:
long data2lineNumber, long data2lineNumber,
const std::string& fileName); const std::string& fileName);
CppUnitException(const CppUnitException& other); CppUnitException(const CppUnitException& other);
virtual ~CppUnitException() throw(); virtual ~CppUnitException() noexcept;
CppUnitException& operator = (const CppUnitException& other); CppUnitException& operator = (const CppUnitException& other);
const char* what() const throw (); const char* what() const noexcept;
long lineNumber() const; long lineNumber() const;
long data1LineNumber() const; long data1LineNumber() const;
@ -81,7 +81,7 @@ inline CppUnitException::CppUnitException (const std::string& message, long line
} }
inline CppUnitException::~CppUnitException () throw() inline CppUnitException::~CppUnitException () noexcept
{ {
} }
@ -102,7 +102,7 @@ inline CppUnitException& CppUnitException::operator = (const CppUnitException& o
} }
inline const char* CppUnitException::what() const throw () inline const char* CppUnitException::what() const noexcept
{ {
return _message.c_str(); return _message.c_str();
} }

View File

@ -45,7 +45,7 @@ PostgreSQLException::PostgreSQLException(const PostgreSQLException& anException)
} }
PostgreSQLException::~PostgreSQLException() throw() PostgreSQLException::~PostgreSQLException() noexcept
{ {
} }

View File

@ -100,7 +100,7 @@ Session SessionPoolContainer::get(const std::string& name)
SessionPool& SessionPoolContainer::getPool(const std::string& name) SessionPool& SessionPoolContainer::getPool(const std::string& name)
{ {
URI uri(name); URI uri(name);
std::string path = uri.getPath(); const std::string& path = uri.getPath();
poco_assert (!path.empty()); poco_assert (!path.empty());
std::string n = Session::uri(uri.getScheme(), path.substr(1)); std::string n = Session::uri(uri.getScheme(), path.substr(1));

View File

@ -47,7 +47,7 @@ private:
// //
// inlines // inlines
// //
const std::string& DirectoryIteratorImpl::get() const inline const std::string& DirectoryIteratorImpl::get() const
{ {
return _current; return _current;
} }

View File

@ -56,7 +56,7 @@ std::istream* URIStreamOpener::open(const std::string& pathOrURI) const
try try
{ {
URI uri(pathOrURI); URI uri(pathOrURI);
std::string scheme(uri.getScheme()); const std::string& scheme(uri.getScheme());
FactoryMap::const_iterator it = _map.find(scheme); FactoryMap::const_iterator it = _map.find(scheme);
if (it != _map.end()) if (it != _map.end())
{ {

View File

@ -148,8 +148,8 @@ void Connection::connect(const std::string& uri, SocketFactory& socketFactory)
Poco::URI theURI(uri); Poco::URI theURI(uri);
if (theURI.getScheme() != "mongodb") throw Poco::UnknownURISchemeException(uri); if (theURI.getScheme() != "mongodb") throw Poco::UnknownURISchemeException(uri);
std::string userInfo = theURI.getUserInfo(); const std::string& userInfo = theURI.getUserInfo();
std::string host = theURI.getHost(); const std::string& host = theURI.getHost();
Poco::UInt16 port = theURI.getPort(); Poco::UInt16 port = theURI.getPort();
if (port == 0) port = 27017; if (port == 0) port = 27017;

View File

@ -397,7 +397,7 @@ private:
void newIPv6(const void* hostAddr, Poco::UInt32 scope); void newIPv6(const void* hostAddr, Poco::UInt32 scope);
void newIPv6(unsigned prefix); void newIPv6(unsigned prefix);
static std::string& compressV6(std::string& v6addr); static std::string& compressV6(std::string& v6addr);
static std::string trimIPv6(const std::string v6Addr); static std::string trimIPv6(const std::string& v6Addr);
#endif #endif
Ptr _pImpl; Ptr _pImpl;
}; };

View File

@ -297,7 +297,7 @@ class Net_API MultipartSource: public PartSource
/// mail messages consisting of multiple nested parts. /// mail messages consisting of multiple nested parts.
{ {
public: public:
explicit MultipartSource(const std::string contentType = "multipart/alternative"); explicit MultipartSource(const std::string& contentType = "multipart/alternative");
/// Creates an empty MultipartSource. /// Creates an empty MultipartSource.
/// ///
/// At least one part must be added with addPart(). /// At least one part must be added with addPart().

View File

@ -549,7 +549,7 @@ std::string& IPAddress::compressV6(std::string& v6addr)
} }
std::string IPAddress::trimIPv6(const std::string v6Addr) std::string IPAddress::trimIPv6(const std::string& v6Addr)
{ {
std::string v6addr(v6Addr); std::string v6addr(v6Addr);
std::string::size_type len = v6addr.length(); std::string::size_type len = v6addr.length();

View File

@ -83,7 +83,7 @@ namespace
MailMessage::ContentTransferEncoding cte = MailMessage::ENCODING_7BIT; MailMessage::ContentTransferEncoding cte = MailMessage::ENCODING_7BIT;
if (header.has(MailMessage::HEADER_CONTENT_TRANSFER_ENCODING)) if (header.has(MailMessage::HEADER_CONTENT_TRANSFER_ENCODING))
{ {
std::string enc = header[MailMessage::HEADER_CONTENT_TRANSFER_ENCODING]; const std::string& enc = header[MailMessage::HEADER_CONTENT_TRANSFER_ENCODING];
if (enc == MailMessage::CTE_8BIT) if (enc == MailMessage::CTE_8BIT)
cte = MailMessage::ENCODING_8BIT; cte = MailMessage::ENCODING_8BIT;
else if (enc == MailMessage::CTE_QUOTED_PRINTABLE) else if (enc == MailMessage::CTE_QUOTED_PRINTABLE)
@ -692,7 +692,7 @@ PartSource* MailMessage::createPartStore(const std::string& content, const std::
} }
MultipartSource::MultipartSource(const std::string contentType): MultipartSource::MultipartSource(const std::string& contentType):
PartSource(contentTypeWithBoundary(contentType)) PartSource(contentTypeWithBoundary(contentType))
{ {
} }

View File

@ -197,7 +197,7 @@ struct RedisTypeTraits<BulkString>
} }
else else
{ {
std::string s = value.value(); const std::string& s = value.value();
return marker return marker
+ NumberFormatter::format(s.length()) + NumberFormatter::format(s.length())
+ LineEnding::NEWLINE_CRLF + LineEnding::NEWLINE_CRLF

View File

@ -33,13 +33,13 @@ class XML_API XMLStreamParserException: public Poco::XML::XMLException
public: public:
XMLStreamParserException(const std::string& name, Poco::UInt64 line, Poco::UInt64 column, const std::string& description); XMLStreamParserException(const std::string& name, Poco::UInt64 line, Poco::UInt64 column, const std::string& description);
XMLStreamParserException(const XMLStreamParser&, const std::string& description); XMLStreamParserException(const XMLStreamParser&, const std::string& description);
virtual ~XMLStreamParserException() throw (); virtual ~XMLStreamParserException() noexcept;
const char* name() const noexcept; const char* name() const noexcept;
Poco::UInt64 line() const; Poco::UInt64 line() const;
Poco::UInt64 column() const; Poco::UInt64 column() const;
const std::string& description() const; const std::string& description() const;
virtual const char* what() const throw (); virtual const char* what() const noexcept;
private: private:
void init(); void init();

View File

@ -20,7 +20,7 @@ namespace Poco {
namespace XML { namespace XML {
XMLStreamParserException::~XMLStreamParserException() throw () XMLStreamParserException::~XMLStreamParserException() noexcept
{ {
} }
@ -79,7 +79,7 @@ const std::string& XMLStreamParserException::description() const
} }
char const* XMLStreamParserException::what() const throw () char const* XMLStreamParserException::what() const noexcept
{ {
return _what.c_str(); return _what.c_str();
} }

View File

@ -724,8 +724,7 @@ void XMLWriter::declareNamespaces(const XMLString& namespaceURI, const XMLString
for (int i = 0; i < attributes.getLength(); i++) for (int i = 0; i < attributes.getLength(); i++)
{ {
XMLString attributeNamespaceURI = attributes.getURI(i); XMLString attributeNamespaceURI = attributes.getURI(i);
XMLString attributeLocalName = attributes.getLocalName(i); const XMLString& attributeQName = attributes.getQName(i);
XMLString attributeQName = attributes.getQName(i);
XMLString attributePrefix; XMLString attributePrefix;
XMLString attributeLocal; XMLString attributeLocal;
@ -774,9 +773,9 @@ void XMLWriter::declareAttributeNamespaces(const Attributes& attributes)
{ {
for (int i = 0; i < attributes.getLength(); i++) for (int i = 0; i < attributes.getLength(); i++)
{ {
XMLString namespaceURI = attributes.getURI(i); const XMLString& namespaceURI = attributes.getURI(i);
XMLString localName = attributes.getLocalName(i); const XMLString& localName = attributes.getLocalName(i);
XMLString qname = attributes.getQName(i); const XMLString& qname = attributes.getQName(i);
if (!localName.empty()) if (!localName.empty())
{ {
XMLString prefix; XMLString prefix;
@ -841,8 +840,8 @@ void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attr
{ {
for (int i = 0; i < attributes.getLength(); i++) for (int i = 0; i < attributes.getLength(); i++)
{ {
XMLString namespaceURI = attributes.getURI(i); const XMLString& namespaceURI = attributes.getURI(i);
XMLString localName = attributes.getLocalName(i); const XMLString& localName = attributes.getLocalName(i);
XMLString qname = attributes.getQName(i); XMLString qname = attributes.getQName(i);
if (!localName.empty()) if (!localName.empty())
{ {
@ -866,8 +865,8 @@ void XMLWriter::addAttributes(CanonicalAttributeMap& attributeMap, const Attribu
{ {
for (int i = 0; i < attributes.getLength(); i++) for (int i = 0; i < attributes.getLength(); i++)
{ {
XMLString namespaceURI = attributes.getURI(i); const XMLString& namespaceURI = attributes.getURI(i);
XMLString localName = attributes.getLocalName(i); const XMLString& localName = attributes.getLocalName(i);
XMLString qname = attributes.getQName(i); XMLString qname = attributes.getQName(i);
XMLString fullQName = qname; XMLString fullQName = qname;
if (!localName.empty()) if (!localName.empty())

View File

@ -79,7 +79,7 @@ bool Decompress::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeade
// directory have 0 size, nth to read // directory have 0 size, nth to read
if (!_flattenDirs) if (!_flattenDirs)
{ {
std::string dirName = hdr.getFileName(); const std::string& dirName = hdr.getFileName();
if (!ZipCommon::isValidPath(dirName)) if (!ZipCommon::isValidPath(dirName))
throw ZipException("Illegal entry name", dirName); throw ZipException("Illegal entry name", dirName);
Poco::Path dir(_outDir, dirName); Poco::Path dir(_outDir, dirName);