<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 --- - Initialization of union type"
   href="http://llvm.org/bugs/show_bug.cgi?id=20829">20829</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Initialization of union type
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>Jani_Lahtinen@mcafee.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code:

typedef union {
  struct {
    int a:1;
    int b:1;
    int c:1;
    int d:1;
  };
  uint8_t mask;
} foo;

int main(void)
{
  foo x;
  x.mask = 0xff;
  x = (foo){.a = 1};
  printf("%02x\n", x.mask);
  return 0;
}

when compiled with -O0 prints two hex-digits the last of which is one, and the
first is random.

C99 standard says:

6.7.8 Initialization

...

8. Except where explicitly stated otherwise, for the purposes of this subclause
unnamed members of objects of structure and union type do not participate in
initialization. Unnamed members of structure objects have indeterminate value
even after initialization.

...

21. If there are fewer initializers in a brace-enclosed list than there are
elements or members
of an aggregate, or fewer characters in a string literal used to initialize an
array of known
size than there are elements in the array, the remainder of the aggregate shall
be
initialized implicitly the same as objects that have static storage duration.

I am unsure is the Clang behaviour according to standard or not.</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>