public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52288] New: Trouble with operator?: and lambdas
@ 2012-02-16 23:12 igodard at pacbell dot net
  2012-02-16 23:55 ` [Bug c++/52288] " redi at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: igodard at pacbell dot net @ 2012-02-16 23:12 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52288
           Summary: Trouble with operator?: and lambdas
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: igodard@pacbell.net


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. 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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/52288] Trouble with operator?: and lambdas
  2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
@ 2012-02-16 23:55 ` redi at gcc dot gnu.org
  2012-02-17  0:01 ` redi at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-16 23:55 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/52288] Trouble with operator?: and lambdas
  2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
  2012-02-16 23:55 ` [Bug c++/52288] " redi at gcc dot gnu.org
@ 2012-02-17  0:01 ` redi at gcc dot gnu.org
  2012-02-17  0:14 ` igodard at pacbell dot net
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-17  0:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 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**)::<lambda(int)>{argc} : main(int, char**)::<lambda(int)>{argc}'


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/52288] Trouble with operator?: and lambdas
  2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
  2012-02-16 23:55 ` [Bug c++/52288] " redi at gcc dot gnu.org
  2012-02-17  0:01 ` redi at gcc dot gnu.org
@ 2012-02-17  0:14 ` igodard at pacbell dot net
  2012-02-17  0:27 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: igodard at pacbell dot net @ 2012-02-17  0:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Ivan Godard <igodard at pacbell dot net> 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".


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/52288] Trouble with operator?: and lambdas
  2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
                   ` (2 preceding siblings ...)
  2012-02-17  0:14 ` igodard at pacbell dot net
@ 2012-02-17  0:27 ` redi at gcc dot gnu.org
  2012-02-17  0:41 ` manu at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2012-02-17  0:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-02-17 00:18:21 UTC ---
I would expect as lambdas get used more people will understand they produce a
unique closure type


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/52288] Trouble with operator?: and lambdas
  2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
                   ` (3 preceding siblings ...)
  2012-02-17  0:27 ` redi at gcc dot gnu.org
@ 2012-02-17  0:41 ` manu at gcc dot gnu.org
  2014-05-09 18:29 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu.org @ 2012-02-17  0:41 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 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')


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/52288] Trouble with operator?: and lambdas
  2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
                   ` (4 preceding siblings ...)
  2012-02-17  0:41 ` manu at gcc dot gnu.org
@ 2014-05-09 18:29 ` jason at gcc dot gnu.org
  2021-08-06  3:27 ` [Bug c++/52288] operator?: and lambdas error message could be better pinskia at gcc dot gnu.org
  2021-08-06  9:18 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jason at gcc dot gnu.org @ 2014-05-09 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
G++ will now say

wa.C:3:17: error: operands to ?: have different types ‘main(int,
char**)::<lambda(int)>’ and ‘main(int, char**)::<lambda(int)>’

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?
>From gcc-bugs-return-451170-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri May 09 18:30:30 2014
Return-Path: <gcc-bugs-return-451170-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 22338 invoked by alias); 9 May 2014 18:30:30 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 21381 invoked by uid 48); 9 May 2014 18:30:19 -0000
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/51317] [C++0x] [DR 587] Wrong value category of conditional expression where lvalue operands differ only in cv-qualification
Date: Fri, 09 May 2014 18:30:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.8.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jason at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: jason at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on cc assigned_to everconfirmed
Message-ID: <bug-51317-4-hAlMZCmtmG@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-51317-4@http.gcc.gnu.org/bugzilla/>
References: <bug-51317-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-05/txt/msg00862.txt.bz2
Content-length: 641

http://gcc.gnu.org/bugzilla/show_bug.cgi?idQ317

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2014-05-09
                 CC|                            |jason at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed on trunk.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/52288] operator?: and lambdas error message could be better
  2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
                   ` (5 preceding siblings ...)
  2014-05-09 18:29 ` jason at gcc dot gnu.org
@ 2021-08-06  3:27 ` pinskia at gcc dot gnu.org
  2021-08-06  9:18 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-06  3:27 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-08-06
            Summary|Trouble with operator?: and |operator?: and lambdas
                   |lambdas                     |error message could be
                   |                            |better

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jason Merrill from comment #6)
> G++ will now say
> 
> wa.C:3:17: error: operands to ?: have different types ‘main(int,
> char**)::<lambda(int)>’ and ‘main(int, char**)::<lambda(int)>’
> 
> 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?

This is how clang does their names of the lambdas in error message:
<source>:4:17: error: incompatible operand types ('(lambda at <source>:4:19)'
and '(lambda at <source>:5:9)')
    void* p = b ? [argc](int i){ return i; } :
                ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~

Maybe we can do the same.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug c++/52288] operator?: and lambdas error message could be better
  2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
                   ` (6 preceding siblings ...)
  2021-08-06  3:27 ` [Bug c++/52288] operator?: and lambdas error message could be better pinskia at gcc dot gnu.org
@ 2021-08-06  9:18 ` redi at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-06  9:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If we don't do the same as Clang, I definitely like the suggestion to drop the
function name if within the same scope. For a function template with many
template arguments and function arguments it can get very hard to read and hard
to find the ::<lambda(...)> part.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-08-06  9:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-16 23:12 [Bug c++/52288] New: Trouble with operator?: and lambdas igodard at pacbell dot net
2012-02-16 23:55 ` [Bug c++/52288] " redi at gcc dot gnu.org
2012-02-17  0:01 ` redi at gcc dot gnu.org
2012-02-17  0:14 ` igodard at pacbell dot net
2012-02-17  0:27 ` redi at gcc dot gnu.org
2012-02-17  0:41 ` manu at gcc dot gnu.org
2014-05-09 18:29 ` jason at gcc dot gnu.org
2021-08-06  3:27 ` [Bug c++/52288] operator?: and lambdas error message could be better pinskia at gcc dot gnu.org
2021-08-06  9:18 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).