Is the following g++
's behaviour a bug?
#include <utility>
#include <type_traits>
template< std::size_t ...i >
constexpr
bool f(int k, std::index_sequence< i... >)
{
int j = (std::size_t((void(i), 1)) + ...) * k;
return 0 < j;
}
static_assert(f(3, std::make_index_sequence< 3 >{}));
Gives an error message:
main.cpp: In function
constexpr bool f(int, std::index_sequence<i ...>)
:main.cpp:11:33: error: declaration of
void i
shadows template parameterint j = (std::size_t((void(i), 1)) + ...) * k; ^
main.cpp:7:11: note: template parameter
i
declared heretemplate< std::size_t ...i > ^~~
Changing from void
to static_cast< void >
makes error to cease.
Multiplication by k
from the left side also makes error to cease.
std::size_t
here is to avoid this g++
's bug.
I know, that declaration int (i),
is equivalent to int i,
in a couple of contexts, but not in lhs part of built-in comma operator. Moreover, it is a void
variable declaration.