While compiling with -Wparentheses this will give a warning and it is understandable
if (myVar= myFunct(param1)) {
// do some stuff
}
but when we declare variable inside if block, compiler doesn't give warning. Why?
if (int myVar= myFunct(param1)) {
// do some stuff
}
g++(GCC) 4.8.5
You may not enclose in parentheses a declaration. So using additional parentheses around a declaration would generate an error.
As for the first if statement then there is used an expression with the assignment operator. So the compiler warns whether using of the assignment is intended.
In the second case there is a declaration with an initializer. There is no an assignment. The value of the condition is determinate by whether the value of the declared variable after the initialization equal or not to the zero.