This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/67693] New: Spurious warning: control reaches end of non-void function [-Wreturn-type]
- From: "larsch at belunktum dot dk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 23 Sep 2015 11:40:59 +0000
- Subject: [Bug c++/67693] New: Spurious warning: control reaches end of non-void function [-Wreturn-type]
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67693
Bug ID: 67693
Summary: Spurious warning: control reaches end of non-void
function [-Wreturn-type]
Product: gcc
Version: 5.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: larsch at belunktum dot dk
Target Milestone: ---
gcc 4.5.3 through to 5.2.0 all warn about reaching end of non-void function on
this code:
struct foo { ~foo(); };
int f(int n, int m) {
foo x; // Remove this to get rid of warning
switch (n) {
case 0:
if (n == 4)
return 1;
else
return 2;
break; // Or remove this
default:
return 0;
}
}
Output:
source.cpp: In function 'int f(int, int)':
14 : warning: control reaches end of non-void function [-Wreturn-type]
Command line:
gcc -Wall -O0 source.cpp
Platforms: x86/arm/arm64.
Other info:
Removing the variable 'x' gets rid of the warning. So does removing the
(unnecessary, but valid) 'break' statement. Adding optimization (-O1 or more)
eliminates the warning.