
The multiple-include optimization allows Clang to avoid opening a files when they contain #pragma once or a proper include guard. Both GCC and Microsoft Visual Studio allow null directives outside of the #ifndef/#endif pair without disabling this multiple-include optimization. GCC documents this behavior here https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html. > There must be no directives outside the controlling directive pair, > but the null directive (a line containing nothing other than a > single '#' and possibly whitespace) is permitted. However, Clang disables the multiple-include optimization when encountering the null directive. In particular, this slows down preprocessing of most projects that depend on boost as many boost libraries depend on the boost preprocessor library, which contains null directives outside the include guard on every header file. Differential Revision: https://reviews.llvm.org/D147928
19 lines
276 B
C
19 lines
276 B
C
# // null directive and comments before include guard
|
|
|
|
#ifndef MULTIPLE_INCLUSION_OPT
|
|
|
|
int foo();
|
|
|
|
// The position of the define should not matter
|
|
#define MULTIPLE_INCLUSION_OPT
|
|
|
|
int bar();
|
|
|
|
#endif
|
|
|
|
#
|
|
#
|
|
/* Two null directives
|
|
and a multiline comment
|
|
after the #endif */
|