Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to suppress clang-tidy warnings #316

Open
ryanpeach opened this issue Oct 5, 2023 · 1 comment
Open

How to suppress clang-tidy warnings #316

ryanpeach opened this issue Oct 5, 2023 · 1 comment

Comments

@ryanpeach
Copy link

I'm trying to suppress clang-tidy warnings from this library.

I'm getting.

[31/79] Building CXX object _deps/backward-build/CMakeFiles/backward.dir/backward.cpp.o
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
   40 | backward::SignalHandling sh;
      | ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:26: warning: initialization of 'sh' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
   40 | backward::SignalHandling sh;
      |                          ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.hpp:4159:3: note: possibly throwing constructor declared here
 4159 |   SignalHandling(const std::vector<int> &posix_signals = make_default_signals())
      |   ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:26: warning: variable 'sh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
   40 | backward::SignalHandling sh;
      |                          ^
[33/79] Building CXX object _deps/backward-build/CMakeFiles/backward_object.dir/backward.cpp.o
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:1: warning: static objects are disallowed; if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
   40 | backward::SignalHandling sh;
      | ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:26: warning: initialization of 'sh' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
   40 | backward::SignalHandling sh;
      |                          ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.hpp:4159:3: note: possibly throwing constructor declared here
 4159 |   SignalHandling(const std::vector<int> &posix_signals = make_default_signals())
      |   ^
/Users/ryanpeach/Documents/Workspace/OrbitsSandCpp/build/_deps/backward-src/backward.cpp:40:26: warning: variable 'sh' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
   40 | backward::SignalHandling sh;
      |

My relevant CMakeLists.txt lines are:

# Clang Tidy
option(ENABLE_CLANG_TIDY "Enable clang-tidy checks during compilation" OFF)
if(ENABLE_CLANG_TIDY)
    find_program(
        CLANG_TIDY_EXE
        NAMES "clang-tidy"
        DOC "Path to clang-tidy executable"
    )
    set(CLANG_TIDY_COLORS 1)
    if(NOT CLANG_TIDY_EXE)
        message(WARNING "clang-tidy not found!")
    else()
        message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
        set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
    endif()
endif()


# Backtrace-cpp
# Also requires one of: libbfd (gnu binutils), libdwarf, libdw (elfutils)
if(CMAKE_BUILD_TYPE MATCHES Debug)
  FetchContent_Declare(backward
          GIT_REPOSITORY https://github.com/bombela/backward-cpp
          GIT_TAG v1.6)
  FetchContent_MakeAvailable(backward)
endif()

function(setup_backward target)
  if(CMAKE_BUILD_TYPE MATCHES Debug)
    add_backward(${target})
    target_link_libraries(${target} bfd dl)
    target_compile_definitions(${target} PRIVATE BACKWARD_HAS_BFD=1)
  endif()
endfunction()

I'm using setup_backward to wrap add_backward so that it only runs on Debug. Idk if that's important or not.

@ryanpeach
Copy link
Author

ryanpeach commented Oct 5, 2023

This makes it a bit better but I think it just prevents it from repeating itself. This has worked for all my other libraries.

# Backtrace-cpp
# Also requires one of: libbfd (gnu binutils), libdwarf, libdw (elfutils)
if(CMAKE_BUILD_TYPE MATCHES Debug)
  FetchContent_Declare(backward
          GIT_REPOSITORY https://github.com/bombela/backward-cpp
          GIT_TAG v1.6)
  FetchContent_GetProperties(backward)

  # Exclude warnings from backward
  if(NOT backward_POPULATED)
    FetchContent_Populate(backward)
    add_subdirectory(${backward_SOURCE_DIR} ${backward_BINARY_DIR} EXCLUDE_FROM_ALL)
    target_compile_options(backward INTERFACE -w)
  endif()

endif()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant