From a9e8784c048b65e33cc284d1eaa61ed3339babfa Mon Sep 17 00:00:00 2001 From: Dan Rose Date: Mon, 13 Apr 2020 21:05:42 -0500 Subject: [PATCH] Make case fallthrough explicit (#153) * Make case fallthrough explicit --- rmw_cyclonedds_cpp/CMakeLists.txt | 2 +- rmw_cyclonedds_cpp/src/fallthrough_macro.hpp | 29 ++++++++++++++++++++ rmw_cyclonedds_cpp/src/rmw_node.cpp | 5 ++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 rmw_cyclonedds_cpp/src/fallthrough_macro.hpp diff --git a/rmw_cyclonedds_cpp/CMakeLists.txt b/rmw_cyclonedds_cpp/CMakeLists.txt index 6ffe634e..8da01c40 100644 --- a/rmw_cyclonedds_cpp/CMakeLists.txt +++ b/rmw_cyclonedds_cpp/CMakeLists.txt @@ -22,7 +22,7 @@ if(NOT CMAKE_CXX_STANDARD) endif() if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wall -Wextra -Wpedantic) + add_compile_options(-Wall -Wextra -Wpedantic -Wimplicit-fallthrough) endif() find_package(ament_cmake_ros REQUIRED) diff --git a/rmw_cyclonedds_cpp/src/fallthrough_macro.hpp b/rmw_cyclonedds_cpp/src/fallthrough_macro.hpp new file mode 100644 index 00000000..ceb02d24 --- /dev/null +++ b/rmw_cyclonedds_cpp/src/fallthrough_macro.hpp @@ -0,0 +1,29 @@ +// Copyright 2019 ADLINK Technology via Rover Robotics and Dan Rose +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef FALLTHROUGH_MACRO_HPP_ +#define FALLTHROUGH_MACRO_HPP_ + +#if __has_cpp_attribute(fallthrough) || (__cplusplus >= 201603L) +// C++17 +#define FALLTHROUGH [[fallthrough]] +#elif __has_cpp_attribute(clang::fallthrough) +// Clang +#define FALLTHROUGH [[clang::fallthrough]] +#else +// gcc +#define FALLTHROUGH /* fallthrough */ +#endif + +#endif // FALLTHROUGH_MACRO_HPP_ diff --git a/rmw_cyclonedds_cpp/src/rmw_node.cpp b/rmw_cyclonedds_cpp/src/rmw_node.cpp index 04dd6dd9..141706b7 100644 --- a/rmw_cyclonedds_cpp/src/rmw_node.cpp +++ b/rmw_cyclonedds_cpp/src/rmw_node.cpp @@ -45,6 +45,7 @@ #include "rmw/sanity_checks.h" #include "rmw/validate_node_name.h" +#include "fallthrough_macro.hpp" #include "Serialization.hpp" #include "rmw/impl/cpp/macros.hpp" @@ -354,12 +355,16 @@ extern "C" rmw_ret_t rmw_set_log_severity(rmw_log_severity_t severity) return RMW_RET_INVALID_ARGUMENT; case RMW_LOG_SEVERITY_DEBUG: mask |= DDS_LC_DISCOVERY | DDS_LC_THROTTLE | DDS_LC_CONFIG; + FALLTHROUGH; case RMW_LOG_SEVERITY_INFO: mask |= DDS_LC_INFO; + FALLTHROUGH; case RMW_LOG_SEVERITY_WARN: mask |= DDS_LC_WARNING; + FALLTHROUGH; case RMW_LOG_SEVERITY_ERROR: mask |= DDS_LC_ERROR; + FALLTHROUGH; case RMW_LOG_SEVERITY_FATAL: mask |= DDS_LC_FATAL; }