[llvm-bugs] [Bug 34033] New: Access control accepts-invalid: friend function definitions aren't a member of their enclosing class

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 2 08:53:53 PDT 2017


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

            Bug ID: 34033
           Summary: Access control accepts-invalid: friend function
                    definitions aren't a member of their enclosing class
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dgregor at apple.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Clang incorrectly accepts this invalid C++:

class Y {
  template<typename T> friend class X;

  template<typename U>
  static bool equals(U const&, U const&) { return true; }
};

template<typename T>
class X {
 public:
  friend bool operator ==(X const& lhs, X const& rhs) {
    return Y::equals(lhs, rhs);
  }
};

void test(X<int> x) {
  if (x == x) { }
}

"operator ==" should not be allowed to access Y::equals(), because a friend
function definition is not a member of the class. GCC and EDG properly diagnose
this ill-formed code.

-- 
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/20170802/e8e50100/attachment.html>


More information about the llvm-bugs mailing list