Skip to content

-Wc++-compat should warn on implicit conversions from int to enum #37027

Closed
@tobiasgrosser

Description

@tobiasgrosser
Bugzilla Link 37679
Version trunk
OS Linux

Extended Description

$cat /tmp/test.c 
enum ENUM {
        ENUM_A,
        ENUM_B,
};

enum ENUM foo() {
        int x;
        enum ENUM e;

        e = x; // should warn
        x = e; // no warning
        return x; // should warn
}

enum ENUM bar() {
        return ENUM_A; // no warning
}

gcc warns here when using -Wc++-compat.

$gcc -Wc++-compat /tmp/test.c -c
/tmp/test.c: In function ‘foo’:
/tmp/test.c:10:4: warning: enum conversion in assignment is invalid in C++ [-Wc++-compat]
e = x; // should warn
^
/tmp/test.c:12:9: warning: enum conversion in return is invalid in C++ [-Wc++-compat]
return x; // should warn
^

clang does not warn, but should.

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