From e508a0190bcea40145bd040532cdcce39cd22fcb Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 22 Jul 2004 01:00:47 +0100 Subject: re PR c/15052 (gcc frontend accepts mismatched function declaration/defintion) PR c/15052 * c-decl.c (grokdeclarator): Only pedwarn for qualified void return type on function definitions. Move other warnings for qualified return type to -Wreturn-type. Do not condition any such warnings on -pedantic. Update comments. (start_function): Only copy function type from previous prototype declaration if return types are compatible. * c-typeck.c (function_types_compatible_p): Don't condition warning for incompatibility of volatile qualifiers on the return type on -pedantic. Update comment. * doc/invoke.texi (-Wreturn-type, -Wextra): Update. testsuite: * gcc.dg/noreturn-5.c: Test qualifiers on function type instead of on return type. * gcc.dg/qual-return-1.c: Use -Wreturn-type. Update expected messages. * gcc.dg/qual-return-2.c: Update expected messages. * gcc.dg/qual-return-3.c, gcc.dg/qual-return-4.c: New tests. From-SVN: r85024 --- gcc/c-decl.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'gcc/c-decl.c') diff --git a/gcc/c-decl.c b/gcc/c-decl.c index c5b50a26312..ac812e3dea7 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4165,21 +4165,15 @@ grokdeclarator (tree declarator, tree declspecs, qualify the return type, not the function type. */ if (type_quals) { - /* Type qualifiers on a function return type are normally - permitted by the standard but have no effect, so give a - warning at -Wextra. Qualifiers on a void return type have - meaning as a GNU extension, and are banned on function - definitions in ISO C. FIXME: strictly we shouldn't - pedwarn for qualified void return types except on function - definitions, but not doing so could lead to the undesirable - state of a "volatile void" function return type not being - warned about, and a use of the function being compiled - with GNU semantics, with no diagnostics under -pedantic. */ - if (VOID_TYPE_P (type) && pedantic && !in_system_header) - pedwarn ("ISO C forbids qualified void function return type"); - else if (extra_warnings - && !(VOID_TYPE_P (type) - && type_quals == TYPE_QUAL_VOLATILE)) + /* Type qualifiers on a function return type are + normally permitted by the standard but have no + effect, so give a warning at -Wreturn-type. + Qualifiers on a void return type are banned on + function definitions in ISO C; GCC used to used them + for noreturn functions. */ + if (VOID_TYPE_P (type) && really_funcdef) + pedwarn ("function definition has qualified void return type"); + else if (warn_return_type) warning ("type qualifiers ignored on function return type"); type = c_build_qualified_type (type, type_quals); @@ -4499,7 +4493,7 @@ grokdeclarator (tree declarator, tree declspecs, if (pedantic && type_quals && ! DECL_IN_SYSTEM_HEADER (decl)) pedwarn ("ISO C forbids qualified function types"); - /* GNU C interprets a `volatile void' return type to indicate + /* GNU C interprets a volatile-qualified function type to indicate that the function does not return. */ if ((type_quals & TYPE_QUAL_VOLATILE) && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (decl)))) @@ -5714,8 +5708,8 @@ start_function (tree declspecs, tree declarator, tree attributes) old_decl = lookup_name_in_scope (DECL_NAME (decl1), current_scope); if (old_decl != 0 && TREE_CODE (TREE_TYPE (old_decl)) == FUNCTION_TYPE && !DECL_BUILT_IN (old_decl) - && (TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (decl1))) - == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (old_decl)))) + && comptypes (TREE_TYPE (TREE_TYPE (decl1)), + TREE_TYPE (TREE_TYPE (old_decl))) && TYPE_ARG_TYPES (TREE_TYPE (decl1)) == 0) { TREE_TYPE (decl1) = TREE_TYPE (old_decl); -- cgit v1.2.1