<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 --- - std::atomic variables are never constant initialized"
   href="http://llvm.org/bugs/show_bug.cgi?id=16056">16056</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::atomic variables are never constant initialized
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>st@quanttec.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>static std::atomic<..> variables are not properly constant initialized. If you
look at the assembly generated by clang for the following test case, you'll see
that testVar2 is not constant initialized to -1 as it should be.

#include <atomic>
int testVar1{-1};
std::atomic<int> testVar2{-1};

The following test case seems to suggest that this might be a problem with the
built-in _Atomic types:

struct TestVar {
  _Atomic(int) value;

  constexpr TestVar(int value) : value(value) {}
};

TestVar testVar{-1};

test.cpp:5:13: error: constexpr constructor never produces a constant
expression [-Winvalid-constexpr]
  constexpr TestVar(int value) : value(value) {}
            ^
test.cpp:5:40: note: non-literal type '_Atomic(int)' cannot be used in a
constant expression
  constexpr TestVar(int value) : value(value) {}
                                       ^</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>