You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Triggers an error in GCC, but only a warning in Clang/LLVM.
GCC:
$ gcc -c enumcast.c -o enumcast.oenumcast.c: In function ‘bar_enum’:enumcast.c:10:20: error: incompatible type for argument 1 of ‘foo_enum’ 10 | return foo_enum ((void *) e); | ^~~~~~~~~~ | | | void *enumcast.c:7:22: note: expected ‘enum E’ but argument is of type ‘void *’ 7 | int foo_enum (enum E e); | ~~~~~~~^enumcast.c: In function ‘bar_int’:enumcast.c:16:19: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] 16 | return foo_int ((void *) x); | ^enumcast.c:16:19: warning: passing argument 1 of ‘foo_int’ makes integer from pointer without a cast [-Wint-conversion] 16 | return foo_int ((void *) x); | ^~~~~~~~~~ | | | void *enumcast.c:13:18: note: expected ‘int’ but argument is of type ‘void *’ 13 | int foo_int (int x); | ~~~~^
Clang:
$ clang -c enumcast.c -o enumcast.oenumcast.c:10:20: warning: incompatible pointer to integer conversion passing 'void *' to parameter of type 'enum E' [-Wint-conversion] return foo_enum ((void *) e); ^~~~~~~~~~enumcast.c:7:22: note: passing argument to parameter 'e' hereint foo_enum (enum E e); ^enumcast.c:16:19: warning: cast to 'void *' from smaller integer type 'int' [-Wint-to-void-pointer-cast] return foo_int ((void *) x); ^~~~~~~~~~enumcast.c:16:19: warning: incompatible pointer to integer conversion passing 'void *' to parameter of type 'int' [-Wint-conversion] return foo_int ((void *) x); ^~~~~~~~~~enumcast.c:13:18: note: passing argument to parameter 'x' hereint foo_int (int x); ^3 warnings generated.
It would be good to have the same behavior in both compilers.
Would clang consider to turn that warning into an error? It seems to me that it makes very little sense to pass pointers as enumerated values...
The program below:
Triggers an error in GCC, but only a warning in Clang/LLVM.
GCC:
Clang:
It would be good to have the same behavior in both compilers.
Would clang consider to turn that warning into an error? It seems to me that it makes very little sense to pass pointers as enumerated values...
The related GCC bugzilla is https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107843
The text was updated successfully, but these errors were encountered: