Clang : invalid operands to binary expression ('const auto' and 'int') with constexpr template variable that depends on template context

Viewed 238
Clang error : invalid operands to binary expression ('const auto' and 'int')

Context :

  • Clang 12.0.0

Simple questions :

  • What does this error means in this context ? (e.g is the message relevant here ?)
  • Why does this error only occur when compiling with Clang, in opposition to GCC and Msvc-cl ?

Here is a minimal reproduction case (available here on godbolt)

template <typename ... Ts>
struct foo
{
    constexpr inline static auto value = 42;
};

template <typename ... Ts>
struct bar
{
    template <typename U>
    constexpr static inline auto foo_value = foo<Ts...>::value; // Error here
    // nb : replacing `auto` with `int` remove the error
};

static_assert(bar<int>::foo_value<int> == 42); // K.O : invalid operands to binary expression ('const auto' and 'int')

Looks like Clang cannot evaluate an auto type that depends on another auto, when both depends on template context.

[author edit] Maybe in correlation with https://bugs.llvm.org/show_bug.cgi?id=43459

0 Answers
Related