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

            Bug ID: 120857
           Summary: The wording of the warning issued by Wreturn-type is
                    overly confident for the current implementation
           Product: gcc
           Version: 16.0
               URL: https://godbolt.org/z/xn5Th8avT
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tiborgyri at gmail dot com
                CC: tiborgyri at gmail dot com
  Target Milestone: ---

As discussed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67629, the current
implementation for issuing -Wreturn-type warnings is relatively simplistic and
has limitations due to how early it runs. This results in false positive
warnings being issued even in cases where it is trivial that control cannot
reach the end of the function, such as this:

int foo (bool a) {
    if (a) return 0;
    else if (!a) return 1;
}

Despite these current (as of GCC 16 trunk) (and longstanding) limitations, the
message emitted is extremely confident:

warning: control reaches end of non-void function [-Wreturn-type]

The wording unambiguously states that control reaches the end, without any
shred of uncertainty. I feel like given how easy it is to run into a false
positive, this is overly confident wording. The issue is made worse by the fact
that Wreturn-type is enabled by default for C++.

I propose that GCC should be more honest about the limitations of its
implementations, such as by changing this message to the following:

warning: cannot prove that control does not reach end of non-void function
[-Wreturn-type]

This message would be clear about the condition being detected and the limited
trust the user should put into the current implementation.

Reply via email to