Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert arguments to double in _GENERIC_MATH2_BASE #3253

Merged
merged 4 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions stl/inc/cmath
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,16 @@ _STD _Common_float_type_t<_Ty1, _Ty2> remquo(_Ty1 _Left, _Ty2 _Right, int* _Pquo
return _CSTD FUN(static_cast<double>(_Left), _Arg2); \
}

// When the arguments are both floats or both long doubles, overload resolution prefers the
// non-template overloads to the templates generated from this macro. The templates generated from
// this macro are only selected by overload resolution when both arguments have integral type, or
// when the types of the two arguments differ, in which case _Common_float_type_t is either double
// or long double.
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
#define _GENERIC_MATH2_BASE(NAME, FUN) \
template <class _Ty1, class _Ty2, \
_STD enable_if_t<_STD is_arithmetic_v<_Ty1> && _STD is_arithmetic_v<_Ty2>, int> = 0> \
_NODISCARD _STD _Common_float_type_t<_Ty1, _Ty2> NAME(_Ty1 _Left, _Ty2 _Right) noexcept /* strengthened */ { \
using _Common = _STD _Common_float_type_t<_Ty1, _Ty2>; \
return FUN(static_cast<_Common>(_Left), static_cast<_Common>(_Right)); \
return FUN(static_cast<double>(_Left), static_cast<double>(_Right)); \
CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
}

#define _GENERIC_MATH2(FUN) _GENERIC_MATH2_BASE(FUN, _CSTD FUN)
Expand Down
1 change: 1 addition & 0 deletions tests/std/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ tests\GH_002992_unwrappable_iter_sent_pairs
tests\GH_003022_substr_allocator
tests\GH_003105_piecewise_densities
tests\GH_003119_error_category_ctor
tests\GH_003246_cmath_narrowing
tests\LWG2597_complex_branch_cut
tests\LWG3018_shared_ptr_function
tests\LWG3121_constrained_tuple_forwarding_ctor
Expand Down
4 changes: 4 additions & 0 deletions tests/std/tests/GH_003246_cmath_narrowing/env.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

RUNALL_INCLUDE ..\usual_matrix.lst
21 changes: 21 additions & 0 deletions tests/std/tests/GH_003246_cmath_narrowing/test.compile.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <cmath>

int main() {} // COMPILE-ONLY

// Ensure the compiler doesn't warn about narrowing long double to double in <cmath> GENERIC_MATH2 templates
#define TEST(meow) \
long double test_##meow(long double x) { return std::meow(x, 1); }

TEST(atan2)
TEST(hypot)
TEST(pow)
TEST(fmod)
TEST(remainder)
TEST(copysign)
TEST(nextafter)
TEST(fdim)
TEST(fmax)
TEST(fmin)