Commit 015c2c66 by Mark Mitchell Committed by Mark Mitchell

re PR c++/28341 (ICE with references as template parameters)

	PR c++/28341
	* tree.c (cast_valid_in_integral_constant_expression_p): New
	function.
	* cp-tree.h (tsubst_copy_and_build): Adjust prototype.
	* pt.c (tsubst_expr): Add integral_constant_expression_p
	parameter.
	(fold_non_dependent_expr): Adjust callers of
	tsubst_{expr,copy_and_build}.
	(tsubst_friend_function): Likewise.
	(tsubst_template_arg): Likewise.
	(tsubst_default_argument): Likewise.
	(tsubst_decl): Likewise.
	(tsubst): Likewise.
	(tsubst_omp_clasuses): Likewise.
	(regenerate_decl_fromp_template): Likewise.
	(instantiate_decl): Likewise.
	(tsubst_initializer_list): Likewise.
	(tsubst_enum): Likewise.
	(tsubst_expr): Use RECUR throughout.
	(tsubst_copy_and_build): Change definition of RECUR.  Do not allow
	invalid casts in integral constant expressions.
	* parser.c (cp_parser_postfix_expression): Use
	cast_valid_in_integral_constant_expression_p.
	(cp_parser_cast_expression): Likewise.
	(cp_parser_functional_cast): Likewise.

	PR c++/28346
	* pt.c (tsubst_qualified_id): Do not strip references from
	OFFSET_REFs. 

2006-08-20  Mark Mitchell  <mark@codesourcery.com>

	PR c++/28341
	* g++.dg/template/ref3.C: New test.
	* g++.dg/template/nontype13.C: New test.

	PR c++/28346
	* g++.dg/template/ptrmem17.C: New test.


2006-08-20  Mark Mitchell  <mark@codesourcery.com>

	* objcp-lang.c (objcp_tsubst_copy_and_build): Adjust call to
	tsubst_copy_and_build.

From-SVN: r116276
parent 1057fc81
2006-08-20 Mark Mitchell <mark@codesourcery.com>
PR c++/28341
* tree.c (cast_valid_in_integral_constant_expression_p): New
function.
* cp-tree.h (tsubst_copy_and_build): Adjust prototype.
* pt.c (tsubst_expr): Add integral_constant_expression_p
parameter.
(fold_non_dependent_expr): Adjust callers of
tsubst_{expr,copy_and_build}.
(tsubst_friend_function): Likewise.
(tsubst_template_arg): Likewise.
(tsubst_default_argument): Likewise.
(tsubst_decl): Likewise.
(tsubst): Likewise.
(tsubst_omp_clasuses): Likewise.
(regenerate_decl_fromp_template): Likewise.
(instantiate_decl): Likewise.
(tsubst_initializer_list): Likewise.
(tsubst_enum): Likewise.
(tsubst_expr): Use RECUR throughout.
(tsubst_copy_and_build): Change definition of RECUR. Do not allow
invalid casts in integral constant expressions.
* parser.c (cp_parser_postfix_expression): Use
cast_valid_in_integral_constant_expression_p.
(cp_parser_cast_expression): Likewise.
(cp_parser_functional_cast): Likewise.
PR c++/28346
* pt.c (tsubst_qualified_id): Do not strip references from
OFFSET_REFs.
2006-08-17 Volker Reichelt <reichelt@igpm.rwth-aachen.de> 2006-08-17 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c++/28606 PR c++/28606
......
...@@ -4117,7 +4117,7 @@ extern void print_candidates (tree); ...@@ -4117,7 +4117,7 @@ extern void print_candidates (tree);
extern void instantiate_pending_templates (int); extern void instantiate_pending_templates (int);
extern tree tsubst_default_argument (tree, tree, tree); extern tree tsubst_default_argument (tree, tree, tree);
extern tree tsubst_copy_and_build (tree, tree, tsubst_flags_t, extern tree tsubst_copy_and_build (tree, tree, tsubst_flags_t,
tree, bool); tree, bool, bool);
extern tree most_general_template (tree); extern tree most_general_template (tree);
extern tree get_mostly_instantiated_function_type (tree); extern tree get_mostly_instantiated_function_type (tree);
extern int problematic_instantiation_changed (void); extern int problematic_instantiation_changed (void);
...@@ -4391,6 +4391,7 @@ extern tree fold_if_not_in_template (tree); ...@@ -4391,6 +4391,7 @@ extern tree fold_if_not_in_template (tree);
extern tree rvalue (tree); extern tree rvalue (tree);
extern tree convert_bitfield_to_declared_type (tree); extern tree convert_bitfield_to_declared_type (tree);
extern tree cp_save_expr (tree); extern tree cp_save_expr (tree);
extern bool cast_valid_in_integral_constant_expression_p (tree);
/* in typeck.c */ /* in typeck.c */
extern int string_conv_p (tree, tree, int); extern int string_conv_p (tree, tree, int);
......
...@@ -4004,9 +4004,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p) ...@@ -4004,9 +4004,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p)
/* Only type conversions to integral or enumeration types /* Only type conversions to integral or enumeration types
can be used in constant-expressions. */ can be used in constant-expressions. */
if (parser->integral_constant_expression_p if (!cast_valid_in_integral_constant_expression_p (type)
&& !dependent_type_p (type)
&& !INTEGRAL_OR_ENUMERATION_TYPE_P (type)
&& (cp_parser_non_integral_constant_expression && (cp_parser_non_integral_constant_expression
(parser, (parser,
"a cast to a type other than an integral or " "a cast to a type other than an integral or "
...@@ -5490,9 +5488,7 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p) ...@@ -5490,9 +5488,7 @@ cp_parser_cast_expression (cp_parser *parser, bool address_p, bool cast_p)
/* Only type conversions to integral or enumeration types /* Only type conversions to integral or enumeration types
can be used in constant-expressions. */ can be used in constant-expressions. */
if (parser->integral_constant_expression_p if (!cast_valid_in_integral_constant_expression_p (type)
&& !dependent_type_p (type)
&& !INTEGRAL_OR_ENUMERATION_TYPE_P (type)
&& (cp_parser_non_integral_constant_expression && (cp_parser_non_integral_constant_expression
(parser, (parser,
"a cast to a type other than an integral or " "a cast to a type other than an integral or "
...@@ -15695,13 +15691,11 @@ cp_parser_functional_cast (cp_parser* parser, tree type) ...@@ -15695,13 +15691,11 @@ cp_parser_functional_cast (cp_parser* parser, tree type)
conversions to integral or enumeration type can be used". */ conversions to integral or enumeration type can be used". */
if (TREE_CODE (type) == TYPE_DECL) if (TREE_CODE (type) == TYPE_DECL)
type = TREE_TYPE (type); type = TREE_TYPE (type);
if (cast != error_mark_node && !dependent_type_p (type) if (cast != error_mark_node
&& !INTEGRAL_OR_ENUMERATION_TYPE_P (type)) && !cast_valid_in_integral_constant_expression_p (type)
{ && (cp_parser_non_integral_constant_expression
if (cp_parser_non_integral_constant_expression (parser, "a call to a constructor")))
(parser, "a call to a constructor")) return error_mark_node;
return error_mark_node;
}
return cast; return cast;
} }
......
...@@ -2376,6 +2376,17 @@ fold_if_not_in_template (tree expr) ...@@ -2376,6 +2376,17 @@ fold_if_not_in_template (tree expr)
return fold (expr); return fold (expr);
} }
/* Returns true if a cast to TYPE may appear in an integral constant
expression. */
bool
cast_valid_in_integral_constant_expression_p (tree type)
{
return (INTEGRAL_OR_ENUMERATION_TYPE_P (type)
|| dependent_type_p (type)
|| type == error_mark_node);
}
#if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
/* Complain that some language-specific thing hanging off a tree /* Complain that some language-specific thing hanging off a tree
......
2006-08-20 Mark Mitchell <mark@codesourcery.com>
* objcp-lang.c (objcp_tsubst_copy_and_build): Adjust call to
tsubst_copy_and_build.
2006-07-28 Volker Reichelt <reichelt@igpm.rwth-aachen.de> 2006-07-28 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
* Make-lang.in: Use $(HEADER_H) instead of header.h in dependencies. * Make-lang.in: Use $(HEADER_H) instead of header.h in dependencies.
......
...@@ -110,8 +110,10 @@ tree ...@@ -110,8 +110,10 @@ tree
objcp_tsubst_copy_and_build (tree t, tree args, tsubst_flags_t complain, objcp_tsubst_copy_and_build (tree t, tree args, tsubst_flags_t complain,
tree in_decl, bool function_p ATTRIBUTE_UNUSED) tree in_decl, bool function_p ATTRIBUTE_UNUSED)
{ {
#define RECURSE(NODE) \ #define RECURSE(NODE) \
tsubst_copy_and_build (NODE, args, complain, in_decl, /*function_p=*/false) tsubst_copy_and_build (NODE, args, complain, in_decl, \
/*function_p=*/false, \
/*integral_constant_expression_p=*/false)
/* The following two can only occur in Objective-C++. */ /* The following two can only occur in Objective-C++. */
......
2006-08-20 Mark Mitchell <mark@codesourcery.com>
PR c++/28341
* g++.dg/template/ref3.C: New test.
* g++.dg/template/nontype13.C: New test.
PR c++/28346
* g++.dg/template/ptrmem17.C: New test.
2006-08-20 Danny Smith <dannysmith@users.sourceforge.net> 2006-08-20 Danny Smith <dannysmith@users.sourceforge.net>
PR target/28648 c: PR target/28648 c:
...@@ -11,7 +11,7 @@ struct Dummy ...@@ -11,7 +11,7 @@ struct Dummy
template<bool B> template<bool B>
void tester() void tester()
{ {
bar<evil>()(); // { dg-error "argument" } bar<evil>()(); // { dg-error "constant" }
} }
template<bool B> template<bool B>
struct bar struct bar
......
// PR c++/28346
template<int> struct A
{
int& i;
A();
~A() { &A::i; } // { dg-error "reference" }
};
A<0> a; // { dg-error "instantiated" }
// PR c++/28341
template<const int&> struct A {};
template<typename T> struct B
{
A<(T)0> b; // { dg-error "constant" }
A<T(0)> a; // { dg-error "constant" }
};
B<const int&> b;
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