libstdc++: Deprecate non-standard std::fabs(const complex<T>&) [PR120235]

There was an overload of fabs for std::complex in TR1 and in some C++0x
drafts, but it was removed from the working draft by LWG 595.

Since we've been providing it for decades we should deprecate it before
removing it.

libstdc++-v3/ChangeLog:

	PR libstdc++/120235
	* doc/html/*: Regenerate.
	* doc/xml/manual/evolution.xml: Document deprecation.
	* include/std/complex: Replace references to TR1 subclauses with
	corresponding C++11 subclauses.
	(fabs): Add deprecated attribute.
	* testsuite/26_numerics/complex/fabs_neg.cc: New test.

Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>
This commit is contained in:
Jonathan Wakely
2025-05-12 11:34:01 +01:00
committed by Jonathan Wakely
parent 87d0daab1e
commit 6dbcbd96e9
8 changed files with 40 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@@ -490,7 +490,7 @@ to provide the symbols for the experimental C++ Contracts support.</p></div><div
Symbols for the Filesystem TS and C++23 <code class="filename">&lt;stacktrace&gt;</code>
header were added to the static library <code class="filename">libstdc++exp.a</code>.
</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="api.rel_141"></a><code class="constant">14</code></h3></div></div></div><p>
Deprecate the non-standard overload that allows <code class="code">std::setfill</code>
Deprecated the non-standard overload that allows <code class="code">std::setfill</code>
to be used with <code class="code">std::basic_istream</code>.
</p><p>
The extension allowing <code class="code">std::basic_string</code> to be instantiated
@@ -509,4 +509,7 @@ and removed in C++20:
</p><p>
Nested <code class="code">result_type</code> and <code class="code">argument_type</code> removed from
<code class="classname">std::hash</code> specializations for C++20.
</p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="api.rel_16"></a><code class="constant">16</code></h3></div></div></div><p>
Deprecated the non-standard overload of <code class="code">std::fabs</code> for
<code class="code">std::complex</code> arguments.
</p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="abi.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="appendix_porting.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="backwards.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ABI Policy and Guidelines </td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top"> Backwards Compatibility</td></tr></table></div></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1117,7 +1117,7 @@ header were added to the static library <filename>libstdc++exp.a</filename>.
<section xml:id="api.rel_141"><info><title><constant>14</constant></title></info>
<para>
Deprecate the non-standard overload that allows <code>std::setfill</code>
Deprecated the non-standard overload that allows <code>std::setfill</code>
to be used with <code>std::basic_istream</code>.
</para>
@@ -1152,4 +1152,11 @@ Nested <code>result_type</code> and <code>argument_type</code> removed from
</section>
<section xml:id="api.rel_16"><info><title><constant>16</constant></title></info>
<para>
Deprecated the non-standard overload of <code>std::fabs</code> for
<code>std::complex</code> arguments.
</para>
</section>
</section>

View File

@@ -969,7 +969,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
// 26.2.7/4: arg(__z): Returns the phase angle of __z.
// C++11 26.4.7 [complex.value.ops]/4: arg(z): Returns the phase angle of z.
template<typename _Tp>
inline _Tp
__complex_arg(const complex<_Tp>& __z)
@@ -2123,8 +2123,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp> std::complex<_Tp> acosh(const std::complex<_Tp>&);
template<typename _Tp> std::complex<_Tp> asinh(const std::complex<_Tp>&);
template<typename _Tp> std::complex<_Tp> atanh(const std::complex<_Tp>&);
// DR 595.
template<typename _Tp> _Tp fabs(const std::complex<_Tp>&);
template<typename _Tp>
inline std::complex<_Tp>
@@ -2309,7 +2307,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
acos(const std::complex<_Tp>& __z)
{ return __complex_acos(__z.__rep()); }
#else
/// acos(__z) [8.1.2].
/// acos(__z) C++11 26.4.8 [complex.transcendentals]
// Effects: Behaves the same as C99 function cacos, defined
// in subclause 7.3.5.1.
template<typename _Tp>
@@ -2345,7 +2343,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
asin(const std::complex<_Tp>& __z)
{ return __complex_asin(__z.__rep()); }
#else
/// asin(__z) [8.1.3].
/// asin(__z) C++11 26.4.8 [complex.transcendentals]
// Effects: Behaves the same as C99 function casin, defined
// in subclause 7.3.5.2.
template<typename _Tp>
@@ -2389,7 +2387,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
atan(const std::complex<_Tp>& __z)
{ return __complex_atan(__z.__rep()); }
#else
/// atan(__z) [8.1.4].
/// atan(__z) C++11 26.4.8 [complex.transcendentals]
// Effects: Behaves the same as C99 function catan, defined
// in subclause 7.3.5.3.
template<typename _Tp>
@@ -2425,7 +2423,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
acosh(const std::complex<_Tp>& __z)
{ return __complex_acosh(__z.__rep()); }
#else
/// acosh(__z) [8.1.5].
/// acosh(__z) C++11 26.4.8 [complex.transcendentals]
// Effects: Behaves the same as C99 function cacosh, defined
// in subclause 7.3.6.1.
template<typename _Tp>
@@ -2464,7 +2462,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
asinh(const std::complex<_Tp>& __z)
{ return __complex_asinh(__z.__rep()); }
#else
/// asinh(__z) [8.1.6].
/// asinh(__z) C++11 26.4.8 [complex.transcendentals]
// Effects: Behaves the same as C99 function casin, defined
// in subclause 7.3.6.2.
template<typename _Tp>
@@ -2508,7 +2506,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
atanh(const std::complex<_Tp>& __z)
{ return __complex_atanh(__z.__rep()); }
#else
/// atanh(__z) [8.1.7].
/// atanh(__z) C++11 26.4.8 [complex.transcendentals]
// Effects: Behaves the same as C99 function catanh, defined
// in subclause 7.3.6.3.
template<typename _Tp>
@@ -2518,14 +2516,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif
template<typename _Tp>
_GLIBCXX11_DEPRECATED_SUGGEST("std::abs")
inline _Tp
/// fabs(__z) [8.1.8].
/// fabs(__z) TR1 8.1.8 [tr.c99.cmplx.fabs]
// Effects: Behaves the same as C99 function cabs, defined
// in subclause 7.3.8.1.
fabs(const std::complex<_Tp>& __z)
{ return std::abs(__z); }
/// Additional overloads [8.1.9].
// Additional overloads C++11 26.4.9 [cmplx.over]
template<typename _Tp>
inline typename __gnu_cxx::__promote<_Tp>::__type
arg(_Tp __x)

View File

@@ -0,0 +1,13 @@
// { dg-do compile }
// Bug 120235 std::fabs(const std::complex<T>&) should not be defined
#include <complex>
void test_pr120235(std::complex<double> c)
{
(void) std::fabs(c);
// { dg-error "no matching function" "" { target c++98_only } 8 }
// { dg-warning "deprecated: use 'std::abs'" "" { target c++11 } 8 }
}
// { dg-prune-output "no type named '__type'" }