Skip to content

Commit

Permalink
Warn when using C++14 in CUB and Thrust (NVIDIA#2166)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Aug 5, 2024
1 parent c65a965 commit e519f25
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
"displayName": "CUB: C++14",
"inherits": "cub-base",
"cacheVariables": {
"CUB_IGNORE_DEPRECATED_CPP_DIALECT": true,
"CUB_ENABLE_DIALECT_CPP14": true
}
},
Expand Down Expand Up @@ -265,6 +266,7 @@
"displayName": "Thrust: C++14",
"inherits": "thrust-base",
"cacheVariables": {
"THRUST_IGNORE_DEPRECATED_CPP_DIALECT": true,
"THRUST_MULTICONFIG_ENABLE_DIALECT_CPP14": true
}
},
Expand Down
1 change: 1 addition & 0 deletions cub/cmake/CubBuildTargetList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function(cub_build_target_list)
endmacro()
add_flag_option(IGNORE_DEPRECATED_CPP_DIALECT "Don't warn about any deprecated C++ standards and compilers." OFF)
add_flag_option(IGNORE_DEPRECATED_CPP_11 "Don't warn about deprecated C++11." OFF)
add_flag_option(IGNORE_DEPRECATED_CPP_14 "Don't warn about deprecated C++14." OFF)
add_flag_option(IGNORE_DEPRECATED_COMPILER "Don't warn about deprecated compilers." OFF)

# Build cub.compiler_interface with warning flags, etc
Expand Down
5 changes: 5 additions & 0 deletions cub/cub/cmake/cub-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ if (CUB_IGNORE_DEPRECATED_CPP_11 OR
target_compile_definitions(_CUB_CUB INTERFACE "CUB_IGNORE_DEPRECATED_CPP_11")
endif()

if (CUB_IGNORE_DEPRECATED_CPP_14 OR
THRUST_IGNORE_DEPRECATED_CPP_14)
target_compile_definitions(_CUB_CUB INTERFACE "CUB_IGNORE_DEPRECATED_CPP_14")
endif()

if (CUB_IGNORE_DEPRECATED_COMPILER OR
THRUST_IGNORE_DEPRECATED_COMPILER)
target_compile_definitions(_CUB_CUB INTERFACE "CUB_IGNORE_DEPRECATED_COMPILER")
Expand Down
13 changes: 10 additions & 3 deletions cub/cub/util_cpp_dialect.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@
// - CUB_IGNORE_DEPRECATED_CPP_11:
// Ignore deprecation warnings when compiling with C++11. C++03 and outdated
// compilers will still issue warnings.
// - CUB_IGNORE_DEPRECATED_CPP_14:
// Ignore deprecation warnings when compiling with C++14. C++03 and outdated
// compilers will still issue warnings.
// - CUB_IGNORE_DEPRECATED_COMPILER
// Ignore deprecation warnings when using deprecated compilers. Compiling
// with C++03 and C++11 will still issue warnings.
// with C++03, C++11 and C++14 will still issue warnings.

// Check for the thrust opt-outs as well:
# if !defined(CUB_IGNORE_DEPRECATED_CPP_DIALECT) && defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT)
Expand All @@ -67,6 +70,7 @@

# ifdef CUB_IGNORE_DEPRECATED_CPP_DIALECT
# define CUB_IGNORE_DEPRECATED_CPP_11
# define CUB_IGNORE_DEPRECATED_CPP_14
# ifndef CUB_IGNORE_DEPRECATED_COMPILER
# define CUB_IGNORE_DEPRECATED_COMPILER
# endif
Expand Down Expand Up @@ -115,10 +119,13 @@ CUB_COMPILER_DEPRECATION_SOFT(MSVC 2019(19.20 / 16.0 / 14.20), MSVC 2017);
// Dialect checks:
# if _CCCL_STD_VER < 2011
// <C++11. Hard upgrade message:
CUB_COMPILER_DEPRECATION(C++ 14);
CUB_COMPILER_DEPRECATION(C++ 17);
# elif _CCCL_STD_VER == 2011 && !defined(CUB_IGNORE_DEPRECATED_CPP_11)
// =C++11. Soft upgrade message:
CUB_COMPILER_DEPRECATION_SOFT(C++ 14, C++ 11);
CUB_COMPILER_DEPRECATION_SOFT(C++ 17, C++ 11);
# elif _CCCL_STD_VER == 2014 && !defined(CUB_IGNORE_DEPRECATED_CPP_14)
// =C++14. Soft upgrade message:
CUB_COMPILER_DEPRECATION_SOFT(C++ 17, C++ 14);
# endif

# endif // CUB_IGNORE_DEPRECATED_DIALECT
Expand Down
1 change: 1 addition & 0 deletions thrust/cmake/ThrustBuildTargetList.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ function(thrust_build_target_list)
endmacro()
add_flag_option(IGNORE_DEPRECATED_CPP_DIALECT "Don't warn about any deprecated C++ standards and compilers." OFF)
add_flag_option(IGNORE_DEPRECATED_CPP_11 "Don't warn about deprecated C++11." OFF)
add_flag_option(IGNORE_DEPRECATED_CPP_14 "Don't warn about deprecated C++14." OFF)
add_flag_option(IGNORE_DEPRECATED_COMPILER "Don't warn about deprecated compilers." OFF)
add_flag_option(IGNORE_CUB_VERSION_CHECK "Don't warn about mismatched CUB versions." OFF)
add_flag_option(IGNORE_DEPRECATED_API "Don't warn about deprecated Thrust or CUB APIs." OFF)
Expand Down
6 changes: 6 additions & 0 deletions thrust/thrust/cmake/thrust-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
# IGNORE_DEPRECATED_API # Silence build warnings about deprecated APIs
# IGNORE_DEPRECATED_CPP_DIALECT # Silence build warnings about deprecated compilers and C++ standards
# IGNORE_DEPRECATED_CPP_11 # Only silence deprecation warnings for C++11
# IGNORE_DEPRECATED_CPP_14 # Only silence deprecation warnings for C++14
# IGNORE_DEPRECATED_COMPILER # Only silence deprecation warnings for old compilers
# IGNORE_CUB_VERSION # Skip configure-time and compile-time CUB version checks
# )
Expand Down Expand Up @@ -118,6 +119,7 @@ function(thrust_create_target target_name)
IGNORE_DEPRECATED_API
IGNORE_DEPRECATED_COMPILER
IGNORE_DEPRECATED_CPP_11
IGNORE_DEPRECATED_CPP_14
IGNORE_DEPRECATED_CPP_DIALECT
)
set(keys
Expand Down Expand Up @@ -222,6 +224,10 @@ function(thrust_create_target target_name)
target_compile_definitions(${target_name} INTERFACE "THRUST_IGNORE_DEPRECATED_CPP_11")
endif()

if (TCT_IGNORE_DEPRECATED_CPP_14)
target_compile_definitions(${target_name} INTERFACE "THRUST_IGNORE_DEPRECATED_CPP_14")
endif()

if (TCT_IGNORE_DEPRECATED_COMPILER)
target_compile_definitions(${target_name} INTERFACE "THRUST_IGNORE_DEPRECATED_COMPILER")
endif()
Expand Down
19 changes: 12 additions & 7 deletions thrust/thrust/detail/config/cpp_dialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@
// - THRUST_IGNORE_DEPRECATED_CPP_11:
// Ignore deprecation warnings when compiling with C++11. C++03 and outdated
// compilers will still issue warnings.
// - THRUST_IGNORE_DEPRECATED_CPP_14:
// Ignore deprecation warnings when compiling with C++14. C++03 and outdated
// compilers will still issue warnings.
// - THRUST_IGNORE_DEPRECATED_COMPILER
// Ignore deprecation warnings when using deprecated compilers. Compiling
// with C++03 and C++11 will still issue warnings.
// with C++03, C++11 and C++14 will still issue warnings.

// Check for the CUB opt-outs as well:
#if !defined(THRUST_IGNORE_DEPRECATED_CPP_DIALECT) && defined(CUB_IGNORE_DEPRECATED_CPP_DIALECT)
Expand All @@ -56,6 +59,7 @@

#ifdef THRUST_IGNORE_DEPRECATED_CPP_DIALECT
# define THRUST_IGNORE_DEPRECATED_CPP_11
# define THRUST_IGNORE_DEPRECATED_CPP_14
# ifndef THRUST_IGNORE_DEPRECATED_COMPILER
# define THRUST_IGNORE_DEPRECATED_COMPILER
# endif
Expand Down Expand Up @@ -84,18 +88,17 @@

#ifndef THRUST_IGNORE_DEPRECATED_COMPILER

// clang-format off
// Compiler checks:
# if defined(_CCCL_COMPILER_GCC) && THRUST_GCC_VERSION < 50000
THRUST_COMPILER_DEPRECATION(GCC 5.0);
# elif defined(_CCCL_COMPILER_CLANG) && THRUST_CLANG_VERSION < 70000
THRUST_COMPILER_DEPRECATION(Clang 7.0);
# elif defined(_CCCL_COMPILER_MSVC) && THRUST_MSVC_VERSION < 1910
// <2017. Hard upgrade message:
THRUST_COMPILER_DEPRECATION(MSVC 2019 (19.20/16.0/14.20));
THRUST_COMPILER_DEPRECATION(MSVC 2019(19.20 / 16.0 / 14.20));
# elif defined(_CCCL_COMPILER_MSVC) && THRUST_MSVC_VERSION < 1920
// >=2017, <2019. Soft deprecation message:
THRUST_COMPILER_DEPRECATION_SOFT(MSVC 2019 (19.20/16.0/14.20), MSVC 2017);
THRUST_COMPILER_DEPRECATION_SOFT(MSVC 2019(19.20 / 16.0 / 14.20), MSVC 2017);
# endif

#endif // THRUST_IGNORE_DEPRECATED_COMPILER
Expand All @@ -105,12 +108,14 @@ THRUST_COMPILER_DEPRECATION_SOFT(MSVC 2019 (19.20/16.0/14.20), MSVC 2017);
// Dialect checks:
# if _CCCL_STD_VER < 2011
// <C++11. Hard upgrade message:
THRUST_COMPILER_DEPRECATION(C++14);
THRUST_COMPILER_DEPRECATION(C++ 17);
# elif _CCCL_STD_VER == 2011 && !defined(THRUST_IGNORE_DEPRECATED_CPP_11)
// =C++11. Soft upgrade message:
THRUST_COMPILER_DEPRECATION_SOFT(C++14, C++11);
THRUST_COMPILER_DEPRECATION_SOFT(C++ 17, C++ 11);
# elif _CCCL_STD_VER == 2014 && !defined(THRUST_IGNORE_DEPRECATED_CPP_14)
// =C++14. Soft upgrade message:
THRUST_COMPILER_DEPRECATION_SOFT(C++ 17, C++ 14);
# endif
// clang-format on

#endif // THRUST_IGNORE_DEPRECATED_DIALECT

Expand Down

0 comments on commit e519f25

Please sign in to comment.