2014-06-26 36 views
12

मैं टेम्पलेट उपनाम में अनपॅकिंग वैरैडिक टेम्पलेट्स के साथ एक समस्या में भाग लेता हूं।टेम्पलेट उपनामों में पैरामीटर पैक अनपॅकिंग

निम्नलिखित कोड बजना 3.4 और जीसीसी 4.8 के साथ काम करता है, लेकिन जीसीसी 4.9 के साथ विफल:

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

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

जीसीसी 4.9 शिकायत:

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...> 
      ^

एक दायर जीसीसी बग (#59498) भी बना हुआ है, लेकिन है यह असफल होना चाहिए? यहाँ 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

क्या आप 'foo' के बाहर 'front_type' को स्थानांतरित कर सकते हैं - वे संबंधित नहीं हैं? – PiotrNycz

+0

हाँ, अच्छा बिंदु @PiotrNycz। (हालांकि यह ठीक नहीं करता है।) – mavam

+0

मैंने इस संशोधित कोड को gcc4.8 के साथ चेक किया - ऐसा लगता है कि यह काम करता है। – PiotrNycz

उत्तर

9

यह gcc4.9 बगजिला में सूचना मिली थी:

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

मिनिमल कोड

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

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

using Fail = variadic_alias<int>; 

int main() { } 

पुन: पेश करने स्पष्टीकरण से जीसीसी लोगों से - यह नहीं है टी इतना स्पष्ट है कि यह एक असली बग है। यह अभी भी जीसीसी बगजिला और डीआर 1430 (http://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1430) में आयोजित चर्चा है - उपर्युक्त प्रश्न में सारांश।

+0

यह एक बग के रूप में रिपोर्ट किया गया है लेकिन यह टिप्पणियों को देखकर ऐसा लगता है डिज़ाइन। –

+0

हाँ, ऐसा लगता है कि यह असफल होना चाहिए? मैंने [# 1430] (http://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1430) से संदर्भ के साथ प्रश्न संपादित किया – mavam

+0

@ टी.सी. अच्छा मुद्दा, मुझे याद आया। – PiotrNycz

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