История изменений
Исправление fsb4000, (текущая версия) :
Это сказано в стандарте?
$ cat main.cpp
template<typename T>
T& f()
{
return *(T*)nullptr;
}
int main()
{
int& a = f<int>();
}
$ clang++ -Wnull-dereference main.cpp
main.cpp:5:12: warning: binding dereferenced null pointer to reference has undefined behavior [-Wnull-dereference]
return *(T*)nullptr;
^~~~~~~~~~~~
main.cpp:10:14: note: in instantiation of function template specialization 'f<int>' requested here
int& a = f<int>();
^
1 warning generated.
Компилятор твой друг.
Ну и кастану stasolog
Исходная версия fsb4000, :
$ cat main.cpp
template<typename T>
T& f()
{
return *(T*)nullptr;
}
int main()
{
int& a = f<int>();
}
$ clang++ -Wnull-dereference main.cpp
main.cpp:5:12: warning: binding dereferenced null pointer to reference has undefined behavior [-Wnull-dereference]
return *(T*)nullptr;
^~~~~~~~~~~~
main.cpp:10:14: note: in instantiation of function template specialization 'f<int>' requested here
int& a = f<int>();
^
1 warning generated.
Компилятор твой друг.
Ну и кастану stasolog