Warn about casting an enum variant function

Closes #18154.