Skip to content

misc-redundant-expression: expression with calls to a non-pure function is considered as always-true #35853

@pavelkryukov

Description

@pavelkryukov
Bugzilla Link 36505
Version unspecified
OS Windows NT
Attachments Example of always-true false positive with calls to a non-pure function
CC @EugeneZelenko,@Xazax-hun

Extended Description

Clang-Tidy produces a false positive warning about always-true expression (misc-redundant-expression check) if expression contains consequent calls to a non-pure function which have different return values:

$> clang-tidy -checks='*' ldfile.c -- -Wall
15 warnings generated.
./ldfile.c:11:32: warning: logical expression is always true [misc-redundant-expression]
    if ((token = yylex()) != 1 || (token = yylex()) != 2) {
                               ^
Suppressed 14 warnings (14 in non-user code).

$> clang ldfile.c -Wall -Wextra && ./a.out
false

The code is taken from GNU Binutils (/ld/ldfile.c) source file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions