Skip to content

[libc++](NFC) Remove unused include caused by wrong __has_include #141328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kikairoya
Copy link
Contributor

The parameter passed to __has_include has to be quoted by <> or ", not both.

@kikairoya kikairoya requested a review from a team as a code owner May 24, 2025 03:31
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label May 24, 2025
@llvmbot
Copy link
Member

llvmbot commented May 24, 2025

@llvm/pr-subscribers-libcxx

Author: Tomohiro Kashiwada (kikairoya)

Changes

The parameter passed to __has_include has to be quoted by &lt;&gt; or ", not both.


Full diff: https://github.com/llvm/llvm-project/pull/141328.diff

1 Files Affected:

  • (modified) libcxx/src/locale.cpp (+1-1)
diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp
index d981d137cf1ba..c15ce54fae23a 100644
--- a/libcxx/src/locale.cpp
+++ b/libcxx/src/locale.cpp
@@ -34,7 +34,7 @@
 #  define _CTYPE_DISABLE_MACROS
 #endif
 
-#if __has_include("<langinfo.h>")
+#if __has_include(<langinfo.h>)
 #  include <langinfo.h>
 #endif
 

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that nobody complained so far, is this even required?

@kikairoya
Copy link
Contributor Author

On linux (or most of other systems), this typo is silently treated as header is not found
But, some compiler variant such as MinGW-GCC raises error as invalid filesystem path.

Anyway, <langinfo.h> has never been included here.

$ uname -ms; gcc -v; clang -v; echo '-------------'; cat test.cc; gcc test.cc; echo '------------------'; clang test.cc
Linux x86_64
組み込み spec を使用しています。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/15.1.1/lto-wrapper
ターゲット: x86_64-pc-linux-gnu
configure 設定: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror
スレッドモデル: posix
サポートされている LTO 圧縮アルゴリズム: zlib zstd
gcc バージョン 15.1.1 20250425 (GCC)
clang version 19.1.7
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/14.2.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/15.1.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/14.2.1
Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1
Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/15.1.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
-------------
#if __has_include("<stdio.h>")
#include <stdio.h>
#endif

int main() {
  puts("ok");
}

test.cc: In function ‘int main()’:
test.cc:6:3: エラー: ‘puts’ was not declared in this scope
    6 |   puts("ok");
      |   ^~~~
------------------
test.cc:6:3: error: use of undeclared identifier 'puts'
    6 |   puts("ok");
      |   ^
1 error generated.
$ uname -ms; gcc -v; clang -v; echo '-------------'; cat test.cc; gcc test.cc; echo '------------------'; clang test.cc
MINGW64_NT-10.0-19045 x86_64
Using built-in specs.
COLLECT_GCC=D:\msys64\ucrt64\bin\gcc.exe
COLLECT_LTO_WRAPPER=D:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/15.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-15.1.0/configure --prefix=/ucrt64 --with-local-prefix=/ucrt64/local --with-native-system-header-dir=/ucrt64/include --libexecdir=/ucrt64/lib --enable-bootstrap --enable-chec
king=release --with-arch=nocona --with-tune=generic --enable-mingw-wildcard --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-thr
eads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-backtrace=yes --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-li
bgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/ucrt64 --with-mpfr
=/ucrt64 --with-mpc=/ucrt64 --with-isl=/ucrt64 --with-pkgversion='Rev5, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-li
bstdcxx-debug --enable-plugin --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.1.0 (Rev5, Built by MSYS2 project)
clang version 20.1.5
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: D:/msys64/ucrt64/bin
-------------
#if __has_include("<stdio.h>")
#include <stdio.h>
#endif

int main() {
  puts("ok");
}

cc1plus.exe: fatal error: <stdio.h>: Invalid argument
compilation terminated.
------------------
test.cc:6:3: error: use of undeclared identifier 'puts'
    6 |   puts("ok");
      |   ^
1 error generated.

The parameter passed to __has_include has to be quoted by `<>` or `"`, not both.
Due to this typo, the guarded header is never included.
No problem has been reported by unconditionally skip of including, so it
would be safe to simply remove the conditionally include block.
@kikairoya kikairoya force-pushed the fix-wrong-__has_include branch from a35faec to 860f2ac Compare May 25, 2025 00:17
@kikairoya kikairoya changed the title [libc++](NFC) fix wrong __has_include [libc++](NFC) Remove unused include caused by wrong __has_include May 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants