This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/603: Problem with Equally-Named Friend- and Member-Functions
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/603: Problem with Equally-Named Friend- and Member-Functions
- From: kfischer at iiic dot ethz dot ch
- Date: 4 Oct 2000 17:13:51 -0000
- Reply-To: kfischer at iiic dot ethz dot ch
- Resent-Cc: gcc-prs at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, jason at gcc dot gnu dot org
- Resent-Reply-To: gcc-gnats@gcc.gnu.org, kfischer@iiic.ethz.ch
>Number: 603
>Category: c++
>Synopsis: Problem with Equally-Named Friend- and Member-Functions
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Wed Oct 04 10:16:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: Kaspar Fischer
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
Linux 2.2.17 on PowerPC (Apple PowerBook G3 Wallstreet)
>Description:
gcc 2.95.2 refuses to compile the small attached program:
[janosch@localhost test]$ g++ test2.c -o test
test2.c: In instantiation of `A<int>':
test2.c:17: instantiated from here
test2.c:9: invalid use of undefined type `struct A<int>'
test2.c:11: forward declaration of `struct A<int>'
However, if I comment out line 10, everything works fine.
(Having posted the code to comp.lang.c++.moderated, someone
reported that Borland C++ compiles the code.)
PS. The 'same' program without templates works fine:
class A;
A f(const A&,const A&);
struct A {
friend A f(const A&,const A&);
const A f() const { return A(); }
};
A f(const A& a,const A&) { return a; }
int main(int argc,char **argv) {
A a1,a2;
A a = f(a1,a2);
a = a1.f();
return 0;
}
Thanks a lot for your efforts!
Kaspar
>How-To-Repeat:
template<typename D>
struct A;
template<typename D>
A<D> f(const A<D>&,const A<D>&);
template<typename D>
struct A {
friend A<D> f<D>(const A<D>&,const A<D>&); /* line 9 */
const A<D> f() const { return A(); } /* line 10 */
};
template<typename D>
A<D> f(const A<D>& a,const A<D>&) { return a; }
int main(int argc,char **argv) {
A<int> a1,a2; /* line 17 */
A<int> a = f(a1,a2);
return 0;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="test2.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test2.c"
dGVtcGxhdGU8dHlwZW5hbWUgRD4Kc3RydWN0IEE7Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBEPgpBPEQ+
IGYoY29uc3QgQTxEPiYsY29uc3QgQTxEPiYpOwoKdGVtcGxhdGU8dHlwZW5hbWUgRD4Kc3RydWN0
IEEgewogIGZyaWVuZCBBPEQ+IGY8RD4oY29uc3QgQTxEPiYsY29uc3QgQTxEPiYpOyAvKiBsaW5l
IDkgKi8KICBjb25zdCBBPEQ+IGYoKSBjb25zdCB7IHJldHVybiBBKCk7IH0gLyogbGluZSAxMCAq
Lwp9OwoKdGVtcGxhdGU8dHlwZW5hbWUgRD4KQTxEPiBmKGNvbnN0IEE8RD4mIGEsY29uc3QgQTxE
PiYpIHsgcmV0dXJuIGE7IH0KCmludCBtYWluKGludCBhcmdjLGNoYXIgKiphcmd2KSB7CiAgQTxp
bnQ+IGExLGEyOyAvKiBsaW5lIDE3ICovCiAgQTxpbnQ+IGEgPSBmKGExLGEyKTsKICByZXR1cm4g
MDsKfQoK