This following code (containing a vicious bug) compiles with GCC without any warning. But, of course, it doesn't work as expected by the developer (me).
#include <iostream>
struct A
{
bool b;
void set(bool b_) { this->b = b_; }
bool get() const { return this-b; } // The bug is here: '-' instead of '->'
};
int main()
{
A a;
a.set(true);
std::cout << a.get() << std::endl; // Print 1
a.set(false);
std::cout << a.get() << std::endl; // Print 1 too...
return 0;
}
Which warning can I add for the compiler (GCC 4.8) to avoid this kind of typo?
Linked question: Is there any option to force (or warn) the access to member variables/functions with this->
?