diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index f7935d0df..d7a3f3f0d 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -1426,9 +1426,9 @@ EIGEN_DEVICE_FUNC constexpr bool all(T t, Ts... ts) { // Notice: Use this macro with caution. The code in the if body should still // compile with C++14. #if defined(EIGEN_HAS_CXX17_IFCONSTEXPR) -#define EIGEN_IF_CONSTEXPR(X) if constexpr (X) +#define EIGEN_IF_CONSTEXPR(...) if constexpr (__VA_ARGS__) #else -#define EIGEN_IF_CONSTEXPR(X) if (X) +#define EIGEN_IF_CONSTEXPR(...) if (__VA_ARGS__) #endif #endif // EIGEN_MACROS_H diff --git a/test/constexpr.cpp b/test/constexpr.cpp index 573d869e0..8a0a90c62 100644 --- a/test/constexpr.cpp +++ b/test/constexpr.cpp @@ -102,3 +102,21 @@ EIGEN_DECLARE_TEST(constexpr_global) { static_assert(global_mat.coeff(0, 0) == 1); } #endif // __cpp_constexpr >= 201907L + +// Check that preprocessor correctly parses and expands EIGEN_IF_CONSTEXPR arguments containing commas +EIGEN_DECLARE_TEST(constexpr_if) { + int true_branch_executed = 0; + int false_branch_executed = 0; + EIGEN_IF_CONSTEXPR (std::is_same::value) { + true_branch_executed++; + } else { + false_branch_executed++; + } + EIGEN_IF_CONSTEXPR (std::is_same::value) { + true_branch_executed++; + } else { + false_branch_executed++; + } + VERIFY_IS_EQUAL(true_branch_executed, 1); + VERIFY_IS_EQUAL(false_branch_executed, 1); +} \ No newline at end of file