Page MenuHome
Paste P1290

(An Untitled Masterwork)
ActivePublic

Authored by Sergey Sharybin (sergey) on Mar 10 2020, 3:22 PM.
// GCC case: gcc-9 -Wall -Wextra
// Clang case: clang-9 -Wall -Wextra
typedef enum MyEnum {
A,
B,
C,
} MyEnum;
typedef enum MyOtherEnum {
D,
E,
F,
} MyOtherEnum;
void foo(MyEnum a) {
(void)a;
}
void bar(MyOtherEnum a) {
(void)a;
}
void baz(void* a) {
(void)a;
}
int main() {
foo(10);
foo(A | D);
bar(10);
bar(A | D);
foo(D); // Fine GCC (implicitly from MyEnum -> int -> MyOtherEnum).
// Warning in Clang.
bar(A); // Fine GCC (implicitly from MyOtherEnum -> int -> MyEnum).
// Warning in Clang.
baz(A); // Fine in GCC (A is value of 0, which can be implicitly converted to pointer).
// Warning in Clang.
baz(D); // Fine in GCC (A is value of 0, which can be implicitly converted to pointer).
// Warning in Clang.
baz(B); // Warning in GCC,
// Warning in Clang.
baz(C); // Warning in GCC.
// Warning in Clang.
return 0;
}

Event Timeline

Sergey Sharybin (sergey) created this object with edit policy "Administrators".
Sergey Sharybin (sergey) edited the content of this paste. (Show Details)
Sergey Sharybin (sergey) updated the paste's language from autodetect to c.