Commit 61df2ee2 by Richard Stallman

(finish_struct): No pedwarn for field with enum type if size matches int.

(grokdeclarator): No error for void type for extern or global var.

(grokdeclarator): Warn here for volatile fn returning non-void type.
(start_function): Not here.

(grokdeclarator): Don't pass on const and volatile
fron function value type to function type.

From-SVN: r5084
parent d8e29a65
...@@ -4306,6 +4306,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized) ...@@ -4306,6 +4306,13 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
flag_traditional flag_traditional
? NULL_TREE : arg_types); ? NULL_TREE : arg_types);
#endif #endif
/* ANSI seems to say that `const int foo ();'
does not make the function foo const. */
if (constp || volatilep)
type = c_build_type_variant (type, constp, volatilep);
constp = 0;
volatilep = 0;
type = build_function_type (type, arg_types); type = build_function_type (type, arg_types);
declarator = TREE_OPERAND (declarator, 0); declarator = TREE_OPERAND (declarator, 0);
...@@ -4424,12 +4431,18 @@ grokdeclarator (declarator, declspecs, decl_context, initialized) ...@@ -4424,12 +4431,18 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
return type; return type;
} }
/* `void' at top level (not within pointer) /* Aside from typedefs and type names (handle above),
is allowed only in typedefs or type names. `void' at top level (not within pointer)
is allowed only in public variables.
We don't complain about parms either, but that is because We don't complain about parms either, but that is because
a better error message can be made later. */ a better error message can be made later. */
if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM) if (TYPE_MAIN_VARIANT (type) == void_type_node && decl_context != PARM
&& ! ((decl_context != FIELD && TREE_CODE (type) != FUNCTION_TYPE)
&& ((specbits & (1 << (int) RID_EXTERN))
|| (current_binding_level == global_binding_level
&& !(specbits
& ((1 << (int) RID_STATIC) | (1 << (int) RID_REGISTER)))))))
{ {
error ("variable or field `%s' declared void", error ("variable or field `%s' declared void",
IDENTIFIER_POINTER (declarator)); IDENTIFIER_POINTER (declarator));
...@@ -4564,6 +4577,10 @@ grokdeclarator (declarator, declspecs, decl_context, initialized) ...@@ -4564,6 +4577,10 @@ grokdeclarator (declarator, declspecs, decl_context, initialized)
&& ! DECL_IN_SYSTEM_HEADER (decl)) && ! DECL_IN_SYSTEM_HEADER (decl))
pedwarn ("ANSI C forbids const or volatile functions"); pedwarn ("ANSI C forbids const or volatile functions");
if (volatilep
&& TREE_TYPE (TREE_TYPE (decl)) != void_type_node)
warning ("volatile function returns non-void value");
if (extern_ref) if (extern_ref)
DECL_EXTERNAL (decl) = 1; DECL_EXTERNAL (decl) = 1;
/* Record absence of global scope for `static' or `auto'. */ /* Record absence of global scope for `static' or `auto'. */
...@@ -5154,7 +5171,11 @@ finish_struct (t, fieldlist) ...@@ -5154,7 +5171,11 @@ finish_struct (t, fieldlist)
} }
if (DECL_INITIAL (x) && pedantic if (DECL_INITIAL (x) && pedantic
&& TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != integer_type_node
&& TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node) && TYPE_MAIN_VARIANT (TREE_TYPE (x)) != unsigned_type_node
/* Accept an enum that's equivalent to int or unsigned int. */
&& !(TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
&& (TYPE_PRECISION (TREE_TYPE (x))
== TYPE_PRECISION (integer_type_node))))
pedwarn_with_decl (x, "bit-field `%s' type invalid in ANSI C"); pedwarn_with_decl (x, "bit-field `%s' type invalid in ANSI C");
/* Detect and ignore out of range field width. */ /* Detect and ignore out of range field width. */
...@@ -5648,10 +5669,6 @@ start_function (declspecs, declarator, nested) ...@@ -5648,10 +5669,6 @@ start_function (declspecs, declarator, nested)
announce_function (decl1); announce_function (decl1);
if (TREE_THIS_VOLATILE (decl1)
&& TREE_TYPE (decl1) != void_type_node)
warning ("volatile function returns non-void value");
if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0) if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl1))) == 0)
{ {
error ("return-type is an incomplete type"); error ("return-type is an incomplete type");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment