33

ऐसा लगता है कि एक उपनाम टेम्पलेट के पैक पैरामीटर के स्थान पर एक पैक तर्क केवल का विस्तार किया जा सकता है।उपनाम टेम्पलेट के लिए पैक विस्तार

template <class T, class... Args> struct x { using type = T; }; 

template <class T, class... Args> using x_t  = typename x<T, Args...>::type; 
template <class... Args>   using x_fix_t = typename x<Args...>::type; 

template <class... Args> auto f(Args...) -> void { 
    typename x<Args...>::type v1; // OK 
    x_t<Args...> v2; // Error 
    x_fix_t<Args...> v3; // OK 
} 

सरल मामला:: यह एक वर्ग या एक समारोह टेम्पलेट के लिए सच नहीं है

template <class T, class U> using y_t = T; 

template <class... Args> auto f(Args...) -> void { 
    y_t<Args...> v4; // Error 
} 

ऊपर कोड दोनों c++11 और g++ 4.9 में c++14 साथ त्रुटि (भले ही f instantiated कभी नहीं किया गया है) उत्पन्न करता है, g++ 5.1 और clang 3.5

इसकी अनुमति क्यों नहीं है और सामान्य नियम क्या है? मुझे इसे प्रतिबंधित करने का कोई कारण नहीं है। यह एक बहुत अजीब निषेध लगता है।

क्यों पहले संस्करण के साथ x_fix_t के रूप में लिखना क्यों नहीं है यह अधिक स्पष्ट है कि x_t में एक अनिवार्य पहला तर्क है। (उदाहरण के लिए f() का कारण नहीं है)। लेकिन यह इतना महत्वपूर्ण नहीं है, फिक्स आसान है। सवाल बनी हुई है: क्यों?

जीसीसी त्रुटि:

error: pack expansion argument for non-pack parameter ‘T’ of 
alias template ‘template<class T, class ... Args> using x_t = typename x::type’ 

बजना त्रुटि:

error: pack expansion used as argument for non-pack parameter of 
alias template x_t<Args...> v2; 
+2

यहां जानकारी प्रासंगिक है, मुझे लगता है: http://stackoverflow.com/q/24433658/4326278 – bogdan

+0

इसके अलावा, इसके लायक होने के लिए, एमएसवीसी 12 और 14 आरसी इसे बिना किसी निदान के संकलित करता है (बिना किसी संदर्भ के सामान्य चेतावनियों से अलग चर) - "कार्यान्वयन भिन्नता", जैसा कि वे कहते हैं। – bogdan

+0

जी ++ 4.8.2 में ठीक काम करता है। –

उत्तर

14

यह जीसीसी 4.8 में संकलित लेकिन जीसीसी 4.9 है, जो सबूत है कि यह DR1430 और bug report #59498 से संबंधित है है में विफल रहता है।

Rewriting the code to use a struct succeeds: 

template <typename T, typename ...> 
struct alias { using type = T; }; 

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

इसके अलावा, जेसन मेरिल कारण है कि यह असफल चाहिए पर बताते हैं:: ठीक रॉय Chrihfield द्वारा प्रस्तावित तुम्हारा के रूप में ठीक उसी में से एक है

Actually, no, this is very much a Core 1430 issue; there's no way to mangle variadic_alias without mentioning the name of an alias template in the mangling, and they're supposed to be entirely transparent. This only works in 4.8 by accident because checking is disabled for the release.

आगे कोई चर्चा बग रिपोर्ट में मौजूद है, तो हम DR1430:

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 in terms of S, so we need to hold onto the A until we have the Ts 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.

(See also issue 1558.)

Notes from the October, 2012 meeting:

The consensus of CWG was that this usage should be prohibited, disallowing use of an alias template when a dependent argument can't simply be substituted directly into the type-id.

Additional note, April, 2013:

For another example, consider:

template<class... x> class list{}; 
    template<class a, class... b> using tail=list<b...>; 
    template <class...T> void f(tail<T...>); 

    int main() { 
    f<int,int>({}); 
    } 

There is implementation variance in the handling of this example.

अन्य शब्दों में, यह बिना किसी संकल्प (AFAIC) के बिना चल रहा मुद्दा है।

संबंधित मुद्दे