[clang] [clang] Warn when builtin names are used outside of invocations (PR #96097)
Mital Ashok via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 29 12:15:57 PDT 2024
MitalAshok wrote:
Looks like `!__is_identifier(<revertible type trait name>)` is used instead of `__has_builtin` sometimes. With this patch, `__is_identifier(<revertible type trait name>)` is true because there's no lparen after the name
In libc++: 7f302f220e7b8727ed1bf8832dcc2d87b897e527 (Pretty easy fix to replace `__has_keyword(__reference_binds_to_temporary)` with `__has_builtin(__reference_binds_to_temporary)` again though)
In WIL which seems to be used by a few people: https://github.com/microsoft/wil/blob/68ab8c19ef557e1006cae6b1b84dedf12c91c9d6/include/wil/wistd_config.h#L249
libstdc++, indirectly through a macro: https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=libstdc%2B%2B-v3/include/bits/c%2B%2Bconfig;h=27302ed392eb163954c5a2d367831dbcb0ead3c3;hp=2e6c880ad95a1cc1dfdead2bbcfb977960172ac5;hb=6aa12274007bccbae2691a9d336c37fe167bb535;hpb=6ea5a23766b8077a503362c4fa6f51de92669c11
These will now all report that those things are identifiers and not available as builtins. It can be supported with the same workaround used for `__has_builtin`. Apparantly `__has_feature(__is_abstract)` is also supposed to be true (https://github.com/llvm/llvm-project/blob/8d4aa1f22ea08b12a7958b681e8a265f78cb349f/clang/docs/LanguageExtensions.rst?plain=1#L1693), but that seems to be broken on main and not a new issue with this patch.
---
Also it doesn't seem ideal to not support things like:
```c++
#define IS_CLASS __is_class
static_assert(!IS_CLASS(void));
```
Since these are supported by GCC and MSVC. Could you check again for an lparen after a macro expansion?
https://github.com/llvm/llvm-project/pull/96097
More information about the cfe-commits
mailing list