<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - clang-cl miscompiles insertion of struct value into std::map"
   href="http://llvm.org/bugs/show_bug.cgi?id=21330">21330</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-cl miscompiles insertion of struct value into std::map
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>hans@chromium.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>david.majnemer@gmail.com, llvmbugs@cs.uiuc.edu, rnk@google.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Example derived from a Chromium unit test:


#include <map>
#include <stdio.h>
#include <string>

struct CrashKey {
  const char *name;
  size_t val;
};

std::map<std::string, CrashKey> map;

int main() {
  const CrashKey keys[] = { { "foo", 42 }, { "bar", 7 } };

  for (int i = 0; i < sizeof keys / sizeof keys[0] ; ++i)
    map.insert(std::make_pair(keys[i].name, keys[i]));

  for (auto i : map)
    printf("key: %s, %d\n", i.second.name, i.second.val);

  return 0;
}

Compiled with clang-cl /Ox, this prints
key: bar, 0
key: foo, 0

Compiled without optimization, or with MSVC, it prints:
key: bar, 7
key: foo, 42

I think this regressed sometime last night.</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>