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: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs