AMGX icon indicating copy to clipboard operation
AMGX copied to clipboard

[C++20] AMGX chokes on `-Wdeprecated-enum-enum-conversion`

Open Jacobfaib opened this issue 3 years ago • 2 comments

Problem:

include/amgx_config.h:128:42: error: arithmetic between different enumeration types ‘AMGX_MemorySpace’ and ‘AMGX_VecPrecision’ is deprecated [-Werror=deprecated-enum-enum-conversion]
  128 |     AMGX_modeRange = AMGX_memorySpaceNum * AMGX_vecPrecisionNum * AMGX_matPrecisionNum * AMGX_indPrecisionNum,
      |                      ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

It also seems that AMGX_ASSEMBLE_MODE() is a hotbed for these warnings,

include/amgx_config.h:116:13: error: arithmetic between different enumeration types ‘AMGX_MemorySpace’ and ‘AMGX_ModeNums’ is deprecated [-Werror=deprecated-enum-enum-conversion]
  116 |   memSpace  * AMGX_MemorySpaceBase  \
      |             ^
/home/svcpetsc/petsc-hash-pkgs/97b05b/include/amgx_config.h:129:22: note: in expansion of macro ‘AMGX_ASSEMBLE_MODE’
  129 |     AMGX_mode_hDDI = AMGX_ASSEMBLE_MODE(AMGX_host,   AMGX_vecDouble, AMGX_matDouble, AMGX_indInt), // mode == 8192
      |                      ^~~~~~~~~~~~~~~~~~
include/amgx_config.h:117:13: error: arithmetic between different enumeration types ‘AMGX_VecPrecision’ and ‘AMGX_ModeNums’ is deprecated [-Werror=deprecated-enum-enum-conversion]
  117 |   + vecPrec * AMGX_VecPrecisionBase \
      |             ^
/home/svcpetsc/petsc-hash-pkgs/97b05b/include/amgx_config.h:129:22: note: in expansion of macro ‘AMGX_ASSEMBLE_MODE’
  129 |     AMGX_mode_hDDI = AMGX_ASSEMBLE_MODE(AMGX_host,   AMGX_vecDouble, AMGX_matDouble, AMGX_indInt), // mode == 8192
      |                      ^~~~~~~~~~~~~~~~~~
...

Version:

git commit 888c206e7596fe926ea05d7121de4cbb4e9ff90f (main Aug 22 2022) using g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 with

-Wall -Werror -std=gnu++20

see https://gitlab.com/petsc/petsc/-/jobs/3699922389 (corresponding make.log truncated to relevant bits)

Suggested fix (illustrative, untested):

#if AMGX_CPP_VERSION >= 23
#  include <utility> // std::to_underlying
#else
#  include <type_traits> // std::underlying_type
#endif

namespace amgx 
{

namespace util
{

#if AMGX_CPP_VERSION >= 23
using std::to_underlying;
#else
template <typename T>
static inline constexpr typename std::underlying_type<T>::type to_underlying(T value) noexcept
{
  static_assert(std::is_enum<T>::value, "");
  return static_cast<typename std::underlying_type<T>::type>(value);
}
#endif

} // namespace util

} // namespace amgx

#define AMGX_ASSEMBLE_MODE(memSpace, vecPrec, matPrec, indPrec)\
(\
  memSpace  * amgx::util::to_underlying(AMGX_MemorySpaceBase)  \
  + vecPrec * amgx::util::to_underlying(AMGX_VecPrecisionBase) \
  + matPrec * amgx::util::to_underlying(AMGX_MatPrecisionBase) \
  + indPrec * amgx::util::to_underlying(AMGX_IndPrecisionBase) \
)

// etc...

Jacobfaib avatar Feb 02 '23 16:02 Jacobfaib

Thank you, Jacob, I will wrap your suggested fix into a pull request soon.

mattmartineau avatar Feb 14 '23 08:02 mattmartineau

@mattmartineau, is this fixed?

prj- avatar Feb 23 '24 06:02 prj-