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]

egcs 1.1.1: odd warning message with template friend functions



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

The final executable runs fine; it's just that this message doesn't 
make sense to me.  The line that causes the warning is the following:

    template <typename T>
    class meta_info {
        friend bool operator== ( const meta_info<T>&, 
            const meta_info<T>& );
        /* ... */
    };

Since the friend declaration is in a template class, I fail
to see how `operator==' could *not* be a template function,
which the warning message suggests.

Furthermore, in Stroustrup, 3rd Edition (pages 854-855), he
has a similar example (a template class with a friend declaration),
and states that because the friend declaration was in a template
class, the friend must also be a template.  In this example,
the friend declaration did *not* have `<>' appended to the function
name.

If I follow the compilers suggestion and modify the class
declaration to:

    template <typename T>
    class meta_info {
        // note `<>' after `operator=='
        friend bool operator==<> ( const meta_info<T>&, 
            const meta_info<T>& );
        /* ... */
    };

egcs will compile this without any error messages, but now
MSVC6 has caniptions...  In addition, it seems to go against
what was stated in Stroustrup, so I'm finding this...bizarre.

(Yes, we could argue that it's a bug in MSVC -- except that
Stroutstrup doesn't mention needing to add a `<>' to make
the friend a template.  In addition, MSVC compiles the original
version without any errors/warnings -- so (to me) it doesn't 
make sense to call it an MSVC bug.)

Again, this doesn't seem to cause any problems in the executable.
I just don't like warning messages that seem to be incorrect, or,
at the very least, don't make any sense for this circumstance.

In a related question: Should I to send future compiler bug 
reports to the cygwin mailing list, to the egcs-bugs mailing
list, or to both?  I didn't see any reference to this on the
web site, so I'm just "playing this by ear"...

Thanks,
 - Jon

mi.cpp

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com