T t(U());
It is so-called "most vexing parse". It is function declaration which returns T, and takes nullary function which returns U as a parameter. Imagine:
typedef U nullary_function_return_U();
T t(nullary_function_return_U /*param_name*/)
{
return T;
}
You can workaround it by adding parentheses:
T t( (U()) );
Or in C++11, you can use uniform initialization syntax:
T t{U{}};
most vexing indeed.The error message is really terrible and regardless of the most vexing parse, it should really compile, shouldn't it?
I have tested on GCC 4.8.1 - Error, Clang 3.4 - OK, MSVC2010 - OK. I cut down it to smallest case which triggers error on GCC:
template <typename = int>
struct Foo
{
Foo()
{
int t(int()); // Error
}
};
int main()
{
int t(int()); // OK
Foo<> a; // Error
}
This looks like GCC bug. I have made report to GCC Bugzilla.
Edit:
Paolo Carlini 2014-07-07 14:11:14 UTC This is already fixed mainline and 4.9.1. I'm adding the testcase and closing the bug.