bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

BUG: Return types should not be computed for non-matching templates


From: Dean Foster
Subject: BUG: Return types should not be computed for non-matching templates
Date: 9 Dec 2002 19:17:18 -0000

Hello Lords of g++;

        I think I have discovered a small bug in g++ version 3.2.  If
a template function definition is not the "best match" its return type
is still checked to see if it is legal.  Since this is not part of the
signature, this is incorrect behavior.  Maybe an example will make
this clearer:

        #include <iostream>

        template<class T>
        class my_traits
        {
          typedef typename T::foo result_type;
        };

        template<class T>
        typename my_traits<T>::result_type      // LINE A:
        f(const T&)
        {
          std::cout << "f(T)" << std::endl;
        }

        template<class T>
        int
        f(T*)                                   // LINE B:
        {
          std::cout << "f(T*)" << std::endl;
        }

        class Empty
        {
        };

        int
        main()
        {
          Empty d;
          f(&d);                                // LINE C:
        }

In LINE C: function f is called.  It is clear that the second
defintion (LINE B) is the better match.  g++ correctly determines that
it is the better match.  But, it generates an error message for LINE
A:. 

        template_matching.cc: In instantiation of `my_traits<Empty*>':
        template_matching.cc:32:   instantiated from here
        template_matching.cc:7: `Empty*' is not a class, struct, or union type

Since this function should not ever be created, checking its return
type shouldn't happen.

thanks!

dean


=============================================================================
Dean Foster                                                   address@hidden
Statistics, Wharton, U. Penn                                     215 898 8233
Philadelphia PA 19104-6340                 http://diskworld.wharton.upenn.edu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]