http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52288

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
           Severity|normal                      |enhancement

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-16 
23:49:39 UTC ---
(In reply to comment #0)
> This code:
> 
> int main(int argc, char** argv) {
>     bool b;
>     void* p = b ? [argc](int i){ return i; } :
>         [argc](int i){ return i; };
> return 0; }
> 
> gets you this:
> 
> s3:~/ootbc/personal/ivan$ g++ --std=c++0x foo.cc
> foo.cc: In function âint main(int, char**)â:
> foo.cc:5:28: error: no match for ternary âoperator?:â in âb ? {argc} : {argc}â
> 
> which is a poor.

What do you suggest instead?

> Meanwhile this code:
> 
> int main(int argc, char** argv) {
>     bool b;
>     void* p = b ? &[argc](int i){ return i; } :
>         &[argc](int i){ return i; };
> return 0; }
> 
> gets you this:
> 
> s3:~/ootbc/personal/ivan$ g++ --std=c++0x foo.cc
> foo.cc: In function âint main(int, char**)â:
> foo.cc:4:42: error: taking address of temporary [-fpermissive]
> foo.cc:5:29: error: taking address of temporary [-fpermissive]
> foo.cc:5:29: error: conditional expression between distinct pointer types
> âmain(int, char**)::<lambda(int)>*â and âmain(int, char**)::<lambda(int)>*â
> lacks a cast
> 
> which is even worse.

Why?  It's entirely accurate, you can't take the address of a lambda, and the
two types are different and incompatible so can't be used as the second and
third operands of a conditional expression.

Reply via email to