From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11539 invoked by alias); 17 Jan 2008 17:12:22 -0000 Received: (qmail 11527 invoked by uid 22791); 17 Jan 2008 17:12:22 -0000 X-Spam-Check-By: sourceware.org Received: from fg-out-1718.google.com (HELO fg-out-1718.google.com) (72.14.220.156) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 17 Jan 2008 17:11:59 +0000 Received: by fg-out-1718.google.com with SMTP id d23so701553fga.28 for ; Thu, 17 Jan 2008 09:11:56 -0800 (PST) Received: by 10.82.140.20 with SMTP id n20mr4049423bud.27.1200589916743; Thu, 17 Jan 2008 09:11:56 -0800 (PST) Received: by 10.82.173.1 with HTTP; Thu, 17 Jan 2008 09:11:56 -0800 (PST) Message-ID: <84fc9c000801170911p199d1913i796e92bba9a17cb7@mail.gmail.com> Date: Thu, 17 Jan 2008 18:09:00 -0000 From: "Richard Guenther" To: "Ian Lance Taylor" Subject: Re: A simple sample code involving templates, friends and lookup Cc: "Dragan Milenkovic" , gcc@gcc.gnu.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <478F3175.2050809@plusplus.co.yu> <84fc9c000801170449j332abd0bp501bbc2fd9d04c46@mail.gmail.com> <478F544F.9060509@plusplus.co.yu> <84fc9c000801170535k1bd3eb89p6f95d63ee6f58647@mail.gmail.com> X-IsSubscribed: yes Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2008-01/txt/msg00276.txt.bz2 On 17 Jan 2008 09:09:38 -0800, Ian Lance Taylor wrote: > > "Richard Guenther" writes: > > > On Jan 17, 2008 2:12 PM, Dragan Milenkovic wrote: > > > Richard Guenther wrote: > > > [snip] > > > >> template > > > >> struct Foo > > > >> { > > > >> template > > > >> friend void func(const Foo &); > > > >> }; > > > >> > > > >> void check(const Foo & x) > > > >> { > > > >> // Foo weird; // uncomment this line and all works > > > >> > > > >> func(x); // <-- ERROR > > > >> } > > > >> > > > >> > > > >> Tested with gcc 4.0 - 4.3, and all behave the same: > > > >> > > > >> "error: 'func' was not declared in this scope" > > > >> > > > >> but it works if you uncomment the weird line. > > > > > > > > Actually even with the weird line the program is invalid. What are > > > > you trying to do? ;) > > > > > > > > Richard. > > > > > > Ok... afaik, that func should be defined on that very place where it is > > > declared as friend. But could you please elaborate why it is invalid, > > > since you made me start questioning my C++ knowledge... :-D > > > > How should name-lookup find func? > > It should use argument dependent lookup. This is like the common case > of > > class x > { > friend x operator+(const& x, const& x) { return x.var + x.var; } > }; > > in which x::operator+ is found without taking special action. Well, first I think you'd need friend-injection or otherwise a global decl of the function. Second I thought argument dependent name-lookup only applies to namespaces, not classes. EDG rejects this consistently btw. Richard.