<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2380: May &lt;cstdlib&gt; provide long ::abs(long) and long long ::abs(long long)?</title>
<meta property="og:title" content="Issue 2380: May &lt;cstdlib&gt; provide long ::abs(long) and long long ::abs(long long)?">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2380.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++17">C++17</a> status.</em></p>
<h3 id="2380"><a href="lwg-defects.html#2380">2380</a>. May <code>&lt;cstdlib&gt;</code> provide <code>long ::abs(long)</code> and <code>long long ::abs(long long)</code>?</h3>
<p><b>Section:</b> 16.4.2.3 <a href="https://wg21.link/headers">[headers]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2014-03-31 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>2
</p>
<p><b>View all other</b> <a href="lwg-index.html#headers">issues</a> in [headers].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>
<p>
 [depr.c.headers] p3 says:
</p>
<blockquote><p>
[<i>Example</i>: The header <code>&lt;cstdlib&gt;</code> assuredly provides its declarations and definitions within the namespace
<code>std</code>. It may also provide these names within the global namespace. The header <code>&lt;stdlib.h&gt;</code> assuredly
provides the same declarations and definitions within the global namespace, much as in the C Standard. It
may also provide these names within the namespace <code>std</code>. &mdash; <i>end example</i>]
</p></blockquote>
<p>
This suggests that <code>&lt;cstdlib&gt;</code> may provide <code>::abs(long)</code> and <code>::abs(long long)</code>. But this seems like 
it might contradict the normative wording of 16.4.2.3 <a href="https://wg21.link/headers">[headers]</a> p4:
</p>
<blockquote><p>
Except as noted in Clauses 18 through 30 and Annex D, the contents of each header <code>c<em>name</em></code> shall be the same
as that of the corresponding header <code><em>name</em>.h</code>, as specified in the C standard library (1.2) or the C Unicode
TR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except for
names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace <code>std</code>. It is
unspecified whether these names are first declared within the global namespace scope and are then injected
into namespace <code>std</code> by explicit using-declarations (7.3.3).
</p></blockquote>
<p>
Note that this allows <code>&lt;cstdlib&gt;</code> to provide <code>::abs(int)</code>, but does not obviously allow <code>::abs(long)</code> 
nor <code>::abs(long long)</code>, since they are not part of the header <code>stdlib.h</code> as specified in the C standard library.
<p/>
29.7 <a href="https://wg21.link/c.math">[c.math]</a> p7 adds signatures <code>std::abs(long)</code> and <code>std::abs(long long)</code>, but not in a way that seems 
to allow <code>::abs(long)</code> and <code>::abs(long long)</code> to be provided.
<p/>
I think the right approach here would be to allow <code>&lt;cstdlib&gt;</code> to either provide no <code>::abs</code> declaration, or 
to provide all three declarations from namespace <code>std</code>, but it should not be permitted to provide only <code>int abs(int)</code>. 
Suggestion:
<p/>
Change in 16.4.2.3 <a href="https://wg21.link/headers">[headers]</a> p4:
</p>
<blockquote><p>
[&hellip;]. It is unspecified whether these names <ins>(including any overloads added in Clauses 18 through 30 and Annex D)</ins> 
are first declared within the global namespace scope and are then injected into namespace <code>std</code> by explicit using-declarations 
(7.3.3).
</p></blockquote>

<p><i>[2015-05, Lenexa]</i></p>

<p>
MC: do we need to defer this?<br/>
PJP: just need to get my mind around it, already playing dirty games here, my reaction is just do it as it will help C++<br/>
STL: this is safe<br/>
TP: would be surprising if using abs didn't bring in all of the overloads<br/>
MC: that's Richard's argument<br/>
MC: move to ready 
</p>



<p id="res-2380"><b>Proposed resolution:</b></p>
<p>This wording is relative to N3936.</p>

<ol>
<li><p>Modify 16.4.2.3 <a href="https://wg21.link/headers">[headers]</a> p4 as indicated:</p>

<blockquote><p>
Except as noted in Clauses 18 through 30 and Annex D, the contents of each header <code>c<em>name</em></code> shall be the same
as that of the corresponding header <code><em>name</em>.h</code>, as specified in the C standard library (1.2) or the C Unicode
TR, as appropriate, as if by inclusion. In the C++ standard library, however, the declarations (except for
names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace <code>std</code>. It is
unspecified whether these names <ins>(including any overloads added in Clauses 18 through 30 and Annex D)</ins> are first 
declared within the global namespace scope and are then injected into namespace <code>std</code> by explicit using-declarations (7.3.3).
</p></blockquote>
</li>
</ol>






</body>
</html>
