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

            Bug ID: 91950
           Summary: -Wreturn-type false positive due to CWG 1766
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: john.boyer at tutanota dot com
  Target Milestone: ---

Given the following code:

enum class foo
{
    bar,
    baz,
};

int func(foo f)
{
    switch (f)
    {
    case foo::bar:
        return 5;
    case foo::baz:
        return 10;
    }
}

GCC will produce the following bug:

source>:16:1: warning: control reaches end of non-void function [-Wreturn-type]

   16 | }

      | ^

This diagnostic is incorrect since CWG 1766:
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1766. Static
casting a number that is not in the range of an enum class is undefined
behavior. It is therefore impossible for standard-compliant code to have an
invalid enum class value, and this diagnostic should not be displayed as
control flow can never reach the end of the function.

Reply via email to