Coverity complains "Big parameter passed by value" in /usr/include/c++/4.6/bits/stl_heap.h

Chris Jefferson chris@bubblescope.net
Wed Jul 24 23:27:00 GMT 2013


On 24/07/13 23:55, Dan Kegel wrote:
> (I don't see libstdc++ listed at http://scan.coverity.com/projects,
> but I do see gcc there,
> so perhaps someone has already handling coverity warnings.)
>
> I'm using Coverity on a project built with gcc-4.6.3 (Ubuntu's version).
> It recently issued a complaint about /usr/include/c++/4.6/bits/stl_heap.h:
>
> 170      _ValueType __value = _GLIBCXX_MOVE(*(__last - 1));
> 171      std::__push_heap(__first, _DistanceType((__last - __first) - 1),
> 172                       _DistanceType(0), _GLIBCXX_MOVE(__value));
> 173    }
> 174
> 175  template<typename _RandomAccessIterator, typename _Distance, typename _Tp,
> 176           typename _Compare>
> 177    void
> 178    __push_heap(_RandomAccessIterator __first, _Distance __holeIndex,
>     	
> CID 10892: Big parameter passed by value (PASS_BY_VALUE)
> pass_by_value: Passing parameter __value of type Request (size 160
> bytes) by value.
> 179                _Distance __topIndex, _Tp __value, _Compare __comp)
>
> ...
>
> 294  template<typename _RandomAccessIterator, typename _Distance,
> 295           typename _Tp, typename _Compare>
> 296    void
> 297    __adjust_heap(_RandomAccessIterator __first, _Distance __holeIndex,
>     	
> CID 10893: Big parameter passed by value (PASS_BY_VALUE)
> pass_by_value: Passing parameter __value of type Request (size 160
> bytes) by value.
> 298                  _Distance __len, _Tp __value, _Compare __comp)
>
> I'm tempted to just ignore it, but I can provide more details if
> anyone's interested.

It's fine and not avoidable. We need to make a copy (or move if you have 
a move constructor) of that object, and we make that copy in the 
function call. We could pass by pointer/reference and then make a 
copy/move straight away in the function, or make the copy/move outside 
the function, but both seem like a bit of a waste really.

Chris



More information about the Libstdc++ mailing list