Commit 9f33663b by Jason Merrill Committed by Jason Merrill

decl.c (warn_extern_redeclared_static): Check DECL_ARTIFICIAL...

	* decl.c (warn_extern_redeclared_static): Check DECL_ARTIFICIAL,
	not DECL_BUILT_IN, to determine if a function is internally declared.
	(duplicate_decls): Likewise.  Improve handling of builtins.
	(push_overloaded_decl): Remove special handling of builtins.

	* cp-tree.h (ANON_AGGR_TYPE_P): Use CLASS_TYPE_P.

	* decl.c (grokdeclarator): Pull out decl_constant_value in
	templates, too.

	* class.c (finish_struct, finish_struct_1): Remove 'warn_anon' parm.
	* cp-tree.h, pt.c, semantics.c: Adjust.
	* method.c (largest_union_member): Remove.

From-SVN: r28204
parent aad23121
1999-07-20 Jason Merrill <jason@yorick.cygnus.com>
* decl.c (warn_extern_redeclared_static): Check DECL_ARTIFICIAL,
not DECL_BUILT_IN, to determine if a function is internally declared.
(duplicate_decls): Likewise. Improve handling of builtins.
(push_overloaded_decl): Remove special handling of builtins.
* cp-tree.h (ANON_AGGR_TYPE_P): Use CLASS_TYPE_P.
* decl.c (grokdeclarator): Pull out decl_constant_value in
templates, too.
* class.c (finish_struct, finish_struct_1): Remove 'warn_anon' parm.
* cp-tree.h, pt.c, semantics.c: Adjust.
* method.c (largest_union_member): Remove.
* lang-specs.h (c++-cpp-output): Pass -fpreprocessed.
* lex.c (token_getch, token_put_back): New fns.
......
......@@ -3202,9 +3202,8 @@ add_fields_to_vec (fields, field_vec, idx)
ATTRIBUTES is the set of decl attributes to be applied, if any. */
void
finish_struct_1 (t, warn_anon)
finish_struct_1 (t)
tree t;
int warn_anon;
{
int old;
enum tree_code code = TREE_CODE (t);
......@@ -4279,9 +4278,8 @@ unreverse_member_declarations (t)
}
tree
finish_struct (t, attributes, warn_anon)
finish_struct (t, attributes)
tree t, attributes;
int warn_anon;
{
/* Append the fields we need for constructing signature tables. */
if (IS_SIGNATURE (t))
......@@ -4299,7 +4297,7 @@ finish_struct (t, attributes, warn_anon)
TYPE_SIZE (t) = integer_zero_node;
}
else
finish_struct_1 (t, warn_anon);
finish_struct_1 (t);
TYPE_BEING_DEFINED (t) = 0;
......
......@@ -1848,8 +1848,7 @@ extern int flag_new_for_scope;
flag for this because "A union for which objects or pointers are
declared is not an anonymous union" [class.union]. */
#define ANON_AGGR_TYPE_P(NODE) \
(TYPE_LANG_SPECIFIC (NODE) \
&& TYPE_LANG_SPECIFIC (NODE)->type_flags.anon_aggr)
(CLASS_TYPE_P (NODE) && TYPE_LANG_SPECIFIC (NODE)->type_flags.anon_aggr)
#define SET_ANON_AGGR_TYPE_P(NODE) \
(TYPE_LANG_SPECIFIC (NODE)->type_flags.anon_aggr = 1)
......@@ -2763,8 +2762,8 @@ extern void add_method PROTO((tree, tree *, tree));
extern int currently_open_class PROTO((tree));
extern tree get_vfield_offset PROTO((tree));
extern void duplicate_tag_error PROTO((tree));
extern tree finish_struct PROTO((tree, tree, int));
extern void finish_struct_1 PROTO((tree, int));
extern tree finish_struct PROTO((tree, tree));
extern void finish_struct_1 PROTO((tree));
extern int resolves_to_fixed_type_p PROTO((tree, int *));
extern void init_class_processing PROTO((void));
extern int is_empty_class PROTO((tree));
......
......@@ -3048,8 +3048,7 @@ warn_extern_redeclared_static (newdecl, olddecl)
if (! (TREE_CODE (newdecl) == FUNCTION_DECL
&& olddecl != NULL_TREE
&& TREE_CODE (olddecl) == FUNCTION_DECL
&& (DECL_BUILT_IN (olddecl)
|| DECL_BUILT_IN_NONANSI (olddecl))))
&& DECL_ARTIFICIAL (olddecl)))
{
cp_pedwarn (IDENTIFIER_IMPLICIT_DECL (name)
? implicit_extern_static_warning
......@@ -3092,44 +3091,58 @@ duplicate_decls (newdecl, olddecl)
/* Check for redeclaration and other discrepancies. */
if (TREE_CODE (olddecl) == FUNCTION_DECL
&& DECL_ARTIFICIAL (olddecl)
&& (DECL_BUILT_IN (olddecl) || DECL_BUILT_IN_NONANSI (olddecl)))
{
/* If you declare a built-in or predefined function name as static,
the old definition is overridden, but optionally warn this was a
bad choice of name. Ditto for overloads. */
if (! TREE_PUBLIC (newdecl)
|| (TREE_CODE (newdecl) == FUNCTION_DECL
&& DECL_LANGUAGE (newdecl) != DECL_LANGUAGE (olddecl)))
{
if (warn_shadow)
cp_warning ("shadowing %s function `%#D'",
DECL_BUILT_IN (olddecl) ? "built-in" : "library",
&& DECL_ARTIFICIAL (olddecl))
{
if (TREE_CODE (newdecl) != FUNCTION_DECL)
{
/* If you declare a built-in or predefined function name as static,
the old definition is overridden, but optionally warn this was a
bad choice of name. */
if (! TREE_PUBLIC (newdecl))
{
if (warn_shadow)
cp_warning ("shadowing %s function `%#D'",
DECL_BUILT_IN (olddecl) ? "built-in" : "library",
olddecl);
/* Discard the old built-in function. */
return 0;
}
/* If the built-in is not ansi, then programs can override
it even globally without an error. */
else if (! DECL_BUILT_IN (olddecl))
cp_warning ("library function `%#D' redeclared as non-function `%#D'",
olddecl, newdecl);
else
{
cp_error ("declaration of `%#D'", newdecl);
cp_error ("conflicts with built-in declaration `%#D'",
olddecl);
/* Discard the old built-in function. */
}
return 0;
}
else if (! types_match)
else if (!types_match)
{
if (TREE_CODE (newdecl) != FUNCTION_DECL)
if ((DECL_LANGUAGE (newdecl) == lang_c
&& DECL_LANGUAGE (olddecl) == lang_c)
|| compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
{
/* If the built-in is not ansi, then programs can override
it even globally without an error. */
if (! DECL_BUILT_IN (olddecl))
cp_warning ("library function `%#D' redeclared as non-function `%#D'",
olddecl, newdecl);
else
/* A near match; override the builtin. */
if (TREE_PUBLIC (newdecl))
{
cp_error ("declaration of `%#D'", newdecl);
cp_error ("conflicts with built-in declaration `%#D'",
olddecl);
cp_warning ("new declaration `%#D'", newdecl);
cp_warning ("ambiguates built-in declaration `%#D'",
olddecl);
}
return 0;
else if (warn_shadow)
cp_warning ("shadowing %s function `%#D'",
DECL_BUILT_IN (olddecl) ? "built-in" : "library",
olddecl);
}
cp_warning ("declaration of `%#D'", newdecl);
cp_warning ("conflicts with built-in declaration `%#D'",
olddecl);
else
/* Discard the old built-in function. */
return 0;
}
}
else if (TREE_CODE (olddecl) != TREE_CODE (newdecl))
......@@ -4469,17 +4482,7 @@ push_overloaded_decl (decl, flags)
int doing_global = (namespace_bindings_p () || !(flags & PUSH_LOCAL));
if (doing_global)
{
old = namespace_binding (name, DECL_CONTEXT (decl));
if (old && TREE_CODE (old) == FUNCTION_DECL
&& DECL_ARTIFICIAL (old)
&& (DECL_BUILT_IN (old) || DECL_BUILT_IN_NONANSI (old)))
{
if (duplicate_decls (decl, old))
return old;
old = NULL_TREE;
}
}
old = namespace_binding (name, DECL_CONTEXT (decl));
else
old = lookup_name_current_level (name);
......@@ -10013,6 +10016,8 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
if (TREE_CODE (size) == NOP_EXPR
&& TREE_TYPE (size) == TREE_TYPE (TREE_OPERAND (size, 0)))
size = TREE_OPERAND (size, 0);
if (TREE_READONLY_DECL_P (size))
size = decl_constant_value (size);
/* If this involves a template parameter, it will be a
constant at instantiation time, but we don't know
......@@ -10048,8 +10053,6 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
dname);
size = integer_one_node;
}
if (TREE_READONLY_DECL_P (size))
size = decl_constant_value (size);
if (pedantic && integer_zerop (size))
cp_pedwarn ("ANSI C++ forbids zero-size array `%D'", dname);
if (TREE_CONSTANT (size))
......
......@@ -2180,24 +2180,6 @@ emit_thunk (thunk_fndecl)
/* Code for synthesizing methods which have default semantics defined. */
/* For the anonymous union in TYPE, return the member that is at least as
large as the rest of the members, so we can copy it. */
static tree
largest_union_member (type)
tree type;
{
tree f, type_size = TYPE_SIZE (type);
for (f = TYPE_FIELDS (type); f; f = TREE_CHAIN (f))
if (simple_cst_equal (DECL_SIZE (f), type_size) == 1)
return f;
/* We should always find one. */
my_friendly_abort (323);
return NULL_TREE;
}
/* Generate code for default X(X&) constructor. */
static void
......
......@@ -5183,7 +5183,7 @@ instantiate_class_template (type)
input_filename = DECL_SOURCE_FILE (typedecl);
unreverse_member_declarations (type);
finish_struct_1 (type, 0);
finish_struct_1 (type);
CLASSTYPE_GOT_SEMICOLON (type) = 1;
/* Clear this now so repo_template_used is happy. */
......
......@@ -1320,7 +1320,6 @@ begin_class_definition (t)
/* Don't change signatures. */
if (! IS_SIGNATURE (t))
{
int needs_writing;
tree name = TYPE_IDENTIFIER (t);
if (! ANON_AGGRNAME_P (name))
......@@ -1464,7 +1463,7 @@ finish_class_definition (t, attributes, semi, pop_scope_p)
;
else
{
t = finish_struct (t, attributes, semi);
t = finish_struct (t, attributes);
if (semi)
note_got_semicolon (t);
}
......
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