Re: When using -Ax with aC++ 6.26 function overloads with rvalue references do not bind (error #3768 (183 Views)
Reply
Occasional Contributor agh
Occasional Contributor
agh
Posts: 5
Registered: ‎12-10-2013
Message 1 of 2 (210 Views)
Accepted Solution

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?

Occasional Visitor
Ashutosh_Nema
Posts: 1
Registered: ‎01-06-2014
Message 2 of 2 (183 Views)

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.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.