error: invalid bitwise operation between different enumeration types when compiling as C++26

Summary

When compiling the code below with a recent clang compiler and choosing C++26, the following error appears:

In file included from <source>:2:
In file included from /opt/compiler-explorer/libs/eigen/vtrunk/Eigen/Geometry:36:
/opt/compiler-explorer/libs/eigen/vtrunk/Eigen/src/Geometry/OrthoMethods.h:98:65: error: invalid bitwise operation between different enumeration types ('Eigen::internal::evaluator<Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1>>>::(unnamed enum at /opt/compiler-explorer/libs/eigen/vtrunk/Eigen/src/Core/CoreEvaluators.h:174:3)' and 'Eigen::internal::binary_evaluator<Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<float>, const Eigen::Matrix<float, 4, 1>, const Eigen::Matrix<float, 4, 1>>>::(unnamed enum at /opt/compiler-explorer/libs/eigen/vtrunk/Eigen/src/Core/CoreEvaluators.h:881:3)')
   98 |           bool Vectorizable = bool((evaluator<VectorLhs>::Flags & evaluator<VectorRhs>::Flags) & PacketAccessBit)>
      |                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/eigen/vtrunk/Eigen/src/Geometry/OrthoMethods.h:132:20: note: in instantiation of default argument for 'cross3_impl<1, internal::remove_all_t<DerivedNested>, internal::remove_all_t<OtherDerivedNested>, typename internal::remove_all_t<DerivedNested>::Scalar>' required here
  132 |   return internal::cross3_impl<Architecture::Target, internal::remove_all_t<DerivedNested>,
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  133 |                                internal::remove_all_t<OtherDerivedNested>>::run(lhs, rhs);
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:9:18: note: in instantiation of function template specialization 'Eigen::MatrixBase<Eigen::Matrix<float, 4, 1>>::cross3<Eigen::CwiseBinaryOp<Eigen::internal::scalar_difference_op<float>, const Eigen::Matrix<float, 4, 1>, const Eigen::Matrix<float, 4, 1>>>' requested here
    9 |   std::cout << a.cross3 (b - c) << std::endl;
      |                  ^
1 error generated.
Compiler returned: 1

Environment

  • Operating System : Linux
  • Architecture : x64
  • Eigen Version : master branch
  • Compiler Version : Clang (e.g. Clang 19)
  • Compile Flags : -std=C++26
  • Vector Extension : none/no difference

Minimal Example

#include <iostream>
#include <Eigen/Geometry>

int main() {
  Eigen::Vector4f a, b, c;
  a.setRandom();
  b.setRandom();
  c.setRandom();
  std::cout << a.cross3 (b - c) << std::endl;
}

https://godbolt.org/z/4WMeoc7n1

Steps to reproduce

  1. Compile the code with a recent clang compiler and choose C++26

What is the current bug behavior?

Error, as shown above

What is the expected correct behavior?

No error 😄

Relevant logs

The error points to https://gitlab.com/libeigen/eigen/-/blame/master/Eigen/src/Geometry/OrthoMethods.h#L98

This is likely due to https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2864r2.pdf , which clang implements since clang 18 according to https://en.cppreference.com/w/cpp/compiler_support/26

Possible solutions:

  1. In OrthoMethods.h, cast to int, perhaps like this: int(evaluator<VectorLhs>::Flags) & int(evaluator<VectorRhs>::Flags)
  2. Switch from enum to static constexpr int or similar, here: https://gitlab.com/libeigen/eigen/-/blame/master/Eigen/src/Core/CoreEvaluators.h#L174 and here: https://gitlab.com/libeigen/eigen/-/blame/master/Eigen/src/Core/CoreEvaluators.h#L881

I can create a merge request, let me know which solution you like best!