<html>
    <head>
      <base href="https://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 --- - Out-of-sequence initialiser causes clang to crash"
   href="https://llvm.org/bugs/show_bug.cgi?id=23514">23514</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Out-of-sequence initialiser causes clang to crash
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.6
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </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++11
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>andyg1001@hotmail.co.uk
          </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>A simplified test case:

struct S {
  S(int a) : a(a) { }
  int a;
};

struct P {
  char i1 : 1;
  char i2 : 7;
  S s;          // avoid crash by changing "S" to "int"
};

static P MakeP() {
  return P { .i1 = 1, .s = 2, .i2 = 3 }; // or using correct order
}


The code as it stands above crashes clang with...

SemaInit.cpp:6455: void diagnoseListInit(clang::Sema&, const
clang::InitializedEntity&, clang::InitListExpr*): Assertion
`DiagnoseInitList.HadError() && "Inconsistent init list check result."' failed.

This is the outcome on clang 3.6.0 and 3.4.1 (which are the two versions I have
tested).

There are two work-arounds that avoid the crash:

1. Change P::s to "int" rather than "struct S"
2. Use a sequential initialisation order in MakeP()

It seems that clang cannot handle this particular scenario where others are ok.
 The following arrangement for "struct P" is, however, ok (oddly?):

struct P {
  S s;
  char i2 : 7;
  char i1 : 1;
};</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>