https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91747
Bug ID: 91747
Summary: Using a type alias leads to wrong static values.
Product: gcc
Version: 9.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: d.frey at gmx dot de
Target Milestone: ---
Sorry for the title, I have no idea how to describe the problem in any better
way :-/
The following program fails, the static_assert() is (wrongly) triggered:
#include <utility>
template< typename T, typename = std::make_index_sequence< T::size() > >
struct inclusive_scan;
template< std::size_t... Ns, std::size_t... Is >
struct inclusive_scan< std::index_sequence< Ns... >, std::index_sequence< Is...
> >
{
template< std::size_t I >
using part = std::integral_constant< std::size_t, ( 0 + ... + ( ( Is <= I )
? Ns : 0 ) ) >;
using type = std::index_sequence< part< Is >::value... >;
};
int main()
{
using S = std::index_sequence<3,1,2,1,3>;
using IS = inclusive_scan<S>::type;
static_assert( std::is_same_v<IS, std::index_sequence<3,4,6,7,10>> );
}
Clang and MSVC accept the code.
If you change
template< std::size_t I >
using part = std::integral_constant< std::size_t, ( 0 + ... + ( ( Is <= I )
? Ns : 0 ) ) >;
into
template< std::size_t I >
struct part : std::integral_constant< std::size_t, ( 0 + ... + ( ( Is <= I
) ? Ns : 0 ) ) >{};
the code is also compiled correctly with GCC. This problem is present in GCC 7,
8, 9 and trunk, see Compiler Explorer https://godbolt.org/z/KOdhTV