It is much cleaner to construct the variable with the correct type instead of using a static_cast, +1 I also see such somewhat related code now and then: auto s = std::string{"hello"};
so as I read it we think that example 2 and example 3 are OK. I believe that example 1 is discussible. There may be situations where auto is preferable and then there are situations where it would be better to remove the cast and not use auto. Imho, the downsides of the auto+cast is that it's extra code and it can hide compiler warnings that may point out real bugs.
It is much cleaner to construct the variable with the correct type instead of using a static_cast, +1 casts can hide compiler warnings about real bugs. I also see such somewhat related code now and then: auto s = std::string{"hello"};
Cppcheck-2.20.0
I feel that auto is overused in cppcheck. And would like to have a little discussion about it. I don't want that we just mechanically replace types with auto whenever possible. Can we agree on when it is OK to use it. Example 1: Cast result assigned to variable: const auto t = static_cast<char>(type); I am not convinced that auto is a good idea if the typename is short and simple. It does not save any bytes to write auto here. If we just save 2-3 bytes by writing auto I still suggest we should write...
I feel that auto is overused in cppcheck. And would like to have a little discussion about it. I don't want that we just mechanically replace types with auto whenever possible. Can we agree on when it is OK to use it. Example 1: Cast result assigned to variable: const auto t = static_cast<char>(type); I am not convinced that auto is a good idea if the typename is short and simple. It does not save any bytes to write auto here. If we just save 2-3 bytes by writing auto I still suggest we should write...
I would like to start preparations for the Cppcheck-2.20 release. The handling of Polyspace suppressions is needed in a customer trial. I suggest that we focus more on fixing bugs and testing in the coming weeks. Avoid adding complex features.
Cppcheck-2.19.0