When declaring a variable as a const and trying to modfiy its value later, you will get a compiler error. For example this code:
void func(){ const int a = 5; a = 4; } will generate error C3892 on MSVS. However, if the opposite case happened, no error nor warning will be thrown. For example, this code:
void func(){ int a = 5; std::cout << a; } won't produce any warning even with /wall configuration. I know that this code is not buggy. It is just does not follow the best practice.
Why there is no warning for such thing? is it only on MSVS? Does the standard have anything to say about that? Are there another compilers that produce a warning for this?
std::cout << 5;. Is not the compiler's job to emit warnings for "bad" practices with some exceptions though (e.g.,if(A || B && C)) that there's a high probability to shoot your foot. This is most likely a job a for an static analysis tool.