Add GNU -Werror & fix warnings (#801)

This commit is contained in:
Bertrand Darbon 2021-04-15 13:27:15 +02:00 committed by GitHub
parent 4eeba18088
commit 44a8a2d5f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 76 additions and 38 deletions

View File

@ -66,6 +66,10 @@ else (BUILD_DROGON_SHARED)
add_library(${PROJECT_NAME} STATIC)
endif (BUILD_DROGON_SHARED)
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)
endif()
include(GenerateExportHeader)
generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/exports/drogon/exports.h)

View File

@ -22,22 +22,22 @@ using namespace drogon::orm;
using namespace drogon;
void DbClientManager::createDbClients(
const std::vector<trantor::EventLoop *> &ioloops)
const std::vector<trantor::EventLoop *> & /*ioloops*/)
{
return;
}
void DbClientManager::createDbClient(const std::string &dbType,
const std::string &host,
const unsigned short port,
const std::string &databaseName,
const std::string &userName,
const std::string &password,
const size_t connectionNum,
const std::string &filename,
const std::string &name,
const bool isFast,
const std::string &characterSet)
void DbClientManager::createDbClient(const std::string & /*dbType*/,
const std::string & /*host*/,
const unsigned short /*port*/,
const std::string & /*databaseName*/,
const std::string & /*userName*/,
const std::string & /*password*/,
const size_t /*connectionNum*/,
const std::string & /*filename*/,
const std::string & /*name*/,
const bool /*isFast*/,
const std::string & /*characterSet*/)
{
LOG_FATAL << "No database is supported by drogon, please install the "
"database development library first.";

View File

@ -1012,7 +1012,8 @@ const HttpResponsePtr &HttpAppFrameworkImpl::getCustom404Page()
static IOThreadStorage<HttpResponsePtr> thread404Pages;
static std::once_flag once;
std::call_once(once, [this] {
thread404Pages.init([this](HttpResponsePtr &resp, size_t index) {
thread404Pages.init(
[this](HttpResponsePtr &resp, size_t /*index*/) {
resp = std::make_shared<HttpResponseImpl>(
*static_cast<HttpResponseImpl *>(custom404_.get()));
});

View File

@ -42,7 +42,7 @@ void HttpControllersRouter::doWhenNoHandlerFound(
}
void HttpControllersRouter::init(
const std::vector<trantor::EventLoop *> &ioLoops)
const std::vector<trantor::EventLoop *> & /*ioLoops*/)
{
for (auto &router : ctrlVector_)
{
@ -537,7 +537,7 @@ void HttpControllersRouter::route(
void HttpControllersRouter::doControllerHandler(
const CtrlBinderPtr &ctrlBinderPtr,
const HttpControllerRouterItem &routerItem,
const HttpControllerRouterItem & /*routerItem*/,
const HttpRequestImplPtr &req,
const std::smatch &matchResult,
std::function<void(const HttpResponsePtr &)> &&callback)

View File

@ -45,7 +45,7 @@ class HttpMessageBody
}
virtual const std::string &getString() const = 0;
virtual std::string &getString() = 0;
virtual void append(const char *buf, size_t len)
virtual void append(const char * /*buf*/, size_t /*len*/)
{
}
virtual ~HttpMessageBody()

View File

@ -134,7 +134,7 @@ HttpResponsePtr HttpResponse::newNotFoundResponse()
static IOThreadStorage<HttpResponsePtr> thread404Pages;
std::call_once(threadOnce, [] {
thread404Pages.init(
[](drogon::HttpResponsePtr &resp, size_t index) {
[](drogon::HttpResponsePtr &resp, size_t /*index*/) {
if (HttpAppFrameworkImpl::instance()
.isUsingCustomErrorHandler())
{

View File

@ -300,7 +300,7 @@ HttpSimpleControllersRouter::getHandlersInfo() const
}
void HttpSimpleControllersRouter::init(
const std::vector<trantor::EventLoop *> &ioLoops)
const std::vector<trantor::EventLoop *> & /*ioLoops*/)
{
for (auto &iter : simpleCtrlMap_)
{

View File

@ -22,17 +22,17 @@ using namespace drogon::nosql;
using namespace drogon;
void RedisClientManager::createRedisClients(
const std::vector<trantor::EventLoop *> &ioloops)
const std::vector<trantor::EventLoop *> & /*ioloops*/)
{
return;
}
void RedisClientManager::createRedisClient(const std::string &name,
const std::string &host,
unsigned short port,
const std::string &password,
size_t connectionNum,
bool isFast)
void RedisClientManager::createRedisClient(const std::string & /*name*/,
const std::string & /*host*/,
unsigned short /*port*/,
const std::string & /*password*/,
size_t /*connectionNum*/,
bool /*isFast*/)
{
LOG_FATAL << "Redis is not supported by drogon, please install the "
"hiredis library first.";

View File

@ -19,9 +19,9 @@ namespace drogon
namespace nosql
{
std::shared_ptr<RedisClient> RedisClient::newRedisClient(
const trantor::InetAddress &serverAddress,
size_t numberOfConnections,
const std::string &password)
const trantor::InetAddress& /*serverAddress*/,
size_t /*numberOfConnections*/,
const std::string& /*password*/)
{
LOG_FATAL << "Redis is not supported by drogon, please install the "
"hiredis library first.";

View File

@ -27,7 +27,7 @@ std::string RedisResult::getStringForDisplaying() const noexcept
}
std::string RedisResult::getStringForDisplayingWithIndent(
size_t indent) const noexcept
size_t /*indent*/) const noexcept
{
LOG_FATAL << "Redis is not supported by drogon, please install the "
"hiredis library first.";

View File

@ -20,7 +20,6 @@ using namespace drogon;
SessionManager::SessionManager(trantor::EventLoop *loop, size_t timeout)
: loop_(loop), timeout_(timeout)
{
assert(timeout_ >= 0);
if (timeout_ > 0)
{
size_t wheelNum = 1;

View File

@ -36,7 +36,7 @@ class SharedLibManager : public trantor::NonCopyable
struct DLStat
{
void *handle{nullptr};
struct timespec mTime = {0};
struct timespec mTime = {0, 0};
};
std::unordered_map<std::string, DLStat> dlMap_;
void *compileAndLoadLib(const std::string &sourceFile, void *oldHld);

View File

@ -830,7 +830,20 @@ std::string urlDecode(const char *begin, const char *end)
/* Compress gzip data */
std::string gzipCompress(const char *data, const size_t ndata)
{
z_stream strm = {0};
z_stream strm = {nullptr,
0,
0,
nullptr,
0,
0,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
0,
0,
0};
if (data && ndata > 0)
{
if (deflateInit2(&strm,
@ -884,7 +897,20 @@ std::string gzipDecompress(const char *data, const size_t ndata)
auto decompressed = std::string(full_length * 2, 0);
bool done = false;
z_stream strm = {0};
z_stream strm = {nullptr,
0,
0,
nullptr,
0,
0,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
0,
0,
0};
strm.next_in = (Bytef *)data;
strm.avail_in = static_cast<uInt>(ndata);
strm.total_out = 0;

View File

@ -43,11 +43,11 @@ class RedisException final : public std::exception
return code_;
}
RedisException(RedisErrorCode code, const std::string &message)
: code_(code), message_(message)
: message_(message), code_(code)
{
}
RedisException(RedisErrorCode code, std::string &&message)
: code_(code), message_(std::move(message))
: message_(std::move(message)), code_(code)
{
}
RedisException() = delete;

View File

@ -38,6 +38,8 @@ std::shared_ptr<DbClient> DbClient::newPgClient(const std::string &connInfo,
#else
LOG_FATAL << "PostgreSQL is not supported!";
exit(1);
(void)(connInfo);
(void)(connNum);
#endif
}
@ -49,6 +51,8 @@ std::shared_ptr<DbClient> DbClient::newMysqlClient(const std::string &connInfo,
#else
LOG_FATAL << "Mysql is not supported!";
exit(1);
(void)(connInfo);
(void)(connNum);
#endif
}
@ -63,5 +67,7 @@ std::shared_ptr<DbClient> DbClient::newSqlite3Client(
#else
LOG_FATAL << "Sqlite3 is not supported!";
exit(1);
(void)(connInfo);
(void)(connNum);
#endif
}

View File

@ -369,6 +369,7 @@ DbConnectionPtr DbClientImpl::newConnection(trantor::EventLoop *loop)
else
{
return nullptr;
(void)(loop);
}
std::weak_ptr<DbClientImpl> weakPtr = shared_from_this();

View File

@ -327,5 +327,6 @@ int SqlBinder::getMysqlTypeBySize(size_t size)
LOG_FATAL << "Mysql is not supported!";
exit(1);
return 0;
(void)(size);
#endif
}