GDB wrong values for vector.size()

前端 未结 1 470
野趣味
野趣味 2020-12-21 04:59

A simple vector.push_back() causes some error in my code:

#include 
using namespace std;

int main(int argc, const char *argv[])
{
    vector&l         


        
相关标签:
1条回答
  • 2020-12-21 05:16

    What may be wrong?

    It's a bug in your compiler, or in your GDB. It does not reproduce on Linux using g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3 and GDB 7.4:

    (gdb) n
    7       stack.push_back(1);
    1: stack.size() = 0
    (gdb) 
    8       stack.push_back(1); //stack.size() becomes 467369971 after this
    1: stack.size() = 1
    (gdb) 
    9       stack.push_back(1);
    1: stack.size() = 2
    (gdb) 
    10      stack.push_back(1);
    1: stack.size() = 3
    (gdb) 
    11      stack.push_back(1);
    1: stack.size() = 4
    (gdb) 
    12      stack.push_back(1); //stack.size() becomes 467369971 after this
    1: stack.size() = 5
    (gdb) 
    13      stack.push_back(1);
    1: stack.size() = 6
    (gdb) 
    14      stack.push_back(1);
    1: stack.size() = 7
    (gdb) 
    15      return 0;
    1: stack.size() = 8
    (gdb) 
    16  }
    (gdb) q
    

    Unfortunately, figuring out which tool is to blame here will be somewhat hard: you'll need to examine the debuginfo generated. Instead you may try to reproduce the problem with different versions of GCC and GDB. If varying GCC causes the bug to disappear, it's probably a bug in GCC. If varying GDB version makes the bug disappear, it's probably a GDB bug.

    0 讨论(0)
提交回复
热议问题