https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90300

            Bug ID: 90300
           Summary: "control reaches end of non-void function" warning
                    despite exhaustive switch for enum class
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maic23 at live dot de
  Target Milestone: ---

GCC can determine if a switch statement on an enum class does not cover all
possible cases. However, even if all cases are covered, GCC will produce a
warning that control may reach the end of a non void function, which is
incorrect.

Steps to reproduce:

$ g++ --version
g++ (GCC) 9.0.1 20190312 (Red Hat 9.0.1-0.10)
$ echo '
enum class Test { A };
int test_to_int(const Test &t) {
  switch (t) {
  case Test::A:
    return 4;
  }
}

int main() {}' | g++ -x c++ -
<stdin>: In function ‘int test_to_int(const Test&)’:
<stdin>:8:1: warning: control reaches end of non-void function [-Wreturn-type]


I am aware that this warning can be worked around by adding a `default:` case,
but that would also disable the warning that not all cases of an enum class are
covered.

Reply via email to