How we sympathize with a question on StackOverflow but keep silent

  • writing integer values other than 0 and 1 to a bool type variable;
  • virtual functions call in the constructor and destructor.
int f1(){
int a=5;
short b=4;
bool a1=a;//maybe warn
bool b1=b;//maybe warn
if(a1&&b1)return 1;
return 0;
}
class M{
public:
virtual int GetAge(){return 0;}
};
class P:public M{
public:
virtual int GetAge(){return 1;}
P(){GetAge();}//maybe warn
~P(){GetAge();}//maybe warn
};

int main(){
return 0;
}
  • 6:1: note: V547 The ‘A = a’ expression is equivalent to the ‘A = true’ expression.
  • 6:1: warning: V786 It is odd that value ‘a’ is assigned to the ‘a1’ variable. The value range of ‘a1’ variable: [0, 1].
  • 7:1: note: V547 The ‘A = b’ expression is equivalent to the ‘A = true’ expression.
  • 7:1: warning: V786 It is odd that value ‘b’ is assigned to the ‘b1’ variable. The value range of ‘b1’ variable: [0, 1].
  • 18:1: error: V1053 Calling the ‘GetAge’ virtual function in the constructor may lead to unexpected result at runtime.
  • 19:1: error: V1053 Calling the ‘GetAge’ virtual function in the destructor may lead to unexpected result at runtime.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrey Karpov

Andrey Karpov

Co-founder of the PVS-Studio project. Microsoft MVP in the ‘Developer Technologies’ nomination and PhD in Physics and Mathematics.