Commit 39703eb9 by Mark Mitchell Committed by Mark Mitchell

re PR c++/11547 (ICE with const temporaries)

	PR c++/11547
	* cp-tree.h (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P): New
	macro.
	(DECL_PRETTY_FUNCTION_P): Use VAR_DECL_CHECK.
	* decl.c (duplicate_decls): Merge
	DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
	* parser.c (cp_parser_postfix_expression): Adjust call to
	cp_parser_initializer_list and
	cp_parser_parenthesized_expression_list.
	(cp_parser_parenthesized_expression_list): Add non_constant_p.
	(cp_parser_new_placement): Adjust call to
	cp_parser_parenthesized_expression_list.
	(cp_parser_direct_new_declarator): Likewise.
	(cp_parser_conditional_expression): Remove.
	(cp_parser_constant_expression): Parse an assignment-expression,
	not a conditional-expression.
	(cp_parser_simple_declaration): Resolve expression/declaration
	ambiguity more quickly.
	(cp_parser_mem_initializer): Adjust call to
	cp_parser_parenthesized_expression_list.
	(cp_parser_init_declarator): Keep track of whether or not the
	initializer is a constant-expression.
	(cp_parser_initializer): Add non_constant_p parameter.
	(cp_parser_initializer_clause): Likewise.
	(cp_parser_initializer_list): Likewise.
	(cp_parser_attribute_list): Adjust call to
	cp_parser_parenthesized_expression_list.
	(cp_parser_functional_cast): Likewise.
	* pt.c (tsubst_decl): Copy
	DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
	(tsubst_expr): Tweak use of DECL_PRETTY_FUNCTION_P.
	* semantics.c (finish_id_expression): Use
	DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.

	PR c++/11547
	* g++.dg/parse/constant3.C: New test.
	* g++.dg/parse/crash7.C: Likewise.

From-SVN: r69493
parent db5eed18
2003-07-16 Mark Mitchell <mark@codesourcery.com>
PR c++/11547
* cp-tree.h (DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P): New
macro.
(DECL_PRETTY_FUNCTION_P): Use VAR_DECL_CHECK.
* decl.c (duplicate_decls): Merge
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
* parser.c (cp_parser_postfix_expression): Adjust call to
cp_parser_initializer_list and
cp_parser_parenthesized_expression_list.
(cp_parser_parenthesized_expression_list): Add non_constant_p.
(cp_parser_new_placement): Adjust call to
cp_parser_parenthesized_expression_list.
(cp_parser_direct_new_declarator): Likewise.
(cp_parser_conditional_expression): Remove.
(cp_parser_constant_expression): Parse an assignment-expression,
not a conditional-expression.
(cp_parser_simple_declaration): Resolve expression/declaration
ambiguity more quickly.
(cp_parser_mem_initializer): Adjust call to
cp_parser_parenthesized_expression_list.
(cp_parser_init_declarator): Keep track of whether or not the
initializer is a constant-expression.
(cp_parser_initializer): Add non_constant_p parameter.
(cp_parser_initializer_clause): Likewise.
(cp_parser_initializer_list): Likewise.
(cp_parser_attribute_list): Adjust call to
cp_parser_parenthesized_expression_list.
(cp_parser_functional_cast): Likewise.
* pt.c (tsubst_decl): Copy
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
(tsubst_expr): Tweak use of DECL_PRETTY_FUNCTION_P.
* semantics.c (finish_id_expression): Use
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P.
2003-07-16 Neil Booth <neil@daikokuya.co.uk>
* lang-options.h: Remove.
......
......@@ -45,6 +45,7 @@ struct diagnostic_context;
AGGR_INIT_VIA_CTOR_P (in AGGR_INIT_EXPR)
PTRMEM_OK_P (in ADDR_EXPR, OFFSET_REF)
PARMLIST_ELLIPSIS_P (in PARMLIST)
DECL_PRETTY_FUNCTION_P (in VAR_DECL)
1: IDENTIFIER_VIRTUAL_P.
TI_PENDING_TEMPLATE_FLAG.
TEMPLATE_PARMS_FOR_INLINE.
......@@ -59,6 +60,7 @@ struct diagnostic_context;
ICS_THIS_FLAG (in _CONV)
BINFO_LOST_PRIMARY_P (in BINFO)
TREE_PARMLIST (in TREE_LIST)
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (in VAR_DECL)
3: TYPE_USES_VIRTUAL_BASECLASSES (in a class TYPE).
BINFO_VTABLE_PATH_MARKED.
BINFO_PUSHDECLS_MARKED.
......@@ -1926,6 +1928,11 @@ struct lang_decl GTY(())
#define DECL_INITIALIZED_P(NODE) \
(TREE_LANG_FLAG_1 (VAR_DECL_CHECK (NODE)))
/* Nonzero for a VAR_DECL that was initialized with a
constant-expression. */
#define DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P(NODE) \
(TREE_LANG_FLAG_2 (VAR_DECL_CHECK (NODE)))
/* Nonzero if the DECL was initialized in the class definition itself,
rather than outside the class. This is used for both static member
VAR_DECLS, and FUNTION_DECLS that are defined in the class. */
......@@ -2033,7 +2040,7 @@ struct lang_decl GTY(())
/* Nonzero if this DECL is the __PRETTY_FUNCTION__ variable in a
template function. */
#define DECL_PRETTY_FUNCTION_P(NODE) \
(TREE_LANG_FLAG_0 (NODE))
(TREE_LANG_FLAG_0 (VAR_DECL_CHECK (NODE)))
/* The _TYPE context in which this _DECL appears. This field holds the
class where a virtual function instance is actually defined. */
......
......@@ -3306,6 +3306,8 @@ duplicate_decls (tree newdecl, tree olddecl)
{
DECL_THIS_EXTERN (newdecl) |= DECL_THIS_EXTERN (olddecl);
DECL_INITIALIZED_P (newdecl) |= DECL_INITIALIZED_P (olddecl);
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (newdecl)
|= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (olddecl);
}
/* Do this after calling `merge_types' so that default
......
......@@ -6190,7 +6190,11 @@ tsubst_decl (tree t, tree args, tree type, tsubst_flags_t complain)
r = copy_decl (t);
if (TREE_CODE (r) == VAR_DECL)
type = complete_type (type);
{
type = complete_type (type);
DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (r)
= DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (t);
}
else if (DECL_SELF_REFERENCE_P (t))
SET_DECL_SELF_REFERENCE_P (r);
TREE_TYPE (r) = type;
......@@ -7620,7 +7624,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
else
{
maybe_push_decl (decl);
if (DECL_PRETTY_FUNCTION_P (decl))
if (TREE_CODE (decl) == VAR_DECL
&& DECL_PRETTY_FUNCTION_P (decl))
{
/* For __PRETTY_FUNCTION__ we have to adjust the
initializer. */
......
......@@ -2478,17 +2478,11 @@ finish_id_expression (tree id_expression,
;
/* Const variables or static data members of integral or
enumeration types initialized with constant expressions
are OK. We also accept dependent initializers; they may
turn out to be constant at instantiation-time. */
are OK. */
else if (TREE_CODE (decl) == VAR_DECL
&& CP_TYPE_CONST_P (TREE_TYPE (decl))
&& INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (decl))
&& DECL_INITIAL (decl)
&& (TREE_CONSTANT (DECL_INITIAL (decl))
|| type_dependent_expression_p (DECL_INITIAL
(decl))
|| value_dependent_expression_p (DECL_INITIAL
(decl))))
&& DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl))
;
else
{
......
2003-07-16 Mark Mitchell <mark@codesourcery.com>
PR c++/11547
* g++.dg/parse/constant3.C: New test.
* g++.dg/parse/crash7.C: Likewise.
2003-07-16 Andrew Pinski <pinskia@physics.uc.edu>
PR target/11008
......
const int i = 1;
const int j (2);
const int k = { 3 };
enum { a = i, b = j, c = k };
struct A
{
int foo () const { return 0; }
};
template <typename> void bar (int x[], const A &a)
{
const int i=a.foo();
x[i]=0;
}
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