Skip to content

[clang-tidy] readability-implicit-bool-conversion false positive with bool and logical operators in C23 #170596

@Chase-san

Description

@Chase-san

The readability-implicit-bool-conversion check incorrectly warns about implicit bool -> int conversion when using bool values with the && operator, even though both operands are scalar types and this is perfectly valid C.

The warning message is misleading - it suggests a type safety issue when this is actually just normal operation of the && operator. If the intent is to enforce a style preference for explicit comparisons, the warning should clearly state that rather than implying a conversion problem.

This only occurs when clangd is set to "-std=c23".

Expected Behavior

No warning should be issued. The C standard explicitly states that && accepts any scalar type, and bool is a scalar type. There is no implicit conversion issue here.

Actual Behavior

"Warning: Implicit conversion 'bool' -> 'int'" on the returns_bool() call when used with &&.

Environment

clangd version: 21.1.4
C standard: C23
Platform: windows

Example Code

bool returns_bool(void) { return true; }

void test(size_t len) {
    // NO WARNING - bool used directly in condition
    while (returns_bool()) {}
    
    // WARNING: "Implicit conversion 'bool' -> 'int'"
    while ((len > 0) && returns_bool()) {}
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions