Skip to content

[18.1.1][BUG][clang-tidy][bugprone-inc-dec-in-conditions] decltype should not count as a variable "reference" #85838

@Jacobfaib

Description

@Jacobfaib

The new bugprone-inc-dec-in-conditions should not consider decltype() to be a reference of a variable when emitting this check.

int main()
{
    auto foo = 0;
    auto bar = 0;
    if (++foo < static_cast<decltype(foo)>(bar)) { }
    return 0;
}
[<source>:6:9: warning: incrementing and referencing a variable in a complex condition can cause unintended side-effects due to C++'s order of evaluation, consider moving the modification outside of the condition to avoid misunderstandings [bugprone-inc-dec-in-conditions]](javascript:;)
    6 |     if (++foo < static_cast<decltype(foo)>(bar)) { }
      |         ^
[<source>:6:38: note: variable is referenced here](javascript:;)
    6 |     if (++foo < static_cast<decltype(foo)>(bar)) { }
      |                                      ^
1 warning generated.

https://godbolt.org/z/6ahz8qea7

Expected Behavior

No diagnostics emitted for the above code, or, if this check intends to catch ++foo itself, have the diagnostic reference the increment itself.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions