Tag: compiler-warnings
-
How can I get a warning when comparing unsigned integers of different size in C and C++?
27 A common source of bugs in C or C++ is code like size_t n = // … for (unsigned int i = 0; i < n; i++) // … which can infinite-loop when the unsigned int overflows. For example, on Linux, unsigned int is 32-bit, while size_t is 64-bit, so if n = 5000000000,…
-
No compiler warning for ‘const’ pointers of non POD types when overriding a method
7 An example where one is overriding POD return type without const in the derived class: struct B1 { virtual const int* f(); }; struct D1 : B1 { int* f() override; }; Compilers like Clang and GCC raise a warning: invalid covariant return type for ‘virtual int* D1::f()’ When same scenario is applied but…