2014-06-26 10 views
12

Ich habe ein Problem beim Entpacken von variadischen Vorlagen in einen Vorlagenalias.Parameterpacks in Vorlagen-Aliase entpacken

Der folgende Code funktioniert mit Clang 3.4 und GCC 4.8 aber nicht mit GCC 4.9:

template <typename T, typename...> 
using front_type = T; 

template <typename... Ts> 
struct foo 
{ 
    using front = front_type<Ts...>; 
}; 

GCC 4.9 klagt:

test.cc:7:37: error: pack expansion argument for non-pack parameter 'T' of alias template 'template<class T, class ...> using front_type = T' 
     using front = front_type<Ts...>; 
            ^
test.cc:1:15: note: declared here 
    template <typename T, typename...> 
      ^

Es gibt einen eingereicht GCC-Bug (#59498), ist aber das soll scheitern? Hier sind einige Kontext aus dem C++ core language issue #1430, "pack expansion into fixed alias template parameter list":

Originally, a pack expansion could not expand into a fixed-length template parameter list, but this was changed in N2555. This works fine for most templates, but causes issues with alias templates.

In most cases, an alias template is transparent; when it's used in a template we can just substitute in the dependent template arguments. But this doesn't work if the template-id uses a pack expansion for non-variadic parameters. For example:

template<class T, class U, class V> 
    struct S {}; 

    template<class T, class V> 
    using A = S<T, int, V>; 

    template<class... Ts> 
    void foo(A<Ts...>); 

There is no way to express A<Ts...> in terms of S , so we need to hold onto the A until we have the T s to substitute in, and therefore it needs to be handled in mangling.

Currently, EDG and Clang reject this testcase, complaining about too few template arguments for A. G++ did as well, but I thought that was a bug. However, on the ABI list John Spicer argued that it should be rejected.

+0

Können Sie 'front_type' außerhalb von' foo' verschieben - sie scheinen nicht verwandt zu sein? – PiotrNycz

+0

Ja, guter Punkt @ PiotrNycz. (Es repariert es aber nicht.) – mavam

+0

Ich habe diesen modifizierten Code mit gcc4.8 überprüft - sieht aus wie es funktioniert. – PiotrNycz

Antwort

9

Es wurde in gcc4.9 Bugzilla berichtet:

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

Minimal Code

template <typename T, typename ...> 
using alias = T; 

template <typename ...T> 
using variadic_alias = alias<T...>; 

using Fail = variadic_alias<int>; 

int main() { } 

Aus der Erklärung zu reproduzieren von GCC-Leuten - ist es nicht t so offensichtlich, das ist ein echter Fehler. Dies ist immer noch Diskussion in gcc Bugzilla und in DR 1430 (http://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1430) - Zusammenfassung jetzt in der obigen Frage statt.

+0

Es wird als Fehler gemeldet, aber mit Blick auf die Kommentare scheint zu sein Design. –

+0

Ja, es sieht so aus, als ob das scheitern soll? Ich habe die Frage mit Kontext aus [# 1430] (http://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1430) – mavam

+0

@ T.C bearbeitet. Guter Punkt, ich habe es verpasst. – PiotrNycz