[llvm-bugs] [Bug 47566] New: -Wcomma flags Boost.Array code incorrectly
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Sep 17 16:14:02 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47566
Bug ID: 47566
Summary: -Wcomma flags Boost.Array code incorrectly
Product: clang
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: mclow.lists at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
The following file:
```
#include <boost/array.hpp>
int main () {
boost::array<int, 5> arr;
return arr.size();
}
```
when compiled with a recent clang using `-Wcomma` gives a warning.
/Users/marshall/Sources/Boost/main/boost/array.hpp:185:107: warning: possible
misuse of comma operator here [-Wcomma]
return i >= size() ? boost::throw_exception(std::out_of_range
("array<>: index out of range")), true : true;
^
/Users/marshall/Sources/Boost/main/boost/array.hpp:185:34: note: cast
expression to void to silence warning
return i >= size() ? boost::throw_exception(std::out_of_range
("array<>: index out of range")), true : true;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
static_cast<void>(
)
The code that it is warning on is constexpr under C++11, and so must be a
single expression. It looks like this:
return i >= size()
? boost::throw_exception(...), true
: true;
The ", true" is necessary to make the two halves of the ?: expression have the
same type.
I believe that the code is correct, and the warning is erroneous. Certainly the
suggested "fix" is a complete non-starter.
--
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/20200917/3b48bc50/attachment.html>
More information about the llvm-bugs
mailing list