public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58894] New: C++11 lambda doesn't take const variable by reference
@ 2013-10-27 12:00 abyss.7 at gmail dot com
  2013-10-27 13:08 ` [Bug c++/58894] " daniel.kruegler at googlemail dot com
  2013-10-27 14:27 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: abyss.7 at gmail dot com @ 2013-10-27 12:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58894
           Summary: C++11 lambda doesn't take const variable by reference
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abyss.7 at gmail dot com

Trying to compile this code:
===
const int a = 1;
auto lambda = [&]() {
  &a;
};
lambda();
===
g++ gives error: lvalue required as unary ‘&’ operand
>From gcc-bugs-return-432828-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Oct 27 12:17:34 2013
Return-Path: <gcc-bugs-return-432828-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 17798 invoked by alias); 27 Oct 2013 12:17:33 -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 17733 invoked by uid 48); 27 Oct 2013 12:17:26 -0000
From: "olegendo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/58895] New: [SH] improve handling of signbit result
Date: Sun, 27 Oct 2013 12:17:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: olegendo at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cf_gcctarget
Message-ID: <bug-58895-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: 2013-10/txt/msg01972.txt.bz2
Content-length: 2357

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

            Bug ID: 58895
           Summary: [SH] improve handling of signbit result
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: olegendo at gcc dot gnu.org
            Target: sh*-*-*

The handling of the result of the floating point signbit functions could be
improved in the following cases.

#include <cmath>

bool test0_OK (float x)
{
  return !std::signbit (x);
}

-m4-single -m4 -O2:
        flds    fr4,fpul
        sts     fpul,r1
        cmp/pz  r1
        rts
        movt    r0

----------------------

bool test1_NG (float x)
{
  return std::signbit (x);
}

-m4-single -m4 -O2:
        flds    fr4,fpul
        sts     fpul,r1
        cmp/pz  r1
        movt    r0
        rts
        xor     #1,r0

better:
        flds    fr4,fpul
        sts     fpul,r1
        shll    r1
        rts
        movt    r1,r0

----------------------

void test2_OK (float x, int* y)
{
  y[0] = !std::signbit (x);
}

-m4-single -m4 -O2:
        flds    fr4,fpul
        sts     fpul,r1
        cmp/pz  r1
        movt    r1
        rts
        mov.l   r1,@r4

----------------------

void test3_NG (float x, int* y)
{
  // c++11 std::signbit returns a bool

  y[0] = std::signbit (x);
}

-m4-single -m4 -O2:
        flds    fr4,fpul
        sts     fpul,r1
        cmp/pz  r1
        mov     #-1,r1
        negc    r1,r1
        rts
        mov.l   r1,@r4

better:
        flds    fr4,fpul
        sts     fpul,r2
        shll    r2
        movt    r1
        rts
        mov.l   r1,@r4

----------------------

void test4_NG (float x, int* y)
{
  // c99 signbit macro and corresponding built-in return
  // zero or non-zero integer, i.e. MSB of x.

  y[0] = __builtin_signbitf (x);
}

-m4-single -m4 -O2:
        flds    fr4,fpul
        sts     fpul,r2
        mov.l   .L7,r1
        and     r2,r1
        rts
        mov.l   r1,@r4
.L8:
        .align 2
.L7:
        .long    -2147483648

possible alternative without 32 bit constant.
smaller size, but probably slower.
        flds    fr4,fpul
        sts     fpul,r2
        shll    r2
        movt    r1
        rotcr   r1
        rts
        mov.l   r1,@r4


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

* [Bug c++/58894] C++11 lambda doesn't take const variable by reference
  2013-10-27 12:00 [Bug c++/58894] New: C++11 lambda doesn't take const variable by reference abyss.7 at gmail dot com
@ 2013-10-27 13:08 ` daniel.kruegler at googlemail dot com
  2013-10-27 14:27 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-10-27 13:08 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 3210 bytes --]

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
The code - as written - is invalid. Here is a valid form of this:

//-------------------------
int main() {
  const int a = 1;
  auto lambda = [&]() {
    &a;
  };
  lambda();
}
//--------------------------

It still produces the mentioned diagnostics even in gcc 4.9.0 20131026
(experimental). It doesn't seem to be a regression, I can track it down back to
gcc 4.5.4
>From gcc-bugs-return-432832-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun Oct 27 13:17:08 2013
Return-Path: <gcc-bugs-return-432832-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 13097 invoked by alias); 27 Oct 2013 13:17:07 -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 13056 invoked by uid 48); 27 Oct 2013 13:17:02 -0000
From: "jjcogliati-r1 at yahoo dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/53001] -Wfloat-conversion should be available to warn about floating point errors
Date: Sun, 27 Oct 2013 13:17: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: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: enhancement
X-Bugzilla-Who: jjcogliati-r1 at yahoo dot com
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: attachments.created
Message-ID: <bug-53001-4-U7yj9comar@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-53001-4@http.gcc.gnu.org/bugzilla/>
References: <bug-53001-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: 2013-10/txt/msg01976.txt.bz2
Content-length: 529

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

--- Comment #27 from Joshua Cogliati <jjcogliati-r1 at yahoo dot com> ---
Created attachment 31097
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id1097&actioníit
Patch to add -Wfloat-conversion option against trunk with new testcase and
detailed warnings

This uses a detailed warnings in the testcase.  I am not sure if this is a good
idea or not since it might get invalidated if the types change.  It bootstraps
and the new testcase works on x86_64-unknown-linux-gnu


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

* [Bug c++/58894] C++11 lambda doesn't take const variable by reference
  2013-10-27 12:00 [Bug c++/58894] New: C++11 lambda doesn't take const variable by reference abyss.7 at gmail dot com
  2013-10-27 13:08 ` [Bug c++/58894] " daniel.kruegler at googlemail dot com
@ 2013-10-27 14:27 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-10-27 14:27 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-10-27
             Blocks|                            |54367
     Ever confirmed|0                           |1


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

end of thread, other threads:[~2013-10-27 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-27 12:00 [Bug c++/58894] New: C++11 lambda doesn't take const variable by reference abyss.7 at gmail dot com
2013-10-27 13:08 ` [Bug c++/58894] " daniel.kruegler at googlemail dot com
2013-10-27 14:27 ` paolo.carlini at oracle dot com

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