<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 --- - atomic_load() requiring a pointer to non-const is not helpful."
   href="https://llvm.org/bugs/show_bug.cgi?id=23567">23567</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>atomic_load() requiring a pointer to non-const is not helpful.
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.6
          </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>toojays@toojays.net
          </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>jscott@citra:/tmp$ cat atomic.c 
/* The following lines work around Clang <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - gcc's stdatomic.h is not usable"
   href="show_bug.cgi?id=22740">bug 22740</a>, where Clang tries to use
 * GCC's stdatomic.h, and fails.
 */
#include <stddef.h>
#include <stdint.h>
#undef __STDC_HOSTED__
#define __STDC_HOSTED__ 0
#define __CLANG_STDINT_H
#include <stdatomic.h>
#undef __CLANG_STDINT_H
#undef __STDC_HOSTED__
#define __STDC_HOSTED__ 1

struct s
{
  atomic_int i;
};

int f (const struct s *p_s)
{
  return atomic_load(&p_s->i);
}
jscott@citra:/tmp$ clang -std=c11 -c atomic.c 
atomic.c:21:10: error: address argument to atomic operation must be a pointer
to non-const _Atomic type ('const atomic_int *' (aka 'const _Atomic(int) *')
invalid)
  return atomic_load(&p_s->i);
         ^           ~~~~~~~
/usr/lib/llvm-3.6/bin/../lib/clang/3.6.1/include/stdatomic.h:134:29: note:
expanded from macro 'atomic_load'
#define atomic_load(object) __c11_atomic_load(object, __ATOMIC_SEQ_CST)
                            ^
1 error generated.


My reading suggests that although this is a strictly correct interpretation of
the C11 standard, it isn't useful. There's no practical reason why
atomic_load() shouldn't accept a pointer to non-const.

Martin Sebor has submitted C defect report 459 about this.
<<a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_459.htm">http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_459.htm</a>>


jscott@citra:/tmp$ clang --version
Ubuntu clang version 3.6.1-svn236856-1~exp1 (branches/release_36) (based on
LLVM 3.6.1)
Target: x86_64-pc-linux-gnu
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>