This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/52288] Trouble with operator?: and lambdas
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 16 Feb 2012 23:49:39 +0000
- Subject: [Bug c++/52288] Trouble with operator?: and lambdas
- Auto-submitted: auto-generated
- References: <bug-52288-4@http.gcc.gnu.org/bugzilla/>
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.