------- Comment #2 from jwakely dot gcc at gmail dot com 2008-03-08 15:25 ------- (In reply to comment #0) > // 1 > #include <functional> > > typedef int value_type; > > // void argument type > template class std::unary_function<void, value_type>;
eurgh, even more of an abomination than int f(void) :-) > template class std::pointer_to_unary_function<void, value_type>; This fails, correctly I think. It's analogous to this illegal declaration: typedef void T; int f(T); > // void return type > template class std::unary_function<value_type, void>; > template class std::pointer_to_unary_function<value_type, void>; These are OK, aren't they? > And more specific things: > > // 2 > #include <functional> > void foo() { }; > > // pointer_to_unary_function > void test01() > { > typedef std::pointer_to_unary_function<void, void> pfunc; > pfunc p(&foo); this is invalid, foo is not a unary function so the number of parameters doesn't match. The declaration void f(void) is valid for C compatibility, but that doesn't make it a unary function. 14.8.2para2 says type deduction can fail due to "Attempting to create a function type in which a parameter has a type of void." That's discussing a different situation, but the principle is the same. I couldn't find anything more specific. > // 3 > #include <functional> > // unary_function > struct void_unary : public std::unary_function<void, void> > { > typedef std::unary_function<void, void> base_type; > typedef base_type::Arg argument_type; > typedef base_type::Result result_type; > }; Hmm, I suppose this is legal, although ill-advised. > Is this usage standards-conforming? I think the declarations and typedefs are legal, but using them isn't necessarily possible. So you can't assign &foo to a unary_function, and you couldn't define this member: Result void_unary::f(Arg); Thankfully the void f(void) syntax is not valid in templates, because there's no need for C compatibility in template code. I don't think this is a bug. -- jwakely dot gcc at gmail dot com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jwakely dot gcc at gmail dot | |com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33628