Skip to content

<cmath>: A compile-time warning C4244: 'argument': conversion from '_Common' to 'double' #3246

@steve02081504

Description

@steve02081504

Describe the bug
I found this annoying warning when I was idly testing my library and I'd like it to be dealt with reasonably well if possible

Command-line test case

#include <type_traits>
#include <cmath>
template<typename T> requires ::std::is_arithmetic_v<T>
constexpr T copy_as_negative(auto x,bool negative=1)noexcept{
	if constexpr(::std::is_signed_v<decltype(x)>){
		if constexpr(::std::is_floating_point_v<decltype(x)>)
			return(T)::std::copysign(x,negative?-1:1);
		else
			return(T)negative?T{}-x:x;
	}
	else
		return x;
}
constexpr auto copy_as_negative(auto x,bool negative=1)noexcept{
	return copy_as_negative<decltype(x)>(x,negative);
}
int main() {
	copy_as_negative(long double{0}, 1);
}

Compile this program together with /W4 and you will reasonably get a C4244 warning

Expected behavior
no C4244 warning plz

STL version

Microsoft Visual Studio Community 2022 (64 位) - Preview
17.5.0 Preview 1.0

Additional context
The original code is at https://godbolt.org/z/3eav315a1 if anyone needs it

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedSomething works now, yay!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions