mardi 4 août 2015

What is the syntax for parameter pack expansion with alignas?

I'm trying to expand a parameter pack in an alignment specifier. I can't get the syntax right. Here's a simple example:

#include <cstdint>
#include <tuple>

template <typename... Ts>
struct C
{
    using Tuple_Type = std::tuple <Ts...>;

    void f()
    {
        uint8_t i1;
        uint8_t i2 alignas (2);
        uint8_t i3 alignas (typename std::tuple_element<0, Tuple_Type>::type);
        uint8_t i4 alignas (Ts...);
    }
};

//template class C <>;  // not compatible with i3 declaration above
template class C <uint64_t>;

This fails to compile with gcc 4.8.3:

foo.cpp: In member function 'void C<Ts>::f()':
foo.cpp:14:31: error: expected ')' before '...' token
         uint8_t i4 alignas (Ts...);
                               ^
foo.cpp:14:31: error: expected ')' before '...' token
foo.cpp:14:31: error: expected initializer before '...' token

The C++ standard ([dcl.align]) says "An alignment-specifier with an ellipsis is a pack expansion", so it seems like it should be possible to do what I want.

I've been unable to find an example of this kind of parameter pack expansion, and my search for a possible bug in gcc didn't find anything.

Aucun commentaire:

Enregistrer un commentaire