【发布时间】:2014-02-02 16:08:55
【问题描述】:
我有一小段代码可以在 clang repo head (3.5) 中编译,但在 gcc 4.9 repo head 中编译得不好。虽然这看起来像一个 gcc 错误,但在向 bugzilla 发送垃圾邮件之前,我想问你是否
- 这是有效的 c++1y 代码(处于当前草稿状态) - 仅仅因为 clang 编译它,它没有理由成为正确的代码,并且
- 如果有人可以重现此错误。
使用clang编译运行sn-p的代码在这里:
http://coliru.stacked-crooked.com/a/acc691b9a407d6f2
但是使用
g++-4.9 -o main main.cpp -std=c++1y
给我前面提到的内部编译器错误:http://pastebin.com/3fqV7xzC
没有它读取的长转储:
g++-4.9 -o main main.cpp -std=c++1y main.cpp: 在'composer::operator()(Func&&, Funcs&& ...):: [with auto:2 = float; Func = main(int, const char*)::; Funcs = {main(int, const char*)::}]': main.cpp:33:88: 从这里需要
main.cpp:19:41: internal compiler error: in retrieve_specialization, at cp/pt.c:1042
return f(c(std::forward<Funcs>(fs)...)(v));
^
为了完整起见,这里是 sn-p(完整的 main.cpp)
#include <iostream>
#include <utility>
template <typename... Funcs>
struct composer;
template <>
struct composer<> {
auto operator()() {
return [&] (auto v) { return v; };
}
};
template <typename Func, typename... Funcs>
struct composer<Func, Funcs...> {
auto operator()(Func&& f, Funcs&&... fs) {
composer<Funcs...> c;
return [&] (auto v) {
return f(c(std::forward<Funcs>(fs)...)(v));
};
}
};
template <typename... Funcs>
auto compose(Funcs&&... fs) {
composer<Funcs...> c;
return c(std::forward<Funcs>(fs)...);
}
int main (int argc, char const* argv[]) {
float v = 3.5f;
auto t = compose([] (auto v) { return v >= 3; }, [] (auto v) { return int(v-0.5); })(v);
std::cout << std::boolalpha << t << "\n";
auto f = compose([] (auto v) { return v > 3; }, [] (auto v) { return int(v-0.5); })(v);
std::cout << std::boolalpha << f << "\n";
}
编辑:奖金!我根本不喜欢该代码 - 如果有人有更好且可能更快的方法来执行此操作,请考虑启发我...
编辑 2 有谁知道如何让 coliru(或类似服务)使用 g++ 4.9?
【问题讨论】:
-
if anyone can reproduce this bug.你检查过bug tracker吗? -
很遗憾,我没能找到与这件事相关的错误,没有。
-
我可以在
gcc version 4.9.0 20131223 (experimental) (GCC)上重现这个ICE -
好的,这是一个问题,谢谢。不管这段代码是否正确,它都不应该产生 ICE,所以我会把它发布到跟踪器......
-
一个内部编译器错误表明这肯定是一个 gcc 错误;无论代码本身是有效还是无效,这都不应该发生。您可能希望在问题中至少包含错误消息的前几行。