Simpler Navigation coming for Servers and Operating Systems
Coming soon: a much simpler Servers and Operating Systems section of the Community. We will combine many of the older boards, and you won't have to click through so many levels to get at the information you need. If you are looking for an older board and do not find it, check the consolidated boards, as the posts are still there.
Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

When using -Ax with aC++ 6.26 function overloads with rvalue references do not bind (error #3768).

SOLVED
Go to solution
agh
Occasional Contributor

When using -Ax with aC++ 6.26 function overloads with rvalue references do not bind (error #3768).

Hi,

 

Using aC++ 6.26, the following code fails to compile.

#include <vector>

template <typename T>
class Container
{
    std::vector<T> m_container;

public:
    void add(const T &value)
    {
        m_container.push_back(value);
    }

    void add(T &&value)
    {
        // Cannot do this as std::move is not implemented in aC++.
        //m_container.push_back(std::move(value));
        m_container.push_back(value);
    }
};

int main()
{
    Container<double> container;
    int item = 5;
    container.add(item);
}

 The failure is:

"rvaluetest.cxx", line 26: error #3768: an rvalue reference cannot be bound to
          an lvalue
      container.add(item);

 Which is strange, since I have overloaded the add function to take an rvalue reference as well as a const lvalue reference.

 

Surely, the compiler should pick the rvalue reference method instead of the lvalue one?

 

To me this looks like a defect in the compiler, but is there a workaround?

1 REPLY
Highlighted
Ashutosh_Nema
Occasional Visitor
Solution

Re: When using -Ax with aC++ 6.26 function overloads with rvalue references do not bind (error #3768

This was a compiler defect in A.06.26 release & got fixed in A.06.27 release.

We recommend to use latest compiler to avoid such defects.

 

Regards

Ashutosh Nema | HP-UX C/C++ Compilers Team.