[llvm-bugs] [Bug 40321] New: declaring a template instance as friend makes all instances of the template as friend

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 15 09:01:34 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40321

            Bug ID: 40321
           Summary: declaring a template instance as friend makes all
                    instances of the template as friend
           Product: clang
           Version: 7.0
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sw6ueyz at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Created attachment 21329
  --> https://bugs.llvm.org/attachment.cgi?id=21329&action=edit
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;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190115/81b54d7a/attachment.html>


More information about the llvm-bugs mailing list