title: Seemingly incorrect conversion from int to char* - how to see an issue
body: <p>To my understanding this code snippet has a problem, since <code>std::string</code> will be removed after <code>to_string</code> and <code>port</code> should have an incorrect value.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  
  int main() {
          int a = 123;
          const char* port = std::to_string(a).c_str();
          printf("val = %s", port);
  
          return 0;
  }
  </code></pre>
  
  <p>However, program works just fine and prints "123" (with g++ compiler). Valgrind does not spot a problem as well.</p>
  
  <p>Is there any way to demonstrate (maybe some tool or compiler option) that code above indeed has a problem?</p>