Skip to content

Warnings about nonsensical comparisons are disabled if macro expansion is involved #12835

@llunak

Description

@llunak
Bugzilla Link 12463
Version trunk
OS Linux
Attachments clang patch, clang patch

Extended Description

$ cat a.cpp
#define FOO "foo"
#define BAR "bar"
bool foo()
    {
    bool b;
    b = FOO == BAR;
    b = "foo" == "bar";
    return b;
    }
$ clang++ -Wall a.cpp -c
a.cpp:7:15: warning: result of comparison against a string literal is unspecified (use strncmp instead) [-Wstring-compare]
    b = "foo" == "bar";
        ~~~~~ ^
1 warning generated.                                                                                                         

Line 6 should generate a warning as well. As the warning says, the result of such a comparison is unspecified, so it is never correct, even if it comes from a macro expansion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillaclang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions