Skip to content

Commit 8f44ad1

Browse files
authored
Fix: #issue76161: error C2440 of 'static_cast': cannot convert from 'InType' to 'OutType' (#76185)
* fix error C2440 when running ninja on windows * fix pre-commit codestyle issues
1 parent 05aa7ef commit 8f44ad1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

paddle/phi/core/framework/data_type_transform.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,26 @@ namespace phi {
3030
template <typename InType, typename OutType>
3131
struct CastDataTypeFunctor {
3232
HOSTDEVICE inline OutType operator()(InType in) const {
33+
#if defined(_MSC_VER)
34+
// Avoid unsupported convert of float/bfloat8/float16 -> complex
35+
if constexpr (
36+
(std::is_same_v<OutType, phi::dtype::complex<float>> ||
37+
std::is_same_v<
38+
OutType,
39+
phi::dtype::complex<
40+
double>>)&&(std::is_same_v<InType,
41+
phi::dtype::float8_e4m3fn> ||
42+
std::is_same_v<InType, phi::dtype::float8_e5m2> ||
43+
std::is_same_v<InType, phi::dtype::bfloat16> ||
44+
std::is_same_v<InType, phi::dtype::float16>)) {
45+
// default value,only to avoid compile error
46+
return OutType(0);
47+
} else {
48+
return static_cast<OutType>(in);
49+
}
50+
#else
3351
return static_cast<OutType>(in);
52+
#endif
3453
}
3554
};
3655

0 commit comments

Comments
 (0)