4

Should the following code compile in C++98/03?

struct Base
{
    template <typename T> void func () { }
    void norm() {  }
};

struct Derived : public Base { };

template <typename U>
struct Usage
{
    typedef void (U::*Method)();

    Usage(Method test) { }
};

int main()
{
    Usage<Derived> good(&Derived::norm);

    // "Error: Cannot use void(*)() to initialize Usage<Derived>." on next line
    Usage<Derived> bad(&Derived::func<int>);

    return 0;
}

This code snippet worked just fine on nearly every compiler that I was able to try out; save Sun C++ 5.11 and Sun C++ 5.12.

Should that be a bug? If so, does anyone know if it has been reported to the vendor (currently Oracle)?

Edit:

I'll accept an answer that provide the proper relevant quotations from either the C++03 or C++11 standards documents. Or if you can provide information about a bug report with Oracle.

Michael Price
  • 8,088
  • 1
  • 17
  • 24
  • 6
    The code is good. Sun C++ is notoriously *not*. – Drew Dormann Mar 21 '13 at 23:24
  • This seems to be fine, since `func` doesn't use the `T` type at all, it's always just `void (Base::*)(void)`, just like `Base::norm` is. –  Mar 21 '13 at 23:28
  • @DrewDormann - Yeah, I know, unfortunately. Their standard library implementation has typically been subpar as well. – Michael Price Mar 21 '13 at 23:46
  • I can't find anything in C++03 that explicitly says that the type of a specialization of a member function template is a member function type. But it's pretty obvious, uh, right? – aschepler Mar 22 '13 at 00:46

1 Answers1

0

I just read most of the C++98 standard, chapter 14. There isn't really much said about what type are resulting (specialized) template member, so I assume that it follows the idea that being a template method doesn't make it any less of a method. I f I have a moment, I will see if C++11 says more about it.

From my general idea about C++ I know that your code should pass - and majority of compilers agreeing on that is also a clue, isn't it? :)

j_kubik
  • 6,062
  • 1
  • 23
  • 42