<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - __STDC_NO_THREADS__ undefined with glibc"
   href="https://bugs.llvm.org/show_bug.cgi?id=32377">32377</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__STDC_NO_THREADS__ undefined with glibc
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.9
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Driver
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>clang@evan.coeusgroup.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>glibc doesn't support the C11 threads API but clang doesn't define
__STDC_NO_THREADS__, even in C11 mode, as is required by the C11 spec (ยง
6.10.8.3).

I know this is partially a libc issue, since it's really up to the standard
library (not the compiler) to support the API.  glibc does contain a `#define
__STDC_NO_THREADS__ 1` (as of 2.16) in stdc-predef.h, but clang doesn't
automatically include that file (GCC does).

I'm working around this issue right now by including stdc-predef.h (indirectly,
for portability reasons; limits.h -> features.h -> stdc-predef.h), but AFAIK
this shouldn't be necessary for a conformant implementation of C11.  I should
be able to have something like

  #if defined(__STDC_VERSION__) && \
      (__STDC_VERSION__ >= 201102L) && \
      !defined(__STDC_NO_THREADS__)
  #  include <threads.h>
  #endif

as the first few lines in my code, and have it work as expected.

It seems like the most straightforward solution would be to include
<stdc-predef.h> on glibc just like GCC does
(<<a href="https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/glibc-c.c?view=markup#l26">https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/config/glibc-c.c?view=markup#l26</a>>).</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>