This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/14849] New: Warning message instead of error message for void function which returns a value
- From: "tonybao at mac dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 4 Apr 2004 21:17:32 -0000
- Subject: [Bug c++/14849] New: Warning message instead of error message for void function which returns a value
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Dear GCC team,
I am a student at University of Wales, Swansea, UK. While working on my third year project I
encountered a bug regarding the following compiler (Apple's Customised gcc Compiler).
gcc -v
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)
The C / C++ program with the ERROR.
void debug() {
return 1;
}
int main() {}
Both gcc and g++ only generated only a warning message
g++ bug.cpp
bug.cpp: In function `void debug()':
bug.cpp:3: warning: return-statement with a value, in function declared with a
void return type
and allowed the this program to build (produced an a.out file).
According to the following sections in the ISO C++ standard,
3.9.1: 9 The void type has an empty set of values. The void type is an incomplete type that cannot be
completed. It is used as the return type for functions that do not return a value. ...
6.6.3: 2: A return statement without an expression can be used only in functions that do not return a
value, that is, a function with the return type void, a constructor (12.1), or a destructor (12.4). A return
statement with an expression of non-void type can be used only in functions returning a value; the
value of the expression is returned to the caller of the function. ...
which leads me to believe that this must be a bug of the compiler. It should report an Error, not an
Warning.
I also tested the same program on Linux platform using the vanilla g++ 3.3.1 and it generated an error
message.
Best regards,
Tony Han Bao
tonybao% g++ -v -save-temps bug.cpp
Reading specs from /usr/libexec/gcc/darwin/ppc/3.3/specs
Thread model: posix
gcc version 3.3 20030304 (Apple Computer, Inc. build 1495)
/usr/libexec/gcc/darwin/ppc/3.3/cc1plus -E -D__GNUG__=3 -quiet -v -D__GNUC__=3
-D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=0 -D__APPLE_CC__=1495 -D__DYNAMIC__ bug.cpp
-fPIC -D__private_extern__=extern bug.ii
ignoring nonexistent directory "/usr/ppc-darwin/include"
ignoring nonexistent directory "/Local/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/gcc/darwin/3.3/c++
/usr/include/gcc/darwin/3.3/c++/ppc-darwin
/usr/include/gcc/darwin/3.3/c++/backward
/usr/local/include
/usr/include/gcc/darwin/3.3
/usr/include
End of search list.
Framework search starts here:
/System/Library/Frameworks
/Library/Frameworks
End of framework search list.
/usr/libexec/gcc/darwin/ppc/3.3/cc1plus -fpreprocessed bug.ii -fPIC -quiet -dumpbase bug.cpp
-auxbase bug -version -D__private_extern__=extern -o bug.s
GNU C++ version 3.3 20030304 (Apple Computer, Inc. build 1495) (ppc-darwin)
compiled by GNU C version 3.3 20030304 (Apple Computer, Inc. build 1495).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=131072
bug.cpp: In function `void debug()':
bug.cpp:4: warning: return-statement with a value, in function declared with a
void return type
/usr/libexec/gcc/darwin/ppc/as -arch ppc -o bug.o bug.s
ld -arch ppc -dynamic -o a.out -lcrt1.o -lcrt2.o -L/usr/lib/gcc/darwin/3.3 -L/usr/lib/gcc/darwin -L/
usr/libexec/gcc/darwin/ppc/3.3/../../.. bug.o -lstdc++ -lgcc -lSystem |
c++filt3
--
Summary: Warning message instead of error message for void
function which returns a value
Product: gcc
Version: 3.3
Status: UNCONFIRMED
Severity: minor
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tonybao at mac dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14849