Commit d7ceab7b by Mark Mitchell Committed by Mark Mitchell

decl.c (grokdeclarator): Complain about in-class initialization of aggregates and/or references.

	* decl.c (grokdeclarator): Complain about in-class initialization
	of aggregates and/or references.
	* pt.c (process_template_parm): Clear IS_AGGR_TYPE for
	TEMPLATE_TYPE_PARMs.

From-SVN: r21916
parent 03d0f4af
1998-08-23 Mark Mitchell <mark@markmitchell.com> 1998-08-23 Mark Mitchell <mark@markmitchell.com>
* decl.c (grokdeclarator): Complain about in-class initialization
of aggregates and/or references.
* pt.c (process_template_parm): Clear IS_AGGR_TYPE for
TEMPLATE_TYPE_PARMs.
* decl2.c (grok_array_decl): Add comment. * decl2.c (grok_array_decl): Add comment.
(mark_used): Don't instantiate an explicit instantiation. (mark_used): Don't instantiate an explicit instantiation.
* friend.c (make_friend_class): Remove bogus comment. Fix check * friend.c (make_friend_class): Remove bogus comment. Fix check
......
...@@ -10431,15 +10431,23 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) ...@@ -10431,15 +10431,23 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
but not both. If it appears in the class, the member is but not both. If it appears in the class, the member is
a member constant. The file-scope definition is always a member constant. The file-scope definition is always
required. */ required. */
if (! constp) if (IS_AGGR_TYPE (type)
/* According to Mike Stump, we generate bad code for || TREE_CODE (type) == REFERENCE_TYPE)
this case, so we might as well always make it an {
error. */ 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 void_type_node;
}
else if (!constp)
cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'", cp_error ("ANSI C++ forbids in-class initialization of non-const static member `%D'",
declarator); declarator);
else if (pedantic && ! INTEGRAL_TYPE_P (type)
if (pedantic && ! INTEGRAL_TYPE_P (type) && !uses_template_parms (type))
&& !uses_template_parms (type))
cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", declarator, type); cp_pedwarn ("ANSI C++ forbids initialization of member constant `%D' of non-integral type `%T'", declarator, type);
} }
...@@ -10452,7 +10460,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist) ...@@ -10452,7 +10460,7 @@ grokdeclarator (declarator, declspecs, decl_context, initialized, attrlist)
/* C++ allows static class members. /* C++ allows static class members.
All other work for this is done by grokfield. All other work for this is done by grokfield.
This VAR_DECL is built by build_lang_field_decl. This VAR_DCL is built by build_lang_field_decl.
All other VAR_DECLs are built by build_decl. */ All other VAR_DECLs are built by build_decl. */
decl = build_lang_field_decl (VAR_DECL, declarator, type); decl = build_lang_field_decl (VAR_DECL, declarator, type);
TREE_STATIC (decl) = 1; TREE_STATIC (decl) = 1;
......
...@@ -1590,6 +1590,7 @@ process_template_parm (list, next) ...@@ -1590,6 +1590,7 @@ process_template_parm (list, next)
else else
{ {
t = make_lang_type (TEMPLATE_TYPE_PARM); t = make_lang_type (TEMPLATE_TYPE_PARM);
IS_AGGR_TYPE (t) = 0;
/* parm is either IDENTIFIER_NODE or NULL_TREE */ /* parm is either IDENTIFIER_NODE or NULL_TREE */
decl = build_decl (TYPE_DECL, parm, t); decl = build_decl (TYPE_DECL, parm, t);
} }
......
// Build don't link:
struct A {
int rep;
static const A a(0); // ERROR - initialization
static const A b = 3; // ERROR - initialization
static const A& c = 2; // ERROR - initialization
A(int x) : rep(x) {}
};
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