Tested on Linux-x64. 2017-11-14 Ville Voutilainen <ville.voutilai...@gmail.com>
Implement LWG 2733 and LWG 2759 * include/experimental/numeric (gcd): Reject cv-qualified bool. (lcm): Likewise. * include/std/numeric (gcd): Likewise. (lcm): Likewise. * testsuite/26_numerics/gcd/gcd_neg.cc: Add tests and adjust. * testsuite/26_numerics/lcm/lcm_neg.cc: Likewise.
diff --git a/libstdc++-v3/include/experimental/numeric b/libstdc++-v3/include/experimental/numeric index c8597fc..6a48c72 100644 --- a/libstdc++-v3/include/experimental/numeric +++ b/libstdc++-v3/include/experimental/numeric @@ -57,8 +57,10 @@ inline namespace fundamentals_v2 { static_assert(is_integral<_Mn>::value, "gcd arguments are integers"); static_assert(is_integral<_Nn>::value, "gcd arguments are integers"); - static_assert(!is_same<_Mn, bool>::value, "gcd arguments are not bools"); - static_assert(!is_same<_Nn, bool>::value, "gcd arguments are not bools"); + static_assert(!is_same<typename remove_cv<_Mn>::type, bool>::value, + "gcd arguments are not bools"); + static_assert(!is_same<typename remove_cv<_Nn>::type, bool>::value, + "gcd arguments are not bools"); return std::__detail::__gcd(__m, __n); } @@ -69,8 +71,10 @@ inline namespace fundamentals_v2 { static_assert(is_integral<_Mn>::value, "lcm arguments are integers"); static_assert(is_integral<_Nn>::value, "lcm arguments are integers"); - static_assert(!is_same<_Mn, bool>::value, "lcm arguments are not bools"); - static_assert(!is_same<_Nn, bool>::value, "lcm arguments are not bools"); + static_assert(!is_same<typename remove_cv<_Mn>::type, bool>::value, + "lcm arguments are not bools"); + static_assert(!is_same<typename remove_cv<_Nn>::type, bool>::value, + "lcm arguments are not bools"); return std::__detail::__lcm(__m, __n); } } // namespace fundamentals_v2 diff --git a/libstdc++-v3/include/std/numeric b/libstdc++-v3/include/std/numeric index 2b80419..e3276e4 100644 --- a/libstdc++-v3/include/std/numeric +++ b/libstdc++-v3/include/std/numeric @@ -133,8 +133,10 @@ namespace __detail { static_assert(is_integral<_Mn>::value, "gcd arguments are integers"); static_assert(is_integral<_Nn>::value, "gcd arguments are integers"); - static_assert(!is_same<_Mn, bool>::value, "gcd arguments are not bools"); - static_assert(!is_same<_Nn, bool>::value, "gcd arguments are not bools"); + static_assert(!is_same<typename std::remove_cv<_Mn>::type, bool>::value, + "gcd arguments are not bools"); + static_assert(!is_same<typename std::remove_cv<_Nn>::type, bool>::value, + "gcd arguments are not bools"); return __detail::__gcd(__m, __n); } @@ -145,8 +147,10 @@ namespace __detail { static_assert(is_integral<_Mn>::value, "lcm arguments are integers"); static_assert(is_integral<_Nn>::value, "lcm arguments are integers"); - static_assert(!is_same<_Mn, bool>::value, "lcm arguments are not bools"); - static_assert(!is_same<_Nn, bool>::value, "lcm arguments are not bools"); + static_assert(!is_same<typename remove_cv<_Mn>::type, bool>::value, + "lcm arguments are not bools"); + static_assert(!is_same<typename remove_cv<_Nn>::type, bool>::value, + "lcm arguments are not bools"); return __detail::__lcm(__m, __n); } diff --git a/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc b/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc index 30524a1b..d5de28f 100644 --- a/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/gcd/gcd_neg.cc @@ -26,6 +26,20 @@ test01() std::gcd(true, 1); // { dg-error "from here" } std::gcd(1, true); // { dg-error "from here" } std::gcd(true, true); // { dg-error "from here" } + std::gcd<const bool, int>(true, 1); // { dg-error "from here" } + std::gcd<int, const bool>(1, true); // { dg-error "from here" } + std::gcd<const bool, const bool>(true, true); // { dg-error "from here" } + std::gcd<const bool&, int>(true, 1); // { dg-error "from here" } + std::gcd<int, const bool&>(1, true); // { dg-error "from here" } + std::gcd<const bool&, const bool&>(true, true); // { dg-error "from here" } + std::gcd<const volatile bool, int>(true, 1); // { dg-error "from here" } + std::gcd<int, const volatile bool>(1, true); // { dg-error "from here" } + std::gcd<const volatile bool, + const volatile bool>(true, true); // { dg-error "from here" } + std::gcd<volatile bool, int>(true, 1); // { dg-error "from here" } + std::gcd<int, volatile bool>(1, true); // { dg-error "from here" } + std::gcd<volatile bool, + volatile bool>(true, true); // { dg-error "from here" } std::gcd(0.1, 1); // { dg-error "from here" } std::gcd(1, 0.1); // { dg-error "from here" } std::gcd(0.1, 0.1); // { dg-error "from here" } @@ -34,6 +48,6 @@ test01() // { dg-error "integers" "" { target *-*-* } 134 } // { dg-error "integers" "" { target *-*-* } 135 } // { dg-error "not bools" "" { target *-*-* } 136 } -// { dg-error "not bools" "" { target *-*-* } 137 } +// { dg-error "not bools" "" { target *-*-* } 138 } // { dg-prune-output "deleted function" } // { dg-prune-output "invalid operands" } diff --git a/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc b/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc index e16e6ae..d6a4b3a 100644 --- a/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc +++ b/libstdc++-v3/testsuite/26_numerics/lcm/lcm_neg.cc @@ -26,14 +26,28 @@ test01() std::lcm(true, 1); // { dg-error "from here" } std::lcm(1, true); // { dg-error "from here" } std::lcm(true, true); // { dg-error "from here" } + std::lcm<const bool, int>(true, 1); // { dg-error "from here" } + std::lcm<int, const bool>(1, true); // { dg-error "from here" } + std::lcm<const bool, const bool>(true, true); // { dg-error "from here" } + std::lcm<const bool&, int>(true, 1); // { dg-error "from here" } + std::lcm<int, const bool&>(1, true); // { dg-error "from here" } + std::lcm<const bool&, const bool&>(true, true); // { dg-error "from here" } + std::lcm<const volatile bool, int>(true, 1); // { dg-error "from here" } + std::lcm<int, const volatile bool>(1, true); // { dg-error "from here" } + std::lcm<const volatile bool, + const volatile bool>(true, true); // { dg-error "from here" } + std::lcm<volatile bool, int>(true, 1); // { dg-error "from here" } + std::lcm<int, volatile bool>(1, true); // { dg-error "from here" } + std::lcm<volatile bool, + volatile bool>(true, true); // { dg-error "from here" } std::lcm(0.1, 1); // { dg-error "from here" } std::lcm(1, 0.1); // { dg-error "from here" } std::lcm(0.1, 0.1); // { dg-error "from here" } } -// { dg-error "integers" "" { target *-*-* } 146 } -// { dg-error "integers" "" { target *-*-* } 147 } -// { dg-error "not bools" "" { target *-*-* } 148 } -// { dg-error "not bools" "" { target *-*-* } 149 } +// { dg-error "integers" "" { target *-*-* } 148 } +// { dg-error "integers" "" { target *-*-* } 149 } +// { dg-error "not bools" "" { target *-*-* } 150 } +// { dg-error "not bools" "" { target *-*-* } 152 } // { dg-prune-output "deleted function" } // { dg-prune-output "invalid operands" }