Issue 115345
Summary [Clang] `switch` statement: an enum value does not always have to equal one of the enumerators.
Labels clang
Assignees
Reporter bjacob
    In this [compiler explorer experiment](https://godbolt.org/z/4ro4ncTzo), GCC warns "warning: control reaches end of non-void function", while Clang does not. 

In this instance, GCC is making an important point: the function `f` cannot assume that its parameter of enum type has a value that is one of the enumerator values, because this enumerator has a a fixed underlying type (the `: int` in the enum declaration) and the standard says that in that case, any integer of that underlying type may be casted to this enum type: https://eel.is/c++draft/expr.static.cast#9

Currently, GCC always warns regardless of having a specified underlying type in the enum declaration ; Clang never warns.  If my understanding of the spec is correct then the reachability of the end of the function (and therefore, the rationale for generating a warning) is when there is no specified underlying type.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to