Why is canonical type _Bool instead of bool?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why is canonical type _Bool instead of bool?

Manas via cfe-dev
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++.

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
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Why is canonical type _Bool instead of bool?

Manas via cfe-dev
On Wed, Oct 14, 2020 at 5:36 AM Ray Zhang via cfe-dev
<[hidden email]> 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
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev