Hi everyone The following code cannot pass compilation by g++ v4.3.2.
#include <functional> #include <algorithm> #include <iostream> #include <string> #include <memory> #include <vector> using namespace std; class test { public: void func(int i) { wcout << i << L": test\n"; } }; namespace { template<class T> class destroyer : public unary_function<T, void> { public: using typename unary_function<T, void>::result_type; using typename unary_function<T, void>::argument_type; public: typename unary_function<T, void>::result_type operator()(typename unary_function<T, void>::argument_type pointer) { delete pointer; } }; } int main() { vector<test *> data; for (int i = 0; i < 5; ++i) data.push_back(new test); for_each(data.begin(), data.end(), bind2nd(mem_fun(&test::func), 0)); for_each(data.begin(), data.end(), destroyer<vector<test *>::value_type>()); return 0; } The error message is quite vague: g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Test_Cplusplus.d" -MT"src/Test_Cplusplus.d" -o"src/Test_Cplusplus.o" "../src/Test_Cplusplus.cpp" ../src/Test_Cplusplus.cpp: In instantiation of ¡®<unnamed>::destroyer<test*>¡¯: ../src/Test_Cplusplus.cpp:49: instantiated from here ../src/Test_Cplusplus.cpp:25: internal compiler error: in dwarf2out_imported_module_or_decl, at dwarf2out.c:14261 Please submit a full bug report, with preprocessed source if appropriate. See <http://bugs.opensuse.org/> for instructions. make: *** [src/Test_Cplusplus.o] error 1 However, if the "result_type" is not void, the code can be compiled successfully. Does this behavior conform to the standard? -- Summary: unary_function<...>::result_type cannot be void. Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: jim_king_2000 at 163 dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39680