Well, with GCC, the following code warns you how you want:
struct Foo { }; struct Bar { Foo f; }; int main() { Bar b;
But if you add a constructor / destructor to the Foo or Bar structure, even trivial, it will not warn.
struct Foo { Foo() {} }; struct Bar { Foo f; }; int main() { Bar b;
Thus, the easiest way to return a warning is to compile all the relevant AND destructors constructors conditionally:
struct Foo { #ifndef TEST_UNUSED Foo() {} #endif }; struct Bar { Foo f; }; int main() { Bar b;
Now compile with g++ -DTEST_UNUSED to check for additional unused variables.
Not my brightest idea, but it works.
source share