<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 - Cast a pointer-to-member template argument. MSVC/GCC will. Clang won't."
   href="https://bugs.llvm.org/show_bug.cgi?id=33708">33708</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Cast a pointer-to-member template argument. MSVC/GCC will. Clang won't.
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>mick.pearson@wildblue.net
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I have some ostensibly C++98 code that because of circular dependencies needs
to cast a pointer-to-member of a class to a pointer-to-char of the same class.

I looked into this, and this is considered a reversible operation and
pointer-to-members are understood to be constants. I've used older versions of
GCC and Visual Studio to do this in template arguments.

I am unsure if casting in a template argument is strictly C++98 at all or not.

However it seems as if this might just be an obscure feature that's yet to be
requested of Clang. I assume Clang will perform this cast in a regular context.
But I did not try.

The C++ standard says pointer-to-member casts only work if the new member type
is of an alignment that is less than the type/member being casted. Of course
the cast can also go in the other direction, but it's undefined-behavior if it
was not previously casted to a lesser-alignment type and then back again.

P.S. My code is using this to assign constants belonging to children in
generated code that creates a representation of an XML schema that is very
close to C++ so that operations are strongly typed and strings are not used to
represent names of elements inside of algorithms that can see the generated
headers. The pointer-to-member constants are actually a pointer to the child
itself (every child has a unique template instantiation) and so the set up is
not something that could ever be done by hand, but this allows the child to
find the parent/container without storing a pointer or offset nor other
workaround. It's an integral feature without which Clang can't be a target
compiler. (XML attributes are the same.)

P.P.S. There is a great complication that the pointer-to-member can't refer to
the member itself. That is gotten around by defining layouts that are
identical. The pointers themselves must be converted to offsets from a
reference pointer (e.g. nullptr) and then negated to access the containers.</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>