2016-08-15 7 views
5
template<bool b = 2> void foo(void) {} 
template void foo(); 

template<unsigned char n = 258> void bar(void) {} 
template void bar(); 

जीसीसी तत्काल foo < सत्य> और बार < 2>; क्लैंग दोनों को "त्रुटि: अस्वीकार करता है: गैर-प्रकार का टेम्पलेट तर्क 2 का मूल्यांकन करता है, जिसे 'बूल' टाइप करने के लिए संकुचित नहीं किया जा सकता है [-WC++ 11-narrowing]"।आउट-ऑफ-रेंज टेम्पलेट पैरामीटर पर अपेक्षित व्यवहार?

क्या उपरोक्त कोड मान्य है? क्या यह उनमें से एक में एक बग है?

संस्करण इस्तेमाल किया: बजना 3.8.0-2ubuntu4, जीसीसी 5.4.0 20,160,609 (उबंटू 5.4.0-6ubuntu1 ~ 16.04.2)

उत्तर

7

यह जीसीसी बग 57891 और 60715 है। [Dcl.init.list] से

A converted constant expression of type T is an expression, implicitly converted to type T, where the converted expression is a constant expression and the implicit conversion sequence contains only [...] integral conversions (4.7) other than narrowing conversions (8.5.4),

:

A narrowing conversion is an implicit conversion [...] from an integer type or unscoped enumeration type to an integer type that cannot represent all the values of the original type, except where the source is a constant expression whose value after integral promotions will fit into the target type.

A template-argument for a non-type template-parameter shall be a converted constant expression (5.20) of the type of the template-parameter.

[expr.const] से:

[temp.arg.nontype] से

रूपांतरणों को संक्षिप्त करना (उदाहरण के लिए 2 से bool या 258 से char) बीमार हैं टेम्पलेट गैर-प्रकार पैरामीटर के लिए डी।

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