Commit b17e2870 by Jason Merrill Committed by Jason Merrill

decl.c (start_decl): Pass attributes to grokdeclarator.

	* decl.c (start_decl): Pass attributes to grokdeclarator.
	(grokdeclarator): Handle attributes on constructor-syntax
	initializers.

From-SVN: r26313
parent 09a07623
1999-04-09 Jason Merrill <jason@yorick.cygnus.com>
* decl.c (start_decl): Pass attributes to grokdeclarator.
(grokdeclarator): Handle attributes on constructor-syntax
initializers.
1999-04-08 Mark Mitchell <mark@codesourcery.com> 1999-04-08 Mark Mitchell <mark@codesourcery.com>
* error.c (dump_expr): Don't crash on INDIRECT_REFs whose operands * error.c (dump_expr): Don't crash on INDIRECT_REFs whose operands
......
...@@ -6975,6 +6975,7 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) ...@@ -6975,6 +6975,7 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
tree context; tree context;
extern int have_extern_spec; extern int have_extern_spec;
extern int used_extern_spec; extern int used_extern_spec;
tree attrlist;
#if 0 #if 0
/* See code below that used this. */ /* See code below that used this. */
...@@ -6989,8 +6990,14 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) ...@@ -6989,8 +6990,14 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
used_extern_spec = 1; used_extern_spec = 1;
} }
if (attributes || prefix_attributes)
attrlist = build_scratch_list (attributes, prefix_attributes);
else
attrlist = NULL_TREE;
decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, decl = grokdeclarator (declarator, declspecs, NORMAL, initialized,
NULL_TREE); attrlist);
if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE) if (decl == NULL_TREE || TREE_CODE (decl) == VOID_TYPE)
return NULL_TREE; return NULL_TREE;
...@@ -8900,6 +8907,41 @@ build_ptrmemfunc_type (type) ...@@ -8900,6 +8907,41 @@ build_ptrmemfunc_type (type)
return t; return t;
} }
/* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
Check to see that the definition is valid. Issue appropriate error
messages. Return 1 if the definition is particularly bad, or 0
otherwise. */
int
check_static_variable_definition (decl, type)
tree decl;
tree type;
{
/* Motion 10 at San Diego: If a static const integral data member is
initialized with an integral constant expression, the initializer
may appear either in the declaration (within the class), or in
the definition, but not both. If it appears in the class, the
member is a member constant. The file-scope definition is always
required. */
if (CLASS_TYPE_P (type) || TREE_CODE (type) == REFERENCE_TYPE)
{
cp_error ("in-class initialization of static data member of non-integral type `%T'",
type);
/* If we just return the declaration, crashes will sometimes
occur. We therefore return void_type_node, as if this was a
friend declaration, to cause callers to completely ignore
this declaration. */
return 1;
}
else if (!CP_TYPE_CONST_P (type))
cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
decl);
else if (pedantic && !INTEGRAL_TYPE_P (type))
cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", decl, type);
return 0;
}
/* Given declspecs and a declarator, /* Given declspecs and a declarator,
determine the name and type of the object declared determine the name and type of the object declared
and construct a ..._DECL node for it. and construct a ..._DECL node for it.
...@@ -8927,6 +8969,9 @@ build_ptrmemfunc_type (type) ...@@ -8927,6 +8969,9 @@ build_ptrmemfunc_type (type)
BITFIELD for a field with specified width. BITFIELD for a field with specified width.
INITIALIZED is 1 if the decl has an initializer. INITIALIZED is 1 if the decl has an initializer.
ATTRLIST is a TREE_LIST node with prefix attributes in TREE_VALUE and
normal attributes in TREE_PURPOSE, or NULL_TREE.
In the TYPENAME case, DECLARATOR is really an absolute declarator. In the TYPENAME case, DECLARATOR is really an absolute declarator.
It may also be so in the PARM case, for a prototype where the It may also be so in the PARM case, for a prototype where the
argument type is specified but not the name. argument type is specified but not the name.
...@@ -8958,41 +9003,6 @@ build_ptrmemfunc_type (type) ...@@ -8958,41 +9003,6 @@ build_ptrmemfunc_type (type)
enum return_types { return_normal, return_ctor, return_dtor, return_conversion }; enum return_types { return_normal, return_ctor, return_dtor, return_conversion };
/* DECL is a VAR_DECL defined in-class, whose TYPE is also given.
Check to see that the definition is valid. Issue appropriate error
messages. Return 1 if the definition is particularly bad, or 0
otherwise. */
int
check_static_variable_definition (decl, type)
tree decl;
tree type;
{
/* Motion 10 at San Diego: If a static const integral data member is
initialized with an integral constant expression, the initializer
may appear either in the declaration (within the class), or in
the definition, but not both. If it appears in the class, the
member is a member constant. The file-scope definition is always
required. */
if (CLASS_TYPE_P (type) || TREE_CODE (type) == REFERENCE_TYPE)
{
cp_error ("in-class initialization of static data member of non-integral type `%T'",
type);
/* If we just return the declaration, crashes will sometimes
occur. We therefore return void_type_node, as if this was a
friend declaration, to cause callers to completely ignore
this declaration. */
return 1;
}
else if (!CP_TYPE_CONST_P (type))
cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
decl);
else if (pedantic && !INTEGRAL_TYPE_P (type))
cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", decl, type);
return 0;
}
tree tree
grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
tree declspecs; tree declspecs;
...@@ -9129,14 +9139,29 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) ...@@ -9129,14 +9139,29 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
case CALL_EXPR: case CALL_EXPR:
if (parmlist_is_exprlist (TREE_OPERAND (decl, 1))) if (parmlist_is_exprlist (TREE_OPERAND (decl, 1)))
{ {
/* This is actually a variable declaration using constructor /* This is actually a variable declaration using
syntax. We need to call start_decl and cp_finish_decl so we constructor syntax. We need to call start_decl and
can get the variable initialized... */ cp_finish_decl so we can get the variable
initialized... */
tree attributes, prefix_attributes;
*next = TREE_OPERAND (decl, 0); *next = TREE_OPERAND (decl, 0);
init = TREE_OPERAND (decl, 1); init = TREE_OPERAND (decl, 1);
decl = start_decl (declarator, declspecs, 1, NULL_TREE, NULL_TREE); if (attrlist)
{
attributes = TREE_PURPOSE (attrlist);
prefix_attributes = TREE_VALUE (attrlist);
}
else
{
attributes = NULL_TREE;
prefix_attributes = NULL_TREE;
}
decl = start_decl (declarator, declspecs, 1,
attributes, prefix_attributes);
if (decl) if (decl)
{ {
/* Look for __unused__ attribute */ /* Look for __unused__ attribute */
......
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