public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tower120 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/67247] New: ICE on std::forward args&& inside nested lambda function
Date: Mon, 17 Aug 2015 10:43:00 -0000	[thread overview]
Message-ID: <bug-67247-4@http.gcc.gnu.org/bugzilla/> (raw)

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.


             reply	other threads:[~2015-08-17 10:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-17 10:43 tower120 at gmail dot com [this message]
2015-08-17 11:03 ` [Bug c++/67247] " trippels at gcc dot gnu.org
2015-08-19  9:29 ` mpolacek at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-67247-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).