4 Replies Latest reply: Jul 4, 2014 5:23 PM by Steve.Clamage-Oracle RSS

    Unable to assign from std::make_pair if type is not movable

    dhaney

      I'm attempting to compile the following code with the -std=c++11 flag:

       

      #include <utility>
      
      
      struct Y
      {
          Y();
          Y(const Y&);
      };
      
      
      int main(void) {
          Y y;
          std::pair<int, Y> p = std::make_pair(0, y);
      
      
          return 0;
      };
      

       

      This works fine when compiled with:

       

      CC -std=c++03 -m64 -c
      

       

      or on Linux (GCC 4.7.3/GCC 4.9) with:

       

      g++ -std=c++11 -m64 -c
      

       

      However when compiled with:

       

      CC -std=c++11 -m64 -c
      

       

      It produces the following error:

       

      "pair.cpp", line 11: Error: Using deleted function 'std::pair<int, Y>::pair(std::pair<int, Y>&&)'.
      
      1 Error(s) detected.
      

       

      I suspect this is a compiler bug, but wanted to confirm there wasn't a clause in the standard that would explain this.

        • 1. Re: Unable to assign from std::make_pair if type is not movable
          Steve.Clamage-Oracle

          This looks like compiler bug 18622662, a confusion among copy and move constructors.

          Thanks for reporting it. I've added the test case to the bug report.

          • 2. Re: Unable to assign from std::make_pair if type is not movable
            1059891

            Another sample program that triggers this bug is:

             

            #include <map>
            #include <string>
            
            class CUserCopyAssign
            {
                public:
                    CUserCopyAssign(int a);
                    CUserCopyAssign(const CUserCopyAssign &other);
                    CUserCopyAssign &operator=(const CUserCopyAssign &other);
            
                    int getA(void) const;
            
                private:
                    int m_A;
            };
            
            CUserCopyAssign::CUserCopyAssign(int a) : m_A(a)
            {
            }
            
            CUserCopyAssign::CUserCopyAssign(const CUserCopyAssign &other) : m_A(other.m_A)
            {
            }
            
            CUserCopyAssign &CUserCopyAssign::operator=(const CUserCopyAssign &other)
            {
                m_A = other.m_A;
                return *this;
            }
            
            int CUserCopyAssign::getA(void) const
            {
                return m_A;
            }
            
            int main(int, char **)
            {
                typedef std::map<std::string, CUserCopyAssign> TStrObjMap;
                TStrObjMap aMap;
                CUserCopyAssign obj(7);
                aMap.insert(TStrObjMap::value_type("a", obj));
                return 0;
            }
            

             

            When built with:

             

            CC -std=c++11 -m64 main.cpp

             

            you get the same error:

             

            "/opt/SolarisStudio12.4-beta_mar14-solaris-x86/lib/compilers/CC-gcc/include/c++/4.7.2/bits/stl_tree.h", line 139: Error: Using deleted function 'std::pair<const std::string, CUserCopyAssign>::pair(std::pair<const std::string, CUserCopyAssign>&&)'.

             

            Please can you make sure this case is covered in your regression tests as well as the make_pair example as it will be critical to people trying to compile a mix of old-style C++03 and new-style C++11 code in the same project.

            • 3. Re: Unable to assign from std::make_pair if type is not movable
              1059891

              It seems that this bug is not fixed in the July refresh of Solaris Studio 12.4 beta.  Both the original test program with make_pair and the additional test case I added in the comment on 13th June still fail with exactly the same errors in the July refresh.

               

              Do you envisage that there might be another beta refresh with this bug fixed before the final release?

               

              It would be unfortunate if not because this is stopping me from attempting to compile our complete codebase using Solaris Studio 12.4 beta which might uncover other bugs.

              • 4. Re: Unable to assign from std::make_pair if type is not movable
                Steve.Clamage-Oracle

                The bug has been fixed, but it was not fixed in time to make the July Beta refresh. No further refreshes are planned. The official product release should occur this year.