public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class
@ 2013-08-01  6:51 gcc at mattwhitlock dot name
  2013-08-01  7:43 ` [Bug c++/58040] " daniel.kruegler at googlemail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gcc at mattwhitlock dot name @ 2013-08-01  6:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58040
           Summary: Cannot take address-of public using-declaration of
                    member from protected base class
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc at mattwhitlock dot name

$ cat <<EOF > test.cpp
struct Base {
    void foo() { }
    void bar() { }
};

struct Derived : protected Base {
    void foo() { this->Base::foo(); }
    using Base::bar;
};

int main() {
    Derived d;
    d.foo(); // OK
    d.bar(); // OK
    d.Derived::foo(); // OK
    d.Derived::bar(); // OK
    (d.*&Derived::foo)(); // OK
    (d.*&Derived::bar)(); // error
}
EOF

$ g++-4.7.3 --version | head -n1
g++ (Gentoo 4.7.3 p1.0, pie-0.5.5) 4.7.3

$ g++-4.7.3 test.cpp
test.cpp: In function 'int main()':
test.cpp:18:19: error: 'Base' is an inaccessible base of 'Derived'

$ g++-4.8.1 --version | head -n1
g++-4.8.1 (Gentoo 4.8.1 p1.0, pie-0.5.6) 4.8.1

$ g++-4.8.1 test.cpp
test.cpp: In function 'int main()':
test.cpp:18:19: error: 'Base' is an inaccessible base of 'Derived'
     (d.*&Derived::bar)(); // error
                   ^


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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
@ 2013-08-01  7:43 ` daniel.kruegler at googlemail dot com
  2013-08-01  9:27 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-08-01  7:43 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
The same problem occurs for gcc 4.9.0 20130616 (experimental)
>From gcc-bugs-return-427084-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Aug 01 08:32:48 2013
Return-Path: <gcc-bugs-return-427084-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 4581 invoked by alias); 1 Aug 2013 08:32:47 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 4492 invoked by uid 48); 1 Aug 2013 08:32:44 -0000
From: "bernd.edlinger at hotmail dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/58041] Unaligned access to arrays in packed structure
Date: Thu, 01 Aug 2013 08:32:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: bernd.edlinger at hotmail dot de
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-58041-4-F9Mrkh7lUM@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58041-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58041-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-08/txt/msg00008.txt.bz2
Content-length: 245

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX041

--- Comment #2 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
Sandra,

this seems to be unrelated to your strict-volatile-bitfields patch,
as it happens with or without that patch.


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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
  2013-08-01  7:43 ` [Bug c++/58040] " daniel.kruegler at googlemail dot com
@ 2013-08-01  9:27 ` paolo.carlini at oracle dot com
  2013-08-02  8:35 ` fabien at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-01  9:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Fabien, are you interested in this?


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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
  2013-08-01  7:43 ` [Bug c++/58040] " daniel.kruegler at googlemail dot com
  2013-08-01  9:27 ` paolo.carlini at oracle dot com
@ 2013-08-02  8:35 ` fabien at gcc dot gnu.org
  2013-08-02  8:46 ` paolo.carlini at oracle dot com
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: fabien at gcc dot gnu.org @ 2013-08-02  8:35 UTC (permalink / raw)
  To: gcc-bugs

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

fabien at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2013-08-02
           Assignee|unassigned at gcc dot gnu.org      |fabien at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #3 from fabien at gcc dot gnu.org ---
(In reply to Paolo Carlini from comment #2)
> Fabien, are you interested in this?

Yes, let's put it on my TODO list. Might be related to PR c++/19377.


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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
                   ` (2 preceding siblings ...)
  2013-08-02  8:35 ` fabien at gcc dot gnu.org
@ 2013-08-02  8:46 ` paolo.carlini at oracle dot com
  2021-07-23 20:45 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-02  8:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Thanks!


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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
                   ` (3 preceding siblings ...)
  2013-08-02  8:46 ` paolo.carlini at oracle dot com
@ 2021-07-23 20:45 ` pinskia at gcc dot gnu.org
  2021-08-04  7:35 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-23 20:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
clang fails the same way.

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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
                   ` (4 preceding siblings ...)
  2021-07-23 20:45 ` pinskia at gcc dot gnu.org
@ 2021-08-04  7:35 ` pinskia at gcc dot gnu.org
  2021-08-04 16:13 ` gcc at mattwhitlock dot name
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC, ICC, clang and MSVC all fail the same way.  Are we sure this is valid?

Even this fails:
    void(Derived:: *t)()  = &Derived::bar;

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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
                   ` (5 preceding siblings ...)
  2021-08-04  7:35 ` pinskia at gcc dot gnu.org
@ 2021-08-04 16:13 ` gcc at mattwhitlock dot name
  2021-08-04 16:25 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gcc at mattwhitlock dot name @ 2021-08-04 16:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Matt Whitlock <gcc at mattwhitlock dot name> ---
Maybe this example will demonstrate it more clearly.

/* begin example */

class PublicBase {
public:
        void pub_base_pub_memb();
protected:
        void pub_base_prot_memb();
};

class ProtectedBase {
public:
        void prot_base_pub_memb();
protected:
        void prot_base_prot_memb();
};

class Derived : public PublicBase, protected ProtectedBase {
public:
        using PublicBase::pub_base_pub_memb;
        using PublicBase::pub_base_prot_memb;
        using ProtectedBase::prot_base_pub_memb;
        using ProtectedBase::prot_base_prot_memb;
};

void (Derived::*pub_base_pub_memb)() = &Derived::pub_base_pub_memb;
void (Derived::*pub_base_prot_memb)() = &Derived::pub_base_prot_memb;
void (Derived::*prot_base_pub_memb)() = &Derived::prot_base_pub_memb; // ERROR
void (Derived::*prot_base_prot_memb)() = &Derived::prot_base_prot_memb; //
ERROR

void func(Derived *d) {
        d->Derived::pub_base_pub_memb();
        d->Derived::pub_base_prot_memb();
        d->Derived::prot_base_pub_memb(); // OK
        d->Derived::prot_base_prot_memb(); // OK

        auto pub_base_pub_memb = &Derived::pub_base_pub_memb;
        auto pub_base_prot_memb = &Derived::pub_base_prot_memb;
        auto prot_base_pub_memb = &Derived::prot_base_pub_memb; // OK
        auto prot_base_prot_memb = &Derived::prot_base_prot_memb; // OK

        (d->*pub_base_pub_memb)();
        (d->*pub_base_prot_memb)();
        (d->*prot_base_pub_memb)(); // ERROR
        (d->*prot_base_prot_memb)(); // ERROR
}

/* end example */

As you can see, it is possible to call all four member functions directly using
their qualified names, but it is not possible to assign the addresses of the
members from the protected base into variables whose type is pointer to member
function of the derived class, nor is it possible to call the members of the
protected base indirectly through pointers to member function of the derived
class.

Maybe this is a defect of the language? It's certainly an asymmetry and a
surprise.

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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
                   ` (6 preceding siblings ...)
  2021-08-04 16:13 ` gcc at mattwhitlock dot name
@ 2021-08-04 16:25 ` redi at gcc dot gnu.org
  2021-08-04 17:38 ` gcc at mattwhitlock dot name
  2021-08-04 18:58 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-04 16:25 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Matt Whitlock from comment #8)
> As you can see, it is possible to call all four member functions directly
> using their qualified names,

Yes, because the /name/ of the function is accessible in Derived, because the
using-declarations delcare them as publicly accessible members of Derived.

> but it is not possible to assign the addresses
> of the members from the protected base into variables whose type is pointer
> to member function of the derived class,

Because that's not the type of the function, and [conv.mem] p2 says you can't
convert them from void (ProtectedBase::*)() to void (Derived::*)() because that
base class is not accessible.

[conv.mem] p2 says:

A prvalue of type “pointer to member of B of type cv T”, where B is a class
type, can be converted to a prvalue of type “pointer to member of D of type cv
T”, where D is a complete class derived (11.7) from B. If B is an inaccessible
(11.8), ambiguous (6.5.2), or virtual (11.7.2) base class of D, or a base class
of a virtual base class of D, a program that necessitates this conversion is
ill-formed.


> nor is it possible to call the
> members of the protected base indirectly through pointers to member function
> of the derived class.

You are not calling them by name here, so the using-declaration isn't relevant.
You are trying to invoke a member of the protect base through the derived type,
which requires converting &d to a ProtectedBase*, which is not an allowed
conversion.

Not a bug, this is how C++ works.

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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
                   ` (7 preceding siblings ...)
  2021-08-04 16:25 ` redi at gcc dot gnu.org
@ 2021-08-04 17:38 ` gcc at mattwhitlock dot name
  2021-08-04 18:58 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: gcc at mattwhitlock dot name @ 2021-08-04 17:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Matt Whitlock <gcc at mattwhitlock dot name> ---
So using declarations are not a direct replacement for user-defined thunks.
Today I learned! This makes using declarations decidedly less useful than I
believed.

Thank you for your time, Jonathan Wakely.

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

* [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class
  2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
                   ` (8 preceding siblings ...)
  2021-08-04 17:38 ` gcc at mattwhitlock dot name
@ 2021-08-04 18:58 ` redi at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2021-08-04 18:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Matt Whitlock from comment #10)
> So using declarations are not a direct replacement for user-defined thunks.

Not even close.

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

end of thread, other threads:[~2021-08-04 18:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-01  6:51 [Bug c++/58040] New: Cannot take address-of public using-declaration of member from protected base class gcc at mattwhitlock dot name
2013-08-01  7:43 ` [Bug c++/58040] " daniel.kruegler at googlemail dot com
2013-08-01  9:27 ` paolo.carlini at oracle dot com
2013-08-02  8:35 ` fabien at gcc dot gnu.org
2013-08-02  8:46 ` paolo.carlini at oracle dot com
2021-07-23 20:45 ` pinskia at gcc dot gnu.org
2021-08-04  7:35 ` pinskia at gcc dot gnu.org
2021-08-04 16:13 ` gcc at mattwhitlock dot name
2021-08-04 16:25 ` redi at gcc dot gnu.org
2021-08-04 17:38 ` gcc at mattwhitlock dot name
2021-08-04 18:58 ` redi 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).