<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2709: offsetof is unnecessarily imprecise</title>
<meta property="og:title" content="Issue 2709: offsetof is unnecessarily imprecise">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2709.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="2709"><a href="lwg-defects.html#2709">2709</a>. <code>offsetof</code> is unnecessarily imprecise</h3>
<p><b>Section:</b> 17.2 <a href="https://wg21.link/support.types">[support.types]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2016-05-10 <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#support.types">issues</a> in [support.types].</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>
Per 17.2 <a href="https://wg21.link/support.types">[support.types]</a>/4:
</p>
<blockquote><p>
"The macro <code>offsetof(<i>type</i>, <i>member-designator</i>)</code> accepts a restricted set of <i>type</i> arguments 
in this International Standard. If <i>type</i> is not a standard-layout class (Clause 9), the results are undefined. [...]"
</p></blockquote>
<p>
Implementations in practice interpret this as meaning that the program is ill-formed for classes that are not 
standard-layout, but several implementations allow additional types as an extension (rejected in their "strictly conforming" 
modes).
<p/>
It would seem superior to specify that implementation-defined extensions are permitted, and that the implementation 
must give a correct answer for any type that it chooses to accept.
</p>

<p><i>[2016-05 Issues Telecon]</i></p>

<p>
People were worried about the requirement to report errors implied by 'conditionally supported'.
</p>

<p><i>[2016-06 Oulu]</i></p>

<p>The concern about errors appears to be less severe that we thought. Moving to Ready.</p>
<p>Friday: status to Immediate</p>


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

<ol>
<li><p>Change in 17.2 <a href="https://wg21.link/support.types">[support.types]</a>/4:</p>

<blockquote>
<p>
-4- The macro <code>offsetof(<i>type</i>, <i>member-designator</i>)</code> accepts a restricted set of <i>type</i> arguments 
in this International Standard. <del>If <code><i>type</i></code> is not</del><ins>Use of the <code>offsetof</code> macro with a 
<code><i>type</i></code> other than</ins> a standard-layout class (Clause 9)<del>, the results are 
undefined</del><ins>is conditionally-supported</ins>.193 The expression <code>offsetof(<i>type</i>, 
<i>member-designator</i>)</code> is never type-dependent (14.6.2.2) and it is value-dependent (14.6.2.3) if and only 
if <code><i>type</i></code> is dependent. The result of applying the <code>offsetof</code> macro to a static data member or 
a function member is undefined. No operation invoked by the <code>offsetof</code> macro shall throw an exception and 
<code>noexcept(offsetof(type, member-designator))</code> shall be <code>true</code>.
</p>
</blockquote>
</li>
</ol>





</body>
</html>
