Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Enable more compiler warning flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
alliepiper committed Dec 11, 2020
1 parent b9f6f6d commit 21bbf7b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
59 changes: 34 additions & 25 deletions cmake/ThrustBuildCompilerTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,31 @@ function(thrust_build_compiler_targets)
endif()

if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
# TODO Enable /Wall instead of W3
append_option_if_available("/W3" cxx_compile_options)
append_option_if_available("/W4" cxx_compile_options)

# Treat all warnings as errors:
append_option_if_available("/WX" cxx_compile_options)

# Suppress overly-pedantic/unavoidable warnings brought in with /W4:
# C4324: structure was padded due to alignment specifier
append_option_if_available("/wd4324" cxx_compile_options)
# C4127: conditional expression is constant
# This can be fixed with `if constexpr` when available, but there's no way
# to silence these pre-C++17.
# TODO We should have per-dialect interface targets so we can leave these
# warnings enabled on C++17:
append_option_if_available("/wd4127" cxx_compile_options)
# C4505: unreferenced local function has been removed
# The CUDA `host_runtime.h` header emits this for
# `__cudaUnregisterBinaryUtil`.
append_option_if_available("/wd4505" cxx_compile_options)
# C4706: assignment within conditional expression
# MSVC doesn't provide an opt-out for this warning when the assignment is
# intentional. Clang will warn for these, but suppresses the warning when
# double-parentheses are used around the assignment. We'll let Clang catch
# unintentional assignments and suppress all such warnings on MSVC.
append_option_if_available("/wd4706" cxx_compile_options)

# Disabled loss-of-data conversion warnings.
# TODO Re-enable.
append_option_if_available("/wd4244" cxx_compile_options)
Expand Down Expand Up @@ -64,27 +83,23 @@ function(thrust_build_compiler_targets)
append_option_if_available("-Winit-self" cxx_compile_options)
append_option_if_available("-Woverloaded-virtual" cxx_compile_options)
append_option_if_available("-Wcast-qual" cxx_compile_options)
append_option_if_available("-Wno-cast-align" cxx_compile_options)
append_option_if_available("-Wno-long-long" cxx_compile_options)
append_option_if_available("-Wno-variadic-macros" cxx_compile_options)

append_option_if_available("-Wpointer-arith" cxx_compile_options)
append_option_if_available("-Wunused-local-typedef" cxx_compile_options)
append_option_if_available("-Wvla" cxx_compile_options)

# Disable GNU extensions (flag is clang only)
append_option_if_available("-Wgnu" cxx_compile_options)
# Calling a variadic macro with zero args is a GNU extension until C++20,
# but the THRUST_PP_ARITY macro is used with zero args. Need to see if this
# is a real problem worth fixing.
append_option_if_available("-Wno-gnu-zero-variadic-macro-arguments" cxx_compile_options)

# This complains about functions in CUDA system headers when used with nvcc.
append_option_if_available("-Wno-unused-function" cxx_compile_options)
append_option_if_available("-Wno-unused-variable" cxx_compile_options)
endif()

if ("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5)
# In GCC 4.4, the CUDA backend's kernel launch templates cause
# impossible-to-decipher "'<anonymous>' is used uninitialized in this
# function" warnings, so we disable uninitialized variable warnings.
append_option_if_available("-Wno-uninitialized" cxx_compile_options)
endif()

if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.5)
# This isn't available until GCC 4.3, and misfires on TMP code until
# GCC 4.5.
append_option_if_available("-Wlogical-op" cxx_compile_options)
endif()

if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3)
# GCC 7.3 complains about name mangling changes due to `noexcept`
# becoming part of the type system; we don't care.
Expand All @@ -100,12 +115,6 @@ function(thrust_build_compiler_targets)
append_option_if_available("-Wno-unused-parameters" cxx_compile_options)
endif()

if ("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID}")
# -Wunneeded-internal-declaration misfires in the unit test framework
# on older versions of Clang.
append_option_if_available("-Wno-unneeded-internal-declaration" cxx_compile_options)
endif()

if ("Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID}")
# Today:
# * NVCC accepts CUDA C++ in .cu files but not .cpp files.
Expand Down

0 comments on commit 21bbf7b

Please sign in to comment.