title: undefined behavior in conditional operator
body: <p>I had to share this:</p>
  
  <p>I got hung up for 2 full days on the following <strong>trivial</strong> error involving the Conditional Operator.</p>
  
  <p>It's an easy correction, but I would like to know:</p>
  
  <ol>
  <li>Why did the buggy code compile?</li>
  <li>What was the bug doing?</li>
  <li>Why it was so damn hard to track down?</li>
  </ol>
  
  <p>buggy code:</p>
  
  <pre><code> std::map&lt;int, some_class&gt;   my_map;
  int key_ctr = 0;
   //...
  std::map&lt;int, some_class&gt;::iterator it_next   =  
                                              key_ctr == 0  ?
                                   it_next  =  my_map.begin()      // BUG!!!
                                   :
                                   it_next  =  --my_map.end();     // BUG!!!!
  
    // .....
  </code></pre>
  
  <p>Clearly, I wrote the Conditional Operator incorrectly.  Eveyrthing works totally fine when I finally found and corrected this bug:</p>
  
  <p>correct code:</p>
  
  <pre><code> std::map&lt;int, some_class&gt;   my_map;
  int key_ctr = 0;
   //...
  std::map&lt;int, some_class&gt;::iterator it_next   =  
                                              key_ctr == 0  ?
                                   my_map.begin()              // CORRECTED!
                                   :
                                   --my_map.end();             // CORRECTED!
  </code></pre>
  
  <p>My program was just hanging when it got near the buggy part - as if it were in an infinite loop.  When I ran it with <strong>valgrind</strong>, I got  stuff like</p>
  
  <pre><code>....
  ==24570== Warning: set address range perms: large range [0x1a7731000, 0x1c5f79000) (defined)
  ==24570== Warning: set address range perms: large range [0x1c5f79000, 0x1e47c1000) (defined)
  ==24570== Warning: set address range perms: large range [0x1e47c1000, 0x203009000) (defined)
  ==24570== Warning: set address range perms: large range [0x203009000, 0x221851000) (defined)
  .....
  ==3733== More than 10000000 total errors detected.  I'm not reporting any more.
  </code></pre>
  
  <p>Which was totally unhelpful and pointed me in the wrong director (I thought I was allocating too much on the heap, somehow).</p>
  
  <p>Again,</p>
  
  <ol>
  <li>Why did the buggy code compile?</li>
  <li>What was the bug doing?</li>
  <li>Why it was so damn hard to track down?</li>
  </ol>
  
  <p>Thanks kids.</p>