public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: pawig@hildesheim.sgh-net.de
To: gcc-gnats@gcc.gnu.org
Subject: c++/8875: Ambiguities in mixed template hierarchies
Date: Sun, 08 Dec 2002 10:56:00 -0000	[thread overview]
Message-ID: <20021208185505.15025.qmail@sources.redhat.com> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2931 bytes --]


>Number:         8875
>Category:       c++
>Synopsis:       Ambiguities in mixed template hierarchies
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 08 10:56:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Stefan Große Pawig
>Release:        gcc (GCC) 3.2.1 (also with 3.2)
>Organization:
>Environment:
Linux rigel 2.4.18 #5 Thu Aug 1 22:19:10 CEST 2002 i686 unknown
>Description:
The following code snippet (see below) exercises a base class
template with concrete and pure virtual methods as well as
general and specialized derived templates, which provide
implementations for the pure virtual methods.

Spezializations are provided for void* as well as for pointers
in general, which builds on the void* spezialization via
private inheritance.

The problem occurs when one of the concrete methods of the base
class is called on an instantiation of the derived template for
pointers (Derviced<int*> in the sample code): the compiler
complains that the concrete member is ambiguous (line 37).

Using explicit qualification works for Base<int*>::doThat() but
fails for Base<void*>::doThat() as expected (line 39), so
why does the compiler regard the unqualified call as ambiguous?

Am I missing something here? Or is this an effect of the
"Two stage lookup in templates is not implemented." as stated
on the "GCC Bugs" page?
>How-To-Repeat:
pawig@rigel:~/src > cat ctest1.cc
// Base class template
template <typename T>
class Base
{
public:
  virtual T doThis() const = 0;
  bool doThat() const { return doThis() == T(); }
};

// General Derived class template
template <typename T>
class Derived : public Base<T>
{
public:
  T doThis() const { return T(); }
};

// Derived specialized for void* 
template<>
class Derived<void*> : public Base<void*>
{
public:
  void* doThis() const { return reinterpret_cast<void*>(0x0badbeef); }
};

// Derived specialized for any pointer
template <typename T>
class Derived<T*> : public Base<T*>, private Derived<void*>
{
public:
  T* doThis() const { return static_cast<T*>(Derived<void*>::doThis()); }
};

int main()
{
  Derived<int*> d;
  bool b1 = d.doThat();                // Line 37
  bool b2 = d.Base<int*>::doThat();
  bool b3 = d.Base<void*>::doThat();   // Line 39
  return 0;
}
pawig@rigel:~/src > g++ -c ctest1.cc
ctest1.cc: In function `int main()':
ctest1.cc:37: request for member `doThat' is ambiguous
ctest1.cc:7: candidates are: bool Base<T>::doThat() const [with T = void*]
ctest1.cc:7:                 bool Base<T>::doThat() const [with T = int*]
ctest1.cc:39: `Base<void*>' is an inaccessible base of `Derived<int*>'
>Fix:
Workaround:
Instead of deriving Derived<T*> privately from Derived<void*>,
just put a Derived<void*> data meber into the Derived<T*> template. 
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-12-08 18:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-08 10:56 pawig [this message]
2002-12-09 11:42 bangerth
2002-12-10  2:09 nathan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20021208185505.15025.qmail@sources.redhat.com \
    --to=pawig@hildesheim.sgh-net.de \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).