Proposal: Allow C++14 generic ("polymorphic") lambdas

75 views
Skip to first unread message

Peter Kasting

unread,
Jan 8, 2018, 9:56:14 PM1/8/18
to cxx
C++14 allows lambda types to be declared as "auto" and deduced using the same rules as for templates.  This thread proposes moving this feature from the "TBD" to "allowed" section of the guide.

The Google style guide (both internal and external versions) makes no explicit comment about this.  The only internal style-arbiter thread I could find on it, from a couple years ago, suggested style arbiters had a few concerns about misuse but intended to allow.  

IMO, using this is much like using "auto" elsewhere: when used judiciously, it can avoid needless verbiage.  See the sample change in https://chromium-review.googlesource.com/#/c/chromium/src/+/855776 .

PK

Nico Weber

unread,
Jan 9, 2018, 8:46:30 AM1/9/18
to Peter Kasting, cxx
This isn't allowed yet because clang runs into an infinite loop when using this feature in certain cases (https://bugs.llvm.org/show_bug.cgi?id=34185). I had hoped to fix this before going on leave, but didn't get around to it :-/

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFC-gO7c0%2B1QqPBvgS8G8mQpap43bo3f94Oct8vX%2BrDv%3Dg%40mail.gmail.com.

Peter Kasting

unread,
Jan 9, 2018, 2:36:56 PM1/9/18
to Nico Weber, cxx
On Tue, Jan 9, 2018 at 5:46 AM, Nico Weber <tha...@chromium.org> wrote:
This isn't allowed yet because clang runs into an infinite loop when using this feature in certain cases (https://bugs.llvm.org/show_bug.cgi?id=34185). I had hoped to fix this before going on leave, but didn't get around to it :-/

That bug looks like it has to do with deduced return types, rather than lambda argument types.  Am I misreading it?

PK 

Nico Weber

unread,
Jan 9, 2018, 4:06:38 PM1/9/18
to Peter Kasting, cxx
Sorry, clipboard mishap, I meant https://bugs.llvm.org/show_bug.cgi?id=33561

Peter Kasting

unread,
Jan 9, 2018, 4:15:19 PM1/9/18
to Nico Weber, cxx
On Tue, Jan 9, 2018 at 1:06 PM, Nico Weber <tha...@chromium.org> wrote:
Sorry, clipboard mishap, I meant https://bugs.llvm.org/show_bug.cgi?id=33561

Ah, yeah, that looks more problematic :)

If you think it will be a while before this is fixed, maybe we should make banned-for-now and link to this bug?  Otherwise, I could sit on the actual CL here, and we could just discuss whether in principle we're OK allowing this once it's technically possible.

PK 

Nico Weber

unread,
Jan 9, 2018, 10:02:00 PM1/9/18
to Peter Kasting, cxx
That makes sense to me (also for "Function return type deduction" next to it). Once this is fixed, I think allowing this is fine.

Peter Kasting

unread,
Jan 9, 2018, 10:06:20 PM1/9/18
to Nico Weber, cxx
On Tue, Jan 9, 2018 at 7:01 PM, Nico Weber <tha...@chromium.org> wrote:
That makes sense to me (also for "Function return type deduction" next to it). Once this is fixed, I think allowing this is fine.

For clarity: you're saying that:
Correct?

I was trying to enable the first of these in https://chromium-review.googlesource.com/c/chromium/src/+/855818 since the discussion thread on it seemed positive.  If the above are true, it seems like both of these features are banned-but-will-be-allowed-soon.

PK

Nico Weber

unread,
Jan 9, 2018, 10:13:36 PM1/9/18
to Peter Kasting, cxx
Yup.

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.

Peter Kasting

unread,
Jan 10, 2018, 8:53:08 PM1/10/18
to Nico Weber, cxx
On Tue, Jan 9, 2018 at 7:13 PM, Nico Weber <tha...@chromium.org> wrote:
Yup.


PK 

Nico Weber

unread,
Mar 28, 2018, 3:20:41 PM3/28/18
to Peter Kasting, cxx
This bug is now fixed. This feature might now be good to go if there's still interest.

Alan Cutter

unread,
Mar 29, 2018, 12:46:03 AM3/29/18
to cxx, pkas...@google.com
+1 to allowing this syntax.

Jan Wilken Dörrie

unread,
Mar 29, 2018, 3:28:47 AM3/29/18
to Alan Cutter, cxx, pkas...@google.com
+1 from me as well. Further interest was shown in this thread: 
https://groups.google.com/a/chromium.org/d/msg/cxx/4WbKn7gDW18/FVzSQ1U7BAAJ


--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.

Peter Kasting

unread,
Mar 30, 2018, 11:10:11 AM3/30/18
to cxx

dan...@chromium.org

unread,
Apr 3, 2018, 1:07:06 PM4/3/18
to Peter Kasting, cxx
On Fri, Mar 30, 2018 at 11:10 AM, 'Peter Kasting' via cxx <c...@chromium.org> wrote:

Thanks, this will be really helpful for using STL algorithms with unique_ptrs.
 

PK

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
Reply all
Reply to author
Forward
0 new messages