N
Noah Roberts
`type_x var();` is "unparseable" in that it's impossible to tell if this
is a function declaration or an instantiation of a variable using the
default constructor. Thus the standard tells the compiler which to
pick. The other day I helped a coworker find a problem that ultimately
ended up being something possibly similar?
type_x var1 = ....;
{
type_y(var);
}
This happened because he was testing to see if the construction of
"type_y" threw an exception and the macro in Boost.Test that does this
turns into something quite similar to the above.
What the compiler did here surprised the hell out of me. It decided
that the line meant, "build a new type_y called 'var' and use the
default constructor."
I also tried some other variations without using the macro and this also
did the same thing:
type_x var = ....;
type_y(var);
This one surprises me more as it should be easy to tell now that it's
illegal to have two 'var' instances in the same scope.
Is this correct behavior or a broken compiler?
is a function declaration or an instantiation of a variable using the
default constructor. Thus the standard tells the compiler which to
pick. The other day I helped a coworker find a problem that ultimately
ended up being something possibly similar?
type_x var1 = ....;
{
type_y(var);
}
This happened because he was testing to see if the construction of
"type_y" threw an exception and the macro in Boost.Test that does this
turns into something quite similar to the above.
What the compiler did here surprised the hell out of me. It decided
that the line meant, "build a new type_y called 'var' and use the
default constructor."
I also tried some other variations without using the macro and this also
did the same thing:
type_x var = ....;
type_y(var);
This one surprises me more as it should be easy to tell now that it's
illegal to have two 'var' instances in the same scope.
Is this correct behavior or a broken compiler?