This is the mail archive of the cygwin@sourceware.cygnus.com
mailing list for the Cygwin project. See the Cygwin
home page for more information.
[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index] [Subject Index] [Author Index] [Thread Index]
Re: egcs 1.1.1: odd warning message with template friend functions
- To: "Jonathan Pryor" <jonpryor@cowpie.acm.vt.edu>, "Mumit Khan" <khan@xraylith.wisc.EDU>
- Subject: Re: egcs 1.1.1: odd warning message with template friend functions
- From: "Jonathan Pryor" <jonpryor@vt.edu>
- Date: Mon, 15 Mar 1999 13:45:43 -0500
- Cc: "Cygwin Mailing List" <cygwin@sourceware.cygnus.com>
- Delivered-To: listarch-cygwin@sourceware.cygnus.com
- Delivered-To: mailing list cygwin@sourceware.cygnus.com
- Mailing-List: contact cygwin-help@sourceware.cygnus.com; run by ezmlm
- Sender: cygwin-owner@sourceware.cygnus.com
Mumit Khan <khan@xraylith.wisc.EDU> writes:
>"Jonathan Pryor" <jonpryor@vt.edu> 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<T> &, const class meta_info<T> &)'
>> 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<T> 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 T> class task;
template<class T> task<T>* preempt(task<T>*);
template<class T> class task {
// ...
friend void next_time();
// all task specializations have the non-template function
// next_time() as a friend.
friend void process(task<T>*);
// "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<T>* preempt<T>(task<T>*);
// "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<class C> 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 <typename T>
class meta_info {
friend const meta_info<T>& metaid ( const T& );
meta_info ();
public:
};
template <typename T>
const meta_info<T>& metaid ( const T& ) {
meta_info<T> 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@sourceware.cygnus.com