Enable compiler errors for implicit switch case fallthroughs.

Also unify warning options across Clang and GCC and fix minor issues that was surfaced by this.

PiperOrigin-RevId: 508619655
Change-Id: I59b777bf2dfea4422485670e2427c7d3f5cf6405
This commit is contained in:
Saran Tunyasuvunakool
2023-02-10 03:48:12 -08:00
committed by Copybara-Service
parent 8a53a33fd1
commit 5e989d18c3
24 changed files with 150 additions and 76 deletions
+5 -12
View File
@@ -104,19 +104,13 @@ endif()
add_library(platform_ui_adapter OBJECT)
target_sources(
platform_ui_adapter
PUBLIC glfw_adapter.h
glfw_dispatch.h
platform_ui_adapter.h
PRIVATE glfw_adapter.cc
glfw_dispatch.cc
platform_ui_adapter.cc
PUBLIC glfw_adapter.h glfw_dispatch.h platform_ui_adapter.h
PRIVATE glfw_adapter.cc glfw_dispatch.cc platform_ui_adapter.cc
)
target_compile_options(platform_ui_adapter PUBLIC ${MUJOCO_SIMULATE_COMPILE_OPTIONS})
target_include_directories(
platform_ui_adapter
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
$<TARGET_PROPERTY:glfw,INTERFACE_INCLUDE_DIRECTORIES>
platform_ui_adapter PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
$<TARGET_PROPERTY:glfw,INTERFACE_INCLUDE_DIRECTORIES>
)
target_link_libraries(platform_ui_adapter PUBLIC mujoco::mujoco)
if(SIMULATE_GLFW_DYNAMIC_SYMBOLS)
@@ -131,8 +125,7 @@ add_library(mujoco::libsimulate ALIAS libsimulate)
target_sources(
libsimulate
PUBLIC simulate.h
PRIVATE simulate.cc
array_safety.h
PRIVATE simulate.cc array_safety.h
)
target_include_directories(libsimulate PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(libsimulate PUBLIC ${MUJOCO_SIMULATE_COMPILE_OPTIONS})
+10 -1
View File
@@ -73,7 +73,16 @@ static inline int sprintf_arr(char (&dest)[N], const char* format, ...) {
// dest is guaranteed to be null-terminated
template <std::size_t N>
static inline char* strcat_arr(char (&dest)[N], const char* src) {
return std::strncat(dest, src, sizeof_arr(dest) - strlen_arr(dest) - 1);
const std::size_t dest_len = strlen_arr(dest);
const std::size_t dest_size = sizeof_arr(dest);
for (std::size_t i = dest_len; i < dest_size; ++i) {
dest[i] = src[i - dest_len];
if (!dest[i]) {
break;
}
}
dest[dest_size - 1] = '\0';
return dest;
}
// like std::strcpy but won't write beyond the bound of dest
+12 -8
View File
@@ -85,15 +85,19 @@ include(MujocoLinkOptions)
get_mujoco_extra_link_options(EXTRA_LINK_OPTIONS)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC))
set(EXTRA_COMPILE_OPTIONS -Wall -Werror)
set(EXTRA_COMPILE_OPTIONS
-Werror
-Wall
-Wimplicit-fallthrough
-Wunused
-Wno-int-in-bool-context
-Wno-sign-compare
-Wno-unknown-pragmas
)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# TODO: This should add to EXTRA_COMPILE_OPTIONS rather than overwrite it.
set(EXTRA_COMPILE_OPTIONS
-Wno-int-in-bool-context
-Wno-maybe-uninitialized
-Wno-sign-compare
-Wno-stringop-overflow
-Wno-stringop-truncation
# Set -Wimplicit-fallthrough=5 to only allow fallthrough annotation via __attribute__.
set(EXTRA_COMPILE_OPTIONS ${EXTRA_COMPILE_OPTIONS} -Wimplicit-fallthrough=5
-Wno-maybe-uninitialized
)
endif()
endif()