Skip to content

Commit d42afac

Browse files
Add Clang support for -Wall -Wextra -Werror; fix -Wunused-parameter warnings when not using OpenSSL (#175)
1 parent 6dba194 commit d42afac

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ else(BUILD_TRANTOR_SHARED)
4646
add_library(${PROJECT_NAME} STATIC)
4747
endif(BUILD_TRANTOR_SHARED)
4848

49-
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND CMAKE_CXX_COMPILER_ID MATCHES GNU)
49+
if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" AND CMAKE_CXX_COMPILER_ID MATCHES Clang|GNU)
5050
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)
5151
endif()
5252

trantor/net/TcpClient.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,13 @@ void TcpClient::enableSSL(
221221
}
222222

223223
#else
224+
// When not using OpenSSL, using `void` here will
225+
// work around the unused parameter warnings without overhead.
226+
(void)useOldTLS;
227+
(void)validateCert;
228+
(void)hostname;
229+
(void)sslConfCmds;
230+
224231
LOG_FATAL << "OpenSSL is not found in your system!";
225232
abort();
226233
#endif

trantor/net/TcpClient.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,13 @@ class TRANTOR_EXPORT TcpClient : NonCopyable
228228
mutable std::mutex mutex_;
229229
TcpConnectionPtr connection_; // @GuardedBy mutex_
230230
std::shared_ptr<SSLContext> sslCtxPtr_;
231-
bool validateCert_{false};
232231
std::string SSLHostName_;
232+
233+
// This member variable is only needed when using OpenSSL, so
234+
// we can safely remove it when not using OpenSSL.
235+
#ifdef USE_OPENSSL
236+
bool validateCert_{false};
237+
#endif
233238
#ifndef _WIN32
234239
class IgnoreSigPipe
235240
{

trantor/net/TcpServer.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ void TcpServer::enableSSL(
195195
/* Create a new OpenSSL context */
196196
sslCtxPtr_ = newSSLServerContext(certPath, keyPath, useOldTLS, sslConfCmds);
197197
#else
198+
// When not using OpenSSL, using `void` here will
199+
// work around the unused parameter warnings without overhead.
200+
(void)certPath;
201+
(void)keyPath;
202+
(void)useOldTLS;
203+
(void)sslConfCmds;
204+
198205
LOG_FATAL << "OpenSSL is not found in your system!";
199206
abort();
200207
#endif

trantor/net/inner/TcpConnectionImpl.cc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,10 @@ std::shared_ptr<SSLContext> newSSLServerContext(
352352
namespace trantor
353353
{
354354
std::shared_ptr<SSLContext> newSSLServerContext(
355-
const std::string &certPath,
356-
const std::string &keyPath,
357-
bool useOldTLS,
358-
const std::vector<std::pair<std::string, std::string>> &sslConfCmds)
355+
const std::string &,
356+
const std::string &,
357+
bool,
358+
const std::vector<std::pair<std::string, std::string>> &)
359359
{
360360
LOG_FATAL << "OpenSSL is not found in your system!";
361361
abort();
@@ -470,6 +470,11 @@ void TcpConnectionImpl::startServerEncryption(
470470
std::function<void()> callback)
471471
{
472472
#ifndef USE_OPENSSL
473+
// When not using OpenSSL, using `void` here will
474+
// work around the unused parameter warnings without overhead.
475+
(void)ctx;
476+
(void)callback;
477+
473478
LOG_FATAL << "OpenSSL is not found in your system!";
474479
abort();
475480
#else
@@ -496,6 +501,14 @@ void TcpConnectionImpl::startClientEncryption(
496501
const std::vector<std::pair<std::string, std::string>> &sslConfCmds)
497502
{
498503
#ifndef USE_OPENSSL
504+
// When not using OpenSSL, using `void` here will
505+
// work around the unused parameter warnings without overhead.
506+
(void)callback;
507+
(void)useOldTLS;
508+
(void)validateCert;
509+
(void)hostname;
510+
(void)sslConfCmds;
511+
499512
LOG_FATAL << "OpenSSL is not found in your system!";
500513
abort();
501514
#else

0 commit comments

Comments
 (0)