This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

unary_function<...>::result cannot be void.


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] éè 1

However, if the "result_type" is not void, the code can be compiled
successfully. Does this behavior conform to the standard?

-- 
View this message in context: http://www.nabble.com/unary_function%3C...%3E%3A%3Aresult-cannot-be-void.-tp22922396p22922396.html
Sent from the gcc - libstdc++ mailing list archive at Nabble.com.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]