Open
Description
Bugzilla Link | 47566 |
Version | unspecified |
OS | All |
CC | @DougGregor,@zygoloid,@Weverything |
Extended Description
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.