[cfe-users] False positive -Wcomma with static_cast<void> of dependent expression
Mat Sutcliffe via cfe-users
cfe-users at lists.llvm.org
Thu Oct 18 15:39:56 PDT 2018
Hello list,
The following code generates one false positive of the -Wcomma
warning: (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).
I came across this when trying to do the "expander trick" without a
fold expression or C-style cast, as in
https://stackoverflow.com/a/30563282/1639256
Thanks
Mat
More information about the cfe-users
mailing list