Utilizzando clang 3.6.0, non riesco a compilare il seguente esempio di codice.È possibile utilizzare una variabile di template `constexpr` come predefinita per un argomento di template formale
#include <type_traits>
template <typename T> constexpr bool IS_SCALAR = ::std::is_scalar<T>::value;
template <typename T, bool = IS_SCALAR<T>>
struct Class_Breaks
{
};
template <typename T, bool = ::std::is_scalar<T>::value>
struct Class_Works
{
};
void function()
{
Class_Breaks<int> break_error;
Class_Breaks<int, IS_SCALAR<int>> breaks_ok;
Class_Works<int> ok;
}
Ma, i seguenti messaggi di errore vengono restituiti:
1> [ 66%] Building CXX object CMakeFiles/Core.dir/tests.cpp.obj
1>D:\Projects\Core\Core\tests.cpp(4,30): error : non-type template argument is not a constant expression
1> template <typename T, bool = IS_SCALAR<T>>
1> ^
1> D:\Projects\Core\Core\tests.cpp(16,18) : note: while checking a default template argument used here
1> Class_Breaks<int> break_error;
1> ~~~~~~~~~~~~~~~~^
1> 1 error generated.
È un [bug noto] (https://stackoverflow.com/questions/10721130/) – StenSoft