<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 - False positive -Wcomma with static_cast<void> of dependent expression"
href="https://bugs.llvm.org/show_bug.cgi?id=39375">39375</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>False positive -Wcomma with static_cast<void> of dependent expression
</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>enhancement
</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>oktal3700@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The following code generates one false positive of the -Wcomma warning
("possible misuse of the comma operator"). Tested with clang trunk via Matt
Godbolt's Compiler Explorer.
template <typename T>
void foo()
{
(void)42, 0; // ok
static_cast<void>(42), 0; // ok
(void)T{}, 0; // ok
static_cast<void>(T{}), 0; // false positive
}
The warning ignores comma expressions where the LHS is a CastExpr with a
CastKind of CK_ToVoid, but the expression static_cast<void>(T{}) has a CastKind
of CK_Dependent (confirmed with Compiler Explorer's AST view). This is a
surprising difference between the C-style cast to void and the equivalent
static_cast.
I came across this when trying to do the "expander trick" without a fold
expression or C-style cast, as in <a href="https://stackoverflow.com/a/30563282/1639256">https://stackoverflow.com/a/30563282/1639256</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>