This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C99 pedantry patch
- To: gcc-patches at gcc dot gnu dot org
- Subject: C99 pedantry patch
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Date: Fri, 16 Jun 2000 20:43:26 +0100 (BST)
This patch fixes the following points about GCC's pedantic C99
behaviour (at least the first two having I believe been discussed before
but not acted on):
* `long long' is part of C99 and should not get a pedwarn in C99 mode.
* Likewise, duplicate type qualifiers are permitted by C99.
* Implicit int warnings with C99 should be pedwarns so that
-pedantic-errors makes them into errors.
* C99 forbids `return' without a value in a function returning
non-void, so I made this into an unconditional pedwarn if
flag_isoc99.
(An alternative approach to some of the changes where the same warning
may be either a plain warning, or a pedwarn in C99, would be a
pedwarn_c99 or similar function, which does pedwarn () if flag_isoc99
and warning () otherwise.)
Bootstrapped and C testsuite run on i686-pc-linux-gnu; no regressions.
If this is committed, I believe the following changes can be made to my
patch <URL:http://gcc.gnu.org/ml/gcc-patches/2000-06/msg00350.html> to
c9xstatus.html: "idempotent type qualifiers" and "return without
expression not permitted in function that returns a value" can both be
listed as Done instead of Missing.
2000-06-14 Joseph S. Myers <jsm28@cam.ac.uk>
* c-decl.c (grokdeclarator): Don't warn about `long long' in C99.
Make warnings about implicit int be pedwarns in C99. Don't warn
about duplicate type qualifiers in C99.
(start_function): Make warning about implict int return type be a
pedwarn in C99.
* c-lex.c (yylex): Don't warn about `long long' in C99.
* c-typeck.c (c_expand_return): In C99, always pedwarn about
`return' with no value in function returning non-void.
--- c-decl.c.orig Tue Jun 13 00:31:30 2000
+++ c-decl.c Thu Jun 15 11:15:53 2000
@@ -3952,7 +3952,8 @@ grokdeclarator (declarator, declspecs, d
error ("`long long long' is too long for GCC");
else
{
- if (pedantic && ! in_system_header && warn_long_long)
+ if (pedantic && ! flag_isoc99 && ! in_system_header
+ && warn_long_long)
pedwarn ("ANSI C does not support `long long'");
longlong = 1;
}
@@ -4014,7 +4015,9 @@ grokdeclarator (declarator, declspecs, d
warning since it is more explicit. */
if ((warn_implicit_int || warn_return_type) && funcdef_flag)
warn_about_return_type = 1;
- else if (warn_implicit_int || flag_isoc99)
+ else if (flag_isoc99)
+ pedwarn ("type defaults to `int' in declaration of `%s'", name);
+ else if (warn_implicit_int)
warning ("type defaults to `int' in declaration of `%s'", name);
}
@@ -4165,11 +4168,11 @@ grokdeclarator (declarator, declspecs, d
restrictp = !! (specbits & 1 << (int) RID_RESTRICT) + TYPE_RESTRICT (type);
volatilep = !! (specbits & 1 << (int) RID_VOLATILE) + TYPE_VOLATILE (type);
inlinep = !! (specbits & (1 << (int) RID_INLINE));
- if (constp > 1)
+ if (constp > 1 && ! flag_isoc99)
pedwarn ("duplicate `const'");
- if (restrictp > 1)
+ if (restrictp > 1 && ! flag_isoc99)
pedwarn ("duplicate `restrict'");
- if (volatilep > 1)
+ if (volatilep > 1 && ! flag_isoc99)
pedwarn ("duplicate `volatile'");
if (! flag_gen_aux_info && (TYPE_QUALS (type)))
type = TYPE_MAIN_VARIANT (type);
@@ -4523,11 +4526,11 @@ grokdeclarator (declarator, declspecs, d
error ("invalid type modifier within pointer declarator");
}
}
- if (constp > 1)
+ if (constp > 1 && ! flag_isoc99)
pedwarn ("duplicate `const'");
- if (volatilep > 1)
+ if (volatilep > 1 && ! flag_isoc99)
pedwarn ("duplicate `volatile'");
- if (restrictp > 1)
+ if (restrictp > 1 && ! flag_isoc99)
pedwarn ("duplicate `restrict'");
type_quals = ((constp ? TYPE_QUAL_CONST : 0)
@@ -5739,7 +5742,12 @@ start_function (declspecs, declarator, p
}
if (warn_about_return_type)
- warning ("return-type defaults to `int'");
+ {
+ if (flag_isoc99)
+ pedwarn ("return-type defaults to `int'");
+ else
+ warning ("return-type defaults to `int'");
+ }
/* Save the parm names or decls from this function's declarator
where store_parm_decls will find them. */
--- c-lex.c.orig Tue Jun 13 00:31:30 2000
+++ c-lex.c Wed Jun 14 23:16:26 2000
@@ -1783,7 +1783,8 @@ yylex ()
{
if (spec_long_long)
error ("three `l's in integer constant");
- else if (pedantic && ! in_system_header && warn_long_long)
+ else if (pedantic && ! flag_isoc99
+ && ! in_system_header && warn_long_long)
pedwarn ("ANSI C forbids long long integer constants");
spec_long_long = 1;
}
--- c-typeck.c.orig Tue Jun 13 00:31:30 2000
+++ c-typeck.c Wed Jun 14 23:23:40 2000
@@ -6529,8 +6529,14 @@ c_expand_return (retval)
if (!retval)
{
current_function_returns_null = 1;
- if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
- warning ("`return' with no value, in function returning non-void");
+ if ((warn_return_type || flag_isoc99)
+ && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
+ {
+ if (flag_isoc99)
+ pedwarn ("`return' with no value, in function returning non-void");
+ else
+ warning ("`return' with no value, in function returning non-void");
+ }
expand_null_return ();
}
else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
--
Joseph S. Myers
jsm28@cam.ac.uk