[Bug c++/52288] Trouble with operator?: and lambdas
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52288 Jason Merrill changed: What|Removed |Added CC||jason at gcc dot gnu.org --- Comment #6 from Jason Merrill --- G++ will now say wa.C:3:17: error: operands to ?: have different types ‘main(int, char**)::’ and ‘main(int, char**)::’ I think that addresses the ?: part of this issue. I'll leave it open for now in case we want to keep it as a question about how to name lambdas in error messages. It seems to me that we might want to omit the function scope if we're currently in the same function. Do we want to give them numbers to distinguish them?
[Bug c++/52288] Trouble with operator?: and lambdas
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52288 Manuel López-Ibáñez changed: What|Removed |Added CC||manu at gcc dot gnu.org --- Comment #5 from Manuel López-Ibáñez 2012-02-17 00:36:59 UTC --- (In reply to comment #3) > As lambdas get used more you will get this kind of report a lot. I suggest you > head off a lot of nuisance by having any lambda/lambda type comparisons emit a > "Note: each lambda is it own unique type". For the little that it is worth, I agree: both error messages are plain awful. As programmers start using more complex lambdas, you should expect the pretty-printing of expressions to reach heavy-template code levels of awfulness. Can't we just say? invalid operands to ternary operator ('lambda' and 'lambda')
[Bug c++/52288] Trouble with operator?: and lambdas
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52288 --- Comment #4 from Jonathan Wakely 2012-02-17 00:18:21 UTC --- I would expect as lambdas get used more people will understand they produce a unique closure type
[Bug c++/52288] Trouble with operator?: and lambdas
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52288 --- Comment #3 from Ivan Godard 2012-02-17 00:00:48 UTC --- As lambdas get used more you will get this kind of report a lot. I suggest you head off a lot of nuisance by having any lambda/lambda type comparisons emit a "Note: each lambda is it own unique type".
[Bug c++/52288] Trouble with operator?: and lambdas
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52288 --- Comment #2 from Jonathan Wakely 2012-02-16 23:53:15 UTC --- (In reply to comment #1) > > foo.cc:5:28: error: no match for ternary âoperator?:â in âb ? {argc} : > > {argc}â > > > > which is a poor. > > What do you suggest instead? Sorry, I missed the {argc} part. Trunk gives a better error: l.cc:4:34: error: no match for ternary 'operator?:' in 'b ? main(int, char**)::{argc} : main(int, char**)::{argc}'
[Bug c++/52288] Trouble with operator?: and lambdas
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52288 Jonathan Wakely changed: What|Removed |Added Keywords||diagnostic Severity|normal |enhancement --- Comment #1 from Jonathan Wakely 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**)::*â and âmain(int, char**)::*â > 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.