public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
@ 2013-05-16 12:49 ` paolo.carlini at oracle dot com
  2013-05-16 13:00 ` paolo.carlini at oracle dot com
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-16 12:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|gcc-bugs at gcc dot gnu.org        |

--- Comment #13 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I may be missing details, but I'm not sure we have a serious problem here. Note
that:

class   A {
public:
        A(){}
        };
class B : virtual A {
    };
class C : public B {};
int main () {
    C c;
    }

is fine. Thus, to be clear, isn't that the "declared access" doesn't matter.
The real issue seems that the complete rules of protected access are complex
and hard to, so to speak, summarize in the error message. Gaby?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
  2013-05-16 12:49 ` [Bug c++/17314] Error message wrongly shows declared rather than inherited access paolo.carlini at oracle dot com
@ 2013-05-16 13:00 ` paolo.carlini at oracle dot com
  2013-05-16 14:07 ` jason at gcc dot gnu.org
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-16 13:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #14 from Paolo Carlini <paolo.carlini at oracle dot com> ---
If I understand correctly the issue, saying in enforce_access something like
"A::A(), declared protected, is inaccessible within this context" instead of
"A::A() is protected within this context" would be less confusing.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
  2013-05-16 12:49 ` [Bug c++/17314] Error message wrongly shows declared rather than inherited access paolo.carlini at oracle dot com
  2013-05-16 13:00 ` paolo.carlini at oracle dot com
@ 2013-05-16 14:07 ` jason at gcc dot gnu.org
  2013-05-16 14:52 ` paolo.carlini at oracle dot com
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2013-05-16 14:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

--- Comment #15 from Jason Merrill <jason at gcc dot gnu.org> ---
Yes, that would be an improvement to the diagnostic.  But it seems to me that
there's a deeper issue here: I think both testcases should be ill-formed
because C::C can't form a pointer to its A base in order to try to call its
constructor.  Just as in this testcase:

class A {
protected:
  void g();
};
class B : virtual A { };
class C : public B {
  void f() { ::A::g(); }
};
int main () {
  C c;
}

Here if we could convert 'this' to an A*, we would be OK.  Now, the magic
conversion for vbase construction is special, and the standard doesn't really
say how special; if it has special access (to go along with its special ability
to choose a specific subobject in a hierarchy that might have multiple bases of
the same type), the original testcase should be ok: we're calling a protected
member through a C object, which is fine by the rules for protected access.  If
the constructor doesn't have special access, then it's ill-formed even if the
constructor is public.

I think a core issue is warranted.  But for the mean time, making that change
to the diagnostic would be an improvement.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2013-05-16 14:07 ` jason at gcc dot gnu.org
@ 2013-05-16 14:52 ` paolo.carlini at oracle dot com
  2013-05-16 20:09 ` jason at gcc dot gnu.org
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-16 14:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

--- Comment #16 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I see, thanks Jason. Indeed, the behavior of various compilers I have here is
inconsistent about the various variants of the testcase.

Thus for now I'm going to test the diagnostic tweak with the plan of committing
something and then immediately suspending the PR. If/when you have a DR # we
can point to it in the Subject.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2013-05-16 14:52 ` paolo.carlini at oracle dot com
@ 2013-05-16 20:09 ` jason at gcc dot gnu.org
  2013-05-16 23:49 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu.org @ 2013-05-16 20:09 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

--- Comment #18 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Jason Merrill from comment #17)
> It would be good to get the same diagnostic as in comment #4.

And also give a warning about the private virtual base.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2013-05-16 20:09 ` jason at gcc dot gnu.org
@ 2013-05-16 23:49 ` paolo.carlini at oracle dot com
  2013-11-07 10:36 ` paolo.carlini at oracle dot com
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-16 23:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

--- Comment #19 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I see, thanks.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2013-05-16 23:49 ` paolo.carlini at oracle dot com
@ 2013-11-07 10:36 ` paolo.carlini at oracle dot com
  2020-04-10 15:22 ` ich.freak at gmx dot net
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-11-07 10:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
           Assignee|gdr at gcc dot gnu.org             |unassigned at gcc dot gnu.org


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2013-11-07 10:36 ` paolo.carlini at oracle dot com
@ 2020-04-10 15:22 ` ich.freak at gmx dot net
  2020-12-29  0:14 ` anthonysharp15 at gmail dot com
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ich.freak at gmx dot net @ 2020-04-10 15:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

Igel <ich.freak at gmx dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ich.freak at gmx dot net

--- Comment #21 from Igel <ich.freak at gmx dot net> ---
Seconded! This bug still exists in 9.2.0. Here's another example:

class Base {  protected: int i; };
class Derived:  public Base    { using Base::i; };
class Derived2: public Derived { using Derived::i; };
int main(){}

> g++ test.cpp -o test
test.cpp:3:7: error: 'int Base::i' is protected within this context
    3 | class Derived2: public Derived { using Derived::i; };
      |       ^~~~~~~~
test.cpp:1:30: note: declared protected here
    1 | class Base {  protected: int i; };
      |                              ^

no mention of line 2 where the actual problem is (namely that i is declared
private (not protected)).

cheers

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2020-04-10 15:22 ` ich.freak at gmx dot net
@ 2020-12-29  0:14 ` anthonysharp15 at gmail dot com
  2021-01-06 13:11 ` anthonysharp15 at gmail dot com
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: anthonysharp15 at gmail dot com @ 2020-12-29  0:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

Anthony Sharp <anthonysharp15 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anthonysharp15 at gmail dot com

--- Comment #22 from Anthony Sharp <anthonysharp15 at gmail dot com> ---
I am currently working on a fix for this.

There seems to be three issues here. 

1. The primary issue is that in cases of private inheritance, GCC incorrectly
reports that the member is inaccessible because it is protected, when the (more
correct) reason is because it is private. This has required some re-working of
the diagnostics code.

2. The second issue (more of a discussion topic) seems to revolve around
whether virtual inheritance is private by default. A few people here have said
that it is. They might be right, but I am not sure.

3. The third issue seems to be an academic debate on the proper effect of a
virtual private inheritance. Currently, it is possible to inherit from a
private virtual base, e.g. the following code compiles:

class Foo { public: Foo(){}  ~Foo(){} };
class A:virtual private Foo { public: A(){}  ~A(){} };
class Bar:public A { public: Bar(){}  ~Bar(){} };

As Jason Merrill points out, this wasn't intended
(http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#7). Also see
https://stackoverflow.com/questions/3900192/msvc9-0-bug-or-misunderstanding-of-virtual-inheritance-and-friends/3917482.
Apparently MSVC9 has the same quirk.

I'm not sure why the C++ standards committee would say it was intended for the
above code to be ill-formed (or that's what they seem to say). There seems to
me to be no access violation in the above code, technically speaking. Jason
Merrill says '~Bar() calls ~Foo(), which is ill-formed due to access violation,
right? (Bar's constructor has the same problem since it needs to call Foo's
constructor.)', but as far as I'm aware, constructors and destructors aren't
affected by access protection levels. It is possible for a class to derive from
a private class (e.g. see
https://stackoverflow.com/questions/30572835/c-private-class-inheritance).
Jason Merrill points out that there might be some under-the-hood issues with
the above code, and he might be right, but that's beyond my current level of
understanding.

Even if such code is ill-formed, it doesn't really bother me (and nor has it
bothered anyone else, considering this bug report was issued 16 years ago).
Virtual private inheritance is a feature that virtually (haha, get it?) no one
uses, and I think it'd be a waste of time to patch a dead feature. So, I intend
to only fix issue 1. After that, I might create a new bug report to do with 3.,
just so the issue is not buried.

Any thoughts are welcome.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2020-12-29  0:14 ` anthonysharp15 at gmail dot com
@ 2021-01-06 13:11 ` anthonysharp15 at gmail dot com
  2021-01-06 23:26 ` igodard at pacbell dot net
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: anthonysharp15 at gmail dot com @ 2021-01-06 13:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

--- Comment #23 from Anthony Sharp <anthonysharp15 at gmail dot com> ---
The patch is now on the mailing list
(https://gcc.gnu.org/pipermail/gcc-patches/2021-January/562835.html).

Please take my last comment with a pinch of salt ... I was mainly trying to sum
up what has already been said. There are plenty of people here who have much
more knowledge than I do and if they say that something is the case, it
probably is.

Also just to be clear when I said that no-one uses virtual private inheritance,
that obviously isn't strictly true. What I meant to say was that no one would
realistically use a virtual private inheritance, and then try to derive another
class from it, which is what the problem is.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2021-01-06 13:11 ` anthonysharp15 at gmail dot com
@ 2021-01-06 23:26 ` igodard at pacbell dot net
  2021-01-07  0:57 ` anthonysharp15 at gmail dot com
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: igodard at pacbell dot net @ 2021-01-06 23:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

--- Comment #24 from Ivan Godard <igodard at pacbell dot net> ---
OP here. 

Yes, no one would *intentionally* try to derive from a virtual private. But one
could - and I did - derive a class with. It took no little wild geese chasing
from the diagnostic to find that a virtual private was the real, and
unreported, problem.

So I filed a *UI* and *QOI* ticket. Compilers exist not only to translate
correct code, but also to help with the inevitable incorrect code. After all,
more of the latter gets submitted for compilation.

To say that a code is nonsense and so can be ignored is a disservice to the
community that gcc purports to serve.

In fairness, gcc and its maintainers are much less arrogant these days than
when this ticket was filed. But I notice that bugzilla shows *twenty seven*
tickets filed by me and still open. Every one of those is a dozen years old or
more, because around then I got fed up with the gcc attitude, switched to
clang, and have never been back.

Except for the occasional rant like this.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (10 preceding siblings ...)
  2021-01-06 23:26 ` igodard at pacbell dot net
@ 2021-01-07  0:57 ` anthonysharp15 at gmail dot com
  2021-01-29 12:34 ` anthonysharp15 at gmail dot com
  2021-01-29 13:03 ` redi at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: anthonysharp15 at gmail dot com @ 2021-01-07  0:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

--- Comment #25 from Anthony Sharp <anthonysharp15 at gmail dot com> ---
Hopefully (pending approval) the original bug is now fixed, even if it did take
a long time! I agree that compilers should match the standard where reasonable
to do so (like in this case), but I can't comment much specifically on the
issue of whether deriving from a virtual private inheritance should be
ill-formed (it seems the general consensus is that it should be, although one
can find people debating the opposite on various forums e.g.
https://stackoverflow.com/questions/2371176/c-private-virtual-inheritance-problem).
Although I could probably go and try find out, I think it'd be best to leave
that to those who know a bit more about the topic than me; this is only my
first ever patch submission after all :)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (11 preceding siblings ...)
  2021-01-07  0:57 ` anthonysharp15 at gmail dot com
@ 2021-01-29 12:34 ` anthonysharp15 at gmail dot com
  2021-01-29 13:03 ` redi at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: anthonysharp15 at gmail dot com @ 2021-01-29 12:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

--- Comment #26 from Anthony Sharp <anthonysharp15 at gmail dot com> ---
Fixed. It seems the issue to do with the virtual class constructors is a
duplicate of 55120 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55120).

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
                   ` (12 preceding siblings ...)
  2021-01-29 12:34 ` anthonysharp15 at gmail dot com
@ 2021-01-29 13:03 ` redi at gcc dot gnu.org
  13 siblings, 0 replies; 15+ messages in thread
From: redi at gcc dot gnu.org @ 2021-01-29 13:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |11.0
             Status|NEW                         |RESOLVED

--- Comment #27 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed by r11-6880, thanks!

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Bug c++/17314] Error message wrongly shows declared rather than inherited access
       [not found] <bug-17314-6594@http.gcc.gnu.org/bugzilla/>
@ 2006-03-21  2:48 ` jason at gcc dot gnu dot org
  0 siblings, 0 replies; 15+ messages in thread
From: jason at gcc dot gnu dot org @ 2006-03-21  2:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from jason at gcc dot gnu dot org  2006-03-21 02:48 -------
tweak summary


-- 

jason at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Error message wrongly shows |Error message wrongly shows
                   |declared rather than        |declared rather than
                   |inherited visibility        |inherited access


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17314


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-01-29 13:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-17314-4@http.gcc.gnu.org/bugzilla/>
2013-05-16 12:49 ` [Bug c++/17314] Error message wrongly shows declared rather than inherited access paolo.carlini at oracle dot com
2013-05-16 13:00 ` paolo.carlini at oracle dot com
2013-05-16 14:07 ` jason at gcc dot gnu.org
2013-05-16 14:52 ` paolo.carlini at oracle dot com
2013-05-16 20:09 ` jason at gcc dot gnu.org
2013-05-16 23:49 ` paolo.carlini at oracle dot com
2013-11-07 10:36 ` paolo.carlini at oracle dot com
2020-04-10 15:22 ` ich.freak at gmx dot net
2020-12-29  0:14 ` anthonysharp15 at gmail dot com
2021-01-06 13:11 ` anthonysharp15 at gmail dot com
2021-01-06 23:26 ` igodard at pacbell dot net
2021-01-07  0:57 ` anthonysharp15 at gmail dot com
2021-01-29 12:34 ` anthonysharp15 at gmail dot com
2021-01-29 13:03 ` redi at gcc dot gnu.org
     [not found] <bug-17314-6594@http.gcc.gnu.org/bugzilla/>
2006-03-21  2:48 ` jason at gcc dot gnu dot 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).