Is there a GCC option to warn about writing `this-field` instead of `this->field`?

This particular issue is detected by cppcheck:

$ cppcheck --enable=all this-minus-bool.cxx 
Checking this-minus-bool.cxx...
[this-minus-bool.cxx:7]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?
(information) Cppcheck cannot find all the include files (use --check-config for details)

This was with no include path given. If I add -I /usr/include/c++/4.8/, the issue is still detected:

Checking this-minus-bool.cxx...
[this-minus-bool.cxx]: (information) Too many #ifdef configurations - cppcheck only checks 12 of 45 configurations. Use --force to check all configurations.
[this-minus-bool.cxx:7]: (warning) Suspicious pointer subtraction. Did you intend to write '->'?
[/usr/include/c++/4.8/bits/ostream.tcc:335]: (style) Struct '__ptr_guard' has a constructor with 1 argument that is not explicit.
[/usr/include/c++/4.8/bits/locale_classes.tcc:248]: (error) Deallocating a deallocated pointer: __c

and then cppcheck slowly works through the aforementioned #ifdef configurations.

(As a side note, the error in local_classes.tcc is a false positive but this is very hard to tell for an automated tool, as it would need to be aware that the catch block at this site should not be entered when the macro __EXCEPTIONS is unset.)

Disclaimer: I have no other experience with cppcheck.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)