[llvm-bugs] [Bug 46454] New: Duplicated warning message in -Wunused-value with "const"

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 25 07:52:37 PDT 2020


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

            Bug ID: 46454
           Summary: Duplicated warning message in  -Wunused-value with
                    "const"
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: haoxintu at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

$cat bug.cc
int int_a = 0;
const int const_int_b = 0;
int int_c = 0;
auto var1 = reinterpret_cast <int> (int_a , const_int_b );
auto var2 = reinterpret_cast <int> (const_int_b ,const_int_b);
auto var3 = reinterpret_cast <int> (const_int_b , int_a);
auto var4 = reinterpret_cast <int> (int_c , int_a);

$clang++ -c -Wunused-value bug.cc
bug.cc:4:37: warning: expression result unused [-Wunused-value]
auto var1 = reinterpret_cast <int> (int_a , const_int_b );
                                    ^~~~~
bug.cc:4:37: warning: expression result unused [-Wunused-value]
auto var1 = reinterpret_cast <int> (int_a , const_int_b );
                                    ^~~~~
bug.cc:5:37: warning: expression result unused [-Wunused-value]
auto var2 = reinterpret_cast <int> (const_int_b ,const_int_b);
                                    ^~~~~~~~~~~
bug.cc:5:37: warning: expression result unused [-Wunused-value]
auto var2 = reinterpret_cast <int> (const_int_b ,const_int_b);
                                    ^~~~~~~~~~~
bug.cc:6:37: warning: expression result unused [-Wunused-value]
auto var3 = reinterpret_cast <int> (const_int_b , int_a);
                                    ^~~~~~~~~~~
bug.cc:7:37: warning: expression result unused [-Wunused-value]
auto var4 = reinterpret_cast <int> (int_c , int_a);
                                    ^~~~~
6 warnings generated.

While in GCC
$g++ -c -Wunused-value bug.cc
bug.cc:4:37: warning: left operand of comma operator has no effect
[-Wunused-value]
    4 | auto var1 = reinterpret_cast <int> (int_a , const_int_b );
      |                                     ^~~~~
bug.cc:5:37: warning: left operand of comma operator has no effect
[-Wunused-value]
    5 | auto var2 = reinterpret_cast <int> (const_int_b ,const_int_b);
      |                                     ^~~~~~~~~~~
bug.cc:6:37: warning: left operand of comma operator has no effect
[-Wunused-value]
    6 | auto var3 = reinterpret_cast <int> (const_int_b , int_a);
      |                                     ^~~~~~~~~~~
bug.cc:7:37: warning: left operand of comma operator has no effect
[-Wunused-value]
    7 | auto var4 = reinterpret_cast <int> (int_c , int_a);
      |   

Clang emits two duplicated warning messages in Line4 and Line5, while following
two lines just gives one warning message. I guess clang might have something
wrong in handling the "const" variable in reinterpret_cast expression.

I have tested in recently released Clang versions, and found that Clang-9 to
Clang-trunk versions have this issue and Clang-8 or lower versions work fine
with it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200625/2fbc9373/attachment.html>


More information about the llvm-bugs mailing list