https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69958

            Bug ID: 69958
           Summary: sizeof... computes wrong size
           Product: gcc
           Version: 5.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: CoachHagins at gmail dot com
  Target Milestone: ---

When sizeof...() is used in a wrapped context, it computes the incorrect size.

This is evident when using std::index_sequence_for, but I think it's a language
problem and not a library problem because I can reproduce the same mal-behavior
without involving the standard library.

I get the same behavior in 5.2 and 5.3; -std=c++14

See the following code example.


template <typename...Ts>
struct list { };

template <std::size_t N>
struct size {  };

template <typename...Ts>
using size_for = size<sizeof...(Ts)>;


template <typename T, typename...Ts>
using plain = size_for<T, Ts...>;

// This assertion passes
static_assert(std::is_same<
    size<5>,
    plain<float, int, double, char, unsigned>>::value, "");


template <typename T, typename...Ts>
using plain2 = size_for<Ts..., T>;

// This assertion passes
static_assert(std::is_same<
    size<5>,
    plain2<float, int, double, char, unsigned>>::value, "");


template <typename T, typename...Ts>
using wrapped = list<T, size_for<T, Ts...>>;

// This assertion fails (produces size<4>)
static_assert(std::is_same<
    list<float, size<5>>,
    wrapped<float, int, double, char, unsigned>>::value, "");


template <typename T, typename...Ts>
using wrapped2 = list<T, size_for<Ts..., T>>;

// This assertion fails (produces size<2>)
static_assert(std::is_same<
    list<float, size<5>>,
    wrapped2<float, int, double, char, unsigned>>::value, "");

Reply via email to