jamieschmeiser wrote: > I think it makes sense for Clang to handle the C Standard Library headers > which can introduce `NULL`, but I'm surprised to see us adding new headers > like `dbm.h`, the `sys` directory, and `unistd,h`.
These other headers define NULL to 0 on AIX and are included through the system include paths. Note that they are guarded to only deal with NULL on AIX and just include_next on other platforms. > Why is the pattern to define `NULL`, include_next the header the user asked > for, and then define `NULL` again? Are the include_next headers defining > `NULL` to something different? And if so, what are we potentially breaking by > redefining it out from under them? (The following relates to AIX, I do not know what happens on other platforms...) Yes, some of the include_next headers are defining NULL to 0, hence the pattern. The definitions are typically guarded such that NULL is not defined if it is already defined. Therefore, it is necessary to force the expected macro before the include_next to ensure that a potentially existing definition is not retained nor a definition of NULL to 0 introduced. The include_next file will now not define the macro since it is already defined but there are ways that the processing of the included files could be unexpected (eg, a header could be replaced) so NULL is forced to the expected definition again after the include_next is processed. Yes, this pattern can potentially break code if the user has defined NULL to something unexpected before including the header but unfortunately, NULL is not a special identifier. The proposed pattern attempts to ensure that the definition is at least consistent within the expected processing of system header files (and after) for those headers that define NULL. There really isn't much more the compiler can do to maintain consistency of the macro and the pattern should provide the correct macro definitions for the overwhelming majority of users. https://github.com/llvm/llvm-project/pull/149176 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits