Hi, This patch implements clang's __has_feature and __has_extension in GCC. Currently the patch aims to implement all documented features (and some undocumented ones) following the documentation at https://clang.llvm.org/docs/LanguageExtensions.html with the following omissions: - C++ type traits. - Objective-C-specific features. C++ type traits aren't currently implemented since, as the clang documentation notes, __has_builtin is the correct "modern" way to query for these (which GCC already implements). Of course there's an argument that we should recognize the legacy set of C++ type traits that can be queried through __has_feature for backwards compatibility with older code. I'm happy to do this if reviewers think that's a good idea. There are some comments in the patch marked with XXX, I'm looking for review comments from C/C++ maintainers on those areas in particular. Bootstrapped/regtested on aarch64-linux-gnu. Any comments? Thanks, Alex gcc/c-family/ChangeLog: PR c++/60512 * c-common.cc (struct hf_feature_info): New. (has_generic_feature_p): New. * c-common.h (c_common_has_feature): New. (has_generic_feature_p): New. (has_lang_feature_p): New. * c-lex.cc (init_c_lex): Plumb through has_feature callback. (c_common_has_builtin): Adapt into more generic helper function. Rename to ... (c_common_lex_availability_macro): ... this. (c_common_has_feature): New. * c-ppoutput.cc (init_pp_output): Plumb through has_feature callback. gcc/c/ChangeLog: PR c++/60512 * c-objc-common.cc (struct c_feature_info): New. (has_lang_feature_p): New. gcc/cp/ChangeLog: PR c++/60512 * cp-objcp-common.cc (struct cp_feature_selector): New. (cp_feature_selector::has_feature): New. (struct cp_feature_info): New. (has_lang_feature_p): New. gcc/ChangeLog: PR c++/60512 * doc/cpp.texi: Document __has_{feature,extension}. libcpp/ChangeLog: PR c++/60512 * include/cpplib.h (struct cpp_callbacks): Add has_feature callback. (enum cpp_builtin_type): Add types for __has_{feature,extension}. * init.cc (builtin_array): Add entries for __has_{feature,extension}. * macro.cc (_cpp_builtin_macro_text): Handle BT_HAS_{FEATURE,EXTENSION}. gcc/testsuite/ChangeLog: PR c++/60512 * c-c++-common/has-feature-common.c: New test. * g++.dg/ext/has-feature.C: New test. * gcc.dg/asan/has-feature-asan.c: New test. * gcc.dg/has-feature.c: New test.