clang 生成对未定义函数的调用

Bul*_*net 5 c++ clang compiler-bug c++14

下面的代码

#include <cstdint>
#include <array>
#include <utility>

std::size_t constexpr num = 5;

using Doubles = std::array<double, num>;

struct meow {

template<typename V>
static constexpr V value(V v, std::size_t)
{
    return v;
}

template<typename V, std::size_t... Indices>
static constexpr auto make(V v, std::index_sequence<Indices...>) -> std::array<V, sizeof...(Indices)>
{
    return {{value(v, Indices)...}};
}

Doubles doubles = make(3.1415926535897932384626433, std::make_index_sequence<num>());

};

int main()
{
    meow m;
    return m.doubles.size();
}
Run Code Online (Sandbox Code Playgroud)

由 GCC 以合理的方式编译,但 clang 尝试调用meow::make<double,0,1,2,3,4>而不生成实现:

https://godbolt.org/z/9Mv67GeYW

到底是怎么回事?我是否进入了IFNDR领域?

flo*_*tan 3

我认为这是 clang 中的一个bug,似乎在 Clang 15 中得到了修复。

这段代码似乎暴露了同样的问题,在 clang < 15 中发出警告,而在 clang >= 15 中则不发出警告。

class A {
  template <char N>
  struct Foo {
    static constexpr char Bar() { return 0; }
  };

  using Constants = Foo<1>;

  char var = Constants::Bar();
};
Run Code Online (Sandbox Code Playgroud)