[libcxx-commits] [libcxx] [libc++] __need_infinity_nan doesn't work in non-gnu c++ standards (PR #172539)

Ian Anderson via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 16 21:01:39 PST 2025


================
@@ -0,0 +1,54 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// gcc supports "partitial inclusion" of some builtin headers via __need macros.
+// These are implemented in modules via textual headers, which are tricky to
+// support because libc++ needs to know about them and make its corresponding
+// headers textual too so that the macros are passed along.
+//
+// Another wrinkle is that __need macros can be used to force a type to be
+// when it wouldn't normally be. e.g. Apple platforms will use __need_rsize_t
+// to force the declaration of rsize_t to be visible even when
+// __STDC_WANT_LIB_EXT1__ isn't set.
+
+// gcc doesn't support all of the __need macros
+// UNSUPPORTED: gcc
+
+// The __need macros don't fully with in the frozen headers
+// UNSUPPORTED: c++03
+
+// Some of the __need macros are new in clang 22.x and Apple clang 21.x
+// UNSUPPORTED: clang-22, apple-clang-20
+
+// float.h doesn't always define INFINITY and NAN.
+#define __need_infinity_nan
+#include <float.h>
+static void func1() {
+  float value = INFINITY;
+  value       = NAN;
+}
+
+// Make sure that only the __need'ed interfaces are availbale. Note that the
+// C++ headers like <cstdarg> do -not- support partial inclusion, only the
+// "compatibility" headers.
+#define __need_va_list
+#include <stdarg.h>
+static void func2(int param, ...) {
+  va_list args;
+  va_start(args, param); // expected-error {{use of undeclared identifier 'va_start'}}
+}
+
+// stdef.h doesn't always define max_align_t.
+#define __need_max_align_t
+#define __need_size_t
+#include <stddef.h>
+#include <cstdalign>
----------------
ian-twilightcoder wrote:

Oh I didn't know `alignof` was a builtin in C++

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


More information about the libcxx-commits mailing list