libcpp: Use `__has_include` for alternate header checks to support custom standard libraries.
libcpp now uses `__has_include` to check for alternate headers, preventing hard errors when a custom standard library is used.
This change modifies libcpp’s behavior when translating standard library #include directives to module imports, specifically for <bits/stdc++.h>. Previously, if stdc++.h did not exist, libcpp would raise a hard error, breaking compatibility with alternate standard library implementations. By using the __has_include mechanism, the check now fails silently, allowing programs to use custom standard libraries without encountering compilation errors.
In Details
This commit updates libcpp/files.cc to use _cpp_FFK_HAS_INCLUDE (which maps to the __has_include preprocessor directive) within the _cpp_stack_include function. The context is the translation of standard library includes (like #include <vector>) to module imports (like import <vector>), particularly the special case of import <bits/stdc++.h>. If the underlying standard library implementation doesn't provide bits/stdc++.h (or an equivalent), the previous logic would error out. Using __has_include allows the preprocessor to conditionally check for the header's existence withou…
- libcpp
- The C++ standard library implementation used by the LLVM Clang compiler.
- header file
- A file, typically with a
.hor.hppextension, that contains C or C++ declarations and definitions. These are included in source files using the#includedirective. - module import
- A C++20 feature that allows for more efficient and organized inclusion of code compared to traditional header files. It uses
importinstead of#include. - bits/stdc++.h
- A convenience header file in some C++ standard library implementations (like GCC's libstdc++) that includes most of the standard library headers. Its use is non-standard and discouraged in production code.
- __has_include
- A preprocessor operator introduced in C++17 that checks if a header file can be included. It returns true if the header exists and can be included, and false otherwise. It's typically used in conditional compilation directives like
#if. - dejagnu
- A testing framework commonly used by GCC and other projects to test compilers and other tools.