Why is canonical type _Bool instead of bool?

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 :slight_smile:

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