[Bug c++/35686] New: Incorrect value returned by function that uses a std::vector
lmdv_gnu at mandata dot nl
gcc-bugzilla@gcc.gnu.org
Mon Mar 24 21:13:00 GMT 2008
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
More information about the Gcc-bugs
mailing list