title: strange behaviour of gdb on next command
body: <p>I am new at gdb and have a cpp file with the following code</p>
  
  <pre><code>#include &lt;set&gt;
  #include &lt;vector&gt;
  struct A{
      int a;
      A(int aa) {a = aa;}
  };
  
  int main () {
      A aa(2);
      aa.a = 1;
      std::set&lt;int&gt; set_int;
      set_int.insert(1);
      std::vector&lt;int&gt; vec_int;
      vec_int.push_back(1);
      return 0;
  }
  </code></pre>
  
  <p>compiled it <code>g++ -g main.cpp -o main</code></p>
  
  <p>then i ran gdb <code>gdb main</code></p>
  
  <p>using commands <code>b main</code>, <code>r</code>,<code>n</code> ...</p>
  
  <p>I got following output</p>
  
  <pre><code>Reading symbols from a.out...done.
  (gdb) b main
  Breakpoint 1 at 0x400aaf: file main.cpp, line 9.
  (gdb) r
  Starting program: /home/srb/Desktop/a.out 
  
  Breakpoint 1, main () at main.cpp:9
  9   int main () {
  (gdb) n
  10      A aa(2);
  (gdb) 
  11      aa.a = 1;
  (gdb) 
  12      std::set&lt;int&gt; set_int;
  (gdb) 
  13      set_int.insert(1);
  (gdb) 
  14      std::vector&lt;int&gt; vec_int;
  (gdb) 
  15      vec_int.push_back(1);
  (gdb) 
  16      return 0;
  (gdb) 
  14      std::vector&lt;int&gt; vec_int;
  (gdb) 
  12      std::set&lt;int&gt; set_int;
  (gdb) 
  17  }
  (gdb) 
  __libc_start_main (main=0x400aa6 &lt;main()&gt;, argc=1, argv=0x7fffffffdbf8, init=&lt;optimized out&gt;, fini=&lt;optimized out&gt;, 
      rtld_fini=&lt;optimized out&gt;, stack_end=0x7fffffffdbe8) at ../csu/libc-start.c:325
  325 ../csu/libc-start.c: No such file or directory.
  (gdb) q
  </code></pre>
  
  <p>for me gdb was working fine till <code>return 0</code> which is on <code>line no 16</code>. after that control moved to <code>line 14</code> and then <code>line 12</code>. </p>
  
  <p>why was this happening that on pressing n after <code>line 16</code> it moved to <code>line 14</code> and then <code>line 12</code>. According to the first comment <code>it is due to destruction of set_int and vec_int</code>. But then why is it not working for <code>aa</code>. why is its destructor not called ? </p>
  
  <p>Please explain where I am missing the things. suggest me some place where I can get proper knoweledge to connect the dots.</p>