[libcxx-commits] [libcxx] [libcxxabi] [libc++][RFC] Always define internal feature test macros (PR #89178)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 19 09:22:45 PDT 2024


================
@@ -0,0 +1,104 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "internal_ftm_use.hpp"
+
+#include <clang/Lex/Lexer.h>
+#include <clang/Lex/PPCallbacks.h>
+#include <clang/Lex/Preprocessor.h>
+
+#include <string>
+
+namespace libcpp {
+namespace {
+std::array valid_macros{
+    // Public API macros
+    "_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER",
+    "_LIBCPP_HAS_ASAN_CONTAINER_ANNOTATIONS_FOR_ALL_ALLOCATORS",
+
+    // TODO: Why does this macro even exist?
+    "_LIBCPP_HAS_NO_TREE_BARRIER",
+
+    // Configuration macros
+    "_LIBCPP_HAS_NO_TIME_ZONE_DATABASE",
+    "_LIBCPP_HAS_NO_FILESYSTEM",
+    "_LIBCPP_HAS_NO_LOCALIZATION",
+    "_LIBCPP_HAS_NO_THREADS",
+    "_LIBCPP_HAS_NO_MONOTONIC_CLOCK",
+    "_LIBCPP_HAS_MUSL_LIBC",
+    "_LIBCPP_HAS_NO_WIDE_CHARACTERS",
+    "_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS",
+    "_LIBCPP_HAS_NO_RANDOM_DEVICE",
+    "_LIBCPP_HAS_NO_UNICODE",
+    "_LIBCPP_HAS_NO_TERMINAL",
+
+    // Atomic API macros
+    "_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP",
+    "_LIBCPP_HAS_GCC_ATOMIC_IMP",
+    "_LIBCPP_HAS_C_ATOMIC_IMP",
+
+    // Thread API macros
+    "_LIBCPP_HAS_THREAD_API_PTHREAD",
+    "_LIBCPP_HAS_THREAD_API_WIN32",
+    "_LIBCPP_HAS_THREAD_API_EXTERNAL",
+    "_LIBCPP_HAS_THREAD_API_C11",
+
+    // Experimental features
+    "_LIBCPP_HAS_NO_EXPERIMENTAL_TZDB",
+    "_LIBCPP_HAS_NO_EXPERIMENTAL_SYNCSTREAM",
+    "_LIBCPP_HAS_NO_EXPERIMENTAL_STOP_TOKEN",
+    "_LIBCPP_HAS_NO_INCOMPLETE_PSTL",
+};
+
+class internal_ftm_use_callbacks : public clang::PPCallbacks {
----------------
ldionne wrote:

Can you document what this Clang-tidy check does? Maybe something like

```
// This clang-tidy check ensures that we don't use any _LIBCPP_HAS_FOO macro inside `#ifdef`, `#ifndef` & friends, since the intent is to always use `#if` instead.
```

https://github.com/llvm/llvm-project/pull/89178


More information about the libcxx-commits mailing list