Is there a way to detect when file dependencies are "accidentally" satisfied?

Viewed 126

Let's say there are three headers AAA.h, BBB.h and MyLib.h. MyLib.h needs to include both AAA.h and BBB.h to work properly.

Now, it just happens that BBB.h also includes AAA.h in it, but this is strictly due to the implementation, a detail that MyLib.h should not need to care about.

However, by mistake, the writer of MyLib.h neglects to include AAA.h and never notices. This normally doesn't result in an error or warning, for as far as I know. Later on, someone changes the implementation details of BBB.h so that AAA.h is no longer needed and thus removed. Now MyLib doesn't compile because internals of library BBB have changed.

Is there a way to error or warn in cases like these? I suspect (if this is even possible) that it would take some kind of annotation in the header being included.

2 Answers
Related