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.

Reply via email to