2014-07-12 11 views
6

क्लैंग 3.4 निम्नलिखित कोड स्वीकार करता है; जबकि कुलपति ++ NOV 2013 CTP एक त्रुटि के साथ यह खारिज कर दिया:कोड को क्लैंग द्वारा स्वीकार क्यों किया जाता है लेकिन वीसी ++ द्वारा अस्वीकार किया जाता है?

error C2668: 'AreEqual' : ambiguous call to overloaded function 
template<class headT, class... tailTypes> 
constexpr headT&& __GetFirst__(headT&& value, tailTypes&&...) 
{ 
    return static_cast<headT&&>(value); 
}; 

template<class T> 
constexpr bool AreEqual(const T& a, const T& b) 
{ 
    return a == b; 
} 

template<class headT, class... tailTypes> 
constexpr bool AreEqual(const headT& head_value, const tailTypes&... tail_values) 
{ 
    return AreEqual(head_value, __GetFirst__(tail_values...)) 
      && AreEqual(tail_values...); 
} 

int main() 
{ 
    AreEqual(1, 1, 2, 1); 
} 

कौन सा संकलक प्रति सी ++ 14 मानक के रूप में सही है?

अद्यतन: पूर्ण त्रुटि संदेश:

error C2668: 'AreEqual' : ambiguous call to overloaded function 
1>   d:\projects\ktl\test\main.cpp(20): could be 'bool AreEqual<headT,int>(const headT &,const int &)' 
1>   with 
1>   [ 
1>    headT=int 
1>   ] 
1>   d:\projects\ktl\test\main.cpp(8): or  'bool AreEqual<headT>(const T &,const T &)' 
1>   with 
1>   [ 
1>    headT=int 
1> ,   T=int 
1>   ] 
1>   while trying to match the argument list '(const int, const int)' 
1> 
1>Build FAILED. 
+4

साइड नोट : '__GetFirst__' एक आरक्षित नाम है। –

+0

क्या आप पूर्ण त्रुटि संदेश पोस्ट कर सकते हैं? –

+0

पता नहीं है कि कौन सा सही है, लेकिन आसान फिक्स में 3+ पैराम – sp2danny

उत्तर

8

बजना (और जीसीसी) के व्यवहार सही है। आप पढ़ सकते हैं §14.8.2.4 [temp.deduct.partial] कैसे समारोह टेम्पलेट्स के लिए आंशिक आदेश से किया जाता है के लिए मानक की, लेकिन उदाहरण है कि उपखंड के p8 में दिए गए सीधे इस स्थिति को शामिल किया गया:

template<class... Args> void f(Args... args); // #1 
template<class T1, class... Args> void f(T1 a1, Args... args); // #2 
template<class T1, class T2> void f(T1 a1, T2 a2); // #3 
f(); // calls #1 
f(1, 2, 3); // calls #2 
f(1, 2); // calls #3; non-variadic template #3 is more 
     // specialized than the variadic templates #1 and #2 
+2

+1। मानक के विभिन्न संस्करणों में इसे ढूंढना आसान बनाने के लिए उस उपखंड के लिए '[ब्रेकड उपखंड]' पहचानकर्ता भी जोड़ा गया। (विशिष्ट क्लॉज # एस चारों ओर घूमते हैं लेकिन उन पहचानकर्ताओं को ठीक किया जाता है) –

+2

@ बिलीओनल मैं उन पहचानकर्ताओं के बारे में झगड़ा करूँगा ('basic.lookup.koenig'->' basic.lookup.argdep' :)) लेकिन बिंदु ले लिया। –

+0

टी.सी. lol - अच्छी तरह से, किसी भी दर पर अपेक्षाकृत तय –

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