Consider
auto x=foo(), y;
Is this legal? (I would imagine it is and implies that y
is of the same type as x
.)
While this particular example may not be very useful, consider
template<typename some_type>
void func(some_type const&x, some_type const&y)
{
for(auto i=std::begin(x),j=std::begin(y); i!=std::end(x) && j!=std::end(y); ) {
...
}
}
Here, i
and j
are both of the same type (because both derive from the same type of operation on the same type of objects), so this seems perfectly safe and sensible, as it avoids to declare the appropriate type (which is best done using decltype()
, i.e. via deduction again).
However, intel's compiler (version 14.0.1) warns me that
warning #3373: nonstandard use of "auto" to both deduce the type from an initializer and to announce a trailing return type
So, what should I make of this warning? Is there any problem that can come up with this type of usage of auto
?
edit The simple code snipped above does indeed not trigger the warning. However, the code which does looks very similar:
struct Neighbour { ... };
typedef std::vector<Neighbour> NeighbourList;
NeighbourList const&A;
NeighbourList const&B;
...
const auto K = std::max(A.size(),B.size());
auto k = 0*K;
for(auto iA=A.begin(),iB=B.begin(); k!=K; ++k,++iA,++iB)
...
(the for loop lives inside a member method of a class template)
auto x=foo(), y;
No it's illegal.
I can't reproduce your warning since both i
and j
have same type. That part is legal code.
The first example is illegal: all declarators must have initialisers, and y
doesn't.
The second is fine: both declarators have initialisers of the same type.
I've no idea what the warning is talking about: there are no trailing return types here. Neither GCC nor Clang give any warning about your code; I don't have an Intel compiler to test with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With