与static_assert和boost :: hana相关的Clang编译错误 [英] Clang compile error related to static_assert and boost::hana

查看:100
本文介绍了与static_assert和boost :: hana相关的Clang编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下问题,该问题使用 -std = c ++ 14 在Clang 3.8上成功编译。

Consider the following problem which compiles successfully on Clang 3.8 using -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 中:

The test is quite non-sensical but that is not the point. Consider now an alternative version where the test is directly put inside the 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");
        });
    });
}

现在我遇到一堆编译错误,说

Now I get a bunch of compile errors, saying


错误:引用包含在lambda表达式中的局部变量 i

问题:什么原因导致第二个版本失败?

编辑:这可能是编译器错误吗?我发现,在 static_assert 之前访问 i 时,所有内容都会再次编译:

Could this be a compiler bug? I turns out that when accessing i before the static_assert, everything compiles again:

#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所建议,我将其提交为bug: https://bugs.llvm.org/show_bug.cgi?id=33318

推荐答案

这是Clang编译器中的错误,因此被确认。这是它的链接: https://bugs.llvm.org/show_bug.cgi ?id = 33318

This is a bug in the Clang compiler and was acknowledged as such. Here is the link to it: https://bugs.llvm.org/show_bug.cgi?id=33318.

这篇关于与static_assert和boost :: hana相关的Clang编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆