Skip to content

Commit 725b6f1

Browse files
authored
Upgrade rcutils to C++17. (ros2#392)
* Upgrade rcutils to C++17. This upgrade was more involved than just increasing the CMAKE_CXX_STANDARD version. In C++17, apparently 'noexcept' became part of the type system. This is problematic because some functions that we use from the underlying libc, like 'stat', actually specify nothrow in their function declaration. This causes the type system to reject our mock shims, since the types are no longer totally compatible. To work around this, introduce a 'remove_noexcept' type into the system which effectively removes the 'noexcept' specifier for any function that it uses. With that in place, everything here works with C++17. See the comments in remove_noexcept.hpp for details on the provenance of that code. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
1 parent 2f647cc commit 725b6f1

4 files changed

Lines changed: 1030 additions & 9 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ project(rcutils)
66
if(NOT CMAKE_C_STANDARD)
77
set(CMAKE_C_STANDARD 11)
88
endif()
9-
# Default to C++14
9+
# Default to C++17
1010
if(NOT CMAKE_CXX_STANDARD)
11-
set(CMAKE_CXX_STANDARD 14)
11+
set(CMAKE_CXX_STANDARD 17)
1212
endif()
1313

1414
include(CheckLibraryExists)
@@ -143,16 +143,18 @@ install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
143143
RUNTIME DESTINATION bin)
144144

145145
if(BUILD_TESTING)
146-
if(NOT WIN32)
147-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
148-
endif()
149-
150146
find_package(performance_test_fixture REQUIRED)
151147

152148
find_package(ament_cmake_gmock REQUIRED)
153149
find_package(ament_cmake_gtest REQUIRED)
154150
find_package(ament_cmake_pytest REQUIRED)
155151
find_package(ament_lint_auto REQUIRED)
152+
# cppcheck 1.90 doesn't understand some of the syntax in remove_noexcept.hpp
153+
# Since we already have cppcheck disabled on Linux, just disable it completely
154+
# for this package.
155+
list(APPEND AMENT_LINT_AUTO_EXCLUDE
156+
ament_cmake_cppcheck
157+
)
156158
ament_lint_auto_find_test_dependencies()
157159

158160
find_package(launch_testing_ament_cmake REQUIRED)

test/mocking_utils/filesystem.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#endif
3434
#endif
3535

36+
#include <functional>
3637
#include <map>
3738
#include <string>
3839
#include <type_traits>

test/mocking_utils/patch.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "mimick/mimick.h"
3636
#include "rcutils/macros.h"
3737

38+
#include "remove_noexcept.hpp"
39+
3840
namespace mocking_utils
3941
{
4042

@@ -215,7 +217,9 @@ class Patch<ID, ReturnT(ArgTs...)>
215217
* trampoline, as setup by the dynamic linker.
216218
* \return a mocking_utils::Patch instance.
217219
*/
218-
explicit Patch(const std::string & target, std::function<ReturnT(ArgTs...)> proxy)
220+
explicit Patch(
221+
const std::string & target,
222+
std::function<remove_noexcept_t<ReturnT(ArgTs...)>> proxy)
219223
: proxy_(proxy)
220224
{
221225
auto MMK_MANGLE(mock_type, create) =
@@ -291,9 +295,9 @@ class Patch<ID, ReturnT(ArgTs...)>
291295
* \sa mocking_utils::Patch for further reference.
292296
*/
293297
template<size_t ID, typename SignatureT>
294-
auto make_patch(const std::string & target, std::function<SignatureT> proxy)
298+
auto make_patch(const std::string & target, std::function<remove_noexcept_t<SignatureT>> proxy)
295299
{
296-
return Patch<ID, SignatureT>(target, proxy);
300+
return Patch<ID, remove_noexcept_t<SignatureT>>(target, proxy);
297301
}
298302

299303
/// Define a dummy operator `op` for a given `type`.

0 commit comments

Comments
 (0)