android / android/ndk

[BUG]: Availability error for __typeof__(AHardwareBuffer_acquire) when targeting android24

Open
#2,228 1 comment 0 reactions 1 assignee Claimed by @pirama-arumuga-nainar View on GitHub
bug
Dominant language
No language data
Stars
2.3k
Forks
310
PR merge metrics
No merged PRs in 30d

Description

### Description

`__typeof__(AHardwareBuffer_acquire)` is a type-only query.

It does not call the function, does not require code generation, and does not involve linking. Availability checks should not trigger in this context.

Is this intended, or a bug in availability diagnostics?

I understand that `__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__` can be used, but it makes it easy to accidentally call `AHardwareBuffer_acquire` instead of, for example, `pAHardwareBuffer_acquire`, which can lead to a segmentation fault due to a null function pointer. If type-only usage were allowed, it would be possible to define simple wrappers or substitutes that could be called uniformly (e.g., `pAHardwareBuffer_acquire`) without the risk of accidentally invoking the original function.

Minimal repro:
```c
#include
__typeof__(AHardwareBuffer_acquire)* p = NULL;
```
Build with something like
```
~/Android/Sdk/ndk/29.0.14206865/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang ./test.c
```
Result:
```
./test.c:3:12: error: 'AHardwareBuffer_acquire' is unavailable: introduced in Android 26 android
3 | __typeof__(AHardwareBuffer_acquire)* p = NULL;
| ^
/home/twaik/Android/Sdk/ndk/29.0.14206865/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/android/hardware_buffer.h:432:6: note: 'AHardwareBuffer_acquire' has been explicitly marked unavailable here
432 | void AHardwareBuffer_acquire(AHardwareBuffer* _Nonnull buffer) __INTRODUCED_IN(26);
| ^
1 error generated.
```

### I am using a supported NDK

- [x] I have checked and the NDK I'm using is currently supported

### Affected versions

r29

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.