Skip to content

Commit

Permalink
Make case fallthrough explicit (#153)
Browse files Browse the repository at this point in the history
* Make case fallthrough explicit
  • Loading branch information
rotu authored Apr 14, 2020
1 parent 5781044 commit a9e8784
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rmw_cyclonedds_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions rmw_cyclonedds_cpp/src/fallthrough_macro.hpp
Original file line number Diff line number Diff line change
@@ -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_
5 changes: 5 additions & 0 deletions rmw_cyclonedds_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit a9e8784

Please sign in to comment.