re PR c++/42013 (cv-qualification of conditional expression type depending on the value of its first expression?!?)

PR c++/42013
	* call.c (build_conditional_expr): Don't fold a TREE_SIDE_EFFECTS
	COND_EXPR in unevaluated context.

From-SVN: r154124
This commit is contained in:
Jason Merrill 2009-11-12 13:25:42 -05:00 committed by Jason Merrill
parent 9d324ddebd
commit f33e4dd77a
4 changed files with 42 additions and 2 deletions

View file

@ -1,3 +1,9 @@
2009-11-12 Jason Merrill <jason@redhat.com>
PR c++/42013
* call.c (build_conditional_expr): Don't fold a TREE_SIDE_EFFECTS
COND_EXPR in unevaluated context.
2009-11-12 Jan Hubicka <jh@suse.cz>
* decl2.c (constrain_visibility): Clear WEAK and COMMON flags.

View file

@ -3991,8 +3991,13 @@ build_conditional_expr (tree arg1, tree arg2, tree arg3,
}
valid_operands:
result = fold_if_not_in_template (build3 (COND_EXPR, result_type, arg1,
arg2, arg3));
result = build3 (COND_EXPR, result_type, arg1, arg2, arg3);
if (cp_unevaluated_operand && TREE_SIDE_EFFECTS (result))
/* Avoid folding a ?: of two calls within decltype (c++/42013). */;
else
result = fold_if_not_in_template (result);
/* We can't use result_type below, as fold might have returned a
throw_expr. */

View file

@ -1,3 +1,8 @@
2009-11-12 Jason Merrill <jason@redhat.com>
PR c++/42013
* g++.dg/cpp0x/decltype19.C: New.
2009-11-11 Jason Merrill <jason@redhat.com>
PR c++/39131

View file

@ -0,0 +1,24 @@
// PR c++/42013
template<typename _Tp>
_Tp
declval();
template<typename _Tp, typename _Up>
struct common_type
{
typedef __decltype(true ? declval<_Tp>() : declval<_Up>()) typet;
typedef __decltype(false ? declval<_Tp>() : declval<_Up>()) typef;
};
template<typename, typename> struct is_same;
template<typename _Tp> struct is_same<_Tp, _Tp> { typedef _Tp type; };
void f()
{
typedef common_type<int, const int>::typet typet;
typedef common_type<int, const int>::typef typef;
typedef is_same<typet, typef>::type type;
}