STL operator = behavior change with Visual Studio 2010?

I am trying to compile QtScriptGenerator ( gitorious ) with Visual Studio 2010 (C ++) and have encountered a compilation error. When searching for a solution, I saw random links to compile the partitions introduced after VS2008 due to changes in the VS2010 implementation, changes to the STL and / or C ++ 0x compliance.

Any ideas what is going on below, or how can I fix this? If the violation code turned out to be QtScriptGenerator, I think it would be easier for me to fix it .. but it seems to me that the violation code may be in the VS2010 STL implementation, and I may need to create a workaround?

PS. I am pretty new to templates and STL. I have experience in embedded and console projects where so far such things have still been often avoided so as to reduce memory consumption and cross-compiler risks.

Change It looks like this was probably implemented in Visual Studio with the replacement of std :: copy .

C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(275) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'rpp::pp_output_iterator<_Container>' (or there is no acceptable conversion) with [ _Container=std::string ] c:\qt\qtscriptgenerator\generator\parser\rpp\pp-iterator.h(75): could be 'rpp::pp_output_iterator<_Container> &rpp::pp_output_iterator<_Container>::operator =(const char &)' with [ _Container=std::string ] while trying to match the argument list '(rpp::pp_output_iterator<_Container>, rpp::pp_output_iterator<_Container>)' with [ _Container=std::string ] C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(2176) : see reference to function template instantiation '_Iter &std::_Rechecked<_OutIt,_OutIt>(_Iter &,_UIter)' being compiled with [ _Iter=rpp::pp_output_iterator<std::string>, _OutIt=rpp::pp_output_iterator<std::string>, _UIter=rpp::pp_output_iterator<std::string> ] c:\qt\qtscriptgenerator\generator\parser\rpp\pp-internal.h(83) : see reference to function template instantiation '_OutIt std::copy<std::_String_iterator<_Elem,_Traits,_Alloc>,_OutputIterator>(_InIt,_InIt,_OutIt)' being compiled with [ _OutIt=rpp::pp_output_iterator<std::string>, _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>, _OutputIterator=rpp::pp_output_iterator<std::string>, _InIt=std::_String_iterator<char,std::char_traits<char>,std::allocator<char>> ] c:\qt\qtscriptgenerator\generator\parser\rpp\pp-engine-bits.h(500) : see reference to function template instantiation 'void rpp::_PP_internal::output_line<_OutputIterator>(const std::string &,int,_OutputIterator)' being compiled with [ _OutputIterator=rpp::pp_output_iterator<std::string> ] C:\Program Files\Microsoft Visual Studio 10.0\VC\INCLUDE\xutility(275) : error C2582: 'operator =' function is unavailable in 'rpp::pp_output_iterator<_Container>' with [ _Container=std::string ] 

Here is the context ..

pp-internal.h

 #ifndef PP_INTERNAL_H #define PP_INTERNAL_H #include <algorithm> #include <stdio.h> namespace rpp { namespace _PP_internal { .. 64 template <typename _OutputIterator> 65 void output_line(const std::string &__filename, int __line, _OutputIterator __result) 66 { 67 std::string __msg; 68 69 __msg += "# "; 70 71 char __line_descr[16]; 72 pp_snprintf (__line_descr, 16, "%d", __line); 73 __msg += __line_descr; 74 75 __msg += " \""; 76 77 if (__filename.empty ()) 78 __msg += "<internal>"; 79 else 80 __msg += __filename; 81 82 __msg += "\"\n"; 83 std::copy (__msg.begin (), __msg.end (), __result); 84 } 

pp-engine-bits.h

 #ifndef PP_ENGINE_BITS_H #define PP_ENGINE_BITS_H #include <stdio.h> namespace rpp { 450 template <typename _InputIterator, typename _OutputIterator> 451 void pp::operator () (_InputIterator __first, _InputIterator __last, _OutputIterator __result) 452 { .. 497 if (env.current_line != was) 498 { 499 env.current_line = was; 500 _PP_internal::output_line (env.current_file, env.current_line, __result); 501 } 

.. and here is the definition of pp_output_iterator

pp-iterator.h

 #ifndef PP_ITERATOR_H #define PP_ITERATOR_H #include <iterator> namespace rpp { .. template <typename _Container> class pp_output_iterator : public std::iterator<std::output_iterator_tag, void, void, void, void> { std::string &_M_result; public: explicit pp_output_iterator(std::string &__result): _M_result (__result) {} inline pp_output_iterator &operator=(typename _Container::const_reference __v) { if (_M_result.capacity () == _M_result.size ()) _M_result.reserve (_M_result.capacity () << 2); _M_result.push_back(__v); return *this; } inline pp_output_iterator &operator * () { return *this; } inline pp_output_iterator &operator ++ () { return *this; } inline pp_output_iterator operator ++ (int) { return *this; } }; 
+4
source share
3 answers

I think the problem is that std::copy trying to use the "copy destination" ( operator=() ) on your rpp::pp_output_iterator<> , and there is no operator=() for this class template. I have to say that there is operator=() , but the wrong parameter should be the "copy destination" function (i.e. It does not accept `` rpp :: pp_output_iterator <> & parameter). I think that the existence of some parameter). I think that the existence of some The operator = () function will prevent the compiler from generating by default (I do not have access to the standard document at the moment to check this 100%).

Note that the type must be assigned (among other things, of course) to be considered an OutputIterator: http://www.sgi.com/tech/stl/OutputIterator.html

Previous versions of std::copy in MSVC may not have actually used the assignment (simply because OutputIterator must support it, this does not mean that std::copy should use it), so it may be a β€œnew” error in VS2010, (I cannot check right now due to limited access to my tools).

+5
source

I added this code to pp-iterator.h for the pp_output_iterator template class and can fix this problem:

  inline pp_output_iterator &operator=(const typename pp_output_iterator<_Container>& __v) { _M_result = __v._M_result; return *this; } 
+2
source

I had the same problem. Predicting things here says it doesn't make much sense to me against the code I got from the git repository (chapter 4.7.2011), so I went around this differently.

This problem is only in the generator project, which creates the generator, which creates the generated code that the qtbindings project uses. The simple fact is that you do not need to use VC10 to build the generator, you can use Qt to build VC9 to make a generator that will not create the mentioned assembly errors.

Before starting the generator: do not forget to change the QTDIR to the VC10 Qt assembly against which you want to bind, or, I think, it does not matter if the version number is the same. The .exe generator will be created in the release folder, copy it and QtCore and QtXml dll: s to the parent folder from your VC9 Qt with which you created the generator.

After that, create the qtbindings project using VC10. I had some minor problems, for example, it had output link extensions like .lib, just change all these files to .dll and it should go through.

I hope this helps people if they have problems with this in the future, as Visual Studio 10 will get more traction :) We hope that the support team will fix the build error at some point.

+1
source

Source: https://habr.com/ru/post/1309148/


All Articles