status of lambda expression implementation

Hello,

I was looking over the clang sources today with some interest. I am curious what the current status is of the lambda C++0x code. I did notice a few declarations in the Parser.h header that seems to indicate some work is going on here. One of the things I did notice was that clang appears to do most of the parsing using custom code which means one would need to reason about the parsing oneself.

Regards,

Carter.

I was looking over the clang sources today with some interest. I am curious
what the current status is of the lambda C++0x code. I did notice a few
declarations in the Parser.h header that seems to indicate some work is
going on here.

Yep - just last week Douglas committed (on behalf of John Freeman) an
initial version of support for parsing lambda expressions. You can see
what's supported from the associated test cases what sort of things
are supported.

http://llvm.org/viewvc/llvm-project?view=rev&revision=136876

In the interests of helping the next person who asks this I've
attached a patch to update the status page (
http://clang.llvm.org/cxx_status.html ) & cc'd cfe-commits in the
hopes that someone will commit it. Since we don't have an extensive
set of test cases I'm just flagging this as "some examples work" for
parsing of lambdas with sema/ast/codegen as "not started" (I'm sure
John is working on sema & I'm poking around with it myself, but
nothing is committed yet).

[though I think the C++ status page is in a perpetual state of "out of
date" - I'm pretty sure unified attribute syntax has been added in
some form, for example. Though I don't know what state it's in
exactly]

One of the things I did notice was that clang appears to do
most of the parsing using custom code which means one would need to reason
about the parsing oneself.

Not sure what you're getting at here - I guess you're referring to
clang as a whole, not just the lambda support, & specifically about
the fact that clang doesn't use a parser generator?

I don't know the history behind that decision, but I expect it's
because C++ (& perhaps ObjC/C++) isn't really easy to parse. Most
importantly it's not context-free, so it requires some fairly heavy
work to do things correctly & I doubt any standard parser generators
could handle it.

- David

cxx-status-lambda.patch (513 Bytes)

Parsing is done for the moment. I have submitted a patch today with the first steps toward semantic analysis and AST generation. No work has started yet on code generation. The near term goal is to support unnested lambda expressions with no implicit captures, but I cannot predict when that will happen.

- John

Has the C++11 status page been updated with the current status of this
work (and other C++11 related work).

http://clang.llvm.org/cxx_status.html

-Shawn

Shawn Erickson wrote:

Has the C++11 status page been updated with the current status of this work (and other C++11 related work).

I can't help being at least a little frustrated at the slow progress of lambda support. It seems like the it's a super-low priority for the Apple folks (who are some of the most prolific clang contributors), and is instead being left to other people who are working on it slowly, as a hobby project.

This is a shame because other compilers (Microsoft C++, GNU G++) have lambda support already, and lots of people seem to be advocating lambda use as the "modern C++ way" (e.g., Herb Sutter's talk at //build/ (*) -- video here: http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-835T ).

    (*) Shouldn't it have been \\build\ :wink:

It's especially strange, since it feels to me like it really shouldn't be so hard to give users *something*. What tantalizes me is that if you use blocks syntax, you can have something that actually (kinda-sorta) works *today*.

unix% cat > feeling-blocked.cpp
#include <list>
#include <string>
#include <iostream>
#include <algorithm>

int main(int argc, const char** argv)
{
    std::list<std::string> args(argv+1, argv+argc);
    std::for_each(args.begin(), args.end(), ^(const std::string& s) {
        std::cout << s << std::endl;
    });
    return 0;
}
^D
unix% clang++ -std=c++0x -stdlib=libc++ -Wall -o feeling-blocked feeling-blocked.cpp
unix% ./feeling-blocked Oh for some lambda love.
Oh
for
some
lambda
love.

So, I could get by writing code like this:

#if __APPLE__
    #define LAMBDA ^
#else
    #define LAMBDA []
#endif

But it would be *so* much nicer if I didn't have to.

    M.E.O.