[libcxx-commits] [libcxx] [libc++] Remove libc++'s own ctype.h (PR #194615)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 28 06:23:30 PDT 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/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.


>From 63bc5ad7ac583c97de1e51bc79c1119db3353163 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 28 Apr 2026 15:22:13 +0200
Subject: [PATCH] [libc++] Remove libc++'s own ctype.h

---
 libcxx/include/CMakeLists.txt      |  1 -
 libcxx/include/cctype              | 65 +-----------------------------
 libcxx/include/ctype.h             | 65 ------------------------------
 libcxx/include/module.modulemap.in |  4 --
 4 files changed, 2 insertions(+), 133 deletions(-)
 delete mode 100644 libcxx/include/ctype.h

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 69a6590d18f85..1e04952614323 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -1007,7 +1007,6 @@ set(files
   cstring
   ctgmath
   ctime
-  ctype.h
   cuchar
   cwchar
   cwctype
diff --git a/libcxx/include/cctype b/libcxx/include/cctype
index abe0ec44e3a64..33d2340633ffc 100644
--- a/libcxx/include/cctype
+++ b/libcxx/include/cctype
@@ -39,13 +39,8 @@ 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_next(<ctype.h>)
+#    include <ctype.h>
 #  endif
 
 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -54,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/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 b7c2ef91be551..3d0008b515c89 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2442,10 +2442,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