https://bugs.llvm.org/show_bug.cgi?id=39375

            Bug ID: 39375
           Summary: False positive -Wcomma with static_cast<void> of
                    dependent expression
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: oktal3...@gmail.com
                CC: llvm-bugs@lists.llvm.org

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 https://stackoverflow.com/a/30563282/1639256

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to