[LLVMbugs] [Bug 16449] New: Template functions see friendship as inherited

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jun 25 11:33:28 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16449

            Bug ID: 16449
           Summary: Template functions see friendship as inherited
           Product: clang
           Version: 3.3
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: w.shane.grant at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Template functions that are friends of a class bypass access control for
derived classes.

----------

template <class T> T&& declval();

template <class T>
auto foo() -> decltype(declval<T&>().bar()) {}

class Base
{
  private:
    template <class T>
    friend auto foo() -> decltype(declval<T&>().bar());

    void bar(){}
};

class Derived : public Base {};

int main()
{
  foo<Derived>();
}

-----------

bar should be private in Derived but the friend declaration in Base is allowing
foo to access it, preventing compilation from failing.  Here's another very
similar example:

---------

template <class T>
void foo(T&&t)
{
  t.bar();
}

class Base
{
  private:
    template <class T>
    friend void foo(T&&);

    void bar(){}
};

class Derived : public Base {};

int main()
{
  foo(Derived());
}

--------

Derived gets the ability to call bar() only inside of the template function
foo.

Tested on clang version 3.3 (trunk 178896) (llvm/trunk 178895) and clang
version 3.4 (trunk 184863).

-- 
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/20130625/4852e3cf/attachment.html>


More information about the llvm-bugs mailing list