public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile
@ 2013-04-24 21:26 tsoae at mail dot ru
  2013-04-25  7:19 ` [Bug c++/57063] " tsoae at mail dot ru
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: tsoae at mail dot ru @ 2013-04-24 21:26 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 57063
           Summary: Valid static_cast from data member to rvalue reference
                    fails to compile
    Classification: Unclassified
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: tsoae@mail.ru


G++ 4.8-20130418 fails to compile the following well-formed code:

    using T = int;

    struct X
    {
        T &&f()
        {
            return static_cast<T &&>(value);
        }
        T &&value;
    };

    int main() {}

It issues the following error at the line with static_cast:

    cannot bind ‘T {aka int}’ lvalue to ‘T&& {aka int&&}’
         return static_cast<T &&>(value);

Command line: g++ test.cpp -std=c++11 -pedantic -v
Output:
==============================================================
Using built-in specs.
COLLECT_GCC=../builds/gcc-4.8-20130418/target/bin/g++
COLLECT_LTO_WRAPPER=../builds/gcc-4.8-20130418/target/libexec/gcc/i686-pc-linux-gnu/4.8.1/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../Downloads/gcc_install/gcc-4.8-20130418/configure
--prefix=../builds/gcc-4.8-20130418/target --enable-languages=c,c++
--disable-werror
Thread model: posix
gcc version 4.8.1 20130418 (prerelease) (GCC) 
COLLECT_GCC_OPTIONS='-std=c++11' '-Wpedantic' '-v' '-shared-libgcc'
'-mtune=generic' '-march=pentiumpro'
 ../builds/gcc-4.8-20130418/target/libexec/gcc/i686-pc-linux-gnu/4.8.1/cc1plus
-quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic
-march=pentiumpro -auxbase test -Wpedantic -std=c++11 -version -o
/tmp/cc8uNbtW.s
GNU C++ (GCC) version 4.8.1 20130418 (prerelease) (i686-pc-linux-gnu)
    compiled by GNU C version 4.8.1 20130418 (prerelease), GMP version 5.1.1,
MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory
"../builds/gcc-4.8-20130418/target/lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:

../builds/gcc-4.8-20130418/target/lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1

../builds/gcc-4.8-20130418/target/lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1/i686-pc-linux-gnu

../builds/gcc-4.8-20130418/target/lib/gcc/i686-pc-linux-gnu/4.8.1/../../../../include/c++/4.8.1/backward
 ../builds/gcc-4.8-20130418/target/lib/gcc/i686-pc-linux-gnu/4.8.1/include
 /usr/local/include
 ../builds/gcc-4.8-20130418/target/include

../builds/gcc-4.8-20130418/target/lib/gcc/i686-pc-linux-gnu/4.8.1/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.8.1 20130418 (prerelease) (i686-pc-linux-gnu)
    compiled by GNU C version 4.8.1 20130418 (prerelease), GMP version 5.1.1,
MPFR version 3.1.2, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 0f47b9d9fd89a439a6a420b23c88ecfa
test.cpp: In member function ‘T&& X::f()’:
test.cpp:7:39: error: cannot bind ‘T {aka int}’ lvalue to ‘T&& {aka int&&}’
         return static_cast<T &&>(value);
                                       ^
>From gcc-bugs-return-420904-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Apr 24 21:44:20 2013
Return-Path: <gcc-bugs-return-420904-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 20437 invoked by alias); 24 Apr 2013 21:44:20 -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 20411 invoked by uid 48); 24 Apr 2013 21:44:17 -0000
From: "paolo.carlini at oracle dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
Date: Wed, 24 Apr 2013 21:44: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-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: paolo.carlini at oracle dot com
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields: Status Last reconfirmed Ever Confirmed
Message-ID: <bug-57063-4-jnYWQeoX8G@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57063-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57063-4@http.gcc.gnu.org/bugzilla/>
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
X-SW-Source: 2013-04/txt/msg02049.txt.bz2
Content-length: 658


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-04-24
     Ever Confirmed|0                           |1

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-04-24 21:44:16 UTC ---
The alias declaration doesn't play a role:

struct X
{
  int&& f()
  {
    return static_cast<int&&>(value);
  }

  int&& value;
};


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

* [Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
  2013-04-24 21:26 [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile tsoae at mail dot ru
@ 2013-04-25  7:19 ` tsoae at mail dot ru
  2013-04-25  8:34 ` paolo.carlini at oracle dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tsoae at mail dot ru @ 2013-04-25  7:19 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from Nikolka <tsoae at mail dot ru> 2013-04-25 07:19:20 UTC ---
The alias is added for convenience - we can quickly test handling of different
types so. It seems that there is no problem with class types and function
types, the error arises when T is a scalar type or an array type:

    #include <string>

    template <class T>
        struct X
    {
        T &&f()
        {
            return static_cast<T &&>(value);
        }
        T &&value;
    };

    enum E {};

    template class X<int>;
    template class X<E>;
    template class X<std::string>;
    template class X<int()>;
    template class X<int[1]>;

test.cpp: In instantiation of ‘T&& X<T>::f() [with T = int]’:
test.cpp:15:20:   required from here
test.cpp:8:43: error: cannot bind ‘int’ lvalue to ‘int&&’
             return static_cast<T &&>(value);
                                           ^
test.cpp: In instantiation of ‘T&& X<T>::f() [with T = E]’:
test.cpp:16:20:   required from here
test.cpp:8:43: error: cannot bind ‘E’ lvalue to ‘E&&’
test.cpp: In instantiation of ‘T&& X<T>::f() [with T = int [1]]’:
test.cpp:19:20:   required from here
test.cpp:8:43: error: cannot bind ‘int [1]’ lvalue to ‘int (&&)[1]’
>From gcc-bugs-return-420920-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Apr 25 07:27:21 2013
Return-Path: <gcc-bugs-return-420920-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 3282 invoked by alias); 25 Apr 2013 07:27:21 -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 3250 invoked by uid 48); 25 Apr 2013 07:27:18 -0000
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/57017]=?UTF-8?Q? «Error?=: expecting string instruction after `rep'=?UTF-8?Q?» in code w?=/o inline assembly
Date: Thu, 25 Apr 2013 07:27:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jakub at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Changed-Fields: Status CC Resolution
Message-ID: <bug-57017-4-D8IzL1bBJq@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57017-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57017-4@http.gcc.gnu.org/bugzilla/>
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
X-SW-Source: 2013-04/txt/msg02065.txt.bz2
Content-length: 550


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|                            |INVALID

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-25 07:27:18 UTC ---
Not a bug in gcc then.


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

* [Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
  2013-04-24 21:26 [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile tsoae at mail dot ru
  2013-04-25  7:19 ` [Bug c++/57063] " tsoae at mail dot ru
@ 2013-04-25  8:34 ` paolo.carlini at oracle dot com
  2013-04-25 13:51 ` tsoae at mail dot ru
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-04-25  8:34 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-04-25 08:34:30 UTC ---
In general, testcases must be minimal, otherwise, eg, you start wondering (as I
did) whether the bug is in the code handling alias declarations.


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

* [Bug c++/57063] Valid static_cast from data member to rvalue reference fails to compile
  2013-04-24 21:26 [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile tsoae at mail dot ru
  2013-04-25  7:19 ` [Bug c++/57063] " tsoae at mail dot ru
  2013-04-25  8:34 ` paolo.carlini at oracle dot com
@ 2013-04-25 13:51 ` tsoae at mail dot ru
  2013-04-28  2:56 ` [Bug c++/57063] static_cast from data member to rvalue reference sometimes wrongfully produces lvalue lucdanton at free dot fr
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: tsoae at mail dot ru @ 2013-04-25 13:51 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from Nikolka <tsoae at mail dot ru> 2013-04-25 13:51:21 UTC ---
It looks like the root of the issue is that static_cast produces an expression
with wrong value category sometimes.

    #include <iostream>
    #include <type_traits>

    #define PRINT_VALUE(...) \
        std::cout << #__VA_ARGS__ " = " << __VA_ARGS__ << std::endl

    template <class T>
        struct X
    {
        void f()
        {
            PRINT_VALUE(std::is_lvalue_reference<
                decltype(static_cast<T &&>(value))>{});

            PRINT_VALUE(std::is_rvalue_reference<
                decltype(static_cast<T &&>(value))>{});

            std::cout << std::endl;
        }
        T &&value;
    };

    struct A {};

    int main()
    {
        X<int>{0}.f();
        X<A>{A()}.f();
    }

When T = int, static_cast<T &&>(value) is wrongfully treated as an lvalue. In
the first example the compiler thinks that we want to return lvalue of type int
by rvalue reference int &&, which would be invalid.


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

* [Bug c++/57063] static_cast from data member to rvalue reference sometimes wrongfully produces lvalue
  2013-04-24 21:26 [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile tsoae at mail dot ru
                   ` (2 preceding siblings ...)
  2013-04-25 13:51 ` tsoae at mail dot ru
@ 2013-04-28  2:56 ` lucdanton at free dot fr
  2014-05-20  0:15 ` ppluzhnikov at google dot com
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: lucdanton at free dot fr @ 2013-04-28  2:56 UTC (permalink / raw)
  To: gcc-bugs


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

lucdanton at free dot fr changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lucdanton at free dot fr

--- Comment #5 from lucdanton at free dot fr 2013-04-28 02:56:42 UTC ---
In case it might help: in the past I reported
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49447 where it was assignments
which possibly had a wrong value category.


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

* [Bug c++/57063] static_cast from data member to rvalue reference sometimes wrongfully produces lvalue
  2013-04-24 21:26 [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile tsoae at mail dot ru
                   ` (3 preceding siblings ...)
  2013-04-28  2:56 ` [Bug c++/57063] static_cast from data member to rvalue reference sometimes wrongfully produces lvalue lucdanton at free dot fr
@ 2014-05-20  0:15 ` ppluzhnikov at google dot com
  2021-08-02  1:04 ` pinskia at gcc dot gnu.org
  2021-12-09  9:28 ` marxin at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: ppluzhnikov at google dot com @ 2014-05-20  0:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Paul Pluzhnikov <ppluzhnikov at google dot com> ---
Google ref: b/15091778


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

* [Bug c++/57063] static_cast from data member to rvalue reference sometimes wrongfully produces lvalue
  2013-04-24 21:26 [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile tsoae at mail dot ru
                   ` (4 preceding siblings ...)
  2014-05-20  0:15 ` ppluzhnikov at google dot com
@ 2021-08-02  1:04 ` pinskia at gcc dot gnu.org
  2021-12-09  9:28 ` marxin at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-02  1:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Seems fixed in GCC 5.4 and GCC 6+.

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

* [Bug c++/57063] static_cast from data member to rvalue reference sometimes wrongfully produces lvalue
  2013-04-24 21:26 [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile tsoae at mail dot ru
                   ` (5 preceding siblings ...)
  2021-08-02  1:04 ` pinskia at gcc dot gnu.org
@ 2021-12-09  9:28 ` marxin at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-09  9:28 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
                 CC|                            |marxin at gcc dot gnu.org

--- Comment #8 from Martin Liška <marxin at gcc dot gnu.org> ---
Fixed with r6-7272-g16dc6b178ad855c5.

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

end of thread, other threads:[~2021-12-09  9:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-24 21:26 [Bug c++/57063] New: Valid static_cast from data member to rvalue reference fails to compile tsoae at mail dot ru
2013-04-25  7:19 ` [Bug c++/57063] " tsoae at mail dot ru
2013-04-25  8:34 ` paolo.carlini at oracle dot com
2013-04-25 13:51 ` tsoae at mail dot ru
2013-04-28  2:56 ` [Bug c++/57063] static_cast from data member to rvalue reference sometimes wrongfully produces lvalue lucdanton at free dot fr
2014-05-20  0:15 ` ppluzhnikov at google dot com
2021-08-02  1:04 ` pinskia at gcc dot gnu.org
2021-12-09  9:28 ` marxin 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).