次のコードをコンパイルするとMicrosoft Visual C++が失敗するのはなぜですか? :constexpr initializer_listコンストラクタを使用するとMSVCがコンパイルされない
template <typename T>
struct slice
{
size_t length;
T *ptr;
constexpr slice(std::initializer_list<T> list)
: length(list.size()), ptr(list.begin()) {}
};
static_assert(slice<const int>({ 1, 2, 3 }).length == 3, "!!");
私が手にエラーがある:
1>test.cpp(12): error C2131: expression did not evaluate to a constant
1> visual studio 14.0\vc\include\initializer_list(50): note: failure was caused by an undefined arithmetic operation
initializer_list
の実装は、すべてのメソッドがconstexpr
をマークしている、それは私には問題ないはずのように見える...多分それはちょうど、コンパイラの問題ですか?
マイVS2015' ' 。 –
@ManuEvansそれは変だ。調査の結果、原因がスタンダードの悪い言い回しであることがわかりました。これはVS 2015の実装では修正されていないようです。編集: – Rakete1111
@ Rakete1111 - 確認を参照してください。 'コンパイルVS2017 – Jeff