1010# - Interface target that adds warning promotion for NVCC cudafe invocations.
1111# - Only exists to work around github issue #1174 on tbb.cuda configurations.
1212# - May be combined with thrust.compiler_interface when #1174 is fully resolved.
13+ #
14+ # thrust.silence_unreachable_code_warnings
15+ # - Interface target that silences unreachable code warnings.
16+ # - Used to selectively disable such warnings in unit tests caused by
17+ # unconditionally thrown exceptions.
1318
1419function (thrust_build_compiler_targets )
1520 set (cxx_compile_definitions)
@@ -24,11 +29,35 @@ function(thrust_build_compiler_targets)
2429 endif ()
2530
2631 if ("MSVC" STREQUAL "${CMAKE_CXX_COMPILER_ID} " )
27- # TODO Enable /Wall instead of W3
28- append_option_if_available ("/W3" cxx_compile_options )
32+ append_option_if_available ("/W4" cxx_compile_options )
33+
34+ # Treat all warnings as errors. This is only supported on Release builds,
35+ # as `nv_exec_check_disable` doesn't seem to work with MSVC debug iterators
36+ # and spurious warnings are emitted.
37+ # See NVIDIA/thrust#1273, NVBug 3129879.
38+ if (CMAKE_BUILD_TYPE STREQUAL "Release" )
39+ append_option_if_available ("/WX" cxx_compile_options )
40+ endif ()
2941
30- # Treat all warnings as errors:
31- append_option_if_available ("/WX" cxx_compile_options )
42+ # Suppress overly-pedantic/unavoidable warnings brought in with /W4:
43+ # C4324: structure was padded due to alignment specifier
44+ append_option_if_available ("/wd4324" cxx_compile_options )
45+ # C4127: conditional expression is constant
46+ # This can be fixed with `if constexpr` when available, but there's no way
47+ # to silence these pre-C++17.
48+ # TODO We should have per-dialect interface targets so we can leave these
49+ # warnings enabled on C++17:
50+ append_option_if_available ("/wd4127" cxx_compile_options )
51+ # C4505: unreferenced local function has been removed
52+ # The CUDA `host_runtime.h` header emits this for
53+ # `__cudaUnregisterBinaryUtil`.
54+ append_option_if_available ("/wd4505" cxx_compile_options )
55+ # C4706: assignment within conditional expression
56+ # MSVC doesn't provide an opt-out for this warning when the assignment is
57+ # intentional. Clang will warn for these, but suppresses the warning when
58+ # double-parentheses are used around the assignment. We'll let Clang catch
59+ # unintentional assignments and suppress all such warnings on MSVC.
60+ append_option_if_available ("/wd4706" cxx_compile_options )
3261
3362 # Disabled loss-of-data conversion warnings.
3463 # TODO Re-enable.
@@ -64,27 +93,23 @@ function(thrust_build_compiler_targets)
6493 append_option_if_available ("-Winit-self" cxx_compile_options )
6594 append_option_if_available ("-Woverloaded-virtual" cxx_compile_options )
6695 append_option_if_available ("-Wcast-qual" cxx_compile_options )
67- append_option_if_available ("-Wno-cast-align" cxx_compile_options )
68- append_option_if_available ("-Wno-long-long" cxx_compile_options )
69- append_option_if_available ("-Wno-variadic-macros" cxx_compile_options )
96+
97+ append_option_if_available ("-Wpointer-arith" cxx_compile_options )
98+ append_option_if_available ("-Wunused-local-typedef" cxx_compile_options )
99+ append_option_if_available ("-Wvla" cxx_compile_options )
100+
101+ # Disable GNU extensions (flag is clang only)
102+ append_option_if_available ("-Wgnu" cxx_compile_options )
103+ # Calling a variadic macro with zero args is a GNU extension until C++20,
104+ # but the THRUST_PP_ARITY macro is used with zero args. Need to see if this
105+ # is a real problem worth fixing.
106+ append_option_if_available ("-Wno-gnu-zero-variadic-macro-arguments" cxx_compile_options )
107+
108+ # This complains about functions in CUDA system headers when used with nvcc.
70109 append_option_if_available ("-Wno-unused-function" cxx_compile_options )
71- append_option_if_available ("-Wno-unused-variable" cxx_compile_options )
72110 endif ()
73111
74112 if ("GNU" STREQUAL "${CMAKE_CXX_COMPILER_ID} " )
75- if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.5)
76- # In GCC 4.4, the CUDA backend's kernel launch templates cause
77- # impossible-to-decipher "'<anonymous>' is used uninitialized in this
78- # function" warnings, so we disable uninitialized variable warnings.
79- append_option_if_available ("-Wno-uninitialized" cxx_compile_options )
80- endif ()
81-
82- if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.5)
83- # This isn't available until GCC 4.3, and misfires on TMP code until
84- # GCC 4.5.
85- append_option_if_available ("-Wlogical-op" cxx_compile_options )
86- endif ()
87-
88113 if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.3)
89114 # GCC 7.3 complains about name mangling changes due to `noexcept`
90115 # becoming part of the type system; we don't care.
@@ -100,12 +125,6 @@ function(thrust_build_compiler_targets)
100125 append_option_if_available ("-Wno-unused-parameters" cxx_compile_options )
101126 endif ()
102127
103- if ("Clang" STREQUAL "${CMAKE_CXX_COMPILER_ID} " )
104- # -Wunneeded-internal-declaration misfires in the unit test framework
105- # on older versions of Clang.
106- append_option_if_available ("-Wno-unneeded-internal-declaration" cxx_compile_options )
107- endif ()
108-
109128 if ("Feta" STREQUAL "${CMAKE_CUDA_COMPILER_ID} " )
110129 # Today:
111130 # * NVCC accepts CUDA C++ in .cu files but not .cpp files.
0 commit comments