re PR c++/23789 (compilation error when template parameters have certain complexity)

PR c++/23789
	* cvt.c (perform_qualification_conversions): Don't create
	unnecessary NOP_EXPRs.
	* pt.c (tsubst_template_arg): Use fold_non_dependent_expr.

	PR c++/23789
	* g++.dg/template/nontype14.C: New test.

From-SVN: r104193
This commit is contained in:
Mark Mitchell 2005-09-12 22:38:34 +00:00 committed by Mark Mitchell
parent b35c082263
commit 6f25cb3578
5 changed files with 30 additions and 28 deletions

View File

@ -1,3 +1,10 @@
2005-09-12 Mark Mitchell <mark@codesourcery.com>
PR c++/23789
* cvt.c (perform_qualification_conversions): Don't create
unnecessary NOP_EXPRs.
* pt.c (tsubst_template_arg): Use fold_non_dependent_expr.
2005-09-12 Ian Lance Taylor <ian@airs.com>
PR g++/7874

View File

@ -1209,8 +1209,10 @@ perform_qualification_conversions (tree type, tree expr)
expr_type = TREE_TYPE (expr);
if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type)
&& comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type)))
if (same_type_p (type, expr_type))
return expr;
else if (TYPE_PTR_P (type) && TYPE_PTR_P (expr_type)
&& comp_ptr_ttypes (TREE_TYPE (type), TREE_TYPE (expr_type)))
return build_nop (type, expr);
else if (TYPE_PTR_TO_MEMBER_P (type)
&& TYPE_PTR_TO_MEMBER_P (expr_type)

View File

@ -5919,32 +5919,7 @@ tsubst_template_arg (tree t, tree args, tsubst_flags_t complain, tree in_decl)
else
{
r = tsubst_expr (t, args, complain, in_decl);
if (!uses_template_parms (r))
{
/* Sometimes, one of the args was an expression involving a
template constant parameter, like N - 1. Now that we've
tsubst'd, we might have something like 2 - 1. This will
confuse lookup_template_class, so we do constant folding
here. We have to unset processing_template_decl, to fool
tsubst_copy_and_build() into building an actual tree. */
/* If the TREE_TYPE of ARG is not NULL_TREE, ARG is already
as simple as it's going to get, and trying to reprocess
the trees will break. Once tsubst_expr et al DTRT for
non-dependent exprs, this code can go away, as the type
will always be set. */
if (!TREE_TYPE (r))
{
int saved_processing_template_decl = processing_template_decl;
processing_template_decl = 0;
r = tsubst_copy_and_build (r, /*args=*/NULL_TREE,
tf_error, /*in_decl=*/NULL_TREE,
/*function_p=*/false);
processing_template_decl = saved_processing_template_decl;
r = fold (r);
}
}
r = fold_non_dependent_expr (r);
}
return r;
}

View File

@ -1,3 +1,8 @@
2005-09-12 Mark Mitchell <mark@codesourcery.com>
PR c++/23789
* g++.dg/template/nontype14.C: New test.
2005-09-12 Ian Lance Taylor <ian@airs.com>
PR g++/7874

View File

@ -0,0 +1,13 @@
// PR c++/23789
template <int W> struct X {
template <int W2>
X< (W+(W&&W) > 1 ? W+(W&&W) : 1)+1>
operator + (const X<W2>&) const;
};
template <int dummy> void foo()
{
X<6> A,B;
A + B;
}