<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 --- - Constructor with empty initializer list generates code that crashes at runtime"
   href="http://llvm.org/bugs/show_bug.cgi?id=22256">22256</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Constructor with empty initializer list generates code that crashes at runtime
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.5
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>evan.exe@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13699" name="attach_13699" title="main.cpp">attachment 13699</a> <a href="attachment.cgi?id=13699&action=edit" title="main.cpp">[details]</a></span>
main.cpp

The attached code contains a List<T> wrapper for std::vector<T> and two
constructors, one default constructor and one that takes a
std::initializer_list<T>.

Steps (using latest OS X Command Line Tools, version 6.1):
1. Compile attached file using "clang++ -std=c++11 main.cpp"
2. Run the attached file using "MallocScribble=1 ./a.out"

Expected:
I expect that "auto keys = new List<std::string>({});" and "auto keys = new
List<std::string>();" both create an empty list and both do not crash. Each one
can be tested by commenting that one in and commenting the other one out.

Actual:
The code for the default constructor runs fine but the code for the initializer
list constructor crashes at runtime. It appears the compiler is generating
incorrect code for the initializer list constructor. Poking around the Xcode
debugger reveals that the __begin_ std::vector member is 0 but the __end_
std::vector member is 24, which is sizeof(std::string). The size() method
returns 1 but get(0) crashes.

This code is a reduced test case from a real app. The real app crashes without
any debug options but the reduced code needs MallocScribble=1 to trigger the
crash.

Also logged as rdar://19510408

clang++ --version:
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix</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>