public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57713] New: Template functions see friendship as inherited
@ 2013-06-25 18:07 w.shane.grant at gmail dot com
2013-06-25 20:23 ` [Bug c++/57713] " w.shane.grant at gmail dot com
0 siblings, 1 reply; 2+ messages in thread
From: w.shane.grant at gmail dot com @ 2013-06-25 18:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57713
Bug ID: 57713
Summary: Template functions see friendship as inherited
Product: gcc
Version: 4.8.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: w.shane.grant at gmail dot com
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.
Happens on (4.9.0 20130625 (experimental)) and (4.8.1).
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/57713] Template functions see friendship as inherited
2013-06-25 18:07 [Bug c++/57713] New: Template functions see friendship as inherited w.shane.grant at gmail dot com
@ 2013-06-25 20:23 ` w.shane.grant at gmail dot com
0 siblings, 0 replies; 2+ messages in thread
From: w.shane.grant at gmail dot com @ 2013-06-25 20:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57713
Shane <w.shane.grant at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Shane <w.shane.grant at gmail dot com> ---
Marking invalid since I think this was actually a case of not interpreting
friendship correctly. A simpler test case:
class Base {
private:
friend void foo();
void bar();
};
class Derived : public Base {};
void foo() { Derived().bar(); }
also compiles with no error because has access to Base (due to friendship) and
thus access to bar.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-06-25 20:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-25 18:07 [Bug c++/57713] New: Template functions see friendship as inherited w.shane.grant at gmail dot com
2013-06-25 20:23 ` [Bug c++/57713] " w.shane.grant at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).