I wonder if it has something to do with lifetime of temporaries - usually, my very last guess would be that it's a compiler bug (I've been proven wrong too many times).
I don't have a Windows box here - could someone do a sanity check with some other environment/compiler and make sure we haven't gone crazy?
typeid.name() gave me "class Z<class B> __cdecl(class B)"
I guess it could have been predicted from your error message that the compiler considers this to be a function declaration...
edit:
Also, if I change line 57 to
1 2
int i = 5;
Y<A> y( A( i ));
I get the same error.
edit:
Apparently it's ok to surround argument names with parenthesis when declaring a function..
that's a useful insight - and makes some sense if the parser thought it was a function declaration
but why do you think?
1 2
Z<B> z_ok( ( B( vi ))); // is an instance
Z<B> z_bad( B( vi )); // is a function declaration?
there must be something in the C++ specifications that says so because VC++ and gcc seems to agree here (thx for the sanity check, hamsterman)
(was just thinking that this would be a very nasty question for a job interview)
edit:
I wonder if the extra parens gives the compiler a chance to create a temporary before the parser decides whether the line is really a function declaration or an object
Z<B> z_ok( ( B( vi ))); // is an instance
Z<B> z_bad( B( vi )); // is a function declaration
Z<B> z_alsobad( B ); // is a function declaration
All other examples in this thread thus far are unambiguously instances.
Line 1 is a small surprise, until you accept that the extra parens is creating a temporary.
Line 2 is a surprise due to human mis-interpretation - there is probably a C++ spec out there which says this is the way it should be
Line 3 is what we expect