Skip to content

Commit cf49723

Browse files
authored
Update to C++17 (#560)
* Upgrading to C++17 * Code Quality: Address compiler warnings - Fixing narrowing issues - Removing useless copies - Removing unused lines - unused-lambda-capture - Removes unused variables - Fix some casts (modernize c-style, or simply remove useless casts) - Explicitly deleting unused endpoint_impl copy and move constructors - Removing redundant std::bind - Improving const correctness - Moving thread init to constructor body - Moved check_routing_credentials_ inside vsomeip security section where it's used - Using =default destructor instead of empty destructor Thread init: Moving the initialization of these threads into the constructor body to ensure that they do not start with an incomplete "this". As they capture this, it is possible that if the new thread begins before the object is fully constructed, the new thread might operate on uninitialized members of "this". * Attempting to fix syntax error on MSVC * Adjusting PR to conform to Covesa style * Using curly brace initialization * Using static_cast to narrow its_device.size() to a socklen_t * Avoided double integer promotion
1 parent 38f9c54 commit cf49723

30 files changed

+129
-125
lines changed

Android.bp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ libvsomeip_sd_srcs = [
3030

3131
cc_defaults {
3232
name: "vsomeip_defaults",
33+
cpp_std: "c++17",
3334

3435
cppflags: [
35-
"-std=c++14",
3636
"-fexceptions",
3737
"-Wno-non-virtual-dtor",
3838
"-Wno-unused-const-variable",

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ if(NOT CMAKE_BUILD_TYPE)
6161
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
6262
endif()
6363

64+
set(CMAKE_CXX_STANDARD 17)
65+
6466
# OS
6567
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
6668
set(DL_LIBRARY "dl")
@@ -248,13 +250,13 @@ if (MSVC)
248250
# add_definitions(-DVSOMEIP_DLL_COMPILATION) now it is controlled per target
249251
SET(BOOST_WINDOWS_VERSION "0x600" CACHE STRING "Set the same Version as the Version with which Boost was built, otherwise there will be errors. (normaly 0x600 is for Windows 7 and 0x501 is for Windows XP)")
250252
# Disable warning C4250 since it warns that the compiler is correctly following the C++ Standard. It's a "We-Are-Doing-Things-By-The-Book" notice, not a real warning.
251-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_WIN32_WINNT=${BOOST_WINDOWS_VERSION} -DWIN32 -DBOOST_ASIO_DISABLE_IOCP /EHsc /std:c++14 /wd4250")
253+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -D_WIN32_WINNT=${BOOST_WINDOWS_VERSION} -DWIN32 -DBOOST_ASIO_DISABLE_IOCP /EHsc /wd4250")
252254
set(USE_RT "")
253255
link_directories(${Boost_LIBRARY_DIR_DEBUG})
254256
elseif(${CMAKE_SYSTEM_NAME} MATCHES "QNX")
255257
set(USE_RT "")
256258
else()
257-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OS_CXX_FLAGS} -g ${OPTIMIZE} -std=c++14 ${NO_DEPRECATED} ${EXPORTSYMBOLS}")
259+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OS_CXX_FLAGS} -g ${OPTIMIZE} ${NO_DEPRECATED} ${EXPORTSYMBOLS}")
258260
set(USE_RT "rt")
259261
endif()
260262

@@ -268,6 +270,7 @@ list(SORT ${VSOMEIP_NAME}-cfg_SRC)
268270
if (VSOMEIP_ENABLE_MULTIPLE_ROUTING_MANAGERS EQUAL 0)
269271
add_library(${VSOMEIP_NAME}-cfg SHARED ${${VSOMEIP_NAME}-cfg_SRC})
270272
set_target_properties (${VSOMEIP_NAME}-cfg PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION})
273+
target_compile_features(${VSOMEIP_NAME}-cfg PRIVATE cxx_std_17)
271274
if (MSVC)
272275
set_target_properties(${VSOMEIP_NAME}-cfg PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION_PLUGIN")
273276
endif()
@@ -302,6 +305,7 @@ list(SORT ${VSOMEIP_NAME}_SRC)
302305

303306
add_library(${VSOMEIP_NAME} SHARED ${${VSOMEIP_NAME}_SRC})
304307
set_target_properties (${VSOMEIP_NAME} PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION})
308+
target_compile_features(${VSOMEIP_NAME} PRIVATE cxx_std_17)
305309
if (MSVC)
306310
set_target_properties(${VSOMEIP_NAME} PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION")
307311
else ()
@@ -331,6 +335,7 @@ file(GLOB ${VSOMEIP_NAME}-sd_SRC
331335
list(SORT ${VSOMEIP_NAME}-sd_SRC)
332336

333337
add_library(${VSOMEIP_NAME}-sd SHARED ${${VSOMEIP_NAME}-sd_SRC})
338+
target_compile_features(${VSOMEIP_NAME}-sd PRIVATE cxx_std_17)
334339
set_target_properties (${VSOMEIP_NAME}-sd PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION})
335340
if (MSVC)
336341
set_target_properties(${VSOMEIP_NAME}-sd PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION_PLUGIN")
@@ -348,6 +353,7 @@ file(GLOB_RECURSE ${VSOMEIP_NAME}-e2e_SRC
348353
list(SORT ${VSOMEIP_NAME}-e2e_SRC)
349354

350355
add_library(${VSOMEIP_NAME}-e2e SHARED ${${VSOMEIP_NAME}-e2e_SRC})
356+
target_compile_features(${VSOMEIP_NAME}-e2e PRIVATE cxx_std_17)
351357
set_target_properties (${VSOMEIP_NAME}-e2e PROPERTIES VERSION ${VSOMEIP_VERSION} SOVERSION ${VSOMEIP_MAJOR_VERSION})
352358
if (MSVC)
353359
set_target_properties(${VSOMEIP_NAME}-e2e PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION_PLUGIN")
@@ -375,6 +381,7 @@ file(GLOB_RECURSE ${VSOMEIP_COMPAT_NAME}_SRC
375381
list(SORT ${VSOMEIP_COMPAT_NAME}_SRC)
376382

377383
add_library(${VSOMEIP_COMPAT_NAME} SHARED ${${VSOMEIP_COMPAT_NAME}_SRC})
384+
target_compile_features(${VSOMEIP_COMPAT_NAME} PRIVATE cxx_std_17)
378385
set_target_properties (${VSOMEIP_COMPAT_NAME} PROPERTIES VERSION ${VSOMEIP_COMPAT_VERSION} SOVERSION ${VSOMEIP_COMPAT_MAJOR_VERSION})
379386
if (MSVC)
380387
set_target_properties(${VSOMEIP_COMPAT_NAME} PROPERTIES COMPILE_DEFINITIONS "VSOMEIP_DLL_COMPILATION_PLUGIN")

examples/hello_world/hello_world_service.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#if defined ANDROID || defined __ANDROID__
1212
#include "android/log.h"
1313
#define LOG_TAG "hello_world_service"
14-
#define LOG_INF(...) fprintf(stdout, __VA_ARGS__), fprintf(stdout, "\n"), (void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, ##__VA_ARGS__)
15-
#define LOG_ERR(...) fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n"), (void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ##__VA_ARGS__)
14+
#define LOG_INF(...) std::fprintf(stdout, __VA_ARGS__), std::fprintf(stdout, "\n"), (void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, ##__VA_ARGS__)
15+
#define LOG_ERR(...) std::fprintf(stderr, __VA_ARGS__), std::fprintf(stderr, "\n"), (void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, ##__VA_ARGS__)
1616
#else
1717
#include <cstdio>
18-
#define LOG_INF(...) fprintf(stdout, __VA_ARGS__), fprintf(stdout, "\n")
19-
#define LOG_ERR(...) fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n")
18+
#define LOG_INF(...) std::fprintf(stdout, __VA_ARGS__), std::fprintf(stdout, "\n")
19+
#define LOG_ERR(...) std::fprintf(stderr, __VA_ARGS__), std::fprintf(stderr, "\n")
2020
#endif
2121

2222
static vsomeip::service_t service_id = 0x1111;
@@ -32,9 +32,9 @@ class hello_world_service {
3232
hello_world_service() :
3333
rtm_(vsomeip::runtime::get()),
3434
app_(rtm_->create_application()),
35-
stop_(false),
36-
stop_thread_(std::bind(&hello_world_service::stop, this))
35+
stop_(false)
3736
{
37+
stop_thread_ = std::thread{&hello_world_service::stop, this};
3838
}
3939

4040
~hello_world_service()

implementation/configuration/include/internal.hpp.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ typedef enum {
143143
IS_SUBSCRIBING
144144
} subscription_state_e;
145145

146-
const std::uint32_t MESSAGE_SIZE_UNLIMITED = (std::numeric_limits<std::uint32_t>::max)();
146+
inline constexpr std::uint32_t MESSAGE_SIZE_UNLIMITED = (std::numeric_limits<std::uint32_t>::max)();
147147

148-
const std::uint32_t QUEUE_SIZE_UNLIMITED = (std::numeric_limits<std::uint32_t>::max)();
148+
inline constexpr std::uint32_t QUEUE_SIZE_UNLIMITED = (std::numeric_limits<std::uint32_t>::max)();
149149

150150
#define VSOMEIP_DEFAULT_NPDU_DEBOUNCING_NANO 2 * 1000 * 1000
151151
#define VSOMEIP_DEFAULT_NPDU_MAXIMUM_RETENTION_NANO 5 * 1000 * 1000
152152

153-
const std::uint32_t MAX_RECONNECTS_UNLIMITED = (std::numeric_limits<std::uint32_t>::max)();
153+
inline constexpr std::uint32_t MAX_RECONNECTS_UNLIMITED = (std::numeric_limits<std::uint32_t>::max)();
154154

155155
const std::uint32_t ANY_UID = 0xFFFFFFFF;
156156
const std::uint32_t ANY_GID = 0xFFFFFFFF;

implementation/configuration/include/internal_android.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ typedef enum {
130130
IS_SUBSCRIBING
131131
} subscription_state_e;
132132

133-
const std::uint32_t MESSAGE_SIZE_UNLIMITED = std::numeric_limits<std::uint32_t>::max();
133+
inline constexpr std::uint32_t MESSAGE_SIZE_UNLIMITED = std::numeric_limits<std::uint32_t>::max();
134134

135-
const std::uint32_t QUEUE_SIZE_UNLIMITED = std::numeric_limits<std::uint32_t>::max();
135+
inline constexpr std::uint32_t QUEUE_SIZE_UNLIMITED = std::numeric_limits<std::uint32_t>::max();
136136

137137
#define VSOMEIP_DEFAULT_NPDU_DEBOUNCING_NANO 2 * 1000 * 1000
138138
#define VSOMEIP_DEFAULT_NPDU_MAXIMUM_RETENTION_NANO 5 * 1000 * 1000
139139

140-
const std::uint32_t MAX_RECONNECTS_UNLIMITED = std::numeric_limits<std::uint32_t>::max();
140+
inline constexpr std::uint32_t MAX_RECONNECTS_UNLIMITED = std::numeric_limits<std::uint32_t>::max();
141141

142-
const std::uint32_t ANY_UID = 0xFFFFFFFF;
143-
const std::uint32_t ANY_GID = 0xFFFFFFFF;
142+
inline constexpr std::uint32_t ANY_UID = 0xFFFFFFFF;
143+
inline constexpr std::uint32_t ANY_GID = 0xFFFFFFFF;
144144

145145
enum class port_type_e {
146146
PT_OPTIONAL,

implementation/configuration/src/configuration_impl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ bool configuration_impl::load(const std::string &_name) {
333333

334334
// Tell, if reading of configuration file(s) failed.
335335
// (This may file if the logger configuration is incomplete/missing).
336-
for (auto f : its_failed)
336+
for (const auto& f : its_failed)
337337
VSOMEIP_WARNING << "Reading of configuration file \""
338338
<< f << "\" failed. Configuration may be incomplete.";
339339

@@ -342,7 +342,7 @@ bool configuration_impl::load(const std::string &_name) {
342342

343343
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
344344

345-
for (auto i : its_input) {
345+
for (const auto& i : its_input) {
346346
if (utility::is_file(i))
347347
VSOMEIP_INFO << "Using configuration file: \"" << i << "\".";
348348

@@ -561,7 +561,7 @@ bool configuration_impl::load_data(const std::vector<configuration_element> &_el
561561

562562
if (is_logging_loaded_) {
563563
logger::logger_impl::init(shared_from_this());
564-
for (auto w : its_warnings)
564+
for (const auto& w : its_warnings)
565565
VSOMEIP_WARNING << w;
566566
}
567567
}
@@ -3255,16 +3255,17 @@ void configuration_impl::trim(std::string &_s) {
32553255
std::find_if(
32563256
_s.begin(),
32573257
_s.end(),
3258-
[](unsigned char ch) { return !std::isspace(ch); }
3258+
[](const auto ch) { return !std::isspace(ch); }
32593259
)
32603260
);
32613261

32623262
_s.erase(
32633263
std::find_if(
32643264
_s.rbegin(),
32653265
_s.rend(),
3266-
[](unsigned char ch) { return !std::isspace(ch); }).base(),
3267-
_s.end()
3266+
[](const auto ch) { return !std::isspace(ch); }
3267+
).base(),
3268+
_s.end()
32683269
);
32693270
}
32703271

implementation/endpoints/include/endpoint_impl.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ class endpoint_impl: public virtual endpoint {
3434
std::uint32_t _max_message_size,
3535
configuration::endpoint_queue_limit_t _queue_limit,
3636
const std::shared_ptr<configuration>& _configuration);
37+
endpoint_impl(endpoint_impl<Protocol> const&) = delete;
38+
endpoint_impl(endpoint_impl<Protocol> const&&) = delete;
39+
3740
virtual ~endpoint_impl();
3841

3942
void enable_magic_cookies();

implementation/endpoints/include/local_server_endpoint_impl_receive_op.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ struct storage :
2525
{
2626
socket_type_t &socket_;
2727
receive_handler_t handler_;
28-
byte_t *buffer_;
29-
std::size_t length_;
28+
byte_t *buffer_ = nullptr;
29+
size_t length_;
3030
uid_t uid_;
3131
gid_t gid_;
3232
size_t bytes_;

implementation/endpoints/include/local_uds_client_endpoint_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class local_uds_client_endpoint_impl: public local_uds_client_endpoint_base_impl
2525
const endpoint_type& _remote,
2626
boost::asio::io_context &_io,
2727
const std::shared_ptr<configuration>& _configuration);
28-
virtual ~local_uds_client_endpoint_impl();
28+
virtual ~local_uds_client_endpoint_impl() = default;
2929

3030
void start();
3131
void stop();

implementation/endpoints/include/local_uds_server_endpoint_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class local_uds_server_endpoint_impl: public local_uds_server_endpoint_base_impl
5050
const std::shared_ptr<configuration>& _configuration,
5151
bool _is_routing_endpoint);
5252

53-
virtual ~local_uds_server_endpoint_impl();
53+
virtual ~local_uds_server_endpoint_impl() = default;
5454

5555
void start();
5656
void stop();

0 commit comments

Comments
 (0)