[libcxx-commits] [libcxx] be8e084 - [libc++] Remove libc++'s own ctype.h (#194615)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun May 3 23:28:28 PDT 2026
Author: Nikolas Klauser
Date: 2026-05-04T08:28:24+02:00
New Revision: be8e0842a103e3dfa276572dd4e4d798759e7e4d
URL: https://github.com/llvm/llvm-project/commit/be8e0842a103e3dfa276572dd4e4d798759e7e4d
DIFF: https://github.com/llvm/llvm-project/commit/be8e0842a103e3dfa276572dd4e4d798759e7e4d.diff
LOG: [libc++] Remove libc++'s own ctype.h (#194615)
Our own `ctype.h` only `#undef`s macros which the C header might define.
None of the libcs we support define any of these functions as macros, so
we can simply drop the header.
Added:
Modified:
libcxx/include/CMakeLists.txt
libcxx/include/__cxx03/cctype
libcxx/include/cctype
libcxx/include/module.modulemap.in
Removed:
libcxx/include/ctype.h
################################################################################
diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 497aadfd799bf..df4909e3ee00c 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -1009,7 +1009,6 @@ set(files
cstring
ctgmath
ctime
- ctype.h
cuchar
cwchar
cwctype
diff --git a/libcxx/include/__cxx03/cctype b/libcxx/include/__cxx03/cctype
index e074f5410efa8..98df6548c8cde 100644
--- a/libcxx/include/__cxx03/cctype
+++ b/libcxx/include/__cxx03/cctype
@@ -36,13 +36,11 @@ int toupper(int c);
#include <__cxx03/__config>
-#include <ctype.h>
-
-#ifndef _LIBCPP_CTYPE_H
-# error <cctype> tried including <ctype.h> but didn't find libc++'s <ctype.h> header. \
- This usually means that your header search paths are not configured properly. \
- The header search paths should contain the C++ Standard Library headers before \
- any C Standard Library.
+#if __has_include(<ctype.h>)
+# include <ctype.h>
+# ifdef _LIBCPP_CTYPE_H
+# error "If libc++ starts defining <ctype.h>, the __has_include check should move to libc++'s <ctype.h>"
+# endif
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -51,62 +49,6 @@ int toupper(int c);
_LIBCPP_BEGIN_NAMESPACE_STD
-#ifdef isalnum
-# undef isalnum
-#endif
-
-#ifdef isalpha
-# undef isalpha
-#endif
-
-#ifdef isblank
-# undef isblank
-#endif
-
-#ifdef iscntrl
-# undef iscntrl
-#endif
-
-#ifdef isdigit
-# undef isdigit
-#endif
-
-#ifdef isgraph
-# undef isgraph
-#endif
-
-#ifdef islower
-# undef islower
-#endif
-
-#ifdef isprint
-# undef isprint
-#endif
-
-#ifdef ispunct
-# undef ispunct
-#endif
-
-#ifdef isspace
-# undef isspace
-#endif
-
-#ifdef isupper
-# undef isupper
-#endif
-
-#ifdef isxdigit
-# undef isxdigit
-#endif
-
-#ifdef tolower
-# undef tolower
-#endif
-
-#ifdef toupper
-# undef toupper
-#endif
-
using ::isalnum _LIBCPP_USING_IF_EXISTS;
using ::isalpha _LIBCPP_USING_IF_EXISTS;
using ::isblank _LIBCPP_USING_IF_EXISTS;
diff --git a/libcxx/include/cctype b/libcxx/include/cctype
index abe0ec44e3a64..f97cfefee281d 100644
--- a/libcxx/include/cctype
+++ b/libcxx/include/cctype
@@ -39,13 +39,11 @@ int toupper(int c);
#else
# include <__config>
-# include <ctype.h>
-
-# ifndef _LIBCPP_CTYPE_H
-# error <cctype> tried including <ctype.h> but didn't find libc++'s <ctype.h> header. \
- This usually means that your header search paths are not configured properly. \
- The header search paths should contain the C++ Standard Library headers before \
- any C Standard Library.
+# if __has_include(<ctype.h>)
+# include <ctype.h>
+# ifdef _LIBCPP_CTYPE_H
+# error "If libc++ starts defining <ctype.h>, the __has_include check should move to libc++'s <ctype.h>"
+# endif
# endif
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -54,62 +52,6 @@ int toupper(int c);
_LIBCPP_BEGIN_NAMESPACE_STD
-# ifdef isalnum
-# undef isalnum
-# endif
-
-# ifdef isalpha
-# undef isalpha
-# endif
-
-# ifdef isblank
-# undef isblank
-# endif
-
-# ifdef iscntrl
-# undef iscntrl
-# endif
-
-# ifdef isdigit
-# undef isdigit
-# endif
-
-# ifdef isgraph
-# undef isgraph
-# endif
-
-# ifdef islower
-# undef islower
-# endif
-
-# ifdef isprint
-# undef isprint
-# endif
-
-# ifdef ispunct
-# undef ispunct
-# endif
-
-# ifdef isspace
-# undef isspace
-# endif
-
-# ifdef isupper
-# undef isupper
-# endif
-
-# ifdef isxdigit
-# undef isxdigit
-# endif
-
-# ifdef tolower
-# undef tolower
-# endif
-
-# ifdef toupper
-# undef toupper
-# endif
-
using ::isalnum _LIBCPP_USING_IF_EXISTS;
using ::isalpha _LIBCPP_USING_IF_EXISTS;
using ::isblank _LIBCPP_USING_IF_EXISTS;
diff --git a/libcxx/include/ctype.h b/libcxx/include/ctype.h
deleted file mode 100644
index b2f83ca1c1aa4..0000000000000
--- a/libcxx/include/ctype.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// 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
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP_CTYPE_H
-#define _LIBCPP_CTYPE_H
-
-/*
- ctype.h synopsis
-
-int isalnum(int c);
-int isalpha(int c);
-int isblank(int c); // C99
-int iscntrl(int c);
-int isdigit(int c);
-int isgraph(int c);
-int islower(int c);
-int isprint(int c);
-int ispunct(int c);
-int isspace(int c);
-int isupper(int c);
-int isxdigit(int c);
-int tolower(int c);
-int toupper(int c);
-*/
-
-#if defined(__cplusplus) && __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
-# include <__cxx03/__config>
-#else
-# include <__config>
-#endif
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-# pragma GCC system_header
-#endif
-
-#if __has_include_next(<ctype.h>)
-# include_next <ctype.h>
-#endif
-
-#ifdef __cplusplus
-
-# undef isalnum
-# undef isalpha
-# undef isblank
-# undef iscntrl
-# undef isdigit
-# undef isgraph
-# undef islower
-# undef isprint
-# undef ispunct
-# undef isspace
-# undef isupper
-# undef isxdigit
-# undef tolower
-# undef toupper
-
-#endif
-
-#endif // _LIBCPP_CTYPE_H
diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index a6f9c5f9f2d09..ae2c95db7d0e3 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2445,10 +2445,6 @@ module std_complex_h [system] {
header "complex.h"
export *
}
-module std_ctype_h [system] {
- header "ctype.h"
- export *
-}
module std_errno_h [system] {
header "errno.h"
export *
More information about the libcxx-commits
mailing list