This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Undefined return type (mis-)reported as fatal error
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Undefined return type (mis-)reported as fatal error
- From: Bob Green <rgreen at etnus dot com>
- Date: Wed, 29 Mar 2000 22:10:58 -0500
- CC: rgreen at etnus dot com, jdelsign at etnus dot com
g++ 2.95.2 on Intel Solaris 2.6 (but the bug isn't platform dependent).
Try compiling code which declares funtions without explicit return
types. In the old C style, these functions implicitly return int.
E.G. try compiling Xlib.h.
Normally g++ has command line flags -Wreturn-type or -pendantic which
enable a warning message about the missing return type. In 2.95.2 this
message is reported without the command line flags as a fatal error.
This makes compiling X11 programs a tad difficult.
I believe the error is in grokdeclarator in gcc/cp/decl.c near line 9835.
if (in_system_header)
/* Allow it, sigh. */;
else if (pedantic || ! is_main)
^^
+----------------------------------------------wrong
cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type",
dname);
else if (warn_return_type)
cp_warning ("ANSI C++ forbids declaration `%D' with no type",
dname);
type = integer_type_node;
In this code, the error is always reported unless in_system_header or is_main is true.
I believe the code should be
if (in_system_header)
/* Allow it, sigh. */;
else if (pedantic && ! is_main)
^^
+--------------------------------------------correct
cp_pedwarn ("ANSI C++ forbids declaration `%D' with no type",
dname);
else if (warn_return_type)
cp_warning ("ANSI C++ forbids declaration `%D' with no type",
dname);
type = integer_type_node;
In this code, the warnings are only reported if the appropriate command line
flags are set.
Hope this helps,
-Bob Green
Etnus, LLC
rgreen@etnus.com