public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95407] New: G++ allows access to base class members from a friend of a derived class
@ 2020-05-29 9:12 dragondreamer at live dot com
2020-06-04 9:45 ` [Bug c++/95407] [DR 1873] " redi at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: dragondreamer at live dot com @ 2020-05-29 9:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95407
Bug ID: 95407
Summary: G++ allows access to base class members from a friend
of a derived class
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: dragondreamer at live dot com
Target Milestone: ---
G++ (at least trunk, 10.1.0, 9.3, 9.2) successfully compiles the following
code:
// ===================================
#include <iostream>
struct test_base
{
protected:
static constexpr int value = 123;
};
template<typename Base>
struct ignored_friend_declaration
{
static void bug()
{
std::cout << Base::value;
}
};
struct test_child : test_base
{
using ignored_friend_declaration_t = ignored_friend_declaration<test_base>;
friend ignored_friend_declaration_t;
static void test()
{
ignored_friend_declaration_t::bug();
}
};
int main()
{
test_child::test();
}
// ===================================
According to http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1873,
access to Base::value should be disallowed. Clang produces the following error
message: <source>:14:28: error: 'value' is a protected member of 'test_base'.
See also https://bugs.llvm.org/show_bug.cgi?id=46036
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/95407] [DR 1873] G++ allows access to base class members from a friend of a derived class
2020-05-29 9:12 [Bug c++/95407] New: G++ allows access to base class members from a friend of a derived class dragondreamer at live dot com
@ 2020-06-04 9:45 ` redi at gcc dot gnu.org
2020-08-14 16:53 ` arthur.j.odwyer at gmail dot com
2021-08-27 0:01 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-04 9:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95407
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|G++ allows access to base |[DR 1873] G++ allows access
|class members from a friend |to base class members from
|of a derived class |a friend of a derived class
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2020-06-04
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/95407] [DR 1873] G++ allows access to base class members from a friend of a derived class
2020-05-29 9:12 [Bug c++/95407] New: G++ allows access to base class members from a friend of a derived class dragondreamer at live dot com
2020-06-04 9:45 ` [Bug c++/95407] [DR 1873] " redi at gcc dot gnu.org
@ 2020-08-14 16:53 ` arthur.j.odwyer at gmail dot com
2021-08-27 0:01 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: arthur.j.odwyer at gmail dot com @ 2020-08-14 16:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95407
Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |arthur.j.odwyer at gmail dot com
--- Comment #1 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
According to Richard's comment on https://bugs.llvm.org/show_bug.cgi?id=46036 ,
http://cwg-issue-browser.herokuapp.com/cwg1873 indicates that Clang may be
correct according to the Standard as written. HOWEVER...
The "misbehavior" here isn't really about `friend`; it's about the interaction
between `static` and `protected`. If you change your test case to make `value`
non-static, then all vendors agree that the non-static `value` is inaccessible.
With a static protected member (Clang rejects, GCC and MSVC accept):
https://godbolt.org/z/essofs
With a non-static protected member (all three correctly reject):
https://godbolt.org/z/T1GWTP
And here's a test case that doesn't use `friend` at all, but rather uses a
private inheritance path, so that `C` is derived from `A`, but `C` itself is
not aware of the fact. This case came up on Slack on 2020-08-14:
https://cpplang.slack.com/archives/C5GN4SP41/p1597391677014800
With a static protected member (GCC and Clang accept, MSVC rejects):
https://godbolt.org/z/6d786M
With a non-static protected member (all three correctly reject):
https://godbolt.org/z/MeTxeW
// https://godbolt.org/z/6d786M
struct A {
protected:
static int sf();
};
struct B : private A {};
struct C : public B {
static void test();
};
void C::test() { &::A::sf; }
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/95407] [DR 1873] G++ allows access to base class members from a friend of a derived class
2020-05-29 9:12 [Bug c++/95407] New: G++ allows access to base class members from a friend of a derived class dragondreamer at live dot com
2020-06-04 9:45 ` [Bug c++/95407] [DR 1873] " redi at gcc dot gnu.org
2020-08-14 16:53 ` arthur.j.odwyer at gmail dot com
@ 2021-08-27 0:01 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-27 0:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95407
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think PR 67943 is also related. But then DR 472 is also related to that one.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-08-27 0:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29 9:12 [Bug c++/95407] New: G++ allows access to base class members from a friend of a derived class dragondreamer at live dot com
2020-06-04 9:45 ` [Bug c++/95407] [DR 1873] " redi at gcc dot gnu.org
2020-08-14 16:53 ` arthur.j.odwyer at gmail dot com
2021-08-27 0:01 ` pinskia at gcc dot gnu.org
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).