[BUG] -fmodules usage broke with including <cstring> since NDK 29
- Dominant language
- No language data
- Stars
- 2.3k
- Forks
- 310
- PR merge metrics
- No merged PRs in 30d
Description
### Description
The Swift compiler testsuite generates a header for C++ interoperability and checks it using the NDK clang++ for Android, but [it has been broken since NDK 29, though hidden behind](https://github.com/swiftlang/swift/issues/85365#issuecomment-4242063298) the earlier #2230 issue till now.
Reducing it, I get the following simple header and command:
```
> cat free.h
#include
#include
#include
void opaqueFree(void *_Nonnull p) noexcept {
free(p);
}
# works fine with NDK 28
> /home/finagolfin/android-ndk-r28c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -target aarch64-unknown-linux-android23 -isystem /home/finagolfin/android-ndk-r28c/toolchains/llvm/prebuilt/linux-x86_64/sysroot -x c++-header -c free.h -fmodules -fcxx-modules
# breaks with NDK 30 beta 2
> /home/finagolfin/android-ndk-r30-beta2/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -target aarch64-unknown-linux-android23 -isystem /home/finagolfin/android-ndk-r30-beta2/toolchains/llvm/prebuilt/linux-x86_64/sysroot -x c++-header -c free.h -fmodules -fcxx-modules
free.h:5:5: error: missing '#include '; 'free' must be declared before it is used
5 | free(p);
| ^
/home/finagolfin/android-ndk-r30-beta2/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/malloc.h:108:6: note: declaration here is not visible
108 | void free(void* _Nullable __ptr);
| ^
1 error generated.
```
I applied the fix for #2230 to NDK 29 and see the same error with that NDK too. Removing the `-fmodules` flag or the first `` include gets it to not error again.
Since this isn't reproducible with other libc++ platforms, it is most likely a C++ modularity problem caused by some incompatibility between libc++ changes after NDK 28 and the Bionic headers in the NDK.
### I am using a supported NDK
- [x] I have checked and the NDK I'm using is currently supported
### Affected versions
r29, r30
Contributor guide
Assessment
This issue has not been assessed yet.