title: clang's support of C++ 11 lambda
body: <p>I have this C++ 11 code that uses lambda, this is an example.</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      auto func = [] () { cout &lt;&lt; &quot;Hello world&quot;; };
      func(); // now call the function
  }
  </code></pre>
  <p>When I compiled this code with clang 3.1 (<code>Apple clang version 3.1 (tags/Apple/clang-318.0.54) (based on LLVM 3.1svn)</code>), I got this error</p>
  <pre><code>lambda.cpp:7:17: error: expected expression
  auto func = [] () { cout &lt;&lt; &quot;Hello world&quot;; };
  </code></pre>
  <p>What might be wrong? In <a href="http://clang.llvm.org/cxx_status.html" rel="noreferrer">this site</a>, lambda seems to be supported with clang 3.1.</p>
  <h2>ADDED</h2>
  <p>With -std=gnu++11 or c++11 option, I got these error messages.</p>
  <pre><code>0.      Program arguments: /usr/bin/clang -cc1 -triple x86_64-apple-macosx10.7.4 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name lambda.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 128.2 -resource-dir /usr/bin/../lib/clang/3.1 -fmodule-cache-path /var/folders/ng/h2hkycqd2q5g2hz42c47bt4w0000gn/T/clang-module-cache -std=gnu++11 -fdeprecated-macro -fdebug-compilation-dir /Users/smcho/Desktop/C++test -ferror-limit 19 -fmessage-length 173 -stack-protector 1 -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/ng/h2hkycqd2q5g2hz42c47bt4w0000gn/T/lambda-XvZzHg.o -x c++ lambda.cpp 
  1.      lambda.cpp:7:49: current parser token ';'
  2.      lambda.cpp:6:1: parsing function body 'main'
  3.      lambda.cpp:6:1: in compound statement ('{}')
  clang: error: unable to execute command: Segmentation fault: 11
  clang: error: clang frontend command failed due to signal 2 (use -v to see invocation)
  clang: note: diagnostic msg: Please submit a bug report to http://developer.apple.com/bugreporter/ and include command line arguments and all diagnostic information.
  clang: note: diagnostic msg: Preprocessed source(s) and associated run script(s) are located at:
  clang: note: diagnostic msg: /var/folders/ng/h2hkycqd2q5g2hz42c47bt4w0000gn/T/lambda-roTwCZ.ii
  clang: note: diagnostic msg: /var/folders/ng/h2hkycqd2q5g2hz42c47bt4w0000gn/T/lambda-roTwCZ.sh
  </code></pre>