Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com Message-ID: <123201be6f14$1abd1160$e63d2509@jonpryor.raleigh.ibm.com> From: "Jonathan Pryor" To: "Jonathan Pryor" , "Mumit Khan" Cc: "Cygwin Mailing List" Subject: Re: egcs 1.1.1: odd warning message with template friend functions Date: Mon, 15 Mar 1999 13:45:43 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Mumit Khan writes: >"Jonathan Pryor" writes: >> ------=_NextPart_000_11AA_01BE6EC4.CC9E62D0 >> Content-Type: text/plain; >> charset="iso-8859-1" >> Content-Transfer-Encoding: 7bit >> >> Note: I'm not complaining about the resulting executable; I'm >> complaining about the warning message itself. >> >> When I compile the attached source code, I get the >> following warning: >> >> mi.cpp:7: warning: friend declaration `bool operator ==( >> const class meta_info &, const class meta_info &)' >> mi.cpp:7: warning: declares a non-template function >> mi.cpp:7: warning: (if this is not what you intended, make sure >> mi.cpp:7: warning: the function template has already been declared, >> mi.cpp:7: warning: and add <> after the function name here) >> mi.cpp:8: warning: friend declaration `class meta_info metaid( >> const T &)' >> mi.cpp:8: warning: declares a non-template function > >Please see "Guiding Declarations" in the standard. EGCS is correct; MSVC >doesn't implmenent this correctly. This was added after Stroustrup book >came out (at least my copy of it). > >Regards, >Mumit If it was added after Stroustrup, that would cure some of my confusion... But I'm always confused. ;-) So.... (In reference to a later note you sent to Bob Aglietti:) Please, bore me with guiding declarations! :-) As for Dejanews -- I tried searching for "guiding declarations" and "guiding decl", but didn't find too much that helped. In all seriousness, I'm currently looking at the draft C++ standard available at http://www.cygnus.com/iso/ . Hopefully this is current enough... (though with my luck, it's incorrect and the only way to know for sure is to spend the $18 (?) to get a real copy of the standard -- which might not be a bad idea, actually...) However, I tried searching for "Guiding Declarations", and didn't find anything. What I did find was section 14.5.3 -- Friends -- and a lot of confusion. Assuming I'm reading this correctly (always a good question), then in the following template class: // prototypes template class task; template task* preempt(task*); template class task { // ... friend void next_time(); // all task specializations have the non-template function // next_time() as a friend. friend void process(task*); // "each specialization of the task class template has an // appropriately typed function process as a friend, and // this friend is not a function template specialization" // // OK, it's not a specialization; but is it still a template? // I think this declaration matches my original report. friend task* preempt(task*); // "each specialization of the task class template has the // appropriate specialization of the function template // preempt as a friend" // // This would match the syntax egcs was looking for. template friend int func(C); // "each specialization of the task class template has all // specializations of the function template func as friends". // // Oddly enough, this actually compiles find with both // egcs and MSVC... // ... }; The 2nd friend declaration resembles what I was curious about. But the standard doesn't seem to specify whether or not the function must be a template; "an appropriately typed function" sounds like a template, but I'd just like to verify this. If "an appropriately typed function" is in fact a template, then I shouldn't be getting a warning for the following template class meta_info { friend const meta_info& metaid ( const T& ); meta_info (); public: }; template const meta_info& metaid ( const T& ) { meta_info mi; return mi; } So what's the scoop here? What's "an appropriately typed function"? Does it mean it'll look for a non-template function with the same types at compile time? If a non-template function with the correct types isn't found, but a template function with the same prototype exists, will a standard-conforming compiler use that? If the last question is true, then why (again) give a warning about declaring a non-template function? Is it "safe" to ignore this warning in this case, then? Thanks, - Jon -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com