public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66698] New: Multiple inheritance from instantiations of template class and what about access to member functions
@ 2015-06-29 20:11 apyszczuk at gmail dot com
  2021-08-04 21:35 ` [Bug c++/66698] " pinskia at gcc dot gnu.org
  2021-08-04 21:36 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: apyszczuk at gmail dot com @ 2015-06-29 20:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66698
           Summary: Multiple inheritance from instantiations of template
                    class and what about access to member functions
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: apyszczuk at gmail dot com
  Target Milestone: ---

Let's take a look at the code:

template <typename C>
class S {
public:
    void add (C c) { ++cnt; }
    size_t size () const { return cnt; }

private:
    size_t cnt {}; 
};

struct Foo1 {};
struct Foo2 {};
struct Foo3 {};

class Z : public S<Foo1>, public S<Foo2>, public S<Foo3> {
public:
    using S<Foo1>::add;
    using S<Foo2>::add;
    using S<Foo3>::add;

    using S<Foo1>::size;    // (1)
    using S<Foo2>::size;    // (2)
    using S<Foo3>::size;    // (3)
};

And usage looks like this:

Z z;

z.add (Foo1 {});
z.add (Foo1 {});
z.add (Foo2 {});

cout << z.size () << endl;

This code compiles fine with gcc-5.1 (c++11), but this code does not compile
under clang-3.5 (c++11 - sorry, I do not have newer version of clang).

Clang produces "error: call to member function 'size' is ambiguous" which is
basically (from my point of view) correct, but gcc compiles it and returns 2.

Ok, but here is much more fun, if I switch the order of lines marked with
comments (1) and (2), to get something like this:

using S<Foo2>::size;    // (2)
using S<Foo1>::size;    // (1)

The code still compiles on gcc and the result is: 1.

As you can imagine, if you write line (3) before these two, you will get 0.

So, from what I see, gcc gets first using declaration of S<C>::size, ignores
rest of them and uses this one.

Is it a bug?

This question (bug) can be seen at
http://stackoverflow.com/questions/31104690/multiple-inheritance-from-instantiations-of-template-class-and-what-about-access
but I didn't receive reasonable answer there.

Best,

Artur


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

* [Bug c++/66698] Multiple inheritance from instantiations of template class and what about access to member functions
  2015-06-29 20:11 [Bug c++/66698] New: Multiple inheritance from instantiations of template class and what about access to member functions apyszczuk at gmail dot com
@ 2021-08-04 21:35 ` pinskia at gcc dot gnu.org
  2021-08-04 21:36 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04 21:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |6.1.0, 6.4.0
   Target Milestone|---                         |7.0
      Known to work|                            |7.1.0, 8.1.0

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
More self contained testcase (rather than the code snipit in comment #0):
#include <stddef.h>
#include <iostream>
template <typename C>
class S {
public:
    void add (C c) { ++cnt; }
    size_t size () const { return cnt; }

private:
    size_t cnt {}; 
};

struct Foo1 {};
struct Foo2 {};
struct Foo3 {};

class Z : public S<Foo1>, public S<Foo2>, public S<Foo3> {
public:
    using S<Foo1>::add;
    using S<Foo2>::add;
    using S<Foo3>::add;

    using S<Foo1>::size;    // (1)
    using S<Foo2>::size;    // (2)
    using S<Foo3>::size;    // (3)
};

int main(void)
{

Z z;

z.add (Foo1 {});
z.add (Foo1 {});
z.add (Foo2 {});

std::cout << z.size () << std::endl;
}

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

* [Bug c++/66698] Multiple inheritance from instantiations of template class and what about access to member functions
  2015-06-29 20:11 [Bug c++/66698] New: Multiple inheritance from instantiations of template class and what about access to member functions apyszczuk at gmail dot com
  2021-08-04 21:35 ` [Bug c++/66698] " pinskia at gcc dot gnu.org
@ 2021-08-04 21:36 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-04 21:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Also fixed in GCC 7+.

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-29 20:11 [Bug c++/66698] New: Multiple inheritance from instantiations of template class and what about access to member functions apyszczuk at gmail dot com
2021-08-04 21:35 ` [Bug c++/66698] " pinskia at gcc dot gnu.org
2021-08-04 21:36 ` 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).