I am trying to ban the inclusion of a list of header files from a source file, and thus preventing the dependency on classes defined in those headers.
There are tricks of checking the header guard macros (like the following), but, in my case, the headers to exclude all use #pragma once
instead of header guards.
#ifdef A_BANNED_HEADER_FILE_H
static_assert(false);
#endif
Is there a way to enforce 0 inclusion at compile time?
P.S. For the purpose of avoiding dependency to any class, I could define a class of the same qualified name in the source file and let redefinition error scream at accidental inclusion.
Preventing a header from being included doesn't necessarily prevent any class from being defined.
But you can explicitly demand that a class is not defined in your source file.
// foo.h must not be included, because class foo must not be defined!
// #include "foo.h"
template<typename T> concept is_defined = requires { sizeof(T); };
static_assert( !is_defined<class foo> );
See it work in Compiler Explorer
Note that you don't want the same concept to evaluate differently in the same program, so it's important to avoid any code that expects a different result for is_defined<class foo>