[llvm-bugs] [Bug 49472] New: "friend Foo< args >; " sometimes gives friendship to other template instances

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Mar 8 04:21:28 PST 2021


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

            Bug ID: 49472
           Summary: "friend Foo< args >;" sometimes gives friendship to
                    other template instances
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jchl at arista.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

Given the following program [https://godbolt.org/z/c9Y895]:

  #include <type_traits>

  template< bool isFriend >
  class Tester {
   public:
     template< typename T, typename = void >
     struct IsAccessible : public std::false_type {};

     template< typename T >
     struct IsAccessible< T, decltype( std::declval< T >().f() ) > : public
std::true_type {};
  };

  class Foo {
     friend Tester< true >;
     void f() const;
  };

  static_assert( !Tester< false >::IsAccessible< Foo >::value );
  static_assert( Tester< true >::IsAccessible< Foo >::value );

the first static_assert fails (with clang trunk), even though Tester< false >
isn't a friend of Foo, and therefore the partial specialization of IsAccessible
shouldn't be used for Tester< false >::IsAccessible< Foo >.

Note that this program works correctly in g++ (trunk), MSVC and ICC.

-- 
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/20210308/a594eb0c/attachment.html>


More information about the llvm-bugs mailing list