do decltype and lambda function mix?
I reduced our current code to this simple snippet:
struct except : public std::exception
{
virtual const char* what() const throw() { return "except"; }
};
void grow() { static unsigned n = 0; if(n++ < 2) throw
std::bad_alloc(); }
template<class F, class ...Args>
auto call(F f, Args&&...args) ->
decltype(f(std::forward<Args>(args)...))
{
while(1)
{
try { return f(std::forward<Args>(args)...); }
catch(except& e) { grow(); }
}
}
int main()
{
call([]{});
return call([](int s) { std::cerr << s; return s; }, 123);
}
The purpose of call() function is to grow special memory allocation
when necessary. The function takes a function object and arguments.
The function object in this case is lambda function. The question is
whether this code standard compliant? The standard forbids lambda
expression in unevaluated context. Does it mean decltype here is
illformed?
This code works as expected in gcc 4.6.2, but when attempted to be
ported to 4.7.0, compiler died with segmentation fault, and no error
message.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]