[libc-commits] [libc] [libc] add support for function level attributes (PR #79891)
Nick Desaulniers via libc-commits
libc-commits at lists.llvm.org
Mon Feb 12 13:00:46 PST 2024
nickdesaulniers wrote:
> Demo macro:
```c
#if !defined(__LIBC_CONST_ATTR) && defined(__cplusplus) && defined(__GNUC__)
#if __has_attribute(const)
#define __LIBC_CONST_ATTR [[gnu::const]]
#endif
#endif
#if !defined(__LIBC_CONST_ATTR) && defined(__GNUC__)
#if __has_attribute(const)
#define __LIBC_CONST_ATTR __attribute__((const))
#endif
#endif
#if !defined(__LIBC_CONST_ATTR)
#define __LIBC_CONST_ATTR
#endif
```
Can you please change this to:
```
#ifndef __LIBC_CONST_ATTR
#if __has_attribute(const)
#ifdef __cplusplus
#define __LIBC_CONST_ATTR [[gnu::const]]
#else
#define __LIBC_CONST_ATTR __attribute__((const))
#endif // __cplusplus
#else
#define __LIBC_CONST_ATTR
#endif // __has_attribute(const)
#endif // __LIBC_CONST_ATTR
```
There's no point checking for `__GNUC__` or `!defined(__LIBC_CONST_ATTR)` twice.
https://github.com/llvm/llvm-project/pull/79891
More information about the libc-commits
mailing list