Closed cgmb closed 7 years ago
It seems the confusion with definitions is a problem even without accepting values. Something like this bit of code from Apitrace will be misinterpreted:
#ifndef DECLSPEC_DEPRECATED
#define DECLSPEC_DEPRECATED
#endif
A fairly simple heuristic would be to check the code after the #define to see if there's an #endif immediately. It's not really guarding anything if there's nothing inside it.
checkguard will complain about perfectly valid guards like this:
The problem with just accepting a value for include guards is that it makes confusing an include guard and a constant declaration more likely. This looks pretty similar:
But, perhaps something could still be done about these cases? If guardonce checked that the
#ifndef
/#endif
covered the whole file (aside from comments and preprocessor directives), it could be reasonably certain the it was dealing with an include guard. That, of course, depends on #7.Do most people who give a value to their include guards use 1? Perhaps that would be a decent heuristic to use in the meantime? Needs research.