<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 --- - Can't assign PTHREAD_MUTEX_INITIALIZER to a class member"
   href="http://llvm.org/bugs/show_bug.cgi?id=17320">17320</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Can't assign PTHREAD_MUTEX_INITIALIZER to a class member
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>bero@lindev.ch
          </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=11261" name="attach_11261" title="sample code showing failures and workaround">attachment 11261</a> <a href="attachment.cgi?id=11261&action=edit" title="sample code showing failures and workaround">[details]</a></span>
sample code showing failures and workaround

This code fails to compile, saying "expected expression" where it sees
PTHREAD_MUTEX_INITIALIZER:

#include <pthread.h>
class Test {
    pthread_mutex_t m;
    Test();
};

Test::Test():m(PTHREAD_MUTEX_INITIALIZER) {}

A variant of this, initializing through = assignment, fails as well, with the
same error:

#include <pthread.h>
class Test {
    pthread_mutex_t m;
    Test();
};

Test::Test() {
    m = PTHREAD_MUTEX_INITIALIZER;
}

This is fine, though:

#include <pthread.h>
static const pthread_mutex_t __pthread_mutex_initializer =
PTHREAD_MUTEX_INITIALIZER;
class Test {
    pthread_mutex_t m;
    Test();
};

Test::Test():m(__pthread_mutex_initializer) {}


I've verified this on Linux with glibc (where PTHREAD_MUTEX_INITIALIZER is { {
0, 0, 0, 0, 0, __PTHREAD_SPINS, { 0, 0 } } } and Android (where
PTHREAD_MUTEX_INITIALIZER is { 0 }.

clang trunk svn rev. 190913.</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>