<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:dimitry@andric.com" title="Dimitry Andric <dimitry@andric.com>"> <span class="fn">Dimitry Andric</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Test using strcmp fails after r339410"
   href="https://bugs.llvm.org/show_bug.cgi?id=38657">bug 38657</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>dimitry@andric.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Test using strcmp fails after r339410"
   href="https://bugs.llvm.org/show_bug.cgi?id=38657#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - Test using strcmp fails after r339410"
   href="https://bugs.llvm.org/show_bug.cgi?id=38657">bug 38657</a>
              from <span class="vcard"><a class="email" href="mailto:dimitry@andric.com" title="Dimitry Andric <dimitry@andric.com>"> <span class="fn">Dimitry Andric</span></a>
</span></b>
        <pre>As far as I can see, the code is invalid. The String() temporary object created
in the first line of main() is immediately destructed afterwards, making str1
point to invalidated memory.

Demonstration:

/* test.cpp */
#include <string.h>
#include <assert.h>
#include <stdio.h>

struct String {
  char    content[100];
  String (const char* a) {
    strcpy(content, a);
  }
  ~String () {
    printf("destroying String\n");
  }
  operator const char* () const {
    return content;
  }
};

int main()
{
  char const* str1 = String("three");
  printf("checking assertion\n");
  assert(strcmp(str1, "three") == 0);

  return 0;
}

$ clang -O2 pr38657-2.cpp -o pr38657-2
$ ./pr38657-2
destroying String
checking assertion
Assertion failed: (strcmp(str1, "three") == 0), function main, file
pr38657-2.cpp, line 23.
Abort trap (core dumped)

E.g., you should ensure the String object is not destroyed before checking the
assertion.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>