public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59144] New: weird behavior when dealing with too complicated templates and class hierarchy
@ 2013-11-15  7:25 tmmikolajczyk at gmail dot com
  2013-11-15 10:32 ` [Bug c++/59144] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: tmmikolajczyk at gmail dot com @ 2013-11-15  7:25 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59144
           Summary: weird behavior when dealing with too complicated
                    templates and class hierarchy
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tmmikolajczyk at gmail dot com

gcc 4.8.2
linux x86_64

Please consider the following code:

class Base
{
public:
    virtual ~Base() {}
protected:
    void foo() const {}
};

template<typename T>
class CRTP : protected virtual T {};

template<typename T, typename U>
class X : protected virtual CRTP<U>
{
public:
    virtual void bar(const Base& inst) const
    {
        inst.foo();
    }
};

template<typename T>
class Y: protected virtual CRTP<T> {};

class Z : private Y<Base>, public X<Z, Base> {};

int main(int, char**)
{
    Z z;
    return 0;
}

Both gcc and clang rejects this code complaining that:
$ g++ main.cpp 
main.cpp: In instantiation of 'void X<T, U>::bar(const Base&) const [with T =
Z; U = Base]':
main.cpp:32:1:   required from here
main.cpp:7:10: error: 'void Base::foo() const' is protected
     void foo() const {}
          ^
main.cpp:19:18: error: within this context
         inst.foo();
                  ^

However when making the "X::bar" method non-virtual:

void bar(const Base& inst) const

The compilation passes (on gcc and clang). It's quite weird that the virtualism
of the "X::bar" method has such an impact.

Please also consider the following sligthly modified "X::bar" method:

virtual void bar(const T& inst) const

Gcc silently accepts such code. but clang rejects it:

$ clang++ main.cpp 
main.cpp:19:14: error: 'foo' is a private member of 'Base'
        inst.foo();
             ^
main.cpp:26:7: note: in instantiation of member function 'X<Z, Base>::bar'
requested here
class Z : private Y<Base>, public X<Z, Base> {};
      ^
main.cpp:26:11: note: constrained by private inheritance here
class Z : private Y<Base>, public X<Z, Base> {};
          ^~~~~~~~~~~~~~~
main.cpp:7:10: note: member is declared here
    void foo() const {}
         ^
main.cpp:19:9: error: cannot cast 'const Z' to its private base class 'const
Base'
        inst.foo();
        ^
main.cpp:26:11: note: constrained by private inheritance here
class Z : private Y<Base>, public X<Z, Base> {};
          ^~~~~~~~~~~~~~~
2 errors generated.
$


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

* [Bug c++/59144] weird behavior when dealing with too complicated templates and class hierarchy
  2013-11-15  7:25 [Bug c++/59144] New: weird behavior when dealing with too complicated templates and class hierarchy tmmikolajczyk at gmail dot com
@ 2013-11-15 10:32 ` redi at gcc dot gnu.org
  2013-11-16 16:13 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-11-15 10:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to tmmikolajczyk from comment #0)
> The compilation passes (on gcc and clang). It's quite weird that the
> virtualism of the "X::bar" method has such an impact.

But that doesn't make it a bug.

> Please also consider the following sligthly modified "X::bar" method:
> 
> virtual void bar(const T& inst) const
> 
> Gcc silently accepts such code. but clang rejects it:

That is probably just because GCC has some bugs regarding access checking in
function templates, see PR 59002


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

* [Bug c++/59144] weird behavior when dealing with too complicated templates and class hierarchy
  2013-11-15  7:25 [Bug c++/59144] New: weird behavior when dealing with too complicated templates and class hierarchy tmmikolajczyk at gmail dot com
  2013-11-15 10:32 ` [Bug c++/59144] " redi at gcc dot gnu.org
@ 2013-11-16 16:13 ` redi at gcc dot gnu.org
  2013-11-16 16:46 ` tmmikolajczyk at gmail dot com
  2021-08-04  6:39 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2013-11-16 16:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to tmmikolajczyk from comment #0)
> > The compilation passes (on gcc and clang). It's quite weird that the
> > virtualism of the "X::bar" method has such an impact.
> 
> But that doesn't make it a bug.

The Intel compiler behaves the same.


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

* [Bug c++/59144] weird behavior when dealing with too complicated templates and class hierarchy
  2013-11-15  7:25 [Bug c++/59144] New: weird behavior when dealing with too complicated templates and class hierarchy tmmikolajczyk at gmail dot com
  2013-11-15 10:32 ` [Bug c++/59144] " redi at gcc dot gnu.org
  2013-11-16 16:13 ` redi at gcc dot gnu.org
@ 2013-11-16 16:46 ` tmmikolajczyk at gmail dot com
  2021-08-04  6:39 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: tmmikolajczyk at gmail dot com @ 2013-11-16 16:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from tmmikolajczyk at gmail dot com ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to tmmikolajczyk from comment #0)
> > The compilation passes (on gcc and clang). It's quite weird that the
> > virtualism of the "X::bar" method has such an impact.
> 
> But that doesn't make it a bug.

Why that's not a bug? No matter if the X::bar method is virtual or not it
should not have any impact on access to it from the derived classes in this
case IMHO.


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

* [Bug c++/59144] weird behavior when dealing with too complicated templates and class hierarchy
  2013-11-15  7:25 [Bug c++/59144] New: weird behavior when dealing with too complicated templates and class hierarchy tmmikolajczyk at gmail dot com
                   ` (2 preceding siblings ...)
  2013-11-16 16:46 ` tmmikolajczyk at gmail dot com
@ 2021-08-04  6:39 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04  6:39 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Invalid as explained.
Also note GCC, ICC, MSVC and clang all behave the same.

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-15  7:25 [Bug c++/59144] New: weird behavior when dealing with too complicated templates and class hierarchy tmmikolajczyk at gmail dot com
2013-11-15 10:32 ` [Bug c++/59144] " redi at gcc dot gnu.org
2013-11-16 16:13 ` redi at gcc dot gnu.org
2013-11-16 16:46 ` tmmikolajczyk at gmail dot com
2021-08-04  6:39 ` 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).