Clang:二进制表达式('const auto' 和'int')的无效操作数,具有依赖于模板上下文的 constexpr 模板变量

Gus*_*uss 5 c++ clang clang++ c++17 c++20

Clang error : invalid operands to binary expression ('const auto' and 'int')
Run Code Online (Sandbox Code Playgroud)

语境 :

  • 叮当 12.0.0

简单的问题:

  • 这个错误在这种情况下意味着什么?(例如,这里的消息是否相关?)
  • 为什么这个错误只在用 Clang 编译时发生,而不是 GCC 和 Msvc-cl ?

这是一个最小的复制案例(可在 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')
Run Code Online (Sandbox Code Playgroud)

看起来 Clang 无法评估auto依赖于另一个的类型auto当两者都依赖于模板上下文时。

[作者编辑] 也许与https://bugs.llvm.org/show_bug.cgi?id=43459 有关