Very simple function returns value of vector-item instead of the correct value. Code compiles without any problem. Running it returns incorrect value. Tried it with Intel and Microsoft compilers, both return the correct value.
Code (since I do not see a method to attach anything here...): #include <iostream> #include <vector> std::vector<int> next; long numOfNodes = 5; int addNode(void) { next.push_back(-1); return numOfNodes; } int main ( int argc, char *argv[] ) { next = std::vector<int> (); next.push_back(-1); next[0] = addNode(); std::cout << "Returned value:" << next[0] << std::endl; std::cout << "Real Value:" << (numOfNodes) << std::endl; return 0; } -- Summary: Incorrect value returned by function that uses a std::vector Product: gcc Version: 4.2.1 Status: UNCONFIRMED Severity: major Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: lmdv_gnu at mandata dot nl GCC build triplet: ../configure --enable-threads=posix --prefix=/usr -- with-local- GCC host triplet: gcc version 4.2.1 (SUSE Linux) GCC target triplet: x86_64-suse-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35686