This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/11: bogus instantiation during template deduction
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/11: bogus instantiation during template deduction
- From: nathan at codesourcery dot com
- Date: 1 Mar 2000 17:09:46 -0000
- Cc: gawrilow at math dot TU-Berlin dot DE
- Reply-To: nathan at codesourcery dot com
- Resent-Cc: gcc-prs at gcc dot gnu dot org, gawrilow at math dot TU-Berlin dot DE
- Resent-Reply-To: gcc-gnats@gcc.gnu.org, nathan@codesourcery.com
>Number: 11
>Category: c++
>Synopsis: bogus instantiation during template deduction
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Mar 01 09:16:01 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Ewgenij Gawrilow <gawrilow@math.TU-Berlin.DE>
>Release: CVS 20000229
>Organization:
>Environment:
All
>Description:
The following piece of code can't be compiled by gcc 2.95.2.
#line 1 "prob.cc"
template <class C>
struct A {
typedef typename C::obj obj;
typedef typename C::cobj cobj;
static obj g(C& c) { return c.g(); }
static cobj g(const C& c) { return c.g(); }
};
#if defined(WORK_AROUND)
template <class C>
struct A<const C> {
typedef typename C::cobj obj;
};
#endif
template <class C> inline
A<C>::obj g(C& c)
{
return A<C>::g(c);
}
template <class C> inline
A<C>::cobj g(const C& c)
{
return A<C>::g(c);
}
class cont {
public:
class obj { };
class cobj { };
obj g();
cobj g() const;
};
void f(const cont& c)
{
g(c);
}
prob.cc: In instantiation of `A<const cont>':
prob.cc:19: instantiated from here
prob.cc:7: `A<const cont>::g(const cont &)' has already been declared in `A<const cont>'
It seems as if the template parameter deduction is being made twice, once when
analyzing the return value of g(c) within f(), and then during the
instantiation of the body of ::g. It wasn't that bad, hadn't the first attempt
lead to wrong results.
>How-To-Repeat:
during deduction of the call to Baz, A<const int> is
instantiated. This fails, but should just be rejected, not
cause a diagnostic [14.8.2]/2
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="nathan105.C"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="nathan105.C"
Ly8gQnVpbGQgZG9uJ3QgbGluazoKCi8vIENvcHlyaWdodCAoQykgMjAwMCBGcmVlIFNvZnR3YXJl
IEZvdW5kYXRpb24sIEluYy4KLy8gQ29udHJpYnV0ZWQgYnkgTmF0aGFuIFNpZHdlbGwgMSBNYXJj
aCAyMDAwIDxuYXRoYW5AY29kZXNvdXJjZXJ5LmNvbT4KCi8vIGRlcml2ZWQgZnJvbSBhIGJ1ZyBy
ZXBvcnQgYnkgRXdnZW5paiBHYXdyaWxvdyA8Z2F3cmlsb3dAbWF0aC5UVS1CZXJsaW4uREU+Cgp0
ZW1wbGF0ZSA8Y2xhc3MgVD4Kc3RydWN0IEEgewogIHR5cGVkZWYgVCBUX3Q7CiAgc3RhdGljIHZv
aWQgRm9vIChUICYpOwogIHN0YXRpYyB2b2lkIEZvbyAoY29uc3QgVCAmKTsgLy8gZ2V0cyBib2d1
cyBlcnJvciAtIFhGQUlMICotKi0qCn07Cgp0ZW1wbGF0ZSA8Y2xhc3MgVD4gdm9pZCBCYXogKFQm
LCB0eXBlbmFtZSBBPFQ+OjpUX3QpOwp0ZW1wbGF0ZSA8Y2xhc3MgVD4gdm9pZCBCYXogKGNvbnN0
IFQmLCB0eXBlbmFtZSBBPFQ+OjpUX3QpOwoKdm9pZCBmICgpCnsKICBjb25zdCBpbnQgaSA9IDE7
CiAgQmF6IChpLCAxKTsgICAgICAgICAgIC8vIGdldHMgYm9ndXMgZXJyb3IgLSBYRkFJTCAqLSot
Kgp9Cg==