[cfe-dev] Why is canonical type _Bool instead of bool?

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 14 04:55:19 PDT 2020


On Wed, Oct 14, 2020 at 5:36 AM Ray Zhang via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> Hi,
>
> When canonicalizing bools, the resulting value is equal to _Bool(which is a C99 thing). The tool I'm developing is turning expressions such as
>
> (bool) 3.2f;
>
> into:
>
> static_cast<_Bool>(3.2f);
>
> Is there some way I can set this to not be the case when parsing C++ files? The closest thing that seemed to make sense was to set language options but I don't see where I can explicitly only support C++.

If you are printing the type out, that behavior is controlled by the
printing policy which get set up from the language options:
https://github.com/llvm/llvm-project/blob/d5ea89f8914fcf7e5f637202c6972cb14617d93d/clang/include/clang/AST/PrettyPrinter.h#L172
and https://github.com/llvm/llvm-project/blob/d5ea89f8914fcf7e5f637202c6972cb14617d93d/clang/include/clang/AST/PrettyPrinter.h#L58

HTH!

~Aaron

>
> Best,
> Ray Zhang
>
> P.S. I'm fairly close to finishing the entire tool and am hoping to contribute it into clang-tools-extra :)
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


More information about the cfe-dev mailing list