Undefined return type (mis-)reported as fatal error
Bob Green
rgreen@etnus.com
Wed Mar 29 19:10:00 GMT 2000
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
More information about the Gcc-bugs
mailing list