This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/35686] New: Incorrect value returned by function that uses a std::vector
- From: "lmdv_gnu at mandata dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Mar 2008 21:12:57 -0000
- Subject: [Bug c++/35686] New: Incorrect value returned by function that uses a std::vector
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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