clang编译错误与static_assert和boost :: hana有关
Clang compile error related to static_assert and boost::hana
考虑以下问题,该问题使用-std=c++14
。
#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");
});
});
}
该测试是非常敏感的,但这不是重点。现在考虑一个替代版本,其中测试直接放置在static_assert
中:
#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");
});
});
}
现在我得到了一堆编译错误,说
错误:引用封闭lambda表达式中声明的本地变量
i
问题:是什么导致第二版失败?
编辑:这可以是编译器错误吗?事实证明,在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");
});
});
}
更新:可以在Clang 4.0和当前的开发分支5.0上复制相同的行为。
更新2:正如@louisdionne建议的那样,我将其作为错误提交:https://bugs.llvm.org/show_bug.cgi?id=33318.iid=33318.<</em>
这是Clang编译器中的一个错误,并被公认。这是它的链接:https://bugs.llvm.org/show_bug.cgi?id=33318。
相关文章:
- 如何将 boost::hana::map 转换为 lambda
- 使用 Boost::Hana 中的 BOOST_HANA_DEFINE_STRUCT 定义具有 40 个以上字段的结构
- 如何将 boost::hana::tuple 转换为 std::变体
- Boost.Hana:在 constexpr 上下文中将值元组转换为相应类型的元组
- 如何实现 Boost.Hana 结构的相等比较运算符?
- 如何使用 Boost.Hana 声明成员变量
- 取 boost::hana::p artial::operator() 的地址
- 从具有部分专用化的boost:hana::set中提取类型失败
- 如何使用boost::hana::unpack和构造函数,而不是函数
- boost::hana 转发声明标头的用例是什么?
- 在boost::hana中给定一个键元组,如何从映射中获取值元组
- 如何使用 Boost Hana 删除元编程递归
- Boost.Hana JSON 示例:字符串和 decltype(std::to_string(..))之间的区别
- 是否可以使用 Boost.Hana 将 std::array 解压缩到非类型模板参数包中
- clang编译错误与static_assert和boost :: hana有关
- 为什么BOOST :: HANA :: EXAREMIS ::键入实验功能?类型列表的棘手是什么
- 使用boost :: hana进行内省
- 用Boost Hana反映C风格的阵列
- boost::hana::map 作为数据成员
- Boost HANA:从集合创建地图和默认值