<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 --- - -Wbraced-scalar-init should explain the ATOMIC_FLAG_INIT rule if applicable" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23899&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=gBZ38V0Cyh71iTW_Bvv8WClZhKuxXWdQ9sEgBRzly2I&s=f8bbyI5M9kbEYxj2zibil-7DyfaVpOijw1XIlp6uflg&e=">23899</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Wbraced-scalar-init should explain the ATOMIC_FLAG_INIT rule if applicable
</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++14
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>nlewycky@google.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>-Wbraced-scalar-init will (correctly!) warn on the following code:
class X {
std::atomic_flag f;
X() : f(ATOMIC_FLAG_INIT) {} // Invalid!
X() : f{ATOMIC_FLAG_INIT} {} // Also invalid!
};
because ATOMIC_FLAG_INIT is usually #define'd to {0}. Unfortunately, it doesn't
explain why this is a problem.
C++14 [atomics.flag]/4 states this:
"The macro ATOMIC_FLAG_INIT shall be defined in such a way that it can be
used to initialize an object of type atomic_flag to the clear state. The macro
can be used in the form:
"atomic_flag guard = ATOMIC_FLAG_INIT;
"It is unspecified whether the macro can be used in other initialization
contexts."
The way to initialize the atomic flag is "std::atomic_flag f =
ATOMIC_FLAG_INIT;". That exact syntax, only.
Frankly, Wbraced-scalar-init picks this up by accident. A happy accident. But
since we're here, we should detect the attempt to initialize a std::atomic_flag
with ATOMIC_FLAG_INIT in any means except the one permitted syntax above. Tell
the user that they need to use an in-class initializer, instead of complaining
about extra braces.</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>