<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - pointer_traits for __wrap_iter types sometimes produces nonsense"
   href="https://bugs.llvm.org/show_bug.cgi?id=32006">32006</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>pointer_traits for __wrap_iter types sometimes produces nonsense
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>4.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arthur.j.odwyer@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is more of an enhancement request than a bug, I think, because I don't see
anywhere that the Standard actually specifies what counts as a "pointer-like
type". However, here's the problem:

In general, it is true (by accident, not by specification) that

    pointer_traits<T>::element_type ==
remove_reference_t<decltype(*declval<T>())>

But when you set T == std::vector<int>::iterator, you find that

    pointer_traits<T>::element_type == T::pointer_type

instead.
<a href="http://melpon.org/wandbox/permlink/pscCG6PVumWexxeN">http://melpon.org/wandbox/permlink/pscCG6PVumWexxeN</a>

This is because for any type of the form X<Y>, the standard mandates that
pointer_traits<X<Y>>::element_type == Y. So when you feed in
std::vector<int>::iterator a.k.a. __wrap_iter<int*>, element_type comes out as
(int*).

Additionally, this nerfs the libc++ extension function "__to_raw_pointer" for
contiguous iterators.
    int *p = std::__to_raw_pointer(myvector.end());
does not compile.
<a href="http://melpon.org/wandbox/permlink/LL61wlsNYdEtQX1X">http://melpon.org/wandbox/permlink/LL61wlsNYdEtQX1X</a>

This could be resolved by
- closing as NOTABUG since iterator types are not "pointer-like"; or
- adding an element_type typedef to libc++'s __wrap_iter; or
- adding a partial specialization for pointer_traits<__wrap_iter<Y>>.

The discussion that led to this "discovery" was
<a href="https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/PBETQcQHB-0">https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/PBETQcQHB-0</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>