diff --git a/flang/include/flang/Runtime/cpp-type.h b/flang/include/flang/Runtime/cpp-type.h --- a/flang/include/flang/Runtime/cpp-type.h +++ b/flang/include/flang/Runtime/cpp-type.h @@ -23,14 +23,14 @@ using common::TypeCategory; -template struct CppTypeForHelper {}; +template struct CppTypeForHelper { + using type = void; +}; template using CppTypeFor = typename CppTypeForHelper::type; -template -constexpr bool HasCppTypeFor{false}; template -constexpr bool HasCppTypeFor{ +constexpr bool HasCppTypeFor{ !std::is_void_v::type>}; template struct CppTypeForHelper { diff --git a/flang/runtime/dot-product.cpp b/flang/runtime/dot-product.cpp --- a/flang/runtime/dot-product.cpp +++ b/flang/runtime/dot-product.cpp @@ -147,24 +147,24 @@ }; extern "C" { -std::int8_t RTNAME(DotProductInteger1)( +CppTypeFor RTNAME(DotProductInteger1)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } -std::int16_t RTNAME(DotProductInteger2)( +CppTypeFor RTNAME(DotProductInteger2)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } -std::int32_t RTNAME(DotProductInteger4)( +CppTypeFor RTNAME(DotProductInteger4)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } -std::int64_t RTNAME(DotProductInteger8)( +CppTypeFor RTNAME(DotProductInteger8)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } #ifdef __SIZEOF_INT128__ -common::int128_t RTNAME(DotProductInteger16)( +CppTypeFor RTNAME(DotProductInteger16)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } @@ -172,16 +172,16 @@ // TODO: REAL/COMPLEX(2 & 3) // Intermediate results and operations are at least 64 bits -float RTNAME(DotProductReal4)( +CppTypeFor RTNAME(DotProductReal4)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } -double RTNAME(DotProductReal8)( +CppTypeFor RTNAME(DotProductReal8)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } #if LDBL_MANT_DIG == 64 -long double RTNAME(DotProductReal10)( +CppTypeFor RTNAME(DotProductReal10)( const Descriptor &x, const Descriptor &y, const char *source, int line) { return DotProduct{}(x, y, source, line); } @@ -193,24 +193,25 @@ } #endif -void RTNAME(CppDotProductComplex4)(std::complex &result, +void RTNAME(CppDotProductComplex4)(CppTypeFor &result, const Descriptor &x, const Descriptor &y, const char *source, int line) { - auto z{DotProduct{}(x, y, source, line)}; - result = std::complex{ - static_cast(z.real()), static_cast(z.imag())}; + result = DotProduct{}(x, y, source, line); } -void RTNAME(CppDotProductComplex8)(std::complex &result, +void RTNAME(CppDotProductComplex8)(CppTypeFor &result, const Descriptor &x, const Descriptor &y, const char *source, int line) { result = DotProduct{}(x, y, source, line); } #if LDBL_MANT_DIG == 64 -void RTNAME(CppDotProductComplex10)(std::complex &result, - const Descriptor &x, const Descriptor &y, const char *source, int line) { +void RTNAME(CppDotProductComplex10)( + CppTypeFor &result, const Descriptor &x, + const Descriptor &y, const char *source, int line) { result = DotProduct{}(x, y, source, line); } -#elif LDBL_MANT_DIG == 113 -void RTNAME(CppDotProductComplex16)(std::complex &result, - const Descriptor &x, const Descriptor &y, const char *source, int line) { +#endif +#if LDBL_MANT_DIG == 113 || HAS_FLOAT128 +void RTNAME(CppDotProductComplex16)( + CppTypeFor &result, const Descriptor &x, + const Descriptor &y, const char *source, int line) { result = DotProduct{}(x, y, source, line); } #endif