Follow up on "Problem with Apple's customised gcc compiler"

Tony Han Bao tonybao@mac.com
Tue Apr 6 21:45:00 GMT 2004


Hi all

A while ago I posted a message to gcc-help looking for help regarding 
Apple's customised gcc compiler (gcc version 3.3 20030304 (Apple 
Computer, Inc. build 1495)) because it produced a warning message 
instead of an error message for the following C++ program.

void debug() {
   return 1;
}

int main() {}

I've decided to submit an bug report to GCC and Apple. (See the end of 
this message for the full bug report and bug id)

This message is a follow up to rectify that the problem I posted is NOT 
a bug of the compiler.

Thank Andrew Pinskia's (pinskia@gcc.gnu.org) quick response, which reads

"Apple's GCC has -fpremissive on by default.  The FSF's GCC does not."

I've checked the compiler option -fpremissive, the man page reads

-fpermissive
            Downgrade messages about nonconformant code from errors to 
warn-
            ings.  By default, G++ effectively sets -pedantic-errors 
without
            -pedantic; this option reverses that.  This behavior and this
            option are superseded by -pedantic, which works as it does 
for GNU
            C.

I tried the command

	g++ -pedantic-errors bug.cpp

and the output is an error message without the a.out file

bug.cpp: In function `void debug()':
bug.cpp:4: error: return-statement with a value, in function declared 
with a
    void return type

Tony Han Bao

PS: If anyone's interested in the details, here is the "bug" number and 
my "bug" report.

GNU Bug #14849
Apple Problem ID # 3611719

---------------------------------------------The Bug 
Report--------------------------------------------------------
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 a 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

[Alyson:~/Desktop/C++] 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 5198 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20040406/bf4340fd/attachment.bin>


More information about the Gcc-help mailing list