<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 - declaring a template instance as friend makes all instances of the template as friend"
   href="https://bugs.llvm.org/show_bug.cgi?id=40321">40321</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>declaring a template instance as friend makes all instances of the template as friend
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>7.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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>sw6ueyz@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=21329" name="attach_21329" title="the code">attachment 21329</a> <a href="attachment.cgi?id=21329&action=edit" title="the code">[details]</a></span>
the code

// this code should compile
// because 'Sub' declares only 'Wrapper< Good >' as friend.

template< class ... >
using Void_t = void;

template< class Key >
struct Wrapper
{
        template< class To, class From, class Void = void >
        struct IsCastable
        { static constexpr bool value = false; };

        template< class To, class From >
        struct IsCastable<
                To, From, Void_t< decltype( static_cast< To >( From{} ) ) >
        >
        { static constexpr bool value = true; };
};

struct Good {};

struct Bad {};

struct Base {};

struct Sub : private Base
{
        friend struct Wrapper< Good >;   // Wrapper< Good > is the only friend
};

int main()
{
        // friendly access : should be true
        static_assert(
                Wrapper< Good >::IsCastable< Base*, Sub* >::value );

        // non-friendly access : should be false
        static_assert(
                !Wrapper< Bad >::IsCastable< Base*, Sub* >::value );

        return 0;
}</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>