https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125879
Bug ID: 125879
Summary: Inconsistent -Wconversion-null
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nikita.leontiev at gmail dot com
Target Milestone: ---
-Wconversion-null warnings generated by gcc for the code below are inconsistent
between x64 and x86 versions.
Code:
#include <stddef.h>
template<typename T>
T test1()
{
return NULL;
}
template<typename T>
T test2()
{
return true?0:NULL;
}
template<typename T>
T test3()
{
return true?static_cast<T>(0):NULL;
}
int main()
{
test1<long>();
test1<long long>();
test2<long>();
test2<long long>();
test3<long>();
test3<long long>();
return 0;
}
x64:
main.cpp: In function 'T test2()':
main.cpp:12:23: warning: converting to non-pointer type 'long long int' from
NULL [-Wconversion-null]
12 | return true?0:NULL;
| ^~~~
main.cpp: In instantiation of 'T test1() [with T = long int]':
main.cpp:23:13: required from here
23 | test1<long>();
| ~~~~~~~~~~~^~
main.cpp:6:16: warning: converting to non-pointer type 'long int' from NULL
[-Wconversion-null]
6 | return NULL;
| ^~~~
main.cpp: In instantiation of 'T test1() [with T = long long int]':
main.cpp:24:18: required from here
24 | test1<long long>();
| ~~~~~~~~~~~~~~~~^~
main.cpp:6:16: warning: converting to non-pointer type 'long long int' from
NULL [-Wconversion-null]
6 | return NULL;
| ^~~~
main.cpp: In instantiation of 'T test2() [with T = long int]':
main.cpp:25:13: required from here
25 | test2<long>();
| ~~~~~~~~~~~^~
main.cpp:12:20: warning: converting to non-pointer type 'long long int' from
NULL [-Wconversion-null]
12 | return true?0:NULL;
| ^
main.cpp: In instantiation of 'T test2() [with T = long long int]':
main.cpp:26:18: required from here
26 | test2<long long>();
| ~~~~~~~~~~~~~~~~^~
main.cpp:12:20: warning: converting to non-pointer type 'long long int' from
NULL [-Wconversion-null]
12 | return true?0:NULL;
| ^
main.cpp: In instantiation of 'T test3() [with T = long int]':
main.cpp:27:13: required from here
27 | test3<long>();
| ~~~~~~~~~~~^~
main.cpp:18:20: warning: converting to non-pointer type 'long long int' from
NULL [-Wconversion-null]
18 | return true?static_cast<T>(0):NULL;
| ^
x86:
main.cpp: In instantiation of 'T test1() [with T = long int]':
main.cpp:23:13: required from here
23 | test1<long>();
| ~~~~~~~~~~~^~
main.cpp:6:16: warning: converting to non-pointer type 'long int' from NULL
[-Wconversion-null]
6 | return NULL;
| ^~~~
main.cpp: In instantiation of 'T test1() [with T = long long int]':
main.cpp:24:18: required from here
24 | test1<long long>();
| ~~~~~~~~~~~~~~~~^~
main.cpp:6:16: warning: converting to non-pointer type 'long long int' from
NULL [-Wconversion-null]
6 | return NULL;
| ^~~~
main.cpp: In instantiation of 'T test3() [with T = long int]':
main.cpp:27:13: required from here
27 | test3<long>();
| ~~~~~~~~~~~^~
main.cpp:18:20: warning: converting to non-pointer type 'long int' from NULL
[-Wconversion-null]
18 | return true?static_cast<T>(0):NULL;
| ^
main.cpp: In instantiation of 'T test3() [with T = long long int]':
main.cpp:28:18: required from here
28 | test3<long long>();
| ~~~~~~~~~~~~~~~~^~
main.cpp:18:20: warning: converting to non-pointer type 'long long int' from
NULL [-Wconversion-null]
18 | return true?static_cast<T>(0):NULL;
| ^