Commit 18fd68a8 by Mark Mitchell Committed by Mark Mitchell

re PR c++/11962 (ICE in type_dependent_expression on omitted second operand to…

re PR c++/11962 (ICE in type_dependent_expression on omitted second operand to ?: in template argument expression)

	PR c++/11962
	* typeck.c (build_x_conditional_expr): Handle missing middle
	operands in templates.
	* mangle.c (write_expression): Issue errors about attempts to
	mangle a non-existant middle operator to the ?: operator.

	PR c++/11962
	* g++.dg/template/cond2.C: New test.

From-SVN: r72785
parent 4f525294
2003-10-21 Mark Mitchell <mark@codesourcery.com>
PR c++/11962
* typeck.c (build_x_conditional_expr): Handle missing middle
operands in templates.
* mangle.c (write_expression): Issue errors about attempts to
mangle a non-existant middle operator to the ?: operator.
2003-10-21 Robert Bowdidge <bowdidge@apple.com> 2003-10-21 Robert Bowdidge <bowdidge@apple.com>
* decl.c (cp_finish_decl): Remove clause intended for asm directives * decl.c (cp_finish_decl): Remove clause intended for asm directives
in struct or class fields: this code is never executed. in struct or class fields: this code is never executed.
......
...@@ -2041,7 +2041,21 @@ write_expression (tree expr) ...@@ -2041,7 +2041,21 @@ write_expression (tree expr)
default: default:
for (i = 0; i < TREE_CODE_LENGTH (code); ++i) for (i = 0; i < TREE_CODE_LENGTH (code); ++i)
write_expression (TREE_OPERAND (expr, i)); {
tree operand = TREE_OPERAND (expr, i);
/* As a GNU expression, the middle operand of a
conditional may be omitted. Since expression
manglings are supposed to represent the input token
stream, there's no good way to mangle such an
expression without extending the C++ ABI. */
if (code == COND_EXPR && i == 1 && !operand)
{
error ("omitted middle operand to `?:' operand "
"cannot be mangled");
continue;
}
write_expression (operand);
}
} }
} }
} }
......
...@@ -4284,11 +4284,13 @@ build_x_conditional_expr (tree ifexp, tree op1, tree op2) ...@@ -4284,11 +4284,13 @@ build_x_conditional_expr (tree ifexp, tree op1, tree op2)
IFEXP is type-dependent, even though the eventual type of the IFEXP is type-dependent, even though the eventual type of the
expression doesn't dependent on IFEXP. */ expression doesn't dependent on IFEXP. */
if (type_dependent_expression_p (ifexp) if (type_dependent_expression_p (ifexp)
|| type_dependent_expression_p (op1) /* As a GNU extension, the middle operand may be omitted. */
|| (op1 && type_dependent_expression_p (op1))
|| type_dependent_expression_p (op2)) || type_dependent_expression_p (op2))
return build_min_nt (COND_EXPR, ifexp, op1, op2); return build_min_nt (COND_EXPR, ifexp, op1, op2);
ifexp = build_non_dependent_expr (ifexp); ifexp = build_non_dependent_expr (ifexp);
op1 = build_non_dependent_expr (op1); if (op1)
op1 = build_non_dependent_expr (op1);
op2 = build_non_dependent_expr (op2); op2 = build_non_dependent_expr (op2);
} }
......
2003-10-21 Mark Mitchell <mark@codesourcery.com>
PR c++/11962
* g++.dg/template/cond2.C: New test.
2003-10-20 Joseph S. Myers <jsm@polyomino.org.uk> 2003-10-20 Joseph S. Myers <jsm@polyomino.org.uk>
* gcc.dg/builtins-28.c: New test. * gcc.dg/builtins-28.c: New test.
......
// PR c++/11962
// { dg-options "" }
template<int X> class c;
template<int X, int Y> int test(c<X ? : Y>&);
void test(c<2>*c2) {
test<0, 2>(*c2); // { dg-error "omitted" }
}
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