This question comes from this c++ how to replace a string in an array for another string
So if we have this code:
void foo( int i )
{
i == 123;
}
we get compiler warning (from gcc v.5.0.1 -Wall):
warning: statement has no effect [-Wunused-value]
which is good, helpful and informative.
But if we do the same with std::string
compiler is quiet:
void foo( std::string str )
{
str == "foobar";
}
As I understand it is fine to ignore result of bool std::string::operator==()
(as for any other function). But is there a way (or any plans to create one) to make compiler to generate warning for user defined types as well, so behavior of embedded types and user defined are closer?
PS I understand that it is not simple to make compiler to do that automatically. But what actually came to my mind is a way to tell compiler "generate warning when result of this function is ignored", aside of if there side effects or not. Is it possible? Are there bad side effects of this way?