-std=c++14
を使用してClang 3.8で正常にコンパイルされる次の問題を考慮してください。static_assertおよびboost :: hanaに関するClangのコンパイルエラー
#include <boost/hana.hpp>
namespace hana = boost::hana;
int main() {
constexpr auto indices = hana::range<unsigned, 0, 3>();
hana::for_each(indices, [&](auto i) {
hana::for_each(indices, [&](auto j) {
constexpr bool test = (i == (j == i ? j : i));
static_assert(test, "error");
});
});
}
このテストは非常に官能的ではありませんが、それは重要ではありません。何が失敗する2番目のバージョンが発生します。今、私は
error: reference to local variable
i
declared in enclosing lambda expression
質問を言って、コンパイルエラーの束を取得
#include <boost/hana.hpp>
namespace hana = boost::hana;
int main() {
constexpr auto indices = hana::range<unsigned, 0, 3>();
hana::for_each(indices, [&](auto i) {
hana::for_each(indices, [&](auto j) {
static_assert((i == (j == i ? j : i)), "error");
});
});
}
:今テストを直接static_assert
の内側に置かれている代替バージョンを考えてみましょうか?
編集:これはコンパイラのバグでしょうか?私はstatic_assert
前i
にアクセスするとき、すべてが再びコンパイルすることが判明:
#include <boost/hana.hpp>
namespace hana = boost::hana;
int main() {
constexpr auto indices = hana::range<unsigned, 0, 3>();
hana::for_each(indices, [&](auto i) {
hana::for_each(indices, [&](auto j) {
constexpr auto a = i;
static_assert((i == (j == i ? j : i)), "error");
});
});
}
アップデート:同じ動作はクラン4.0と現在の開発ブランチ5.0上で再生することができます。
更新2:@LouisDionneの提案によれば、私はバグ:https://bugs.llvm.org/show_bug.cgi?id=33318を提出しました。
@aschepler:申し訳ありません - 私はあなたのポイントを取得しません。あなたは精巧にお考えですか? – LocalVolatility
"this"は類似しています。https://stackoverflow.com/questions/43665610/why-is-this-nested-lambda-not-considered-constexpr –
私は_believe_というコンパイラのバグです。私はあなたの最善の策は、Clangに対するバグを報告し、そこに精通している人々が何を考えているかを見ることだと思います。 –