[Bug c++/39452] New: G++ cannot compile local classes together with template.
The following code cannot be compiled by GCC 4.3.3. #include #include #include using namespace std; int main() { class PrintOne : unary_function { public: result_type operator()(argument_type i) { wcout << i << L'\n'; } }; int a[20] = {0, 0, 0, 0, 0}; for_each(a, a + 20, PrintOne()); return 0; } The error message is: test.cpp:22: error: no matching function for call to `for_each(int[20], int*, main()::PrintOne)' If we move class PrintOne outside or do not use template function, the compilation will succeed. -- Summary: G++ cannot compile local classes together with template. Product: gcc Version: 4.3.4 Status: UNCONFIRMED Severity: minor 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=39452
[Bug c++/39452] G++ cannot compile local classes together with template.
--- Comment #2 from jim_king_2000 at 163 dot com 2009-03-13 10:45 --- So, is it possible that the error message could be made more meaningful? I spent several hours to find out what the "no matching function for call to" refers to. Thanks. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39452
[Bug c++/39452] G++ cannot compile local classes together with template.
--- Comment #3 from jim_king_2000 at 163 dot com 2009-03-13 10:59 --- And I'm still wondering which line in the C++ spec disallows the usage of local class within the template function. Would you please figure it out? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39452
[Bug c++/39452] G++ cannot compile local classes together with template.
--- Comment #5 from jim_king_2000 at 163 dot com 2009-03-13 12:41 --- Thank you very much. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39452
[Bug c++/39680] New: unary_function<...>::result_type cannot be void.
Hi everyone The following code cannot pass compilation by g++ v4.3.2. #include #include #include #include #include #include using namespace std; class test { public: void func(int i) { wcout << i << L": test\n"; } }; namespace { template class destroyer : public unary_function { public: using typename unary_function::result_type; using typename unary_function::argument_type; public: typename unary_function::result_type operator()(typename unary_function::argument_type pointer) { delete pointer; } }; } int main() { vector 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::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 ¡®::destroyer¡¯: ../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