Skip to content

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

@twaik

Description

@twaik

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:

#include <android/hardware_buffer.h>
__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

  • I have checked and the NDK I'm using is currently supported

Affected versions

r29

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions