Skip to content

Commit

Permalink
Fix some issues found with clang-tidy (pocoproject#4353)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
teksturi and Kari Argillander authored Dec 17, 2023
1 parent 111fe90 commit bf3c519
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 30 deletions.
8 changes: 4 additions & 4 deletions CppUnit/include/CppUnit/CppUnitException.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class CppUnit_API CppUnitException: public std::exception
long data2lineNumber,
const std::string& fileName);
CppUnitException(const CppUnitException& other);
virtual ~CppUnitException() throw();
virtual ~CppUnitException() noexcept;

CppUnitException& operator = (const CppUnitException& other);

const char* what() const throw ();
const char* what() const noexcept;

long lineNumber() const;
long data1LineNumber() const;
Expand Down Expand Up @@ -81,7 +81,7 @@ inline CppUnitException::CppUnitException (const std::string& message, long line
}


inline CppUnitException::~CppUnitException () throw()
inline CppUnitException::~CppUnitException () noexcept
{
}

Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Data/PostgreSQL/src/PostgreSQLException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ PostgreSQLException::PostgreSQLException(const PostgreSQLException& anException)
}


PostgreSQLException::~PostgreSQLException() throw()
PostgreSQLException::~PostgreSQLException() noexcept
{
}

Expand Down
2 changes: 1 addition & 1 deletion Data/src/SessionPoolContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Session SessionPoolContainer::get(const std::string& name)
SessionPool& SessionPoolContainer::getPool(const std::string& name)
{
URI uri(name);
std::string path = uri.getPath();
const std::string& path = uri.getPath();
poco_assert (!path.empty());
std::string n = Session::uri(uri.getScheme(), path.substr(1));

Expand Down
2 changes: 1 addition & 1 deletion Foundation/include/Poco/DirectoryIterator_UNIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Foundation_API DirectoryIteratorImpl
//
// inlines
//
const std::string& DirectoryIteratorImpl::get() const
inline const std::string& DirectoryIteratorImpl::get() const
{
return _current;
}
Expand Down
2 changes: 1 addition & 1 deletion Foundation/src/URIStreamOpener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::istream* URIStreamOpener::open(const std::string& pathOrURI) const
try
{
URI uri(pathOrURI);
std::string scheme(uri.getScheme());
const std::string& scheme(uri.getScheme());
FactoryMap::const_iterator it = _map.find(scheme);
if (it != _map.end())
{
Expand Down
4 changes: 2 additions & 2 deletions MongoDB/src/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ void Connection::connect(const std::string& uri, SocketFactory& socketFactory)
Poco::URI theURI(uri);
if (theURI.getScheme() != "mongodb") throw Poco::UnknownURISchemeException(uri);

std::string userInfo = theURI.getUserInfo();
std::string host = theURI.getHost();
const std::string& userInfo = theURI.getUserInfo();
const std::string& host = theURI.getHost();
Poco::UInt16 port = theURI.getPort();
if (port == 0) port = 27017;

Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class Net_API IPAddress
void newIPv6(const void* hostAddr, Poco::UInt32 scope);
void newIPv6(unsigned prefix);
static std::string& compressV6(std::string& v6addr);
static std::string trimIPv6(const std::string v6Addr);
static std::string trimIPv6(const std::string& v6Addr);
#endif
Ptr _pImpl;
};
Expand Down
2 changes: 1 addition & 1 deletion Net/include/Poco/Net/MailMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class Net_API MultipartSource: public PartSource
/// mail messages consisting of multiple nested parts.
{
public:
explicit MultipartSource(const std::string contentType = "multipart/alternative");
explicit MultipartSource(const std::string& contentType = "multipart/alternative");
/// Creates an empty MultipartSource.
///
/// At least one part must be added with addPart().
Expand Down
2 changes: 1 addition & 1 deletion Net/src/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::size_type len = v6addr.length();
Expand Down
4 changes: 2 additions & 2 deletions Net/src/MailMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace
MailMessage::ContentTransferEncoding cte = MailMessage::ENCODING_7BIT;
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)
cte = MailMessage::ENCODING_8BIT;
else if (enc == MailMessage::CTE_QUOTED_PRINTABLE)
Expand Down Expand Up @@ -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))
{
}
Expand Down
2 changes: 1 addition & 1 deletion Redis/include/Poco/Redis/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ struct RedisTypeTraits<BulkString>
}
else
{
std::string s = value.value();
const std::string& s = value.value();
return marker
+ NumberFormatter::format(s.length())
+ LineEnding::NEWLINE_CRLF
Expand Down
4 changes: 2 additions & 2 deletions XML/include/Poco/XML/XMLStreamParserException.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class XML_API XMLStreamParserException: public Poco::XML::XMLException
public:
XMLStreamParserException(const std::string& name, Poco::UInt64 line, Poco::UInt64 column, const std::string& description);
XMLStreamParserException(const XMLStreamParser&, const std::string& description);
virtual ~XMLStreamParserException() throw ();
virtual ~XMLStreamParserException() noexcept;

const char* name() const noexcept;
Poco::UInt64 line() const;
Poco::UInt64 column() const;
const std::string& description() const;
virtual const char* what() const throw ();
virtual const char* what() const noexcept;

private:
void init();
Expand Down
4 changes: 2 additions & 2 deletions XML/src/XMLStreamParserException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Poco {
namespace XML {


XMLStreamParserException::~XMLStreamParserException() throw ()
XMLStreamParserException::~XMLStreamParserException() noexcept
{
}

Expand Down Expand Up @@ -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();
}
Expand Down
17 changes: 8 additions & 9 deletions XML/src/XMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,7 @@ void XMLWriter::declareNamespaces(const XMLString& namespaceURI, const XMLString
for (int i = 0; i < attributes.getLength(); i++)
{
XMLString attributeNamespaceURI = attributes.getURI(i);
XMLString attributeLocalName = attributes.getLocalName(i);
XMLString attributeQName = attributes.getQName(i);
const XMLString& attributeQName = attributes.getQName(i);

XMLString attributePrefix;
XMLString attributeLocal;
Expand Down Expand Up @@ -774,9 +773,9 @@ void XMLWriter::declareAttributeNamespaces(const Attributes& attributes)
{
for (int i = 0; i < attributes.getLength(); i++)
{
XMLString namespaceURI = attributes.getURI(i);
XMLString localName = attributes.getLocalName(i);
XMLString qname = attributes.getQName(i);
const XMLString& namespaceURI = attributes.getURI(i);
const XMLString& localName = attributes.getLocalName(i);
const XMLString& qname = attributes.getQName(i);
if (!localName.empty())
{
XMLString prefix;
Expand Down Expand Up @@ -841,8 +840,8 @@ void XMLWriter::addAttributes(AttributeMap& attributeMap, const Attributes& attr
{
for (int i = 0; i < attributes.getLength(); i++)
{
XMLString namespaceURI = attributes.getURI(i);
XMLString localName = attributes.getLocalName(i);
const XMLString& namespaceURI = attributes.getURI(i);
const XMLString& localName = attributes.getLocalName(i);
XMLString qname = attributes.getQName(i);
if (!localName.empty())
{
Expand All @@ -866,8 +865,8 @@ void XMLWriter::addAttributes(CanonicalAttributeMap& attributeMap, const Attribu
{
for (int i = 0; i < attributes.getLength(); i++)
{
XMLString namespaceURI = attributes.getURI(i);
XMLString localName = attributes.getLocalName(i);
const XMLString& namespaceURI = attributes.getURI(i);
const XMLString& localName = attributes.getLocalName(i);
XMLString qname = attributes.getQName(i);
XMLString fullQName = qname;
if (!localName.empty())
Expand Down
2 changes: 1 addition & 1 deletion Zip/src/Decompress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ bool Decompress::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeade
// directory have 0 size, nth to read
if (!_flattenDirs)
{
std::string dirName = hdr.getFileName();
const std::string& dirName = hdr.getFileName();
if (!ZipCommon::isValidPath(dirName))
throw ZipException("Illegal entry name", dirName);
Poco::Path dir(_outDir, dirName);
Expand Down

0 comments on commit bf3c519

Please sign in to comment.