Bug 55817 - [C++11] void return value in std::vector<T>::insert() c++11 should be an iterator
Summary: [C++11] void return value in std::vector<T>::insert() c++11 should be an iter...
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.7.1
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2012-12-27 16:31 UTC by Jobst.Ziebell
Modified: 2014-04-23 13:07 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2013-01-08 00:00:00

Preprocessed file as created by -save-temps (31.11 KB, application/octet-stream)
2012-12-27 16:31 UTC, Jobst.Ziebell
The testcase (125 bytes, application/octet-stream)
2012-12-27 16:32 UTC, Jobst.Ziebell

Note You need to log in before you can comment on or make changes to this bug.
Description Jobst.Ziebell 2012-12-27 16:31:28 UTC
Created attachment 29054 [details]
Preprocessed file as created by -save-temps

GCC version: 4.7.1
System type: Mac OS X 10.6.8 (i386-apple-darwin10.8.0)
GCC configure options: --prefix=/Users/JayZ/usr --enable-lto --enable-objc-gc --disable-multilib
Error occurs by command: ~/usr/bin/g++ --std=c++11 insert_error.cpp

Error message (unfortunately in German - but message should be clear):
insert_error.cpp: In Funktion »int main()«:
insert_error.cpp:8:64: Fehler: Umwandlung von »void« in nicht-skalaren Typen »std::vector<int>::iterator {aka __gnu_cxx::__normal_iterator<int*, std::vector<int> >}« angefordert

 - A complaint about conversion from type "void" to type "std::vector<int>::iterator"

Expected behaviour:
Flawless compilation and no error message.

As documented by the following websites:
 - "http://www.cplusplus.com/reference/vector/vector/insert/" (C++11 section)
 - "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf" (page 726)

Unless I misread the c++11 library requirements (which I hope I didn't) this seems to be an error in the "vector" implementation. The method insert() should return an iterator.


Jobst Ziebell
Comment 1 Jobst.Ziebell 2012-12-27 16:32:32 UTC
Created attachment 29055 [details]
The testcase
Comment 2 Daniel Krügler 2013-01-07 22:54:45 UTC
The same problem seems to exist for gcc 4.8.0 20121209 and for the signatures

void insert(iterator __position, initializer_list<value_type> __l)

(should be:

iterator insert(iterator __position, initializer_list<value_type> __l)

void insert(iterator __position, size_type __n, const value_type& __x)

(should be:

iterator insert(iterator __position, size_type __n, const value_type& __x)

template<typename _InputIterator,
	       typename = std::_RequireInputIter<_InputIterator>>
void insert(iterator __position, _InputIterator __first,
	       _InputIterator __last)

(should be:

template<typename _InputIterator,
	       typename = std::_RequireInputIter<_InputIterator>>
iterator insert(iterator __position, _InputIterator __first,
	       _InputIterator __last)
Comment 3 Jonathan Wakely 2013-01-08 01:00:14 UTC
Known issue, there's probably an existing for it PR somewhere.
Comment 4 Jobst.Ziebell 2014-04-22 21:41:40 UTC
This seems to be fixed in GCC 4.9.0
Comment 5 Jonathan Wakely 2014-04-23 13:07:19 UTC
Yes, fixed for 4.9.0 by r200571