[Bug c++/67247] New: ICE on std::forward args&& inside nested lambda function
tower120 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Aug 17 10:43:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67247
Bug ID: 67247
Summary: ICE on std::forward args&& inside nested lambda
function
Product: gcc
Version: 5.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tower120 at gmail dot com
Target Milestone: ---
Code as is:
http://coliru.stacked-crooked.com/a/903e76d5446bfeb2
----------------------------------------------------------------
#include <iostream>
#include <tuple>
#include <utility>
template <class F1, class F2>
decltype(auto) operator >> (F1 &&f1, F2 &&f2){
using namespace std;
return f2(forward<F1>(f1));
}
template <class F1, class F2>
decltype(auto) operator << (F1 &&f1, F2 &&f2){
using namespace std;
return f1(forward<F2>(f2));
}
// curry 2 args pack (temporary)
#define f(...) \
[](auto&& ...args1){return \
[&](auto&& ...args2){return __VA_ARGS__
(std::forward<decltype(args1)>(args1)..., args2...);} ; /* <-- ICE HERE!*/ \
}
using namespace std;
auto sum(int a, int b){
return a+b;
}
auto divide(int a, int b){
return a/b;
}
int main() {
float a = 10;
float b = 20;
auto part1 = f(divide) << 5; // just for test purpose
auto res = sum(a,b) >> f(divide) << 5;
auto res_ctrl = divide(sum(a,b), 5.0);
cout << "res : "<< res << endl;
cout << "ctrl: "<< res_ctrl << endl;
return 0;
}
----------------------------------------------------------------
C:\Dropbox\C++\exp_chained_call\simple_chain.h:22:49: internal compiler error:
Segmentation fault
[&](auto&& ...args2){return __VA_ARGS__
(std::forward<decltype(args1)>(args1)..., args2...);} ; \
Without std::forward<decltype(args1)> it is ok.
With [&](auto&& ...args2){return __VA_ARGS__ (args1...,
std::forward<decltype(args2)>(args2)...);} ; ok also.
P.S. I just realize, that args1 is probably stored as &, not && inside
lambda... But ICE is ICE.
More information about the Gcc-bugs
mailing list