void test(int place_holder, ...) { va_list args; va_start(args, place_holder); bool unicode = va_arg(args, bool); }
Currently, if the second argument is "Bool", it will be casted to "int".
This patch add support for Bool type
Differential D136416
[AST] Support Bool type in va_arg Qfrost911 on Oct 20 2022, 8:54 PM. Authored by
Details
void test(int place_holder, ...) { va_list args; va_start(args, place_holder); bool unicode = va_arg(args, bool); } Currently, if the second argument is "Bool", it will be casted to "int". This patch add support for Bool type
Diff Detail Event TimelineComment Actions
That behavior is required by the standard, which is why we give a warning about it being undefined behavior due to the promotion. For C, see C2x 7.16.1.1p2 ("If type is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined, except for the following cases: ..." and none of the cases apply to bool.) and for C++, see https://eel.is/c++draft/cstdarg.syn#1.sentence-4 which says the same thing in different words. You'll see the same kind of UB if you try to use short instead of bool: https://godbolt.org/z/Kz95vbaY4 Comment Actions Thank you for trying to improve things in Clang! Even if this wasn't the right approach, the effort is still appreciated. :-) BTW, we have been trying to tag issues in GitHub with the "good first issue" label if we think it's a good way to get introduced to the code base. If you're looking for a way to help contribute small fixes to Clang. You can see the list here: https://github.com/llvm/llvm-project/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22 |