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

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

GCC foo < doğru başlatır> ve < 2> bar; Clang her ikisi de "hata: tip olmayan şablon argümanı 2 ile değerlendirir, bu da" bool "[-WC++ 11-daraltma] 'türüne göre daraltılamaz.Aralık dışı şablon parametrelerinde beklenen davranış?

Yukarıdaki kod geçerli mi? Bu onlardan birinde bir böcek mi? kullanılan

Versiyonlar: Clang 3.8.0-2ubuntu4 GCC 5.4.0 20.160.609 (~ 16.04.2 Ubuntu 5.4.0-6ubuntu1)

cevap

7

gcc hata 57891 ve 60715 olup. [Dcl.init.list] kaynaktan

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.

[expr.const] kaynaktan

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

: [temp.arg.nontype] kaynaktan

Daralma dönüşümleri (örn. 2 - bool veya 258 - char) şablon olmayan tip parametreler için d.

İlgili konular