Skip to content

-Wcomma flags Boost.Array code incorrectly #46910

Open
@mclow

Description

@mclow
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions